0.2.5 • Published 2 months ago

kohortpay-node v0.2.5

Weekly downloads
-
License
-
Repository
github
Last release
2 months ago

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

customers

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 ObjectStatus CodeContent Type
models.SDKError4xx-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:

#ServerVariables
0https://api.kohortpay.comNone

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:

NameTypeScheme
bearerhttpHTTP 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!

SDK Created by Speakeasy

0.2.5

2 months ago

0.2.4

3 months ago

0.2.3

3 months ago

0.2.2

3 months ago

0.2.1

5 months ago

0.2.0

5 months ago

0.1.7

5 months ago

0.1.6

5 months ago

0.1.5

5 months ago

0.1.4

5 months ago