Merge pull request #542 from woocommerce/PCP-590-incorrect-tax-details-on-paypal-

Add shipping tax to taxes instead of shipping
This commit is contained in:
Emili Castells 2022-03-23 11:07:14 +01:00 committed by GitHub
commit 260693147a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 18 deletions

View file

@ -76,12 +76,12 @@ class AmountFactory {
$item_total = $cart->get_cart_contents_total() + $cart->get_discount_total() + $total_fees_amount;
$item_total = new Money( (float) $item_total, $this->currency );
$shipping = new Money(
(float) $cart->get_shipping_total() + $cart->get_shipping_tax(),
(float) $cart->get_shipping_total(),
$this->currency
);
$taxes = new Money(
$cart->get_subtotal_tax(),
$cart->get_subtotal_tax() + $cart->get_shipping_tax(),
$this->currency
);
@ -131,7 +131,7 @@ class AmountFactory {
$currency
);
$shipping = new Money(
(float) $order->get_shipping_total() + (float) $order->get_shipping_tax(),
(float) $order->get_shipping_total(),
$currency
);
$taxes = new Money(

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use WC_Product;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
@ -41,8 +42,9 @@ class ItemFactory {
* @return Item[]
*/
public function from_wc_cart( \WC_Cart $cart ): array {
$items = array_map(
function ( array $item ): Item {
$shipping_tax = round( $cart->get_shipping_tax(), 2 );
$items = array_map(
function ( array $item ) use ( $shipping_tax ): Item {
$product = $item['data'];
/**
@ -56,7 +58,7 @@ class ItemFactory {
$price_without_tax = (float) wc_get_price_excluding_tax( $product );
$price_without_tax_rounded = round( $price_without_tax, 2 );
$tax = round( $price - $price_without_tax_rounded, 2 );
$tax = new Money( $tax, $this->currency );
$tax = new Money( $tax + $shipping_tax, $this->currency );
return new Item(
mb_substr( $product->get_name(), 0, 127 ),
new Money( $price_without_tax_rounded, $this->currency ),
@ -123,21 +125,21 @@ class ItemFactory {
* @return Item
*/
private function from_wc_order_line_item( \WC_Order_Item_Product $item, \WC_Order $order ): Item {
$currency = $order->get_currency();
$product = $item->get_product();
/**
* The WooCommerce product.
*
* @var \WC_Product $product
* @var WC_Product $product
*/
$quantity = (int) $item->get_quantity();
$product = $item->get_product();
$currency = $order->get_currency();
$shipping_tax = round( (float) $order->get_shipping_tax(), 2 );
$quantity = (int) $item->get_quantity();
$price = (float) $order->get_item_subtotal( $item, true );
$price_without_tax = (float) $order->get_item_subtotal( $item, false );
$price_without_tax_rounded = round( $price_without_tax, 2 );
$tax = round( $price - $price_without_tax_rounded, 2 );
$tax = new Money( $tax, $currency );
$tax = new Money( $tax + $shipping_tax, $currency );
return new Item(
mb_substr( $product->get_name(), 0, 127 ),
new Money( $price_without_tax_rounded, $currency ),