What You'll Need | Initialise FlexPay Widget | Show Finance Offers | Eligibility Check | Start Checkout | Complete Checkout | Confirm Payment

8. Complete Checkout

Following successful checkout (applying for and using the selected FlexPay finance offer to complete a purchase), the FlexPay Widget checkout method resolves with a receipt object, whereas if checkout is unsuccessful (the application for finance is rejected or cancelled and the purchase is declined) then the checkout method fails.

To capture both successful and unsuccessful checkout scenarios from the FlexPay Widget, please follow the Javascript example shown below. Platforms are also encouraged to implement a separate callback handler via which we can confirm to you privately and asynchronously of the outcome of a transaction, including to confirm payment.

const receipt = widget.checkout(cac)
    .then((receipt) => {
      // See the decoded receipt JWT example in the next window 
      console.log(‘SUCCESS ====’, receipt);
      
      // This will happen only on a payment success
      return receipt;
    })
    .catch((e) => {
      console.log(‘FAILURE ====’, e.message);
      alert(`FAILURE - ${e.message}`);
      // This will happen when either the customer does not meet credit lending qualification or their deposit payment card has been declined
    });

Purchase Receipt

The receipt received from a successful checkout is a JWT detailing the order and proving that it was sent from FlexPay.

{
  "scope": "application:create",
  "https://flexpayapi.blackhorseflexpay.co.uk/application": {
    "status": "success", // the status of the application, not to be confused with the order
    "product": "blackhorse-flexpay", // the product (in this case FlexPay)
    "links": [
      {
        "href": "https://flexpayapi.blackhorseflexpay.co.uk/checkout/blackhorse-flexpay/87463d12-9831-3267-a108-d4613efa370c",
        "rel": "self"
      }
    ],
    "last_updated": "1642167702440",
    "application_id": "87463d12-9831-3267-a108-d4613efa370c", // the flexpay unique identifier for the order
    "transaction_id": "e917ecf1-00ed-46a9-8867-cbaf53dfef1d", // the merchant unique reference
  },
  "iat": 1642167703,
  "exp": 1643967703,
  "aud": "https://flexpayapi.blackhorseflexpay.co.uk",
  "iss": "https://flexpayapi.blackhorseflexpay.co.uk/",
  "sub": "b0151983-1ddb-4d89-8cc8-17f708da5606",
  "jti": "bf011cc8-f226-4376-9d55-ec94619818a1"
}

You can use the receipt information to then confirm the order status securely via API, by invoking the transaction endpoint detailed below. You will also be able to do this as a result of our private callback (see Confirm Payment) whenever the transaction status is updated.

curl -X 'GET' \
  'https://dummy-api.staging.host.com/transaction/e917ecf1-00ed-46a9-8867-cbaf53dfef1d' \
  -H 'accept: application/hal+json' \
  -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Imp6SXZmaU1HNkJqVEpUWGxkRlVwZSJ9.eyJpc3MiOiJodHRwczovL2Rla29wYXktbWVyY2hhbnQtZGV2LmV1LmF1dGgwLmNvbS8iLCJzdWIiOiJ2TDBac0VOOWo1TlQ0VlAzY0ZLQnAxakY5NHNtNUM4dkBjbGllbnRzIiwiYXVkIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgxL2FwaS9jaGVja291dCIsImlhdCI6MTYxNjU5MTU4NywiZXhwIjoxNjE2Njc3OTg3LCJhenAiOiJ2TDBac0VOOWo1TlQ0VlAzY0ZLQnAxakY5NHNtNUM4diIsImd0eSI6ImNsaWVudC1jcmVkZW50aWFscyJ9.F-dzPkJVF0ub2kGiWn1As5PSMnIiqAriOhyux47t7lbNk0tD9Wu655JGHmjuAqqQ3uWyqXx9-feuYjv61xufgBfxH17OkIqBB9lVJzEONoVqF5uIzsnaTD2z0FTzcvOuH8RXzA-_q7vFZwvbboE9iZCFd-JN8vI_1jjWDUpdKFWzGk0-AmID9F7qgNnyC2WEb6DK4Ky5VttXPXcGfnIGD2ybOgkg1dOlBhzabJBT9jU_UQuBoKjqQoNqVm1ovhFJzzSWMsHqDIDOb7r-0zXRB33ka4_oKoVnVrvxL2hGblgC-2Jg6gfB7uuVPdbM5FIBFx8Cbt4T83KxXbpJy5hQbg'