use crate::payments::adapters::service_unavailable::ServiceUnavailablePaymentProcessor;
#[cfg(feature = "payments-stripe")]
#[allow(unused)]
use crate::payments::adapters::stripe::StripePaymentProcessor;
use crate::payments::{Error, PaymentProcessor};
use crate::storage::config_store::ConfigStore;
use std::str::FromStr;
use std::sync::Arc;
#[cfg(feature = "payments-stripe")]
pub const STRIPE_ACCESS_TOKEN: &str = "STRIPE_ACCESS_TOKEN";
pub async fn new<B: Clone + FromStr + Send + Sync + ToString + 'static>(
app_name: &str,
#[allow(unused)] config_store: Arc<dyn ConfigStore<B>>,
) -> Result<Arc<dyn PaymentProcessor<B>>, Error> {
#[cfg(feature = "payments-stripe")]
if let Ok(access_token) = std::env::var(STRIPE_ACCESS_TOKEN) {
return Ok(Arc::new(StripePaymentProcessor::new(
app_name,
&access_token,
config_store,
)));
}
Ok(Arc::new(ServiceUnavailablePaymentProcessor::new(app_name)))
}