Implementing Moneybookers Payment Gateway with PHP

32 comments
Today we will integrate a Payment gateway in our website. We are going to implement Moneybookers Payment Gateway. Moneybookers provide an easily customizable payment gateway that can be implemented without much headache. You just need to create two accounts on Moneybookers, one for the Merchant and other for the Buyer. Then send a request to Moneybookers to convert these accounts into test accounts (for testing purpose). This is a manual process as Moneybookers provide no sandbox account like PayPal for the developers. After your account has been approved as test account, you can start using it for transactions.
Moneybookers payment gateway gives you two options for the payment, either you can transfer the buyer to Moneybookers payment page or you can embed the iframe into your own page which looks more elegant. Here we will be following the second one i.e the iframe.



Database structure:
Create table 'payment_details' as:
CREATE TABLE `payment_status` (
  `order_id` int(11) NOT NULL AUTO_INCREMENT,
  `transaction_id` varchar(255) DEFAULT NULL,
  `amount` float(10,2) DEFAULT NULL,
  `status` int(1) DEFAULT NULL,
  `payment_type` varchar(20) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `username` varbinary(255) DEFAULT NULL,
  PRIMARY KEY (`order_id`)
)

Create the payment page:
We will include our payment form inthis page using an iframe. This is simple and doesn't need anything special. We will pass the necessary information with the URL of the iframe as:
<iframe src="http://yoursite.com/payment-form?email=<?php echo $email ?>&fname=<?php echo $FirstName ?>&lname=<?php echo $LastName ?>&address=<?php echo $Address ?>&address2=<?php echo $Address2 ?>&city=<?php echo $City ?>&postal_code=<?php echo $PostalCode ?>&country=<?php echo $CountryId ?>&state=<?php echo $State ?>" name="payment" height="600" width="610" border="0">
 </iframe>

Create the payment form:
Payment page starts with a form with a number of hidden fields for the payment process. We will autosubnit this form to proceed to the next step of payment.
<html>
<head>
<title>MoneyBookers by WebSpeaks.in</title>
</head>
<body>
<?php
$email = $_GET['email'];
$fname = $_GET['fname'];
$lname = $_GET['lname'];
$address = $_GET['address'];
$address = $_GET['address'];
$address2 = $_GET['address2'];
$city = $_GET['city'];
$postal_code = $_GET['postal_code'];
$country = $_GET['country'];
$state = $_GET['state'];

$price = 10;
?>
<form action="https://www.moneybookers.com/app/payment.pl" target="_self" name="payment_form">

 <input type="hidden" name="pay_to_email" value="your_merchant_email"> 
 <input type="hidden" name="pay_from_email" value="<?php echo $email ?>">
 <input type="hidden" name="return_url" value="http://yoursite.com/payment_success.php"> <!-- URL to redirect after payment success -->
 <input type="hidden" name="cancel_url" value="http://yoursite.com/payment_cancel.php">  <!-- URL to redirect after payment cancel -->
 <input type="hidden" name="status_url" value="http://yoursite.com/payment_status.php"> <!-- URL to get the payment response (not visible to user, called on backend) -->
 <input type="hidden" name="language" value="EN"> <!-- Language of payment -->

 <input type="hidden" name="hide_login" value="1">  <!-- Whether to show the tiny login form with the payment form, no in our case -->

 <!-- Specifies a target in which the return_url value will be called upon successful payment from customer.  -->
 <!-- 1 = '_top', 2 = '_parent', 3 = '_self', 4= '_blank' -->
 <input type="hidden" name="return_url_target" value="1">  
 <input type="hidden" name="cancel_url_target" value="1"> 

 <!-- Custom fields for your own needs -->
 <input type="hidden" name="merchant_fields" value="name, username, order_amount, user_id"> <!-- List all your custom fields here (comma separated, max 5)-->
 <input type="hidden" name="name" value="<?php echo $fname. ' '.$lname ?>"> <!-- Value of Custom 'name' -->
 <input type="hidden" name="username" value="<?php echo $username ?>">  <!-- Value of Custom 'username' -->
 <input type="hidden" name="order_amount" value="<?php echo $price ?>"> <!-- Value of Custom 'order_amount' -->
 <input type="hidden" name="user_id" value="<?php echo $user_id ?>">  <!-- Value of Custom 'user_id' -->

 <input type="hidden" name="amount_description" value="Testing Amount">  <!-- Description of the amount -->
 <input type="hidden" name="amount" value="<?php echo $price ?>">  <!-- Amount to be charged -->
 <input type="hidden" name="currency" value="GBP">   <!-- Currency of payment -->
 <input type="hidden" name="firstname" value="<?php echo $fname ?>">   <!-- Firstname of buyer, need for autofilling -->
 <input type="hidden" name="lastname" value="<?php echo $lname ?>">    <!-- Lastname of buyer, need for autofilling -->
 <input type="hidden" name="email" value="<?php echo $email ?>">    <!-- Email of buyer, need for autofilling -->
 <input type="hidden" name="address" value="<?php echo $address ?>">     <!-- Address of buyer, need for autofilling -->
 <input type="hidden" name="city" value="<?php echo $city ?>">     <!-- City of buyer, need for autofilling -->
 <input type="hidden" name="state" value="<?php echo $state ?>">     <!-- State of buyer, need for autofilling -->
 <input type="hidden" name="postal_code" value="<?php echo $postal_code ?>">     <!-- Postal_code of buyer, need for autofilling -->
 <input type="hidden" name="country" value="<?php echo $country ?>">     <!-- Country code of buyer, need for autofilling -->
 <input type="hidden" name="detail1_description" value="New Product">      <!-- Description heading of the payyment, shown after payment has been made -->
 <input type="hidden" name="detail1_text" value="<?php echo $product ?>">      <!-- Detailed description of the payment, shown after payment has been made -->
 <input type="hidden" name="confirmation_note" value="Thanks for purchasing Voodoo Video!"> <!-- Confirmation message to be shown after payment has been made --> 

 <p>
  <input type="submit" class="submitBtn

