Skip to content

Commit

Permalink
pre payment network tokenization
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSagnik007 committed Dec 23, 2024
1 parent c99b100 commit 3f9c0ba
Show file tree
Hide file tree
Showing 20 changed files with 330 additions and 39 deletions.
22 changes: 22 additions & 0 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,10 @@ pub struct ProfileCreate {
/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<HashMap<String, id_type::MerchantConnectorAccountId>>,

/// Indicates if network tokenization before first payment is enabled or not
#[serde(default)]
pub is_tokenize_before_payment_enabled: bool,
}

#[nutype::nutype(
Expand Down Expand Up @@ -2090,6 +2094,10 @@ pub struct ProfileCreate {
/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<HashMap<String, id_type::MerchantConnectorAccountId>>,

/// Indicates if network tokenization before first payment is enabled or not
#[serde(default)]
pub is_tokenize_before_payment_enabled: bool,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -2226,6 +2234,9 @@ pub struct ProfileResponse {
/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<serde_json::Value>,

/// Indicates if network tokenization before first payment is enabled or not
pub is_tokenize_before_payment_enabled: bool,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -2349,6 +2360,9 @@ pub struct ProfileResponse {
/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<serde_json::Value>,

/// Indicates if network tokenization before first payment is enabled or not
pub is_tokenize_before_payment_enabled: bool,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -2479,6 +2493,10 @@ pub struct ProfileUpdate {
/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<HashMap<String, id_type::MerchantConnectorAccountId>>,

/// Indicates if network tokenization before first payment is enabled or not
#[schema(default = false, example = false)]
pub is_tokenize_before_payment_enabled: Option<bool>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -2590,6 +2608,10 @@ pub struct ProfileUpdate {
/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<HashMap<String, id_type::MerchantConnectorAccountId>>,

/// Indicates if network tokenization before first payment is enabled or not
#[schema(default = false, example = false)]
pub is_tokenize_before_payment_enabled: Option<bool>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
Expand Down
6 changes: 6 additions & 0 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub struct Profile {
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<serde_json::Value>,
pub is_tokenize_before_payment_enabled: bool,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -104,6 +105,7 @@ pub struct ProfileNew {
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<serde_json::Value>,
pub is_tokenize_before_payment_enabled: Option<bool>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -146,6 +148,7 @@ pub struct ProfileUpdateInternal {
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: Option<bool>,
pub authentication_product_ids: Option<serde_json::Value>,
pub is_tokenize_before_payment_enabled: Option<bool>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -187,6 +190,7 @@ impl ProfileUpdateInternal {
max_auto_retries_enabled,
is_click_to_pay_enabled,
authentication_product_ids,
is_tokenize_before_payment_enabled,
} = self;
Profile {
profile_id: source.profile_id,
Expand Down Expand Up @@ -250,6 +254,8 @@ impl ProfileUpdateInternal {
.unwrap_or(source.is_click_to_pay_enabled),
authentication_product_ids: authentication_product_ids
.or(source.authentication_product_ids),
is_tokenize_before_payment_enabled: is_tokenize_before_payment_enabled
.unwrap_or(source.is_tokenize_before_payment_enabled),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ diesel::table! {
max_auto_retries_enabled -> Nullable<Int2>,
is_click_to_pay_enabled -> Bool,
authentication_product_ids -> Nullable<Jsonb>,
is_tokenize_before_payment_enabled -> Bool,
}
}

Expand Down
27 changes: 27 additions & 0 deletions crates/hyperswitch_domain_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct Profile {
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<serde_json::Value>,
pub is_tokenize_before_payment_enabled: bool,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -102,6 +103,7 @@ pub struct ProfileSetter {
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<serde_json::Value>,
pub is_tokenize_before_payment_enabled: bool,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -151,6 +153,7 @@ impl From<ProfileSetter> for Profile {
max_auto_retries_enabled: value.max_auto_retries_enabled,
is_click_to_pay_enabled: value.is_click_to_pay_enabled,
authentication_product_ids: value.authentication_product_ids,
is_tokenize_before_payment_enabled: value.is_tokenize_before_payment_enabled,
}
}
}
Expand Down Expand Up @@ -202,6 +205,7 @@ pub struct ProfileGeneralUpdate {
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: Option<bool>,
pub authentication_product_ids: Option<serde_json::Value>,
pub is_tokenize_before_payment_enabled: Option<bool>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -266,6 +270,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled,
is_click_to_pay_enabled,
authentication_product_ids,
is_tokenize_before_payment_enabled,
} = *update;

Self {
Expand Down Expand Up @@ -305,6 +310,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled,
is_click_to_pay_enabled,
authentication_product_ids,
is_tokenize_before_payment_enabled,
}
}
ProfileUpdate::RoutingAlgorithmUpdate {
Expand Down Expand Up @@ -346,6 +352,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::DynamicRoutingAlgorithmUpdate {
dynamic_routing_algorithm,
Expand Down Expand Up @@ -385,6 +392,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::ExtendedCardInfoUpdate {
is_extended_card_info_enabled,
Expand Down Expand Up @@ -424,6 +432,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::ConnectorAgnosticMitUpdate {
is_connector_agnostic_mit_enabled,
Expand Down Expand Up @@ -463,6 +472,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::NetworkTokenizationUpdate {
is_network_tokenization_enabled,
Expand Down Expand Up @@ -502,6 +512,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
}
}
Expand Down Expand Up @@ -560,6 +571,7 @@ impl super::behaviour::Conversion for Profile {
max_auto_retries_enabled: self.max_auto_retries_enabled,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids: self.authentication_product_ids,
is_tokenize_before_payment_enabled: self.is_tokenize_before_payment_enabled,
})
}

Expand Down Expand Up @@ -630,6 +642,7 @@ impl super::behaviour::Conversion for Profile {
max_auto_retries_enabled: item.max_auto_retries_enabled,
is_click_to_pay_enabled: item.is_click_to_pay_enabled,
authentication_product_ids: item.authentication_product_ids,
is_tokenize_before_payment_enabled: item.is_network_tokenization_enabled,
})
}
.await
Expand Down Expand Up @@ -684,6 +697,7 @@ impl super::behaviour::Conversion for Profile {
max_auto_retries_enabled: self.max_auto_retries_enabled,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids: self.authentication_product_ids,
is_tokenize_before_payment_enabled: Some(self.is_tokenize_before_payment_enabled),
})
}
}
Expand Down Expand Up @@ -730,6 +744,7 @@ pub struct Profile {
pub is_network_tokenization_enabled: bool,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<serde_json::Value>,
pub is_tokenize_before_payment_enabled: bool,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -772,6 +787,7 @@ pub struct ProfileSetter {
pub is_network_tokenization_enabled: bool,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<serde_json::Value>,
pub is_tokenize_before_payment_enabled: bool,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -821,6 +837,7 @@ impl From<ProfileSetter> for Profile {
is_network_tokenization_enabled: value.is_network_tokenization_enabled,
is_click_to_pay_enabled: value.is_click_to_pay_enabled,
authentication_product_ids: value.authentication_product_ids,
is_tokenize_before_payment_enabled: value.is_tokenize_before_payment_enabled,
}
}
}
Expand Down Expand Up @@ -973,6 +990,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids,
is_tokenize_before_payment_enabled: None,
}
}
ProfileUpdate::RoutingAlgorithmUpdate {
Expand Down Expand Up @@ -1016,6 +1034,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::ExtendedCardInfoUpdate {
is_extended_card_info_enabled,
Expand Down Expand Up @@ -1057,6 +1076,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::ConnectorAgnosticMitUpdate {
is_connector_agnostic_mit_enabled,
Expand Down Expand Up @@ -1098,6 +1118,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::DefaultRoutingFallbackUpdate {
default_fallback_routing,
Expand Down Expand Up @@ -1139,6 +1160,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::NetworkTokenizationUpdate {
is_network_tokenization_enabled,
Expand Down Expand Up @@ -1180,6 +1202,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::CollectCvvDuringPaymentUpdate {
should_collect_cvv_during_payment,
Expand Down Expand Up @@ -1221,6 +1244,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
authentication_product_ids: None,
is_tokenize_before_payment_enabled: None,
},
}
}
Expand Down Expand Up @@ -1282,6 +1306,7 @@ impl super::behaviour::Conversion for Profile {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids: self.authentication_product_ids,
is_tokenize_before_payment_enabled: self.is_tokenize_before_payment_enabled,
})
}

Expand Down Expand Up @@ -1352,6 +1377,7 @@ impl super::behaviour::Conversion for Profile {
is_network_tokenization_enabled: item.is_network_tokenization_enabled,
is_click_to_pay_enabled: item.is_click_to_pay_enabled,
authentication_product_ids: item.authentication_product_ids,
is_tokenize_before_payment_enabled: item.is_tokenize_before_payment_enabled,
})
}
.await
Expand Down Expand Up @@ -1409,6 +1435,7 @@ impl super::behaviour::Conversion for Profile {
max_auto_retries_enabled: None,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids: self.authentication_product_ids,
is_tokenize_before_payment_enabled: self.is_tokenize_before_payment_enabled,
})
}
}
2 changes: 2 additions & 0 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3701,6 +3701,7 @@ impl ProfileCreateBridge for api::ProfileCreate {
max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from),
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids,
is_tokenize_before_payment_enabled: self.is_tokenize_before_payment_enabled,
}))
}

Expand Down Expand Up @@ -4075,6 +4076,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate {
max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from),
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids,
is_tokenize_before_payment_enabled: self.is_tokenize_before_payment_enabled,
},
)))
}
Expand Down
15 changes: 8 additions & 7 deletions crates/router/src/core/payment_methods/network_tokenization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,22 @@ pub struct GetCardToken {
}
#[derive(Debug, Deserialize)]
pub struct AuthenticationDetails {
cryptogram: Secret<String>,
token: CardNumber, //network token
pub cryptogram: Secret<String>,
pub token: CardNumber, //network token
}

#[derive(Debug, Serialize, Deserialize)]
pub struct TokenDetails {
exp_month: Secret<String>,
exp_year: Secret<String>,
pub exp_month: Secret<String>,
pub exp_year: Secret<String>,
}

#[derive(Debug, Deserialize)]
pub struct TokenResponse {
authentication_details: AuthenticationDetails,
network: api_enums::CardNetwork,
token_details: TokenDetails,
pub authentication_details: AuthenticationDetails,
pub network: api_enums::CardNetwork,
pub token_details: TokenDetails,
pub eci: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
Loading

0 comments on commit 3f9c0ba

Please sign in to comment.