Skip to content

Commit 7c80e3a

Browse files
committed
Include fuel surcharge in quotes
1 parent d9a13af commit 7c80e3a

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

src/Auspost.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 {

src/Shipment.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ public function addParcel($data) {
8484
public function getQuotes() {
8585
$request = [
8686
'from' => [
87-
'suburb' => $this->from->suburb,
87+
'suburb' => $this->from->suburb,
8888
'postcode' => $this->from->postcode,
89+
'state' => $this->from->state,
8990
'country' => $this->from->country,
9091
],
9192
'to' => [
92-
'suburb' => $this->to->suburb,
93+
'suburb' => $this->to->suburb,
9394
'postcode' => $this->to->postcode,
95+
'state' => $this->to->state,
9496
'country' => $this->to->country,
9597
],
9698
'items' => [],
@@ -217,5 +219,4 @@ public function getLabel($labelType) {
217219
public function deleteShipment() {
218220
return $this->_auspost->deleteShipment($this->shipment_id);
219221
}
220-
221222
}

0 commit comments

Comments
 (0)