کد PHP:
<?php
function mellat_config(){ $configarray = array( "FriendlyName" => array("Type" => "System", "Value" => "پرداخت ریالی بانک ملت"), "mellatterminalId" => array( "FriendlyName" => "ترمینال عملیاتی", "Type" => "text", "Size" => "30", ), "mellatuserName" => array( "FriendlyName" => "نام کاربری", "Type" => "text", "Size" => "30", ), "mellatuserPassword" => array( "FriendlyName" => "رمز عبور", "Type" => "text", "Size" => "30", ), ); return $configarray;}
function mellat_link($params){
$terminalId = $params['mellatterminalId']; $userName = $params['mellatuserName']; $userPassword = $params['mellatuserPassword'];
$invoiceid = $params['invoiceid']; $description = $params["description"]; $amount = $params['amount'];
$companyname = $params['companyname']; $systemurl = $params['systemurl']; $currency = $params['currency'];
//Because WHMCS has bug on this section we check inculde (Fastest way) $included_files = get_included_files(); $flag = 0; foreach ($included_files as $file) { if (basename($file) == "nusoap.php") { $flag = 1; } } if ($flag == 0) { require_once ("./modules/gateways/callback/lib/nusoap.php"); $client = new nusoap_client('https://pgws.bpm.bankmellat.ir/pgwchannel/services/pgw?wsdl'); $namespace = 'http://interfaces.core.sw.bps.com/'; mysql_query("INSERT INTO `morders` (`oid`, `invoiceid`, `amount`, `description`, `isPayed`, `resLink`, `resBank`, `refid`, `saleorderid`, `refund`) VALUES (NULL, '$invoiceid', '$amount', '$description', '0', '0', '-1', 'no', '-1', '0');"); $orderId = mysql_insert_id(); $ops = array( 'terminalId' => $terminalId, 'userName' => $userName, 'userPassword' => $userPassword, 'orderId' => $orderId, 'amount' => intval($amount * 10), 'localDate' => date("Ymd"), 'localTime' => date("His"), 'additionalData' => $description, 'callBackUrl' => $systemurl . '/modules/gateways/callback/mellat.php?iid=' . $invoiceid, 'payerId' => 0); $result = $client->call('bpPayRequest', $ops, $namespace); if ($client->fault) { echo '<h2>Fault</h2><pre>'; print_r($result); echo '</pre>'; die(); } else { $err = $client->getError(); if ($err) { echo '<h2>Error</h2><pre>' . $err . '</pre>'; die(); } else { $res = explode(',', $result); if ($res[0] == "0") { $refid = $res[1]; $resLink = $res[0]; mysql_query("UPDATE `morders` SET `refid` = '$refid',`resLink` = '$resLink' WHERE `morders`.`oid` ='$orderId';"); return '<form action="https://pgw.bpm.bankmellat.ir/pgwchannel/startpay.mellat" method="post" target="_self"><input type="hidden" name="RefId" value="' . $res[1] . '" /><input type="submit" value="' . $params['langpaynow'] . '" /></form>'; } else { $resLink = $res[0]; mysql_query("UPDATE `morders` SET `resLink` = '$resLink' WHERE `morders`.`oid` ='$orderId';"); return ("اتصال به بانک دچار مشکل شد است .خطا: $resLink"); } } } }
}
function mellat_refund($params){ $terminalId = $params['mellatterminalId']; $userName = $params['mellatuserName']; $userPassword = $params['mellatuserPassword'];
$invoiceid = $params['invoiceid']; $description = $params["description"]; $amount = $params['amount'];
$companyname = $params['companyname']; $systemurl = $params['systemurl']; $currency = $params['currency'];
//Because WHMCS has bug on this section we check inculde (Fastest way) $included_files = get_included_files(); $flag = 0; foreach ($included_files as $file) { if (basename($file) == "nusoap.php") { $flag = 1; } } if ($flag == 0) { $results = array(); require_once ("./modules/gateways/callback/lib/nusoap.php"); $client = new nusoap_client('https://pgws.bpm.bankmellat.ir/pgwchannel/services/pgw?wsdl'); $namespace = 'http://interfaces.core.sw.bps.com/'; //isPayed should be 1, we have just on payed. $morderq = mysql_query("SELECT * FROM `morders` WHERE `invoiceid` = $invoiceid AND `isPayed` = '1' LIMIT 1"); if (mysql_num_rows($morderq) != 0) { $morder = mysql_fetch_array($morderq); mysql_query("INSERT INTO `morders` (`oid`, `invoiceid`, `amount`, `description`, `isPayed`, `resLink`, `resBank`, `refid`, `saleorderid`, `refund`) VALUES (NULL, '$invoiceid', '$amount', '$description', '0', '0', '-1', 'no', '-1', '1');"); $refundId = mysql_insert_id(); $orderId = $morder['oid']; $saleReferenceId = $morder['saleorderid']; $ops = array( 'terminalId' => $terminalId, 'userName' => $userName, 'userPassword' => $userPassword, 'orderId' => $refundId, //We make new record to refund 'saleOrderId' => $orderId, 'saleReferenceId' => $saleReferenceId, 'refundAmount' => $amount); $result = $client->call('bpRefundRequest', $ops, $namespace); $res = explode(',', $result); if ($res[0] == 0) { $refId = $res[1]; $ops = array( 'terminalId' => $terminalId, 'userName' => $userName, 'userPassword' => $userPassword, 'orderId' => $refundId, //We make new record to refund 'refundOrderId' => $refundId, 'refundReferenceId' => $refId); $result = $client->call('bpRefundVerifyRequest', $ops, $namespace); if ($result == 0) { mysql_query("UPDATE `morders` SET `refid` = '$refId',`refund`='2' WHERE `morders`.`oid` ='$refundId';"); $results['status'] = "success"; $results['transid'] = $refId; return array( "status" => "success", "transid" => $refId, "rawdata" => $results); } else { $result = $client->call('bpRefundInquiryRequest', $ops, $namespace); if ($result == 0) { mysql_query("UPDATE `morders` SET `refid` = '$refId',`refund`='2' WHERE `morders`.`oid` ='$refundId';"); $results['status'] = "success"; $results['transid'] = $refId; return array( "status" => "success", "transid" => $refId, "rawdata" => $results); } else { mysql_query("UPDATE `morders` SET `refid` = '$refId', WHERE `morders`.`oid` ='$refundId';"); $results['status'] = "error"; $results['transid'] = $refId; return array("status" => "error", "rawdata" => $results); } } } else { $results['status'] = "declined"; return array("status" => "declined", "rawdata" => $results); }
} else { $results['status'] = "declined"; return array("status" => "declined", "rawdata" => $results); }
}
}?>