oxidecomputer / cio

Rust libraries for APIs needed by our automated CIO.
Apache License 2.0
264 stars 42 forks source link

Shippo add parcel "extra" field for insurance rates. #283

Open defcronyke opened 1 year ago

defcronyke commented 1 year ago

Fixes #282

Add optional "extra" field to Parcel and Shipment structs, and create Extra and Insurance structs.

I wanted to be able to request shipping rates with insurance, so I added this "extra" field as an Option type.

Unfortunately Shippo will only add the insurance rates to the price for one carrier which you have to specify in the Parcel extra.provider field, and it only supports "UPS" or "FEDEX", so if your Shippo account has more than one carrier enabled and rates are returned from multiple carriers, the other carrier rates will be returned without any insurance amount added, which isn't ideal.

It's possible to request insurance rates from a different insurance company affiliated with Shippo, on the Shipment struct's "extra" field, however I'm not using this personally and not supporting it properly in this PR, because it needs a slightly different Insurance struct with the "amount" field being a String, and instead of the "provider" field, it needs a "content": String field.

Since I wanted to buy insurance from FedEx or UPS and not Shippo's provider, I didn't feel like properly supporting the "extra" field on the Shipment struct. It would be very easy to fix this though.

See for details: https://goshippo.com/docs/insurance/

augustuswm commented 1 year ago

Just to clarify on this, since I have not looked at how insurance is handled closely, can the provider field be an enum over Fedex, USPS, UDS instead of a string? (Insurance would not be able to derive Default, which it probably shouldn't have anyway)

Otherwise looks good to me.