use super::*;
impl RefundReason {
pub const fn as_str(&self) -> &'static str {
match self {
RefundReason::RequestedByCustomer => REASON_REQUESTED_BY_CUSTOMER,
RefundReason::Duplicate => REASON_DUPLICATE,
RefundReason::Fraudulent => REASON_FRAUDULENT,
RefundReason::OrderCancellation => REASON_ORDER_CANCELLATION,
}
}
pub const fn is_involuntary(&self) -> bool {
matches!(self, RefundReason::Duplicate | RefundReason::Fraudulent)
}
}
impl Display for RefundReason {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
write!(formatter, "{}", self.as_str())
}
}
impl Refund {
pub fn new(id: String, charge: String, amount: Money, reason: RefundReason) -> Self {
Self {
id,
charge,
amount: amount.get_amount(),
currency: String::from(amount.currency_code()),
reason,
succeeded: true,
}
}
pub fn get_amount(&self) -> Result<Money, StripeParseError> {
let currency: Currency = self.currency.parse()?;
Ok(Money::from_minor(self.amount, currency))
}
pub fn is_succeeded(&self) -> bool {
self.get_succeeded()
}
pub fn is_involuntary(&self) -> bool {
self.get_reason().is_involuntary()
}
}