1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//! The customer model.
use serde::Deserialize;
use serde_json::Value;
/// A customer as returned by the API.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CustomerResponse {
/// Unique customer ID.
pub customer_id: String,
/// ISO 8601 creation timestamp.
#[serde(default)]
pub created_at: Option<String>,
/// Full name.
#[serde(default)]
pub name: Option<String>,
/// Email address.
#[serde(default)]
pub email: Option<String>,
/// Phone number.
#[serde(default)]
pub phone: Option<String>,
/// Phone country code.
#[serde(default)]
pub phone_country_code: Option<String>,
/// Internal notes.
#[serde(default)]
pub description: Option<String>,
/// ID of the default saved payment method, if any.
#[serde(default)]
pub default_payment_method_id: Option<String>,
/// Arbitrary metadata.
#[serde(default)]
pub metadata: Option<Value>,
/// Shops (business profiles) this customer has transacted in, derived from
/// their payments — the same rule the `profile_ids` list filter applies. A
/// customer created but never charged belongs to no shop.
///
/// Returned by [`Customers::retrieve`](crate::resources::customers::Customers::retrieve)
/// only: deriving it costs a query per customer, so the list endpoints omit
/// it. **`None` means "not computed", not "no shops"** — `Some(vec![])` is
/// a real answer and stays distinguishable from a field nobody filled in.
///
/// A shop-scoped caller only sees their own shop here; the server narrows
/// the list to the caller's scope.
#[serde(default)]
pub profile_ids: Option<Vec<String>>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// What placing a customer in a shop did.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum CustomerShopPlacementOutcome {
/// The customer now belongs to the shop; their other shops are unchanged.
Placed,
/// The customer already belonged to the shop; nothing changed.
AlreadyInShop,
/// No customer with this id. Only a bulk placement answers it; a single
/// placement answers `CustomerNotFound` instead.
NotFound,
/// An outcome this SDK version does not know yet.
#[serde(other)]
Unknown,
}
/// One customer's placement in a shop.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CustomerShopPlacementResponse {
/// The customer.
pub customer_id: String,
/// The shop.
pub profile_id: String,
/// What the placement did.
pub outcome: CustomerShopPlacementOutcome,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Every distinct customer of a bulk placement, in the order of the request.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CustomerShopBulkPlacementResponse {
/// The shop.
pub profile_id: String,
/// One entry per distinct customer id of the request.
#[serde(default)]
pub placements: Vec<CustomerShopPlacementResponse>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
#[cfg(test)]
mod tests {
use super::*;
/// "This customer has paid no shop" and "the list endpoint did not compute
/// this" are different answers. Mutation: `#[serde(default)]` on a
/// `Vec<String>` instead of an `Option` collapses them into one.
#[test]
fn customer_distinguishes_empty_shops_from_uncomputed_shops() {
let charged: CustomerResponse =
serde_json::from_str(r#"{"customer_id":"cus_1","profile_ids":["pro_1"]}"#).unwrap();
let never_charged: CustomerResponse =
serde_json::from_str(r#"{"customer_id":"cus_2","profile_ids":[]}"#).unwrap();
let from_a_list: CustomerResponse =
serde_json::from_str(r#"{"customer_id":"cus_3"}"#).unwrap();
assert_eq!(
charged.profile_ids.as_deref(),
Some(&["pro_1".to_string()][..])
);
assert_eq!(never_charged.profile_ids.as_deref(), Some(&[][..]));
assert_eq!(from_a_list.profile_ids, None);
}
}