kohortpay-node v0.2.5
kohortPay
SDK Installation
NPM
npm add kohortpay-node
Yarn
yarn add kohortpay-node
SDK Example Usage
Example
import { KohortPay, Status } from "kohortpay-node";
async function run() {
const sdk = new KohortPay({
bearer: "<YOUR_BEARER_TOKEN_HERE>",
});
const res = await sdk.paymentIntents.create({
amount: 5000,
checkoutSessionId: "cs_1abc2def3ghi",
customerId: "cus_1abc2def3ghi",
metadata: {},
status: Status.RequiresPaymentMethod,
});
if (res.statusCode == 200) {
// handle response
}
}
run();
Available Resources and Operations
paymentIntents
- create - Create a new Payment Intent
- findAll - Retrieve all Payment Intents
- findOne - Retrieve a Payment Intent by ID
- cancel - Cancel a Payment Intent by ID
paymentGroups
- create - Create a new payment group
- findAll - Retrieve all payment groups
- findOne - Retrieve a payment group by id
- update - Update a payment group by id
- getParticipants - Retrieve participants of a payment group by id
- cancel - Cancel a payment group by id
- expire - Expire a payment group by id
- validatePaymentGroup - Validate a payment group by id
customers
- create - Create a new customer.
- findAll - find All customers of an organization.
- findOne - find All customers of an organization.
- updateCustomer - Update a customer.
- delete - Delete a customer.
checkoutSessions
- create - Create a new checkout session.
- findAll - Retrieve all checkout sessions for the current organization and livemode.
- findOne - Retrieve a checkout session by ID for the current organization and livemode.
- expire - Expire a checkout session by ID for the current organization and livemode.
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
Error Object | Status Code | Content Type |
---|---|---|
models.SDKError | 4xx-5xx | / |
Example
import { KohortPay, Status } from "kohortpay-node";
async function run() {
const sdk = new KohortPay({
bearer: "<YOUR_BEARER_TOKEN_HERE>",
});
let res;
try {
res = await sdk.paymentIntents.create({
amount: 5000,
checkoutSessionId: "cs_1abc2def3ghi",
customerId: "cus_1abc2def3ghi",
metadata: {},
status: Status.RequiresPaymentMethod,
});
} catch (err) {
if (err instanceof models.SDKError) {
console.error(err); // handle exception
throw err;
}
}
if (res.statusCode == 200) {
// handle response
}
}
run();
Server Selection
Select Server by Index
You can override the default server globally by passing a server index to the serverIdx: number
optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://api.kohortpay.com | None |
Example
import { KohortPay, Status } from "kohortpay-node";
async function run() {
const sdk = new KohortPay({
serverIdx: 0,
bearer: "<YOUR_BEARER_TOKEN_HERE>",
});
const res = await sdk.paymentIntents.create({
amount: 5000,
checkoutSessionId: "cs_1abc2def3ghi",
customerId: "cus_1abc2def3ghi",
metadata: {},
status: Status.RequiresPaymentMethod,
});
if (res.statusCode == 200) {
// handle response
}
}
run();
Override Server URL Per-Client
The default server can also be overridden globally by passing a URL to the serverURL: str
optional parameter when initializing the SDK client instance. For example:
import { KohortPay, Status } from "kohortpay-node";
async function run() {
const sdk = new KohortPay({
serverURL: "https://api.kohortpay.com",
bearer: "<YOUR_BEARER_TOKEN_HERE>",
});
const res = await sdk.paymentIntents.create({
amount: 5000,
checkoutSessionId: "cs_1abc2def3ghi",
customerId: "cus_1abc2def3ghi",
metadata: {},
status: Status.RequiresPaymentMethod,
});
if (res.statusCode == 200) {
// handle response
}
}
run();
Custom HTTP Client
The Typescript SDK makes API calls using the axios HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom AxiosInstance
object.
For example, you could specify a header for every request that your sdk makes as follows:
import { kohortpay-node } from "KohortPay";
import axios from "axios";
const httpClient = axios.create({
headers: {'x-custom-header': 'someValue'}
})
const sdk = new KohortPay({defaultClient: httpClient});
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
bearer | http | HTTP Bearer |
To authenticate with the API the bearer
parameter must be set when initializing the SDK client instance. For example:
import { KohortPay, Status } from "kohortpay-node";
async function run() {
const sdk = new KohortPay({
bearer: "<YOUR_BEARER_TOKEN_HERE>",
});
const res = await sdk.paymentIntents.create({
amount: 5000,
checkoutSessionId: "cs_1abc2def3ghi",
customerId: "cus_1abc2def3ghi",
metadata: {},
status: Status.RequiresPaymentMethod,
});
if (res.statusCode == 200) {
// handle response
}
}
run();
Per-Operation Security Schemes
Some operations in this SDK require the security scheme to be specified at the request level. For example:
import { CancelPaymentIntentRequest, CancelPaymentIntentSecurity, KohortPay } from "kohortpay-node";
async function run() {
const sdk = new KohortPay();
const id: string = "<value>";
const operationSecurity: CancelPaymentIntentSecurity = {
bearer: "<YOUR_BEARER_TOKEN_HERE>",
};
const res = await sdk.paymentIntents.cancel(operationSecurity, id);
if (res.statusCode == 200) {
// handle response
}
}
run();
Development
Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!