-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from xendit/RegionalRetailOutlet
RegionalRetailOutlet
- Loading branch information
Showing
13 changed files
with
253 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const x = require('../xendit'); | ||
|
||
const RegionalRetailOutlet = x.RegionalRetailOutlet; | ||
const ro = new RegionalRetailOutlet({}); | ||
|
||
(async function() { | ||
try { | ||
const pmCode = await ro.createPaymentCode({ | ||
referenceId: 'test_dharma_61', | ||
channelCode: 'CEBUANA', | ||
customerName: 'Dharma', | ||
amount: 50, | ||
currency: 'PHP', | ||
market: 'PH' | ||
}); | ||
// eslint-disable-next-line no-console | ||
console.log('fixed payment code created:', pmCode); | ||
|
||
const { id } = pmCode; | ||
const retrievedPmCode = await ro.getPaymentCode({ id }); | ||
// eslint-disable-next-line no-console | ||
console.log('fixed payment code details:', retrievedPmCode); | ||
|
||
const updatedPmCode = await ro.updatePaymentCode({ | ||
id, | ||
customerName: "DharmaLain", | ||
}); | ||
// eslint-disable-next-line no-console | ||
console.log('updated payment code details:', updatedPmCode); | ||
|
||
process.exit(0); | ||
} catch (e) { | ||
console.error(e); // eslint-disable-line no-console | ||
process.exit(1); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const x = require('../xendit'); | ||
|
||
const RegionalRetailOutlet = x.RegionalRetailOutlet; | ||
const ro = new RegionalRetailOutlet(); | ||
|
||
ro.createPaymentCode({ | ||
referenceId: 'test_dharma_4', | ||
channelCode: 'CEBUANA', | ||
customerName: 'Dharma', | ||
amount: 50, | ||
currency: 'PHP', | ||
market: 'PH' | ||
}) | ||
.then(r => { | ||
// eslint-disable-next-line no-console | ||
console.log('fixed payment code created:', r); | ||
return r; | ||
}) | ||
.then(({ id }) => ro.getPaymentCode({ id })) | ||
.then(r => { | ||
// eslint-disable-next-line no-console | ||
console.log('fixed payment code details:', r); | ||
return r; | ||
}) | ||
.then(({ id }) => { | ||
return ro.updatePaymentCode({ | ||
id, | ||
customerName: "DharmaLain", | ||
}); | ||
}) | ||
.then(r => { | ||
// eslint-disable-next-line no-console | ||
console.log('updated payment code details:', r); | ||
return r; | ||
}) | ||
.catch(e => { | ||
console.error(e); // eslint-disable-line no-console | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const x = require('./xendit_ph.test'); | ||
|
||
const RegionalRetailOutlet = x.RegionalRetailOutlet; | ||
const ro = new RegionalRetailOutlet({}); | ||
|
||
const dynamicReferenceId = Math.floor((Math.random() * 9999) + 1) | ||
|
||
module.exports = function() { | ||
return ro | ||
.createPaymentCode({ | ||
referenceId: `test_dharma_${dynamicReferenceId}`, | ||
channelCode: 'CEBUANA', | ||
customerName: 'Dharma', | ||
amount: 50, | ||
currency: 'PHP', | ||
market: 'PH' | ||
}) | ||
.then(({ id }) => ro.getPaymentCode({ id })) | ||
.then(({ id }) => ro.updatePaymentCode({ id: id, customerName: "DharmaLain" })) | ||
.then(() => { | ||
// eslint-disable-next-line no-console | ||
console.log('Regional Retail outlet integration test done...'); | ||
}) | ||
.catch(e => { | ||
throw new Error(`Regional RO integration tests failed with error: ${e.message}`); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// For actual usage, this should be require('xendit-node') | ||
const Xendit = require('../src/xendit'); | ||
const dotenv = require('dotenv'); | ||
|
||
dotenv.config(); | ||
|
||
const xph = new Xendit({ | ||
secretKey: process.env.SECRET_KEY_PH, | ||
xenditURL: process.env.XENDIT_URL, | ||
}); | ||
|
||
module.exports = xph; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import RegionalRetailOutletService from './regional_retail_outlet'; | ||
|
||
export { RegionalRetailOutletService }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const RegionalRetailOutletService = require('./regional_retail_outlet'); | ||
|
||
module.exports = { RegionalRetailOutletService }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { XenditOptions } from '../xendit_opts'; | ||
|
||
export = class RegionalRetailOutlet { | ||
constructor({}); | ||
static _constructorWithInjectedXenditOpts: ( | ||
opts: XenditOptions, | ||
) => typeof RetailOutlet; | ||
createPaymentCode(data: { | ||
reference_id: string; | ||
channel_code: string; | ||
amount: number; | ||
currency: number; | ||
customer_name: string; | ||
market: string; | ||
payment_code?: string; | ||
expires_at?: Date; | ||
is_single_use?: boolean; | ||
desciption?: string; | ||
metadata?: object[]; | ||
}): Promise<object>; | ||
updateFixedPaymentCode(data: { | ||
id: string; | ||
name?: string; | ||
expectedAmt?: number; | ||
expirationDate?: Date; | ||
}): Promise<object>; | ||
getFixedPaymentCode(data: { id: string }): Promise<object>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
const { promWithJsErr, Validate, fetchWithHTTPErr, Auth } = require('../utils'); | ||
|
||
const REGIONAL_RETAIL_OUTLET_PATH = '/payment_codes'; | ||
|
||
function RegionalRetailOutlet(options) { | ||
let aggOpts = options; | ||
if ( | ||
RegionalRetailOutlet._injectedOpts && | ||
Object.keys(RegionalRetailOutlet._injectedOpts).length > 0 | ||
) { | ||
aggOpts = Object.assign({}, options, RegionalRetailOutlet._injectedOpts); | ||
} | ||
|
||
this.opts = aggOpts; | ||
this.API_ENDPOINT = this.opts.xenditURL + REGIONAL_RETAIL_OUTLET_PATH; | ||
} | ||
|
||
RegionalRetailOutlet._injectedOpts = {}; | ||
RegionalRetailOutlet._constructorWithInjectedXenditOpts = function(options) { | ||
RegionalRetailOutlet._injectedOpts = options; | ||
return RegionalRetailOutlet; | ||
}; | ||
|
||
RegionalRetailOutlet.prototype.createPaymentCode = function(data) { | ||
return promWithJsErr((resolve, reject) => { | ||
Validate.rejectOnMissingFields( | ||
['referenceId', 'channelCode', 'amount', 'currency', 'customerName', 'market'], | ||
data, | ||
reject, | ||
); | ||
|
||
fetchWithHTTPErr(`${this.API_ENDPOINT}`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: Auth.basicAuthHeader(this.opts.secretKey), | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
reference_id: data.referenceId, | ||
channel_code: data.channelCode, | ||
amount: data.amount, | ||
currency: data.currency, | ||
customer_name: data.customerName, | ||
market: data.market, | ||
payment_code: data.paymentCode, | ||
description: data.description, | ||
metadata: data.metadata, | ||
expires_at: data.expiresAt | ||
? data.expiresAt.toISOString() | ||
: undefined, | ||
is_single_use: data.isSingleUse, | ||
}), | ||
}) | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
}; | ||
|
||
RegionalRetailOutlet.prototype.updatePaymentCode = function(data) { | ||
return promWithJsErr((resolve, reject) => { | ||
Validate.rejectOnMissingFields(['id'], data, reject); | ||
|
||
fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}`, { | ||
method: 'PATCH', | ||
headers: { | ||
Authorization: Auth.basicAuthHeader(this.opts.secretKey), | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
amount: data.amount, | ||
currency: data.amount, | ||
customer_name: data.customerName | ||
}), | ||
}) | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
}; | ||
|
||
RegionalRetailOutlet.prototype.getPaymentCode = function(data) { | ||
return promWithJsErr((resolve, reject) => { | ||
Validate.rejectOnMissingFields(['id'], data, reject); | ||
|
||
fetchWithHTTPErr(`${this.API_ENDPOINT}/${data.id}`, { | ||
method: 'GET', | ||
headers: { | ||
Authorization: Auth.basicAuthHeader(this.opts.secretKey), | ||
}, | ||
}) | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
}; | ||
|
||
module.exports = RegionalRetailOutlet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters