You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/integrations/apps/unified-billing/example-queries.mdx
+59-5Lines changed: 59 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,57 @@
1
-
# GraphQL Account API: Unified billing
1
+
# GraphQL Account API: Unified Billing
2
2
3
-
The following examples of queries and mutations use the Unified Billing features of the BigCommerce GraphQL Account API. Use the API by submitting POST requests to `https://api.bigcommerce.com/accounts/{{partner_account_uuid}}/graphql`.
3
+
Below are examples of queries and mutations. They demonstrate how to use the Unified Billing features available through the BigCommerce GraphQL Account API.
4
+
5
+
Use the API by submitting POST requests to `https://api.bigcommerce.com/accounts/{{your_partner_account_uuid}}/graphql`.
4
6
5
7
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](https://developer.bigcommerce.com/docs/integrations/apps/unified-billing/postman-collection)
6
8
9
+
## Possible Implementation Strategies
10
+
11
+
Using the information gathered from the [prerequisites section](https://developer.bigcommerce.com/docs/integrations/apps/unified-billing#prerequisites), 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.
12
+
13
+
### Creating Subscriptions
14
+
15
+
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.
16
+
17
+
**Implementation Options:**
18
+
19
+
**Option A: Polling Checkout Status**
20
+
- Cache the checkout URL for each merchant store
21
+
- Periodically poll the [Checkout Query](https://developer.bigcommerce.com/docs/integrations/apps/unified-billing/example-queries#fetch-a-checkout) until the status changes to `COMPLETE`
22
+
- Once complete, retrieve the `subscriptionId` from the checkout response
23
+
24
+
**Option B: Polling Subscription Status (Recommended)**
25
+
- Instead of monitoring individual checkouts, gate access to premium features until the [Subscriptions Query](https://developer.bigcommerce.com/docs/integrations/apps/unified-billing/example-queries#query-subscriptions) returns an active subscription
26
+
- This approach is more efficient and provides better reliability for verifying completed purchases
27
+
28
+
### Managing Access Control
29
+
30
+
Use the [Subscriptions Query](https://developer.bigcommerce.com/docs/integrations/apps/unified-billing/example-queries#query-subscriptions) to verify which merchants have active subscriptions. Filter by `scopeId` (store hash) to find the subscription for a specific merchant.
31
+
32
+
**Caching Strategy:**
33
+
- Cache subscription results to reduce API calls
34
+
- Invalidate the cache when processing cancellations or when subscriptions expire
35
+
- Consider periodic cache refresh to handle external subscription changes
36
+
37
+
### Handling Subscription Cancellations
38
+
39
+
When merchants request to cancel their subscription, use the [CancelSubscription Mutation](https://developer.bigcommerce.com/docs/integrations/apps/unified-billing/example-queries#cancel-a-subscription). The response includes a `cancelledAt` date indicating when access ends:
40
+
41
+
-**Regular subscriptions**: Access continues until the end of the current billing cycle
**Implementation Note:** Invalidate any cached subscription data immediately after processing a cancellation to ensure accurate access control.
45
+
46
+
### Updating Subscription Plans
47
+
48
+
To handle plan changes (upgrades, downgrades, or billing frequency modifications), create a new checkout using the [UpdateSubscription Mutation](https://developer.bigcommerce.com/docs/integrations/apps/unified-billing/example-queries#update-a-subscription). This allows you to modify subscription details while preserving the merchant's billing relationship.
49
+
50
+
**Use Cases:**
51
+
- Plan tier changes (Basic → Premium)
52
+
- Billing frequency updates (Monthly → Annual)
53
+
- Price adjustments for existing subscribers
54
+
7
55
## Example queries and mutations
8
56
9
57
### Create a checkout
@@ -71,7 +119,7 @@ To create a checkout, run the `createCheckout` mutation:
"accountId": "bc/account/account/61db983a-cd07-4d6b-8b59-a5ffe285ca6a",// This should be the merchant's account UUID
75
123
"items": [
76
124
{
77
125
"product": {
@@ -80,7 +128,7 @@ To create a checkout, run the `createCheckout` mutation:
80
128
"productLevel": "Standard"
81
129
},
82
130
"scope": {
83
-
"id": "bc/account/scope/f0qyczpkb2",
131
+
"id": "bc/account/scope/f0qyczpkb2",// This should be the merchant's store hash
84
132
"type": "STORE"
85
133
},
86
134
"pricingPlan": {
@@ -150,6 +198,12 @@ To create a checkout, run the `createCheckout` mutation:
150
198
</Tab>
151
199
</Tabs>
152
200
201
+
Some common errors returned when creating a checkout:
202
+
*`Product is not supported for your account.` - The application being purchased [is not owned by the partner account](https://developer.bigcommerce.com/docs/integrations/apps/unified-billing#required-app-setup) (in the request URL) making the request.
203
+
*`Scope does not belong to account.` - The store hash provided does not belong to the merchant account provided.
204
+
*`You do not have permission to do this operation.` - This failure has multiple possible causes:
205
+
* The account-level API token being used does not have the [required auth scope](https://developer.bigcommerce.com/docs/integrations/apps/unified-billing#authentication) for the given operation.
206
+
* The account-level API token does not match the account UUID being used in the request URL.
153
207
154
208
### Fetch a checkout
155
209
@@ -461,7 +515,7 @@ The `createCheckout` mutation can also be used to update an existing subscriptio
461
515
462
516
### Cancel a subscription
463
517
464
-
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).
518
+
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.
0 commit comments