forked from PAYONE-GmbH/oxid-6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcPayOneOrder.php
executable file
·2190 lines (1934 loc) · 71.1 KB
/
fcPayOneOrder.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
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
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
434
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
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE OXID Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.payone.de
* @copyright (C) Payone GmbH
* @version OXID eShop CE
*/
class fcPayOneOrder extends fcPayOneOrder_parent
{
const FCPO_AMAZON_ERROR_TRANSACTION_TIMED_OUT = 980;
const FCPO_AMAZON_ERROR_INVALID_PAYMENT_METHOD = 981;
const FCPO_AMAZON_ERROR_REJECTED = 982;
const FCPO_AMAZON_ERROR_PROCESSING_FAILURE = 983;
const FCPO_AMAZON_ERROR_BUYER_EQUALS_SELLER = 984;
const FCPO_AMAZON_ERROR_PAYMENT_NOT_ALLOWED = 985;
const FCPO_AMAZON_ERROR_PAYMENT_PLAN_NOT_SET = 986;
const FCPO_AMAZON_ERROR_SHIPPING_ADDRESS_NOT_SET = 987;
const FCPO_AMAZON_ERROR_900 = 900;
/**
* Helper object for dealing with different shop versions
*
* @var object
*/
protected $_oFcpoHelper = null;
/**
* Database instance
*
* @var object
*/
protected $_oFcpoDb = null;
/**
* Array with all reponse paramaters from the API order request
*
* @var array
*/
protected $_aResponse = null;
/**
* Array with all request parameters from API order request
* @var array
*/
protected $_aRequest = null;
/**
* Flag for redirecting after save
*
* @var bool
*/
protected $_blIsRedirectAfterSave = null;
/**
* Variable for flagging payment as payone payment
*
* @var bool
*/
protected $_blIsPayonePayment = false;
/**
* Appointed error
*
* @var bool
*/
protected $_blFcPayoneAppointedError = false;
/**
* List of Payment IDs which need to save workorderid
*
* @var array
*/
protected $_aPaymentsWorkorderIdSave = array(
'fcpopo_bill',
'fcpopo_debitnote',
'fcpopo_installment',
'fcpoklarna_invoice',
'fcpoklarna_directdebit',
'fcpoklarna_installments',
);
/**
* List of Payment IDs which are foreseen for saving clearing reference
*
* @var array
*/
protected $_aPaymentsClearingReferenceSave = array(
'fcporp_bill',
'fcpopo_bill',
'fcpopo_debitnote',
'fcpopo_installment',
'fcpoklarna_invoice',
'fcpoklarna_directdebit',
'fcpoklarna_installments',
);
/**
* List of Payment IDs which are foreseen for saving external shopid
*
* @var array
*/
protected $_aPaymentsProfileIdentSave = array('fcporp_bill');
/**
* PaymentId of order
* @var string
*/
protected $_sFcpoPaymentId = null;
/**
* Flag for marking order as generally problematic
* @var bool
*/
protected $_blOrderHasProblems = false;
/** Flag that indicates that payone payment of this order is flagged as redirect payment
* @var boolean
*/
protected $_blOrderPaymentFlaggedAsRedirect = null;
/**
* Flag for finishing order completely
* @var bool
*/
protected $_blFinishingSave = true;
/**
* Indicator if loading basket from session has been triggered
* @var bool
*/
protected $_blFcPoLoadFromSession = false;
/**
* init object construction
*
* @return null
*/
public function __construct()
{
parent::__construct();
$this->_oFcpoHelper = oxNew('fcpohelper');
$this->_oFcpoDb = oxDb::getDb();
}
/**
* Checks if the selected payment method for this order is a PAYONE payment method
*
* @param string $sPaymenttype payment id. Default is null
*
* @return bool
*/
public function isPayOnePaymentType($sPaymenttype = null)
{
if (!$sPaymenttype) {
$sPaymenttype = $this->oxorder__oxpaymenttype->value;
}
return $this->_fcpoIsPayonePaymentType($sPaymenttype);
}
/**
* Method validates if given payment-type is an payone iframe payment
*
* @param string $sPaymenttype
* @return bool
*/
public function isPayOneIframePayment($sPaymenttype = null)
{
if (!$sPaymenttype) {
$sPaymenttype = $this->oxorder__oxpaymenttype->value;
}
return $this->_fcpoIsPayonePaymentType($sPaymenttype, true);
}
/**
* Checks if user already exists
*
* @param string $sEmail
* @return mixed
* @todo Should be moved to oxUser
*/
public function fcpoDoesUserAlreadyExist($sEmail)
{
$sQuery = "SELECT oxid FROM oxuser WHERE oxusername = " . oxDb::getDb()->quote($sEmail) . " AND oxpassword != ''";
$sUserId = $this->_oFcpoDb->GetOne($sQuery);
$mReturn = ($sUserId) ? $sUserId : false;
return $mReturn;
}
/**
* Returns user id by given username
*
* @param string $sUserName
* @return type
*/
public function fcpoGetIdByUserName($sUserName)
{
$oConfig = $this->_oFcpoHelper->fcpoGetConfig();
$sQuery = "SELECT oxid FROM oxuser WHERE oxusername = " . oxDb::getDb()->quote($sUserName);
if (!$oConfig->getConfigParam('blMallUsers')) {
$sQuery .= " AND oxshopid = '{$oConfig->getShopId()}'";
}
$sReturn = $this->_oFcpoDb->GetOne($sQuery);
return $sReturn;
}
/**
* Returns countryid by given countrycode
*
* @param string $sCode
* @return mixed
*/
public function fcpoGetIdByCode($sCode)
{
$sQuery = "SELECT oxid FROM oxcountry WHERE oxisoalpha2 = " . oxDb::getDb()->quote($sCode);
return $this->_oFcpoDb->GetOne($sQuery);
}
/**
* Returns salutation stored in database by firstname
*
* @param string $sFirstname
* @return string
*/
public function fcpoGetSalByFirstName($sFirstname)
{
$sQuery = "SELECT oxsal FROM oxuser WHERE oxfname = " . oxDb::getDb()->quote($sFirstname) . " AND oxsal != '' LIMIT 1";
$sSal = $this->_oFcpoDb->GetOne($sQuery);
return $sSal;
}
/**
* Checks address database for receiving a address matching to response
*
* @param array $aResponse
* @return mixed
*/
public function fcpoGetAddressIdByResponse($aResponse, $sStreet, $sStreetNr)
{
$sQuery = " SELECT
oxid
FROM
oxaddress
WHERE
oxfname = {$this->_oFcpoDb->quote($aResponse['add_paydata[shipping_firstname]'])} AND
oxlname = {$this->_oFcpoDb->quote($aResponse['add_paydata[shipping_lastname]'])} AND
oxstreet = {$this->_oFcpoDb->quote($sStreet)} AND
oxstreetnr = {$this->_oFcpoDb->quote($sStreetNr)} AND
oxcity = {$this->_oFcpoDb->quote($aResponse['add_paydata[shipping_city]'])} AND
oxzip = {$this->_oFcpoDb->quote($aResponse['add_paydata[shipping_zip]'])} AND
oxcountryid = {$this->_oFcpoDb->quote($this->fcpoGetIdByCode($aResponse['add_paydata[shipping_country]']))}";
return $this->_oFcpoDb->GetOne($sQuery);
}
/**
* Removes MSIE(\s)?(\S)*(\s) from browser agent information
*
* @param string $sAgent browser user agent idenfitier
*
* @return string
*/
protected function _fcProcessUserAgentInfo($sAgent)
{
if ($sAgent) {
$sAgent = getStr()->preg_replace("/MSIE(\s)?(\S)*(\s)/", "", (string) $sAgent);
}
return $sAgent;
}
/**
* Compares the HTTP user agent before and after the redirect payment method.
* If HTTP user agent is diffenrent it checks if the remote tokens match.
* If so, the current user agent is updated in the user session.
*
* @return null
*/
protected function _fcpoCheckUserAgent()
{
$oUtils = $this->_oFcpoHelper->fcpoGetUtilsServer();
$sAgent = $oUtils->getServerVar('HTTP_USER_AGENT');
$sExistingAgent = $this->_oFcpoHelper->fcpoGetSessionVariable('sessionagent');
$sAgent = $this->_fcProcessUserAgentInfo($sAgent);
$sExistingAgent = $this->_fcProcessUserAgentInfo($sExistingAgent);
if ($this->_fcGetCurrentVersion() >= 4310 && $sAgent && $sAgent !== $sExistingAgent) {
$oSession = $this->_oFcpoHelper->fcpoGetSession();
$sInputToken = $this->_oFcpoHelper->fcpoGetRequestParameter('rtoken');
$sToken = $oSession->getRemoteAccessToken(false);
$blValid = $this->_fcpoValidateToken($sInputToken, $sToken);
if ($blValid === true) {
$this->_oFcpoHelper->fcpoGetSessionVariable("sessionagent", $oUtils->getServerVar('HTTP_USER_AGENT'));
}
}
}
/**
* Compares tokens and returns if they are valid
*
* @param string $param
* @return bool
*/
protected function _fcpoValidateToken($sInputToken, $sToken)
{
$blTokenEqual = !(bool) strcmp($sInputToken, $sToken);
$blValid = $sInputToken && $blTokenEqual;
return $blValid;
}
/**
* Get current version number as 4 digit integer e.g. Oxid 4.5.9 is 4590
*
* @return integer
*/
protected function _fcGetCurrentVersion()
{
return $this->_oFcpoHelper->fcpoGetIntShopVersion();
}
/**
* Returns true if this request is the return to the shop from a payment provider where the user has been redirected to
*
* @return bool
*/
protected function _isRedirectAfterSave()
{
if ($this->_blIsRedirectAfterSave === null) {
$this->_blIsRedirectAfterSave = false;
$blUseRedirectAfterSave = (
$this->_oFcpoHelper->fcpoGetRequestParameter('fcposuccess') &&
$this->_oFcpoHelper->fcpoGetRequestParameter('refnr') &&
$this->_oFcpoHelper->fcpoGetSessionVariable('fcpoTxid')
);
if ($blUseRedirectAfterSave) {
$this->_blIsRedirectAfterSave = true;
}
}
return $this->_blIsRedirectAfterSave;
}
/**
* Overrides standard oxid finalizeOrder method
*
* Order checking, processing and saving method.
* Before saving performed checking if order is still not executed (checks in
* database oxorder table for order with know ID), if yes - returns error code 3,
* if not - loads payment data, assigns all info from basket to new oxorder object
* and saves full order with error status. Then executes payment. On failure -
* deletes order and returns error code 2. On success - saves order (oxorder::save()),
* removes article from wishlist (oxorder::_updateWishlist()), updates voucher data
* (oxorder::_markVouchers()). Finally sends order confirmation email to customer
* (oxemail::SendOrderEMailToUser()) and shop owner (oxemail::SendOrderEMailToOwner()).
* If this is order recalculation, skipping payment execution, marking vouchers as used
* and sending order by email to shop owner and user
* Mailing status (1 if OK, 0 on error) is returned.
*
* @param OxidEsales\Eshop\Application\Model\Basket $oBasket Shopping basket object
* @param object $oUser Current user object
* @param bool $blRecalculatingOrder Order recalculation
*
* @throws Exception
*
* @return integer
*/
public function finalizeOrder(OxidEsales\Eshop\Application\Model\Basket $oBasket, $oUser, $blRecalculatingOrder = false)
{
$sPaymentId = $oBasket->getPaymentId();
$this->_sFcpoPaymentId = $sPaymentId;
$blPayonePayment = $this->isPayOnePaymentType($sPaymentId);
// OXID-219 If payone method, the order will be completed by this method
// If overloading is needed, the _fcpoFinalizeOrder have to be overloaded
// Otherwise, the execution goes over, to the normal flow from parent class
if ($blPayonePayment) {
return $this->_fcpoFinalizeOrder($oBasket, $oUser, $blRecalculatingOrder);
}
return parent::finalizeOrder($oBasket, $oUser, $blRecalculatingOrder);
}
/**
* Overloading of basket load method for handling
* basket loading from session => avoiding loading it twice
*
* @param \OxidEsales\Eshop\Application\Model\Basket $oBasket
* @return mixed
* @see https://integrator.payone.de/jira/browse/OXID-263
*/
protected function _loadFromBasket(\OxidEsales\Eshop\Application\Model\Basket $oBasket)
{
$sSessionChallenge =
$this->_oFcpoHelper->fcpoGetSessionVariable('sess_challenge');
$blTriggerLoadingFromSession = (
$this->_blFcPoLoadFromSession &&
$sSessionChallenge
);
if (!$blTriggerLoadingFromSession)
return parent::_loadFromBasket($oBasket);
return $this->load($sSessionChallenge);
}
/**
* Assigns data, stored in oxorderarticles to oxorder object .
*
* @param bool $blExcludeCanceled excludes canceled items from list
*
* FATCHIP MOD:
* load articles from db if order already exists
*
* @return \oxlist
*/
public function getOrderArticles($blExcludeCanceled = false)
{
$sSessionChallenge =
$this->_oFcpoHelper->fcpoGetSessionVariable('sess_challenge');
$blSetArticlesNull = (
$this->_blFcPoLoadFromSession &&
$sSessionChallenge
);
if ($blSetArticlesNull) {
//null trigger orderarticles getter from db
$this->_oArticles = null;
}
return parent::getOrderArticles($blExcludeCanceled);
}
/**
* Payone handling on finalizing order
*
* @param $oBasket
* @param $oUser
* @param $blRecalculatingOrder
* @return bool|int
*/
protected function _fcpoFinalizeOrder($oBasket, $oUser, $blRecalculatingOrder) {
$blSaveAfterRedirect = $this->_isRedirectAfterSave();
$mRet = $this->_fcpoEarlyValidation($blSaveAfterRedirect, $oBasket, $oUser, $blRecalculatingOrder);
if ($mRet !== null) {
return $mRet;
}
// copies user info
$this->_setUser($oUser);
// copies basket info if no basket injection or presave order is inactive
$this->_fcpoHandleBasket($blSaveAfterRedirect, $oBasket);
// payment information
$oUserPayment = $this->_setPayment($oBasket->getPaymentId());
// set folder information, if order is new
// #M575 in recalcualting order case folder must be the same as it was
if (!$blRecalculatingOrder) {
$this->_setFolder();
}
$mRet = $this->_fcpoExecutePayment($blSaveAfterRedirect, $oBasket, $oUserPayment, $blRecalculatingOrder);
if ($mRet !== null) {
return $mRet;
}
//saving all order data to DB
$this->_blFinishingSave = true;
$this->save();
// deleting remark info only when order is finished
$this->_oFcpoHelper->fcpoDeleteSessionVariable('ordrem');
$this->_oFcpoHelper->fcpoDeleteSessionVariable('stsprotection');
//#4005: Order creation time is not updated when order processing is complete
if (method_exists($this, '_updateOrderDate') && !$blRecalculatingOrder) {
$this->_updateOrderDate();
}
$this->_fcpoSetOrderStatus();
// store orderid
$oBasket->setOrderId($this->getId());
$this->_fcpoAddShadowBasketOrderId();
// updating wish lists
$this->_updateWishlist($oBasket->getContents(), $oUser);
// updating users notice list
$this->_updateNoticeList($oBasket->getContents(), $oUser);
// marking vouchers as used and sets them to $this->_aVoucherList (will be used in order email)
// skipping this action in case of order recalculation
$this->_fcpoMarkVouchers($blRecalculatingOrder, $oUser, $oBasket);
if (!$this->oxorder__oxordernr->value) {
$this->_setNumber();
} else {
oxNew(\OxidEsales\Eshop\Core\Counter::class)->update($this->_getCounterIdent(), $this->oxorder__oxordernr->value);
}
$this->_fcpoSaveAfterRedirect($blSaveAfterRedirect);
$this->_oFcpoHelper->fcpoDeleteSessionVariable('fcpoordernotchecked');
$this->_oFcpoHelper->fcpoDeleteSessionVariable('fcpoWorkorderId');
// send order by email to shop owner and current user
// skipping this action in case of order recalculation
$iRet = $this->_fcpoFinishOrder($blRecalculatingOrder, $oUser, $oBasket, $oUserPayment);
// OXID-233 : handle amazon different login
$this->_fcpoAdjustAmazonPayUserDetails($oUserPayment);
return $iRet;
}
/**
* OXID-233: If the user was logged in during order,
* its ID is set back as order__userid, to link back the order to that user
*
* ONLY during AmazonPay process, and with logged user
* (i.e session 'sOxidPreAmzUser' is set)
*
* @param \OxidEsales\Eshop\Application\Model\UserPayment $oUserPayment
*/
protected function _fcpoAdjustAmazonPayUserDetails($oUserPayment)
{
$sUserId = $this->_oFcpoHelper->fcpoGetSessionVariable('sOxidPreAmzUser');
if (!empty($sUserId)) {
$this->oxorder__oxuserid = new \OxidEsales\Eshop\Core\Field($sUserId);
$this->save();
$oUserPayment->oxuserpayments__oxuserid = new \OxidEsales\Eshop\Core\Field($sUserId);
$oUserPayment->save();
$this->_oFcpoHelper->fcpoSetSessionVariable('usr', $sUserId);
$this->_oFcpoHelper->fcpoDeleteSessionVariable('sOxidPreAmzUser');
}
}
/**
* Overriding _setUser for correcting email-address
*
* @param void
* @return void
*/
protected function _setUser($oUser) {
parent::_setUser($oUser);
if ($this->_sFcpoPaymentId == 'fcpoamazonpay') {
$oViewConf = $this->_oFcpoHelper->getFactoryObject('oxViewConfig');
$sPrefixEmail = $oUser->oxuser__oxusername->value;
$sEmail = $oViewConf->fcpoAmazonEmailDecode($sPrefixEmail);
$this->oxorder__oxbillemail = new oxField($sEmail);
}
}
/**
* Triggers steps to execute payment
*
* @param bool $blSaveAfterRedirect
* @param oxBasket $oBasket
* @param oxUserPayment $oUserPayment
* @return mixed
*/
protected function _fcpoExecutePayment($blSaveAfterRedirect, $oBasket, $oUserPayment, $blRecalculatingOrder)
{
if ($blSaveAfterRedirect === true) {
$sRefNrCheckResult = $this->_fcpoCheckRefNr();
$sTxid = $this->_oFcpoHelper->fcpoGetSessionVariable('fcpoTxid');
if ($sRefNrCheckResult != '') {
return $sRefNrCheckResult;
}
$this->_fcpoProcessOrder($sTxid);
} else {
if (!$blRecalculatingOrder) {
$blRet = $this->_executePayment($oBasket, $oUserPayment);
if ($blRet !== true) {
return $blRet;
}
}
}
return null;
}
/**
* Returns oxuser object of this user
* Adjustment for prefixed email (currently amazon)
*
* @param void
* @return oxUser
*/
public function getOrderUser() {
$oUser = parent::getOrderUser();
$sPaymenttype = $this->oxorder__oxpaymenttype->value;
if ($sPaymenttype == 'fcpoamazonpay') {
$oViewConf = $this->_oFcpoHelper->getFactoryObject('oxViewConfig');
$sPrefixEmail = $oUser->oxuser__oxusername->value;
$sEmail = $oViewConf->fcpoAmazonEmailDecode($sPrefixEmail);
$oUser->oxuser__oxusername = new oxField($sEmail);
}
return $oUser;
}
/**
* Sends clearing data mail to customer after a capture.
* This currently is only for payment fcpoinvoice
*
*
*/
public function fcpoSendClearingDataAfterCapture()
{
$sPaymentId = $this->oxorder__oxpaymenttype->value;
$sAuthMode = $this->oxorder__fcpoauthmode->value;
$blSendMail = (
in_array($sPaymentId, array('fcpoinvoice','fcpopayadvance')) &&
$sAuthMode == 'preauthorization'
);
if (!$blSendMail) {
return;
};
$sTo = $this->oxorder__oxbillemail->value;
$sSubject = $this->_fcpoGetClearingDataEmailSubject();
$sBody = $this->_fcpoGetClearingDataEmailBody();
$oEmail = $this->_oFcpoHelper->getFactoryObject('oxEmail');
$oEmail->sendEmail($sTo, $sSubject, $sBody);
}
/**
* Returns translated subject for clearing mail
*
* @param void
* @return string
*/
protected function _fcpoGetClearingDataEmailSubject()
{
$oLang = $this->_oFcpoHelper->getFactoryObject('oxLang');
$oShop = $this->_oFcpoHelper->getFactoryObject('oxShop');
$oShop->load($this->oxorder__oxshopid->value);
$sSubject = $oShop->oxshops__oxname->value." - ";
$sSubject .= $oLang->translateString('FCPO_EMAIL_CLEARING_SUBJECT')." ";
$sSubject .= $this->oxorder__oxordernr->value;
return $sSubject;
}
/**
* Returns translated body content for clearing mail
*
* @param void
* @return string
*/
protected function _fcpoGetClearingDataEmailBody()
{
$oLang = $this->_oFcpoHelper->getFactoryObject('oxLang');
$oShop = $this->_oFcpoHelper->getFactoryObject('oxShop');
$oShop->load($this->oxorder__oxshopid->value);
$sBody = $oLang->translateString('FCPO_EMAIL_CLEARING_BODY_WELCOME');
$sBody = str_replace('%NAME%', $this->oxorder__oxbillfname->value, $sBody);
$sBody = str_replace('%SURNAME%', $this->oxorder__oxbilllname->value, $sBody);
$sBody .= $oLang->translateString("FCPO_BANKACCOUNTHOLDER").": ".$this->getFcpoBankaccountholder()."\n";
$sBody .= $oLang->translateString("FCPO_EMAIL_BANK")." ".$this->getFcpoBankname()."\n";
$sBody .= $oLang->translateString("FCPO_EMAIL_ROUTINGNUMBER")." ".$this->getFcpoBankcode()."\n";
$sBody .= $oLang->translateString("FCPO_EMAIL_ACCOUNTNUMBER")." ".$this->getFcpoBanknumber()."\n";
$sBody .= $oLang->translateString("FCPO_EMAIL_BIC")." ".$this->getFcpoBiccode()."\n";
$sBody .= $oLang->translateString("FCPO_EMAIL_IBAN")." ".$this->getFcpoIbannumber()."\n";
$sBody .= $oLang->translateString("FCPO_EMAIL_USAGE").": ".$this->oxorder__fcpotxid->value."\n";
$sBody .= "\n\n";
$sThankyou = $oLang->translateString('FCPO_EMAIL_CLEARING_BODY_THANKYOU');
$sBody .= str_replace('%SHOPNAME%', $oShop->oxshops__oxname->value, $sThankyou);
return $sBody;
}
/**
* Handles basket loading into order
*
* @param bool $blSaveAfterRedirect
* @param oxBasket $oBasket
* @return void
*/
protected function _fcpoHandleBasket($blSaveAfterRedirect, $oBasket)
{
$sGetChallenge = $this->_oFcpoHelper->fcpoGetSessionVariable('sess_challenge');
$oConfig = $this->getConfig();
$blFCPOPresaveOrder = $oConfig->getConfigParam('blFCPOPresaveOrder');
if ($blFCPOPresaveOrder === false || $blSaveAfterRedirect === false) {
$this->_loadFromBasket($oBasket);
} else {
$this->load($sGetChallenge);
}
}
/**
*
*
* @param bool $blSaveAfterRedirected
* @param oxBasket $oBasket
* @param oxUser $oUser
* @return mixed
*/
protected function _fcpoEarlyValidation($blSaveAfterRedirect, $oBasket, $oUser, $blRecalculatingOrder)
{
// check if this order is already stored
$sGetChallenge = $this->_oFcpoHelper->fcpoGetSessionVariable('sess_challenge');
$this->_blFcPoLoadFromSession = (
$blSaveAfterRedirect &&
!$blRecalculatingOrder &&
$sGetChallenge &&
$oBasket &&
$oUser &&
$this->_checkOrderExist($sGetChallenge)
);
$blIsRedirectionOnGoing = (bool) $this->_oFcpoHelper->fcpoGetSessionVariable('fcpoRedirectOnGoing');
if ($blSaveAfterRedirect === false && !$blIsRedirectionOnGoing) {
if ($this->_checkOrderExist($sGetChallenge)) {
$oUtils = $this->_oFcpoHelper->fcpoGetUtils();
$oUtils->logger('BLOCKER');
// we might use this later, this means that somebody klicked like mad on order button
return self::ORDER_STATE_ORDEREXISTS;
}
}
// check if basket is still the same as it was before
if ($blSaveAfterRedirect) {
$this->_fcCompareBasketAgainstShadowBasket($oBasket);
}
// if not recalculating order, use sess_challenge id, else leave old order id
if (!$blRecalculatingOrder) {
// use this ID
$this->setId($sGetChallenge);
// validating various order/basket parameters before finalizing
if (($iOrderState = $this->validateOrder($oBasket, $oUser))) {
return $iOrderState;
}
}
return null;
}
/**
* Checks if previously saved basket is still the same (valid) as it is now
*
* @param void
* @return void
*/
protected function _fcCompareBasketAgainstShadowBasket($oBasket) {
$oShadowBasket = $this->fcpoGetShadowBasket();
$blIsValid = $this->_fcpoCompareBaskets($oBasket, $oShadowBasket);
if ($blIsValid === false) {
$this->_fcpoMarkOrderAsProblematic();
$this->_fcpoAddShadowBasketCheckDate();
} else {
$this->_fcpoDeleteShadowBasket();
}
}
/**
* Adding checkdate to basket, so we can see how much time has been between
* creating and checking the shadow basket
*
* @param void
* @return void
*/
protected function _fcpoAddShadowBasketCheckDate() {
$oDb = $this->_oFcpoHelper->fcpoGetDb();
$oSession = $this->getSession();
$sSessionId = $oSession->getId();
$sQuery = "
UPDATE
fcposhadowbasket
SET
FCPOCHECKED=NOW()
WHERE
FCPOSESSIONID=".$oDb->quote($sSessionId)."
LIMIT 1
";
$oDb->Execute($sQuery);
}
/**
* Adds orderid to shadowbasket table, so it is possible to analyze
* differences
*
* @param void
* @return void
*/
protected function _fcpoAddShadowBasketOrderId() {
$oDb = $this->_oFcpoHelper->fcpoGetDb();
$oSession = $this->getSession();
$sSessionId = $oSession->getId();
$sQuery = "
UPDATE
fcposhadowbasket
SET
OXORDERID=".$oDb->quote($this->getId())."
WHERE
FCPOSESSIONID=".$oDb->quote($sSessionId)."
LIMIT 1
";
$oDb->Execute($sQuery);
}
/**
* Deleting Shadow-Basket
*
* @param void
* @return void
*/
protected function _fcpoDeleteShadowBasket() {
$oDb = $this->_oFcpoHelper->fcpoGetDb();
$oSession = $this->getSession();
$sSessionId = $oSession->getId();
$sQuery = "
DELETE FROM
fcposhadowbasket
WHERE
FCPOSESSIONID=".$oDb->quote($sSessionId)."
LIMIT 1
";
$oDb->Execute($sQuery);
}
/**
* Compares current basket with prior saved basket for avoiding fraud
*
* @param $oBasket
* @param $oShadowBasket
* @return bool
*/
protected function _fcpoCompareBaskets($oBasket, $oShadowBasket) {
$blGeneralCheck = (
$oShadowBasket instanceof oxBasket &&
$oBasket instanceof oxBasket
);
if ($blGeneralCheck == false) {
$blReturn = false;
} else {
// compare brut sums
$dBruttoSumBasket = $oBasket->getBruttoSum();
$dBruttoSumShadowBasket = $oShadowBasket->getBruttoSum();
$blReturn = ($dBruttoSumBasket == $dBruttoSumShadowBasket);
}
return $blReturn;
}
/**
* Returns shadow Basket matching to sessionid
*
* @param $blByOrderId
* @return mixed object | bool
*/
public function fcpoGetShadowBasket($blByOrderId=false) {
$oDb = $this->_oFcpoHelper->fcpoGetDb();
$oSession = $this->getSession();
$sSessionId = $oSession->getId();
$oShadowBasket = false;
$sWhere = "FCPOSESSIONID=".$oDb->quote($sSessionId);
if ($blByOrderId){
$sWhere = "OXORDERID=".$oDb->quote($this->getId());
}
$sQuery = "
SELECT
FCPOBASKET
FROM
fcposhadowbasket
WHERE
".$sWhere."
LIMIT 1
";
$sSerializedShadowBasket = $oDb->GetOne($sQuery);
if ($sSerializedShadowBasket) {
$oShadowBasket = unserialize(base64_decode($sSerializedShadowBasket));
}
return $oShadowBasket;
}
/**
* Mark order as problematic
*
* @param void
* @return void
*/
protected function _fcpoMarkOrderAsProblematic() {
$this->_blOrderHasProblems = true;
}
/**
* Finishes order and returns state
*
* @param bool $blRecalculatingOrder
* @param oxUser $oUser
* @param oxBasket $oBasket
* @param oxUserPayment $oUserPayment
* @return int
*/
protected function _fcpoFinishOrder($blRecalculatingOrder, $oUser, $oBasket, $oUserPayment)
{
if (!$blRecalculatingOrder) {
$iRet = $this->_sendOrderByEmail($oUser, $oBasket, $oUserPayment);
} else {
$iRet = self::ORDER_STATE_OK;
}
return $iRet;
}
/**
* Mathod triggers saving after redirect if this option has been configured
*
* @param bool $blSaveAfterRedirect
* @return void
*/
protected function _fcpoSaveAfterRedirect($blSaveAfterRedirect)
{
if ($blSaveAfterRedirect === true && !empty($this->oxorder__fcpotxid->value)) {
$sQuery = "UPDATE fcpotransactionstatus SET fcpo_ordernr = '{$this->oxorder__oxordernr->value}' WHERE fcpo_txid = '".$this->oxorder__fcpotxid->value."'";
$this->_oFcpoDb->Execute($sQuery);
}
}
/**
* Sets order status depending on having an appointed error
*
* @return void
*/
protected function _fcpoSetOrderStatus() {
$blIsAmazonPending = $this->_oFcpoHelper->fcpoGetSessionVariable('fcpoAmazonPayOrderIsPending');
$blOrderOk = $this->_fcpoValidateOrderAgainstProblems();
if ($blIsAmazonPending) {
$this->_setOrderStatus('PENDING');
$this->oxorder__oxfolder = new oxField('ORDERFOLDER_PROBLEMS', oxField::T_RAW);
$this->save();
} elseif ($blOrderOk === true) {
// updating order trans status (success status)
$this->_setOrderStatus('OK');
} else {
$this->_setOrderStatus('ERROR');
}
}
/**
* Validates order for checking if there were any occuring problems
*
* @param void
* @return bool
*/
protected function _fcpoValidateOrderAgainstProblems() {
$blOrderOk = (
$this->_fcpoGetAppointedError() === false &&