From 10f88032a82d00931af2daa9634b040621ceab62 Mon Sep 17 00:00:00 2001 From: Dharnit <85389770+dharmasatrya@users.noreply.github.com> Date: Wed, 2 Nov 2022 16:23:58 +0700 Subject: [PATCH 1/7] APPL-1038/PaymentMethodV2 --- package-lock.json | 23 +- src/payment_method_v2/index.d.ts | 3 + src/payment_method_v2/index.js | 3 + src/payment_method_v2/payment_method_v2.d.ts | 241 +++++++++++++++ src/payment_method_v2/payment_method_v2.js | 291 ++++++++++++++++++ src/xendit.d.ts | 2 + src/xendit.js | 2 + test/payment_method_v2/constants.js | 79 +++++ .../payment_method_v2.test.js | 49 +++ 9 files changed, 673 insertions(+), 20 deletions(-) create mode 100644 src/payment_method_v2/index.d.ts create mode 100644 src/payment_method_v2/index.js create mode 100644 src/payment_method_v2/payment_method_v2.d.ts create mode 100644 src/payment_method_v2/payment_method_v2.js create mode 100644 test/payment_method_v2/constants.js create mode 100644 test/payment_method_v2/payment_method_v2.test.js diff --git a/package-lock.json b/package-lock.json index 1b7861a..b8bd697 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,15 @@ { "name": "xendit-node", - "version": "1.21.2", + "version": "1.21.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "xendit-node", - "version": "1.21.2", + "version": "1.21.7", "license": "MIT", "dependencies": { - "node-fetch": "^2.6.1", - "xendit-node": "^1.21.1" + "node-fetch": "^2.6.1" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^2.13.0", @@ -9455,14 +9454,6 @@ "node": ">=8" } }, - "node_modules/xendit-node": { - "version": "1.21.1", - "resolved": "https://registry.npmjs.org/xendit-node/-/xendit-node-1.21.1.tgz", - "integrity": "sha512-lWNW49JmNRxHMkuMqn7jGCe36H2kA4xDCWBV3lECOG1ZayTyzHdHya47wL7x7N1rwjK6/DgoM6Z2gw8wVbNjyA==", - "dependencies": { - "node-fetch": "^2.6.1" - } - }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", @@ -16636,14 +16627,6 @@ "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==", "dev": true }, - "xendit-node": { - "version": "1.21.1", - "resolved": "https://registry.npmjs.org/xendit-node/-/xendit-node-1.21.1.tgz", - "integrity": "sha512-lWNW49JmNRxHMkuMqn7jGCe36H2kA4xDCWBV3lECOG1ZayTyzHdHya47wL7x7N1rwjK6/DgoM6Z2gw8wVbNjyA==", - "requires": { - "node-fetch": "^2.6.1" - } - }, "xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/src/payment_method_v2/index.d.ts b/src/payment_method_v2/index.d.ts new file mode 100644 index 0000000..39543b7 --- /dev/null +++ b/src/payment_method_v2/index.d.ts @@ -0,0 +1,3 @@ +import PaymentMethodV2Service from './payment_method_v2'; + +export { PaymentMethodV2Service }; \ No newline at end of file diff --git a/src/payment_method_v2/index.js b/src/payment_method_v2/index.js new file mode 100644 index 0000000..dacec73 --- /dev/null +++ b/src/payment_method_v2/index.js @@ -0,0 +1,3 @@ +const PaymentMethodV2Service = require('./payment_method_v2'); + +module.exports = { PaymentMethodV2Service }; \ No newline at end of file diff --git a/src/payment_method_v2/payment_method_v2.d.ts b/src/payment_method_v2/payment_method_v2.d.ts new file mode 100644 index 0000000..ff58f1e --- /dev/null +++ b/src/payment_method_v2/payment_method_v2.d.ts @@ -0,0 +1,241 @@ +import { XenditOptions } from '../xendit_opts'; + +enum PaymentMethodV2Types { + Card = 'CARD', + eWallet = 'EWALLET', + DirectDebit = 'DIRECT_DEBIT', + OverTheCounter = 'OVER_THE_COUNTER', + QRCODE = 'QR_CODE', + VitrualAccount = 'VIRTUAL_ACCOUNT' +} + +enum PaymentMenthodV2Reusabilities { + OneTimeUse = 'ONE_TIME_USE', + MultipleUse = 'MULTIPLE_USE', +} + +enum CreatePaymentMenthodV2Countries { + ID = 'ID', + PH = 'PH', +} + +enum EWalletChannelCodes { + Dana = 'DANA', + OVO = 'OVO', + LinkAja = 'LINKAJA', + Astrapay = 'ASTRAPAY', + JeniusPay = 'JENIUSPAY', + ShopeePay = 'SHOPEEPAY', + GrabPay = 'GRABPAY', + Paymaya = 'PAYMAYA', + GCash = 'GCASH' +} + +enum DirectDebitChannelCodes { + BRI = 'BRI', + Mandiri = 'MANDIRI', + BPI = 'BPI', + UBP = 'UBP', + RCBC = 'RCBC', + ChinaBank = 'CHINABANK' +} + +enum CardCurrencies { + IDR = 'IDR', + PHP = 'PHP', + USD = 'USD' +} + +enum OverTheCounterChannelCodes { + Alfamart = 'ALFAMART', + Indomaret = 'INDOMARET', + '7Eleven' = '7ELEVEN', + '7ElevenCLIQQ' = '7ELEVEN_CLIQQ', + Cebuana = 'CEBUANA', + ECPay = 'ECPAY', + Palawan = 'PALAWAN', + MLhuillier = 'MLHUILLIER', + DragonLoanECPAY = 'DRAGONLOAN_ECPAY' +} + +enum OverTheCounterCurrencies { + IDR = 'IDR', + PHP = 'PHP' +} + +enum VirtualAccountChannelCodes { + BCA = 'BCA', + BSI = 'BSI', + BJB = 'BJB', + CIMB = 'CIMB', + SahabatSampoerna = 'SAHABAT_SAMPOERNA', + Artajasa = 'ARTAJASA', + BRI = 'BRI', + BNI = 'BNI', + Mandiri = 'MANDIRI', + Permata = 'PERMATA' +} + +enum VirtualAccountCurrencies { + IDR = 'IDR' +} + +enum QRISChannelCodes { + QRIS = 'QRIS' +} + +enum QRISCurrencies { + IDR = 'IDR' +} + +enum PaymentMethodV2Statuses { + Succeeded = 'SUCCEEDED', + Failed = 'FAILED', + Pending = 'PENDING' +} + +interface BillingInformationItems { + country: string; + street_line1?: string; + street_line2?: string; + city?: string; + province_state?: string; + postal_code?: string; +} + +interface EwalletItems { + channel_code: EWalletChannelCodes; + channel_properties: object; +} + +interface DirectDebitItems { + channel_code: DirectDebitChannelCodes; + channel_properties: object; +} + +interface CardItems { + currency: CardCurrencies; + channel_properties: object; + card_information: + { + card_number: string, + expiry_month: string, + expiry_year: string, + cardholder_name?: string + } +} + +interface OverTheCounterItems { + channel_code: OverTheCounterChannelCodes; + currency?: OverTheCounterCurrencies; + amount?: number; + channel_properties: object; +} + +interface VirtualAccountItems { + channel_code: VirtualAccountChannelCodes; + currency?: VirtualAccountCurrencies; + amount?: number; + channel_properties: object; +} + +interface QRISItems { + channel_code: QRISChannelCodes; + currency?: QRISCurrencies; + amount?: number; +} + +interface UpdateOverTheCounterItems { + amount?: number; + channel_properties: object; +} + +interface UpdateVirtualAccountItems { + amount?: number; + channel_properties: object; +} + +interface ListPaymentMethodV2StatusItems { + status?: PaymentMethodV2Statuses; +} + + +export = class PaymentMethodV2 { + constructor({ }); + static _constructorWithInjectedXenditOpts: ( + opts: XenditOptions, + ) => typeof PaymentMethodV2; + createPaymentMethodV2(data: { + type: PaymentMethodV2Types; + reusability: PaymentMenthodV2Reusabilities; + reference_id?: string; + customer_id?: string; + country?: CreatePaymentMenthodV2Countries; + description?: string; + billing_information?: BillingInformationItems; + metadata?: object; + ewallet?: EwalletItems; + direct_debit?: DirectDebitItems; + card?: CardItems; + over_the_counter?: OverTheCounterItems; + virtual_account?: VirtualAccountItems; + qr_code?: QRISItems; + for_user_id?: string; + idempotency_key?: string; + }): Promise; + + listPaymentMethodV2(data: { + id: string; + type?: PaymentMethodV2Types; + reusability?: PaymentMenthodV2Reusabilities; + reference_id?: string; + customer_id?: string; + limit?: string; + after_id?: string; + before_id?: string + for_user_id?: string + }): Promise; + + authorizePaymentMethodV2(data: { + id: string; + auth_code: string; + for_user_id?: string; + idempotency_key?: string; + }): Promise; + + getPaymentMethodByIdV2(data: { + id: string + for_user_id?: string + }): Promise; + + updatePaymentMethodV2(data: { + id: string; + reference_id?: string; + description?: string; + metadata?: object; + status?: object; + reusability?: PaymentMenthodV2Reusabilities; + over_the_counter?: UpdateOverTheCounterItems; + virtual_account?: UpdateVirtualAccountItems; + for_user_id?: string + }): Promise; + + expirePaymentMethodV2(data: { + id: string + for_user_id?: string + idempotency_key?: string + }): Promise; + + listPaymentsByPaymentMethodIdV2(data: { + id: string; + payment_request_id?: string; + reference_id?: string; + status?: ListPaymentMethodV2StatusItems; + limit?: number; + after_id?: string; + before_id?: string; + created?: string; + updated?: string; + for_user_id?: string; + }): Promise; +}; \ No newline at end of file diff --git a/src/payment_method_v2/payment_method_v2.js b/src/payment_method_v2/payment_method_v2.js new file mode 100644 index 0000000..d998e8a --- /dev/null +++ b/src/payment_method_v2/payment_method_v2.js @@ -0,0 +1,291 @@ +const { promWithJsErr, Validate, fetchWithHTTPErr, Auth, queryStringWithoutUndefined } = require('../utils'); + +const PAYMENT_METHOD_V2_PATH = '/v2/payment_methods'; + +function PaymentMethodV2(options) { + let aggOpts = options; + if ( + PaymentMethodV2._injectedOpts && + Object.keys(PaymentMethodV2._injectedOpts).length > 0 + ) { + aggOpts = Object.assign({}, options, PaymentMethodV2._injectedOpts); + } + + this.opts = aggOpts; + this.API_ENDPOINT = this.opts.xenditURL + PAYMENT_METHOD_V2_PATH; +} + +PaymentMethodV2._injectedOpts = {}; +PaymentMethodV2._constructorWithInjectedXenditOpts = function (options) { + PaymentMethodV2._injectedOpts = options; + return PaymentMethodV2; +}; + +PaymentMethodV2.prototype.createPaymentMethodV2 = function (data) { + return promWithJsErr((resolve, reject) => { + Validate.rejectOnMissingFields( + ['type', 'reusability'], + data, + reject, + ); + + let headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + }; + + if (data && data.for_user_id) { + headers['for-user-id'] = data.for_user_id; + } + + if (data && data.idempotency_key) { + headers['idempotency-key'] = data.idempotency_key; + } + + fetchWithHTTPErr(`${this.API_ENDPOINT}`, { + method: 'POST', + headers, + body: JSON.stringify({ + type: data.type, + reusability: data.reusability, + reference_id: data.reference_id, + customer_id: data.customer_id, + country: data.country, + description: data.description, + billing_information: data.billing_information, + metadata: data.metadata, + ewallet: data.ewallet, + direct_debit: data.direct_debit, + card: data.card, + over_the_counter: data.over_the_counter, + virtual_account: data.virtual_account, + qr_code: data.qr_code + }), + }) + .then(resolve) + .catch(reject); + }); +}; + +PaymentMethodV2.prototype.listPaymentMethodV2 = function (data) { + return promWithJsErr((resolve, reject) => { + Validate.rejectOnMissingFields([], data, reject); + + let headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + }; + + if (data && data.for_user_id) { + headers['for-user-id'] = data.for_user_id; + } + + const queryStr = data + ? queryStringWithoutUndefined({ + id: data.id ? data.id : undefined, + type: data.type ? data.type : undefined, + reusability: data.reusability ? data.reusability : undefined, + reference_id: data.reference_id ? data.reference_id : undefined, + customer_id: data.customer_id ? data.customer_id : undefined, + limit: data.limit ? data.limit : undefined, + after_id: data.after_id ? data.after_id : undefined, + before_id: data.before_id ? data.before_id : undefined + }) + : ''; + + const queryStrWithQuestionMark = queryStr ? `?${queryStr}` : ''; + + + fetchWithHTTPErr(`${this.API_ENDPOINT}${queryStrWithQuestionMark}`, { + method: 'GET', + headers, + }) + .then(resolve) + .catch(reject); + }); +}; + +PaymentMethodV2.prototype.authorizePaymentMethodV2 = function (data) { + return promWithJsErr((resolve, reject) => { + Validate.rejectOnMissingFields(['id'], data, reject); + + let headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + }; + + if (data && data.for_user_id) { + headers['for-user-id'] = data.forUserID; + } + + if (data && data.idempotency_key) { + headers['idempotency-key'] = data.idempotency_key; + } + + fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}/auth`, { + method: 'GET', + headers, + body: JSON.stringify({ + auth_code: data.auth_code + }), + }) + .then(resolve) + .catch(reject); + }); +}; + +PaymentMethodV2.prototype.getPaymentMethodByIdV2 = function (data) { + return promWithJsErr((resolve, reject) => { + Validate.rejectOnMissingFields(['id'], data, reject); + + let headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + }; + + if (data && data.for_user_id) { + headers['for-user-id'] = data.forUserID; + } + + fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}`, { + method: 'GET', + headers, + body: JSON.stringify({ + auth_code: data.auth_code + }), + }) + .then(resolve) + .catch(reject); + }); +}; + +PaymentMethodV2.prototype.updatePaymentMethodV2 = function (data) { + return promWithJsErr((resolve, reject) => { + Validate.rejectOnMissingFields(['id'], data, reject); + + let headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + }; + + if (data && data.for_user_id) { + headers['for-user-id'] = data.forUserID; + } + + fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}`, { + method: 'PATCH', + headers, + body: JSON.stringify({ + reference_id?: data.reference_id, + description?: data.description, + metadata?: data.metadata, + status?: data.status, + reusability?: data.reusability, + over_the_counter?: data.over_the_counter, + virtual_account?: data.virtual_account + }), + }) + .then(resolve) + .catch(reject); + }); +}; + +PaymentMethodV2.prototype.expirePaymentMethodV2 = function (data) { + return promWithJsErr((resolve, reject) => { + Validate.rejectOnMissingFields(['id'], data, reject); + + let headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + }; + + if (data && data.for_user_id) { + headers['for-user-id'] = data.forUserID; + } + + + if (data && data.idempotency_key) { + headers['idempotency-key'] = data.idempotency_key; + } + + fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}/expire`, { + method: 'POST', + headers, + body: JSON.stringify({ + auth_code: data.auth_code + }), + }) + .then(resolve) + .catch(reject); + }); +}; + +PaymentMethodV2.prototype.expirePaymentMethodV2 = function (data) { + return promWithJsErr((resolve, reject) => { + Validate.rejectOnMissingFields(['id'], data, reject); + + let headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + }; + + if (data && data.for_user_id) { + headers['for-user-id'] = data.forUserID; + } + + + if (data && data.idempotency_key) { + headers['idempotency-key'] = data.idempotency_key; + } + + fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}/expire`, { + method: 'POST', + headers, + body: JSON.stringify({ + auth_code: data.auth_code + }), + }) + .then(resolve) + .catch(reject); + }); +}; + +PaymentMethodV2.prototype.listPaymentsByPaymentMethodIdV2 = function (data) { + return promWithJsErr((resolve, reject) => { + Validate.rejectOnMissingFields([], data, reject); + + let headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + }; + + if (data && data.for_user_id) { + headers['for-user-id'] = data.for_user_id; + } + + const queryStr = data + ? queryStringWithoutUndefined({ + payment_request_id: data.payment_request_id ? data.payment_request_id : undefined, + reference_id: data.reference_id ? data.reference_id : undefined, + status: data.status ? data.status :undefined, + limit: data.limit ? data.limit : undefined, + after_id: data.after_id ? data.after_id : undefined, + before_id: data.before_id ? data.before_id : undefined, + created: data.created ? data.created : undefined, + updated: data.updated ? data.updated : undefined + }) + : ''; + + const queryStrWithQuestionMark = queryStr ? `?${queryStr}` : ''; + + + fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}/payments${queryStrWithQuestionMark}`, { + method: 'GET', + headers, + }) + .then(resolve) + .catch(reject); + }); +}; + +module.exports = PaymentMethodV2; diff --git a/src/xendit.d.ts b/src/xendit.d.ts index 3e620a1..5479c58 100644 --- a/src/xendit.d.ts +++ b/src/xendit.d.ts @@ -16,6 +16,7 @@ import { CustomerService } from './customer'; import { DirectDebitService } from './direct_debit'; import { ReportService } from './report'; import { TransactionService } from './transaction'; +import { PaymentMethodV2Service } from './payment_method_v2' declare class Xendit { constructor(opts: XenditOptions); @@ -37,5 +38,6 @@ declare class Xendit { DirectDebit: typeof DirectDebitService; Report: typeof ReportService; Transaction: typeof TransactionService; + PaymentMethodV2: typeof PaymentMethodV2Service } export = Xendit; diff --git a/src/xendit.js b/src/xendit.js index b53e627..b06deb0 100644 --- a/src/xendit.js +++ b/src/xendit.js @@ -15,6 +15,7 @@ const { DirectDebitService } = require('./direct_debit'); const { RegionalRetailOutletService } = require('./regional_retail_outlet'); const { ReportService } = require('./report'); const { TransactionService } = require('./transaction'); +const { PaymentMethodV2Service } = require('./payment_method_v2') const Errors = require('./errors'); function Xendit(options) { @@ -43,6 +44,7 @@ function Xendit(options) { this.RetailOutlet = RetailOutletService._constructorWithInjectedXenditOpts( this.opts, ); + this.PaymentMethodV2 = PaymentMethodV2Service._constructorWithInjectedXenditOpts(this.opts) // eslint-disable-next-line this.RegionalRetailOutlet = RegionalRetailOutletService._constructorWithInjectedXenditOpts( this.opts, diff --git a/test/payment_method_v2/constants.js b/test/payment_method_v2/constants.js new file mode 100644 index 0000000..ec62544 --- /dev/null +++ b/test/payment_method_v2/constants.js @@ -0,0 +1,79 @@ +const TYPES = ['DISBURSEMENT', 'PAYMENT']; +const STATUSES = ['PENDING', 'SUCCESS']; +const CHANNEL_CATEGORIES = ['BANK']; +const CREATED_DATE_FROM = new Date('2022-01-01T00:00:00.000Z'); +const CREATED_DATE_TO = new Date('2022-02-01T00:00:00.000Z'); + +const TRANSACTION_ID = 'txn_123123'; +const QUERY_STRING = + 'types=DISBURSEMENT&types=PAYMENT&statuses=PENDING&statuses=SUCCESS&' + + 'channel_categories=BANK&created[gte]=2022-01-01T00:00:00.000Z&' + + 'created[lte]=2022-02-01T00:00:00.000Z'; + +const GET_TRANSACTION_RESPONSE = { + id: TRANSACTION_ID, + product_id: '1232131', + type: TYPES[0], + status: STATUSES[0], + channel_category: CHANNEL_CATEGORIES[0], + channel_code: 'BCA', + reference_id: 'Bank Central Asia (BCA) - BCA single disbursement', + account_identifier: '123123', + currency: 'IDR', + amount: 10000, + net_amount: 10000, + cashflow: 'MONEY_OUT', + business_id: '13123', + created: '2022-02-01T00:00:00.000Z', + updated: '2022-02-01T00:00:00.000Z', + fee: { + xendit_fee: 0, + value_added_tax: 0, + xendit_withholding_tax: 0, + third_party_withholding_tax: 0, + status: 'COMPLETED', + }, +}; + +const ANOTHER_TRANSACTION_RESPONSE = { + id: TRANSACTION_ID, + product_id: '1232132131', + type: TYPES[1], + status: STATUSES[1], + channel_category: CHANNEL_CATEGORIES[0], + channel_code: 'BCA', + reference_id: 'Bank Central Asia (BCA) - BCA single disbursement', + account_identifier: '123123', + currency: 'IDR', + amount: 100001, + net_amount: 100001, + cashflow: 'MONEY_OUT', + business_id: '13123', + created: '2022-02-01T00:00:00.000Z', + updated: '2022-02-01T00:00:00.000Z', + fee: { + xendit_fee: 0, + value_added_tax: 0, + xendit_withholding_tax: 0, + third_party_withholding_tax: 0, + status: 'COMPLETED', + }, +}; + +const LIST_TRANSACTIONS_RESPONSE = { + has_more: false, + data: [GET_TRANSACTION_RESPONSE, ANOTHER_TRANSACTION_RESPONSE], + links: [], +}; + +module.exports = { + TYPES, + STATUSES, + CHANNEL_CATEGORIES, + CREATED_DATE_FROM, + CREATED_DATE_TO, + TRANSACTION_ID, + GET_TRANSACTION_RESPONSE, + LIST_TRANSACTIONS_RESPONSE, + QUERY_STRING, +}; diff --git a/test/payment_method_v2/payment_method_v2.test.js b/test/payment_method_v2/payment_method_v2.test.js new file mode 100644 index 0000000..2069ab2 --- /dev/null +++ b/test/payment_method_v2/payment_method_v2.test.js @@ -0,0 +1,49 @@ +const chai = require('chai'); +const chaiAsProm = require('chai-as-promised'); +const TestConstants = require('./constants'); +const { expect } = chai; +const nock = require('nock'); +const { Errors } = require('../../src/xendit'); +const Xendit = require('../../src/xendit'); +const { QUERY_STRING } = require('./constants'); + +const x = new Xendit({ + secretKey: 'xnd_production_ypr0UI6148UVBDHMJsHCUgF0Yff4XEjRSAzBvM626qPzHEBo45IRCBdqEHmmql', +}); + +chai.use(chaiAsProm); + +const { PaymentMethodV2 } = x; +let p = new PaymentMethodV2({}); +beforeEach(function () { + p = new PaymentMethodV2({}); +}); +before(function () { + nock(x.opts.xenditURL) + .post('/v2/payment_method', { + type: "QR_CODE", + reusability: "ONE_TIME_USE", + qr_code: { + channel_code: "QRIS", + amount: 10000 + } + }) +}); + +describe('Payment Method V2 Service', () => { + describe('list payments', () => { + it('should get a list of payments', done => { + expect( + p.createPaymentMethodV2({ + type: "QR_CODE", + reusability: "ONE_TIME_USE", + qr_code: { + channel_code: "QRIS", + amount: 10000 + } + }), + ) + .and.notify(done); + }); + }); +}); From 77203cb6ffa374880a7a8dcec8cae3cc59e19400 Mon Sep 17 00:00:00 2001 From: Dharnit <85389770+dharmasatrya@users.noreply.github.com> Date: Thu, 3 Nov 2022 18:06:53 +0700 Subject: [PATCH 2/7] APPL-1038/PaymentMethodV2 --- integration_test/index.js | 1 + integration_test/payment_method_v2.test.js | 32 ++ src/payment_method_v2/payment_method_v2.js | 21 +- test/payment_method_v2/constants.js | 352 ++++++++++++++---- .../payment_method_v2.test.js | 115 +++++- 5 files changed, 435 insertions(+), 86 deletions(-) create mode 100644 integration_test/payment_method_v2.test.js diff --git a/integration_test/index.js b/integration_test/index.js index 7afb52f..a2ea440 100644 --- a/integration_test/index.js +++ b/integration_test/index.js @@ -15,6 +15,7 @@ Promise.all([ require('./direct_debit.test')(), require('./report.test')(), require('./transaction.test')(), + require('./payment_method_v2.test') ]) .then(() => { Promise.all([require('./regional_retail_outlet.test')()]).then(() => diff --git a/integration_test/payment_method_v2.test.js b/integration_test/payment_method_v2.test.js new file mode 100644 index 0000000..51e3897 --- /dev/null +++ b/integration_test/payment_method_v2.test.js @@ -0,0 +1,32 @@ +const x = require('./xendit.test'); + +const { PaymentMethodV2 } = x; +const pm = new PaymentMethodV2({}); + +module.exports = function () { + return pm + .createPaymentMethodV2({ + type: 'QR_CODE', + reusability: 'ONE_TIME_USE', + qr_code: { + channel_code: 'QRIS', + amount: 10000 + } + } + ) + .then(pm => + pm.listPaymentMethodV2( + id = 'pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a' + ), + ) + .then(() => { + // eslint-disable-next-line no-console + console.log('Platform integration test done...'); + }) + .catch(e => { + throw new Error( + `Platform integration tests failed with error: ${e.message}`, + ); + }); +}; + diff --git a/src/payment_method_v2/payment_method_v2.js b/src/payment_method_v2/payment_method_v2.js index d998e8a..6f425f4 100644 --- a/src/payment_method_v2/payment_method_v2.js +++ b/src/payment_method_v2/payment_method_v2.js @@ -123,7 +123,7 @@ PaymentMethodV2.prototype.authorizePaymentMethodV2 = function (data) { } fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}/auth`, { - method: 'GET', + method: 'POST', headers, body: JSON.stringify({ auth_code: data.auth_code @@ -149,10 +149,7 @@ PaymentMethodV2.prototype.getPaymentMethodByIdV2 = function (data) { fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}`, { method: 'GET', - headers, - body: JSON.stringify({ - auth_code: data.auth_code - }), + headers }) .then(resolve) .catch(reject); @@ -176,13 +173,13 @@ PaymentMethodV2.prototype.updatePaymentMethodV2 = function (data) { method: 'PATCH', headers, body: JSON.stringify({ - reference_id?: data.reference_id, - description?: data.description, - metadata?: data.metadata, - status?: data.status, - reusability?: data.reusability, - over_the_counter?: data.over_the_counter, - virtual_account?: data.virtual_account + reference_id: data.reference_id, + description: data.description, + metadata: data.metadata, + status: data.status, + reusability: data.reusability, + over_the_counter: data.over_the_counter, + virtual_account: data.virtual_account }), }) .then(resolve) diff --git a/test/payment_method_v2/constants.js b/test/payment_method_v2/constants.js index ec62544..0a4876b 100644 --- a/test/payment_method_v2/constants.js +++ b/test/payment_method_v2/constants.js @@ -1,79 +1,291 @@ -const TYPES = ['DISBURSEMENT', 'PAYMENT']; -const STATUSES = ['PENDING', 'SUCCESS']; -const CHANNEL_CATEGORIES = ['BANK']; -const CREATED_DATE_FROM = new Date('2022-01-01T00:00:00.000Z'); -const CREATED_DATE_TO = new Date('2022-02-01T00:00:00.000Z'); +const CREATE_PAYMENT_RESPONSE = { + id: "pm-77de3ae9-0795-4de4-a08f-b8a463ae8eb4", + type: "QR_CODE", + country: "ID", + business_id: "58cd618ba0464eb64acdb246", + customer_id: null, + reference_id: "117e6382-d612-4d7c-94b0-21b76b136f64", + reusability: "ONE_TIME_USE", + status: "ACTIVE", + actions: [], + description: null, + created: "2022-11-02T10:14:20.8306107Z", + updated: "2022-11-02T10:14:20.8306107Z", + metadata: null, + billing_information: null, + failure_code: null, + ewallet: null, + direct_bank_transfer: null, + direct_debit: null, + card: null, + over_the_counter: null, + qr_code: { + amount: 10000, + currency: "IDR", + channel_code: "QRIS", + channel_properties: { + qr_string: "00020101021226660014ID.LINKAJA.WWW011893600911002414220002152003260414220010303UME51450015ID.OR.GPNQR.WWW02150000000000000000303UME520454995802ID5909Xendit QR6007Jakarta61051216062380115WxFFAGZrEbCqdch0715WxFFAGZrEbCqdch53033605405100006304716E" + } + }, + virtual_account: null +} -const TRANSACTION_ID = 'txn_123123'; -const QUERY_STRING = - 'types=DISBURSEMENT&types=PAYMENT&statuses=PENDING&statuses=SUCCESS&' + - 'channel_categories=BANK&created[gte]=2022-01-01T00:00:00.000Z&' + - 'created[lte]=2022-02-01T00:00:00.000Z'; +const CREATE_PAYMENT_MISSING_TYPE_RESPONSE = { + error_code: "API_VALIDATION_ERROR", + message: "Failed to validate the request, 1 error occurred.", + errors: [ + { + path: "body.type", + message: "Property 'type' is missing" + } + ] +} -const GET_TRANSACTION_RESPONSE = { - id: TRANSACTION_ID, - product_id: '1232131', - type: TYPES[0], - status: STATUSES[0], - channel_category: CHANNEL_CATEGORIES[0], - channel_code: 'BCA', - reference_id: 'Bank Central Asia (BCA) - BCA single disbursement', - account_identifier: '123123', - currency: 'IDR', - amount: 10000, - net_amount: 10000, - cashflow: 'MONEY_OUT', - business_id: '13123', - created: '2022-02-01T00:00:00.000Z', - updated: '2022-02-01T00:00:00.000Z', - fee: { - xendit_fee: 0, - value_added_tax: 0, - xendit_withholding_tax: 0, - third_party_withholding_tax: 0, - status: 'COMPLETED', - }, +const LIST_PAYMENT_METHOD_RESPONSE = { + data: [ + { + id: "pm-77de3ae9-0795-4de4-a08f-b8a463ae8eb4", + type: "QR_CODE", + country: "ID", + business_id: "58cd618ba0464eb64acdb246", + customer_id: null, + reference_id: "117e6382-d612-4d7c-94b0-21b76b136f64", + reusability: "ONE_TIME_USE", + status: "ACTIVE", + actions: [], + description: null, + created: "2022-11-02T10:14:20.830611Z", + updated: "2022-11-02T10:14:20.830611Z", + metadata: null, + billing_information: null, + failure_code: null, + ewallet: null, + direct_bank_transfer: null, + direct_debit: null, + card: null, + over_the_counter: null, + qr_code: { + amount: 10000, + currency: "IDR", + channel_code: "QRIS", + channel_properties: { + qr_string: "00020101021226660014ID.LINKAJA.WWW011893600911002414220002152003260414220010303UME51450015ID.OR.GPNQR.WWW02150000000000000000303UME520454995802ID5909Xendit QR6007Jakarta61051216062380115WxFFAGZrEbCqdch0715WxFFAGZrEbCqdch53033605405100006304716E" + } + }, + virtual_account: null + } + ], + has_more: false }; -const ANOTHER_TRANSACTION_RESPONSE = { - id: TRANSACTION_ID, - product_id: '1232132131', - type: TYPES[1], - status: STATUSES[1], - channel_category: CHANNEL_CATEGORIES[0], - channel_code: 'BCA', - reference_id: 'Bank Central Asia (BCA) - BCA single disbursement', - account_identifier: '123123', - currency: 'IDR', - amount: 100001, - net_amount: 100001, - cashflow: 'MONEY_OUT', - business_id: '13123', - created: '2022-02-01T00:00:00.000Z', - updated: '2022-02-01T00:00:00.000Z', - fee: { - xendit_fee: 0, - value_added_tax: 0, - xendit_withholding_tax: 0, - third_party_withholding_tax: 0, - status: 'COMPLETED', +const PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE = { + id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a", + card: null, + type: "DIRECT_DEBIT", + status: "ACTIVE", + actions: [], + country: "ID", + created: "2022-08-12T13:30:26.579048Z", + ewallet: null, + qr_code: null, + updated: "2022-08-12T13:30:58.908220358Z", + metadata: null, + customer_id: "e2878b4c-d57e-4a2c-922d-c0313c2800a3", + description: null, + reusability: "MULTIPLE_USE", + direct_debit: { + type: "DEBIT_CARD", + debit_card: { + mobile_number: "+62818555988", + card_last_four: "8888", + card_expiry: "06/24", + email: "email@email.com" + }, + bank_account: null, + channel_code: "BRI", + channel_properties: { + mobile_number: "+62818555988", + card_last_four: "8888", + card_expiry: "06/24", + email: "test.email@xendit.co" + } }, -}; + failure_code: null, + reference_id: "620b9df4-fe69-4bfd-b9d4-5cba6861db8a", + virtual_account: null, + over_the_counter: null, + billing_information: null, + direct_bank_transfer: null, + business_id: "5f27a14a9bf05c73dd040bc8" +} -const LIST_TRANSACTIONS_RESPONSE = { - has_more: false, - data: [GET_TRANSACTION_RESPONSE, ANOTHER_TRANSACTION_RESPONSE], - links: [], -}; +const GET_PAYMENT_METHOD_LIST_BY_ID_SUCCESS_RESPONSE = { + id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a", + card: null, + type: "DIRECT_DEBIT", + status: "ACTIVE", + actions: [], + country: "ID", + created: "2022-08-12T13:30:26.579048Z", + ewallet: null, + qr_code: null, + updated: "2022-08-12T13:30:58.908220358Z", + metadata: null, + customer_id: "e2878b4c-d57e-4a2c-922d-c0313c2800a3", + description: null, + reusability: "MULTIPLE_USE", + direct_debit: { + type: "DEBIT_CARD", + debit_card: { + mobile_number: "+62818555988", + card_last_four: "8888", + card_expiry: "06/24", + email: "email@email.com" + }, + bank_account: null, + channel_code: "BRI", + channel_properties: { + mobile_number: "+62818555988", + card_last_four: "8888", + card_expiry: "06/24", + email: "test.email@xendit.co" + } + }, + failure_code: null, + reference_id: "620b9df4-fe69-4bfd-b9d4-5cba6861db8a", + virtual_account: null, + over_the_counter: null, + billing_information: null, + direct_bank_transfer: null, + business_id: "5f27a14a9bf05c73dd040bc8" +} + +const UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE = { + actions: [], + billing_information: null, + business_id: "5f27a14a9bf05c73dd040bc8", + card: null, + country: "ID", + created: "2022-08-12T13:30:26.579048Z", + customer_id: "e2878b4c-d57e-4a2c-922d-c0313c2800a3", + description: null, + direct_bank_transfer: null, + direct_debit: { + bank_account: null, + channel_code: "BRI", + channel_properties: { + card_expiry: "06/24", + card_last_four: "8888", + email: "test.email@xendit.co", + mobile_number: "+62818555988" + }, + debit_card: { + card_expiry: "06/24", + card_last_four: "8888", + email: "email@email.com", + mobile_number: "+62818555988" + }, + type: "DEBIT_CARD" + }, + ewallet: null, + failure_code: null, + id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a", + metadata: null, + over_the_counter: null, + qr_code: null, + reference_id: "620b9df4-fe69-4bfd-b9d4-5cba6861db8a", + reusability: "MULTIPLE_USE", + status: "ACTIVE", + type: "DIRECT_DEBIT", + updated: "2022-08-12T13:30:58.908220358Z", + virtual_account: null, +} + +const EXPIRE_PAYMENT_METHOD_SUCCESS_RESPONSE = { + id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a", + card: null, + type: "DIRECT_DEBIT", + status: "EXPIRED", + actions: [], + country: "PH", + created: "2022-08-12T13:30:26.579048Z", + ewallet: null, + qr_code: null, + updated: "2022-08-12T13:30:58.908220358Z", + metadata: null, + customer_id: "e2878b4c-d57e-4a2c-922d-c0313c2800a3", + description: null, + reusability: "MULTIPLE_USE", + direct_debit: { + type: "BANK_ACCOUNT", + debit_card: null, + bank_account: { + bank_account_hash: "b4dfa99c9b60c77f2e3962b73c098945", + masked_bank_account_number: "XXXXXX1234" + }, + channel_code: "BPI", + channel_propertie: { + failure_return_url: "https://your-redirect-website.com/failure", + success_return_url: "https://your-redirect-website.com/success" + } + }, + failure_code: null, + reference_id: "620b9df4-fe69-4bfd-b9d4-5cba6861db8a", + virtual_account: null, + over_the_counter: null, + billing_information: null, + direct_bank_transfer: null, + business_id: "5f27a14a9bf05c73dd040bc8" +} + +const LIST_PAYMENTS_BY_PAYMENT_METHOD_ID_SUCCESS_RESPONSE = { + actions: [], + billing_information: null, + business_id: "5f27a14a9bf05c73dd040bc8", + card: null, + country: "ID", + created: "2022-08-12T13:30:26.579048Z", + customer_id: "e2878b4c-d57e-4a2c-922d-c0313c2800a3", + description: null, + direct_bank_transfer: null, + direct_debit: { + bank_account: null, + channel_code: "BRI", + channel_properties: { + card_expiry: "06/24", + card_last_four: "8888", + email: "test.email@xendit.co", + mobile_number: "+62818555988", + }, + debit_card: { + card_expiry: "06/24", + card_last_four: "8888", + email: "email@email.com", + mobile_number: "+62818555988", + }, + type: "DEBIT_CARD" + }, + ewallet: null, + failure_code: null, + id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a", + metadata: null, + over_the_counter: null, + qr_code: null, + reference_id: "620b9df4-fe69-4bfd-b9d4-5cba6861db8a", + reusability: "MULTIPLE_USE", + status: "ACTIVE", + type: "DIRECT_DEBIT", + updated: "2022-08-12T13:30:58.908220358Z", + virtual_account: null, +} module.exports = { - TYPES, - STATUSES, - CHANNEL_CATEGORIES, - CREATED_DATE_FROM, - CREATED_DATE_TO, - TRANSACTION_ID, - GET_TRANSACTION_RESPONSE, - LIST_TRANSACTIONS_RESPONSE, - QUERY_STRING, + CREATE_PAYMENT_RESPONSE, + CREATE_PAYMENT_MISSING_TYPE_RESPONSE, + LIST_PAYMENT_METHOD_RESPONSE, + PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE, + GET_PAYMENT_METHOD_LIST_BY_ID_SUCCESS_RESPONSE, + UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE, + EXPIRE_PAYMENT_METHOD_SUCCESS_RESPONSE, + LIST_PAYMENTS_BY_PAYMENT_METHOD_ID_SUCCESS_RESPONSE }; diff --git a/test/payment_method_v2/payment_method_v2.test.js b/test/payment_method_v2/payment_method_v2.test.js index 2069ab2..b118b9e 100644 --- a/test/payment_method_v2/payment_method_v2.test.js +++ b/test/payment_method_v2/payment_method_v2.test.js @@ -5,7 +5,15 @@ const { expect } = chai; const nock = require('nock'); const { Errors } = require('../../src/xendit'); const Xendit = require('../../src/xendit'); -const { QUERY_STRING } = require('./constants'); +const { + CREATE_PAYMENT_RESPONSE, + CREATE_PAYMENT_MISSING_TYPE_RESPONSE, + LIST_PAYMENT_METHOD_RESPONSE, + PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE, + GET_PAYMENT_METHOD_LIST_BY_ID_SUCCESS_RESPONSE, + UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE, + LIST_PAYMENTS_BY_PAYMENT_METHOD_ID_SUCCESS_RESPONSE +} = require('./constants'); const x = new Xendit({ secretKey: 'xnd_production_ypr0UI6148UVBDHMJsHCUgF0Yff4XEjRSAzBvM626qPzHEBo45IRCBdqEHmmql', @@ -20,7 +28,7 @@ beforeEach(function () { }); before(function () { nock(x.opts.xenditURL) - .post('/v2/payment_method', { + .post('/v2/payment_methods', { type: "QR_CODE", reusability: "ONE_TIME_USE", qr_code: { @@ -28,11 +36,24 @@ before(function () { amount: 10000 } }) + .reply(201, TestConstants.CREATE_PAYMENT_RESPONSE) + .get('/v2/payment_methods') + .reply(200, TestConstants.LIST_PAYMENT_METHOD_RESPONSE) + .post('/v2/payment_methods/pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a/auth') + .reply(200, TestConstants.PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE) + .get('/v2/payment_methods/pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a') + .reply(200, TestConstants.GET_PAYMENT_METHOD_LIST_BY_ID_SUCCESS_RESPONSE) + .patch('/v2/payment_methods/pm-4c85fd2c-29da-4bc4-b642-064a42727d89') + .reply(200, TestConstants.UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE) + .post('/v2/payment_methods/pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a/expire') + .reply(200, TestConstants.EXPIRE_PAYMENT_METHOD_SUCCESS_RESPONSE) + .get('/v2/payment_methods/qrpy_0de1622b-677c-48c5-ac8c-ea1b9636c48f/payments') + .reply(200, TestConstants.LIST_PAYMENTS_BY_PAYMENT_METHOD_ID_SUCCESS_RESPONSE) }); describe('Payment Method V2 Service', () => { - describe('list payments', () => { - it('should get a list of payments', done => { + describe('create payments', () => { + it('should get a response of payment created', done => { expect( p.createPaymentMethodV2({ type: "QR_CODE", @@ -43,6 +64,92 @@ describe('Payment Method V2 Service', () => { } }), ) + .to.eventually.deep.equal(TestConstants.CREATE_PAYMENT_RESPONSE) + .and.notify(done); + }); + it('should reject with missing field', done => { + expect( + p.createPaymentMethodV2({ + reusability: "ONE_TIME_USE", + qr_code: { + channel_code: "QRIS", + amount: 10000 + } + }), + ) + .to.eventually.deep.equal(TestConstants.CREATE_PAYMENT_MISSING_TYPE_RESPONSE) + .to.eventually.be.rejected.then(e => + Promise.all([ + expect(e).to.have.property('status', 400), + expect(e).to.have.property('code', Errors.API_VALIDATION_ERROR) + ]), + ) + .then(() => done()) + .catch(e => done(e)); + }); + }); + describe('list payments', () => { + it('should get a list of payment created', done => { + expect( + p.listPaymentMethodV2({}), + ) + .to.eventually.deep.equal(TestConstants.LIST_PAYMENT_METHOD_RESPONSE) + .and.notify(done); + }); + }); + describe('auth payments', () => { + it('should get a success response of payment authorized', done => { + expect( + p.authorizePaymentMethodV2({ + auth_code: "12345", + id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a" + }), + ) + .to.eventually.deep.equal(TestConstants.PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE) + .and.notify(done); + }); + }); + describe('get payment method by id', () => { + it('should get a response of payment method by id', done => { + expect( + p.getPaymentMethodByIdV2({ + id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a" + }), + ) + .to.eventually.deep.equal(TestConstants.PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE) + .and.notify(done); + }); + }); + describe('update payment method', () => { + it('should get a response of updated payment method by id', done => { + expect( + p.updatePaymentMethodV2({ + id: "pm-4c85fd2c-29da-4bc4-b642-064a42727d89" + }), + ) + .to.eventually.deep.equal(TestConstants.UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE) + .and.notify(done); + }); + }); + describe('expire payment method', () => { + it('should get a response of expired payment method by id', done => { + expect( + p.expirePaymentMethodV2({ + id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a" + }), + ) + .to.eventually.deep.equal(TestConstants.EXPIRE_PAYMENT_METHOD_SUCCESS_RESPONSE) + .and.notify(done); + }); + }); + describe('list payments by payment method', () => { + it('should get a list of payments by payment method', done => { + expect( + p.listPaymentsByPaymentMethodIdV2({ + id: "qrpy_0de1622b-677c-48c5-ac8c-ea1b9636c48f" + }), + ) + .to.eventually.deep.equal(TestConstants.UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE) .and.notify(done); }); }); From 153877ac9cea18e55b6086a0cc8cd0aaae552b29 Mon Sep 17 00:00:00 2001 From: Dharnit <85389770+dharmasatrya@users.noreply.github.com> Date: Mon, 7 Nov 2022 16:39:22 +0700 Subject: [PATCH 3/7] fix package lock --- package-lock.json | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b8bd697..1b7861a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "xendit-node", - "version": "1.21.7", + "version": "1.21.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "xendit-node", - "version": "1.21.7", + "version": "1.21.2", "license": "MIT", "dependencies": { - "node-fetch": "^2.6.1" + "node-fetch": "^2.6.1", + "xendit-node": "^1.21.1" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^2.13.0", @@ -9454,6 +9455,14 @@ "node": ">=8" } }, + "node_modules/xendit-node": { + "version": "1.21.1", + "resolved": "https://registry.npmjs.org/xendit-node/-/xendit-node-1.21.1.tgz", + "integrity": "sha512-lWNW49JmNRxHMkuMqn7jGCe36H2kA4xDCWBV3lECOG1ZayTyzHdHya47wL7x7N1rwjK6/DgoM6Z2gw8wVbNjyA==", + "dependencies": { + "node-fetch": "^2.6.1" + } + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", @@ -16627,6 +16636,14 @@ "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==", "dev": true }, + "xendit-node": { + "version": "1.21.1", + "resolved": "https://registry.npmjs.org/xendit-node/-/xendit-node-1.21.1.tgz", + "integrity": "sha512-lWNW49JmNRxHMkuMqn7jGCe36H2kA4xDCWBV3lECOG1ZayTyzHdHya47wL7x7N1rwjK6/DgoM6Z2gw8wVbNjyA==", + "requires": { + "node-fetch": "^2.6.1" + } + }, "xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", From 42340c3d2451a60920588e8a89c3315f9a194f70 Mon Sep 17 00:00:00 2001 From: Dharnit <85389770+dharmasatrya@users.noreply.github.com> Date: Tue, 8 Nov 2022 10:25:28 +0700 Subject: [PATCH 4/7] fix test --- integration_test/index.js | 2 +- integration_test/payment_method_v2.test.js | 32 ------- .../payment_method_v2.test.js | 95 ++++++++++--------- 3 files changed, 52 insertions(+), 77 deletions(-) delete mode 100644 integration_test/payment_method_v2.test.js diff --git a/integration_test/index.js b/integration_test/index.js index a2ea440..4586d97 100644 --- a/integration_test/index.js +++ b/integration_test/index.js @@ -15,7 +15,7 @@ Promise.all([ require('./direct_debit.test')(), require('./report.test')(), require('./transaction.test')(), - require('./payment_method_v2.test') + // require('./payment_method_v2.test') ]) .then(() => { Promise.all([require('./regional_retail_outlet.test')()]).then(() => diff --git a/integration_test/payment_method_v2.test.js b/integration_test/payment_method_v2.test.js deleted file mode 100644 index 51e3897..0000000 --- a/integration_test/payment_method_v2.test.js +++ /dev/null @@ -1,32 +0,0 @@ -const x = require('./xendit.test'); - -const { PaymentMethodV2 } = x; -const pm = new PaymentMethodV2({}); - -module.exports = function () { - return pm - .createPaymentMethodV2({ - type: 'QR_CODE', - reusability: 'ONE_TIME_USE', - qr_code: { - channel_code: 'QRIS', - amount: 10000 - } - } - ) - .then(pm => - pm.listPaymentMethodV2( - id = 'pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a' - ), - ) - .then(() => { - // eslint-disable-next-line no-console - console.log('Platform integration test done...'); - }) - .catch(e => { - throw new Error( - `Platform integration tests failed with error: ${e.message}`, - ); - }); -}; - diff --git a/test/payment_method_v2/payment_method_v2.test.js b/test/payment_method_v2/payment_method_v2.test.js index b118b9e..74bf193 100644 --- a/test/payment_method_v2/payment_method_v2.test.js +++ b/test/payment_method_v2/payment_method_v2.test.js @@ -5,36 +5,28 @@ const { expect } = chai; const nock = require('nock'); const { Errors } = require('../../src/xendit'); const Xendit = require('../../src/xendit'); -const { - CREATE_PAYMENT_RESPONSE, - CREATE_PAYMENT_MISSING_TYPE_RESPONSE, - LIST_PAYMENT_METHOD_RESPONSE, - PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE, - GET_PAYMENT_METHOD_LIST_BY_ID_SUCCESS_RESPONSE, - UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE, - LIST_PAYMENTS_BY_PAYMENT_METHOD_ID_SUCCESS_RESPONSE -} = require('./constants'); const x = new Xendit({ - secretKey: 'xnd_production_ypr0UI6148UVBDHMJsHCUgF0Yff4XEjRSAzBvM626qPzHEBo45IRCBdqEHmmql', + secretKey: + 'xnd_production_ypr0UI6148UVBDHMJsHCUgF0Yff4XEjRSAzBvM626qPzHEBo45IRCBdqEHmmql', }); chai.use(chaiAsProm); const { PaymentMethodV2 } = x; let p = new PaymentMethodV2({}); -beforeEach(function () { +beforeEach(function() { p = new PaymentMethodV2({}); }); -before(function () { +before(function() { nock(x.opts.xenditURL) .post('/v2/payment_methods', { - type: "QR_CODE", - reusability: "ONE_TIME_USE", + type: 'QR_CODE', + reusability: 'ONE_TIME_USE', qr_code: { - channel_code: "QRIS", - amount: 10000 - } + channel_code: 'QRIS', + amount: 10000, + }, }) .reply(201, TestConstants.CREATE_PAYMENT_RESPONSE) .get('/v2/payment_methods') @@ -47,8 +39,13 @@ before(function () { .reply(200, TestConstants.UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE) .post('/v2/payment_methods/pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a/expire') .reply(200, TestConstants.EXPIRE_PAYMENT_METHOD_SUCCESS_RESPONSE) - .get('/v2/payment_methods/qrpy_0de1622b-677c-48c5-ac8c-ea1b9636c48f/payments') - .reply(200, TestConstants.LIST_PAYMENTS_BY_PAYMENT_METHOD_ID_SUCCESS_RESPONSE) + .get( + '/v2/payment_methods/qrpy_0de1622b-677c-48c5-ac8c-ea1b9636c48f/payments', + ) + .reply( + 200, + TestConstants.LIST_PAYMENTS_BY_PAYMENT_METHOD_ID_SUCCESS_RESPONSE, + ); }); describe('Payment Method V2 Service', () => { @@ -56,12 +53,12 @@ describe('Payment Method V2 Service', () => { it('should get a response of payment created', done => { expect( p.createPaymentMethodV2({ - type: "QR_CODE", - reusability: "ONE_TIME_USE", + type: 'QR_CODE', + reusability: 'ONE_TIME_USE', qr_code: { - channel_code: "QRIS", - amount: 10000 - } + channel_code: 'QRIS', + amount: 10000, + }, }), ) .to.eventually.deep.equal(TestConstants.CREATE_PAYMENT_RESPONSE) @@ -70,18 +67,20 @@ describe('Payment Method V2 Service', () => { it('should reject with missing field', done => { expect( p.createPaymentMethodV2({ - reusability: "ONE_TIME_USE", + reusability: 'ONE_TIME_USE', qr_code: { - channel_code: "QRIS", - amount: 10000 - } + channel_code: 'QRIS', + amount: 10000, + }, }), ) - .to.eventually.deep.equal(TestConstants.CREATE_PAYMENT_MISSING_TYPE_RESPONSE) + .to.eventually.deep.equal( + TestConstants.CREATE_PAYMENT_MISSING_TYPE_RESPONSE, + ) .to.eventually.be.rejected.then(e => Promise.all([ expect(e).to.have.property('status', 400), - expect(e).to.have.property('code', Errors.API_VALIDATION_ERROR) + expect(e).to.have.property('code', Errors.API_VALIDATION_ERROR), ]), ) .then(() => done()) @@ -90,9 +89,7 @@ describe('Payment Method V2 Service', () => { }); describe('list payments', () => { it('should get a list of payment created', done => { - expect( - p.listPaymentMethodV2({}), - ) + expect(p.listPaymentMethodV2({})) .to.eventually.deep.equal(TestConstants.LIST_PAYMENT_METHOD_RESPONSE) .and.notify(done); }); @@ -101,11 +98,13 @@ describe('Payment Method V2 Service', () => { it('should get a success response of payment authorized', done => { expect( p.authorizePaymentMethodV2({ - auth_code: "12345", - id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a" + auth_code: '12345', + id: 'pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a', }), ) - .to.eventually.deep.equal(TestConstants.PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE) + .to.eventually.deep.equal( + TestConstants.PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE, + ) .and.notify(done); }); }); @@ -113,10 +112,12 @@ describe('Payment Method V2 Service', () => { it('should get a response of payment method by id', done => { expect( p.getPaymentMethodByIdV2({ - id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a" + id: 'pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a', }), ) - .to.eventually.deep.equal(TestConstants.PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE) + .to.eventually.deep.equal( + TestConstants.PAYMENT_METHOD_AUTH_SUCCESS_RESPONSE, + ) .and.notify(done); }); }); @@ -124,10 +125,12 @@ describe('Payment Method V2 Service', () => { it('should get a response of updated payment method by id', done => { expect( p.updatePaymentMethodV2({ - id: "pm-4c85fd2c-29da-4bc4-b642-064a42727d89" + id: 'pm-4c85fd2c-29da-4bc4-b642-064a42727d89', }), ) - .to.eventually.deep.equal(TestConstants.UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE) + .to.eventually.deep.equal( + TestConstants.UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE, + ) .and.notify(done); }); }); @@ -135,10 +138,12 @@ describe('Payment Method V2 Service', () => { it('should get a response of expired payment method by id', done => { expect( p.expirePaymentMethodV2({ - id: "pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a" + id: 'pm-6ff0b6f2-f5de-457f-b08f-bc98fbae485a', }), ) - .to.eventually.deep.equal(TestConstants.EXPIRE_PAYMENT_METHOD_SUCCESS_RESPONSE) + .to.eventually.deep.equal( + TestConstants.EXPIRE_PAYMENT_METHOD_SUCCESS_RESPONSE, + ) .and.notify(done); }); }); @@ -146,10 +151,12 @@ describe('Payment Method V2 Service', () => { it('should get a list of payments by payment method', done => { expect( p.listPaymentsByPaymentMethodIdV2({ - id: "qrpy_0de1622b-677c-48c5-ac8c-ea1b9636c48f" + id: 'qrpy_0de1622b-677c-48c5-ac8c-ea1b9636c48f', }), ) - .to.eventually.deep.equal(TestConstants.UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE) + .to.eventually.deep.equal( + TestConstants.UPDATE_PAYMENT_METHOD_SUCCESS_RESPONSE, + ) .and.notify(done); }); }); From f5d6f9ee9660edd84aec02f4351e4b885cbca4aa Mon Sep 17 00:00:00 2001 From: Dharnit <85389770+dharmasatrya@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:33:03 +0700 Subject: [PATCH 5/7] fix lint --- examples/with_async/payment_method_v2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/with_async/payment_method_v2.js b/examples/with_async/payment_method_v2.js index c64724b..b50cc49 100644 --- a/examples/with_async/payment_method_v2.js +++ b/examples/with_async/payment_method_v2.js @@ -20,7 +20,8 @@ const pm = new PaymentMethodV2({}); }, }, }); - console.log('created payment method', createdPaymentMethod); // eslint-disable-line no-console + // eslint-disable-next-line no-console + console.log('created payment method', createdPaymentMethod); const paymentMethodDetailsById = await pm.getPaymentMethodByIdV2({ id: createdPaymentMethod.id, From 3f35960a87611ee58d83f37be8ba7548ad5bae11 Mon Sep 17 00:00:00 2001 From: Dharnit <85389770+dharmasatrya@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:35:03 +0700 Subject: [PATCH 6/7] add new line for lint --- src/payment_method_v2/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/payment_method_v2/index.d.ts b/src/payment_method_v2/index.d.ts index 39543b7..5364e16 100644 --- a/src/payment_method_v2/index.d.ts +++ b/src/payment_method_v2/index.d.ts @@ -1,3 +1,3 @@ import PaymentMethodV2Service from './payment_method_v2'; -export { PaymentMethodV2Service }; \ No newline at end of file +export { PaymentMethodV2Service }; From 250e0f2161be8d60af26149bcfd46fa41ef10902 Mon Sep 17 00:00:00 2001 From: Dharnit <85389770+dharmasatrya@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:35:56 +0700 Subject: [PATCH 7/7] add new line for lint --- src/payment_method_v2/index.js | 2 +- src/payment_method_v2/payment_method_v2.d.ts | 336 +++++++++---------- 2 files changed, 168 insertions(+), 170 deletions(-) diff --git a/src/payment_method_v2/index.js b/src/payment_method_v2/index.js index dacec73..95c0c9e 100644 --- a/src/payment_method_v2/index.js +++ b/src/payment_method_v2/index.js @@ -1,3 +1,3 @@ const PaymentMethodV2Service = require('./payment_method_v2'); -module.exports = { PaymentMethodV2Service }; \ No newline at end of file +module.exports = { PaymentMethodV2Service }; diff --git a/src/payment_method_v2/payment_method_v2.d.ts b/src/payment_method_v2/payment_method_v2.d.ts index ff58f1e..5955085 100644 --- a/src/payment_method_v2/payment_method_v2.d.ts +++ b/src/payment_method_v2/payment_method_v2.d.ts @@ -1,241 +1,239 @@ import { XenditOptions } from '../xendit_opts'; enum PaymentMethodV2Types { - Card = 'CARD', - eWallet = 'EWALLET', - DirectDebit = 'DIRECT_DEBIT', - OverTheCounter = 'OVER_THE_COUNTER', - QRCODE = 'QR_CODE', - VitrualAccount = 'VIRTUAL_ACCOUNT' + Card = 'CARD', + eWallet = 'EWALLET', + DirectDebit = 'DIRECT_DEBIT', + OverTheCounter = 'OVER_THE_COUNTER', + QRCODE = 'QR_CODE', + VitrualAccount = 'VIRTUAL_ACCOUNT', } enum PaymentMenthodV2Reusabilities { - OneTimeUse = 'ONE_TIME_USE', - MultipleUse = 'MULTIPLE_USE', + OneTimeUse = 'ONE_TIME_USE', + MultipleUse = 'MULTIPLE_USE', } enum CreatePaymentMenthodV2Countries { - ID = 'ID', - PH = 'PH', + ID = 'ID', + PH = 'PH', } enum EWalletChannelCodes { - Dana = 'DANA', - OVO = 'OVO', - LinkAja = 'LINKAJA', - Astrapay = 'ASTRAPAY', - JeniusPay = 'JENIUSPAY', - ShopeePay = 'SHOPEEPAY', - GrabPay = 'GRABPAY', - Paymaya = 'PAYMAYA', - GCash = 'GCASH' + Dana = 'DANA', + OVO = 'OVO', + LinkAja = 'LINKAJA', + Astrapay = 'ASTRAPAY', + JeniusPay = 'JENIUSPAY', + ShopeePay = 'SHOPEEPAY', + GrabPay = 'GRABPAY', + Paymaya = 'PAYMAYA', + GCash = 'GCASH', } enum DirectDebitChannelCodes { - BRI = 'BRI', - Mandiri = 'MANDIRI', - BPI = 'BPI', - UBP = 'UBP', - RCBC = 'RCBC', - ChinaBank = 'CHINABANK' + BRI = 'BRI', + Mandiri = 'MANDIRI', + BPI = 'BPI', + UBP = 'UBP', + RCBC = 'RCBC', + ChinaBank = 'CHINABANK', } enum CardCurrencies { - IDR = 'IDR', - PHP = 'PHP', - USD = 'USD' + IDR = 'IDR', + PHP = 'PHP', + USD = 'USD', } enum OverTheCounterChannelCodes { - Alfamart = 'ALFAMART', - Indomaret = 'INDOMARET', - '7Eleven' = '7ELEVEN', - '7ElevenCLIQQ' = '7ELEVEN_CLIQQ', - Cebuana = 'CEBUANA', - ECPay = 'ECPAY', - Palawan = 'PALAWAN', - MLhuillier = 'MLHUILLIER', - DragonLoanECPAY = 'DRAGONLOAN_ECPAY' + Alfamart = 'ALFAMART', + Indomaret = 'INDOMARET', + '7Eleven' = '7ELEVEN', + '7ElevenCLIQQ' = '7ELEVEN_CLIQQ', + Cebuana = 'CEBUANA', + ECPay = 'ECPAY', + Palawan = 'PALAWAN', + MLhuillier = 'MLHUILLIER', + DragonLoanECPAY = 'DRAGONLOAN_ECPAY', } enum OverTheCounterCurrencies { - IDR = 'IDR', - PHP = 'PHP' + IDR = 'IDR', + PHP = 'PHP', } enum VirtualAccountChannelCodes { - BCA = 'BCA', - BSI = 'BSI', - BJB = 'BJB', - CIMB = 'CIMB', - SahabatSampoerna = 'SAHABAT_SAMPOERNA', - Artajasa = 'ARTAJASA', - BRI = 'BRI', - BNI = 'BNI', - Mandiri = 'MANDIRI', - Permata = 'PERMATA' + BCA = 'BCA', + BSI = 'BSI', + BJB = 'BJB', + CIMB = 'CIMB', + SahabatSampoerna = 'SAHABAT_SAMPOERNA', + Artajasa = 'ARTAJASA', + BRI = 'BRI', + BNI = 'BNI', + Mandiri = 'MANDIRI', + Permata = 'PERMATA', } enum VirtualAccountCurrencies { - IDR = 'IDR' + IDR = 'IDR', } enum QRISChannelCodes { - QRIS = 'QRIS' + QRIS = 'QRIS', } enum QRISCurrencies { - IDR = 'IDR' + IDR = 'IDR', } enum PaymentMethodV2Statuses { - Succeeded = 'SUCCEEDED', - Failed = 'FAILED', - Pending = 'PENDING' + Succeeded = 'SUCCEEDED', + Failed = 'FAILED', + Pending = 'PENDING', } interface BillingInformationItems { - country: string; - street_line1?: string; - street_line2?: string; - city?: string; - province_state?: string; - postal_code?: string; + country: string; + street_line1?: string; + street_line2?: string; + city?: string; + province_state?: string; + postal_code?: string; } interface EwalletItems { - channel_code: EWalletChannelCodes; - channel_properties: object; + channel_code: EWalletChannelCodes; + channel_properties: object; } interface DirectDebitItems { - channel_code: DirectDebitChannelCodes; - channel_properties: object; + channel_code: DirectDebitChannelCodes; + channel_properties: object; } interface CardItems { - currency: CardCurrencies; - channel_properties: object; - card_information: - { - card_number: string, - expiry_month: string, - expiry_year: string, - cardholder_name?: string - } + currency: CardCurrencies; + channel_properties: object; + card_information: { + card_number: string; + expiry_month: string; + expiry_year: string; + cardholder_name?: string; + }; } interface OverTheCounterItems { - channel_code: OverTheCounterChannelCodes; - currency?: OverTheCounterCurrencies; - amount?: number; - channel_properties: object; + channel_code: OverTheCounterChannelCodes; + currency?: OverTheCounterCurrencies; + amount?: number; + channel_properties: object; } interface VirtualAccountItems { - channel_code: VirtualAccountChannelCodes; - currency?: VirtualAccountCurrencies; - amount?: number; - channel_properties: object; + channel_code: VirtualAccountChannelCodes; + currency?: VirtualAccountCurrencies; + amount?: number; + channel_properties: object; } interface QRISItems { - channel_code: QRISChannelCodes; - currency?: QRISCurrencies; - amount?: number; + channel_code: QRISChannelCodes; + currency?: QRISCurrencies; + amount?: number; } interface UpdateOverTheCounterItems { - amount?: number; - channel_properties: object; + amount?: number; + channel_properties: object; } interface UpdateVirtualAccountItems { - amount?: number; - channel_properties: object; + amount?: number; + channel_properties: object; } interface ListPaymentMethodV2StatusItems { - status?: PaymentMethodV2Statuses; + status?: PaymentMethodV2Statuses; } - export = class PaymentMethodV2 { - constructor({ }); - static _constructorWithInjectedXenditOpts: ( - opts: XenditOptions, - ) => typeof PaymentMethodV2; - createPaymentMethodV2(data: { - type: PaymentMethodV2Types; - reusability: PaymentMenthodV2Reusabilities; - reference_id?: string; - customer_id?: string; - country?: CreatePaymentMenthodV2Countries; - description?: string; - billing_information?: BillingInformationItems; - metadata?: object; - ewallet?: EwalletItems; - direct_debit?: DirectDebitItems; - card?: CardItems; - over_the_counter?: OverTheCounterItems; - virtual_account?: VirtualAccountItems; - qr_code?: QRISItems; - for_user_id?: string; - idempotency_key?: string; - }): Promise; - - listPaymentMethodV2(data: { - id: string; - type?: PaymentMethodV2Types; - reusability?: PaymentMenthodV2Reusabilities; - reference_id?: string; - customer_id?: string; - limit?: string; - after_id?: string; - before_id?: string - for_user_id?: string - }): Promise; - - authorizePaymentMethodV2(data: { - id: string; - auth_code: string; - for_user_id?: string; - idempotency_key?: string; - }): Promise; - - getPaymentMethodByIdV2(data: { - id: string - for_user_id?: string - }): Promise; - - updatePaymentMethodV2(data: { - id: string; - reference_id?: string; - description?: string; - metadata?: object; - status?: object; - reusability?: PaymentMenthodV2Reusabilities; - over_the_counter?: UpdateOverTheCounterItems; - virtual_account?: UpdateVirtualAccountItems; - for_user_id?: string - }): Promise; - - expirePaymentMethodV2(data: { - id: string - for_user_id?: string - idempotency_key?: string - }): Promise; - - listPaymentsByPaymentMethodIdV2(data: { - id: string; - payment_request_id?: string; - reference_id?: string; - status?: ListPaymentMethodV2StatusItems; - limit?: number; - after_id?: string; - before_id?: string; - created?: string; - updated?: string; - for_user_id?: string; - }): Promise; -}; \ No newline at end of file + constructor({}); + static _constructorWithInjectedXenditOpts: ( + opts: XenditOptions, + ) => typeof PaymentMethodV2; + createPaymentMethodV2(data: { + type: PaymentMethodV2Types; + reusability: PaymentMenthodV2Reusabilities; + reference_id?: string; + customer_id?: string; + country?: CreatePaymentMenthodV2Countries; + description?: string; + billing_information?: BillingInformationItems; + metadata?: object; + ewallet?: EwalletItems; + direct_debit?: DirectDebitItems; + card?: CardItems; + over_the_counter?: OverTheCounterItems; + virtual_account?: VirtualAccountItems; + qr_code?: QRISItems; + for_user_id?: string; + idempotency_key?: string; + }): Promise; + + listPaymentMethodV2(data: { + id: string; + type?: PaymentMethodV2Types; + reusability?: PaymentMenthodV2Reusabilities; + reference_id?: string; + customer_id?: string; + limit?: string; + after_id?: string; + before_id?: string; + for_user_id?: string; + }): Promise; + + authorizePaymentMethodV2(data: { + id: string; + auth_code: string; + for_user_id?: string; + idempotency_key?: string; + }): Promise; + + getPaymentMethodByIdV2(data: { + id: string; + for_user_id?: string; + }): Promise; + + updatePaymentMethodV2(data: { + id: string; + reference_id?: string; + description?: string; + metadata?: object; + status?: object; + reusability?: PaymentMenthodV2Reusabilities; + over_the_counter?: UpdateOverTheCounterItems; + virtual_account?: UpdateVirtualAccountItems; + for_user_id?: string; + }): Promise; + + expirePaymentMethodV2(data: { + id: string; + for_user_id?: string; + idempotency_key?: string; + }): Promise; + + listPaymentsByPaymentMethodIdV2(data: { + id: string; + payment_request_id?: string; + reference_id?: string; + status?: ListPaymentMethodV2StatusItems; + limit?: number; + after_id?: string; + before_id?: string; + created?: string; + updated?: string; + for_user_id?: string; + }): Promise; +};