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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: CI

on:
push:
branches:
- main
pull_request:
types: [closed, review_requested, ready_for_review, synchronize, opened]
types: [opened, synchronize, reopened, ready_for_review]

jobs:
test:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.2.0 (15.01.2025)

- Get payment link info

## 0.1.4 (15.01.2025)

- Add iva and tip amount to payment link
Expand Down
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bold-api-sdk",
"version": "0.1.4",
"version": "0.2.0",
"description": "A Node.js library for interacting with the Bold API, providing seamless integration to manage payments, customers, and transactions efficiently.",
"main": "src/app.js",
"repository": "https://github.com/boterop/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