-
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 #15 from peoray/payment-links
Add Payment Links methods
- Loading branch information
Showing
13 changed files
with
318 additions
and
4 deletions.
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,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() |
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,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() |
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,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() |
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,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() |
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,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() |
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
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,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 }) | ||
} | ||
} |
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
Oops, something went wrong.