Crazy Horse
asked on
redirect and post data to payment gateway after database insert.
I am submitting cart data to a database by using php/ajax/jQuery. If the database insert is successful, I then need to post data from the same page to the payment gateway. The instructions from the payment gateway are to post the form to their provided url with some hidden fields. But I can't figure out how to store the data in the database at the same time or just before posting to that url. So far, in my jQuery I have posted to a method which inserts the data to the database. On my .done callback, I want to then after successful database entry post the data to the payment gateway url but not sure how to achieve this as I actually need the page to redirect to the url.
$(document).ready(function () {
$('.placeOrder').on('click', function (e) {
e.preventDefault();
var form = $( '#checkoutForm' ).serialize();
$.ajax({
url: url + '/CartAjax/TempOrder',
type: 'POST',
dataType: 'json',
data: form,
beforeSend: function () {
$('.placeOrder').prop('disabled', true);
$('.spinner').show();
$('.ordertext').hide();
},
})
.done(function (data) {
if (!data.success) {
$( '.alert-danger' ).append(data.message).fadeIn();
} else {
// redirect to payment gateway and post the necessary hidden fields to that redirect page.
}
})
.fail(function (jqXHR, textStatus, errorThrown) {
$('.alert-danger').append("Something went wrong. Try again later.");
console.log(textStatus + ': ' + errorThrown);
console.warn(jqXHR.responseText);
});
});
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Chris, that was surprisingly easy and seemed to work. I thought it was going to be more complicated than that! :)
Easy is good :)
like:
Open in new window