kohortpay v0.3.2
kohortPay/sdk
🏗 Welcome to your new SDK! 🏗
It has been generated successfully based on your OpenAPI spec. However, it is not yet ready for production use. Here are some next steps:
- 🛠 Make your SDK feel handcrafted by customizing it
- ♻️ Refine your SDK quickly by iterating locally with the Speakeasy CLI
- 🎁 Publish your SDK to package managers by configuring automatic publishing
- ✨ When ready to productionize, delete this section from the README
SDK Installation
NPM
npm add kohortpay
Yarn
yarn add kohortpay
SDK Example Usage
Example
import { KohortPay } from "kohortpay";
import { CheckoutSessionsControllerCreateSecurity } from "kohortpay/dist/sdk/models/operations";
(async () => {
const sdk = new KohortPay();
const operationSecurity: CheckoutSessionsControllerCreateSecurity = {
basic: {
password: "",
username: "",
},
};
const res = await sdk.checkoutSessionsAPI.checkoutSessionsControllerCreate(
{
cancelUrl: "https://cancel.example.com",
customerEmail: "customer@example.com",
customerFirstName: "John",
customerId: "user_xxxxxxxxxxxxxxxx",
customerLastName: "Doe",
expiresAt: new Date("2023-10-02T14:30:00.000Z"),
lineItems: [
{
description: "Item Description",
imageUrl: "https://example.com/image.jpg",
name: "Item Name",
price: 100,
quantity: 1,
},
],
metadata: {},
successUrl: "https://success.example.com",
},
operationSecurity
);
if (res.statusCode == 200) {
// handle response
}
})();
Available Resources and Operations
checkoutSessionsAPI
- checkoutSessionsControllerCreate - Create a new checkout session.
- checkoutSessionsControllerExpire - Expire a checkout session by ID for the current organization and livemode.
- checkoutSessionsControllerFindAll - Retrieve all checkout sessions for the current organization and livemode.
- checkoutSessionsControllerFindOne - Retrieve a checkout session by ID for the current organization and livemode.
organizations
- organizationsControllerFindCheckoutSettings - Retrieve checkout settings for a specified organization ID.
- organizationsControllerFindPaymentGroupSettings
- organizationsControllerUpdate - Update the details of a specified organization.
- organizationsControllerUpdateCheckoutSettings - Update checkout settings for a specified organization ID.
- organizationsControllerUpdatePaymentGroupSettings - Update an organization by ID.
- organizationsFindOne - Retrieve an organization by ID or Clerk ID.
paymentGroupSettingsAPI
- paymentGroupSettingsControllerFindOne - Retrieve payment group settings by ID.
- paymentGroupSettingsControllerUpdate - Update payment group settings by ID.
paymentGroups
- paymentGroupsControllerCancel - Cancel a payment group by id
- paymentGroupsControllerCreate - Create a new payment group
- paymentGroupsControllerExpire - Expire a payment group by id
- paymentGroupsControllerFindAll - Retrieve all payment groups
- paymentGroupsControllerFindOne - Retrieve a payment group by id
- paymentGroupsControllerParticipants - Retrieve participants of a payment group by id
- paymentGroupsControllerUpdate - Update a payment group by id
- paymentGroupsControllerValidate - Validate a payment group by id
paymentIntents
- paymentIntentsControllerCancel - Cancel a Payment Intent by ID
- paymentIntentsControllerCreate - Create a new Payment Intent
- paymentIntentsControllerFindAll - Retrieve all Payment Intents
- paymentIntentsControllerFindOne - Retrieve a Payment Intent by ID
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 |
---|---|---|
errors.BadRequestResponse | 400,401,404 | application/json |
errors.ErrorT | 500 | application/json |
errors.SDKError | 400-600 | / |
Example
import { KohortPay } from "kohortpay";
import { CheckoutSessionsControllerCreateSecurity } from "kohortpay/dist/sdk/models/operations";
(async () => {
const sdk = new KohortPay();
const operationSecurity: CheckoutSessionsControllerCreateSecurity = {
basic: {
password: "",
username: "",
},
};
let res;
try {
res = await sdk.checkoutSessionsAPI.checkoutSessionsControllerCreate(
{
cancelUrl: "https://cancel.example.com",
customerEmail: "customer@example.com",
customerFirstName: "John",
customerId: "user_xxxxxxxxxxxxxxxx",
customerLastName: "Doe",
expiresAt: new Date("2023-10-02T14:30:00.000Z"),
lineItems: [
{
description: "Item Description",
imageUrl: "https://example.com/image.jpg",
name: "Item Name",
price: 100,
quantity: 1,
},
],
metadata: {},
successUrl: "https://success.example.com",
},
operationSecurity
);
} catch (e) {
if (e instanceof errors.BadRequestResponse) {
console.error(e); // handle exception
} else if (e instanceof errors.ErrorT) {
console.error(e); // handle exception
} else if (e instanceof errors.SDKError) {
console.error(e); // handle exception
}
}
if (res.statusCode == 200) {
// handle response
}
})();
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 } from "kohortpay";
import { CheckoutSessionsControllerCreateSecurity } from "kohortpay/dist/sdk/models/operations";
(async () => {
const sdk = new KohortPay({
serverIdx: 0,
});
const operationSecurity: CheckoutSessionsControllerCreateSecurity = {
basic: {
password: "",
username: "",
},
};
const res = await sdk.checkoutSessionsAPI.checkoutSessionsControllerCreate(
{
cancelUrl: "https://cancel.example.com",
customerEmail: "customer@example.com",
customerFirstName: "John",
customerId: "user_xxxxxxxxxxxxxxxx",
customerLastName: "Doe",
expiresAt: new Date("2023-10-02T14:30:00.000Z"),
lineItems: [
{
description: "Item Description",
imageUrl: "https://example.com/image.jpg",
name: "Item Name",
price: 100,
quantity: 1,
},
],
metadata: {},
successUrl: "https://success.example.com",
},
operationSecurity
);
if (res.statusCode == 200) {
// handle response
}
})();
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 } from "kohortpay";
import { CheckoutSessionsControllerCreateSecurity } from "kohortpay/dist/sdk/models/operations";
(async () => {
const sdk = new KohortPay({
serverURL: "https://api.kohortpay.com",
});
const operationSecurity: CheckoutSessionsControllerCreateSecurity = {
basic: {
password: "",
username: "",
},
};
const res = await sdk.checkoutSessionsAPI.checkoutSessionsControllerCreate(
{
cancelUrl: "https://cancel.example.com",
customerEmail: "customer@example.com",
customerFirstName: "John",
customerId: "user_xxxxxxxxxxxxxxxx",
customerLastName: "Doe",
expiresAt: new Date("2023-10-02T14:30:00.000Z"),
lineItems: [
{
description: "Item Description",
imageUrl: "https://example.com/image.jpg",
name: "Item Name",
price: 100,
quantity: 1,
},
],
metadata: {},
successUrl: "https://success.example.com",
},
operationSecurity
);
if (res.statusCode == 200) {
// handle response
}
})();
Custom HTTP Client
The Typescript SDK makes API calls using the (axios)https://axios-http.com/docs/intro 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:
from kohortpay import KohortPay;
import 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 } from "kohortpay";
import { CheckoutSessionsControllerCreateSecurity } from "kohortpay/dist/sdk/models/operations";
(async () => {
const sdk = new KohortPay();
const operationSecurity: CheckoutSessionsControllerCreateSecurity = {
basic: {
password: "",
username: "",
},
};
const res = await sdk.checkoutSessionsAPI.checkoutSessionsControllerCreate(
{
cancelUrl: "https://cancel.example.com",
customerEmail: "customer@example.com",
customerFirstName: "John",
customerId: "user_xxxxxxxxxxxxxxxx",
customerLastName: "Doe",
expiresAt: new Date("2023-10-02T14:30:00.000Z"),
lineItems: [
{
description: "Item Description",
imageUrl: "https://example.com/image.jpg",
name: "Item Name",
price: 100,
quantity: 1,
},
],
metadata: {},
successUrl: "https://success.example.com",
},
operationSecurity
);
if (res.statusCode == 200) {
// handle response
}
})();
Per-Operation Security Schemes
Some operations in this SDK require the security scheme to be specified at the request level. For example:
import { KohortPay } from "kohortpay";
import { CheckoutSessionsControllerCreateSecurity } from "kohortpay/dist/sdk/models/operations";
(async () => {
const sdk = new KohortPay();
const operationSecurity: CheckoutSessionsControllerCreateSecurity = {
basic: {
password: "",
username: "",
},
};
const res = await sdk.checkoutSessionsAPI.checkoutSessionsControllerCreate(
{
cancelUrl: "https://cancel.example.com",
customerEmail: "customer@example.com",
customerFirstName: "John",
customerId: "user_xxxxxxxxxxxxxxxx",
customerLastName: "Doe",
expiresAt: new Date("2023-10-02T14:30:00.000Z"),
lineItems: [
{
description: "Item Description",
imageUrl: "https://example.com/image.jpg",
name: "Item Name",
price: 100,
quantity: 1,
},
],
metadata: {},
successUrl: "https://success.example.com",
},
operationSecurity
);
if (res.statusCode == 200) {
// handle response
}
})();
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!