{"id":35679,"date":"2016-06-15T17:30:27","date_gmt":"2016-06-15T12:00:27","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=35679"},"modified":"2016-08-24T15:48:22","modified_gmt":"2016-08-24T10:18:22","slug":"payu-payment-gateway-android-integration","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/payu-payment-gateway-android-integration\/","title":{"rendered":"PayU Payment Gateway : Android Integration"},"content":{"rendered":"<h1><strong>About PayU India<\/strong><\/h1>\n<p>Gurgaon-based PayU India Internet Pvt. Ltd. \u00a0offers online payment solutions to websites and mobiles apps.\u00a0PayU offers electronic payment services to merchant website through its partnerships with various banks and payment instrument companies.<\/p>\n<p>PayU India started in October 2011 and claims to be the number one payments company in the e-commerce category in the country. It is currently serving more than 8,500 businesses in India, up from 5,000 merchants in November 2013. Its clientele includes companies such as BookMyShow, Snapdeal, Micromax, HUDA water board, Amity University, Religare Insurance,\u00a0Goibibo and redBus.<\/p>\n<p>Before going ahead with your integration please download the sample app source code provided by the PayU from <a href=\"https:\/\/github.com\/payu-intrepos\/Android-SDK-Sample-App\">here<\/a>, run it\u00a0and play with it. It will help you understand different classes in their sdk you need to use and parameters setting while creating payment requests.<\/p>\n<h1><strong>Payment Methods available with PayU<\/strong><\/h1>\n<p>Using PayU customers can make electronic payments through a variety of modes which are mentioned below:<\/p>\n<ul>\n<li>Credit Card<\/li>\n<li>Debit Card<\/li>\n<li>Online Net Banking Account<\/li>\n<li>EMI Payment<\/li>\n<li>Cash Card<\/li>\n<li>Email Invoicing<\/li>\n<li>IVR<\/li>\n<li>Cash on Delivery(COD)<\/li>\n<\/ul>\n<h1><strong>Payment Process Flow<\/strong><\/h1>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-35683\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/06\/payu_process.png\" alt=\"payu_process\" width=\"751\" height=\"414\" \/><\/p>\n<h1><strong>Android\u00a0Integration<\/strong><\/h1>\n<p>This post shows the integration of PayU with your\u00a0<a title=\"android app development services\" href=\"http:\/\/www.tothenew.com\/mobile-android-application-development-services\">android application<\/a>. Before proceeding further with this blog,\u00a0make sure that you must already have installed and configured:<\/p>\n<ul>\n<li style=\"padding-left: 30px;\">Java JDK version 1.6 or greater<\/li>\n<li style=\"padding-left: 30px;\">Android SDK<\/li>\n<li style=\"padding-left: 30px;\">A Git client<\/li>\n<li style=\"padding-left: 30px;\">Android Studio \/ Eclipse<\/li>\n<li style=\"padding-left: 30px;\">All PayU PG Prerequisites (Key, Salt)<\/li>\n<\/ul>\n<p>PayU provides the following two types of solutions using their SDK:<\/p>\n<ul>\n<li><strong><a href=\"https:\/\/github.com\/payu-intrepos\/Documentations\/wiki\/6.-Android-SDK-Integration#21-non-seamless-using-sdks-inbuilt-ui\"><em>Non-Seamless<\/em><\/a>:<\/strong> In case you decide to not build your own UI, you are free to use this module<\/li>\n<li><strong><a href=\"https:\/\/github.com\/payu-intrepos\/Documentations\/wiki\/6.-Android-SDK-Integration#22-seamless-using-your-own-ui\"><em>Seamless<\/em><\/a>:<\/strong> In this case you need to build your own UI to collect user banking information for example credit card number, CVV etc.<\/li>\n<\/ul>\n<h2><strong>Non-Seamless Integration: Using SDK\u2019s Inbuilt UI<\/strong><\/h2>\n<ul>\n<li>Get all the required parameters<\/li>\n<li>Create an object of <code>PaymentParams<\/code>, put all the obtained parameters in it by using its default set methods and <code>setHash<\/code> to paymentHash\n<pre><code>PaymentParams mPaymentParams = new PaymentParams();\r\nmPaymentParams.setKey(\u201cgtKFFx\u201d);\r\nmPaymentParams.setAmount(\u201c15.0\u201d);\r\nmPaymentParams.setProductInfo(\u201cTshirt\u201d);\r\nmPaymentParams.setFirstName(\u201cGuru\u201d);\r\nmPaymentParams.setEmail(\u201cguru@gmail.com\u201d);\r\nmPaymentParams.setTxnId(\u201c0123479543689\u201d);\r\nmPaymentParams.setSurl(\u201chttps:\/\/payu.herokuapp.com\/success\u201d);\r\nmPaymentParams.setFurl(\u201chttps:\/\/payu.herokuapp.com\/failure\");\r\nmPaymentParams.setUdf1(\u201cudf1l\u201d);\r\nmPaymentParams.setUdf2(\u201cudf2\u201d);\r\nmPaymentParams.setUdf3(\u201cudf3\u201d);\r\nmPaymentParams.setUdf4(\u201cudf4\u201d);\r\nmPaymentParams.setUdf5(\u201cudf5\u201d);\r\n\r\nmPaymentParams.setHash(\"your payment hash\");\r\n<\/code><\/pre>\n<blockquote>\n<ul>\n<li>You don&#8217;t need to set udf1-5 in case you are not using them<\/li>\n<li>Email and Firstname can be empty strings &#8220;&#8221; if you don&#8217;t want to use them<\/li>\n<li>For store user card feature<br \/>\n<code>mPaymentParams.setUserCredentials(\"your_key:user_id\")<\/code>, you need to pass user_credentials here<\/li>\n<li>For offers <code>mPaymentParams.setOfferKey(\"your_offer_key\")<\/code><\/li>\n<li>For any other payment default param (like phone and others)<code>mPaymentParams.setPhone(\"your_number\")<\/code><\/li>\n<\/ul>\n<\/blockquote>\n<\/li>\n<li>Get the required hashes by using your own server. Create an object of class <code>PayuHashes<\/code> and set the corresponding hashes using the default set methods provided\n<pre><code>mPaymentParams.setHash(payuHashes.getPaymentHash());\r\n<\/code><\/pre>\n<\/li>\n<li>Create a new intent pointing to <code>PayUBaseActivity<\/code> and do the following:\n<pre><code>intent.putExtra(PayuConstants.ENV, PayuConstants.PRODUCTION_ENV);  \r\nintent.putExtra(PayuConstants.PAYMENT_DEFAULT_PARAMS, mPaymentParams);  \r\nintent.putExtra(PayuConstants.PAYU_HASHES, payuHashes);\r\n<\/code><\/pre>\n<\/li>\n<li>To enable one-click payment\n<pre><code>\/\/ Enable one click with MOBILE as storage option for hash\r\nintent.putExtra(PayuConstants.STORE_ONE_CLICK_HASH,PayuConstants.STORE_ONE_CLICK_HASH_MOBILE);\r\nOR\r\n\/\/ Enable once click with MERCHANT SERVER as storage option for hash\r\nintent.putExtra(PayuConstants.STORE_ONE_CLICK_HASH,PayuConstants.STORE_ONE_CLICK_HASH_SERVER);\r\nOR\r\n\/\/ DISABLE one click payment\r\nintent.putExtra(PayuConstants.STORE_ONE_CLICK_HASH,PayuConstants.STORE_ONE_CLICK_HASH_NONE);\r\n<\/code><\/pre>\n<\/li>\n<li>Start the activity and let PayU SDK take care of the rest<br \/>\n<code>startActivity(intent);<\/code><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h1><strong>Seamless Integration: Using your own UI<\/strong><\/h1>\n<p>In seamless kind of integration, we will only discuss the example of Credit Card and Net Banking transactions. Though you can integrate Cash Cards, Store Cards, one-click Payment Cards and PayU Money payments using this technique.<\/p>\n<h1><strong>Seamless Credit \/ Debit card Payment Integration<\/strong><\/h1>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-35733\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/06\/credit_card_own_ui.png\" alt=\"credit_card_own_ui\" width=\"389\" height=\"691\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Create an object of PaymentParams, put all the obtained parameters in it by using its default set methods in the same way as you will create for the non-seamless style and setHash to paymentHash<\/p>\n<ul>\n<li>Set the following additional properties to <code>mPaymentParams<\/code>\n<pre><code>mPaymentParams.setCardNumber(cardNumber);\r\nmPaymentParams.setCardName(cardName);\r\nmPaymentParams.setNameOnCard(cardName);\r\nmPaymentParams.setExpiryMonth(expiryMonth);\/\/ MM\r\nmPaymentParams.setExpiryYear(expiryYear);\/\/ YYYY  \r\nmPaymentParams.setCvv(cvv);\r\n<\/code><\/pre>\n<\/li>\n<li>To enable one-click payment\n<pre><code>\/\/ To store one click payment hash pass 1\r\nmPaymentParams.setEnableOneClickPayment(1);\r\n\/\/ Otherwise pass 0, OR don't call the method at all\r\nmPaymentParams.setEnableOneClickPayment(0);\r\n<\/code><\/pre>\n<\/li>\n<li>Create a\u00a0<code>PaymentPostParams<\/code> object with the above data of the type <code>PostData<\/code>. Make sure to set the environment (test or prod), create intent and launch the PaymentsActivity activity\n<pre><code>PostData postData = new PaymentPostParams(mPaymentParams, PayuConstants.CC).getPaymentPostParams();\r\nif (postData.getCode() == PayuErrors.NO_ERROR) {\r\n  \/\/ launch webview\r\n  PayuConfig payuConfig = new PayuConfig();\r\n  payuConfig.setEnvironment(PayuConstants.PRODUCTION_ENV);\r\n  payuConfig.setData(postData.getResult());\r\n  Intent intent = new Intent(this,PaymentsActivity.class);\r\n  intent.putExtra(PayuConstants.PAYU_CONFIG,payuConfig);\r\n  startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE);\r\n} else {\r\n  \/\/ something went wrong\r\n  Toast.makeText(this,postData.getResult(), Toast.LENGTH_LONG).show();\r\n}<\/code><\/pre>\n<p>At this point you should be able to see Bank\u2019s 3D Secure page like the following for HDFC Bank<\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-35736\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/06\/pay_processing_request.png\" alt=\"pay_processing_request\" width=\"330\" height=\"587\" \/><\/p>\n<ul>\n<li><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-35735\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/06\/bank_page.png\" alt=\"bank_page\" width=\"365\" height=\"649\" \/><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h1><strong>Seamless Net Banking Integration<\/strong><\/h1>\n<p>&nbsp;<\/p>\n<ul>\n<li>Create an object of <code>PaymentParams<\/code>, put all the obtained parameters in it by using its default set methods in the same way as you will create for the non-seamless style and <code>setHash<\/code> to paymentHash<\/li>\n<li>Get the bankCode (String) of selected bank from your spinner\/list view adapter and add it to the <code>mPaymentParams<\/code> created above\n<pre><code>mPaymentParams.setBankCode(bankCode);\r\n<\/code><\/pre>\n<\/li>\n<li>Create <code>PaymentPostParams<\/code> object of the type PostData and start the\u00a0PaymentsActivity\n<pre><code>PostData postData = new PaymentPostParams(mPaymentParams, PayuConstants.NB).getPaymentPostParams();\r\nif (postData.getCode() == PayuErrors.NO_ERROR){\r\n  \/\/ launch webview\r\n  PayuConfig payuConfig = new PayuConfig();\r\n  payuConfig.setEnvironment(PayuConstants.PRODUCTION_ENV);\r\n  payuConfig.setData(postData.getResult());\r\n  Intent intent = new Intent(this,PaymentsActivity.class); \r\n  intent.putExtra(PayuConstants.PAYU_CONFIG,payuConfig); \r\n  startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE);\r\n} else {\r\n  \/\/ something went wrong\r\n  Toast.makeText(this,postData.getResult(), Toast.LENGTH_LONG).show(); \r\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>To start off the integration process, you would be provided a test setup by PayU where you would be given a test merchant account and test credit card credentials to have a first-hand experience of the overall transaction flow. Here, you can make transaction request in our sample app (pointed to the testing server). Next step is to integrate the SDK code with your app. Once the testing is complete, you should be ready to point your app to the PayU production server for some real transactions.<\/p>\n<h2>Test credentials<\/h2>\n<p>Start with test key and salt (which targets the test server) to enable extra logs. Please use the following test account (only on test environment):<\/p>\n<ul>\n<li>key: gtKFFx<\/li>\n<li>Salt: eCwWELxi<\/li>\n<\/ul>\n<h2>Dummy test card<\/h2>\n<p>This will succeed only in\u00a0the\u00a0test environment. Also, all other cards (real or not) will fail on the\u00a0test server.<\/p>\n<ul>\n<li>Name on Card: Any name<\/li>\n<li>Card Number: 5123456789012346<\/li>\n<li>CVV: 123<\/li>\n<li>Expiry Date: 05\/2017<\/li>\n<\/ul>\n<p>Its all about getting started with PayU integration in Android App.\u00a0Best of Luck for you integration!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>About PayU India Gurgaon-based PayU India Internet Pvt. Ltd. \u00a0offers online payment solutions to websites and mobiles apps.\u00a0PayU offers electronic payment services to merchant website through its partnerships with various banks and payment instrument companies. PayU India started in October 2011 and claims to be the number one payments company in the e-commerce category in [&hellip;]<\/p>\n","protected":false},"author":150,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":42},"categories":[518],"tags":[3487],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/35679"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/150"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=35679"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/35679\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=35679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=35679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=35679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}