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 learnAnchor link to section titled "What you'll learn"
In this tutorial, you'll learn how to do the following tasks:
RequirementsAnchor link to section titled "Requirements"
Step 1: Create an app subscriptionAnchor 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.
To create an app subscription based on usage, use the
Step 2: Combine billing models in a pricing planAnchor 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 recordAnchor 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
To create an app usage record, use the
Step 4: Subscribe to webhooks to monitor app usageAnchor 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
To receive a notification when merchants reach or exceed 90% of their capped amount, subscribe to the GraphQL Admin API's