-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from peoray/transfers-methods
Add transfers methods
- Loading branch information
Showing
10 changed files
with
298 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] | ||
} |