View as Markdown

Quickstart

Create a customer, send them to checkout and receive the webhook. In test mode, from your server.

Samples show a placeholder key, gpy_test_…. Sign in to create a test key of your own.Start free
  1. Install and authenticate

    A secret key starts with gpy_test_ or gpy_live_. Send it as Authorization: Bearer … from your server only. The key's prefix decides the mode, so a test key can never touch live data.

    Create a test key in the dashboard under Developers › API keys. It is shown once.

    lib/mint.ts
    import { Mint } from '@globaly-inc/mint-sdk'
     
    // One client per process. The mode comes from the key.
    export const mint = new Mint({
      secretKey: process.env.MINT_SECRET_KEY!, // gpy_test_…
    })
  2. Create the customer

    A customer is keyed by your own id for the account: a workspace or organisation id. Upserting is safe to repeat, so call it on every sign-in.

    Checkout does not create customers. A session for an id we have not seen answers 404.

    customer.ts
    await mint.customers.upsert({
      externalId: 'ws_123',
      email: 'owner@acme.dev',
      name: 'Acme Inc',
    })
  3. Open a checkout

    Name the plan by its code. Create plans in the dashboard under Products, or with mint.catalog.upsertPlan. Both URLs are required and must be https (http is accepted for localhost).

    Redirect the browser to session.url. The link is valid for 24 hours. The page collects the card through Stripe, so connect your Stripe test keys under Settings › Payments first, then pay with Stripe's test card 4242 4242 4242 4242.

    checkout.ts
    const session = await mint.checkout.create({
      customerExternalId: 'ws_123',
      planCode: 'pro_monthly',
      seats: 5,
      successUrl: 'https://app.acme.dev/billing?ok=1',
      cancelUrl: 'https://app.acme.dev/billing',
    })
     
    redirect(session.url)
  4. Receive the webhook

    Add an endpoint under Developers › Webhooks and copy its whsec_ secret; it is shown once. The URL must be https on a public host, so use a tunnel while you develop locally.

    When the payer finishes, we send checkout.session.completed and, once the first invoice is paid, invoice.paid. Grant access on the webhook, not on the redirect to your success URL. Order is not guaranteed and delivery is at least once, so skip any event.id you have already handled.

    app/api/mint/webhooks/route.ts
    import { mint } from '@/lib/mint'
     
    export const POST = mint.webhooks.handler({
      secret: process.env.MINT_WEBHOOK_SECRET!, // whsec_…
      on: {
        'invoice.paid': async (event) => {
          // event.id is stable: use it to skip duplicates.
          await grantAccess(event.data.customer_external_id)
        },
      },
    })
    No test event sent yet.

    Not released yet. Sending a test event from this page arrives with test events. Until then, complete a checkout in test mode and watch the delivery under Developers › Webhooks.

Next