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 18, 2024
1 parent ce42fcf commit 276d588
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 8 deletions.
8 changes: 8 additions & 0 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,10 @@ pub struct ProfileCreate {
/// Indicates if click to pay is enabled or not.
#[serde(default)]
pub is_click_to_pay_enabled: bool,

/// 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 @@ -2459,6 +2463,10 @@ pub struct ProfileUpdate {
/// Indicates if click to pay is enabled or not.
#[schema(default = false, example = false)]
pub is_click_to_pay_enabled: Option<bool>,

/// 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
5 changes: 5 additions & 0 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct Profile {
pub is_auto_retries_enabled: Option<bool>,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub is_tokenize_before_payment_enabled: bool,
}

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

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

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -183,6 +186,7 @@ impl ProfileUpdateInternal {
is_auto_retries_enabled,
max_auto_retries_enabled,
is_click_to_pay_enabled,
is_tokenize_before_payment_enabled,
} = self;
Profile {
profile_id: source.profile_id,
Expand Down Expand Up @@ -244,6 +248,7 @@ impl ProfileUpdateInternal {
max_auto_retries_enabled: max_auto_retries_enabled.or(source.max_auto_retries_enabled),
is_click_to_pay_enabled: is_click_to_pay_enabled
.unwrap_or(source.is_click_to_pay_enabled),
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 @@ -213,6 +213,7 @@ diesel::table! {
is_network_tokenization_enabled -> Bool,
is_auto_retries_enabled -> Nullable<Bool>,
max_auto_retries_enabled -> Nullable<Int2>,
is_tokenize_before_payment_enabled -> Bool,
is_click_to_pay_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 @@ -59,6 +59,7 @@ pub struct Profile {
pub is_auto_retries_enabled: bool,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub is_tokenize_before_payment_enabled: bool,
}

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

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -148,6 +150,7 @@ impl From<ProfileSetter> for Profile {
is_auto_retries_enabled: value.is_auto_retries_enabled,
max_auto_retries_enabled: value.max_auto_retries_enabled,
is_click_to_pay_enabled: value.is_click_to_pay_enabled,
is_tokenize_before_payment_enabled: value.is_tokenize_before_payment_enabled,
}
}
}
Expand Down Expand Up @@ -198,6 +201,7 @@ pub struct ProfileGeneralUpdate {
pub is_auto_retries_enabled: Option<bool>,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: Option<bool>,
pub is_tokenize_before_payment_enabled: Option<bool>,
}

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

Self {
Expand Down Expand Up @@ -299,6 +304,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled,
max_auto_retries_enabled,
is_click_to_pay_enabled,
is_tokenize_before_payment_enabled,
}
}
ProfileUpdate::RoutingAlgorithmUpdate {
Expand Down Expand Up @@ -339,6 +345,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::DynamicRoutingAlgorithmUpdate {
dynamic_routing_algorithm,
Expand Down Expand Up @@ -377,6 +384,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::ExtendedCardInfoUpdate {
is_extended_card_info_enabled,
Expand Down Expand Up @@ -415,6 +423,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::ConnectorAgnosticMitUpdate {
is_connector_agnostic_mit_enabled,
Expand Down Expand Up @@ -453,6 +462,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::NetworkTokenizationUpdate {
is_network_tokenization_enabled,
Expand Down Expand Up @@ -491,6 +501,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
}
}
Expand Down Expand Up @@ -548,6 +559,7 @@ impl super::behaviour::Conversion for Profile {
is_auto_retries_enabled: Some(self.is_auto_retries_enabled),
max_auto_retries_enabled: self.max_auto_retries_enabled,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
is_tokenize_before_payment_enabled: self.is_tokenize_before_payment_enabled,
})
}

Expand Down Expand Up @@ -617,6 +629,7 @@ impl super::behaviour::Conversion for Profile {
is_auto_retries_enabled: item.is_auto_retries_enabled.unwrap_or(false),
max_auto_retries_enabled: item.max_auto_retries_enabled,
is_click_to_pay_enabled: item.is_click_to_pay_enabled,
is_tokenize_before_payment_enabled: item.is_network_tokenization_enabled,
})
}
.await
Expand Down Expand Up @@ -670,6 +683,7 @@ impl super::behaviour::Conversion for Profile {
is_auto_retries_enabled: Some(self.is_auto_retries_enabled),
max_auto_retries_enabled: self.max_auto_retries_enabled,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
is_tokenize_before_payment_enabled: Some(self.is_tokenize_before_payment_enabled),
})
}
}
Expand Down Expand Up @@ -715,6 +729,7 @@ pub struct Profile {
pub version: common_enums::ApiVersion,
pub is_network_tokenization_enabled: bool,
pub is_click_to_pay_enabled: bool,
pub is_tokenize_before_payment_enabled: bool,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -756,6 +771,7 @@ pub struct ProfileSetter {
pub is_tax_connector_enabled: bool,
pub is_network_tokenization_enabled: bool,
pub is_click_to_pay_enabled: bool,
pub is_tokenize_before_payment_enabled: bool,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -804,6 +820,7 @@ impl From<ProfileSetter> for Profile {
version: consts::API_VERSION,
is_network_tokenization_enabled: value.is_network_tokenization_enabled,
is_click_to_pay_enabled: value.is_click_to_pay_enabled,
is_tokenize_before_payment_enabled: value.is_tokenize_before_payment_enabled,
}
}
}
Expand Down Expand Up @@ -953,6 +970,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled,
is_tokenize_before_payment_enabled: None,
}
}
ProfileUpdate::RoutingAlgorithmUpdate {
Expand Down Expand Up @@ -995,6 +1013,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::ExtendedCardInfoUpdate {
is_extended_card_info_enabled,
Expand Down Expand Up @@ -1035,6 +1054,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::ConnectorAgnosticMitUpdate {
is_connector_agnostic_mit_enabled,
Expand Down Expand Up @@ -1075,6 +1095,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::DefaultRoutingFallbackUpdate {
default_fallback_routing,
Expand Down Expand Up @@ -1115,6 +1136,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::NetworkTokenizationUpdate {
is_network_tokenization_enabled,
Expand Down Expand Up @@ -1155,6 +1177,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
ProfileUpdate::CollectCvvDuringPaymentUpdate {
should_collect_cvv_during_payment,
Expand Down Expand Up @@ -1195,6 +1218,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: None,
is_tokenize_before_payment_enabled: None,
},
}
}
Expand Down Expand Up @@ -1255,6 +1279,7 @@ impl super::behaviour::Conversion for Profile {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
is_tokenize_before_payment_enabled: self.is_tokenize_before_payment_enabled,
})
}

Expand Down Expand Up @@ -1324,6 +1349,7 @@ impl super::behaviour::Conversion for Profile {
version: item.version,
is_network_tokenization_enabled: item.is_network_tokenization_enabled,
is_click_to_pay_enabled: item.is_click_to_pay_enabled,
is_tokenize_before_payment_enabled: item.is_tokenize_before_payment_enabled,
})
}
.await
Expand Down Expand Up @@ -1380,6 +1406,7 @@ impl super::behaviour::Conversion for Profile {
is_auto_retries_enabled: None,
max_auto_retries_enabled: None,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
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 @@ -3556,6 +3556,7 @@ impl ProfileCreateBridge for api::ProfileCreate {
is_auto_retries_enabled: self.is_auto_retries_enabled.unwrap_or_default(),
max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from),
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
is_tokenize_before_payment_enabled: self.is_tokenize_before_payment_enabled,
}))
}

Expand Down Expand Up @@ -3914,6 +3915,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate {
is_auto_retries_enabled: self.is_auto_retries_enabled,
max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from),
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
is_tokenize_before_payment_enabled: self.is_tokenize_before_payment_enabled,
},
)))
}
Expand Down
16 changes: 8 additions & 8 deletions crates/router/src/core/payment_methods/network_tokenization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct CardNetworkTokenResponse {
pub struct CardNetworkTokenResponsePayload {
pub card_brand: api_enums::CardNetwork,
pub card_fingerprint: Option<Secret<String>>,
pub card_reference: String,
pub card_reference: String,//
pub correlation_id: String,
pub customer_id: String,
pub par: String,
Expand All @@ -79,21 +79,21 @@ 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,
}

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

0 comments on commit 276d588

Please sign in to comment.