GoCardlessDeveloper Docs
Create a sandbox account

Pay By Bank with Components#

View as Markdown

Pay By Bank lets you collect a one-off payment directly from your customer's bank account with confirmation within minutes. Unlike Direct Debit, there's no mandate: the customer authorises each payment individually via their banking app. Learn more about Pay By Bank.

With Components, Pay By Bank is available in GBP via Faster Payments. For other schemes, use Hosted Pages or Custom Payment Pages instead.

Unlike setting up mandates, the payment definition is created on your server, so the flow has three steps:

  1. Create a Billing Request with a payment_request
  2. Mint a session token linked to that Billing Request
  3. Mount the component with the Billing Request ID

Pay By Bank flow

1. Before you start#

Complete the general setup (access token and session token endpoint) and add and configure the library.

2. Create a Billing Request#

Create the billing request on your server before the checkout loads, because it carries the payment the customer is going to authorise. Use your access token to create a billing request with a payment_request:

POST /billing_requests
Authorization: Bearer YOUR_ACCESS_TOKEN
 
{
  "billing_requests": {
    "payment_request": {
      "description": "Order #9012",
      "amount": 12000,
      "currency": "GBP",
      "scheme": "faster_payments"
    }
  }
}

The payment_request accepts the following properties:

PropertyDescriptionRequired
descriptionA human-readable description of the payment, displayed to the payer when they authorise itNo
amountThe amount in penceYes
currencyISO 4217 currency code. GBP is the only supported currencyYes
schemeThe scheme used for the payment. faster_payments is the only supported schemeYes

The response contains the billing request id (e.g. BRQ0000302) in pending status. You need it in the next two steps.

For the response and examples in other languages, see Pay By Bank.

Direct Debit fallback#

To let customers who can't use Pay By Bank set up a Direct Debit instead, also set "fallback_enabled": true on the billing request:

{
  "billing_requests": {
    "payment_request": {
      "description": "Order #9012",
      "amount": 12000,
      "currency": "GBP",
      "scheme": "faster_payments"
    },
    "fallback_enabled": true
  }
}

The Direct Debit option is only shown if the customer can't find their bank, or if authorising through their bank fails. A billing request can fall back only once. See Retain customers with Fallbacks for details, including when not to use it.

Direct Debit fallback

3. Mint a session token linked to the Billing Request#

Mint the session token as described in Setting up an endpoint to mint session tokens, and set links.billing_request to the id of the billing request you created in step 2:

POST /session_tokens
Authorization: Bearer YOUR_ACCESS_TOKEN
 
{
    "session_tokens": {
        "policies": [
            "ui_components"
        ],
        "links": {
            "billing_request": "BRQ0000302"
        }
    }
}

The session token can then only act on that billing request. The billing request must belong to the same organisation as the access token and be in pending status. Otherwise the request fails, with a 404 if the billing request isn't found and an error if it isn't pending.

When a session token expires, the library calls your sessionToken callback again to mint a new one. Your endpoint must link the same billing request every time it mints a token.

4. Mount the component#

Pass the id of the billing request you created in step 2 as billingRequestId:

<div id="gc-billing"></div>
const brComponent = gc.createComponent("billing-request", {
  billingRequestId: "BRQ0000302",
  onError: (error) => console.error("Error: ", error),
});
 
brComponent.mount("#gc-billing");
PropertyDescriptionRequired
billingRequestIdThe id of the billing request you created in step 2Yes
onError(error: GoCardlessError) => void — called on error, in addition to the event busNo

See all Billing Request options.

Pay By Bank component

5. Testing#

We recommend testing your checkout end to end before going live. Check that you reach the confirmation screen without errors, then confirm the payment was created in the GoCardless dashboard or through the API.

Payment authorised

6. Common errors#

Payment authorisation failures#

When authorising with the bank fails in a way the payer can act on, the component shows them one of these screens:

What the payer seesCauseWhat the payer can do
Bank connection unsuccessfulA problem connecting to their bankTry again, or pay with Direct Debit if fallback_enabled is set
Your account has insufficient fundsThe account doesn't have enough money for the paymentAdd funds and try again, or select a different bank
Your payment could not be authorisedThe payer rejected the authorisation at their bankTry again, or use a different bank account
Your bank authorisation has expiredThe payer didn't authorise in timeTry again

Each failure is also reported to your onError callback as a recoverable error: timeout_error for an expired authorisation, api_error for the others. See Handling errors and events for the error shape.

Billing request errors#

These are reported to onError with the type config_validation:

MessageCause
Billing requests with auto_fulfil disabled are not supportedThe billing request was created with auto_fulfil set to false
Scheme not supportedThe billing request's scheme isn't available to the component for your organisation

What's next?#