Save Bacs Direct Debit bank details
Learn how to use Checkout to save payment method details for future Bacs Direct Debit payments.
Use Stripe Checkout to collect Bacs Direct Debit payment details in advance, with the final amount or payment date determined later. This is useful for:
- Saving payment methods to a wallet to streamline future purchases.
- Collecting surcharges after fulfilling a service.
- Starting a free trial for a subscription.
Set up StripeServer-side
First, you need a Stripe account. Register now.
Use our official libraries for access to the Stripe API from your application:
Create a CustomerServer-side
To reuse a Bacs Direct Debit payment method for future payments, you must attach it to a Customer. Create a Customer object when someone creates an account with you and associate the ID of the Customer object with your own internal representation of a customer so you can use the stored payment method details later. If you have an existing Customer object, skip this step.
Create a Checkout SessionClient-sideServer-side
Before you can accept Direct Debit payments, your customer must provide their bank account information and give permission to debit their account (also known as a mandate) through Stripe Checkout.
Add a checkout button to your website that calls a server-side endpoint to create a Checkout Session.
<html> <head> <title>Checkout</title> </head> <body> <form action="/create-checkout-session" method="POST"> <button type="submit">Checkout</button> </form> </body> </html>
Create a Checkout Session in setup
mode to collect the required information. After creating the Checkout Session, redirect your customer to the URL returned in the response.
When your customer provides their payment method details, they’re redirected to the success_
, a page on your website that informs them that their payment method was saved successfully. Make the Session ID available on your success page by including the {CHECKOUT_
template variable in the success_
as in the above example.
When your customer clicks on your logo in a Checkout Session without providing their payment method details, Checkout redirects them back to your website by navigating to the cancel_
. This is usually the page on your website that the customer viewed prior to redirecting to Stripe Checkout.
Caution
Don’t rely on the redirect to the success_
alone for detecting payment initiation, as:
- Malicious users could directly access the
success_
without paying and gain access to your goods or services.url - Customers may not always reach the
success_
after a successful payment—they might close their browser tab before the redirect occurs.url
Note
The Bacs Direct Debit rules require that customers are sent an email notification when payment details are collected. By default, these emails are sent automatically by Stripe. You can also opt to send your own Bacs notifications.
Retrieve the payment methodServer-side
After a customer submits their payment details, retrieve the PaymentMethod object. A PaymentMethod stores the customer’s bank account information for future payments. You can retrieve the PaymentMethod synchronously using the success_
or asynchronously using webhooks.
The decision to retrieve the PaymentMethod synchronously or asynchronously depends on your tolerance for dropoff, as customers might not always reach the success_
after a successful payment (for example, it’s possible for them to close their browser tab before the redirect occurs). Using webhooks prevents your integration from experiencing this form of dropoff.
Handle post-setup eventsServer-side
Once the Checkout Session completes, payment details are submitted to the bank as a mandate.
The mandate can change at any time after you’ve collected it. This might be the result of the customer instructing their bank to amend the mandate or because of a change in the bank itself (for example, the customer changes to a different one). Stripe sends the following events when the mandate changes:
Event name | Description | Can accept payments? |
---|---|---|
mandate. | Occurs whenever a mandate is rejected, cancelled, or reactivated by the Bacs network. Check mandate.status to determine if the mandate can continue to be used. | Yes, if the new status is active |
payment_ | Occurs when a customer’s bank account details change. | Yes |
These events are available in the Dashboard, but you can set up a webhook to handle these programatically.
Test the integration
There are several test bank account numbers you can use in test mode to make sure this integration is ready.
Sort code | Account number | Description |
---|---|---|
108800 | 00012345 | The payment succeeds and the PaymentIntent transitions from processing to succeeded . |
108800 | 90012345 | The payment succeeds after three minutes and the PaymentIntent transitions from processing to succeeded . |
108800 | 33333335 | The payment is accepted but then immediately fails with a debit_ failure code and the PaymentIntent transitions from processing to requires_ . The Mandate becomes inactive and the PaymentMethod can not be used again. |
108800 | 93333335 | The payment fails after three minutes with a debit_ failure code and the PaymentIntent transitions from processing to requires_ . The Mandate becomes inactive and the PaymentMethod can not be used again. |
108800 | 22222227 | The payment fails with an insufficient_ failure code and the PaymentIntent transitions from processing to requires_ . The Mandate remains active and the PaymentMethod can be used again. |
108800 | 92222227 | The payment fails after three minutes with an insufficient_ failure code and the PaymentIntent transitions from processing to requires_ . The Mandate remains active and the PaymentMethod can be used again. |
108800 | 55555559 | The payment succeeds after three minutes and the PaymentIntent transitions from processing to succeeded , but a dispute is immediately created. |
108800 | 00033333 | Payment Method creation succeeds, but the Mandate is refused by the customer’s bank and immediately transitions to inactive. |
108800 | 00044444 | The request to set up Bacs Direct Debit fails immediately due to an invalid account number and the customer is prompted to update their information before submitting. Payment details are not collected. |
108800 | 34343434 | The payment fails with a charge_ failure code due to the payment amount causing the account to exceed its weekly payment volume limit. |
108800 | 12121212 | The payment fails with a charge_ failure code due to the payment amount exceeding the account’s transaction volume limit. |
You can test using any of the account numbers provided above. However, because Bacs Direct Debit payments take several days to process, use the test account numbers that operate on a three-minute delay to better simulate the behavior of live payments.
Note
By default, Stripe automatically sends emails to the customer when payment details are initially collected and each time a debit will be made on their account. These notifications aren’t sent in test mode.
Use the payment method for future paymentsServer-side
After you set up a PaymentMethod, you can accept future Bacs Direct Debit payments by creating and confirming a PaymentIntent.