/checkout redirect, through the customer’s purchase, to the webhook that lands back in your handler — and see exactly where anything went sideways.
And because Macropay is your merchant of record, that’s all you have to build. We’re the legal seller on the buyer’s statement, so we calculate and remit sales tax and VAT worldwide, keep PCI scope off your servers (cards are tokenized in our PCI DSS Level 1 compliant vault), and own chargebacks. You ship the Encore endpoints; we handle the global money plumbing.
What you’ll build
Both use
api.raw() so you control the raw HTTP request and response — required for redirects and for webhook signature verification, which depends on the exact bytes of the request body.
Install the SDK
Pull in the Macropay JavaScript SDK alongside the Standard Webhooks verification library:Terminal
Store your secrets
Encore ships a secrets manager that behaves the same in local development and in the cloud, so you never hardcode credentials. You’ll need three values.Access token and mode
Create an organization access token in your organization settings — this authenticates every API call. The mode flag tells the SDK whether to hit the sandbox or production environment.Terminal
MACROPAY_MODE to sandbox while developing, and flip it to production when you go live.
Webhook secret
You’ll generate this when you register the webhook endpoint (see Handle webhooks). For now, reserve the slot:Terminal
These commands set local secrets. For Encore Cloud, set the production values in the Encore dashboard or your CI/CD pipeline — covered under Deploy to production.
Initialize the client
Read the token and mode from Encore’s secret manager and construct a single sharedMacropay instance you can import anywhere in your backend.
payments/macropay.ts
Create a checkout endpoint
This endpoint takes a product ID from the query string, opens a hosted checkout session, and302-redirects the buyer to it. The same code works for a one-time purchase or a subscription — in Macropay both are just “products,” so the API call doesn’t change.
payments/payments.ts
/checkout?product=YOUR_PRODUCT_ID. Macropay interpolates the real session ID into {CHECKOUT_ID} on the successUrl, so your post-purchase page can look the order up.
Handle webhooks
Macropay emits events as things happen in your organization — an order is created, a subscription activates or cancels, a customer’s state changes. Listening to these is how you keep your own database in sync, rather than polling the API.Register the endpoint
In your organization settings, open the webhooks page and click Add Endpoint, then:1
Set the URL
Point the endpoint at
https://your-app.com/webhooks/macropay — an absolute URL Macropay can reach. During local development the Macropay CLI tunnel (below) supplies this for you.2
Pick your events
Subscribe only to what you act on. See the full catalog in the webhook events reference.
3
Generate a signing secret
Macropay signs every delivery with this secret so you can prove the request really came from us. Copy it.
4
Store it in Encore
Terminal
Tunnel events to localhost
Encore runs your full app locally, so you just need to forward Macropay’s events to it. The Macropay CLI tunnels deliveries straight to your machine:Terminal
Terminal
Write the handler
Useapi.raw() so you can read the unparsed request body — signature verification runs against the exact bytes that were signed, so any reframing would invalidate it.
payments/payments.ts
Run it locally
Terminal
localhost:9400. For a billing integration it earns its keep:
- Distributed traces for every request — including the checkout redirect and each webhook delivery
- Service-to-service calls laid out so you can see what your code did with an event
- Local database queries to confirm your records updated
- Live logs and errors as flows run
Deploy to production
Ship to Encore Cloud (or your own cloud account) with:Terminal
- Set the production
MACROPAY_ACCESS_TOKEN,MACROPAY_MODE, andMACROPAY_WEBHOOK_SECRETin the Encore Cloud dashboard. - Set
MACROPAY_MODEtoproductionso the SDK targets the live API. - Update the webhook endpoint in Macropay to your production domain.
- Point
successUrlat your production confirmation page.