stripe/resources/generated/
terminal_reader.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::TerminalReaderId;
7use crate::params::{Expand, Expandable, List, Metadata, Object, Paginable};
8use crate::resources::{Charge, Currency, PaymentIntent, Refund, SetupIntent, TerminalLocation};
9use serde::{Deserialize, Serialize};
10
11/// The resource representing a Stripe "TerminalReaderReader".
12///
13/// For more details see <https://stripe.com/docs/api/terminal/readers/object>
14#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct TerminalReader {
16    /// Unique identifier for the object.
17    pub id: TerminalReaderId,
18
19    /// The most recent action performed by the reader.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub action: Option<TerminalReaderReaderResourceReaderAction>,
22
23    // Always true for a deleted object
24    #[serde(default)]
25    pub deleted: bool,
26
27    /// The current software version of the reader.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub device_sw_version: Option<String>,
30
31    /// Type of reader, one of `bbpos_wisepad3`, `stripe_m2`, `bbpos_chipper2x`, `bbpos_wisepos_e`, `verifone_P400`, or `simulated_wisepos_e`.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub device_type: Option<TerminalReaderDeviceType>,
34
35    /// The local IP address of the reader.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub ip_address: Option<String>,
38
39    /// Custom label given to the reader for easier identification.
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub label: Option<String>,
42
43    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub livemode: Option<bool>,
46
47    /// The location identifier of the reader.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub location: Option<Expandable<TerminalLocation>>,
50
51    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
52    ///
53    /// This can be useful for storing additional information about the object in a structured format.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub metadata: Option<Metadata>,
56
57    /// Serial number of the reader.
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub serial_number: Option<String>,
60
61    /// The networking status of the reader.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub status: Option<TerminalReaderStatus>,
64}
65
66impl TerminalReader {
67    /// Returns a list of `Reader` objects.
68    pub fn list(
69        client: &Client,
70        params: &ListTerminalReaders<'_>,
71    ) -> Response<List<TerminalReader>> {
72        client.get_query("/terminal/readers", params)
73    }
74
75    /// Creates a new `Reader` object.
76    pub fn create(client: &Client, params: CreateTerminalReader<'_>) -> Response<TerminalReader> {
77        #[allow(clippy::needless_borrows_for_generic_args)]
78        client.post_form("/terminal/readers", &params)
79    }
80}
81
82impl Object for TerminalReader {
83    type Id = TerminalReaderId;
84    fn id(&self) -> Self::Id {
85        self.id.clone()
86    }
87    fn object(&self) -> &'static str {
88        "terminal.reader"
89    }
90}
91
92#[derive(Clone, Debug, Default, Deserialize, Serialize)]
93pub struct TerminalReaderReaderResourceReaderAction {
94    /// Failure code, only set if status is `failed`.
95    pub failure_code: Option<String>,
96
97    /// Detailed failure message, only set if status is `failed`.
98    pub failure_message: Option<String>,
99
100    #[serde(skip_serializing_if = "Option::is_none")]
101    pub process_payment_intent: Option<TerminalReaderReaderResourceProcessPaymentIntentAction>,
102
103    #[serde(skip_serializing_if = "Option::is_none")]
104    pub process_setup_intent: Option<TerminalReaderReaderResourceProcessSetupIntentAction>,
105
106    #[serde(skip_serializing_if = "Option::is_none")]
107    pub refund_payment: Option<TerminalReaderReaderResourceRefundPaymentAction>,
108
109    #[serde(skip_serializing_if = "Option::is_none")]
110    pub set_reader_display: Option<TerminalReaderReaderResourceSetReaderDisplayAction>,
111
112    /// Status of the action performed by the reader.
113    pub status: TerminalReaderReaderResourceReaderActionStatus,
114
115    /// Type of action performed by the reader.
116    #[serde(rename = "type")]
117    pub type_: TerminalReaderReaderResourceReaderActionType,
118}
119
120#[derive(Clone, Debug, Default, Deserialize, Serialize)]
121pub struct TerminalReaderReaderResourceProcessPaymentIntentAction {
122    /// Most recent PaymentIntent processed by the reader.
123    pub payment_intent: Expandable<PaymentIntent>,
124
125    #[serde(skip_serializing_if = "Option::is_none")]
126    pub process_config: Option<TerminalReaderReaderResourceProcessConfig>,
127}
128
129#[derive(Clone, Debug, Default, Deserialize, Serialize)]
130pub struct TerminalReaderReaderResourceProcessConfig {
131    /// Override showing a tipping selection screen on this transaction.
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub skip_tipping: Option<bool>,
134
135    #[serde(skip_serializing_if = "Option::is_none")]
136    pub tipping: Option<TerminalReaderReaderResourceTippingConfig>,
137}
138
139#[derive(Clone, Debug, Default, Deserialize, Serialize)]
140pub struct TerminalReaderReaderResourceProcessSetupIntentAction {
141    /// ID of a card PaymentMethod generated from the card_present PaymentMethod that may be attached to a Customer for future transactions.
142    ///
143    /// Only present if it was possible to generate a card PaymentMethod.
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub generated_card: Option<String>,
146
147    #[serde(skip_serializing_if = "Option::is_none")]
148    pub process_config: Option<TerminalReaderReaderResourceProcessSetupConfig>,
149
150    /// Most recent SetupIntent processed by the reader.
151    pub setup_intent: Expandable<SetupIntent>,
152}
153
154#[derive(Clone, Debug, Default, Deserialize, Serialize)]
155pub struct TerminalReaderReaderResourceProcessSetupConfig {}
156
157#[derive(Clone, Debug, Default, Deserialize, Serialize)]
158pub struct TerminalReaderReaderResourceRefundPaymentAction {
159    /// The amount being refunded.
160    #[serde(skip_serializing_if = "Option::is_none")]
161    pub amount: Option<i64>,
162
163    /// Charge that is being refunded.
164    #[serde(skip_serializing_if = "Option::is_none")]
165    pub charge: Option<Expandable<Charge>>,
166
167    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
168    ///
169    /// This can be useful for storing additional information about the object in a structured format.
170    #[serde(skip_serializing_if = "Option::is_none")]
171    pub metadata: Option<Metadata>,
172
173    /// Payment intent that is being refunded.
174    #[serde(skip_serializing_if = "Option::is_none")]
175    pub payment_intent: Option<Expandable<PaymentIntent>>,
176
177    /// The reason for the refund.
178    #[serde(skip_serializing_if = "Option::is_none")]
179    pub reason: Option<TerminalReaderReaderResourceRefundPaymentActionReason>,
180
181    /// Unique identifier for the refund object.
182    #[serde(skip_serializing_if = "Option::is_none")]
183    pub refund: Option<Expandable<Refund>>,
184
185    /// Boolean indicating whether the application fee should be refunded when refunding this charge.
186    ///
187    /// If a full charge refund is given, the full application fee will be refunded.
188    /// Otherwise, the application fee will be refunded in an amount proportional to the amount of the charge refunded.
189    /// An application fee can be refunded only by the application that created the charge.
190    #[serde(skip_serializing_if = "Option::is_none")]
191    pub refund_application_fee: Option<bool>,
192
193    /// Boolean indicating whether the transfer should be reversed when refunding this charge.
194    ///
195    /// The transfer will be reversed proportionally to the amount being refunded (either the entire or partial amount).
196    /// A transfer can be reversed only by the application that created the charge.
197    #[serde(skip_serializing_if = "Option::is_none")]
198    pub reverse_transfer: Option<bool>,
199}
200
201#[derive(Clone, Debug, Default, Deserialize, Serialize)]
202pub struct TerminalReaderReaderResourceSetReaderDisplayAction {
203    /// Cart object to be displayed by the reader.
204    pub cart: Option<TerminalReaderReaderResourceCart>,
205
206    /// Type of information to be displayed by the reader.
207    #[serde(rename = "type")]
208    pub type_: TerminalReaderReaderResourceSetReaderDisplayActionType,
209}
210
211#[derive(Clone, Debug, Default, Deserialize, Serialize)]
212pub struct TerminalReaderReaderResourceCart {
213    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
214    ///
215    /// Must be a [supported currency](https://stripe.com/docs/currencies).
216    pub currency: Currency,
217
218    /// List of line items in the cart.
219    pub line_items: Vec<TerminalReaderReaderResourceLineItem>,
220
221    /// Tax amount for the entire cart.
222    ///
223    /// A positive integer in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
224    pub tax: Option<i64>,
225
226    /// Total amount for the entire cart, including tax.
227    ///
228    /// A positive integer in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
229    pub total: i64,
230}
231
232#[derive(Clone, Debug, Default, Deserialize, Serialize)]
233pub struct TerminalReaderReaderResourceLineItem {
234    /// The amount of the line item.
235    ///
236    /// A positive integer in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
237    pub amount: i64,
238
239    /// Description of the line item.
240    pub description: String,
241
242    /// The quantity of the line item.
243    pub quantity: u64,
244}
245
246#[derive(Clone, Debug, Default, Deserialize, Serialize)]
247pub struct TerminalReaderReaderResourceTippingConfig {
248    /// Amount used to calculate tip suggestions on tipping selection screen for this transaction.
249    ///
250    /// Must be a positive integer in the smallest currency unit (e.g., 100 cents to represent $1.00 or 100 to represent ¥100, a zero-decimal currency).
251    #[serde(skip_serializing_if = "Option::is_none")]
252    pub amount_eligible: Option<i64>,
253}
254
255/// The parameters for `TerminalReader::create`.
256#[derive(Clone, Debug, Serialize)]
257pub struct CreateTerminalReader<'a> {
258    /// Specifies which fields in the response should be expanded.
259    #[serde(skip_serializing_if = "Expand::is_empty")]
260    pub expand: &'a [&'a str],
261
262    /// Custom label given to the reader for easier identification.
263    ///
264    /// If no label is specified, the registration code will be used.
265    #[serde(skip_serializing_if = "Option::is_none")]
266    pub label: Option<&'a str>,
267
268    /// The location to assign the reader to.
269    #[serde(skip_serializing_if = "Option::is_none")]
270    pub location: Option<&'a str>,
271
272    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
273    ///
274    /// This can be useful for storing additional information about the object in a structured format.
275    /// Individual keys can be unset by posting an empty value to them.
276    /// All keys can be unset by posting an empty value to `metadata`.
277    #[serde(skip_serializing_if = "Option::is_none")]
278    pub metadata: Option<Metadata>,
279
280    /// A code generated by the reader used for registering to an account.
281    pub registration_code: &'a str,
282}
283
284impl<'a> CreateTerminalReader<'a> {
285    pub fn new(registration_code: &'a str) -> Self {
286        CreateTerminalReader {
287            expand: Default::default(),
288            label: Default::default(),
289            location: Default::default(),
290            metadata: Default::default(),
291            registration_code,
292        }
293    }
294}
295
296/// The parameters for `TerminalReader::list`.
297#[derive(Clone, Debug, Serialize, Default)]
298pub struct ListTerminalReaders<'a> {
299    /// Filters readers by device type.
300    #[serde(skip_serializing_if = "Option::is_none")]
301    pub device_type: Option<TerminalReaderDeviceType>,
302
303    /// A cursor for use in pagination.
304    ///
305    /// `ending_before` is an object ID that defines your place in the list.
306    /// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
307    #[serde(skip_serializing_if = "Option::is_none")]
308    pub ending_before: Option<TerminalReaderId>,
309
310    /// Specifies which fields in the response should be expanded.
311    #[serde(skip_serializing_if = "Expand::is_empty")]
312    pub expand: &'a [&'a str],
313
314    /// A limit on the number of objects to be returned.
315    ///
316    /// Limit can range between 1 and 100, and the default is 10.
317    #[serde(skip_serializing_if = "Option::is_none")]
318    pub limit: Option<u64>,
319
320    /// A location ID to filter the response list to only readers at the specific location.
321    #[serde(skip_serializing_if = "Option::is_none")]
322    pub location: Option<&'a str>,
323
324    /// Filters readers by serial number.
325    #[serde(skip_serializing_if = "Option::is_none")]
326    pub serial_number: Option<&'a str>,
327
328    /// A cursor for use in pagination.
329    ///
330    /// `starting_after` is an object ID that defines your place in the list.
331    /// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
332    #[serde(skip_serializing_if = "Option::is_none")]
333    pub starting_after: Option<TerminalReaderId>,
334
335    /// A status filter to filter readers to only offline or online readers.
336    #[serde(skip_serializing_if = "Option::is_none")]
337    pub status: Option<TerminalReaderStatus>,
338}
339
340impl<'a> ListTerminalReaders<'a> {
341    pub fn new() -> Self {
342        ListTerminalReaders {
343            device_type: Default::default(),
344            ending_before: Default::default(),
345            expand: Default::default(),
346            limit: Default::default(),
347            location: Default::default(),
348            serial_number: Default::default(),
349            starting_after: Default::default(),
350            status: Default::default(),
351        }
352    }
353}
354impl Paginable for ListTerminalReaders<'_> {
355    type O = TerminalReader;
356    fn set_last(&mut self, item: Self::O) {
357        self.starting_after = Some(item.id());
358    }
359}
360/// An enum representing the possible values of an `TerminalReader`'s `device_type` field.
361#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
362#[serde(rename_all = "snake_case")]
363pub enum TerminalReaderDeviceType {
364    BbposChipper2x,
365    BbposWisepad3,
366    BbposWiseposE,
367    SimulatedWiseposE,
368    StripeM2,
369    #[serde(rename = "verifone_P400")]
370    VerifoneP400,
371}
372
373impl TerminalReaderDeviceType {
374    pub fn as_str(self) -> &'static str {
375        match self {
376            TerminalReaderDeviceType::BbposChipper2x => "bbpos_chipper2x",
377            TerminalReaderDeviceType::BbposWisepad3 => "bbpos_wisepad3",
378            TerminalReaderDeviceType::BbposWiseposE => "bbpos_wisepos_e",
379            TerminalReaderDeviceType::SimulatedWiseposE => "simulated_wisepos_e",
380            TerminalReaderDeviceType::StripeM2 => "stripe_m2",
381            TerminalReaderDeviceType::VerifoneP400 => "verifone_P400",
382        }
383    }
384}
385
386impl AsRef<str> for TerminalReaderDeviceType {
387    fn as_ref(&self) -> &str {
388        self.as_str()
389    }
390}
391
392impl std::fmt::Display for TerminalReaderDeviceType {
393    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
394        self.as_str().fmt(f)
395    }
396}
397impl std::default::Default for TerminalReaderDeviceType {
398    fn default() -> Self {
399        Self::BbposChipper2x
400    }
401}
402
403/// An enum representing the possible values of an `TerminalReaderReaderResourceReaderAction`'s `status` field.
404#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
405#[serde(rename_all = "snake_case")]
406pub enum TerminalReaderReaderResourceReaderActionStatus {
407    Failed,
408    InProgress,
409    Succeeded,
410}
411
412impl TerminalReaderReaderResourceReaderActionStatus {
413    pub fn as_str(self) -> &'static str {
414        match self {
415            TerminalReaderReaderResourceReaderActionStatus::Failed => "failed",
416            TerminalReaderReaderResourceReaderActionStatus::InProgress => "in_progress",
417            TerminalReaderReaderResourceReaderActionStatus::Succeeded => "succeeded",
418        }
419    }
420}
421
422impl AsRef<str> for TerminalReaderReaderResourceReaderActionStatus {
423    fn as_ref(&self) -> &str {
424        self.as_str()
425    }
426}
427
428impl std::fmt::Display for TerminalReaderReaderResourceReaderActionStatus {
429    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
430        self.as_str().fmt(f)
431    }
432}
433impl std::default::Default for TerminalReaderReaderResourceReaderActionStatus {
434    fn default() -> Self {
435        Self::Failed
436    }
437}
438
439/// An enum representing the possible values of an `TerminalReaderReaderResourceReaderAction`'s `type` field.
440#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
441#[serde(rename_all = "snake_case")]
442pub enum TerminalReaderReaderResourceReaderActionType {
443    ProcessPaymentIntent,
444    ProcessSetupIntent,
445    RefundPayment,
446    SetReaderDisplay,
447}
448
449impl TerminalReaderReaderResourceReaderActionType {
450    pub fn as_str(self) -> &'static str {
451        match self {
452            TerminalReaderReaderResourceReaderActionType::ProcessPaymentIntent => {
453                "process_payment_intent"
454            }
455            TerminalReaderReaderResourceReaderActionType::ProcessSetupIntent => {
456                "process_setup_intent"
457            }
458            TerminalReaderReaderResourceReaderActionType::RefundPayment => "refund_payment",
459            TerminalReaderReaderResourceReaderActionType::SetReaderDisplay => "set_reader_display",
460        }
461    }
462}
463
464impl AsRef<str> for TerminalReaderReaderResourceReaderActionType {
465    fn as_ref(&self) -> &str {
466        self.as_str()
467    }
468}
469
470impl std::fmt::Display for TerminalReaderReaderResourceReaderActionType {
471    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
472        self.as_str().fmt(f)
473    }
474}
475impl std::default::Default for TerminalReaderReaderResourceReaderActionType {
476    fn default() -> Self {
477        Self::ProcessPaymentIntent
478    }
479}
480
481/// An enum representing the possible values of an `TerminalReaderReaderResourceRefundPaymentAction`'s `reason` field.
482#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
483#[serde(rename_all = "snake_case")]
484pub enum TerminalReaderReaderResourceRefundPaymentActionReason {
485    Duplicate,
486    Fraudulent,
487    RequestedByCustomer,
488}
489
490impl TerminalReaderReaderResourceRefundPaymentActionReason {
491    pub fn as_str(self) -> &'static str {
492        match self {
493            TerminalReaderReaderResourceRefundPaymentActionReason::Duplicate => "duplicate",
494            TerminalReaderReaderResourceRefundPaymentActionReason::Fraudulent => "fraudulent",
495            TerminalReaderReaderResourceRefundPaymentActionReason::RequestedByCustomer => {
496                "requested_by_customer"
497            }
498        }
499    }
500}
501
502impl AsRef<str> for TerminalReaderReaderResourceRefundPaymentActionReason {
503    fn as_ref(&self) -> &str {
504        self.as_str()
505    }
506}
507
508impl std::fmt::Display for TerminalReaderReaderResourceRefundPaymentActionReason {
509    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
510        self.as_str().fmt(f)
511    }
512}
513impl std::default::Default for TerminalReaderReaderResourceRefundPaymentActionReason {
514    fn default() -> Self {
515        Self::Duplicate
516    }
517}
518
519/// An enum representing the possible values of an `TerminalReaderReaderResourceSetReaderDisplayAction`'s `type` field.
520#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
521#[serde(rename_all = "snake_case")]
522pub enum TerminalReaderReaderResourceSetReaderDisplayActionType {
523    Cart,
524}
525
526impl TerminalReaderReaderResourceSetReaderDisplayActionType {
527    pub fn as_str(self) -> &'static str {
528        match self {
529            TerminalReaderReaderResourceSetReaderDisplayActionType::Cart => "cart",
530        }
531    }
532}
533
534impl AsRef<str> for TerminalReaderReaderResourceSetReaderDisplayActionType {
535    fn as_ref(&self) -> &str {
536        self.as_str()
537    }
538}
539
540impl std::fmt::Display for TerminalReaderReaderResourceSetReaderDisplayActionType {
541    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
542        self.as_str().fmt(f)
543    }
544}
545impl std::default::Default for TerminalReaderReaderResourceSetReaderDisplayActionType {
546    fn default() -> Self {
547        Self::Cart
548    }
549}
550
551/// An enum representing the possible values of an `TerminalReader`'s `status` field.
552#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
553#[serde(rename_all = "snake_case")]
554pub enum TerminalReaderStatus {
555    Offline,
556    Online,
557}
558
559impl TerminalReaderStatus {
560    pub fn as_str(self) -> &'static str {
561        match self {
562            TerminalReaderStatus::Offline => "offline",
563            TerminalReaderStatus::Online => "online",
564        }
565    }
566}
567
568impl AsRef<str> for TerminalReaderStatus {
569    fn as_ref(&self) -> &str {
570        self.as_str()
571    }
572}
573
574impl std::fmt::Display for TerminalReaderStatus {
575    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
576        self.as_str().fmt(f)
577    }
578}
579impl std::default::Default for TerminalReaderStatus {
580    fn default() -> Self {
581        Self::Offline
582    }
583}