Manage billing cycle contracts
Billing cycle contracts inherit the contract lines, pricing policy, and delivery policy from the billing cycle's source subscription contract. However, you might want to edit the contract information on a billing cycle when you need to make a temporary change to a customer's subscription contract. For example, you might remove a product that's out of stock and replace it with a similar product for a single billing cycle.
This tutorial shows you how to edit the contract information on a billing cycle.
Anchor to What you'll learnWhat you'll learn
In this tutorial, you'll learn how to do the following tasks:
- Retrieve a draft of the most up-to-date contract information for a subscription billing cycle
- Remove a line item from the contract draft
- Add a line item to the contract draft
- Commit the edited contract information
- Fetch the edited contract information on a subscription billing cycle
- Create an order for a subscription billing cycle
Anchor to RequirementsRequirements
- Most subscriptions, pre-order and try before you buy apps need to request API access through the Partner Dashboard. We give API access to apps that are designed according to our [principles for subscriptions, pre-order and TBYB apps] (/docs/apps/selling-strategies/purchase-options#shopifys-principles).
- Public apps that use subscriptions, pre-order or TBYB need to meet specific requirements to be published on the Shopify App Store.
- Custom apps created in the Shopify admin can't use subscriptions, pre-order or TBYB because these apps can't use extensions or request access to protected scopes. If you're building a solution for a single store, then build your custom app in the Partner Dashboard.
- Your app can make authenticated requests to the GraphQL Admin API.
- Your app has the
read_own_subscription_contracts
andwrite_own_subscription_contracts
access scopes. Learn how to configure your access scopes using Shopify CLI. - You've created products and product variants in your development store.
- You've created an active subscription contract with a recurring billing and delivery policy.
- You've familiarized yourself with the concept of billing cycles.
Anchor to Step 1: Create a subscription draftStep 1: Create a subscription draft
You can use the subscriptionBillingCycleContractEdit
mutation to create a subscription draft with the most up-to-date contract information on a specified billing cycle. Pass the contract ID and either the index or a date belonging to the billing cycle to specify the billing cycle.
Make note of the subscription contract draft ID and line ID in the response. You'll use it to update the draft data in the next step.
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
JSON response
Anchor to Step 2: Update the subscription draftStep 2: Update the subscription draft
This step shows you how to remove or add a line item to the contract. However, you can make other updates to the subscription draft in this step as needed, such as adding a discount or changing the line quantity.
After retrieving the draft ID, you can begin making edits to the contract draft. Edits to the contract draft can be made incrementally. Changes to the contract draft aren't made live until the draft is committed.
Anchor to Remove a line itemRemove a line item
You can pass the draft ID and line ID to the subscriptionDraftLineRemove
mutation to remove a line item from the subscription draft:
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
JSON response
Anchor to Add a line itemAdd a line item
You can pass the draft ID and line information to the subscriptionDraftLineAdd
mutation to add a line item to the subscription draft:
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
JSON response
Anchor to Step 3: Commit the subscription draftStep 3: Commit the subscription draft
When you commit the subscription draft, the changes that you've made become active on the billing cycle for which the draft was created. You can call the subscriptionDraft
query to review the information on the subscription draft before committing it.
After you're satisfied with your updates, you can call the subscriptionBillingCycleContractDraftCommit
mutation to commit your changes to the billing cycle:
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
JSON response
Anchor to Step 4: Fetch the edited contractStep 4: Fetch the edited contract
After committing the subscription draft, you might want to fetch the information on your edited contract.
You can do so using subscriptionBillingCycle
query.
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL query
JSON response
Anchor to Step 5: Create an orderStep 5: Create an order
When the billing date comes, you can use subscriptionBillingCycleCharge
mutation to create an order. This mutation only allows a single successfull charge per billing cycle and only allows charging billing cycles with the billing attempt expected date in the past or within the next 24 hours. To use the subscriptionBillingCycleCharge
mutation, you need to specify the following inputs:
subscriptionContractId
: The ID of the subscription contract.billingCycleSelector
: The billing cycle you want to charge. You can select the billing cycle by passing a date or a billing cycle index.
Billing attempts are processed asynchronously, which means the resulting order won't be available right away. You can fetch the billing attempt and inspect the ready
field to find out whether the order has been created (true
) or not (false
).
You can also create orders by creating a billing attempt.
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
JSON response
Anchor to Next stepsNext steps
Learn how to bulk charge multiple contracts at the same time.