-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat(core): [Network Tokenization] pre network tokenization #6873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
276d588
to
5c13cc8
Compare
a5845b1
to
3f9c0ba
Compare
16e0f52
to
dcc8625
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also when constructing router data, if pre-tokenization enabled, we need to pass network token data as payment method data. Could you point me to that change?
crates/router/src/core/payments.rs
Outdated
if is_pre_tokenization_enabled && is_nt_supported_connector_available { | ||
let pre_tokenization_response = tokenization::pre_payment_tokenization( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this validation for pre-network tokenization move to a a function?
crates/router/src/core/payments.rs
Outdated
.await?; | ||
let pm_data = payment_data.get_payment_method_data(); | ||
match pre_tokenization_response { | ||
(Some(token_response), Some(_token_ref)) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we ignoring this token_ref
? this should be set in payment method info right?
crates/router/src/core/payments.rs
Outdated
let filtered_nt_supported_connectors = | ||
get_filtered_nt_supported_connectors(&state, [connector.clone()].to_vec()); | ||
|
||
let is_nt_supported_connector_available = | ||
filtered_nt_supported_connectors.first().is_some(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do no filter out. check only if the connector decided by routing is in the network tokenization supported connectors. this is because routing should always be prioritized over any feature. please remove this.
crates/router/src/core/payments.rs
Outdated
match pre_tokenization_response { | ||
(Some(token_response), Some(_token_ref)) => { | ||
let token_data = domain::NetworkTokenData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is same logic, can you write this to a common function?
4c8d6a4
to
7563104
Compare
crates/api_models/src/admin.rs
Outdated
|
||
/// Indicates if network tokenization before first payment is enabled or not | ||
#[serde(default)] | ||
pub is_tokenize_before_payment_enabled: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_tokenize_before_payment_enabled
is bit ambiguous when 'before payment' is mentioned in variable name.
is_pre_network_tokenization_enabled
can be used ig. We can add clear doc comment
crates/router/src/core/payments.rs
Outdated
|
||
let is_nt_supported_connector = ntid_supported_connectors.contains(&connector_data.connector_name); | ||
|
||
println!("{:?}<<>>10",is_nt_supported_connector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the loggers.
crates/router/src/core/payments.rs
Outdated
println!("{:?}<<>>10",is_nt_supported_connector); | ||
|
||
if is_pre_tokenization_enabled && is_nt_supported_connector { | ||
println!("{:?}<<>>14",is_nt_supported_connector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here ^
crates/router/src/core/payments.rs
Outdated
if is_pre_tokenization_enabled && is_nt_supported_connector { | ||
println!("{:?}<<>>14",is_nt_supported_connector); | ||
save_card_and_network_token_data(state, &mut payment_data).await; | ||
println!("{:?}<<>>15",payment_data.get_payment_method_data()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this too^
crates/router/src/core/payments.rs
Outdated
network_token_data: token_data.clone(), | ||
ref_id: token_ref | ||
}; | ||
println!("{:?}<<>>17", network_token_data_for_vault); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove logger here^
crates/router/src/core/payments.rs
Outdated
#[derive(Default, Clone, serde::Serialize, Debug)] | ||
pub struct NetworkTokenDataForVault { | ||
pub network_token_data: hyperswitch_domain_models::payment_method_data::NetworkTokenData, | ||
pub ref_id: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is network_token_req_ref id right?
Can you rename it?
crates/router/src/core/payments.rs
Outdated
|
||
if is_pre_tokenization_enabled && is_nt_supported_connector { | ||
println!("{:?}<<>>14",is_nt_supported_connector); | ||
save_card_and_network_token_data(state, &mut payment_data).await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you modify save_card_and_network_token_data
fn name? because, the fn is trying to pre tokenize and update payment data.payment method data. but not saving card flow.
crates/router/src/core/payments.rs
Outdated
} | ||
|
||
#[derive(Default, Clone, serde::Serialize, Debug)] | ||
pub struct CardDataForVault { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like this struct has never been used. if this is not needed, can you remove this?
crates/router/src/core/payments.rs
Outdated
.await.ok(); | ||
match pre_tokenization_response { | ||
Some((Some(token_response), Some(token_ref))) => { | ||
let token_data = domain::NetworkTokenData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be moved to a From implementation?
Some(token_response), | ||
network_token_requestor_ref_id.clone(), | ||
)), | ||
_ => Ok((None, None)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incase fetch cryptogram fails we need to delete the network token generated right?
you return Ok((None, None)) in this failure case.
in save_card_and_network_token_data
fn, it is written that if pre_payment_tokenization
is None, then vault operation is set to SaveCardData(api::Card). but we need to return network token requestor ref id right? so that we can use this id to delete network token at token requestor in post update tracker
d3d4ecf
to
90da476
Compare
4b62178
to
6bb59b2
Compare
a699724
to
9311c2c
Compare
57396fb
to
4cfa5db
Compare
crates/api_models/src/admin.rs
Outdated
|
||
/// Indicates if pre network tokenization is enabled or not | ||
#[schema(default = false, example = false)] | ||
pub is_pre_network_tokenization_enabled: Option<bool>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed from all v2 structs
4cfa5db
to
038d6f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -0,0 +1,2 @@ | |||
-- Your SQL goes here | |||
ALTER TABLE business_profile DROP COLUMN IF EXISTS is_pre_network_tokenization_enabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we are removing here? the feature should be available in v2 also
@@ -0,0 +1,2 @@ | |||
-- Your SQL goes here | |||
ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS is_pre_network_tokenization_enabled BOOLEAN NOT NULL DEFAULT FALSE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove default and handle the default logic in code, basically when its null, change it to default in code
crates/router/src/core/payments.rs
Outdated
#[cfg(feature = "v1")] | ||
pub async fn set_payment_method_data_for_pre_network_tokenization<F, D>( | ||
state: &SessionState, | ||
payment_data: &mut D, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write logic in a way so that mutation is not required in this function, basically do things and return output, so that only in one place mutation is handled
3d03326
a75adef
to
3d03326
Compare
3d03326
to
4c2d1b4
Compare
4c2d1b4
to
a0b5e24
Compare
…ss-typos * 'main' of github.com:juspay/hyperswitch: chore(version): 2025.05.20.0 feat(core): add all_keys_required in confirm and psync payload (#7998) fix(connector): [CASHTOCODE] Added supported countries and currencies (#8060) feat(connector): [CYBERSOURCE] add SEK currency for cybersource (#8048) build(deps): migrate usages of `once_cell` crate to standard library equivalents (#8030) feat(core): [Network Tokenization] pre network tokenization (#6873) feat(router): add open router integration for debit routing (#7907) chore(cypress): Update creds for stripe (#8069) chore(version): 2025.05.19.0
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Type of Change
Description
Introduced a new field in business_profile (is_pre_network_tokenization_enabled).
Based on that field the card will be tokenized before first payment.
If the payment get succeeded the card and network token data will be stored in the locker afterwards.
Additional Changes
Motivation and Context
How did you test it?
Connector Create(Cybersource):
Payments Create:
Response:
Logs:
Raw Connector Request:
Checklist
cargo +nightly fmt --all
cargo clippy