Skip to content

Commit

Permalink
Merge pull request #6 from peoray/checkout-methods
Browse files Browse the repository at this point in the history
Add checkout method
  • Loading branch information
peoray committed Jan 26, 2024
2 parents 835babf + 3bfd710 commit 56a5147
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
20 changes: 20 additions & 0 deletions examples/checkout/create-checkout.ts
Original file line number Diff line number Diff line change
@@ -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()
7 changes: 6 additions & 1 deletion src/bloc.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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)
}
}
27 changes: 27 additions & 0 deletions src/services/checkout.ts
Original file line number Diff line number Diff line change
@@ -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<ICheckoutResponse>} A promise that resolves to the checkout response.
*/
public async createCheckout(
data: ICreateCheckout
): Promise<ICheckoutResponse> {
return this.post<ICheckoutResponse>(`/checkout/new`, data)
}
}
1 change: 1 addition & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './customer'
export * from './beneficary'
export * from './webhook'
export * from './checkout'
12 changes: 12 additions & 0 deletions src/types/checkout.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './customer'
export * from './beneficiary'
export * from './webhook'
export * from './checkout'

0 comments on commit 56a5147

Please sign in to comment.