Ipay Web Payments Integration Document
Ipay Web Payments Integration Document
Integration Document
Version 1.0
Table of Contents
1. Introduction ............................................................................................................................ 2
2. How iPay Payment Gateway Works........................................................................................ 2
3. Prerequisites ........................................................................................................................... 3
4. Getting Started........................................................................................................................ 3
5. Setting up Development Environment ................................................................................... 5
5.1 Add Checkout HTML form to your website...................................................................... 5
5.2 Capture the Transaction................................................................................................... 7
5.3 Verifying Payment Status ................................................................................................. 8
6. Card Payments Test Details .................................................................................................... 9
7. Live Implementation ............................................................................................................. 10
Appendix ....................................................................................................................................... 11
1. Introduction
The usage of E-Commerce has increased exponentially in the recent past. The iPay Payment
Gateway solution looks to empower the growth of all businesses with a website by providing a
payment processing platform to ride the E-Commerce wave. The iPay Payment Gateway can be
integrated to your website easily with minimum technical effort by following the simple instructions
in this document. The successful integration to the iPay Payment Gateway will allow businesses to
accept payments from their customers via Payment Cards, via iPay and other LankaQR compliant apps
in the country.
This document will provide an easy to follow, step-by-step guide to the technical integration work
required to enable this feature to the merchant e-commerce website in the iPay Sandbox
environment. Upon successful integration in the Sandbox environment, the business will be required
to contact the iPay Merchant Management Team to complete the iPay merchant registration and
enable this product in the live environment. The steps followed in the Sandbox environment will
simply have to be replicated in the live environment after successful registration.
Once the payment is processed, iPay notifies your call-back API about the payment status as a
server callback. Here, iPay generates a checksum and sends it with response parameters to ensure
integrity and you can use those response parameters & checksum to verify and update your system
accordingly.
1. You as the web merchant should have your own custom e-commerce web application as you need
code level integration.
2. You as the web merchant should register as a Merchant in the iPay Sandbox by providing the
required information to obtain the Web payment token.
3. You should have the iPay sandbox mobile application or any other Lanka QR compliant payment
application connected with the Lanka Pay sandbox. (You can download the iPay sandbox mobile
application from the Admin Portal after registration)
4. Getting Started
1. Go to the iPay Sandbox website using the following URL.
Sandbox: https://sandbox.ipay.lk/ipayMerchantApp/enroll/businessType
2. Register as a merchant and log in to the Sandbox Merchant admin portal by using the username
and password approved at registration.
3. Go to the “Merchant Settings” option on the user side menu and click on “Development
Settings”.
Then the page will display the screen shown below. Enable Development Settings by clicking on
the checkbox shown below.
Then Merchant should provide value for the “Secret” option and this secret is used to generate the
Checksum.
Merchant should provide a “Call back API URL” and this will be used to notify the Payment Status.
Note: This IP address or domain based HTTPS URL must be publicly accessible.
5. Select the payment schemes you want to enable for your website.
6. Enable Additional Security (Optional) – Merchant can enable additional security for the checkout
HTML form to ensure the integrity of Order ID and Transaction Amount. Here, the Merchant needs to
generate a checksum using the below given combination of parameters and send it to the checkout
HTML form.
Message = IPG Integration Token + Order ID + Transaction Amount
NOTE: Please refer to Section 5.3 for additional information on checksum generation
7. The IPG Integration Token will be automatically generated when clicked on the “Generate Token”
button which will be specific for the merchant. The merchant should use this IPG Integration Token
when setting up iPay Payment checkout API.
iPay provides HTML form-based POST API to integrate iPay with your website. Here you need to add
an HTML form to your website and submit the required parameters to iPay Payment Gateway interface.
After submitting the form, the customer will be redirected to the iPay Payment Gateway interface
securely.
Action URLs
Environment URL
Sandbox https://sandbox.ipay.lk/ipg/checkout
Live https://ipay.lk/ipg/checkout
Max
Parameter Name Description Mandatory?
Length
The IPG Integration token generated in the
merchantWebToken N/A YES
Merchant Admin Portal
totalAmount Total payment amount 10 YES
Merchant can filter any payment scheme for a specific checkout request if required by passing
payment method to the checkout HTML form. In the Merchant web page, if you require only a particular
payment scheme to be displayed, then you will be required to pass the respective Code below to the
checkout form as the “paymentMethod” parameter. Then other payment schemes will not be visible to
the customer for selection.
Code Sample
<html>
<body>
<form method="POST" action="https://sandbox.ipay.lk/ipg/checkout">
<input type="hidden" name="merchantWebToken" value="eyJhbGciOiJIUz..."> <!-- Replace your web token -->
<input type="hidden" name="orderId" value="OID123456">
<input type="hidden" name="orderDescription" value="My Order"> <!-- Optional -->
<input type="hidden" name="returnUrl" value="http://mywebsite.com/return?orderId=OID123456">
<input type="hidden" name="cancelUrl" value="http://mywebsite.com/cancel?orderId=OID123456">
<input type="hidden" name="subMerchantReference" value=""> <!-- Optional -->
<table>
<tr>
<td>Total Amount</td>
<td>:</td>
<td><input type="text" name="totalAmount" value="750"></td>
</tr>
<tr>
<td>Customer Name </td>
<td>:</td>
<td><input type="text" name="customerName" value="Ravindu Fernando"></td>
</tr>
<tr>
<td>Customer Mobile</td>
<td>:</td>
<td><input type="text" name="customerPhone" value="0701234567"></td>
</tr>
<tr>
<td>Customer Email</td>
<td>:</td>
<td><input type="text" name="customerEmail" value="[email protected]"></td>
</tr>
</table>
<br>
<input type="submit" value="Checkout Now">
</form>
</body>
</html>
Once the payment is authorized by the customer, iPay will notify the payment status to your call-back
API. Payment notification will contain the following data as JSON POST parameters, so you need to make
sure the call-back API URL you set is accepting these parameters on a POST request. After capturing the
payment status you need to verify the payment status and update your database accordingly. Here you
need to cross check your order amount matches with the transaction amount sent by call-back API to
make sure the customer has paid the correct amount.
Note:
iPay redirects the customer back to your website returnUrl which you provided, only after we receive the
Success response from your Call-back API.
We do not send any parameters with this return URL and you must include the required query
parameters to your return URL such as Order ID, in order to obtain payment status from your database
when the customer redirects back to the return URL.
Max
Parameter Name Description
Length
Payment reference number for particular transaction
transactionReference 20
generated by iPay
It is important to verify the Payment notification before taking any action on the payment response.
You can do the verification using the checksum parameter generated and sent by iPay.
The Checksum is generated using the HMAC SHA256 algorithm, using the below given combination of
parameters.
Note: Please refer the Appendix section for more information on creating base64 hashes using HMAC
SHA256 in different languages.
Once you receive the payment notification from iPay, you can locally generate this checksum using above
mentioned parameters and the secret you have locally. Your locally generated checksum should be equal
to the checksum sent by iPay if the payment notification is valid.
5123450000000008 Y
2223000000000007 Y
Mastercard
5111111111111118 N
2223000000000023 N
4508750015741019 Y
Visa
4012000033330026 N
01 / 39 APPROVED
05 / 22 DECLINED
04 / 27 EXPIRED_CARD
08 / 28 TIMED_OUT
01 / 37 ACQUIRER_SYSTEM_ERROR
02 / 37 UNSPECIFIED_FAILURE
05 / 37 UNKNOWN
100 MATCH
101 NOT_PROCESSED
102 NO_MATCH
After the iPay merchant registration is successfully completed, you are required to follow these same
steps in your live environment.
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js
"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/hmac-sha256.min.
js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/enc-base64.min.j
s"></script>
<script>
var hash = CryptoJS.HmacSHA256("Message", "secret");
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
document.write(hashInBase64);
</script>
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;
C# HMAC SHA256
using System.Security.Cryptography;
namespace Test
{
public class MyHmac
{
private string CreateToken(string message, string secret)
{
secret = secret ?? "";
var encoding = new System.Text.ASCIIEncoding();
byte[] keyByte = encoding.GetBytes(secret);
byte[] messageBytes = encoding.GetBytes(message);
using (var hmacsha256 = new HMACSHA256(keyByte))
{
byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
return Convert.ToBase64String(hashmessage);
}
}
}
}
#import "AppDelegate.h"
#import <CommonCrypto/CommonHMAC.h>
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSString* key = @"secret";
NSString* data = @"Message";
NSLog(@"%@", hash);
+ (NSString*)base64forData:(NSData*)theData {
const uint8_t* input = (const uint8_t*)[theData bytes];
NSInteger length = [theData length];
NSInteger i;
for (i=0; i < length; i += 3) {
NSInteger value = 0;
NSInteger j;
for (j = i; j < (i + 3); j++) {
value <<= 8;
@end
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"fmt"
)
func main() {
fmt.Println(ComputeHmac256("Message", "secret"))
}
require 'openssl'
require "base64"
import hashlib
import hmac
import base64
message = bytes("Message").encode('utf-8')
secret = bytes("secret").encode('utf-8')
print $digest;
# digest is now: qnR8UCqJggD55PohusaBNviGoOJ67HC6Btry4qXLVZc=
import 'dart:html';
import 'dart:convert';
import 'package:crypto/crypto.dart';
void main() {