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.
What you'll learn
Anchor link to section titled "What 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
Requirements
Anchor link to section titled "Requirements"- 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.
Step 1: Create a subscription draft
Anchor link to section titled "Step 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.
Step 2: Update the subscription draft
Anchor link to section titled "Step 2: Update the subscription draft"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.
Remove a line item
Anchor link to section titled "Remove 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:
Add a line item
Anchor link to section titled "Add 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:
Step 3: Commit the subscription draft
Anchor link to section titled "Step 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:
Step 4: Fetch the edited contract
Anchor link to section titled "Step 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.
Step 5: Create an order
Anchor link to section titled "Step 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
).
Learn how to bulk charge multiple contracts at the same time.