> Beta: > Post-purchase checkout extensions are in beta and can be used without restrictions in a [development store](/docs/api/development-stores). To use post-purchase extensions on a live store, you need to [request access](/docs/apps/build/checkout/product-offers/build-a-post-purchase-offer#step-5-request-access). In this tutorial, you'll learn how to create a post-purchase offer that allows a buyer to add a subscription to their order. ![Overview of a post-purchase subscription added to a single item](/assets/api/post-purchase/post-purchase-subscription-overview.png) ## What you'll learn In this tutorial, you’ll learn how to do the following tasks: - Update your app with the required scopes to manage subscriptions - Add UI elements to allow buyers to select one time or subscription products - Update the app server to return subscription data ## Requirements - You've completed [Build a post-purchase product offer checkout extension](/docs/apps/build/checkout/product-offers/build-a-post-purchase-offer). ## Limitations You can't create a post-purchase subscription that does the following: * Modifies a subscription on an order with an existing subscription * Adds a subscription to an order with an existing subscription * Converts a one-time purchase into a subscription order ## Step 1: Add required data To offer a customer a subscription, a product needs to have an associated selling plan group. [Selling plans](/docs/apps/build/purchase-options/subscriptions/selling-plans) represent how products can be sold and purchased. When you create a selling plan, you can determine the policies under which a product can be sold. For example, you can create a selling plan where a customer can purchase a subscription on a monthly billing cycle, and where you offer a 15% discount for weekly deliveries of the product. > Note: > If your app already has the capability to manage selling plans, or if you're integrating with an app that already has this capability, then you can skip to [step 2](#step-2-return-subscription-information-from-the-app-server). To complete this tutorial, the product on the store you will have in the upsell offer needs to be associated with a selling plan. ### Update app scopes To create a selling plan and associate it to a product, you need to add the `write_purchase_options` scope to the app. Update the app scopes in the `shopify.app.toml` file to include the `write_purchase_options` scope. This scope allows you to create selling plan groups. After you update scopes, when you navigate to the app home in the Shopify admin, you should be prompted to reauthorize the app to allow editing of purchase options. If you're not prompted to reauthorize, restart your server, and then navigate to the app home in the Shopify admin.

### Create a selling plan group Use the GraphQL Admin API to create a selling plan group, and associate a product with the selling plan group. In the following `cURL` command, add the `myshopify` domain of your development store, the access token for the app, and the product and variant IDs of the product that you're offering in the upsell. > Note: > You can run `npm run prisma studio` to view your data in your browser. > The access token is stored in the `Session` table in the `accessToken` column.

## Step 2: Return subscription information from the app server Update the `OFFERS` array in the `app/offer.server.js` file that you created in the [previous tutorial](/docs/apps/build/checkout/product-offers/build-a-post-purchase-offer) to return an offer with the selling plan information that you created in the previous step.

## Step 3: Update your extension code to offer subscriptions Replace the content of your extension script with the following code.

### How the example extension code works The following sections explain how different parts of the example extension code in [Step 2](#step-2-return-subscription-information-from-the-app-server) works. #### Showing the selling plan options To show the selling plan options to buyers, you need to use the [`Select`](/docs/api/checkout-extensions/post-purchase/components/select) component. When a buyer selects a new selling plan, we update the value of the selected purchase option.

After you've updated the code, the selling plan option renders as follows: ![Selling plan option picker](/assets/api/post-purchase/selling_plan_options.png) #### Updating the price breakdown To show the price breakdown matching the currently selected offer, you need to call `calculateChangeset` when the buyer selects a selling plan:

After you've updated the code, the price breakdown renders as follows: ![Price breakdown including subtotal, shipping and taxes](/assets/api/post-purchase/price_breakdown.png) #### Showing a recurring subtotal For subscription offers, you need to display the recurring subtotal of the order. > Note: > The `totalPriceSet` for subscription items indicates the price of that item after discounts at each billing cycle, and not the total for the subscription duration.

After you've updated the code, the recurring subtotal renders as follows: ![Recurring subtotal price and explanation](/assets/api/post-purchase/recurring_subtotal.png) #### Collecting buyer's consent To add a subscription item to an order, the buyer’s payment method must be vaulted for future billing cycles of the subscription. Before you can vault the buyer's payment method, the buyer has to explicitly give consent to the subscription policies. Use the `BuyerConsent` component in App Bridge to collect consent:

This component creates a checkbox and a link to the subscription policies. ![The checkbox where buyers can give their consent to adding a subscription](/assets/api/post-purchase/buyer-consent-checkbox.png) ### Applying the subscription change For the `add_subscription` change to be accepted, the value of the buyer consent checkbox needs to be provided as a new parameter to the `applyChangeset` method. Without this parameter, the changeset won’t be applied and an error is returned.

## Step 4: Test your extension Complete a test order on your store and go through the checkout steps. When the post-purchase page appears, add a subscription product to your order. Navigate to the orders section of the Shopify Admin. You should see that on the latest order you have a one time as well as a subscription product. ## Next steps - Get familiar with the [UX guidelines](/docs/apps/build/checkout/product-offers/ux-for-post-purchase-subscriptions) for creating subscriptions with post-purchase checkout extensions.