Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit f667f48

Browse files
authored
Merge pull request #38 from JeremyDunn/response-parsing
Response parsing functionality
2 parents 6401382 + 488d69a commit f667f48

File tree

649 files changed

+1465
-2272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

649 files changed

+1465
-2272
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*.php]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 4

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# CHANGELOG
2+
3+
## 2.0 (released 2017-07-13)
4+
5+
- SoapClient responses are now parsed and populate Reply objects. All of the Request 'Reply' methods now return a populated Reply object instead of the SoapClient stdClass. *This is a backward incompatible change.* To make your code compatible, simply send `true` as the 2nd argument to your `get...Reply` calls. [Click here for an example.](src/FedEx/RateService/Request.php#L27)
6+
- Added more phpunit tests.
7+
8+
## 1.0 (released 2016-03-28)
9+
10+
- Tagged release to indicate stable version in packagist
11+
- Created phpunit tests
12+
- Current web service versions:
13+
14+
|Service|Version|
15+
|---|---|
16+
|Address Validation|2|
17+
|Close|2|
18+
|Courier Dispatch|3|
19+
|Locator|2|
20+
|Package Movement Information|5|
21+
|Pickup|3|
22+
|Rate|10|
23+
|Return Tag|1|
24+
|Ship|12|
25+
|Track|5|
26+
|Upload Document|1|
27+

README.md

Lines changed: 19 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PHP FedEx API Wrapper
22

3-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ee5bdc605dfd44d0a590ea1dfc031421)](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)
43
[![Build Status](https://travis-ci.org/JeremyDunn/php-fedex-api-wrapper.svg?branch=master)](https://travis-ci.org/JeremyDunn/php-fedex-api-wrapper)
4+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ee5bdc605dfd44d0a590ea1dfc031421)](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)
55

66
This library provides a fluid interface for constructing requests to the FedEx web service API.
77

@@ -32,164 +32,6 @@ For example if we wish to get shipping rates, we'll create a new instance of [Fe
3232

3333
This assumes the `FEDEX_KEY`, `FEDEX_PASSWORD`, `FEDEX_ACCOUNT_NUMBER`, and `FEDEX_METER_NUMBER` are previously defined in your application.
3434
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.
19335

19436
```php
19537
use FedEx\RateService\Request;
@@ -261,12 +103,28 @@ $rateRequest->RequestedShipment->RequestedPackageLineItems[1]->GroupPackageCount
261103

262104
$rateServiceRequest = new Request();
263105
$rateServiceRequest->getSoapClient()->__setLocation(Request::PRODUCTION_URL); //use production URL
264-
$response = $rateServiceRequest->getGetRatesReply($rateRequest);
265106

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);
267123

268124
```
269125

270126
More examples can be found in the [examples](examples) folder.
271127

128+
## [Change Log](CHANGELOG.md)
129+
272130

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"symfony/console": "2.*",
2020
"apigen/apigen": "^4.1",
2121
"phpunit/phpunit": "^5.7",
22-
"fzaninotto/faker": "^1.6"
22+
"fzaninotto/faker": "^1.6",
23+
"squizlabs/php_codesniffer": "*"
2324
},
2425
"autoload": {
2526
"psr-4": {

0 commit comments

Comments
 (0)