Skip to content

Commit

Permalink
Add the request to error response for apple pay validate (#201)
Browse files Browse the repository at this point in the history
* add request to error response for apple pay validate

* include all fields in return object (for debugging)

* updated response object

* add domain name
  • Loading branch information
elizalucas authored Mar 22, 2022
1 parent a2a042b commit da2d1f7
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions server-middleware/apiApplePay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,45 @@ 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:
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,
merchantType,
responseStatus: a.response.status,
responseData: a.response.data,
responseHeaders: a.response.headers,
appleUrl,
displayName: DISPLAY_NAME,
domainName,
})
})
})
Expand Down

0 comments on commit da2d1f7

Please sign in to comment.