xendit-node
Advanced tools
Comparing version 1.19.5 to 1.19.6
@@ -29,2 +29,14 @@ const x = require('../xendit'); | ||
await ro.simulatePayment({ | ||
retailOutletName: 'ALFAMART', | ||
paymentCode: updatedPmCode.payment_code, | ||
transferAmount: 12000, | ||
}); | ||
// eslint-disable-next-line no-console | ||
console.log('simulated payment:', updatedPmCode); | ||
const paymentsByCodeId = await ro.getPaymentsByFixedPaymentCodeId({ id }); | ||
// eslint-disable-next-line no-console | ||
console.log('payments by fixed payment code ID:', paymentsByCodeId); | ||
process.exit(0); | ||
@@ -31,0 +43,0 @@ } catch (e) { |
@@ -34,2 +34,23 @@ const x = require('../xendit'); | ||
}) | ||
.then(({ id, payment_code }) => | ||
Promise.all([ | ||
id, | ||
ro.simulatePayment({ | ||
retailOutletName: 'ALFAMART', | ||
paymentCode: payment_code, | ||
transferAmount: 12000, | ||
}), | ||
]), | ||
) | ||
.then(r => { | ||
// eslint-disable-next-line no-console | ||
console.log('simulated payment:', r); | ||
return r; | ||
}) | ||
.then(([id]) => ro.getPaymentsByFixedPaymentCodeId({ id })) | ||
.then(r => { | ||
// eslint-disable-next-line no-console | ||
console.log('payments by fixed payment code ID:', r); | ||
return r; | ||
}) | ||
.catch(e => { | ||
@@ -36,0 +57,0 @@ console.error(e); // eslint-disable-line no-console |
@@ -16,2 +16,13 @@ const x = require('./xendit.test'); | ||
.then(({ id }) => ro.updateFixedPaymentCode({ id: id, expectedAmt: 12000 })) | ||
.then(({ id, payment_code }) => | ||
Promise.all([ | ||
id, | ||
ro.simulatePayment({ | ||
retailOutletName: 'ALFAMART', | ||
paymentCode: payment_code, | ||
transferAmount: 12000, | ||
}), | ||
]), | ||
) | ||
.then(([id]) => ro.getPaymentsByFixedPaymentCodeId({ id })) | ||
.then(() => { | ||
@@ -18,0 +29,0 @@ // eslint-disable-next-line no-console |
{ | ||
"name": "xendit-node", | ||
"version": "1.19.5", | ||
"version": "1.19.6", | ||
"description": "NodeJS client for Xendit API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -68,3 +68,5 @@ # Xendit API Node.js Client | ||
+ [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) | ||
* [QR Code Services](#qr-code-services) | ||
@@ -848,2 +850,8 @@ + [Create code](#create-code) | ||
#### Get payments by fixed payment code ID | ||
```ts | ||
ro.getPaymentsByFixedPaymentCodeId(data: { id: string }) | ||
``` | ||
#### Update fixed payment code | ||
@@ -860,2 +868,12 @@ | ||
#### Simulate payment | ||
```ts | ||
ro.simulatePayment(data: { | ||
retailOutletName: string; | ||
paymentCode: string; | ||
transferAmount: number; | ||
}) | ||
``` | ||
### QR Code Services | ||
@@ -862,0 +880,0 @@ |
@@ -24,2 +24,8 @@ import { XenditOptions } from '../xendit_opts'; | ||
getFixedPaymentCode(data: { id: string }): Promise<object>; | ||
getPaymentsByFixedPaymentCodeId(data: { id: string }): Promise<object>; | ||
simulatePayment(data: { | ||
retailOutletName: string; | ||
paymentCode: string; | ||
transferAmount: number; | ||
}): Promise<object>; | ||
}; |
@@ -93,2 +93,42 @@ const { promWithJsErr, Validate, fetchWithHTTPErr, Auth } = require('../utils'); | ||
RetailOutlet.prototype.getPaymentsByFixedPaymentCodeId = function(data) { | ||
return promWithJsErr((resolve, reject) => { | ||
Validate.rejectOnMissingFields(['id'], data, reject); | ||
fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}/payments`, { | ||
method: 'GET', | ||
headers: { | ||
Authorization: Auth.basicAuthHeader(this.opts.secretKey), | ||
}, | ||
}) | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
}; | ||
RetailOutlet.prototype.simulatePayment = function(data) { | ||
return promWithJsErr((resolve, reject) => { | ||
Validate.rejectOnMissingFields( | ||
['retailOutletName', 'paymentCode', 'transferAmount'], | ||
data, | ||
reject, | ||
); | ||
fetchWithHTTPErr(`${this.API_ENDPOINT}/simulate_payment`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: Auth.basicAuthHeader(this.opts.secretKey), | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
retail_outlet_name: data.retailOutletName, | ||
payment_code: data.paymentCode, | ||
transfer_amount: data.transferAmount, | ||
}), | ||
}) | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
}; | ||
module.exports = RetailOutlet; |
198131
5437
1284