diff --git a/examples/checkout/create-checkout.ts b/examples/checkout/create-checkout.ts new file mode 100644 index 0000000..fe2f098 --- /dev/null +++ b/examples/checkout/create-checkout.ts @@ -0,0 +1,20 @@ +import { Bloc, ICreateCheckout } from '../../dist' + +const bloc = new Bloc('secret-keyasfasfbahfb', 'public-key') + +const createCheckout = async () => { + try { + const data: ICreateCheckout = { + customer_email: 'jerry@orchs.xyz', + customer_name: 'jerry', + country: 'Nigeria', + amount: 100000, + } + const response = await bloc.createCheckout(data) + console.log(response) + } catch (error) { + console.error(error) + } +} + +createCheckout() diff --git a/src/bloc.ts b/src/bloc.ts index 3dbfc23..0019d20 100644 --- a/src/bloc.ts +++ b/src/bloc.ts @@ -1,14 +1,16 @@ -import { Customer, Beneficiary, Webhook } from './services' +import { Customer, Beneficiary, Webhook, Checkout } from './services' export class Bloc { private customer: Customer private beneficiary: Beneficiary private webhook: Webhook + private checkout: Checkout constructor(secretKey: string, publicKey: string) { this.customer = new Customer(secretKey, publicKey) this.beneficiary = new Beneficiary(secretKey, publicKey) this.webhook = new Webhook(secretKey, publicKey) + this.checkout = new Checkout(secretKey, publicKey) } public get createCustomer() { @@ -56,4 +58,7 @@ export class Bloc { public get getWebhook() { return this.webhook.getWebhook.bind(this.webhook) } + public get createCheckout() { + return this.checkout.createCheckout.bind(this.checkout) + } } diff --git a/src/services/checkout.ts b/src/services/checkout.ts new file mode 100644 index 0000000..7118ea8 --- /dev/null +++ b/src/services/checkout.ts @@ -0,0 +1,27 @@ +import { HTTPCore } from '../api' +import { ICheckoutResponse, ICreateCheckout } from '../types' + +/** + * Class representing operations related to Checkouts, extending HTTPCore. + */ +export class Checkout extends HTTPCore { + /** + * Creates an instance of the Webhook class. + * @param {string} secretKey - The secret key for authentication. + * @param {string} publicKey - The public key for authentication. + */ + constructor(public secretKey: string, public publicKey: string) { + super(secretKey, publicKey) + } + + /** + * Creates a new checkout using the provided data. + * @param {ICreateCheckout} data - The data to create the checkout. + * @returns {Promise} A promise that resolves to the checkout response. + */ + public async createCheckout( + data: ICreateCheckout + ): Promise { + return this.post(`/checkout/new`, data) + } +} diff --git a/src/services/index.ts b/src/services/index.ts index e6d3620..aec47dd 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,3 +1,4 @@ export * from './customer' export * from './beneficary' export * from './webhook' +export * from './checkout' diff --git a/src/types/checkout.ts b/src/types/checkout.ts new file mode 100644 index 0000000..f1b0a75 --- /dev/null +++ b/src/types/checkout.ts @@ -0,0 +1,12 @@ +export interface ICreateCheckout { + customer_email: string + customer_name: string + country: string + amount: number +} + +export interface ICheckoutResponse { + success: boolean + data: string + message: string +} diff --git a/src/types/index.ts b/src/types/index.ts index 9a80201..30b7ba2 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,4 @@ export * from './customer' export * from './beneficiary' export * from './webhook' +export * from './checkout'