changing the IP used during a jquery request

I’m working on a payment integration and sadly i don’t have a static IP and my country is banned.

Working from my personal hosting and that IP has been whitelisted but it seems like the initial request to their servers fails.

Read More

Possibly that the ajax request that runs uses my IP adress and not the server one?

The code is something like this:

return jQuery.ajax({
    type: "POST",
    url: serviceUrlCard,
    data: JSON.stringify(x),
    contentType: "application/json",
    dataType: "json"
})

Is it possible to maybe send the “IP” of the server and not mine ?

Related posts

3 comments

  1. If the AJAX request is sending data directly to the payment service then your local computer’s ip address is being used. You need to send the data first to your server through a view that accepts an AJAX request.

    jQuery.ajax({
        type: "POST",
        url: "/charge", // You need a view to handle this on your server
        data: JSON.stringify(x),
        contentType: "application/json",
        dataType: "json"
    }
    

    Then define a view to accept the data and hopefully the payment service you’re integrating has a binding for your language or you can at least interact with their API using a cURL binding.

    function charge ( request ) {
        if ( $request->is_ajax() ) {
            response = payment->api->charge(request->data);
            if ( response ) {
                return json(response);
            }
        }
     }
    
  2. You can instead send a AJAX request to your server and then send the information from your server to there server…

    Some file in your Server will have

    jQuery.ajax({
        type: "POST",
        url: serviceUrlCard,
        data: JSON.stringify(x),
        contentType: "application/json",
        dataType: "json"    
    }
    

    In the same file accept data as post / get, and make a ajax call to this file ..
    I know this is not optimal way of doing , but cannot thing of another ..

  3. Normally, the Ajax request should go back to your server, and then from your server to the external service.

    If this is not an option, and all you need is a fixed IP in a whitelisted country (i.e. US), then you can rent a proxy server for ~2 USD per month.

    You can then modify your Ajax to use this proxy server by using a library such as https://www.ajaxproxy.com/ – and modifying your code as follows:

    ajaxProxy.proxy.url = "http://your proxy";
    ajaxProxy.proxy.credentials.username = "proxy username";
    ajaxProxy.proxy.credentials.password = "proxy password";
    return jQuery.ajax({
        type: "POST",
        url: serviceUrlCard,
        data: JSON.stringify(x),
        headers: ajaxProxy.proxyHeaders(),
        contentType: "application/json",
        dataType: "json"
    })
    

Comments are closed.