# Set up a subscription with BECS Direct Debit in Australia Learn how to create and charge for a subscription with BECS Direct Debit. > If you’re a new user, use the [Payment Element](https://docs.stripe.com/payments/payment-element.md) instead of using Stripe Elements as described in this guide. The Payment Element provides a low-code integration path with built-in conversion optimizations. For instructions, see [Build a subscription](https://docs.stripe.com/billing/subscriptions/build-subscriptions.md?payment-ui=elements). Use this guide to set up a *subscription* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis) using [BECS Direct Debit](https://docs.stripe.com/payments/au-becs-debit.md) as a payment method. ## 创建产品和价格 [管理平台] [Products](https://docs.stripe.com/api/products.md) 表示您销售的商品或服务。[Prices](https://docs.stripe.com/api/prices.md) 定义对某一产品收费的多少和频率。包括产品成本、接受的货币,以及是一次性还是经常性。如果您只有很少几个产品和价格,则在管理平台中创建和管理即可。 本指南所举示例是一个素材图片服务,向客户收取 15 AUD 的月订阅费。要建立此模型: 1. 转到[产品](https://dashboard.stripe.com/products?active=true) 页面并点击**创建产品**。 1. 输入产品的**名称**。您可以选择性地添加**描述**并上传产品的图片。 1. 选择一个**产品税码**。了解更多关于[产品税码](https://docs.stripe.com/tax/tax-codes.md) 的信息。 1. 选择**定期**。然后输入**15**作为价格,并选择**AUD\**作为货币。 1. 选择是否**将税费包含在价格中**。您可以使用您[税务设置](https://dashboard.stripe.com/test/settings/tax) 中的默认值,也可以手动设置该值。在此示例中,选择**自动**。 1. 选择**每月**作为**计费周期**。 1. 点击**更多定价选项**。然后选择**固定费率**作为本示例的定价模型。了解更多关于[固定费率](https://docs.stripe.com/products-prices/pricing-models.md#flat-rate) 和其他[定价模型](https://docs.stripe.com/products-prices/pricing-models.md) 的信息。 1. 添加一个内部**价格描述**和[查找键](https://docs.stripe.com/products-prices/manage-prices.md#lookup-keys),以便将来组织、查询和更新特定价格。 1. 点击**下一步**。然后点击**添加产品**。 创建完产品和价格后,记录下此价格 ID,后面的步骤中会用到。价格页面会显示此 ID,类似于此:`price_G0FvDp6vZvdwRZ`。 ## 创建 SetupIntent [服务器端] A [SetupIntent](https://docs.stripe.com/api/setup_intents.md) is an object that represents your intent to set up a customer’s payment method for future payments. The `SetupIntent` will track the steps of this set-up process. For BECS Direct Debit, this includes collecting a mandate from the customer and tracking its validity throughout its lifecycle. Create a [SetupIntent](https://docs.stripe.com/api/setup_intents.md) on your server with [payment_method_types](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_types) set to `au_becs_debit`: #### curl ```bash curl https://api.stripe.com/v1/setup_intents \ -u <>: \ -d "payment_method_types[]"="au_becs_debit" ``` The returned `SetupIntent` object contains a `client_secret` property. Pass the client secret to the client-side application to continue with the setup process. ## Collect payment method details and mandate acknowledgment [客户端] You’re ready to collect payment information on the client with [Stripe Elements](https://docs.stripe.com/payments/elements.md). Elements is a set of prebuilt UI components for collecting payment details. Stripe Element 中包含一个 iframe,它通过一个 HTTPS 连接安全地将支付信息发送到 Stripe。结账页面上的地址也必须以 https:// 开头,不能是 http://,否则您的集成不能工作。 您可以在不使用 HTTPS 的情况下测试您的集成。准备好进行真实收款时[启用它](https://docs.stripe.com/security/guide.md#tls)。 ### 设置 Stripe Elements #### HTML + JS Stripe Elements is automatically available as a feature of Stripe.js. Include the Stripe.js script on your payment page by adding it to the `head` of your HTML file. Always load Stripe.js directly from js.stripe.com to remain PCI compliant. Don’t include the script in a bundle or host a copy of it yourself. ```html Payment Setup ``` Create an instance of [Elements](https://docs.stripe.com/js.md#stripe-elements) with the following JavaScript on your payment page: ```javascript const stripe = Stripe('<>'); const elements = stripe.elements(); ``` ### Direct Debit Requests Before you can create a BECS Direct Debit payment, your customer must agree with the Direct Debit Request Service Agreement. They do so by submitting a completed Direct Debit Request (DDR). The approval gives you a mandate to debit their account. The `Mandate` is a record of the permission to debit a payment method. For online mandate acceptance, you can create a form to collect the necessary information. Serve the form over [HTTPS](https://docs.stripe.com/security/guide.md#tls) and capture the following information: | 信息 | 描述 | | ------------------ | ------------------------------------------------------------------------- | | **Account name** | The full name of the account holder | | **BSB number** | The Bank-State-Branch number of the bank account (for example, `123-456`) | | **Account number** | The bank account number (for example, `87654321`) | When collecting a Direct Debit Request, follow our [BECS Direct Debit Terms](https://stripe.com/au-becs/legal) and as part of your checkout form: - Display the exact terms of [Stripe’s DDR service agreement](https://stripe.com/au-becs-dd-service-agreement/legal) either inline on the form, or on a page linked from the form, and identifying it as the “DDR service agreement.” - Make sure the accepted DDR and its accompanying [DDR service agreement](https://stripe.com/au-becs-dd-service-agreement/legal) can be shared with your customer at all times, either as a printed or non-changeable electronic copy (such as email). Stripe hosts this for you. - Display the following standard authorization text for your customer to accept the BECS DDR, where you replace *Rocketship Inc* with your company name. Their acceptance authorizes you to initiate BECS Direct Debit payments from their bank account. > By providing your bank account details, you agree to this Direct Debit Request and the [Direct Debit Request service agreement](https://stripe.com/au-becs-dd-service-agreement/legal), and authorize Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf of *Rocketship Inc* (the “Merchant”) for payments as per the terms of your agreement with the Merchant. You certify that you’re either an account holder or an authorized signatory on the account listed above. The details of the accepted mandate are generated when setting up a [PaymentMethod](https://docs.stripe.com/payments/payment-methods.md) or confirming a `PaymentIntent`. At all times, you should be able to share this mandate—the accepted DDR and its accompanying DDR service agreement—with your customer, either in print or as a non-changeable electronic copy (such as email). Stripe hosts this for you under the `url` property of the `Mandate` object linked to the `PaymentMethod`. ### Add and configure an Australia Bank Account Element The Australia Bank Account Element will help you collect and validate both the BSB number and the account number. It needs a place to live in your payment form. Create empty DOM nodes (containers) with unique IDs in your payment form. Additionally, your customer must read and accept the [Direct Debit Request service agreement](https://stripe.com/au-becs-dd-service-agreement/legal). #### HTML ```html
By providing your bank account details, you agree to this Direct Debit Request and the Direct Debit Request service agreement, and authorise Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf ofRocket Rides(the "Merchant") for any amounts separately communicated to you by the Merchant. You certify that you are either an account holder or an authorised signatory on the account listed above.
``` When the form loads, you can [create an instance](https://docs.stripe.com/js/elements_object/create_element?type=au_bank_account) of the Australia Bank Account Element and mount it to the Element container: ```javascript // Custom styling can be passed to options when creating an Element const style = { base: { color: '#32325d', fontSize: '16px', '::placeholder': { color: '#aab7c4' }, ':-webkit-autofill': { color: '#32325d', }, }, invalid: { color: '#fa755a', iconColor: '#fa755a', ':-webkit-autofill': { color: '#fa755a', }, } }; const options = { style: style, disabled: false, hideIcon: false, iconStyle: "default", // or "solid" } // Create an instance of the auBankAccount Element. const auBankAccount = elements.create('auBankAccount', options); // Add an instance of the auBankAccount Element into // the `au-bank-account-element`
. auBankAccount.mount('#au-bank-account-element'); ``` #### React #### npm 从 npm 公共注册表安装 [React Stripe.js](https://www.npmjs.com/package/@stripe/react-stripe-js) 和 [Stripe.js 加载器](https://www.npmjs.com/package/@stripe/stripe-js)。 ```bash npm install --save @stripe/react-stripe-js @stripe/stripe-js ``` #### umd 对于不使用 npm 或模块的网站,我们也提供了一个 UMD 模块。 包含进 Stripe.js 脚本——它可以导出一个全局 `Stripe` 函数,也包含进 React Stripe.js 的 UMD 模块,它可以导出一个全局 `ReactStripe` 对象。为保持 PCI 合规,始终从 **js.stripe.com** 加载 Stripe.js 脚本。不要把脚本打包或自行保留副本。 ```html ``` > 可通过 [CodeSandbox 内的演示](https://codesandbox.io/s/react-stripe-official-q1loc?fontsize=14&hidenavigation=1&theme=dark)尝试 React Stripe.js,不需要新建项目。 ### 在您的页面添加 Stripe.js 和 Elements 使用 Element 组件时,将您的结账页面包裹到某个 [Elements 提供程序](https://docs.stripe.com/sdks/stripejs-react.md#elements-provider)中。用您的公钥调用 `loadStripe`,并将返回的 `Promise` 传递到 `Elements` 提供程序。 ```jsx import React from 'react'; import ReactDOM from 'react-dom'; import {Elements} from '@stripe/react-stripe-js'; import {loadStripe} from '@stripe/stripe-js'; import PaymentSetupForm from './PaymentSetupForm'; // Make sure to call `loadStripe` outside of a component's render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>'); function App() { return ( ); }; ReactDOM.render(, document.getElementById('root')); ``` ### Direct Debit Requests Before you can create a BECS Direct Debit payment, your customer must agree with the Direct Debit Request Service Agreement. They do so by submitting a completed Direct Debit Request (DDR). The approval gives you a mandate to debit their account. The `Mandate` is a record of the permission to debit a payment method. For online mandate acceptance, you can create a form to collect the necessary information. Serve the form over [HTTPS](https://docs.stripe.com/security/guide.md#tls) and capture the following information: | 信息 | 描述 | | ------------------ | ------------------------------------------------------------------------- | | **Account name** | The full name of the account holder | | **BSB number** | The Bank-State-Branch number of the bank account (for example, `123-456`) | | **Account number** | The bank account number (for example, `87654321`) | When collecting a Direct Debit Request, follow our [BECS Direct Debit Terms](https://stripe.com/au-becs/legal) and as part of your checkout form: - Display the exact terms of [Stripe’s DDR service agreement](https://stripe.com/au-becs-dd-service-agreement/legal) either inline on the form, or on a page linked from the form, and identifying it as the “DDR service agreement.” - Make sure the accepted DDR and its accompanying [DDR service agreement](https://stripe.com/au-becs-dd-service-agreement/legal) can be shared with your customer at all times, either as a printed or non-changeable electronic copy (such as email). Stripe hosts this for you. - Display the following standard authorization text for your customer to accept the BECS DDR, where you replace *Rocketship Inc* with your company name. Their acceptance authorizes you to initiate BECS Direct Debit payments from their bank account. > By providing your bank account details, you agree to this Direct Debit Request and the [Direct Debit Request service agreement](https://stripe.com/au-becs-dd-service-agreement/legal), and authorize Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf of *Rocketship Inc* (the “Merchant”) for payments as per the terms of your agreement with the Merchant. You certify that you’re either an account holder or an authorized signatory on the account listed above. The details of the accepted mandate are generated when setting up a [PaymentMethod](https://docs.stripe.com/payments/payment-methods.md) or confirming a `PaymentIntent`. At all times, you should be able to share this mandate—the accepted DDR and its accompanying DDR service agreement—with your customer, either in print or as a non-changeable electronic copy (such as email). Stripe hosts this for you under the `url` property of the `Mandate` object linked to the `PaymentMethod`. ### Add and configure an AuBankAccountElement component The `AuBankAccountElement` component will help you collect and validate both the BSB number and the account number. Additionally, your customer must read and accept the [Direct Debit Request service agreement](https://stripe.com/au-becs-dd-service-agreement/legal). #### JSX ```jsx /** * Use the CSS tab above to style your Element's container. */ import React from 'react'; import {AuBankAccountElement} from '@stripe/react-stripe-js'; import './BecsFormStyles.css' // Custom styling can be passed as options when creating an Element. const AU_BANK_ACCOUNT_STYLE = { base: { color: '#32325d', fontSize: '16px', '::placeholder': { color: '#aab7c4' }, ':-webkit-autofill': { color: '#32325d', }, }, invalid: { color: '#fa755a', iconColor: '#fa755a', ':-webkit-autofill': { color: '#fa755a', }, } }; const AU_BANK_ACCOUNT_ELEMENT_OPTIONS = { style: AU_BANK_ACCOUNT_STYLE, disabled: false, hideIcon: false, iconStyle: "default", // or "solid" }; export default function BecsForm({onSubmit, disabled}) { return (
{/* Display mandate acceptance text. */}
By providing your bank account details, you agree to this Direct Debit Request and the Direct Debit Request service agreement, and authorise Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf ofRocket Rides(the "Merchant") for any amounts separately communicated to you by the Merchant. You certify that you are either an account holder or an authorised signatory on the account listed above.
``` Elements are completely customizable. You can [style Elements](https://docs.stripe.com/js/elements_object/create_element?type=au_bank_account#elements_create-options) to match the look and feel of your site, providing a seamless checkout experience for your customers. It’s also possible to style various input states, for example when the Element has focus. ## Submit the payment method details to Stripe [客户端] Rather than sending the entire `SetupIntent` object to the client, use its [client secret](https://docs.stripe.com/api/setup_intents/object.md#setup_intent_object-client_secret) from [step 2](https://docs.stripe.com/billing/subscriptions/au-becs-debit.md#web-create-setup-intent). This is different from your API keys that authenticate Stripe API requests. The client secret should be handled carefully because it can complete the setup. Don’t log it, embed it in URLs, or expose it to anyone but the customer. #### HTML + JS Use [stripe.confirmAuBecsDebitSetup](https://docs.stripe.com/js/setup_intents/confirm_au_becs_debit_setup) to complete the setup when the user submits the form. A successful setup returns a `succeeded` value for the SetupIntent’s `status` property. If the setup isn’t successful, inspect the returned `error` to determine the cause. ```javascript const form = document.getElementById('setup-form'); const accountholderName = document.getElementById('accountholder-name'); const email = document.getElementById('email'); const submitButton = document.getElementById('submit-button'); const clientSecret = submitButton.dataset.secret; form.addEventListener('submit', async (event) => { event.preventDefault(); stripe.confirmAuBecsDebitSetup( clientSecret, { payment_method: { au_becs_debit: auBankAccount, billing_details: { name: accountholderName.value, email: email.value } } } ); }); ``` After successfully confirming the `SetupIntent`, you should share the [mandate URL](https://docs.stripe.com/api/mandates/object.md#mandate_object-payment_method_details-au_becs_debit-url) from the [Mandate object](https://docs.stripe.com/api/mandates.md) with your customer. We also recommend including the following details to your customer when you confirm their mandate has been established: - an explicit confirmation message that indicates a Direct Debit arrangement has been set up - the [business name](https://docs.stripe.com/billing/subscriptions/au-becs-debit.md#statement-descriptors) that will appear on the customer’s bank statement whenever their account gets debited - the payment amount and schedule (if applicable) - a link to the generated DDR mandate URL The `Mandate` object’s ID is accessible from the `mandate` on the SetupIntent object, which is sent as part of the `setup_intent.succeeded` event sent after confirmation, but can also be [retrieved through the API](https://docs.stripe.com/api/setup_intents/retrieve.md). ```curl curl -G https://api.stripe.com/v1/setup_intents/{{SETUP_INTENT_ID}} \ -u "<>:" \ -d "expand[]=mandate" ``` #### React Use [stripe.confirmAuBecsDebitSetup](https://docs.stripe.com/js/setup_intents/confirm_au_becs_debit_setup) to complete the mandate collection when the user submits the form. Including the customer’s email address and the account holder’s name in the `billing_details` property of the `payment_method` parameter is required to create a BECS Direct Debit `PaymentMethod`. To call `stripe.confirmAuBecsDebitSetup` from your payment form component, use the [useStripe](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 instead use an [ElementsConsumer](https://docs.stripe.com/sdks/stripejs-react.md#elements-consumer). #### Hooks ```jsx import React from 'react'; import {useStripe, useElements, AuBankAccountElement} from '@stripe/react-stripe-js'; import BecsForm from './BecsForm'; export default function PaymentSetupForm() { const stripe = useStripe(); const elements = useElements(); const handleSubmit = async (event) => { // We don't want to let default form submission happen here, // which would refresh the page. event.preventDefault(); if (!stripe || !elements) { // Stripe.js hasn't yet loaded. // Make sure to disable form submission until Stripe.js has loaded. return; } const auBankAccount = elements.getElement(AuBankAccountElement); // For brevity, this example is using uncontrolled components for // the accountholder's name and email. In a real world app you will // probably want to use controlled components. // https://reactjs.org/docs/uncontrolled-components.html // https://reactjs.org/docs/forms.html#controlled-components const accountholderName = event.target['accountholder-name']; const email = event.target.email; const result = await stripe.confirmAuBecsDebitSetup('{{CLIENT_SECRET}}', { payment_method: { au_becs_debit: auBankAccount, billing_details: { name: accountholderName.value, email: email.value, }, } }); if (result.error) { // Show error to your customer. console.log(result.error.message); } else { // Show a confirmation message to your customer. // The SetupIntent is in the 'succeeded' state. } }; return ( ); } ``` #### Class Components ```jsx import React from 'react'; import {ElementsConsumer, AuBankAccountElement} from '@stripe/react-stripe-js'; import BecsForm from './BecsForm'; class PaymentSetupForm extends React.Component { handleSubmit = async (event) => { // We don't want to let default form submission happen here, // which would refresh the page. event.preventDefault(); const {stripe, elements} = this.props; if (!stripe || !elements) { // Stripe.js hasn't yet loaded. // Make sure to disable form submission until Stripe.js has loaded. return; } const auBankAccount = elements.getElement(AuBankAccountElement); // For brevity, this example is using uncontrolled components for // the accountholder's name and email. In a real world app you will // probably want to use controlled components. // https://reactjs.org/docs/uncontrolled-components.html // https://reactjs.org/docs/forms.html#controlled-components const accountholderName = event.target['accountholder-name']; const email = event.target.email; const result = await stripe.confirmAuBecsDebitSetup('{{CLIENT_SECRET}}', { payment_method: { au_becs_debit: auBankAccount, billing_details: { name: accountholderName.value, email: email.value, }, } }); if (result.error) { // Show error to your customer. console.log(result.error.message); } else { // Show a confirmation message to your customer. // The SetupIntent is in the 'succeeded' state. } }; render() { const {stripe} = this.props; return ( ); } } export default function InjectedPaymentSetupForm() { return ( {({stripe, elements}) => ( )} ); } ``` After successfully confirming the `SetupIntent`, you should share the [mandate URL](https://docs.stripe.com/api/mandates/object.md#mandate_object-payment_method_details-au_becs_debit-url) from the [Mandate object](https://docs.stripe.com/api/mandates.md) with your customer. We also recommend including the following details to your customer when you confirm their mandate has been established: - an explicit confirmation message that indicates a Direct Debit arrangement has been set up - the [business name](https://docs.stripe.com/billing/subscriptions/au-becs-debit.md#statement-descriptors) that will appear on the customer’s bank statement whenever their account gets debited - the payment amount and schedule (if applicable) - a link to the generated DDR mandate URL The `Mandate` object’s ID is accessible from the `mandate` on the SetupIntent object, which is sent as part of the `setup_intent.succeeded` event sent after confirmation, but can also be [retrieved through the API](https://docs.stripe.com/api/setup_intents/retrieve.md). ```curl curl -G https://api.stripe.com/v1/setup_intents/{{SETUP_INTENT_ID}} \ -u "<>:" \ -d "expand[]=mandate" ``` ## Create a customer with a PaymentMethod [服务器端] Creating *subscriptions* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis) requires a [customer](https://docs.stripe.com/api.md#customer_object), which represents the customer purchasing your product. Because the price you created charges on a monthly basis, you need to add a stored payment method to the customer so future payments are successful. You do this by setting the payment method you just collected at the top level of the *Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments) object and as the [default payment method](https://docs.stripe.com/api/customers/create.md#create_customer-invoice_settings-default_payment_method) for *invoices* (Invoices are statements of amounts owed by a customer. They track the status of payments from draft through paid or otherwise finalized. Subscriptions automatically generate invoices, or you can manually create a one-off invoice): ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ --data-urlencode "email=jenny.rosen@example.com" \ -d payment_method=pm_1FU2bgBF6ERF9jhEQvwnA7sX \ -d "invoice_settings[default_payment_method]=pm_1FU2bgBF6ERF9jhEQvwnA7sX" ``` This returns a `Customer` object. You can see the default payment method in the `invoice_settings` object: ```json { "id": "cus_Gk0uVzT2M4xOKD", "object": "customer", "address": null, "balance": 0, "created": 1581797088, "currency": null, "default_source": null, "delinquent": false, "description": null, "discount": null, "email": "jenny.rosen@example.com", "invoice_prefix": "11D0B3D7", "invoice_settings": { "custom_fields": null, "default_payment_method": "pm_1FU2bgBF6ERF9jhEQvwnA7sX", "footer": null }, "livemode": false, "metadata": { }, "name": null, "phone": null, "preferred_locales": [ ], "shipping": null, "sources": { "object": "list", "data": [ ], "has_more": false, "total_count": 0, "url": "/v1/customers/cus_Gk0uVzT2M4xOKD/sources" }, "subscriptions": { "object": "list", "data": [ ], "has_more": false, "total_count": 0, "url": "/v1/customers/cus_Gk0uVzT2M4xOKD/subscriptions" }, "tax_exempt": "none", "tax_ids": { "object": "list", "data": [ ], "has_more": false, "total_count": 0, "url": "/v1/customers/cus_Gk0uVzT2M4xOKD/tax_ids" } } ``` After creating the customer, store the `id` value in your own database so you can use it later. The next step also requires this ID. ## 创建订阅 [服务器端] Create a [subscription](https://docs.stripe.com/api/subscriptions.md) with the price and customer: ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d customer=cus_Gk0uVzT2M4xOKD \ -d "items[0][price]=price_F52b2UdntfQsfR" ``` Creating subscriptions automatically charges customers because the [default payment method](https://docs.stripe.com/api/customers/create.md#create_customer-invoice_settings-default_payment_method) is set. After a successful payment, the status in the [Stripe Dashboard](https://dashboard.stripe.com/test/subscriptions) changes to **Active**. The price you created earlier determines subsequent billings. ## Manage subscription status [客户端] When the initial payment succeeds, the status of the *subscription* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis) is `active` and no further action is needed. When payments fail, the status is changed to the **Subscription status** configured in your [automatic collection settings](https://docs.stripe.com/invoicing/automatic-collection.md). Notify the customer after a failure and [charge them with a different payment method](https://docs.stripe.com/billing/subscriptions/overview.md#requires-payment-method). > BECS Direct Debit payments are never automatically retried, even if you have a [retry schedule](https://docs.stripe.com/invoicing/automatic-collection.md) configured for other payment methods. ## 测试集成 You can test your form using the test BSB number `000000` and one of the test account numbers below with your [confirmAuBecsDebitSetup](https://docs.stripe.com/js/setup_intents/confirm_au_becs_debit_setup) request. | BSB 号码 | 账号 | 描述 | | -------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------- | | `000000` | `000123456` | 用生成的 PaymentMethod 创建的 PaymentIntent 从 `processing` 变为 `succeeded`。授权状态仍为 `active`。 | | `000000` | `900123456` | 用生成的 PaymentMethod 创建的 PaymentIntent 从 `processing` 变为 `succeeded`(延迟三分钟)。授权状态仍为 `active`。 | | `000000` | `111111113` | 用生成的 PaymentMethod 创建的 PaymentIntent 将从 `processing` 变为 `requires_payment_method`,并显示 `account_closed` 失败代码。此时,授权状态变为 `inactive`。 | | `000000` | `111111116` | 用生成的 PaymentMethod 创建的 PaymentIntent 从 `processing` 变为 `requires_payment_method`,并显示 `no_account` 失败代码。此时,授权状态变为 `inactive`。 | | `000000` | `222222227` | 用生成的 PaymentMethod 创建的 PaymentIntent 从 `processing` 变为 `requires_payment_method`,并显示 `refer_to_customer` 失败代码。授权状态仍为 `active`。 | | `000000` | `922222227` | 用生成的 PaymentMethod 创建的 PaymentIntent 从 `processing` 变为 `requires_payment_method`,并显示 `refer_to_customer` 失败代码(延迟三分钟)。授权状态仍为 `active`。 | | `000000` | `333333335` | 用生成的 PaymentMethod 创建的 PaymentIntent 从 `processing` 变为 `requires_payment_method`,并显示 `debit_not_authorized` 失败代码。此时,授权状态变为 `inactive`。 | | `000000` | `666666660` | 用生成的 PaymentMethod 创建的 PaymentIntent 从 `processing` 变为 `succeeded`,但会立即创建争议。 | | `000000` | `343434343` | 由于支付金额导致账户超过了其每周交易限额,用生成的 PaymentMethod 创建的 PaymentIntent 失败,显示 `charge_exceeds_source_limit` 错误。 | | `000000` | `121212121` | 由于支付金额超过账户的交易限额,用生成的 PaymentMethod 创建的 PaymentIntent 失败,显示 `charge_exceeds_transaction_limit` 错误。 | ## Optional: Set the billing period 创建订阅时,默认会自动设置计费周期。例如,某客户在 9 月 7 日订阅了一个月度方案,则之后每月 7 日向其扣款。有些公司喜欢手动设置计费周期,以便在每个周期的同一时间对客户扣款。[billing cycle anchor](https://docs.stripe.com/api/subscriptions/create.md#create_subscription-billing_cycle_anchor) 参数可用来进行这种操作。 ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d "customer={{CUSTOMER_ID}}" \ -d "items[0][price]={{PRICE_ID}}" \ -d billing_cycle_anchor=1611008505 ``` 手动设置计费周期会在创建订阅和计费周期锚之间的时间内自动按比例向客户收取费用。如果此时不想向客户收款,可以将 [proration_behavior](https://docs.stripe.com/api/subscriptions/create.md#create_subscription-proration_behavior) 参数设置为 `none`。还可以将计费周期锚与[试用期](https://docs.stripe.com/billing/subscriptions/au-becs-debit.md#trial-periods)结合起来使用,让用户免费使用您的产品,然后按比例向其收取费用。 ## Optional: 订阅试用 免费试用允许客户在一段时间内免费使用您的产品。使用免费试用并非就是将 [proration_behavior](https://docs.stripe.com/api/subscriptions/create.md#create_subscription-proration_behavior) 设置为 `none`,因为您可以自定义免费期的长度。在 [trial end](https://docs.stripe.com/api/subscriptions/create.md#create_subscription-trial_end) 中传递一个时间戳来设置试用期。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "items[0][price]={{PRICE_ID}}" \ -d trial_end=1610403705 ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d "customer={{CUSTOMER_ID}}" \ -d "items[0][price]={{PRICE_ID}}" \ -d trial_end=1610403705 ``` 还可以将[计费周期锚](https://docs.stripe.com/billing/subscriptions/au-becs-debit.md#billing-cycle)与免费试用组合使用。例如,假设今天是 9 月 15 日,您想给客户免费试用七天,然后在 10 月 1 日开启正常的计费周期。则便可以将免费试用设置为 9 月 22 日结束,计费周期锚定为 10 月 1 日。这便为客户提供了七天的免费试用期,然后在试用期结束之日和 10 月 1 日之间按比例收取费用。在 10 月 1 日,向他们收取第一个完整计费周期的正常订阅金额。