我正在使用Mollie的平台设置捐赠卡。他们为WordPress提供的插件是有限的,因此我利用了它们的API。他们不允许我通过客户端JS发送API密钥,因此我不得不提出服务器代码,以便密钥保持隐藏状态。我之所以使用Appery.io,是因为它是一种非常简单的方法,并且能够实现所需的结果。问题:我不想只为那里托管1个服务器代码而每月支付90美元。我应该如何重新创建以下代码并将其托管在为WP网站提供动力的服务器中?
``
// REST API URL
var url = "https://api.mollie.com/v2/payments";
//Function to encode the generated donation object and be used in the body of the POST request
serialize = function(obj) {
var str = [];
for (var p in obj)
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
}
//Give the following var's the value of the paramenters that the user specified on the url GET requset
var desc = request.get("description");
var amount = request.get("amount");
var currency = request.get("currency");
var redirUrl = request.get("redirectUrl");
//Transform the user's parameters into an object
var parameters = {
"description": desc,
"amount[value]": amount,
"amount[currency]": currency,
"redirectUrl": redirUrl
};
var XHRResponse = XHR2.send("POST", url, {
"headers": {
"Authorization": "Bearer test_MYAPIKEYISHERE",
},
"body": serialize(parameters)
});
Apperyio.response.success(XHRResponse.body, "application/json");
``
答案 0 :(得分:0)
一个选项可能是将此脚本迁移到无服务器平台之一,例如AWS Lambda,IBM Cloud Functions,Microsoft Azure或Google Cloud Functions。所有这些供应商都提供了可能适合您的免费套餐。即使您使用了免费套餐,您也只能在脚本运行时付费。