use super::*;
impl ChargeStatus {
pub const fn as_str(&self) -> &'static str {
match self {
ChargeStatus::Pending => CHARGE_STATUS_PENDING,
ChargeStatus::Succeeded => CHARGE_STATUS_SUCCEEDED,
ChargeStatus::Authorized => CHARGE_STATUS_AUTHORIZED,
ChargeStatus::Failed => CHARGE_STATUS_FAILED,
}
}
pub const fn is_captured(&self) -> bool {
matches!(self, ChargeStatus::Succeeded)
}
}
impl Display for ChargeStatus {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
write!(formatter, "{}", self.as_str())
}
}
impl PaymentMethodKind {
pub const fn as_str(&self) -> &'static str {
match self {
PaymentMethodKind::Card => METHOD_KIND_CARD,
PaymentMethodKind::SepaDebit => METHOD_KIND_SEPA_DEBIT,
PaymentMethodKind::BankTransfer => METHOD_KIND_BANK_TRANSFER,
PaymentMethodKind::Wallet => METHOD_KIND_WALLET,
}
}
}
impl Charge {
pub fn new(
id: String,
amount: Money,
status: ChargeStatus,
payment_method_kind: PaymentMethodKind,
) -> Self {
Self {
id,
amount: amount.get_amount(),
currency: String::from(amount.currency_code()),
status,
payment_method_kind,
disputed: false,
payment_intent: None,
}
}
pub fn get_amount(&self) -> Result<Money, StripeParseError> {
let currency: Currency = self.currency.parse()?;
Ok(Money::from_minor(self.amount, currency))
}
pub fn is_disputed(&self) -> bool {
self.get_disputed()
}
pub fn is_captured(&self) -> bool {
self.get_status().is_captured()
}
}