Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm trying to use the PayPal-PHP-SDK to integrate PayPal with a custom built WordPress eCommerce theme and I'm getting a an error:
Got Http response code 400 when accessing
https://api.paypal.com/v1/payments/payment/..
.
This error only appears when I which to live, it works completely fine on sandbox mode.
On the client side I'm using checkout.js and redirecting it to the PHP file where I'm trying to use the the PayPal-PHP-SDK to execute the payment and I get the error where the code reads:
$result = $payment->execute($execution, $apiContext);
Below is a sample code I am using
JavaScript
paypal.Button.render({
env: 'production',
client: {
sandbox: 'sandbox_id',
production: 'production_id'
locale: 'en_US',
style: {
color: 'blue',
size: 'responsive',
commit: true,
payment: function (data, actions) {
return actions.payment.create({
payment: {
redirect_urls: {
return_url: site_url + '/execute-payment'
transactions: [{
amount: {
total: '0.01',
currency: 'NZD',
details: {
subtotal: '0.01',
shipping: '0.00',
tax: '0.00',
insurance: '0.00'
description: "TEST",
invoice_number: json.invoice_number ? json.invoice_number : "",
item_list: {
items: items_ ? items_ : "",
shipping_address: {
"recipient_name": json.recipient_name ? json.recipient_name : "",
"line1": json.line1 ? json.line1 : "",
"line2": json.line2 ? json.line2 : "",
"city": json.city ? json.city : "",
"country_code": json.country_code ? json.country_code : "",
"postal_code": json.postal_code ? json.postal_code : "",
"phone": json.phone ? json.phone : "",
"state": json.state ? json.state : ""
"note_to_payer": "Contact us for any questions on your order.",
onAuthorize: function (data, actions) {
console.log('::Authorized: ');
return actions.redirect();
onCancel: function (data, actions) {
console.log('::Canceled: ');
/* window.location = "/paypal/cancel/"; */
onError: function (error) {
console.log('::Error: ', error)
}, '#paypal_container');
# live client id
$live_cid = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
# live secret id
$live_sid = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$live_cid,
$live_sid
$apiContext->setConfig(
array(
'log.LogEnabled' => true,
'log.FileName' => 'PayPal.log',
'log.LogLevel' => 'DEBUG',
'mode' => 'live'
# die(var_dump($apiContext));
# redirect here via link: https://example.com/execute-payment/?paymentId=xxxxxxxxxxxxxxxxxxxxxxxxxxxx&token=xxxxxxxxxxxxxxxxxx&PayerID=xxxxxxxxxxxxxx
# die(var_dump("<br><br>" . "paymentId: " . $_GET['paymentId'] . "<br>" . "PayerID: " . $_GET['PayerID']));
$paymentId = $_GET['paymentId'];
$payment = Payment::get($paymentId, $apiContext);
$execution = new PaymentExecution();
$execution->setPayerId($_GET['PayerID']);
$transaction = new Transaction();
$amount = new Amount();
$details = new Details();
$details->setShipping(0.00)
->setTax(0.00)
->setSubtotal(0.01);
$amount->setCurrency('NZD');
$amount->setTotal(0.01);
$amount->setDetails($details);
$transaction->setAmount($amount);
$execution->addTransaction($transaction);
$result = $payment->execute($execution, $apiContext);
# I get the error after trying to execute the payment
$paymentId = $result->id;
$PayerID = $result->payer->payer_info->payer_id;
die(var_dump($result));
Error
Fatal error: Uncaught PayPal\Exception\PayPalConnectionException: Got Http response code 400 when accessing https://api.paypal.com/v1/payments/payment/xxxxxxxxxxxxxxxxxxxxxxxxxx/execute. in /mnt/stor10-wc1-ord1/825767/984521/www.example.com/web/content/newww/wp-content/themes/example/framework/paypal/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php:207 Stack trace: #0 /mnt/stor10-wc1-ord1/825767/984521/www.example.com/web/content/newww/wp-content/themes/example/framework/paypal/vendor/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php(78): PayPal\Core\PayPalHttpConnection->execute('{"payer_id":"66...') #1 /mnt/stor10-wc1-ord1/825767/984521/www.example.com/web/content/newww/wp-content/themes/example/framework/paypal/vendor/paypal/rest-api-sdk-php/lib/PayPal/Common/PayPalResourceModel.php(104): PayPal\Transport\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"payer_id":"66...', Array) #2 /mnt/stor10-wc1-ord1/825767/984521/www.example.com in /mnt/stor10-wc1-ord1/825767/984521/www.example.com/web/content/newww/wp-content/themes/example/framework/paypal/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php on line 207
The above code is part of an old code that was on the website, I'm just trying to make it work. It was working fine until we changed the Client and Secret ID. The payment is being created fine but the issue comes when I execute the payment
PayPal.log
[05-08-2020 08:51:12] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.paypal.com/v1/oauth2/token
[05-08-2020 08:51:13] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 200
[05-08-2020 08:51:13] PayPal\Core\PayPalHttpConnection : INFO: GET https://api.paypal.com/v1/payments/payment/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[05-08-2020 08:51:14] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 200
[05-08-2020 08:51:14] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.paypal.com/v1/payments/payment/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/execute
[05-08-2020 08:51:14] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 404
[05-08-2020 08:51:14] PayPal\Core\PayPalHttpConnection : ERROR: Got Http response code 404 when accessing https://api.paypal.com/v1/payments/payment/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/execute. {"name":"INVALID_RESOURCE_ID","message":"Requested resource ID was not found.","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"acba76cd232a5"}
[05-08-2020 08:55:31] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.paypal.com/v1/oauth2/token
[05-08-2020 08:55:33] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 200
[05-08-2020 08:55:34] PayPal\Core\PayPalHttpConnection : INFO: GET https://api.paypal.com/v1/payments/payment/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[05-08-2020 08:55:36] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 200
[05-08-2020 08:55:40] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.paypal.com/v1/payments/payment/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/execute
[05-08-2020 08:55:42] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 404
[05-08-2020 08:55:42] PayPal\Core\PayPalHttpConnection : ERROR: Got Http response code 404 when accessing https://api.paypal.com/v1/payments/payment/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/execute. {"name":"INVALID_RESOURCE_ID","message":"Requested resource ID was not found.","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"3c22c723fa27a"}
I'm definitely doing something wrong with this.
Hard to guess at what precisely is wrong with the execute call without seeing the full API response body and headers, including a PayPal-Debug-ID
400 errors are usually a wrong credential problem, or credentials paired with the wrong environment, but that is less likely if your payment creation and oauth2 calls are working okay
The more important question is why are you using an deprecated V1 SDK, at all, which is no longer maintained? You should completely change your integration to the current V2 PHP SDK, documented here: https://developer.paypal.com/docs/api/rest-sdks/
The current best front-end experience to pair it with is https://developer.paypal.com/demo/checkout/#/pattern/server
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.