use serde::{Deserialize, Serialize};
use crate::client::{Client, Response};
use crate::ids::TerminalReaderId;
use crate::params::{Expand, Expandable, List, Metadata, Object, Paginable};
use crate::resources::{Charge, Currency, PaymentIntent, Refund, SetupIntent, TerminalLocation};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReader {
pub id: TerminalReaderId,
#[serde(skip_serializing_if = "Option::is_none")]
pub action: Option<TerminalReaderReaderResourceReaderAction>,
#[serde(default)]
pub deleted: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub device_sw_version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub device_type: Option<TerminalReaderDeviceType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ip_address: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub label: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub livemode: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub location: Option<Expandable<TerminalLocation>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,
#[serde(skip_serializing_if = "Option::is_none")]
pub serial_number: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<TerminalReaderStatus>,
}
impl TerminalReader {
pub fn list(
client: &Client,
params: &ListTerminalReaders<'_>,
) -> Response<List<TerminalReader>> {
client.get_query("/terminal/readers", params)
}
pub fn create(client: &Client, params: CreateTerminalReader<'_>) -> Response<TerminalReader> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/terminal/readers", ¶ms)
}
}
impl Object for TerminalReader {
type Id = TerminalReaderId;
fn id(&self) -> Self::Id {
self.id.clone()
}
fn object(&self) -> &'static str {
"terminal.reader"
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReaderReaderResourceReaderAction {
pub failure_code: Option<String>,
pub failure_message: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub process_payment_intent: Option<TerminalReaderReaderResourceProcessPaymentIntentAction>,
#[serde(skip_serializing_if = "Option::is_none")]
pub process_setup_intent: Option<TerminalReaderReaderResourceProcessSetupIntentAction>,
#[serde(skip_serializing_if = "Option::is_none")]
pub refund_payment: Option<TerminalReaderReaderResourceRefundPaymentAction>,
#[serde(skip_serializing_if = "Option::is_none")]
pub set_reader_display: Option<TerminalReaderReaderResourceSetReaderDisplayAction>,
pub status: TerminalReaderReaderResourceReaderActionStatus,
#[serde(rename = "type")]
pub type_: TerminalReaderReaderResourceReaderActionType,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReaderReaderResourceProcessPaymentIntentAction {
pub payment_intent: Expandable<PaymentIntent>,
#[serde(skip_serializing_if = "Option::is_none")]
pub process_config: Option<TerminalReaderReaderResourceProcessConfig>,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReaderReaderResourceProcessConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub skip_tipping: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tipping: Option<TerminalReaderReaderResourceTippingConfig>,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReaderReaderResourceProcessSetupIntentAction {
#[serde(skip_serializing_if = "Option::is_none")]
pub generated_card: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub process_config: Option<TerminalReaderReaderResourceProcessSetupConfig>,
pub setup_intent: Expandable<SetupIntent>,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReaderReaderResourceProcessSetupConfig {}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReaderReaderResourceRefundPaymentAction {
#[serde(skip_serializing_if = "Option::is_none")]
pub amount: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub charge: Option<Expandable<Charge>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_intent: Option<Expandable<PaymentIntent>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<TerminalReaderReaderResourceRefundPaymentActionReason>,
#[serde(skip_serializing_if = "Option::is_none")]
pub refund: Option<Expandable<Refund>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub refund_application_fee: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reverse_transfer: Option<bool>,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReaderReaderResourceSetReaderDisplayAction {
pub cart: Option<TerminalReaderReaderResourceCart>,
#[serde(rename = "type")]
pub type_: TerminalReaderReaderResourceSetReaderDisplayActionType,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReaderReaderResourceCart {
pub currency: Currency,
pub line_items: Vec<TerminalReaderReaderResourceLineItem>,
pub tax: Option<i64>,
pub total: i64,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReaderReaderResourceLineItem {
pub amount: i64,
pub description: String,
pub quantity: u64,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReaderReaderResourceTippingConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub amount_eligible: Option<i64>,
}
#[derive(Clone, Debug, Serialize)]
pub struct CreateTerminalReader<'a> {
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
#[serde(skip_serializing_if = "Option::is_none")]
pub label: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub location: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,
pub registration_code: &'a str,
}
impl<'a> CreateTerminalReader<'a> {
pub fn new(registration_code: &'a str) -> Self {
CreateTerminalReader {
expand: Default::default(),
label: Default::default(),
location: Default::default(),
metadata: Default::default(),
registration_code,
}
}
}
#[derive(Clone, Debug, Serialize, Default)]
pub struct ListTerminalReaders<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub device_type: Option<TerminalReaderDeviceType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ending_before: Option<TerminalReaderId>,
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub location: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub serial_number: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_after: Option<TerminalReaderId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<TerminalReaderStatus>,
}
impl<'a> ListTerminalReaders<'a> {
pub fn new() -> Self {
ListTerminalReaders {
device_type: Default::default(),
ending_before: Default::default(),
expand: Default::default(),
limit: Default::default(),
location: Default::default(),
serial_number: Default::default(),
starting_after: Default::default(),
status: Default::default(),
}
}
}
impl Paginable for ListTerminalReaders<'_> {
type O = TerminalReader;
fn set_last(&mut self, item: Self::O) {
self.starting_after = Some(item.id());
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TerminalReaderDeviceType {
BbposChipper2x,
BbposWisepad3,
BbposWiseposE,
SimulatedWiseposE,
StripeM2,
#[serde(rename = "verifone_P400")]
VerifoneP400,
}
impl TerminalReaderDeviceType {
pub fn as_str(self) -> &'static str {
match self {
TerminalReaderDeviceType::BbposChipper2x => "bbpos_chipper2x",
TerminalReaderDeviceType::BbposWisepad3 => "bbpos_wisepad3",
TerminalReaderDeviceType::BbposWiseposE => "bbpos_wisepos_e",
TerminalReaderDeviceType::SimulatedWiseposE => "simulated_wisepos_e",
TerminalReaderDeviceType::StripeM2 => "stripe_m2",
TerminalReaderDeviceType::VerifoneP400 => "verifone_P400",
}
}
}
impl AsRef<str> for TerminalReaderDeviceType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for TerminalReaderDeviceType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for TerminalReaderDeviceType {
fn default() -> Self {
Self::BbposChipper2x
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TerminalReaderReaderResourceReaderActionStatus {
Failed,
InProgress,
Succeeded,
}
impl TerminalReaderReaderResourceReaderActionStatus {
pub fn as_str(self) -> &'static str {
match self {
TerminalReaderReaderResourceReaderActionStatus::Failed => "failed",
TerminalReaderReaderResourceReaderActionStatus::InProgress => "in_progress",
TerminalReaderReaderResourceReaderActionStatus::Succeeded => "succeeded",
}
}
}
impl AsRef<str> for TerminalReaderReaderResourceReaderActionStatus {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for TerminalReaderReaderResourceReaderActionStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for TerminalReaderReaderResourceReaderActionStatus {
fn default() -> Self {
Self::Failed
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TerminalReaderReaderResourceReaderActionType {
ProcessPaymentIntent,
ProcessSetupIntent,
RefundPayment,
SetReaderDisplay,
}
impl TerminalReaderReaderResourceReaderActionType {
pub fn as_str(self) -> &'static str {
match self {
TerminalReaderReaderResourceReaderActionType::ProcessPaymentIntent => {
"process_payment_intent"
}
TerminalReaderReaderResourceReaderActionType::ProcessSetupIntent => {
"process_setup_intent"
}
TerminalReaderReaderResourceReaderActionType::RefundPayment => "refund_payment",
TerminalReaderReaderResourceReaderActionType::SetReaderDisplay => "set_reader_display",
}
}
}
impl AsRef<str> for TerminalReaderReaderResourceReaderActionType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for TerminalReaderReaderResourceReaderActionType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for TerminalReaderReaderResourceReaderActionType {
fn default() -> Self {
Self::ProcessPaymentIntent
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TerminalReaderReaderResourceRefundPaymentActionReason {
Duplicate,
Fraudulent,
RequestedByCustomer,
}
impl TerminalReaderReaderResourceRefundPaymentActionReason {
pub fn as_str(self) -> &'static str {
match self {
TerminalReaderReaderResourceRefundPaymentActionReason::Duplicate => "duplicate",
TerminalReaderReaderResourceRefundPaymentActionReason::Fraudulent => "fraudulent",
TerminalReaderReaderResourceRefundPaymentActionReason::RequestedByCustomer => {
"requested_by_customer"
}
}
}
}
impl AsRef<str> for TerminalReaderReaderResourceRefundPaymentActionReason {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for TerminalReaderReaderResourceRefundPaymentActionReason {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for TerminalReaderReaderResourceRefundPaymentActionReason {
fn default() -> Self {
Self::Duplicate
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TerminalReaderReaderResourceSetReaderDisplayActionType {
Cart,
}
impl TerminalReaderReaderResourceSetReaderDisplayActionType {
pub fn as_str(self) -> &'static str {
match self {
TerminalReaderReaderResourceSetReaderDisplayActionType::Cart => "cart",
}
}
}
impl AsRef<str> for TerminalReaderReaderResourceSetReaderDisplayActionType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for TerminalReaderReaderResourceSetReaderDisplayActionType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for TerminalReaderReaderResourceSetReaderDisplayActionType {
fn default() -> Self {
Self::Cart
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TerminalReaderStatus {
Offline,
Online,
}
impl TerminalReaderStatus {
pub fn as_str(self) -> &'static str {
match self {
TerminalReaderStatus::Offline => "offline",
TerminalReaderStatus::Online => "online",
}
}
}
impl AsRef<str> for TerminalReaderStatus {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for TerminalReaderStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for TerminalReaderStatus {
fn default() -> Self {
Self::Offline
}
}