i have successful created ajax code to send data to external api (payment gateway).
The problem is how can i get data after they pay and show "waiting payment" button before display "Thank you" container ?
Below is my code for ajax post data :
$.ajax({
url: 'creating_bill.php',
data: {
paid_amount : JSON.stringify(jumlah_semua),
email : emel,
mobile : telefon,
name : nama
},
type: "POST",
dataType: "json",
success: function (data) {
confirm('Terima Kasih ! Sila buat pembayaran dengan segera.');
console.log(data)
window.open(data.url, '_blank');
setTimeout(function()
{
window.location = 'index.html';
},10000);
},
async: false,
error: function(data) {
handleRequestError(data);
}
})
}
Here is the api doc link for payment completion : BillPlz doc
But i have no idea how its work. How can i post the data and get the data back in same ajax request ?
Basically my system process is like this.
- Customer visit the website
- Customer add item that they want to buy
- Customer confirm the item and decide to pay via payment gateway
- Customer redirect to payment gateway invoice to pay
- System show 'waiting' message at my website while waiting customer to complete their payment.
- After customer complete their payment then they will back to my website and see "thank you for your payment" message.
The code i post above is a code that i use to post customer data to payment gateway api. My problem now is, how can i show "waiting" message while waiting for customer to complete their payment and show "Thank you" message when payment has been completed.
</div>