[英]How to get the failure response on clicking Razorpay payment failure button?
I am using Razorpay test mode to integrate into my website with the codes that I am using I can console the data when I am clicking on the success button but I want to console the data when there is a failure too because I need to update my status column in the database.我正在使用 Razorpay 测试模式将我正在使用的代码集成到我的网站中 我可以在单击成功按钮时控制数据,但我也想在失败时控制数据,因为我需要更新我的数据库中的状态列。 So how can I do that below here is what I have tried so far?
那么我该怎么做呢?这是我迄今为止尝试过的?
$.ajax({
url:'details-action.php?form-product-test',
type:'post',
data:new FormData(this),
contentType:false,
processData:false,
success:function(result_data){
if(result_data == 'success'){
var options = {
"key": "key",
"amount": amt1*100,
"currency": "INR",
"name": "Test",
"description": "Order Details",
"image": "",
"handler": function (response){
var payment_id = response.razorpay_payment_id;
console.log(response);
$.ajax({
type:'post',
url:'form-action.php?paymentsucc',
data:{payment_id:payment_id},
success:function(result){
console.log(result);
alert('Your order is successfully done');
}
});
}
};
var rzp1 = new Razorpay(options);
rzp1.open();
} else {
alert(result_data);
}
},
error:function(result_data){}
});
So when I am getting success everything is working fine and also I am getting the razorpay_payment_id.因此,当我获得成功时,一切正常,而且我也获得了 razorpay_payment_id。 I want to run another ajax when there is a failure or the customer is clicking on the failure button so that I can update into my database but the problem is I am not getting the razorpay_payment_id or console.log is not showing anything.
当出现故障或客户单击故障按钮时,我想运行另一个 ajax,以便我可以更新到我的数据库,但问题是我没有得到 razorpay_payment_id 或 console.log 没有显示任何内容。
You can try this i think you are asking for this or you may follow this link to know more https://razorpay.com/docs/payment-gateway/web-integration/standard/你可以试试这个我想你问这个或者你可以点击这个链接了解更多https://razorpay.com/docs/payment-gateway/web-integration/standard/
var rzp1 = new Razorpay(options); rzp1.on('payment.failed', function (response){ alert(response.error.code); alert(response.error.description); alert(response.error.source); alert(response.error.step); alert(response.error.reason); alert(response.error.metadata.order_id); alert(response.error.metadata.payment_id); }); document.getElementById('form-submit').onclick = function(e){ rzp1.open(); e.preventDefault(); }
Just change your ajax to sth like this to catch the error只需将您的 ajax 更改为这样即可捕获错误
$.ajax({
type:'post',
url:'form-action.php?paymentsucc',
data:{payment_id:payment_id},
success: function(result) {
console.log(result);
alert('Your order is successfully done');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus);
alert("Error: " + errorThrown);
}
});
I am still searching for solutions.我仍在寻找解决方案。 The answer marked as accepted does not give a way to store data on the database.
标记为已接受的答案并未提供在数据库中存储数据的方法。 I tried ajax call in payment.failed method but it is not working.
我在 payment.failed 方法中尝试了 ajax 调用,但它不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.