This repository is a collection of practical TypeScript demo projects showing how to use the OpenPay API via the TypeScript SDK (@getopenpay/client). These examples cover common tasks in OpenPay integrations – from creating checkout sessions to handling webhooks and invoices with TypeScript.
This repository includes several examples (each in its own folder) giving more details on how to work with OpenPay’s use cases:
- Hosted Checkout: Shows how to create a hosted checkout session with OpenPay’s REST API and redirects the user to a payment page. Using the TypeScript SDK, the example calls
client.checkoutApi.createCheckoutSession(...)to generate a session and then redirects tocheckoutSession.url. This mirrors the OpenPay docs example for creating a subscription checkout. - One-time Invoice: This showcases creating and paying a one-off invoice via the API. OpenPay supports one-time (non-subscription) invoices for single purchases. This example uses the SDK to draft an invoice (
createInvoice) for a customer and then finalize/pay it. The code closely follows the official recipe for one-off payments (creating an invoice withinvoiceType=ONE_OFFand then finalizing it). - Metered (Overage) Billing: This example shows to simulate an overage-style one-time charge using OpenPay's REST API (without subscriptions or metered tiers). This example creates a product and a one-time price, and then immediately generates an invoice using raw
axioscalls. It’s useful when you want to charge customers for excess usage via APIs in a single invoice.
These examples use the official OpenPay TypeScript SDK package @getopenpay/client. All example code assumes this (or a compatible) version of the SDK is installed. Make sure your package.json references the same version or newer.
-
Clone the repo:
git clone https://github.com/getopenpay/openpay-ts-examples.git cd openpay-ts-examples -
Install dependencies:
Each example uses Node.js and npm. From the root (or inside an example folder), run:
npm install
This will install the OpenPay client and other dependencies. (For example, you should see
@getopenpay/clientinstalled – you can also runnpm install @getopenpay/clientexplicitly as shown in the code that works with OpenPay’s SDK.) -
Configure API keys:
Refer to this guide to learn how to get your Secret and Publishable keys in OpenPay.
You need to supply your OpenPay Publishable Key and Secret Key. Edit the example’s configuration (often in code or a
.envfile) to include:const config = new Configuration({ basePath: 'https://connto.getopenpay.com', // or staging URL apiKey: 'YOUR_PUBLISHABLE_KEY', accessToken: 'YOUR_SECRET_KEY' }); const client = new OpenPayClient(config);
(This follows the official setup pattern in the hosted checkout docs.) Replace the placeholders with your actual API credentials from the OpenPay dashboard.
-
Other settings:
- Make sure you have Node.js ≥14 installed.
Each example typically runs as a small server or script. To launch an example:
-
Navigate into the example’s directory.
-
Run
npm install(if not already done) and then start the app, e.g.:npm run start
or
npx ts-node src/index.ts
-
Follow any on-screen logs or instructions. For instance, the Hosted Checkout example may listen on a port and provide a “Subscribe” button.
For detailed API references and guides, see the OpenPay’s Official documentation.