# Accept subscription payments with PayTo Learn how to create and charge for a subscription with PayTo. 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 [PayTo](https://docs.stripe.com/payments/payto.md) as a payment method. # SetupIntents API Create and confirm a subscription using two API calls. The [first API call](https://docs.stripe.com/billing/subscriptions/payto.md#create-setup-intent) uses the [Setup Intents API](https://docs.stripe.com/api/setup_intents.md) to set PayTo as a payment method. The [second API call](https://docs.stripe.com/billing/subscriptions/payto.md#create-subscription) sends customer, product, and payment method information to the [Subscriptions API](https://docs.stripe.com/api/subscriptions.md) to create a Subscription and confirm a payment in one call. ## Create a product and price [Dashboard] [Products](https://docs.stripe.com/api/products.md) represent the item or service you’re selling. [Prices](https://docs.stripe.com/api/prices.md) define how much and how frequently you charge for a product. This includes how much the product costs, what currency you accept, and whether it’s a one-time or recurring charge. If you only have a few products and prices, create and manage them in the Dashboard. This guide uses a stock photo service as an example and charges customers a 15 AUD monthly subscription. To model this: 1. Go to the [Products](https://dashboard.stripe.com/products?active=true) page and click **Create product**. 2. Enter a **Name** for the product. You can optionally add a **Description** and upload an image of the product. 3. Select a **Product tax code**. Learn more about [product tax codes](https://docs.stripe.com/tax/tax-codes.md). 4. Select **Recurring**. Then enter **15** for the price and select **AUD** as the currency. 5. Choose whether to **Include tax in price**. You can either use the default value from your [tax settings](https://dashboard.stripe.com/test/settings/tax) or set the value manually. In this example, select **Auto**. 6. Select **Monthly** for the **Billing period**. 7. Click **More pricing options**. Then select **Flat rate** as the pricing model for this example. Learn more about [flat rate](https://docs.stripe.com/products-prices/pricing-models.md#flat-rate) and other [pricing models](https://docs.stripe.com/products-prices/pricing-models.md). 8. Add an internal **Price description** and [Lookup key](https://docs.stripe.com/products-prices/manage-prices.md#lookup-keys) to organize, query, and update specific prices in the future. 9. Click **Next**. Then click **Add product**. After you create the product and the price, record the price ID so you can use it in subsequent steps. The pricing page displays the ID and it looks similar to this: `price_G0FvDp6vZvdwRZ`. ## Create a SetupIntent [Server-side] Create a [SetupIntent](https://docs.stripe.com/api/setup_intents.md) to save a customer’s payment method for future payments. The `SetupIntent` tracks the steps of this setup process. Limit the amount on your mandates by setting `amount` in the `payment_method_options` as several banks [always reject mandates without an amount specified](https://docs.stripe.com/payments/payto.md#bank-limits). ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d confirm=true \ --data-urlencode "return_url=https://www.stripe.com" \ -d usage=off_session \ -d customer=cus_ODQluYFNl44ODI \ -d "payment_method_data[type]=payto" \ -d "automatic_payment_methods[enabled]=true" \ -d "payment_method_options[payto][mandate_options][amount]=1500" \ -d "mandate_data[customer_acceptance][type]=online" \ -d "mandate_data[customer_acceptance][online][ip_address]=127.0.0.0" \ -d "mandate_data[customer_acceptance][online][user_agent]=device" ``` The SetupIntent object contains a `client_secret`, which is a unique key that you must pass to Stripe.js on the client side to redirect your buyer to PayTo and authorize the mandate. ## Create a subscription [Server-side] Create a subscription that has a price and a customer. Set the value of the `default_payment_method` parameter to the PaymentMethod ID from the SetupIntent response. ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d customer={{CUSTOMER_ID}} \ -d "items[0][price]={{PRICE_ID}}" \ -d default_payment_method={{PAYMENT_METHOD_ID}} \ -d off_session=true ``` Creating subscriptions automatically charges customers because of the pre-set default payment method. After a successful payment, the status in the Stripe Dashboard changes to **Active**. The price that you previously set up determines the amount for future billings. ## 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. |