0.3.2 • Published 6 months ago

kohortpay v0.3.2

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

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:

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

organizations

paymentGroupSettingsAPI

paymentGroups

paymentIntents

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
errors.BadRequestResponse400,401,404application/json
errors.ErrorT500application/json
errors.SDKError400-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:

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

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:

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

SDK Created by Speakeasy

0.3.2

6 months ago

0.3.1

6 months ago

0.3.0

6 months ago