1

我已将 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".

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

4

1 回答 1

0

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

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

在更改我的数据库中的数据以对产品具有合理的权重后,这个错误就消失了。

于 2017-07-29T13:46:27.437 回答