/
2checkout.php
executable file
·205 lines (181 loc) · 8.48 KB
/
2checkout.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
202
203
204
205
<?php
/*------------------------------------------------------------------------------
$Id$
AbanteCart, Ideal OpenSource Ecommerce Solution
http://www.AbanteCart.com
Copyright © 2011-2018 Belavier Commerce LLC
This source file is subject to Open Software License (OSL 3.0)
Lincence details is bundled with this package in the file LICENSE.txt.
It is also available at this URL:
<http://www.opensource.org/licenses/OSL-3.0>
UPGRADE NOTE:
Do not edit or add to this file if you wish to upgrade AbanteCart to newer
versions in the future. If you wish to customize AbanteCart for your
needs please refer to http://www.AbanteCart.com for more information.
------------------------------------------------------------------------------*/
if (!defined('DIR_CORE')) {
header('Location: static_pages/');
}
/**
* @property ModelExtension2Checkout $model_extension_2checkout
* @property ModelCheckoutOrder $model_checkout_order
*/
class ControllerResponsesExtension2Checkout extends AController
{
public $data = array();
public function main()
{
$this->loadLanguage('2checkout/2checkout');
$this->data['button_confirm'] = $this->language->get('button_confirm');
$this->data['button_back'] = $this->language->get('button_back');
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
if ($this->config->get('2checkout_test')) {
$this->data['action'] = 'https://sandbox.2checkout.com/checkout/purchase';
} else {
$this->data['action'] = 'https://www.2checkout.com/checkout/purchase';
}
$this->data['sid'] = $this->config->get('2checkout_account');
$this->data['currency_code'] = $order_info['currency'];
$this->data['total'] = $this->currency->format($order_info['total'], $order_info['currency'], $order_info['value'], false);
$this->data['cart_order_id'] = $this->session->data['order_id'];
$this->data['order_number'] = $this->session->data['order_id'];
$this->data['card_holder_name'] = $order_info['payment_firstname'].' '.$order_info['payment_lastname'];
$this->data['street_address'] = $order_info['payment_address_1'];
$this->data['city'] = $order_info['payment_city'];
$this->data['state'] = $order_info['payment_zone'];
$this->data['zip'] = $order_info['payment_postcode'];
$this->data['country'] = $order_info['payment_country'];
$this->data['email'] = $order_info['email'];
$this->data['phone'] = $order_info['telephone'];
if ($order_info['shipping_lastname']) {
$this->data['ship_name'] = $order_info['shipping_firstname'].' '.$order_info['shipping_lastname'];
} else {
$this->data['ship_name'] = $order_info['firstname'].' '.$order_info['lastname'];
}
if ($this->cart->hasShipping()) {
$this->data['ship_street_address'] = $order_info['shipping_address_1'];
$this->data['ship_city'] = $order_info['shipping_city'];
$this->data['ship_state'] = $order_info['shipping_zone'];
$this->data['ship_zip'] = $order_info['shipping_postcode'];
$this->data['ship_country'] = $order_info['shipping_country'];
} else {
$this->data['ship_street_address'] = $order_info['payment_address_1'];
$this->data['ship_city'] = $order_info['payment_city'];
$this->data['ship_state'] = $order_info['payment_zone'];
$this->data['ship_zip'] = $order_info['payment_postcode'];
$this->data['ship_country'] = $order_info['payment_country'];
}
$this->data['products'] = array();
$products = $this->cart->getProducts();
foreach ($products as $product) {
$this->data['products'][] = array(
'product_id' => $product['product_id'],
'name' => $product['name'],
'description' => $product['name'],
'quantity' => $product['quantity'],
'price' => $this->currency->format(
$product['price'],
$order_info['currency'],
$order_info['value'],
false
),
);
}
if ($this->config->get('2checkout_test')) {
$this->data['demo'] = 'Y';
}
$this->data['lang'] = $this->session->data['language'];
if ($this->request->get['rt'] == 'checkout/guest_step_3') {
$this->data['back'] = $this->html->getSecureURL('checkout/guest_step_2', '&mode=edit', true);
} else {
$this->data['back'] = $this->html->getSecureURL('checkout/payment', '&mode=edit', true);
}
$this->view->batchAssign($this->data);
$this->processTemplate('responses/2checkout.tpl');
}
public function callback()
{
if ($this->request->is_GET()) {
redirect($this->html->getNonSecureURL('index/home'));
}
$post = $this->request->post;
// hash check
if (!md5(
$post['sale_id']
.$this->config->get('2checkout_account')
.$post['invoice_id']
.$this->config->get('2checkout_secret')) == strtolower($post['md5_hash'])
){
exit;
}
$this->load->model('checkout/order');
$order_id = (int)$this->request->post['vendor_order_id'];
$order_info = $this->model_checkout_order->getOrder($order_id);
if (!$order_info) {
return null;
}
$this->load->model('extension/2checkout');
if ($post['message_type'] == 'ORDER_CREATED') {
$this->model_checkout_order->confirm(
(int)$post['vendor_order_id'],
$this->config->get('2checkout_order_status_id')
);
} elseif ($post['message_type'] == 'REFUND_ISSUED') {
$order_status_id = $this->model_extension_2checkout->getOrderStatusIdByName('failed');
$this->model_checkout_order->update(
(int)$post['vendor_order_id'],
$order_status_id,
'Status changed by 2Checkout INS'
);
} elseif ($post['message_type'] == 'FRAUD_STATUS_CHANGED' && $post['fraud_status'] == 'pass') {
$order_status_id = $this->model_extension_2checkout->getOrderStatusIdByName('processing');
$this->model_checkout_order->update(
(int)$post['vendor_order_id'],
$order_status_id,
'Status changed by 2Checkout INS'
);
} elseif ($post['message_type'] == 'SHIP_STATUS_CHANGED' && $post['ship_status'] == 'shipped') {
$order_status_id = $this->model_extension_2checkout->getOrderStatusIdByName('complete');
$this->model_checkout_order->update(
(int)$post['vendor_order_id'],
$order_status_id,
'Status changed by 2Checkout INS'
);
} else {
redirect($this->html->getSecureURL('checkout/confirm'));
}
}
public function pending_payment()
{
$this->addChild('common/head', 'head', 'common/head.tpl');
$this->addChild('common/footer', 'footer', 'common/footer.tpl');
$this->document->setTitle('waiting for payment');
$this->view->assign('text_message', 'waiting for payment confirmation');
$this->view->assign('text_redirecting', 'redirecting');
$this->view->assign('test_url', $this->html->getSecureURL('r/extension/2checkout/is_confirmed'));
$this->view->assign('success_url', $this->html->getSecureURL('checkout/success'));
$this->processTemplate('responses/pending_ipn.tpl');
}
public function is_confirmed()
{
$order_id = (int)$this->session->data['order_id'];
if (!$order_id) {
$result = true;
} else {
$this->loadModel('checkout/order');
$order_info = $this->model_checkout_order->getOrder($order_id);
//do nothing if order confirmed or it's not created with paypal standart
if ((int)$order_info['order_status_id'] != 0
|| $order_info['payment_method_key'] != '2checkout'
) {
$result = true;
} else {
$result = false;
}
}
$this->load->library('json');
$this->response->addJSONHeader();
$this->response->setOutput(AJson::encode(array('result' => $result)));
}
}