Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(network_tokenization): populate par in payments response for network_token payments (#11360)

Sarthak Sonib822cab40134
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index b2e0e0e1fc..3d24600010 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -23511,6 +23511,11 @@
"type": "string",
"description": "The ECI(Electronic Commerce Indicator) value for this authentication.",
"nullable": true
+ },
+ "par": {
+ "type": "string",
+ "description": "The Payment Account Reference (PAR) for this card.",
+ "nullable": true
}
}
},
@@ -23564,6 +23569,11 @@
"type": "string",
"description": "The card holder's name",
"nullable": true
+ },
+ "par": {
+ "type": "string",
+ "description": "The Payment Account Reference (PAR) for this card",
+ "nullable": true
}
}
},
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 02ca594f5a..a507b2f9c9 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -17527,6 +17527,11 @@
"type": "string",
"description": "The ECI(Electronic Commerce Indicator) value for this authentication.",
"nullable": true
+ },
+ "par": {
+ "type": "string",
+ "description": "The Payment Account Reference (PAR) for this card.",
+ "nullable": true
}
}
},
@@ -17591,6 +17596,11 @@
},
"saved_to_locker": {
"type": "boolean"
+ },
+ "par": {
+ "type": "string",
+ "example": "522134KAVJ1JPZ8L77N0Z2LRYZS7J",
+ "nullable": true
}
}
},
@@ -21780,6 +21790,14 @@
"keep_alive": {
"type": "boolean",
"description": "Whether the card with new status should be listed in the session"
+ },
+ "network_tokenization_data": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/NetworkTokenResponse"
+ }
+ ],
+ "nullable": true
}
}
},
diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs
index c97d09bf5f..253ec2ae31 100644
--- a/crates/api_models/src/payment_methods.rs
+++ b/crates/api_models/src/payment_methods.rs
@@ -1441,6 +1441,8 @@ pub struct NetworkTokenDetailsPaymentMethod {
pub card_type: Option<String>,
#[serde(default = "saved_in_locker_default")]
pub saved_to_locker: bool,
+ #[schema(value_type = Option<String>, example = "522134KAVJ1JPZ8L77N0Z2LRYZS7J")]
+ pub par: Option<masking::Secret<String>>,
}
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
@@ -4009,6 +4011,9 @@ pub struct PaymentMethodSessionResponse {
/// Whether the card with new status should be listed in the session
pub keep_alive: bool,
+
+ /// Network token details if available
+ pub network_tokenization_data: Option<NetworkTokenResponse>,
}
#[cfg(feature = "v2")]
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 87e97d3f75..94f4298458 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -3525,6 +3525,11 @@ pub struct NetworkTokenData {
#[schema(value_type = Option<String>)]
#[smithy(value_type = "Option<String>")]
pub eci: Option<String>,
+
+ /// The Payment Account Reference (PAR) for this card.
+ #[schema(value_type = Option<String>)]
+ #[smithy(value_type = "Option<String>")]
+ pub par: Option<Secret<String>>,
}
#[derive(
@@ -3575,6 +3580,11 @@ pub struct NetworkTokenResponse {
#[schema(value_type = Option<String>)]
#[smithy(value_type = "Option<String>")]
pub card_holder_name: Option<Secret<String>>,
+
+ /// The Payment Account Reference (PAR) for this card
+ #[schema(value_type = Option<String>)]
+ #[smithy(value_type = "Option<String>")]
+ pub par: Option<Secret<String>>,
}
#[derive(
@@ -4120,6 +4130,9 @@ pub struct AdditionalNetworkTokenInfo {
/// The card holder's name
pub card_holder_name: Option<Secret<String>>,
+
+ /// Payment Account Reference (PAR) for the card
+ pub par: Option<Secret<String>>,
}
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
@@ -9243,6 +9256,7 @@ impl From<AdditionalNetworkTokenInfo> for NetworkTokenResponse {
token_exp_month: network_token.token_exp_month,
token_exp_year: network_token.token_exp_year,
card_holder_name: network_token.card_holder_name,
+ par: network_token.par,
}
}
}
diff --git a/crates/hyperswitch_domain_models/src/payment_method_data.rs b/crates/hyperswitch_domain_models/src/payment_method_data.rs
index 6d0e408450..b490881533 100644
--- a/crates/hyperswitch_domain_models/src/payment_method_data.rs
+++ b/crates/hyperswitch_domain_models/src/payment_method_data.rs
@@ -667,6 +667,7 @@ impl From<NetworkTokenDetailsForNetworkTransactionId> for NetworkTokenData {
bank_code: network_token_details_for_nti.bank_code,
nick_name: network_token_details_for_nti.nick_name,
eci: network_token_details_for_nti.eci,
+ par: None, // Setting Par to None as it is not required for NetworkTransactionId flows
}
}
}
@@ -1385,6 +1386,7 @@ pub struct NetworkTokenData {
pub bank_code: Option<String>,
pub nick_name: Option<Secret<String>>,
pub eci: Option<String>,
+ pub par: Option<Secret<String>>,
}
#[cfg(feature = "v2")]
@@ -1402,6 +1404,7 @@ pub struct NetworkTokenData {
pub card_holder_name: Option<Secret<String>>,
pub nick_name: Option<Secret<String>>,
pub eci: Option<String>,
+ pub par: Option<Secret<String>>,
}
#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize, Default)]
@@ -1416,6 +1419,7 @@ pub struct NetworkTokenDetails {
pub card_issuing_country: Option<api_enums::CountryAlpha2>,
pub card_holder_name: Option<Secret<String>>,
pub nick_name: Option<Secret<String>>,
+ pub par: Option<Secret<String>>,
}
#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize)]
@@ -2591,6 +2595,7 @@ impl From<api_models::payments::NetworkTokenData> for NetworkTokenData {
bank_code: network_token_data.bank_code,
nick_name: network_token_data.nick_name,
eci: network_token_data.eci,
+ par: network_token_data.par,
}
}
}
@@ -2615,6 +2620,7 @@ impl From<api_models::payments::NetworkTokenData> for NetworkTokenData {
card_holder_name: network_token_data.card_holder_name,
nick_name: network_token_data.nick_name,
eci: network_token_data.eci,
+ par: network_token_data.par,
}
}
}
@@ -3052,6 +3058,7 @@ pub struct NetworkTokenDetailsPaymentMethod {
pub card_type: Option<String>,
#[serde(default = "saved_in_locker_default")]
pub saved_to_locker: bool,
+ pub par: Option<Secret<String>>,
}
fn saved_in_locker_default() -> bool {
@@ -3301,6 +3308,7 @@ impl From<NetworkTokenDetails> for NetworkTokenDetailsPaymentMethod {
card_network: item.card_network,
card_type: item.card_type.map(|card| card.to_string()),
saved_to_locker: true,
+ par: item.par,
}
}
}
@@ -3339,6 +3347,7 @@ impl From<NetworkTokenDetailsPaymentMethod> for payment_methods::NetworkTokenDet
card_network: item.card_network,
card_type: item.card_type,
saved_to_locker: item.saved_to_locker,
+ par: item.par,
}
}
}
@@ -3411,6 +3420,7 @@ impl From<NetworkTokenData> for AdditionalNetworkTokenInfo {
card_holder_name: None,
last4: Some(network_token_data.token_number.get_last4().clone()),
token_isin: Some(network_token_data.token_number.get_card_isin().clone()),
+ par: network_token_data.par.clone(),
}
}
}
@@ -3431,6 +3441,7 @@ impl From<NetworkTokenData> for AdditionalNetworkTokenInfo {
card_holder_name: network_token_data.card_holder_name.to_owned(),
last4: Some(network_token_data.network_token.get_last4().clone()),
token_isin: Some(network_token_data.network_token.get_card_isin().clone()),
+ par: network_token_data.par.clone(),
}
}
}
@@ -3453,6 +3464,7 @@ impl From<NetworkTokenDetailsForNetworkTransactionId> for AdditionalNetworkToken
.get_card_isin()
.clone(),
),
+ par: None,
}
}
}
@@ -3475,6 +3487,7 @@ impl From<DecryptedWalletTokenDetailsForNetworkTransactionId> for AdditionalNetw
.get_card_isin()
.clone(),
),
+ par: None, // Setting Par to None as it is not required for NetworkTransactionId flows
}
}
}
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index ef93607e23..d4a366d596 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -1636,7 +1636,7 @@ async fn execute_payment_method_create(
&payment_method,
None,
None,
- network_tokenization_resp,
+ network_tokenization_resp.clone(),
Some(req.payment_method_type),
payment_method_subtype,
external_vault_source,
@@ -4628,6 +4628,7 @@ pub async fn payment_methods_session_create(
request.storage_type,
None,
None,
+ None,
);
Ok(services::ApplicationResponse::Json(response))
@@ -4696,6 +4697,7 @@ pub async fn payment_methods_session_update(
update_state_change.storage_type,
None,
None,
+ None,
);
Ok(services::ApplicationResponse::Json(response))
@@ -4755,6 +4757,7 @@ pub async fn payment_methods_session_retrieve(
payment_methods::CardCVCTokenStorageDetails::generate_expiry_timestamp(time)
}),
None,
+ None,
);
Ok(services::ApplicationResponse::Json(response))
@@ -4856,6 +4859,7 @@ pub async fn payment_methods_session_update_payment_method(
updated_payment_method_session.storage_type,
update_response.card_cvc_token_storage,
update_response.payment_method_data.clone(),
+ None,
);
Ok(services::ApplicationResponse::Json(response))
@@ -5187,6 +5191,7 @@ pub async fn payment_methods_session_confirm(
payment_method_response.storage_type,
payment_method_response.card_cvc_token_storage,
None,
+ payment_method_response.network_token,
);
Ok(services::ApplicationResponse::Json(
diff --git a/crates/router/src/core/payment_methods/network_tokenization.rs b/crates/router/src/core/payment_methods/network_tokenization.rs
index 06521f3495..baa233c782 100644
--- a/crates/router/src/core/payment_methods/network_tokenization.rs
+++ b/crates/router/src/core/payment_methods/network_tokenization.rs
@@ -446,6 +446,7 @@ pub async fn make_card_network_tokenization_request(
card_holder_name: card.card_holder_name.clone(),
nick_name: card.nick_name.clone(),
cryptogram: None,
+ par: Some(Secret::new(resp.par)),
};
Ok((network_token_details, network_token_req_ref_id))
}
@@ -663,6 +664,7 @@ pub async fn get_token_from_tokenization_service(
card_issuing_country: None,
bank_code: None,
eci: token_response.eci,
+ par: token_response.card_details.map(|details| details.par),
};
Ok(network_token_data)
}
@@ -743,6 +745,7 @@ pub async fn get_token_from_tokenization_service(
card_issuing_country: token_decrypted.issuer_country,
bank_code: None,
eci: token_response.eci,
+ par: token_response.card_details.map(|details| details.par),
};
Ok(network_token_data)
}
diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rs
index 2cadfe2225..b3c86523b7 100644
--- a/crates/router/src/core/payment_methods/transformers.rs
+++ b/crates/router/src/core/payment_methods/transformers.rs
@@ -1019,6 +1019,7 @@ pub fn generate_payment_method_session_response(
storage_type: common_enums::StorageType,
card_cvc_token_storage: Option<api_models::payment_methods::CardCVCTokenStorageDetails>,
payment_method_data: Option<api_models::payment_methods::PaymentMethodResponseData>,
+ network_tokenization_response: Option<api_models::payment_methods::NetworkTokenResponse>,
) -> api_models::payment_methods::PaymentMethodSessionResponse {
let next_action = associated_payment
.as_ref()
@@ -1060,6 +1061,7 @@ pub fn generate_payment_method_session_response(
payment_method_data,
sdk_authorization,
keep_alive: payment_method_session.keep_alive,
+ network_tokenization_data: network_tokenization_response,
}
}
@@ -1701,6 +1703,7 @@ pub async fn create_payment_method_in_modular_service(
payment_method_data: domain::PaymentMethodData,
billing_address: Option<hyperswitch_domain_models::address::Address>,
customer_id: id_type::CustomerId,
+ is_network_tokenization_enabled: bool,
) -> CustomResult<domain::PaymentMethod, errors::ApiErrorResponse> {
let payment_method_request = CreatePaymentMethodV1Request {
merchant_id: provider_merchant_id.clone(),
@@ -1710,7 +1713,11 @@ pub async fn create_payment_method_in_modular_service(
customer_id,
payment_method_data,
billing: billing_address,
- network_tokenization: None,
+ network_tokenization: is_network_tokenization_enabled.then_some(
+ common_types::payment_methods::NetworkTokenization {
+ enable: common_enums::NetworkTokenizationToggle::Enable,
+ },
+ ),
storage_type: Some(common_enums::StorageType::Persistent),
modular_service_prefix: state.conf.micro_services.payment_methods_prefix.0.clone(),
};
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index f99844b1d6..78af75ae3d 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -3008,6 +3008,7 @@ pub async fn fetch_network_token_details_from_locker(
card_issuing_country: None,
bank_code: None,
eci: None,
+ par: None,
};
Ok(network_token_data)
}
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 12b1f68107..197003e397 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -1135,6 +1135,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.customer_id
.clone()
.get_required_value("customer_id")?,
+ business_profile.is_network_tokenization_enabled,
)
.await
{
@@ -1757,6 +1758,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
bank_code: None,
nick_name: None,
eci: authentication_details.eci,
+ par: None,
}),common_enums::AuthenticationStatus::Success)
},
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 72b44e13b8..f88aab2c45 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -7072,6 +7072,9 @@ impl From<pm_types::TokenResponse> for domain::NetworkTokenData {
bank_code: None,
nick_name: None,
eci: None,
+ par: token_response
+ .card_details
+ .map(|card_details| card_details.par),
}
}
}
diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rs
index dce5caf991..1dfacbbe2d 100644
--- a/crates/router/src/core/unified_authentication_service/utils.rs
+++ b/crates/router/src/core/unified_authentication_service/utils.rs
@@ -597,6 +597,7 @@ fn get_vault_details(
card_issuing_country: None,
card_holder_name: None,
nick_name: None,
+ par: None,
},
),
)
diff --git a/crates/router/src/types/payment_methods.rs b/crates/router/src/types/payment_methods.rs
index 17e98fefb7..7dbf9680e0 100644
--- a/crates/router/src/types/payment_methods.rs
+++ b/crates/router/src/types/payment_methods.rs
@@ -331,6 +331,11 @@ pub struct TokenDetails {
pub exp_year: Secret<String>,
}
+#[derive(Debug, Serialize, Deserialize)]
+pub struct TokenCardDetails {
+ pub par: Secret<String>,
+}
+
#[derive(Debug, Deserialize)]
pub struct TokenResponse {
pub authentication_details: AuthenticationDetails,
@@ -340,6 +345,7 @@ pub struct TokenResponse {
pub card_type: Option<String>,
pub issuer: Option<String>,
pub nickname: Option<Secret<String>>,
+ pub card_details: Option<TokenCardDetails>,
}
#[cfg(feature = "v1")]