Skip to content

Commit 3e44ed7

Browse files
authored
Merge pull request #128 from fpgadeveloper/master
* Added FedexCancelPickupRequest class and example usage code to crea…
2 parents 7ea2ca8 + 6fed48e commit 3e44ed7

File tree

3 files changed

+159
-2
lines changed

3 files changed

+159
-2
lines changed

examples/create_pickup.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/env python
22
"""
3-
This example shows how to create a pickup request
3+
This example shows how to create a pickup request and then cancel it
44
"""
55
import datetime
66

77
from example_config import CONFIG_OBJ
88
from fedex.services.pickup_service import FedexCreatePickupRequest
99

10+
pickup_date = datetime.datetime.now().replace(microsecond=0)
11+
1012
customer_transaction_id = "*** PickupService Request v11 using Python ***" # Optional transaction_id
1113
pickup_service = FedexCreatePickupRequest(CONFIG_OBJ, customer_transaction_id)
1214

@@ -29,7 +31,7 @@
2931
# pickup_service.OriginDetail.BuildingPart = 'SUITE'
3032

3133
# Identifies the date and time the package will be ready for pickup by FedEx.
32-
pickup_service.OriginDetail.ReadyTimestamp = datetime.datetime.now().replace(microsecond=0).isoformat()
34+
pickup_service.OriginDetail.ReadyTimestamp = pickup_date.isoformat()
3335

3436
# Identifies the latest time at which the driver can gain access to pick up the package(s)
3537
pickup_service.OriginDetail.CompanyCloseTime = '23:00:00'
@@ -51,5 +53,29 @@
5153

5254
pickup_service.send_request()
5355

56+
print('Pickup request sent:')
5457
print pickup_service.response.HighestSeverity == 'SUCCESS'
5558
print pickup_service.response.Notifications[0].Message
59+
60+
# Cancel the pickup request that we just got confirmation for
61+
cancel_pickup = FedexCancelPickupRequest(CONFIG_OBJ)
62+
63+
cancel_pickup.PickupConfirmationNumber = pickup_service.response.PickupConfirmationNumber
64+
# the date for the pickup (eg. '2016-09-26')
65+
cancel_pickup.ScheduledDate = pickup_date.strftime('%Y-%m-%d')
66+
cancel_pickup.EndDate = pickup_date.strftime('%Y-%m-%d')
67+
cancel_pickup.Location = pickup_service.response.Location
68+
cancel_pickup.Remarks = None
69+
cancel_pickup.ShippingChargesPayment = None
70+
cancel_pickup.Reason = ''
71+
cancel_pickup.ContactName = 'Sender Name'
72+
cancel_pickup.PhoneNumber = '9012638716'
73+
cancel_pickup.PhoneExtension = ''
74+
75+
cancel_pickup.CarrierCode = 'FDXE'
76+
77+
cancel_pickup.send_request()
78+
79+
print('Cancel pickup request sent:')
80+
print('Highest severity:',cancel_pickup.response.HighestSeverity)
81+
print('Message:',cancel_pickup.response.Notifications[0].Message)

