Pre-Auth / Post-Auth Payment
Pre-Authorization
To create a pre-authorization, you can send a request to the payment service with the transaction_type
parameter set to PreAuth
using 3D Secure. See: Payment with 3D Secure
Pre-Authorization & 3D Secure
The pre-authorization process with 3D Secure is applicable for normal 3D Secure flows as well. When the end user verifies with the received OTP code, the Pre Auth is completed as 3D Secure. The 3D Secure Pre Auth transaction needs to be completed first through the 3D Complete service, and then the pre-authorization closure service should be used.
Post-Authorization
For a successfully created pre-authorization payment, you can complete the payment using the confirmPayment
service.
The HTTP method, endpoint, headers, and request details are provided below.
Method |
API Endpoint |
Content-Type |
POST |
/api/confirmPayment |
application/json |
Parameter |
Requirement |
Content-Type |
Authorization |
Required |
Bearer |
Accept |
Required |
application/json |
Parameter |
Data Type |
Requirement |
Description |
invoice_id |
string |
Required |
Unique invoice number for the initiated payment. |
merchant_key |
string |
Required |
Unique 'Merchant Key' obtained from PayBull. |
status |
integer |
Required |
Sent as 1 for approval, 2 for cancellation. |
hash_key |
string |
Required |
See Hash Key Generation |
total |
double |
Optional |
Amount to be approved in the pre-authorization process. Should be less than or equal to the product price. |
HASH KEY GENERATION
function generateConfrimPaymentHashKey($merchant_key, $invoice_id, $status, $app_secret)
{
$data = $merchant_key . '|' . $invoice_id . '|' . $status;
$iv = substr(sha1(mt_rand()), 0, 16);
$password = sha1($app_secret);
$salt = substr(sha1(mt_rand()), 0, 4);
$saltWithPassword = hash('sha256', $password . $salt);
$encrypted = openssl_encrypt(
"$data", 'aes-256-cbc', "$saltWithPassword", null, $iv
);
$msg_encrypted_bundle = "$iv:$salt:$encrypted";
$msg_encrypted_bundle = str_replace('/', '__', $msg_encrypted_bundle);
return $msg_encrypted_bundle;
}
public static string GenerateHashKey(string merchant_key, string invoice_id, string status,
string app_secret){
var data = merchant_key + '|'+invoice_id+'|'+status;
var sha1 = new SHA1Managed();
Random rnd = new Random();
var iv = sha1.ComputeHash(Encoding.UTF8.GetBytes(rnd.ToString()));
var password = sha1.ComputeHash(Encoding.UTF8.GetBytes(app_secret)).ToString();
rnd = new Random();
var shaSalt = sha1.ComputeHash(Encoding.UTF8.GetBytes(rnd.ToString())).ToString();
var salt = shaSalt.Substring(0, 4);
var sha256 = new SHA256Managed();
var saltWithPassword = sha256.ComputeHash(Encoding.UTF8.GetBytes(password+salt));
//var encrypted = EncryptString(data,saltWithPassword,iv);
var encrypted = "asdasdasd";
var msg_encrypted_bundle = iv + ":" + salt + ":" + encrypted;
msg_encrypted_bundle = msg_encrypted_bundle.Replace("/","__");
return msg_encrypted_bundle;
}
public static string EncryptString(string plainText, byte[] key, byte[] iv){
Aes encryptor = Aes.Create();
encryptor.Mode = CipherMode.CBC;
encryptor.Key = key;
encryptor.IV = iv;
MemoryStream memoryStream = new MemoryStream();
ICryptoTransform aesEncryptor = encryptor.CreateEncryptor();
CryptoStream cryptoStream = new CryptoStream(memoryStream, aesEncryptor, CryptoStreamMode.Write);
byte[] plainBytes = Encoding.ASCII.GetBytes(plainText);
cryptoStream.Write(plainBytes, 0, plainBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] cipherBytes = memoryStream.ToArray();
memoryStream.Close();
cryptoStream.Close();
string cipherText = Convert.ToBase64String(cipherBytes, 0, cipherBytes.Length);
return cipherText;
}
function generateHashKey(merchant_key, invoice_id, status, app_secret) {
var data = merchant_key + "|" + invoice_id + "|" + status;
var randNumIv = Math.floor(Math.random() * (99999999999999999 - 10000000000000000) + 10000000000000000);
var hashNumIv = sha1(randNumIv);
hashNumIv = hashNumIv.create();
var iv = hashNumIv.slice(0,16);
var hashPass = sha1(app_secret);
hashPass = hashPass.create();
var password = hashPass.hex();
var randNumSalt = Math.floor(Math.random() * (99999999999999999 - 10000000000000000) + 10000000000000000);
var hashNumSalt = sha1(randNumIv);
hashNumSalt = hashNumSalt.create();
var salt = hashNumSalt.hex();
var strPassSalt = password + salt;
var hashStr = sha1(strPassSalt);
strPassSalt.create();
var saltWithPassword = strPassSalt.hex();
var encrypted = "";
var msg_encrypted_bundle = iv + ":" + salt + ":" + encrypted;
msg_encrypted_bundle = msg_encrypted_bundle.replaceAll("/" , "_");
return msg_encrypted_bundle;
}
Sample Codes
{
"merchant_key": "$2y$10$w/ODdbTmfubcbUCUq/ia3OoJFMUmkM1UVNBiIQIuLfUlPmaLUT1he",
"invoice_id": "9a197ed9-cfaf-4456-b0fc-da74a95f461c",
"status": 1,
"hash_key": "36a50210c8b2f19e:11629:eHBA0moN...",
"total": 100.44
}
{
"status_code": 100,
"status_description": "An order has been taken place for this invoice id: 33491162435928",
"transaction_status": "Completed",
"order_id": "162435932934307",
"invoice_id": "9a197ed9-cfaf-4456-b0fc-da74a95f461c"
}
{
"status_code": 105,
"status_description": " The transaction is not Approved",
"transaction_status": "Pending",
"order_id": "162435924998223",
"invoice_id": "9a197ed9-cfaf-4456-b0fc-da74a95f461c"
}