Skip to content

Commit 44da841

Browse files
committed
Add option to return negotiated rates
1 parent 9506695 commit 44da841

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

demo/create-label.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipmentRequest;
2020
use RahulGodiyal\PhpUpsApiWrapper\Entity\Shipper;
2121
use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipQuery;
22+
use RahulGodiyal\PhpUpsApiWrapper\Entity\ShippingRatingOptions;
2223
use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipTo;
2324
use RahulGodiyal\PhpUpsApiWrapper\Entity\UnitOfMeasurement;
2425
use RahulGodiyal\PhpUpsApiWrapper\Ship;
@@ -153,6 +154,13 @@
153154
$shipment->setPaymentInformation($paymentInformation);
154155
$shipment->setService($service);
155156
$shipment->setPackage($package);
157+
158+
/************ ShippingRatingOptions **********/
159+
$shippingRatingOptions = new ShippingRatingOptions(); // optional
160+
$shippingRatingOptions->setNegotiatedRatesIndicator(true); // optional
161+
$shipment->setShippingRatingOptions($shippingRatingOptions); // optional
162+
/************ End ShippingRatingOptions **********/
163+
156164
/************ End Shipment **********/
157165

158166
/************ Label Specification **********/

src/Entity/Shipment.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ class Shipment
1212
private PaymentInformation $paymentInformation;
1313
private Service $service;
1414
private Package $package;
15+
private ShippingRatingOptions $shippingRatingOptions;
1516

1617
public function __construct()
1718
{
1819
$this->returnService = new ReturnService();
1920
$this->paymentInformation = new PaymentInformation();
21+
$this->shippingRatingOptions = new ShippingRatingOptions();
2022
}
2123

2224
public function setDescription(string $description): self
@@ -107,6 +109,17 @@ public function getPackage(): Package
107109
return $this->package;
108110
}
109111

112+
public function setShippingRatingOptions(ShippingRatingOptions $shippingRatingOptions): self
113+
{
114+
$this->shippingRatingOptions = $shippingRatingOptions;
115+
return $this;
116+
}
117+
118+
public function getShippingRatingOptions(): ShippingRatingOptions
119+
{
120+
return $this->shippingRatingOptions;
121+
}
122+
110123
public function toArray(): array
111124
{
112125
$shipment = [
@@ -132,6 +145,10 @@ public function toArray(): array
132145
$shipment["ReturnService"] = $this->returnService->toArray();
133146
}
134147

148+
if ($this->shippingRatingOptions->exists()) {
149+
$shipment["ShipmentRatingOptions"] = $this->shippingRatingOptions->toArray();
150+
}
151+
135152
return $shipment;
136153
}
137154
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace RahulGodiyal\PhpUpsApiWrapper\Entity;
4+
5+
class ShippingRatingOptions
6+
{
7+
private bool $negotiatedRatesIndicator = false;
8+
private bool $frsShipmentIndicator = false;
9+
private bool $rateChartIndicator = false;
10+
11+
public function exists(): bool
12+
{
13+
return $this->negotiatedRatesIndicator || $this->frsShipmentIndicator || $this->rateChartIndicator;
14+
}
15+
16+
public function setNegotiatedRatesIndicator(bool $negotiatedRatesIndicator): self
17+
{
18+
$this->negotiatedRatesIndicator = $negotiatedRatesIndicator;
19+
return $this;
20+
}
21+
22+
public function getNegotiatedRatesIndicator(): bool
23+
{
24+
return $this->negotiatedRatesIndicator;
25+
}
26+
27+
public function setFrsShipmentIndicator(bool $frsShipmentIndicator): self
28+
{
29+
$this->frsShipmentIndicator = $frsShipmentIndicator;
30+
return $this;
31+
}
32+
33+
public function getFrsShipmentIndicator(): bool
34+
{
35+
return $this->frsShipmentIndicator;
36+
}
37+
38+
public function setRateChartIndicator(bool $rateChartIndicator): self
39+
{
40+
$this->rateChartIndicator = $rateChartIndicator;
41+
return $this;
42+
}
43+
44+
public function getRateChartIndicator(): bool
45+
{
46+
return $this->rateChartIndicator;
47+
}
48+
49+
public function toArray(): array
50+
{
51+
$options = [];
52+
53+
if ($this->negotiatedRatesIndicator) {
54+
$options["NegotiatedRatesIndicator"] = "";
55+
}
56+
57+
if ($this->frsShipmentIndicator) {
58+
$options["FRSShipmentIndicator"] = "";
59+
}
60+
61+
if (!empty($this->rateChartIndicator)) {
62+
$options["RateChartIndicator"] = "";
63+
}
64+
65+
return $options;
66+
}
67+
}

0 commit comments

Comments
 (0)