Skip to content

Commit

Permalink
Merge branch 'develop' into fix/9537-woopay-button-size-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelzaleski authored Oct 31, 2024
2 parents 84d1fc0 + ccff836 commit 81bd795
Show file tree
Hide file tree
Showing 17 changed files with 377 additions and 221 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-7761-align-deposit-colors
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Introducing consistency in colors for deposits across pages
4 changes: 4 additions & 0 deletions changelog/fix-9456-bnpl-respect-limits-per-currency
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Prevent dead space on product pages when no BNPL offers are available.
4 changes: 4 additions & 0 deletions changelog/fix-express-checkout-block-registering
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Register Expresss Checkout block only when enabled in the settings
20 changes: 11 additions & 9 deletions client/checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,17 @@ if ( getUPEConfig( 'isWooPayEnabled' ) ) {
}
}

if ( getUPEConfig( 'isTokenizedCartPrbEnabled' ) ) {
registerExpressPaymentMethod(
tokenizedCartPaymentRequestPaymentMethod( api )
);
} else if ( getUPEConfig( 'isExpressCheckoutElementEnabled' ) ) {
registerExpressPaymentMethod( expressCheckoutElementApplePay( api ) );
registerExpressPaymentMethod( expressCheckoutElementGooglePay( api ) );
} else {
registerExpressPaymentMethod( paymentRequestPaymentMethod( api ) );
if ( getUPEConfig( 'isPaymentRequestEnabled' ) ) {
if ( getUPEConfig( 'isTokenizedCartPrbEnabled' ) ) {
registerExpressPaymentMethod(
tokenizedCartPaymentRequestPaymentMethod( api )
);
} else if ( getUPEConfig( 'isExpressCheckoutElementEnabled' ) ) {
registerExpressPaymentMethod( expressCheckoutElementApplePay( api ) );
registerExpressPaymentMethod( expressCheckoutElementGooglePay( api ) );
} else {
registerExpressPaymentMethod( paymentRequestPaymentMethod( api ) );
}
}
window.addEventListener( 'load', () => {
enqueueFraudScripts( getUPEConfig( 'fraudServices' ) );
Expand Down
4 changes: 2 additions & 2 deletions client/components/deposit-status-chip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import type { DepositStatus } from 'wcpay/types/deposits';
*/
const mappings: Record< DepositStatus, ChipType > = {
pending: 'warning',
in_transit: 'success',
in_transit: 'primary',
paid: 'success',
failed: 'alert',
canceled: 'alert',
canceled: 'light',
};

/**
Expand Down
24 changes: 15 additions & 9 deletions client/deposits/details/style.scss
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
.wcpay-deposit-overview {
.woocommerce-order-status {
margin-bottom: 4px;
white-space: nowrap;
}

.woocommerce-order-status__indicator {
width: 0.85em;
height: 0.85em;

// is-canceled uses the default gray color.

&.is-paid {
background: $studio-green-50;
border-color: $studio-green-5;
background: $wp-green-30;
border-color: $wp-green-5;
}
&.is-pending {
background: $wp-yellow-20;
border-color: $wp-yellow-5;
}
&.is-pending,
&.is-in_transit {
background: $studio-yellow-30;
border-color: $studio-yellow-5;
background: $wp-blue-30;
border-color: $wp-blue-5;
}
&.is-failed {
background: $studio-red-50;
border-color: $studio-red-5;
background: $wp-red-50;
border-color: $wp-red-10;
}
}

Expand All @@ -34,11 +40,11 @@
}

.wcpay-deposit-fee {
color: $studio-red-50;
color: $wp-red-70;
}

.wcpay-deposit-net {
color: $studio-green-30;
color: $wp-green-70;
}

.wcpay-deposit-automatic ul {
Expand Down
5 changes: 2 additions & 3 deletions client/product-details/bnpl-site-messaging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ export const initializeBnplSiteMessaging = async () => {
isCart,
isCartBlock,
cartTotal,
minimumOrderAmount,
isBnplAvailable,
} = window.wcpayStripeSiteMessaging;

let amount;
let elementLocation = 'bnplProductPage';
const minOrderAmount = parseInt( minimumOrderAmount, 10 ) || 0;
const paymentMessageContainer = document.getElementById(
'payment-method-message'
);
Expand All @@ -71,7 +70,7 @@ export const initializeBnplSiteMessaging = async () => {
} else {
amount = parseInt( productVariations.base_product.amount, 10 ) || 0;

if ( amount < minOrderAmount ) {
if ( ! isBnplAvailable ) {
paymentMessageContainer.style.setProperty( 'display', 'none' );
}
}
Expand Down
36 changes: 34 additions & 2 deletions client/product-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,29 @@ jQuery( async function ( $ ) {
'get_cart_total'
),
{
security: window.wcpayStripeSiteMessaging.nonce,
security: window.wcpayStripeSiteMessaging.nonce.get_cart_total,
}
);
};

const isBnplAvailable = ( price, currency, country ) => {
return request(
buildAjaxURL(
window.wcpayStripeSiteMessaging.wcAjaxUrl,
'check_bnpl_availability'
),
{
security:
window.wcpayStripeSiteMessaging.nonce.is_bnpl_available,
price: price,
currency: currency,
country: country,
}
);
};

// Update BNPL message based on the quantity change
quantityInput.on( 'change', ( event ) => {
quantityInput.on( 'change', async ( event ) => {
let amount = baseProductAmount;
const variationId = $( VARIATION_ID_SELECTOR ).val();

Expand All @@ -123,6 +139,22 @@ jQuery( async function ( $ ) {
}

updateBnplPaymentMessage( amount, productCurrency, event.target.value );

// Check if changes in quantity/price affect BNPL availability and show/hide BNPL messaging accordingly.
try {
const response = await isBnplAvailable(
amount * event.target.value,
productCurrency,
window.wcpayStripeSiteMessaging.country
);
if ( response.success && response.data.is_available ) {
$( '#payment-method-message' ).slideDown();
} else {
$( '#payment-method-message' ).slideUp();
}
} catch {
// Do nothing.
}
} );

$( document.body ).on( 'updated_cart_totals', () => {
Expand Down
9 changes: 9 additions & 0 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,15 @@ public function is_saved_cards_enabled() {
return 'yes' === $this->get_option( 'saved_cards' );
}

/**
* Checks if the setting to show the payment request buttons is enabled.
*
* @return bool Whether the setting to show the payment request buttons is enabled or not.
*/
public function is_payment_request_enabled() {
return 'yes' === $this->get_option( 'payment_request' );
}

/**
* Check if account is eligible for card present.
*
Expand Down
1 change: 1 addition & 0 deletions includes/class-wc-payments-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function get_payment_fields_js_config() {
'isPreview' => is_preview(),
'isSavedCardsEnabled' => $this->gateway->is_saved_cards_enabled(),
'isExpressCheckoutElementEnabled' => WC_Payments_Features::is_stripe_ece_enabled(),
'isPaymentRequestEnabled' => $this->gateway->is_payment_request_enabled(),
'isTokenizedCartPrbEnabled' => WC_Payments_Features::is_tokenized_cart_prb_enabled(),
'isWooPayEnabled' => $this->woopay_util->should_enable_woopay( $this->gateway ) && $this->woopay_util->should_enable_woopay_on_cart_or_checkout(),
'isWoopayExpressCheckoutEnabled' => $this->woopay_util->is_woopay_express_checkout_enabled(),
Expand Down
49 changes: 32 additions & 17 deletions includes/class-wc-payments-payment-method-messaging-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public function init() {
'currency' => $currency_code,
],
];

$product_price = $product_variations['base_product']['amount'];

foreach ( $product->get_children() as $variation_id ) {
$variation = wc_get_product( $variation_id );
if ( $variation ) {
Expand All @@ -98,11 +101,13 @@ public function init() {
'amount' => WC_Payments_Utils::prepare_amount( $price, $currency_code ),
'currency' => $currency_code,
];

$product_price = $product_variations['base_product']['amount'];
}
}
}

$enabled_upe_payment_methods = $this->gateway->get_payment_method_ids_enabled_at_checkout();
$enabled_upe_payment_methods = $this->gateway->get_upe_enabled_payment_method_ids();
// Filter non BNPL out of the list of payment methods.
$bnpl_payment_methods = array_intersect( $enabled_upe_payment_methods, Payment_Method::BNPL_PAYMENT_METHODS );

Expand All @@ -118,26 +123,36 @@ public function init() {
WC_Payments::get_file_version( 'dist/product-details.css' ),
);

$country = empty( $billing_country ) ? $store_country : $billing_country;

$script_data = [
'productId' => 'base_product',
'productVariations' => $product_variations,
'country' => $country,
'locale' => WC_Payments_Utils::convert_to_stripe_locale( get_locale() ),
'accountId' => $this->account->get_stripe_account_id(),
'publishableKey' => $this->account->get_publishable_key( WC_Payments::mode()->is_test() ),
'paymentMethods' => array_values( $bnpl_payment_methods ),
'currencyCode' => $currency_code,
'isCart' => is_cart(),
'isCartBlock' => $is_cart_block,
'cartTotal' => WC_Payments_Utils::prepare_amount( $cart_total, $currency_code ),
'nonce' => [
'get_cart_total' => wp_create_nonce( 'wcpay-get-cart-total' ),
'is_bnpl_available' => wp_create_nonce( 'wcpay-is-bnpl-available' ),
],
'wcAjaxUrl' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
];

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

// Create script tag with config.
wp_localize_script(
'WCPAY_PRODUCT_DETAILS',
'wcpayStripeSiteMessaging',
[
'productId' => 'base_product',
'productVariations' => $product_variations,
'country' => empty( $billing_country ) ? $store_country : $billing_country,
'locale' => WC_Payments_Utils::convert_to_stripe_locale( get_locale() ),
'accountId' => $this->account->get_stripe_account_id(),
'publishableKey' => $this->account->get_publishable_key( WC_Payments::mode()->is_test() ),
'paymentMethods' => array_values( $bnpl_payment_methods ),
'currencyCode' => $currency_code,
'isCart' => is_cart(),
'isCartBlock' => $is_cart_block,
'cartTotal' => WC_Payments_Utils::prepare_amount( $cart_total, $currency_code ),
'minimumOrderAmount' => WC_Payments_Utils::get_cached_minimum_amount( $currency_code, true ),
'nonce' => wp_create_nonce( 'wcpay-get-cart-total' ),
'wcAjaxUrl' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
]
$script_data
);

// Ensure wcpayConfig is available in the page.
Expand Down
Loading

0 comments on commit 81bd795

Please sign in to comment.