Save SEPA Direct Debit details for future payments
Learn how to save payment method details for future SEPA Direct Debit payments.
You can use the Setup Intents API to collect payment method details in advance, and determine the final amount or payment date later. Use it to:
- Save payment methods to a wallet to streamline future purchases
- Collect surcharges after fulfilling a service
- Start a free trial for a subscription
Set up StripeServer-sideClient-side
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:
Client-side
The React Native SDK is open source and fully documented. Internally, it uses the native iOS and Android SDKs. To install Stripe’s React Native SDK, run one of the following commands in your project’s directory (depending on which package manager you use):
Next, install some other necessary dependencies:
- For iOS, navigate to the ios directory and run
pod install
to ensure that you also install the required native dependencies. - For Android, there are no more dependencies to install.
Stripe initialisation
To initialise Stripe in your React Native app, either wrap your payment screen with the StripeProvider
component, or use the initStripe
initialisation method. Only the API publishable key in publishableKey
is required. The following example shows how to initialise Stripe using the StripeProvider
component.
import { StripeProvider } from '@stripe/stripe-react-native'; function App() { const [publishableKey, setPublishableKey] = useState(''); const fetchPublishableKey = async () => { const key = await fetchKey(); // fetch key from your server here setPublishableKey(key); }; useEffect(() => { fetchPublishableKey(); }, []); return ( <StripeProvider publishableKey={publishableKey} merchantIdentifier="merchant.identifier" // required for Apple Pay urlScheme="your-url-scheme" // required for 3D Secure and bank redirects > // Your app code here </StripeProvider> ); }
Create or retrieve a CustomerServer-side
To reuse a SEPA 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 hasn’t created an account, you can still create a Customer object now 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 these payment details. Include the following code on your server to create a new Customer.
Create a SetupIntentServer-side
A SetupIntent is an object that represents your intent and tracks the steps to set up your customer’s payment method for future payments. For SEPA Direct Debit, this includes collecting a mandate from the customer and checking the validity of the IBAN.
Create a SetupIntent on your server with payment_method_types set to sepa_
and specify the Customer’s id.:
Collect payment method details and mandate acknowledgmentClient-side
Collect the customer’s IBAN in your payment form and display the following standard authorisation text for your customer to implicitly sign the mandate.
Display the following standard authorization text for your customer to implicitly sign the mandate.
Replace Rocket Rides with your company name.
Setting up a payment method creates the accepted mandate. As the customer has implicitly signed the mandate when accepting these terms, you must communicate these terms in your form or through email.
export default function SepaSetupFuturePaymentScreen() { const [email, setEmail] = useState(''); const [iban, setIban] = useState(''); return ( <Screen> <TextInput placeholder="E-mail" keyboardType="email-address" onChange={(value) => setEmail(value.nativeEvent.text)} style={styles.input} /> <TextInput placeholder="Iban" onChange={(value) => setIban(value.nativeEvent.text.toLowerCase())} style={styles.input} /> <Button variant="primary" onPress={handlePayPress} title="Save IBAN" loading={loading} /> </Screen> ); }
Submit the payment method details to StripeClient-side
Retrieve the client secret from the SetupIntent you created and call confirmSetupIntent
.
The client secret should be handled carefully because it can complete the setup. Don’t log it, embed it in URLs, or expose it to anyone but the customer.
Note
addressCountry
and addressLine1
must be provided in the billingDetails
for IBANs with the following country codes: AD, PF, TF, GI, GB, GG, VA, IM, JE, MC, NC, BL, PM, SM, CH, WF. See the React Native SDK reference for a list of address fields.
export default function SepaSetupFuturePaymentScreen() { const [iban, setIban] = useState(''); const {confirmSetupIntent, loading} = useConfirmSetupIntent(); const handlePayPress = async () => { const clientSecret = await createSetupIntentOnBackend(email); const billingDetails: PaymentMethodCreateParams.BillingDetails = { name: 'Jenny Rosen', email: 'jenny.rosen@example.com', }; const {error, setupIntent} = await confirmSetupIntent(clientSecret, { paymentMethodType: 'SepaDebit', paymentMethodData: { billingDetails, iban, } }); if (error) { Alert.alert(`Error code: ${error.code}`, error.message); console.log('Setup intent confirmation error', error.message); } else if (setupIntent) { Alert.alert( `Success: Setup intent created. Intent status: ${setupIntent.status}`, ); } }; return <Screen>{/* ... */}</Screen>; }
Test the integration
You can test your form using the IBANs below with your confirmSepaDebitSetup request. The payment method details are successfully collected for each IBAN but exhibit different behaviour when charged.