backbone_pos/domain/entity/
pos_payment_method.rs1use serde::{Deserialize, Serialize};
2use sqlx::Type;
3use std::str::FromStr;
4#[cfg(feature = "openapi")]
5use utoipa::ToSchema;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
8#[cfg_attr(feature = "openapi", derive(ToSchema))]
9#[serde(rename_all = "snake_case")]
10#[sqlx(type_name = "pos_payment_method", rename_all = "snake_case")]
11pub enum PosPaymentMethod {
12 Cash,
13 Card,
14 Qris,
15 EWallet,
16 BankTransfer,
17 VirtualAccount,
18}
19
20impl std::fmt::Display for PosPaymentMethod {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 match self {
23 Self::Cash => write!(f, "cash"),
24 Self::Card => write!(f, "card"),
25 Self::Qris => write!(f, "qris"),
26 Self::EWallet => write!(f, "e_wallet"),
27 Self::BankTransfer => write!(f, "bank_transfer"),
28 Self::VirtualAccount => write!(f, "virtual_account"),
29 }
30 }
31}
32
33impl FromStr for PosPaymentMethod {
34 type Err = String;
35
36 fn from_str(s: &str) -> Result<Self, Self::Err> {
37 match s.to_lowercase().as_str() {
38 "cash" => Ok(Self::Cash),
39 "card" => Ok(Self::Card),
40 "qris" => Ok(Self::Qris),
41 "e_wallet" => Ok(Self::EWallet),
42 "bank_transfer" => Ok(Self::BankTransfer),
43 "virtual_account" => Ok(Self::VirtualAccount),
44 _ => Err(format!("Unknown PosPaymentMethod variant: {}", s)),
45 }
46 }
47}
48
49impl Default for PosPaymentMethod {
50 fn default() -> Self {
51 Self::Cash
52 }
53}