|
19 | 19 | use_test_server=True) |
20 | 20 |
|
21 | 21 | # This is the object that will be handling our tracking request. |
22 | | -ship = FedexProcessShipmentRequest(config_obj) |
| 22 | +shipment = FedexProcessShipmentRequest(config_obj) |
23 | 23 |
|
24 | 24 | # This is very generalized, top-level information. |
25 | 25 | # REGULAR_PICKUP, REQUEST_COURIER, DROP_BOX, BUSINESS_SERVICE_CENTER or STATION |
26 | | -ship.RequestedShipment.DropoffType = 'REGULAR_PICKUP' |
| 26 | +shipment.RequestedShipment.DropoffType = 'REGULAR_PICKUP' |
27 | 27 |
|
28 | 28 | # See page 355 in WS_ShipService.pdf for a full list. Here are the common ones: |
29 | 29 | # STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, FEDEX_EXPRESS_SAVER |
30 | | -ship.RequestedShipment.ServiceType = 'PRIORITY_OVERNIGHT' |
| 30 | +shipment.RequestedShipment.ServiceType = 'PRIORITY_OVERNIGHT' |
31 | 31 |
|
32 | 32 | # What kind of package this will be shipped in. |
33 | 33 | # FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING |
34 | | -ship.RequestedShipment.PackagingType = 'FEDEX_PAK' |
| 34 | +shipment.RequestedShipment.PackagingType = 'FEDEX_PAK' |
35 | 35 |
|
36 | 36 | # No idea what this is. |
37 | 37 | # INDIVIDUAL_PACKAGES, PACKAGE_GROUPS, PACKAGE_SUMMARY |
38 | | -ship.RequestedShipment.PackageDetail = 'INDIVIDUAL_PACKAGES' |
| 38 | +shipment.RequestedShipment.PackageDetail = 'INDIVIDUAL_PACKAGES' |
39 | 39 |
|
40 | 40 | # Shipper contact info. |
41 | | -ship.ShipperContact.PersonName = 'Sender Name' |
42 | | -ship.ShipperContact.CompanyName = 'Some Company' |
43 | | -ship.ShipperContact.PhoneNumber = '9012638716' |
| 41 | +shipment.ShipperContact.PersonName = 'Sender Name' |
| 42 | +shipment.ShipperContact.CompanyName = 'Some Company' |
| 43 | +shipment.ShipperContact.PhoneNumber = '9012638716' |
44 | 44 |
|
45 | 45 | # Shipper address. |
46 | | -ship.ShipperAddress.StreetLines = ['Address Line 1'] |
47 | | -ship.ShipperAddress.City = 'Herndon' |
48 | | -ship.ShipperAddress.StateOrProvinceCode = 'VA' |
49 | | -ship.ShipperAddress.PostalCode = '20171' |
50 | | -ship.ShipperAddress.CountryCode = 'US' |
51 | | -ship.ShipperAddress.Residential = True |
| 46 | +shipment.ShipperAddress.StreetLines = ['Address Line 1'] |
| 47 | +shipment.ShipperAddress.City = 'Herndon' |
| 48 | +shipment.ShipperAddress.StateOrProvinceCode = 'VA' |
| 49 | +shipment.ShipperAddress.PostalCode = '20171' |
| 50 | +shipment.ShipperAddress.CountryCode = 'US' |
| 51 | +shipment.ShipperAddress.Residential = True |
52 | 52 |
|
53 | 53 | # Recipient contact info. |
54 | | -ship.RecipientContact.PersonName = 'Recipient Name' |
55 | | -ship.RecipientContact.CompanyName = 'Recipient Company' |
56 | | -ship.RecipientContact.PhoneNumber = '9012637906' |
| 54 | +shipment.RecipientContact.PersonName = 'Recipient Name' |
| 55 | +shipment.RecipientContact.CompanyName = 'Recipient Company' |
| 56 | +shipment.RecipientContact.PhoneNumber = '9012637906' |
57 | 57 |
|
58 | 58 | # Recipient address |
59 | | -ship.RecipientAddress.StreetLines = ['Address Line 1'] |
60 | | -ship.RecipientAddress.City = 'Herndon' |
61 | | -ship.RecipientAddress.StateOrProvinceCode = 'VA' |
62 | | -ship.RecipientAddress.PostalCode = '20171' |
63 | | -ship.RecipientAddress.CountryCode = 'US' |
| 59 | +shipment.RecipientAddress.StreetLines = ['Address Line 1'] |
| 60 | +shipment.RecipientAddress.City = 'Herndon' |
| 61 | +shipment.RecipientAddress.StateOrProvinceCode = 'VA' |
| 62 | +shipment.RecipientAddress.PostalCode = '20171' |
| 63 | +shipment.RecipientAddress.CountryCode = 'US' |
64 | 64 | # This is needed to ensure an accurate rate quote with the response. |
65 | | -ship.RecipientAddress.Residential = True |
| 65 | +shipment.RecipientAddress.Residential = True |
66 | 66 |
|
67 | 67 | # RECIPIENT, SENDER or THIRD_PARTY |
68 | | -ship.ShippingChargesPayment.PaymentType = 'SENDER' |
| 68 | +shipment.ShippingChargesPayment.PaymentType = 'SENDER' |
69 | 69 |
|
70 | 70 | # These are example label values. You'll want to adjust these to fit your |
71 | 71 | # usage case. |
72 | | -ship.LabelSpecification.LabelFormatType = 'COMMON2D' |
73 | | -ship.LabelSpecification.ImageType = 'PNG' |
74 | | -ship.LabelSpecification.LabelStockType = 'PAPER_7X4.75' |
| 72 | +shipment.LabelSpecification.LabelFormatType = 'COMMON2D' |
| 73 | +shipment.LabelSpecification.ImageType = 'PNG' |
| 74 | +shipment.LabelSpecification.LabelStockType = 'PAPER_7X4.75' |
75 | 75 |
|
76 | | -package1_weight = ship.create_wsdl_object_of_type('Weight') |
| 76 | +package1_weight = shipment.create_wsdl_object_of_type('Weight') |
77 | 77 | # Weight, in pounds. |
78 | 78 | package1_weight.Value = 1.0 |
79 | 79 | package1_weight.Units = "LB" |
80 | 80 |
|
81 | | -package1 = ship.create_wsdl_object_of_type('RequestedPackageLineItem') |
| 81 | +package1 = shipment.create_wsdl_object_of_type('RequestedPackageLineItem') |
82 | 82 | package1.Weight = package1_weight |
83 | 83 | #print package1 |
84 | 84 |
|
85 | | -ship.add_package(package1) |
| 85 | +shipment.add_package(package1) |
86 | 86 |
|
87 | 87 | # If you'd like to see some documentation on the ship service WSDL, un-comment |
88 | 88 | # this line. (Spammy). |
89 | | -#print ship.client |
| 89 | +#print shipment.client |
90 | 90 |
|
91 | 91 | # Un-comment this to see your complete, ready-to-send request as it stands |
92 | 92 | # before it is actually sent. This is useful for seeing what values you can |
93 | 93 | # change. |
94 | | -#print ship.RequestedShipment |
| 94 | +#print shipment.RequestedShipment |
95 | 95 |
|
96 | 96 | # Fires off the request, sets the 'response' attribute on the object. |
97 | | -ship.send_request() |
| 97 | +shipment.send_request() |
98 | 98 |
|
99 | 99 | # This will show the reply to your shipment being sent. You can access the |
100 | | -# attributes through the response attribute on the request object. |
101 | | -print ship.response |
| 100 | +# attributes through the response attribute on the request object. This is |
| 101 | +# good to un-comment to see the variables returned by the Fedex reply. |
| 102 | +#print shipment.response |
| 103 | + |
| 104 | +# Here is the overall end result of the query. |
| 105 | +print "HighestSeverity:", shipment.response.HighestSeverity |
| 106 | +# Getting the tracking number from the new shipment. |
| 107 | +print "Tracking #:", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds[0].TrackingNumber |
| 108 | +# Net shipping costs. |
| 109 | +print "Net Shipping Cost (US$):", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].PackageRating.PackageRateDetails[0].NetCharge.Amount |
102 | 110 |
|
103 | 111 | # Get the label image in ASCII format from the reply. Note the list indices |
104 | 112 | # we're using. You'll need to adjust or iterate through these if your shipment |
105 | 113 | # has multiple packages. |
106 | | -ascii_label_data = ship.response.CompletedShipmentDetail.CompletedPackageDetails[0].Label.Parts[0].Image |
| 114 | +ascii_label_data = shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].Label.Parts[0].Image |
107 | 115 | # Convert the ASCII data to binary. |
108 | 116 | label_binary_data = binascii.a2b_base64(ascii_label_data) |
109 | 117 |
|
|
0 commit comments