|
1 | 1 | # PHP FedEx API Wrapper |
2 | 2 |
|
3 | | -[](https://www.codacy.com/app/JeremyDunn/php-fedex-api-wrapper?utm_source=github.com&utm_medium=referral&utm_content=JeremyDunn/php-fedex-api-wrapper&utm_campaign=badger) |
4 | 3 | [](https://travis-ci.org/JeremyDunn/php-fedex-api-wrapper) |
| 4 | +[](https://www.codacy.com/app/JeremyDunn/php-fedex-api-wrapper?utm_source=github.com&utm_medium=referral&utm_content=JeremyDunn/php-fedex-api-wrapper&utm_campaign=badger) |
5 | 5 |
|
6 | 6 | This library provides a fluid interface for constructing requests to the FedEx web service API. |
7 | 7 |
|
@@ -32,164 +32,6 @@ For example if we wish to get shipping rates, we'll create a new instance of [Fe |
32 | 32 |
|
33 | 33 | This assumes the `FEDEX_KEY`, `FEDEX_PASSWORD`, `FEDEX_ACCOUNT_NUMBER`, and `FEDEX_METER_NUMBER` are previously defined in your application. |
34 | 34 | Also note that by default, the library will use the beta/testing server (wsbeta.fedex.com). To use the production server (ws.fedex.com), set the location on the `\SoapClient` returned from the Request. See below for an example of how to do this. |
35 | | -```php |
36 | | -use FedEx\RateService; |
37 | | -use FedEx\RateService\ComplexType; |
38 | | -use FedEx\RateService\SimpleType; |
39 | | - |
40 | | -//RateRequest |
41 | | -$rateRequest = new ComplexType\RateRequest(); |
42 | | - |
43 | | -//UserCredential |
44 | | -$userCredential = new ComplexType\WebAuthenticationCredential(); |
45 | | -$userCredential |
46 | | - ->setKey(FEDEX_KEY) |
47 | | - ->setPassword(FEDEX_PASSWORD); |
48 | | - |
49 | | -//WebAuthenticationDetail |
50 | | -$webAuthenticationDetail = new ComplexType\WebAuthenticationDetail(); |
51 | | -$webAuthenticationDetail->setUserCredential($userCredential); |
52 | | - |
53 | | -$rateRequest->setWebAuthenticationDetail($webAuthenticationDetail); |
54 | | - |
55 | | -//ClientDetail |
56 | | -$clientDetail = new ComplexType\ClientDetail(); |
57 | | -$clientDetail |
58 | | - ->setAccountNumber(FEDEX_ACCOUNT_NUMBER) |
59 | | - ->setMeterNumber(FEDEX_METER_NUMBER); |
60 | | - |
61 | | -$rateRequest->setClientDetail($clientDetail); |
62 | | - |
63 | | -//TransactionDetail |
64 | | -$transactionDetail = new ComplexType\TransactionDetail(); |
65 | | -$transactionDetail->setCustomerTransactionId('Testing Rate Service request'); |
66 | | - |
67 | | -$rateRequest->setTransactionDetail($transactionDetail); |
68 | | - |
69 | | -//VersionId |
70 | | -$versionId = new ComplexType\VersionId(); |
71 | | -$versionId |
72 | | - ->setServiceId('crs') |
73 | | - ->setMajor(10) |
74 | | - ->setIntermediate(0) |
75 | | - ->setMinor(0); |
76 | | - |
77 | | -$rateRequest->setVersion($versionId); |
78 | | - |
79 | | -//OPTIONAL ReturnTransitAndCommit |
80 | | -$rateRequest->setReturnTransitAndCommit(true); |
81 | | - |
82 | | -//RequestedShipment |
83 | | -$requestedShipment = new ComplexType\RequestedShipment(); |
84 | | -$requestedShipment->setDropoffType(SimpleType\DropoffType::_REGULAR_PICKUP); |
85 | | -$requestedShipment->setShipTimestamp(date('c')); |
86 | | - |
87 | | -$rateRequest->setRequestedShipment($requestedShipment); |
88 | | - |
89 | | -//RequestedShipment/Shipper |
90 | | -$shipper = new ComplexType\Party(); |
91 | | - |
92 | | -$shipperAddress = new ComplexType\Address(); |
93 | | -$shipperAddress |
94 | | - ->setStreetLines(array('10 Fed Ex Pkwy')) |
95 | | - ->setCity('Memphis') |
96 | | - ->setStateOrProvinceCode('TN') |
97 | | - ->setPostalCode(38115) |
98 | | - ->setCountryCode('US'); |
99 | | - |
100 | | -$shipper->setAddress($shipperAddress); |
101 | | - |
102 | | -$requestedShipment->setShipper($shipper); |
103 | | - |
104 | | -//RequestedShipment/Recipient |
105 | | -$recipient = new ComplexType\Party(); |
106 | | - |
107 | | -$recipientAddress = new ComplexType\Address(); |
108 | | -$recipientAddress |
109 | | - ->setStreetLines(array('13450 Farmcrest Ct')) |
110 | | - ->setCity('Herndon') |
111 | | - ->setStateOrProvinceCode('VA') |
112 | | - ->setPostalCode(20171) |
113 | | - ->setCountryCode('US'); |
114 | | - |
115 | | -$recipient->setAddress($recipientAddress); |
116 | | - |
117 | | -$requestedShipment->setRecipient($recipient); |
118 | | - |
119 | | -//RequestedShipment/ShippingChargesPayment |
120 | | -$shippingChargesPayment = new ComplexType\Payment(); |
121 | | -$shippingChargesPayment->setPaymentType(SimpleType\PaymentType::_SENDER); |
122 | | - |
123 | | -$payor = new ComplexType\Payor(); |
124 | | -$payor |
125 | | - ->setAccountNumber(FEDEX_ACCOUNT_NUMBER) |
126 | | - ->setCountryCode('US'); |
127 | | - |
128 | | -$shippingChargesPayment->setPayor($payor); |
129 | | - |
130 | | -$requestedShipment->setShippingChargesPayment($shippingChargesPayment); |
131 | | - |
132 | | -//RequestedShipment/RateRequestType(s) |
133 | | -$requestedShipment->setRateRequestTypes([ |
134 | | - SimpleType\RateRequestType::_LIST, |
135 | | - SimpleType\RateRequestType::_ACCOUNT |
136 | | -]); |
137 | | - |
138 | | -//RequestedShipment/PackageCount |
139 | | -$requestedShipment->setPackageCount(2); |
140 | | - |
141 | | -//RequestedShipment/RequestedPackageLineItem(s) |
142 | | -$item1Weight = new ComplexType\Weight(); |
143 | | -$item1Weight |
144 | | - ->setUnits(SimpleType\WeightUnits::_LB) |
145 | | - ->setValue(2.0); |
146 | | - |
147 | | -$item1Dimensions = new ComplexType\Dimensions(); |
148 | | -$item1Dimensions |
149 | | - ->setLength(10) |
150 | | - ->setWidth(10) |
151 | | - ->setHeight(3) |
152 | | - ->setUnits(SimpleType\LinearUnits::_IN); |
153 | | - |
154 | | -$item1 = new ComplexType\RequestedPackageLineItem(); |
155 | | -$item1 |
156 | | - ->setWeight($item1Weight) |
157 | | - ->setDimensions($item1Dimensions) |
158 | | - ->setGroupPackageCount(1); |
159 | | - |
160 | | -$item2Weight = new ComplexType\Weight(); |
161 | | -$item2Weight |
162 | | - ->setUnits(SimpleType\WeightUnits::_LB) |
163 | | - ->setValue(5.0); |
164 | | - |
165 | | -$item2Dimensions = new ComplexType\Dimensions(); |
166 | | -$item2Dimensions |
167 | | - ->setLength(20) |
168 | | - ->setWidth(20) |
169 | | - ->setHeight(10) |
170 | | - ->setUnits(SimpleType\LinearUnits::_IN); |
171 | | - |
172 | | -$item2 = new ComplexType\RequestedPackageLineItem(); |
173 | | -$item2 |
174 | | - ->setWeight($item2Weight) |
175 | | - ->setDimensions($item2Dimensions) |
176 | | - ->setGroupPackageCount(1); |
177 | | - |
178 | | -$requestedShipment->setRequestedPackageLineItems([$item1, $item2]); |
179 | | - |
180 | | -$rateRequest->setRequestedShipment($requestedShipment); |
181 | | - |
182 | | -$rateServiceRequest = new RateService\Request(); |
183 | | -$rateServiceRequest->getSoapClient()->__setLocation(RateService\Request::PRODUCTION_URL); //use the production web service |
184 | | -$response = $rateServiceRequest->getGetRatesReply($rateRequest); |
185 | | - |
186 | | -var_dump($response); |
187 | | - |
188 | | -``` |
189 | | - |
190 | | -## Shorter syntax example |
191 | | - |
192 | | -This is the same request as above using a shorter class property syntax. |
193 | 35 |
|
194 | 36 | ```php |
195 | 37 | use FedEx\RateService\Request; |
@@ -261,12 +103,28 @@ $rateRequest->RequestedShipment->RequestedPackageLineItems[1]->GroupPackageCount |
261 | 103 |
|
262 | 104 | $rateServiceRequest = new Request(); |
263 | 105 | $rateServiceRequest->getSoapClient()->__setLocation(Request::PRODUCTION_URL); //use production URL |
264 | | -$response = $rateServiceRequest->getGetRatesReply($rateRequest); |
265 | 106 |
|
266 | | -var_dump($response); |
| 107 | +$rateReply = $rateServiceRequest->getGetRatesReply($rateRequest); // send true as the 2nd argument to return the SoapClient's stdClass response. |
| 108 | + |
| 109 | +if (!empty($rateReply->RateReplyDetails)) { |
| 110 | + foreach ($rateReply->RateReplyDetails as $rateReplyDetail) { |
| 111 | + var_dump($rateReplyDetail->ServiceType); |
| 112 | + var_dump($rateReplyDetail->DeliveryTimestamp); |
| 113 | + if (!empty($rateReplyDetail->RatedShipmentDetails)) { |
| 114 | + foreach ($rateReplyDetail->RatedShipmentDetails as $ratedShipmentDetail) { |
| 115 | + var_dump($ratedShipmentDetail->ShipmentRateDetail->RateType . ": " . $ratedShipmentDetail->ShipmentRateDetail->TotalNetCharge->Amount); |
| 116 | + } |
| 117 | + } |
| 118 | + echo "<hr />"; |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +var_dump($rateReply); |
267 | 123 |
|
268 | 124 | ``` |
269 | 125 |
|
270 | 126 | More examples can be found in the [examples](examples) folder. |
271 | 127 |
|
| 128 | +## [Change Log](CHANGELOG.md) |
| 129 | + |
272 | 130 |
|
0 commit comments