简体   繁体   中英

PayPal REST Api error: response 401 PPConnectionException

I'm using the PHP PayPal REST API sandbox and getting errors when I do my $payment->create( $apiContext );

My Error log reads as:

    PHP Fatal error:  Uncaught exception 'PayPal\\Exception\\PPConnectionException' with message 

'Got Http response code 401 when accessing https://api.paypal.com/v1/oauth2/token. 
    Retried 0 times.' in /usr/local/web/servers/domain/guts/paypal_api/vendor/paypal/sdk-core-php/lib/PayPal/Core/PPHttpConnection.php:99\nStack trace:\n

#0 /usr/local/web/servers/domain/guts/paypal_api/lib/PayPal/Auth/OAuthTokenCredential.php(96): 
    PayPal\\Core\\PPHttpConnection->execute('grant_type=clie...')\n

#1 /usr/local/web/servers/domain/guts/paypal_api/lib/PayPal/Auth/OAuthTokenCredential.php(76): 
    PayPal\\Auth\\OAuthTokenCredential->_generateAccessToken(Array)\n

#2 /usr/local/web/servers/domain/guts/paypal_api/lib/PayPal/Rest/RestHandler.php(56): PayPal\\Auth\\OAuthTokenCredential->getAccessToken(Array)\n

#3 /usr/local/web/servers/domain/guts/paypal_api/vendor/paypal/sdk-core-php/lib/PayPal/Transport/PPRestCall.php(41): 
    PayPal\\Rest\\RestHandler->handle(Object(PayPal\\Core\\PPHttpConfig), '{"intent":"sale...', Array)\n

#4 /usr/local/web/servers/domain/guts/paypal_api/lib/PayPal/A in 
    /usr/local/web/servers/domain/guts/paypal_api/vendor/paypal/sdk-core-php/lib/PayPal/Core/PPHttpConnection.php on line 99, 
    referer: http://domain.com/products/basket/verify/

my PayPal.log file shows:

PayPal\Core\PPHttpConnection: Connecting to https://api.paypal.com/v1/oauth2/token
PayPal\Core\PPHttpConnection: Payload grant_type=client_credentials
PayPal\Core\PPHttpConnection: Adding header User-Agent: PayPalSDK/rest-sdk-php 0.6.0 (lang=PHP;v=5.3.3;bit=64;os=Linux_2.6.18-348.6.1.el5;machine=x86_64;openssl=0.9.8e-fips-rhel5;curl=7.15.5)
PayPal\Core\PPHttpConnection: Adding header Authorization: Basic QVpteVVCQ3VfdDhlb3QxcGx0UksyUG56Y3NhcXpOeXNIMlNDLXBDbTlUNGVGNDE3OFd1cFBFRmhkTVpnOkVGZ3g4UkNCZUppSkw3NW1JV1FDRFROTVVsanFOLW1fdlFuM3owMzZOZ3EwTUp3RVFwRkNlV0Z0dWhaag==
PayPal\Core\PPHttpConnection: Adding header Accept: */*

I've tried test cc numbers, cc numbers set up on paypal's sandbox site. I've tried using the credentials in the demo app provided in rest-api-skd-php-master (the demo works btw).

I can show you my code though it pretty precisely emulates the test case.

The only thing I can think of is that the processing files are buried below www access levels?

If you can clean any info from the error logs I'm all ears. If there's more info you need from me I can provide it.

If you are intending to use sandbox as stated in the first line, then the error is happening because you are calling production PayPal servers.

Change https://api.paypal.com/v1/oauth2/token

To https://api.sandbox.paypal.com/v1/oauth2/token

I had same issue due to being a new in laravel 5.1, for paypal you need to set it to sandbox in /app/Http/controllers/paypalcontroller.php and also your paypal details in /app/Ecommerce/Billing/paypal.php. hope that helps

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM