This article is totally for the step-by-step guide for integrating the FrillPay’s payment gateway API into your website, offering insights into popular scenarios like deposits and withdrawals. Additionally, we’ll delve into code examples and best practices specifically tailored for PHP integration.
Integration with FrillPay API: A Step-by-Step Guide
Merchant Account Registration:
- Open a merchant account with FrillPay by submitting an application. (Guide here)
- Provide essential company details and required documentation, including business registration documents and proof of identification for authorized representatives. (Guide here)
- Undergo a verification process to ensure compliance with regulatory and security standards.
Obtaining API Access Credentials:
- Upon successful registration and verification, obtain API access credentials, including your unique API key and Token key. (Guide here)
- Securely store and protect these credentials, treating them as sensitive information.
Initiating a Deposit (Top-Up):
- Collect customer data, including first name, last name, email, and deposit amount.
- Prepare data for the payment gateway using FrillPay’s provided code examples.
- Redirect the customer to the FrillPay payment gateway for a secure deposit transaction.
Initiating a Withdrawal:
- Collect necessary information for withdrawal, such as the user’s name, email, and withdrawal amount.
- Prepare withdrawal data using FrillPay’s code examples.
- Redirect the user to the FrillPay withdrawal endpoint for a secure transaction.
Code Examples for API Integration
Initiating a Deposit (Top-Up) – PHP Example:
<?php
// Arranging necessary parameters
$apiKey = [YOUR-API-KEY-HERE]; // Replace with your actual API Key
$token = [YOUR-TOKEN-KEY-HERE]; // Replace with your actual Token Key// Collect form data
$reqestedId = “Abc123321”;
$fName = “John”;
$lName = “Doe”;
$email = “[email protected]”;
$amount = 100;
$currency = “USD”;
$accountno = 00000;$websiteURL = “[MERCHANT_CALL_BACK_URL_FOR_DEPOSIT]”; // Where to redirect after a deposit?
// Preparing the data to be sent to the payment gateway (FrillPay)
$data = array(
‘apiKey’ => encryptData($apiKey, $token),
‘reqestedId’ => encryptData($reqestedId, $token),
‘fName’ => encryptData($fName, $token),
‘lName’ => encryptData($lName, $token),
’email’ => encryptData(“$email”, $token),
‘amount’ => encryptData($amount, $token),
‘currency’ => encryptData($currency, $token),
‘accountno’ => encryptData($accountno, $token),
‘websiteURL’ => encryptData($websiteURL, $token),
);// Sending the data to FrillPay
$queryString = http_build_query(array_merge($data, [‘token’ => $token]));// URL to hit for deposit
$redirectUrl = ‘https://frillpay.com/merchant-dashboard/fp-payment.php?’ . $queryString;// Redirect to the URL
redirect($redirectUrl);
exit();
?>
Initiating a Withdrawal – PHP Example:
<?php
// Arranging necessary parameters
$apiKey = [YOUR-API-KEY-HERE]; // Replace with your actual API Key
$token = [YOUR-TOKEN-KEY-HERE]; // Replace with your actual Token Key// Collect form data
$reqestedId = “Abc123321”;
$name = “John Doe”;
$email = “[email protected]”;
$amount = 100;
$websiteURL = “[MERCHANT_CALL_BACK_URL_FOR_WITHDRAWAL]”; // Where to redirect after a withdrawal?$data = array(
‘apiKey’ => encryptData($apiKey, $token),
‘reqestedId’ => encryptData($reqestedId, $token),
‘name’ => encryptData($name, $token),
’email’ => encryptData($email, $token),
‘amount’ => encryptData($amount, $token),
‘websiteURL’ => encryptData($websiteURL, $token),
);$queryString = http_build_query(array_merge($data, [‘token’ => $token]));
// URL to hit for withdrawal
$redirectUrl = ‘https://frillpay.com/mrc-wdrw-fr-usr?’ . $queryString;// Redirect to the URL
redirect($redirectUrl);
exit();
?>
How to Encrypt & Decrypt Data?
Here is a complete understanding of how we are using this encryption and decryption processes for every of your API requests.
Please be noted:
- Make sure to assign the same ‘Token Key’ assigned to you on your merchant backoffice. (Guide here)
- All Deposits and Withdrawals requests should use this function to securely communicate with our server and get the responses accordingly!
// Function to encrypt data using AES encryption
function encryptData($data, $token)
{
$ivSize = openssl_cipher_iv_length('aes-256-cbc');
$iv = openssl_random_pseudo_bytes($ivSize);
$encrypted = openssl_encrypt($data, 'aes-256-cbc', $token, OPENSSL_RAW_DATA, $iv);
$encryptedData = base64_encode($iv . $encrypted);
return $encryptedData;
}// Function to decrypt data using AES decryption
function decryptData($data, $token)
{
$data = base64_decode($data);
$ivSize = openssl_cipher_iv_length(‘aes-256-cbc’);
$iv = substr($data, 0, $ivSize);
$encryptedData = substr($data, $ivSize);
$decrypted = openssl_decrypt($encryptedData, ‘aes-256-cbc’, $token, OPENSSL_RAW_DATA, $iv);
return $decrypted;
}
These PHP code examples serve as a foundation for integrating FrillPay API into your web applications seamlessly. By following these steps and incorporating best practices, you pave the way for a secure and user-friendly payment experience.
Tips for Successful & Secure Integration
- Activate ‘Sandbox’: Begin by activating the ‘sandbox mode’ during the integration phase until you are confident that the integration is thoroughly tested and set up.
- Replace API Keys: Ensure to replace the placeholder values of the ‘$apiKey’ and ‘$token’ variables with your actual ‘API Key’ and ‘Token Key’.
- Don’t alter the ‘$redirectUrl’ variable: Use the same URL as described in the sample code above for ‘deposits/withdrawal’ requests.
- Submit Call Back URL: Provide us with the ‘Call Back URL’ of your website designated for redirecting users after ‘deposits/withdrawals’ requests. Simply send us the exact URL you assigned to the ‘$websiteURL’ variable via email at [email protected].
- Currency Selection: Pass only the ‘USD’ in a currency field as this is the only supported currency for time being.
- Setup Request ID: Make sure each of your API request comes with an unique Request ID to make is easier for you to track status later.
Stay tuned for further articles as we delve into testing in the sandbox environment, security measures, and error handling best practices. The path to FrillPay integration unfolds, ensuring a frictionless journey for both developers and end-users.