Skip to content

Commit

Permalink
PP-12853 Add the charset in Content-Type header for Apple Pay
Browse files Browse the repository at this point in the history
With the previous PR[1], we have made some progress in communicating with
Apple Pay via Axios and HttpsProxyAgent and we have tested that the
validation is initiated correctly but then fails with the following message
from Apple: `Apple Pay Merchant ID not valid`.

See screenshot in the new PR[2].

With this change, we are now adding the charset to the Content-Type header in
the post request, in case that is what is expected by Apple Pay, and we are
also adding the status to the error log, to have a little bit more
information back.

Further information in JIRA[3].

[1]
#3885

[2]
#3886

[3]
https://payments-platform.atlassian.net/browse/PP-12853
  • Loading branch information
marcotranchino committed Aug 2, 2024
1 parent ee386b6 commit c3cc7fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,20 @@ module.exports = async (req, res) => {
}

const alternativeOptions = {
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json; charset=utf-8' },
httpsAgent: proxyAgent
}

try {
const response = await axios.post(url, data, alternativeOptions)

logger.info('Apple Pay session successfully generated via axios')
logger.info('Apple Pay session successfully generated via axios and https proxy agent')
res.status(200).send(response.data)
} catch (error) {
logger.info('Error generating Apple Pay session', {
...getLoggingFields(req),
error: error.message
error: error.message,
status: error.response ? error.response.status : 'No status'
})
logger.info('Apple Pay session via axios and https proxy agent failed', 'Apple Pay Error')
res.status(500).send('Apple Pay Error')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('Validate with Apple the merchant is legitimate', () => {
initiativeContext: merchantDomain
}),
sinon.match({
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json; charset=utf-8' },
httpsAgent: sinon.match.instanceOf(HttpsProxyAgent)
})
)
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('Validate with Apple the merchant is legitimate', () => {
initiativeContext: merchantDomain
}),
sinon.match({
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json; charset=utf-8' },
httpsAgent: sinon.match.instanceOf(HttpsProxyAgent)
})
)
Expand Down Expand Up @@ -197,7 +197,7 @@ describe('Validate with Apple the merchant is legitimate', () => {
initiativeContext: merchantDomain
}),
sinon.match({
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json; charset=utf-8' },
httpsAgent: sinon.match.instanceOf(HttpsProxyAgent)
})
)
Expand Down

0 comments on commit c3cc7fe

Please sign in to comment.