-
Notifications
You must be signed in to change notification settings - Fork 2
/
ph_tokenization_handler.js
41 lines (34 loc) · 1.14 KB
/
ph_tokenization_handler.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
import responseJson from './responseJson';
import getPaymentApi from './phapi';
import { buildResponse } from './util';
export const tokenization = async (event, context, callback) => {
return executeTokenization(event);
};
const transactionTokenResponse = (token) => token ? { token } : {};
const transactionCardResponse = (card) => {
if (!card) return {}
return {
card: {
cardType: card.type,
partialPan: card.partial_pan,
expireMonth: card.expire_month,
expireYear: card.expire_year
}
}
}
const executeTokenization = (event) => new Promise((resolve, reject) => {
let paymentAPI = getPaymentApi();
const transactionId = event.pathParameters.transactionId;
paymentAPI
.tokenization(transactionId)
.then((response) => {
let result = buildResponse(response,
transactionTokenResponse(response.card_token),
transactionCardResponse(response.card));
resolve(responseJson(200, result));
})
.catch((error) => {
console.error(error);
reject(error);
});
});