PayLe REST API
Merchants can use PayLe REST API as their Payment gateway. Currently, we are supporting for Java and PHP integration.
Requirements:
Merchant must have a user account in payleq8.com. Merchant needs to make a request for obtaining the keys for payment integration and the system will provide:
- Account ID
- Account password
- Resource key
Merchants can use these details for further development.
Sandbox Mode Development
This means merchants can use sandbox payment to test their implementation.
Merchant can get the total amount to be charged by the customer by calling this endpoint.
POST https://sandpay.payleq8.com/apifee/requestfullamounts?lang=ar&initialAmount=10&businessCode=(merchant business
code here)
Response JSON:
{
"records": [
{
"name": "Knet",
"fullAmount": 10.350,
"id": 1
},
{
"name": "Visa / Master Card",
"fullAmount": 10.600,
"id": 3
}
],
"errorMessages": null,
"errorSetMessages": null,
"validated": true,
"httpcode": 200
}
Note: Merchant needs to send this full amount detail in the payment process
Make The Payment
For making the payment, you need to call the URL like this:
API-URL/Lang/TransactionData/TransactionID/Version
API-URL
API Root URL
This is going to be different for sandbox and production
Parameter :- Https://Sandpay.Payleq8.Com/Payinit/
Required :- Yes
Lang -
Transaction page language (English – ar / Arabic – ar)
Parameter :- ar
Required :- Yes
Transaction Data -
Encrypted transaction details. Encryption method will be given by System (JAVA or PHP)
Required :- Yes
Example:
84AB86C59E0E1B0F13504C836C09F1106001BF4CEB8C7B0FB8E1768672FDA97D387DE86019353E6D1CBE8930F2E05395885EEC82E56940EF2D737E9C7611322C5F5AF1EF04EC423ED96C638017A2E1D51030C06D5F63F6540C6B194BA4F116F788BAE7401678E5E90B45162564DEFE58B42E7139609359C9C236F18A4B9933FCB6D04C89502FA9E16E43B7832F951D6491039B5AC03C02D856C135D4E5E70E42495DC5A0038362BDDE53FB5A4F194A2B40546A865F0763CE625B2998A7E1A3ACDC01B86B7F7D1F9CA2BCD1A52733D7447BBF03F419B13CC94A9202E3242AC9DD40A442B0D5617C3C239B985D2058D825A19DF368E723494726FB3C52C450DBDABC9AEE6686FA7B2C5751545076FA9641F896837E07422526E2582452C82207F1B55DE2CAD18C000C12BC923060BB5DAA
TransactionID
System given account id when requesting for public payment integration
Parameter :- Transaction account id
Required :- Yes
Version
API Version
Parameter :- 0
Required :- Yes
Here is a complete sample URL:
https://sandpay.payleq8.com/payinit84AB86C59E0E1B0F13504C836C09F1106001BF4CEB8C7B0FB8E1768672FDA97D387DE86019353E6D1CBE8930F2E05395885EEC82E56940EF2D737E9C7611322C5F5AF1EF04EC423ED96C638017A2E1D51030C06D5F63F6540C6B194BA4F116F788BAE7401678E5E90B45162564DEFE58B42E7139609359C9C236F18A4B9933FCB6D04C89502FA9E16E43B7832F951D6491039B5AC03C02D856C135D4E5E70E42495DC5A0038362BDDE53FB5A4F194A2B40546A865F0763CE625B2998A7E1A3ACDC01B86B7F7D1F9CA2BCD1A52733D7447BBF03F419B13CC94A9202E3242AC9DD40A442B0D5617C3C239B985D2058D825A19DF368E723494726FB3C52C450DBDABC9AEE6686FA7B2C5751545076FA9641F896837E07422526E2582452C82207F1B55DE2CAD18C000C12BC923060BB5DAA/Trsactionaccountid/0
For Java
Step1: Create Encrypt String
String TpId = “Account id that given by system ” ;// must be string
String ReqTranportalId = "tpid="+ TpId +"&";
String TpKey = “Account password that given by system ” ;// must be string
String ReqTranportalPassword = "tpkey="+ TpKey +"&";
String TranAmount = “Amount without commission calculation”;// must be string
String ReqAmount = "amount="+TranAmount+"&";
String TranFullAmount = “Amount with commission calculation”;// must be string
String ReqFullAmount = "fullamount="+TranFullAmount+"&";
String paymenttype = “Card type”;// “1 mean Knet, 3 mean Visa/Master” must be string
String ReqPaymentType = "paymenttype="+ paymenttype +"&";
String businesscode = “business code that given by system”;// must be string
String ReqBusinesscode = "businesscode="+ businesscode +"&";
String TranTrackid= “Unique key for identify transaction given by merchant”;// must be string
String ReqInvoiceKey="invoicekey="+TranTrackid+"&";
String udf1 = “return url must be give by merchant”;// must be string
String ReqUdf1 = "udf1="+ udf1 +"&";
String udf2 = “merchant can define , not required”;// must be string
String ReqUdf2 = "udf2="+ udf2 +"&";
String udf3 = “merchant can define , not required”;// must be string
String ReqUdf3 = "udf3="+ udf3 +"&";
String paymentmedia = “Payment source”; //“0 mean mobile app, 1 mean web browser” must be string
String ReqPaymentMedia = "paymentmedia="+paymentmedia+"&";
//Buyer details
String buyerMobile= “Buyer mobile number”;// must be string
String ReqPaymentBuyerMobile = "buyermobile="+buyerMobile+"&";
String buyerEmail= “Buyer email”;// must be string
String ReqPaymentBuyerEmail = "buyeremail="+buyerEmail+"&";
String buyerName= “Buyer name”;// must be string
String ReqPaymentBuyerName = "buyername="+buyerName+"&";
String transactionRequestData = ReqPaymentMedia+ReqAmount+ReqFullAmount
+ReqPaymentType+ReqBusinesscode+ReqInvoiceKey+ReqUdf1+ReqUdf2+ReqUdf3
+ReqTranportalId+ReqTranportalPassword+ReqPaymentBuyerMobile
+ReqPaymentBuyerEmail+ReqPaymentBuyerName;
String encriptData = call encryption method to encrypt data;
Example
String encriptData = encryptAES(transactionRequestData);// need to call encryptAES in PayleGatewayHelper Service class
For PHP
Step1:Create Encrypt String
$TranportalId = “Account id that given by system ” ;
$ReqTranportalId = "tpid=".$TranportalId."&";
$TranportalKey = “Account password that given by system ” ;
$ReqTranportalKey = "tpkey=".$TranportalKey."&";
$TranAmount = “Amount without commission calculation”;
$ReqAmount = "amount=".$TranAmount."&";
$TranFullAmount = “Amount with commission calculation”;
$ReqFullAmount = "fullamount=".$TranFullAmount."&";
$paymenttype = “Card type”; // “1 mean Knet, 3 mean Visa/Master”
$ReqPaymentType = "paymenttype=".$paymenttype."&";
$businesscode = “business code that given by system”;
$ReqBusinesscode = "businesscode=".$businesscode."&";
$invoicekey = “Unique key for identify transaction given by merchant”;
$ReqInvoiceKey="invoicekey=".$invoicekey."&";
$udf1 = “return url must be give by merchant”;
$udf2 = “merchant can define , not required”;
$udf3 = “merchant can define , not required”;
$ReqUdf1 = "udf1=". $udf1 ."&";
$ReqUdf2 = "udf2=". $udf2 ."&";
$ReqUdf3 = "udf3=". $udf3 ."&";
$paymentmedia = “Payment source”; //“0 mean mobile app, 1 mean web browser”
$ReqPaymentMedia = "paymentmedia=".$paymentmedia."&";
$buyerMobile = “Buyer mobile number”;
$buyerEmail = “Buyer email”;
$buyername = “Buyer name”;
$ReqPaymentBuyerMobile = "buyermobile=".$buyerMobile."&";
$ReqPaymentBuyerEmail = "buyeremail=".$buyerEmail."&";
$ReqPaymentBuyerName = "buyername=".$buyername."&";
$transactionRequestData = $ReqPaymentMedia.$ReqAmount.$ReqFullAmount.$ReqPaymentType.$ReqBusinesscode.$ReqInvoiceKey.$ReqUdf1.$ReqUdf2.$ReqUdf3.$ReqTranportalId.$ReqTranportalPassword.$ReqPaymentBuyerMobile.$ReqPaymentBuyerEmail.$ReqPaymentBuyerName;
$encriptData = call encryption method to encrypt data;
Example
$phpclass = new PHP_AES_Cipher;
$encriptData = $phpclass->encrypt($transactionRequestData);// need to call encrypt in aescipher.php class
For PHP & JAVA
Step 02: Create request url
NOTE: You can use any url for development testing. But for the production environment you need to send us the
final URL ( that you need for us to send the payment status parameters ) when you request for the production
API Keys.
JAVA
String redirectUrl= “https://sandpay.payleq8.com/payinit”+encriptData+”/”+TpId+”/0”;
PHP
$redirectUrl= “https://sandpay.payleq8.com/payinit”.$encriptData.”/”.$TpId.”/0”;
Step 03:
Call this url in java class
return "redirect:" + redirectUrl;
In PHP
header("Location:" .$redirectUrl);
Step 04: After complete transaction process will send response given url by merchant (UDF1) Response url will look like:
Given url + “?code=00&error=&refnumber=4592951491159139322&trackNumber=3784359362267089584&transDate=CAD67EA864563BB7BBA102881BFC06D6DF55F962A050A53B31A6D08051757486CC05061522C2CC20EAF88E1FC5B24C9F83E8ED7C4931CDDD55E320CBC257992F314DB02B5BE96CFE40A0353A7EC11B603AEAF71974C8F18D1CEBE8E471662EB456FDE815431539D2B7E40EA994416AEC3272F125017485D61EC509AE1C9F6DD6771E3E122BE8DBBED7869E38DEB5E65BAECF689678EB9F7D25996AD6AE784C5D0E68737C09D285408B609EF1CEE0404DF1370A4BEE724B20A0C0D26874E41F148A90AE2797C573CB66C1DC6B6BE95DF82AE0B9A9D6C654B1EBFA08EA74203CBA550C403032BA8330AA74ADFDD858F02526F29B9D77BCECC6E6ECF9F50ED4C0EF2D390F17456F21208B0BE950619514970065BB1AD7EB2E1EB67C4B20E42B890B2E605271A47605C154860F12F0D4A64E3F01C5CBA1CE93ADACCD5CA3467409912910404E131770E58DB6D20E3AE15A3D99D87273327F20000673807C3749ABC66EA27C26F09240D55436FFC423A99C7737C2B5743F0E0562B82712E723294420”;
Code
Payment process status
00 = success payment initiation with no error;
Other codes meaning error or fail:
Miss Match Amount = "01";
Miss Match Payment Method = "02";
Duplicate Key = "03";
System Cannot Find Detail = "04";
Bank Given Error = "05";
System Cannot Find Transaction Detail = "06";
Fail Transaction = "07";
Cancel Transaction = "08";
System Cannot Save Data = "09";
System Technical Error = "10";
System Error = "11";
Validation Fail = "12";
Note that :- code 00 does not mean payment is success
From here this data needs to be decrypted:Error: If there is any error, it will show here Refnumber: Unique key for the transaction by merchant TrackNumber: Unique key by PayLe system to track transaction TransData: Encrypted data by PayLe system
Example:
Java
String decriptData = decryptAES(TransDate);// need to call decryptAES in PayleGatewayHelper
Service class
PHP
$phpclass->decrypt(TransDate);// need to call encrypt in aescipher.php class
After decrypt it will see like below
decriptData = paymentmedia=1&earnamount=100.000&amount=100.000&fullamount=103.300&paymenttype=3&businesscode={business code}&invoicekey={given reference key by merchant}&udf1={given url here}&udf2=null&udf3=null&tranportalid={given transaction account id }&buyermobile=null&buyeremail=null&buyername=null&paymentid={given unique key by system}&result=1
After decrypt:
Paymentmediamean payment source 0 through app, 1 through web browser
Earnamountmean merchant earn amount that particular transaction
AmountMean payment amount without commission given in initial request
Full AmountMean payment amount with commission calculation given in initial request
PaymentTypeMean card type (1 Knet, 3 Visa/Master) given in initial request
BusinessCodeMean business code given in initial request
Invoice keyMean given reference key by merchant in initial request
Udf1 ,udf2,udf3Mean user defined data given in initial request
TranportalidMean given transaction account id by system in initial request
BuyermobileMean buyer mobile number given by merchant in initial request
BuyeremailMean buyer email given by merchant in initial request
BuyernameMean buyer name given by merchant in initial request
ResultMean after complete process check whether it success or not
** this code is very important
Result code
If code is 1
Payment was success and merchant earn money
Else
Payment was not success
Java: Create a service class called PayleGatewayHelper
import java.math.BigDecimal;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.springframework.stereotype.Service;
@Service
public class PayleGatewayHelper {
private static final String HEX_DIGITS = "0123456789abcdef";
private static final String RESOURCE_KEY = "**********"; // given by payle system
private String encryptAES(String encryptString) throws Exception {
byte[] encryptedText = null;
IvParameterSpec ivspec = null;
SecretKeySpec skeySpec = null;
Cipher cipher = null;
byte[] text = null;
String s = null;
try {
ivspec = new IvParameterSpec(RESOURCE_KEY.getBytes("UTF-8"));
skeySpec = new SecretKeySpec(RESOURCE_KEY.getBytes("UTF-8"), "AES");
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivspec);
text = encryptString.getBytes("UTF-8");
encryptedText = cipher.doFinal(text);
s = byteArrayToHexString(encryptedText);
} catch (Exception e) {
e.printStackTrace();
} finally {
encryptedText = null;
ivspec = null;
skeySpec = null;
cipher = null;
text = null;
}
return s.toUpperCase();
}
private static String byteArrayToHexString(byte[] data) {
return byteArrayToHexString(data, data.length);
}
private static String byteArrayToHexString(byte[] data, int length) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i != length; i++) {
int v = data[i] & 0xff;
buf.append(HEX_DIGITS.charAt(v >> 4));
buf.append(HEX_DIGITS.charAt(v & 0xf));
}
return buf.toString();
}
public static String decryptAES(String encryptedString) throws Exception {
SecretKeySpec skeySpec = null;
IvParameterSpec ivspec = null;
Cipher cipher = null;
byte[] textDecrypted = null;
try {
byte[] b = hexStringToByteArray(encryptedString);
skeySpec = new SecretKeySpec(RESOURCE_KEY.getBytes("UTF-8"), "AES");
ivspec = new IvParameterSpec(RESOURCE_KEY.getBytes("UTF-8"));
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivspec);
textDecrypted = cipher.doFinal(b);
} catch (Exception e) {
e.printStackTrace();
} finally {
skeySpec = null;
ivspec = null;
cipher = null;
}
return (new String(textDecrypted));
}
private static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
}
return data;
}
}
PHP: Create class aescipher
<?php
class PHP_AES_Cipher {
private static $OPENSSL_CIPHER_NAME = "aes-128-cbc"; //Name of OpenSSL Cipher
private static $CIPHER_KEY_LEN = 16; //128 bits
private static $key = "**********";// given by payle system
/**
* Encrypt data using AES Cipher (CBC) with 128 bit key
*
* @param type $key - key to use should be 16 bytes long (128 bits)
* @param type $data - data to encrypt
* @return encrypted data in base64 encoding with iv attached at end after a :
*/
static function encrypt($data) {
if (strlen($key) < PHP_AES_Cipher::$CIPHER_KEY_LEN) {
$key = str_pad("$key", PHP_AES_Cipher::$CIPHER_KEY_LEN, "0"); //0 pad to len 16
} else if (strlen($key) > PHP_AES_Cipher::$CIPHER_KEY_LEN) {
$key = substr($str, 0, PHP_AES_Cipher::$CIPHER_KEY_LEN); //truncate to 16 bytes
}
$encryptedPayload = bin2hex (openssl_encrypt($data, PHP_AES_Cipher::$OPENSSL_CIPHER_NAME, $key, OPENSSL_RAW_DATA, $key));
return strtoupper($encryptedPayload);
}
/**
* Decrypt data using AES Cipher (CBC) with 128 bit key
*
* @param type $key - key to use should be 16 bytes long (128 bits)
* @param type $data - data to be decrypted in base64 encoding with iv attached at the end after a :
* @return decrypted data
*/
static function decrypt( $data) {
if (strlen($key) < PHP_AES_Cipher::$CIPHER_KEY_LEN) {
$key = str_pad("$key", PHP_AES_Cipher::$CIPHER_KEY_LEN, "0"); //0 pad to len 16
} else if (strlen($key) > PHP_AES_Cipher::$CIPHER_KEY_LEN) {
$key = substr($str, 0, PHP_AES_Cipher::$CIPHER_KEY_LEN); //truncate to 16 bytes
}
$hex2bin = hex2bin($data);
$decryptedData = openssl_decrypt($hex2bin, PHP_AES_Cipher::$OPENSSL_CIPHER_NAME, $key, OPENSSL_RAW_DATA, $key);
// $parts = explode(':', $data); //Separate Encrypted data from iv.
// $decryptedData = openssl_decrypt(base64_decode($parts[0]), PHP_AES_Cipher::$OPENSSL_CIPHER_NAME, $key, OPENSSL_RAW_DATA, base64_decode($parts[1]));
return $decryptedData;
}
}
?>
For The Production :
1- Change the URL to --> https://trans.payleq8.com/gatewaypublicinit
هل لديك أي أسئلة؟
اتصل بخدمة العملاء لدينا
أفضل دعم عملاء يساعدك في حل المشاكل التي تواجهها بسرعة.