0

I know this question has been asked before, but none of them have quite matched what I was looking for.

I have some JavaScript which is creating a post request.

var request = new 
var method = 'post';
var url = 'https://api.worldpay.com/v1/orders';

var content = { 
    "paymentMethod":{
        "type":"Card",
        "name":card_name,
        "expiryMonth":card_exp_month,
        "expiryYear":card_exp_year,
        "cardNumber":card_number,
        "cvc":card_cvc,
        "issueNumber":"1"
    }, 
    "orderType": "ECOM", 
    "orderDescription": "coolio-beans", 
    "customerOrderCode" : 123,
    "amount": 1337, 
    "currencyCode": "GBP"
}

request.open(method, url);
request.setRequestHeader("Content-Type", "application/json");   
request.setRequestHeader("Authorization", "T_S_73c02fe7-f9f6-4d07-a594-9d1774181890");
request.send(JSON.stringify(content));

console.log(request.responseText);
}

This is just a test account on WorldPay, so it is safe. I'm assuming I have set the headers and content correctly as it does actually sent. I read one post where it said I should install a plugin, Allow-Control-Allow-Origin: *. This actually works for me. However, it doesn't seem like best practice to have to install plugins. So i tried:

request.setRequsetHeader("Access-Control-Allow-Origin", "*");

But that did not work either.

I understand that this has been answered before, but I cannot seem to find a fix. Any help is greatly appreciated.

N. Sainsbury
  • 137
  • 2
  • 15
  • Do you get any errors or anything? – Bombebak Feb 21 '18 at 09:46
  • @Bombebak — See the title of the question. – Quentin Feb 21 '18 at 09:46
  • https://developer.worldpay.com/jsonapi/docs/code-libraries – Quentin Feb 21 '18 at 09:48
  • If the 'duplicated question' is correct, then why does my setRequestHeader not work? It mentions that adding Access-Control-Allow-Origin : *, should work. When I do that, it does not. – N. Sainsbury Feb 21 '18 at 09:53
  • Access control allow origin are set on the server side not on client side. What's your problem exactly? – John Feb 21 '18 at 10:04
  • @John The problem is that I want to make a request to the URL listed in the question. However, I cannot make the request as I get the error listed above. There must be a way to authorize my website, if that makes sense. – N. Sainsbury Feb 21 '18 at 10:25
  • https://api.worldpay.com/v1/orders Is that your website? If yes when you catch the command you respond with allow origin thing. If no you can't do what you want. Depending what you want to do you may consider using UserScripts – John Feb 21 '18 at 10:27

0 Answers0