From 34bda49aa7eb37aa8dd1cdb1d72b371c5c0f0460 Mon Sep 17 00:00:00 2001 From: Santiago Botero <98826652+boterop@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:29:47 -0500 Subject: [PATCH 1/4] Report after merge to any branch (#18) --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72e6813..c5c6de8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,12 @@ name: CI on: + push: + branches: + - main + - 'v*.[0-99]' pull_request: - types: [closed, review_requested, ready_for_review, synchronize, opened] + types: [opened, synchronize, reopened, ready_for_review] jobs: test: From e46a986c8f29bf4863ba5095250cb4b6c93ebdee Mon Sep 17 00:00:00 2001 From: Santiago Botero <98826652+boterop@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:47:56 -0500 Subject: [PATCH 2/4] Link status (#19) * Get payment link info * Add domain to readme * Add new types --- README.md | 34 +++++++++++++++++++++++++++++++ src/app.d.ts | 29 +++++++++++++++++++++++++- src/domain/payment_link.js | 1 + src/services/payment_link.js | 10 ++++++++- tests/domain/payment_link.test.js | 21 ++++++++++++++++++- 5 files changed, 92 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0f427b6..f5e4149 100644 --- a/README.md +++ b/README.md @@ -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'; diff --git a/src/app.d.ts b/src/app.d.ts index 426fab7..72cb6ab 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -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; @@ -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; create: ( apiKey: BoldApiKey, order: Order, diff --git a/src/domain/payment_link.js b/src/domain/payment_link.js index e144ff4..d6a285b 100644 --- a/src/domain/payment_link.js +++ b/src/domain/payment_link.js @@ -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), }; diff --git a/src/services/payment_link.js b/src/services/payment_link.js index d0ac768..a73959b 100644 --- a/src/services/payment_link.js +++ b/src/services/payment_link.js @@ -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, { @@ -51,7 +59,7 @@ exports.create = async ( : {}; return httpClient.fetch({ - endpoint: '/online/link/v1', + endpoint: URL, apiKey, options: { method: 'POST', diff --git a/tests/domain/payment_link.test.js b/tests/domain/payment_link.test.js index 4fb3097..555bbfc 100644 --- a/tests/domain/payment_link.test.js +++ b/tests/domain/payment_link.test.js @@ -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'; @@ -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'; From 1523f027ee78f99be798b0c53d5b404d6bab10e9 Mon Sep 17 00:00:00 2001 From: Santiago Botero <98826652+boterop@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:56:22 -0500 Subject: [PATCH 3/4] Remove unnecessary push tag (#20) --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5c6de8..c31b66e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - 'v*.[0-99]' pull_request: types: [opened, synchronize, reopened, ready_for_review] From 4bf77d1a25db1e55065675b1a886b5848fcea482 Mon Sep 17 00:00:00 2001 From: Santiago Botero <98826652+boterop@users.noreply.github.com> Date: Wed, 15 Jan 2025 19:12:15 -0500 Subject: [PATCH 4/4] Prepare to release v0.2.0 (#21) * Prepare to release v0.2.0 * Format --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c70be..98ce1d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 01d865e..e7d9011 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bold-api-sdk", - "version": "0.1.4", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bold-api-sdk", - "version": "0.1.4", + "version": "0.2.0", "license": "MIT", "devDependencies": { "eslint": "^9.17.0", diff --git a/package.json b/package.json index 21a9ca2..8ab2f9e 100644 --- a/package.json +++ b/package.json @@ -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",