Webhooks
Handle webhooks from your mobile app's billing provider.
API deployment required
To handle billing webhooks in production (and allow your Expo app to talk to your backend), you must first deploy the Hono API.
TurboStarter uses billing webhooks to keep customer data in sync based on events sent by your billing provider.
However, sometimes you may want to perform custom actions when specific events arrive.
In that case, customize the billing webhook handler in packages/api/src/modules/billing/router.ts.
By default, the webhook handler is configured to be as straightforward as possible:
import { webhookHandler, provider } from "@workspace/billing-mobile/server";
export const billingRouter = new Hono().post(`/webhook/${provider}`, (c) =>
webhookHandler(c.req.raw),
);However, you can extend it using the callbacks provided by the @workspace/billing-mobile package:
import { webhookHandler, provider } from "@workspace/billing-mobile/server";
export const billingRouter = new Hono().post(`/webhook/${provider}`, (c) =>
webhookHandler(c.req.raw, {
onOneTimePurchaseSucceeded: (orderId) => {},
onSubscriptionCreated: (subscriptionId) => {},
onSubscriptionUpdated: (subscriptionId) => {},
onSubscriptionDeleted: (subscriptionId) => {},
onEvent: (rawEvent) => {},
}),
);You can provide one or more of the callbacks to handle the events you are interested in.
Don't mix up web and mobile billing
Mobile billing webhooks are set up using the same method as in the web app. Make sure to keep your configurations organized and confirm that events are handled properly for each provider on both mobile and web platforms.
How is this guide?
Last updated on