Receive Payment Status:
In the payment form we have specified the 'status_url' field. This field specifies the URL on which the Moneybookers sends the status of the payment. It is URL to which the transaction details will be posted after the payment process is complete. Alternatively, you may specify an email address to which you would like to receive the results. If the status_url is omitted, no transaction details will be sent to the Merchant.
Detailed status description
‘2’ Processed – This status is sent when the transaction is processed and the funds have been received on your Moneybookers account.
‘0’ Pending – This status is sent when the customers pays via the pending bank transfer option. Such transactions will auto-process IF the bank transfer is received by Moneybookers. We strongly recommend that you do NOT process the order/transaction in your system upon receipt of a pending status from Moneybookers.
‘-1’ Cancelled – Pending transactions can either be cancelled manually by the sender in their online account history or they will auto-cancel after 14 days if still pending. ‘-2’ Failed – This status is sent when the customer tries to pay via Credit Card or Direct debit but our provider declines the transaction. If you do not accept Credit Card or Direct debit payments via Moneybookers (see page 16) then you will never receive the failed status.
‘-3’ Chargeback – This status could be received only if your account is configured to receive chargebacks. If this is the case, whenever a chargeback is received by Moneybookers, a -3 status will be posted on the status_url for the reversed transaction.

Create payment_status.php as:
$status = $_POST['status']/*Status of transaction*/
$username = $_POST['username'];/*Custom field*/
$user_id = $_POST['user_id'];/*Custom field*/
$amount = $_POST['amount'];/*Amount of transaction*/
$payment_type = $_POST['payment_type'];/*Type of Payment*/
$mb_transaction_id = $_POST['mb_transaction_id'];/*Moneybookers transaction id*/

/*save transaction details in database*/
mysql_query("INSERT INTO `payment_details` (`transaction_id`, `amount`, `status`, `payment_type`, `user_id`, `username`) VALUES ('".$mb_transaction_id."', '".$amount."', '".$status."', '".$payment_type."', '".$user_id."', '".$username."') ");

Payment Success Page:
Create payment_success.php as
<?php
echo "Your payment has been received. Thanks for purchasing our product.";
?>

Payment Cancel Page:
Create payment_cancel.php as
<?php
echo "Your payment has been cancelled. Please try again.";
?>

32 comments

Can u give the complete module related to sending email in magento by writing an action in magento..

Could you tell how to create this with button? Such that when user clicks on the button, he will be taken to moneybookers and he can finish the transaction there and once its over, he is taken back to site?

There are a number of problems with your code, Arvind. For instance your "payment_status.php" page is susceptible to SQL injection. Plus, you don't even verify that the order is valid.

I recently wrote an article that shows how to correctly process orders using Moneybookers and how to verify the order is valid before taking an action on the data (e.g. saving it to a database, generating a product key, etc). See the article here: How to automate Moneybookers (Skrill) using status_url (IPN)

how can i get the custom fields ie merchan_fields ?
i try to get bu using $_POST['merchant_fields']

