-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy patheasysocialpoints.php
More file actions
executable file
·298 lines (253 loc) · 7.16 KB
/
easysocialpoints.php
File metadata and controls
executable file
·298 lines (253 loc) · 7.16 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
/**
* @package Payment_Easysocialpoints
* @author Techjoomla http://www.techjoomla.com <support@techjoomla.com>
* @copyright Copyright (c) 2009-2013 TechJoomla. All rights reserved.
* @license GNU General Public License version 2, or later
*/
/** ensure this file is being included by a parent file */
// No direct access
defined('_JEXEC') or die('Restricted access');
$lang = JFactory::getLanguage();
$lang->load('plg_payment_easysocialpoints', JPATH_ADMINISTRATOR);
if (JVERSION >= '1.6.0')
{
require_once JPATH_SITE . '/plugins/payment/easysocialpoints/easysocialpoints/helper.php';
}
else
{
require_once JPATH_SITE . '/plugins/payment/easysocialpoints/helper.php';
}
/**
* @since 1.6
*/
class Plgpaymenteasysocialpoints extends JPlugin
{
var $payment_gateway = 'payment_easysocialpoints';
var $log = null;
Public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
// Set the language in the class
$config = JFactory::getConfig();
// Define Payment Status codes in Authorise And Respective Alias in Framework
// 1 = Approved, 2 = Declined, 3 = Error, 4 = Held for Review
$this->responseStatus = array(
'Success' => 'C',
'Failure' => 'X',
);
}
/**
* Check Override file exists
*
* @param string Return File path.
*
* @return mixed file path.
*
* @since 1.6
*/
Protected function buildLayoutPath($layout)
{
jimport('joomla.filesystem.file');
$app = JFactory::getApplication();
$core_file = dirname(__FILE__) . DS . $this->_name . DS . 'tmpl' . DS . 'form.php';
$override = JPATH_BASE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'plugins' . DS .
$this->_type . DS . $this->_name . DS . $layout . '.php';
if (JFile::exists($override))
{
return $override;
}
else
{
return $core_file;
}
}
// Builds the layout to be shown, along with hidden fields.
Protected 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_GetHTML($vars)
{
jimport('joomla.filesystem.folder');
$db = JFactory::getDBO();
$jspath = JPATH_ROOT . DS . 'components' . DS . 'com_easysocial';
if (JFolder::exists($jspath))
{
$query = "SELECT SUM(points) FROM #__social_points_history where user_id=" . $vars->user_id. " AND state = 1 ";
$db->setQuery($query);
$user_points = $db->loadResult();
$vars->user_points = $user_points;
if ($user_points == '')
{
$vars->user_points = 0;
}
$vars->convert_val = $this->params->get('conversion');
$html = $this->buildLayout($vars);
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;
}
// Adds a row for the first time in the db, calls the layout view
Public function onTP_Processpayment($data)
{
$isValid = true;
$error = array();
$error['code'] = '';
$error['desc'] = '';
$db = JFactory::getDBO();
$query = "SELECT SUM(points) FROM #__social_points_history where user_id=" . $data['user_id']. " AND state = 1 ";
$db->setQuery($query);
$points_count = $db->loadResult();
$convert_val = $this->params->get('conversion');
$allowCredit = $this->params->get('seller_credit');
$points_charge = $data['total'] * $convert_val;
require_once JPATH_SITE . '/components/com_quick2cart/helper.php';
$comquick2cartHelper = new comquick2cartHelper;
$orderId = explode('-',$data['order_id']);
$orderInfo = $comquick2cartHelper->getorderinfo($orderId[2]);
$orderItems = $orderInfo['items'];
foreach($orderItems as $orderItem)
{
$productNames[] = $orderItem->order_item_name;
}
$product_names = implode(',', $productNames);
if ($points_charge <= $points_count)
{
//insert new entry in history table to deduct points
$espoint=new stdClass();
$espoint->id = '';
$espoint->state = 1;
$espoint->points = "-". $points_charge;
$espoint->user_id = $data['user_id'];
$espoint->message = JText::sprintf('PLG_POINTS_DEDUCTION',$product_names);
$espoint->created = date("Y-m-d H:i:s"); // 2014-08-12 11:14:54
if (!$db->insertObject( '#__social_points_history', $espoint, 'id' ))
{
echo $db->stderr();
return false;
}
$payment_status = 'Success';
}
else
{
$payment_status = 'Failure';
$isValid = false;
}
// Insert points in seller's account.
if ($allowCredit == 1)
{
foreach ($orderItems as $orderItem)
{
$storeOwner = $comquick2cartHelper->getSoreInfo($orderItem->store_id);
$credit_points = $orderItem->product_item_price * $convert_val;
//insert new entry in history table to credit points
$espoint=new stdClass();
$espoint->id = '';
$espoint->state = 1;
$espoint->points = round($credit_points);
$espoint->user_id = $storeOwner['owner'];
$espoint->message = JText::sprintf('POINTS_CREDIT', $orderItem->order_item_name);
$espoint->created = date("Y-m-d H:i:s");
if (!$db->insertObject('#__social_points_history', $espoint, 'id'))
{
echo $db->stderr();
return false;
}
}
}
// 3.compare response order id and send order id in notify URL
$res_orderid = '';
$res_orderid = $data['order_id'];
if ($isValid)
{
if (!empty($vars) && $res_orderid != $vars->order_id)
{
$payment_status = 'ERROR';
$isValid = false;
$error['desc'] .= "ORDER_MISMATCH" . " Invalid ORDERID; notify order_is " . $vars->order_id . ", and response " . $res_orderid;
}
}
// Amount check
if ($isValid)
{
if (!empty($vars))
{
// Check that the amount is correct
$order_amount = (float) $vars->amount;
$retrunamount = (float) $data['total'];
$epsilon = 0.01;
if (($order_amount - $retrunamount) > $epsilon)
{
$payment_status = 'ERROR';
$isValid = false;
$error['desc'] .= "ORDER_AMOUNT_MISTMATCH - order amount= " . $order_amount . 'response order amount = ' . $retrunamount;
}
}
}
// TRANSLET RESPONSE
$payment_status = $this->translateResponse($payment_status);
$data['payment_status'] = $payment_status;
$result = array('transaction_id' => '',
'order_id' => $data['order_id'],
'status' => $payment_status,
'total_paid_amt' => $data['total'],
'raw_data' => json_encode($data),
'error' => ' ',
'return' => $data['return'],
);
return $result;
}
/**
* Method to translate response according to status.
*
* @param String $invoice_status Payment Status
*
* @return array
*
* @since 1.8.1
*/
Public function translateResponse($invoice_status)
{
foreach ($this->responseStatus as $key => $value)
{
if ($key == $invoice_status)
{
return $value;
}
}
}
/**
* Method onTP_Storelog.
*
* @param String $data Data
*
* @return void
*
* @since 1.8.1
*/
Public function onTP_Storelog($data)
{
$log_write = $this->params->get('log_write', '0');
if ($log_write == 1)
{
$log = plgPaymenteasysocialpointsHelper::Storelog($this->_name, $data);
}
}
}