@@ -57,7 +57,7 @@ public function is_active() {
5757 */
5858 public function get_payment_method_script_handles () {
5959 $ dependencies = array ();
60- $ version = '1 ' ;
60+ $ version = '3.3.10 ' ;
6161
6262 wp_register_script (
6363 'WooCommerce_PostFinanceCheckout_blocks_support ' ,
@@ -108,6 +108,7 @@ public static function get_payment_methods(): array {
108108 }
109109
110110 $ payment_gateways = WC ()->payment_gateways ()->payment_gateways ();
111+
111112 $ available_payment_methods = WC_PostFinanceCheckout_Service_Transaction::instance ()->get_possible_payment_methods_for_cart ();
112113
113114 $ payment_plugin = array_filter (
@@ -118,7 +119,15 @@ public static function get_payment_methods(): array {
118119
119120 $ payments_list =
120121 array_map (
121- function ( WC_PostFinanceCheckout_Gateway $ payment_gateway ) use ( $ available_payment_methods ) {
122+ function ( $ payment_gateway ) use ( $ available_payment_methods ) {
123+ $ has_subscription = WC_PostFinanceCheckout_Zero_Gateway::cart_has_subscription ();
124+ $ cartTotal = (WC ()->cart && WC ()->cart ->total ) ?? 0 ;
125+ $ isPaymentMethodVisibleOnCheckout = $ payment_gateway ->get_payment_configuration_id () === WC_PostFinanceCheckout_Zero_Gateway::ZERO_PAYMENT_CONF_ID && $ cartTotal == 0 ;
126+
127+ if ( !$ isPaymentMethodVisibleOnCheckout ) {
128+ $ isPaymentMethodVisibleOnCheckout = in_array ( $ payment_gateway ->get_payment_configuration_id (), $ available_payment_methods , true ) && ( $ cartTotal > 0 || $ has_subscription );
129+ }
130+
122131 return array (
123132 'name ' => $ payment_gateway ->id ,
124133 'label ' => $ payment_gateway ->get_title (),
@@ -128,7 +137,7 @@ function ( WC_PostFinanceCheckout_Gateway $payment_gateway ) use ( $available_pa
128137 'integration_mode ' => get_option ( WooCommerce_PostFinanceCheckout::POSTFINANCECHECKOUT_CK_INTEGRATION ),
129138 'supports ' => $ payment_gateway ->supports ,
130139 'icon ' => $ payment_gateway ->get_icon (),
131- 'isActive ' => in_array ( $ payment_gateway -> get_payment_configuration_id (), $ available_payment_methods , true )
140+ 'isActive ' => $ isPaymentMethodVisibleOnCheckout
132141 );
133142 },
134143 $ payment_plugin
@@ -195,18 +204,17 @@ public static function enqueue_portal_scripts() {
195204 $ transaction_service = WC_PostFinanceCheckout_Service_Transaction::instance ();
196205 $ transaction = $ transaction_service ->get_transaction_from_session ();
197206
198- switch ( get_option ( WooCommerce_PostFinanceCheckout::POSTFINANCECHECKOUT_CK_INTEGRATION ) ) {
199- case WC_PostFinanceCheckout_Integration::POSTFINANCECHECKOUT_IFRAME :
200- // Ask the portal for the iframe's javascript file.
201- $ js_url = $ transaction_service ->get_javascript_url_for_transaction ( $ transaction );
202- break ;
203- case WC_PostFinanceCheckout_Integration::POSTFINANCECHECKOUT_LIGHTBOX :
204- $ js_url = $ transaction_service ->get_lightbox_url_for_transaction ( $ transaction );
205- // Ask the portal for the lighbox's javascript file.
206- break ;
207- default :
208- $ js_url = '' ;
209- break ;
207+ $ js_url = '' ;
208+ $ zeroPaymentMethod = new WC_PostFinanceCheckout_Zero_Gateway ();
209+ if ( !$ zeroPaymentMethod ->is_available () || $ zeroPaymentMethod ->cart_has_subscription () ) {
210+ switch ( get_option ( WooCommerce_PostFinanceCheckout::POSTFINANCECHECKOUT_CK_INTEGRATION ) ) {
211+ case WC_PostFinanceCheckout_Integration::POSTFINANCECHECKOUT_IFRAME :
212+ $ js_url = $ transaction_service ->get_javascript_url_for_transaction ( $ transaction );
213+ break ;
214+ case WC_PostFinanceCheckout_Integration::POSTFINANCECHECKOUT_LIGHTBOX :
215+ $ js_url = $ transaction_service ->get_lightbox_url_for_transaction ( $ transaction );
216+ break ;
217+ }
210218 }
211219
212220 if ( $ js_url ) {
@@ -250,6 +258,7 @@ public static function process_payment( PaymentContext $context, PaymentResult &
250258 if ( ! $ payment_method_object instanceof \WC_PostFinanceCheckout_Gateway ) {
251259 return ;
252260 }
261+
253262 $ payment_method_object ->validate_fields ();
254263
255264 // We call here the payment processor from our gateway.
0 commit comments