Reputation: 380
I am using php to make a GET Request. After the response it must redirect me to response URL, but I do not know to do it. The response is in json format, like this:
{"orderId":"308fea18-9288-460e-8c24-e2******","formUrl":"https://test.bank.com/payment/merchants/payment.html?mdOrder=308fea18-e2c68d9d3a2e&language=en"}
This response is after success payment request and redirects me to a page with card information.
Here is form request:
<form name="PaymentForm" action="https://test.bank.com/payment/register.do" method="GET" id="formPayment">
<input type="hidden" name="userName" id="userName" value="api">
<input type="hidden" name="password" id="password" value="api2">
<input type="hidden" name="orderNumber" id="orderNumber" value="00000116">
<input type="hidden" name="amount" id="amount" value="1000">
<input type="hidden" name="description" id="description" value="description">
<input type="hidden" name="language" id="language" value="en">
<input type="hidden" name="pageView" id="pageView" value="DESKTOP">
<input type="hidden" name="clientId" id="clientId" value="2">
//a button for payment confirmation
<input value="Изпрати" type="submit" id="buttonPayment" class="btn btn-lg btn-primary">
</form>
How to redirect users automatically after success request?
I searched through many links but somehow could not solve my problem.
Now i tried to send data with ajax, but i catch other error :
Access to XMLHttpRequest at 'https://test.bank.com/payment/register.do?[object%20FormData]' from origin 'http://site.domain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
here is a ajax:
$( "#buttonPayment" ).click(function() {
var modal = $(this);
$.ajax({
url: "https://ecomtest.dskbank.bg/payment/rest/register.do",
crossDomain: true,
method: "GET",
data: new FormData($('#formPayment')[0]), // The form with the file inputs.
processData: false, // Using FormData, no need to process data.
contentType: false, // Using FormData, no need to process data.
success: function (data) {
console.log(data)
},
error: function () {
console.log("error");
}
});
});
Upvotes: 1
Views: 1311
Reputation: 3590
You have to decode first your json object and then get the url.
<?php
$json = '{"orderId":"308fea18-9288-460e-8c24-e2******","formUrl":"https://test.bank.com/payment/merchants/payment.html?mdOrder=308fea18-e2c68d9d3a2e&language=en"}';
$json_decoded = json_decode($json); //Decode the json object
$url = $json_decoded->formUrl; //Get the url
header("Location: $url"); //Pass the url into redirection
Upvotes: 1