【问题标题】:"code":"BAD_REQUEST_ERROR","description":"The id provided does not exist" RazorPay error while integrating to android"code":"BAD_REQUEST_ERROR","description":"提供的 id 不存在" RazorPay 集成到 android 时出错
【发布时间】:2020-05-25 10:31:39
【问题描述】:

我在将 RazorPay 与 android 集成时遇到上述错误。

这是我的代码

我从 Razorpay 官方文档中复制了以下代码。 而我提供的 KeyId 是针对测试环境的。 甚至我也尝试过重新生成 KeyId,但一次又一次地得到同样的错误。

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_paytm_try);
        Checkout.preload(getApplicationContext());

        payBtn = findViewById(R.id.payBtn);
        payBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                startPayment();

            }
        });


    }

    public void startPayment() {

        /**
         * Instantiate Checkout
         */
        Checkout checkout = new Checkout();

        checkout.setKeyID("rzp_test_R2oCIrTkyM4LqA");

        /**
         * Set your logo here
         */
        checkout.setImage(R.drawable.gps);

        /**
         * Reference to current activity
         */
        final Activity activity = this;

        /**
         * Pass your payment options to the Razorpay Checkout as a JSONObject
         */
        try {
            JSONObject options = new JSONObject();

            /**
             * Merchant Name
             * eg: ACME Corp || HasGeek etc.
             */
            options.put("name", "Praveen");

            /**
             * Description can be anything
             * eg: Reference No. #123123 - This order number is passed by you for your internal reference. This is not the `razorpay_order_id`.
             *     Invoice Payment
             *     etc.
             */
            options.put("description", "Reference No. #123456");
            //options.put("image", "https://s3.amazonaws.com/rzp-mobile/images/rzp.png");
            options.put("order_id", "154546548");
            options.put("currency", "INR");

            /**
             * Amount is always passed in currency subunits
             * Eg: "500" = INR 5.00
             */
            options.put("amount", "500");

            checkout.open(activity, options);
        } catch(Exception e) {
            Log.e(TAG, "Error in starting Razorpay Checkout", e);
        }
    }

    @Override
    public void onPaymentSuccess(String s) {

        Toast.makeText(getApplicationContext(),"Payment Successful",Toast.LENGTH_LONG).show();

    }

    @Override
    public void onPaymentError(int i, String s) {

        Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
        Log.d(TAG, "onPaymentError: "+s);

    }

我已将以下代码添加到清单文件中

  <meta-data
            android:name="com.razorpay.ApiKey"
            android:value="rzp_test_R2oCIrTkyM4LqA"
            >

        </meta-data>

【问题讨论】:

    标签: android razorpay


    【解决方案1】:

    我认为 Razorpay 有问题,

    只需删除以下行(订单 ID)

    options.put("order_id", "154546548");
    

    【讨论】:

    • 现在工作,但我们需要那个订单 ID 对吗?
    • 实际上不需要,您可以创建本地共享首选项或通过成功页面的意图发送订单 id 值,类似这样
    • dummy order_id 不工作,但有效的订单 ID 工作,谢谢!
    猜你喜欢
    • 2019-08-03
    • 2020-03-20
    • 2021-02-24
    • 2020-08-21
    • 2020-12-12
    • 2018-12-03
    • 2021-01-18
    • 2021-06-08
    • 2020-08-18
    相关资源
    最近更新 更多