@@ -140,6 +140,8 @@ public function __construct( WC_PostFinanceCheckout_Entity_Method_Configuration
140140 )
141141 );
142142
143+ add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'enqueue_checkout_scripts ' ) );
144+
143145 $ this ->supports = array (
144146 'products ' ,
145147 'refunds ' ,
@@ -433,7 +435,7 @@ protected function get_safe_possible_payment_methods_for_cart() {
433435 WooCommerce_PostFinanceCheckout::instance ()->log ( $ e ->getMessage (), WC_Log_Levels::DEBUG );
434436 }
435437
436- return false ;
438+ return array () ;
437439 }
438440
439441 /**
@@ -473,7 +475,6 @@ public function payment_fields() {
473475
474476 parent ::payment_fields ();
475477 $ transaction_service = WC_PostFinanceCheckout_Service_Transaction::instance ();
476- $ woocommerce_data = get_plugin_data ( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php ' , false , false );
477478 try {
478479 if ( apply_filters ( 'wc_postfinancecheckout_is_order_pay_endpoint ' , is_checkout_pay_page () ) ) { //phpcs:ignore
479480 global $ wp ;
@@ -485,49 +486,6 @@ public function payment_fields() {
485486 } else {
486487 $ transaction = $ transaction_service ->get_transaction_from_session ();
487488 }
488- if ( ! wp_script_is ( 'postfinancecheckout-remote-checkout-js ' , 'enqueued ' ) ) {
489- $ ajax_url = $ transaction_service ->get_javascript_url_for_transaction ( $ transaction );
490- // !isset($wp->query_vars['order-pay'])->If you're not in the "re-pay" checkout.
491- if (
492- ( get_option ( WooCommerce_PostFinanceCheckout::POSTFINANCECHECKOUT_CK_INTEGRATION ) == WC_PostFinanceCheckout_Integration::POSTFINANCECHECKOUT_LIGHTBOX )
493- && ( is_checkout ()
494- && ! isset ( $ wp ->query_vars ['order-pay ' ] ) )
495- ) {
496- $ ajax_url = $ transaction_service ->get_lightbox_url_for_transaction ( $ transaction );
497- }
498- wp_enqueue_script (
499- 'postfinancecheckout-remote-checkout-js ' ,
500- $ ajax_url ,
501- array (
502- 'jquery ' ,
503- ),
504- 1 ,
505- true
506- );
507- wp_enqueue_script (
508- 'postfinancecheckout-checkout-js ' ,
509- WooCommerce_PostFinanceCheckout::instance ()->plugin_url () . '/assets/js/frontend/checkout.js ' ,
510- array (
511- 'jquery ' ,
512- 'jquery-blockui ' ,
513- 'postfinancecheckout-remote-checkout-js ' ,
514- ),
515- 1 ,
516- true
517- );
518- global $ wp_version ;
519- $ localize = array (
520- 'i18n_not_complete ' => esc_html__ ( 'Please fill out all required fields. ' , 'woo-postfinancecheckout ' ),
521- 'integration ' => get_option ( WooCommerce_PostFinanceCheckout::POSTFINANCECHECKOUT_CK_INTEGRATION ),
522- 'versions ' => array (
523- 'wordpress ' => $ wp_version ,
524- 'woocommerce ' => $ woocommerce_data ['Version ' ],
525- 'postfinancecheckout ' => WC_POSTFINANCECHECKOUT_VERSION ,
526- ),
527- );
528- wp_localize_script ( 'postfinancecheckout-checkout-js ' , 'postfinancecheckout_js_params ' , $ localize );
529-
530- }
531489 $ transaction_nonce = hash_hmac ( 'sha256 ' , $ transaction ->getLinkedSpaceId () . '- ' . $ transaction ->getId (), NONCE_KEY );
532490
533491 ?>
@@ -550,6 +508,70 @@ class="postfinancecheckout-method-configuration" style="display: none;"
550508 }
551509 }
552510
511+ public function enqueue_checkout_scripts () {
512+
513+ $ transaction_service = WC_PostFinanceCheckout_Service_Transaction::instance ();
514+ $ woocommerce_data = get_plugin_data ( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php ' , false , false );
515+ if ( apply_filters ( 'wc_postfinancecheckout_is_order_pay_endpoint ' , is_checkout_pay_page () ) ) { //phpcs:ignore
516+ global $ wp ;
517+ $ order = WC_Order_Factory::get_order ( $ wp ->query_vars ['order-pay ' ] );
518+ if ( ! $ order ) {
519+ return false ;
520+ }
521+ $ transaction = $ transaction_service ->get_transaction_from_order ( $ order );
522+ } else {
523+ $ transaction = $ transaction_service ->get_transaction_from_session ();
524+ }
525+ if ( ! wp_script_is ( 'postfinancecheckout-remote-checkout-js ' , 'enqueued ' ) ) {
526+ $ ajax_url = $ transaction_service ->get_javascript_url_for_transaction ( $ transaction );
527+ // !isset($wp->query_vars['order-pay'])->If you're not in the "re-pay" checkout.
528+ if (
529+ ( get_option ( WooCommerce_PostFinanceCheckout::POSTFINANCECHECKOUT_CK_INTEGRATION ) == WC_PostFinanceCheckout_Integration::POSTFINANCECHECKOUT_LIGHTBOX )
530+ && ( is_checkout ()
531+ && ! isset ( $ wp ->query_vars ['order-pay ' ] ) )
532+ ) {
533+ $ ajax_url = $ transaction_service ->get_lightbox_url_for_transaction ( $ transaction );
534+ }
535+
536+ if (get_option ( WooCommerce_PostFinanceCheckout::POSTFINANCECHECKOUT_CK_INTEGRATION ) == WC_PostFinanceCheckout_Integration::POSTFINANCECHECKOUT_PAYMENTPAGE ) {
537+ return false ;
538+ }
539+
540+ wp_enqueue_script (
541+ 'postfinancecheckout-remote-checkout-js ' ,
542+ $ ajax_url ,
543+ array (
544+ 'jquery ' ,
545+ ),
546+ 1 ,
547+ true
548+ );
549+ wp_enqueue_script (
550+ 'postfinancecheckout-checkout-js ' ,
551+ WooCommerce_PostFinanceCheckout::instance ()->plugin_url () . '/assets/js/frontend/checkout.js ' ,
552+ array (
553+ 'jquery ' ,
554+ 'jquery-blockui ' ,
555+ 'postfinancecheckout-remote-checkout-js ' ,
556+ ),
557+ 1 ,
558+ true
559+ );
560+ global $ wp_version ;
561+ $ localize = array (
562+ 'i18n_not_complete ' => esc_html__ ( 'Please fill out all required fields. ' , 'woo-postfinancecheckout ' ),
563+ 'integration ' => get_option ( WooCommerce_PostFinanceCheckout::POSTFINANCECHECKOUT_CK_INTEGRATION ),
564+ 'versions ' => array (
565+ 'wordpress ' => $ wp_version ,
566+ 'woocommerce ' => $ woocommerce_data ['Version ' ],
567+ 'postfinancecheckout ' => WC_POSTFINANCECHECKOUT_VERSION ,
568+ ),
569+ );
570+ wp_localize_script ( 'postfinancecheckout-checkout-js ' , 'postfinancecheckout_js_params ' , $ localize );
571+
572+ }
573+ }
574+
553575 /**
554576 * Validate frontend fields.
555577 *
0 commit comments