Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal Rest API gives 401 error when switched to Live Credentials

Tags:

rest

php

api

paypal

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. i.e.

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?

like image 226
user2524046 Avatar asked Jul 22 '13 07:07

user2524046


2 Answers

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'
    )
);
like image 182
Sharjeel Alam Avatar answered Oct 20 '22 01:10

Sharjeel Alam


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!

like image 30
Dfranc3373 Avatar answered Oct 20 '22 00:10

Dfranc3373