Tuesday 10 November 2015

Neteller payment integration core Php , Curl.

You may also see the post here https://yourlearn.in/posts/view/6/neteller-payment-integration-core-php and know and read much more about it.


If you want to implement Neteller payment using Core / Simple Php below is code for you can get it. I have used below code for only testing purpose so i can check weather Neteller working OR not. Please never used below code on production if you want to use below code in production you have to modify it accordingly like.
 
You can create function for CURL request , passing merchant info in hidden field is not good way you can take that in your PHP SCRIPT.
 
To set up a Business Test Account, you need to provide the below information to merchantsupport@paysafe.com and they`ll set it up for you
Merchant descriptor name: Your descriptor name
Contact Person: Your Name
Phone number: Your Number
Country:      Your Country          
Contact E-mail: create an email on gmail , yahoo...etc and put here.
Currency Accounts: Your Currency USD..etc
 
You can find Member Test Accounts in the Integration Manual on page 153.
 
You can go to https://merchant.neteller.com/merchflux/public/index and grab your merchant info and replace in hidden field. You have to request there customer support for enabling API client key and secret key for testing purpose. During my code testing i found invalid client issue response from API so for issue i have to add IP address there. Another issue i have faced minimum amount , Amount should be passed as $_POST['amount']*100.
 
1. Your All Php , Html Code file or you can say your view file will goes like below.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>NETELLER</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>NETELLER</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form method="post" action=""><br>
Version: <input type="text" name="version" value="4.1"><br>
Amount : <input type="text" name="amount" value="1"><br>
Currency: <input type="text" name="currency" value="USD"><br>
net_account: <input type="text" name="net_account" value="12 digit number"><br>
secure_id: <input type="text" name="secure_id" value="326415"><br>
<div><hr></div>
MI: <input type="hidden" name="merchant_id" value="08762"><br>
MK: <input type="hidden" name="merch_key" value="client_id:client_key"><br>
MTID: <input type="hidden" name="merch_transid" value="<?php echo time(); ?>"><br>
MN: <input type="hidden" name="merch_name" value="Company Ltd"><br>
MA: <input type="hidden" name="merch_account" value="Comany Ltd"><br>
<input type="submit" name="button" value="Make transfer">
</form>
</body>
</html>
<?php
if (isset($_POST['button'])) {
$fields = array(
'version' => $_POST['version'],
'amount' => urlencode($_POST['amount']),
'currency' => $_POST['currency'],
'net_account' => urlencode($_POST['net_account']),
'secure_id' => urlencode($_POST['secure_id']),
'merchant_id' => urlencode($_POST['merchant_id']),
'merch_key' => urlencode($_POST['merch_key']),
'merch_transid' => urlencode($_POST['merch_transid']),
'button' => 'Make Transfer'
);

$merchantkey = $_POST['merch_key'];
$amount_value = $_POST['amount']*100;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, "https://api.neteller.com/v1/oauth2/token?grant_type=client_credentials");
curl_setopt($ch, CURLOPT_USERPWD, $merchantkey);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Cache-Control:no-cache"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$serverOutput = curl_exec($ch);
$serverOutput = json_decode($serverOutput);
if (isset($serverOutput->error) && $serverOutput->error != '') {
header("Location:your_page.php?status=" . $serverOutput->error->message . "&payment_type=neteller");
exit;
}
if (isset($serverOutput->accessToken) && $serverOutput->accessToken != "") {
$access_token = $serverOutput->accessToken;
$requestParams = array(
"paymentMethod" => array(
"type" => "neteller",
"value" => $_SESSION["email"],
),
"transaction" => array (
"merchantRefId" => (string) time(),
"amount" => $amount_value,
"currency" => "USD"
),
"verificationCode" => $_POST['secure_id']
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, "https://api.neteller.com/v1/transferIn");
curl_setopt($curl, CURLOPT_HTTPHEADER, 
array("Content-Type:application/json", "Authorization: Bearer $access_token"));
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($requestParams));
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$serverOutput = curl_exec($curl);
$serverOutput = json_decode($serverOutput);
if (isset($serverOutput->error->code) && $serverOutput->error->message != '') {
header("Location:payment.php?status=" . urlencode($serverOutput->error->message) . "
&payment_type=neteller");
exit;
}
curl_close($ch);
//Success full return array;
echo "<pre>";
print_r($serverOutput);
}
}
?>