mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Fix GooglePay general fixes / improvements
This commit is contained in:
parent
d6a564f24f
commit
318217acb9
9 changed files with 85 additions and 41 deletions
|
@ -29,7 +29,8 @@ return function ( string $root_dir ): iterable {
|
||||||
( require "$modules_dir/ppcp-blocks/module.php" )(),
|
( require "$modules_dir/ppcp-blocks/module.php" )(),
|
||||||
);
|
);
|
||||||
if ( apply_filters(
|
if ( apply_filters(
|
||||||
'inpsyde_feature_flags_woocommerce_paypal_payments_googlepay_enabled',
|
//phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||||
|
'woocommerce.feature-flags.woocommerce_paypal_payments.googlepay_enabled',
|
||||||
getenv( 'PCP_GOOGLEPAY_ENABLED' ) === '1'
|
getenv( 'PCP_GOOGLEPAY_ENABLED' ) === '1'
|
||||||
) ) {
|
) ) {
|
||||||
$modules[] = ( require "$modules_dir/ppcp-googlepay/module.php" )();
|
$modules[] = ( require "$modules_dir/ppcp-googlepay/module.php" )();
|
||||||
|
|
|
@ -7,8 +7,7 @@ import {keysToCamelCase} from "./Utils";
|
||||||
// This component may be used by multiple modules. This assures that options are shared between all instances.
|
// This component may be used by multiple modules. This assures that options are shared between all instances.
|
||||||
let options = window.ppcpWidgetBuilder = window.ppcpWidgetBuilder || {
|
let options = window.ppcpWidgetBuilder = window.ppcpWidgetBuilder || {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
onLoadedCallbacks: [],
|
onLoadedCallbacks: []
|
||||||
loadingWaitTime: 5000 // 5 seconds
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadPaypalScript = (config, onLoaded) => {
|
export const loadPaypalScript = (config, onLoaded) => {
|
||||||
|
@ -27,13 +26,6 @@ export const loadPaypalScript = (config, onLoaded) => {
|
||||||
}
|
}
|
||||||
options.isLoading = true;
|
options.isLoading = true;
|
||||||
|
|
||||||
// Arm a timeout so the module isn't locked on isLoading state on failure.
|
|
||||||
let loadingTimeout = setTimeout(() => {
|
|
||||||
console.error('Failed to load PayPal script.');
|
|
||||||
options.isLoading = false;
|
|
||||||
options.onLoadedCallbacks = [];
|
|
||||||
}, options.loadingWaitTime);
|
|
||||||
|
|
||||||
// Callback to be called once the PayPal script is loaded.
|
// Callback to be called once the PayPal script is loaded.
|
||||||
const callback = (paypal) => {
|
const callback = (paypal) => {
|
||||||
widgetBuilder.setPaypal(paypal);
|
widgetBuilder.setPaypal(paypal);
|
||||||
|
@ -44,7 +36,6 @@ export const loadPaypalScript = (config, onLoaded) => {
|
||||||
|
|
||||||
options.isLoading = false;
|
options.isLoading = false;
|
||||||
options.onLoadedCallbacks = [];
|
options.onLoadedCallbacks = [];
|
||||||
clearTimeout(loadingTimeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the PayPal script options.
|
// Build the PayPal script options.
|
||||||
|
|
|
@ -462,8 +462,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->button_renderer( PayPalGateway::ID );
|
$this->button_renderer( PayPalGateway::ID, 'woocommerce_paypal_payments_single_product_button_render' );
|
||||||
do_action( 'woocommerce_paypal_payments_single_product_button_render' );
|
|
||||||
},
|
},
|
||||||
31
|
31
|
||||||
);
|
);
|
||||||
|
@ -495,18 +494,16 @@ class SmartButton implements SmartButtonInterface {
|
||||||
add_action(
|
add_action(
|
||||||
$this->pay_order_renderer_hook(),
|
$this->pay_order_renderer_hook(),
|
||||||
function (): void {
|
function (): void {
|
||||||
$this->button_renderer( PayPalGateway::ID );
|
$this->button_renderer( PayPalGateway::ID, 'woocommerce_paypal_payments_payorder_button_render' );
|
||||||
$this->button_renderer( CardButtonGateway::ID );
|
$this->button_renderer( CardButtonGateway::ID );
|
||||||
do_action( 'woocommerce_paypal_payments_payorder_button_render' );
|
|
||||||
},
|
},
|
||||||
20
|
20
|
||||||
);
|
);
|
||||||
add_action(
|
add_action(
|
||||||
$this->checkout_button_renderer_hook(),
|
$this->checkout_button_renderer_hook(),
|
||||||
function (): void {
|
function (): void {
|
||||||
$this->button_renderer( PayPalGateway::ID );
|
$this->button_renderer( PayPalGateway::ID, 'woocommerce_paypal_payments_checkout_button_render' );
|
||||||
$this->button_renderer( CardButtonGateway::ID );
|
$this->button_renderer( CardButtonGateway::ID );
|
||||||
do_action( 'woocommerce_paypal_payments_checkout_button_render' );
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -518,8 +515,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->button_renderer( PayPalGateway::ID );
|
$this->button_renderer( PayPalGateway::ID, 'woocommerce_paypal_payments_cart_button_render' );
|
||||||
do_action( 'woocommerce_paypal_payments_cart_button_render' );
|
|
||||||
},
|
},
|
||||||
20
|
20
|
||||||
);
|
);
|
||||||
|
@ -622,9 +618,10 @@ class SmartButton implements SmartButtonInterface {
|
||||||
/**
|
/**
|
||||||
* Renders the HTML for the buttons.
|
* Renders the HTML for the buttons.
|
||||||
*
|
*
|
||||||
* @param string $gateway_id The gateway ID, like 'ppcp-gateway'.
|
* @param string $gateway_id The gateway ID, like 'ppcp-gateway'.
|
||||||
|
* @param string|null $action_name The action name to be called.
|
||||||
*/
|
*/
|
||||||
public function button_renderer( string $gateway_id ) {
|
public function button_renderer( string $gateway_id, string $action_name = null ) {
|
||||||
|
|
||||||
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
|
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
|
||||||
|
|
||||||
|
@ -634,7 +631,14 @@ class SmartButton implements SmartButtonInterface {
|
||||||
|
|
||||||
// The wrapper is needed for the loading spinner,
|
// The wrapper is needed for the loading spinner,
|
||||||
// otherwise jQuery block() prevents buttons rendering.
|
// otherwise jQuery block() prevents buttons rendering.
|
||||||
echo '<div class="ppc-button-wrapper"><div id="ppc-button-' . esc_attr( $gateway_id ) . '"></div></div>';
|
echo '<div class="ppc-button-wrapper">';
|
||||||
|
echo '<div id="ppc-button-' . esc_attr( $gateway_id ) . '"></div>';
|
||||||
|
|
||||||
|
if ( null !== $action_name ) {
|
||||||
|
do_action( $action_name );
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,7 +29,7 @@ return array(
|
||||||
$fields,
|
$fields,
|
||||||
'allow_card_button_gateway',
|
'allow_card_button_gateway',
|
||||||
array(
|
array(
|
||||||
'googlepay_button_enabled' => array(
|
'googlepay_button_enabled' => array(
|
||||||
'title' => __( 'Google Pay Button', 'woocommerce-paypal-payments' ),
|
'title' => __( 'Google Pay Button', 'woocommerce-paypal-payments' ),
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'label' => __( 'Enable Google Pay button', 'woocommerce-paypal-payments' ),
|
'label' => __( 'Enable Google Pay button', 'woocommerce-paypal-payments' ),
|
||||||
|
@ -44,14 +44,18 @@ return array(
|
||||||
'handler' => 'SubElementsHandler',
|
'handler' => 'SubElementsHandler',
|
||||||
'options' => array(
|
'options' => array(
|
||||||
'values' => array( '1' ),
|
'values' => array( '1' ),
|
||||||
'elements' => array( '#field-googlepay_button_color', '#field-googlepay_button_type' ),
|
'elements' => array(
|
||||||
|
'#field-googlepay_button_color',
|
||||||
|
'#field-googlepay_button_type',
|
||||||
|
'#field-googlepay_button_shipping_enabled',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'googlepay_button_color' => array(
|
'googlepay_button_color' => array(
|
||||||
'title' => str_repeat( ' ', 6 ) . __( 'Button Color', 'woocommerce-paypal-payments' ),
|
'title' => str_repeat( ' ', 6 ) . __( 'Button Color', 'woocommerce-paypal-payments' ),
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'label' => '',
|
'label' => '',
|
||||||
|
@ -63,7 +67,7 @@ return array(
|
||||||
'gateway' => 'paypal',
|
'gateway' => 'paypal',
|
||||||
'requirements' => array(),
|
'requirements' => array(),
|
||||||
),
|
),
|
||||||
'googlepay_button_type' => array(
|
'googlepay_button_type' => array(
|
||||||
'title' => str_repeat( ' ', 6 ) . __( 'Button Type', 'woocommerce-paypal-payments' ),
|
'title' => str_repeat( ' ', 6 ) . __( 'Button Type', 'woocommerce-paypal-payments' ),
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'class' => array(),
|
'class' => array(),
|
||||||
|
@ -74,6 +78,15 @@ return array(
|
||||||
'gateway' => 'paypal',
|
'gateway' => 'paypal',
|
||||||
'requirements' => array(),
|
'requirements' => array(),
|
||||||
),
|
),
|
||||||
|
'googlepay_button_shipping_enabled' => array(
|
||||||
|
'title' => str_repeat( ' ', 6 ) . __( 'Shipping Callback', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __( 'Enable Google Pay shipping callback', 'woocommerce-paypal-payments' ),
|
||||||
|
'default' => 'no',
|
||||||
|
'screens' => array( State::STATE_ONBOARDED ),
|
||||||
|
'gateway' => 'paypal',
|
||||||
|
'requirements' => array(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
.ppcp-button-googlepay {
|
.ppcp-button-googlepay {
|
||||||
margin: 5px 0;
|
margin: 7px 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
min-height: 40px;
|
||||||
height: 45px;
|
height: 45px;
|
||||||
|
|
||||||
&.ppcp-button-pill {
|
&.ppcp-button-pill {
|
||||||
|
@ -15,14 +16,31 @@
|
||||||
|
|
||||||
.woocommerce-checkout {
|
.woocommerce-checkout {
|
||||||
.ppcp-button-googlepay {
|
.ppcp-button-googlepay {
|
||||||
margin: 0;
|
margin-top: 0;
|
||||||
border-radius: 18px;
|
|
||||||
height: 38px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.wp-block-woocommerce-cart, .wp-block-woocommerce-checkout {
|
.ppcp-has-googlepay-block {
|
||||||
.ppcp-button-googlepay {
|
|
||||||
margin: 0;
|
.wp-block-woocommerce-checkout {
|
||||||
|
.ppcp-button-googlepay {
|
||||||
|
margin: 0;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.wp-block-woocommerce-cart {
|
||||||
|
.ppcp-button-googlepay {
|
||||||
|
margin: 0;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
/* Workaround for blocks grid */
|
||||||
|
.wc-block-components-express-payment__event-buttons {
|
||||||
|
display: block;
|
||||||
|
li[id*="express-payment-method-ppcp-"] {
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,8 @@ class GooglepayButton {
|
||||||
const paymentDataRequest = await this.paymentDataRequest();
|
const paymentDataRequest = await this.paymentDataRequest();
|
||||||
console.log('[GooglePayButton] onButtonClick: paymentDataRequest', paymentDataRequest, this.context);
|
console.log('[GooglePayButton] onButtonClick: paymentDataRequest', paymentDataRequest, this.context);
|
||||||
|
|
||||||
|
window.ppcpFundingSource = 'googlepay'; // TODO : do this on another place like on create order
|
||||||
|
|
||||||
this.paymentsClient.loadPaymentData(paymentDataRequest);
|
this.paymentsClient.loadPaymentData(paymentDataRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,13 @@ const GooglePayComponent = () => {
|
||||||
manager.init();
|
manager.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const bodyClass = 'ppcp-has-googlepay-block';
|
||||||
|
if (!document.body.classList.contains(bodyClass)) {
|
||||||
|
document.body.classList.add(bodyClass);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Load GooglePay SDK
|
// Load GooglePay SDK
|
||||||
loadCustomScript({ url: buttonConfig.sdk_url }).then(() => {
|
loadCustomScript({ url: buttonConfig.sdk_url }).then(() => {
|
||||||
|
@ -44,7 +51,7 @@ const GooglePayComponent = () => {
|
||||||
}, [paypalLoaded, googlePayLoaded]);
|
}, [paypalLoaded, googlePayLoaded]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id={buttonConfig.button.wrapper.replace('#', '')}></div>
|
<div id={buttonConfig.button.wrapper.replace('#', '')} className="ppcp-button-googlepay"></div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ class Button implements ButtonInterface {
|
||||||
*
|
*
|
||||||
* @psalm-suppress MissingClosureParamType
|
* @psalm-suppress MissingClosureParamType
|
||||||
*/
|
*/
|
||||||
private function add_onboarding_options( $options ): string {
|
public function add_onboarding_options( $options ): string {
|
||||||
$checked = '';
|
$checked = '';
|
||||||
try {
|
try {
|
||||||
$onboard_with_apple = $this->settings->get( 'ppcp-onboarding-apple' );
|
$onboard_with_apple = $this->settings->get( 'ppcp-onboarding-apple' );
|
||||||
|
@ -162,7 +162,7 @@ class Button implements ButtonInterface {
|
||||||
* @param array $data The referrals data.
|
* @param array $data The referrals data.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function add_partner_referrals_data( array $data ): array {
|
public function add_partner_referrals_data( array $data ): array {
|
||||||
try {
|
try {
|
||||||
$onboard_with_google = $this->settings->get( 'ppcp-onboarding-google' );
|
$onboard_with_google = $this->settings->get( 'ppcp-onboarding-google' );
|
||||||
if ( ! wc_string_to_bool( $onboard_with_google ) ) {
|
if ( ! wc_string_to_bool( $onboard_with_google ) ) {
|
||||||
|
@ -326,10 +326,8 @@ class Button implements ButtonInterface {
|
||||||
*/
|
*/
|
||||||
private function googlepay_button(): void {
|
private function googlepay_button(): void {
|
||||||
?>
|
?>
|
||||||
<div class="ppc-button-wrapper">
|
<div id="ppc-button-googlepay-container" class="ppcp-button-googlepay">
|
||||||
<div id="ppc-button-googlepay-container" class="ppcp-button-googlepay">
|
<?php wp_nonce_field( 'woocommerce-process_checkout', 'woocommerce-process-checkout-nonce' ); ?>
|
||||||
<?php wp_nonce_field( 'woocommerce-process_checkout', 'woocommerce-process-checkout-nonce' ); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
|
@ -939,6 +939,13 @@ return array(
|
||||||
'paylater' => _x( 'Pay Later', 'Name of payment method', 'woocommerce-paypal-payments' ),
|
'paylater' => _x( 'Pay Later', 'Name of payment method', 'woocommerce-paypal-payments' ),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'wcgateway.extra-funding-sources' => static function( ContainerInterface $container ): array {
|
||||||
|
return array(
|
||||||
|
'googlepay' => _x( 'Google Pay', 'Name of payment method', 'woocommerce-paypal-payments' ),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sources that do not cause issues about redirecting (on mobile, ...) and sometimes not returning back.
|
* The sources that do not cause issues about redirecting (on mobile, ...) and sometimes not returning back.
|
||||||
*/
|
*/
|
||||||
|
@ -1034,7 +1041,10 @@ return array(
|
||||||
'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer {
|
'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer {
|
||||||
return new FundingSourceRenderer(
|
return new FundingSourceRenderer(
|
||||||
$container->get( 'wcgateway.settings' ),
|
$container->get( 'wcgateway.settings' ),
|
||||||
$container->get( 'wcgateway.all-funding-sources' )
|
array_merge(
|
||||||
|
$container->get( 'wcgateway.all-funding-sources' ),
|
||||||
|
$container->get( 'wcgateway.extra-funding-sources' )
|
||||||
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue