-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·49 lines (47 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const request = require('request')
const xml = require('xml')
const Parser = require('xml2js').Parser
const url = 'https://sec.paymentexpress.com/pxpost.aspx'
const uat = 'https://uat.paymentexpress.com/pxpost.aspx'
module.exports = {
submit: (details, callback) => {
const dpsData = {
Txn: [
{ PostUsername: details.user },
{ PostPassword: details.password },
{ CardHolderName: details.card.name },
{ CardNumber: details.card.number },
{ Amount: details.amount },
{ DateExpiry: details.card.expiry },
{ Cvc2: details.card.cvc2 },
{ InputCurrency: details.currency || 'NZD' },
{ TxnType: details.transactionType || 'Purchase' },
{ TxnId: details.transactionId || '' },
{ MerchentReference: details.reference },
],
}
request(
{
uri: process.env.NODE_ENV === 'production' ? url : uat,
method: 'POST',
body: xml(dpsData),
},
(err, res, body) => {
process.nextTick(() => {
if (err) {
process.nextTick(() => {
callback(err)
})
} else {
const parser = new Parser({ explicitArray: false })
process.nextTick(() => {
parser.parseString(body, (error, result) => {
callback(error, result.Txn.Transaction)
})
})
}
})
}
)
},
}