Skip to content

Commit b4c7df6

Browse files
committed
Remove bizum and google/apple when subs
1 parent c23050e commit b4c7df6

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

assets/js/monei-block-checkout-bizum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
content: <MoneiBizumContent />,
187187
edit: <div> { __( bizumData.title, 'monei' ) }</div>,
188188
canMakePayment: ( { billingData } ) => {
189-
return billingData.country === 'ES';
189+
return billingData.country === 'ES' && !bizumData.cart_has_subscription;
190190
},
191191
supports: bizumData.supports,
192192
};

src/Features/Subscriptions/WooCommerceSubscriptionsHandler.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,17 @@ public function get_subscription_payment_method_friendly_name( $subscription ) {
312312
/* translators: 1) card brand 2) last 4 digits */
313313
return sprintf( __( '%1$s card ending in %2$s', 'monei' ), $brand, $last_digits );
314314
}
315+
316+
/**
317+
* Check if a product is a subscription using WooCommerce Subscription logic
318+
*
319+
* @param int|WC_Product $product Product ID or WC_Product object
320+
* @return bool
321+
*/
322+
function cart_has_subscription() {
323+
if (!$this->is_subscriptions_addon_enabled()) {
324+
return false;
325+
}
326+
return is_array( WC()->cart->recurring_carts ) ? count( WC()->cart->recurring_carts ) : 0;
327+
}
315328
}

src/Features/Subscriptions/YithSubscriptionPluginHandler.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,23 @@ public function get_subscription_payment_method_friendly_name( $subscription ) {
298298
/* translators: 1) card brand 2) last 4 digits */
299299
return sprintf( __( '%1$s card ending in %2$s', 'monei' ), $brand, $last_digits );
300300
}
301+
302+
/**
303+
* Check if a product is a subscription using YITH WooCommerce Subscription logic
304+
*
305+
* @param int|WC_Product $product Product ID or WC_Product object
306+
* @return bool
307+
*/
308+
function cart_has_subscription() {
309+
// Ensure YITH WooCommerce Subscription plugin is active
310+
if (!function_exists('YITH_WC_Subscription')) {
311+
return false;
312+
}
313+
314+
// Get the YITH_WC_Subscription instance
315+
$ywsbs = YITH_WC_Subscription();
316+
317+
// Use the is_subscription method to check if the product is a subscription
318+
return $ywsbs->cart_has_subscriptions();
319+
}
301320
}

src/Gateways/Blocks/MoneiBizumBlocksSupport.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Monei\Gateways\Blocks;
44

55
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
6+
use Monei\Features\Subscriptions\SubscriptionService;
67
use Monei\Gateways\Abstracts\WCMoneiPaymentGateway;
78
use Monei\Gateways\PaymentMethods\WCGatewayMoneiBizum;
89

@@ -11,9 +12,12 @@ final class MoneiBizumBlocksSupport extends AbstractPaymentMethodType {
1112

1213
private $gateway;
1314
protected $name = 'monei_bizum';
15+
protected SubscriptionService $subscriptions_service;
1416

15-
public function __construct( WCMoneiPaymentGateway $gateway ) {
17+
public function __construct( WCMoneiPaymentGateway $gateway, SubscriptionService $subscriptionService) {
1618
$this->gateway = $gateway;
19+
$this->subscriptions_service = $subscriptionService;
20+
$this->handler = $this->subscriptions_service->getHandler();
1721
}
1822

1923
public function initialize() {
@@ -61,6 +65,7 @@ public function is_active() {
6165

6266
public function get_payment_method_data() {
6367
$total = isset( WC()->cart ) ? WC()->cart->get_total( false ) : 0;
68+
$cart_has_subscription = $this->handler? $this->handler->cart_has_subscription(): false;
6469
$data = array(
6570

6671
'title' => $this->gateway->title,
@@ -76,6 +81,7 @@ public function get_payment_method_data() {
7681
'test_mode' => $this->gateway->getTestmode() ?? false,
7782
'accountId' => $this->gateway->getAccountId() ?? false,
7883
'sessionId' => ( wc()->session ) ? wc()->session->get_customer_id() : '',
84+
'cart_has_subscription' => $cart_has_subscription,
7985
);
8086

8187
if ( 'yes' === $this->get_setting( 'hide_logo' ) ?? 'no' ) {

src/Gateways/PaymentMethods/WCGatewayMoneiAppleGoogle.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public function __construct(
5555
$this->icon = ( $this->hide_logo ) ? '' : $iconMarkup;
5656
$this->settings = get_option( 'woocommerce_monei_settings', array() );
5757
$this->enabled = ( ! empty( isset( $this->settings['apple_google_pay'] ) && 'yes' === $this->settings['apple_google_pay'] ) ) ? 'yes' : 'no';
58-
58+
$this->supports = array(
59+
'products',
60+
'refunds',
61+
);
5962
add_filter(
6063
'woocommerce_available_payment_gateways',
6164
array( $this, 'hideAppleGoogleInCheckout' ),

0 commit comments

Comments
 (0)