sumup 0.5.14

Rust SDK for the SumUp API.
Documentation
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
// The contents of this file are generated; do not modify them.

//! Retrieve structured receipt data for a transaction, including payment, merchant, and acquirer details. Use this data to display a receipt in your application. The response is JSON, rather than a rendered receipt document.
use super::common::*;
/// Structured receipt details for a transaction. The transaction's `amount`, `vat_amount`, and `tip_amount`, as well as event amounts, are returned as decimal strings in major currency units, for example `"10.10"` for EUR 10.10.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Receipt {
    /// Acquirer-specific metadata related to the card authorization.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub acquirer_data: Option<ReceiptAcquirerData>,
    /// EMV-specific metadata returned for card-present payments.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emv_data: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub merchant_data: Option<ReceiptMerchantData>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transaction_data: Option<ReceiptTransaction>,
}
/// Payment card details displayed on the receipt.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiptCard {
    /// Last four digits of the payment card number.
    ///
    /// Example: `3456`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_4_digits: Option<String>,
    /// Issuing card network of the payment card.
    ///
    /// Example: `VISA`
    #[serde(rename = "type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#type: Option<String>,
}
/// Transaction event details as rendered on the receipt.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiptEvent {
    /// Amount associated with the transaction event, in major units.
    ///
    /// Example: `10.10`
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        deserialize_with = "crate::string_or_number::deserialize_option"
    )]
    pub amount: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<TransactionEventId>,
    /// Receipt number associated with the event.
    ///
    /// Example: `123456`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub receipt_no: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<TransactionEventStatus>,
    /// The timestamp of when the transaction event occurred.
    ///
    /// Example: `2020-05-25T10:49:42.784Z`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timestamp: Option<crate::datetime::DateTime>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transaction_id: Option<TransactionId>,
    #[serde(rename = "type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#type: Option<TransactionEventType>,
}
/// Merchant details displayed on a transaction receipt.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiptMerchantData {
    /// Locale used for rendering localized receipt fields.
    ///
    /// Example: `de-DE`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub locale: Option<String>,
    /// Merchant profile details displayed on the receipt.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub merchant_profile: Option<ReceiptMerchantDataMerchantProfile>,
}
/// Card reader details displayed on the receipt.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiptReader {
    /// Unique identifier of the physical card reader.
    ///
    /// Example: `U1DT3NA00-CN`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub code: Option<String>,
    /// Model of the physical card reader.
    ///
    /// Example: `solo`
    #[serde(rename = "type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#type: Option<String>,
}
/// Transaction details displayed on a receipt.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiptTransaction {
    /// Total transaction amount, in major units.
    ///
    /// Example: `10.10`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub amount: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub card: Option<ReceiptCard>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub card_reader: Option<ReceiptReader>,
    /// Three-letter ISO 4217 currency code of the transaction.
    ///
    /// Example: `EUR`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub currency: Option<String>,
    /// Entry mode of the payment details.
    ///
    /// Example: `CUSTOMER_ENTRY`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub entry_mode: Option<String>,
    /// Transaction events displayed on the receipt.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub events: Option<Vec<ReceiptEvent>>,
    /// Number of installments.
    ///
    /// Example: `1`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub installments_count: Option<i64>,
    /// Short unique identifier for the merchant.
    ///
    /// Example: `MH4H92C7`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub merchant_code: Option<String>,
    /// Payment type used for the transaction.
    ///
    /// Example: `ECOM`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub payment_type: Option<String>,
    /// Whether the transaction was processed as credit or debit.
    ///
    /// Example: `CREDIT`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub process_as: Option<ReceiptTransactionProcessAs>,
    /// Products associated with the transaction.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub products: Option<Vec<ReceiptTransactionProductsItem>>,
    /// Receipt number associated with the transaction.
    ///
    /// Example: `123456`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub receipt_no: Option<String>,
    /// Current processing status of the transaction.
    ///
    /// Example: `SUCCESSFUL`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,
    /// The timestamp of when the transaction was created.
    ///
    /// Example: `2020-02-29T10:56:56.876Z`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timestamp: Option<crate::datetime::DateTime>,
    /// Tip included in the transaction amount, in major units.
    ///
    /// Example: `3.00`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tip_amount: Option<String>,
    /// Transaction code returned after processing the transaction.
    ///
    /// Example: `TEENSK4W2K`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transaction_code: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transaction_id: Option<TransactionId>,
    /// VAT included in the transaction amount, in major units.
    ///
    /// Example: `6.00`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vat_amount: Option<String>,
    /// VAT breakdown for the transaction.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vat_rates: Option<Vec<ReceiptTransactionVatRatesItem>>,
    /// Cardholder verification method.
    ///
    /// Example: `none`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub verification_method: Option<String>,
}
/// Acquirer-specific metadata related to the card authorization.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiptAcquirerData {
    /// Authorization code returned by the acquirer.
    ///
    /// Example: `053201`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub authorization_code: Option<String>,
    /// Local timestamp of the card authorization.
    ///
    /// Example: `2020-02-29T11:56:56+01:00`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub local_time: Option<String>,
    /// Return code reported by the acquirer.
    ///
    /// Example: `00`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub return_code: Option<String>,
    /// Identifier of the terminal used for the authorization.
    ///
    /// Example: `12345678`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tid: Option<String>,
}
/// Business address of the merchant.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiptMerchantDataMerchantProfileAddress {
    /// First line of the merchant address.
    ///
    /// Example: `Sample street 1`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub address_line1: Option<String>,
    /// Second line of the merchant address.
    ///
    /// Example: `Floor 2`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub address_line2: Option<String>,
    /// City of the merchant address.
    ///
    /// Example: `Berlin`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub city: Option<String>,
    /// Two-letter ISO 3166-1 alpha-2 country code of the merchant address.
    ///
    /// Example: `DE`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country: Option<String>,
    /// English name of the country in the merchant address.
    ///
    /// Example: `Germany`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country_en_name: Option<String>,
    /// Localized name of the country in the merchant address.
    ///
    /// Example: `Deutschland`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country_native_name: Option<String>,
    /// Landline phone number of the merchant.
    ///
    /// Example: `+493012345678`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub landline: Option<String>,
    /// Postal code of the merchant address.
    ///
    /// Example: `10115`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub post_code: Option<String>,
    /// Region or state of the merchant address.
    ///
    /// Example: `Berlin`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub region_name: Option<String>,
}
/// Merchant profile details displayed on the receipt.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiptMerchantDataMerchantProfile {
    /// Business address of the merchant.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub address: Option<ReceiptMerchantDataMerchantProfileAddress>,
    /// Business name of the merchant.
    ///
    /// Example: `Coffee House`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub business_name: Option<String>,
    /// Company registration number of the merchant.
    ///
    /// Example: `HRB 123456`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub company_registration_number: Option<String>,
    /// Email address of the merchant.
    ///
    /// Example: `merchant@example.com`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub email: Option<String>,
    /// Language configured for the merchant profile.
    ///
    /// Example: `de`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language: Option<String>,
    /// Short unique identifier for the merchant.
    ///
    /// Example: `MH4H92C7`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub merchant_code: Option<String>,
    /// VAT identification number of the merchant.
    ///
    /// Example: `DE123456789`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vat_id: Option<String>,
    /// Website of the merchant.
    ///
    /// Example: `https://example.com`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub website: Option<String>,
}
/// Whether the transaction was processed as credit or debit.
///
/// Example: `CREDIT`
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum ReceiptTransactionProcessAs {
    #[serde(rename = "CREDIT")]
    Credit,
    #[serde(rename = "DEBIT")]
    Debit,
    #[serde(untagged)]
    Other(String),
}
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiptTransactionProductsItem {
    /// Product description.
    ///
    /// Example: `Cappuccino`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Product name.
    ///
    /// Example: `Coffee`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Product price.
    ///
    /// Example: `150.0`
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        deserialize_with = "crate::string_or_number::deserialize_option"
    )]
    pub price: Option<f64>,
    /// Product price including VAT.
    ///
    /// Example: `150.0`
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        deserialize_with = "crate::string_or_number::deserialize_option"
    )]
    pub price_with_vat: Option<f64>,
    /// Product quantity.
    ///
    /// Example: `1`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quantity: Option<i64>,
    /// VAT amount for a single product.
    ///
    /// Example: `0.0`
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        deserialize_with = "crate::string_or_number::deserialize_option"
    )]
    pub single_vat_amount: Option<f64>,
    /// Total price calculated as the product price multiplied by the quantity.
    ///
    /// Example: `150.0`
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        deserialize_with = "crate::string_or_number::deserialize_option"
    )]
    pub total_price: Option<f64>,
    /// Total product price including VAT.
    ///
    /// Example: `150.0`
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        deserialize_with = "crate::string_or_number::deserialize_option"
    )]
    pub total_with_vat: Option<f64>,
    /// Total VAT amount for the product quantity.
    ///
    /// Example: `0.0`
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        deserialize_with = "crate::string_or_number::deserialize_option"
    )]
    pub vat_amount: Option<f64>,
    /// VAT rate.
    ///
    /// Example: `0.0`
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        deserialize_with = "crate::string_or_number::deserialize_option"
    )]
    pub vat_rate: Option<f64>,
}
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiptTransactionVatRatesItem {
    /// Gross amount to which the VAT rate applies.
    ///
    /// Example: `10.1`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub gross: Option<f32>,
    /// Net amount to which the VAT rate applies.
    ///
    /// Example: `8.49`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub net: Option<f32>,
    /// VAT rate applied to the transaction amount.
    ///
    /// Example: `0.19`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rate: Option<f32>,
    /// VAT amount included in the gross amount.
    ///
    /// Example: `1.61`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vat: Option<f32>,
}
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct GetParams {
    /// Short unique identifier for the merchant.
    ///
    /// Example: `MH4H92C7`
    pub mid: String,
    /// Unique identifier of the transaction event to include on the receipt.
    ///
    /// Example: `9567461191`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tx_event_id: Option<i64>,
}
use crate::client::Client;
#[derive(Debug, PartialEq)]
pub enum GetErrorBody {
    BadRequest(Error),
    Unauthorized(Problem),
    NotFound(Error),
}
/// Client for the Receipts API endpoints.
#[derive(Debug)]
pub struct ReceiptsClient<'a> {
    client: &'a Client,
}
impl<'a> ReceiptsClient<'a> {
    pub(crate) fn new(client: &'a Client) -> Self {
        Self { client }
    }
    /// Returns a reference to the underlying client.
    pub fn client(&self) -> &Client {
        self.client
    }
    /// Retrieve receipt details
    ///
    /// Retrieves structured receipt data for a transaction belonging to the merchant specified by `mid`. The path accepts either the SumUp transaction ID or transaction code. Provide `tx_event_id` to include a specific transaction event, such as a refund, on the receipt.
    ///
    /// Responses:
    /// - 200: Returns receipt details for the requested transaction.
    /// - 400: The request is invalid for the submitted parameters.
    /// - 401: The request is not authorized.
    /// - 404: The requested transaction event does not exist for the provided transaction.
    pub async fn get(
        &self,
        transaction_id: impl Into<String>,
        params: GetParams,
    ) -> crate::error::SdkResult<Receipt, GetErrorBody> {
        let path = format!("/v1.1/receipts/{}", transaction_id.into());
        let url = format!("{}{}", self.client.base_url(), path);
        let mut request = self
            .client
            .http_client()
            .get(&url)
            .header("User-Agent", crate::version::user_agent())
            .timeout(self.client.timeout());
        if let Some(authorization) = self.client.authorization() {
            request = request.header("Authorization", format!("Bearer {}", authorization));
        }
        for (header_name, header_value) in self.client.runtime_headers() {
            request = request.header(*header_name, header_value);
        }
        request = request.query(&[("mid", &params.mid)]);
        if let Some(ref value) = params.tx_event_id {
            request = request.query(&[("tx_event_id", value)]);
        }
        let response = request.send().await?;
        let status = response.status();
        match status {
            reqwest::StatusCode::OK => {
                let data: Receipt = response.json().await?;
                Ok(data)
            }
            reqwest::StatusCode::BAD_REQUEST => {
                let body: Error = response.json().await?;
                Err(crate::error::SdkError::api(GetErrorBody::BadRequest(body)))
            }
            reqwest::StatusCode::UNAUTHORIZED => {
                let body: Problem = response.json().await?;
                Err(crate::error::SdkError::api(GetErrorBody::Unauthorized(
                    body,
                )))
            }
            reqwest::StatusCode::NOT_FOUND => {
                let body: Error = response.json().await?;
                Err(crate::error::SdkError::api(GetErrorBody::NotFound(body)))
            }
            _ => {
                let body_bytes = response.bytes().await?;
                let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
                Err(crate::error::SdkError::unexpected(status, body))
            }
        }
    }
}