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
Configuring an OurPay API Client
To interact with the OurPay API, create a versioned client using Encore’s secret management.payments/ourpay.ts
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
/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
Terminal
Add Webhook Endpoint
- 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. - Select which events you want to be notified about. You can read more about the available events in the Events section.
- Generate a secret key to sign the requests. This will allow you to verify that the requests are truly coming from OurPay.
- Add the secret key to Encore:
Terminal
Setting up the Webhook handler
Encore webhook handlers useapi.raw() to access the raw request body, which is required for signature verification.
payments/payments.ts
Local Development
Start your Encore app:Terminal
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
Deploying to Production
When you’re ready to go live, deploy to Encore Cloud or your own cloud account:Terminal
- Set production secrets in the Encore Cloud dashboard
- Update the
environmentoption from"sandbox"to"production"in your OurPay client - Update your webhook URL in OurPay to point to your production domain
- Update
success_urlto your production URL