Version Notes
Version 1.0.13 of the Onescan Payment Extension.
Changelog
---------------
1.0.13
Check Magento admin settings to determine whether prices sent to the Onescanner's device should include tax.
Improved efficiency of extension code.
Modified shipping tax calculation to round down so that the amount displayed on the Onescanner's device matches the amount calculated by Magento.
1.0.12
Check Magento database to determine whether country of delivery requires state/region to be present.
Added a new field to the configuration menu that allows the Magento store administrator to specify the message that is sent to the Onescanner's device if the state/region is not recognised.
In some circumstances, the wrong delivery method was being stored in the Magento database
1.0.11
Potential installation issue with some Magento instances fixed.
1.0.10
Purchase failure where delivery is to a country in which Magento requires state/region information to be present - fixed.
Configurable error message added if the Magento store cannot deliver the Onescanner's order to the address supplied by Onescan.
The incorrect URL was being used for the redirect after a successful order in some Magento store configurations - fixed.
1.0.9
Under certain circumstances, shipping charges were being added twice - fixed.
1.0.8
Incorrect country code used in some Magento installations - fixed.
Compatibility issue reported when installing into latest version of Magento - fixed.
1.0.7
Prevented jQuery conflict for older versions of Magento
1.0.6
Potential installation issue with some Magento instances fixed.
1.0.5
Allows merchant to specify the image that will be displayed on the device during a purchase.
Under certain circumstances the tax calculation was rounding incorrectly making a £0.01 difference between the actual payment and what was recorded in Magento - fixed.
1.0.4
Incorrect compatibility information shown on Magento Connect - fixed.
1.0.3
Corrected error in layout file preventing Onescan logo from being shown on the admin pages.
1.0.2
Incorrect postage applied where minimum order value applies. Fixed.
Tax missing from individual items in admin sales/orders list. Fixed.
Orders not marked as paid and invoice not created in admin. Fixed.
Onescan was being listed as payment method option on the standard checkout page, resulting in orders potentially being placed with no payment being taken. If a customer uses Onescan to pay, they never get to that part of the checkout process so it makes no sense to have Onescan listed as a payment method there. This has been removed so now the only way for Onescan to be selected as a payment method is for the padlock to be scanned as intended.
1.0.1
Fixed potential installation problem.
1.0.0
Initial version.
Release Info
Developer | Ensygnia |
Extension | Ensygnia_Onescan |
Version | 1.0.13 |
Comparing to | |
See all releases |
Code changes from version 1.0.12 to 1.0.13
@@ -1,578 +1,562 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Ensygnia Onescan extension
|
4 |
-
Copyright (C) 2014 Ensygnia Ltd
|
5 |
-
|
6 |
-
This program is free software: you can redistribute it and/or modify
|
7 |
-
it under the terms of the GNU General Public License as published by
|
8 |
-
the Free Software Foundation, either version 3 of the License, or
|
9 |
-
(at your option) any later version.
|
10 |
-
|
11 |
-
This program is distributed in the hope that it will be useful,
|
12 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
-
GNU General Public License for more details.
|
15 |
-
|
16 |
-
You should have received a copy of the GNU General Public License
|
17 |
-
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 |
-
*/
|
19 |
-
require_once(Mage::getBaseDir('lib') . "/Onescan/login/LocalDataFactory.php");
|
20 |
-
|
21 |
-
class Ensygnia_Onescan_Model_Callback_Purchase extends Ensygnia_Onescan_Model_Callback_Abstract {
|
22 |
-
public function getConfigReference() {
|
23 |
-
return 'onescan/config_purchase';
|
24 |
-
}
|
25 |
-
|
26 |
-
//Callback entry point
|
27 |
-
public function handle() {
|
28 |
-
$settings = $this->getConfig()->getSettings();
|
29 |
-
if (isset($_GET['basket'])) {
|
30 |
-
$settings->OnescanCallbackURL .= '?basket=' . $_GET['basket'];
|
31 |
-
}
|
32 |
-
|
33 |
-
$onescanMessage = Onescan::ReadMessage($settings);
|
34 |
-
//Mage::log('Message: ' . print_r($onescanMessage,true));
|
35 |
-
|
36 |
-
$purchaseProcess = new OnescanPurchaseProcess();
|
37 |
-
$nextAction = $purchaseProcess->DecodePurchaseMessage($onescanMessage);
|
38 |
-
$sessionState = $purchaseProcess->SessionState();
|
39 |
-
|
40 |
-
switch ($nextAction)
|
41 |
-
{
|
42 |
-
case PurchaseAction::StartPayment:
|
43 |
-
//Mage::log('Start Payment');
|
44 |
-
$purchasePayload = $this->BuildPurchasePayload($sessionState->SessionID);
|
45 |
-
$purchaseProcess->ProcessStartPurchase($purchasePayload);
|
46 |
-
break;
|
47 |
-
case PurchaseAction::AdditionalCharges:
|
48 |
-
//Mage::log('Additional Charges');
|
49 |
-
$purchaseProcess->DecodeAdditionalChargesRequest($onescanMessage);
|
50 |
-
$additionalChargesPayload = $this->BuildAdditionalCharges($purchaseProcess);
|
51 |
-
$purchaseProcess->ProcessAdditionalCharges($additionalChargesPayload);
|
52 |
-
break;
|
53 |
-
case PurchaseAction::PaymentConfirmed:
|
54 |
-
//Mage::log('Payment Confirmed');
|
55 |
-
$purchaseProcess->DecodePaymentConfirmed($onescanMessage);
|
56 |
-
$orderAcceptedPayload = $this->BuildOrderAccepted($purchaseProcess);
|
57 |
-
$purchaseProcess->ProcessPaymentConfirmed($orderAcceptedPayload);
|
58 |
-
break;
|
59 |
-
case PurchaseAction::PaymentFailed:
|
60 |
-
//Mage::log('Payment Failed');
|
61 |
-
$purchaseProcess->ProcessPaymentFailed();
|
62 |
-
break;
|
63 |
-
case PurchaseAction::PaymentCancelled:
|
64 |
-
//Mage::log('Payment Cancelled');
|
65 |
-
$purchaseProcess->ProcessPaymentCancelled();
|
66 |
-
break;
|
67 |
-
}
|
68 |
-
$responseMessage = $purchaseProcess->EncodeOutcome();
|
69 |
-
//Mage::log('Response: ' . print_r($responseMessage,true));
|
70 |
-
|
71 |
-
Onescan::SendMessage($responseMessage,$settings);
|
72 |
-
return parent::handle();
|
73 |
-
}
|
74 |
-
|
75 |
-
/// <summary>
|
76 |
-
/// Build some extra information about further charges.
|
77 |
-
/// </summary>
|
78 |
-
private function BuildAdditionalCharges($process) {
|
79 |
-
$additionalChargesContext = $process->AdditionalChargesContext;
|
80 |
-
$requires=$process->PurchaseInfo->Requires;
|
81 |
-
$purchaseCharges = new AdditionalChargesPayload();
|
82 |
-
|
83 |
-
if ($requires->DeliveryOptions && !empty($additionalChargesContext->DeliveryAddress)){
|
84 |
-
$deliveryChargesResponse=$this->AddDeliveryCharges($additionalChargesContext->DeliveryAddress,$purchaseCharges,$process);
|
85 |
-
if($deliveryChargesResponse!==true){
|
86 |
-
$purchaseCharges->AddressNotSupported=1;
|
87 |
-
$purchaseCharges->AddressNotSupportedReason=$deliveryChargesResponse;
|
88 |
-
}
|
89 |
-
}
|
90 |
-
|
91 |
-
//Surcharges not yet supported
|
92 |
-
/*if ($requires->Surcharges && !empty($additionalChargesContext->PaymentMethod)){
|
93 |
-
if(!$this->AddPaymentMethodCharges($additionalChargesContext->PaymentMethod,$purchaseCharges,$process)){
|
94 |
-
//REPORT SURCHARGES ERROR TO DEVICE;
|
95 |
-
}
|
96 |
-
}*/
|
97 |
-
|
98 |
-
return $purchaseCharges;
|
99 |
-
}
|
100 |
-
|
101 |
-
/// <summary>
|
102 |
-
/// Add charges for the specified payment method.
|
103 |
-
/// </summary>
|
104 |
-
private function AddPaymentMethodCharges($paymentMethod,$purchaseCharges,$process) {
|
105 |
-
//Surcharges not yet supported, this sample function never gets called
|
106 |
-
switch ($paymentMethod->PaymentMethodType) {
|
107 |
-
case 'CreditCard':
|
108 |
-
$this->HandleCreditCardCharges($paymentMethod,$purchaseCharges,$process);
|
109 |
-
break;
|
110 |
-
case 'OnescanPlay':
|
111 |
-
$this->HandlePlayCardCharges($paymentMethod,$purchaseCharges,$process);
|
112 |
-
break;
|
113 |
-
}
|
114 |
-
return true;
|
115 |
-
}
|
116 |
-
|
117 |
-
/// <summary>
|
118 |
-
/// Handle charges for the onescan test card.
|
119 |
-
/// </summary>
|
120 |
-
private function HandlePlayCardCharges($paymentMethod,$purchaseCharges,$process) {
|
121 |
-
//Surcharges not yet supported, this sample function never gets called
|
122 |
-
$cardDetails = $paymentMethod->CardInformation;
|
123 |
-
|
124 |
-
$purchaseCharges->PaymentMethodCharge = new PaymentMethodCharge();
|
125 |
-
$purchaseCharges->PaymentMethodCharge->Code = "PLAY";
|
126 |
-
$purchaseCharges->PaymentMethodCharge->Description = "The onescan play card attracts a
|
127 |
-
$purchaseCharges->PaymentMethodCharge->Charge = new Charge();
|
128 |
-
$purchaseCharges->PaymentMethodCharge->Charge->BaseAmount = 1.00;
|
129 |
-
$purchaseCharges->PaymentMethodCharge->Charge->Tax = 0;
|
130 |
-
$purchaseCharges->PaymentMethodCharge->Charge->TotalAmount = 1.00;
|
131 |
-
}
|
132 |
-
|
133 |
-
/// <summary>
|
134 |
-
/// Handle charges for credit cards
|
135 |
-
/// </summary>
|
136 |
-
private function HandleCreditCardCharges($paymentMethod,$purchaseCharges,$process) {
|
137 |
-
//Surcharges not yet supported, this sample function never gets called
|
138 |
-
$cardDetails = $paymentMethod->CardInformation;
|
139 |
-
|
140 |
-
if ($cardDetails->PaymentSystemCode == "VISA") {
|
141 |
-
|
142 |
-
$surcharge = round($process->PurchaseInfo->PaymentAmount * 0.01, 2);
|
143 |
-
|
144 |
-
$purchaseCharges->PaymentMethodCharge = new PaymentMethodCharge();
|
145 |
-
$purchaseCharges->PaymentMethodCharge->Code = "VISA";
|
146 |
-
$purchaseCharges->PaymentMethodCharge->Description = "Paying with a credit card attracts a 1% charge";
|
147 |
-
$purchaseCharges->PaymentMethodCharge->Charge = new Charge();
|
148 |
-
$purchaseCharges->PaymentMethodCharge->Charge->BaseAmount = $surcharge;
|
149 |
-
$purchaseCharges->PaymentMethodCharge->Charge->Tax = 0;
|
150 |
-
$purchaseCharges->PaymentMethodCharge->Charge->TotalAmount = $surcharge;
|
151 |
-
}
|
152 |
-
}
|
153 |
-
|
154 |
-
/// <summary>
|
155 |
-
/// Add delivery charges for the specified address.
|
156 |
-
/// </summary>
|
157 |
-
private function AddDeliveryCharges($address,$purchaseCharges,$process) {
|
158 |
-
//Retreive quote from database
|
159 |
-
$quote=$this->MagentoRetrieveQuote($process->SessionState()->SessionID);
|
160 |
-
|
161 |
-
//Retrieve allowed shipping rates.
|
162 |
-
$shippingError=false;
|
163 |
-
$allowedRates=$this->MagentoGetShippingRates($quote,$shippingError,$address);
|
164 |
-
|
165 |
-
//If retrieval of shipping rates was unsuccessful, return the error.
|
166 |
-
if($shippingError!==false){
|
167 |
-
return $shippingError;
|
168 |
-
}
|
169 |
-
|
170 |
-
//Get shipping tax rate
|
171 |
-
$taxCalculation = Mage::getModel('tax/calculation');
|
172 |
-
$request = $taxCalculation->getRateRequest(null,null,null,$quote->getStore());
|
173 |
-
$taxRateId = Mage::getStoreConfig('tax/classes/shipping_tax_class',$quote->getStore());
|
174 |
-
$shippingTaxPercent = $taxCalculation->getRate($request->setProductClassId($taxRateId));
|
175 |
-
|
176 |
-
//Build delivery options array to pass back to Onescan
|
177 |
-
$purchaseCharges->DeliveryOptions = array();
|
178 |
-
foreach ($allowedRates as $rate) {
|
179 |
-
$amount=$rate->getPrice();
|
180 |
-
if(is_numeric($amount)){
|
181 |
-
$option=new DeliveryOption();
|
182 |
-
$option->Code = $rate->getCode();
|
183 |
-
$option->Description = $rate->getMethodDescription();
|
184 |
-
//Setting default option is not yet supported in the Onescan extension
|
185 |
-
/*if($option->Code==$defaultCode){
|
186 |
-
$option->IsDefault = true;
|
187 |
-
}*/
|
188 |
-
$option->Label = $rate->getMethodTitle();
|
189 |
-
$option->Charge = new Charge();
|
190 |
-
$option->Charge->TotalAmount = $amount;
|
191 |
-
|
192 |
-
$option->Charge->
|
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 |
-
$payload->
|
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 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
$
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
return $
|
310 |
-
}
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
$
|
315 |
-
$
|
316 |
-
|
317 |
-
$
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
$
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
$
|
330 |
-
$
|
331 |
-
$
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
);
|
374 |
-
$
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
$
|
388 |
-
}
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
$
|
426 |
-
|
427 |
-
$
|
428 |
-
|
429 |
-
|
430 |
-
$
|
431 |
-
|
432 |
-
|
433 |
-
$addressData
|
434 |
-
$addressData['
|
435 |
-
$
|
436 |
-
|
437 |
-
|
438 |
-
$
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
$
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
$
|
457 |
-
$
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
$
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
if
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
$
|
554 |
-
$quote->getShippingAddress()->
|
555 |
-
|
556 |
-
|
557 |
-
}
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
Mage::getSingleton('checkout/session')->addException($e, Mage::helper('checkout')->__('Load customer quote error'));
|
563 |
-
}
|
564 |
-
|
565 |
-
$quote->save();
|
566 |
-
|
567 |
-
$allowedRates=array();
|
568 |
-
foreach ($rates as $rate){
|
569 |
-
$rateCode=$rate->getCode();
|
570 |
-
if($quote->getShippingAddress()->collectShippingRates()->getShippingRateByCode($rateCode)){
|
571 |
-
$allowedRates[$rateCode]=$rate; //Using $rateCode as key removes duplicates
|
572 |
-
}
|
573 |
-
}
|
574 |
-
|
575 |
-
return $allowedRates;
|
576 |
-
}
|
577 |
-
}
|
578 |
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Ensygnia Onescan extension
|
4 |
+
Copyright (C) 2014 Ensygnia Ltd
|
5 |
+
|
6 |
+
This program is free software: you can redistribute it and/or modify
|
7 |
+
it under the terms of the GNU General Public License as published by
|
8 |
+
the Free Software Foundation, either version 3 of the License, or
|
9 |
+
(at your option) any later version.
|
10 |
+
|
11 |
+
This program is distributed in the hope that it will be useful,
|
12 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
GNU General Public License for more details.
|
15 |
+
|
16 |
+
You should have received a copy of the GNU General Public License
|
17 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 |
+
*/
|
19 |
+
require_once(Mage::getBaseDir('lib') . "/Onescan/login/LocalDataFactory.php");
|
20 |
+
|
21 |
+
class Ensygnia_Onescan_Model_Callback_Purchase extends Ensygnia_Onescan_Model_Callback_Abstract {
|
22 |
+
public function getConfigReference() {
|
23 |
+
return 'onescan/config_purchase';
|
24 |
+
}
|
25 |
+
|
26 |
+
//Callback entry point
|
27 |
+
public function handle() {
|
28 |
+
$settings = $this->getConfig()->getSettings();
|
29 |
+
if (isset($_GET['basket'])) {
|
30 |
+
$settings->OnescanCallbackURL .= '?basket=' . $_GET['basket'];
|
31 |
+
}
|
32 |
+
|
33 |
+
$onescanMessage = Onescan::ReadMessage($settings);
|
34 |
+
//Mage::log('Message: ' . print_r($onescanMessage,true));
|
35 |
+
|
36 |
+
$purchaseProcess = new OnescanPurchaseProcess();
|
37 |
+
$nextAction = $purchaseProcess->DecodePurchaseMessage($onescanMessage);
|
38 |
+
$sessionState = $purchaseProcess->SessionState();
|
39 |
+
|
40 |
+
switch ($nextAction)
|
41 |
+
{
|
42 |
+
case PurchaseAction::StartPayment:
|
43 |
+
//Mage::log('Start Payment');
|
44 |
+
$purchasePayload = $this->BuildPurchasePayload($sessionState->SessionID);
|
45 |
+
$purchaseProcess->ProcessStartPurchase($purchasePayload);
|
46 |
+
break;
|
47 |
+
case PurchaseAction::AdditionalCharges:
|
48 |
+
//Mage::log('Additional Charges');
|
49 |
+
$purchaseProcess->DecodeAdditionalChargesRequest($onescanMessage);
|
50 |
+
$additionalChargesPayload = $this->BuildAdditionalCharges($purchaseProcess);
|
51 |
+
$purchaseProcess->ProcessAdditionalCharges($additionalChargesPayload);
|
52 |
+
break;
|
53 |
+
case PurchaseAction::PaymentConfirmed:
|
54 |
+
//Mage::log('Payment Confirmed');
|
55 |
+
$purchaseProcess->DecodePaymentConfirmed($onescanMessage);
|
56 |
+
$orderAcceptedPayload = $this->BuildOrderAccepted($purchaseProcess);
|
57 |
+
$purchaseProcess->ProcessPaymentConfirmed($orderAcceptedPayload);
|
58 |
+
break;
|
59 |
+
case PurchaseAction::PaymentFailed:
|
60 |
+
//Mage::log('Payment Failed');
|
61 |
+
$purchaseProcess->ProcessPaymentFailed();
|
62 |
+
break;
|
63 |
+
case PurchaseAction::PaymentCancelled:
|
64 |
+
//Mage::log('Payment Cancelled');
|
65 |
+
$purchaseProcess->ProcessPaymentCancelled();
|
66 |
+
break;
|
67 |
+
}
|
68 |
+
$responseMessage = $purchaseProcess->EncodeOutcome();
|
69 |
+
//Mage::log('Response: ' . print_r($responseMessage,true));
|
70 |
+
|
71 |
+
Onescan::SendMessage($responseMessage,$settings);
|
72 |
+
return parent::handle();
|
73 |
+
}
|
74 |
+
|
75 |
+
/// <summary>
|
76 |
+
/// Build some extra information about further charges.
|
77 |
+
/// </summary>
|
78 |
+
private function BuildAdditionalCharges($process) {
|
79 |
+
$additionalChargesContext = $process->AdditionalChargesContext;
|
80 |
+
$requires=$process->PurchaseInfo->Requires;
|
81 |
+
$purchaseCharges = new AdditionalChargesPayload();
|
82 |
+
|
83 |
+
if ($requires->DeliveryOptions && !empty($additionalChargesContext->DeliveryAddress)){
|
84 |
+
$deliveryChargesResponse=$this->AddDeliveryCharges($additionalChargesContext->DeliveryAddress,$purchaseCharges,$process);
|
85 |
+
if($deliveryChargesResponse!==true){
|
86 |
+
$purchaseCharges->AddressNotSupported=1;
|
87 |
+
$purchaseCharges->AddressNotSupportedReason=$deliveryChargesResponse;
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
//Surcharges not yet supported
|
92 |
+
/*if ($requires->Surcharges && !empty($additionalChargesContext->PaymentMethod)){
|
93 |
+
if(!$this->AddPaymentMethodCharges($additionalChargesContext->PaymentMethod,$purchaseCharges,$process)){
|
94 |
+
//REPORT SURCHARGES ERROR TO DEVICE;
|
95 |
+
}
|
96 |
+
}*/
|
97 |
+
|
98 |
+
return $purchaseCharges;
|
99 |
+
}
|
100 |
+
|
101 |
+
/// <summary>
|
102 |
+
/// Add charges for the specified payment method.
|
103 |
+
/// </summary>
|
104 |
+
private function AddPaymentMethodCharges($paymentMethod,$purchaseCharges,$process) {
|
105 |
+
//Surcharges not yet supported, this sample function never gets called
|
106 |
+
switch ($paymentMethod->PaymentMethodType) {
|
107 |
+
case 'CreditCard':
|
108 |
+
$this->HandleCreditCardCharges($paymentMethod,$purchaseCharges,$process);
|
109 |
+
break;
|
110 |
+
case 'OnescanPlay':
|
111 |
+
$this->HandlePlayCardCharges($paymentMethod,$purchaseCharges,$process);
|
112 |
+
break;
|
113 |
+
}
|
114 |
+
return true;
|
115 |
+
}
|
116 |
+
|
117 |
+
/// <summary>
|
118 |
+
/// Handle charges for the onescan test card.
|
119 |
+
/// </summary>
|
120 |
+
private function HandlePlayCardCharges($paymentMethod,$purchaseCharges,$process) {
|
121 |
+
//Surcharges not yet supported, this sample function never gets called
|
122 |
+
$cardDetails = $paymentMethod->CardInformation;
|
123 |
+
|
124 |
+
$purchaseCharges->PaymentMethodCharge = new PaymentMethodCharge();
|
125 |
+
$purchaseCharges->PaymentMethodCharge->Code = "PLAY";
|
126 |
+
$purchaseCharges->PaymentMethodCharge->Description = "The onescan play card attracts a �1 surcharge";
|
127 |
+
$purchaseCharges->PaymentMethodCharge->Charge = new Charge();
|
128 |
+
$purchaseCharges->PaymentMethodCharge->Charge->BaseAmount = 1.00;
|
129 |
+
$purchaseCharges->PaymentMethodCharge->Charge->Tax = 0;
|
130 |
+
$purchaseCharges->PaymentMethodCharge->Charge->TotalAmount = 1.00;
|
131 |
+
}
|
132 |
+
|
133 |
+
/// <summary>
|
134 |
+
/// Handle charges for credit cards
|
135 |
+
/// </summary>
|
136 |
+
private function HandleCreditCardCharges($paymentMethod,$purchaseCharges,$process) {
|
137 |
+
//Surcharges not yet supported, this sample function never gets called
|
138 |
+
$cardDetails = $paymentMethod->CardInformation;
|
139 |
+
|
140 |
+
if ($cardDetails->PaymentSystemCode == "VISA") {
|
141 |
+
|
142 |
+
$surcharge = round($process->PurchaseInfo->PaymentAmount * 0.01, 2);
|
143 |
+
|
144 |
+
$purchaseCharges->PaymentMethodCharge = new PaymentMethodCharge();
|
145 |
+
$purchaseCharges->PaymentMethodCharge->Code = "VISA";
|
146 |
+
$purchaseCharges->PaymentMethodCharge->Description = "Paying with a credit card attracts a 1% charge";
|
147 |
+
$purchaseCharges->PaymentMethodCharge->Charge = new Charge();
|
148 |
+
$purchaseCharges->PaymentMethodCharge->Charge->BaseAmount = $surcharge;
|
149 |
+
$purchaseCharges->PaymentMethodCharge->Charge->Tax = 0;
|
150 |
+
$purchaseCharges->PaymentMethodCharge->Charge->TotalAmount = $surcharge;
|
151 |
+
}
|
152 |
+
}
|
153 |
+
|
154 |
+
/// <summary>
|
155 |
+
/// Add delivery charges for the specified address.
|
156 |
+
/// </summary>
|
157 |
+
private function AddDeliveryCharges($address,$purchaseCharges,$process) {
|
158 |
+
//Retreive quote from database
|
159 |
+
$quote=$this->MagentoRetrieveQuote($process->SessionState()->SessionID);
|
160 |
+
|
161 |
+
//Retrieve allowed shipping rates.
|
162 |
+
$shippingError=false;
|
163 |
+
$allowedRates=$this->MagentoGetShippingRates($quote,$shippingError,$address);
|
164 |
+
|
165 |
+
//If retrieval of shipping rates was unsuccessful, return the error.
|
166 |
+
if($shippingError!==false){
|
167 |
+
return $shippingError;
|
168 |
+
}
|
169 |
+
|
170 |
+
//Get shipping tax rate
|
171 |
+
$taxCalculation = Mage::getModel('tax/calculation');
|
172 |
+
$request = $taxCalculation->getRateRequest(null,null,null,$quote->getStore());
|
173 |
+
$taxRateId = Mage::getStoreConfig('tax/classes/shipping_tax_class',$quote->getStore());
|
174 |
+
$shippingTaxPercent = $taxCalculation->getRate($request->setProductClassId($taxRateId));
|
175 |
+
|
176 |
+
//Build delivery options array to pass back to Onescan
|
177 |
+
$purchaseCharges->DeliveryOptions = array();
|
178 |
+
foreach ($allowedRates as $rate) {
|
179 |
+
$amount=$rate->getPrice();
|
180 |
+
if(is_numeric($amount)){
|
181 |
+
$option=new DeliveryOption();
|
182 |
+
$option->Code = $rate->getCode();
|
183 |
+
$option->Description = $rate->getMethodDescription();
|
184 |
+
//Setting default option is not yet supported in the Onescan extension
|
185 |
+
/*if($option->Code==$defaultCode){
|
186 |
+
$option->IsDefault = true;
|
187 |
+
}*/
|
188 |
+
$option->Label = $rate->getMethodTitle();
|
189 |
+
$option->Charge = new Charge();
|
190 |
+
$option->Charge->TotalAmount = $amount;
|
191 |
+
//Round shipping tax down
|
192 |
+
$option->Charge->Tax = floor(($amount-$amount/(1+$shippingTaxPercent/100))*100)/100;
|
193 |
+
if(Mage::getStoreConfig('tax/display/type',Mage::app()->getStore())==1){
|
194 |
+
//Show price excluding tax
|
195 |
+
$option->Charge->BaseAmount = $amount-$option->Charge->Tax;
|
196 |
+
}else{
|
197 |
+
//Show price including tax
|
198 |
+
$option->Charge->BaseAmount = $amount;
|
199 |
+
}
|
200 |
+
$option->Charge->BaseAmount = $amount;
|
201 |
+
$purchaseCharges->DeliveryOptions[]=$option;
|
202 |
+
}
|
203 |
+
}
|
204 |
+
|
205 |
+
if(count($purchaseCharges->DeliveryOptions)==0){
|
206 |
+
//No shipping rates available for this order, return an error
|
207 |
+
return Mage::getStoreConfig('onescantab/general/onescan_cannot-deliver-message');
|
208 |
+
}
|
209 |
+
|
210 |
+
//Retreive Onescan data from database
|
211 |
+
$sessionID = $process->SessionState()->SessionID;
|
212 |
+
|
213 |
+
$onescanData = Mage::getModel('onescan/sessiondata')->getCollection();
|
214 |
+
$onescanData->addFieldToFilter('sessionid', array('like' => $sessionID));
|
215 |
+
$onescanData->load();
|
216 |
+
$sessionData=$onescanData->getData();
|
217 |
+
|
218 |
+
//Save details to Onescan database tables for later retrieval
|
219 |
+
$onescanModel=Mage::getModel('onescan/sessiondata');
|
220 |
+
$onescanModel->setId($sessionData[0]['sessiondata_id']);
|
221 |
+
$onescanModel->setSessionid($process->SessionState()->SessionID);
|
222 |
+
$onescanModel->setQuoteid($quote->getId());
|
223 |
+
$onescanModel->setCustomerid($sessionData[0]['customerid']);
|
224 |
+
$onescanModel->save();
|
225 |
+
|
226 |
+
return true;
|
227 |
+
}
|
228 |
+
|
229 |
+
/// <summary>
|
230 |
+
/// Build purchase payload.
|
231 |
+
/// </summary>
|
232 |
+
private function BuildPurchasePayload($sessionID) {
|
233 |
+
//Retreive quote from database and reserve order id
|
234 |
+
$quote=$this->MagentoRetrieveQuote($sessionID);
|
235 |
+
$quote->reserveOrderId();
|
236 |
+
$quote->save();
|
237 |
+
|
238 |
+
//Retreive prices from quote
|
239 |
+
$storeid=$quote->getStoreId();
|
240 |
+
$totals=$quote->getTotals();
|
241 |
+
|
242 |
+
//Build Onescan payload from quote data
|
243 |
+
$payload = new PurchasePayload();
|
244 |
+
$payload->RequiresDeliveryAddress = true;
|
245 |
+
$payload->MerchantName = Mage::app()->getStore()->getFrontendName();
|
246 |
+
$payload->MerchantTransactionID = GUID();
|
247 |
+
$payload->PurchaseDescription = Mage::getStoreConfig('onescantab/general/onescan_basket-name');
|
248 |
+
|
249 |
+
if(isset($totals['tax']) && $totals['tax']->getValue()) {
|
250 |
+
$payload->Tax = $totals['tax']->getValue();
|
251 |
+
} else {
|
252 |
+
$payload->Tax = 0;
|
253 |
+
}
|
254 |
+
|
255 |
+
if(Mage::getStoreConfig('tax/display/type',Mage::app()->getStore())==1){
|
256 |
+
//Show price excluding tax
|
257 |
+
$payload->ProductAmount = $totals['subtotal']->getValue()-$payload->Tax;
|
258 |
+
}else{
|
259 |
+
//Show price including tax
|
260 |
+
$payload->ProductAmount = $totals['subtotal']->getValue();
|
261 |
+
}
|
262 |
+
$payload->PaymentAmount = $totals['subtotal']->getValue();
|
263 |
+
$payload->Currency = Mage::app()->getStore($storeid)->getCurrentCurrencyCode();
|
264 |
+
|
265 |
+
$payload->Requires = new PaymentOptIns();
|
266 |
+
|
267 |
+
$payload->Requires->Surcharges = false;
|
268 |
+
$payload->Requires->DeliveryOptions=true;
|
269 |
+
|
270 |
+
$payload->ImageData = Mage::getStoreConfig('onescantab/general/onescan_basket-logo-url');
|
271 |
+
|
272 |
+
return $payload;
|
273 |
+
}
|
274 |
+
|
275 |
+
/// <summary>
|
276 |
+
/// Build order accepted payload.
|
277 |
+
/// </summary>
|
278 |
+
private function BuildOrderAccepted($process) {
|
279 |
+
//Retreive Onescan data from database
|
280 |
+
$sessionID = $process->SessionState()->SessionID;
|
281 |
+
|
282 |
+
$onescanData = Mage::getModel('onescan/sessiondata')->getCollection();
|
283 |
+
$onescanData->addFieldToFilter('sessionid', array('like' => $sessionID));
|
284 |
+
$onescanData->load();
|
285 |
+
$sessionData=$onescanData->getData();
|
286 |
+
|
287 |
+
$quoteid=$sessionData[0]['quoteid'];
|
288 |
+
$customerid=$sessionData[0]['customerid'];
|
289 |
+
|
290 |
+
//If FirstName or LastName are blank, Magento can't proceed with order
|
291 |
+
if ($process->PaymentConfirmation->FirstName=="") {
|
292 |
+
$process->PaymentConfirmation->FirstName="First";
|
293 |
+
}
|
294 |
+
if ($process->PaymentConfirmation->LastName=="") {
|
295 |
+
$process->PaymentConfirmation->LastName="Last";
|
296 |
+
}
|
297 |
+
|
298 |
+
//Make sure we have an account and are logged in to Magento
|
299 |
+
$this->MagentoLogin($customerid,$quoteid,$process);
|
300 |
+
|
301 |
+
//Place the order
|
302 |
+
$orderId=$this->MagentoPlaceOrder($process,$quoteid);
|
303 |
+
|
304 |
+
//Pass data back to Onescan
|
305 |
+
$orderAccepted = new OrderAcceptedPayload();
|
306 |
+
$orderAccepted->ReceiptId = $process->ProcessId();
|
307 |
+
$orderAccepted->OrderId = $orderId;
|
308 |
+
|
309 |
+
return $orderAccepted;
|
310 |
+
}
|
311 |
+
|
312 |
+
//Create random password for "manual" login
|
313 |
+
private function randomPassword() {
|
314 |
+
$alphabet = "abcdefghijkmnopqrstuwxyzABCDEFGHJKLMNPQRSTUWXYZ23456789";
|
315 |
+
$pass='';
|
316 |
+
|
317 |
+
for ($i = 0; $i < 8; $i++) {
|
318 |
+
$n = rand(0, strlen($alphabet)-1);
|
319 |
+
$pass .= $alphabet[$n];
|
320 |
+
}
|
321 |
+
|
322 |
+
return $pass;
|
323 |
+
}
|
324 |
+
|
325 |
+
private function MagentoRetrieveQuote($sessionID){
|
326 |
+
//Retrieve quote from database
|
327 |
+
$onescanData = Mage::getModel('onescan/sessiondata')->getCollection();
|
328 |
+
$onescanData->addFieldToFilter('sessionid', array('like' => $sessionID));
|
329 |
+
$onescanData->load();
|
330 |
+
$sessionData=$onescanData->getData();
|
331 |
+
$quoteid=$sessionData[0]['quoteid'];
|
332 |
+
|
333 |
+
//Retreive quote
|
334 |
+
$cart=Mage::getModel('checkout/cart')->getCheckoutSession();
|
335 |
+
$cart->setQuoteId($quoteid);
|
336 |
+
|
337 |
+
return $cart->getQuote();
|
338 |
+
}
|
339 |
+
|
340 |
+
protected function MagentoLogin($customerid,$quoteid,$process){
|
341 |
+
//Retreive quote from database
|
342 |
+
$cart=Mage::getModel('checkout/cart')->getCheckoutSession();
|
343 |
+
$cart->setQuoteId($quoteid);
|
344 |
+
$quote=$cart->getQuote();
|
345 |
+
$sessionID=$process->SessionState()->SessionID;
|
346 |
+
|
347 |
+
if ($customerid) {
|
348 |
+
// We are already logged in:
|
349 |
+
$customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getWebsite()->getId())->load($customerid);
|
350 |
+
$quote->assignCustomer($customer);
|
351 |
+
} else {
|
352 |
+
//Determine whether Onescan user token is recognised
|
353 |
+
$loginTokens = Mage::getModel('onescan/logintokens')->getCollection();
|
354 |
+
$loginTokens->addFieldToFilter('onescantoken', array('like' => $process->UserToken));
|
355 |
+
$loginTokens->load();
|
356 |
+
$details=$loginTokens->getData();
|
357 |
+
$customer = Mage::getModel('customer/customer');
|
358 |
+
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
|
359 |
+
if (empty($details)) {
|
360 |
+
//We do not recognise the user token, so we create an account and log in
|
361 |
+
$customer->loadByEmail($process->PaymentConfirmation->UserEmail);
|
362 |
+
|
363 |
+
if(!$customer->getId()) {
|
364 |
+
//New customer registration
|
365 |
+
$customer->setEmail($process->PaymentConfirmation->UserEmail);
|
366 |
+
$customer->setFirstname($process->PaymentConfirmation->FirstName);
|
367 |
+
$customer->setLastname($process->PaymentConfirmation->LastName);
|
368 |
+
$customer->setPassword($this->randomPassword());
|
369 |
+
try {
|
370 |
+
$customer->save();
|
371 |
+
//Determine whether email confirmation is required then set up account and send appropriate email
|
372 |
+
if (Mage::getStoreConfig('onescantab/general/onescan_skip-confirmation') || !$customer->isConfirmationRequired()) {
|
373 |
+
$customer->setConfirmation(null);
|
374 |
+
$customer->save();
|
375 |
+
$customer->sendNewAccountEmail(
|
376 |
+
'registered',
|
377 |
+
'',
|
378 |
+
Mage::app()->getStore()->getId()
|
379 |
+
);
|
380 |
+
$confirmMessage=false;
|
381 |
+
} else {
|
382 |
+
$customer->sendNewAccountEmail(
|
383 |
+
'confirmation',
|
384 |
+
$session->getBeforeAuthUrl(),
|
385 |
+
Mage::app()->getStore()->getId()
|
386 |
+
);
|
387 |
+
$confirmMessage=true;
|
388 |
+
}
|
389 |
+
|
390 |
+
//Store the Onescan user token in the database and associate it with the Magento account
|
391 |
+
$newToken=Mage::getModel('onescan/logintokens');
|
392 |
+
$newToken->setOnescantoken($process->UserToken);
|
393 |
+
$newToken->setMagentouserid($customer->getId());
|
394 |
+
$newToken->save();
|
395 |
+
|
396 |
+
$message=Mage::getStoreConfig('onescantab/general/onescan_register-success-message');
|
397 |
+
|
398 |
+
if ($confirmMessage) {
|
399 |
+
$value=Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail());
|
400 |
+
$message = Mage::helper('customer')->__(Mage::getStoreConfig('onescantab/general/onescan_email-not-confirmed-message'),$value);
|
401 |
+
}
|
402 |
+
|
403 |
+
LocalDataFactory::storeObject($sessionID,$customer->getId());
|
404 |
+
LocalDataFactory::storeObject($sessionID . '-message',$message);
|
405 |
+
}
|
406 |
+
catch (Mage_Core_Exception $e) {
|
407 |
+
LocalDataFactory::storeObject($sessionID . '-message',$e->getMessage());
|
408 |
+
}
|
409 |
+
} else {
|
410 |
+
//Email address recognised so redirect to login page
|
411 |
+
LocalDataFactory::storeObject($sessionID . '-message',Mage::getStoreConfig('onescantab/general/onescan_email-exists-message'));
|
412 |
+
}
|
413 |
+
} else {
|
414 |
+
//We recognise the user token, so we can log in
|
415 |
+
$customer->load($details[0]['magentouserid']);
|
416 |
+
LocalDataFactory::storeObject($sessionID,$details[0]['magentouserid']);
|
417 |
+
LocalDataFactory::storeObject($sessionID . '-message',Mage::getStoreConfig('onescantab/general/onescan_login-success-message'));
|
418 |
+
}
|
419 |
+
$quote->assignCustomer($customer);
|
420 |
+
}
|
421 |
+
}
|
422 |
+
|
423 |
+
protected function MagentoPlaceOrder($process,$quoteid){
|
424 |
+
//Retreive quote from database
|
425 |
+
$cart=Mage::getModel('checkout/cart')->getCheckoutSession();
|
426 |
+
$cart->setQuoteId($quoteid);
|
427 |
+
$quote=$cart->getQuote();
|
428 |
+
|
429 |
+
//Add customer name to the quote, along with billing address and shipping address.
|
430 |
+
$quote->setcustomerfirstname($process->PaymentConfirmation->FirstName);
|
431 |
+
$quote->setcustomerlastname($process->PaymentConfirmation->LastName);
|
432 |
+
|
433 |
+
$addressData=$quote->getBillingAddress()->getData();
|
434 |
+
$addressData['firstname']=$process->PaymentConfirmation->FirstName;
|
435 |
+
$addressData['lastname']=$process->PaymentConfirmation->LastName;
|
436 |
+
$billingAddress = $quote->getBillingAddress()->setData($addressData);
|
437 |
+
|
438 |
+
$addressData=$quote->getShippingAddress()->getData();
|
439 |
+
$addressData['firstname']=$process->PaymentConfirmation->FirstName;
|
440 |
+
$addressData['lastname']=$process->PaymentConfirmation->LastName;
|
441 |
+
$shippingAddress = $quote->getShippingAddress()->setData($addressData);
|
442 |
+
|
443 |
+
//Set shipping and payment methods for order
|
444 |
+
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
|
445 |
+
->setShippingMethod($process->PaymentConfirmation->DeliveryMethodCode)
|
446 |
+
->setPaymentMethod('onescan');
|
447 |
+
|
448 |
+
$quote->getPayment()->importData(array('method' => 'onescan'));
|
449 |
+
|
450 |
+
//Create order from quote
|
451 |
+
$service = Mage::getModel('sales/service_quote', $quote);
|
452 |
+
$service->submitAll();
|
453 |
+
$order = $service->getOrder();
|
454 |
+
|
455 |
+
//Add payment to order
|
456 |
+
$payment = $order->getPayment();
|
457 |
+
$payment->setTransactionId($process->PaymentConfirmation->GatewayTransactionId)
|
458 |
+
->setCurrencyCode($order->getBaseCurrencyCode())
|
459 |
+
->setPreparedMessage('Comment')
|
460 |
+
->setIsTransactionClosed(0)
|
461 |
+
->registerCaptureNotification($process->PaymentConfirmation->AmountCharged->PaymentAmount);
|
462 |
+
$order->save();
|
463 |
+
|
464 |
+
//Delete quote
|
465 |
+
$quote->setIsActive(false);
|
466 |
+
$quote->delete();
|
467 |
+
|
468 |
+
return $order->getIncrementId();
|
469 |
+
}
|
470 |
+
|
471 |
+
protected function MagentoGetShippingRates($quote,$shippingError,$address){
|
472 |
+
//Coupons not yet supported, sample code for reference
|
473 |
+
/*if ($quote->getCouponCode() != '') {
|
474 |
+
$c = Mage::getResourceModel('salesrule/rule_collection');
|
475 |
+
$c->getSelect()->where("code=?", $quote->getCouponCode());
|
476 |
+
foreach ($c->getItems() as $item) {
|
477 |
+
$coupon = $item;
|
478 |
+
}
|
479 |
+
if ($coupon->getSimpleFreeShipping() > 0) {
|
480 |
+
$quote->getShippingAddress()->setShippingMethod($this->_shippingCode)->save();
|
481 |
+
return true;
|
482 |
+
}
|
483 |
+
}*/
|
484 |
+
|
485 |
+
//Add address to quote
|
486 |
+
try {
|
487 |
+
$addressData = array(
|
488 |
+
'street' => $address->AddressLine1 . ', ' . $address->AddressLine2,
|
489 |
+
'city' => $address->Town,
|
490 |
+
'postcode' => $address->Postcode,
|
491 |
+
'telephone' => '0',
|
492 |
+
'country_id' => $address->CountryCode,
|
493 |
+
);
|
494 |
+
|
495 |
+
//Check to see if region/state is required for the delivery country
|
496 |
+
$requiredStates=explode(',',Mage::getStoreConfig('general/region/state_required', Mage::app()->getStore()));
|
497 |
+
if(in_array($address->CountryCode,$requiredStates)){
|
498 |
+
$regions=Mage::getModel('directory/region')
|
499 |
+
->getResourceCollection()
|
500 |
+
->addCountryFilter($address->CountryCode)
|
501 |
+
->load();
|
502 |
+
|
503 |
+
//Ensure we have a valid region/state as either the full name or two letter abbreviation
|
504 |
+
$regionMatch=false;
|
505 |
+
//Check if supplied county text appears within full region name
|
506 |
+
foreach($regions as $region){
|
507 |
+
if(stripos($region->default_name,$address->County)!==false
|
508 |
+
//Use first region if county is empty to allow testing with early version of Onscan app
|
509 |
+
|| $address->County==''){
|
510 |
+
$addressData['region']=$region->default_name;
|
511 |
+
$addressData['region_id']=$region->region_id;
|
512 |
+
$regionMatch=true;
|
513 |
+
break;
|
514 |
+
}
|
515 |
+
}
|
516 |
+
//If supplied county is two characters long, check if we match the two letter region abbreviation
|
517 |
+
if(strlen($address->County)==2){
|
518 |
+
foreach($regions as $region){
|
519 |
+
if(strcasecmp($address->County,$region->code)==0){
|
520 |
+
$addressData['region']=$region->default_name;
|
521 |
+
$addressData['region_id']=$region->region_id;
|
522 |
+
$regionMatch=true;
|
523 |
+
break;
|
524 |
+
}
|
525 |
+
}
|
526 |
+
}
|
527 |
+
if(!$regionMatch){
|
528 |
+
//Region not found, return an error
|
529 |
+
return Mage::getStoreConfig('onescantab/general/onescan_unknown-region-message');
|
530 |
+
}
|
531 |
+
}
|
532 |
+
|
533 |
+
$billingAddress = $quote->getBillingAddress()->addData($addressData);
|
534 |
+
$shippingAddress = $quote->getShippingAddress()->addData($addressData);
|
535 |
+
|
536 |
+
//Get valid shipping rates for this address
|
537 |
+
$quote->getShippingAddress()->collectTotals();
|
538 |
+
$quote->getShippingAddress()->setCollectShippingRates(true);
|
539 |
+
$quote->getShippingAddress()->collectShippingRates();
|
540 |
+
$rates = $quote->getShippingAddress()->getShippingRatesCollection();
|
541 |
+
}
|
542 |
+
catch (Mage_Core_Exception $e) {
|
543 |
+
Mage::getSingleton('checkout/session')->addError($e->getMessage());
|
544 |
+
}
|
545 |
+
catch (Exception $e) {
|
546 |
+
Mage::getSingleton('checkout/session')->addException($e, Mage::helper('checkout')->__('Load customer quote error'));
|
547 |
+
}
|
548 |
+
|
549 |
+
$quote->save();
|
550 |
+
|
551 |
+
$allowedRates=array();
|
552 |
+
foreach ($rates as $rate){
|
553 |
+
$rateCode=$rate->getCode();
|
554 |
+
if($quote->getShippingAddress()->collectShippingRates()->getShippingRateByCode($rateCode)){
|
555 |
+
$allowedRates[$rateCode]=$rate; //Using $rateCode as key removes duplicates
|
556 |
+
}
|
557 |
+
}
|
558 |
+
|
559 |
+
return $allowedRates;
|
560 |
+
}
|
561 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
562 |
?>
|
@@ -19,7 +19,7 @@
|
|
19 |
<config>
|
20 |
<modules>
|
21 |
<Ensygnia_Onescan>
|
22 |
-
<version>1.0.
|
23 |
</Ensygnia_Onescan>
|
24 |
</modules>
|
25 |
<global>
|
19 |
<config>
|
20 |
<modules>
|
21 |
<Ensygnia_Onescan>
|
22 |
+
<version>1.0.13</version>
|
23 |
</Ensygnia_Onescan>
|
24 |
</modules>
|
25 |
<global>
|
@@ -1,37 +1,43 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Ensygnia Onescan extension
|
4 |
-
Copyright (C) 2014 Ensygnia Ltd
|
5 |
-
|
6 |
-
This program is free software: you can redistribute it and/or modify
|
7 |
-
it under the terms of the GNU General Public License as published by
|
8 |
-
the Free Software Foundation, either version 3 of the License, or
|
9 |
-
(at your option) any later version.
|
10 |
-
|
11 |
-
This program is distributed in the hope that it will be useful,
|
12 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
-
GNU General Public License for more details.
|
15 |
-
|
16 |
-
You should have received a copy of the GNU General Public License
|
17 |
-
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 |
-
*/
|
19 |
-
class LocalDataFactory {
|
20 |
-
|
21 |
-
public static function removeStoredObject($signature) {
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Ensygnia Onescan extension
|
4 |
+
Copyright (C) 2014 Ensygnia Ltd
|
5 |
+
|
6 |
+
This program is free software: you can redistribute it and/or modify
|
7 |
+
it under the terms of the GNU General Public License as published by
|
8 |
+
the Free Software Foundation, either version 3 of the License, or
|
9 |
+
(at your option) any later version.
|
10 |
+
|
11 |
+
This program is distributed in the hope that it will be useful,
|
12 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
GNU General Public License for more details.
|
15 |
+
|
16 |
+
You should have received a copy of the GNU General Public License
|
17 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 |
+
*/
|
19 |
+
class LocalDataFactory {
|
20 |
+
|
21 |
+
public static function removeStoredObject($signature) {
|
22 |
+
if(file_exists(sys_get_temp_dir() . '/' . $signature)){
|
23 |
+
return (unlink(sys_get_temp_dir() . '/' . $signature));
|
24 |
+
}else{
|
25 |
+
return false;
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
public static function getStoredObject($signature) {
|
30 |
+
if(!file_exists(sys_get_temp_dir() . '/' . $signature)){
|
31 |
+
return false;
|
32 |
+
}elseif($data = file_get_contents(sys_get_temp_dir() . '/' . $signature)) {
|
33 |
+
$obj = @unserialize($data);
|
34 |
+
return $obj;
|
35 |
+
}
|
36 |
+
return false;
|
37 |
+
}
|
38 |
+
|
39 |
+
public static function storeObject($signature, $obj) {
|
40 |
+
file_put_contents(sys_get_temp_dir() . '/' . $signature,serialize($obj));
|
41 |
+
}
|
42 |
+
}
|
43 |
?>
|
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Ensygnia_Onescan</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://www.gnu.org/licenses/gpl.html">GPL</license>
|
7 |
<channel>community</channel>
|
@@ -14,11 +14,18 @@ No usernames and passwords to remember, no security checks to pass, or tiresome
|
|
14 |
All while improving the security of your site. And the burden of dealing with sensitive financial information is lifted. Payments are confirmed by a tokenised system: at no point do the details need to be shared.
|
15 |

|
16 |
Thanks to Onescan, mobile phones become a secure proof of identity. Online, all customers have to do to login, register or even purchase an item is complete one simple scan. We take all the hassle out of online shopping and tear down the barriers between you and your customers.</description>
|
17 |
-
<notes>Version 1.0.
|
18 |

|
19 |
Changelog
|
20 |
---------------
|
21 |

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
1.0.12
|
23 |
Check Magento database to determine whether country of delivery requires state/region to be present.
|
24 |

|
@@ -76,9 +83,9 @@ Fixed potential installation problem.
|
|
76 |
1.0.0
|
77 |
Initial version.</notes>
|
78 |
<authors><author><name>Ensygnia</name><user>MAG002660123</user><email>paul.newson@ensygnia.com</email></author></authors>
|
79 |
-
<date>2015-07-
|
80 |
-
<time>
|
81 |
-
<contents><target name="magelocal"><dir name="Ensygnia"><dir name="Onescan"><dir name="Block"><file name="Abstract.php" hash="4488b86743ac3cd970d52a4dc857c4d6"/><dir name="Adminhtml"><dir name="System"><dir name="Config"><file name="Cta.php" hash="433c964de85d708af211461033f7a5fc"/></dir></dir></dir><file name="Basket.php" hash="438f95ad093d4b5cde252eb4a8661035"/><file name="Login.php" hash="099ce7a3c3b483e0e509357949d0056d"/><file name="Logo.php" hash="fd58bed8012207372450577b137781ea"/><file name="Register.php" hash="a3ce5e2b5d4cb627f23a6d52dc3f5db9"/><dir name="Widget"><file name="Basket.php" hash="95fad0d733885b0c4651d7e41bc0039c"/><file name="Login.php" hash="225660cace8fc351da454b49d887e124"/><file name="Register.php" hash="89a1492f818fc787cdde4f1adc29702b"/></dir></dir><dir name="Helper"><file name="Data.php" hash="6bf2bcc51f0639615a150835c182b014"/></dir><dir name="Model"><dir name="Callback"><file name="Abstract.php" hash="31b73999f34ffd0f7e539d9ed6499cce"/><file name="Login.php" hash="94f1d610a7c56a95e10694b58e84de31"/><file name="Purchase.php" hash="
|
82 |
<compatible/>
|
83 |
<dependencies><required><php><min>5.2.13</min><max>5.6.1</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.7.0.0</min><max></max></package></required></dependencies>
|
84 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Ensygnia_Onescan</name>
|
4 |
+
<version>1.0.13</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://www.gnu.org/licenses/gpl.html">GPL</license>
|
7 |
<channel>community</channel>
|
14 |
All while improving the security of your site. And the burden of dealing with sensitive financial information is lifted. Payments are confirmed by a tokenised system: at no point do the details need to be shared.
|
15 |

|
16 |
Thanks to Onescan, mobile phones become a secure proof of identity. Online, all customers have to do to login, register or even purchase an item is complete one simple scan. We take all the hassle out of online shopping and tear down the barriers between you and your customers.</description>
|
17 |
+
<notes>Version 1.0.13 of the Onescan Payment Extension.
|
18 |

|
19 |
Changelog
|
20 |
---------------
|
21 |

|
22 |
+
1.0.13
|
23 |
+
Check Magento admin settings to determine whether prices sent to the Onescanner's device should include tax.
|
24 |
+

|
25 |
+
Improved efficiency of extension code.
|
26 |
+

|
27 |
+
Modified shipping tax calculation to round down so that the amount displayed on the Onescanner's device matches the amount calculated by Magento.
|
28 |
+

|
29 |
1.0.12
|
30 |
Check Magento database to determine whether country of delivery requires state/region to be present.
|
31 |

|
83 |
1.0.0
|
84 |
Initial version.</notes>
|
85 |
<authors><author><name>Ensygnia</name><user>MAG002660123</user><email>paul.newson@ensygnia.com</email></author></authors>
|
86 |
+
<date>2015-07-08</date>
|
87 |
+
<time>20:05:26</time>
|
88 |
+
<contents><target name="magelocal"><dir name="Ensygnia"><dir name="Onescan"><dir name="Block"><file name="Abstract.php" hash="4488b86743ac3cd970d52a4dc857c4d6"/><dir name="Adminhtml"><dir name="System"><dir name="Config"><file name="Cta.php" hash="433c964de85d708af211461033f7a5fc"/></dir></dir></dir><file name="Basket.php" hash="438f95ad093d4b5cde252eb4a8661035"/><file name="Login.php" hash="099ce7a3c3b483e0e509357949d0056d"/><file name="Logo.php" hash="fd58bed8012207372450577b137781ea"/><file name="Register.php" hash="a3ce5e2b5d4cb627f23a6d52dc3f5db9"/><dir name="Widget"><file name="Basket.php" hash="95fad0d733885b0c4651d7e41bc0039c"/><file name="Login.php" hash="225660cace8fc351da454b49d887e124"/><file name="Register.php" hash="89a1492f818fc787cdde4f1adc29702b"/></dir></dir><dir name="Helper"><file name="Data.php" hash="6bf2bcc51f0639615a150835c182b014"/></dir><dir name="Model"><dir name="Callback"><file name="Abstract.php" hash="31b73999f34ffd0f7e539d9ed6499cce"/><file name="Login.php" hash="94f1d610a7c56a95e10694b58e84de31"/><file name="Purchase.php" hash="784b739775a2b9e33e91e6730755a608"/><file name="Registration.php" hash="7cf4b0cdd39e84e392cecaa38a35bd50"/></dir><dir name="Config"><file name="Abstract.php" hash="9e407f490c53651e5fe6b19c92cb5c1a"/><file name="Login.php" hash="6fbec423b7b3c6d72fa6e3b519163cd8"/><file name="Purchase.php" hash="0bd21ab4d83b48a31aa9003b473ed6db"/><file name="Registration.php" hash="4c39c0ee7690abc16c0519d3c950c5cb"/></dir><file name="Logintokens.php" hash="1a61be2e17f8ef9562cc205d525a473c"/><dir name="Method"><file name="Onescan.php" hash="9700daf18892390d3c6c73d1ad9349a9"/></dir><dir name="Resource"><dir name="Logintokens"><file name="Collection.php" hash="3767dcf1cbe12088186664ef7d1be309"/></dir><file name="Logintokens.php" hash="4f0fd6b83ee508a382a442641a357e31"/><dir name="Sessiondata"><file name="Collection.php" hash="0b62795cd0f7f7b6dba3ecf07599a9f6"/></dir><file name="Sessiondata.php" hash="48c60528f7accbf52da25030a7681fc0"/><file name="Setup.php" hash="e09e39a39405ebd80af368fefa013839"/></dir><file name="Sessiondata.php" hash="f5f6c2f7ea7fc3c6f033d5a5ff3b1666"/></dir><dir name="controllers"><file name="CallbackController.php" hash="dbbaebed3d7f7aa4e1431d22e2f6a541"/><file name="IndexController.php" hash="37d200f846305bed89a853d41e8f2c55"/></dir><dir name="etc"><file name="adminhtml.xml" hash="42e02288cfa5329abafb1ea0a98ef387"/><file name="config.xml" hash="54ad76a6b3ec05ab636f5704d3ae6393"/><file name="system.xml" hash="92cb2fbfe0086273b664f181cabb2241"/><file name="widget.xml" hash="2a9946cbc623b75b95eaf6d851d73c52"/></dir><file name="license.txt" hash="f075d971a6aa12e3ae52489ef961a7f5"/><dir name="sql"><dir name="onescan_setup"><file name="install-1.0.0.php" hash="08887eb2180ac838dcacd73b5cd2ab8b"/><file name="upgrade-1.0.4-1.0.5.php" hash="c55d900031db2717429a2e575ed4aa59"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="onescan.xml" hash="419c0333c31ba849f2ed2a8ea57cb823"/></dir><dir name="template"><dir name="onescan"><dir name="system"><dir name="config"><file name="cta.phtml" hash="c99b3ce3333dbff286f2156a031f5401"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="onescan.xml" hash="3f702507b0dfc4ffd7e6c3e3647ee831"/></dir><dir name="template"><dir name="onescan"><file name="basket.phtml" hash="d561c70fd9ea873fa2e25f6bd90df1d4"/><file name="login.phtml" hash="06e2ba3a1101b46050a65553cf5b2758"/><file name="logo.phtml" hash="29e5cb387d8e2aaf676040a2c25b9596"/><file name="register.phtml" hash="17749f596a966ec18933d0c779b8b56b"/><file name="scripts.phtml" hash="e2c4469065c629b34a9280879f9da71e"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ensygnia_Onescan.xml" hash="d0d96d5e505006873bdb9c1b4f4c591f"/></dir></target><target name="magelib"><dir name="Onescan"><dir name="core"><file name="onescan-Exceptions.php" hash="1733a8f40cdc6fbb7a2c77890f0fd197"/><file name="onescan-GUID.php" hash="732799426a921038f30f1485f5cd7264"/><file name="onescan-HMAC.php" hash="797d68c8879ee9574dcb06770947d19b"/><file name="onescan-HTTPClient.php" hash="59eee1d07c3796ad24126c0c85b35086"/><file name="onescan-Login.php" hash="deaf58a3c6c9bc30a0acc4f10d64ade0"/><file name="onescan-Message.php" hash="f978243be9032897fcf1a288a23ce837"/><file name="onescan-Onescan.php" hash="93120300b4add29f3cd44709d8cc32d6"/><file name="onescan-Process.php" hash="86d8ccd62a5261d86ae7c35a099b5c1f"/><file name="onescan-Session.php" hash="a365d6c0fc9d41f603e88384b0c15fea"/><file name="onescan-SessionState.php" hash="a0b3b8d6d8d433551340ede175d094cc"/><file name="onescan-Settings.php" hash="2c62dcbb810b2d1d02f5773db9184408"/></dir><dir name="login"><file name="LocalDataFactory.php" hash="99605095507fb98c2de5dcf57e34411e"/><file name="onescan-LoginProcess.php" hash="c3552a34b51e879c535d7b67d541e0fd"/></dir><dir name="purchase"><file name="onescan-AdditionalChargesPayload.php" hash="cb1f2d49d560e1b46b866dffda932111"/><file name="onescan-CardInformation.php" hash="6c2fd7227533dfe986d93bd8bfeb4c1e"/><file name="onescan-CardType.php" hash="8e7765420c6a0de517949393b7360818"/><file name="onescan-Charge.php" hash="285cc0b1f0708f3a3dbc503447b7c0bd"/><file name="onescan-ConfirmPaymentPayload.php" hash="7eda3538cd471c41976732d462a2d84e"/><file name="onescan-CorePurchaseInfo.php" hash="08d943667c901189edaf8dc22406b7d8"/><file name="onescan-DeliveryOption.php" hash="8580b35f993b668c153b6488a9572bd4"/><file name="onescan-OrderAcceptedPayload.php" hash="c007ac8a0a78e51f516f9456d47c0129"/><file name="onescan-OrderDeclinedPayload.php" hash="1cfd9499b9cb167435a33766a5822909"/><file name="onescan-PaymentMethodCharge.php" hash="35f576d4ba1965a5ffc1155d28ba2ceb"/><file name="onescan-PaymentMethodInformation.php" hash="9c332bf6aa9395ec484a13a771101f94"/><file name="onescan-PaymentMethodType.php" hash="df5296173d5a34e55a425810072192dd"/><file name="onescan-PaymentOptins.php" hash="da07521ee0d52657a776ea8ecb705ac0"/><file name="onescan-PurchaseAction.php" hash="ca494c86fe5548b93ba2876a4e3b7aad"/><file name="onescan-PurchaseCharges.php" hash="1b67b353045ea1f93a7b18d2c1940b94"/><file name="onescan-PurchaseContextPayload.php" hash="0bdf109a37bd5104660d13ee3ea42d42"/><file name="onescan-PurchaseInclude.php" hash="a52385a7ceb5f056367a40eaff2a2d32"/><file name="onescan-PurchasePayload.php" hash="0970da6cfc0907c268218501d24f08d1"/><file name="onescan-PurchaseProcess.php" hash="e5108485d920ef899003d402f7bd5efd"/><file name="onescan-PurchaseSettings.php" hash="f3c3d6776d5da8a616eb417a9728fe61"/><file name="onescan-UserAddress.php" hash="4e1ec23d74d6f192a1edb31f3e3c9c8e"/></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="onescan"><dir name="css"><file name="onescan.css" hash="1f758b313e54a8782fcc96e34423caf5"/></dir><dir name="images"><file name="logo-sml.png" hash="af6d80c8d752b68ffff5d2cedd60319f"/><file name="logo.png" hash="ad10933575eaa2f9e379c0aad2ac038e"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="onescan.css" hash="c649f4ebbe1ccb865f3582e04b842c34"/></dir><dir name="images"><file name="logo.png" hash="658a845e0e5d71fb94c072680a42c74b"/></dir><dir name="js"><file name="onescan.js" hash="22e614add95533cbb8415d030cccfe2e"/></dir></dir></dir></dir></target></contents>
|
89 |
<compatible/>
|
90 |
<dependencies><required><php><min>5.2.13</min><max>5.6.1</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.7.0.0</min><max></max></package></required></dependencies>
|
91 |
</package>
|
Binary file
|