Handle funding failures

DocsCurrentLast updated: March 16th 2023, @ 11:23:55 am

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

This feature modifies an existing checkout integration and uses the following:

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:

  onApprove: function (data, actions) {
    return fetch('/my-server/capture-paypal-transaction', {
      headers: {
        'content-type': 'application/json'
      body: JSON.stringify({
        orderID: data.orderID
    }).then(function(res) {
      return res.json();
    }).then(function(captureData) {
      if (captureData.error === 'INSTRUMENT_DECLINED'); // Your server response structure and key names are what you choose
        return actions.restart();