use super::mpp::detect_realm;
pub use crate::protocol::methods::stripe::method::ChargeMethod as StripeChargeMethod;
pub use crate::protocol::methods::stripe::{StripeCredentialPayload, StripeMethodDetails};
pub struct StripeConfig<'a> {
pub secret_key: &'a str,
pub network_id: &'a str,
pub payment_method_types: &'a [&'a str],
pub currency: &'a str,
pub decimals: u8,
}
#[derive(Debug, Default)]
pub struct StripeChargeOptions<'a> {
pub description: Option<&'a str>,
pub external_id: Option<&'a str>,
pub expires: Option<&'a str>,
pub metadata: Option<&'a std::collections::HashMap<String, String>>,
}
pub struct StripeBuilder {
pub(crate) secret_key: String,
pub(crate) network_id: String,
pub(crate) payment_method_types: Vec<String>,
pub(crate) currency: String,
pub(crate) decimals: u8,
pub(crate) realm: String,
pub(crate) hmac_secret_key: Option<String>,
pub(crate) stripe_api_base: Option<String>,
}
impl StripeBuilder {
pub fn realm(mut self, realm: &str) -> Self {
self.realm = realm.to_string();
self
}
pub fn secret_key(mut self, key: &str) -> Self {
self.hmac_secret_key = Some(key.to_string());
self
}
pub fn stripe_api_base(mut self, url: &str) -> Self {
self.stripe_api_base = Some(url.to_string());
self
}
}
pub fn stripe(config: StripeConfig<'_>) -> StripeBuilder {
StripeBuilder {
secret_key: config.secret_key.to_string(),
network_id: config.network_id.to_string(),
payment_method_types: config
.payment_method_types
.iter()
.map(|s| s.to_string())
.collect(),
currency: config.currency.to_string(),
decimals: config.decimals,
realm: detect_realm(),
hmac_secret_key: None,
stripe_api_base: None,
}
}