$_POST['mb_transaction_id']

How can i get this value?

I need a programmer proficient in moneybookers intergration to make changes to the gateway i.e. remove it and simplify the payment processing as cannot now afford the 19.99 monthly fee that has been implemented.

did you ever get answer to this question pls help... I have the same problem..

did you guy find out the answer to that -I have the same problem...

SasikaranFebruary 25, 2012 8:46 PM
$_POST['mb_transaction_id']

How can i get this value?

Reply

You need to define the page in the payment form on which you want to get the variables from moneybookers as:
<input type="hidden" name="status_url" value="http://yoursite.com/payment_status.php">
Now on payment_status.php you will receive all the variables.

Hello WebSpeaks,
Thank you for this tutorial,
I have another question regarding implementing payment_status.php verfication through status_url callback and redirection from MoneyBookers gateway to final page
Could you check this script and post working example
Regards,Nik

@Nik, What exactly your doubt is?

Hello again,

I'tried using follow script in order to verify transaction and redirect client to download page
but without response from MoneyBookers gateway at this script url after submmiting in both return_url and status_url
Could you suggest something in order to verify transaction status and reditrect?
Regards
----

------

Hello again,

Ive'tried using following script in order to verify transaction and redirect client to download page
but without response from MoneyBookers gateway at this script url after submmiting in both return_url and status_url
Could you suggest something in order to verify transaction status and reditrect?
Regards
----
$statusofPayment = $_POST['status'];
$userName = $_POST['username'];/*Custom field*/
$userId = $_POST['user_id'];/*Custom field*/
$transactionAmount = $_POST['amount'];/*Amount that is taken from user after the transaction*/
$paymentType = $_POST['payment_type'];
$transaction_id = $_POST['mb_transaction_id'];/*Moneybookers transaction id*/


if $_POST['status'] == ‘2’ Processed transaction is processed
{
Header("Location:site-scripts.php");
exit;
}
if $_POST['status'] == ‘0’ Pending customers pays via the pending bank transfer option
{
Header("Location:site-scripts-07345.php");
exit;
}
if $_POST['status'] == ‘-1’ Cancelled cancelled manually by the sender
{
Header("Location:download.php");
exit;
}
if $_POST['status'] == ‘-3’ Chargeback receive chargebacks
{
Header("Location:download.php");
exit;
}
------

I have define that hidden field with a proper value. after successful transaction it redirect to my success page, but I didn't get any value in status page. how to insert into database with all value.

You must get the values in $_POST on the status page.

I use demo transaction and set up all pages into localhost. my hidden field field is like "input type="hidden" name="status_url" value="http://localhost/moneybookers/payment_status.php"".

but still I didn't get value. is this for local server? I used your code define in this page. I'm new to moneybooker. please help me out.

@Moumita Bala, you will not able to get the response on localhost. You need to have a publicly accessible server or I.P. for that.

I upload it into a server and test it again. but still it does not get any value into status page. only return into success page. here I print a "$_request" which return an array "Array ( [treemenu1] => none open [treemenu2] => none open [treemenu3] => none open )".
again I mentioned its a demo transaction. but why anything is not inserted into my db or into status page.

@Moumita Bala, If you have implemented the code in a right way, it must work. Please recheck the code. I am not able to help without the code.

Thank you for your code. now its work for me. I have one more question. its return with status 0 means pending. when payment process is complete then it will updated automatically or I need to update it from my end ?

another question : into database only merchant's user_id and username is inserted. How could I get users information?

recurring payment process is possible in moneybookers? how to implement this?

@Moumita Bala, You need to repeat the process when the pending payment is completed. Moneybookers will automatically update it in its database, but you need to manually update your database to change the status to complete (get and process the response on status page).
The user_id and username of the merchant are sent as hidden fields when you post the form to Moneybookers. Please check Moneybookers documentation if they allow more custom fields to be sent along with the payment form (I believe there must be a limit on the custom fields).
Recurring payment should be there, I am not really sure about that. Please check the documentation for that.

contact to me to implement moneybookers to any shopping cart

contact to me to integrate moneybookers

How can i make a test payment in moneybookers??

I Also want to Allow the user to pay via credit and debit card. what I need to add in that form?
Please help me in that.

You have to contact them via a message

Have to change the "payment_metod"

input type="hidden" name="payment_methods" value="VSE,AMX,MSC,VSA,WLT,"

But it didn't work 4 me

When status_url call
i have set status url and code for save details in database but its not update database.
not getting when this url call and how to call this url

We would love to hear from you...

back to top