jazminschroeder / fedex

Ruby library to interact with FedEx Rate Web Service
105 stars 179 forks source link

Customs Value is required error on create shipment #135

Open ReinierKorth opened 5 years ago

ReinierKorth commented 5 years ago

Hi,

When I try to create an international shipment i get a "Customs Value is required" error.

Is there a way to declare the value of the shipment? Setting insured_value on the package didn't work.

Thank you,

Reinier

MatinF commented 5 years ago

I have the same issue. Below is my code if anyone else takes a stab at this.

It seems like the rate calculation works as per the example in the Wiki - but I'm not able to get the shipment to work. Any inputs would be great! @jazminschroeder If you have any inputs it would be greatly appreciated :-)

require 'fedex'

fedex = Fedex::Shipment.new(: key => '***',: password => '***',: account_number => '***',: meter => '***',: mode => 'development')

shipper = {
  : name => "Shipper Name",
  : company => "Shipper Company",
  : phone_number => "12345678",
  : address => "Shipper Address",
  : city => "Shipper City",
  : postal_code => "8230",
  : country_code => "DK"
}

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

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

canadian_recipient = {
  : name => "Recipient",
  : company => "Company",
  : phone_number => "555-555-5555",
  : address => "Address Line 1",
  : city => "Richmond",
  : state => "BC",
  : postal_code => "V7C4V4",
  : country_code => "CA",
  : residential => "true"
}

broker = {
  : account_number => "510087143",
  : tins => {
    : tin_type => "BUSINESS_NATIONAL",: number => "431870271",: usage => "Usage"
  },
  : contact => {
    : contact_id => "1",: person_name => "Broker Name",: title => "Broker",: company_name => "Broker One",: phone_number => "555-555-5555",: phone_extension => "555-555-5555",: pager_number => "555",: fax_number => "555-555-5555",: e_mail_address => "contact@me.com"
  },
  : address => {
    : street_lines => "Main Street",: city => "Franklin Park",: state_or_province_code => 'IL',: postal_code => '60131',: urbanization_code => '123',: country_code => 'US',: residential => 'false'
  }
}

clearance_brokerage = "BROKER_INCLUSIVE"

importer_of_record = {
  : account_number => "22222",
  : tins => {
    : tin_type => "BUSINESS_NATIONAL",: number => "22222",: usage => "Usage"
  },
  : contact => {
    : contact_id => "1",: person_name => "Importer Name",: title => "Importer",: company_name => "Importer One",: phone_number => "555-555-5555",: phone_extension => "555-555-5555",: pager_number => "555",: fax_number => "555-555-5555",: e_mail_address => "contact@me.com"
  },
  : address => {
    : street_lines => "Main Street",: city => "Chicago",: state_or_province_code => 'IL',: postal_code => '60611',: urbanization_code => '2308',: country_code => 'US',: residential => 'false'
  }
}

recipient_customs_id = {
  : type => 'COMPANY',
  : value => '1254587'
}

duties_payment = {
  : payment_type => "SENDER",
  : payor => {
    : account_number => "510087143",: country_code => "US"
  }
}

customs_value = {
  : currency => "USD",
  : amount => "200"
}
commodities = []
commodities << {
  : name => "Cotton Coat",
  : number_of_pieces => "2",
  : description => "Cotton Coat",
  : country_of_manufacture => "US",
  : harmonized_code => "6103320000",
  : weight => {
    : units => "LB",: value => "2"
  },
  : quantity => "3",
  : unit_price => {
    : currency => "USD",: amount => "50"
  },
  : customs_value => {
    : currency => "USD",: amount => "150"
  }
}

commodities << {
  : name => "Poster",
  : number_of_pieces => "1",
  : description => "Paper Poster",
  : country_of_manufacture => "US",
  : harmonized_code => "4817100000",
  : weight => {
    : units => "LB",: value => "0.2"
  },
  : quantity => "3",
  : unit_price => {
    : currency => "USD",: amount => "50"
  },
  : customs_value => {
    : currency => "USD",: amount => "150"
  }
}

customs_clearance = {
  : broker => broker,
  : clearance_brokerage => clearance_brokerage,
  : importer_of_record => importer_of_record,
  : recipient_customs_id => recipient_customs_id,
  : duties_payment => duties_payment,
  : customs_value => customs_value,
  : commodities => commodities
}

# the rate calculations seems to work as per the example
rate = fedex.rate({
  : shipper => shipper,
  : recipient => canadian_recipient,
  : packages => packages,
  : service_type => "INTERNATIONAL_PRIORITY",
  : customs_clearance => customs_clearance
})

#
ship = fedex.ship(: shipper => shipper,: recipient => canadian_recipient,: packages => packages,: service_type => "INTERNATIONAL_PRIORITY",: customs_clearance => customs_clearance,: shipping_options => shipping_options)
puts ship[: completed_shipment_detail][: operational_detail][: transit_time]