This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PaymentViveum.php
executable file
·263 lines (220 loc) · 8.04 KB
/
PaymentViveum.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
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
<?php
/**
* Extension for Contao Open Source CMS
*
* Copyright (C) 2013 terminal42 gmbh
*
* @package isotope_viveum
* @link http://www.terminal42.ch
* @license http://opensource.org/licenses/lgpl-3.0.html LGPL
*/
class PaymentViveum extends IsotopePayment
{
/**
* SHA-OUT relevant fields
* @var array
*/
private static $arrShaOut = array
(
'AAVADDRESS',
'AAVCHECK',
'AAVZIP',
'ACCEPTANCE',
'ALIAS',
'AMOUNT',
'BIN',
'BRAND',
'CARDNO',
'CCCTY',
'CN',
'COMPLUS',
'CREATION_STATUS',
'CURRENCY',
'CVCCHECK',
'DCC_COMMPERCENTAGE',
'DCC_CONVAMOUNT',
'DCC_CONVCCY',
'DCC_EXCHRATE',
'DCC_EXCHRATESOURCE',
'DCC_EXCHRATETS',
'DCC_INDICATOR',
'DCC_MARGINPERCENTAGE',
'DCC_VALIDHOURS',
'DIGESTCARDNO',
'ECI',
'ED',
'ENCCARDNO',
'IP',
'IPCTY',
'NBREMAILUSAGE',
'NBRIPUSAGE',
'NBRIPUSAGE_ALLTX',
'NBRUSAGE',
'NCERROR',
'ORDERID',
'PAYID',
'PM',
'SCO_CATEGORY',
'SCORING',
'STATUS',
'SUBBRAND',
'SUBSCRIPTION_ID',
'TRXDATE',
'VC'
);
/**
* Process payment on confirmation page.
*/
public function processPayment()
{
if ($this->Input->get('NCERROR') > 0) {
$this->log('Order ID "' . $this->Input->get('orderID') . '" has NCERROR ' . $this->Input->get('NCERROR'), __METHOD__, TL_ERROR);
return false;
}
$objOrder = new IsotopeOrder();
if (!$objOrder->findBy('id', $this->Input->get('orderID'))) {
$this->log('Order ID "' . $this->Input->get('orderID') . '" not found', __METHOD__, TL_ERROR);
return false;
}
if (!$this->validateSHASign()) {
$this->log('Received invalid postsale data for order ID "' . $objOrder->id . '"', __METHOD__, TL_ERROR);
return false;
}
// Validate payment data
if ($objOrder->currency != $this->Input->post('currency') || $objOrder->grandTotal != $this->Input->post('amount')) {
$this->log('Postsale checkout manipulation in payment for Order ID ' . $objOrder->id . '!', __METHOD__, TL_ERROR);
$this->redirect($this->addToUrl('step=failed', true));
}
$objOrder->date_paid = time();
$objOrder->save();
return true;
}
/**
* Process post-sale request from the VIVEUM payment server.
*/
public function processPostSale()
{
$objOrder = new IsotopeOrder();
if (!$objOrder->findBy('id', $this->Input->post('orderID'))) {
$this->log('Order ID "' . $this->Input->post('orderID') . '" not found', __METHOD__, TL_ERROR);
return false;
}
if (!$this->validateSHASign()) {
$this->log('Received invalid postsale data for order ID "' . $objOrder->id . '"', __METHOD__, TL_ERROR);
return false;
}
// Validate payment data
if ($objOrder->currency != $this->Input->post('currency') || $objOrder->grandTotal != $this->Input->post('amount')) {
$this->log('Postsale checkout manipulation in payment for Order ID ' . $objOrder->id . '!', __METHOD__, TL_ERROR);
return false;
}
// Validate payment status
switch ($this->Input->post('STATUS')) {
case 9: // Zahlung beantragt (Authorize & Capture)
$objOrder->date_paid = time();
// no break
case 5: // Genehmigt (Authorize ohne Capture)
$intStatus = $this->new_order_status;
break;
case 41: // Unbekannter Wartezustand
case 51: // Genehmigung im Wartezustand
case 91: // Zahlung im Wartezustand
case 52: // Genehmigung nicht bekannt
case 92: // Zahlung unsicher
$objConfig = new IsotopeConfig();
if (!$objConfig->findBy('id', $objOrder->config_id)) {
$this->log('Config for Order ID ' . $objOrder->id . ' not found', __METHOD__, TL_ERROR);
return false;
}
$intStatus = $objConfig->orderstatus_error;
break;
case 0: // Ungültig / Unvollständig
case 1: // Zahlungsvorgang abgebrochen
case 2: // Genehmigung verweigert
case 4: // Gespeichert
case 93: // Bezahlung verweigert
default:
return false;
}
if (!$objOrder->checkout()) {
$this->log('Post-Sale checkout for Order ID "' . $objOrder->id . '" failed', __METHOD__, TL_ERROR);
return false;
}
$objOrder->updateOrderStatus($intStatus);
$objOrder->save();
return true;
}
/**
* Return the payment form.
* @return string
*/
public function checkoutForm()
{
$objOrder = new IsotopeOrder();
if (!$objOrder->findBy('cart_id', $this->Isotope->Cart->id)) {
$this->redirect($this->addToUrl('step=failed', true));
}
$objAddress = $this->Isotope->Cart->billingAddress;
$strFailedUrl = $this->Environment->base . $this->addToUrl('step=failed', true);
$arrParam = array
(
'PSPID' => $this->viveum_pspid,
'ORDERID' => $objOrder->id,
'AMOUNT' => round(($this->Isotope->Cart->grandTotal * 100)),
'CURRENCY' => $this->Isotope->Config->currency,
'LANGUAGE' => $GLOBALS['TL_LANGUAGE'] . '_' . strtoupper($GLOBALS['TL_LANGUAGE']),
'CN' => $objAddress->firstname . ' ' . $objAddress->lastname,
'EMAIL' => $objAddress->email,
'OWNERZIP' => $objAddress->postal,
'OWNERADDRESS' => $objAddress->street_1,
'OWNERADDRESS2' => $objAddress->street_2,
'OWNERCTY' => $objAddress->country,
'OWNERTOWN' => $objAddress->city,
'OWNERTELNO' => $objAddress->phone,
'ACCEPTURL' => $this->Environment->base . IsotopeFrontend::addQueryStringToUrl('uid=' . $objOrder->uniqid, $this->addToUrl('step=complete', true)),
'DECLINEURL' => $strFailedUrl,
'EXCEPTIONURL' => $strFailedUrl,
'BACKURL' => $this->Environment->base . $this->addToUrl('step=review', true),
'TP' => $this->viveum_dynamic_template ? $this->viveum_dynamic_template : '',
'PARAMPLUS' => 'mod=pay&id=' . $this->id,
);
// SHA-1 must be generated on alphabetically sorted keys.
ksort($arrParam);
$strSHASign = '';
foreach ($arrParam as $k => $v) {
if ($v == '')
continue;
$strSHASign .= $k . '=' . htmlspecialchars_decode($v) . $this->viveum_hash_in;
}
$arrParam['SHASIGN'] = strtoupper(sha1($strSHASign));
$objTemplate = new FrontendTemplate('iso_payment_viveum');
$objTemplate->action = 'https://viveum.v-psp.com/ncol/' . ($this->debug ? 'test' : 'prod') . '/orderstandard_utf8.asp';
$objTemplate->params = $arrParam;
$objTemplate->slabel = $GLOBALS['TL_LANG']['MSC']['pay_with_cc'][2];
$objTemplate->id = $this->id;
return $objTemplate->parse();
}
/**
* Validate SHA-OUT signature
*/
private function validateSHASign()
{
$strSHASign = '';
$arrParam = array();
foreach (array_keys($_POST) as $key) {
if (in_array(strtoupper($key), self::$arrShaOut)) {
$arrParam[$key] = $this->Input->post($key);
}
}
uksort($arrParam, 'strcasecmp');
foreach ($arrParam as $k => $v) {
if ($v == '')
continue;
$strSHASign .= strtoupper($k) . '=' . $v . $this->viveum_hash_out;
}
if ($this->Input->post('SHASIGN') == strtoupper(sha1($strSHASign))) {
return true;
}
return false;
}
}