From d313da9ba26060b51455328c617d885ba851f9cf Mon Sep 17 00:00:00 2001 From: Jeremy Carter Date: Sat, 19 Nov 2022 04:42:54 -0500 Subject: [PATCH] Shippo add "extra" field to Shipment and Parcel. Fixes #282 Support getting Shippo shipping rates with shipping insurance included: https://goshippo.com/docs/insurance/ It's supported through a field named "extra" that's missing in Shipment for single parcel shipments, and for multiple parcel shipments it's supported in an "extra" field on Parcel. Add Extra and Insurance structs. --- shippo/src/lib.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/shippo/src/lib.rs b/shippo/src/lib.rs index f717325bc..5576ce1bd 100644 --- a/shippo/src/lib.rs +++ b/shippo/src/lib.rs @@ -652,6 +652,9 @@ pub struct Shipment { /// Indicates whether the object has been created in test mode. #[serde(default)] pub test: bool, + /// Add extra options to the parcel request, such as shipping insurance. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub extra: Option, } /// The data type for a carrier account. @@ -835,6 +838,39 @@ pub struct Parcel { /// Indicates whether the object has been created in test mode. #[serde(default)] pub test: bool, + /// Add extra options to the parcel request, such as shipping insurance. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub extra: Option, +} + +/// The data type for extra Parcel or Shipment features, such as requesting +/// insurance rates. +#[derive(Clone, Debug, Default, Serialize, Deserialize)] +pub struct Extra { + /// Add extra insurance to the parcel or shipment. + /// If there's more than one parcel in the shipment, + /// you have to request insurance per-parcel on the + /// Parcel struct, otherwise, you can request it on + /// the Shipment struct instead. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub insurance: Option, +} + +/// The data type for requesting shipping rates with extra insurance. +/// FROM: https://goshippo.com/docs/insurance/ +#[derive(Clone, Debug, Default, Serialize, Deserialize)] +pub struct Insurance { + /// The value of the parcel or shipment to insure. + #[serde(default, skip_serializing_if = "String::is_empty")] + pub amount: String, + /// The currency to use for the previous amount value. + /// "USD" | "CAD", etc. + #[serde(default, skip_serializing_if = "String::is_empty")] + pub currency: String, + /// A short description of the contents of the parcel or shipment. + /// "5 t-shirts" + #[serde(default, skip_serializing_if = "String::is_empty")] + pub content: String, } /// The data type for a rate.