我已经将Shippo与我的Rails狂欢平台集成在一起了。一切看起来都很好,除了当我去创建一个事务来打印运输标签时,我在响应中出现了一个错误。
以下是我的回应:
#<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"出现时。
如果需要,我很乐意发布更多的代码。谢谢。
发布于 2017-07-29 13:46:27
我发现了大量的尝试和错误,我发送给Shippo的产品实际上超过了运输公司在包裹中允许的重量。(这是因为我的数据库是一堆假数据)。一定要设置您的测量单位,在这里:
parcel = {
:length => getLength(order_info),
:width => getWidth(order_info),
:height => getHeight(order_info),
:distance_unit => :m,
:weight => getWeight(order_info),
:mass_unit => :lb
}在更改数据库中的数据以使产品具有合理的权重之后,这个错误就消失了。
https://stackoverflow.com/questions/44791472
复制相似问题