Skip to content

Commit

Permalink
Merge pull request #8 from peoray/miscellaneous-methods
Browse files Browse the repository at this point in the history
Add Miscellaneous methods
  • Loading branch information
peoray authored Jan 26, 2024
2 parents bf0ca46 + 0c13368 commit 335328f
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/miscellaneous/get-exchange-rate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Bloc } from '../../dist'

const bloc = new Bloc('secret-keyasfasfbahfb', 'public-key')

const getExchangeRate = async () => {
try {
const rate = await bloc.getExchangeRate('USD-NGN')
console.log(rate)
} catch (error) {
console.error(error)
}
}

getExchangeRate()
14 changes: 14 additions & 0 deletions examples/miscellaneous/get-list-of-banks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Bloc } from '../../dist'

const bloc = new Bloc('secret-keyasfasfbahfb', 'public-key')

const getListOfBanks = async () => {
try {
const banks = await bloc.getListOfBanks()
console.log(banks)
} catch (error) {
console.error(error)
}
}

getListOfBanks()
14 changes: 14 additions & 0 deletions examples/miscellaneous/resolve-account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Bloc } from '../../dist'

const bloc = new Bloc('secret-keyasfasfbahfb', 'public-key')

const resolveAccount = async () => {
try {
const account = await bloc.resolveAccount() // add query params
console.log(account)
} catch (error) {
console.error(error)
}
}

resolveAccount()
12 changes: 12 additions & 0 deletions src/bloc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Checkout,
Simulation,
Transaction,
Miscellaneous,
} from './services'

export class Bloc {
Expand All @@ -14,6 +15,7 @@ export class Bloc {
private webhook: Webhook
private checkout: Checkout
private simulation: Simulation
private miscellaneous: Miscellaneous

constructor(secretKey: string, publicKey: string) {
this.customer = new Customer(secretKey, publicKey)
Expand All @@ -22,6 +24,7 @@ export class Bloc {
this.webhook = new Webhook(secretKey, publicKey)
this.checkout = new Checkout(secretKey, publicKey)
this.simulation = new Simulation(secretKey, publicKey)
this.miscellaneous = new Miscellaneous(secretKey, publicKey)
}

public get createCustomer() {
Expand Down Expand Up @@ -84,4 +87,13 @@ export class Bloc {
public get debitAccount() {
return this.simulation.debitAccount.bind(this.simulation)
}
public get getListOfBanks() {
return this.miscellaneous.getListOfBanks.bind(this.miscellaneous)
}
public get resolveAccount() {
return this.miscellaneous.resolveAccount.bind(this.miscellaneous)
}
public get getExchangeRate() {
return this.miscellaneous.getExchangeRate.bind(this.miscellaneous)
}
}
1 change: 1 addition & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './transaction'
export * from './webhook'
export * from './checkout'
export * from './simulation'
export * from './miscellaneous'
53 changes: 53 additions & 0 deletions src/services/miscellaneous.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { HTTPCore } from '../api'
import {
IGetExchangeRateResponse,
IListOfBanksResponse,
IResolveAccountResponse,
} from '../types'
import { IQueryParams } from '../types/base'

/**
* Class representing operations related to Miscellaneous, extending HTTPCore.
*/
export class Miscellaneous extends HTTPCore {
/**
* Creates an instance of the Miscellaneous 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)
}

/**
* Gets a list of banks.
* @returns {Promise<IListOfBanksResponse>} A promise that resolves to the response containing the list of banks.
*/
public async getListOfBanks(): Promise<IListOfBanksResponse> {
return this.get<IListOfBanksResponse>(`/banks`)
}

/**
* Resolves account information.
* @param {IQueryParams} params - Query parameters for resolving account.
* @returns {Promise<IResolveAccountResponse>} A promise that resolves to the response containing the resolved account information.
*/
public async resolveAccount(
params?: IQueryParams
): Promise<IResolveAccountResponse> {
return this.get<IResolveAccountResponse>(`/resolve-account`, { params })
}

/**
* Gets the exchange rate for a currency pair.
* @param {string} currencyPair - The currency pair for which to retrieve the exchange rate.
* @returns {Promise<IGetExchangeRateResponse>} A promise that resolves to the response containing the exchange rate.
*/
public async getExchangeRate(
currencyPair: string
): Promise<IGetExchangeRateResponse> {
return this.get<IGetExchangeRateResponse>(
`/rates/currencies/${currencyPair}`
)
}
}
2 changes: 2 additions & 0 deletions src/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export interface IQueryParams {
}
per_page?: number
start_date?: string
account_number?: string
bank_code?: string
end_date?: string
status?: string
drcr?: string
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './transaction'
export * from './webhook'
export * from './checkout'
export * from './simulation'
export * from './miscellaneous'
27 changes: 27 additions & 0 deletions src/types/miscellaneous.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface IListOfBanksResponse {
success: boolean
data: {
bank_name: string
short_code: string
bank_code: string
}[]
message: string
}

export interface IResolveAccountResponse {
success: boolean
data: {
account_name: string
account_number: string
}[]
message: string
}

export interface IGetExchangeRateResponse {
success: boolean
data: {
buy: string
sell: string
}[]
message: string
}

0 comments on commit 335328f

Please sign in to comment.