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

Razor Pay callback methods are not invoked in background

我已经在我的 Android 应用程序中实施了 Razor Pay 支付网关。 debit/credit 卡一切正常。

我遇到 UPI 付款问题。实际上,对于 UPI 付款,用户必须访问 UPI 应用程序才能付款。一切都适用于 UPI,但唯一的问题是,如果付款成功或不成功,则不会调用回调方法,除非我再次访问该应用程序。

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

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

这是代码片段:

开通支付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。

Link: https://razorpay.com/docs/webhooks/