Encore is an open source backend framework for TypeScript with built-in infrastructure automation and observability. When you define services, databases, and APIs in code, Encore automatically provisions and manages the underlying infrastructure, both locally and in the cloud. Because Encore defines infrastructure in code and provides built-in distributed tracing, AI coding assistants can both build and debug your backend end-to-end, including your OurPay integration. They can read the code to understand the full system, then inspect traces to diagnose exactly what happened when a checkout completes or a webhook arrives. Consider following this guide while using the OurPay Sandbox Environment. This will allow you to test your integration without affecting your production data.

Install the OurPay JavaScript SDK

Install the official OurPay SDK:
Terminal

Setting up Secrets

Encore has built-in secrets management that works consistently across local development and cloud environments.

OurPay Access Token and Mode

To authenticate with OurPay, you need to create an access token and specify if it’s production or sandbox mode. You can create an organization access token from your organization settings. Add it to Encore using the secrets manager:
Terminal

OurPay Webhook Secret

You’ll need a webhook secret to verify incoming webhook events. We’ll set this up in the webhook section below.
Terminal
When deploying to Encore Cloud, you’ll set production secrets through the dashboard or CI/CD pipeline.

Configuring an OurPay API Client

To interact with the OurPay API, create a versioned client using Encore’s secret management.
payments/ourpay.ts
Remember to set OURPAY_MODE as production when you’re ready to switch to the production environment.

Generating OurPay Checkout Sessions

Create a checkout endpoint that creates a OurPay checkout session and redirects the user.
payments/payments.ts
You can now create a checkout session by visiting /checkout?product=YOUR_PRODUCT_ID.

Handling OurPay Webhooks

OurPay can send you events about various things happening in your organization. This is useful for keeping your database in sync with OurPay checkouts, orders, subscriptions, etc. Configuring a webhook is simple. Head over to your organization’s settings page and click on the “Add Endpoint” button to create a new webhook.

Tunneling webhook events to your local development environment

Encore runs your app locally with full infrastructure support. Expose the local port through an HTTPS tunnel, then register its forwarding URL as a sandbox webhook endpoint:
Terminal
Make sure to copy the webhook secret and set it using:
Terminal

Add Webhook Endpoint

  1. Point the Webhook to your-app.com/webhooks/ourpay. This must be an absolute HTTPS URL which OurPay can reach. During local development, use your tunnel origin plus /webhooks/ourpay.
  2. Select which events you want to be notified about. You can read more about the available events in the Events section.
  3. Generate a secret key to sign the requests. This will allow you to verify that the requests are truly coming from OurPay.
  4. Add the secret key to Encore:
Terminal

Setting up the Webhook handler

Encore webhook handlers use api.raw() to access the raw request body, which is required for signature verification.
payments/payments.ts

Local Development

Start your Encore app:
Terminal
Encore provides a local development dashboard at localhost:9400 where you can:
  • View distributed traces for all requests, including checkout redirects and webhook deliveries
  • Inspect API calls between services
  • Query local databases
  • View logs and errors in real-time
This makes debugging payment flows straightforward since you can trace exactly what happens when a checkout completes or a webhook arrives.

Deploying to Production

When you’re ready to go live, deploy to Encore Cloud or your own cloud account:
Terminal
Encore automatically provisions all the infrastructure your app needs. Remember to:
  1. Set production secrets in the Encore Cloud dashboard
  2. Update the environment option from "sandbox" to "production" in your OurPay client
  3. Update your webhook URL in OurPay to point to your production domain
  4. Update success_url to your production URL