- Please add the following dependencies to your application build.gradle file:
repositories {
mavenCentral()
}
dependencies {
implementation 'com. Razorpay: checkout: 1.5.16'
}
Copy the code
- Checkout and pass the payment details and options as a JSONObject. Make sure you add the order_id generated in Step 1 (usually in the background)
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"); // This is an important part of Razorpay. It is generated by the interface that calls Razorpay. Otherwise, the status of payment is not correct."currency"."INR");
options.put("amount"."100");
options.put("payment_capture"."1");
JSONObject preFill = new JSONObject();
preFill.put("email"."[email protected]");
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(); }}Copy the code
- Callbacks handle payment status and handle success and error events
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) {
}
}
Copy the code
- confusion
-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*(...) ; }Copy the code