Skip to content

Commit

Permalink
leverage isBnplAvailable for cart block
Browse files Browse the repository at this point in the history
  • Loading branch information
timur27 committed Feb 21, 2025
1 parent 68a42c2 commit 900cc45
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions client/cart/blocks/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,13 @@ const ProductDetail = ( { cart, context } ) => {
country,
paymentMethods,
currencyCode,
isBnplAvailable,
} = window.wcpayStripeSiteMessaging;

if ( ! isBnplAvailable ) {
return null;
}

const amount = parseInt( cartTotal, 10 ) || 0;

const options = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public function init() {

if ( $product ) {
$script_data['isBnplAvailable'] = WC_Payments_Utils::is_any_bnpl_method_available( array_values( $bnpl_payment_methods ), $country, $currency_code, $product_price );
} else {
$script_data['isBnplAvailable'] = WC_Payments_Utils::is_any_bnpl_method_available( array_values( $bnpl_payment_methods ), $country, $currency_code );
}

// Create script tag with config.
Expand Down
7 changes: 6 additions & 1 deletion includes/class-wc-payments-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -856,13 +856,18 @@ public static function get_bnpl_limits_per_currency( $payment_method ) {
* @param float $price Product price.
* @return bool True if any BNPL method is available, false otherwise.
*/
public static function is_any_bnpl_method_available( array $enabled_methods, string $country_code, string $currency_code, float $price ): bool {
public static function is_any_bnpl_method_available( array $enabled_methods, string $country_code, string $currency_code, ?float $price = null ): bool {
$price_in_cents = $price;

foreach ( $enabled_methods as $method ) {
$limits = self::get_bnpl_limits_per_currency( $method );

if ( isset( $limits[ $currency_code ][ $country_code ] ) ) {
// If no price provided, just check country/currency availability.
if ( null === $price_in_cents ) {
return true;
}

$min_amount = $limits[ $currency_code ][ $country_code ]['min'];
$max_amount = $limits[ $currency_code ][ $country_code ]['max'];

Expand Down

0 comments on commit 900cc45

Please sign in to comment.