This repository has been archived by the owner on Feb 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrangellzarinpal.php
executable file
·201 lines (170 loc) · 6.5 KB
/
trangellzarinpal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* @package Joomla - > Site and Administrator payment info
* @subpackage com_jgive
* @subpackage Trangell_Zarinpal
* @copyright trangell team => https://trangell.com
* @copyright Copyright (C) 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');
require_once dirname(__FILE__) . '/trangellzarinpal/helper.php';
if (!class_exists ('checkHack')) {
require_once( dirname(__FILE__) . '/trangellzarinpal/trangell_inputcheck.php');
}
class PlgPaymentTrangellZarinpal extends JPlugin
{
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
// Set the language in the class
$config = JFactory::getConfig();
}
public function buildLayoutPath($layout)
{
$layout = trim($layout);
if (empty($layout))
{
$layout = 'default';
}
$app = JFactory::getApplication();
$core_file = dirname(__FILE__) . '/' . $this->_name . '/' . 'tmpl' . '/' . $layout . '.php';
return $core_file;
}
public function buildLayout($vars, $layout = 'default' )
{
// Load the layout & push variables
ob_start();
$layout = $this->buildLayoutPath($layout);
include $layout;
$html = ob_get_contents();
ob_end_clean();
return $html;
}
public function onTP_GetInfo($config)
{
if (!in_array($this->_name, $config))
{
return;
}
$obj = new stdClass;
$obj->name = $this->params->get('plugin_name');
$obj->id = $this->_name;
return $obj;
}
public function onTP_GetHTML($vars) {
$app = JFactory::getApplication();
$config = JFactory::getConfig();
$Amount = round($vars->amount,0)/10; // Toman
$Description = 'پرداخت برای سایت'.' ' .$config->get( 'sitename' );
$Email = '';
$Mobile = '';
$CallbackURL = $vars->notify_url;
try {
$client = new SoapClient('https://www.zarinpal.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']);
//$client = new SoapClient('https://sandbox.zarinpal.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']); // for local
$result = $client->PaymentRequest(
[
'MerchantID' => $this->params->get('merchant_id',''),
'Amount' => $Amount,
'Description' => $Description,
'Email' => $Email,
'Mobile' => $Mobile,
'CallbackURL' => $CallbackURL,
]
);
$resultStatus = abs($result->Status);
if ($resultStatus == 100) {
// Header('Location: https://www.zarinpal.com/pg/StartPay/'.$result->Authority);
if ($this->params->get('zaringate', '') == 0){
$vars->action_url = 'https://www.zarinpal.com/pg/StartPay/'.$result->Authority;
}
else {
$vars->action_url = 'https://www.zarinpal.com/pg/StartPay/'.$result->Authority.'/ZarinGate';
}
$html = $this->buildLayout($vars);
return $html;
} else {
$msg= plgPaymentTrangellZarinpalHelper::getGateMsg('error');
$link = JRoute::_(JUri::root(). 'index.php?option=com_jgive&task=donations.cancel&processor=trangellzarinpal&order_id='.$vars->order_id,false);
$app->redirect($link, '<h2>'.$msg.' خطای: '.$resultStatus.'</h2>', $msgType='Error');
}
}
catch(\SoapFault $e) {
$msg= plgPaymentTrangellZarinpalHelper::getGateMsg('error');
$link = JRoute::_(JUri::root(). 'index.php?option=com_jgive&task=donations.cancel&processor=trangellzarinpal&order_id='.$vars->order_id,false);
$app->redirect($link, '<h2>'.$msg.'</h2>', $msgType='Error');
}
}
public function onTP_Processpayment($data, $vars = array()) {
$app = JFactory::getApplication();
$jinput = $app->input;
$Authority = $jinput->get->get('Authority', '0', 'INT');
$status = $jinput->get->get('Status', '', 'STRING');
if (checkHack::checkString($status)){
if ($status == 'OK') {
try {
$client = new SoapClient('https://www.zarinpal.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']);
//$client = new SoapClient('https://sandbox.zarinpal.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']); // for local
$result = $client->PaymentVerification(
[
'MerchantID' =>$this->params->get('merchant_id',''),
'Authority' => $Authority,
'Amount' => round($vars->amount/10,0),
]
);
$resultStatus = abs($result->Status);
if ($resultStatus == 100) {
$msg= plgPaymentTrangellZarinpalHelper::getGateMsg($resultStatus);
JFactory::getApplication()->enqueueMessage('<h2>'.$msg.'</h2>'.'<h3>'. $result->RefID .'شماره پیگری ' .'</h3>', 'Message');
plgPaymentTrangellZarinpalHelper::saveComment($this->params->get('plugin_name'), str_replace('JGOID-','',$vars->order_id), $result->RefID .'شماره پیگری ');
$result = array(
'transaction_id' => '',
'order_id' => $vars->order_id,
'status' => 'C',
'total_paid_amt' => $vars->amount,
'raw_data' => '',
'error' => '',
'return' => $vars->return
);
return $result;
}
else {
$msg= plgPaymentTrangellZarinpalHelper::getGateMsg($resultStatus);
$link = JRoute::_(JUri::root(). 'index.php?option=com_jgive&task=donations.cancel&processor=trangellzarinpal&order_id='.$vars->order_id,false);
$app->redirect($link, '<h2>'.$msg.'</h2>', $msgType='Error');
return false;
}
}
catch(\SoapFault $e) {
$msg= plgPaymentTrangellZarinpalHelper::getGateMsg('error');
$link = JRoute::_(JUri::root(). 'index.php?option=com_jgive&task=donations.cancel&processor=trangellzarinpal&order_id='.$vars->order_id,false);
$app->redirect($link, '<h2>'.$msg.'</h2>', $msgType='Error');
return false;
}
}
else {
$msg= plgPaymentTrangellZarinpalHelper::getGateMsg(intval(17));
$link = JRoute::_(JUri::root(). 'index.php?option=com_jgive&task=donations.cancel&processor=trangellzarinpal&order_id='.$vars->order_id,false);
$app->redirect($link, '<h2>'.$msg.'</h2>', $msgType='Error');
return false;
}
}
else {
$msg= plgPaymentTrangellZarinpalHelper::getGateMsg('hck2');
$link = JRoute::_(JUri::root(). 'index.php?option=com_jgive&task=donations.cancel&processor=trangellzarinpal&order_id='.$vars->order_id,false);
$app->redirect($link, '<h2>'.$msg.'</h2>' , $msgType='Error');
return false;
}
}
public function onTP_Storelog($data)
{
$log_write = $this->params->get('log_write', '0');
if ($log_write == 1)
{
$log = plgPaymentTrangellZarinpalHelper::Storelog($this->_name, $data);
}
}
}