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
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, RequestOptions};
use reqwest::Method;
pub struct PaymentsClient {
pub http_client: HttpClient,
}
impl PaymentsClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Create a new payment request for a Brevo contact. The request requires a reference (displayed on the payment page), a contact ID, and a cart with currency and amount in cents. You can optionally configure a custom success redirect URL and enable email notifications with reminders. Returns the payment request ID and its public payment URL. A `403` error is returned if Brevo Payments is not activated or the account is not validated.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use brevo_rust::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<value>".to_string()),
/// ..Default::default()
/// };
/// let client = BrevoClient::new(config).expect("Failed to build client");
/// client
/// .payments
/// .create_payment_request(
/// &CreatePaymentRequestRequest {
/// cart: Cart {
/// currency: "EUR".to_string(),
/// specific_amount: 1200,
/// },
/// contact_id: 43,
/// reference: "Invoice #INV0001".to_string(),
/// configuration: None,
/// description: None,
/// notification: None,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn create_payment_request(
&self,
request: &CreatePaymentRequestRequest,
options: Option<RequestOptions>,
) -> Result<CreatePaymentRequestResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"payments/requests",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Retrieve the details of a specific payment request by its ID. The response includes the reference, status (created, sent, reminderSent, or paid), cart details, notification configuration, contact ID, and the number of reminders sent. Returns a `404` error if no payment request matches the provided ID.
///
/// # Arguments
///
/// * `id` - Id of the payment Request
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use brevo_rust::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<value>".to_string()),
/// ..Default::default()
/// };
/// let client = BrevoClient::new(config).expect("Failed to build client");
/// client
/// .payments
/// .get_payment_request(&"050db7b0-9bb7-4c1e-9c68-5a8dace8c1dc".to_string(), None)
/// .await;
/// }
/// ```
pub async fn get_payment_request(
&self,
id: &str,
options: Option<RequestOptions>,
) -> Result<GetPaymentRequestResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("payments/requests/{}", id),
None,
None,
options,
)
.await
}
/// Delete a payment request by its UUID. Once deleted, the payment request can no longer be accessed or paid. Returns a `404` error if no payment request matches the provided ID, and a `403` error if Brevo Payments is not activated or the account is not validated.
///
/// # Arguments
///
/// * `id` - ID of the payment request.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// Empty response
///
/// # Examples
///
/// ```no_run
/// use brevo_rust::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<value>".to_string()),
/// ..Default::default()
/// };
/// let client = BrevoClient::new(config).expect("Failed to build client");
/// client
/// .payments
/// .delete_payment_request(&"9ae7d68a-565c-4695-9381-d8fb3e3a14cc".to_string(), None)
/// .await;
/// }
/// ```
pub async fn delete_payment_request(
&self,
id: &str,
options: Option<RequestOptions>,
) -> Result<(), ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("payments/requests/{}", id),
None,
None,
options,
)
.await
}
}