Skip to content

Commit

Permalink
Merge pull request #14 from peoray/transfers-methods
Browse files Browse the repository at this point in the history
Add transfers methods
  • Loading branch information
peoray committed Jan 29, 2024
2 parents 5932595 + 8a75752 commit 00754ce
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 1 deletion.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ A Nodejs API wrapper for [Bloc](https://www.blochq.io/) banking services written
- [Transactions API](#transactions-api)
- [Get All Transactions](#get-all-transactions)
- [Get Transaction by Reference](#get-transaction-by-reference)
- [Transfers API](#transfer-api)
- [Transfer From A Fixed Account](#transfer-from-a-fixed-account)
- [Transfer From Organization Balance](#transfer-from-organization-balance)
- [Internal transfer](#internal-transfer)
- [Bulk transfer](#bulk-transfer)
- [Webhook API](#webhook-api)
- [Set Webhook](#set-webhook)
- [Get Webhook](#get-webhook)
Expand Down Expand Up @@ -571,6 +576,75 @@ console.log(response) // ITransactionByReferenceResponse

Find more details about the parameters and response for the above method [here](https://docs.blochq.io/reference/getalltransactions)


### Transfers API

Transfers API operations

#### Transfer From A Fixed Account

```ts
// import the transfers interfaces from the sdk
import type { ITransferFromAFixedAccountRequest, ITransferResponse } from 'bloc-nodejs';

const payload: ITransferFromAFixedAccountRequest = {
// payload data
}

const response = await bloc.transferFromAFixedAccount(payload)
console.log(response) // ITransferResponse
```

Find more details about the parameters and response for the above method [here](https://docs.blochq.io/reference/transferfromafixedaccount)

#### Transfer From Organization Balance

```ts
// import the transfers interfaces from the sdk
import type { ITransferFromOrganizationBalance, ITransferResponse } from 'bloc-nodejs';

const payload: ITransferFromOrganizationBalance = {
// payload data
}

const response = await bloc.transferFromOrganizationBalance(payload)
console.log(response) // ITransferResponse
```

Find more details about the parameters and response for the above method [here](https://docs.blochq.io/reference/transferfromorganizationbalance)

#### Internal Transfer

```ts
// import the transfers interfaces from the sdk
import type { IInternalTransferRequest, ITransferResponse } from 'bloc-nodejs';

const payload: IInternalTransferRequest = {
// payload data
}

const response = await bloc.internalTransfer(payload)
console.log(response) // ITransferResponse
```

Find more details about the parameters and response for the above method [here](https://docs.blochq.io/reference/internaltransfer)

#### Bulk Transfer

```ts
// import the transfers interfaces from the sdk
import type { IBulkTransferRequest, ITransferResponse } from 'bloc-nodejs';

const payload: IBulkTransferRequest = {
// payload data
}

const response = await bloc.bulkTransfer(payload)
console.log(response) // ITransferResponse
```

Find more details about the parameters and response for the above method [here](https://docs.blochq.io/reference/bulktransfer)

### Webhook API

Webhook API operations
Expand Down
33 changes: 33 additions & 0 deletions examples/transfers/bulk-transfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Bloc, IBulkTransferRequest } from '../../dist'

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

const bulkTransfer = async () => {
try {
const data: IBulkTransferRequest = {
account_id: '640b045929eb9cf45bc720d2',
bulk_list: [
{
amount: 1000,
bank_code: '090110',
account_number: '1012233362',
narration: 'Bulk Test',
reference: '68314903j344223dd232ed13',
},
{
amount: 1000,
bank_code: '090110',
account_number: '1012233362',
narration: 'Bulk Test',
reference: '68314903j344223dd232ed13',
},
],
}
const response = await bloc.bulkTransfer(data)
console.log(response)
} catch (error) {
console.error(error)
}
}

bulkTransfer()
21 changes: 21 additions & 0 deletions examples/transfers/internal-transfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Bloc, IInternalTransferRequest } from '../../dist'

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

const internalTransfer = async () => {
try {
const data: IInternalTransferRequest = {
amount: 10000,
from_account_id: '6410616d7f1b4b36103f872b',
to_account_id: '64105fdd7f1b4b36103f870f',
narration: 'test transaction',
reference: '617849033kd44223dvs232cd13',
}
const response = await bloc.internalTransfer(data)
console.log(response)
} catch (error) {
console.error(error)
}
}

internalTransfer()
22 changes: 22 additions & 0 deletions examples/transfers/transfer-from-a-fixed-account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Bloc, ITransferFromAFixedAccountRequest } from '../../dist'

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

const transferFromAFixedAccount = async () => {
try {
const data: ITransferFromAFixedAccountRequest = {
amount: 10000,
bank_code: '058',
account_number: '2020202020',
narration: 'from jerry',
account_id: '64cb260d73152af277afcb53',
reference: 'REF2bbbfa09f11688558067066',
}
const response = await bloc.transferFromAFixedAccount(data)
console.log(response)
} catch (error) {
console.error(error)
}
}

transferFromAFixedAccount()
21 changes: 21 additions & 0 deletions examples/transfers/transfer-from-organization-balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Bloc, ITransferFromOrganizationBalance } from '../../dist'

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

const transferFromOrganizationBalance = async () => {
try {
const data: ITransferFromOrganizationBalance = {
amount: 10000,
bank_code: '058',
account_number: '2020202020',
narration: 'from jerry',
reference: 'REF2bbbfa09f11688558067066',
}
const response = await bloc.transferFromOrganizationBalance(data)
console.log(response)
} catch (error) {
console.error(error)
}
}

transferFromOrganizationBalance()
17 changes: 16 additions & 1 deletion src/bloc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Wallet,
BillsPayments,
Disputes,
Transfers,
} from './services'

export class Bloc {
Expand All @@ -22,6 +23,7 @@ export class Bloc {
private wallet: Wallet
private billsPayments: BillsPayments
private disputes: Disputes
private transfers: Transfers

constructor(secretKey: string, publicKey: string) {
this.customer = new Customer(secretKey, publicKey)
Expand All @@ -34,6 +36,7 @@ export class Bloc {
this.wallet = new Wallet(secretKey, publicKey)
this.billsPayments = new BillsPayments(secretKey, publicKey)
this.disputes = new Disputes(secretKey, publicKey)
this.transfers = new Transfers(secretKey, publicKey)
}

public get createCustomer() {
Expand Down Expand Up @@ -148,6 +151,18 @@ export class Bloc {
return this.disputes.getCardDisputeById.bind(this.disputes)
}
public get updateCardDispute() {
return this.disputes.getCardDisputeReasons.bind(this.disputes)
return this.disputes.updateCardDispute.bind(this.disputes)
}
public get transferFromAFixedAccount() {
return this.transfers.transferFromAFixedAccount.bind(this.transfers)
}
public get transferFromOrganizationBalance() {
return this.transfers.transferFromOrganizationBalance.bind(this.transfers)
}
public get internalTransfer() {
return this.transfers.internalTransfer.bind(this.transfers)
}
public get bulkTransfer() {
return this.transfers.bulkTransfer.bind(this.transfers)
}
}
1 change: 1 addition & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './miscellaneous'
export * from './wallet'
export * from './bills-payments'
export * from './disputes'
export * from './transfers'
66 changes: 66 additions & 0 deletions src/services/transfers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { HTTPCore } from '../api'
import {
IBulkTransferRequest,
IInternalTransferRequest,
ITransferFromAFixedAccountRequest,
ITransferFromOrganizationBalance,
ITransferResponse,
} from '../types'

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

/**
* Initiates a transfer from a fixed account.
* @param {ITransferFromAFixedAccountRequest} data - The data for the transfer.
* @returns {Promise<ITransferResponse>} A promise that resolves to the transfer response.
*/
public async transferFromAFixedAccount(
data: ITransferFromAFixedAccountRequest
): Promise<ITransferResponse> {
return this.post<ITransferResponse>(`/transfers`, data)
}

/**
* Initiates a transfer from the organization's balance.
* @param {ITransferFromOrganizationBalance} data - The data for the transfer.
* @returns {Promise<ITransferResponse>} A promise that resolves to the transfer response.
*/
public async transferFromOrganizationBalance(
data: ITransferFromOrganizationBalance
): Promise<ITransferResponse> {
return this.post<ITransferResponse>(`/transfers/balance`, data)
}

/**
* Initiates an internal transfer.
* @param {IInternalTransferRequest} data - The data for the transfer.
* @returns {Promise<ITransferResponse>} A promise that resolves to the transfer response.
*/
public async internalTransfer(
data: IInternalTransferRequest
): Promise<ITransferResponse> {
return this.post<ITransferResponse>(`/transfers/internal`, data)
}

/**
* Initiates a bulk transfer.
* @param {IBulkTransferRequest} data - The data for the bulk transfer.
* @returns {Promise<ITransferResponse>} A promise that resolves to the bulk transfer response.
*/
public async bulkTransfer(
data: IBulkTransferRequest
): Promise<ITransferResponse> {
return this.post<ITransferResponse>(`/transfers/bulk`, data)
}
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './miscellaneous'
export * from './wallet'
export * from './bills-payments'
export * from './disputes'
export * from './transfers'
43 changes: 43 additions & 0 deletions src/types/transfers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
interface ITransfer {
amount: number
bank_code: string
account_number: string
narration: string
reference: string
}

export interface ITransferFromAFixedAccountRequest extends ITransfer {
account_id: string
}

export interface ITransferResponse {
success: boolean
data: {
reference: string
account_id: string
recipient_account_number: string
recipient_account_name: string
amount: number
narration: string
currency: string
transaction_fee: number
status: string
create_at: string
}
message: string
}

export interface ITransferFromOrganizationBalance extends ITransfer {}

export interface IInternalTransferRequest {
amount: number
from_account_id: string
to_account_id: string
narration: string
reference: string
}

export interface IBulkTransferRequest {
account_id: string
bulk_list: ITransfer[]
}

0 comments on commit 00754ce

Please sign in to comment.