Skip to content

Commit 7e5b239

Browse files
author
Brent Sanders
committed
Updates services to handle freight - removes test acct #
1 parent cd8521a commit 7e5b239

File tree

3 files changed

+179
-2
lines changed

3 files changed

+179
-2
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#!/usr/bin/env python
2+
"""
3+
This example shows how to create shipments. The variables populated below
4+
represents the minimum required values. You will need to fill all of these, or
5+
risk seeing a SchemaValidationError exception thrown.
6+
7+
Near the bottom of the module, you'll see some different ways to handle the
8+
label data that is returned with the reply.
9+
"""
10+
import logging
11+
import binascii
12+
from example_config import CONFIG_OBJ
13+
from fedex.services.ship_service import FedexProcessShipmentRequest
14+
15+
# Set this to the INFO level to see the response from Fedex printed in stdout.
16+
#logging.basicConfig(filename="suds.log", level=logging.DEBUG)
17+
logging.basicConfig(level=logging.INFO)
18+
# This is the object that will be handling our tracking request.
19+
# We're using the FedexConfig object from example_config.py in this dir.
20+
shipment = FedexProcessShipmentRequest(CONFIG_OBJ)
21+
shipment.RequestedShipment.DropoffType = 'REGULAR_PICKUP'
22+
shipment.RequestedShipment.ServiceType = 'FEDEX_FREIGHT_ECONOMY'
23+
shipment.RequestedShipment.PackagingType = 'YOUR_PACKAGING'
24+
25+
shipment.RequestedShipment.FreightShipmentDetail.FedExFreightAccountNumber = 'xxxxxxxxx' #freight account number
26+
27+
# Shipper contact info.
28+
shipment.RequestedShipment.Shipper.Contact.PersonName = 'Sender Name'
29+
shipment.RequestedShipment.Shipper.Contact.CompanyName = 'Some Company'
30+
shipment.RequestedShipment.Shipper.Contact.PhoneNumber = '9012638716'
31+
32+
# Shipper address.
33+
shipment.RequestedShipment.Shipper.Address.StreetLines = ['1202 Chalet Ln']
34+
shipment.RequestedShipment.Shipper.Address.City = 'Harrison'
35+
shipment.RequestedShipment.Shipper.Address.StateOrProvinceCode = 'AR'
36+
shipment.RequestedShipment.Shipper.Address.PostalCode = '72601'
37+
shipment.RequestedShipment.Shipper.Address.CountryCode = 'US'
38+
shipment.RequestedShipment.Shipper.Address.Residential = True
39+
40+
# Recipient contact info.
41+
shipment.RequestedShipment.Recipient.Contact.PersonName = 'Recipient Name'
42+
shipment.RequestedShipment.Recipient.Contact.CompanyName = 'Recipient Company'
43+
shipment.RequestedShipment.Recipient.Contact.PhoneNumber = '9012637906'
44+
45+
# Recipient address
46+
shipment.RequestedShipment.Recipient.Address.StreetLines = ['2000 Freight LTL Testing']
47+
shipment.RequestedShipment.Recipient.Address.City = 'Harrison'
48+
shipment.RequestedShipment.Recipient.Address.StateOrProvinceCode = 'AR'
49+
shipment.RequestedShipment.Recipient.Address.PostalCode = '72601'
50+
shipment.RequestedShipment.Recipient.Address.CountryCode = 'US'
51+
# This is needed to ensure an accurate rate quote with the response.
52+
shipment.RequestedShipment.Recipient.Address.Residential = False
53+
shipment.RequestedShipment.FreightShipmentDetail.TotalHandlingUnits = 1
54+
55+
shipment.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Contact.PersonName = 'Sender Name'
56+
shipment.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Contact.CompanyName = 'Some Company'
57+
shipment.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Contact.PhoneNumber = '9012638716'
58+
59+
shipment.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.StreetLines = ['2000 Freight LTL Testing']
60+
shipment.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.City = 'Harrison'
61+
shipment.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.StateOrProvinceCode = 'AR'
62+
shipment.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.PostalCode = '72601'
63+
shipment.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.CountryCode = 'US'
64+
shipment.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.Residential = False
65+
spec = shipment.create_wsdl_object_of_type('ShippingDocumentSpecification')
66+
67+
spec.ShippingDocumentTypes = [spec.CertificateOfOrigin]
68+
# shipment.RequestedShipment.ShippingDocumentSpecification = spec
69+
70+
role = shipment.create_wsdl_object_of_type('FreightShipmentRoleType')
71+
72+
shipment.RequestedShipment.FreightShipmentDetail.Role = role.SHIPPER
73+
shipment.RequestedShipment.FreightShipmentDetail.CollectTermsType = 'STANDARD'
74+
75+
76+
# Specifies the label type to be returned.
77+
shipment.RequestedShipment.LabelSpecification.LabelFormatType = 'FEDEX_FREIGHT_STRAIGHT_BILL_OF_LADING'
78+
79+
# Specifies which format the label file will be sent to you in.
80+
# DPL, EPL2, PDF, PNG, ZPLII
81+
shipment.RequestedShipment.LabelSpecification.ImageType = 'PDF'
82+
83+
# To use doctab stocks, you must change ImageType above to one of the
84+
# label printer formats (ZPLII, EPL2, DPL).
85+
# See documentation for paper types, there quite a few.
86+
shipment.RequestedShipment.LabelSpecification.LabelStockType = 'PAPER_LETTER'
87+
88+
# This indicates if the top or bottom of the label comes out of the
89+
# printer first.
90+
# BOTTOM_EDGE_OF_TEXT_FIRST or TOP_EDGE_OF_TEXT_FIRST
91+
shipment.RequestedShipment.LabelSpecification.LabelPrintingOrientation = 'BOTTOM_EDGE_OF_TEXT_FIRST'
92+
shipment.RequestedShipment.EdtRequestType = 'NONE'
93+
94+
package1_weight = shipment.create_wsdl_object_of_type('Weight')
95+
package1_weight.Value = 500.0
96+
package1_weight.Units = "LB"
97+
98+
shipment.RequestedShipment.FreightShipmentDetail.PalletWeight = package1_weight
99+
100+
package1 = shipment.create_wsdl_object_of_type('FreightShipmentLineItem')
101+
package1.Weight = package1_weight
102+
package1.Packaging = 'PALLET'
103+
package1.Description = 'Products'
104+
package1.FreightClass = 'CLASS_500'
105+
package1.HazardousMaterials = None
106+
package1.Pieces = 12
107+
108+
109+
shipment.RequestedShipment.FreightShipmentDetail.LineItems = package1
110+
111+
# If you'd like to see some documentation on the ship service WSDL, un-comment
112+
# this line. (Spammy).
113+
#print shipment.client
114+
115+
# Un-comment this to see your complete, ready-to-send request as it stands
116+
# before it is actually sent. This is useful for seeing what values you can
117+
# change.
118+
#print shipment.RequestedShipment
119+
120+
# If you want to make sure that all of your entered details are valid, you
121+
# can call this and parse it just like you would via send_request(). If
122+
# shipment.response.HighestSeverity == "SUCCESS", your shipment is valid.
123+
#shipment.send_validation_request()
124+
125+
# Fires off the request, sets the 'response' attribute on the object.
126+
shipment.send_request()
127+
128+
# This will show the reply to your shipment being sent. You can access the
129+
# attributes through the response attribute on the request object. This is
130+
# good to un-comment to see the variables returned by the Fedex reply.
131+
print shipment.response
132+
# Here is the overall end result of the query.
133+
# print "HighestSeverity:", shipment.response.HighestSeverity
134+
# # Getting the tracking number from the new shipment.
135+
# print "Tracking #:", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds[0].TrackingNumber
136+
# # Net shipping costs.
137+
# print "Net Shipping Cost (US$):", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].PackageRating.PackageRateDetails[0].NetCharge.Amount
138+
139+
# # Get the label image in ASCII format from the reply. Note the list indices
140+
# we're using. You'll need to adjust or iterate through these if your shipment
141+
# has multiple packages.
142+
143+
ascii_label_data = shipment.response.CompletedShipmentDetail.ShipmentDocuments[0].Parts[0].Image
144+
145+
# Convert the ASCII data to binary.
146+
label_binary_data = binascii.a2b_base64(ascii_label_data)
147+
148+
"""
149+
This is an example of how to dump a label to a PNG file.
150+
"""
151+
# This will be the file we write the label out to.
152+
pdf_file = open('example_shipment_label.pdf', 'wb')
153+
pdf_file.write(label_binary_data)
154+
pdf_file.close()
155+
156+
"""
157+
This is an example of how to print the label to a serial printer. This will not
158+
work for all label printers, consult your printer's documentation for more
159+
details on what formats it can accept.
160+
"""
161+
# Pipe the binary directly to the label printer. Works under Linux
162+
# without requiring PySerial. This WILL NOT work on other platforms.
163+
#label_printer = open("/dev/ttyS0", "w")
164+
#label_printer.write(label_binary_data)
165+
#label_printer.close()
166+
167+
"""
168+
This is a potential cross-platform solution using pySerial. This has not been
169+
tested in a long time and may or may not work. For Windows, Mac, and other
170+
platforms, you may want to go this route.
171+
"""
172+
#import serial
173+
#label_printer = serial.Serial(0)
174+
#print "SELECTED SERIAL PORT: "+ label_printer.portstr
175+
#label_printer.write(label_binary_data)
176+
#label_printer.close()

