Skip to content

Commit 724a455

Browse files
author
Greg Taylor
committed
First iteration of shipment creation. Failing due to a Schema validation error coming from suds for some reason. This is currently not anywhere near production quality, as it was meant to check to make sure I could form a valid request.
1 parent 4f78c31 commit 724a455

File tree

5 files changed

+110
-32
lines changed

5 files changed

+110
-32
lines changed

examples/track_shipment.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
config_obj = FedexConfig(key='ZyNQQFdcxUATOx9L',
1515
password='GtngmKzs4Dk4RYmrlAjrLykwi',
1616
account_number='510087780',
17-
meter_number='118501898')
17+
meter_number='118501898',
18+
use_test_server=True)
1819

1920
# This is the object that will be handling our tracking request.
20-
track = FedexTrackRequest(config_obj, '1777768882')
21+
track = FedexTrackRequest(config_obj, '798114182456')
2122
# Fires off the request, sets the 'response' attribute on the object.
2223
track.send_request()
2324

fedex/services/ship_service.py

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ShipService WSDL file. Each is encapsulated in a class for easy access.
66
For more details on each, refer to the respective class's documentation.
77
"""
8+
from datetime import datetime
89
from .. base_service import FedexBaseService
910

1011
class FedexShipRequest(FedexBaseService):
@@ -35,19 +36,97 @@ def __init__(self, config_obj, tracking_value,
3536
self._config_obj = config_obj
3637

3738
# Holds version info for the VersionId SOAP object.
38-
self._version_info = {'service_id': 'trck', 'major': '7',
39+
self._version_info = {'service_id': 'ship', 'major': '7',
3940
'intermediate': '0', 'minor': '0'}
4041
# Call the parent FedexBaseService class for basic setup work.
4142
super(FedexShipRequest, self).__init__(self._config_obj,
4243
'ShipService_v7.wsdl',
4344
*args, **kwargs)
4445

45-
def __set_transactional_detail(self):
46+
def __set_requested_shipment(self):
4647
"""
48+
This is the data that will be used to create your shipment. Create
49+
the data structure and get it ready for the WSDL request.
4750
"""
48-
TransactionDetail = self.client.factory.create('TransactionDetail')
49-
self.logger.info(TransactionDetail)
50-
self.TransactionDetail = TransactionDetail
51+
RequestedShipment = self.client.factory.create('RequestedShipment')
52+
RequestedShipment.ShipTimestamp = datetime.now()
53+
RequestedShipment.DropoffType = 'REGULAR_PICKUP' # REGULAR_PICKUP, REQUEST_COURIER, DROP_BOX, BUSINESS_SERVICE_CENTER and STATION
54+
RequestedShipment.ServiceType = 'PRIORITY_OVERNIGHT' # valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND
55+
RequestedShipment.PackagingType = 'FEDEX_PAK' # valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING
56+
57+
Weight = self.client.factory.create('Weight')
58+
Weight.Value = 50.0
59+
Weight.Units = 'LB' # LB or KG
60+
# Assemble
61+
RequestedShipment.TotalWeight = Weight
62+
63+
"""
64+
Begin shipper info.
65+
"""
66+
ShipperParty = self.client.factory.create('Party')
67+
ShipperContact = self.client.factory.create('Contact')
68+
ShipperContact.PersonName = 'Sender Name'
69+
ShipperContact.CompanyName = 'Some Company'
70+
ShipperContact.PhoneNumber = '9012638716'
71+
# Assemble
72+
ShipperParty.Contact = ShipperContact
73+
74+
ShipperAddress = self.client.factory.create('Address')
75+
ShipperAddress.StreetLines = ['Address Line 1']
76+
ShipperAddress.City = 'Herndon'
77+
ShipperAddress.StateOrProvinceCode = 'VA'
78+
ShipperAddress.PostalCode = '20171'
79+
ShipperAddress.CountryCode = 'US'
80+
ShipperAddress.Residential = True
81+
# Assemble
82+
ShipperParty.Address = ShipperAddress
83+
# Assemble
84+
RequestedShipment.Shipper = ShipperParty
85+
"""
86+
End shipper info.
87+
"""
88+
89+
"""
90+
Begin recipient info.
91+
"""
92+
RecipientParty = self.client.factory.create('Party')
93+
RecipientContact = self.client.factory.create('Contact')
94+
RecipientContact.PersonName = 'Recipient Name'
95+
RecipientContact.CompanyName = 'Recipient Company'
96+
RecipientContact.PhoneNumber = '9012637906'
97+
# Assemble
98+
RecipientParty.Contact = RecipientContact
99+
100+
RecipientAddress = self.client.factory.create('Address')
101+
RecipientAddress.StreetLines = ['Address Line 1']
102+
RecipientAddress.City = 'Herndon'
103+
RecipientAddress.StateOrProvinceCode = 'VA'
104+
RecipientAddress.PostalCode = '20171'
105+
RecipientAddress.CountryCode = 'US'
106+
RecipientAddress.Residential = True
107+
# Assemble
108+
RecipientParty.Address = RecipientAddress
109+
# Assemble
110+
RequestedShipment.Recipient = RecipientParty
111+
"""
112+
End recipient info.
113+
"""
114+
115+
ShippingChargesPayment = self.client.factory.create('Payment')
116+
ShippingChargesPayment.PaymentType = 'SENDER' # RECIPIENT, SENDER and THIRD_PARTY
117+
Payor = self.client.factory.create('Payor')
118+
Payor.AccountNumber = self._config_obj.account_number
119+
Payor.CountryCode = 'US'
120+
ShippingChargesPayment.Payor = Payor
121+
# Assemble
122+
RequestedShipment.ShippingChargesPayment = ShippingChargesPayment
123+
124+
RequestedShipment.RateRequestTypes = ['ACCOUNT'] # ACCOUNT and LIST
125+
RequestedShipment.PackageCount = 1
126+
RequestedShipment.PackageDetail = 'INDIVIDUAL_PACKAGES'
127+
128+
self.logger.debug(RequestedShipment)
129+
self.RequestedShipment = RequestedShipment
51130

52131
def _assemble_and_send_request(self):
53132
"""
@@ -56,14 +135,19 @@ def _assemble_and_send_request(self):
56135
@warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
57136
ON FedexBaseService AND IS INHERITED.
58137
"""
59-
self.__set_transactional_detail()
138+
self.__set_requested_shipment()
60139
client = self.client
61140
# Fire off the query.
141+
response = client.service.processShipment(WebAuthenticationDetail=self.WebAuthenticationDetail,
142+
ClientDetail=self.ClientDetail,
143+
TransactionDetail=self.TransactionDetail,
144+
Version=self.VersionId,
145+
RequestedShipment=self.RequestedShipment)
62146
"""
63147
processShipment(WebAuthenticationDetail WebAuthenticationDetail,
64148
ClientDetail ClientDetail,
65149
TransactionDetail TransactionDetail,
66150
VersionId Version,
67151
RequestedShipment RequestedShipment)
68152
"""
69-
#return response
153+
return response

test_runner.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/common.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ def get_test_config():
88
"""
99
Returns a basic FedexConfig to test with.
1010
"""
11+
"""
12+
# Production server
13+
return FedexConfig(key='xxxxxxxxxxxxxxxxx',
14+
password='xxxxxxxxxxxxxxxxxxxxxxxxx',
15+
account_number='xxxxxxxxx',
16+
meter_number='xxxxxxxxxx')
17+
"""
18+
# Test server
1119
return FedexConfig(key='ZyNQQFdcxUATOx9L',
1220
password='GtngmKzs4Dk4RYmrlAjrLykwi',
1321
account_number='510087780',
14-
meter_number='118501898')
22+
meter_number='118501898',
23+
use_test_server=True)

tests/t_track_service.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ def test_track(self):
1717
Test shipment tracking. Query for a tracking number and make sure the
1818
first (and hopefully only) result matches up.
1919
"""
20-
tracking_num = '1777768882'
21-
tracking_num = '799428562846'
22-
tracking_num = '111111111111'
23-
tracking_num = '012301230123'
20+
#tracking_num = '1777768882'
21+
#tracking_num = '799428562846'
22+
#tracking_num = '111111111111'
23+
#tracking_num = '012301230123'
24+
tracking_num = '798114182456'
2425

2526
track_request = FedexTrackRequest(CONFIG_OBJ, tracking_num)
2627
track_request.send_request()
27-
28-
print track_request.response
2928

3029
for match in track_request.response.TrackDetails:
3130
# This should be the same tracking number on the response that we
3231
# asked for in the request.
33-
self.assertEqual(match.TrackingNumber, tracking_num)
32+
self.assertEqual(match.TrackingNumber, tracking_num)

0 commit comments

Comments
 (0)