Skip to content

Commit

Permalink
Merge pull request #15 from peoray/payment-links
Browse files Browse the repository at this point in the history
Add Payment Links methods
  • Loading branch information
peoray committed Jan 29, 2024
2 parents 00754ce + 18713a9 commit a54393c
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 4 deletions.
86 changes: 84 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A Nodejs API wrapper for [Bloc](https://www.blochq.io/) banking services written
- [Available Methods exposed by the SDK](#available-methods-exposed-by-the-sdk)
- [Wallets API](#wallets-api)
- [Create Wallet](#create-wallet)
- [Get Wallets](#get-wallet)
- [Get Wallets](#get-wallets)
- [Get Wallet by id](#get-wallet-by-id)
- [Get Customer Wallets](#get-customer-wallets)
- [Debit Wallet](#debit-wallet)
Expand Down Expand Up @@ -51,14 +51,20 @@ 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)
- [Transfers API](#transfers-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)
- [Payment Links API](#payment-links-api)
- [Create Payment Link](#create-payment-link)
- [Get Payment Links](#get-payment-links)
- [Get Payment Link By id](#get-payment-link-by-id)
- [Edit Payment Link](#edit-payment-link)
- [Delete Payment Link](#delete-payment-link)
- [Beneficiaries API](#beneficiaries-api)
- [Create Beneficiary](#create-beneficiary)
- [Get Beneficiary by ID](#get-beneficiary-by-id)
Expand Down Expand Up @@ -677,6 +683,82 @@ console.log(response) // IWebhookResponse

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

### Payment Links API

Payment Link API operations

#### Create Payment Link

```ts
// import the payment-links interfaces from the sdk
import type { ICreatePaymentLinkRequest, IPaymentLinkResponse } from 'bloc-nodejs';

const payload: ICreatePaymentLinkRequest = {
// payload data
}

const response = await bloc.createPaymentLink(payload)
console.log(response) // IPaymentLinkResponse
```

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

#### Get Payment Links

```ts
// import the payment-links interfaces from the sdk
import type { IGetPaymentLinksResponse } from 'bloc-nodejs';

const response = await bloc.getPaymentLinks()
console.log(response) // IGetPaymentLinksResponse
```

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

#### Get Payment Link By id

```ts
// import the payment-links interfaces from the sdk
import type { IPaymentLinkResponse } from 'bloc-nodejs';

const response = await bloc.getPaymentLinkById('link-id')
console.log(response) // IPaymentLinkResponse
```

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

#### Edit Payment Link

```ts
// import the payment-links interfaces from the sdk
import type { IEditPaymentLinkRequest, IPaymentLinkResponse } from 'bloc-nodejs';

const payload: IEditPaymentLinkRequest = {
// payload data
}

const response = await bloc.editPaymentLink('link-id', payload)
console.log(response) // IPaymentLinkResponse
```

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

#### Delete Payment Link

```ts
// import the payment-links interfaces from the sdk
import type { IDeletePaymentLinksRequest, IPaymentLinkResponse } from 'bloc-nodejs';

const payload: IDeletePaymentLinksRequest = {
// payload data
}

const response = await bloc.deletePaymentLink(payload)
console.log(response) // IPaymentLinkResponse
```

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

### Beneficiaries API

Beneficiaries API operations
Expand Down
20 changes: 20 additions & 0 deletions examples/payment-links/create-payment-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Bloc, ICreatePaymentLinkRequest } from '../../dist'

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

const createPaymentLink = async () => {
try {
const data: ICreatePaymentLinkRequest = {
name: 'AmG',
description: 'Project Adam',
amount: 500000,
currency: 'USD',
}
const response = await bloc.createPaymentLink(data)
console.log(response)
} catch (error) {
console.error(error)
}
}

createPaymentLink()
17 changes: 17 additions & 0 deletions examples/payment-links/delete-payment-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Bloc, IDeletePaymentLinksRequest } from '../../dist'

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

const deletePaymentLink = async () => {
try {
const payload: IDeletePaymentLinksRequest = {
ids: ['645a234d85b17f000a30541a', '645a20d185b17f000a305385'],
}
const response = await bloc.deletePaymentLink(payload)
console.log(response)
} catch (error) {
console.error(error)
}
}

deletePaymentLink()
18 changes: 18 additions & 0 deletions examples/payment-links/edit-payment-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Bloc, IEditPaymentLinkRequest } from '../../dist'

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

const editPaymentLink = async () => {
const payload: IEditPaymentLinkRequest = {
name: 'hmd',
description: 'Project Hamadam',
}
try {
const response = await bloc.editPaymentLink('link-id', payload)
console.log(response)
} catch (error) {
console.error(error)
}
}

editPaymentLink()
14 changes: 14 additions & 0 deletions examples/payment-links/get-payment-link-by-id.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 getPaymentLinkById = async () => {
try {
const response = await bloc.getPaymentLinkById('link-id')
console.log(response)
} catch (error) {
console.error(error)
}
}

getPaymentLinkById()
14 changes: 14 additions & 0 deletions examples/payment-links/get-payment-links.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 getPaymentLinks = async () => {
try {
const response = await bloc.getPaymentLinks()
console.log(response)
} catch (error) {
console.error(error)
}
}

getPaymentLinks()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"start": "tsdx watch",
"build": "tsdx build",
"lint": "tsdx lint",
"dev": "npx tsx ./examples/transaction/get-all-transactions.ts",
"dev": "npx tsx ./examples/payment-links/create-payment-link.ts",
"prepare": "tsdx build",
"prepublishOnly": "pnpm build",
"preversion": "pnpm build"
Expand Down
6 changes: 5 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ export class HTTPCore {
* @param {AxiosRequestConfig} [config] - The Axios request configuration.
* @returns {Promise<T>} - The response data.
*/
public async delete<T>(url: string, config?: AxiosRequestConfig): Promise<T> {
public async delete<T>(
url: string,
// data?: any,
config?: AxiosRequestConfig
): Promise<T> {
return this.handleRequest<T>(this.request.delete(url, config))
}
}
18 changes: 18 additions & 0 deletions src/bloc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
BillsPayments,
Disputes,
Transfers,
PaymentLinks,
} from './services'

export class Bloc {
Expand All @@ -24,6 +25,7 @@ export class Bloc {
private billsPayments: BillsPayments
private disputes: Disputes
private transfers: Transfers
private paymentLinks: PaymentLinks

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

public get createCustomer() {
Expand Down Expand Up @@ -165,4 +168,19 @@ export class Bloc {
public get bulkTransfer() {
return this.transfers.bulkTransfer.bind(this.transfers)
}
public get createPaymentLink() {
return this.paymentLinks.createPaymentLink.bind(this.paymentLinks)
}
public get getPaymentLinks() {
return this.paymentLinks.getPaymentLinks.bind(this.paymentLinks)
}
public get getPaymentLinkById() {
return this.paymentLinks.getPaymentLinkById.bind(this.paymentLinks)
}
public get editPaymentLink() {
return this.paymentLinks.editPaymentLink.bind(this.paymentLinks)
}
public get deletePaymentLink() {
return this.paymentLinks.deletePaymentLink.bind(this.paymentLinks)
}
}
1 change: 1 addition & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './wallet'
export * from './bills-payments'
export * from './disputes'
export * from './transfers'
export * from './payment-links'
77 changes: 77 additions & 0 deletions src/services/payment-links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { HTTPCore } from '../api'
import {
ICreatePaymentLinkRequest,
IPaymentLinkResponse,
IGetPaymentLinksResponse,
IEditPaymentLinkRequest,
IDeletePaymentLinksResponse,
IDeletePaymentLinksRequest,
} from '../types'

/**
* Class representing operations related to Payment Links, extending HTTPCore.
*/
export class PaymentLinks extends HTTPCore {
/**
* Creates an instance of the PaymentLinks 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 payment link using the provided data.
* @param {ICreatePaymentLinkRequest} data - The data to create the payment link.
* @returns {Promise<IPaymentLinkResponse>} A promise that resolves to the payment link creation response.
*/
public async createPaymentLink(
data: ICreatePaymentLinkRequest
): Promise<IPaymentLinkResponse> {
return this.post<IPaymentLinkResponse>(`/paymentlinks`, data)
}

/**
* Retrieves a list of payment links.
* @returns {Promise<IGetPaymentLinksResponse>} A promise that resolves to the list of payment links response.
*/
public async getPaymentLinks(): Promise<IGetPaymentLinksResponse> {
return this.get<IGetPaymentLinksResponse>(`/paymentlinks`)
}

/**
* Retrieves a payment link by its ID.
* @param {string} linkId - The ID of the payment link to retrieve.
* @returns {Promise<IPaymentLinkResponse>} A promise that resolves to the payment link response.
*/
public async getPaymentLinkById(
linkId: string
): Promise<IPaymentLinkResponse> {
return this.get<IPaymentLinkResponse>(`/paymentlinks/${linkId}`)
}

/**
* Edits an existing payment link using the provided data.
* @param {string} linkId - The ID of the payment link to edit.
* @param {IEditPaymentLinkRequest} data - The data to edit the payment link.
* @returns {Promise<IPaymentLinkResponse>} A promise that resolves to the edited payment link response.
*/
public async editPaymentLink(
linkId: string,
data: IEditPaymentLinkRequest
): Promise<IPaymentLinkResponse> {
return this.put<IPaymentLinkResponse>(`/paymentlinks/${linkId}`, data)
}

/**
* Deletes one or more payment links using the provided data.
* @param {IDeletePaymentLinksRequest} data - The data to delete the payment links.
* @returns {Promise<IDeletePaymentLinksResponse>} A promise that resolves to the payment link deletion response.
*/
public async deletePaymentLink(
data: IDeletePaymentLinksRequest
): Promise<IDeletePaymentLinksResponse> {
return this.delete<IDeletePaymentLinksResponse>(`/paymentlinks`, { data })
}
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './wallet'
export * from './bills-payments'
export * from './disputes'
export * from './transfers'
export * from './payment-links'
Loading

0 comments on commit a54393c

Please sign in to comment.