mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge pull request #1719 from woocommerce/PCP-2006-google-pay-settings-improvements
Google Pay Settings improvements (2006)
This commit is contained in:
commit
c07e8eaa87
55 changed files with 1784 additions and 243 deletions
|
@ -14,6 +14,7 @@ use Psr\Log\LoggerInterface;
|
|||
use WC_Order;
|
||||
use WC_Product;
|
||||
use WC_Product_Variation;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
|
@ -1038,6 +1039,10 @@ class SmartButton implements SmartButtonInterface {
|
|||
'funding_sources_without_redirect' => $this->funding_sources_without_redirect,
|
||||
);
|
||||
|
||||
if ( 'pay-now' === $this->context() ) {
|
||||
$localize['pay_now'] = $this->pay_now_script_data();
|
||||
}
|
||||
|
||||
if ( $this->style_for_context( 'layout', 'mini-cart' ) !== 'horizontal' ) {
|
||||
$localize['button']['mini_cart_style']['tagline'] = false;
|
||||
}
|
||||
|
@ -1058,6 +1063,32 @@ class SmartButton implements SmartButtonInterface {
|
|||
return $localize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pay-now payment data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function pay_now_script_data(): array {
|
||||
$order_id = $this->get_order_pay_id();
|
||||
$base_location = wc_get_base_location();
|
||||
$shop_country_code = $base_location['country'] ?? '';
|
||||
$currency_code = get_woocommerce_currency();
|
||||
|
||||
$wc_order = wc_get_order( $order_id );
|
||||
if ( ! $wc_order instanceof WC_Order ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$total = (float) $wc_order->get_total( 'numeric' );
|
||||
|
||||
return array(
|
||||
'total' => $total,
|
||||
'total_str' => ( new Money( $total, $currency_code ) )->value_str(),
|
||||
'currency_code' => $currency_code,
|
||||
'country_code' => $shop_country_code,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If we can find the payer data for a current customer, we will return it.
|
||||
*
|
||||
|
|
|
@ -76,7 +76,7 @@ class CartScriptParamsEndpoint implements EndpointInterface {
|
|||
|
||||
// Shop settings.
|
||||
$base_location = wc_get_base_location();
|
||||
$shop_country_code = $base_location['country'];
|
||||
$shop_country_code = $base_location['country'] ?? '';
|
||||
$currency_code = get_woocommerce_currency();
|
||||
|
||||
wp_send_json_success(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue