七宝 API 集成:状态 returns 为 "ERROR" 即使 "VALID"

Shippo API Integration: Status returns as "ERROR" even if "VALID"

我已经在 Rails Spree 平台上将 Shippo 与我的 Ruby 集成。一切似乎都运行良好,除了当我去创建一个交易来打印运输标签时,我在响应中收到一个错误。

这是我的回复:

#<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".

如果需要,我很乐意 post 更多代码。谢谢。

经过反复试验,我发现我寄给七宝的产品实际上超过了承运商允许的包裹重量。 (这是因为我的数据库是一堆虚拟数据)。请务必在此处也设置您的测量单位:

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

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