|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +This module prints a label used to certify International Priority shipments. |
| 4 | +""" |
| 5 | +import logging |
| 6 | +from cert_config import CONFIG_OBJ |
| 7 | +from fedex.services.ship_service import FedexProcessShipmentRequest |
| 8 | +from fedex.printers.unix import DirectDevicePrinter |
| 9 | + |
| 10 | +logging.basicConfig(level=logging.INFO) |
| 11 | + |
| 12 | +shipment = FedexProcessShipmentRequest(CONFIG_OBJ) |
| 13 | +shipment.RequestedShipment.DropoffType = 'REGULAR_PICKUP' |
| 14 | +shipment.RequestedShipment.ServiceType = 'INTERNATIONAL_PRIORITY' |
| 15 | +shipment.RequestedShipment.PackagingType = 'YOUR_PACKAGING' |
| 16 | +shipment.RequestedShipment.PackageDetail = 'INDIVIDUAL_PACKAGES' |
| 17 | + |
| 18 | +# Shipper contact info. |
| 19 | +shipment.RequestedShipment.Shipper.Contact.PersonName = 'Gregory Taylor' |
| 20 | +shipment.RequestedShipment.Shipper.Contact.CompanyName = 'International Paper' |
| 21 | +shipment.RequestedShipment.Shipper.Contact.PhoneNumber = '8646336010' |
| 22 | + |
| 23 | +# Shipper address. |
| 24 | +shipment.RequestedShipment.Shipper.Address.StreetLines = ['155 Old Greenville Hwy', |
| 25 | + 'Suite 103'] |
| 26 | +shipment.RequestedShipment.Shipper.Address.City = 'Clemson' |
| 27 | +shipment.RequestedShipment.Shipper.Address.StateOrProvinceCode = 'SC' |
| 28 | +shipment.RequestedShipment.Shipper.Address.PostalCode = '29631' |
| 29 | +shipment.RequestedShipment.Shipper.Address.CountryCode = 'US' |
| 30 | +shipment.RequestedShipment.Shipper.Address.Residential = False |
| 31 | + |
| 32 | +# Recipient contact info. |
| 33 | +shipment.RequestedShipment.Recipient.Contact.PersonName = 'Some Guy' |
| 34 | +#shipment.RequestedShipment.Recipient.Contact.CompanyName = 'Recipient Company' |
| 35 | +shipment.RequestedShipment.Recipient.Contact.PhoneNumber = '8646336010' |
| 36 | + |
| 37 | +# Recipient address |
| 38 | +shipment.RequestedShipment.Recipient.Address.StreetLines = ['77 Foo Young'] |
| 39 | +shipment.RequestedShipment.Recipient.Address.City = 'Taipei' |
| 40 | +shipment.RequestedShipment.Recipient.Address.PostalCode = '115' |
| 41 | +shipment.RequestedShipment.Recipient.Address.CountryCode = 'TW' |
| 42 | + |
| 43 | +shipment.RequestedShipment.ShippingChargesPayment.PaymentType = 'SENDER' |
| 44 | + |
| 45 | +# Specifies the label type to be returned. |
| 46 | +# LABEL_DATA_ONLY or COMMON2D |
| 47 | +shipment.RequestedShipment.LabelSpecification.LabelFormatType = 'COMMON2D' |
| 48 | + |
| 49 | +# Specifies which format the label file will be sent to you in. |
| 50 | +# DPL, EPL2, PDF, PNG, ZPLII |
| 51 | +shipment.RequestedShipment.LabelSpecification.ImageType = 'EPL2' |
| 52 | + |
| 53 | +# To use doctab stocks, you must change ImageType above to one of the |
| 54 | +# label printer formats (ZPLII, EPL2, DPL). |
| 55 | +# See documentation for paper types, there quite a few. |
| 56 | +shipment.RequestedShipment.LabelSpecification.LabelStockType = 'STOCK_4X6.75_LEADING_DOC_TAB' |
| 57 | + |
| 58 | +# This indicates if the top or bottom of the label comes out of the |
| 59 | +# printer first. |
| 60 | +# BOTTOM_EDGE_OF_TEXT_FIRST or TOP_EDGE_OF_TEXT_FIRST |
| 61 | +shipment.RequestedShipment.LabelSpecification.LabelPrintingOrientation = 'BOTTOM_EDGE_OF_TEXT_FIRST' |
| 62 | + |
| 63 | +package1_weight = shipment.create_wsdl_object_of_type('Weight') |
| 64 | +package1_weight.Value = 10.0 |
| 65 | +package1_weight.Units = "LB" |
| 66 | + |
| 67 | +package1 = shipment.create_wsdl_object_of_type('RequestedPackageLineItem') |
| 68 | +package1.Weight = package1_weight |
| 69 | + |
| 70 | +shipment.add_package(package1) |
| 71 | + |
| 72 | +shipment.RequestedShipment.InternationalDetail.DocumentContent = "NON_DOCUMENTS" |
| 73 | +shipment.RequestedShipment.InternationalDetail.CustomsValue.Currency = "USD" |
| 74 | +shipment.RequestedShipment.InternationalDetail.CustomsValue.Amount = "10.00" |
| 75 | + |
| 76 | +commod = shipment.create_wsdl_object_of_type('Commodity') |
| 77 | +commod.NumberOfPieces = "1" |
| 78 | +commod.Description = "Technical Book" |
| 79 | +commod.CountryOfManufacture = "US" |
| 80 | +commod.Weight.Units = "LB" |
| 81 | +commod.Weight.Value = "5.0" |
| 82 | +commod.Quantity = "1" |
| 83 | +commod.QuantityUnits = "EA" |
| 84 | +commod.UnitPrice.Currency = "USD" |
| 85 | +commod.UnitPrice.Amount = "10.00" |
| 86 | +shipment.RequestedShipment.InternationalDetail.Commodities.append(commod) |
| 87 | + |
| 88 | +shipment.RequestedShipment.InternationalDetail.DutiesPayment.PaymentType = "SENDER" |
| 89 | +shipment.RequestedShipment.InternationalDetail.DutiesPayment.Payor.AccountNumber = CONFIG_OBJ.account_number |
| 90 | +shipment.RequestedShipment.InternationalDetail.DutiesPayment.Payor.CountryCode = "US" |
| 91 | + |
| 92 | +shipment.send_request() |
| 93 | + |
| 94 | +print shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds |
| 95 | + |
| 96 | +device = DirectDevicePrinter(shipment) |
| 97 | +device.print_label() |
0 commit comments