mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Refactor GooglePay context handlers to use response currency and country.
This commit is contained in:
parent
2f6545aa57
commit
78d58f1a03
4 changed files with 22 additions and 8 deletions
|
@ -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,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ 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();
|
||||
|
|
|
@ -31,10 +31,10 @@ class BaseHandler {
|
|||
const data = result.data;
|
||||
|
||||
resolve({
|
||||
countryCode: 'US', // data.country_code,
|
||||
currencyCode: 'USD', // data.currency_code,
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.amount // Your amount
|
||||
totalPrice: data.total_str
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -41,7 +41,7 @@ class SingleProductHandler extends BaseHandler {
|
|||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str // Your amount
|
||||
totalPrice: data.total_str
|
||||
});
|
||||
|
||||
}, products);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue