forked from JeremyDunn/php-fedex-api-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathship.php
More file actions
128 lines (108 loc) · 4.54 KB
/
ship.php
File metadata and controls
128 lines (108 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* This test will send the same test data as in FedEx's documentation:
* /php/RateAvailableServices/RateAvailableServices.php5
*/
//remember to copy example.credentials.php as credentials.php replace 'FEDEX_KEY', 'FEDEX_PASSWORD', 'FEDEX_ACCOUNT_NUMBER', and 'FEDEX_METER_NUMBER'
require_once 'credentials.php';
require_once 'bootstrap.php';
use FedEx\ShipService;
use FedEx\ShipService\ComplexType;
use FedEx\ShipService\SimpleType;
$userCredential = new ComplexType\WebAuthenticationCredential();
$userCredential
->setKey(FEDEX_KEY)
->setPassword(FEDEX_PASSWORD);
$webAuthenticationDetail = new ComplexType\WebAuthenticationDetail();
$webAuthenticationDetail->setUserCredential($userCredential);
$clientDetail = new ComplexType\ClientDetail();
$clientDetail
->setAccountNumber(FEDEX_ACCOUNT_NUMBER)
->setMeterNumber(FEDEX_METER_NUMBER);
$version = new ComplexType\VersionId();
$version
->setMajor(12)
->setIntermediate(1)
->setMinor(0)
->setServiceId('ship');
$shipperAddress = new ComplexType\Address();
$shipperAddress
->setStreetLines(['Address Line 1'])
->setCity('Austin')
->setStateOrProvinceCode('TX')
->setPostalCode('73301')
->setCountryCode('US');
$shipperContact = new ComplexType\Contact();
$shipperContact
->setCompanyName('Company Name')
->setEMailAddress('[email protected]')
->setPersonName('Person Name')
->setPhoneNumber(('123-123-1234'));
$shipper = new ComplexType\Party();
$shipper
->setAccountNumber(FEDEX_ACCOUNT_NUMBER)
->setAddress($shipperAddress)
->setContact($shipperContact);
$recipientAddress = new ComplexType\Address();
$recipientAddress
->setStreetLines(['Address Line 1'])
->setCity('Herndon')
->setStateOrProvinceCode('VA')
->setPostalCode('20171')
->setCountryCode('US');
$recipientContact = new ComplexType\Contact();
$recipientContact
->setPersonName('Contact Name')
->setPhoneNumber('1234567890');
$recipient = new ComplexType\Party();
$recipient
->setAddress($recipientAddress)
->setContact($recipientContact);
$labelSpecification = new ComplexType\LabelSpecification();
$labelSpecification
->setLabelStockType(new SimpleType\LabelStockType(SimpleType\LabelStockType::_PAPER_7X4POINT75))
->setImageType(new SimpleType\ShippingDocumentImageType(SimpleType\ShippingDocumentImageType::_PDF))
->setLabelFormatType(new SimpleType\LabelFormatType(SimpleType\LabelFormatType::_COMMON2D));
$packageLineItem1 = new ComplexType\RequestedPackageLineItem();
$packageLineItem1
->setSequenceNumber(1)
->setItemDescription('Product description')
->setDimensions(new ComplexType\Dimensions(array(
'Width' => 10,
'Height' => 10,
'Length' => 25,
'Units' => SimpleType\LinearUnits::_IN
)))
->setWeight(new ComplexType\Weight(array(
'Value' => 2,
'Units' => SimpleType\WeightUnits::_LB
)));
$shippingChargesPayor = new ComplexType\Payor();
$shippingChargesPayor->setResponsibleParty($shipper);
$shippingChargesPayment = new ComplexType\Payment();
$shippingChargesPayment
->setPaymentType(SimpleType\PaymentType::_SENDER)
->setPayor($shippingChargesPayor);
$requestedShipment = new ComplexType\RequestedShipment();
$requestedShipment->setShipTimestamp(date('c'));
$requestedShipment->setDropoffType(new SimpleType\DropoffType(SimpleType\DropoffType::_REGULAR_PICKUP));
$requestedShipment->setServiceType(new SimpleType\ServiceType(SimpleType\ServiceType::_FEDEX_GROUND));
$requestedShipment->setPackagingType(new SimpleType\PackagingType(SimpleType\PackagingType::_YOUR_PACKAGING));
$requestedShipment->setShipper($shipper);
$requestedShipment->setRecipient($recipient);
$requestedShipment->setLabelSpecification($labelSpecification);
$requestedShipment->setRateRequestTypes(array(new SimpleType\RateRequestType(SimpleType\RateRequestType::_ACCOUNT)));
$requestedShipment->setPackageCount(1);
$requestedShipment->setRequestedPackageLineItems([
$packageLineItem1
]);
$requestedShipment->setShippingChargesPayment($shippingChargesPayment);
$processShipmentRequest = new ComplexType\ProcessShipmentRequest();
$processShipmentRequest->setWebAuthenticationDetail($webAuthenticationDetail);
$processShipmentRequest->setClientDetail($clientDetail);
$processShipmentRequest->setVersion($version);
$processShipmentRequest->setRequestedShipment($requestedShipment);
$shipService = new ShipService\Request();
//$shipService->getSoapClient()->__setLocation('https://ws.fedex.com:443/web-services/ship');
$result = $shipService->getProcessShipmentReply($processShipmentRequest);
var_dump($result);