mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
feat(connector): [payload] add recurring payments (#8597)
This commit is contained in:
@ -88,7 +88,7 @@ pub struct ConnectorAuthentication {
|
||||
pub opennode: Option<HeaderKey>,
|
||||
pub paybox: Option<HeaderKey>,
|
||||
pub payeezy: Option<SignatureKey>,
|
||||
pub payload: Option<HeaderKey>,
|
||||
pub payload: Option<CurrencyAuthKey>,
|
||||
pub payme: Option<BodyKey>,
|
||||
pub payone: Option<HeaderKey>,
|
||||
pub paypal: Option<BodyKey>,
|
||||
@ -220,54 +220,78 @@ impl ConnectorAuthenticationMap {
|
||||
.into_iter()
|
||||
.map(|(connector_name, config)| {
|
||||
let auth_type = match config {
|
||||
toml::Value::Table(table) => {
|
||||
match (
|
||||
table.get("api_key"),
|
||||
table.get("key1"),
|
||||
table.get("api_secret"),
|
||||
table.get("key2"),
|
||||
) {
|
||||
(Some(api_key), None, None, None) => ConnectorAuthType::HeaderKey {
|
||||
api_key: Secret::new(
|
||||
api_key.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
},
|
||||
(Some(api_key), Some(key1), None, None) => ConnectorAuthType::BodyKey {
|
||||
api_key: Secret::new(
|
||||
api_key.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
key1: Secret::new(key1.as_str().unwrap_or_default().to_string()),
|
||||
},
|
||||
(Some(api_key), Some(key1), Some(api_secret), None) => {
|
||||
ConnectorAuthType::SignatureKey {
|
||||
toml::Value::Table(mut table) => {
|
||||
if let Some(auth_key_map_value) = table.remove("auth_key_map") {
|
||||
// This is a CurrencyAuthKey
|
||||
if let toml::Value::Table(auth_key_map_table) = auth_key_map_value {
|
||||
let mut parsed_auth_map = HashMap::new();
|
||||
for (currency, val) in auth_key_map_table {
|
||||
if let Ok(currency_enum) =
|
||||
currency.parse::<common_enums::Currency>()
|
||||
{
|
||||
parsed_auth_map
|
||||
.insert(currency_enum, Secret::new(val.to_string()));
|
||||
}
|
||||
}
|
||||
ConnectorAuthType::CurrencyAuthKey {
|
||||
auth_key_map: parsed_auth_map,
|
||||
}
|
||||
} else {
|
||||
ConnectorAuthType::NoKey
|
||||
}
|
||||
} else {
|
||||
match (
|
||||
table.get("api_key"),
|
||||
table.get("key1"),
|
||||
table.get("api_secret"),
|
||||
table.get("key2"),
|
||||
) {
|
||||
(Some(api_key), None, None, None) => ConnectorAuthType::HeaderKey {
|
||||
api_key: Secret::new(
|
||||
api_key.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
key1: Secret::new(
|
||||
key1.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
api_secret: Secret::new(
|
||||
api_secret.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
},
|
||||
(Some(api_key), Some(key1), None, None) => {
|
||||
ConnectorAuthType::BodyKey {
|
||||
api_key: Secret::new(
|
||||
api_key.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
key1: Secret::new(
|
||||
key1.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
(Some(api_key), Some(key1), Some(api_secret), Some(key2)) => {
|
||||
ConnectorAuthType::MultiAuthKey {
|
||||
api_key: Secret::new(
|
||||
api_key.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
key1: Secret::new(
|
||||
key1.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
api_secret: Secret::new(
|
||||
api_secret.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
key2: Secret::new(
|
||||
key2.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
(Some(api_key), Some(key1), Some(api_secret), None) => {
|
||||
ConnectorAuthType::SignatureKey {
|
||||
api_key: Secret::new(
|
||||
api_key.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
key1: Secret::new(
|
||||
key1.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
api_secret: Secret::new(
|
||||
api_secret.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
}
|
||||
}
|
||||
(Some(api_key), Some(key1), Some(api_secret), Some(key2)) => {
|
||||
ConnectorAuthType::MultiAuthKey {
|
||||
api_key: Secret::new(
|
||||
api_key.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
key1: Secret::new(
|
||||
key1.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
api_secret: Secret::new(
|
||||
api_secret.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
key2: Secret::new(
|
||||
key2.as_str().unwrap_or_default().to_string(),
|
||||
),
|
||||
}
|
||||
}
|
||||
_ => ConnectorAuthType::NoKey,
|
||||
}
|
||||
_ => ConnectorAuthType::NoKey,
|
||||
}
|
||||
}
|
||||
_ => ConnectorAuthType::NoKey,
|
||||
@ -275,7 +299,6 @@ impl ConnectorAuthenticationMap {
|
||||
(connector_name, auth_type)
|
||||
})
|
||||
.collect();
|
||||
|
||||
Self(auth_map)
|
||||
}
|
||||
}
|
||||
@ -344,6 +367,25 @@ impl From<MultiAuthKey> for ConnectorAuthType {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CurrencyAuthKey {
|
||||
pub auth_key_map: HashMap<String, toml::Value>,
|
||||
}
|
||||
|
||||
impl From<CurrencyAuthKey> for ConnectorAuthType {
|
||||
fn from(key: CurrencyAuthKey) -> Self {
|
||||
let mut auth_map = HashMap::new();
|
||||
for (currency, auth_data) in key.auth_key_map {
|
||||
if let Ok(currency_enum) = currency.parse::<common_enums::Currency>() {
|
||||
auth_map.insert(currency_enum, Secret::new(auth_data.to_string()));
|
||||
}
|
||||
}
|
||||
Self::CurrencyAuthKey {
|
||||
auth_key_map: auth_map,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct NoKey {}
|
||||
|
||||
@ -396,6 +438,9 @@ pub enum ConnectorAuthType {
|
||||
api_secret: Secret<String>,
|
||||
key2: Secret<String>,
|
||||
},
|
||||
CurrencyAuthKey {
|
||||
auth_key_map: HashMap<common_enums::Currency, Secret<String>>,
|
||||
},
|
||||
#[default]
|
||||
NoKey,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user