کد PHP:
<?
/*
Virtual Freer
http://freer.ir/virtual
Copyright (c) 2011 Mohammad Hossein Beyram, freer.ir
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License v3 (http://www.gnu.org/licenses/gpl-3.0.html)
as published by the Free Software Foundation.
*/
//-- اطلاعات کلی پلاگین
$pluginData[mellat][type] = 'payment';
$pluginData[mellat][name] = 'درگاه بانک ملت';
$pluginData[mellat][uniq] = 'mellat';
$pluginData[mellat][description] = 'مخصوص پرداخت با دروازه پرداخت <a rel="nofollow" href="http://bankmellat.ir">بانک ملت</a>';
$pluginData[mellat][author][name] = 'Freer';
$pluginData[mellat][author][url] = 'http://freer.ir';
$pluginData[mellat][author][email] = 'hossin@gmail.com';
//-- فیلدهای تنظیمات پلاگین
$pluginData[mellat][field][config][1][title] = 'شماره پايانه پذيرنده';
$pluginData[mellat][field][config][1][name] = 'terminalId';
$pluginData[mellat][field][config][2][title] = 'نام كاربري پذيرنده';
$pluginData[mellat][field][config][2][name] = 'userName';
$pluginData[mellat][field][config][3][title] = 'كلمه عبور پذيرنده';
$pluginData[mellat][field][config][3][name] = 'userPassword';
//-- تابع انتقال به دروازه پرداخت
function gateway__mellat($data)
{
global $config,$smarty,$db;
include_once('include/libs/nusoap.php');
$terminalId = trim($data[terminalId]);
$userName = trim($data[userName]);
$userPassword = trim($data[userPassword]);
$orderId = $data[invoice_id];
$amount = $data[amount];
$localDate = date('Ymd');
$localTime = date('Gis');
$additionalData = '';
$callBackUrl = $data[callback];
$payerId = 0;
//-- تبدیل اطلاعات به آرایه برای ارسال به بانک
$parameters = array(
'terminalId' => $terminalId,
'userName' => $userName,
'userPassword' => $userPassword,
'orderId' => $orderId,
'amount' => $amount,
'localDate' => $localDate,
'localTime' => $localTime,
'additionalData' => $additionalData,
'callBackUrl' => $callBackUrl,
'payerId' => $payerId);
$client = new nusoap_client('https://pgws.bpm.bankmellat.ir/pgwchannel/services/pgw?wsdl');
$namespace='http://interfaces.core.sw.bps.com/';
$result = $client->call('bpPayRequest', $parameters, $namespace);
//-- بررسی وجود خطا
if ($client->fault)
{
//-- نمایش خطا
$data[title] = 'خطای سیستم';
$data[message] = '<font color="red">در اتصال به درگاه بانک ملت مشکلی به وجود آمد٬ لطفا از درگاه سایر بانکها استفاده نمایید.</font> خطا: <br />خطا در اتصال به بانک ملت<br /><a href="http://www.webhostingtalk.ir/forum.php" class="button">بازگشت</a>';
$smarty->assign('data', $data);
$smarty->display('message.tpl');
exit;
}
else
{
$err = $client->getError();
if ($err)
{
//-- نمایش خطا
$data[title] = 'خطای سیستم';
$data[message] = '<font color="red">در اتصال به درگاه بانک ملت مشکلی به وجود آمد٬ لطفا از درگاه سایر بانکها استفاده نمایید.</font> خطا: <br /><pre>'.$err.'</pre><br /><a href="http://www.webhostingtalk.ir/forum.php" class="button">بازگشت</a>';
$smarty->assign('data', $data);
$smarty->display('message.tpl');
exit;
}
else
{
$res = explode (',',$result);
$ResCode = $res[0];
if ($ResCode == "0")
{
$update[payment_rand] = $res[1];
$sql = $db->queryUpdate('payment', $update, "WHERE `payment_rand` = '$orderId' LIMIT 1;");
$db->execute($sql);
$smarty->assign('RefId', $res[1]);
$smarty->display('mellat.tpl');
exit;
}
else
{
//-- نمایش خطا
$data[title] = 'خطای سیستم';
$data[message] = '<font color="red">در اتصال به درگاه بانک ملت مشکلی به وجود آمد٬ لطفا از درگاه سایر بانکها استفاده نمایید.</font> خطا: <br /><pre>'.$err.'</pre><br /><a href="http://www.webhostingtalk.ir/forum.php" class="button">بازگشت</a>';
$smarty->assign('data', $data);
$smarty->display('message.tpl');
exit;
}
}
}
}
//-- تابع بررسی وضعیت پرداخت
function callback__mellat($data)
{
global $db,$post,$smarty;
$sql = "SELECT * FROM `payment` WHERE `payment_rand` = '$post[RefId]' LIMIT 1;";
$payment = $db->fetch($sql);
if ($payment)
{
if ($_POST[ResCode] == '0')
{
include_once('include/libs/nusoap.php');
$client = new nusoap_client('https://pgws.bpm.bankmellat.ir/pgwchannel/services/pgw?wsdl');
$namespace='http://interfaces.core.sw.bps.com/';
//-- تست برای پیدا کردن خطا
$err = $client->getError();
if ($err)
{
$output[status] = 0;
}
else
{
$terminalId = trim($data[terminalId]);
$userName = trim($data[userName]);
$userPassword = trim($data[userPassword]);
$parameters = array(
'terminalId' => $terminalId,
'userName' => $userName,
'userPassword' => $userPassword,
'orderId' => $post[SaleOrderId],
'saleOrderId' => $post[SaleOrderId],
'saleReferenceId' => $post[SaleReferenceId]);
$result = $client->call('bpVerifyRequest', $parameters, $namespace);
//-- نمایش خطا
if ($client->fault)
{
$output[status] = 0;
}
else
{
$err = $client->getError();
if ($err)
{
$output[status] = 0;
}
else
{
if ($result == '0')
{
$err = $client->getError();
if ($err)
{
$output[status] = 0;
}
else
{
$result = $client->call('bpSettleRequest', $parameters, $namespace);
// Check for a fault
if ($client->fault)
{
$output[status] = 0;
}
else
{
$err = $client->getError();
if ($err)
{
$output[status] = 0;
}
else
{
if ($result == 0)
{
//-- آماده کردن خروجی
$output[status] = 1;
$output[res_num] = $post[SaleReferenceId];
$output[ref_num] = $post[RefId];
$output[payment_id] = $payment[payment_id];
}
else
{
$output[status] = 0;
}
}
}
}
}
else
{
$output[status] = 0;
}
}
}
}
}
else
{
$output[status] = 0;
}
}
else
{
$output[status] = 0;
}
return $output;
}