feat(connector): [payload] add recurring payments (#8597)

This commit is contained in:
Pa1NarK
2025-07-31 12:21:44 +05:30
committed by GitHub
parent d4d7397b0a
commit 64e6dc860d
22 changed files with 393 additions and 182 deletions

View File

@ -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,
}