mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge branch 'trunk' into PCP-3395-when-there-isnt-any-shipping-option-for-the-address-the-order-is-still-created-from-classic-cart
This commit is contained in:
commit
5d5dd761f8
26 changed files with 666 additions and 111 deletions
|
@ -181,9 +181,14 @@ class CheckoutBootstap {
|
|||
const isSeparateButtonGateway = [ PaymentMethods.CARD_BUTTON ].includes(
|
||||
currentPaymentMethod
|
||||
);
|
||||
const isGooglePayMethod =
|
||||
currentPaymentMethod === PaymentMethods.GOOGLEPAY;
|
||||
const isSavedCard = isCard && isSavedCardSelected();
|
||||
const isNotOurGateway =
|
||||
! isPaypal && ! isCard && ! isSeparateButtonGateway;
|
||||
! isPaypal &&
|
||||
! isCard &&
|
||||
! isSeparateButtonGateway &&
|
||||
! isGooglePayMethod;
|
||||
const isFreeTrial = PayPalCommerceGateway.is_free_trial_cart;
|
||||
const hasVaultedPaypal =
|
||||
PayPalCommerceGateway.vaulted_paypal_email !== '';
|
||||
|
@ -227,6 +232,8 @@ class CheckoutBootstap {
|
|||
}
|
||||
}
|
||||
|
||||
setVisible( '#ppc-button-ppcp-googlepay', isGooglePayMethod );
|
||||
|
||||
jQuery( document.body ).trigger( 'ppcp_checkout_rendered' );
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import { getPlanIdFromVariation } from '../Helper/Subscriptions';
|
|||
import SimulateCart from '../Helper/SimulateCart';
|
||||
import { strRemoveWord, strAddWord, throttle } from '../Helper/Utils';
|
||||
import merge from 'deepmerge';
|
||||
import { debounce } from '../../../../../ppcp-blocks/resources/js/Helper/debounce';
|
||||
|
||||
class SingleProductBootstap {
|
||||
constructor( gateway, renderer, errorHandler ) {
|
||||
|
@ -20,9 +21,13 @@ class SingleProductBootstap {
|
|||
|
||||
// Prevent simulate cart being called too many times in a burst.
|
||||
this.simulateCartThrottled = throttle(
|
||||
this.simulateCart,
|
||||
this.simulateCart.bind( this ),
|
||||
this.gateway.simulate_cart.throttling || 5000
|
||||
);
|
||||
this.debouncedHandleChange = debounce(
|
||||
this.handleChange.bind( this ),
|
||||
100
|
||||
);
|
||||
|
||||
this.renderer.onButtonsInit(
|
||||
this.gateway.button.wrapper,
|
||||
|
@ -74,7 +79,7 @@ class SingleProductBootstap {
|
|||
}
|
||||
|
||||
jQuery( document ).on( 'change', this.formSelector, () => {
|
||||
this.handleChange();
|
||||
this.debouncedHandleChange();
|
||||
} );
|
||||
this.mutationObserver.observe( form, {
|
||||
childList: true,
|
||||
|
|
|
@ -3,6 +3,7 @@ export const PaymentMethods = {
|
|||
CARDS: 'ppcp-credit-card-gateway',
|
||||
OXXO: 'ppcp-oxxo-gateway',
|
||||
CARD_BUTTON: 'ppcp-card-button-gateway',
|
||||
GOOGLEPAY: 'ppcp-googlepay',
|
||||
};
|
||||
|
||||
export const ORDER_BUTTON_SELECTOR = '#place_order';
|
||||
|
|
|
@ -16,8 +16,10 @@ use WC_Data_Exception;
|
|||
use WC_Order;
|
||||
use WC_Order_Item_Product;
|
||||
use WC_Order_Item_Shipping;
|
||||
use WC_Product;
|
||||
use WC_Subscription;
|
||||
use WC_Subscriptions_Product;
|
||||
use WC_Tax;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Shipping;
|
||||
|
@ -113,6 +115,7 @@ class WooCommerceOrderCreator {
|
|||
* @param Payer|null $payer The payer.
|
||||
* @param Shipping|null $shipping The shipping.
|
||||
* @return void
|
||||
* @psalm-suppress InvalidScalarArgument
|
||||
*/
|
||||
protected function configure_line_items( WC_Order $wc_order, WC_Cart $wc_cart, ?Payer $payer, ?Shipping $shipping ): void {
|
||||
$cart_contents = $wc_cart->get_cart();
|
||||
|
@ -137,18 +140,21 @@ class WooCommerceOrderCreator {
|
|||
return;
|
||||
}
|
||||
|
||||
$total = $product->get_price() * $quantity;
|
||||
$subtotal = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) );
|
||||
$subtotal = apply_filters( 'woocommerce_paypal_payments_shipping_callback_cart_line_item_total', $subtotal, $cart_item );
|
||||
|
||||
$item->set_name( $product->get_name() );
|
||||
$item->set_subtotal( $total );
|
||||
$item->set_total( $total );
|
||||
$item->set_subtotal( $subtotal );
|
||||
$item->set_total( $subtotal );
|
||||
|
||||
$this->configure_taxes( $product, $item, $subtotal );
|
||||
|
||||
$product_id = $product->get_id();
|
||||
|
||||
if ( $this->is_subscription( $product_id ) ) {
|
||||
$subscription = $this->create_subscription( $wc_order, $product_id );
|
||||
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $product );
|
||||
$subscription_total = $total + $sign_up_fee;
|
||||
$subscription_total = (float) $subtotal + (float) $sign_up_fee;
|
||||
|
||||
$item->set_subtotal( $subscription_total );
|
||||
$item->set_total( $subscription_total );
|
||||
|
@ -295,6 +301,30 @@ class WooCommerceOrderCreator {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the taxes.
|
||||
*
|
||||
* @param WC_Product $product The Product.
|
||||
* @param WC_Order_Item_Product $item The line item.
|
||||
* @param float|string $subtotal The subtotal.
|
||||
* @return void
|
||||
* @psalm-suppress InvalidScalarArgument
|
||||
*/
|
||||
protected function configure_taxes( WC_Product $product, WC_Order_Item_Product $item, $subtotal ): void {
|
||||
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
|
||||
$taxes = WC_Tax::calc_tax( $subtotal, $tax_rates, true );
|
||||
|
||||
$item->set_tax_class( $product->get_tax_class() );
|
||||
$item->set_total_tax( (float) array_sum( $taxes ) );
|
||||
|
||||
foreach ( $taxes as $tax_rate_id => $tax_amount ) {
|
||||
if ( $tax_amount > 0 ) {
|
||||
$item->add_meta_data( 'tax_rate_id', $tax_rate_id, true );
|
||||
$item->add_meta_data( 'tax_amount', $tax_amount, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the product with given ID is WC subscription.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue