From d47b213b7d1e0f1f42c84874077b4633db1c0ff5 Mon Sep 17 00:00:00 2001 From: Eliza Lucas Date: Tue, 22 Mar 2022 16:59:33 -0400 Subject: [PATCH 1/4] add request to error response for apple pay validate --- server-middleware/apiApplePay.ts | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/server-middleware/apiApplePay.ts b/server-middleware/apiApplePay.ts index 8902c40b..c5253f77 100644 --- a/server-middleware/apiApplePay.ts +++ b/server-middleware/apiApplePay.ts @@ -37,28 +37,24 @@ app.post('/validate', (req, res) => { ? payfacMerchantIdentityKey : partnershipMerchantIdentityKey, // key apple }) + const requestData = { + merchantIdentifier: + merchantType === 'PayFac' ? payfacMerchantId : partnershipMerchantId, + domainName, + displayName: DISPLAY_NAME, + } axios - .post( - appleUrl, - { - merchantIdentifier: - merchantType === 'PayFac' - ? payfacMerchantId - : partnershipMerchantId, - domainName, - displayName: DISPLAY_NAME, - }, - { - httpsAgent, - } - ) + .post(appleUrl, requestData, { + httpsAgent, + }) .then((a) => { // return the json received from Apple Pay server unmodified res.send(a.data) }) .catch((a) => { res.send({ - message: a.message, + errorMessage: a.message, + request: requestData, responseStatus: a.response.status, responseData: a.response.data, responseHeaders: a.response.headers, From d2b110f3aa5d8c350a687bb6842b4a010572863e Mon Sep 17 00:00:00 2001 From: Eliza Lucas Date: Tue, 22 Mar 2022 17:50:39 -0400 Subject: [PATCH 2/4] include all fields in return object (for debugging) --- server-middleware/apiApplePay.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/server-middleware/apiApplePay.ts b/server-middleware/apiApplePay.ts index c5253f77..ddc8abbe 100644 --- a/server-middleware/apiApplePay.ts +++ b/server-middleware/apiApplePay.ts @@ -11,6 +11,8 @@ import { payfacMerchantId, } from './applePaySettings' import { apiHostname, domainName } from './serverEnv' +import { encoding } from 'openpgp' +import getCheckSum = encoding.armor.getCheckSum const app = express() const DISPLAY_NAME = 'Circle Apple Pay' @@ -25,17 +27,19 @@ app.post('/validate', (req, res) => { req.on('data', (data) => { // data is in byte array so first transform it to string and then parse it to object, and then take it's property appleUrl const { appleUrl, merchantType } = JSON.parse(data.toString()) + const cert = + merchantType === 'PayFac' + ? payfacMerchantIdentityCertificate + : partnershipMerchantIdentityCertificate // pem apple cert + const key = + merchantType === 'PayFac' + ? payfacMerchantIdentityKey + : partnershipMerchantIdentityKey const httpsAgent = new https.Agent({ rejectUnauthorized: false, - cert: - merchantType === 'PayFac' - ? payfacMerchantIdentityCertificate - : partnershipMerchantIdentityCertificate, // pem apple cert - key: - merchantType === 'PayFac' - ? payfacMerchantIdentityKey - : partnershipMerchantIdentityKey, // key apple + cert, + key, }) const requestData = { merchantIdentifier: @@ -55,9 +59,14 @@ app.post('/validate', (req, res) => { res.send({ errorMessage: a.message, request: requestData, + merchantType, responseStatus: a.response.status, responseData: a.response.data, responseHeaders: a.response.headers, + checksumCert: getCheckSum(cert), + checksumKey: getCheckSum(key), + appleUrl, + displayName: DISPLAY_NAME, }) }) }) From 2a06027689354f83efd06c80d9097e8fc90cbcd6 Mon Sep 17 00:00:00 2001 From: Eliza Lucas Date: Tue, 22 Mar 2022 18:13:35 -0400 Subject: [PATCH 3/4] updated response object --- server-middleware/apiApplePay.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server-middleware/apiApplePay.ts b/server-middleware/apiApplePay.ts index ddc8abbe..455887c4 100644 --- a/server-middleware/apiApplePay.ts +++ b/server-middleware/apiApplePay.ts @@ -11,8 +11,6 @@ import { payfacMerchantId, } from './applePaySettings' import { apiHostname, domainName } from './serverEnv' -import { encoding } from 'openpgp' -import getCheckSum = encoding.armor.getCheckSum const app = express() const DISPLAY_NAME = 'Circle Apple Pay' @@ -63,8 +61,6 @@ app.post('/validate', (req, res) => { responseStatus: a.response.status, responseData: a.response.data, responseHeaders: a.response.headers, - checksumCert: getCheckSum(cert), - checksumKey: getCheckSum(key), appleUrl, displayName: DISPLAY_NAME, }) From 8cd2753bfcab2ed9e8daac156999e8d6695ef9b3 Mon Sep 17 00:00:00 2001 From: Eliza Lucas Date: Tue, 22 Mar 2022 18:15:25 -0400 Subject: [PATCH 4/4] add domain name --- server-middleware/apiApplePay.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server-middleware/apiApplePay.ts b/server-middleware/apiApplePay.ts index 455887c4..e4ed3a80 100644 --- a/server-middleware/apiApplePay.ts +++ b/server-middleware/apiApplePay.ts @@ -63,6 +63,7 @@ app.post('/validate', (req, res) => { responseHeaders: a.response.headers, appleUrl, displayName: DISPLAY_NAME, + domainName, }) }) })