diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 593892c..22ed22b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,5 +25,5 @@ jobs: - run: npm test - run: npm run test:integration env: - SECRET_KEY: xnd_development_chBDpzjQZEI8nncBLrWtwau5r7rgiuunCJ4JCqsd68rXemDd74BnRpdO0bIZAMK + SECRET_KEY: xnd_development_oI7I6slPeYIxZPyfNxVIQt6R0JxiXGIRTBxBw5Ij26rjUwUeF29Aa9wHSETkM3 SECRET_KEY_PH: xnd_development_Va7pPIfYxIo7letKqhZCkwniwggDGyjB0sAzmOUe1mMkED4k0nLh1TvtVi0raNne diff --git a/README.md b/README.md index de6e2fb..ef967fa 100644 --- a/README.md +++ b/README.md @@ -16,106 +16,106 @@ For PCI compliance to be maintained, tokenization of credit cards info should be - [API Documentation](#api-documentation) - [Installation](#installation) - [Usage](#usage) - * [Card Services](#card-services) - + [Create charge](#create-charge) - + [Capture charge](#capture-charge) - + [Get charge](#get-charge) - + [Create authorization](#create-authorization) - + [Reverse authorization](#reverse-authorization) - + [Create refund](#create-refund) - + [Create promotion](#create-promotion) - * [Virtual Account Services](#virtual-account-services) - + [Get banks with available virtual account service](#get-banks-with-available-virtual-account-service) - + [Create a fixed virtual account](#create-a-fixed-virtual-account) - + [Get details of your fixed virtual account](#get-details-of-your-fixed-virtual-account) - + [Update details of your fixed virtual account](#update-details-of-your-fixed-virtual-account) - + [Get details of a VA payment](#get-details-of-a-va-payment) - * [Disbursement Services](#disbursement-services) - + [Get banks with available disbursement service](#get-banks-with-available-disbursement-service) - + [Create a disbursement](#create-a-disbursement) - + [Create a batch of disbursements](#create-a-batch-of-disbursements) - + [Get a disbursement by ID](#get-a-disbursement-by-id) - * [Invoice Services](#invoice-services) - + [Create an invoice](#create-an-invoice) - + [Get an invoice](#get-an-invoice) - + [Expire an invoice](#expire-an-invoice) - + [Get all invoices](#get-all-invoices) - * [Recurring Payments Services](#recurring-payments-services) - + [Create recurring payment](#create-recurring-payment) - + [Get recurring payment](#get-recurring-payment) - + [Edit recurring payment](#edit-recurring-payment) - + [Stop recurring payment](#stop-recurring-payment) - + [Pause recurring payment](#pause-recurring-payment) - + [Resume recurring payment](#resume-recurring-payment) - * [Recurring Services](#recurring-services) - + [Create recurring schedule](#create-recurring-schedule) - + [Edit recurring schedule](#edit-recurring-schedule) - + [Get recurring schedule](#get-recurring-schedule) - + [Create recurring plan](#create-recurring-plan) - + [Create recurring plan with schedule](#create-recurring-plan-with-schedule) - + [Edit recurring plan](#edit-recurring-plan) - + [Get recurring plan](#get-recurring-plan) - + [Deactivate recurring plan](#deactivate-recurring-plan) - + [Edit recurring cycle](#edit-recurring-cycle) - + [Get recurring cycle](#get-recurring-cycle) - + [Get all recurring cycles](#get-all-recurring-cycles) - + [Cancel recurring cycle](#cancel-recurring-cycle) - * [Payout Services](#payout-services) - + [Create a payout](#create-a-payout) - + [Get a payout](#get-a-payout) - + [Void a payout](#void-a-payout) - * [EWallet Services](#ewallet-services) - + [Create payment](#create-payment) - + [Get payment](#get-payment) - + [Create an ewallet charge](#create-an-ewallet-charge) - + [Get an ewallet charge status](#get-an-ewallet-charge-status) - + [Void an ewallet charge](#void-an-ewallet-charge) - + [Initialize tokenization](#initialize-tokenization) - + [Unlink tokenization](#unlink-tokenization) - + [Create payment method (E-Wallet)](#create-payment-method-e-wallet) - + [Get payment methods by customer ID (E-Wallet)](#get-payment-methods-by-customer-id-e-wallet) - * [Balance Services](#balance-services) - + [Get balance](#get-balance) - * [Retail Outlet Services](#retail-outlet-services) - + [Create fixed payment code](#create-fixed-payment-code) - + [Get fixed payment code](#get-fixed-payment-code) - + [Get payments by fixed payment code ID](#get-payments-by-fixed-payment-code-id) - + [Update fixed payment code](#update-fixed-payment-code) - + [Simulate payment for RO (only in dev mode)](#simulate-payment-for-ro-only-in-dev-mode) - * [QR Code Services](#qr-code-services) - + [Create code](#create-code) - + [Get code](#get-code) - + [Simulate payment for QR (only in dev mode)](#simulate-payment-for-qr-only-in-dev-mode) - + [Get payments by external ID](#get-payments-by-external-id) - * [Customer services](#customer-services) - + [Create customer](#create-customer) - + [Get customer](#get-customer) - + [Get customer by reference ID](#get-customer-by-reference-id) - + [Update customer](#update-customer) - * [Direct debit services](#direct-debit-services) - + [Initialize linked account tokenization](#initialize-linked-account-tokenization) - + [Validate OTP for Linked Account Token](#validate-otp-for-linked-account-token) - + [Retrieve accessible accounts by linked account token](#retrieve-accessible-accounts-by-linked-account-token) - + [Create payment method (Direct Debit)](#create-payment-method-direct-debit) - + [Get payment methods by customer ID (Direct Debit)](#get-payment-methods-by-customer-id-direct-debit) - + [Create direct debit payment](#create-direct-debit-payment) - + [Validate OTP for direct debit payment](#validate-otp-for-direct-debit-payment) - + [Get direct debit payment status by ID](#get-direct-debit-payment-status-by-id) - + [Get direct debit payment status by reference ID](#get-direct-debit-payment-status-by-reference-id) - * [Report Service](#report-service) - + [Generate Report](#generate-report) - + [Get Report](#get-report) - * [Transaction Service](#transaction-service) - + [Get Transaction](#get-transaction) - + [List Transactions](#list-transactions) - * [XenPlatform Service](#xenplatform-service) - + [Create sub-account](#create-sub-account) - + [Create sub-account using V2](#create-sub-account-using-v2) - + [Get sub-account by ID](#get-sub-account-by-id) - + [Update sub-account](#update-sub-account) - + [Set Callback URL](#set-callback-url) - + [Create transfers](#create-transfers) - + [Create fee rules](#create-fee-rules) + - [Card Services](#card-services) + - [Create charge](#create-charge) + - [Capture charge](#capture-charge) + - [Get charge](#get-charge) + - [Create authorization](#create-authorization) + - [Reverse authorization](#reverse-authorization) + - [Create refund](#create-refund) + - [Create promotion](#create-promotion) + - [Virtual Account Services](#virtual-account-services) + - [Get banks with available virtual account service](#get-banks-with-available-virtual-account-service) + - [Create a fixed virtual account](#create-a-fixed-virtual-account) + - [Get details of your fixed virtual account](#get-details-of-your-fixed-virtual-account) + - [Update details of your fixed virtual account](#update-details-of-your-fixed-virtual-account) + - [Get details of a VA payment](#get-details-of-a-va-payment) + - [Disbursement Services](#disbursement-services) + - [Get banks with available disbursement service](#get-banks-with-available-disbursement-service) + - [Create a disbursement](#create-a-disbursement) + - [Create a batch of disbursements](#create-a-batch-of-disbursements) + - [Get a disbursement by ID](#get-a-disbursement-by-id) + - [Invoice Services](#invoice-services) + - [Create an invoice](#create-an-invoice) + - [Get an invoice](#get-an-invoice) + - [Expire an invoice](#expire-an-invoice) + - [Get all invoices](#get-all-invoices) + - [Recurring Payments Services](#recurring-payments-services) + - [Create recurring payment](#create-recurring-payment) + - [Get recurring payment](#get-recurring-payment) + - [Edit recurring payment](#edit-recurring-payment) + - [Stop recurring payment](#stop-recurring-payment) + - [Pause recurring payment](#pause-recurring-payment) + - [Resume recurring payment](#resume-recurring-payment) + - [Recurring Services](#recurring-services) + - [Create recurring schedule](#create-recurring-schedule) + - [Edit recurring schedule](#edit-recurring-schedule) + - [Get recurring schedule](#get-recurring-schedule) + - [Create recurring plan](#create-recurring-plan) + - [Create recurring plan with schedule](#create-recurring-plan-with-schedule) + - [Edit recurring plan](#edit-recurring-plan) + - [Get recurring plan](#get-recurring-plan) + - [Deactivate recurring plan](#deactivate-recurring-plan) + - [Edit recurring cycle](#edit-recurring-cycle) + - [Get recurring cycle](#get-recurring-cycle) + - [Get all recurring cycles](#get-all-recurring-cycles) + - [Cancel recurring cycle](#cancel-recurring-cycle) + - [Payout Services](#payout-services) + - [Create a payout](#create-a-payout) + - [Get a payout](#get-a-payout) + - [Void a payout](#void-a-payout) + - [EWallet Services [SOON TO BE DEPRECATED - MAR 31 2022]](#ewallet-services-soon-to-be-deprecated---mar-31-2022) + - [Create payment](#create-payment) + - [Get payment](#get-payment) + - [Create an ewallet charge](#create-an-ewallet-charge) + - [Get an ewallet charge status](#get-an-ewallet-charge-status) + - [Void an ewallet charge](#void-an-ewallet-charge) + - [Initialize tokenization](#initialize-tokenization) + - [Unlink tokenization](#unlink-tokenization) + - [Create payment method (E-Wallet)](#create-payment-method-e-wallet) + - [Get payment methods by customer ID (E-Wallet)](#get-payment-methods-by-customer-id-e-wallet) + - [Balance Services](#balance-services) + - [Get balance](#get-balance) + - [Retail Outlet Services](#retail-outlet-services) + - [Create fixed payment code](#create-fixed-payment-code) + - [Get fixed payment code](#get-fixed-payment-code) + - [Get payments by fixed payment code ID](#get-payments-by-fixed-payment-code-id) + - [Update fixed payment code](#update-fixed-payment-code) + - [Simulate payment for RO (only in dev mode)](#simulate-payment-for-ro-only-in-dev-mode) + - [QR Code Services](#qr-code-services) + - [Create code](#create-code) + - [Get code](#get-code) + - [Simulate payment for QR (only in dev mode)](#simulate-payment-for-qr-only-in-dev-mode) + - [Get payments by external ID](#get-payments-by-external-id) + - [Customer services](#customer-services) + - [Create customer](#create-customer) + - [Get customer](#get-customer) + - [Get customer by reference ID](#get-customer-by-reference-id) + - [Update customer](#update-customer) + - [Direct debit services](#direct-debit-services) + - [Initialize linked account tokenization](#initialize-linked-account-tokenization) + - [Validate OTP for Linked Account Token](#validate-otp-for-linked-account-token) + - [Retrieve accessible accounts by linked account token](#retrieve-accessible-accounts-by-linked-account-token) + - [Create payment method (Direct Debit)](#create-payment-method-direct-debit) + - [Get payment methods by customer ID (Direct Debit)](#get-payment-methods-by-customer-id-direct-debit) + - [Create direct debit payment](#create-direct-debit-payment) + - [Validate OTP for direct debit payment](#validate-otp-for-direct-debit-payment) + - [Get direct debit payment status by ID](#get-direct-debit-payment-status-by-id) + - [Get direct debit payment status by reference ID](#get-direct-debit-payment-status-by-reference-id) + - [Report Service](#report-service) + - [Generate Report](#generate-report) + - [Get Report](#get-report) + - [Transaction Service](#transaction-service) + - [Get Transaction](#get-transaction) + - [List Transactions](#list-transactions) + - [XenPlatform Service](#xenplatform-service) + - [Create sub-account](#create-sub-account) + - [Create sub-account using V2](#create-sub-account-using-v2) + - [Get sub-account by ID](#get-sub-account-by-id) + - [Update sub-account](#update-sub-account) + - [Set Callback URL](#set-callback-url) + - [Create transfers](#create-transfers) + - [Create fee rules](#create-fee-rules) - [Contributing](#contributing) @@ -636,6 +636,7 @@ rp.pausePayment(data: { id: string }) ```ts rp.resumePayment(data: { id: string }) ``` + ### Recurring Services Instantiate Recurring service using constructor that has been injected with Xendit keys @@ -743,6 +744,7 @@ r.createPlan(data: { ``` #### Create recurring plan with schedule + ```ts r.createPlan(data: { businessId: string; @@ -879,7 +881,10 @@ p.getPayout(data: { id: string }) p.voidPayout(data: { id: string }) ``` -### EWallet Services +### EWallet Services [SOON TO BE DEPRECATED - MAR 31 2022] + +Deprecation notice here: +We will continue working on developing the SDK to support the new EWallet service Instanitiate EWallet service using constructor that has been injected with Xendit keys @@ -1440,14 +1445,14 @@ Example: Getting a transaction ```js t.getTransaction({ - id: "txn_123" + id: 'txn_123', }) .then(res => { console.log('Get Transaction:', res); }) .catch(e => { console.error(`Get Transaction Failed with Error: ${e.message}`); - }) + }); ``` #### Get Transaction diff --git a/examples/with_async/card.js b/examples/with_async/card.js index 21f381c..c2a4709 100644 --- a/examples/with_async/card.js +++ b/examples/with_async/card.js @@ -5,8 +5,18 @@ const card = new Card({}); // These IDs should be obtained using Xendit.js // https://docs.xendit.co/xenpayments/payments-credit-cards-overview/credit-cards-integration-and-testing/collecting-card-details-tokenization/index.html -const tokenID = '5e0461a86113354249aab7ec'; -const authID = '5e0461a96113354249aab7ee'; +// You can generate sample token/authentication data and replace it below +// https://js.xendit.co/test_tokenize.html +// https://js.xendit.co/test_authenticate.html +const tokenID = '623d394d672113001b79c1a1'; +const authID = '623d394d672113001b79c1a2'; + +function sleepFor(sleepDuration) { + var now = new Date().getTime(); + while (new Date().getTime() < now + sleepDuration) { + /* Do nothing */ + } +} (async function() { try { @@ -24,14 +34,16 @@ const authID = '5e0461a96113354249aab7ee'; console.log('charge created:', charge); // eslint-disable-line no-console const capture = await card.captureCharge({ - chargeID: id, + chargeID: charge.id, amount: 10000, }); console.log('charge captured:', capture); // eslint-disable-line no-console + sleepFor(3000); + const refund = await card.createRefund({ - chargeID: id, - externalID: external_id, + chargeID: charge.id, + externalID: charge.external_id, amount: 5000, }); console.log('refund created:', refund); // eslint-disable-line no-console @@ -45,8 +57,8 @@ const authID = '5e0461a96113354249aab7ee'; currency: 'IDR', minOriginalAmount: 25000, maxDiscountAmount: 5000, - startTime: '2022-03-25T00:00:00.000Z', - endTime: '2022-05-25T00:00:00.000Z', + startTime: '2022-01-25T00:00:00.000Z', + endTime: '2023-01-25T00:00:00.000Z', }); // eslint-disable-next-line max-len console.log('promotion created:', promotion); // eslint-disable-line no-console diff --git a/examples/with_async/customer.js b/examples/with_async/customer.js index 535ae8e..085e914 100644 --- a/examples/with_async/customer.js +++ b/examples/with_async/customer.js @@ -31,28 +31,6 @@ const c = new Customer({}); }); // eslint-disable-next-line no-console console.log('retrieved customers', customers); - - customer = await c.updateCustomer({ - id: customer.id, - description: 'customer dummy', - phoneNumber: '+628987654321', - nationality: 'ID', - dateOfBirth: '2000-06-13', - addresses: [ - { - streetLine1: 'jalan raya', - country: 'ID', - city: 'Jakarta', - }, - { - streetLine1: 'jalan raya 2', - country: 'ID', - city: 'Jakarta', - }, - ], - apiVersion: '2020-05-19', - }); - console.log('updated customer', customer); //eslint-disable-line no-console } catch (e) { console.error(e); // eslint-disable-line no-console process.exit(1); diff --git a/examples/with_async/direct_debit.js b/examples/with_async/direct_debit.js index a284d87..c35b9f6 100644 --- a/examples/with_async/direct_debit.js +++ b/examples/with_async/direct_debit.js @@ -15,6 +15,7 @@ const c = new Customer({}); middleName: 'middle', surname: 'surname', addresses: [], + apiVersion: '2020-05-19', }); let tokenization = await dd.initializeTokenization({ diff --git a/examples/with_async/platform.js b/examples/with_async/platform.js index eb50383..5f2d081 100644 --- a/examples/with_async/platform.js +++ b/examples/with_async/platform.js @@ -27,7 +27,7 @@ const p = new Platform({}); const transfer = await p.createTransfer({ reference: `example+${Date.now().toString()}`, amount: 1, - sourceUserID: '5df358652ebad7084a70ac6c', + sourceUserID: '623d3cda7012f7478e9a7e69', destinationUserID: account.user_id, }); diff --git a/examples/with_promises/card.js b/examples/with_promises/card.js index 0dae7d2..96adbb5 100644 --- a/examples/with_promises/card.js +++ b/examples/with_promises/card.js @@ -5,8 +5,18 @@ const card = new Card({}); // These IDs should be obtained using Xendit.js // https://docs.xendit.co/xenpayments/payments-credit-cards-overview/credit-cards-integration-and-testing/collecting-card-details-tokenization/index.html -const tokenID = '5e0461a86113354249aab7ec'; -const authID = '5e0461a96113354249aab7ee'; +// You can generate sample token/authentication data and replace it below +// https://js.xendit.co/test_tokenize.html +// https://js.xendit.co/test_authenticate.html +const tokenID = '6201f056382ab2001b4bc3d6'; +const authID = '6205f8dcca71c0001bc26ae6'; + +function sleepFor(sleepDuration) { + var now = new Date().getTime(); + while (new Date().getTime() < now + sleepDuration) { + /* Do nothing */ + } +} card .createCharge({ @@ -29,6 +39,7 @@ card ) .then(r => { console.log('charge captured:', r); // eslint-disable-line no-console + sleepFor(3000); return r; }) .then(({ id, external_id }) => diff --git a/examples/with_promises/customer.js b/examples/with_promises/customer.js index 2cd0b06..928dbc3 100644 --- a/examples/with_promises/customer.js +++ b/examples/with_promises/customer.js @@ -33,32 +33,6 @@ c.createCustomer({ console.log('retrieved customers', r); // eslint-disable-line no-console return r[0]; }) - .then(r => - c.updateCustomer({ - id: r.id, - description: 'customer dummy', - phoneNumber: '+628987654321', - nationality: 'ID', - dateOfBirth: '2000-06-13', - addresses: [ - { - streetLine1: 'jalan raya', - country: 'ID', - city: 'Jakarta', - }, - { - streetLine1: 'jalan raya 2', - country: 'ID', - city: 'Jakarta', - }, - ], - apiVersion: '2020-05-19', - }), - ) - .then(r => { - console.log('updated customer', r); // eslint-disable-line no-console - return r; - }) .catch(e => { console.error(e); // eslint-disable-line no-console process.exit(1); diff --git a/examples/with_promises/direct_debit.js b/examples/with_promises/direct_debit.js index 7458ee8..539b8c6 100644 --- a/examples/with_promises/direct_debit.js +++ b/examples/with_promises/direct_debit.js @@ -13,6 +13,7 @@ c.createCustomer({ middleName: 'middle', surname: 'surname', addresses: [], + apiVersion: '2020-05-19', }) .then(r => dd.initializeTokenization({ diff --git a/integration_test/card.test.js b/integration_test/card.test.js index 8e2067a..63fbf8c 100644 --- a/integration_test/card.test.js +++ b/integration_test/card.test.js @@ -2,10 +2,10 @@ const x = require('./xendit.test'); const Card = x.Card; const card = new Card({}); - +// 5e046a736113354249aab8bd old charge module.exports = function() { return card - .getCharge({ chargeID: '5e046a736113354249aab8bd' }) + .getCharge({ chargeID: '623d397a360c32001b0aeeda' }) .then(() => card.createPromotion({ referenceId: Date.now().toString(), diff --git a/integration_test/customer.test.js b/integration_test/customer.test.js index f615da7..d1b9a69 100644 --- a/integration_test/customer.test.js +++ b/integration_test/customer.test.js @@ -14,30 +14,10 @@ module.exports = function() { middleName: 'middle', surname: 'surname', addresses: [], + apiVersion: '2020-05-19', }) .then(r => c.getCustomer({ id: r.id })) .then(r => c.getCustomerByReferenceID({ referenceID: r.reference_id })) - .then(r => - c.updateCustomer({ - id: r[0].id, - description: 'customer dummy', - phoneNumber: '+628987654321', - nationality: 'ID', - dateOfBirth: '2000-06-13', - addresses: [ - { - streetLine1: 'jalan raya', - country: 'ID', - city: 'Jakarta', - }, - { - streetLine1: 'jalan raya 2', - country: 'ID', - city: 'Jakarta', - }, - ], - }), - ) .then(() => { // eslint-disable-next-line no-console console.log('Customer integration test done...'); diff --git a/integration_test/direct_debit.test.js b/integration_test/direct_debit.test.js index 59b7cd8..11107f0 100644 --- a/integration_test/direct_debit.test.js +++ b/integration_test/direct_debit.test.js @@ -15,6 +15,7 @@ module.exports = function() { middleName: 'middle', surname: 'surname', addresses: [], + apiVersion: '2020-05-19', }) .then(r => dd.initializeTokenization({ diff --git a/integration_test/index.js b/integration_test/index.js index 2306225..7afb52f 100644 --- a/integration_test/index.js +++ b/integration_test/index.js @@ -8,7 +8,7 @@ Promise.all([ require('./recurring.test')(), require('./balance.test')(), require('./retail_outlet.test')(), - require('./ewallet.test')(), + // require('./ewallet.test')(), require('./qr_code.test')(), require('./platform.test')(), require('./customer.test')(), diff --git a/integration_test/platform.test.js b/integration_test/platform.test.js index fabf5fc..863b4ae 100644 --- a/integration_test/platform.test.js +++ b/integration_test/platform.test.js @@ -12,19 +12,19 @@ module.exports = function() { businessName: `example+${Date.now().toString()}`, }, }) - .then(({ user_id }) => + .then(r => p.setCallbackURL({ - forUserID: user_id, + forUserID: r.user_id, type: 'invoice', url: 'https://httpstat.us/200', }), ) - .then(({ user_id }) => + .then(r => p.createTransfer({ reference: `example+${Date.now().toString()}`, amount: 1, - sourceUserID: '5df358652ebad7084a70ac6c', - destinationUserID: user_id, + sourceUserID: '623d3cda7012f7478e9a7e69', + destinationUserID: r.user_id, }), ) .then(() => diff --git a/package.json b/package.json index bf4ced7..b94ff20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xendit-node", - "version": "1.21.0", + "version": "1.21.1", "description": "NodeJS client for Xendit API", "main": "index.js", "types": "index.d.ts", @@ -10,7 +10,7 @@ "lint": "eslint index.js ./**/*.{js,ts}", "lint:fix": "eslint index.js ./**/*.{js,ts} --fix", "format": "prettier --config .prettierrc --write index.js ./**/*.{js,json,ts}", - "gentoc": "markdown-toc -i README.md", + "gentoc": "markdown-toc -i --bullets=- README.md", "release": "np", "report": "nyc -r text -r lcov npm run test", "coveralls": "cat coverage/lcov.info | coveralls" @@ -35,7 +35,7 @@ "git add" ], "README.md": [ - "markdown-toc -i", + "markdown-toc -i --bullets=-", "git add" ] },