【问题标题】:Razorpay Error - {"code":"BAD_REQUEST_ERROR","description":"ay_order_id is not a valid id"}Razorpay 错误 - {"code":"BAD_REQUEST_ERROR","description":"ay_order_id is not a valid id"}
【发布时间】:2019-08-03 16:51:07
【问题描述】:

我正在用PaymentResultWithDataListener 实现Razorpay。实际上我需要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" />

build.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"}
    }
}

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

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

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

任何帮助将不胜感激。

【问题讨论】:

  • 你的身份证是什么?
  • @ManojPerumarath 是什么意思?
  • razorpay_order_id 是价值 & order_id 是关键
  • 其实这些key & value是由razerpay支持团队提供的
  • {“code”:“BAD_REQUEST_ERROR”,“description”:“ay_order_id is not a valid id”}

标签: android razorpay


【解决方案1】:
options.put("order_id","**razorpay_order_id**");

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

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

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

【讨论】:

    【解决方案2】:

    根据官方文档,当您开始结帐时,当商家的后端使用 RazorPay 后端开始下单时,您会收到order_id。 见图表here`。

    至于签名,根据文档,这不是您放置的东西,而是来自服务器响应的东西,您必须最终验证。检查this

    【讨论】:

      猜你喜欢
      • 2020-05-25
      • 2012-09-11
      • 1970-01-01
      • 2022-06-21
      • 2017-03-03
      • 2018-03-29
      • 2011-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多