From bcfbeca1ed9f6af79e4e2bf99325a8e7e2572532 Mon Sep 17 00:00:00 2001 From: Eric Bangug Date: Thu, 7 Jan 2021 22:20:04 +0800 Subject: [PATCH 1/3] Add retrieve source functionality --- README.md | 10 ++++++++++ src/sources/sources.js | 14 ++++++++++++++ src/sources/sources.spec.js | 14 +++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b80d3f3..77d2cb4 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ If you like this project, please give it a star, and consider following the auth - [Retrieve](#payment-intents---retrieve) - [Sources](#sources) - [Create](#sources---create) + - [Retrieve](#sources---retrieve) - [Payments](#payments) - [Create](#payments---create) - [List](#payments---list) @@ -221,6 +222,15 @@ const result = await paymongo.sources.create(data); } } ``` + +#### Sources - Retrieve + +```javascript +/** + * @param {string} id Source id + */ +const result = await paymongo.sources.retrieve(id); +``` [Go back to top ⮝](#contents) ### PAYMENTS diff --git a/src/sources/sources.js b/src/sources/sources.js index 55ded53..0ef5d84 100644 --- a/src/sources/sources.js +++ b/src/sources/sources.js @@ -22,3 +22,17 @@ export const createSource = async (secret, data) => { data, }); }; + + +/** + * @param {string} secret API private key + * @param {string} id Source id + */ +export const retrieveSource = async (secret, id) => { + if (!id) throw new Error('Source id is required.'); + return makeRequest({ + secret, + method: 'GET', + path: `/sources/${id}`, + }); +}; \ No newline at end of file diff --git a/src/sources/sources.spec.js b/src/sources/sources.spec.js index c93e488..145de79 100644 --- a/src/sources/sources.spec.js +++ b/src/sources/sources.spec.js @@ -1,5 +1,5 @@ import { makeRequest } from '../utils/rest'; -import { createSource } from './sources'; +import { createSource, retrieveSource } from './sources'; import faker from 'faker'; const fakePrivateKey = faker.random.uuid(); @@ -28,4 +28,16 @@ describe('Sources', () => { expect(createSource(fakePrivateKey, [])).rejects.toEqual(expect.any(Error)); }); }); + + describe('|- retrieveSource', () => { + it('should return object with id', async () => { + makeRequest.mockImplementationOnce(() => Promise.resolve({ + id: 'src_123abc', + })); + + const result = await retrieveSource(fakePrivateKey, 'src_123abc'); + expect(result).toHaveProperty('id'); + expect(result.id).toEqual('src_123abc'); + }); + }); }); \ No newline at end of file From e6320fbee7ed6937957839f45399085f78da2178 Mon Sep 17 00:00:00 2001 From: Eric Bangug Date: Thu, 7 Jan 2021 22:27:15 +0800 Subject: [PATCH 2/3] Add retrieve() to paymongo.sources --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c3fc5bc..964cf15 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import { createPaymentMethod, retrievePaymentMethod } from './payment-methods/index'; import { createPaymentIntent, retrievePaymentIntent, attachToPaymentIntent } from './payment-intents/index'; import { createToken, retrieveToken } from './tokens/index'; -import { createSource } from './sources/index'; +import { createSource, retrieveSource } from './sources/index'; import { createPayment, retrievePayment, listPayments } from './payments/index'; import { createWebhook, retrieveWebhook, listWebhooks, toggleWebhook } from './webhooks/index'; @@ -25,6 +25,7 @@ export default class Paymongo { // SOURCES this.sources = { create: (data) => createSource(this.secret, data), + retrieve: (id) => retrieveSource(this.secret, id), }; // PAYMENTS this.payments = { From c36b719a61edfcbc1741fdd564512131d3882405 Mon Sep 17 00:00:00 2001 From: Eric Bangug Date: Fri, 8 Jan 2021 08:50:13 +0800 Subject: [PATCH 3/3] execute build script --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 4e74d7d..686fbb6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var _classCallCheck=_interopDefault(require("@babel/runtime/helpers/classCallCheck")),_regeneratorRuntime=_interopDefault(require("@babel/runtime/regenerator")),_defineProperty=_interopDefault(require("@babel/runtime/helpers/defineProperty")),_slicedToArray=_interopDefault(require("@babel/runtime/helpers/slicedToArray")),_asyncToGenerator=_interopDefault(require("@babel/runtime/helpers/asyncToGenerator")),bent=_interopDefault(require("bent"));function ownKeys(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function _objectSpread(t){for(var r,e=1;e