TypeScript SDK
The OpenPay TypeScript SDK (@getopenpay/client
) helps developers integrate OpenPay into TypeScript projects with ease. It offers convenient bindings around the OpenPay API, abstracting HTTP calls and request shaping. This guide helps you use the package to integrate with OpenPay’s API using TypeScript.
To start working with the TypeScript SDK, follow the next steps:
InstallationCopied!
npm install @getopenpay/client
yarn add @getopenpay/client
SDK ArchitectureCopied!
The OpenPay SDK is auto-generated from an OpenAPI schema and exports:
-
A
Configuration
class for API key setup -
A set of resource-specific API classes like
CustomersApi
andSubscriptionsApi
-
Fully-typed method inputs and outputs (via interfaces like
CustomerCreateParams
, etc.)
Step 1: Initialize the SDKCopied!
You must create a Configuration
instance and use it to instantiate each API class.
import { Configuration } from '@getopenpay/client';
const config = new Configuration({
basePath: 'https://connto.getopenpay.com', // REQUIRED: OpenPay API base
accessToken: 'sk_test_abc123', // REQUIRED: your secret key
});
You then pass this config to an API client:
import { CustomersApi } from '@getopenpay/client';
const customers = new CustomersApi(config);
Example: Create a CustomerCopied!
const createdCustomer = await customers.createCustomer({
createCustomerRequest: {
email: 'opemipo@disu.com',
},
});
Note:
-
The argument must match the exact structure expected, for example, an object with a
createCustomerRequest
property.
Example: Create a SubscriptionCopied!
import { SubscriptionsApi } from '@getopenpay/client';
const subscriptions = new SubscriptionsApi(config);
const result = await subscriptions.createSubscription({
createSubscriptionRequest: {
customerId: 'cus_abc123',
subscriptionItems: [
{
priceId: 'price_xyz456',
},
],
},
});
Reminder:
-
priceId
andcustomerId
must refer to existing resources. These are typically created using thePricesApi
andCustomersApi
, respectively.
Example: List SubscriptionsCopied!
The listSubscriptions
method requires a non-empty object with a subscriptionQueryParams
key.
const result = await subscriptions.listSubscriptions({
subscriptionQueryParams: {},
});
If you remove subscriptionQueryParams, or pass undefined, TypeScript will throw an error.
Type Safety & AutocompletionCopied!
Every method expects a named object input, and the SDK ships with full types like:
import type { CustomerCreateParams } from '@getopenpay/client';
const payload: CustomerCreateParams = {
name: 'Jane Doe',
email: 'jane@example.com',
};
This enables full IntelliSense and compile-time validation.
Error HandlingCopied!
The SDK throws a ResponseError
when an HTTP error occurs:
import { ResponseError } from '@getopenpay/client';
try {
await customers.getCustomer({ customer_id: 'invalid-id' });
} catch (error) {
if (error instanceof ResponseError) {
const body = await error.response.json();
console.error('OpenPay API Error:', body);
} else {
console.error(error);
}
}
Example Project StructureCopied!
// openpayClient.ts
import {
Configuration,
CustomersApi,
SubscriptionsApi,
} from '@getopenpay/client';
const config = new Configuration({
basePath: '<https://connto.getopenpay.com>',
accessToken: process.env.OPENPAY_SECRET_KEY!,
});
export const OpenPay = {
customers: new CustomersApi(config),
subscriptions: new SubscriptionsApi(config),
};
Then in your app:
import { OpenPay } from './openpayClient';
await OpenPay.customers.createCustomer({
customerCreateParams: { name: 'Ope', email: 'ope@example.com' }
});
NotesCopied!
-
Most methods follow the pattern:
api.method({ methodSpecificParams: {...} })
-
All API endpoints are documented here.
-
The SDK is designed to make direct REST interactions easier while preserving OpenPay’s API shape and constraints.
-
You can inspect request/response bodies from your OpenPay dashboard or logs.