mirror of
https://github.com/KevinMidboe/planetposen.git
synced 2025-10-29 09:40:31 +00:00
Can handle apple pay requests with local certificate files.
This commit is contained in:
46
server/controllers/applePay.js
Normal file
46
server/controllers/applePay.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const fetch = require('node-fetch')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const https = require('https')
|
||||
|
||||
const validateWithApple = (appleUrl) => {
|
||||
const httpsAgent = new https.Agent({
|
||||
rejectUnauthorized: false,
|
||||
cert: fs.readFileSync(path.join(__dirname, '../assets/certificate_sandbox.pem')),
|
||||
key: fs.readFileSync(path.join(__dirname, '../assets/certificate_sandbox.key'))
|
||||
})
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
merchantIdentifier: 'merchant.com.planetposen.sandbox',
|
||||
domainName: 'planet.kevinmidboe.com',
|
||||
displayName: 'Planetposen'
|
||||
}),
|
||||
agent: httpsAgent
|
||||
}
|
||||
|
||||
return fetch(appleUrl, options)
|
||||
.then(resp => resp.json())
|
||||
}
|
||||
|
||||
const validateSession = async (req, res) => {
|
||||
const { validationURL } = req.body;
|
||||
|
||||
const appleData = await validateWithApple(validationURL)
|
||||
return res.json(appleData)
|
||||
}
|
||||
|
||||
const pay = (req, res) => {
|
||||
const { payment } = req.body;
|
||||
|
||||
const { token } = payment;
|
||||
console.log('payment data: ', token);
|
||||
|
||||
res.send({ approved: true })
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateSession,
|
||||
pay
|
||||
}
|
||||
Reference in New Issue
Block a user