fedex/services/document_service.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ def _assemble_and_send_request(self):
7070
OriginCountryCode = self.OriginCountryCode,
7171
DestinationCountryCode = self.DestinationCountryCode,
7272
)
73+
74+
def enable_post_shipment(self,trackingnumber):
75+
"""
76+
Enable post shipment upload - when uploading docs after the shipment has been processed
77+
or confirmed, you must provide the tracking number.
78+
The shipment also must have been processed with the POST_SHIPMENT_UPLOAD_REQUESTED ETD attribute.
79+
"""
80+
self.ProcessingOptions.Options = ["POST_SHIPMENT_UPLOAD"]
81+
self.ProcessingOptions.PostShipmentUploadDetail.TrackingNumber = trackingnumber
82+
7383
def get_document(self, line_number,customer_reference,
7484
document_type , file_name, document_content, expiration_date =None
7585
):
@@ -81,5 +91,59 @@ def get_document(self, line_number,customer_reference,
8191
document_item.DocumentContent = document_content
8292
document_item.ExpirationDate = expiration_date
8393
return document_item
94+
8495
def add_documents(self, document_item):
8596
self.Documents.append(document_item)
97+
98+
99+
class FedexUploadImagesRequest(FedexBaseService):
100+
"""
101+
This class allows you to submit images.
102+
You will need to add images to self.Images,
103+
then send the request.
104+
"""
105+
106+
def __init__(self, config_obj, *args, **kwargs):
107+
"""
108+
The optional keyword args detailed on L{FedexBaseService}
109+
apply here as well.
110+
@type config_obj: L{FedexConfig}
111+
@param config_obj: A valid FedexConfig object.
112+
"""
113+
114+
self._config_obj = config_obj
115+
116+
# Holds version info for the VersionId SOAP object.
117+
self._version_info = {'service_id': 'cdus', 'major': '11',
118+
'intermediate': '0', 'minor': '0'}
119+
120+
super(FedexUploadImagesRequest, self).__init__(
121+
self._config_obj, 'UploadDocumentService_v11.wsdl', *args, **kwargs)
122+
123+
def _prepare_wsdl_objects(self):
124+
"""
125+
This is the data that will be used to create your shipment. Create
126+
the data structure and get it ready for the WSDL request.
127+
"""
128+
self.Images = []
129+
130+
def _assemble_and_send_request(self):
131+
"""
132+
Fires off the Fedex request.
133+
134+
@warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(),
135+
WHICH RESIDES ON FedexBaseService AND IS INHERITED.
136+
"""
137+
138+
# Fire off the query.
139+
return self.client.service.uploadImages(
140+
WebAuthenticationDetail=self.WebAuthenticationDetail,
141+
ClientDetail=self.ClientDetail,
142+
TransactionDetail=self.TransactionDetail,
143+
Version=self.VersionId,
144+
Images=self.Images,
145+
)
146+
147+
def add_image(self, image_item):
148+
self.Images.append(image_item)
149+

fedex/services/pickup_service.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,70 @@ def _assemble_and_send_request(self):
143143
ShipmentAttributes=self.ShipmentAttributes,
144144
PackageDetails=self.PackageDetails
145145
)
146+
147+
class FedexCancelPickupRequest(FedexBaseService):
148+
"""
149+
This class allows you to cancel a pickup request, given a dispatch confirmation number.
150+
"""
151+
152+
def __init__(self, config_obj, *args, **kwargs):
153+
"""
154+
Cancels a pickup request via a dispatch confirmation number.
155+
"""
156+
157+
self._config_obj = config_obj
158+
159+
# Holds version info for the VersionId SOAP object.
160+
self._version_info = {'service_id': 'disp', 'major': '17',
161+
'intermediate': '0', 'minor': '0'}
162+
self.CarrierCode = None
163+
self.PickupConfirmationNumber = None
164+
self.ScheduledDate = None
165+
self.EndDate = None
166+
self.Location = None
167+
self.Remarks = None
168+
self.ShippingChargesPayment = None
169+
self.Reason = None
170+
self.ContactName = None
171+
self.PhoneNumber = None
172+
self.PhoneExtension = None
173+
# Call the parent FedexBaseService class for basic setup work.
174+
super(FedexCancelPickupRequest, self).__init__(self._config_obj,
175+
'PickupService_v17.wsdl',
176+
*args, **kwargs)
177+
178+
def _prepare_wsdl_objects(self):
179+
"""
180+
Preps the WSDL data structures for the user.
181+
"""
182+
183+
self.CarrierCode = self.client.factory.create('CarrierCodeType')
184+
self.ShippingChargesPayment = self.client.factory.create('Payment')
185+
186+
def _assemble_and_send_request(self):
187+
"""
188+
Fires off the Fedex request.
189+
190+
@warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
191+
ON FedexBaseService AND IS INHERITED.
192+
"""
193+
194+
# Fire off the query.
195+
return self.client.service.cancelPickup(
196+
WebAuthenticationDetail=self.WebAuthenticationDetail,
197+
ClientDetail=self.ClientDetail,
198+
TransactionDetail=self.TransactionDetail,
199+
Version=self.VersionId,
200+
CarrierCode=self.CarrierCode,
201+
PickupConfirmationNumber=self.PickupConfirmationNumber,
202+
ScheduledDate=self.ScheduledDate,
203+
EndDate=self.EndDate,
204+
Location=self.Location,
205+
Remarks=self.Remarks,
206+
ShippingChargesPayment=self.ShippingChargesPayment,
207+
Reason=self.Reason,
208+
ContactName=self.ContactName,
209+
PhoneNumber=self.PhoneNumber,
210+
PhoneExtension=self.PhoneExtension
211+
)
212+

0 commit comments

Comments
 (0)