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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct CustomerClient {
pub http_client: HttpClient,
}
impl CustomerClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Creates a customer in an entrypoint. An identifier is required to create customer records. Change your identifier settings in Settings > Custom Fields in PartnerHub.
/// If you don't include an identifier, the record is rejected.
///
/// # Arguments
///
/// * `force_customer_creation` - When `true`, the request creates a new customer record, regardless of whether customer identifiers match an existing customer.
/// * `replace_existing` - Flag indicating to replace existing customer with a new record. Possible values: 0 (don't replace), 1 (replace). Default is `0`.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn add_customer(
&self,
entry: &Entrypointfield,
request: &AddCustomerRequest,
options: Option<RequestOptions>,
) -> Result<PayabliApiResponseCustomerQuery, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("Customer/single/{}", entry.0),
Some(serde_json::to_value(&request.body).map_err(ApiError::Serialization)?),
QueryBuilder::new()
.bool(
"forceCustomerCreation",
request.force_customer_creation.clone(),
)
.int("replaceExisting", request.replace_existing.clone())
.build(),
options,
)
.await
}
/// Delete a customer record.
///
/// # Arguments
///
/// * `customer_id` - Payabli-generated customer ID. Maps to "Customer ID" column in PartnerHub.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn delete_customer(
&self,
customer_id: i64,
options: Option<RequestOptions>,
) -> Result<PayabliApiResponse00Responsedatanonobject, ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("Customer/{}", customer_id),
None,
None,
options,
)
.await
}
/// Retrieves a customer's record and details.
///
/// # Arguments
///
/// * `customer_id` - Payabli-generated customer ID. Maps to "Customer ID" column in PartnerHub.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn get_customer(
&self,
customer_id: i64,
options: Option<RequestOptions>,
) -> Result<CustomerQueryRecords, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("Customer/{}", customer_id),
None,
None,
options,
)
.await
}
/// Links a customer to a transaction by ID.
///
/// # Arguments
///
/// * `customer_id` - Payabli-generated customer ID. Maps to "Customer ID" column in PartnerHub.
/// * `trans_id` - ReferenceId for the transaction (PaymentId).
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn link_customer_transaction(
&self,
customer_id: i64,
trans_id: &str,
options: Option<RequestOptions>,
) -> Result<PayabliApiResponse00Responsedatanonobject, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("Customer/link/{}/{}", customer_id, trans_id),
None,
None,
options,
)
.await
}
/// Sends the consent opt-in email to the customer email address in the customer record.
///
/// # Arguments
///
/// * `customer_id` - Payabli-generated customer ID. Maps to "Customer ID" column in PartnerHub.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn request_consent(
&self,
customer_id: i64,
options: Option<RequestOptions>,
) -> Result<PayabliApiResponse00Responsedatanonobject, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("Customer/{}/consent", customer_id),
None,
None,
options,
)
.await
}
/// Update a customer record. Include only the fields you want to change.
///
/// # Arguments
///
/// * `customer_id` - Payabli-generated customer ID. Maps to "Customer ID" column in PartnerHub.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn update_customer(
&self,
customer_id: i64,
request: &CustomerData,
options: Option<RequestOptions>,
) -> Result<PayabliApiResponse00Responsedatanonobject, ApiError> {
self.http_client
.execute_request(
Method::PUT,
&format!("Customer/{}", customer_id),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
}