Add button method for checkout context

This commit is contained in:
Emili Castells Guasch 2024-07-15 18:42:44 +02:00
parent 473b286de0
commit 82f46baa16
2 changed files with 41 additions and 0 deletions

View file

@ -62,6 +62,30 @@ class GooglepayButton {
)
.then( ( response ) => {
if ( response.result ) {
if ( this.context === 'checkout' ) {
const wrapper = document.getElementById(
'ppc-button-ppcp-googlepay'
);
if ( wrapper ) {
const { ppcpStyle, buttonStyle } =
this.contextConfig();
wrapper.className = `ppcp-button-${ ppcpStyle.shape }`;
if ( ppcpStyle.height ) {
wrapper.style.height = `${ ppcpStyle.height }px`;
}
this.addButtonCheckout(
this.baseCardPaymentMethod,
wrapper,
buttonStyle
);
return;
}
}
this.addButton( this.baseCardPaymentMethod );
}
} )
@ -221,6 +245,19 @@ class GooglepayButton {
} );
}
addButtonCheckout( baseCardPaymentMethod, wrapper, buttonStyle ) {
const button = this.paymentsClient.createButton( {
onClick: this.onButtonClick.bind( this ),
allowedPaymentMethods: [ baseCardPaymentMethod ],
buttonColor: buttonStyle.color || 'black',
buttonType: buttonStyle.type || 'pay',
buttonLocale: buttonStyle.language || 'en',
buttonSizeMode: 'fill',
} );
wrapper.appendChild( button );
}
waitForWrapper( selector, callback, delay = 100, timeout = 2000 ) {
const startTime = Date.now();
const interval = setInterval( () => {

View file

@ -186,6 +186,10 @@ class GooglepayModule implements ModuleInterface {
return $methods;
}
);
add_action('woocommerce_review_order_after_payment', function () {
echo '<div id="ppc-button-' . esc_attr( GooglePayGateway::ID ) . '"></div>';
});
}
/**