Skip to content

Commit

Permalink
Fix PMME appearance in checkout (#9621)
Browse files Browse the repository at this point in the history
Co-authored-by: Timur Karimov <[email protected]>
  • Loading branch information
gpressutto5 and timur27 authored Oct 25, 2024
1 parent e280f2a commit 98f3467
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-pmme-appearance-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix PMME appearance in checkout
3 changes: 0 additions & 3 deletions client/checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ const api = new WCPayAPI(
request
);

const stripeAppearance = getUPEConfig( 'wcBlocksUPEAppearance' );

Object.entries( enabledPaymentMethodsConfig )
.filter( ( [ upeName ] ) => upeName !== 'link' )
.forEach( ( [ upeName, upeConfig ] ) => {
Expand Down Expand Up @@ -114,7 +112,6 @@ Object.entries( enabledPaymentMethodsConfig )
api={ api }
upeConfig={ upeConfig }
upeName={ upeName }
stripeAppearance={ stripeAppearance }
upeAppearanceTheme={ upeAppearanceTheme }
/>
),
Expand Down
2 changes: 1 addition & 1 deletion client/checkout/blocks/payment-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const PaymentElements = ( { api, ...props } ) => {
useEffect( () => {
async function generateUPEAppearance() {
// Generate UPE input styles.
let upeAppearance = getAppearance( 'blocks_checkout', false, true );
let upeAppearance = getAppearance( 'blocks_checkout', false );
upeAppearance = await api.saveUPEAppearance(
upeAppearance,
'blocks_checkout'
Expand Down
34 changes: 25 additions & 9 deletions client/checkout/blocks/payment-method-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import { normalizeCurrencyToMinorUnit } from '../utils';
import { getUPEConfig } from 'wcpay/utils/checkout';
import { __ } from '@wordpress/i18n';
import './style.scss';
import { useEffect, useState } from '@wordpress/element';
import { getAppearance } from 'wcpay/checkout/upe-styles';

export default ( {
api,
upeConfig,
upeName,
stripeAppearance,
upeAppearanceTheme,
} ) => {
export default ( { api, upeConfig, upeName, upeAppearanceTheme } ) => {
const cartData = wp.data.select( 'wc/store/cart' ).getCartData();
const bnplMethods = [ 'affirm', 'afterpay_clearpay', 'klarna' ];
const isTestMode = getUPEConfig( 'testMode' );
const [ appearance, setAppearance ] = useState(
getUPEConfig( 'wcBlocksUPEAppearance' )
);

// Stripe expects the amount to be sent as the minor unit of 2 digits.
const amount = parseInt(
Expand All @@ -38,6 +37,22 @@ export default ( {

const isCreditCard = upeName === 'card';

useEffect( () => {
async function generateUPEAppearance() {
// Generate UPE input styles.
let upeAppearance = getAppearance( 'blocks_checkout', false );
upeAppearance = await api.saveUPEAppearance(
upeAppearance,
'blocks_checkout'
);
setAppearance( upeAppearance );
}

if ( ! appearance ) {
generateUPEAppearance();
}
}, [ api, appearance ] );

return (
<>
<div className="payment-method-label">
Expand All @@ -63,12 +78,13 @@ export default ( {
( upeConfig.countries.length === 0 ||
upeConfig.countries.includes( currentCountry ) ) &&
amount > 0 &&
currentCountry && (
currentCountry &&
appearance && (
<div className="bnpl-message">
<Elements
stripe={ api.getStripeForUPE( upeName ) }
options={ {
appearance: stripeAppearance ?? {},
appearance: appearance,
} }
>
<PaymentMethodMessagingElement
Expand Down
3 changes: 2 additions & 1 deletion client/checkout/classic/event-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ jQuery( function ( $ ) {
decimalPlaces:
cartData?.totals?.currency_minor_unit,
country: currentCountry,
}
},
'shortcode_checkout'
);
}
}
Expand Down
5 changes: 3 additions & 2 deletions client/checkout/classic/payment-processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,11 @@ export async function mountStripePaymentElement(
export async function mountStripePaymentMethodMessagingElement(
api,
domElement,
cartData
cartData,
location
) {
const paymentMethodType = domElement.dataset.paymentMethodType;
const appearance = await initializeAppearance( api );
const appearance = await initializeAppearance( api, location );

try {
const paymentMethodMessagingElement = api
Expand Down

0 comments on commit 98f3467

Please sign in to comment.