android 如何优雅的集成 Razorpay

  1. 请在您的应用build.gradle文件中添加以下依赖项:
repositories {   
    mavenCentral()
 }
 dependencies {    
    implementation 'com.razorpay:checkout:1.5.16'
 }

在这里插入图片描述

  1. Checkout并将付款详细信息和选项作为传递JSONObject。确保您添加了order_id在步骤1中生成的(一般是后台生成)
 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", "Razorpay Corp");
            options.put("description", "Demoing Charges");
            //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("order_id", "order_DBJOWzybf0sJbb");//这一部很重要,是后台调用Razorpay的接口生成的,否则支付成功的状态不对

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

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

            options.put("prefill", preFill);

            co.open(activity, options);
        } catch (Exception e) {
            Toast.makeText(activity, "Error in payment: " + e.getMessage(), Toast.LENGTH_SHORT)
                    .show();
            e.printStackTrace();
        }
    }
  1. 回调处理支付状态,处理成功和错误事件
  public class PaymentActivity extends Activity implements PaymentResultListener{
	    @Override
	    public void onPaymentSuccess(String s, PaymentData paymentData) {
	    }
	
	    @Override
	    public void onPaymentError(int i, String s, PaymentData paymentData) {
	
	    }
    }
  1. 混淆
-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

-keepattributes JavascriptInterface
-keepattributes *Annotation*

-dontwarn com.razorpay.**
-keep class com.razorpay.** {*;}

-optimizations !method/inlining/*

-keepclasseswithmembers class * {
  public void onPayment*(...);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值