PayPal Rest API gives error 401 when switching to Live Credentials

I am creating a small website on which I have implemented the PayPal REST API for processing credit card statements.

Now the problem is that it works fine using Sandbox credentials ... but when switching to Live Credentials it gives the following error:

Fatal error: "PayPal \ Exception \ PPConnectionException" exception with the message "Get an Http 401 response code when accessing https://api.paypal.com/v1/payments/payment . Resubmitted 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} b Roshen in C: \ xampp \ htdocs \ rest_api_sdk_php \ sample \ vendor \ paypal \ sdk-core-php \ lib \ PayPal \ Core \ PPHttpConnection.php on line 99

Honestly, I have no idea what causes this error. When switching to PayPal Live, I made changes in two places. i.e.

1st in "bootstrap.php":

$apiContext = new ApiContext(new OAuthTokenCredential( '<Live Client ID>', '<Live Secret>')); 

Give the identifier and secret identifier Live. And the other file in which I made the 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 in which I have to make changes?

+6
source share
2 answers

I faced the same problem, after which I got a solution.

You must change the mode from sandbox to live and 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' ) ); 
+3
source

Reply from comments - @PayPal_Patrick Thanx buddy! I solved the problem.

In fact, the problem was not on my part. I did everything right.

The client did not enable their account, so I was unable to complete payment requests using Live Credentials. Anyway, thanks for your help!

+2
source

Source: https://habr.com/ru/post/949968/


All Articles