mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Merge branch 'trunk' into PCP-3342-shipping-callback-compatibility-problem-with-name-your-price-plugin
# Conflicts: # modules/ppcp-button/src/Helper/WooCommerceOrderCreator.php
This commit is contained in:
commit
d20b1b982f
174 changed files with 15007 additions and 11994 deletions
|
@ -829,7 +829,9 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
|
|||
*/
|
||||
do_action( "ppcp_before_{$location_hook}_message_wrapper" );
|
||||
|
||||
$messages_placeholder = '<div class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
|
||||
$bn_code = PPCP_PAYPAL_BN_CODE;
|
||||
|
||||
$messages_placeholder = '<div class="ppcp-messages" data-partner-attribution-id="' . esc_attr( $bn_code ) . '"></div>';
|
||||
|
||||
if ( is_array( $block_params ) && ( $block_params['blockName'] ?? false ) ) {
|
||||
$this->render_after_block(
|
||||
|
@ -1163,11 +1165,11 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
|
|||
),
|
||||
'update_customer_shipping' => array(
|
||||
'shipping_options' => array(
|
||||
'endpoint' => '/wp-json/wc/store/cart/select-shipping-rate',
|
||||
'endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT . 'select-shipping-rate' ),
|
||||
),
|
||||
'shipping_address' => array(
|
||||
'cart_endpoint' => '/wp-json/wc/store/cart/',
|
||||
'update_customer_endpoint' => '/wp-json/wc/store/v1/cart/update-customer/',
|
||||
'cart_endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT ),
|
||||
'update_customer_endpoint' => home_url( UpdateShippingEndpoint::WC_STORE_API_ENDPOINT . 'update-customer' ),
|
||||
),
|
||||
'wp_rest_nonce' => wp_create_nonce( 'wc_store_api' ),
|
||||
'update_shipping_method' => \WC_AJAX::get_endpoint( 'update_shipping_method' ),
|
||||
|
@ -1511,7 +1513,10 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
|
|||
private function bn_code_for_context( string $context ): string {
|
||||
|
||||
$codes = $this->bn_codes();
|
||||
return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : 'Woo_PPCP';
|
||||
|
||||
$bn_code = PPCP_PAYPAL_BN_CODE;
|
||||
|
||||
return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : $bn_code;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1519,13 +1524,15 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
private function bn_codes(): array {
|
||||
private function bn_codes() : array {
|
||||
|
||||
$bn_code = PPCP_PAYPAL_BN_CODE;
|
||||
|
||||
return array(
|
||||
'checkout' => 'Woo_PPCP',
|
||||
'cart' => 'Woo_PPCP',
|
||||
'mini-cart' => 'Woo_PPCP',
|
||||
'product' => 'Woo_PPCP',
|
||||
'checkout' => $bn_code,
|
||||
'cart' => $bn_code,
|
||||
'mini-cart' => $bn_code,
|
||||
'product' => $bn_code,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,10 @@ use WC_Cart;
|
|||
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;
|
||||
|
@ -106,6 +108,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();
|
||||
|
@ -130,19 +133,21 @@ class WooCommerceOrderCreator {
|
|||
return;
|
||||
}
|
||||
|
||||
$total = $product->get_price() * $quantity;
|
||||
$total = apply_filters( 'woocommerce_paypal_payments_shipping_callback_cart_line_item_total', $total, $cart_item );
|
||||
$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 );
|
||||
|
@ -283,6 +288,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