@@ -460,8 +460,8 @@ public function __saveOrderTaxes( Order $order, $taxes ): float
460460
461461 foreach ( $ taxes as $ index => $ tax ) {
462462 $ orderTax = new OrderTax ;
463- $ orderTax ->tax_name = $ tax [ 'tax_name ' ];
464- $ orderTax ->tax_value = $ response [ 'percentages ' ][ $ index ][ 'tax ' ];
463+ $ orderTax ->tax_name = $ tax [ 'name ' ];
464+ $ orderTax ->tax_value = ( $ response [ 'percentages ' ][ $ index ][ 'tax ' ] ?? 0 ) ;
465465 $ orderTax ->rate = $ tax [ 'rate ' ];
466466 $ orderTax ->tax_id = $ tax [ 'tax_id ' ];
467467 $ orderTax ->order_id = $ order ->id ;
@@ -918,9 +918,9 @@ private function __checkOrderPayments( $fields, ?Order $order, Customer $custome
918918
919919 $ totalPayments = 0 ;
920920
921- $ subtotal = Currency:: raw ( collect ( $ fields [ 'products ' ] )->map ( function ( $ product ) {
921+ $ subtotal = ns ()-> currency -> define ( collect ( $ fields [ 'products ' ] )->map ( function ( $ product ) {
922922 return floatval ( $ product ['total_price ' ] );
923- } )->sum () );
923+ } )->sum () )-> toFloat () ;
924924
925925 $ total = $ this ->currencyService ->define (
926926 $ subtotal + $ this ->__getShippingFee ( $ fields )
@@ -1034,13 +1034,13 @@ protected function __computeOrderTotal( $data )
10341034 * increase the total with the
10351035 * shipping fees and subtract the discounts
10361036 */
1037- $ order ->total = Currency::fresh ( $ order ->subtotal )
1037+ $ order ->total = Currency::define ( $ order ->subtotal )
10381038 ->additionateBy ( $ order ->shipping )
10391039 ->additionateBy (
10401040 ( $ order ->tax_type === 'exclusive ' ? $ order ->tax_value : 0 )
10411041 )
10421042 ->subtractBy (
1043- Currency::fresh ( $ order ->total_coupons )
1043+ Currency::define ( $ order ->total_coupons )
10441044 ->additionateBy ( $ order ->discount )
10451045 ->toFloat ()
10461046 )
@@ -1051,7 +1051,7 @@ protected function __computeOrderTotal( $data )
10511051 /**
10521052 * compute change
10531053 */
1054- $ order ->change = Currency::fresh ( $ order ->tendered )
1054+ $ order ->change = Currency::define ( $ order ->tendered )
10551055 ->subtractBy ( $ order ->total )
10561056 ->toFloat ();
10571057
@@ -1060,7 +1060,7 @@ protected function __computeOrderTotal( $data )
10601060 *
10611061 * @todo not accurate
10621062 */
1063- $ order ->total_without_tax = Currency::fresh ( $ order ->subtotal )
1063+ $ order ->total_without_tax = Currency::define ( $ order ->subtotal )
10641064 ->subtractBy ( $ order ->discount )
10651065 ->subtractBy ( $ order ->total_coupons )
10661066 ->subtractBy ( $ order ->tax_value )
@@ -1151,7 +1151,7 @@ private function __saveOrderProducts( $order, $products )
11511151
11521152 if ( $ product [ 'product ' ] instanceof Product ) {
11531153 $ orderProduct ->total_purchase_price = $ this ->currencyService ->define (
1154- $ product [ 'total_purchase_price ' ] ?? Currency::fresh ( $ this ->productService ->getCogs (
1154+ $ product [ 'total_purchase_price ' ] ?? Currency::define ( $ this ->productService ->getCogs (
11551155 product: $ product [ 'product ' ],
11561156 unit: $ unit
11571157 ) )
@@ -1454,8 +1454,8 @@ public function computeProduct( $fields, ?Product $product = null, ?ProductUnitQ
14541454 price: $ sale_price
14551455 )
14561456 )
1457- ->multiplyBy ( floatval ( $ fields [ 'quantity ' ] ) )
1458- ->toFloat ();
1457+ ->multiplyBy ( floatval ( $ fields [ 'quantity ' ] ) )
1458+ ->toFloat ();
14591459 }
14601460
14611461 /**
@@ -1882,7 +1882,7 @@ public function refundSingleProduct( Order $order, OrderRefund $orderRefund, Ord
18821882
18831883 $ productRefund ->tax_value = $ this ->computeTaxFromOrderTaxes (
18841884 $ order ,
1885- Currency::raw ( $ details [ 'unit_price ' ] * $ details [ 'quantity ' ] ),
1885+ Currency::define ( $ details [ 'unit_price ' ] )-> multipliedBy ( $ details [ 'quantity ' ] )-> toFloat ( ),
18861886 ns ()->option ->get ( 'ns_pos_tax_type ' )
18871887 );
18881888
@@ -2146,11 +2146,11 @@ public function refreshOrder( Order $order )
21462146 /**
21472147 * let's refresh all the order values
21482148 */
2149- $ order ->subtotal = Currency::raw ( $ productTotal );
2149+ $ order ->subtotal = Currency::define ( $ productTotal )-> toFloat ( );
21502150 $ order ->total_without_tax = $ productPriceWithoutTax ;
21512151 $ order ->total_with_tax = $ productPriceWithTax ;
21522152 $ order ->discount = $ this ->computeOrderDiscount ( $ order );
2153- $ order ->total = Currency::fresh ( $ order ->subtotal )
2153+ $ order ->total = Currency::define ( $ order ->subtotal )
21542154 ->additionateBy ( $ orderShipping )
21552155 ->additionateBy (
21562156 ( $ order ->tax_type === 'exclusive ' ? $ order ->tax_value : 0 )
@@ -2162,7 +2162,7 @@ public function refreshOrder( Order $order )
21622162 )
21632163 ->toFloat ();
21642164
2165- $ order ->change = Currency::fresh ( $ order ->tendered )->subtractBy ( $ order ->total )->toFloat ();
2165+ $ order ->change = Currency::define ( $ order ->tendered )->subtractBy ( $ order ->total )->toFloat ();
21662166
21672167 $ refunds = $ order ->refunds ;
21682168
@@ -2851,11 +2851,11 @@ public function createInstalment( Order $order, $fields )
28512851 {
28522852 $ totalInstalment = $ order ->instalments ->map ( fn ( $ instalment ) => $ instalment ->amount )->sum ();
28532853
2854- if ( Currency::raw ( $ fields [ 'amount ' ] ) <= 0 ) {
2854+ if ( Currency::define ( $ fields [ 'amount ' ] )-> toFloat ( ) <= 0 ) {
28552855 throw new NotAllowedException ( __ ( 'The defined amount is not valid. ' ) );
28562856 }
28572857
2858- if ( Currency::raw ( $ totalInstalment ) >= $ order ->total ) {
2858+ if ( Currency::define ( $ totalInstalment )-> toFloat ( ) >= $ order ->total ) {
28592859 throw new NotAllowedException ( __ ( 'No further instalments is allowed for this order. The total instalment already covers the order total. ' ) );
28602860 }
28612861
0 commit comments