Shippo API集成:即使“有效”,状态也会返回“错误”

时间:2017-06-27 23:27:30

标签: ruby-on-rails ruby spree shippo

我已经将Shippo与我的Ruby on Rails Spree平台集成在一起。一切似乎都很好,除了当我创建一个打印运输标签的交易时,我在回复中收到错误。

以下是我的回复:

#<Transaction:0x3feee363470c[id=1b419434531e4b43b438c54b93e2a9f5] {"object_state"=>"VALID", "status"=>"ERROR", "object_created"=>"2017-06-27T23:11:54.567Z", "object_updated"=>"2017-06-27T23:11:55.330Z", "object_id"=>"xxxx", "object_owner"=>"----@gmail.com", "test"=>true, "rate"=>{"object_id"=>"xxxx", "amount"=>"6.52", "currency"=>"USD", "amount_local"=>"6.52", "currency_local"=>"USD", "provider"=>"USPS", "servicelevel_name"=>"Priority Mail", "servicelevel_token"=>"usps_priority", "carrier_account"=>"xxxx"}, "tracking_number"=>"", "tracking_status"=>nil, "tracking_history"=>[], "tracking_url_provider"=>"", "label_url"=>"", "commercial_invoice_url"=>nil, "messages"=>[#<Hashie::Mash code="" source="USPS" text="Request failed. Please try again or contact Shippo support at support@goshippo.com.">], "order"=>nil, "metadata"=>"", "parcel"=>"xxxx"}->#<Shippo::API::ApiObject created=2017-06-27 23:11:54 UTC id="1b419434531e4b43b438c54b93e2a9f5" owner="xxxx@xxxx.com" state=#<Shippo::API::Category::State:0x007fddbca5a2e8 @name=:state, @value=:valid> updated=2017-06-27 23:11:55 UTC>

以下是用于创建标签的代码:

def self.createLabel(order_info)
    shipping_info = order_info.shipping_address
    stock_location = order_info.store.stock_location

address_from = {
  :name => stock_location.name,
  :company => order_info.store.name,
  :street1 => stock_location.address1,
  :street2 => stock_location.address2,
  :city => stock_location.city,
  :state => "#{Spree::State.find(stock_location.state_id)}",
  :zip => stock_location.zipcode,
  :country => "#{Spree::Country.find(stock_location.country_id)}",
  :phone => stock_location.phone,
}

address_to = {
    :name => "#{shipping_info.firstname} #{shipping_info.lastname}",
    :company => shipping_info.company,
    :street1 => shipping_info.address1,
    :street2 => shipping_info.address2,
    :city => shipping_info.city,
    :state => "#{Spree::State.find(shipping_info.state_id)}",
    :zip => shipping_info.zipcode,
    :country => "#{Spree::Country.find(shipping_info.country_id)}",
    :phone => shipping_info.phone,
    :email => order_info.email
}
parcel = {
    :length => getLength(order_info),
    :width => getWidth(order_info),
    :height => getHeight(order_info),
    :distance_unit => :m,
    :weight => getWeight(order_info),
    :mass_unit => :lb
}

shipment = {
    :address_from => address_from,
    :address_to => address_to,
    :parcels => parcel
}

#Shippo Carrier ids
@ups = Rails.application.secrets.ups_shippo_id
@usps = Rails.application.secrets.usps_shippo_id
transaction = Shippo::Transaction.create(
    :shipment => shipment,
    :carrier_account => "#{@usps}",
    :servicelevel_token => "usps_priority",
    :label_file_type => "PDF",
    :async => false
)
end

之前是否有人遇到此问题?我查看了他们的文档,在"status"=>"ERROR"时无法找到"object_state"=>"VALID"消息的任何原因。

如果需要,我很乐意发布更多代码。感谢。

1 个答案:

答案 0 :(得分:0)

我通过大量试验和错误发现,我发送给Shippo的产品实际上超过了运输公司在包装中允许的重量。 (这是因为我的数据库是一堆虚拟数据)。请务必同时设置您的测量单位:

    parcel = {
      :length => getLength(order_info),
      :width => getWidth(order_info),
      :height => getHeight(order_info),
      :distance_unit => :m,
      :weight => getWeight(order_info),
      :mass_unit => :lb
    }

更改数据库中的数据以使产品具有合理的权重后,此错误就消失了。