Updated 15 December 2016
PayU biz is a payment gateway aggregator who offer electronic payment services to merchant website through its partnerships with various banks and payment instrument companies. With PayU,customers can pay through various options like Credit cards, Debit cards, Net banking, EMI,Cash Cards,Email Invoicing, IVR, Cash on Delivery(COD).
Integration of PayU biz in android application is quiet easy as they provide there own SDK with UI, its on you you can use their UI (Non-Seamless method) or create your own(Seamless method). Here we will integrate the PayU with Non-Seamless method in our Android Application.
Make sure you are registered with PayU biz and have your Merchant key and Salt if not, please get one for your website.
You can get the SDK from here and the Custom Browser from here which is required for the integration. Now when you have these put them as modules in your application and have a dependency to them from your application’s build.gradle as
1 2 |
compile project(':sdkui') compile project(':PayU-release') |
Now whenever you want to make a payment you have to send all the values the SDK need to process your request. You can either get them from server or you can generate them in app by yourself. The earlier one is better as you should never put the Merchant key and Salt in your app for obvious security reasons. but here I am directly giving the values also the mode is STAGING_ENVIRONMENT, while going for release do change itd to PRODUCTION_ENVIRONMENT.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
String key = "gtKFFx",salt = "eCwWELxi", amount = "10",product_info = "MY PRODUCT INFO",firstname = "John", lastname = "Doe",pg = "CC", email = "[email protected]", txnID = "XXX5678",zip = "NNNNN", phone_num = "9754XXXXXX", success_url = "http://mysuccess" ,failure_url = "http://failure"; String UDF =""; // User Defined Fields, you can put any data here. onClickPaymentButton(View v){ Intent intent = new Intent(MainActivity.this, PayUBaseActivity.class); mPaymentParams = new PaymentParams(); payuConfig = new PayuConfig(); mPaymentParams.setKey(key); mPaymentParams.setAmount(amount); mPaymentParams.setProductInfo(product_info); mPaymentParams.setFirstName(firstname); mPaymentParams.setLastName(lastname); mPaymentParams.setPg(pg); mPaymentParams.setEmail(email); mPaymentParams.setTxnId(txnID); mPaymentParams.setZipCode(zip); mPaymentParams.setUdf1(UDF); mPaymentParams.setUdf2(UDF); mPaymentParams.setUdf3(UDF); mPaymentParams.setUdf4(UDF); mPaymentParams.setUdf5(UDF); mPaymentParams.setPhone(phone_num); mPaymentParams.setSurl(success_url); mPaymentParams.setFurl(failure_url); payuConfig.setEnvironment(PayuConstants.MOBILE_STAGING_ENV); //generate hashes or get them from server PayuHashes hashes = getHashesFromServer(); mPaymentParams.setHash(hashes.getPaymentHash()); intent.putExtra(PayuConstants.PAYU_CONFIG, payuConfig); intent.putExtra(PayuConstants.PAYMENT_PARAMS, mPaymentParams); intent.putExtra(PayuConstants.PAYU_HASHES, hashes); startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE); } |
In case needed, the php code for generating hashes is as follows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php $code= key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||SALT; $paymentHash = strtolower(hash('sha512', $code)); $arr['payment_hash'] = $paymentHash; $cmnNameMerchantCodes = 'get_merchant_ibibo_codes'; $merchantCodesHash_str = key.'|' . $cmnNameMerchantCodes . '|default|'.SALT ; $merchantCodesHash = strtolower(hash('sha512', $merchantCodesHash_str)); $arr['get_merchant_ibibo_codes_hash'] = $merchantCodesHash; $cmnMobileSdk = 'vas_for_mobile_sdk'; $mobileSdk_str = key.'|' . $cmnMobileSdk . '|default|'.SALT; $mobileSdk = strtolower(hash('sha512', $mobileSdk_str)); $arr['vas_for_mobile_sdk_hash'] = $mobileSdk; $cmnPaymentRelatedDetailsForMobileSdk1 = 'payment_related_details_for_mobile_sdk'; $detailsForMobileSdk_str1 = key.'|' . $cmnPaymentRelatedDetailsForMobileSdk1 . '|default|'.SALT; $detailsForMobileSdk1 = strtolower(hash('sha512', $detailsForMobileSdk_str1)); $arr['payment_related_details_for_mobile_sdk_hash'] = $detailsForMobileSdk1; ?> |
And you are ready for your test Payment. Be sure the hashes are same on both the ends server and mobile as they are matched at every point.
Source: https://developer.payubiz.in .
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
3 comments
what should i do in this function?