use std::fmt;
use crate::charge::{Charge, ChargeRequest, PaymentId};
use crate::error::Error;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ProviderId(&'static str);
impl ProviderId {
pub const STRIPE: Self = Self("stripe");
pub const IYZICO: Self = Self("iyzico");
#[must_use]
pub const fn new(name: &'static str) -> Self {
Self(name)
}
#[must_use]
pub const fn as_str(self) -> &'static str {
self.0
}
}
impl fmt::Display for ProviderId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.0)
}
}
#[async_trait::async_trait]
pub trait Provider: fmt::Debug + Send + Sync {
fn id(&self) -> ProviderId;
async fn charge(&self, request: &ChargeRequest) -> Result<Charge, Error>;
async fn charge_status(&self, id: &PaymentId) -> Result<Charge, Error>;
}