Migrating existing subscription contracts to Shopify

For merchants that currently process their subscription payments through Stripe, Shopify has built a set of tools to import pay-as-you-go contracts into Shopify without the need to migrate credit cards directly.

The process includes connecting Stripe as a legacy subscription payment gateway and migrating each pay-as-you-go contract to Shopify. After the process is complete, you can use a subscription contract to create subsequent orders like contracts created through Shopify Checkout.

Requirements

This tutorial assumes that you've already completed the preceding tutorial, the Subscriptions API migration guide.

What you'll learn

This tutorial covers the following concepts:

Configure your payment gateway to work with subscriptions

The steps for configuring your payment gateway to work with subscriptions depend on the payment gateway you are using.

Import any missing customers

You need to import the customer records to connect them to payment methods and subscription contracts. You can use the customerCreate and customerUpdate mutations to add customers to Shopify.

Create new payment methods for the customers

The steps for creating new payment methods depends on the payment gateway that you're using.

Import subscription contracts

After you've created or updated Shopify's customer record, you can import the subscription contracts. Subscription contracts include information about the variant, the plan, the payment method, and the billing and shipping addresses.

Importing subscription contracts is a three step process:

  1. Use the SubscriptionContractCreate mutation to create a Subscription Draft.
  2. After the draft is created, you need to add lines to the subscription that represent the variants that are included in the subscription.
  3. After you add lines, perform a mutation to commit the draft, which turns the draft into a live contract.

The following example creates a subscription contract including the customer imported earlier and the payment method from the preceding step:

POST /admin/api/2021-01/graphql.json

View response

JSON response:

Now that the subscription draft has been created, you need add lines to the draft, to tell the subscription which line items should be included in the contract:

POST /admin/api/2021-01/graphql.json

View response

JSON response:

To convert the subscription draft into a subscription contract that you can bill against, you need to commit the draft. The following mutation commits the draft, and returns a live subscription contract that accepts billing attempts:

POST /admin/api/2021-01/graphql.json

View response

JSON response:

Create billing attempts

You need to create billing attempts to trigger the billing schedule of a contract. When billing attempts are successful, Shopify creates an order.

The following mutation makes a billing attempt by specifying the required fields subscriptionContractId and idempotencyKey (a unique key generated by the client to avoid duplicate payments). In response to a successful mutation, the subscription contract is billed against its current status:

View response

JSON response:

For more information on creating billing attempts, refer to Create a billing attempt.