uber_api/models/create_delivery/
create_delivery.rs

1use serde::{Deserialize, Serialize};
2use reqwest::StatusCode;
3
4
5use crate::models::general::{
6    LocalDateTime,
7    ManifestItem,
8    VerificationRequirement,
9    TestSpecifications,
10    CourierInfo,
11    WaypointInfo,
12    ManifestInfo,
13    RelatedDelivery,
14    StructuredAddress
15};
16/// # Request Body Parameters
17///
18/// | Name | Type | Description |
19/// | :--- | :--- | :--- |
20/// | dropoff_address | string - Structured Address | (required) For single string, format is : "Street Address, City, State, Zip" |
21/// | dropoff_name | string | (required) Name of the place where the courier will make the dropoff. |
22/// | dropoff_phone_number | string | (required) The phone number of the dropoff location. |
23/// | manifest | string | (required) [SOON TO BE DEPRECATED] 'manifest_items` should be used instead. |
24/// | manifest_items | Manifestltem[] | (required) List of items being delivered. |
25/// | pickup_address | string | (required) Pickup address in Street Address, City, State, Zip format. |
26/// | pickup_name | string | (required) Name of the place where the courier will make the pickup. |
27/// | pickup_phone_number | string | (required) Name of the place where the courier will make the pickup. |
28/// | deliverable_action | DeliverableAction | Specify the "happy path" action for the courier to take on a delivery. When used, delivery action can be set to "leave at door" for a contactless delivery. Cannot leave at door when signature or ID verification requirements are applied when creating a delivery. Photo confirmation of delivery will be automatically applied as a requirement to complete dropoff. |
29/// | dropoff_business_name | string | Business name of the dropoff location. |
30/// | dropoff_latitude | double | Dropoff latitude coordinate. |
31/// | dropoff_longitude | double | Dropoff longitude coordinate. |
32/// | dropoff_notes | string | Additional instructions for the courier at the dropoff location. Max 280 characters. |
33/// | dropoff_seller_notes | string | Additional instructions provided by the merchant for the dropoff. Max 280 characters. |
34/// | dropoff_verification | VerificationRequirement | Verification steps (i.e. barcode scanning) that must be taken before the dropoff can be completed. |
35/// | manifest_reference | string | Reference that identifies the manifest. Use this to connect a delivery to corresponding information in your system. |
36/// | manifest_total_value | integer | Value (in US cents) of the items in the delivery. i.e.: $10.99=>1099. |
37/// | pickup_business_name | string | Business name of the pickup location. |
38/// | pickup_latitude | double | Pickup latitude coordinate. |
39/// | pickup_longitude | double | Pickup longitude coordinate. |
40/// | pickup_notes | string | Additional instructions for the courier at the pickup location. Max 280 characters. |
41/// | pickup_verification | VerificationRequirement | Verification steps (i.e. barcode scanning) that must be taken before the pickup can be completed. |
42/// | quote_id | string | The ID of a previously generated delivery quote. |
43/// | undeliverable_action | UndeliverableAction | Specify the "unhappy path" action for the courier to take on a delivery once a normal delivery attempt is made and a customer is not available. |
44/// | pickup_ready_dt | timestamp (RFC 3339) | Beginning of the window when an order must be picked up. Must be less than 30 days in the future. |
45/// | pickup_deadline_dt | timestamp (RFC 3339) | End of the window when an order may be picked up. Must be at least 10 mins later than pickup_ready_dt and at least 20 minutes in the future from now. |
46/// | dropoff_ready_dt | timestamp (RFC 3339) | Beginning of the window when an order must be dropped off. Must be less than or equal to pickup_deadline_dt . |
47/// | dropoff_deadline_dt | timestamp (RFC 3339) | End of the window when an order must be dropped off. Must be at least 20 mins later than dropoff_ready_dt and must be greater than or equal to pickup_deadline_dt. |
48/// | requires_dropoff_signature | boolean | [DEPRECATED] Flag to indicate this delivery requires signature capture at dropoff. |
49/// | requires_id | boolean | Flag to indicate this delivery requires ID check (minimum age) at dropoff |
50/// | tip | integer | Upfront tip amount. 0.01 of the national currency (cents in US or $0.01 ) |
51/// | idempotency_key | string | A key which is used to avoid duplicate order creation with identical idempotency keys for the same account. The key persists for a set time frame, defaulting to 6 hours |
52/// | external_store_id | string | (Optional) Unique identifier used by our Partners to reference a Store or Location |
53/// | return_verification | VerificationRequirement | Verification steps (barcode scanning, picture, or signature) that must be taken before the return can be completed. |
54///
55#[derive(Serialize, Debug, Default)]
56#[serde(rename_all = "snake_case")]
57pub struct CreateDeliveryRequest {
58    pub dropoff_address: String, // StructuredAddress then serde_json::to_string(&dropoff_address).unwrap()
59    pub dropoff_name: String,
60    pub dropoff_phone_number: String,
61    pub manifest_items: Vec<ManifestItem>,
62    pub pickup_address: String,
63    pub pickup_name: String,
64    pub pickup_phone_number: String,
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub deliverable_action: Option<String>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub dropoff_business_name: Option<String>,
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub dropoff_latitude: Option<f64>,
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub dropoff_longitude: Option<f64>,
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub dropoff_notes: Option<String>,
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub dropoff_seller_notes: Option<String>,
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub dropoff_verification: Option<VerificationRequirement>,
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub manifest_reference: Option<String>,
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub manifest_total_value: Option<i64>,
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub pickup_business_name: Option<String>,
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub pickup_latitude: Option<f64>,
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub pickup_longitude: Option<f64>,
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub pickup_notes: Option<String>,
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub pickup_verification: Option<VerificationRequirement>,
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub quote_id: Option<String>,
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub undeliverable_action: Option<String>,
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub pickup_ready_dt: Option<LocalDateTime>,
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub pickup_deadline_dt: Option<LocalDateTime>,
101    #[serde(skip_serializing_if = "Option::is_none")]
102    pub dropoff_ready_dt: Option<LocalDateTime>,
103    #[serde(skip_serializing_if = "Option::is_none")]
104    pub dropoff_deadline_dt: Option<LocalDateTime>,
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub tip: Option<u32>,
107    #[serde(skip_serializing_if = "Option::is_none")]
108    pub external_store_id: Option<String>,
109    #[serde(skip_serializing_if = "Option::is_none")]
110    pub return_verification: Option<VerificationRequirement>,
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub test_specifications: Option<TestSpecifications>,
113}
114
115#[derive(Deserialize, Debug)]
116#[serde(rename_all = "snake_case")]
117pub struct CreateDeliveryResponse {
118    pub complete: Option<bool>,
119    pub courier: Option<CourierInfo>,
120    pub courier_imminent: Option<bool>,
121    pub created: Option<LocalDateTime>,
122    pub currency: Option<String>,
123    pub dropoff: Option<WaypointInfo>,
124    pub dropoff_deadline: Option<LocalDateTime>,
125    pub dropoff_eta: Option<LocalDateTime>,
126    pub dropoff_identifier: Option<String>,
127    pub dropoff_ready: Option<LocalDateTime>,
128    pub external_id: Option<String>,
129    pub fee: Option<u32>,
130    pub id: Option<String>,
131    pub kind: Option<String>,
132    pub live_mode: Option<bool>,
133    pub manifest: Option<ManifestInfo>,
134    pub manifest_items:	Option<Vec<ManifestItem>>,
135    pub pickup:	Option<WaypointInfo>,
136    pub pickup_deadline: Option<LocalDateTime>,
137    pub pickup_eta: Option<LocalDateTime>,
138    pub pickup_ready: Option<LocalDateTime>,
139    pub quote_id: Option<String>,
140    pub related_deliveries: Option<Vec<RelatedDelivery>>,
141    pub status: Option<String>,
142    pub tip: Option<u32>,
143    pub tracking_url: Option<String>,
144    pub undeliverable_action: Option<String>,
145    pub undeliverable_reason: Option<String>,
146    pub updated: Option<LocalDateTime>,
147    pub uuid: Option<String>,
148    #[serde(rename = "return")]
149    pub return_waypoint: Option<WaypointInfo>,
150}
151
152pub fn convert_status_to_message_create(status: StatusCode) -> String {
153    match status {
154        StatusCode::OK => String::from("Success!"),
155        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("duplicate_delivery") => String::from("An active delivery like this already exists. A pointer to the other delivery is provided."),
156        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("invalid_params") => String::from("The parameters of your request were invalid."),
157        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("unknown_location") => String::from("The specified location was not understood."),
158        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("address_undeliverable") => String::from("The specified location is not in a deliverable area."),
159        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("expired_quote") => String::from("The price quote specified has expired."),
160        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("used_quote") => String::from("The price quote specified has already been used."),
161        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("mismatched_price_quote") => String::from("The price quote specified doesn’t match the delivery."),
162        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("missing_payment") => String::from("Your account’s payment information has not been provided."),
163        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("pickup_ready_time_not_specified") => String::from("Pickup ready time must be specified when passing in pickup/dropoff windows."),
164        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("pickup_window_too_small") => String::from("The pickup window needs to be at least 10 minutes long."),
165        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("dropoff_deadline_too_early") => String::from("The dropoff deadline needs to be at least 20 minutes after the dropoff ready time."),
166        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("dropoff_deadline_before_pickup_deadline") => String::from("The dropoff deadline needs to be after the pickup deadline."),
167        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("dropoff_ready_after_pickup_deadline") => String::from("The dropoff ready time needs to be at or before the pickup deadline."),
168        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("pickup_ready_too_early") => String::from("The pickup ready time cannot be in the past."),
169        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("pickup_deadline_too_early") => String::from("The pickup deadline time needs to be at least 20 minutes from now."),
170        StatusCode::BAD_REQUEST if status.canonical_reason().unwrap_or("").contains("pickup_ready_too_late") => String::from("The pickup ready time needs to be within the next 30 days."),
171        StatusCode::PAYMENT_REQUIRED if status.canonical_reason().unwrap_or("").contains("customer_suspended") => String::from("Your account is passed due. Payment is required."),
172        StatusCode::FORBIDDEN if status.canonical_reason().unwrap_or("").contains("customer_blocked") => String::from("Your account is not allowed to create deliveries."),
173        StatusCode::UNPROCESSABLE_ENTITY if status.canonical_reason().unwrap_or("").contains("address_undeliverable_limited_couriers") => String::from("The specified location is not in a deliverable area at this time because all couriers are currently busy."),
174        StatusCode::TOO_MANY_REQUESTS if status.canonical_reason().unwrap_or("").contains("customer_limited") => String::from("Your account's limits have been exceeded."),
175        StatusCode::INTERNAL_SERVER_ERROR if status.canonical_reason().unwrap_or("") == "unknown_error" => String::from("An unknown error happened."),
176        _ => String::from("Unknown status code."),
177    }
178}