首页 > 解决方案 > Razorpay 错误 - {"code":"BAD_REQUEST_ERROR","description":"ay_order_id is not a valid id"}

问题描述

我正在Razorpay使用PaymentResultWithDataListener. 实际上我需要order_idsignature所以我使用PaymentResultWithDataListener不使用PaymentResultListener,因为没有选项可以获取order_idsignature。我已经按照这些链接

https://docs.razorpay.com/v1/page/orders#verifying-the-signature

https://razorpay.com/mobile/

https://github.com/razorpay/razorpay-android-sample-app

但没有得到任何解决方案。

清单文件

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

构建.gradle

api 'com.razorpay:checkout:1.5.4'

我有一个错误

{"code":"BAD_REQUEST_ERROR","description":"ay_order_id is not a valid id"}

我正在尝试使用此代码

public class CheckoutActivity extends AppCompatActivity implements View.OnClickListener, PaymentResultWithDataListener {
    private static final String TAG = CheckoutActivity.class.getSimpleName();

    Button mCheckOutView;

    String OrderId = "";
    String signature = "";
    String order_id = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_payment_method);

        Checkout.preload(getApplicationContext());

        mCheckOutView = findViewById(R.id.check_out);

        mCheckOutView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v == mCheckOutView) {
            startPayment();
        }
    }

    public void startPayment() {
        /*
          You need to pass current activity in order to let Razorpay create CheckoutActivity
         */
        final Activity activity = this;

        final Checkout co = new Checkout();

        try {
            JSONObject options = new JSONObject();
            options.put("name","Test");
            options.put("description", getString(R.string.app_name));
            options.put("key", getString(R.string.api_key));
            options.put("order_id","razorpay_order_id");
            options.put("signature","razorpay_signature");

            options.put("currency", "INR");
            options.put("amount", 100);

            JSONObject preFill = new JSONObject();
            preFill.put("email", "test@gmail.com");
            preFill.put("contact", "9999999999");

            options.put("prefill", preFill);

            JSONObject notesData=new JSONObject();
            notesData.put("Order Id","order123");
            notesData.put("address","Test Address");

            options.put("notes", notesData);

            JSONObject theme=new JSONObject();
            theme.put("color","#738598");
            theme.put("emi_mode",true);

            options.put("theme", theme);

            co.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 s, PaymentData paymentData) {
        String paymentId = paymentData.getPaymentId();
        String signature = paymentData.getSignature();  // got null
        String orderId = paymentData.getOrderId();      // got null
    }

    @Override
    public void onPaymentError(int i, String s, PaymentData paymentData) {
        Log.e(TAG,s);  //error {"code":"BAD_REQUEST_ERROR","description":"ay_order_id is not a valid id"}
    }
}

如果我删除这 2 行,则不会出现此错误。

options.put("order_id","razorpay_order_id");
options.put("signature","razorpay_signature");

但是paymentData.getSignature()并且paymentData.getOrderId()null

任何帮助将不胜感激。

标签: androidrazorpay

解决方案


options.put("order_id","**razorpay_order_id**");

您需要从razorpay Order_ID API生成此 order_id ,只有在此order_id作为 API 的响应之后,您才能顺利处理。从 API 获取此 Order_id 后,将其以值形式发送到上述代码中(代替razorpay_order_id

options.put("signature","razorpay_signature");

这在请求中不是必需的。这将在您的服务器上生成,并在PaymentResultWithDataListener函数中收到响应时使用。在此处阅读官方文档中的签名生成方法:https ://razorpay.com/docs/payment-gateway/android-integration/standard/


推荐阅读