A simple & Easiest way to integrate PayU Biz Payment Gateway with your Android Application
- Add Maven repository and compile dependency in build.gradle file.
dependencies { compile 'com.sasidhar.smaps.payu:payu:0.0.5' }
- Add Internt Permissions in your Android Application Manifest file
<uses-permission android:name="android.permission.INTERNET" />
- Create an object for PayuConfig Class and Configure your environement (test/dev)
PayuConfig payuConfig = new PayuConfig();
// for testing payuConfig.setEnvironment(PayuConstants.MOBILE_DEV_ENV);
// for production payuConfig.setEnvironment(PayuConstants.PRODUCTION_ENV);
Create an object for PaymentParams and obtain all the required parameters
-
PaymentParams paymentParams = new PaymentParams(); paymentParams.setKey("merchant_key"); // Get Merchant Key from PayU Biz Merchant Account paymentParams.setFirstName("name"); // User Name paymentParams.setEmail("email"); // User Email Address paymentParams.setPhone("phone"); // User Mobile Number paymentParams.setProductInfo("productinfo"); // Product info paymentParams.setAmount("amount"); // Amout paymentParams.setTxnId(""); // Transaction ID paymentParams.setSurl("SURL"); // Success URL paymentParams.setFurl("FURL"); // Failure URL
// User defined fields are optional (pass empty string)
paymentParams.setUdf1(""); paymentParams.setUdf2(""); paymentParams.setUdf3(""); paymentParams.setUdf4(""); paymentParams.setUdf5("");
- Generate HASH by with PaymentParams object & SALT and add it to PaymentParams object.
PayuHashes payuHashes = Utils.generateHashFromSDK(paymentParams, "SALT"); // Get SALT from PayU Biz Merchant Account paymentParams.setHash(payuHashes.getPaymentHash());
Note: It is recommanded to generate HASH from your own server instea of here.
- Create an Intent to a PaymentActivity and pass PayuConfig, PaymentParams and PayuHashes objects that we are create in the above steps as intent extras.
Intent intent = new Intent(this, PaymentActivity.class); intent.putExtra(PayuConstants.PAYU_CONFIG, payuConfig); intent.putExtra(PayuConstants.PAYMENT_PARAMS, paymentParams); intent.putExtra(PayuConstants.PAYU_HASHES, payuHashes);
- Start Activity for Result
startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE);
- Handle response at onActivityResult
if (requestCode == PayuConstants.PAYU_REQUEST_CODE) { switch (resultCode) { case RESULT_OK: Toast.makeText(MainActivity.this, "Payment Success.", Toast.LENGTH_SHORT).show(); break;
case RESULT_CANCELED: Toast.makeText(MainActivity.this, "Payment Cancelled | Failed.", Toast.LENGTH_SHORT).show(); break; }
}
- Optionally you can alos configure Payment Methods to enable or disable by setting boolean value (true/false) before calling startActivityForResult
PaymentOptions.DebitCardEnabled = true; PaymentOptions.CreditCardEnabled = true; PaymentOptions.isNetBankingEnabled = true; PaymentOptions.isEMIEnabled = false; PaymentOptions.isPayUMoneyWalletEnabled = true; PaymentOptions.isCashCardEnabled = false;