Использование Apple Pay JavaScript/NodeJS в Azure

Я использовал следующий пример в качестве рабочего примера для получения транзакций JavaScript Apple Pay через сервер NodeJS в Azure. Существует целый процесс, который вы должны пройти для получения сертификатов, когда у вас есть учетная запись разработчика, но, надеюсь, это кому-то поможет.

Это выполняется в среде службы приложений Azure (ASE).

/*
Using Apple Pay JavaScript/NodeJS on Azure  

*/

const express = require("express");
const bodyParser = require("body-parser");
const fs = require("fs");
const https = require("https");
const http = require("http");
const request = require("request");
var port = process.env.PORT || 1337;


console.log("port: "+port);
/**
* IMPORTANT
* Change these paths to your own SSL and Apple Pay certificates,
* with the appropriate merchant identifier and domain
* See the README for more information.
*/
const APPLE_PAY_CERTIFICATE_PATH = "./certificates/apple_pay.pem";
const SSL_CERTIFICATE_PATH = "./certificates/merchant_id.pem";
const SSL_KEY_PATH = "./certificates/merchant_id_local.pem";
const MERCHANT_IDENTIFIER = "merchant.com.yourcompany";
const MERCHANT_DOMAIN = "yourdomain.azurewebsites.net";

console.log("==>> server starting.........");

try {
  fs.accessSync(APPLE_PAY_CERTIFICATE_PATH);
  fs.accessSync(SSL_CERTIFICATE_PATH);
  fs.accessSync(SSL_KEY_PATH);
} catch (e) {
    console.log("==>> error:.."+e);
  throw new Error('You must generate your SSL and Apple Pay certificates before running this example.');
}

  console.log("==>> getting certs:..");
const sslKey = fs.readFileSync(SSL_KEY_PATH);
const sslCert = fs.readFileSync(SSL_CERTIFICATE_PATH);
const applePayCert = fs.readFileSync(APPLE_PAY_CERTIFICATE_PATH);


/**
* Set up our server and static page hosting
*/
console.log("==>> setting up server ");
const app = express();
app.use(express.static('public',{ dotfiles: 'allow' }));
app.use(bodyParser.json());


console.log("==>> setting up post ");

app.post('/postToServer', function (req, res) {
    
    console.log("==>> inside  postToServer");
    console.log(req.body.toCS);
     if (!req.body.url) return res.sendStatus(400);
});

app.post('/getApplePaySession', function (req, res) {
console.log("==>> inside  getApplePaySession post req:");
 // We need a URL from the client to call
 if (!req.body.url) return res.sendStatus(400);

 // We must provide our Apple Pay certificate, merchant ID, domain name, and display name
 const options = {
  url: req.body.url,
  cert: sslKey,
  key: sslKey,
  method: 'post',
  body: {
   merchantIdentifier: MERCHANT_IDENTIFIER,
   domainName: MERCHANT_DOMAIN,
   displayName: 'My Store',
  },
  json: true,
 }

 // Send the request to the Apple Pay server and return the response to the client
 request(options, function(err, response, body) {
     console.log("==>> sending to apple pay server body: ");
    console.log(body);
    console.log(response);
  if (err) {
   console.log('Error generating Apple Pay session!');
   console.log(err, response, body);
   res.status(500).send(body);
  }
  res.send(body);
 });
});

process.on('uncaughtException', function(err){
 console.log("error: "+err.stack);
});

app.get('/.well-known/apple-developer-merchantid-domain-association', function(req, res) {
    console.log("==>>1 __dirname"+__dirname);
  res.sendfile(__dirname + '/.well-known/apple-developer-merchantid-domain-association');
  
});

app.get('/.well-known/apple-app-site-association', function(req, res) {
    console.log("==>>2 __dirname"+__dirname);
  res.sendfile(__dirname + '/.well-known/apple-app-site-association.file');
});

http.createServer(app).listen(port);

1 ответ

это ошибка:

      cert: sslKey,
key: sslKey

cer: certificate_sandbox.pem
ключ: certificate_sandbox.key

Другие вопросы по тегам