# Pay By Bank with Components

Source: https://docs.gocardless.com/docs/collect-payments/integration-types/gocardless-components/billing-requests/pay-by-bank

# Pay By Bank with Components

**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](/docs/collect-payments/one-off-payments/pay-by-bank).

With Components, Pay By Bank is available in **GBP via Faster Payments**. For other schemes, use [Hosted Pages](/docs/collect-payments/integration-types/gocardless-hosted-pages) or [Custom Payment Pages](/docs/collect-payments/integration-types/custom-payment-pages) instead.

Unlike [setting up mandates](/docs/collect-payments/integration-types/gocardless-components/billing-requests/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](/images/docs/collect-payments/integration-types/gocardless-components/pbb_flow.gif)

## 1. Before you start

Complete the [general setup](/docs/collect-payments/integration-types/gocardless-components#1-setup) (access token and session token endpoint) and [add and configure the library](/docs/collect-payments/integration-types/gocardless-components#2-implementation).

## 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`:

```http
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:

| Property      | Description                                                                                                         | Required |
| ------------- | ------------------------------------------------------------------------------------------------------------------- | -------- |
| `description` | A human-readable description of the payment, displayed to the payer when they authorise it                          | No       |
| `amount`      | The amount in pence                                                                                                 | Yes      |
| `currency`    | [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency code. `GBP` is the only supported currency | Yes      |
| `scheme`      | The scheme used for the payment. `faster_payments` is the only supported scheme                                     | Yes      |

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](/docs/collect-payments/one-off-payments/pay-by-bank#create-a-billing-request).

### 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:

```json
{
  "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](/docs/optimise/retain-customers-with-fallbacks) for details, including when not to use it.

![Direct Debit fallback](/images/docs/collect-payments/integration-types/gocardless-components/fallback_to_dd_1.png)

## 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](/docs/collect-payments/integration-types/gocardless-components#12-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](#2-create-a-billing-request):

```json
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](#2-create-a-billing-request) as `billingRequestId`:

```html
<div id="gc-billing"></div>
```

```javascript
const brComponent = gc.createComponent("billing-request", {
  billingRequestId: "BRQ0000302",
  onError: (error) => console.error("Error: ", error),
});

brComponent.mount("#gc-billing");
```

| Property         | Description                                                                          | Required |
| ---------------- | ------------------------------------------------------------------------------------ | -------- |
| billingRequestId | The `id` of the billing request you created in [step 2](#2-create-a-billing-request) | Yes      |
| onError          | `(error: GoCardlessError) => void` — called on error, in addition to the event bus   | No       |

See [all Billing Request options](/docs/collect-payments/integration-types/gocardless-components/billing-requests#2-options).

![Pay By Bank component](/images/docs/collect-payments/integration-types/gocardless-components/preview_1.png)

## 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](/images/docs/collect-payments/integration-types/gocardless-components/success_1.png)

## 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 sees                  | Cause                                                 | What the payer can do                                            |
| ------------------------------------ | ----------------------------------------------------- | ---------------------------------------------------------------- |
| Bank connection unsuccessful         | A problem connecting to their bank                    | Try again, or pay with Direct Debit if `fallback_enabled` is set |
| Your account has insufficient funds  | The account doesn't have enough money for the payment | Add funds and try again, or select a different bank              |
| Your payment could not be authorised | The payer rejected the authorisation at their bank    | Try again, or use a different bank account                       |
| Your bank authorisation has expired  | The payer didn't authorise in time                    | Try 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](/docs/collect-payments/integration-types/gocardless-components#5-handling-errors-and-events) for the error shape.

### Billing request errors

These are reported to `onError` with the type `config_validation`:

| Message                                                      | Cause                                                                               |
| ------------------------------------------------------------ | ----------------------------------------------------------------------------------- |
| Billing requests with auto_fulfil disabled are not supported | The billing request was created with `auto_fulfil` set to `false`                   |
| Scheme not supported                                         | The billing request's scheme isn't available to the component for your organisation |

## What's next?

  
#### [Setting up mandates](/docs/collect-payments/integration-types/gocardless-components/billing-requests/mandates)

Set up Bacs and Sepa Direct Debit mandates.

  
#### [Remember Me Components](/docs/collect-payments/integration-types/gocardless-components/remember-me)

Recognise returning payers and save new payers' details for faster checkout.

  
#### [Components for Partners](/docs/collect-payments/integration-types/gocardless-components/partners)

Mint session tokens per merchant when you integrate Components on behalf of others.