# Accept a payment and save a mandate for future PayTo payments Learn how to collect a PayTo payment and authorize future 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 where you get [delayed notification](https://docs.stripe.com/payments/payment-methods.md#payment-notification) on whether the payment succeeded or failed. Setting up a PayTo mandate for future payments allows you to collect future recurring payments without needing customer authorization again. 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/save-during-payment?payment-ui=checkout. > Stripe can automatically present the relevant payment methods to your customers by evaluating currency, payment method restrictions, and other parameters. > > - Follow the [Accept a payment](https://docs.stripe.com/payments/accept-a-payment.md?payment-ui=checkout&ui=stripe-hosted) guide to build a Checkout integration that uses [dynamic payment methods](https://docs.stripe.com/payments/payment-methods/dynamic-payment-methods.md). - If you don’t want to use dynamic payment methods, follow the steps below to manually configure the payment methods in your Checkout integration. ## Determine compatibility **Customer Geography**: Australia **Supported currencies**: `aud` **Presentment currencies**: `aud` **Payment mode**: Yes **Setup mode**: Yes **Subscription mode**: Yes To support PayTo payments in Checkout, express all *Prices* (Prices define how much and how often to charge for products. This includes how much the product costs, what currency to use, and the interval if the price is for subscriptions) for all line items in AUD (currency code `aud`). ## Accept a payment > This guide builds on the foundational [accept a payment](https://docs.stripe.com/payments/accept-a-payment.md?ui=stripe-hosted) Checkout integration. To enable Payto as a payment method, create a new [Checkout Session](https://docs.stripe.com/api/checkout/sessions.md): 1. Add `payto` to the list of `payment_method_types`. 1. Make sure all your `line_items` use the `aud` currency. 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). #### Stripe-hosted page ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price_data][currency]"=aud \ -d "line_items[0][price_data][product_data][name]"=T-shirt \ -d "line_items[0][price_data][unit_amount]"=2000 \ -d "line_items[0][quantity]"=1 \ -d mode=payment \ -d "payment_method_options[payto][mandate_options][amount]"=10000 \ -d "payment_method_options[payto][mandate_options][amount_type]"=maximum \ -d "payment_method_options[payto][mandate_options][payment_schedule]"=adhoc \ -d "payment_method_options[payto][setup_future_usage]"=off_session \ -d "payment_method_types[0]"=card \ -d "payment_method_types[1]"=payto \ --data-urlencode success_url="https://example.com/success" ``` #### Embedded form ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price_data][currency]"=aud \ -d "line_items[0][price_data][product_data][name]"=T-shirt \ -d "line_items[0][price_data][unit_amount]"=2000 \ -d "line_items[0][quantity]"=1 \ -d mode=payment \ -d "payment_method_options[payto][mandate_options][amount]"=10000 \ -d "payment_method_options[payto][mandate_options][amount_type]"=maximum \ -d "payment_method_options[payto][mandate_options][payment_schedule]"=adhoc \ -d "payment_method_options[payto][setup_future_usage]"=off_session \ -d "payment_method_types[0]"=card \ -d "payment_method_types[1]"=payto \ --data-urlencode return_url="https://example.com/return" \ -d ui_mode=embedded ``` ### 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/save-during-payment?payment-ui=elements. To accept PayTo payments, create a [PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) object to track a payment, collect payment method details, then submit the payment to Stripe for processing. Stripe uses the PaymentIntent to track and handle all the states of the payment until the payment completes. Use the ID of the [Mandate](https://docs.stripe.com/api/mandates.md) collected from your initial PayTo PaymentIntent to create future payments. ## 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 PaymentIntent [Server-side] Create a PaymentIntent on your server and specify the `amount` to collect, the `aud` currency, the customer ID, and `off_session` as an argument for [setup future usage](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-setup_future_usage). The minimum charge amount is 0.50 AUD and PayTo doesn’t support other currencies. If you have an existing [Payment Intents API](https://docs.stripe.com/payments/payment-intents.md) integration, add `payto` to the list of [payment method types](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types). You can specify the terms of the mandate for your customer’s consent in the [PayTo payment method options](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-payto). > The payment method options `amount` must match the PaymentIntent `amount` unless you set the `amount_type` to `maximum`, in which case you can set payment method options value that’s higher than the PaymentIntent. The following code sample shows a PaymentIntent amount of 10 AUD and a payment method options amount of 1500 AUD because the `amount_type` is `maximum`. ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1000 \ -d currency=aud \ -d "payment_method_types[]"=payto \ -d customer={{CUSTOMER_ID}} \ -d setup_future_usage=off_session \ -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][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 PaymentIntent 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 PaymentIntent {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/payment_intents/object.md#payment_intent_object-client_secret) in your checkout form. In your server-side code, retrieve the client secret from the PaymentIntent: #### Ruby ```erb
``` ```ruby get '/checkout' do @intent = # ... Fetch or create the PaymentIntent erb :checkout end ``` ## Collect payment method details and submit the payment [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.confirmPayment](https://docs.stripe.com/js/payment_intents/confirm_payment) to complete the payment using details from the Payment Element. This sends an authorization request to the buyer. > `stripe.confirmPayment` 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, paymentIntent} = await stripe.confirmPayment({ //`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 payment. 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 // payment fails asynchronously. switch (paymentIntent.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 again break; default: message.innerText = 'Something went wrong.'; break; } } }); ``` #### React To call [stripe.confirmPayment](https://docs.stripe.com/js/payment_intents/confirm_payment) 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, paymentIntent} = await stripe.confirmPayment({ //`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 payment. 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 // payment fails asynchronously. switch (paymentIntent.status) { case 'succeeded': setMessage('Success! Payment received.'); break; case 'processing': setMessage("Payment processing. We'll update you when payment is received."); break; case 'requires_payment_method': setMessage('Payment failed. Please try another payment method.'); // Redirect your user back to your payment page to attempt collecting // payment again break; default: setMessage('Something went wrong.'); break; } } }; return (
{/* Show message to your customers */} {message &&
{message}
} ) }; export default CheckoutForm; ``` ## Charge the PayTo PaymentMethod later When you need to charge your customer again, create a new PaymentIntent. To find the mandate ID, customer ID, and payment method ID, [retrieve](https://docs.stripe.com/api/payment_intents/retrieve.md) the previous PaymentIntent and [expand](https://docs.stripe.com/api/expanding_objects.md) the `latest_charge` field. ```curl curl -G https://api.stripe.com/v1/payment_intents/{{PAYMENT_INTENT_ID}} \ -u "<>:" \ -d "expand[]"=latest_charge ``` View the necessary IDs in the response below. #### Json ```json { // ... "customer": "cus_PW6rQWRGAaBD7z", // <---- Here's the customer "latest_charge": { "payment_method": "pm_1Ok4l9A8DuEjWaGwhB4SGrWh", // <---- Here's the payment method "payment_method_details": { "payto": { "bsb_number": null, "last4": null, "mandate": "mandate_1Ok4lVA8DuEjWaGwu0uTwI94", // <----- Here's the mandate "pay_id": "jenny@example.com" }, "type": "payto" }, }, "payment_method_types": [ "payto" ], // ... } ``` Create a PaymentIntent 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). ### Receive events and run business actions There are a few options for receiving and running business actions. #### Manually Use the Stripe Dashboard to view all your Stripe payments, send email receipts, handle payouts, or retry failed payments. - [View your test payments in the Dashboard](https://dashboard.stripe.com/test/payments) #### Custom code Build a webhook handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI. - [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) #### Prebuilt apps Handle common business events, like [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/save-during-payment?payment-ui=direct-api. To accept PayTo payments, create a [PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) object to track a payment, collect payment method details, then submit the payment to Stripe for processing. Stripe uses the PaymentIntent to track and handle all the states of the payment until the payment completes. Use the ID of the [Mandate](https://docs.stripe.com/api/mandates.md) collected from your initial PayTo PaymentIntent to create future payments. ## 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 PaymentIntent [Server-side] Create a PaymentIntent on your server and specify the `amount` to collect, the `aud` currency, the customer ID, and `off_session` as an argument for [setup future usage](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-setup_future_usage). The minimum charge amount is 0.50 AUD and PayTo doesn’t support other currencies. If you have an existing [Payment Intents API](https://docs.stripe.com/payments/payment-intents.md) integration, add `payto` to the list of [payment method types](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types). You can specify the terms of the mandate for your customer’s consent in the [PayTo payment method options](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-payto). > The payment method options `amount` must match the PaymentIntent `amount` unless you set the `amount_type` to `maximum`, in which case you can set payment method options value that’s higher than the PaymentIntent. The following code sample shows a PaymentIntent amount of 10 AUD and a payment method options amount of 1500 AUD because the `amount_type` is `maximum`. ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1000 \ -d currency=aud \ -d "payment_method_types[]"=payto \ -d customer={{CUSTOMER_ID}} \ -d setup_future_usage=off_session \ -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][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 PaymentIntent 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 PaymentIntent {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/payment_intents/object.md#payment_intent_object-client_secret) in your checkout form. In your server-side code, retrieve the client secret from the PaymentIntent: #### Ruby ```erb
``` ```ruby get '/checkout' do @intent = # ... Fetch or create the PaymentIntent erb :checkout end ``` ## Collect payment method details and submit the payment [Client-side] When you confirm the payment, pass in the client secret. > Handle the client secret carefully, because it allows access to the PaymentIntent. Don’t log it, embed it in URLs, or expose it to anyone but the customer. Use `stripe.confirmPayToPayment` 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.confirmPayToPayment( '{{PAYMENT_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 PaymentIntent. The promise returned by `confirmPayToPayment` resolves when the PaymentIntent reaches the `succeeded` state, or when the payment fails and the PaymentIntent returns to the `requires_payment_method` state. See the [PaymentIntent lifecycle](https://docs.stripe.com/payments/paymentintents/lifecycle.md) for details on how these transitions happen. To poll yourself, you can disable automatic polling by setting `handleActions: false`: ```javascript stripe.confirmPayToPayment( '{{PAYMENT_INTENT_CLIENT_SECRET}}', { payment_method: { payto: { account_number: '000123456', bsb_number: '000000' } } }, { handleActions: false } // <---- Like this ) ``` In this case, you can call the [PaymentIntents API](https://docs.stripe.com/api/payment_intents/retrieve.md) to fetch status of the PaymentIntent yourself. ## Charge the PayTo PaymentMethod later When you need to charge your customer again, create a new PaymentIntent. To find the mandate ID, customer ID, and payment method ID, [retrieve](https://docs.stripe.com/api/payment_intents/retrieve.md) the previous PaymentIntent and [expand](https://docs.stripe.com/api/expanding_objects.md) the `latest_charge` field. ```curl curl -G https://api.stripe.com/v1/payment_intents/{{PAYMENT_INTENT_ID}} \ -u "<>:" \ -d "expand[]"=latest_charge ``` View the necessary IDs in the response below. #### Json ```json { // ... "customer": "cus_PW6rQWRGAaBD7z", // <---- Here's the customer "latest_charge": { "payment_method": "pm_1Ok4l9A8DuEjWaGwhB4SGrWh", // <---- Here's the payment method "payment_method_details": { "payto": { "bsb_number": null, "last4": null, "mandate": "mandate_1Ok4lVA8DuEjWaGwu0uTwI94", // <----- Here's the mandate "pay_id": "jenny@example.com" }, "type": "payto" }, }, "payment_method_types": [ "payto" ], // ... } ``` Create a PaymentIntent 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). ### Receive events and run business actions There are a few options for receiving and running business actions. #### Manually Use the Stripe Dashboard to view all your Stripe payments, send email receipts, handle payouts, or retry failed payments. - [View your test payments in the Dashboard](https://dashboard.stripe.com/test/payments) #### Custom code Build a webhook handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI. - [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) #### Prebuilt apps Handle common business events, like [automation](https://stripe.partners/?f_category=automation) or [marketing and sales](https://stripe.partners/?f_category=marketing-and-sales), by integrating a partner application.