Payment Automation with Liberty Reserve – PHP script
Today I will post the solution for payment automation. Since e-gold doesn’t seem to process payments (I’ve submitted my documents and still waiting them to review for about a month), Liberty Reserve becomes another popular payment solution for non-Paypal countries.
We need to have an account with them in order to process payments. We need some basic PHP knowledge to set up payment automation, but if you follow my guide, I think you will be able to set up your payment system without any problems.
As soon as we have an account with LR, we need to do the following steps:
- Login to your LR account.
- Click on ‘Merchant Tools.’
- Click on ‘Create new API.’
- Fill in the form. ‘API Name’ and ‘Security Word’ are required fields, which are used to protect your account from an unauthorized access via API. ‘Requesting IP Addresses’ is an additional security measure that restricts API access to your account only to the IPs listed in this field. Leaving this field empty will allow any IP to have API access to your account (if they know the API Name and Security Word).
- Enter your ‘Security PIN’ and submit this form. Make sure the API was
created and is enabled.
Then we need to download the script package that provides the necessary API functionality. You can find it here.
Then we need to check whether our PHP configuration allows us to use this script. The requirements are: domxml, mhash and curl extensions for PHP4 or mhash and curl for PHP5. Most servers’ PHP configurations are built with these options, but if your server doesn’t have them, you’re welcome to search my blog to find out how to install the missing components.
After our server is OK, we need to extract the contents of the downloaded ZIP archive to a directory on our server. functions.php is the file that will be used for our needs, though you’re welcome to use the sample code provided. I will show you a faster solution without any graphic interface. Here it is:
<?
require(“functions.php”);
// Setting our payment information: login
$payerAcct=”U123456″;
// API name
$apiName=”U123456″;
// And the security word
$securityWord=”JKhfjJHGfjdjh”;
// Most important part: transfer details: recipient account, payment amount, privacy setting (private or not), memo
$transferList=”U654321, 0.05, not-private, Payment Memo”;$canDisplayForm = false;
$canDisplayResult = true;if (is_null($payerAcct) || trim($payerAcct) == “”) {
$wasError = true;
$payerAcctError = “Payer account number can’t be empty.”;
}
else if (!isValidAccountNumber($payerAcct)) {
$wasError = true;
$payerAcctError = “Invalid payer account number format.”;
}if (is_null($securityWord) || trim($securityWord) == ”) {
$wasError = true;
$securityWordError = “Security Word can’t be empty.”;
}if (is_null($apiName) || trim($apiName) == ”) {
$wasError = true;
$apiNameError = “Api Name can’t be empty.”;
}$request = new TransferRequest($apiName, $securityWord);
$request->addTransfersFromText($payerAcct, $transferList, $transferListError);$transferListError = str_replace(“\n”,”<br />”, $transferListError);
if ($transferListError != “”) {
$wasError = true;
}$responseContent = $request->getResponse();
// Checking whether everything is OK with payment
if (substr_count($responseContent, “ReceiptId”))echo “OK”;
else echo “Error”;?>
You may clean up this code to remove some checks to make the script smaller. But… it works and provides you with the ability to use mass payments using Liberty Reserve.