jazminschroeder/fedex — pull request #40 by yevgenko (2013-08-30 22:57:28+00:00)
Title: Add support for shipping document service

Initial support for shipping document service

> FedEx Web Services can save you time and help optimize your shipping by creating many shipping documents for you. You will need to submit the required data elements in your Ship requests

Usage example `examples/ex1.rb`, generates commercial invoice:

require 'fedex'

# TODO: update with your credentials
fedex = Fedex::Shipment.new(
:key => '',
:password => '',
:account_number => '',
:meter => '',
:mode => 'development'
)

# United Kingdom
shipper = {
:name => "Sender",
:company => "Company",
:phone_number => "555-555-5555",
:address => "King Street",
:city => "Ashbourne",
:postal_code => "DE6 1EA",
:country_code => "GB"
}

# USA
recipient = {
:name => "Recipient",
:company => "Company",
:phone_number => "555-555-5555",
:address => "Main Street",
:city => "Franklin Park",
:state => "IL",
:postal_code => "60131",
:country_code => "US",
:residential => "true"
}

packages = []
packages << {
:weight => {:units => "LB", :value => 2},
}

customs = {
:duties_payment => {
:payment_type => 'SENDER',
:payor => {
:responsible_party => {
:account_number => '510087623',
:contact => {
:person_name => 'Mr. Test',
:phone_number => '12345678'
}
}
}
},
:document_content => 'NON_DOCUMENTS',
:customs_value => {
:currency => 'UKL', # UK Pounds Sterling
:amount => 155.79
},
:parties_to_transaction_are_related => false,
:commercial_invoice => {
:purpose => 'SOLD',
:terms_of_sale => 'DDU'
},
:commodities => [
{
:number_of_pieces => 1,
:description => 'Pink Toy',
:country_of_manufacture => 'GB',
:weight => {
:units => 'LB',
:value => 2
},
:quantity => 1,
:quantity_units => 'EA',
:unit_price => {
:currency => 'UKL',
:amount => 155.79
},
:customs_value => {
:currency => 'UKL', # UK Pounds Sterling
:amount => 155.79
}
}
]
}

shipment_docs = {
:shipping_document_types => ['COMMERCIAL_INVOICE'],
:commercial_invoice_detail => {
:format => {
:image_type => 'PDF',
:stock_type => 'PAPER_LETTER'
}
}
}

shipping_details = {
:packaging_type => "YOUR_PACKAGING",
:drop_off_type => "REGULAR_PICKUP"
}

document = fedex.document(
:shipper => shipper,
:recipient => recipient,
:packages => packages,
:service_type => "INTERNATIONAL_PRIORITY",
:shipping_details => shipping_details,
:customs_clearance => customs,
:shipping_document => shipment_docs,
:filenames => {
:label => 'label.pdf',
:commercial_invoice => 'invoice.pdf',
}
)

p document.tracking_number

# bundle exec examples/ex1.rb