refactor(enums): move enums from storage_models and api_models crates to common_enums crate (#1265)

This commit is contained in:
Amisha Prabhat
2023-07-13 17:42:14 +05:30
committed by GitHub
parent b8393d4b50
commit c0e1d4d3b0
40 changed files with 991 additions and 1852 deletions

View File

@ -1,5 +1,759 @@
use router_derive;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
#[doc(hidden)]
pub mod diesel_exports {
pub use super::{
DbAttemptStatus as AttemptStatus, DbAuthenticationType as AuthenticationType,
DbCaptureMethod as CaptureMethod, DbConnectorType as ConnectorType,
DbCountryAlpha2 as CountryAlpha2, DbCurrency as Currency, DbDisputeStage as DisputeStage,
DbDisputeStatus as DisputeStatus, DbEventType as EventType, DbFutureUsage as FutureUsage,
DbIntentStatus as IntentStatus, DbMandateStatus as MandateStatus,
DbPaymentMethodIssuerCode as PaymentMethodIssuerCode, DbRefundStatus as RefundStatus,
};
}
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AttemptStatus {
Started,
AuthenticationFailed,
RouterDeclined,
AuthenticationPending,
AuthenticationSuccessful,
Authorized,
AuthorizationFailed,
Charged,
Authorizing,
CodInitiated,
Voided,
VoidInitiated,
CaptureInitiated,
CaptureFailed,
VoidFailed,
AutoRefunded,
PartialCharged,
Unresolved,
#[default]
Pending,
Failure,
PaymentMethodAwaited,
ConfirmationAwaited,
DeviceDataCollectionPending,
}
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumVariantNames,
strum::EnumIter,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AuthenticationType {
/// If the card is enrolled for 3DS authentication, the 3DS based authentication will be activated. The liability of chargeback shift to the issuer
ThreeDs,
/// 3DS based authentication will not be activated. The liability of chargeback stays with the merchant.
#[default]
NoThreeDs,
}
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumVariantNames,
strum::EnumIter,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum CaptureMethod {
/// Post the payment authorization, the capture will be executed on the full amount immediately
#[default]
Automatic,
/// The capture will happen only if the merchant triggers a Capture API request
Manual,
/// The capture will happen only if the merchant triggers a Capture API request
ManualMultiple,
/// The capture can be scheduled to automatically get triggered at a specific date & time
Scheduled,
}
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
strum::Display,
strum::EnumString,
serde::Deserialize,
serde::Serialize,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[strum(serialize_all = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum ConnectorType {
/// PayFacs, Acquirers, Gateways, BNPL etc
PaymentProcessor,
/// Fraud, Currency Conversion, Crypto etc
PaymentVas,
/// Accounting, Billing, Invoicing, Tax etc
FinOperations,
/// Inventory, ERP, CRM, KYC etc
FizOperations,
/// Payment Networks like Visa, MasterCard etc
Networks,
/// All types of banks including corporate / commercial / personal / neo banks
BankingEntities,
/// All types of non-banking financial institutions including Insurance, Credit / Lending etc
NonBankingFinance,
}
#[allow(clippy::upper_case_acronyms)]
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
strum::EnumIter,
strum::EnumVariantNames,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
pub enum Currency {
AED,
ALL,
AMD,
ANG,
ARS,
AUD,
AWG,
AZN,
BBD,
BDT,
BHD,
BMD,
BND,
BOB,
BRL,
BSD,
BWP,
BZD,
CAD,
CHF,
CNY,
COP,
CRC,
CUP,
CZK,
DKK,
DOP,
DZD,
EGP,
ETB,
EUR,
FJD,
GBP,
GHS,
GIP,
GMD,
GTQ,
GYD,
HKD,
HNL,
HRK,
HTG,
HUF,
IDR,
ILS,
INR,
JMD,
JOD,
JPY,
KES,
KGS,
KHR,
KRW,
KWD,
KYD,
KZT,
LAK,
LBP,
LKR,
LRD,
LSL,
MAD,
MDL,
MKD,
MMK,
MNT,
MOP,
MUR,
MVR,
MWK,
MXN,
MYR,
NAD,
NGN,
NIO,
NOK,
NPR,
NZD,
OMR,
PEN,
PGK,
PHP,
PKR,
PLN,
QAR,
RON,
RUB,
SAR,
SCR,
SEK,
SGD,
SLL,
SOS,
SSP,
SVC,
SZL,
THB,
TRY,
TTD,
TWD,
TZS,
#[default]
USD,
UYU,
UZS,
YER,
ZAR,
}
impl Currency {
pub fn iso_4217(&self) -> &'static str {
match *self {
Self::AED => "784",
Self::ALL => "008",
Self::AMD => "051",
Self::ANG => "532",
Self::ARS => "032",
Self::AUD => "036",
Self::AWG => "533",
Self::AZN => "944",
Self::BBD => "052",
Self::BDT => "050",
Self::BHD => "048",
Self::BMD => "060",
Self::BND => "096",
Self::BOB => "068",
Self::BRL => "986",
Self::BSD => "044",
Self::BWP => "072",
Self::BZD => "084",
Self::CAD => "124",
Self::CHF => "756",
Self::COP => "170",
Self::CRC => "188",
Self::CUP => "192",
Self::CZK => "203",
Self::DKK => "208",
Self::DOP => "214",
Self::DZD => "012",
Self::EGP => "818",
Self::ETB => "230",
Self::EUR => "978",
Self::FJD => "242",
Self::GBP => "826",
Self::GHS => "936",
Self::GIP => "292",
Self::GMD => "270",
Self::GTQ => "320",
Self::GYD => "328",
Self::HKD => "344",
Self::HNL => "340",
Self::HTG => "332",
Self::HUF => "348",
Self::HRK => "191",
Self::IDR => "360",
Self::ILS => "376",
Self::INR => "356",
Self::JMD => "388",
Self::JOD => "400",
Self::JPY => "392",
Self::KES => "404",
Self::KGS => "417",
Self::KHR => "116",
Self::KRW => "410",
Self::KWD => "414",
Self::KYD => "136",
Self::KZT => "398",
Self::LAK => "418",
Self::LBP => "422",
Self::LKR => "144",
Self::LRD => "430",
Self::LSL => "426",
Self::MAD => "504",
Self::MDL => "498",
Self::MKD => "807",
Self::MMK => "104",
Self::MNT => "496",
Self::MOP => "446",
Self::MUR => "480",
Self::MVR => "462",
Self::MWK => "454",
Self::MXN => "484",
Self::MYR => "458",
Self::NAD => "516",
Self::NGN => "566",
Self::NIO => "558",
Self::NOK => "578",
Self::NPR => "524",
Self::NZD => "554",
Self::OMR => "512",
Self::PEN => "604",
Self::PGK => "598",
Self::PHP => "608",
Self::PKR => "586",
Self::PLN => "985",
Self::QAR => "634",
Self::RON => "946",
Self::CNY => "156",
Self::RUB => "643",
Self::SAR => "682",
Self::SCR => "690",
Self::SEK => "752",
Self::SGD => "702",
Self::SLL => "694",
Self::SOS => "706",
Self::SSP => "728",
Self::SVC => "222",
Self::SZL => "748",
Self::THB => "764",
Self::TRY => "949",
Self::TTD => "780",
Self::TWD => "901",
Self::TZS => "834",
Self::USD => "840",
Self::UYU => "858",
Self::UZS => "860",
Self::YER => "886",
Self::ZAR => "710",
}
}
}
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum EventType {
PaymentSucceeded,
PaymentFailed,
PaymentProcessing,
ActionRequired,
RefundSucceeded,
RefundFailed,
DisputeOpened,
DisputeExpired,
DisputeAccepted,
DisputeCancelled,
DisputeChallenged,
DisputeWon,
DisputeLost,
}
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
Hash,
PartialEq,
ToSchema,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum IntentStatus {
Succeeded,
Failed,
Cancelled,
Processing,
RequiresCustomerAction,
RequiresMerchantAction,
RequiresPaymentMethod,
#[default]
RequiresConfirmation,
RequiresCapture,
}
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum FutureUsage {
#[default]
OffSession,
OnSession,
}
#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[strum(serialize_all = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum PaymentMethodIssuerCode {
JpHdfc,
JpIcici,
JpGooglepay,
JpApplepay,
JpPhonepay,
JpWechat,
JpSofort,
JpGiropay,
JpSepa,
JpBacs,
}
#[derive(
Eq,
strum::EnumString,
PartialEq,
Hash,
Copy,
Clone,
Debug,
serde::Serialize,
serde::Deserialize,
strum::Display,
ToSchema,
Default,
)]
#[router_derive::diesel_enum(storage_type = "text")]
#[strum(serialize_all = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum PaymentExperience {
/// The URL to which the customer needs to be redirected for completing the payment.
#[default]
RedirectToUrl,
/// Contains the data for invoking the sdk client for completing the payment.
InvokeSdkClient,
/// The QR code data to be displayed to the customer.
DisplayQrCode,
/// Contains data to finish one click payment.
OneClick,
/// Redirect customer to link wallet
LinkWallet,
/// Contains the data for invoking the sdk client for completing the payment.
InvokePaymentApp,
}
#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumVariantNames,
strum::EnumIter,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "text")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum PaymentMethodType {
Ach,
Affirm,
AfterpayClearpay,
AliPay,
AliPayHk,
ApplePay,
Bacs,
BancontactCard,
Becs,
Blik,
#[serde(rename = "classic")]
ClassicReward,
Credit,
CryptoCurrency,
Debit,
Eps,
Evoucher,
Giropay,
GooglePay,
Ideal,
Interac,
Klarna,
MbWay,
MobilePay,
Multibanco,
OnlineBankingCzechRepublic,
OnlineBankingFinland,
OnlineBankingPoland,
OnlineBankingSlovakia,
PayBright,
Paypal,
Przelewy24,
SamsungPay,
Sepa,
Sofort,
Swish,
Trustly,
UpiCollect,
Walley,
WeChatPay,
}
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumVariantNames,
strum::EnumIter,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "text")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum PaymentMethod {
#[default]
Card,
PayLater,
Wallet,
BankRedirect,
BankTransfer,
Crypto,
BankDebit,
Reward,
Upi,
}
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
Hash,
PartialEq,
strum::Display,
strum::EnumString,
serde::Serialize,
serde::Deserialize,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[strum(serialize_all = "snake_case")]
pub enum RefundStatus {
Failure,
ManualReview,
#[default]
Pending,
Success,
TransactionFailure,
}
/// The status of the mandate, which indicates whether it can be used to initiate a payment
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
Default,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum MandateStatus {
#[default]
Active,
Inactive,
Pending,
Revoked,
}
#[derive(
Clone,
Debug,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumVariantNames,
strum::EnumIter,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "text")]
pub enum CardNetwork {
Visa,
Mastercard,
AmericanExpress,
JCB,
DinersClub,
Discover,
CartesBancaires,
UnionPay,
Interac,
RuPay,
Maestro,
}
#[derive(
Clone,
Copy,
Default,
Debug,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum DisputeStage {
PreDispute,
#[default]
Dispute,
PreArbitration,
}
#[derive(
Clone,
Debug,
Copy,
Default,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum DisputeStatus {
#[default]
DisputeOpened,
DisputeExpired,
DisputeAccepted,
DisputeCancelled,
DisputeChallenged,
// dispute has been successfully challenged by the merchant
DisputeWon,
// dispute has been unsuccessfully challenged
DisputeLost,
}
#[derive(
Clone,
@ -61,7 +815,20 @@ pub enum CountryAlpha3 {
VEN, VNM, VGB, VIR, WLF, ESH, YEM, ZMB, ZWE
}
#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)]
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
strum::Display,
strum::EnumVariantNames,
strum::EnumIter,
strum::EnumString,
Deserialize,
Serialize,
)]
pub enum Country {
Afghanistan,
AlandIslands,

View File

@ -2,7 +2,7 @@ use std::fmt::{Display, Formatter};
use serde::{Deserialize, Serialize};
use crate::enums::{Country, CountryAlpha2, CountryAlpha3};
use crate::enums::{Country, CountryAlpha2, CountryAlpha3, PaymentMethod, PaymentMethodType};
impl Display for NumericCountryCodeParseError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
@ -1532,6 +1532,52 @@ impl Country {
}
}
impl From<PaymentMethodType> for PaymentMethod {
fn from(value: PaymentMethodType) -> Self {
match value {
PaymentMethodType::Ach => Self::BankDebit,
PaymentMethodType::Affirm => Self::PayLater,
PaymentMethodType::AfterpayClearpay => Self::PayLater,
PaymentMethodType::AliPay => Self::Wallet,
PaymentMethodType::AliPayHk => Self::Wallet,
PaymentMethodType::ApplePay => Self::Wallet,
PaymentMethodType::Bacs => Self::BankDebit,
PaymentMethodType::BancontactCard => Self::BankRedirect,
PaymentMethodType::Becs => Self::BankDebit,
PaymentMethodType::Blik => Self::BankRedirect,
PaymentMethodType::ClassicReward => Self::Reward,
PaymentMethodType::Credit => Self::Card,
PaymentMethodType::CryptoCurrency => Self::Crypto,
PaymentMethodType::Debit => Self::Card,
PaymentMethodType::Eps => Self::BankRedirect,
PaymentMethodType::Evoucher => Self::Reward,
PaymentMethodType::Giropay => Self::BankRedirect,
PaymentMethodType::GooglePay => Self::Wallet,
PaymentMethodType::Ideal => Self::BankRedirect,
PaymentMethodType::Klarna => Self::PayLater,
PaymentMethodType::MbWay => Self::Wallet,
PaymentMethodType::MobilePay => Self::Wallet,
PaymentMethodType::Multibanco => Self::BankTransfer,
PaymentMethodType::Interac => Self::BankRedirect,
PaymentMethodType::OnlineBankingCzechRepublic => Self::BankRedirect,
PaymentMethodType::OnlineBankingFinland => Self::BankRedirect,
PaymentMethodType::OnlineBankingPoland => Self::BankRedirect,
PaymentMethodType::OnlineBankingSlovakia => Self::BankRedirect,
PaymentMethodType::PayBright => Self::PayLater,
PaymentMethodType::Paypal => Self::Wallet,
PaymentMethodType::Przelewy24 => Self::BankRedirect,
PaymentMethodType::SamsungPay => Self::Wallet,
PaymentMethodType::Sepa => Self::BankDebit,
PaymentMethodType::Sofort => Self::BankRedirect,
PaymentMethodType::Swish => Self::BankRedirect,
PaymentMethodType::Trustly => Self::BankRedirect,
PaymentMethodType::UpiCollect => Self::Upi,
PaymentMethodType::Walley => Self::PayLater,
PaymentMethodType::WeChatPay => Self::Wallet,
}
}
}
#[derive(Debug)]
pub struct NumericCountryCodeParseError;
#[allow(dead_code)]