@@ -2071,19 +2071,6 @@ public static function getWaOrder($order, $options = array())
20712071
20722072 }
20732073
2074- $ tax_included = null ;
2075- foreach ($ order ['items ' ] as $ item_id => $ item ) {
2076- if (isset ($ item ['tax_included ' ])) {
2077- if ($ tax_included !== null ) {
2078- if ($ tax_included != !!$ item ['tax_included ' ]) {
2079- $ tax_included = 0 ;
2080- }
2081- } else {
2082- $ tax_included = !!$ item ['tax_included ' ];
2083- }
2084- }
2085- }
2086-
20872074 $ item_options = array (
20882075 'order_currency ' => ifset ($ order ['currency ' ], $ default_currency ),
20892076 'shipping_address ' => $ shipping_address ,
@@ -2163,10 +2150,6 @@ public static function getWaOrder($order, $options = array())
21632150 $ order_data ['dimensions_unit ' ] = $ options ['dimensions ' ];
21642151 }
21652152
2166- if (in_array ($ tax_included , array (true , false ), true )) {
2167- $ order_data ['tax_included ' ] = $ tax_included ;
2168- }
2169-
21702153 if (isset ($ order ['params ' ]['shipping_tax_percent ' ])) {
21712154 $ order_data ['shipping_tax_rate ' ] = $ order ['params ' ]['shipping_tax_percent ' ];
21722155 }
@@ -2187,17 +2170,20 @@ public static function getWaOrder($order, $options = array())
21872170 $ order_data ['discount ' ] = 0 ;
21882171 }
21892172
2173+ // order.total always includes all taxes
2174+ $ order_data ['tax_included ' ] = true ;
21902175 $ order_data ['total ' ] = $ order_data ['shipping ' ];
2176+ if (empty ($ order_data ['shipping_tax_included ' ]) && !empty ($ order_data ['shipping_tax_rate ' ])) {
2177+ $ order_data ['total ' ] *= 1 + $ order_data ['shipping_tax_rate ' ]/100 ;
2178+ }
21912179 foreach ($ order_data ['items ' ] as $ item ) {
2192- $ item_subtotal = $ item ['price ' ] * $ item ['quantity ' ];
2180+ $ item_subtotal = $ item ['price ' ] * $ item ['quantity ' ] - ifset ( $ item , ' total_discount ' , 0 ) ;
21932181 if (isset ($ item ['tax_included ' ]) && empty ($ item ['tax_included ' ]) && !empty ($ item ['tax_rate ' ])) {
21942182 $ item_subtotal *= 1 + $ item ['tax_rate ' ]/100 ;
21952183 }
21962184 $ order_data ['total ' ] += $ item_subtotal ;
21972185 }
21982186
2199- $ order_data ['total ' ] -= $ order_data ['discount ' ];
2200-
22012187 $ total = self ::workupValue ($ order ['total ' ], 'price ' , $ options ['currency ' ], $ order ['currency ' ]);
22022188
22032189 if ($ total !== $ order_data ['total ' ]) {
0 commit comments