@@ -694,8 +694,8 @@ protected function startTransaction(WC_Order $order, $pickupLocation = null)
694694 $ clean = preg_replace ('/[^A-Za-z0-9]/u ' , '' , $ raw );
695695 $ request ->setReference ($ clean );
696696
697- if ($ this ->getOptionId () == 1927 ) {
698- $ request ->setTerminal (PPMFWC_Helper_Data:: getPostTextField ( ' terminal_id ' ));
697+ if ($ this ->getOptionId () == PayNL \ Sdk \ Model \Method:: PIN ) {
698+ $ request ->setTerminal ($ this -> getTerminal ( ));
699699 }
700700
701701 $ extra1 = apply_filters ('paynl-extra1 ' , $ order ->get_order_number (), $ order );
@@ -733,6 +733,30 @@ protected function startTransaction(WC_Order $order, $pickupLocation = null)
733733 return $ payOrder ;
734734 }
735735
736+ /**
737+ * @return false|string
738+ */
739+ private function getTerminal ()
740+ {
741+ $ terminalThCode = PPMFWC_Helper_Data::getPostTextField ('terminal_id ' );
742+ $ terminal_setting = $ this ->get_option ('paynl_instore_terminal ' );
743+
744+ if ($ terminal_setting == 'checkout ' ) {
745+ # do nothing, just use terminalThCode
746+ }
747+ if ($ terminal_setting == 'checkout_save ' ) {
748+ # Only save the tg-code in the cookie. This will then later be integrated in the checkout-view(hidden).
749+ setcookie ('paynl_instore_terminal_id ' , $ terminalThCode , time () + (60 * 60 * 24 * 365 ));
750+
751+ } elseif (str_starts_with (strtoupper ($ terminal_setting ), 'TH ' )) {
752+ # A designated TH-code is selected as preferred terminal, so always use this one.
753+ $ terminalThCode = $ terminal_setting ;
754+ }
755+
756+
757+ return $ terminalThCode ?? '' ;
758+ }
759+
736760 /**
737761 * @return boolean
738762 */
0 commit comments