Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,40 @@ npm install bold-api-sdk

### Payment Link

## Get

```js
import { paymentLink } from 'bold-api-sdk';

const response = await paymentLink.get('bold-identity-key', 'LNK_EX95SG8SZT');

console.log(response);
```

#### Response

```json
{
"id": "LNK_EX95SG8SZT",
"total": 0,
"status": "ACTIVE",
"expiration_date": 1736984191779000000,
"description": null,
"api_version": 1,
"subtotal": 0,
"tip_amount": 0,
"taxes": [],
"creation_date": 1736982392918743600,
"payment_method": null,
"transaction_id": null,
"amount_type": "OPEN",
"is_sandbox": true,
"callback_url": null
}
```

## Create

```js
import { paymentLink } from 'bold-api-sdk';

Expand Down
29 changes: 28 additions & 1 deletion src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
declare module 'bold-api-sdk' {
export type AmountType = 'OPEN' | 'CLOSE';

export interface Order {
amountType?: 'OPEN' | 'CLOSE';
amountType?: AmountType;
description?: string;
payerEmail?: string;
amount?: number;
Expand Down Expand Up @@ -37,9 +39,34 @@ declare module 'bold-api-sdk' {
errors: BoldError[];
}

export interface Tax {
type: string;
base: number;
value: number;
}

export interface GetLinkResponse {
id: string;
total: number;
status: 'ACTIVE' | 'PROCESSING' | 'PAID' | 'EXPIRED';
expiration_date: number;
description: string | null;
api_version: number;
subtotal: number;
tip_amount: number;
taxes: Tax[];
creation_date: number;
payment_method: string | null;
transaction_id: string | null;
amount_type: AmountType;
is_sandbox: boolean;
callback_url: string | null;
}

export type BoldApiKey = string | undefined | null;

export const paymentLink: {
get: (apiKey: BoldApiKey, id: string) => Promise<GetLinkResponse>;
create: (
apiKey: BoldApiKey,
order: Order,
Expand Down
1 change: 1 addition & 0 deletions src/domain/payment_link.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { paymentLinkService } = require('../services');

const paymentLink = {
get: async (apiKey, id) => paymentLinkService.get(apiKey, id),
create: async (apiKey, order) => paymentLinkService.create(apiKey, order),
};

Expand Down
10 changes: 9 additions & 1 deletion src/services/payment_link.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const { httpClient } = require('../shared');

const URL = '/online/link/v1';

exports.get = async (apiKey, id) =>
httpClient.fetch({
endpoint: `${URL}/${id}`,
apiKey,
});

exports.create = async (
apiKey,
{
Expand Down Expand Up @@ -51,7 +59,7 @@ exports.create = async (
: {};

return httpClient.fetch({
endpoint: '/online/link/v1',
endpoint: URL,
apiKey,
options: {
method: 'POST',
Expand Down
21 changes: 20 additions & 1 deletion tests/domain/payment_link.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ const paymentLink = require('../../src/domain/payment_link');

describe('paymentLink', () => {
const PAYMENT_LINK = 'bold.co/payment';
const apiKey = process.env.BOLD_API_KEY || 'bold-api-key';

describe('get', () => {
it('should return a payment link', async () => {
const { payload } = await paymentLink.create();
const { payment_link: id } = payload;

const { status } = await paymentLink.get(apiKey, id);

expect(status).toBe('ACTIVE');
});

it('should return an error if payment link does not exist', async () => {
const invalidId = 'non-existent-id';
const { errors } = await paymentLink.get(apiKey, invalidId);

expect(errors).toHaveLength(1);
expect(errors[0].errors).toBe(`Link ${invalidId} not valid`);
});
});

describe('create', () => {
const amountType = 'CLOSE';
Expand All @@ -11,7 +31,6 @@ describe('paymentLink', () => {
const callbackUrl = 'https://example.org/return';
const expirationMinutes = 30;
const currency = 'COP';
const apiKey = process.env.BOLD_API_KEY || 'bold-api-key';

beforeEach(() => {
process.env.BOLD_API_URL = 'https://integrations.api.bold.co';
Expand Down
Loading