1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
$Id$ |
4
|
|
|
|
5
|
|
|
osCommerce, Open Source E-Commerce Solutions |
6
|
|
|
http://www.oscommerce.com |
7
|
|
|
|
8
|
|
|
Copyright (c) 2014 osCommerce |
9
|
|
|
|
10
|
|
|
Released under the GNU General Public License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
if ( !class_exists('OSCOM_PayPal') ) { |
14
|
|
|
include(DIR_FS_CATALOG . 'includes/apps/paypal/OSCOM_PayPal.php'); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
class paypal_express { |
18
|
|
|
var $code, $title, $description, $enabled, $_app; |
19
|
|
|
|
20
|
|
|
function paypal_express() { |
21
|
|
|
global $PHP_SELF, $order, $payment, $request_type; |
22
|
|
|
|
23
|
|
|
$this->_app = new OSCOM_PayPal(); |
24
|
|
|
$this->_app->loadLanguageFile('modules/EC/EC.php'); |
25
|
|
|
|
26
|
|
|
$this->signature = 'paypal|paypal_express|' . $this->_app->getVersion() . '|2.3'; |
|
|
|
|
27
|
|
|
$this->api_version = $this->_app->getApiVersion(); |
|
|
|
|
28
|
|
|
|
29
|
|
|
$this->code = 'paypal_express'; |
30
|
|
|
$this->title = $this->_app->getDef('module_ec_title'); |
31
|
|
|
$this->public_title = $this->_app->getDef('module_ec_public_title'); |
|
|
|
|
32
|
|
|
$this->description = '<div align="center">' . $this->_app->drawButton($this->_app->getDef('module_ec_legacy_admin_app_button'), tep_href_link('paypal.php', 'action=configure&module=EC'), 'primary', null, true) . '</div>'; |
33
|
|
|
$this->sort_order = defined('OSCOM_APP_PAYPAL_EC_SORT_ORDER') ? OSCOM_APP_PAYPAL_EC_SORT_ORDER : 0; |
|
|
|
|
34
|
|
|
$this->enabled = defined('OSCOM_APP_PAYPAL_EC_STATUS') && in_array(OSCOM_APP_PAYPAL_EC_STATUS, array('1', '0')) ? true : false; |
35
|
|
|
$this->order_status = defined('OSCOM_APP_PAYPAL_EC_ORDER_STATUS_ID') && ((int)OSCOM_APP_PAYPAL_EC_ORDER_STATUS_ID > 0) ? (int)OSCOM_APP_PAYPAL_EC_ORDER_STATUS_ID : 0; |
|
|
|
|
36
|
|
|
|
37
|
|
|
if ( defined('OSCOM_APP_PAYPAL_EC_STATUS') ) { |
38
|
|
|
if ( OSCOM_APP_PAYPAL_EC_STATUS == '0' ) { |
39
|
|
|
$this->title .= ' [Sandbox]'; |
40
|
|
|
$this->public_title .= ' (' . $this->code . '; Sandbox)'; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ( !function_exists('curl_init') ) { |
45
|
|
|
$this->description .= '<div class="secWarning">' . $this->_app->getDef('module_ec_error_curl') . '</div>'; |
46
|
|
|
|
47
|
|
|
$this->enabled = false; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
if ( $this->enabled === true ) { |
|
|
|
|
51
|
|
|
if ( OSCOM_APP_PAYPAL_GATEWAY == '1' ) { // PayPal |
52
|
|
|
if ( !$this->_app->hasCredentials('EC') ) { |
53
|
|
|
$this->description .= '<div class="secWarning">' . $this->_app->getDef('module_ec_error_credentials') . '</div>'; |
54
|
|
|
|
55
|
|
|
$this->enabled = false; |
56
|
|
|
} |
57
|
|
|
} else { // Payflow |
58
|
|
|
if ( !$this->_app->hasCredentials('EC', 'payflow') ) { |
59
|
|
|
$this->description .= '<div class="secWarning">' . $this->_app->getDef('module_ec_error_credentials_payflow') . '</div>'; |
60
|
|
|
|
61
|
|
|
$this->enabled = false; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ( $this->enabled === true ) { |
67
|
|
|
if ( isset($order) && is_object($order) ) { |
68
|
|
|
$this->update_status(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if ( defined('FILENAME_SHOPPING_CART') && (basename($PHP_SELF) == FILENAME_SHOPPING_CART) ) { |
73
|
|
|
if ( (OSCOM_APP_PAYPAL_GATEWAY == '1') && (OSCOM_APP_PAYPAL_EC_CHECKOUT_FLOW == '1') ) { |
74
|
|
|
if ( isset($request_type) && ($request_type != 'SSL') && (ENABLE_SSL == true) ) { |
|
|
|
|
75
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, tep_get_all_get_params(), 'SSL')); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
header('X-UA-Compatible: IE=edge', true); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
// When changing the shipping address due to no shipping rates being available, head straight to the checkout confirmation page |
83
|
|
|
if ( defined('FILENAME_CHECKOUT_PAYMENT') && (basename($PHP_SELF) == FILENAME_CHECKOUT_PAYMENT) && tep_session_is_registered('appPayPalEcRightTurn') ) { |
84
|
|
|
tep_session_unregister('appPayPalEcRightTurn'); |
85
|
|
|
|
86
|
|
|
if ( tep_session_is_registered('payment') && ($payment == $this->code) ) { |
87
|
|
|
tep_redirect(tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL')); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
View Code Duplication |
function update_status() { |
|
|
|
|
93
|
|
|
global $order; |
94
|
|
|
|
95
|
|
|
if ( ($this->enabled == true) && ((int)OSCOM_APP_PAYPAL_EC_ZONE > 0) ) { |
|
|
|
|
96
|
|
|
$check_flag = false; |
97
|
|
|
$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . OSCOM_APP_PAYPAL_EC_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); |
98
|
|
|
while ($check = tep_db_fetch_array($check_query)) { |
99
|
|
|
if ($check['zone_id'] < 1) { |
100
|
|
|
$check_flag = true; |
101
|
|
|
break; |
102
|
|
|
} elseif ($check['zone_id'] == $order->delivery['zone_id']) { |
103
|
|
|
$check_flag = true; |
104
|
|
|
break; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if ($check_flag == false) { |
|
|
|
|
109
|
|
|
$this->enabled = false; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
function checkout_initialization_method() { |
115
|
|
|
global $cart; |
116
|
|
|
|
117
|
|
|
$string = ''; |
118
|
|
|
|
119
|
|
|
if (OSCOM_APP_PAYPAL_GATEWAY == '1') { |
120
|
|
|
if (OSCOM_APP_PAYPAL_EC_CHECKOUT_FLOW == '0') { |
121
|
|
|
if (OSCOM_APP_PAYPAL_EC_CHECKOUT_IMAGE == '1') { |
122
|
|
|
if (OSCOM_APP_PAYPAL_EC_STATUS == '1') { |
123
|
|
|
$image_button = 'https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image'; |
124
|
|
|
} else { |
125
|
|
|
$image_button = 'https://fpdbs.sandbox.paypal.com/dynamicimageweb?cmd=_dynamic-image'; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$params = array('locale=' . $this->_app->getDef('module_ec_button_locale')); |
129
|
|
|
|
130
|
|
|
if ( $this->_app->hasCredentials('EC') ) { |
131
|
|
|
$response_array = $this->_app->getApiResult('EC', 'GetPalDetails'); |
132
|
|
|
|
133
|
|
|
if ( isset($response_array['PAL']) ) { |
134
|
|
|
$params[] = 'pal=' . $response_array['PAL']; |
135
|
|
|
$params[] = 'ordertotal=' . $this->_app->formatCurrencyRaw($cart->show_total()); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
if ( !empty($params) ) { |
140
|
|
|
$image_button .= '&' . implode('&', $params); |
141
|
|
|
} |
142
|
|
|
} else { |
143
|
|
|
$image_button = $this->_app->getDef('module_ec_button_url'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$button_title = tep_output_string_protected($this->_app->getDef('module_ec_button_title')); |
147
|
|
|
|
148
|
|
|
if ( OSCOM_APP_PAYPAL_EC_STATUS == '0' ) { |
149
|
|
|
$button_title .= ' (' . $this->code . '; Sandbox)'; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$string .= '<a href="' . tep_href_link('ext/modules/payment/paypal/express.php', '', 'SSL') . '"><img src="' . $image_button . '" border="0" alt="" title="' . $button_title . '" /></a>'; |
153
|
|
|
} else { |
154
|
|
|
$string .= '<script src="https://www.paypalobjects.com/api/checkout.js" async></script>'; |
155
|
|
|
|
156
|
|
|
$merchant_id = (OSCOM_APP_PAYPAL_EC_STATUS === '1') ? OSCOM_APP_PAYPAL_LIVE_MERCHANT_ID : OSCOM_APP_PAYPAL_SANDBOX_MERCHANT_ID; |
157
|
|
|
if (empty($merchant_id)) $merchant_id = ' '; |
158
|
|
|
|
159
|
|
|
$server = (OSCOM_APP_PAYPAL_EC_STATUS === '1') ? 'production' : 'sandbox'; |
160
|
|
|
|
161
|
|
|
$ppecset_url = tep_href_link('ext/modules/payment/paypal/express.php', 'format=json', 'SSL'); |
162
|
|
|
|
163
|
|
View Code Duplication |
switch (OSCOM_APP_PAYPAL_EC_INCONTEXT_BUTTON_COLOR) { |
|
|
|
|
164
|
|
|
case '3': |
165
|
|
|
$button_color = 'silver'; |
166
|
|
|
break; |
167
|
|
|
|
168
|
|
|
case '2': |
169
|
|
|
$button_color = 'blue'; |
170
|
|
|
break; |
171
|
|
|
|
172
|
|
|
case '1': |
173
|
|
|
default: |
174
|
|
|
$button_color = 'gold'; |
175
|
|
|
break; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
View Code Duplication |
switch (OSCOM_APP_PAYPAL_EC_INCONTEXT_BUTTON_SIZE) { |
|
|
|
|
179
|
|
|
case '3': |
180
|
|
|
$button_size = 'medium'; |
181
|
|
|
break; |
182
|
|
|
|
183
|
|
|
case '1': |
184
|
|
|
$button_size = 'tiny'; |
185
|
|
|
break; |
186
|
|
|
|
187
|
|
|
case '2': |
188
|
|
|
default: |
189
|
|
|
$button_size = 'small'; |
190
|
|
|
break; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
switch (OSCOM_APP_PAYPAL_EC_INCONTEXT_BUTTON_SHAPE) { |
194
|
|
|
case '2': |
195
|
|
|
$button_shape = 'rect'; |
196
|
|
|
break; |
197
|
|
|
|
198
|
|
|
case '1': |
199
|
|
|
default: |
200
|
|
|
$button_shape = 'pill'; |
201
|
|
|
break; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
$string .= <<<EOD |
205
|
|
|
<span id="ppECButton"></span> |
206
|
|
|
<script> |
207
|
|
|
if ( typeof jQuery == 'undefined' ) { |
208
|
|
|
document.write('<scr' + 'ipt src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></scr' + 'ipt>'); |
209
|
|
|
} |
210
|
|
|
</script> |
211
|
|
|
<script> |
212
|
|
|
window.paypalCheckoutReady = function () { |
213
|
|
|
paypal.checkout.setup('${merchant_id}', { |
214
|
|
|
environment: '{$server}', |
215
|
|
|
buttons: [ |
216
|
|
|
{ |
217
|
|
|
container: 'ppECButton', |
218
|
|
|
color: '${button_color}', |
219
|
|
|
size: '${button_size}', |
220
|
|
|
shape: '${button_shape}', |
221
|
|
|
click: function (event) { |
222
|
|
|
event.preventDefault(); |
223
|
|
|
|
224
|
|
|
paypal.checkout.initXO(); |
225
|
|
|
|
226
|
|
|
var action = $.getJSON('${ppecset_url}'); |
227
|
|
|
|
228
|
|
|
action.done(function (data) { |
229
|
|
|
paypal.checkout.startFlow(data.token); |
230
|
|
|
}); |
231
|
|
|
|
232
|
|
|
action.fail(function () { |
233
|
|
|
paypal.checkout.closeFlow(); |
234
|
|
|
}); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
] |
238
|
|
|
}); |
239
|
|
|
}; |
240
|
|
|
</script> |
241
|
|
|
EOD; |
242
|
|
|
} |
243
|
|
|
} else { |
244
|
|
|
$image_button = $this->_app->getDef('module_ec_button_url'); |
245
|
|
|
|
246
|
|
|
$button_title = tep_output_string_protected($this->_app->getDef('module_ec_button_title')); |
247
|
|
|
|
248
|
|
|
if (OSCOM_APP_PAYPAL_EC_STATUS == '0') { |
249
|
|
|
$button_title .= ' (' . $this->code . '; Sandbox)'; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
$string .= '<a href="' . tep_href_link('ext/modules/payment/paypal/express.php', '', 'SSL') . '"><img src="' . $image_button . '" border="0" alt="" title="' . $button_title . '" /></a>'; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
return $string; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
function javascript_validation() { |
259
|
|
|
return false; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
function selection() { |
263
|
|
|
return array('id' => $this->code, |
264
|
|
|
'module' => $this->public_title); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
function pre_confirmation_check() { |
268
|
|
|
global $appPayPalEcResult, $appPayPalEcSecret, $messageStack, $order; |
269
|
|
|
|
270
|
|
|
if ( !tep_session_is_registered('appPayPalEcResult') ) { |
271
|
|
|
tep_redirect(tep_href_link('ext/modules/payment/paypal/express.php', '', 'SSL')); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
if ( OSCOM_APP_PAYPAL_GATEWAY == '1' ) { // PayPal |
275
|
|
View Code Duplication |
if ( !in_array($appPayPalEcResult['ACK'], array('Success', 'SuccessWithWarning')) ) { |
|
|
|
|
276
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . stripslashes($appPayPalEcResult['L_LONGMESSAGE0']), 'SSL')); |
277
|
|
|
} elseif ( !tep_session_is_registered('appPayPalEcSecret') || ($appPayPalEcResult['PAYMENTREQUEST_0_CUSTOM'] != $appPayPalEcSecret) ) { |
278
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, '', 'SSL')); |
279
|
|
|
} |
280
|
|
View Code Duplication |
} else { // Payflow |
|
|
|
|
281
|
|
|
if ($appPayPalEcResult['RESULT'] != '0') { |
282
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . urlencode($appPayPalEcResult['OSCOM_ERROR_MESSAGE']), 'SSL')); |
283
|
|
|
} elseif ( !tep_session_is_registered('appPayPalEcSecret') || ($appPayPalEcResult['CUSTOM'] != $appPayPalEcSecret) ) { |
284
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, '', 'SSL')); |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
$order->info['payment_method'] = '<img src="https://www.paypalobjects.com/webstatic/mktg/Logo/pp-logo-100px.png" border="0" alt="PayPal Logo" style="padding: 3px;" />'; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
function confirmation() { |
292
|
|
|
global $comments; |
293
|
|
|
|
294
|
|
|
if (!isset($comments)) { |
295
|
|
|
$comments = null; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
$confirmation = false; |
299
|
|
|
|
300
|
|
|
if (empty($comments)) { |
301
|
|
|
$confirmation = array('fields' => array(array('title' => $this->_app->getDef('module_ec_field_comments'), |
302
|
|
|
'field' => tep_draw_textarea_field('ppecomments', 'soft', '60', '5', $comments)))); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
return $confirmation; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
function process_button() { |
309
|
|
|
return false; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
function before_process() { |
313
|
|
|
if ( OSCOM_APP_PAYPAL_GATEWAY == '1' ) { |
314
|
|
|
$this->before_process_paypal(); |
315
|
|
|
} else { |
316
|
|
|
$this->before_process_payflow(); |
317
|
|
|
} |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
function before_process_paypal() { |
321
|
|
|
global $customer_id, $order, $sendto, $appPayPalEcResult, $appPayPalEcSecret, $response_array, $HTTP_POST_VARS, $comments; |
322
|
|
|
|
323
|
|
|
if ( !tep_session_is_registered('appPayPalEcResult') ) { |
324
|
|
|
tep_redirect(tep_href_link('ext/modules/payment/paypal/express.php', '', 'SSL')); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
View Code Duplication |
if ( in_array($appPayPalEcResult['ACK'], array('Success', 'SuccessWithWarning')) ) { |
|
|
|
|
328
|
|
|
if ( !tep_session_is_registered('appPayPalEcSecret') || ($appPayPalEcResult['PAYMENTREQUEST_0_CUSTOM'] != $appPayPalEcSecret) ) { |
329
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, '', 'SSL')); |
330
|
|
|
} |
331
|
|
|
} else { |
332
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . stripslashes($appPayPalEcResult['L_LONGMESSAGE0']), 'SSL')); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
View Code Duplication |
if (empty($comments)) { |
|
|
|
|
336
|
|
|
if (isset($HTTP_POST_VARS['ppecomments']) && tep_not_null($HTTP_POST_VARS['ppecomments'])) { |
337
|
|
|
$comments = tep_db_prepare_input($HTTP_POST_VARS['ppecomments']); |
338
|
|
|
|
339
|
|
|
$order->info['comments'] = $comments; |
340
|
|
|
} |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
$params = array('TOKEN' => $appPayPalEcResult['TOKEN'], |
344
|
|
|
'PAYERID' => $appPayPalEcResult['PAYERID'], |
345
|
|
|
'PAYMENTREQUEST_0_AMT' => $this->_app->formatCurrencyRaw($order->info['total']), |
346
|
|
|
'PAYMENTREQUEST_0_CURRENCYCODE' => $order->info['currency']); |
347
|
|
|
|
348
|
|
|
if (is_numeric($sendto) && ($sendto > 0)) { |
349
|
|
|
$params['PAYMENTREQUEST_0_SHIPTONAME'] = $order->delivery['firstname'] . ' ' . $order->delivery['lastname']; |
350
|
|
|
$params['PAYMENTREQUEST_0_SHIPTOSTREET'] = $order->delivery['street_address']; |
351
|
|
|
$params['PAYMENTREQUEST_0_SHIPTOCITY'] = $order->delivery['city']; |
352
|
|
|
$params['PAYMENTREQUEST_0_SHIPTOSTATE'] = tep_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['state']); |
353
|
|
|
$params['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $order->delivery['country']['iso_code_2']; |
354
|
|
|
$params['PAYMENTREQUEST_0_SHIPTOZIP'] = $order->delivery['postcode']; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
$response_array = $this->_app->getApiResult('EC', 'DoExpressCheckoutPayment', $params); |
358
|
|
|
|
359
|
|
|
if ( !in_array($response_array['ACK'], array('Success', 'SuccessWithWarning')) ) { |
360
|
|
|
if ( $response_array['L_ERRORCODE0'] == '10486' ) { |
361
|
|
|
if ( OSCOM_APP_PAYPAL_EC_STATUS == '1' ) { |
362
|
|
|
$paypal_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout'; |
363
|
|
|
} else { |
364
|
|
|
$paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout'; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
$paypal_url .= '&token=' . $appPayPalEcResult['TOKEN']; |
368
|
|
|
|
369
|
|
|
tep_redirect($paypal_url); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . stripslashes($response_array['L_LONGMESSAGE0']), 'SSL')); |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
function before_process_payflow() { |
377
|
|
|
global $customer_id, $order, $sendto, $appPayPalEcResult, $appPayPalEcSecret, $response_array, $HTTP_POST_VARS, $comments; |
378
|
|
|
|
379
|
|
|
if ( !tep_session_is_registered('appPayPalEcResult') ) { |
380
|
|
|
tep_redirect(tep_href_link('ext/modules/payment/paypal/express.php', '', 'SSL')); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
View Code Duplication |
if ( $appPayPalEcResult['RESULT'] == '0' ) { |
|
|
|
|
384
|
|
|
if ( !tep_session_is_registered('appPayPalEcSecret') || ($appPayPalEcResult['CUSTOM'] != $appPayPalEcSecret) ) { |
385
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, '', 'SSL')); |
386
|
|
|
} |
387
|
|
|
} else { |
388
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . urlencode($appPayPalEcResult['OSCOM_ERROR_MESSAGE']), 'SSL')); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
View Code Duplication |
if ( empty($comments) ) { |
|
|
|
|
392
|
|
|
if ( isset($HTTP_POST_VARS['ppecomments']) && tep_not_null($HTTP_POST_VARS['ppecomments']) ) { |
393
|
|
|
$comments = tep_db_prepare_input($HTTP_POST_VARS['ppecomments']); |
394
|
|
|
|
395
|
|
|
$order->info['comments'] = $comments; |
396
|
|
|
} |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
$params = array('EMAIL' => $order->customer['email_address'], |
400
|
|
|
'TOKEN' => $appPayPalEcResult['TOKEN'], |
401
|
|
|
'PAYERID' => $appPayPalEcResult['PAYERID'], |
402
|
|
|
'AMT' => $this->_app->formatCurrencyRaw($order->info['total']), |
403
|
|
|
'CURRENCY' => $order->info['currency']); |
404
|
|
|
|
405
|
|
|
if ( is_numeric($sendto) && ($sendto > 0) ) { |
406
|
|
|
$params['SHIPTONAME'] = $order->delivery['firstname'] . ' ' . $order->delivery['lastname']; |
407
|
|
|
$params['SHIPTOSTREET'] = $order->delivery['street_address']; |
408
|
|
|
$params['SHIPTOCITY'] = $order->delivery['city']; |
409
|
|
|
$params['SHIPTOSTATE'] = tep_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['state']); |
410
|
|
|
$params['SHIPTOCOUNTRY'] = $order->delivery['country']['iso_code_2']; |
411
|
|
|
$params['SHIPTOZIP'] = $order->delivery['postcode']; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
$response_array = $this->_app->getApiResult('EC', 'PayflowDoExpressCheckoutPayment', $params); |
415
|
|
|
|
416
|
|
|
if ( $response_array['RESULT'] != '0' ) { |
417
|
|
|
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . urlencode($response_array['OSCOM_ERROR_MESSAGE']), 'SSL')); |
418
|
|
|
} |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
function after_process() { |
422
|
|
|
if ( OSCOM_APP_PAYPAL_GATEWAY == '1' ) { |
423
|
|
|
$this->after_process_paypal(); |
424
|
|
|
} else { |
425
|
|
|
$this->after_process_payflow(); |
426
|
|
|
} |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
function after_process_paypal() { |
430
|
|
|
global $response_array, $insert_id, $appPayPalEcResult; |
431
|
|
|
|
432
|
|
|
$pp_result = 'Transaction ID: ' . tep_output_string_protected($response_array['PAYMENTINFO_0_TRANSACTIONID']) . "\n" . |
433
|
|
|
'Payer Status: ' . tep_output_string_protected($appPayPalEcResult['PAYERSTATUS']) . "\n" . |
434
|
|
|
'Address Status: ' . tep_output_string_protected($appPayPalEcResult['ADDRESSSTATUS']) . "\n" . |
435
|
|
|
'Payment Status: ' . tep_output_string_protected($response_array['PAYMENTINFO_0_PAYMENTSTATUS']) . "\n" . |
436
|
|
|
'Payment Type: ' . tep_output_string_protected($response_array['PAYMENTINFO_0_PAYMENTTYPE']) . "\n" . |
437
|
|
|
'Pending Reason: ' . tep_output_string_protected($response_array['PAYMENTINFO_0_PENDINGREASON']); |
438
|
|
|
|
439
|
|
|
$sql_data_array = array('orders_id' => $insert_id, |
440
|
|
|
'orders_status_id' => OSCOM_APP_PAYPAL_TRANSACTIONS_ORDER_STATUS_ID, |
441
|
|
|
'date_added' => 'now()', |
442
|
|
|
'customer_notified' => '0', |
443
|
|
|
'comments' => $pp_result); |
444
|
|
|
|
445
|
|
|
tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); |
446
|
|
|
|
447
|
|
|
tep_session_unregister('appPayPalEcResult'); |
448
|
|
|
tep_session_unregister('appPayPalEcSecret'); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
function after_process_payflow() { |
452
|
|
|
global $response_array, $insert_id, $appPayPalEcResult; |
453
|
|
|
|
454
|
|
|
$pp_result = 'Transaction ID: ' . tep_output_string_protected($response_array['PNREF']) . "\n" . |
455
|
|
|
'Gateway: Payflow' . "\n" . |
456
|
|
|
'PayPal ID: ' . tep_output_string_protected($response_array['PPREF']) . "\n" . |
457
|
|
|
'Payer Status: ' . tep_output_string_protected($appPayPalEcResult['PAYERSTATUS']) . "\n" . |
458
|
|
|
'Address Status: ' . tep_output_string_protected($appPayPalEcResult['ADDRESSSTATUS']) . "\n" . |
459
|
|
|
'Payment Status: ' . tep_output_string_protected($response_array['PENDINGREASON']) . "\n" . |
460
|
|
|
'Payment Type: ' . tep_output_string_protected($response_array['PAYMENTTYPE']) . "\n" . |
461
|
|
|
'Response: ' . tep_output_string_protected($response_array['RESPMSG']) . "\n"; |
462
|
|
|
|
463
|
|
|
$sql_data_array = array('orders_id' => $insert_id, |
464
|
|
|
'orders_status_id' => OSCOM_APP_PAYPAL_TRANSACTIONS_ORDER_STATUS_ID, |
465
|
|
|
'date_added' => 'now()', |
466
|
|
|
'customer_notified' => '0', |
467
|
|
|
'comments' => $pp_result); |
468
|
|
|
|
469
|
|
|
tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); |
470
|
|
|
|
471
|
|
|
tep_session_unregister('appPayPalEcResult'); |
472
|
|
|
tep_session_unregister('appPayPalEcSecret'); |
473
|
|
|
|
474
|
|
|
// Manually call PayflowInquiry to retrieve more details about the transaction and to allow admin post-transaction actions |
475
|
|
|
$response = $this->_app->getApiResult('APP', 'PayflowInquiry', array('ORIGID' => $response_array['PNREF'])); |
476
|
|
|
|
477
|
|
|
if ( isset($response['RESULT']) && ($response['RESULT'] == '0') ) { |
478
|
|
|
$result = 'Transaction ID: ' . tep_output_string_protected($response['ORIGPNREF']) . "\n" . |
479
|
|
|
'Gateway: Payflow' . "\n"; |
480
|
|
|
|
481
|
|
|
$pending_reason = $response['TRANSSTATE']; |
482
|
|
|
$payment_status = null; |
483
|
|
|
|
484
|
|
View Code Duplication |
switch ( $response['TRANSSTATE'] ) { |
|
|
|
|
485
|
|
|
case '3': |
486
|
|
|
$pending_reason = 'authorization'; |
487
|
|
|
$payment_status = 'Pending'; |
488
|
|
|
break; |
489
|
|
|
|
490
|
|
|
case '4': |
491
|
|
|
$pending_reason = 'other'; |
492
|
|
|
$payment_status = 'In-Progress'; |
493
|
|
|
break; |
494
|
|
|
|
495
|
|
|
case '6': |
496
|
|
|
$pending_reason = 'scheduled'; |
497
|
|
|
$payment_status = 'Pending'; |
498
|
|
|
break; |
499
|
|
|
|
500
|
|
|
case '8': |
501
|
|
|
case '9': |
502
|
|
|
$pending_reason = 'None'; |
503
|
|
|
$payment_status = 'Completed'; |
504
|
|
|
break; |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
if ( isset($payment_status) ) { |
508
|
|
|
$result .= 'Payment Status: ' . tep_output_string_protected($payment_status) . "\n"; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
$result .= 'Pending Reason: ' . tep_output_string_protected($pending_reason) . "\n"; |
512
|
|
|
|
513
|
|
|
switch ( $response['AVSADDR'] ) { |
514
|
|
|
case 'Y': |
515
|
|
|
$result .= 'AVS Address: Match' . "\n"; |
516
|
|
|
break; |
517
|
|
|
|
518
|
|
|
case 'N': |
519
|
|
|
$result .= 'AVS Address: No Match' . "\n"; |
520
|
|
|
break; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
View Code Duplication |
switch ( $response['AVSZIP'] ) { |
|
|
|
|
524
|
|
|
case 'Y': |
525
|
|
|
$result .= 'AVS ZIP: Match' . "\n"; |
526
|
|
|
break; |
527
|
|
|
|
528
|
|
|
case 'N': |
529
|
|
|
$result .= 'AVS ZIP: No Match' . "\n"; |
530
|
|
|
break; |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
switch ( $response['IAVS'] ) { |
534
|
|
|
case 'Y': |
535
|
|
|
$result .= 'IAVS: International' . "\n"; |
536
|
|
|
break; |
537
|
|
|
|
538
|
|
|
case 'N': |
539
|
|
|
$result .= 'IAVS: USA' . "\n"; |
540
|
|
|
break; |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
switch ( $response['CVV2MATCH'] ) { |
544
|
|
|
case 'Y': |
545
|
|
|
$result .= 'CVV2: Match' . "\n"; |
546
|
|
|
break; |
547
|
|
|
|
548
|
|
|
case 'N': |
549
|
|
|
$result .= 'CVV2: No Match' . "\n"; |
550
|
|
|
break; |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
$sql_data_array = array('orders_id' => $insert_id, |
554
|
|
|
'orders_status_id' => OSCOM_APP_PAYPAL_TRANSACTIONS_ORDER_STATUS_ID, |
555
|
|
|
'date_added' => 'now()', |
556
|
|
|
'customer_notified' => '0', |
557
|
|
|
'comments' => $result); |
558
|
|
|
|
559
|
|
|
tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); |
560
|
|
|
} |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
function get_error() { |
564
|
|
|
return false; |
565
|
|
|
} |
566
|
|
|
|
567
|
|
View Code Duplication |
function check() { |
|
|
|
|
568
|
|
|
$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'OSCOM_APP_PAYPAL_EC_STATUS'"); |
569
|
|
|
if ( tep_db_num_rows($check_query) ) { |
570
|
|
|
$check = tep_db_fetch_array($check_query); |
571
|
|
|
|
572
|
|
|
return tep_not_null($check['configuration_value']); |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
return false; |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
function install() { |
579
|
|
|
tep_redirect(tep_href_link('paypal.php', 'action=configure&subaction=install&module=EC')); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
function remove() { |
583
|
|
|
tep_redirect(tep_href_link('paypal.php', 'action=configure&subaction=uninstall&module=EC')); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
function keys() { |
587
|
|
|
return array('OSCOM_APP_PAYPAL_EC_SORT_ORDER'); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
function getProductType($id, $attributes) { |
591
|
|
|
foreach ( $attributes as $a ) { |
592
|
|
|
$virtual_check_query = tep_db_query("select pad.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$id . "' and pa.options_values_id = '" . (int)$a['value_id'] . "' and pa.products_attributes_id = pad.products_attributes_id limit 1"); |
593
|
|
|
|
594
|
|
|
if ( tep_db_num_rows($virtual_check_query) == 1 ) { |
595
|
|
|
return 'Digital'; |
596
|
|
|
} |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
return 'Physical'; |
600
|
|
|
} |
601
|
|
|
} |
602
|
|
|
?> |
|
|
|
|
603
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: