@@ -679,8 +679,8 @@ protected function startTransaction(WC_Order $order, $pickupLocation = null)
679679 $ clean = preg_replace ('/[^A-Za-z0-9]/u ' , '' , $ raw );
680680 $ request ->setReference ($ clean );
681681
682- if ($ this ->getOptionId () == 1927 ) {
683- $ request ->setTerminal (PPMFWC_Helper_Data:: getPostTextField ( ' terminal_id ' ));
682+ if ($ this ->getOptionId () == PayNL \ Sdk \ Model \Method:: PIN ) {
683+ $ request ->setTerminal ($ this -> getTerminal ( ));
684684 }
685685
686686 $ extra1 = apply_filters ('paynl-extra1 ' , $ order ->get_order_number (), $ order );
@@ -718,6 +718,30 @@ protected function startTransaction(WC_Order $order, $pickupLocation = null)
718718 return $ payOrder ;
719719 }
720720
721+ /**
722+ * @return false|string
723+ */
724+ private function getTerminal ()
725+ {
726+ $ terminalThCode = PPMFWC_Helper_Data::getPostTextField ('terminal_id ' );
727+ $ terminal_setting = $ this ->get_option ('paynl_instore_terminal ' );
728+
729+ if ($ terminal_setting == 'checkout ' ) {
730+ # do nothing, just use terminalThCode
731+ }
732+ if ($ terminal_setting == 'checkout_save ' ) {
733+ # Only save the tg-code in the cookie. This will then later be integrated in the checkout-view(hidden).
734+ setcookie ('paynl_instore_terminal_id ' , $ terminalThCode , time () + (60 * 60 * 24 * 365 ));
735+
736+ } elseif (str_starts_with (strtoupper ($ terminal_setting ), 'TH ' )) {
737+ # A designated TH-code is selected as preferred terminal, so always use this one.
738+ $ terminalThCode = $ terminal_setting ;
739+ }
740+
741+
742+ return $ terminalThCode ?? '' ;
743+ }
744+
721745 /**
722746 * @return boolean
723747 */
0 commit comments