简体   繁体   中英

Migrating Server Code from appery.io to WordPress

I'm setting up a donation card using Mollie's platform. The plugin they provide for WordPress is limited so I did it making use of their API. They don't allow me to send the API key through client side JS so I had to come up with Server Code so the key would stay hidden. I used Appery.io because it was a pretty straight-forward approach I and was able to accomplish the wanted result. The problem: I don't want do pay 90 bucks a month just to have 1 server code hosted in there. How should I proceed to recreate the following code and host it in a server that powers a WP website?

``

// 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");

``

One option could be to migrate this script to one of the Serverless platforms such as AWS Lambda, IBM Cloud Functions, Microsoft Azure or Google Cloud Functions. All these vendors offer a free tier that might work for you. Even if you do go over the free tier, you only pay when the script runs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM