From 82f46baa162c3658ed961e347ebd933e2db4f8f1 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 15 Jul 2024 18:42:44 +0200 Subject: [PATCH] Add button method for checkout context --- .../resources/js/GooglepayButton.js | 37 +++++++++++++++++++ .../ppcp-googlepay/src/GooglepayModule.php | 4 ++ 2 files changed, 41 insertions(+) diff --git a/modules/ppcp-googlepay/resources/js/GooglepayButton.js b/modules/ppcp-googlepay/resources/js/GooglepayButton.js index 973648af3..44daed173 100644 --- a/modules/ppcp-googlepay/resources/js/GooglepayButton.js +++ b/modules/ppcp-googlepay/resources/js/GooglepayButton.js @@ -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( () => { diff --git a/modules/ppcp-googlepay/src/GooglepayModule.php b/modules/ppcp-googlepay/src/GooglepayModule.php index 8167e87f9..03ad140bb 100644 --- a/modules/ppcp-googlepay/src/GooglepayModule.php +++ b/modules/ppcp-googlepay/src/GooglepayModule.php @@ -186,6 +186,10 @@ class GooglepayModule implements ModuleInterface { return $methods; } ); + + add_action('woocommerce_review_order_after_payment', function () { + echo '
'; + }); } /**