# Set up a subscription with Cash App Pay

Learn how to create and charge for a subscription with Cash App Pay.

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 [Cash App Pay](https://docs.stripe.com/payments/cash-app-pay.md) as a payment method.

# Subscriptions API


Create and confirm a Subscription using two API calls. The [first API call](https://docs.stripe.com/billing/subscriptions/cash-app-pay.md#pi-create-subscription) sends customer and product information to the [Subscriptions API](https://docs.stripe.com/api/subscriptions.md) to create a Subscription and PaymentIntent in one call. The response includes a PaymentIntent ID that you must use in a [Payment Intents API](https://docs.stripe.com/api/payment_intents.md) call to [confirm a payment](https://docs.stripe.com/billing/subscriptions/cash-app-pay.md#pi-confirm-payment).

## 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 USD 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 **USD** 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 subscription [Server-side]

Create a [subscription](https://docs.stripe.com/api/subscriptions.md) that has a price and customer with status of `incomplete` by providing the [payment_behavior](https://docs.stripe.com/api/subscriptions/create.md#create_subscription-payment_behavior) parameter with a value of `default_incomplete`. Set the `payment_settings.save_default_payment_method=on_subscription` parameter to save a payment method when a subscription is activated.

```curl
curl https://api.stripe.com/v1/subscriptions \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d customer={{CUSTOMER_ID}} \
  -d payment_behavior=default_incomplete \
  -d "items[0][price]={{PRICE_ID}}" \
  -d "payment_settings[save_default_payment_method]=on_subscription" \
  -d "expand[0]=latest_invoice.payments" \
  -d "expand[1]=latest_invoice.confirmation_secret"
```

The response includes 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)’s first [Invoice](https://docs.stripe.com/api/invoices.md). This contains the invoice’s payments, which includes a default PaymentIntent that Stripe generated for this invoice and the confirmation secret which you can use on the client side to securely complete the payment process instead of passing the entire PaymentIntent object. Return the `latest_invoice.confirmation_secret.client_secret` to the front end to complete payment.

Get the PaymentIntent ID that you must use to confirm a payment from `latest_invoice.payments`.

> To create 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) with a free trial period, see [Subscription trials](https://docs.stripe.com/billing/subscriptions/trials/free-trials.md).

## Confirm a payment [Server-side]

Confirm a payment with [PaymentIntents](https://docs.stripe.com/api/payment_intents.md) using the PaymentIntent ID from the Subscriptions response. Add the PaymentIntent ID to the URL path:

```curl
curl https://api.stripe.com/v1/payment_intents/:id/confirm \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "payment_method_data[type]=cashapp" \
  --data-urlencode "return_url=https://www.stripe.com" \
  -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" \
  -d "mandate_data[customer_acceptance][accepted_at]=1660000000"
```

The PaymentIntent response includes the status `requires_action`, which means your users must perform another action to complete the PaymentIntent. Use the `next_action.cashapp_handle_redirect_or_display_qr_code` object from the PaymentIntent response to redirect your users to a Stripe hosted page that displays the QR code, or render the QR code directly. To authenticate users, follow the instructions for [redirect and authenticate transactions](https://docs.stripe.com/payments/cash-app-pay/accept-a-payment.md?payment-ui=direct-api#handle-redirect). After they authenticate, the Cash App mobile application redirects users to the `return_url` on their mobile device, and the PaymentIntent moves to a `succeeded` state.

After a successful payment, the subscription becomes active and saves the payment method as the default payment method.

