Bob
Bob

Reputation: 1

Paypal checkout - trouble for going live

I am making a payment page with paypal checkout (in php), everything is working fine when i am in sandbox mode but when i go live, i got this error after paying...

Fatal error: Uncaught PayPal\Exception\PayPalConnectionException: Got Http response code 401 when accessing https://api.sandbox.paypal.com/v1/oauth2/token. in www/src/package/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php:207 Stack trace: #0 www/src/package/vendor/paypal/rest-api-sdk-php/lib/PayPal/Auth/OAuthTokenCredential.php(252): PayPal\Core\PayPalHttpConnection->execute('grant_type=clie...') #1 www/src/package/vendor/paypal/rest-api-sdk-php/lib/PayPal/Auth/OAuthTokenCredential.php(280): PayPal\Auth\OAuthTokenCredential->getToken(Array, 'qsdqsdqsdqsd', 'qdsqdsdqsdsqd', 'grant_type=clie...') #2 www/src/package/vendor/paypal/rest-api-sdk-php/lib/PayPal/Auth/OAuthTokenCredential.php(216): PayPal\Auth\OAuthTokenCredential->generateAccessToken(Array, NULL) #3 www/src/package/vendor/paypal/rest-api-sdk-php/lib/PayPal/Auth/OAuthTokenCredential.php(166): PayPal\Auth\OAuthTokenCredential->updateAccessToken(Array) #4 www/src/package/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php on line 207

Could you help me ? Thanks

Upvotes: 0

Views: 577

Answers (1)

Preston PHX
Preston PHX

Reputation: 30477

As mentioned in comments, it appears you changed your credentials to live without changing the environment from sandbox to live, so those live credentials are being used against a sandbox endpoint, which won't work. The two environments are completely separate.

Also, it appears you are using the deprecated v1/payments SDK, for which there is no support. You should change your integration to the current v2/checkout/orders Checkout-PHP-SDK...

Make two routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return only JSON data (no HTML or text). The latter one should (on success) store the payment details in your database before it does the return (particularly purchase_units[0].payments.captures[0].id, the PayPal transaction ID)

Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

Upvotes: 1

Related Questions