Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
MA7 committed Mar 6, 2016
1 parent ced249b commit 4a7279e
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 135 deletions.
Binary file added Help.doc
Binary file not shown.
41 changes: 21 additions & 20 deletions admin/controller/payment/zarinpalZg.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
class ControllerPaymentZarinpalZg extends Controller {
class ControllerPaymentZARINPALZG extends Controller {

private $error = array();

public function index() {
$this->load->language('payment/zarinpalZg');
$this->load->language('payment/zarinpalzg');


$this->document->setTitle = $this->language->get('heading_title');
Expand All @@ -13,7 +14,7 @@ public function index() {
if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) {
$this->load->model('setting/setting');

$this->model_setting_setting->editSetting('zarinpalZg', $this->request->post);
$this->model_setting_setting->editSetting('zarinpalzg', $this->request->post);

$this->session->data['success'] = $this->language->get('text_success');

Expand Down Expand Up @@ -70,46 +71,46 @@ public function index() {

$this->document->breadcrumbs[] = array(
//'href' => $this->url->https('payment/sb24'),
'href' => $this->url->link('payment/zarinpalZg', 'token=' . $this->session->data['token'], 'SSL'),
'href' => $this->url->link('payment/zarinpalzg', 'token=' . $this->session->data['token'], 'SSL'),
'text' => $this->language->get('heading_title'),
'separator' => ' :: '
);


$this->data['action'] = $this->url->link('payment/zarinpalZg', 'token=' . $this->session->data['token'], 'SSL');
$this->data['action'] = $this->url->link('payment/zarinpalzg', 'token=' . $this->session->data['token'], 'SSL');

$this->data['cancel'] = $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL');

if (isset($this->request->post['zarinpal_PIN'])) {
$this->data['zarinpal_PIN'] = $this->request->post['zarinpal_PIN'];
if (isset($this->request->post['zarinpalzg_PIN'])) {
$this->data['zarinpalzg_PIN'] = $this->request->post['zarinpalzg_PIN'];
} else {
$this->data['zarinpal_PIN'] = $this->config->get('zarinpal_PIN');
$this->data['zarinpalzg_PIN'] = $this->config->get('zarinpalzg_PIN');
}


if (isset($this->request->post['zarinpal_order_status_id'])) {
$this->data['zarinpal_order_status_id'] = $this->request->post['zarinpal_order_status_id'];
if (isset($this->request->post['zarinpalzg_order_status_id'])) {
$this->data['zarinpalzg_order_status_id'] = $this->request->post['zarinpalzg_order_status_id'];
} else {
$this->data['zarinpal_order_status_id'] = $this->config->get('zarinpal_order_status_id');
$this->data['zarinpalzg_order_status_id'] = $this->config->get('zarinpalzg_order_status_id');
}

$this->load->model('localisation/order_status');

$this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();

if (isset($this->request->post['zarinpal_status'])) {
$this->data['zarinpal_status'] = $this->request->post['zarinpal_status'];
if (isset($this->request->post['zarinpalzg_status'])) {
$this->data['zarinpalzg_status'] = $this->request->post['zarinpalzg_status'];
} else {
$this->data['zarinpal_status'] = $this->config->get('zarinpal_status');
$this->data['zarinpalzg_status'] = $this->config->get('zarinpalzg_status');
}

if (isset($this->request->post['zarinpal_sort_order'])) {
$this->data['zarinpal_sort_order'] = $this->request->post['zarinpal_sort_order'];
if (isset($this->request->post['zarinpalzg_sort_order'])) {
$this->data['zarinpalzg_sort_order'] = $this->request->post['zarinpalzg_sort_order'];
} else {
$this->data['zarinpal_sort_order'] = $this->config->get('zarinpal_sort_order');
$this->data['zarinpalzg_sort_order'] = $this->config->get('zarinpalzg_sort_order');
}

$this->template = 'payment/zarinpalZg.tpl';
$this->template = 'payment/zarinpalzg.tpl';
$this->children = array(
'common/header',
'common/footer'
Expand All @@ -121,11 +122,11 @@ public function index() {

private function validate() {

if (!$this->user->hasPermission('modify', 'payment/zarinpalZg')) {
if (!$this->user->hasPermission('modify', 'payment/zarinpalzg')) {
$this->error['warning'] = $this->language->get('error_permission');
}

if (!$this->request->post['zarinpal_PIN']) {
if (!$this->request->post['zarinpalzg_PIN']) {
$this->error['PIN'] = $this->language->get('error_PIN');
}

Expand Down
6 changes: 3 additions & 3 deletions admin/language/persian/payment/zarinpalZg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


// Heading
$_['heading_title'] = ' زرين پال- زرین گیت';
$_['heading_title'] = 'زرين پال-زرین گیت';

// Text
$_['text_payment'] = 'پرداخت';
$_['text_success'] = '&#1605;&#1608;&#1601;&#1602;: &#1608;&#1740;&#1585;&#1575;&#1740;&#1588; &#1588;&#1583;!';
$_['text_development'] = '<span style="color: green;">&#1570;&#1605;&#1575;&#1583;&#1607;</span>';
$_['text_zarinpal'] = '<a onclick="window.open(\'http://www.zarinpal.com\');"><img src="view/image/payment/zarinpal.gif" alt="ZarinPal" title="ZarinPal" style="border: 1px solid #EEEEEE;" /></a>';
$_['text_zarinpalzg'] = '<a onclick="window.open(\'http://www.zarinpalzg.com\');"><img src="view/image/payment/zarinpalzg.gif" alt="ZarinPal" title="ZarinPal" style="border: 1px solid #EEEEEE;" /></a>';

// Entry
$_['entry_PIN'] = 'کد دروازه پرداخت:<br/><small></small>';
Expand All @@ -19,4 +19,4 @@
// Error
$_['error_permission'] = '&#1575;&#1582;&#1591;&#1575;&#1585;: &#1575;&#1580;&#1575;&#1586;&#1607; &#1608;&#1740;&#1585;&#1575;&#1740;&#1588; &#1606;&#1583;&#1575;&#1585;&#1740;&#1583;!';
$_['error_PIN'] = 'PIN &#1590;&#1585;&#1608;&#1585;&#1740;&#1587;&#1578;!';
?>
?>
Binary file added admin/view/image/payment/zarinpalzg.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions admin/view/template/payment/zarinpalZg.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@

<tr>
<td width="25%"><span class="required">*</span> <?php echo $entry_PIN; ?></td>
<td><input type="text" name="zarinpal_PIN" value="<?php echo $zarinpal_PIN; ?>" />
<td><input type="text" name="zarinpalzg_PIN" value="<?php echo $zarinpalzg_PIN; ?>" />
<br />
<?php if ($error_PIN) { ?>
<span class="error"><?php echo $error_PIN; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><?php echo $entry_order_status; ?></td>
<td><select name="zarinpal_order_status_id">
<td><select name="zarinpalzg_order_status_id">
<?php foreach ($order_statuses as $order_status) { ?>
<?php if ($order_status['order_status_id'] == $zarinpal_order_status_id) { ?>
<?php if ($order_status['order_status_id'] == $zarinpalzg_order_status_id) { ?>
<option value="<?php echo $order_status['order_status_id']; ?>" selected="selected"><?php echo $order_status['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $order_status['order_status_id']; ?>"><?php echo $order_status['name']; ?></option>
Expand All @@ -45,8 +45,8 @@
</tr>
<tr>
<td><?php echo $entry_status; ?></td>
<td><select name="zarinpal_status">
<?php if ($zarinpal_status) { ?>
<td><select name="zarinpalzg_status">
<?php if ($zarinpalzg_status) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } else { ?>
Expand All @@ -57,12 +57,12 @@
</tr>
<tr>
<td><?php echo $entry_sort_order; ?></td>
<td><input type="text" name="zarinpal_sort_order" value="<?php echo $zarinpal_sort_order; ?>" size="1" /></td>
<td><input type="text" name="zarinpalzg_sort_order" value="<?php echo $zarinpalzg_sort_order; ?>" size="1" /></td>
</tr>
</table>

</form>
</div>
</div>
</div>
<?php echo $footer; ?>
<?php echo $footer; ?>
153 changes: 55 additions & 98 deletions catalog/controller/payment/zarinpalZg.php
Original file line number Diff line number Diff line change
@@ -1,100 +1,69 @@
<?php
require_once(DIR_SYSTEM.'library/nuSoap/nusoap.php');
class ControllerPaymentZarinpalZg extends Controller {

private $RefId = 0;

class ControllerPaymentZarinpalzg extends Controller {
protected function index() {
$this->language->load('payment/zarinpalZg');
$this->data['button_confirm'] = $this->language->get('button_confirm');
$this->language->load('payment/zarinpalzg');
$this->data['button_confirm'] = $this->language->get('button_confirm');

$this->data['text_wait'] = $this->language->get('text_wait');
$this->data['text_ersal'] = $this->language->get('text_ersal');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/zarinpalZg.tpl')) {
$this->template = $this->config->get('config_template') . '/template/payment/zarinpalZg.tpl';
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/zarinpalzg.tpl')) {
$this->template = $this->config->get('config_template') . '/template/payment/zarinpalzg.tpl';
} else {
$this->template = 'default/template/payment/zarinpalZg.tpl';
$this->template = 'default/template/payment/zarinpalzg.tpl';
}

$this->render();
}

public function confirm() {

$this->load->model('checkout/order');

$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);

$this->load->library('encryption');
$encryption = new Encryption($this->config->get('config_encryption'));

//$this->data['Amount'] = $this->currency->format($order_info['total'], 'TMN', $order_info['value'], FALSE);

$this->data['Amount'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false);

//$this->data['Amount']=$this->data['Amount']\10;

$this->data['PIN']=$this->config->get('zarinpal_PIN');

$this->data['PIN']=$this->config->get('zarinpalzg_PIN');
$this->data['ResNum'] = $this->session->data['order_id'];

$this->data['return'] = $this->url->link('checkout/success', '', 'SSL');
//$this->data['return'] = HTTPS_SERVER . 'index.php?route=checkout/success';

$this->data['cancel_return'] = $this->url->link('checkout/payment', '', 'SSL');
//$this->data['cancel_return'] = HTTPS_SERVER . 'index.php?route=checkout/payment';

$this->data['back'] = $this->url->link('checkout/payment', '', 'SSL');

//$client = new SoapClient("https://www.zarinpal.com/pg/services/WebGate/wsdl");
$client = new nusoap_client('https://de.zarinpal.com/pg/services/WebGate/wsdl', 'wsdl');
$client->soap_defencoding = 'UTF-8';
$client = new SoapClient('https://www.zarinpal.com/pg/services/WebGate/wsdl', array('encoding' => 'UTF-8'));

if((!$client)){
if ((!$client)) {
$json = array();
$json['error']= "Can not connect to ZarinPal.<br>";

$this->response->setOutput(json_encode($json));
}

$amount = intval($this->data['Amount'])/$order_info['currency_value'];
if($this->currency->getCode()=='RLS') {
$amount = $amount/10;
if ($this->currency->getCode()=='RLS') {
$amount = $amount / 10;
}
//$callbackUrl = $this->url->https('payment/zarinpal/callback&order_id=' . $encryption->encrypt($this->session->data['order_id']));
//$callbackUrl = HTTPS_SERVER . 'index.php?route=payment/zarinpal/callback&order_id=' . $encryption->encrypt($this->session->data['order_id']);
$this->data['order_id'] = $encryption->encrypt($this->session->data['order_id']);
//$callbackUrl = $this->url->link('payment/zarinpal/callback&order_id=' . $encryption->encrypt($this->session->data['order_id']));
$callbackUrl = $this->url->link('payment/zarinpalZg/callback', 'order_id='. $this->data['order_id'], 'SSL');

//$res=$client->PaymentRequest($this->data['PIN'], $amount, $callbackUrl, urlencode(' خريد شماره: '.$order_info['order_id']) );
$parameters = array(
array(
'MerchantID' => $this->data['PIN'],
'Amount' => $amount,
'Description' => 'خريد شماره: '.$order_info['order_id'],
'Email' => '',
'Mobile' => '',
'CallbackURL' => $callbackUrl
)
);
$res = $client->call('PaymentRequest', $parameters);
if($res['Status'] == 100){
$this->data['action'] = 'https://www.zarinpal.com/pg/StartPay/' . $res['Authority'];

$this->data['order_id'] = $this->session->data['order_id'];
$callbackUrl = $this->url->link('payment/zarinpalzg/callback&order_id=' . $this->data['order_id']);

$result = $client->PaymentRequest(array(
'MerchantID' => $this->data['PIN'],
'Amount' => $amount,
'Description' => 'خريد شماره: ' . $order_info['order_id'],
'Email' => '',
'Mobile' => '',
'CallbackURL' => $callbackUrl
));
if ($result->Status == 100) {
$this->data['action'] = 'https://www.zarinpal.com/pg/StartPay/'. $result->Authority .'/ZarinGate';
$json = array();
$json['success']= $this->data['action'];
$json['success']= $this->data['action'];
$this->response->setOutput(json_encode($json));
} else {
echo 'ERR: '. $res['Status'];
$this->CheckState($res['Status']);
//die();
$this->CheckState($result->Status);
}
}

public function CheckState($status) {
$json = array();
switch($status){

switch ($status) {
case "-1" :
$json['error']="اطلاعات ارسالی ناقص می باشند";
break;
Expand All @@ -115,70 +84,58 @@ public function CheckState($status) {
break;

default :
$json['error']= "خطای نامشخص;";
$json['error']= "خطای نامشخص. کد خطا: " ;
break;
}
}

$this->response->setOutput(json_encode($json));
}

function verify_payment($authority, $amount){

if($authority){
//$client = new SoapClient("http://pg.zarinpal.com/services/WebGate/wsdl");
$client = new nusoap_client('https://de.zarinpal.com/pg/services/WebGate/wsdl', 'wsdl');
$client->soap_defencoding = 'UTF-8';
if ((!$client)){
echo 'Error: can not connect to ZarinPal.<br>';return false;
if ($authority) {
//$client = new SoapClient("http://www.zarinpalzg.com/WebserviceGateway/wsdl");
$client = new SoapClient('https://www.zarinpal.com/pg/services/WebGate/wsdl', array('encoding' => 'UTF-8'));
if ((!$client)) {
echo "Error: can not connect to ZarinPal.<br>";
return false;
} else {
$this->data['PIN'] = $this->config->get('zarinpal_PIN');
//$res = $client->PaymentVerification($this->data['PIN'], $authority ,$amount);
$parameters = array(
array(
'MerchantID' => $this->data['PIN'],
'Authority' => $authority,
'Amount' => $amount
)
);
$res = $client->call('PaymentVerification', $parameters);
$this->data['PIN'] = $this->config->get('zarinpalzg_PIN');
$result = $client->PaymentVerification(array(
'MerchantID' => $this->data['PIN'],
'Authority' => $authority,
'Amount' => $amount
));

$this->CheckState($res['Status']);
$this->CheckState($result);

if($res['Status']==100){
$this->RefId = $res['RefId'];
if ($result->Status==100) {
return true;
} else {
echo 'ERR: '. $res['Status'];
return false;
}
}
} else {
return false;
}

return false;
}

public function callback() {
$this->load->library('encryption');

$encryption = new Encryption($this->config->get('config_encryption'));
$au = $this->request->get['Authority'];
$status = $this->request->get['Status'];
$order_id = $encryption->decrypt($this->request->get['order_id']);
$MerchantID=$this->config->get('zarinpal_PIN');
$authority = $this->request->get['Authority'];
$order_id = $this->request->get['order_id'];
$MerchantID = $this->config->get('zarinpalzg_PIN');
$debugmod = false;

$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($order_id);
//$Amount = $this->currency->format($order_info['total'], 'RLS', $order_info['value'], FALSE);

$Amount = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false); //echo $this->data['Amount'];

$amount = $Amount/$order_info['currency_value'];
if ($order_info && $status == "OK") {
if(($this->verify_payment($au, $amount))) {
$this->model_checkout_order->confirm($order_id, $this->config->get('zarinpal_order_status_id'), 'شماره سند تراکنش: '. $this->RefId);
$amount = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false); //echo $this->data['Amount'];
if ($order_info) {
if (($this->verify_payment($authority, $amount)) or ($debugmod==true)) {
$this->model_checkout_order->confirm($order_id, $this->config->get('zarinpalzg_order_status_id'),'شماره رسيد ديجيتالي; Authority: '.$authority);

$this->response->setOutput('<html><head><meta http-equiv="refresh" CONTENT="2; url=' . $this->url->link('checkout/success') . '"></head><body><table border="0" width="100%"><tr><td>&nbsp;</td><td style="border: 1px solid gray; font-family: tahoma; font-size: 14px; direction: rtl; text-align: right;">با تشکر پرداخت شما با شماره تراکنش '. $this->RefId .' تکمیل شد.لطفا چند لحظه صبر کنید و یا <a href="' . $this->url->link('checkout/success') . '"><b>اینجا کلیک نمایید</b></a></td><td>&nbsp;</td></tr></table></body></html>');
$this->response->setOutput('<html><head><meta http-equiv="refresh" CONTENT="2; url=' . $this->url->link('checkout/success') . '"></head><body><table border="0" width="100%"><tr><td>&nbsp;</td><td style="border: 1px solid gray; font-family: tahoma; font-size: 14px; direction: rtl; text-align: right;">با تشکر پرداخت تکمیل شد.لطفا چند لحظه صبر کنید و یا <a href="' . $this->url->link('checkout/success') . '"><b>اینجا کلیک نمایید</b></a></td><td>&nbsp;</td></tr></table></body></html>');
}
} else {
$this->response->setOutput('<html><body><table border="0" width="100%"><tr><td>&nbsp;</td><td style="border: 1px solid gray; font-family: tahoma; font-size: 14px; direction: rtl; text-align: right;">.<br /><br /><a href="' . $this->url->link('checkout/cart'). '"><b>بازگشت به فروشگاه</b></a></td><td>&nbsp;</td></tr></table></body></html>');
Expand Down
Loading

0 comments on commit 4a7279e

Please sign in to comment.