---
title: "Accepting Payments with Waffo Pancake"
description: "How to accept payments with Waffo Pancake in LaunchFast starter kits?"
source: "https://www.launchfa.st/documentation/payments/waffo"
---

> **Site index for agents**
> Fetch https://www.launchfa.st/llms.txt to discover every page on this site.
> Every page is also available as Markdown by appending `.md` to its URL.

> Browse the source code [here](https://github.com/LaunchFast-Boilerplates/launchfa.st-astro/tree/master/src/pages/api/waffo).

import { Steps, Tabs, TabItem } from '@astrojs/starlight/components'

LaunchFast ships with a built-in [Waffo Pancake](https://pancake.waffo.ai) integration. Waffo Pancake is a merchant of record for software businesses: it handles payments, sales tax, compliance, and payouts worldwide, and sells one-time products and subscriptions through a hosted checkout that accepts cards, Apple Pay, and Google Pay.

The starter kit uses the official [`@waffo/pancake-ts`](https://www.npmjs.com/package/@waffo/pancake-ts) SDK, which signs every API request with your private key and verifies webhooks with Waffo's built-in public keys.

Here's how you would set up Waffo Pancake to use it with LaunchFast:

<Steps>
  1. Create a [Waffo Pancake](https://pancake.waffo.ai) account.
  2. Create an API key in the dashboard under **API & Development**, and copy your merchant ID and private key. Test and production keys are separate.
  3. Create a product, publish it, and copy its product ID.
  4. Add a webhook pointing to `https://<your-domain>/api/waffo/webhook`.
  5. Make sure to update the environment variable(s) of your application per the following instruction:

      <Tabs>
        <TabItem label="Astro">
            [https://github.com/LaunchFast-Boilerplates/launchfa.st-astro#payments](https://github.com/LaunchFast-Boilerplates/launchfa.st-astro#payments)
        </TabItem>
        <TabItem label="SvelteKit">
            [https://github.com/LaunchFast-Boilerplates/launchfa.st-sveltekit#payments](https://github.com/LaunchFast-Boilerplates/launchfa.st-sveltekit#payments)
        </TabItem>
        <TabItem label="Next.js">
            [https://github.com/LaunchFast-Boilerplates/launchfa.st-nextjs#payments](https://github.com/LaunchFast-Boilerplates/launchfa.st-nextjs#payments)
        </TabItem>
      </Tabs>
</Steps>

```bash
## Waffo Pancake Environment Variables
WAFFO_MERCHANT_ID="MER_..."
WAFFO_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n" # PEM or base64 encoded PEM
WAFFO_PRODUCT_ID="PROD_..." # Default product used by the Buttons/Waffo component
WAFFO_CURRENCY="USD" # Optional, defaults to USD
```

The private key is read as a server-side secret and never reaches the browser. It can be stored as a PEM with real or escaped `\n` newlines, or as a base64 encoded PEM, whichever your hosting provider handles best.

## Adding a Checkout Button

Import the Waffo checkout button anywhere in your app. Clicking it posts to the `/api/waffo/checkout` route, which creates a Waffo checkout session and redirects the user to it:

```astro
---
import ButtonWaffoCheckout from '@/components/Buttons/Waffo.astro'
---

<ButtonWaffoCheckout brand_name="ACME" />

<!-- or checkout a specific product -->
<ButtonWaffoCheckout brand_name="ACME Pro" product_id="PROD_..." />
```

Leave out `product_id` to sell the product set in `WAFFO_PRODUCT_ID`. Pass it to sell several products, such as different plans on a pricing page, from the same route.

Here is what the checkout route does under the hood:

```typescript
// File: src/pages/api/waffo/checkout.ts

const waffo = getWaffoClient()
// Use the product picked by the button, else fall back to WAFFO_PRODUCT_ID
const productId = await getProductId(request, getSecret('WAFFO_PRODUCT_ID'))
// Create a Waffo Pancake checkout session
const session = await waffo.checkout.createSession({
  productId,
  metadata: getReflioMetadata(cookies),
  currency: getSecret('WAFFO_CURRENCY') || 'USD',
  // Mentioning the URL where user would land up when they complete the transaction succesfully (must be https)
  successUrl: new URL('/api/waffo/success', site).toString(),
})
// Redirect the user to the Waffo Pancake hosted checkout created above
if (session.checkoutUrl) return webRedirect(session.checkoutUrl)
```

## Handling the Webhook

Once a payment goes through, Waffo calls your webhook route. The starter kit verifies the `x-waffo-signature` header against the raw request body and gives the customer access in the database:

```typescript
// File: src/pages/api/waffo/webhook.ts

// Obtain the raw body of the request to be used for verification
const rawBody = await request.text()
// Verify the RSA-SHA256 signature using the Waffo public keys baked into the SDK
// (test vs prod is detected automatically)
const event = verifyWebhook(rawBody, sig)
// A one-time order being completed or a subscription being activated point to a succesful payment
if (event.eventType === WebhookEventType.OrderCompleted || event.eventType === WebhookEventType.SubscriptionActivated) {
  const customerEmail = event.data.buyerEmail
  if (customerEmail) {
    // Add the 'email' to the access list in the database
    await setAccess(customerEmail, '1')
    return webResponse('approved user access', 200)
  }
}
// Acknowledge the other events so that Waffo does not retry them
return webJson({ received: event.eventType }, 200)
```

`order.completed` fires for one-time products and `subscription.activated` for subscriptions. The SDK exposes every other event too, such as `subscription.canceled` and `refund.succeeded`, through the `WebhookEventType` enum, so you can revoke access or send emails from the same route.

## Testing

In [test mode](https://docs.waffo.ai/features/test-mode), pay with the card number `4576 7500 0000 0110`, any future expiry date, and any CVC.
