# Set up future PayTo payments Learn how to set up future PayTo payments. PayTo allows customers in Australia to [authenticate](https://docs.stripe.com/payments/payment-methods.md#customer-actions) PayTo mandates for one-off and recurring payments in their banking apps. *Customers* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments) pay with PayTo by receiving notification of a pending mandate request, authorizing the terms of the mandate, then returning to your app. Setting up a PayTo mandate for future payments allows you to get customer authorization now for collecting future payments. Customers can view, manage, pause, and cancel their PayTo mandates in their banking apps. > Stripe doesn’t support modification or pausing of PayTo mandates by customers. If a customer attempts to pause or modify a mandate, we cancel the mandate and send you a [`mandate.updated` webhook](https://docs.stripe.com/api/events/types.md#event_types-mandate.updated). After receiving the webhook, you can reach out to your customer to find out why they adjusted their mandate, as well as set up a new mandate. # Checkout > This is a Checkout for when payment-ui is checkout. View the full page at https://docs.stripe.com/payments/payto/set-up-payment?payment-ui=checkout. ## Set up a payment > This guide builds on the foundational [Set up future payments](https://docs.stripe.com/payments/checkout/save-and-reuse.md) Checkout integration. To enable Payto as a payment method, create a new [Checkout Session](https://docs.stripe.com/api/checkout/sessions.md): 1. Set the [mode](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-mode) to `setup`. 1. Specify the terms of the mandate you want your customer to agree to using [payment method options](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-payment_method_options-payto). 1. Add `payto` to the list of `payment_method_types`. #### Stripe-hosted page ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d customer="{{CUSTOMER_ID}}" \ -d mode=setup \ -d "payment_method_options[payto][mandate_options][amount_type]"=maximum \ -d "payment_method_options[payto][mandate_options][payment_schedule]"=annual \ -d "payment_method_options[payto][mandate_options][amount]"=150000 \ -d "payment_method_options[payto][mandate_options][payments_per_period]"=13 \ -d "payment_method_options[payto][mandate_options][start_date]"=2026-12-25 \ -d "payment_method_options[payto][mandate_options][end_date]"=2036-12-25 \ -d "payment_method_options[payto][mandate_options][purpose]"=mortgage \ -d "payment_method_types[]"=card \ -d "payment_method_types[]"=payto \ --data-urlencode success_url="https://example.com/success" ``` #### Embedded form ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d customer="{{CUSTOMER_ID}}" \ -d mode=setup \ -d "payment_method_options[payto][mandate_options][amount_type]"=maximum \ -d "payment_method_options[payto][mandate_options][payment_schedule]"=annual \ -d "payment_method_options[payto][mandate_options][amount]"=150000 \ -d "payment_method_options[payto][mandate_options][payments_per_period]"=13 \ -d "payment_method_options[payto][mandate_options][start_date]"=2026-12-25 \ -d "payment_method_options[payto][mandate_options][end_date]"=2036-12-25 \ -d "payment_method_options[payto][mandate_options][purpose]"=mortgage \ -d "payment_method_types[]"=card \ -d "payment_method_types[]"=payto \ --data-urlencode return_url="https://example.com/return" \ -d ui_mode=embedded ``` Stripe supports various types of mandates, with controls for the amount, duration, cadence, and purpose of the mandate. Specify mandate terms that match your requirements as closely as possible—customers see these precise terms at authorization time, so accuracy can improve your conversion rate. Stripe infers the default `purpose` based on your *merchant category code (MCC)* (A Merchant Category Code (MCC) is a four-digit number that classifies the type of goods or services a business offers). Override this field using any of the [valid values](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-payment_method_options-payto-mandate_options-purpose) if the default value doesn’t accurately represent the purpose of the mandate. You can inspect the default value on the [Mandate](https://docs.stripe.com/api/mandates/object.md#mandate_object-payment_method_details-payto) object when you don’t specify the purpose. ## Charge the PayTo PaymentMethod later Before you can charge your customer, find the mandate ID, customer ID, and payment method ID by [retrieving](https://docs.stripe.com/api/setup_intents/retrieve.md) the [SetupIntent](https://docs.stripe.com/payments/setup-intents.md) using its ID from the Checkout Session. ```curl curl https://api.stripe.com/v1/setup_intents/{{SETUPINTENT_ID}} \ -u "<>:" ``` View the necessary IDs in the response below. #### Json ```json { // ... "customer": "cus_PW6rQWRGAaBD7z", // <---- Here is the customer "mandate": "mandate_1Ok6ZrA8DuEjWaGw2nrO9xeS", // <---- Here is the mandate "metadata": {}, "next_action": null, "on_behalf_of": null, "payment_method": "pm_1Ok4l9A8DuEjWaGwhB4SGrWh", // <---- Here is the payment method "payment_method_configuration_details": null, "payment_method_options": { "payto": { "mandate_options": { "amount": 150000, "amount_type": "maximum", "start_date": "2026-12-25", "end_date": "2036-12-25", "payment_schedule": "annual", "payments_per_period": 13, "purpose": "mortgage", } } }, "payment_method_types": [ "payto" ], "single_use_mandate": null, "status": "succeeded", "usage": "off_session" // ... } ``` Create a *PaymentIntent* (API object that represents your intent to collect payment from a customer, tracking charge attempts and payment state changes throughout the process) with the PaymentMethod, Mandate, and Customer IDs. ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]"=payto \ -d amount=1099 \ -d currency=aud \ -d customer="{{CUSTOMER_ID}}" \ -d payment_method="{{PAYMENTMETHOD_ID}}" \ -d mandate="{{MANDATE_ID}}" \ -d confirm=true ``` ### Fulfill your orders After accepting a payment, learn how to [fulfill orders](https://docs.stripe.com/checkout/fulfillment.md). ## Test your integration Test your PayTo integration with your test API keys by using the various test PayIDs and bank account details below. Each set of details results in a different scenario your integration might commonly face in live mode. #### PayID | PayID | Description | | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `{any_prefix}+succeed@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `succeeded` after an additional 5 seconds. The mandate enters an `active` state. | | `{any_prefix}+decline@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and an `invalid_authorization` decline code. The mandate enters an `inactive` state. | | `{any_prefix}+expire@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and a `generic_decline` decline code. The mandate enters an `inactive` state. | | `{any_prefix}+insufficient_funds@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `requires_payment_method` after an additional 5 seconds. Stripe returns the `payment_method_provider_decline` error code and an `insufficient_funds` decline code. The mandate enters an `inactive` state. | | `{any_prefix}+revoke@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds then to `succeeded` after a further 5 seconds. The mandate begins in an `active` state and transitions to `inactive` after 1 minute. | | `{any_prefix}+agreement_type_not_supported@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code. The mandate enters an `inactive` state. | #### Account + BSB numbers | BSB number | Account number | Description | | ---------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `000000` | `000123456` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `succeeded` after an additional 5 seconds. The mandate enters an `active` state. | | `000000` | `333333335` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and an `invalid_authorization` decline code. The mandate enters an `inactive` state. | | `000000` | `333333337` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and a `generic_decline` decline code. The mandate enters an `inactive` state. | | `000000` | `222222227` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `requires_payment_method` after an additional 5 seconds. Stripe returns the `payment_method_provider_decline` error code and an `insufficient_funds` decline code. The mandate enters an `inactive` state. | | `000000` | `444444447` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `succeeded` after an additional 5 seconds. The mandate begins in an `active` state and transitions to `inactive` after 1 minute. | | `000000` | `666666667` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code. The mandate enters an `inactive` state. | # Elements > This is a Elements for when payment-ui is elements. View the full page at https://docs.stripe.com/payments/payto/set-up-payment?payment-ui=elements. ## Set up Stripe [Server-side] First, you need a Stripe account. [Register now](https://dashboard.stripe.com/register). To access the Stripe API from your application, use our official libraries: #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## Create a Customer [Server-side] Create a *Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments) after they create an account with your business and associate it with your internal representation of their account. This enables you to retrieve and use their saved payment method details later. ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d name="Jenny Rosen" \ --data-urlencode email="jenny@example.com" ``` ## Create a SetupIntent [Server-side] A [SetupIntent](https://docs.stripe.com/api/setup_intents/object.md) is an object that represents your intent to collect a future payment from a customer and tracks the authorization process. To create a SetupIntent that accepts a PayTo payment method, specify the terms of the mandate, and `payto` in the [payment_method_types](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_types) list. If you maintain a list of payment method types that you pass when creating a SetupIntent, add `payto` to it. Specify the terms of the mandate you want your customer to agree to using [payment method options](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_options-payto). ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]"=payto \ -d customer="{{CUSTOMER_ID}}" \ -d "payment_method_options[payto][mandate_options][amount_type]"=maximum \ -d "payment_method_options[payto][mandate_options][payment_schedule]"=annual \ -d "payment_method_options[payto][mandate_options][amount]"=150000 \ -d "payment_method_options[payto][mandate_options][payments_per_period]"=13 \ -d "payment_method_options[payto][mandate_options][start_date]"=2026-12-25 \ -d "payment_method_options[payto][mandate_options][end_date]"=2036-12-25 \ -d "payment_method_options[payto][mandate_options][purpose]"=mortgage ``` Stripe supports various types of mandates, with controls for the amount, duration, cadence, and purpose of the mandate. Specify mandate terms that match your requirements as closely as possible—customers see these precise terms at authorization time, so accuracy can improve your conversion rate. Stripe infers the default `purpose` based on your *merchant category code (MCC)* (A Merchant Category Code (MCC) is a four-digit number that classifies the type of goods or services a business offers). Override this field using [any of the valid values](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-payto-mandate_options-purpose) if the default value doesn’t accurately represent the purpose of the mandate. You can inspect the default value on the [Mandate](https://docs.stripe.com/api/mandates/object.md#mandate_object-payment_method_details-payto) object when you don’t specify the purpose. ### Retrieve the client secret The SetupIntent includes a *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) that the client side uses to securely complete the payment process. You can use different approaches to pass the client secret to the client side. #### Single-page application Retrieve the client secret from an endpoint on your server, using the browser’s `fetch` function. This approach is best if your client side is a single-page application, particularly one built with a modern frontend framework like React. Create the server endpoint that serves the client secret: #### Ruby ```ruby get '/secret' do intent = # ... Create or retrieve the SetupIntent {client_secret: intent.client_secret}.to_json end ``` And then fetch the client secret with JavaScript on the client side: ```javascript (async () => { const response = await fetch('/secret'); const {client_secret: clientSecret} = await response.json(); // Render the form using the clientSecret })(); ``` #### Server-side rendering Pass the client secret to the client from your server. This approach works best if your application generates static content on the server before sending it to the browser. Add the [client_secret](https://docs.stripe.com/api/setup_intents/object.md#setup_intent_object-client_secret) in your checkout form. In your server-side code, retrieve the client secret from the SetupIntent: #### Ruby ```erb
``` ```ruby get '/checkout' do @intent = # ... Fetch or create the SetupIntent erb :checkout end ``` ## Collect payment method details and submit the request for authorization [Client-side] Collect payment details on the client with the [Payment Element](https://docs.stripe.com/payments/payment-element.md). The Payment Element is a prebuilt UI component that simplifies collecting payment details for a variety of payment methods. The Payment Element contains an iframe that securely sends payment information to Stripe over an HTTPS connection. Avoid placing the Payment Element within another iframe because some payment methods require redirecting to another page for payment confirmation. If you choose to use an iframe and want to accept Apple Pay or Google Pay, the iframe must have the [allow](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-allowpaymentrequest) attribute set to equal `"payment *"`. The checkout page address must start with `https://` rather than `http://` for your integration to work. You can test your integration without using HTTPS, but remember to [enable it](https://docs.stripe.com/security/guide.md#tls) when you’re ready to accept live payments. #### HTML + JS ### Set up Stripe.js The Payment Element is automatically available as a feature of Stripe.js. Include the Stripe.js script on your checkout page by adding it to the `head` of your HTML file. Always load Stripe.js directly from js.stripe.com to remain PCI compliant. Don’t include the script in a bundle or host a copy of it yourself. ```html Checkout ``` Create an instance of Stripe with the following JavaScript on your checkout page: ```javascript // Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe('<>'); ``` ### Add the Payment Element to your payment page The Payment Element needs a place to live on your payment page. Create an empty DOM node (container) with a unique ID in your payment form: ```html
``` When the previous form loads, create an instance of the Payment Element and mount it to the container DOM node. Pass the [client secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) from the previous step into `options` when you create the [Elements](https://docs.stripe.com/js/elements_object/create) instance: Handle the client secret carefully because it can complete the charge. Don’t log it, embed it in URLs, or expose it to anyone but the customer. ```javascript const options = { clientSecret: '{{CLIENT_SECRET}}', // Fully customizable with appearance API. appearance: {/*...*/}, }; // Set up Stripe.js and Elements to use in checkout form, passing the client secret obtained in a previous stepconst elements = stripe.elements(options); // Optional: Autofill user's saved payment methods. If the customer's // email is known when the page is loaded, you can pass the email // to the linkAuthenticationElement on mount: // // linkAuthenticationElement.mount("#link-authentication-element", { // defaultValues: { // email: 'jenny.rosen@example.com', // } // }) // Create and mount the Payment Element const paymentElementOptions = { layout: 'accordion'}; const paymentElement = elements.create('payment', paymentElementOptions); paymentElement.mount('#payment-element'); ``` #### React ### Set up Stripe.js Install [React Stripe.js](https://www.npmjs.com/package/@stripe/react-stripe-js) and the [Stripe.js loader](https://www.npmjs.com/package/@stripe/stripe-js) from the npm public registry: ```bash npm install --save @stripe/react-stripe-js @stripe/stripe-js ``` ### Add and configure the Elements provider to your payment page To use the Payment Element component, wrap your checkout page component in an [Elements provider](https://docs.stripe.com/sdks/stripejs-react.md#elements-provider). Call `loadStripe` with your publishable key, and pass the returned `Promise` to the `Elements` provider. Also pass the [client secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) from the previous step as `options` to the `Elements` provider. ```jsx import React from 'react'; import ReactDOM from 'react-dom'; import {Elements} from '@stripe/react-stripe-js'; import {loadStripe} from '@stripe/stripe-js'; import CheckoutForm from './CheckoutForm'; // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>'); function App() { const options = { // passing the client secret obtained in step 3 clientSecret: '{{CLIENT_SECRET}}', // Fully customizable with appearance API. appearance: {/*...*/}, }; return ( ); }; ReactDOM.render(, document.getElementById('root')); ``` ### Add the Payment Element component Use the `PaymentElement` component to build your form: ```jsx import React from 'react'; import {PaymentElement} from '@stripe/react-stripe-js'; const CheckoutForm = () => { return (
// Optional: Autofill user's saved payment methods. If the customer's // email is known when the page is loaded, you can pass the email // to the linkAuthenticationElement // // ); }; export default CheckoutForm; ``` Use [stripe.confirmSetup](https://docs.stripe.com/js/setup_intents/confirm_setup) to complete the setup using details from the Payment Element. This sends an authorization request to the buyer. > `stripe.confirmSetup` might take several seconds to complete while waiting for customers to authorize the payment. During that time, disable your form from being resubmitted and show a waiting indicator like a spinner. If you receive an error, show it to the customer, re-enable the form, and hide the waiting indicator. #### HTML + JS ```javascript const form = document.getElementById('payment-form'); form.addEventListener('submit', async (event) => { event.preventDefault(); const {error, setupIntent} = await stripe.confirmSetup({ //`Elements` instance that was used to create the Payment Element elements, redirect: 'if_required', confirmParams: { mandate_data: { customer_acceptance: { type: 'online', online: { infer_from_client: true, }, }, } } }); const message = document.querySelector('#message') if (error) { // This point will only be reached if there is an immediate error when // confirming the SetupIntent. Show error to your customer (for example, payment // details incomplete) message.innerText = error.message; } else { // This will execute if the confirm request is successful, or if the // setup fails asynchronously. switch (setupIntent.status) { case 'succeeded': message.innerText = 'Success! Payment received.'; break; case 'processing': message.innerText = "Payment processing. We'll update you when payment is received."; break; case 'requires_payment_method': message.innerText = 'Payment failed. Please try another payment method.'; // Redirect your user back to your payment page to attempt collecting // payment details again break; default: message.innerText = 'Something went wrong.'; break; } } }); ``` #### React To call [stripe.confirmSetup](https://docs.stripe.com/js/setup_intents/confirm_setup) from your payment form component, use the [useStripe](https://docs.stripe.com/sdks/stripejs-react.md#usestripe-hook) and [useElements](https://docs.stripe.com/sdks/stripejs-react.md#useelements-hook) hooks. If you prefer traditional class components over hooks, you can use an [ElementsConsumer](https://docs.stripe.com/sdks/stripejs-react.md#elements-consumer) instead. ```jsx import React, {useState} from 'react'; import {useStripe, useElements, PaymentElement} from '@stripe/react-stripe-js'; const CheckoutForm = () => { const stripe = useStripe(); const elements = useElements(); const [message, setMessage] = useState(null); 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 hasn't yet loaded. // Make sure to disable form submission until Stripe.js has loaded. return; } const {error, setupIntent} = await stripe.confirmSetup({ //`Elements` instance that was used to create the Payment Element elements, redirect: 'if_required', confirmParams: { mandate_data: { customer_acceptance: { type: 'online', online: { infer_from_client: true, }, }, } }, }); if (error) { // This point will only be reached if there is an immediate error when // confirming the SetupIntent. Show error to your customer (for example, payment // details incomplete) setMessage(error.message); } else { // This will execute if the confirm request is successful, or if the // setup fails asynchronously. switch (setupIntent.status) { case 'succeeded': setMessage('Success! Authorization received.'); break; case 'requires_payment_method': setMessage('Setup failed. Please try another payment method.'); // Redirect your user back to your payment page to attempt collecting // payment details again break; default: setMessage('Something went wrong.'); break; } } }; return (
{/* Show message to your customers */} {message &&
{message}
} ) }; export default CheckoutForm; ``` ## Charge the PayTo PaymentMethod later Before you can charge your customer, find the mandate ID, customer ID, and payment method ID by [retrieving](https://docs.stripe.com/api/setup_intents/retrieve.md) the previous SetupIntent. ```curl curl https://api.stripe.com/v1/setup_intents/{{SETUPINTENT_ID}} \ -u "<>:" ``` View the necessary IDs in the response below. #### Json ```json { // ... "customer": "cus_PW6rQWRGAaBD7z", // <---- Here is the customer "mandate": "mandate_1Ok6ZrA8DuEjWaGw2nrO9xeS", // <---- Here is the mandate "metadata": {}, "next_action": null, "on_behalf_of": null, "payment_method": "pm_1Ok4l9A8DuEjWaGwhB4SGrWh", // <---- Here is the payment method "payment_method_configuration_details": null, "payment_method_options": { "payto": { "mandate_options": { "amount": 150000, "amount_type": "maximum", "start_date": "2026-12-25", "end_date": "2036-12-25", "payment_schedule": "annual", "payments_per_period": 13, "purpose": "mortgage", } } }, "payment_method_types": [ "payto" ], "single_use_mandate": null, "status": "succeeded", "usage": "off_session" // ... } ``` Create a *PaymentIntent* (API object that represents your intent to collect payment from a customer, tracking charge attempts and payment state changes throughout the process) with the PaymentMethod, Mandate, and Customer IDs. ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]"=payto \ -d amount=1099 \ -d currency=aud \ -d customer="{{CUSTOMER_ID}}" \ -d payment_method="{{PAYMENTMETHOD_ID}}" \ -d mandate="{{MANDATE_ID}}" \ -d confirm=true ``` ## Test your integration Test your PayTo integration with your test API keys by using the various test PayIDs and bank account details below. Each set of details results in a different scenario your integration might commonly face in live mode. #### PayID | PayID | Description | | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `{any_prefix}+succeed@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `succeeded` after an additional 5 seconds. The mandate enters an `active` state. | | `{any_prefix}+decline@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and an `invalid_authorization` decline code. The mandate enters an `inactive` state. | | `{any_prefix}+expire@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and a `generic_decline` decline code. The mandate enters an `inactive` state. | | `{any_prefix}+insufficient_funds@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `requires_payment_method` after an additional 5 seconds. Stripe returns the `payment_method_provider_decline` error code and an `insufficient_funds` decline code. The mandate enters an `inactive` state. | | `{any_prefix}+revoke@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds then to `succeeded` after a further 5 seconds. The mandate begins in an `active` state and transitions to `inactive` after 1 minute. | | `{any_prefix}+agreement_type_not_supported@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code. The mandate enters an `inactive` state. | #### Account + BSB numbers | BSB number | Account number | Description | | ---------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `000000` | `000123456` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `succeeded` after an additional 5 seconds. The mandate enters an `active` state. | | `000000` | `333333335` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and an `invalid_authorization` decline code. The mandate enters an `inactive` state. | | `000000` | `333333337` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and a `generic_decline` decline code. The mandate enters an `inactive` state. | | `000000` | `222222227` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `requires_payment_method` after an additional 5 seconds. Stripe returns the `payment_method_provider_decline` error code and an `insufficient_funds` decline code. The mandate enters an `inactive` state. | | `000000` | `444444447` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `succeeded` after an additional 5 seconds. The mandate begins in an `active` state and transitions to `inactive` after 1 minute. | | `000000` | `666666667` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code. The mandate enters an `inactive` state. | ## Optional: Handle post-payment events Stripe sends a [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) event when the payment completes. Use the Dashboard, a custom *webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests), or a partner solution to receive these events and run actions, like sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events also helps you accept more payment methods in the future. Learn about the [differences between all supported payment methods](https://stripe.com/payments/payment-methods-guide). - **Handle events manually in the Dashboard** Use the Dashboard to [View your test payments in the Dashboard](https://dashboard.stripe.com/test/payments), send email receipts, handle payouts, or retry failed payments. - **Build a custom webhook** [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI. - **Integrate a prebuilt app** Handle common business events, such as [automation](https://stripe.partners/?f_category=automation) or [marketing and sales](https://stripe.partners/?f_category=marketing-and-sales), by integrating a partner application. # Direct API > This is a Direct API for when payment-ui is direct-api. View the full page at https://docs.stripe.com/payments/payto/set-up-payment?payment-ui=direct-api. ## Set up Stripe [Server-side] First, you need a Stripe account. [Register now](https://dashboard.stripe.com/register). To access the Stripe API from your application, use our official libraries: #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## Create a Customer [Server-side] Create a *Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments) after they create an account with your business and associate it with your internal representation of their account. This enables you to retrieve and use their saved payment method details later. ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d name="Jenny Rosen" \ --data-urlencode email="jenny@example.com" ``` ## Create a SetupIntent [Server-side] A [SetupIntent](https://docs.stripe.com/api/setup_intents/object.md) is an object that represents your intent to collect a future payment from a customer and tracks the authorization process. To create a SetupIntent that accepts a PayTo payment method, specify the terms of the mandate, and `payto` in the [payment_method_types](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_types) list. If you maintain a list of payment method types that you pass when creating a SetupIntent, add `payto` to it. Specify the terms of the mandate you want your customer to agree to using [payment method options](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_options-payto). ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]"=payto \ -d customer="{{CUSTOMER_ID}}" \ -d "payment_method_options[payto][mandate_options][amount_type]"=maximum \ -d "payment_method_options[payto][mandate_options][payment_schedule]"=annual \ -d "payment_method_options[payto][mandate_options][amount]"=150000 \ -d "payment_method_options[payto][mandate_options][payments_per_period]"=13 \ -d "payment_method_options[payto][mandate_options][start_date]"=2026-12-25 \ -d "payment_method_options[payto][mandate_options][end_date]"=2036-12-25 \ -d "payment_method_options[payto][mandate_options][purpose]"=mortgage ``` Stripe supports various types of mandates, with controls for the amount, duration, cadence, and purpose of the mandate. Specify mandate terms that match your requirements as closely as possible—customers see these precise terms at authorization time, so accuracy can improve your conversion rate. Stripe infers the default `purpose` based on your *merchant category code (MCC)* (A Merchant Category Code (MCC) is a four-digit number that classifies the type of goods or services a business offers). Override this field using [any of the valid values](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-payto-mandate_options-purpose) if the default value doesn’t accurately represent the purpose of the mandate. You can inspect the default value on the [Mandate](https://docs.stripe.com/api/mandates/object.md#mandate_object-payment_method_details-payto) object when you don’t specify the purpose. ### Retrieve the client secret The SetupIntent includes a *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) that the client side uses to securely complete the payment process. You can use different approaches to pass the client secret to the client side. #### Single-page application Retrieve the client secret from an endpoint on your server, using the browser’s `fetch` function. This approach is best if your client side is a single-page application, particularly one built with a modern frontend framework like React. Create the server endpoint that serves the client secret: #### Ruby ```ruby get '/secret' do intent = # ... Create or retrieve the SetupIntent {client_secret: intent.client_secret}.to_json end ``` And then fetch the client secret with JavaScript on the client side: ```javascript (async () => { const response = await fetch('/secret'); const {client_secret: clientSecret} = await response.json(); // Render the form using the clientSecret })(); ``` #### Server-side rendering Pass the client secret to the client from your server. This approach works best if your application generates static content on the server before sending it to the browser. Add the [client_secret](https://docs.stripe.com/api/setup_intents/object.md#setup_intent_object-client_secret) in your checkout form. In your server-side code, retrieve the client secret from the SetupIntent: #### Ruby ```erb
``` ```ruby get '/checkout' do @intent = # ... Fetch or create the SetupIntent erb :checkout end ``` ## Collect payment method details and submit the request for authorization [Client-side] When you confirm the SetupIntent, pass in the client secret. > Handle the client secret carefully, because it allows access to the SetupIntent. Don’t log it, embed it in URLs, or expose it to anyone but the customer. Use `stripe.confirmPayToSetup` to initiate the mandate authorization with your customer. The customer receives a notification about the mandate request, and authorizes or declines the request in their banking app. ```javascript // Inititates the mandate request notification to the customer stripe.confirmPayToSetup( '{{SETUP_INTENT_CLIENT_SECRET}}', { payment_method: { payto: { // Either provide a PayID (typically an email or phone number) pay_id: 'jenny@example.com' // ...or provide bank account details account_number: '000123456', bsb_number: '000000' } } } ).then(function(result) { if (result.error) { // Inform the customer that there was an error. console.log(result.error.message); } }); ``` By default, Stripe.js polls for updates to the SetupIntent. The promise returned by `confirmPayToSetup` resolves when the SetupIntent reaches the `succeeded` state, or when the setup fails and the SetupIntent returns to the `requires_payment_method` state. See the [SetupIntent lifecycle](https://docs.stripe.com/payments/paymentintents/lifecycle.md) for details on how these transitions happen. To poll yourself, disable automatic polling by setting `handleActions: false`: ```javascript stripe.confirmPayToSetup( '{{SETUP_INTENT_CLIENT_SECRET}}', { payment_method: { payto: { account_number: '000123456', bsb_number: '000000' } } } { handleActions: false } // <---- Like this ) ``` In this case, call the [SetupIntents API](https://docs.stripe.com/api/setup_intents/retrieve.md) to fetch the status of the SetupIntent yourself. ## Charge the PayTo PaymentMethod later ```curl curl https://api.stripe.com/v1/setup_intents/{{SETUPINTENT_ID}} \ -u "<>:" ``` View the necessary IDs in the response below. #### Json ```json { // ... "customer": "cus_PW6rQWRGAaBD7z", // <---- Here is the customer "mandate": "mandate_1Ok6ZrA8DuEjWaGw2nrO9xeS", // <---- Here is the mandate "metadata": {}, "next_action": null, "on_behalf_of": null, "payment_method": "pm_1Ok4l9A8DuEjWaGwhB4SGrWh", // <---- Here is the payment method "payment_method_configuration_details": null, "payment_method_options": { "payto": { "mandate_options": { "amount": 150000, "amount_type": "maximum", "start_date": "2026-12-25", "end_date": "2036-12-25", "payment_schedule": "annual", "payments_per_period": 13, "purpose": "mortgage", } } }, "payment_method_types": [ "payto" ], "single_use_mandate": null, "status": "succeeded", "usage": "off_session" // ... } ``` Create a *PaymentIntent* (API object that represents your intent to collect payment from a customer, tracking charge attempts and payment state changes throughout the process) with the PaymentMethod, Mandate, and Customer IDs. ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]"=payto \ -d amount=1099 \ -d currency=aud \ -d customer="{{CUSTOMER_ID}}" \ -d payment_method="{{PAYMENTMETHOD_ID}}" \ -d mandate="{{MANDATE_ID}}" \ -d confirm=true ``` ## Test your integration Test your PayTo integration with your test API keys by using the various test PayIDs and bank account details below. Each set of details results in a different scenario your integration might commonly face in live mode. #### PayID | PayID | Description | | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `{any_prefix}+succeed@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `succeeded` after an additional 5 seconds. The mandate enters an `active` state. | | `{any_prefix}+decline@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and an `invalid_authorization` decline code. The mandate enters an `inactive` state. | | `{any_prefix}+expire@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and a `generic_decline` decline code. The mandate enters an `inactive` state. | | `{any_prefix}+insufficient_funds@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `requires_payment_method` after an additional 5 seconds. Stripe returns the `payment_method_provider_decline` error code and an `insufficient_funds` decline code. The mandate enters an `inactive` state. | | `{any_prefix}+revoke@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds then to `succeeded` after a further 5 seconds. The mandate begins in an `active` state and transitions to `inactive` after 1 minute. | | `{any_prefix}+agreement_type_not_supported@{any_domain}` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code. The mandate enters an `inactive` state. | #### Account + BSB numbers | BSB number | Account number | Description | | ---------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `000000` | `000123456` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `succeeded` after an additional 5 seconds. The mandate enters an `active` state. | | `000000` | `333333335` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and an `invalid_authorization` decline code. The mandate enters an `inactive` state. | | `000000` | `333333337` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code and a `generic_decline` decline code. The mandate enters an `inactive` state. | | `000000` | `222222227` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `requires_payment_method` after an additional 5 seconds. Stripe returns the `payment_method_provider_decline` error code and an `insufficient_funds` decline code. The mandate enters an `inactive` state. | | `000000` | `444444447` | The PaymentIntent status transitions from `requires_action` to `processing` after 10 seconds, then transitions to `succeeded` after an additional 5 seconds. The mandate begins in an `active` state and transitions to `inactive` after 1 minute. | | `000000` | `666666667` | The PaymentIntent status transitions from `requires_action` to `requires_payment_method` after 10 seconds. Stripe returns the `payment_method_provider_decline` error code. The mandate enters an `inactive` state. | ## Optional: Handle post-payment events Stripe sends a [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) event when the payment completes. Use the Dashboard, a custom *webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests), or a partner solution to receive these events and run actions, like sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events also helps you accept more payment methods in the future. Learn about the [differences between all supported payment methods](https://stripe.com/payments/payment-methods-guide). - **Handle events manually in the Dashboard** Use the Dashboard to [View your test payments in the Dashboard](https://dashboard.stripe.com/test/payments), send email receipts, handle payouts, or retry failed payments. - **Build a custom webhook** [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI. - **Integrate a prebuilt app** Handle common business events, such as [automation](https://stripe.partners/?f_category=automation) or [marketing and sales](https://stripe.partners/?f_category=marketing-and-sales), by integrating a partner application.