Create recurring charges based on usage
You can use the appSubscriptionCreate
mutation to create a billing model that charges merchants based on the usage of your app. This billing model benefits both the merchant and you, because you have a constant stream of revenue, and the merchant will continue to get updates to the app that they subscribe to.
You want to add a usage-based billing model to your app. You want to combine the usage charges with a recurring subscription plan. You'd also like to create a usage record, and to listen for changes that the merchant might make to their usage limit.
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:
Requirements
Anchor link to section titled "Requirements"Create a Partner account
Create a development store
Step 1: Create an app subscription
Anchor link to section titled "Step 1: Create an app subscription"When you use the appSubscriptionCreate
mutation, you need to include the cappedAmount
field, which indicates the maximum amount of usage the merchant is billed for within the Shopify 30-day billing cycle. You also need to include the terms
field, which is reviewed by the merchant when they accept your pricing plan.
The AppSubscription.id
and the AppSubscriptionLineItem.id
that are included in the payload are then used to create app usage records.
To create an app subscription based on usage, use the appSubscriptionCreate
mutation:
Step 2: Combine billing models in a pricing plan
Anchor link to section titled "Step 2: Combine billing models in a pricing plan"You can also create a recurring pricing plan and a usage pricing plan in a single mutation:
Step 3: Create an app usage record
Anchor link to section titled "Step 3: Create an app usage record"After you've created the usage pricing plan and the merchant has accepted the plan, you can create a usage record. The usage record needs to include the
AppSubscriptionLineItem.id
of the AppSubscription
object that is returned by the appSubscriptionCreate
mutation.
To create an app usage record, use the appUsageRecordCreate
mutation:
Step 4: Subscribe to webhooks to monitor app usage
Anchor link to section titled "Step 4: Subscribe to webhooks to monitor app usage"Merchants can use the Shopify admin to change their capped amount. This is the maximum amount of usage to bill for within the Shopify 30-day billing cycle.
To receive notifications when merchants change the capped amount, subscribe to the GraphQL Admin API's APP_SUBSCRIPTIONS_UPDATE
topic.
To receive a notification when merchants reach or exceed 90% of their capped amount, subscribe to the GraphQL Admin API's APP_SUBSCRIPTIONS_APPROACHING_CAPPED_AMOUNT
topic.