Moonbase Documentation

Checkout Guards

Block checkout until a plugin validates prerequisites.

Checkout guards run inside the API helper methods:

Guard entry points

  • app/lib/api.ts:createCheckoutSession
  • app/lib/api.ts:createCartCheckout

If you trigger checkout by calling the API directly, call runCheckoutGuards first.

type CheckoutGuardContext = {
  type: 'cart' | 'product';
  items?: Array<{ productId: string; plan?: string; quantity?: number }>;
  productId?: string;
  plan?: string;
  paymentMethod?: string;
};
const plugin: FrontendPlugin = {
  name: 'license-guard',
  bootstrap: (ctx) => {
    return ctx.checkout.registerGuard(async (context) => {
      if (context?.type === 'product') {
        const response = await ctx.api.post('/api/plugins/license/check', {
          productId: context.productId
        });
        return response.ok;
      }
      return true;
    });
  }
};

Guard outcome

Return false to cancel checkout.