Skip to content

Commit

Permalink
Merge pull request #135 from xendit/feat/support-transaction-api
Browse files Browse the repository at this point in the history
feat/support transaction api
  • Loading branch information
xen-HendryZheng authored Feb 7, 2022
2 parents 8f8c2d5 + d08e48b commit 96920d7
Show file tree
Hide file tree
Showing 17 changed files with 3,939 additions and 2,260 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.13.2
65 changes: 61 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ For PCI compliance to be maintained, tokenization of credit cards info should be
+ [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 (only in dev mode)](#simulate-payment)
+ [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 (only in dev mode)](#simulate-payment-only-in-dev-mode)
+ [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)
Expand All @@ -92,6 +92,9 @@ For PCI compliance to be maintained, tokenization of credit cards info should be
* [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-accounts](#create-sub-accounts)
+ [Set Callback URL](#set-callback-url)
Expand Down Expand Up @@ -883,7 +886,7 @@ ro.updateFixedPaymentCode(data: {
})
```

#### Simulate payment
#### Simulate payment for RO (only in dev mode)

```ts
ro.simulatePayment(data: {
Expand Down Expand Up @@ -939,7 +942,7 @@ q.createCode(data: {
q.getCode(data: { externalID: string });
```

#### Simulate payment (only in dev mode)
#### Simulate payment for QR (only in dev mode)

```ts
q.simulate(data: { externalID: string; amount?: number });
Expand Down Expand Up @@ -1207,6 +1210,60 @@ r.getReport(data: {
})
```
### Transaction Service
Instantiate the Transaction service using a constructor which has been injected with Xendit keys.
```js
const { Transaction } = x;
const transactionSpecificOptions = {};
const t = new Transaction(transactionSpecificOptions);
```
Example: Getting a transaction
```js
t.getTransaction({
id: "txn_123"
})
.then(res => {
console.log('Get Transaction:', res);
})
.catch(e => {
console.error(`Get Transaction Failed with Error: ${e.message}`);
})
```
#### Get Transaction
```ts
t.getTransaction(data: {
id: string;
})
```
#### List Transactions
```ts
t.listTransactions(data: {
types?: Array<string>;
statuses?: Array<string>;
channelCategories?: Array<string>;
referenceId?: string;
productId?: string;
accountIdentifier?: string;
currency?: string;
amount?: number;
limit?: number;
afterId?: string;
beforeId?: string;
createdDateFrom?: Date;
createdDateTo?: Date;
updatedDateFrom?: Date;
updatedDateTo?: Date;
})
```
### XenPlatform Service
Instanitiate Platform service using constructor that has been injected with Xendit keys
Expand Down
32 changes: 32 additions & 0 deletions examples/with_async/transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const x = require('../xendit');

const { Transaction } = x;
const t = new Transaction({});

(async function() {
try {
const listTransactions = await t.listTransactions({
types: ['DISBURSEMENT', 'PAYMENT'],
statuses: ['PENDING', 'SUCCESS'],
channelCategories: ['BANK'],
createdDateFrom: new Date(
new Date().getTime() - 30 * 24 * 60 * 60 * 1000,
),
createdDateTo: new Date(),
});
// eslint-disable-next-line no-console
console.log('list transactions', listTransactions);

/* Will fail if there is no transaction data in the time period */
const getTransaction = await t.getTransaction({
id: listTransactions.data[0].id,
});
// eslint-disable-next-line no-console
console.log('get transaction', getTransaction);
process.exit(0);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
process.exit(1);
}
})();
28 changes: 28 additions & 0 deletions examples/with_promises/transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const x = require('../xendit');

const { Transaction } = x;
const t = new Transaction({});

t.listTransactions({
types: ['DISBURSEMENT', 'PAYMENT'],
statuses: ['PENDING', 'SUCCESS'],
channelCategories: ['BANK'],
createdDateFrom: new Date(new Date().getTime() - 30 * 24 * 60 * 60 * 1000),
createdDateTo: new Date(),
})
.then(res => {
// eslint-disable-next-line no-console
console.log('list transactions:', res);
return res;
})
// will fail if there are no transactions in this time period
.then(res => t.getTransaction({ id: res.data[0].id }))
.then(res => {
// eslint-disable-next-line no-console
console.log('get transaction', res);
return res;
})
.catch(e => {
console.error(e); // eslint-disable-line no-console
process.exit(1);
});
1 change: 1 addition & 0 deletions integration_test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Promise.all([
require('./customer.test')(),
require('./direct_debit.test')(),
require('./report.test')(),
require('./transaction.test')(),
])
.then(() => {
Promise.all([require('./regional_retail_outlet.test')()]).then(() =>
Expand Down
27 changes: 27 additions & 0 deletions integration_test/transaction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const x = require('./xendit.test');

const { Transaction } = x;
const t = new Transaction({});

module.exports = function() {
return t
.listTransactions({
types: ['DISBURSEMENT', 'PAYMENT'],
statuses: ['PENDING', 'SUCCESS'],
channelCategories: ['BANK'],
createdDateFrom: new Date('2022-01-01T00:00:00.000Z'),
createdDateTo: new Date('2022-02-01T00:00:00.000Z'),
})
.then(res => {
t.getTransaction({ id: res.data[0].id });
})
.then(() => {
// eslint-disable-next-line no-console
console.log('Transaction integration test done...');
})
.catch(e => {
throw new Error(
`Transaction integration tests failed with error: ${e.message}`,
);
});
};
Loading

0 comments on commit 96920d7

Please sign in to comment.