In this era of technology, digital payment services are highly trending. There’s always a need for every business to maintain your online presence, you want to offer to your customers a safe, quick, and easy-to-use payment system which should satisfy both the needs of your customers and your business. There are various types of payment methods which should be convenient to use, and compatible with your platform.
There are a lot of electronic payment modes available through credit cards or debit cards to accept the payments. Then, a need arises for the payment gateway. It’s important while choosing the right payment gateway for your business depends on many factors like the currencies you can accept, the transaction fee, how fast money gets in your merchant account, and the payment methods offerings.
What is a Payment Gateway?
A payment gateway is a merchant service provided by an e-commerce application service provider that authorizes credit card or direct payments processing for e-businesses, online retailers, bricks and clicks, or traditional brick and mortar. Let’s look at some of the benefits of digital payments given below:
- Increase transparency and security
- Increase Convenience & accessibility
- Easily traceable
- 24×7 availability of banking services
- Reduces the fraud in fake currencies
As we have many of the payment gateway service providers available in the marketplace, there are several options available for payment gateway like Paypal, PayUMoney, PaySimple, SecurePay, 2Checkout, etc but among all these, we’ve chosen PayUMoney which is simple and easy to integrate with your website and mobile services.
Let’s move further how can we integrate PayUMoney with Liferay. The following document states the integration of the PayUMoney with your website. PayUMoney supports all modern payment options like debit cards, credit cards, net banking, UPI, EMI option, etc. The payment request is submitting an HTML Form filled with transaction parameters or details.
Step-1:
Front-end (Angular/HTML)
You can directly use the below-mentioned code in Angular/HTML file
There are two URL provided by PayUMoney
- Sandbox for Testing: https://sandboxsecure.payu.in/_payment
- Live: https://secure.payu.in/_payment
[minti_blockquote]
<form ngNoForm id=”payUMoneyForm” action=”https://sandboxsecure.payu.in/_payment” name=”payuform” method=”POST”
onsubmit=”window.location.href = ‘https://sandboxsecure.payu.in/_payment'”>
<input id=”key” type=”text” name=”key” hidden [value]=”dataPayUMoney.key”>
<input id=”txnid” type=”text” name=”txnid” hidden [value]=”dataPayUMoney.txnid”>
<input id=”amount” type=”text” name=”amount” hidden [value]=”dataPayUMoney.amount”>
<input id=”productInfo” type=”text” name=”productInfo” hidden [value]=”dataPayUMoney.productInfo”>
<input id=”firstname” type=”text” name=”firstname” hidden [value]=”dataPayUMoney.firstname”>
<input id=”email” type=”text” name=”email” hidden [value]=”dataPayUMoney.email”>
<input id=”phone” type=”text” name=”phone” hidden [value]=”dataPayUMoney.phone”>
<input type=”text” name=”udf1″ hidden value=”NA”>
<input type=”text” name=”udf2″ hidden value=”NA”>
<input type=”text” name=”udf3″ hidden value=”NA”>
<input type=”text” name=”udf4″ hidden value=”NA”>
<input type=”text” name=”udf5″ hidden value=”NA”>
<input type=”text” name=”udf6″ hidden value=”NA”>
<input type=”text” name=”udf7″ hidden value=”NA”>
<input type=”text” name=”udf8″ hidden value=”NA”>
<input type=”text” name=”udf9″ hidden value=”NA”>
<input type=”text” name=”udf10″ hidden value=”NA”>
<input id=”surl” type=”text” name=”surl” hidden [value]=”dataPayUMoney.surl”>
<input id=”furl” type=”text” name=”furl” hidden [value]=”dataPayUMoney.furl”>
<input id=”hash” type=”text” name=”hash” hidden [value]=”dataPayUMoney.hash”>
<input type=”text” name=”service_provider” hidden value=”payu_paisa”>
<input type=”submit” value=”BOOK APPOINTMENT”>
</form>
[/minti_blockquote]
In the above code snippet, please make sure to maintain the same sequence for every property such as key, txnid, amount and respectively. As above shown the name of input should not be changed for every property.
For those who are using angular can assign the values from the respective “module.ts” files.
Step-2:
Short description of the above all properties:
- Key: Merchant key provides by the PayUMoney in your respective account
- Txnid: transactionId can be generated as per the need
- Amount: Amount to be paid
- Product info: description of what you paid
- First name: name who is paying
- Email: email id of payer
- Phone: phone number of the payer
- Udf1: set value to “NA”
- Udf2: set value to “NA”
- Udf3: set value to “NA”
- Udf4: set value to “NA”
- Udf5: set value to “NA”
- Udf6: set value to “NA”
- Udf7: set value to “NA”
- Udf8: set value to “NA”
- Udf9: set value to “NA”
- Udf10: set value to “NA”
- Surl: success URL, after successful payment did a redirect to surl
- Furl: failure URL, after failing payment is redirected to furl
- Hash: Is a unique string generated with above all parameters
- Service provider: Always set to “payu_paisa”
Except for UDF1 to UDF10 is not mandatory every else parameter is mandatory to use by PayUMoney, Udf1 to Udf10 is dependent on generating the hash string.
Step-3:
Generate hash string for PayUMoney, add the following function into your .java file.
By Liferay Portal, we can get a serviceImpl.java file used to generate hash by API.
Need to maintain the sequence for generating Hash: sha512(key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10|salt) *(SALT will be provided by PayUMoney)
The Hash generated must be set in above HTML form parameter named “hash”
SiteConstant.PIPE_SIGN = “|”, SiteConstant.PAY_U_MONEY_HASH_TYPE = “SHA-512”
[minti_blockquote]@JSONWebService(method = “POST”) public String getHashString() { String hashString = this.key + SiteConstant.PIPE_SIGN + this.transactionId + SiteConstant.PIPE_SIGN + this.amount + SiteConstant.PIPE_SIGN + this.productInfo + SiteConstant.PIPE_SIGN + this.username + SiteConstant.PIPE_SIGN + this.email + SiteConstant.PIPE_SIGN + “NA” + SiteConstant.PIPE_SIGN + “NA” + SiteConstant.PIPE_SIGN + “NA” + SiteConstant.PIPE_SIGN + “NA” + SiteConstant.PIPE_SIGN + “NA” + SiteConstant.PIPE_SIGN + “NA” + SiteConstant.PIPE_SIGN + “NA” + SiteConstant.PIPE_SIGN + “NA” + SiteConstant.PIPE_SIGN + “NA” + SiteConstant.PIPE_SIGN + “NA” + SiteConstant.PIPE_SIGN + CommonUtil.getTelehealthConfiguration().payUMoneySalt(); StringBuilder hash = new StringBuilder(); MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance(SiteConstant.PAY_U_MONEY_HASH_TYPE); messageDigest.update(hashString.getBytes()); byte[] mdbytes = messageDigest.digest(); for (byte hashByte : mdbytes) { hash.append(Integer.toString((hashByte & 0xff) + 0x100, 16).substring(1)); } } catch (NoSuchAlgorithmException e) { LOG.error(e.getMessage(), e); } return hash.toString(); } [/minti_blockquote]
Following are the credentials used for testing only in Sandbox, not in Live
- *PayUMoney Test Card details*
- Card Number : 4012 0010 3714 1112
- Expiry: 05/20
- CVV: 123
Step-4:
Server Side handling Request object after Success/Fail of transaction. In any .java file can use the following method to receive the PayUMoney Response object:
[minti_blockquote]@POST @Path(“/payu/success-webhook”) public void handleWebhookSuccess(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException { _log.info(request); //Bussiness Logic }[/minti_blockquote]
Can handle response object via API call by giving respective API in Surl and Furl. In request Object, you will receive the response from the PayUMoney whether your transaction is successful or fail with short of reason along with transaction details.
Conclusion
So we have discussed the advantages of using PayUMoney and integration with the Liferay portal. At AIMDek Technologies, we offer a full range of Liferay Consulting services that include development, Upgrade & Migration, Performance Tuning, and support. And we’ve successfully delivered the integration of payment gateway for many of our clients in different industry verticals e-commerce, healthcare, etc.
With profound experience and consultative approach, AIMDek acts as your true business partner in your success than just being a service partner. Our dedicated and experienced Liferay developers provide end-to-end support and maintenance for all Liferay implementations resulting in smooth processing of different functionalities of Liferay projects. Reach us out at sales@aimdek.com for projecting a project with us.