Skip to main content

Billing

Contains function used to bill merchants for your app with the Billing API.

This object is returned on authenticated Admin requests.

Note

Managed App Pricing is now available. Define your app’s pricing plans directly in the Shopify Partner Dashboard, without needing to use the Billing API.

Provides utilities that apps can use to request billing for the app using the Admin API.

Anchor to cancel
cancel
(options: ) => Promise<AppSubscription>
required

Cancels an ongoing subscription, given its ID.

Anchor to check
check
<Options extends <Config>>(options?: Options) => Promise<BillingCheckResponseObject>
required

Checks if the shop has an active payment for any plan defined in the billing config option.

Anchor to createUsageRecord
createUsageRecord
(options: ) => Promise<UsageRecord>
required

Creates a usage record for an app subscription.

Anchor to request
request
(options: <Config>) => Promise<never>
required

Requests payment for the plan.

Anchor to require
require
(options: <Config>) => Promise<BillingCheckResponseObject>
required

Checks if the shop has an active payment for any plan defined in the billing config option.

Anchor to updateUsageCappedAmount
updateUsageCappedAmount
(options: ) => Promise<never>
required

Updates the capped amount for a usage billing plan.

Examples
import { LoaderFunctionArgs } from "react-router";
import { authenticate, MONTHLY_PLAN } from "../shopify.server";

export const loader = async ({ request }: LoaderFunctionArgs) => {
const { billing } = await authenticate.admin(request);
const billingCheck = await billing.require({
plans: [MONTHLY_PLAN],
onFailure: async () => billing.request({ plan: MONTHLY_PLAN }),
});

const subscription = billingCheck.appSubscriptions[0];
const cancelledSubscription = await billing.cancel({
subscriptionId: subscription.id,
isTest: true,
prorate: true,
});

// App logic
};
Was this page helpful?