Handle funding failures
Last updated: Feb 28th, 7:42pm
If your payer's funding source fails, the Orders API returns an INSTRUMENT_DECLINED
error. A funding source might fail for the following reasons:
- The billing address associated with the payment method is incorrect.
- The transaction exceeds the card limit.
- The card issuer denied the transaction.
To handle this error, restart the payment so the payer can select a different payment option.
Know before you code
PayPal Checkout
Complete the steps in Get started to get your sandbox account login information and access token from the Developer Dashboard.
This feature modifies an existing PayPal Checkout integration and uses the following:
- PayPal JavaScript SDK
- Orders REST API - Create order endpoint
Explore PayPal APIs with Postman
You can use Postman to explore and test PayPal APIs. Learn more in our Postman guide.
Restart the payment
Restarting the payment is required if you directly call the Orders API from your server. If you use actions.order.capture()
, the script automatically restarts the checkout flow and prompts the payer to select a different funding source.
Restart the payment in the onApprove
function as follows:
1paypal.Buttons({2 onApprove: function (data, actions) {3 return fetch('/my-server/capture-paypal-transaction', {4 headers: {5 'content-type': 'application/json'6 },7 body: JSON.stringify({8 orderID: data.orderID9 })10 }).then(function(res) {11 return res.json();12 }).then(function(captureData) {13 if (captureData.error === 'INSTRUMENT_DECLINED'); // Your server response structure and key names are what you choose14 return actions.restart();15 }16 });17 }18}).render('#paypal-button-container');