mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Fix GooglePay button on Pay Now page.
This commit is contained in:
parent
bdf472c3dc
commit
886f214dc6
4 changed files with 70 additions and 2 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;
|
||||
|
@ -971,6 +972,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;
|
||||
}
|
||||
|
@ -991,6 +996,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(
|
||||
|
|
|
@ -4,6 +4,7 @@ import CheckoutHandler from "./CheckoutHandler";
|
|||
import CartBlockHandler from "./CartBlockHandler";
|
||||
import CheckoutBlockHandler from "./CheckoutBlockHandler";
|
||||
import MiniCartHandler from "./MiniCartHandler";
|
||||
import PayNowHandler from "./PayNowHandler";
|
||||
import PreviewHandler from "./PreviewHandler";
|
||||
|
||||
class ContextHandlerFactory {
|
||||
|
@ -15,8 +16,9 @@ class ContextHandlerFactory {
|
|||
case 'cart':
|
||||
return new CartHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'checkout':
|
||||
case 'pay-now': // same as checkout
|
||||
return new CheckoutHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'pay-now':
|
||||
return new PayNowHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'mini-cart':
|
||||
return new MiniCartHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'cart-block':
|
||||
|
|
35
modules/ppcp-googlepay/resources/js/Context/PayNowHandler.js
Normal file
35
modules/ppcp-googlepay/resources/js/Context/PayNowHandler.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
import Spinner from "../../../../ppcp-button/resources/js/modules/Helper/Spinner";
|
||||
import BaseHandler from "./BaseHandler";
|
||||
import CheckoutActionHandler
|
||||
from "../../../../ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler";
|
||||
|
||||
class PayNowHandler extends BaseHandler {
|
||||
|
||||
shippingAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
transactionInfo() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const data = this.ppcpConfig['pay_now'];
|
||||
|
||||
resolve({
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
return new CheckoutActionHandler(
|
||||
this.ppcpConfig,
|
||||
this.errorHandler(),
|
||||
new Spinner()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default PayNowHandler;
|
Loading…
Add table
Add a link
Reference in a new issue