title: Got Http response code 400 when accessing https://api.paypal.com/v1/payments/payment/
body: <p>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:</p>
  <blockquote>
  <p>Got Http response code 400 when accessing <a href="https://api.paypal.com/v1/payments/payment/.." rel="nofollow noreferrer">https://api.paypal.com/v1/payments/payment/..</a>.</p>
  </blockquote>
  <p>This error only appears when I which to live, it works completely fine on sandbox mode.</p>
  <p>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:</p>
  <pre><code>$result = $payment-&gt;execute($execution, $apiContext);
  </code></pre>
  <p>Below is a <strong>sample code</strong> I am using</p>
  <p><strong>JavaScript</strong></p>
  <pre><code>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: &quot;TEST&quot;,
                  invoice_number: json.invoice_number ? json.invoice_number : &quot;&quot;,
                  item_list: {
                      items: items_ ? items_ : &quot;&quot;,
                      shipping_address: {
                          &quot;recipient_name&quot;: json.recipient_name ? json.recipient_name : &quot;&quot;,
                          &quot;line1&quot;: json.line1 ? json.line1 : &quot;&quot;,
                          &quot;line2&quot;: json.line2 ? json.line2 : &quot;&quot;,
                          &quot;city&quot;: json.city ? json.city : &quot;&quot;,
                          &quot;country_code&quot;: json.country_code ? json.country_code : &quot;&quot;,
                          &quot;postal_code&quot;: json.postal_code ? json.postal_code : &quot;&quot;,
                          &quot;phone&quot;: json.phone ? json.phone : &quot;&quot;,
                          &quot;state&quot;: json.state ? json.state : &quot;&quot;
                      }
                  }
              }],
              &quot;note_to_payer&quot;: &quot;Contact us for any questions on your order.&quot;,
          }
      });
  },
  
  onAuthorize: function (data, actions) {
  
      console.log('::Authorized: ');
  
      return actions.redirect();
  
  },
  
  onCancel: function (data, actions) {
      
      console.log('::Canceled: ');
  
      /* window.location = &quot;/paypal/cancel/&quot;; */
  
  },
  
  onError: function (error) {
  
      console.log('::Error: ', error)
  
  }
  }, '#paypal_container');
  </code></pre>
  <p><strong>PHP</strong></p>
  <pre><code># 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-&gt;setConfig(
      array(
          'log.LogEnabled' =&gt; true,
          'log.FileName' =&gt; 'PayPal.log',
          'log.LogLevel' =&gt; 'DEBUG',
          'mode' =&gt; 'live'
      )
  );
  
  # die(var_dump($apiContext));
  
  # redirect here via link: https://example.com/execute-payment/?paymentId=xxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;token=xxxxxxxxxxxxxxxxxx&amp;PayerID=xxxxxxxxxxxxxx
  # die(var_dump(&quot;&lt;br&gt;&lt;br&gt;&quot; . &quot;paymentId: &quot; . $_GET['paymentId'] . &quot;&lt;br&gt;&quot; . &quot;PayerID: &quot; . $_GET['PayerID']));
  
  $paymentId = $_GET['paymentId'];
  $payment = Payment::get($paymentId, $apiContext);
  
  $execution = new PaymentExecution();
  $execution-&gt;setPayerId($_GET['PayerID']);
  
  $transaction = new Transaction();
  $amount = new Amount();
  $details = new Details();
  
  $details-&gt;setShipping(0.00)
          -&gt;setTax(0.00)
          -&gt;setSubtotal(0.01);
  
  $amount-&gt;setCurrency('NZD');
  $amount-&gt;setTotal(0.01);
  $amount-&gt;setDetails($details);
  $transaction-&gt;setAmount($amount);
  
  $execution-&gt;addTransaction($transaction);
  
  $result = $payment-&gt;execute($execution, $apiContext);
  
  # I get the error after trying to execute the payment
  
  $paymentId = $result-&gt;id;
  $PayerID = $result-&gt;payer-&gt;payer_info-&gt;payer_id;
  
  die(var_dump($result));
  </code></pre>
  <p><strong>Error</strong></p>
  <blockquote>
  <p>Fatal error: Uncaught PayPal\Exception\PayPalConnectionException: Got Http response code 400 when accessing <a href="https://api.paypal.com/v1/payments/payment/xxxxxxxxxxxxxxxxxxxxxxxxxx/execute" rel="nofollow noreferrer">https://api.paypal.com/v1/payments/payment/xxxxxxxxxxxxxxxxxxxxxxxxxx/execute</a>. 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-&gt;execute('{&quot;payer_id&quot;:&quot;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-&gt;execute(Array, '/v1/payments/pa...', 'POST', '{&quot;payer_id&quot;:&quot;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</p>
  </blockquote>
  <p>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</p>
  <p><strong>PayPal.log</strong></p>
  <pre><code>[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. {&quot;name&quot;:&quot;INVALID_RESOURCE_ID&quot;,&quot;message&quot;:&quot;Requested resource ID was not found.&quot;,&quot;information_link&quot;:&quot;https://developer.paypal.com/docs/api/payments/#errors&quot;,&quot;debug_id&quot;:&quot;acba76cd232a5&quot;}
  
  
  [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. {&quot;name&quot;:&quot;INVALID_RESOURCE_ID&quot;,&quot;message&quot;:&quot;Requested resource ID was not found.&quot;,&quot;information_link&quot;:&quot;https://developer.paypal.com/docs/api/payments/#errors&quot;,&quot;debug_id&quot;:&quot;3c22c723fa27a&quot;}
  </code></pre>
  <p>I'm definitely doing something wrong with this.</p>