mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:41:40 +08:00
Merge pull request #1689 from woocommerce/wip/apple-google-combined
Combined Apple Pay and Google Pay integration (154, 1744)
This commit is contained in:
commit
4bedeab529
83 changed files with 11165 additions and 52 deletions
47
modules/ppcp-button/src/Assets/ButtonInterface.php
Normal file
47
modules/ppcp-button/src/Assets/ButtonInterface.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* The interface for the button asset renderer.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Button\Assets
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Button\Assets;
|
||||
|
||||
/**
|
||||
* Interface ButtonInterface
|
||||
*/
|
||||
interface ButtonInterface {
|
||||
|
||||
/**
|
||||
* Initializes the button.
|
||||
*/
|
||||
public function initialize(): void;
|
||||
|
||||
/**
|
||||
* Indicates if the button is enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_enabled(): bool;
|
||||
|
||||
/**
|
||||
* Renders the necessary HTML.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function render(): bool;
|
||||
|
||||
/**
|
||||
* Enqueues scripts/styles.
|
||||
*/
|
||||
public function enqueue(): void;
|
||||
|
||||
/**
|
||||
* The configuration for the smart buttons.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function script_data(): array;
|
||||
}
|
|
@ -462,7 +462,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
$this->button_renderer( PayPalGateway::ID, 'woocommerce_paypal_payments_single_product_button_render' );
|
||||
},
|
||||
31
|
||||
);
|
||||
|
@ -479,10 +479,10 @@ class SmartButton implements SmartButtonInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
echo '<p
|
||||
id="ppc-button-minicart"
|
||||
class="woocommerce-mini-cart__buttons buttons"
|
||||
></p>';
|
||||
echo '<p class="woocommerce-mini-cart__buttons buttons">';
|
||||
echo '<span id="ppc-button-minicart"></span>';
|
||||
do_action( 'woocommerce_paypal_payments_minicart_button_render' );
|
||||
echo '</div>';
|
||||
},
|
||||
30
|
||||
);
|
||||
|
@ -494,7 +494,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
add_action(
|
||||
$this->pay_order_renderer_hook(),
|
||||
function (): void {
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
$this->button_renderer( PayPalGateway::ID, 'woocommerce_paypal_payments_payorder_button_render' );
|
||||
$this->button_renderer( CardButtonGateway::ID );
|
||||
},
|
||||
20
|
||||
|
@ -502,7 +502,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
add_action(
|
||||
$this->checkout_button_renderer_hook(),
|
||||
function (): void {
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
$this->button_renderer( PayPalGateway::ID, 'woocommerce_paypal_payments_checkout_button_render' );
|
||||
$this->button_renderer( CardButtonGateway::ID );
|
||||
}
|
||||
);
|
||||
|
@ -515,7 +515,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
$this->button_renderer( PayPalGateway::ID, 'woocommerce_paypal_payments_cart_button_render' );
|
||||
},
|
||||
20
|
||||
);
|
||||
|
@ -616,9 +616,10 @@ class SmartButton implements SmartButtonInterface {
|
|||
/**
|
||||
* 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();
|
||||
|
||||
|
@ -628,7 +629,14 @@ class SmartButton implements SmartButtonInterface {
|
|||
|
||||
// The wrapper is needed for the loading spinner,
|
||||
// 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>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1160,7 +1168,15 @@ class SmartButton implements SmartButtonInterface {
|
|||
if ( $this->dcc_is_enabled() ) {
|
||||
$components[] = 'hosted-fields';
|
||||
}
|
||||
return $components;
|
||||
/**
|
||||
* Filter to add further components from the extensions.
|
||||
*
|
||||
* @internal Matches filter name in APM extension.
|
||||
* @since TODO
|
||||
*
|
||||
* @param array $components The array of components already registered.
|
||||
*/
|
||||
return apply_filters( 'woocommerce_paypal_payments_sdk_components_hook', $components );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Button\Endpoint;
|
|||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Throwable;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButton;
|
||||
|
||||
/**
|
||||
|
@ -71,12 +72,24 @@ class CartScriptParamsEndpoint implements EndpointInterface {
|
|||
|
||||
$script_data = $this->smart_button->script_data();
|
||||
|
||||
$total = (float) WC()->cart->get_total( 'numeric' );
|
||||
|
||||
// Shop settings.
|
||||
$base_location = wc_get_base_location();
|
||||
$shop_country_code = $base_location['country'];
|
||||
$currency_code = get_woocommerce_currency();
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'url_params' => $script_data['url_params'],
|
||||
'button' => $script_data['button'],
|
||||
'messages' => $script_data['messages'],
|
||||
'amount' => WC()->cart->get_total( 'raw' ),
|
||||
'url_params' => $script_data['url_params'],
|
||||
'button' => $script_data['button'],
|
||||
'messages' => $script_data['messages'],
|
||||
'amount' => WC()->cart->get_total( 'raw' ),
|
||||
|
||||
'total' => $total,
|
||||
'total_str' => ( new Money( $total, $currency_code ) )->value_str(),
|
||||
'currency_code' => $currency_code,
|
||||
'country_code' => $shop_country_code,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Button\Endpoint;
|
|||
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButton;
|
||||
|
||||
/**
|
||||
|
@ -97,18 +98,26 @@ class SimulateCartEndpoint extends AbstractCartEndpoint {
|
|||
$button_enabled = $button_enabled && ! $this->smart_button->is_button_disabled( 'product', $context_data );
|
||||
}
|
||||
|
||||
// Shop settings.
|
||||
$base_location = wc_get_base_location();
|
||||
$shop_country_code = $base_location['country'];
|
||||
$currency_code = get_woocommerce_currency();
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'total' => $total,
|
||||
'funding' => array(
|
||||
'total' => $total,
|
||||
'total_str' => ( new Money( $total, $currency_code ) )->value_str(),
|
||||
'currency_code' => $currency_code,
|
||||
'country_code' => $shop_country_code,
|
||||
'funding' => array(
|
||||
'paylater' => array(
|
||||
'enabled' => $pay_later_enabled,
|
||||
),
|
||||
),
|
||||
'button' => array(
|
||||
'button' => array(
|
||||
'is_disabled' => ! $button_enabled,
|
||||
),
|
||||
'messages' => array(
|
||||
'messages' => array(
|
||||
'is_hidden' => ! $pay_later_messaging_enabled,
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue