Payments
Bank debits and transfers
BECS Direct Debit in Australia
Save bank details

Save BECS Direct Debit details for future payments

Use the Setup Intents API to save payment method details for future BECS Direct Debit payments.

Use Stripe Elements, our prebuilt UI components, to create a payment form that lets you securely collect a customer’s bank details without handling the sensitive data. You can use the Setup Intents API to collect BECS Direct Debit payment method details in advance, with the final amount or payment date determined later. This is useful for:

1 Set up Stripe Server-side

First, you need a Stripe account. Register now.

Use our official libraries for access to the Stripe API from your application:

# Available as a gem gem install stripe
# If you use bundler, you can add this line to your Gemfile gem 'stripe'
# Install through pip pip install --upgrade stripe
# Or find the Stripe package on http://pypi.python.org/pypi/stripe/
# Find the version you want to pin: # https://github.com/stripe/stripe-python/blob/master/CHANGELOG.md # Specify that version in your requirements.txt file stripe>=2.48.0,<3.0
# Install the PHP library via Composer composer require stripe/stripe-php
# Or download the source directly: https://github.com/stripe/stripe-php/releases
/* For Gradle, add the following dependency to your build.gradle and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest */ implementation "com.stripe:stripe-java:{VERSION}"
<!-- For Maven, add the following dependency to your POM and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest --> <dependency> <groupId>com.stripe</groupId> <artifactId>stripe-java</artifactId> <version>{VERSION}</version> </dependency>
# For other environments, manually install the following JARs: # - The Stripe JAR from https://github.com/stripe/stripe-java/releases/latest # - Google Gson from https://github.com/google/gson
# Install via npm npm install --save stripe
# Make sure your project is using Go Modules god mod init # Install stripe-go go get -u github.com/stripe/stripe-go/v71
// Then import the package import ( "github.com/stripe/stripe-go/v71" )
# Install via dotnet dotnet add package Stripe.net dotnet restore
# Or install via NuGet PM> Install-Package Stripe.net

2 Create or retrieve a Customer Server-side

To reuse a BECS Direct Debit account for future payments, it must be attached to a Customer.

You should create a Customer object when your customer creates an account with your business. Associating the ID of the Customer object with your own internal representation of a customer will enable you to retrieve and use the stored payment method details later. If your customer is making a payment as a guest, you can still create a Customer object before payment and associate it with your internal representation of the customer’s account later.

Create a new Customer or retrieve an existing Customer to associate with this payment. Include the following code on your server to create a new Customer.

curl https://api.stripe.com/v1/customers \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -X POST
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' customer = Stripe::Customer.create
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' customer = stripe.Customer.create()
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $customer = \Stripe\Customer::create();
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; CustomerCreateParams params = CustomerCreateParams.builder() .build(); Customer customer = Customer.create(params);
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const customer = await stripe.customers.create();
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.CustomerParams{} c, _ := customer.New(params)
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new CustomerCreateOptions{}; var service = new CustomerService(); var customer = service.Create(options);

3 Create a SetupIntent Server-side

A SetupIntent is an object that represents your intent to set up a customer’s payment method for future payments. The SetupIntent will track the steps of this set-up process. For BECS Direct Debit, this includes collecting a mandate from the customer and tracking its validity throughout its lifecycle.

Create a SetupIntent on your server with payment_method_types set to au_becs_debit and specify the Customer’s id:

