gpt4 book ai didi

java - Razorpay 回调方法不会在后台调用

转载 作者:行者123 更新时间:2023-12-01 16:36:59 25 4
gpt4 key购买 nike

我已经在我的 Android 应用程序中实现了 Razor Pay 支付网关。借记卡/信用卡一切正常。

我遇到了 UPI 付款问题。实际上,对于UPI支付,用户必须访问UPI应用程序才能进行支付。 UPI 也一切正常,但唯一的问题是,无论支付成功与否,回调方法都不会被调用,除非我再次访问该应用程序。

这对我来说是个大问题,因为有时如果用户通过 UPI 应用程序付款并且不再打开该应用程序,我很难将付款条目保存在数据库中。

每次调用成功回调方法时,我都会在数据库中保存条目。当应用程序在后台但未关闭时,如何调用 success 方法。

这是代码 fragment :

要打开付款 Activity :

  Intent intent = new Intent(context, PaymentActivity.class);
intent.putExtra("orderId", order_id);
intent.putExtra("totalAmount", String.valueOf(totalPrice));
intent.putExtra("email", email);
intent.putExtra("phoneNo", phone_number);
intent.putExtra("userId", user_id);
startActivityForResult(intent, 2);
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);

调用 Razor 付费 Activity :

final Activity activity = this;
price = Double.parseDouble(total_price);
double paisa_double = price * 100;
int paisa_int = (int) paisa_double;
final Checkout checkout = new Checkout();
checkout.setKeyID(getResources().getString(R.string.razor_pay_key));
try {
JSONObject options = new JSONObject();
options.put("name", "Razorpay Corp");
options.put("description", "Order No: " + order_id);
options.put("order_id", razor_id);
//You can omit the image option to fetch the image from dashboard
options.put("image", "https://s3.amazonaws.com/rzp-mobile/images/rzp.png");
options.put("currency", "INR");
options.put("amount", String.valueOf(paisa_int));
//options.put("amount", "100");
JSONObject preFill = new JSONObject();
preFill.put("email", email);
preFill.put("contact", phone_no);
options.put("prefill", preFill);
JSONObject notes = new JSONObject();
notes.put("notes", order_id);
options.put("notes", notes);
checkout.open(activity, options);
} catch (Exception e) {
Toast.makeText(activity, "Error in payment: " + e.getMessage(), Toast.LENGTH_SHORT)
.show();
e.printStackTrace();
}

这些是回调方法:

  @Override
public void onPaymentSuccess(String razorpayPaymentID, PaymentData paymentData) {
try {
//Toast.makeText(this, "Payment Successful: " + razorpayPaymentID, Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra("razorpayPaymentID", razorpayPaymentID);
setResult(2, intent);
finish();

} catch (Exception e) {
Log.e(TAG, "Exception in onPaymentSuccess", e);
}
}

@Override
public void onPaymentError(int code, String response, PaymentData paymentData) {
try {
Toast.makeText(this, "Payment failed: " + code + " " + response, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.e(TAG, "Exception in onPaymentError", e);
}
}

最佳答案

在后端代码中使用 Razor pay web hooks 来解决上述问题。

链接: https://razorpay.com/docs/webhooks/

关于java - Razorpay 回调方法不会在后台调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61932926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com