Fix GooglePay small issues

This commit is contained in:
Pedro Silva 2023-08-29 08:19:11 +01:00
parent 4a1d369ad2
commit 37ef761e0f
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
6 changed files with 60 additions and 12 deletions

View file

@ -4,7 +4,7 @@ import CartActionHandler
import onApprove
from "../../../../ppcp-button/resources/js/modules/OnApproveHandler/onApproveForContinue";
class CartHandler {
class CartBlockHandler {
constructor(buttonConfig, ppcpConfig) {
console.log('NEW CartHandler');
@ -72,4 +72,4 @@ class CartHandler {
}
export default CartHandler;
export default CartBlockHandler;

View file

@ -4,7 +4,7 @@ import CartActionHandler
import onApprove
from "../../../../ppcp-button/resources/js/modules/OnApproveHandler/onApproveForContinue";
class CartHandler {
class CheckoutBlockHandler {
constructor(buttonConfig, ppcpConfig) {
console.log('NEW CartHandler');
@ -72,4 +72,4 @@ class CartHandler {
}
export default CartHandler;
export default CheckoutBlockHandler;

View file

@ -3,6 +3,7 @@ import CartHandler from "./CartHandler";
import CheckoutHandler from "./CheckoutHandler";
import CartBlockHandler from "./CartBlockHandler";
import CheckoutBlockHandler from "./CheckoutBlockHandler";
import MiniCartHandler from "./MiniCartHandler";
class ContextHandlerFactory {
@ -13,13 +14,10 @@ class ContextHandlerFactory {
case 'cart':
return new CartHandler(buttonConfig, ppcpConfig);
case 'checkout':
return new CheckoutHandler(buttonConfig, ppcpConfig);
case 'pay-now':
// todo
return null;
return new CheckoutHandler(buttonConfig, ppcpConfig);
case 'mini-cart':
// todo
return null;
return new MiniCartHandler(buttonConfig, ppcpConfig);
case 'cart-block':
return new CartBlockHandler(buttonConfig, ppcpConfig);
case 'checkout-block':

View file

@ -0,0 +1,7 @@
import CartHandler from "./CartHandler";
class MiniCartHandler extends CartHandler {
}
export default MiniCartHandler;

View file

@ -124,6 +124,15 @@ class GooglepayManager {
buttonSizeMode: 'fill',
});
jQuery(this.buttonConfig.button.wrapper).append(button);
// const buttonMiniCart =
// paymentsClient.createButton({
// onClick: this.onButtonClick.bind(this),
// allowedPaymentMethods: [this.baseCardPaymentMethod],
// buttonType: 'pay',
// buttonSizeMode: 'fill',
// });
// jQuery(this.buttonConfig.button.mini_cart_wrapper).append(buttonMiniCart);
}
//------------------------

View file

@ -131,6 +131,10 @@ class Button implements ButtonInterface {
$button_enabled_product = $is_googlepay_button_enabled && $this->settings_status->is_smart_button_enabled_for_location( 'product' );
$button_enabled_cart = $is_googlepay_button_enabled && $this->settings_status->is_smart_button_enabled_for_location( 'cart' );
$button_enabled_checkout = $is_googlepay_button_enabled;
$button_enabled_payorder = $is_googlepay_button_enabled;
$button_enabled_minicart = $is_googlepay_button_enabled && $this->settings_status->is_smart_button_enabled_for_location( 'mini-cart' );
/**
* Param types removed to avoid third-party issues.
@ -188,16 +192,45 @@ class Button implements ButtonInterface {
);
}
if ( $button_enabled_payorder ) {
$default_hook_name = 'woocommerce_paypal_payments_payorder_button_render';
$render_placeholder = apply_filters( 'woocommerce_paypal_payments_googlepay_payorder_button_render_hook', $default_hook_name );
$render_placeholder = is_string( $render_placeholder ) ? $render_placeholder : $default_hook_name;
add_action(
$render_placeholder,
function () {
$this->googlepay_button();
},
21
);
}
if ( $button_enabled_minicart ) {
$default_hook_name = 'woocommerce_paypal_payments_minicart_button_render';
$render_placeholder = apply_filters( 'woocommerce_paypal_payments_googlepay_minicart_button_render_hook', $default_hook_name );
$render_placeholder = is_string( $render_placeholder ) ? $render_placeholder : $default_hook_name;
add_action(
$render_placeholder,
function () {
$this->googlepay_button( 'ppc-button-googlepay-container-minicart' );
},
21
);
}
return true;
}
/**
* GooglePay button markup
*
* @param string $id The HTML id.
* @return void
*/
private function googlepay_button(): void {
private function googlepay_button( string $id = 'ppc-button-googlepay-container' ): void {
?>
<div class="ppc-button-wrapper">
<div id="ppc-button-googlepay-container">
<div id="<?php echo esc_attr( $id ); ?>">
<?php wp_nonce_field( 'woocommerce-process_checkout', 'woocommerce-process-checkout-nonce' ); ?>
</div>
</div>
@ -248,7 +281,8 @@ class Button implements ButtonInterface {
return array(
'sdk_url' => $this->sdk_url,
'button' => array(
'wrapper' => '#ppc-button-googlepay-container',
'wrapper' => '#ppc-button-googlepay-container',
'mini_cart_wrapper' => '#ppc-button-googlepay-container-minicart',
),
);
}