curl https://api.stripe.com/v1/setup_intents \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d "payment_method_types[]"=au_becs_debit \ -d customer="{{CUSTOMER_ID}}"
require 'sinatra' require 'json' require 'stripe' # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' get '/wallet' do intent = Stripe::SetupIntent.create({ payment_method_types: ['au_becs_debit'], customer: customer['id'], }) client_secret = setup_intent['client_secret'] # Pass the client secret to the client end
import stripe import json from flask import Flask, request, render_template app = Flask(__name__, static_folder=".", static_url_path="", template_folder=".") # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' @app.route('/wallet') def wallet(): setup_intent = stripe.SetupIntent.create( payment_method_types=['au_becs_debit'], customer=customer['id'] ) client_secret = setup_intent.client_secret # Pass the client secret to the client if __name__ == '__main__': app.run()
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); # vendor using composer require_once('vendor/autoload.php'); $setup_intent = \Stripe\SetupIntent::create([ 'payment_method_types' => ['au_becs_debit'], 'customer' => $customer->id, ]); $client_secret = $setup_intent->client_secret // Pass the client secret to the client
import java.util.HashMap; import java.util.Map; import com.stripe.Stripe; import com.stripe.model.SetupIntent; public class StripeJavaQuickStart { public static void main(String[] args) { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; Map<String, Object> setupIntentParams = new HashMap<String, Object>(); ArrayList paymentMethodTypes = new ArrayList(); setupIntentParams.put("payment_method_types", Arrays.asList("au_becs_debit")); setupIntentParams.put("customer", customer.getId()); SetupIntent setupIntent = SetupIntent.create(setupIntentParams); String clientSecret = setupIntent.getClientSecret(); // Pass the client secret to the client } }
// Using Express const express = require('express'); const app = express(); app.use(express.json()); const { resolve } = require("path"); // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const setupIntent = await stripe.setupIntents.create({ payment_method_types: ['au_becs_debit'], customer: customer.id, }); const clientSecret = setupIntent.client_secret; // Pass the client secret to the client
package main import ( "encoding/json" "log" "net/http" "github.com/stripe/stripe-go/v71" "github.com/stripe/stripe-go/v71/setupintent" ) func main() { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" setupIntentParams := &stripe.SetupIntentParams{ PaymentMethodTypes: stripe.StringSlice([]string{ "au_becs_debit", }), Customer: stripe.String(customer.ID), } setupIntent, err := setupintent.New(setupIntentParams) clientSecret := setupIntent.ClientSecret // Pass the client secret to the client }
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; using System; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Stripe; namespace StripeExampleApi.Controllers { [Route("/wallet")] public class WalletController : Controller { public IActionResult Index() { var service = new SetupIntentService(); var options = new SetupIntentCreateOptions { PaymentMethodTypes = new List<string> { "au_becs_debit", }, Customer = "{{CUSTOMER_ID}}", }; SetupIntent intent = service.Create(options); var clientSecret = setupIntent.ClientSecret; // Pass the client secret to the client } } }

After creating a SetupIntent on your server, you can associate the SetupIntent ID with the current session’s customer in your application’s data model. Doing so allows you to retrieve the information after you have successfully collected a payment method.

The returned SetupIntent object contains a client_secret property. Pass the client secret to the client-side application to continue with the setup process.

4 Collect payment method details and mandate acknowledgment Client-side

You’re ready to collect payment information on the client with Stripe Elements. Elements is a set of prebuilt UI components for collecting payment details.

A Stripe Element contains an iframe that securely sends the payment information to Stripe over a HTTPS connection. The checkout page address must also start with https:// rather than http:// for your integration to work.

You can test your integration without using HTTPS. Enable it when you’re ready to accept live payments.

Set up Stripe Elements

Stripe Elements is automatically available as a feature of Stripe.js. Include the Stripe.js script on your payment page by adding it to the head of your HTML file. Always load Stripe.js directly from js.stripe.com to remain PCI compliant. Do not include the script in a bundle or host a copy of it yourself.

<head> <title>Payment Setup</title> <script src="https://js.stripe.com/v3/"></script> </head>

Create an instance of Elements with the following JavaScript on your payment page:

var stripe = Stripe('pk_test_TYooMQauvdEDq54NiTphI7jx'); var elements = stripe.elements();
const stripe = Stripe('pk_test_TYooMQauvdEDq54NiTphI7jx'); const elements = stripe.elements();

Direct Debit Requests

Before you can create a BECS Direct Debit payment, your customer must agree with the Direct Debit Request Service Agreement. They do so by submitting a completed Direct Debit Request (DDR). The approval gives you a mandate to debit their account. The Mandate is a record of the permission a customer has given you to debit their payment method corresponding to this Direct Debit Request.

For online mandate acceptance, you can create a form to collect the necessary information. The form should be served over HTTPS and capture the following information:

Information Description
Account name The full name of the account holder
BSB number The Bank-State-Branch number of the bank account (eg. 123-456)
Account number The bank account number (eg. 87654321)

When collecting a Direct Debit Request, you should follow our BECS Direct Debit Terms and as part of your checkout form:

  • Display the exact terms of Stripe’s DDR service agreement either inline on the form, or on a page linked from the form, and identifying it as the “DDR service agreement”
  • Ensure the accepted DDR and its accompanying DDR service agreement can be shared with your customer at all times, either as a printed or non-changeable electronic copy (such as via email). Stripe will host this for you
  • Display the following standard authorization text for your customer to accept the BECS DDR, where you replace Rocketship Inc with your company name. Their acceptance authorizes you to initiate BECS Direct Debit payments from their bank account.

The details of the accepted mandate are generated when setting up a PaymentMethod or confirming a PaymentIntent. At all times, you should be able to share this mandate—the accepted DDR and its accompanying DDR service agreement—with your customer, either in print or as a non-changeable electronic copy (such as via email). Stripe hosts this for you under the url property of the Mandate object linked to the PaymentMethod. You can review an example of how this looks.

Add and configure an Australia Bank Account Element

The Australia Bank Account Element will help you collect and validate both the BSB number and the account number. It needs a place to live in your payment form. Create empty DOM nodes (container) with unique IDs in your payment form. Additionally, your customer must read and accept the Direct Debit Request service agreement.

<form action="/setup" method="post" id="setup-form"> <div class="form-row inline"> <div class="col"> <label for="accountholder-name"> Name </label> <input id="accountholder-name" name="accountholder-name" placeholder="John Smith" required /> </div> <div class="col"> <label for="email"> Email Address </label> <input id="email" name="email" type="email" placeholder="john.smith@example.com" required /> </div> </div> <div class="form-row"> <!-- Using a label with a for attribute that matches the ID of the Element container enables the Element to automatically gain focus when the customer clicks on the label. --> <label for="au-bank-account-element"> Bank Account </label> <div id="au-bank-account-element"> <!-- A Stripe Element will be inserted here. --> </div> </div> <!-- Used to display bank (branch) name associated with the entered BSB --> <div id="bank-name"></div> <!-- Used to display form errors. --> <div id="error-message" role="alert"></div> <!-- Display mandate acceptance text. --> <div class="col" id="mandate-acceptance"> By providing your bank account details, you agree to this Direct Debit Request and the <a href="https://stripe.com/au-becs-dd-service-agreement/legal">Direct Debit Request service agreement</a>, and authorise Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf of Rocketship Inc. (the "Merchant") for any amounts separately communicated to you by the Merchant. You certify that you are either an account holder or an authorised signatory on the account listed above. </div> <!-- Add the client_secret from the SetupIntent as a data attribute --> <button id="submit-button" data-secret="{{CLIENT_SECRET}}">Set up BECS Direct Debit</button> </form>
/** * Shows how you can use CSS to style your Element's container. * These classes are added to your Stripe Element by default. * You can override these classNames by using the options passed * to the `iban` element. * https://stripe.com/docs/js/elements_object/create_element?type=iban#elements_create-options-classes */ input, .StripeElement { height: 40px; padding: 10px 12px; color: #32325d; background-color: white; border: 1px solid transparent; border-radius: 4px; box-shadow: 0 1px 3px 0 #e6ebf1; -webkit-transition: box-shadow 150ms ease; transition: box-shadow 150ms ease; } input:focus, .StripeElement--focus { box-shadow: 0 1px 3px 0 #cfd7df; } .StripeElement--invalid { border-color: #fa755a; } .StripeElement--webkit-autofill { background-color: #fefde5 !important; }

When the form loads, you can create an instance of the Australia Bank Account Element and mount it to the Element container:

// Custom styling can be passed to options when creating an Element var style = { base: { color: '#32325d', fontSize: '16px', '::placeholder': { color: '#aab7c4' }, ':-webkit-autofill': { color: '#32325d', }, }, invalid: { color: '#fa755a', iconColor: '#fa755a', ':-webkit-autofill': { color: '#fa755a', }, } }; var options = { style: style, disabled: false, hideIcon: false, iconStyle: "default", // or "solid" } // Create an instance of the auBankAccount Element. var auBankAccount = elements.create('auBankAccount', options); // Add an instance of the auBankAccount Element into // the `au-bank-account-element` <div>. auBankAccount.mount('#au-bank-account-element');
// Custom styling can be passed to options when creating an Element const style = { base: { color: '#32325d', fontSize: '16px', '::placeholder': { color: '#aab7c4' }, ':-webkit-autofill': { color: '#32325d', }, }, invalid: { color: '#fa755a', iconColor: '#fa755a', ':-webkit-autofill': { color: '#fa755a', }, } }; const options = { style: style, disabled: false, hideIcon: false, iconStyle: "default", // or "solid" } // Create an instance of the auBankAccount Element. const auBankAccount = elements.create('auBankAccount', options); // Add an instance of the auBankAccount Element into // the `au-bank-account-element` <div>. auBankAccount.mount('#au-bank-account-element');

Install React Stripe.js and the Stripe.js loader from the npm public registry.

npm install --save @stripe/react-stripe-js @stripe/stripe-js

We also provide a UMD build for sites that do not use npm or modules.

Include the Stripe.js script, which exports a global Stripe function, and the UMD build of React Stripe.js, which exports a global ReactStripe object. Always load the Stripe.js script directly from js.stripe.com to remain PCI compliant. Do not include the script in a bundle or host a copy of it yourself.

<!-- Stripe.js --> <script src="https://js.stripe.com/v3/"></script> <!-- React Stripe.js development build --> <script src="https://unpkg.com/@stripe/react-stripe-js@latest/dist/react-stripe.umd.js"></script> <!-- When you are ready to deploy your site to production, remove the above development script, and include the following production build. --> <script src="https://unpkg.com/@stripe/react-stripe-js@latest/dist/react-stripe.umd.min.js"></script>

Add Stripe.js and Elements to your page

To use Element components, wrap the root of your React app in an Elements provider. Call loadStripe with your publishable key and pass the returned Promise to the Elements provider.

import React from 'react'; import ReactDOM from 'react-dom'; import {Elements} from '@stripe/react-stripe-js'; import {loadStripe} from '@stripe/stripe-js'; import PaymentSetupForm from './PaymentSetupForm'; // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe("pk_test_TYooMQauvdEDq54NiTphI7jx"); function App() { return ( <Elements stripe={stripePromise}> <PaymentSetupForm /> </Elements> ); }; ReactDOM.render(<App />, document.getElementById('root'));

Direct Debit Requests

Before you can create a BECS Direct Debit payment, your customer must agree with the Direct Debit Request Service Agreement. They do so by submitting a completed Direct Debit Request (DDR). The approval gives you a mandate to debit their account. The Mandate is a record of the permission a customer has given you to debit their payment method corresponding to this Direct Debit Request.

For online mandate acceptance, you can create a form to collect the necessary information. The form should be served over HTTPS and capture the following information:

Information Description
Account name The full name of the account holder
BSB number The Bank-State-Branch number of the bank account (eg. 123-456)
Account number The bank account number (eg. 87654321)

When collecting a Direct Debit Request, you should follow our BECS Direct Debit Terms and as part of your checkout form:

  • Display the exact terms of Stripe’s DDR service agreement either inline on the form, or on a page linked from the form, and identifying it as the “DDR service agreement”
  • Ensure the accepted DDR and its accompanying DDR service agreement can be shared with your customer at all times, either as a printed or non-changeable electronic copy (such as via email). Stripe will host this for you
  • Display the following standard authorization text for your customer to accept the BECS DDR, where you replace Rocketship Inc with your company name. Their acceptance authorizes you to initiate BECS Direct Debit payments from their bank account.

The details of the accepted mandate are generated when setting up a PaymentMethod or confirming a PaymentIntent. At all times, you should be able to share this mandate—the accepted DDR and its accompanying DDR service agreement—with your customer, either in print or as a non-changeable electronic copy (such as via email). Stripe hosts this for you under the url property of the Mandate object linked to the PaymentMethod. You can review an example of how this looks.

Add and configure an AuBankAccountElement component

The AuBankAccountElement component will help you collect and validate both the BSB number and the account number. Additionally, your customer must read and accept the Direct Debit Request service agreement.

/** * Use the CSS tab above to style your Element's container. */ import React from 'react'; import {AuBankAccountElement} from '@stripe/react-stripe-js'; import './BecsFormStyles.css' // Custom styling can be passed as options when creating an Element. const AU_BANK_ACCOUNT_STYLE = { base: { color: '#32325d', fontSize: '16px', '::placeholder': { color: '#aab7c4' }, ':-webkit-autofill': { color: '#32325d', }, }, invalid: { color: '#fa755a', iconColor: '#fa755a', ':-webkit-autofill': { color: '#fa755a', }, } }; const AU_BANK_ACCOUNT_ELEMENT_OPTIONS = { style: AU_BANK_ACCOUNT_STYLE, disabled: false, hideIcon: false, iconStyle: "default", // or "solid" }; export default function BecsForm({onSubmit, disabled}) { return ( <form onSubmit={onSubmit}> <div className="form-row inline"> <div className="col"> <label> Name <input name="accountholder-name" placeholder="John Smith" required /> </label> </div> <div className="col"> <label> Email Address <input name="email" type="email" placeholder="john.smith@example.com" required /> </label> </div> </div> <div className="form-row"> <label> Bank Account <AuBankAccountElement options={AU_BANK_ACCOUNT_ELEMENT_OPTIONS} /> </label> </div> {/* Display mandate acceptance text. */} <div className="mandate-acceptance"> By providing your bank account details, you agree to this Direct Debit Request and the <a href="https://stripe.com/au-becs-dd-service-agreement/legal">Direct Debit Request service agreement</a>, and authorise Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf of Rocketship Inc. (the "Merchant") for any amounts separately communicated to you by the Merchant. You certify that you are either an account holder or an authorised signatory on the account listed above. </div> <button type="submit" disabled={disabled}>Set up BECS Direct Debit</button> </form> ); };
/** * Shows how you can use CSS to style your Element's container. * These classes are added to your Stripe Element by default. * You can override these classNames by using the options passed * to the IbanElement component. * https://stripe.com/docs/js/elements_object/create_element?type=iban#elements_create-options-classes */ input, .StripeElement { height: 40px; padding: 10px 12px; color: #32325d; background-color: white; border: 1px solid transparent; border-radius: 4px; box-shadow: 0 1px 3px 0 #e6ebf1; -webkit-transition: box-shadow 150ms ease; transition: box-shadow 150ms ease; } input:focus, .StripeElement--focus { box-shadow: 0 1px 3px 0 #cfd7df; } .StripeElement--invalid { border-color: #fa755a; } .StripeElement--webkit-autofill { background-color: #fefde5 !important; }

Elements are completely customizable. You can style Elements to match the look and feel of your site, providing a seamless checkout experience for your customers. It’s also possible to style various input states, for example when the Element has focus.

5 Submit the payment method details to Stripe Client-side

Rather than sending the entire SetupIntent object to the client, use its client secret from step 2. This is different from your API keys that authenticate Stripe API requests.

The client secret should still be handled carefully because it can complete the setup. Do not log it, embed it in URLs, or expose it to anyone but the customer.

Use stripe.confirmAuBecsDebitSetup to complete the setup when the user submits the form.

A successful setup will return a succeeded value for the SetupIntent’s status property. If the setup is not successful, inspect the returned error to determine the cause.

Because customer was set, the PaymentMethod will be attached to the provided Customer object after a successful setup. At this point, you can associate the ID of the Customer object with your internal representation of a customer. This allows you to use the stored PaymentMethod to collect future payments without prompting for your customer’s payment method details.

var form = document.getElementById('setup-form'); var accountholderName = document.getElementById('accountholder-name'); var email = document.getElementById('email'); var submitButton = document.getElementById('submit-button'); var clientSecret = submitButton.dataset.secret; form.addEventListener('submit', function(event) { event.preventDefault(); stripe.confirmAuBecsDebitSetup( clientSecret, { payment_method: { au_becs_debit: auBankAccount, billing_details: { name: accountholderName.value, email: email.value } } } ); });
const form = document.getElementById('setup-form'); const accountholderName = document.getElementById('accountholder-name'); const email = document.getElementById('email'); const submitButton = document.getElementById('submit-button'); const clientSecret = submitButton.dataset.secret; form.addEventListener('submit', async (event) => { event.preventDefault(); stripe.confirmAuBecsDebitSetup( clientSecret, { payment_method: { au_becs_debit: auBankAccount, billing_details: { name: accountholderName.value, email: email.value } } } ); });

After successfully confirming the SetupIntent, you should share the mandate URL from the Mandate object with your customer. We also recommend including the following details to your customer when you confirm their mandate has been established:

  • an explicit confirmation message that indicates a Direct Debit arrangement has been set up
  • the business name that will appear on the customer’s bank statement whenever their account gets debited
  • the payment amount and schedule (if applicable)
  • a link to the generated DDR mandate URL

The Mandate object’s ID is accessible from the mandate on the SetupIntent object, which is sent as part of the setup_intent.succeeded event sent after confirmation, but can also be retrieved through the API.

curl https://api.stripe.com/v1/setup_intents/{{SETUP_INTENT_ID}} \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d "expand[]"=mandate
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' intent = Stripe::SetupIntent.retrieve({ id: '{{SETUP_INTENT_ID}}', expand: ['mandate'] }); mandate = intent.mandate
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' intent = stripe.SetupIntent.retrieve( '{{SETUP_INTENT_ID}}', expand=['mandate'] ) mandate = intent.mandate
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $intent = \Stripe\SetupIntent::retrieve([ 'id' => '{{SETUP_INTENT_ID}}', 'expand' => ['mandate'] ]); $mandate = $intent->mandate;
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; List<String> expandList = new ArrayList<>(); expandList.add("mandate"); Map<String, Object> params = new HashMap<>(); params.put("expand", expandList); SetupIntent intent = SetupIntent.retrieve("{{SETUP_INTENT_ID}}", params, null); Mandate mandate = intent.getMandateObject();
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const intent = stripe.setupIntents.retrieve('{{SETUP_INTENT_ID}}', {expand: ['mandate']}); const mandate = intent.mandate;
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.SetupIntentParams{}; params.AddExpand("mandate"); intent, _ := setupintent.Get("{{SETUP_INTENT_ID}}", params); m := intent.Mandate;
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var intentService = new SetupIntentService(); var options = new SetupIntentGetOptions(); options.AddExpand("mandate"); SetupIntent intent = intentService.Get("{{SETUP_INTENT_ID}}", options); var mandateService = new MandateService(); Mandate mandate = mandateService.Get(intent.Mandate);

Use stripe.confirmAuBecsDebitSetup to complete the mandate collection when the user submits the form. Including the customer’s email address and the account holder’s name in the billing_details property of the payment_method parameter is required to create a BECS Direct Debit PaymentMethod.

To call stripe.confirmAuBecsDebitSetup from your payment form component, use the useStripe and useElements hooks.

If you prefer traditional class components over hooks, you can instead use an ElementsConsumer.

import React from 'react'; import {useStripe, useElements, AuBankAccountElement} from '@stripe/react-stripe-js'; import BecsForm from './BecsForm'; export default function PaymentSetupForm() { const stripe = useStripe(); const elements = useElements(); const handleSubmit = async (event) => { // We don't want to let default form submission happen here, // which would refresh the page. event.preventDefault(); if (!stripe || !elements) { // Stripe.js has not yet loaded. // Make sure to disable form submission until Stripe.js has loaded. return; } const auBankAccount = elements.getElement(AuBankAccountElement); // For brevity, this example is using uncontrolled components for // the accountholder's name and email. In a real world app you will // probably want to use controlled components. // https://reactjs.org/docs/uncontrolled-components.html // https://reactjs.org/docs/forms.html#controlled-components const accountholderName = event.target['accountholder-name']; const email = event.target.email; const result = await stripe.confirmAuBecsDebitSetup('{{CLIENT_SECRET}}', { payment_method: { au_becs_debit: auBankAccount, billing_details: { name: accountholderName.value, email: email.value, }, } }); if (result.error) { // Show error to your customer. console.log(result.error.message); } else { // Show a confirmation message to your customer. // The SetupIntent is in the 'succeeded' state. } }; return ( <BecsForm onSubmit={handleSubmit} disabled={!stripe} /> ); }
import React from 'react'; import {ElementsConsumer, AuBankAccountElement} from '@stripe/react-stripe-js'; import BecsForm from './BecsForm'; class PaymentSetupForm extends React.Component { handleSubmit = async (event) => { // We don't want to let default form submission happen here, // which would refresh the page. event.preventDefault(); const {stripe, elements} = this.props if (!stripe || !elements) { // Stripe.js has not yet loaded. // Make sure to disable form submission until Stripe.js has loaded. return; } const auBankAccount = elements.getElement(AuBankAccountElement); // For brevity, this example is using uncontrolled components for // the accountholder's name and email. In a real world app you will // probably want to use controlled components. // https://reactjs.org/docs/uncontrolled-components.html // https://reactjs.org/docs/forms.html#controlled-components const accountholderName = event.target['accountholder-name']; const email = event.target.email; const result = await stripe.confirmAuBecsDebitSetup('{{CLIENT_SECRET}}', { payment_method: { au_becs_debit: auBankAccount, billing_details: { name: accountholderName.value, email: email.value, }, } }); if (result.error) { // Show error to your customer. console.log(result.error.message); } else { // Show a confirmation message to your customer. // The SetupIntent is in the 'succeeded' state. } }; render() { const {stripe} = this.props; return ( <BecsForm onSubmit={this.handleSubmit} disabled={!stripe} /> ); } } export default function InjectedPaymentSetupForm() { return ( <ElementsConsumer> {({stripe, elements}) => ( <PaymentSetupForm stripe={stripe} elements={elements} /> )} </ElementsConsumer> ); }

After successfully confirming the SetupIntent, you should share the mandate URL from the Mandate object with your customer. We also recommend including the following details to your customer when you confirm their mandate has been established:

  • an explicit confirmation message that indicates a Direct Debit arrangement has been set up
  • the business name that will appear on the customer’s bank statement whenever their account gets debited
  • the payment amount and schedule (if applicable)
  • a link to the generated DDR mandate URL

The Mandate object’s ID is accessible from the mandate on the SetupIntent object, which is sent as part of the setup_intent.succeeded event sent after confirmation, but can also be retrieved through the API.

curl https://api.stripe.com/v1/setup_intents/{{SETUP_INTENT_ID}} \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d "expand[]"=mandate
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' intent = Stripe::SetupIntent.retrieve({ id: '{{SETUP_INTENT_ID}}', expand: ['mandate'] }); mandate = intent.mandate
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' intent = stripe.SetupIntent.retrieve( '{{SETUP_INTENT_ID}}', expand=['mandate'] ) mandate = intent.mandate
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $intent = \Stripe\SetupIntent::retrieve([ 'id' => '{{SETUP_INTENT_ID}}', 'expand' => ['mandate'] ]); $mandate = $intent->mandate;
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; List<String> expandList = new ArrayList<>(); expandList.add("mandate"); Map<String, Object> params = new HashMap<>(); params.put("expand", expandList); SetupIntent intent = SetupIntent.retrieve("{{SETUP_INTENT_ID}}", params, null); Mandate mandate = intent.getMandateObject();
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const intent = stripe.setupIntents.retrieve('{{SETUP_INTENT_ID}}', {expand: ['mandate']}); const mandate = intent.mandate;
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.SetupIntentParams{}; params.AddExpand("mandate"); intent, _ := setupintent.Get("{{SETUP_INTENT_ID}}", params); m := intent.Mandate;
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var intentService = new SetupIntentService(); var options = new SetupIntentGetOptions(); options.AddExpand("mandate"); SetupIntent intent = intentService.Get("{{SETUP_INTENT_ID}}", options); var mandateService = new MandateService(); Mandate mandate = mandateService.Get(intent.Mandate);

6 Test the integration

You can test your form using the test BSB number 000-000 and one of the test account numbers below with your confirmAuBecsDebitSetup request.

Account Number Description
000123456 PaymentIntents created with the resulting PaymentMethod will transition from processing to succeeded. The mandate status will remain active.
900123456 PaymentIntents created with the resulting PaymentMethod will transition from processing to succeeded (with a three-minute delay). The mandate status will remain active.
111111113 The PaymentIntent created with the resulting PaymentMethod will transition from processing to requires_payment_method with an account_closed failure code. The mandate status will become inactive at that point.
111111116 The PaymentIntent created with the resulting PaymentMethod will transition from processing to requires_payment_method with a no_account failure code. The mandate status will become inactive at that point.
222222227 PaymentIntents created with the resulting PaymentMethod will transition from processing to requires_payment_method with a refer_to_customer failure code. The mandate status will remain active.
922222227 PaymentIntents created with the resulting PaymentMethod will transition from processing to requires_payment_method with a refer_to_customer failure code (with a three-minute delay). The mandate status will remain active.
333333335 The PaymentIntent created with the resulting PaymentMethod will transition from processing to requires_payment_method with a debit_not_authorized failure code. The mandate status will become inactive at that point.

Optional Validate the Australia Bank Account Element Client-side

The Australia Bank Account Element validates user input as it is typed. To help your customers fix mistakes, you should listen to change events on the Australia Bank Account Element and display any errors:

auBankAccount.on('change', function(event) { var displayError = document.getElementById('error-message'); if (event.error) { displayError.textContent = event.error.message; } else { displayError.textContent = ''; } });
auBankAccount.on('change', (event) => { const displayError = document.getElementById('error-message'); if (event.error) { displayError.textContent = event.error.message; } else { displayError.textContent = ''; } });
<AuBankAccountElement onChange={(event) => { if (event.error) { // Store event.error.message in state and display it. } else { // Remove existing error from state. } }}>

The change event contains other parameters that can help to build a richer user experience. Refer to the Stripe.js reference for more details.

Optional Accepting future payments Client-side

When the SetupIntent succeeds, it will create a new PaymentMethod object and a Mandate object. These can be used to initiate future payments without having to prompt the customer for information information.

curl https://api.stripe.com/v1/payment_intents \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d amount=1000 \ -d currency=aud \ -d "payment_method_types[]"=au_becs_debit \ -d customer="{{CUSTOMER_ID}}" \ -d payment_method="{{PAYMENT_METHOD_ID}}" \ -d confirm=true
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' Stripe::PaymentIntent.create({ amount: 1000, currency: 'aud', payment_method_types: ['au_becs_debit'], customer: '{{CUSTOMER_ID}}', payment_method: '{{PAYMENT_METHOD_ID}}', confirm: true, })
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' stripe.PaymentIntent.create( amount=1000, currency='aud', payment_method_types=['au_becs_debit'], customer='{{CUSTOMER_ID}}', payment_method='{{PAYMENT_METHOD_ID}}', confirm=True )
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); \Stripe\PaymentIntent::create([ 'amount' => 1000, 'currency' => 'aud', 'payment_method_types' => ['au_becs_debit'], 'customer' => '{{CUSTOMER_ID}}', 'payment_method' => '{{PAYMENT_METHOD_ID}}', 'confirm' => true, ]);
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; PaymentIntentCreateParams params = PaymentIntentCreateParams.builder() .addPaymentMethodType("au_becs_debit") .setAmount(1000L) .setCurrency("aud") .setCustomer("{{CUSTOMER_ID}}") .setPaymentMethod("{{PAYMENT_METHOD_ID}}") .setConfirm(true) .build(); PaymentIntent paymentIntent = PaymentIntent.create(params);
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const paymentIntent = await stripe.paymentIntents.create({ amount: 1000, currency: 'aud', payment_method_types: ['au_becs_debit'], customer: '{{CUSTOMER_ID}}', payment_method: '{{PAYMENT_METHOD_ID}}', confirm: true, });
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.PaymentIntentParams{ Amount: stripe.Int64(1000), Currency: stripe.String(string(stripe.CurrencyAUD)), PaymentMethodTypes: []*string{ stripe.String("au_becs_debit"), }, Customer: stripe.String("{{CUSTOMER_ID}}"), PaymentMethod: stripe.String("{{PAYMENT_METHOD_ID}}"), Confirm: stripe.Bool(true), } pi, _ := paymentintent.New(params)
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new PaymentIntentCreateOptions { Amount = 1000, Currency = "aud", PaymentMethodTypes = new List<string> { "au_becs_debit", }, Customer = "{{CUSTOMER_ID}}", PaymentMethod = "{{PAYMENT_METHOD_ID}}", }; var service = new PaymentIntentService(); service.Create(options);

Use STPAUBECSFormView, Stripe’s prebuilt BECS payment details collection UI, to create a payment form that lets you securely collect bank details without handling sensitive customer data. You can use the Setup Intents API to collect BECS Direct Debit payment method details in advance, with the final amount or payment date determined later. This is useful for:

1 Set up Stripe Server-side Client-side

First, you need a Stripe account. Register now.

Server-side

This integration requires endpoints on your server that talk to the Stripe API. Use our official libraries for access to the Stripe API from your server:

# Available as a gem gem install stripe
# If you use bundler, you can add this line to your Gemfile gem 'stripe'
# Install through pip pip install --upgrade stripe
# Or find the Stripe package on http://pypi.python.org/pypi/stripe/
# Find the version you want to pin: # https://github.com/stripe/stripe-python/blob/master/CHANGELOG.md # Specify that version in your requirements.txt file stripe>=2.48.0,<3.0
# Install the PHP library via Composer composer require stripe/stripe-php
# Or download the source directly: https://github.com/stripe/stripe-php/releases
/* For Gradle, add the following dependency to your build.gradle and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest */ implementation "com.stripe:stripe-java:{VERSION}"
<!-- For Maven, add the following dependency to your POM and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest --> <dependency> <groupId>com.stripe</groupId> <artifactId>stripe-java</artifactId> <version>{VERSION}</version> </dependency>
# For other environments, manually install the following JARs: # - The Stripe JAR from https://github.com/stripe/stripe-java/releases/latest # - Google Gson from https://github.com/google/gson
# Install via npm npm install --save stripe
# Make sure your project is using Go Modules god mod init # Install stripe-go go get -u github.com/stripe/stripe-go/v71
// Then import the package import ( "github.com/stripe/stripe-go/v71" )
# Install via dotnet dotnet add package Stripe.net dotnet restore
# Or install via NuGet PM> Install-Package Stripe.net

Client-side

The iOS SDK is open source, fully documented, and compatible with apps supporting iOS 10 or above.

  1. If you haven't already, install the latest version of CocoaPods.
  2. If you don't have an existing Podfile, run the following command to create one:
    pod init
  3. Add this line to your Podfile:
    pod 'Stripe'
  4. Run the following command:
    pod install
  5. Don't forget to use the .xcworkspace file to open your project in Xcode, instead of the .xcodeproj file, from here on out.
  6. In the future, to update to the latest version of the SDK, just run:
    pod update Stripe
  1. If you haven't already, install the latest version of Carthage.
  2. Add this line to your Cartfile:
    github "stripe/stripe-ios"
  3. Follow the Carthage installation instructions.
  4. In the future, to update to the latest version of the SDK, run the following command:
    carthage update stripe-ios --platform ios
  1. Head to our GitHub releases page and download and unzip Stripe.framework.zip.
  2. Drag Stripe.framework to the "Embedded Binaries" section of your Xcode project's "General" settings. Make sure to select "Copy items if needed".
  3. Head to the "Build Phases" section of your Xcode project settings, and create a new "Run Script Build Phase". Paste the following snippet into the text field:
    bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Stripe.framework/integrate-dynamic-framework.sh"
  4. In the future, to update to the latest version of our SDK, just repeat steps 1 and 2.

When your app starts, configure the SDK with your Stripe publishable key so that it can make requests to the Stripe API.

import UIKit import Stripe @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { Stripe.setDefaultPublishableKey("pk_test_TYooMQauvdEDq54NiTphI7jx") // do any other necessary launch configuration return true } }
#import "AppDelegate.h" #import <Stripe/Stripe.h> @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [Stripe setDefaultPublishableKey:@"pk_test_TYooMQauvdEDq54NiTphI7jx"]; // do any other necessary launch configuration return YES; } @end

2 Create or retrieve a Customer Server-side

To reuse a BECS Direct Debit account for future payments, it must be attached to a Customer.

You should create a Customer object when your customer creates an account with your business. Associating the ID of the Customer object with your own internal representation of a customer will enable you to retrieve and use the stored payment method details later. If your customer is making a payment as a guest, you can still create a Customer object before payment and associate it with your internal representation of the customer’s account later.

Create a new Customer or retrieve an existing Customer to associate with this payment. Include the following code on your server to create a new Customer.

curl https://api.stripe.com/v1/customers \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -X POST
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' customer = Stripe::Customer.create
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' customer = stripe.Customer.create()
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $customer = \Stripe\Customer::create();
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; CustomerCreateParams params = CustomerCreateParams.builder() .build(); Customer customer = Customer.create(params);
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const customer = await stripe.customers.create();
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.CustomerParams{} c, _ := customer.New(params)
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new CustomerCreateOptions{}; var service = new CustomerService(); var customer = service.Create(options);

3 Collect payment method details and mandate acknowledgment Client-side

You can securely collect BECS Debit payment information with STPAUBECSFormView, a drop-in UI component provided by the SDK. STPAUBECSFormView​ provides a UI for customers to enter their name, email, BSB number, and account number—in addition to displaying the BECS Direct Debit Terms.

Create an instance of STPAUBECSFormView​ configured with your company name and set up a delegate for the SDK to notify after the customer enters the required details to create an instance of STPPaymentMethodParams​. You can also customize STPAUBECSFormView​ to match the look and feel of your app by providing values to STPAUBECSFormView​'s public properties.

import UIKit import Stripe class CheckoutViewController: UIViewController { private var becsFormView = STPAUBECSDebitFormView(companyName: "Example Company Inc.") private let saveButton = UIButton() private var setupIntentClientSecret: String? override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .secondarySystemBackground saveButton.layer.cornerRadius = 5 saveButton.contentEdgeInsets = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8) saveButton.backgroundColor = .systemGray3 saveButton.titleLabel?.font = UIFont.systemFont(ofSize: 18) saveButton.setTitle("Save", for: .normal) saveButton.addTarget(self, action: #selector(save), for: .touchUpInside) saveButton.isEnabled = false saveButton.translatesAutoresizingMaskIntoConstraints = false view.addSubview(saveButton) becsFormView.becsDebitFormDelegate = self becsFormView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(becsFormView) NSLayoutConstraint.activate([ becsFormView.leadingAnchor.constraint(equalTo: view.leadingAnchor), view.trailingAnchor.constraint(equalTo: becsFormView.trailingAnchor), becsFormView.topAnchor.constraint(equalToSystemSpacingBelow: view.safeAreaLayoutGuide.topAnchor, multiplier: 2), saveButton.centerXAnchor.constraint(equalTo: view.centerXAnchor), saveButton.topAnchor.constraint(equalToSystemSpacingBelow: becsFormView.bottomAnchor, multiplier: 2), ]) } @objc func save() { // ... } } extension CheckoutViewController: STPAUBECSDebitFormViewDelegate { func auBECSDebitForm(_ form: STPAUBECSDebitFormView, didChangeToStateComplete complete: Bool) { saveButton.isEnabled = complete saveButton.backgroundColor = complete ? .systemBlue : .systemGray3 } }
#import "CheckoutViewController.h" #import <Stripe/Stripe.h> @interface CheckoutViewController () <STPAUBECSDebitFormViewDelegate> @property (nonatomic) STPAUBECSDebitFormView *becsFormView; @property (nonatomic, readonly) UIButton *saveButton; @property (nonatomic, copy) NSString *setupIntentClientSecret; @end @implementation CheckoutViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; _saveButton = [UIButton buttonWithType:UIButtonTypeCustom]; self.saveButton.layer.cornerRadius = 5; self.saveButton.backgroundColor = [UIColor systemGray3Color]; self.saveButton.titleLabel.font = [UIFont systemFontOfSize:18]; self.saveButton.contentEdgeInsets = UIEdgeInsetsMake(4, 8, 4, 8); self.saveButton.enabled = NO; [self.saveButton setTitle:@"Save" forState:UIControlStateNormal]; [self.saveButton addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside]; self.saveButton.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:self.saveButton]; self.becsFormView = [[STPAUBECSDebitFormView alloc] initWithCompanyName:@"Example Company Inc."]; self.becsFormView.becsDebitFormDelegate = self; self.becsFormView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:self.becsFormView]; [NSLayoutConstraint activateConstraints:@[ [self.becsFormView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], [self.view.trailingAnchor constraintEqualToAnchor:self.becsFormView.trailingAnchor], [self.becsFormView.topAnchor constraintEqualToSystemSpacingBelowAnchor:self.view.safeAreaLayoutGuide.topAnchor multiplier:2], [self.saveButton.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], [self.saveButton.topAnchor constraintEqualToSystemSpacingBelowAnchor:self.becsFormView.bottomAnchor multiplier:2], ]]; } - (void)save { // ... } #pragma mark - STPAUBECSDebitFormViewDelegate - (void)auBECSDebitForm:(STPAUBECSDebitFormView *)form didChangeToStateComplete:(BOOL)complete { self.saveButton.enabled = complete; self.saveButton.backgroundColor = complete ? [UIColor systemBlueColor] : [UIColor systemGray3Color]; } @end

4 Create a SetupIntent Server-side

A SetupIntent is an object that represents your intent to set up a customer’s payment method for future payments. The SetupIntent will track the steps of this set-up process. For BECS Direct Debit, this includes collecting a mandate from the customer and tracking its validity throughout its lifecycle.

Create a SetupIntent on your server with payment_method_types set to au_becs_debit and specify the Customer’s id:

curl https://api.stripe.com/v1/setup_intents \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d "payment_method_types[]"=au_becs_debit \ -d customer="{{CUSTOMER_ID}}"
require 'sinatra' require 'json' require 'stripe' # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' get '/wallet' do intent = Stripe::SetupIntent.create({ payment_method_types: ['au_becs_debit'], customer: customer['id'], }) client_secret = setup_intent['client_secret'] # Pass the client secret to the client end
import stripe import json from flask import Flask, request, render_template app = Flask(__name__, static_folder=".", static_url_path="", template_folder=".") # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' @app.route('/wallet') def wallet(): setup_intent = stripe.SetupIntent.create( payment_method_types=['au_becs_debit'], customer=customer['id'] ) client_secret = setup_intent.client_secret # Pass the client secret to the client if __name__ == '__main__': app.run()
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); # vendor using composer require_once('vendor/autoload.php'); $setup_intent = \Stripe\SetupIntent::create([ 'payment_method_types' => ['au_becs_debit'], 'customer' => $customer->id, ]); $client_secret = $setup_intent->client_secret // Pass the client secret to the client
import java.util.HashMap; import java.util.Map; import com.stripe.Stripe; import com.stripe.model.SetupIntent; public class StripeJavaQuickStart { public static void main(String[] args) { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; Map<String, Object> setupIntentParams = new HashMap<String, Object>(); ArrayList paymentMethodTypes = new ArrayList(); setupIntentParams.put("payment_method_types", Arrays.asList("au_becs_debit")); setupIntentParams.put("customer", customer.getId()); SetupIntent setupIntent = SetupIntent.create(setupIntentParams); String clientSecret = setupIntent.getClientSecret(); // Pass the client secret to the client } }
// Using Express const express = require('express'); const app = express(); app.use(express.json()); const { resolve } = require("path"); // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const setupIntent = await stripe.setupIntents.create({ payment_method_types: ['au_becs_debit'], customer: customer.id, }); const clientSecret = setupIntent.client_secret; // Pass the client secret to the client
package main import ( "encoding/json" "log" "net/http" "github.com/stripe/stripe-go/v71" "github.com/stripe/stripe-go/v71/setupintent" ) func main() { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" setupIntentParams := &stripe.SetupIntentParams{ PaymentMethodTypes: stripe.StringSlice([]string{ "au_becs_debit", }), Customer: stripe.String(customer.ID), } setupIntent, err := setupintent.New(setupIntentParams) clientSecret := setupIntent.ClientSecret // Pass the client secret to the client }
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; using System; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Stripe; namespace StripeExampleApi.Controllers { [Route("/wallet")] public class WalletController : Controller { public IActionResult Index() { var service = new SetupIntentService(); var options = new SetupIntentCreateOptions { PaymentMethodTypes = new List<string> { "au_becs_debit", }, Customer = "{{CUSTOMER_ID}}", }; SetupIntent intent = service.Create(options); var clientSecret = setupIntent.ClientSecret; // Pass the client secret to the client } } }

After creating a SetupIntent on your server, you can associate the SetupIntent ID with the current session’s customer in your application’s data model. Doing so allows you to retrieve the information after you have successfully collected a payment method.

The returned SetupIntent object contains a client_secret property. Pass the client secret to the client-side application to continue with the setup process.

5 Submit the payment method details to Stripe Client-side

After the user enters their payment details, confirm the SetupIntent to complete saving the debit information.

First, assemble a STPSetupIntentConfirmParams object with:

  1. The STPAUBECSFormView’s paymentMethodParams property
  2. The SetupIntent client secret from your server

Rather than sending the entire SetupIntent object to the client, use its client secret from step 4. This is different from your API keys that authenticate Stripe API requests.

The client secret should still be handled carefully because it can complete the setup. Do not log it, embed it in URLs, or expose it to anyone but the customer.

Next, complete the payment by calling the STPPaymentHandler confirmSetupIntent method.

Because customer was set, the PaymentMethod will be attached to the provided Customer object after a successful setup. At this point, you can associate the ID of the Customer object with your internal representation of a customer. This allows you to use the stored PaymentMethod to collect future payments without prompting the customer for payment method details.

import UIKit import Stripe class CheckoutViewController: UIViewController { // ... @objc func save() { guard let setupIntentClientSecret = setupIntentClientSecret, let paymentMethodParams = becsFormView.paymentMethodParams else { return; } let setupIntentParams = STPSetupIntentConfirmParams(clientSecret: setupIntentClientSecret) setupIntentParams.paymentMethodParams = paymentMethodParams STPPaymentHandler.shared().confirmSetupIntent(withParams: setupIntentParams, authenticationContext: self) { (handlerStatus, setupIntent, error) in switch (handlerStatus) { case .failed: // Setup failed break case .canceled: // Setup canceled break case .succeeded: // Setup succeeded break @unknown default: fatalError() break } } } } extension CheckoutViewController: STPAuthenticationContext { func authenticationPresentingViewController() -> UIViewController { return self } }
#import "CheckoutViewController.h" #import <Stripe/Stripe.h> @interface CheckoutViewController () <STPAUBECSDebitFormViewDelegate, STPAuthenticationContext> // ... @end @implementation CheckoutViewController // ... - (void)save { if (self.setupIntentClientSecret == nil || self.becsFormView.paymentMethodParams == nil) { return; } STPSetupIntentConfirmParams *setupIntentParams = [[STPSetupIntentConfirmParams alloc] initWithClientSecret:self.setupIntentClientSecret]; setupIntentParams.paymentMethodParams = self.becsFormView.paymentMethodParams; [[STPPaymentHandler sharedHandler] confirmSetupIntent:setupIntentParams withAuthenticationContext:self completion:^(STPPaymentHandlerActionStatus handlerStatus, STPSetupIntent * _Nullable setupIntent, NSError * _Nullable error) { switch (handlerStatus) { case STPPaymentHandlerActionStatusFailed: { // Setup failed break; } case STPPaymentHandlerActionStatusCanceled: { // Setup canceled break; } case STPPaymentHandlerActionStatusSucceeded: { // Setup succeeded break; } default: break; } }]; } #pragma mark - STPAuthenticationContext - (UIViewController *)authenticationPresentingViewController { return self; } @end

After confirming the SetupIntent​, share the mandate URL from the Mandate object with your customer. We also recommend including the following details when you confirm their mandate has been established:

  • An explicit confirmation message that indicates a Direct Debit arrangement has been set up
  • The business name that will appear on the customer’s bank statement whenever their account gets debited
  • The payment amount and schedule (if applicable)
  • A link to the generated DDR mandate URL

​​You can access the the Mandate​ object’s ID from the mandate on the SetupIntent object (included with the setup_intent.succeeded event sent after confirmation) or you can retrieve it through the API.

6 Test the integration

You can test your form using the test BSB number 000-000 and one of the test account numbers below with your STPPaymentHandler confirmSetupIntent method call.

Account Number Description
000123456 PaymentIntents created with the resulting PaymentMethod will transition from processing to succeeded. The mandate status will remain active.
900123456 PaymentIntents created with the resulting PaymentMethod will transition from processing to succeeded (with a three-minute delay). The mandate status will remain active.
111111113 The PaymentIntent created with the resulting PaymentMethod will transition from processing to requires_payment_method with an account_closed failure code. The mandate status will become inactive at that point.
111111116 The PaymentIntent created with the resulting PaymentMethod will transition from processing to requires_payment_method with a no_account failure code. The mandate status will become inactive at that point.
222222227 PaymentIntents created with the resulting PaymentMethod will transition from processing to requires_payment_method with a refer_to_customer failure code. The mandate status will remain active.
922222227 PaymentIntents created with the resulting PaymentMethod will transition from processing to requires_payment_method with a refer_to_customer failure code (with a three-minute delay). The mandate status will remain active.
333333335 The PaymentIntent created with the resulting PaymentMethod will transition from processing to requires_payment_method with a debit_not_authorized failure code. The mandate status will become inactive at that point.

Use BecsDebitWidget, Stripe’s prebuilt BECS payment details collection UI, to create a payment form that lets you securely collect bank details without handling sensitive customer data. You can use the Setup Intents API to collect BECS Direct Debit payment method details in advance, with the final amount or payment date determined later. This is useful for:

1 Set up Stripe Server-side Client-side

First, you need a Stripe account. Register now.

Server-side

This integration requires endpoints on your server that talk to the Stripe API. Use our official libraries for access to the Stripe API from your server:

# Available as a gem gem install stripe
# If you use bundler, you can add this line to your Gemfile gem 'stripe'
# Install through pip pip install --upgrade stripe
# Or find the Stripe package on http://pypi.python.org/pypi/stripe/
# Find the version you want to pin: # https://github.com/stripe/stripe-python/blob/master/CHANGELOG.md # Specify that version in your requirements.txt file stripe>=2.48.0,<3.0
# Install the PHP library via Composer composer require stripe/stripe-php
# Or download the source directly: https://github.com/stripe/stripe-php/releases
/* For Gradle, add the following dependency to your build.gradle and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest */ implementation "com.stripe:stripe-java:{VERSION}"
<!-- For Maven, add the following dependency to your POM and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest --> <dependency> <groupId>com.stripe</groupId> <artifactId>stripe-java</artifactId> <version>{VERSION}</version> </dependency>
# For other environments, manually install the following JARs: # - The Stripe JAR from https://github.com/stripe/stripe-java/releases/latest # - Google Gson from https://github.com/google/gson
# Install via npm npm install --save stripe
# Make sure your project is using Go Modules god mod init # Install stripe-go go get -u github.com/stripe/stripe-go/v71
// Then import the package import ( "github.com/stripe/stripe-go/v71" )
# Install via dotnet dotnet add package Stripe.net dotnet restore
# Or install via NuGet PM> Install-Package Stripe.net

Client-side

The Android SDK is open source and fully documented.

To install the SDK, add stripe-android to the dependencies block of your app/build.gradle file:

apply plugin: 'com.android.application' android { ... } dependencies { // ... // Stripe Android SDK implementation 'com.stripe:stripe-android:15.0.1' }

Configure the SDK with your Stripe publishable key so that it can make requests to the Stripe API, such as in your Application subclass:

import com.stripe.android.PaymentConfiguration class MyApp : Application() { override fun onCreate() { super.onCreate() PaymentConfiguration.init( applicationContext, "pk_test_TYooMQauvdEDq54NiTphI7jx" ) } }
import com.stripe.android.PaymentConfiguration; public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); PaymentConfiguration.init( getApplicationContext(), "pk_test_TYooMQauvdEDq54NiTphI7jx" ); } }

Our code samples also use OkHttp and GSON to make HTTP requests to a server.

2 Create or retrieve a Customer Server-side

To reuse a BECS Direct Debit account for future payments, it must be attached to a Customer.

You should create a Customer object when your customer creates an account with your business. Associating the ID of the Customer object with your own internal representation of a customer will enable you to retrieve and use the stored payment method details later. If your customer is making a payment as a guest, you can still create a Customer object before payment and associate it with your internal representation of the customer’s account later.

Create a new Customer or retrieve an existing Customer to associate with this payment. Include the following code on your server to create a new Customer.

curl https://api.stripe.com/v1/customers \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -X POST
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' customer = Stripe::Customer.create
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' customer = stripe.Customer.create()
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $customer = \Stripe\Customer::create();
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; CustomerCreateParams params = CustomerCreateParams.builder() .build(); Customer customer = Customer.create(params);
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const customer = await stripe.customers.create();
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.CustomerParams{} c, _ := customer.New(params)
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new CustomerCreateOptions{}; var service = new CustomerService(); var customer = service.Create(options);

3 Collect payment method details and mandate acknowledgment Client-side

You can securely collect BECS Debit payment information with BecsDebitWidget, a drop-in UI component provided by the SDK. BecsDebitWidget provides a UI for customers to enter their name, email, BSB number, and account number. It also displays the BECS Direct Debit Terms.

Add BecsDebitWidget to your layout

Add BecsDebitWidget to your layout and configure the app:companyName attribute with your company name.

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- app:companyName is a required attribute --> <com.stripe.android.view.BecsDebitWidget android:id="@+id/becs_debit_widget" android:layout_width="match_parent" android:layout_height="wrap_content" app:companyName="@string/company_name" /> <Button android:id="@+id/save_button" android:layout_width="300dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:enabled="false" android:text="@string/save_with_becs_debit" /> </LinearLayout>

Style the BecsDebitWidget

The BecsDebitWidget can be further customized by adding the following styles to your application’s styles.xml.

<?xml version="1.0" encoding="utf-8"?> <!-- Optionally customize the widget's EditText fields --> <style name="Stripe.BecsDebitWidget.EditText" parent="Stripe.Base.BecsDebitWidget.EditText"> <!-- Add custom styles here --> </style> <!-- Optionally customize the mandate --> <style name="Stripe.BecsDebitWidget.MandateAcceptanceTextView" parent="Stripe.Base.BecsDebitWidget.MandateAcceptanceTextView"> <!-- Add custom styles here --> </style>

Configure your Activity

Set a BecsDebitWidget.ValidParamsCallback instance on BecsDebitWidget#validParamsCallback to be notified after the customer enters the required details to create an instance of PaymentMethodCreateParams​.

class CheckoutActivity : Activity() { private val stripe: Stripe by lazy { Stripe(this, PaymentConfiguration.getInstance(this).publishableKey) } private lateinit var becsDebitWidget: BecsDebitWidget private lateinit var setupIntentClientSecret: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.checkout_activity) becsDebitWidget = findViewById(R.id.becs_debit_widget) val saveButton = findViewById<Button>(R.id.save_button) becsDebitWidget.validParamsCallback = object : BecsDebitWidget.ValidParamsCallback { override fun onInputChanged(isValid: Boolean) { // enable saveButton if the customer's input is valid saveButton.isEnabled = isValid } } saveButton.setOnClickListener { onSaveClicked(paymentIntentClientSecret) } createSetupIntent() } private fun createSetupIntent() { // Create a SetupIntent on your backend and return the client_secret to // this Activity. Set setupIntentClientSecret to the client_secret. } }
public class CheckoutActivity extends Activity { private Stripe stripe; private BecsDebitWidget becsDebitWidget; private String setupIntentClientSecret; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.checkout_activity); stripe = new Stripe( this, PaymentConfiguration.getInstance(this).getPublishableKey() ); becsDebitWidget = findViewById(R.id.becs_debit_widget); final Button payButton = findViewById(R.id.pay_button); payButton.setOnClickListener(v -> { onSaveClicked(setupIntentClientSecret); }); // enable payButton if the customer's input is valid becsDebitWidget .setValidParamsCallback(isValid -> payButton.setEnabled(isValid)); createSetupIntent(); } private void createSetupIntent() { // Create a SetupIntent on your backend and return the client_secret to // this Activity. Set setupIntentClientSecret to the client_secret. } }

4 Create a SetupIntent Server-side

A SetupIntent is an object that represents your intent to set up a customer’s payment method for future payments. The SetupIntent will track the steps of this set-up process. For BECS Direct Debit, this includes collecting a mandate from the customer and tracking its validity throughout its lifecycle.

Create a SetupIntent on your server with payment_method_types set to au_becs_debit and specify the Customer’s id:

curl https://api.stripe.com/v1/setup_intents \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d "payment_method_types[]"=au_becs_debit \ -d customer="{{CUSTOMER_ID}}"
require 'sinatra' require 'json' require 'stripe' # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' get '/wallet' do intent = Stripe::SetupIntent.create({ payment_method_types: ['au_becs_debit'], customer: customer['id'], }) client_secret = setup_intent['client_secret'] # Pass the client secret to the client end
import stripe import json from flask import Flask, request, render_template app = Flask(__name__, static_folder=".", static_url_path="", template_folder=".") # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' @app.route('/wallet') def wallet(): setup_intent = stripe.SetupIntent.create( payment_method_types=['au_becs_debit'], customer=customer['id'] ) client_secret = setup_intent.client_secret # Pass the client secret to the client if __name__ == '__main__': app.run()
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); # vendor using composer require_once('vendor/autoload.php'); $setup_intent = \Stripe\SetupIntent::create([ 'payment_method_types' => ['au_becs_debit'], 'customer' => $customer->id, ]); $client_secret = $setup_intent->client_secret // Pass the client secret to the client
import java.util.HashMap; import java.util.Map; import com.stripe.Stripe; import com.stripe.model.SetupIntent; public class StripeJavaQuickStart { public static void main(String[] args) { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; Map<String, Object> setupIntentParams = new HashMap<String, Object>(); ArrayList paymentMethodTypes = new ArrayList(); setupIntentParams.put("payment_method_types", Arrays.asList("au_becs_debit")); setupIntentParams.put("customer", customer.getId()); SetupIntent setupIntent = SetupIntent.create(setupIntentParams); String clientSecret = setupIntent.getClientSecret(); // Pass the client secret to the client } }
// Using Express const express = require('express'); const app = express(); app.use(express.json()); const { resolve } = require("path"); // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const setupIntent = await stripe.setupIntents.create({ payment_method_types: ['au_becs_debit'], customer: customer.id, }); const clientSecret = setupIntent.client_secret; // Pass the client secret to the client
package main import ( "encoding/json" "log" "net/http" "github.com/stripe/stripe-go/v71" "github.com/stripe/stripe-go/v71/setupintent" ) func main() { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" setupIntentParams := &stripe.SetupIntentParams{ PaymentMethodTypes: stripe.StringSlice([]string{ "au_becs_debit", }), Customer: stripe.String(customer.ID), } setupIntent, err := setupintent.New(setupIntentParams) clientSecret := setupIntent.ClientSecret // Pass the client secret to the client }
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; using System; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Stripe; namespace StripeExampleApi.Controllers { [Route("/wallet")] public class WalletController : Controller { public IActionResult Index() { var service = new SetupIntentService(); var options = new SetupIntentCreateOptions { PaymentMethodTypes = new List<string> { "au_becs_debit", }, Customer = "{{CUSTOMER_ID}}", }; SetupIntent intent = service.Create(options); var clientSecret = setupIntent.ClientSecret; // Pass the client secret to the client } } }

After creating a SetupIntent on your server, you can associate the SetupIntent ID with the current session’s customer in your application’s data model. Doing so allows you to retrieve the information after you have successfully collected a payment method.

The returned SetupIntent object contains a client_secret property. Pass the client secret to the client-side application to continue with the setup process.

5 Submit the payment method details to Stripe Client-side

After the user enters their payment details, confirm the SetupIntent to complete saving the debit information.

First, assemble a ConfirmSetupIntentParams object with:

  1. The BecsDebitWidget#params property
  2. The SetupIntent client secret from your server

Rather than sending the entire SetupIntent object to the client, use its client secret from step 4. This is different from your API keys that authenticate Stripe API requests.

The client secret should still be handled carefully because it can complete the setup. Do not log it, embed it in URLs, or expose it to anyone but the customer.

Next, complete the payment by calling the Stripe#confirmSetupIntent() method.

Because customer was set, the PaymentMethod will be attached to the provided Customer object after a successful setup. At this point, you can associate the ID of the Customer object with your internal representation of a customer. This allows you to use the stored PaymentMethod to collect future payments without prompting the customer for payment method details.

class CheckoutActivity : Activity() { // ... fun onSaveClicked(setupIntentClientSecret: String) { becsDebitWidget.params?.let { params -> stripe.confirmSetupIntent( this, ConfirmSetupIntentParams.create( paymentMethodCreateParams = params, clientSecret = setupIntentClientSecret ) ) } } override fun onActivityResult( requestCode: Int, resultCode: Int, data: Intent? ) { super.onActivityResult(requestCode, resultCode, data) stripe.onSetupResult( requestCode, data, object : ApiResultCallback<SetupIntentResult> { override fun onSuccess(result: SetupIntentResult) { when (result.outcome) { StripeIntentResult.Outcome.SUCCEEDED -> { // Setup succeeded } StripeIntentResult.Outcome.CANCELED -> { // Setup canceled } StripeIntentResult.Outcome.TIMEDOUT -> { // Setup timed-out } StripeIntentResult.Outcome.FAILED -> { // Setup failed } } } override fun onError(e: Exception) { } } ) } }
public class CheckoutActivity extends Activity { private Stripe stripe; private BecsDebitWidget becsDebitWidget; // ... private void onSaveClicked(@NonNull String setupIntentClientSecret) { final PaymentMethodCreateParams params = becsDebitWidget.getParams(); if (params != null) { stripe.confirmSetupIntent( this, ConfirmSetupIntentParams.create( params, viewModel.clientSecret ) ); } else { // customer input is invalid } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); stripe.onSetupResult( requestCode, data, new ApiResultCallback<SetupIntentResult>() { @Override public void onSuccess(@NonNull SetupIntentResult result) { final int outcome = result.getOutcome(); if (outcome == StripeIntentResult.Outcome.SUCCEEDED) { // SetupIntent confirmation succeeded } else if (outcome == StripeIntentResult.Outcome.SUCCEEDED) { // SetupIntent confirmation canceled } else if (outcome == StripeIntentResult.Outcome.TIMEDOUT) { // SetupIntent confirmation timed-out } else if (outcome == StripeIntentResult.Outcome.FAILED) { // SetupIntent confirmation failed } } @Override public void onError(@NonNull Exception e) { // error while confirming Setup Intent } } ) } }

After confirming the SetupIntent​, share the mandate URL from the Mandate object with your customer. We also recommend including the following details when you confirm their mandate has been established:

  • An explicit confirmation message that indicates a Direct Debit arrangement has been set up
  • The business name that will appear on the customer’s bank statement whenever their account gets debited
  • The payment amount and schedule (if applicable)
  • A link to the generated DDR mandate URL

​​You can access the the Mandate​ object’s ID from the mandate on the SetupIntent object (included with the setup_intent.succeeded event sent after confirmation) or you can retrieve it through the API.

6 Test the integration

You can test your form using the test BSB number 000-000 and one of the test account numbers below with your Stripe#confirmSetupIntent() method call.

Account Number Description
000123456 PaymentIntents created with the resulting PaymentMethod will transition from processing to succeeded. The mandate status will remain active.
900123456 PaymentIntents created with the resulting PaymentMethod will transition from processing to succeeded (with a three-minute delay). The mandate status will remain active.
111111113 The PaymentIntent created with the resulting PaymentMethod will transition from processing to requires_payment_method with an account_closed failure code. The mandate status will become inactive at that point.
111111116 The PaymentIntent created with the resulting PaymentMethod will transition from processing to requires_payment_method with a no_account failure code. The mandate status will become inactive at that point.
222222227 PaymentIntents created with the resulting PaymentMethod will transition from processing to requires_payment_method with a refer_to_customer failure code. The mandate status will remain active.
922222227 PaymentIntents created with the resulting PaymentMethod will transition from processing to requires_payment_method with a refer_to_customer failure code (with a three-minute delay). The mandate status will remain active.
333333335 The PaymentIntent created with the resulting PaymentMethod will transition from processing to requires_payment_method with a debit_not_authorized failure code. The mandate status will become inactive at that point.

See also

Congrats, you are done with your integration! You can learn about accepting a BECS Direct Debit payment and integrating with Connect.

Was this page helpful?
Questions? Contact us.
Developer tutorials on YouTube.
You can unsubscribe at any time. Read our privacy policy.