@@ -28,7 +28,7 @@ private function __construct(Registry $registry){
2828 $ this ->loggers = array (
2929 self ::LOG_ERROR => $ registry ->get ('log ' ),
3030 self ::LOG_DEBUG => new Log ('wallee_debug.log ' ),
31- self ::LOG_INFO => new Log ('wallee_info.log ' )
31+ self ::LOG_INFO => new Log ('wallee_info.log ' )
3232 );
3333 }
3434 else {
@@ -108,14 +108,15 @@ public function compareStoredCustomerSessionIdentifier(){
108108 else {
109109 return false ;
110110 }
111-
111+
112112 $ parts = explode ('_ ' , $ id );
113113 $ customer = $ this ->getCustomer ();
114114 switch ($ parts [0 ]) {
115115 case 'customer ' :
116116 return isset ($ customer ['customer_id ' ]) && 'customer_ ' . $ customer ['customer_id ' ] == $ id ;
117117 case 'user ' :
118- return (isset ($ customer ['user_id ' ]) && 'user_ ' . $ customer ['user_id ' ] == $ id ) || (isset ($ data ['user_id ' ]) && 'user_ ' . $ data ['user_id ' ] == $ id );
118+ return (isset ($ customer ['user_id ' ]) && 'user_ ' . $ customer ['user_id ' ] == $ id ) ||
119+ (isset ($ data ['user_id ' ]) && 'user_ ' . $ data ['user_id ' ] == $ id );
119120 case 'guest ' :
120121 return $ this ->buildGuestSessionIdentifier ($ customer ) == $ id ;
121122 case 'cart ' :
@@ -140,17 +141,17 @@ public function getAddress($key, $order_info = array()){
140141 $ session = $ this ->registry ->get ('session ' )->data ;
141142 $ address_model = $ this ->registry ->get ('model_account_address ' );
142143 $ address = array ();
143-
144+
144145 if (isset ($ order_info [$ key . '_address ' ])) {
145146 $ address = \WalleeHelper::mergeArray ($ address , $ order_info [$ key . '_address ' ]);
146147 }
147148 if (isset ($ order_info [$ key . '_address_id ' ])) {
148149 $ address = \WalleeHelper::mergeArray ($ address , $ address_model ->getAddress ($ $ order_info [$ key . '_address_id ' ]));
149150 }
150- if (empty ($ address ) && $ key != 'payment ' ) {
151+ if (empty ($ address ) && $ key != 'payment ' ) {
151152 $ address = $ this ->getAddress ('payment ' , $ order_info );
152153 }
153- if (empty ($ address )) {
154+ if (empty ($ address )) {
154155 if ($ customer && $ customer ->isLogged () && isset ($ session [$ key . '_address_id ' ])) {
155156 $ address = $ address_model ->getAddress ($ session [$ key . '_address_id ' ]);
156157 }
@@ -170,7 +171,7 @@ public function getAddress($key, $order_info = array()){
170171 public function refreshWebhook (){
171172 $ db = $ this ->registry ->get ('db ' );
172173 $ config = DB_PREFIX . 'setting ' ;
173-
174+
174175 $ generated = $ this ->getWebhookUrl ();
175176 $ saved = $ this ->registry ->get ('config ' )->get ('wallee_notification_url ' );
176177 if ($ generated == $ saved ) {
@@ -179,7 +180,7 @@ public function refreshWebhook(){
179180 $ space_id = $ this ->registry ->get ('config ' )->get ('wallee_space_id ' );
180181 \Wallee \Service \Webhook::instance ($ this ->registry )->uninstall ($ space_id , $ saved );
181182 \Wallee \Service \Webhook::instance ($ this ->registry )->install ($ space_id , $ generated );
182-
183+
183184 $ store_id = $ this ->registry ->get ('config ' )->get ('config_store_id ' );
184185 if ($ store_id === null ) {
185186 $ store_id = 0 ;
@@ -217,22 +218,22 @@ public function areAmountsEqual($amount1, $amount2, $currency_code){
217218
218219 public function hasRunningJobs (\Wallee \Entity \TransactionInfo $ transaction_info ){
219220 return \Wallee \Entity \CompletionJob::countRunningForOrder ($ this ->registry , $ transaction_info ->getOrderId ()) +
220- \Wallee \Entity \VoidJob::countRunningForOrder ($ this ->registry , $ transaction_info ->getOrderId ()) +
221- \Wallee \Entity \RefundJob::countRunningForOrder ($ this ->registry , $ transaction_info ->getOrderId ()) > 0 ;
221+ \Wallee \Entity \VoidJob::countRunningForOrder ($ this ->registry , $ transaction_info ->getOrderId ()) +
222+ \Wallee \Entity \RefundJob::countRunningForOrder ($ this ->registry , $ transaction_info ->getOrderId ()) > 0 ;
222223 }
223224
224225 public function isCompletionPossible (\Wallee \Entity \TransactionInfo $ transaction_info ){
225226 return $ transaction_info ->getState () == \Wallee \Sdk \Model \TransactionState::AUTHORIZED &&
226- (\Wallee \Entity \CompletionJob::countRunningForOrder ($ this ->registry , $ transaction_info ->getOrderId ()) == 0 ) &&
227- (\Wallee \Entity \VoidJob::countRunningForOrder ($ this ->registry , $ transaction_info ->getOrderId ()) == 0 );
227+ (\Wallee \Entity \CompletionJob::countRunningForOrder ($ this ->registry , $ transaction_info ->getOrderId ()) == 0 ) &&
228+ (\Wallee \Entity \VoidJob::countRunningForOrder ($ this ->registry , $ transaction_info ->getOrderId ()) == 0 );
228229 }
229230
230231 public function isRefundPossible (\Wallee \Entity \TransactionInfo $ transaction_info ){
231232 if (!in_array ($ transaction_info ->getState (),
232233 array (
233234 \Wallee \Sdk \Model \TransactionState::COMPLETED ,
234235 \Wallee \Sdk \Model \TransactionState::FULFILL ,
235- \Wallee \Sdk \Model \TransactionState::DECLINE
236+ \Wallee \Sdk \Model \TransactionState::DECLINE
236237 ))) {
237238 return false ;
238239 }
@@ -372,14 +373,14 @@ public function dbTransactionRollback(){
372373 */
373374 public function dbTransactionLock ($ space_id , $ transaction_id ){
374375 $ db = $ this ->registry ->get ('db ' );
375-
376+
376377 $ table = DB_PREFIX . 'wallee_transaction_info ' ;
377378 $ locked_at = date ('Y-m-d H:i:s ' );
378379 $ space_id = $ db ->escape ($ space_id );
379380 $ transaction_id = $ db ->escape ($ transaction_id );
380-
381+
381382 $ db ->query ("SELECT locked_at FROM $ table WHERE transaction_id = ' $ transaction_id' AND space_id = ' $ space_id' FOR UPDATE " );
382-
383+
383384 $ db ->query ("UPDATE $ table SET locked_at = ' $ locked_at' WHERE transaction_id = ' $ transaction_id' AND space_id = ' $ space_id' " );
384385 }
385386
@@ -388,7 +389,7 @@ public function translate($strings, $language = null){
388389 if (isset ($ strings [$ language ])) {
389390 return $ strings [$ language ];
390391 }
391-
392+
392393 if ($ language ) {
393394 try {
394395 $ language_provider = \Wallee \Provider \Language::instance ($ this ->registry );
@@ -434,10 +435,10 @@ public function getCleanLanguageCode($language = null){
434435 $ language = $ config ->get ('config_admin_language ' );
435436 }
436437 }
437-
438+
438439 $ prefixWithDash = substr ($ language , 0 , 3 );
439440 $ postfix = strtoupper (substr ($ language , 3 ));
440-
441+
441442 return $ prefixWithDash . $ postfix ;
442443 }
443444
@@ -468,7 +469,7 @@ public function getCache(){
468469
469470 public function getSuccessUrl (){
470471 return WalleeVersionHelper::createUrl ($ this ->getCatalogUrl (), 'checkout/success ' , array (
471- 'utm_nooverride ' => 1
472+ 'utm_nooverride ' => 1
472473 ), $ this ->registry ->get ('config ' )->get ('config_secure ' ));
473474 }
474475
@@ -477,7 +478,7 @@ public function getFailedUrl($order_id){
477478 WalleeVersionHelper::createUrl ($ this ->getCatalogUrl (), 'extension/wallee/transaction/fail ' ,
478479 array (
479480 'order_id ' => $ order_id ,
480- 'utm_nooverride ' => 1
481+ 'utm_nooverride ' => 1
481482 ), $ this ->registry ->get ('config ' )->get ('config_secure ' )));
482483 }
483484
@@ -494,7 +495,8 @@ public function getWebhookUrl(){
494495 public function isValidOrder ($ order_id ){
495496 if (!$ this ->isAdmin ()) {
496497 $ order_info = $ this ->getOrder ($ order_id );
497- if ($ this ->registry ->get ('customer ' ) && $ this ->registry ->get ('customer ' )->isLogged () && isset ($ this ->registry ->get ('session ' )->data ['customer_id ' ])) {
498+ if ($ this ->registry ->get ('customer ' ) && $ this ->registry ->get ('customer ' )->isLogged () &&
499+ isset ($ this ->registry ->get ('session ' )->data ['customer_id ' ])) {
498500 if ($ this ->registry ->get ('session ' )->data ['customer_id ' ] != $ order_info ['customer_id ' ]) {
499501 return false ;
500502 }
@@ -539,6 +541,21 @@ public function addOrderHistory($order_id, $status, $message = '', $notify = fal
539541 $ this ->registry ->get ('model_checkout_order ' )->addOrderHistory ($ order_id , $ status , $ message , $ notify );
540542 }
541543
544+ public function ensurePaymentCode (array $ order_info , \Wallee \Sdk \Model \Transaction $ transaction ){
545+ $ code = 'wallee_ ' . $ transaction ->getPaymentConnectorConfiguration ()->getPaymentMethodConfiguration ()->getId ();
546+ if ($ order_info ['payment_code ' ] == $ code ) {
547+ return ;
548+ }
549+ $ db = $ this ->registry ->get ('db ' );
550+ $ table = DB_PREFIX . 'order ' ;
551+ $ code = $ db ->escape ($ code );
552+ $ title = $ db ->escape ($ transaction ->getPaymentConnectorConfiguration ()->getPaymentMethodConfiguration ()->getName ());
553+ $ order_id = $ db ->escape ($ order_info ['order_id ' ]);
554+ $ query = "UPDATE ` $ table` SET `payment_code`=' $ code', `payment_method`=' $ title' WHERE `order_id`=' $ order_id'; " ;
555+ $ this ->log ("Changing payment method on order: [ " . $ query . "], was [ " . $ order_info ['payment_code ' ] . "] " , self ::LOG_DEBUG );
556+ $ db ->query ($ query );
557+ }
558+
542559 /**
543560 *
544561 * @return Url
@@ -580,10 +597,10 @@ private function getStoreUrl($ssl = true){
580597 public function rewrite ($ url ){
581598 return str_replace (array (
582599 HTTP_SERVER ,
583- HTTPS_SERVER
600+ HTTPS_SERVER
584601 ), array (
585602 HTTP_CATALOG ,
586- HTTPS_CATALOG
603+ HTTPS_CATALOG
587604 ), $ url );
588605 }
589606
@@ -614,30 +631,31 @@ public function getLimitEnd($page){
614631 $ limit = $ this ->registry ->get ('config ' )->get ('config_limit_admin ' );
615632 return $ page * $ limit ;
616633 }
617-
634+
618635 /**
619- * Disable inc vat setting in xfeepro. Necessary to ensure taxes are calculated and transmitted correctly.
636+ * Disable inc vat setting in xfeepro.
637+ * Necessary to ensure taxes are calculated and transmitted correctly.
620638 */
621- public function xfeeproDisableIncVat () {
639+ public function xfeeproDisableIncVat (){
622640 $ config = $ this ->registry ->get ('config ' );
623641 $ xfeepro = $ config ->get ('xfeepro ' );
624- if ($ xfeepro ) {
642+ if ($ xfeepro ) {
625643 $ xfeepro = unserialize (base64_decode ($ xfeepro ));
626644 $ this ->xfeepro = $ xfeepro ;
627- if (isset ($ xfeepro ['inc_vat ' ])) {
628- foreach ($ xfeepro ['inc_vat ' ] as $ i => $ value ) {
645+ if (isset ($ xfeepro ['inc_vat ' ])) {
646+ foreach ($ xfeepro ['inc_vat ' ] as $ i => $ value ) {
629647 $ xfeepro ['inc_vat ' ][$ i ] = 0 ;
630- }
648+ }
631649 }
632650 $ config ->set ('xfeepro ' , base64_encode (serialize ($ xfeepro )));
633651 }
634652 }
635-
653+
636654 /**
637655 * Restore xfeepro settings.
638656 */
639- public function xfeeProRestoreIncVat () {
640- if ($ this ->xfeepro ) {
657+ public function xfeeProRestoreIncVat (){
658+ if ($ this ->xfeepro ) {
641659 $ this ->registry ->get ('config ' )->set ('xfeepro ' , base64_encode (serialize ($ this ->xfeepro )));
642660 }
643661 }
@@ -648,8 +666,8 @@ public static function instance(Registry $registry){
648666 }
649667 return self ::$ instance ;
650668 }
651-
652- public static function extractPaymentMethodId ($ code ) {
669+
670+ public static function extractPaymentMethodId ($ code ){
653671 return substr ($ code , strlen ('wallee_ ' ));
654672 }
655673
@@ -669,7 +687,7 @@ public static function isEditableState($state){
669687 $ completable_states = array (
670688 \Wallee \Sdk \Model \TransactionState::AUTHORIZED ,
671689 \Wallee \Sdk \Model \TransactionState::CONFIRMED ,
672- \Wallee \Sdk \Model \TransactionState::PROCESSING
690+ \Wallee \Sdk \Model \TransactionState::PROCESSING
673691 );
674692 return in_array ($ state , $ completable_states );
675693 }
0 commit comments