examples/freight_rate_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
rate_request.RequestedShipment.FreightShipmentDetail.TotalHandlingUnits = 1
2929

30-
rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightAccountNumber = '510087020'
30+
rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightAccountNumber = 'xxxxxxxx' #freight account number
3131

3232
rate_request.RequestedShipment.Shipper.Address.PostalCode = '72601'
3333
rate_request.RequestedShipment.Shipper.Address.CountryCode = 'US'

fedex/services/ship_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ def _prepare_wsdl_objects(self):
7272

7373
Payor = self.client.factory.create('Payor')
7474
# Grab the account number from the FedexConfig object by default.
75-
Payor.ResponsibleParty.AccountNumber = self._config_obj.account_number
75+
Payor.ResponsibleParty.AccountNumber = 'xxxxxxxx' #freight account number!
7676
# Assume US.
7777
Payor.ResponsibleParty.Address.CountryCode = 'US'
7878

7979
ShippingChargesPayment = self.client.factory.create('Payment')
8080
ShippingChargesPayment.Payor = Payor
81+
ShippingChargesPayment.PaymentType = 'SENDER'
8182

8283
self.RequestedShipment.ShippingChargesPayment = ShippingChargesPayment
8384
self.RequestedShipment.LabelSpecification = self.client.factory.create('LabelSpecification')

0 commit comments

Comments
 (0)