GraphQL Account API: Unified Billing
GraphQL Account API: Unified Billing
GraphQL Account API: Unified Billing
Below are examples of queries and mutations. They demonstrate how to use the Unified Billing features available through the BigCommerce GraphQL Account API.
Use the API by submitting POST requests to https://api.bigcommerce.com/accounts/{{your_partner_account_uuid}}/graphql.
We have prepared a Postman collection you can import into your Postman workspace to interact with the Unified Billing API. It includes example requests for common operations such as creating checkouts, querying checkouts, querying subscriptions, and canceling subscriptions: Unified Billing Postman Collection
Using the information gathered from the prerequisites section, you can begin integrating with the Unified Billing API. The following examples are meant to be a helpful guide for implementation. When considering how to utilize the API, keep in mind the specific needs of your app.
When a merchant wants to purchase a subscription after installing your app, use the Create Checkout Mutation to generate a checkout URL for them to complete the purchase.
Implementation Options:
Option A: Polling Checkout Status
COMPLETEsubscriptionId from the checkout responseOption B: Polling Subscription Status (Recommended)
Use the Subscriptions Query to verify which merchants have active subscriptions. Filter by scopeId (store hash) to find the subscription for a specific merchant.
Caching Strategy:
When merchants request to cancel their subscription, use the CancelSubscription Mutation. The response includes a cancelledAt date indicating when access ends:
Implementation Note: Invalidate any cached subscription data immediately after processing a cancellation to ensure accurate access control.
To handle plan changes (upgrades, downgrades, or billing frequency modifications), create a new checkout using the UpdateSubscription Mutation. This allows you to modify subscription details while preserving the merchant’s billing relationship.
Use Cases:
The first step in charging a merchant for a product is to create a checkout. After creating a checkout through the API, the checkout will be in a pending status, and a checkoutUrl will be included in the response. The checkoutUrl routes to the BigCommerce checkout UI where a merchant must complete the checkout in their store’s control panel. After checkout completion, a subscription is created and billed to the merchant, and the checkout status moves to complete. When the merchant exits the BigCommerce checkout UI, they will be redirected to the redirectUrl provided in the request. Use this field to route the merchant back to your app.
When creating a checkout with a product that has a trial period, set the trialDays field to the number of days the trial should last.
The merchant will not be charged during this period. A subscription only generates an invoice once the trial period ends. No charges are made during the trial.
Checkout links are valid for 24 hours and expire automatically to prevent misuse.
To create a checkout, run the createCheckout mutation:
Some common errors returned when creating a checkout:
Product is not supported for your account. - The application being purchased is not owned by the partner account (in the request URL) making the request.Scope does not belong to account. - The store hash provided does not belong to the merchant account provided.You do not have permission to do this operation. - This failure has multiple possible causes:
Once the checkout is created, you can periodically poll the status of the checkout by calling this endpoint. To fetch an existing checkout, copy and run the following query:
Replace the checkoutId with the following variable:
The createCheckout mutation can also be used to update an existing subscription’s pricing plan information and product level. A subscriptionId must be passed in the request for this to be processed as an update.
This mutation cancels the subscription at the end of the merchant’s current billing cycle. The cancelledAt value will be the last day of the merchant’s billing cycle (i.e., the day through which they have already paid). For trials and subscriptions that have not yet been invoiced, the cancellation takes effect immediately and the cancelledAt value will reflect this immediate time.
No Billing During Trial
Immediate Cancellation During Trial
Post Trial Cancellation Behavior
Subscriptions can be queried using the subscriptions query endpoint.
Fields that can be retrieved are:
id - subscription idaccountId - account id belonging to the merchantactivationDate - date billing beganbillingInterval - billing frequencycreatedAt - date and time the subscription was createdcurrentPeriodEnd - date of the end of the current billing periodupdatedAt - date and time the subscription was last updatedpricePerInterval - amount being billed with the following fields:
value - the scalar amountcurrencyCode - the currency of the amountproduct - product object with the following fields
productLevel - the level of the product if it was providedid - product idtype - product typestatus - subscription statusscope - scope object with the following fields
type - scope typeid - scope idIn this example, no filters are passed, so the response will include all subscriptions of the partner. The default number of subscriptions returned per page is 10.
Pagination info is returned with cursors on every subscription node. The pageInfo provides information on the next page along with the cursors to use in traversing the graph.
Use the endCursor to begin the next query. first can be used to limit how many subscriptions are returned. The max limit is 50 subscriptions at a time.
Filters can also be used to query subscriptions.
The supported filters are
productIdproductTypescopeIdscopeTypeupdatedAfterstatusids