@@ -80,6 +80,48 @@ public function getMerchantAddress() {
8080 return false ;
8181 }
8282
83+ public function getFuelSurchargeInclusiveQuote ($ product_id , $ input ) {
84+ try {
85+ $ items = [];
86+ if (!isset ($ input ['from ' ]['state ' ])) {
87+ throw new \Exception ('Need State to get quote ' );
88+ }
89+ if (!isset ($ input ['to ' ]['state ' ])) {
90+ throw new \Exception ('Need State to get quote ' );
91+ }
92+ foreach ($ input ['items ' ] as $ item ) {
93+ $ items [] = [
94+ 'product_id ' => $ product_id ,
95+ 'length ' => $ item ['length ' ],
96+ 'height ' => $ item ['height ' ],
97+ 'width ' => $ item ['width ' ],
98+ 'weight ' => $ item ['weight ' ],
99+ ];
100+ }
101+ $ request = [
102+ 'shipments ' => [
103+ 'from ' => $ input ['from ' ],
104+ 'to ' => $ input ['to ' ],
105+ 'items ' => $ items ,
106+ ],
107+ ];
108+ $ this ->sendPostRequest ('prices/shipments ' , $ request );
109+ $ data = $ this ->convertResponse ($ this ->getResponse ()->data );
110+ $ price_inc_gst = 0 ;
111+ $ price_exc_gst = 0 ;
112+ foreach ($ data ['shipments ' ] as $ shipment ) {
113+ $ price_exc_gst += $ shipment ['shipment_summary ' ]['total_cost_ex_gst ' ];
114+ $ price_inc_gst += $ shipment ['shipment_summary ' ]['total_cost ' ];
115+ }
116+ return [
117+ 'price_inc_gst ' => $ price_inc_gst ,
118+ 'price_exc_gst ' => $ price_exc_gst ,
119+ ];
120+ } catch (\Exception $ e ) {
121+ return null ;
122+ }
123+ }
124+
83125 /**
84126 * Perform a Prices/Items API call
85127 *
@@ -106,6 +148,8 @@ public function getQuotes($input) {
106148 }
107149 }
108150 foreach ($ item ['prices ' ] as $ price ) {
151+ $ fuel_surcharge_prices = $ this ->getFuelSurchargeInclusiveQuote ($ price ['product_id ' ], $ input );
152+
109153 if (!array_key_exists ($ price ['product_id ' ], $ quotes )) {
110154 $ signature_on_delivery_option = false ;
111155 $ authority_to_leave_option = false ;
@@ -129,7 +173,11 @@ public function getQuotes($input) {
129173 'price_exc_gst ' => 0 ,
130174 ];
131175 }
132- if (array_key_exists ('bundled_price ' , $ price ) && $ is_subsequent_item ) {
176+
177+ if ($ fuel_surcharge_prices ) {
178+ $ quotes [$ price ['product_id ' ]]['price_inc_gst ' ] += $ fuel_surcharge_prices ['price_inc_gst ' ];
179+ $ quotes [$ price ['product_id ' ]]['price_exc_gst ' ] += $ fuel_surcharge_prices ['price_exc_gst ' ];
180+ } else if (array_key_exists ('bundled_price ' , $ price ) && $ is_subsequent_item ) {
133181 $ quotes [$ price ['product_id ' ]]['price_inc_gst ' ] += $ price ['bundled_price ' ];
134182 $ quotes [$ price ['product_id ' ]]['price_exc_gst ' ] += $ price ['bundled_price_ex_gst ' ];
135183 } else {
0 commit comments