I am creating a small website in which I implemented PayPal REST API to process Credit Card checkouts.
Now the problem is that it is working fine using Sandbox Credentials... but it gives following error when I switch to Live Credentials:
Fatal error: Uncaught exception 'PayPal\\Exception\\PPConnectionException' with message 'Got Http response code 401 when accessing https://api.paypal.com/v1/payments/payment . Retried 0 times.' in C:\\xampp\\htdocs\\rest_api_sdk_php\\sample\\vendor\\paypal\\sdk-core-php\\lib\\PayPal\\Core\\PPHttpConnection.php:99 Stack trace: #0 C:\\xampp\\htdocs\\rest_api_sdk_php\\sample\\vendor\\paypal\\sdk-core-php\\lib\\PayPal\\Transport\\PPRestCall.php(44): PayPal\\Core\\PPHttpConnection->execute('{"intent":"sale...') #1 C:\\xampp\\htdocs\\rest_api_sdk_php\\sample\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Api\\Payment.php(246): PayPal\\Transport\\PPRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"intent":"sale...') #2 C:\\xampp\\htdocs\\rest_api_sdk_php\\sample\\payments\\CreatePayment.php(89): PayPal\\Api\\Payment->create(Object(PayPal\\Rest\\ApiContext)) #3 {main} thrown in C:\\xampp\\htdocs\\rest_api_sdk_php\\sample\\vendor\\paypal\\sdk-core-php\\lib\\PayPal\\Core\\PPHttpConnection.php on line 99
Quite frankly I have no idea what is causing this error. I made changes in two places when switching to PayPal Live. ie
1st in "bootstrap.php":
$apiContext = new ApiContext(new OAuthTokenCredential(
'<Live Client ID>',
'<Live Secret>'));
Gave Live Client-ID and Secret. And the other file in which I made change is "sdk_config.ini":
;Service Configuration
[Service]
mode=live ; can be set to sandbox / live
Changed "mode" from "sandbox" to "live"
Is there any other file also in which I have to make changes?
I was facing same issue then got solution.
You have to change the mode from sandbox
to live
and the log.LogLevel
from DEBUG
to FINE
:
/* Sandbox */
$apiContext->setConfig(
array(
'mode' => 'sandbox',
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'DEBUG', // PLEASE USE FINE LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
'cache.enabled' => true,
// 'http.CURLOPT_CONNECTTIMEOUT' => 30
// 'http.headers.PayPal-Partner-Attribution-Id' => '123123123'
)
);
/* For Live */
$apiContext->setConfig(
array(
'mode' => 'live',
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'FINE', // PLEASE USE FINE LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
'cache.enabled' => true,
// 'http.CURLOPT_CONNECTTIMEOUT' => 30
// 'http.headers.PayPal-Partner-Attribution-Id' => '123123123'
)
);
Answer from the comments - @PayPal_Patrick Thanx buddy! I have resolved the issue.
In fact the problem was not from my side. I was doing everything correctly.
Client didn't enable her Live Account that's why I was unable to make payment requests using Live Credentials. Anyhow, thanx for your help!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.