android - Razorpay 错误 - {"code":"BAD_REQUEST_ERROR","description":"ay_order_id is not a valid id"}
问题描述
我正在Razorpay
使用PaymentResultWithDataListener
. 实际上我需要order_id
,signature
所以我使用PaymentResultWithDataListener
不使用PaymentResultListener
,因为没有选项可以获取order_id
和signature
。我已经按照这些链接
https://docs.razorpay.com/v1/page/orders#verifying-the-signature
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
。
任何帮助将不胜感激。
解决方案
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/
推荐阅读
- php - Search in PHP and XML
- python - 将 dict 的值与数据帧的两列的值匹配,并将第三列的值替换为 dict 的键
- php - 组合三个字符串(日、月、年)并计算下一个日期(PHP)
- vuetify.js - 缩小 v-card 时保持 v-img 的右侧可见
- java - Android已签名/未签名的两个.apk文件一直在停止
- flutter - 插件设置飞机
- numpy - numpy.lib.stride_tricks 为相同形状的数组产生不同的步幅
- python - 如何找到可以被其他数组的至少一个元素精确划分的 numpy 数组的所有元素?
- java - 使用 Java AWS SDK 在 Ceph 对象网关上创建角色时出现异常
- pagespeed-insights - PageSpeed Insights 与 Core Web Vitals