mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Add fees as line items
This commit is contained in:
parent
5a84bd1430
commit
0452171869
1 changed files with 28 additions and 1 deletions
|
@ -66,12 +66,21 @@ class ItemFactory {
|
|||
* @return Item[]
|
||||
*/
|
||||
public function from_wc_order( \WC_Order $order ): array {
|
||||
return array_map(
|
||||
$items = array_map(
|
||||
function ( \WC_Order_Item_Product $item ) use ( $order ): Item {
|
||||
return $this->from_wc_order_line_item( $item, $order );
|
||||
},
|
||||
$order->get_items( 'line_item' )
|
||||
);
|
||||
|
||||
$fees = array_map(
|
||||
function ( \WC_Order_Item_Fee $item ) use ( $order ): Item {
|
||||
return $this->from_wc_order_fee( $item, $order );
|
||||
},
|
||||
$order->get_fees()
|
||||
);
|
||||
|
||||
return array_merge( $items, $fees );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,6 +118,24 @@ class ItemFactory {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Item based off a WooCommerce Fee Item.
|
||||
*
|
||||
* @param \WC_Order_Item_Fee $item The WooCommerce order item.
|
||||
* @param \WC_Order $order The WooCommerce order.
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
private function from_wc_order_fee( \WC_Order_Item_Fee $item, \WC_Order $order ): Item {
|
||||
return new Item(
|
||||
$item->get_name(),
|
||||
new Money( (float) $item->get_amount(), $order->get_currency() ),
|
||||
$item->get_quantity(),
|
||||
'',
|
||||
new Money( (float) $item->get_total_tax(), $order->get_currency() )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Item based off a PayPal response.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue