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): Introduce NT credentials in domain tables (#11503)

Sarthak Sonia9ecf888b3b4
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 24d0864519..d55ea7f1db 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -21854,6 +21854,42 @@
}
}
},
+ "InternalNetworkTokenizationCredentials": {
+ "type": "object",
+ "required": [
+ "token_service_api_key",
+ "public_key",
+ "private_key",
+ "key_id"
+ ],
+ "properties": {
+ "token_service_api_key": {
+ "type": "string",
+ "description": "The API key to contact the network tokenization provider",
+ "example": "MDRFRDU3Mzc1Q0Q0N2893727712QzQjJEQzlENTBCOg==",
+ "maxLength": 255
+ },
+ "public_key": {
+ "type": "string",
+ "description": "The public key to encrypt the card details before sending to the network tokenization provider",
+ "example": "-----BEGIN PUBLIC KEY-----\nsom8723hj1bajhgd123==\n-----END PUBLIC KEY-----",
+ "maxLength": 255
+ },
+ "private_key": {
+ "type": "string",
+ "description": "The private key to decrypt the tokenized card details received from the network tokenization provider",
+ "example": "-----BEGIN RSA PRIVATE KEY-----\n897238huhbsdbjh12==\n-----END RSA PRIVATE KEY-----",
+ "maxLength": 255
+ },
+ "key_id": {
+ "type": "string",
+ "description": "The key_id used in encryption",
+ "example": "key_1ac9895a6d85414897213gahdac838a8",
+ "maxLength": 255
+ }
+ },
+ "additionalProperties": false
+ },
"Invoice": {
"type": "object",
"required": [
@@ -22525,6 +22561,14 @@
}
],
"nullable": true
+ },
+ "network_tokenization_credentials": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/NetworkTokeizationProviderCredentials"
+ }
+ ],
+ "nullable": true
}
},
"additionalProperties": false
@@ -22983,6 +23027,14 @@
},
"merchant_account_type": {
"$ref": "#/components/schemas/MerchantAccountType"
+ },
+ "network_tokenization_credentials": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/NetworkTokeizationProviderCredentials"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -23119,6 +23171,14 @@
}
],
"nullable": true
+ },
+ "network_tokenization_credentials": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/NetworkTokeizationProviderCredentials"
+ }
+ ],
+ "nullable": true
}
},
"additionalProperties": false
@@ -24228,6 +24288,22 @@
}
}
},
+ "NetworkTokeizationProviderCredentials": {
+ "oneOf": [
+ {
+ "type": "object",
+ "required": [
+ "internal_network_token_service"
+ ],
+ "properties": {
+ "internal_network_token_service": {
+ "$ref": "#/components/schemas/InternalNetworkTokenizationCredentials"
+ }
+ }
+ }
+ ],
+ "description": "The credentials required for calling the network tokenization provider APIs"
+ },
"NetworkTokenData": {
"type": "object",
"required": [
@@ -35893,6 +35969,14 @@
"description": "Flag to enable Level 2 and Level 3 processing data for card transactions",
"nullable": true
},
+ "network_tokenization_credentials": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/NetworkTokeizationProviderCredentials"
+ }
+ ],
+ "nullable": true
+ },
"payment_method_blocking": {
"allOf": [
{
@@ -36267,6 +36351,14 @@
"description": "Flag to enable Level 2 and Level 3 processing data for card transactions",
"nullable": true
},
+ "network_tokenization_credentials": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/NetworkTokeizationProviderCredentials"
+ }
+ ],
+ "nullable": true
+ },
"payment_method_blocking": {
"allOf": [
{
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index f621e06a92..8d71ef47bf 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -117,6 +117,10 @@ pub struct MerchantAccountCreate {
/// Merchant Account Type of this merchant account
#[schema(value_type = Option<MerchantAccountType>, example = "standard")]
pub merchant_account_type: Option<api_enums::MerchantAccountType>,
+
+ /// Network tokenization credentials for this merchant account
+ #[schema(value_type = Option<NetworkTokeizationProviderCredentials>)]
+ pub network_tokenization_credentials: Option<NetworkTokeizationProviderCredentials>,
}
#[cfg(feature = "v1")]
@@ -419,6 +423,10 @@ pub struct MerchantAccountUpdate {
/// Default payment method collect link config
#[schema(value_type = Option<BusinessCollectLinkConfig>)]
pub pm_collect_link_config: Option<BusinessCollectLinkConfig>,
+
+ /// Network tokenization credentials for this merchant account
+ #[schema(value_type = Option<NetworkTokeizationProviderCredentials>)]
+ pub network_tokenization_credentials: Option<NetworkTokeizationProviderCredentials>,
}
#[cfg(feature = "v1")]
@@ -621,6 +629,10 @@ pub struct MerchantAccountResponse {
/// Merchant Account Type of this merchant account
#[schema(value_type = MerchantAccountType, example = "standard")]
pub merchant_account_type: api_enums::MerchantAccountType,
+
+ /// Network tokenization credentials for this merchant account
+ #[schema(value_type = Option<NetworkTokeizationProviderCredentials>)]
+ pub network_tokenization_credentials: Option<NetworkTokeizationProviderCredentials>,
}
#[cfg(feature = "v2")]
@@ -703,6 +715,35 @@ pub struct MerchantDetails {
#[schema(value_type = Option<String>, example = "123456789")]
pub merchant_tax_registration_id: Option<Secret<String>>,
}
+
+/// The credentials required for calling the network tokenization provider APIs
+#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
+#[serde(deny_unknown_fields)]
+#[serde(rename_all = "snake_case")]
+pub enum NetworkTokeizationProviderCredentials {
+ InternalNetworkTokenService(InternalNetworkTokenizationCredentials),
+}
+
+#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
+#[serde(deny_unknown_fields)]
+#[serde(rename_all = "snake_case")]
+pub struct InternalNetworkTokenizationCredentials {
+ /// The API key to contact the network tokenization provider
+ #[schema(value_type = String, max_length = 255, example = "MDRFRDU3Mzc1Q0Q0N2893727712QzQjJEQzlENTBCOg==")]
+ pub token_service_api_key: Secret<String>,
+
+ /// The public key to encrypt the card details before sending to the network tokenization provider
+ #[schema(value_type = String, max_length = 255, example = "-----BEGIN PUBLIC KEY-----\nsom8723hj1bajhgd123==\n-----END PUBLIC KEY-----")]
+ pub public_key: Secret<String>,
+
+ /// The private key to decrypt the tokenized card details received from the network tokenization provider
+ #[schema(value_type = String, max_length = 255, example = "-----BEGIN RSA PRIVATE KEY-----\n897238huhbsdbjh12==\n-----END RSA PRIVATE KEY-----")]
+ pub private_key: Secret<String>,
+
+ /// The key_id used in encryption
+ #[schema(value_type = String, max_length = 255, example = "key_1ac9895a6d85414897213gahdac838a8")]
+ pub key_id: Secret<String>,
+}
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct PrimaryBusinessDetails {
@@ -2303,6 +2344,9 @@ pub struct ProfileCreate {
#[schema(value_type = Option<bool>)]
pub is_l2_l3_enabled: Option<bool>,
+ /// Network tokenization credentials for this merchant account
+ #[schema(value_type = Option<NetworkTokeizationProviderCredentials>)]
+ pub network_tokenization_credentials: Option<NetworkTokeizationProviderCredentials>,
/// Payment method blocking configuration for the profile
#[schema(value_type = Option<PaymentMethodBlockingConfig>)]
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
@@ -2680,6 +2724,9 @@ pub struct ProfileResponse {
#[schema(value_type = Option<bool>)]
pub is_l2_l3_enabled: Option<bool>,
+ /// Network tokenization credentials for this merchant account
+ #[schema(value_type = Option<NetworkTokeizationProviderCredentials>)]
+ pub network_tokenization_credentials: Option<NetworkTokeizationProviderCredentials>,
/// Payment method blocking configuration for the profile
#[schema(value_type = Option<PaymentMethodBlockingConfig>)]
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
@@ -3060,11 +3107,13 @@ pub struct ProfileUpdate {
#[schema(value_type = Option<bool>)]
pub is_l2_l3_enabled: Option<bool>,
+ /// Network tokenization credentials for this merchant account
+ #[schema(value_type = Option<NetworkTokeizationProviderCredentials>)]
+ pub network_tokenization_credentials: Option<NetworkTokeizationProviderCredentials>,
/// Payment method blocking configuration for the profile
#[schema(value_type = Option<PaymentMethodBlockingConfig>)]
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
}
-
#[cfg(feature = "v2")]
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
#[serde(deny_unknown_fields)]
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index 647457887e..105de2bbe5 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -84,6 +84,7 @@ pub struct Profile {
pub is_external_vault_enabled: Option<bool>,
pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,
pub is_l2_l3_enabled: Option<bool>,
+ pub network_tokenization_credentials: Option<Encryption>,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
}
@@ -148,6 +149,7 @@ pub struct ProfileNew {
pub is_external_vault_enabled: Option<bool>,
pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,
pub is_l2_l3_enabled: Option<bool>,
+ pub network_tokenization_credentials: Option<Encryption>,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
}
@@ -213,6 +215,7 @@ pub struct ProfileUpdateInternal {
pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
pub is_external_vault_enabled: Option<bool>,
pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,
+ pub network_tokenization_credentials: Option<Encryption>,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
}
@@ -275,6 +278,7 @@ impl ProfileUpdateInternal {
is_external_vault_enabled,
external_vault_connector_details,
billing_processor_id,
+ network_tokenization_credentials,
payment_method_blocking,
} = self;
Profile {
@@ -371,6 +375,8 @@ impl ProfileUpdateInternal {
external_vault_connector_details: external_vault_connector_details
.or(source.external_vault_connector_details),
billing_processor_id: billing_processor_id.or(source.billing_processor_id),
+ network_tokenization_credentials: network_tokenization_credentials
+ .or(source.network_tokenization_credentials),
payment_method_blocking: payment_method_blocking.or(source.payment_method_blocking),
}
}
@@ -442,6 +448,7 @@ pub struct Profile {
pub is_external_vault_enabled: Option<bool>,
pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,
pub is_l2_l3_enabled: Option<bool>,
+ pub network_tokenization_credentials: Option<Encryption>,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub order_fulfillment_time: Option<i64>,
@@ -756,6 +763,7 @@ impl ProfileUpdateInternal {
always_enable_overcapture: None,
is_l2_l3_enabled: None,
billing_processor_id: billing_processor_id.or(source.billing_processor_id),
+ network_tokenization_credentials: source.network_tokenization_credentials,
payment_method_blocking: None,
}
}
diff --git a/crates/diesel_models/src/merchant_account.rs b/crates/diesel_models/src/merchant_account.rs
index e0b421f40c..ca954917e3 100644
--- a/crates/diesel_models/src/merchant_account.rs
+++ b/crates/diesel_models/src/merchant_account.rs
@@ -55,6 +55,7 @@ pub struct MerchantAccount {
pub id: Option<common_utils::id_type::MerchantId>,
pub product_type: Option<common_enums::MerchantProductType>,
pub merchant_account_type: Option<common_enums::MerchantAccountType>,
+ pub network_tokenization_credentials: Option<Encryption>,
}
#[cfg(feature = "v1")]
@@ -90,6 +91,7 @@ pub struct MerchantAccountSetter {
pub is_platform_account: bool,
pub product_type: Option<common_enums::MerchantProductType>,
pub merchant_account_type: common_enums::MerchantAccountType,
+ pub network_tokenization_credentials: Option<Encryption>,
}
#[cfg(feature = "v1")]
@@ -128,6 +130,7 @@ impl From<MerchantAccountSetter> for MerchantAccount {
is_platform_account: item.is_platform_account,
product_type: item.product_type,
merchant_account_type: Some(item.merchant_account_type),
+ network_tokenization_credentials: item.network_tokenization_credentials,
}
}
}
@@ -162,6 +165,7 @@ pub struct MerchantAccount {
pub id: common_utils::id_type::MerchantId,
pub product_type: Option<common_enums::MerchantProductType>,
pub merchant_account_type: Option<common_enums::MerchantAccountType>,
+ pub network_tokenization_credentials: Option<Encryption>,
}
#[cfg(feature = "v2")]
@@ -182,6 +186,7 @@ impl From<MerchantAccountSetter> for MerchantAccount {
is_platform_account: item.is_platform_account,
product_type: item.product_type,
merchant_account_type: Some(item.merchant_account_type),
+ network_tokenization_credentials: None, // need to check if we can have this column in v2
}
}
}
@@ -252,6 +257,7 @@ pub struct MerchantAccountNew {
pub id: Option<common_utils::id_type::MerchantId>,
pub product_type: Option<common_enums::MerchantProductType>,
pub merchant_account_type: common_enums::MerchantAccountType,
+ pub network_tokenization_credentials: Option<Encryption>,
}
#[cfg(feature = "v2")]
@@ -320,6 +326,7 @@ impl MerchantAccountUpdateInternal {
is_platform_account: is_platform_account.unwrap_or(source.is_platform_account),
product_type: product_type.or(source.product_type),
merchant_account_type: source.merchant_account_type,
+ network_tokenization_credentials: source.network_tokenization_credentials,
}
}
}
@@ -355,6 +362,7 @@ pub struct MerchantAccountUpdateInternal {
pub pm_collect_link_config: Option<serde_json::Value>,
pub is_platform_account: Option<bool>,
pub product_type: Option<common_enums::MerchantProductType>,
+ pub network_tokenization_credentials: Option<Encryption>,
}
#[cfg(feature = "v1")]
@@ -388,6 +396,7 @@ impl MerchantAccountUpdateInternal {
pm_collect_link_config,
is_platform_account,
product_type,
+ network_tokenization_credentials,
} = self;
MerchantAccount {
@@ -427,6 +436,8 @@ impl MerchantAccountUpdateInternal {
id: source.id,
product_type: product_type.or(source.product_type),
merchant_account_type: source.merchant_account_type,
+ network_tokenization_credentials: network_tokenization_credentials
+ .or(source.network_tokenization_credentials),
}
}
}
diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs
index 2ecd45373c..12cfa6f8fa 100644
--- a/crates/diesel_models/src/payment_method.rs
+++ b/crates/diesel_models/src/payment_method.rs
@@ -67,6 +67,7 @@ pub struct PaymentMethod {
pub last_modified_by: Option<String>,
pub customer_details: Option<Encryption>,
pub locker_fingerprint_id: Option<String>,
+ pub network_tokenization_data: Option<Encryption>,
}
#[cfg(feature = "v2")]
@@ -97,6 +98,7 @@ pub struct PaymentMethod {
pub last_modified_by: Option<String>,
pub customer_details: Option<Encryption>,
pub locker_fingerprint_id: Option<String>,
+ pub network_tokenization_data: Option<Encryption>,
pub payment_method_type_v2: Option<storage_enums::PaymentMethod>,
pub payment_method_subtype: Option<storage_enums::PaymentMethodType>,
pub id: common_utils::id_type::GlobalPaymentMethodId,
@@ -161,6 +163,7 @@ pub struct PaymentMethodNew {
pub last_modified_by: Option<String>,
pub customer_details: Option<Encryption>,
pub locker_fingerprint_id: Option<String>,
+ pub network_tokenization_data: Option<Encryption>,
}
#[cfg(feature = "v2")]
@@ -261,7 +264,8 @@ pub enum PaymentMethodUpdate {
last_modified_by: Option<String>,
metadata: Option<serde_json::Value>,
last_used_at: Option<PrimitiveDateTime>,
- connector_mandate_details: Option<serde_json::Value>,
+ connector_mandate_details: Option<Box<serde_json::Value>>,
+ network_tokenization_data: Option<Encryption>,
},
ConnectorMandateDetailsUpdate {
connector_mandate_details: Option<serde_json::Value>,
@@ -271,6 +275,7 @@ pub enum PaymentMethodUpdate {
network_token_requestor_reference_id: Option<String>,
network_token_locker_id: Option<String>,
network_token_payment_method_data: Option<Encryption>,
+ network_tokenization_data: Option<Encryption>,
last_modified_by: Option<String>,
},
ConnectorNetworkTransactionIdAndMandateDetailsUpdate {
@@ -427,6 +432,7 @@ impl PaymentMethodUpdateInternal {
created_by: source.created_by,
last_modified_by: last_modified_by.or(source.last_modified_by),
customer_details: customer_details.or(source.customer_details),
+ network_tokenization_data: source.network_tokenization_data,
}
}
}
@@ -453,6 +459,7 @@ pub struct PaymentMethodUpdateInternal {
scheme: Option<String>,
last_modified_by: Option<String>,
customer_details: Option<Encryption>,
+ network_tokenization_data: Option<Encryption>,
}
#[cfg(feature = "v1")]
@@ -477,6 +484,7 @@ impl PaymentMethodUpdateInternal {
scheme,
last_modified_by,
customer_details,
+ network_tokenization_data,
} = self;
PaymentMethod {
@@ -523,6 +531,8 @@ impl PaymentMethodUpdateInternal {
created_by: source.created_by,
last_modified_by: last_modified_by.or(source.last_modified_by),
customer_details: customer_details.or(source.customer_details),
+ network_tokenization_data: network_tokenization_data
+ .or(source.network_tokenization_data),
}
}
}
@@ -554,6 +564,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
scheme: None,
last_modified_by,
customer_details: None,
+ network_tokenization_data: None,
},
PaymentMethodUpdate::PaymentMethodDataUpdate {
payment_method_data,
@@ -577,6 +588,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
scheme: None,
last_modified_by,
customer_details: None,
+ network_tokenization_data: None,
},
PaymentMethodUpdate::LastUsedUpdate { last_used_at } => Self {
metadata: None,
@@ -597,6 +609,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
scheme: None,
last_modified_by: None,
customer_details: None,
+ network_tokenization_data: None,
},
PaymentMethodUpdate::UpdatePaymentMethodDataAndLastUsed {
payment_method_data,
@@ -622,6 +635,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
scheme,
last_modified_by,
customer_details: None,
+ network_tokenization_data: None,
},
PaymentMethodUpdate::NetworkTransactionIdAndStatusUpdate {
network_transaction_id,
@@ -646,6 +660,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
scheme: None,
last_modified_by,
customer_details: None,
+ network_tokenization_data: None,
},
PaymentMethodUpdate::StatusUpdate {
status,
@@ -669,6 +684,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
scheme: None,
last_modified_by,
customer_details: None,
+ network_tokenization_data: None,
},
PaymentMethodUpdate::AdditionalDataUpdate {
payment_method_data,
@@ -684,6 +700,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
metadata,
last_used_at,
connector_mandate_details,
+ network_tokenization_data,
} => Self {
metadata,
payment_method_data,
@@ -693,7 +710,8 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
locker_id,
network_token_requestor_reference_id,
payment_method,
- connector_mandate_details,
+ connector_mandate_details: connector_mandate_details
+ .map(|mandate_details| *mandate_details),
updated_by: None,
payment_method_issuer,
payment_method_type,
@@ -703,6 +721,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
scheme: None,
last_modified_by,
customer_details: None,
+ network_tokenization_data,
},
PaymentMethodUpdate::ConnectorMandateDetailsUpdate {
connector_mandate_details,
@@ -726,11 +745,13 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
scheme: None,
last_modified_by,
customer_details: None,
+ network_tokenization_data: None,
},
PaymentMethodUpdate::NetworkTokenDataUpdate {
network_token_requestor_reference_id,
network_token_locker_id,
network_token_payment_method_data,
+ network_tokenization_data,
last_modified_by,
} => Self {
metadata: None,
@@ -751,6 +772,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
scheme: None,
last_modified_by,
customer_details: None,
+ network_tokenization_data,
},
PaymentMethodUpdate::ConnectorNetworkTransactionIdAndMandateDetailsUpdate {
connector_mandate_details,
@@ -776,6 +798,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
scheme: None,
last_modified_by,
customer_details: None,
+ network_tokenization_data: None,
},
PaymentMethodUpdate::PaymentMethodBatchUpdate {
connector_mandate_details,
@@ -803,6 +826,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
payment_method_data,
last_modified_by,
customer_details: None,
+ network_tokenization_data: None,
},
}
}
@@ -1054,6 +1078,7 @@ impl From<&PaymentMethodNew> for PaymentMethod {
last_modified_by: payment_method_new.last_modified_by.clone(),
customer_details: payment_method_new.customer_details.clone(),
locker_fingerprint_id: payment_method_new.locker_fingerprint_id.clone(),
+ network_tokenization_data: payment_method_new.network_tokenization_data.clone(),
}
}
}
@@ -1099,6 +1124,7 @@ impl From<&PaymentMethodNew> for PaymentMethod {
created_by: payment_method_new.created_by.clone(),
last_modified_by: payment_method_new.last_modified_by.clone(),
customer_details: payment_method_new.customer_details.clone(),
+ network_tokenization_data: None,
}
}
}
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 6bb1ea41c1..82bce7d926 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -299,6 +299,7 @@ diesel::table! {
is_external_vault_enabled -> Nullable<Bool>,
external_vault_connector_details -> Nullable<Jsonb>,
is_l2_l3_enabled -> Nullable<Bool>,
+ network_tokenization_credentials -> Nullable<Bytea>,
payment_method_blocking -> Nullable<Jsonb>,
}
}
@@ -955,6 +956,7 @@ diesel::table! {
product_type -> Nullable<Varchar>,
#[max_length = 64]
merchant_account_type -> Nullable<Varchar>,
+ network_tokenization_credentials -> Nullable<Bytea>,
}
}
@@ -1379,6 +1381,7 @@ diesel::table! {
customer_details -> Nullable<Bytea>,
#[max_length = 64]
locker_fingerprint_id -> Nullable<Varchar>,
+ network_tokenization_data -> Nullable<Bytea>,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 3c01144a2f..47a5cdb060 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -294,6 +294,7 @@ diesel::table! {
is_external_vault_enabled -> Nullable<Bool>,
external_vault_connector_details -> Nullable<Jsonb>,
is_l2_l3_enabled -> Nullable<Bool>,
+ network_tokenization_credentials -> Nullable<Bytea>,
payment_method_blocking -> Nullable<Jsonb>,
#[max_length = 64]
routing_algorithm_id -> Nullable<Varchar>,
@@ -946,6 +947,7 @@ diesel::table! {
product_type -> Nullable<Varchar>,
#[max_length = 64]
merchant_account_type -> Nullable<Varchar>,
+ network_tokenization_credentials -> Nullable<Bytea>,
}
}
@@ -1317,6 +1319,7 @@ diesel::table! {
customer_details -> Nullable<Bytea>,
#[max_length = 64]
locker_fingerprint_id -> Nullable<Varchar>,
+ network_tokenization_data -> Nullable<Bytea>,
#[max_length = 64]
payment_method_type_v2 -> Nullable<Varchar>,
#[max_length = 64]
diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs
index f894ce7f3f..f39361ea8b 100644
--- a/crates/hyperswitch_domain_models/src/business_profile.rs
+++ b/crates/hyperswitch_domain_models/src/business_profile.rs
@@ -91,6 +91,7 @@ pub struct Profile {
pub always_enable_overcapture: Option<primitive_wrappers::AlwaysEnableOvercaptureBool>,
pub external_vault_details: ExternalVaultDetails,
pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
+ pub network_tokenization_credentials: OptionalEncryptableValue,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
}
@@ -250,6 +251,7 @@ pub struct ProfileSetter {
pub always_enable_overcapture: Option<primitive_wrappers::AlwaysEnableOvercaptureBool>,
pub external_vault_details: ExternalVaultDetails,
pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
+ pub network_tokenization_credentials: OptionalEncryptableValue,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
}
@@ -319,6 +321,7 @@ impl From<ProfileSetter> for Profile {
always_enable_overcapture: value.always_enable_overcapture,
external_vault_details: value.external_vault_details,
billing_processor_id: value.billing_processor_id,
+ network_tokenization_credentials: value.network_tokenization_credentials,
payment_method_blocking: value.payment_method_blocking,
}
}
@@ -391,6 +394,7 @@ pub struct ProfileGeneralUpdate {
pub is_external_vault_enabled: Option<common_enums::ExternalVaultEnabled>,
pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,
pub billing_processor_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
+ pub network_tokenization_credentials: OptionalEncryptableValue,
pub payment_method_blocking: Option<PaymentMethodBlockingConfig>,
}
@@ -414,6 +418,7 @@ pub enum ProfileUpdate {
},
NetworkTokenizationUpdate {
is_network_tokenization_enabled: bool,
+ network_tokenization_credentials: OptionalEncryptableValue,
},
CardTestingSecretKeyUpdate {
card_testing_secret_key: OptionalEncryptableName,
@@ -481,6 +486,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_external_vault_enabled,
external_vault_connector_details,
billing_processor_id,
+ network_tokenization_credentials,
payment_method_blocking,
} = *update;
@@ -549,6 +555,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
is_external_vault_enabled,
external_vault_connector_details,
billing_processor_id,
+ network_tokenization_credentials: network_tokenization_credentials
+ .map(Encryption::from),
payment_method_blocking,
}
}
@@ -612,6 +620,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
external_vault_connector_details: None,
billing_processor_id: None,
is_l2_l3_enabled: None,
+ network_tokenization_credentials: None,
payment_method_blocking: None,
},
ProfileUpdate::DynamicRoutingAlgorithmUpdate {
@@ -672,6 +681,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
external_vault_connector_details: None,
billing_processor_id: None,
is_l2_l3_enabled: None,
+ network_tokenization_credentials: None,
payment_method_blocking: None,
},
ProfileUpdate::ExtendedCardInfoUpdate {
@@ -732,6 +742,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
external_vault_connector_details: None,
billing_processor_id: None,
is_l2_l3_enabled: None,
+ network_tokenization_credentials: None,
payment_method_blocking: None,
},
ProfileUpdate::ConnectorAgnosticMitUpdate {
@@ -792,10 +803,12 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
external_vault_connector_details: None,
billing_processor_id: None,
is_l2_l3_enabled: None,
+ network_tokenization_credentials: None,
payment_method_blocking: None,
},
ProfileUpdate::NetworkTokenizationUpdate {
is_network_tokenization_enabled,
+ network_tokenization_credentials,
} => Self {
profile_name: None,
modified_at: now,
@@ -852,6 +865,8 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
external_vault_connector_details: None,
billing_processor_id: None,
is_l2_l3_enabled: None,
+ network_tokenization_credentials: network_tokenization_credentials
+ .map(Encryption::from),
payment_method_blocking: None,
},
ProfileUpdate::CardTestingSecretKeyUpdate {
@@ -912,6 +927,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
external_vault_connector_details: None,
billing_processor_id: None,
is_l2_l3_enabled: None,
+ network_tokenization_credentials: None,
payment_method_blocking: None,
},
ProfileUpdate::AcquirerConfigMapUpdate {
@@ -972,6 +988,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {
external_vault_connector_details: None,
billing_processor_id: None,
is_l2_l3_enabled: None,
+ network_tokenization_credentials: None,
payment_method_blocking: None,
},
}
@@ -1055,6 +1072,9 @@ impl Conversion for Profile {
is_external_vault_enabled,
external_vault_connector_details,
billing_processor_id: self.billing_processor_id,
+ network_tokenization_credentials: self
+ .network_tokenization_credentials
+ .map(|name| name.into()),
payment_method_blocking: self.payment_method_blocking,
})
}
@@ -1069,7 +1089,11 @@ impl Conversion for Profile {
Self: Sized,
{
// Decrypt encrypted fields first
- let (outgoing_webhook_custom_http_headers, card_testing_secret_key) = async {
+ let (
+ outgoing_webhook_custom_http_headers,
+ card_testing_secret_key,
+ network_tokenization_credentials,
+ ) = async {
let outgoing_webhook_custom_http_headers = item
.outgoing_webhook_custom_http_headers
.async_lift(|inner| async {
@@ -1100,9 +1124,25 @@ impl Conversion for Profile {
})
.await?;
+ let network_tokenization_credentials = item
+ .network_tokenization_credentials
+ .async_lift(|inner| async {
+ crypto_operation(
+ state,
+ type_name!(Self::DstType),
+ CryptoOperation::DecryptOptional(inner),
+ key_manager_identifier.clone(),
+ key.peek(),
+ )
+ .await
+ .and_then(|val| val.try_into_optionaloperation())
+ })
+ .await?;
+
Ok::<_, error_stack::Report<common_utils::errors::CryptoError>>((
outgoing_webhook_custom_http_headers,
card_testing_secret_key,
+ network_tokenization_credentials,
))
}
.await
@@ -1181,6 +1221,7 @@ impl Conversion for Profile {
always_enable_overcapture: item.always_enable_overcapture,
external_vault_details,
billing_processor_id: item.billing_processor_id,
+ network_tokenization_credentials,
payment_method_blocking: item.payment_method_blocking,
})
}
@@ -1251,6 +1292,9 @@ impl Conversion for Profile {
is_external_vault_enabled,
external_vault_connector_details,
billing_processor_id: self.billing_processor_id,
+ network_tokenization_credentials: self
+ .network_tokenization_credentials
+ .map(|name| name.into()),
payment_method_blocking: self.payment_method_blocking,
})
}
@@ -2428,6 +2472,7 @@ impl Conversion for Profile {
is_l2_l3_enabled: None,
always_enable_overcapture: None,
billing_processor_id: self.billing_processor_id,
+ network_tokenization_credentials: None,
payment_method_blocking: None,
})
}
diff --git a/crates/hyperswitch_domain_models/src/merchant_account.rs b/crates/hyperswitch_domain_models/src/merchant_account.rs
index 8ad8fe3aab..d377dde8ef 100644
--- a/crates/hyperswitch_domain_models/src/merchant_account.rs
+++ b/crates/hyperswitch_domain_models/src/merchant_account.rs
@@ -54,6 +54,7 @@ pub struct MerchantAccount {
pub is_platform_account: bool,
pub product_type: Option<common_enums::MerchantProductType>,
pub merchant_account_type: common_enums::MerchantAccountType,
+ pub network_tokenization_credentials: OptionalEncryptableValue,
}
#[cfg(feature = "v1")]
@@ -91,6 +92,7 @@ pub struct MerchantAccountSetter {
pub is_platform_account: bool,
pub product_type: Option<common_enums::MerchantProductType>,
pub merchant_account_type: common_enums::MerchantAccountType,
+ pub network_tokenization_credentials: OptionalEncryptableValue,
}
#[cfg(feature = "v1")]
@@ -128,6 +130,7 @@ impl From<MerchantAccountSetter> for MerchantAccount {
is_platform_account: item.is_platform_account,
product_type: item.product_type,
merchant_account_type: item.merchant_account_type,
+ network_tokenization_credentials: item.network_tokenization_credentials,
}
}
}
@@ -283,6 +286,7 @@ pub enum MerchantAccountUpdate {
default_profile: Option<Option<common_utils::id_type::ProfileId>>,
payment_link_config: Option<serde_json::Value>,
pm_collect_link_config: Option<serde_json::Value>,
+ network_tokenization_credentials: OptionalEncryptableValue,
},
StorageSchemeUpdate {
storage_scheme: MerchantStorageScheme,
@@ -339,6 +343,7 @@ impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {
default_profile,
payment_link_config,
pm_collect_link_config,
+ network_tokenization_credentials,
} => Self {
merchant_name: merchant_name.map(Encryption::from),
merchant_details: merchant_details.map(Encryption::from),
@@ -367,6 +372,8 @@ impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {
recon_status: None,
is_platform_account: None,
product_type: None,
+ network_tokenization_credentials: network_tokenization_credentials
+ .map(Encryption::from),
},
MerchantAccountUpdate::StorageSchemeUpdate { storage_scheme } => Self {
storage_scheme: Some(storage_scheme),
@@ -396,6 +403,7 @@ impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {
pm_collect_link_config: None,
is_platform_account: None,
product_type: None,
+ network_tokenization_credentials: None,
},
MerchantAccountUpdate::ReconUpdate { recon_status } => Self {
recon_status: Some(recon_status),
@@ -425,6 +433,7 @@ impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {
pm_collect_link_config: None,
is_platform_account: None,
product_type: None,
+ network_tokenization_credentials: None,
},
MerchantAccountUpdate::UnsetDefaultProfile => Self {
default_profile: Some(None),
@@ -454,6 +463,7 @@ impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {
pm_collect_link_config: None,
is_platform_account: None,
product_type: None,
+ network_tokenization_credentials: None,
},
MerchantAccountUpdate::ModifiedAtUpdate => Self {
modified_at: now,
@@ -483,6 +493,7 @@ impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {
pm_collect_link_config: None,
is_platform_account: None,
product_type: None,
+ network_tokenization_credentials: None,
},
}
}
@@ -705,6 +716,9 @@ impl Conversion for MerchantAccount {
is_platform_account: self.is_platform_account,
product_type: self.product_type,
merchant_account_type: self.merchant_account_type,
+ network_tokenization_credentials: self
+ .network_tokenization_credentials
+ .map(|credentials| credentials.into()),
};
Ok(diesel_models::MerchantAccount::from(setter))
@@ -785,6 +799,20 @@ impl Conversion for MerchantAccount {
is_platform_account: item.is_platform_account,
product_type: item.product_type,
merchant_account_type: item.merchant_account_type.unwrap_or_default(),
+ network_tokenization_credentials: item
+ .network_tokenization_credentials
+ .async_lift(|inner| async {
+ crypto_operation(
+ state,
+ type_name!(Self::DstType),
+ CryptoOperation::DecryptOptional(inner),
+ key_manager_identifier.clone(),
+ key.peek(),
+ )
+ .await
+ .and_then(|val| val.try_into_optionaloperation())
+ })
+ .await?,
})
}
.await
@@ -829,6 +857,9 @@ impl Conversion for MerchantAccount {
.product_type
.or(Some(common_enums::MerchantProductType::Orchestration)),
merchant_account_type: self.merchant_account_type,
+ network_tokenization_credentials: self
+ .network_tokenization_credentials
+ .map(|credentials| credentials.into()),
})
}
}
diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs
index 9a9af38119..f463544865 100644
--- a/crates/hyperswitch_domain_models/src/payment_methods.rs
+++ b/crates/hyperswitch_domain_models/src/payment_methods.rs
@@ -1,4 +1,3 @@
-#[cfg(feature = "v2")]
use std::collections::HashMap;
#[cfg(feature = "v2")]
@@ -97,6 +96,7 @@ pub struct PaymentMethod {
pub last_modified_by: Option<CreatedBy>,
pub customer_details: OptionalEncryptableValue,
pub locker_fingerprint_id: Option<String>,
+ pub network_tokenization_data: OptionalEncryptableValue,
}
#[cfg(feature = "v2")]
@@ -143,6 +143,9 @@ pub struct PaymentMethod {
pub last_modified_by: Option<CreatedBy>,
#[encrypt(ty = Value)]
pub customer_details: Option<Encryptable<customers::CustomerDocumentDetails>>,
+ #[encrypt(ty = Value)]
+ pub network_tokenization_data:
+ Option<Encryptable<PaymentMethodNetworkTokenizationDataDomainType>>,
}
impl PaymentMethod {
@@ -461,6 +464,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.map(|last_modified_by| last_modified_by.to_string()),
customer_details: self.customer_details.map(|val| val.into()),
locker_fingerprint_id: self.locker_fingerprint_id,
+ network_tokenization_data: self.network_tokenization_data.map(|val| val.into()),
})
}
@@ -478,6 +482,7 @@ impl super::behaviour::Conversion for PaymentMethod {
payment_method_data,
payment_method_billing_address,
network_token_payment_method_data,
+ network_tokenization_data,
customer_details,
) = async {
let payment_method_data = item
@@ -525,6 +530,21 @@ impl super::behaviour::Conversion for PaymentMethod {
})
.await?;
+ let network_tokenization_data = item
+ .network_tokenization_data
+ .async_lift(|inner| async {
+ crypto_operation(
+ state,
+ type_name!(Self::DstType),
+ CryptoOperation::DecryptOptional(inner),
+ key_manager_identifier.clone(),
+ key.peek(),
+ )
+ .await
+ .and_then(|val| val.try_into_optionaloperation())
+ })
+ .await?;
+
let customer_details = item
.customer_details
.async_lift(|inner| async {
@@ -544,6 +564,7 @@ impl super::behaviour::Conversion for PaymentMethod {
payment_method_data,
payment_method_billing_address,
network_token_payment_method_data,
+ network_tokenization_data,
customer_details,
))
}
@@ -602,6 +623,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.and_then(|last_modified_by| last_modified_by.parse::<CreatedBy>().ok()),
customer_details,
locker_fingerprint_id: item.locker_fingerprint_id,
+ network_tokenization_data,
})
}
@@ -654,6 +676,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.map(|last_modified_by| last_modified_by.to_string()),
customer_details: self.customer_details.map(|val| val.into()),
locker_fingerprint_id: self.locker_fingerprint_id,
+ network_tokenization_data: self.network_tokenization_data.map(|val| val.into()),
})
}
}
@@ -699,6 +722,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.last_modified_by
.map(|last_modified_by| last_modified_by.to_string()),
customer_details: self.customer_details.map(|val| val.into()),
+ network_tokenization_data: self.network_tokenization_data.map(|val| val.into()),
})
}
@@ -726,6 +750,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.network_token_payment_method_data,
external_vault_token_data: storage_model.external_vault_token_data,
customer_details: storage_model.customer_details,
+ network_tokenization_data: storage_model.network_tokenization_data,
},
)),
key_manager_identifier,
@@ -790,6 +815,17 @@ impl super::behaviour::Conversion for PaymentMethod {
.change_context(common_utils::errors::CryptoError::DecodingFailed)
.attach_printable("Error while deserializing External Vault Token Data")?;
+ let network_tokenization_data = data
+ .network_tokenization_data
+ .map(|tokenization_data| {
+ tokenization_data.deserialize_inner_value(|value| {
+ value.parse_value("Network Tokenization Data")
+ })
+ })
+ .transpose()
+ .change_context(common_utils::errors::CryptoError::DecodingFailed)
+ .attach_printable("Error while deserializing Network Tokenization Data")?;
+
Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
customer_id: Some(storage_model.customer_id),
merchant_id: storage_model.merchant_id,
@@ -826,6 +862,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.last_modified_by
.and_then(|last_modified_by| last_modified_by.parse::<CreatedBy>().ok()),
customer_details,
+ network_tokenization_data,
})
}
.await
@@ -1534,6 +1571,26 @@ pub struct PaymentMethodResponse {
pub locker_fingerprint_id: Option<String>,
}
+/// Struct to hold Network Tokenization Data for a payment method. This struct contains optional fields for network token requestor reference ID, network token locker ID, and network token payment method data.
+/// This struct is used to store the network tokenization data associated with a payment method in the database.
+#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
+pub struct PaymentMethodNetworkTokenData {
+ network_token_requestor_reference_id: Secret<String>,
+ network_token_locker_id: Secret<String>,
+ network_token_payment_method_data: crate::payment_method_data::PaymentMethodsData,
+}
+
+/// The domain type for Network Tokenization Data stored in payment methods table.
+/// This structure allows for efficient retrieval of network tokenization data based on either merchant or profile context.
+/// This struct contains two maps:
+/// 1. `merchant_map`: A map where the key is the MerchantId and the value is the Network Tokenization Data specific to that merchant.
+/// 2. `profile_map`: A map where the key is the ProfileId and the value is the Network Tokenization Data specific to that profile.
+#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
+pub struct PaymentMethodNetworkTokenizationDataDomainType {
+ pub merchant_map: Option<HashMap<id_type::MerchantId, PaymentMethodNetworkTokenData>>,
+ pub profile_map: Option<HashMap<id_type::ProfileId, PaymentMethodNetworkTokenData>>,
+}
+
#[cfg(feature = "v1")]
#[cfg(test)]
mod tests {
@@ -1584,6 +1641,7 @@ mod tests {
last_modified_by: None,
customer_details: None,
locker_fingerprint_id: None,
+ network_tokenization_data: None,
};
payment_method.clone()
}
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 649d5429d7..1846d0b489 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -355,6 +355,8 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::admin::BusinessPayoutLinkConfig,
api_models::admin::CardTestingGuardConfig,
api_models::admin::CardTestingGuardStatus,
+ api_models::admin::NetworkTokeizationProviderCredentials,
+ api_models::admin::InternalNetworkTokenizationCredentials,
api_models::admin::PaymentMethodBlockingConfig,
api_models::admin::CardBlockingConfig,
api_models::merchant_connector_webhook_management::ConnectorWebhookRegisterRequest,
diff --git a/crates/payment_methods/src/core/migration/payment_methods.rs b/crates/payment_methods/src/core/migration/payment_methods.rs
index a521d65e29..cb07dba9b8 100644
--- a/crates/payment_methods/src/core/migration/payment_methods.rs
+++ b/crates/payment_methods/src/core/migration/payment_methods.rs
@@ -727,6 +727,7 @@ pub async fn skip_locker_call_and_migrate_payment_method(
last_modified_by: initiator.and_then(|initiator| initiator.to_created_by()),
customer_details: None,
locker_fingerprint_id: None,
+ network_tokenization_data: None,
},
provider.get_account().storage_scheme,
)
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 25325b517b..51f2ec0a6c 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -216,6 +216,7 @@ fn create_platform_merchant_account_request(
payout_routing_algorithm: None,
pm_collect_link_config: None,
product_type: Some(consts::user::DEFAULT_PRODUCT_TYPE),
+ network_tokenization_credentials: None,
}
}
@@ -567,6 +568,14 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
let key = key_store.key.clone().into_inner();
let key_manager_state = state.into();
+ let network_tokenization_credentials = self
+ .network_tokenization_credentials
+ .async_map(|value| cards::create_encrypted_data(&key_manager_state, &key_store, value))
+ .await
+ .transpose()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Unable to encrypt network_tokenization_credentials")?;
+
let merchant_account = async {
Ok::<_, error_stack::Report<common_utils::errors::CryptoError>>(
domain::MerchantAccountSetter {
@@ -634,6 +643,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
is_platform_account: false,
product_type: self.product_type,
merchant_account_type,
+ network_tokenization_credentials,
},
)
}
@@ -1188,6 +1198,14 @@ impl MerchantAccountUpdateBridge for api::MerchantAccountUpdate {
})
.await;
+ let network_tokenization_credentials = self
+ .network_tokenization_credentials
+ .async_map(|value| cards::create_encrypted_data(key_manager_state, key_store, value))
+ .await
+ .transpose()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Unable to encrypt network_tokenization_credentials")?;
+
let identifier = km_types::Identifier::Merchant(key_store.merchant_id.clone());
Ok(storage::MerchantAccountUpdate::Update {
merchant_name: self
@@ -1243,6 +1261,7 @@ impl MerchantAccountUpdateBridge for api::MerchantAccountUpdate {
payment_link_config: None,
pm_collect_link_config,
routing_algorithm: self.routing_algorithm,
+ network_tokenization_credentials,
})
}
}
@@ -3383,6 +3402,16 @@ impl ProfileCreateBridge for api::ProfileCreate {
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to encrypt outgoing webhook custom HTTP headers")?;
+ let network_tokenization_credentials = self
+ .network_tokenization_credentials
+ .async_map(|headers| {
+ cards::create_encrypted_data(&key_manager_state, processor.get_key_store(), headers)
+ })
+ .await
+ .transpose()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Unable to encrypt network_tokenization_credentials")?;
+
let payout_link_config = self
.payout_link_config
.map(|payout_conf| match payout_conf.config.validate() {
@@ -3543,6 +3572,7 @@ impl ProfileCreateBridge for api::ProfileCreate {
.attach_printable("error while generating external vault details")?,
billing_processor_id: self.billing_processor_id,
is_l2_l3_enabled: self.is_l2_l3_enabled.unwrap_or(false),
+ network_tokenization_credentials,
payment_method_blocking: self.payment_method_blocking.map(ForeignInto::foreign_into),
}))
}
@@ -3904,6 +3934,14 @@ impl ProfileUpdateBridge for api::ProfileUpdate {
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to encrypt outgoing webhook custom HTTP headers")?;
+ let network_tokenization_credentials = self
+ .network_tokenization_credentials
+ .async_map(|value| cards::create_encrypted_data(&key_manager_state, key_store, value))
+ .await
+ .transpose()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Unable to encrypt network_tokenization_credentials")?;
+
let payout_link_config = self
.payout_link_config
.map(|payout_conf| match payout_conf.config.validate() {
@@ -4047,6 +4085,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate {
.map(ForeignInto::foreign_into),
billing_processor_id: self.billing_processor_id,
is_l2_l3_enabled: self.is_l2_l3_enabled,
+ network_tokenization_credentials,
payment_method_blocking: self
.payment_method_blocking
.map(ForeignInto::foreign_into),
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index 7b3af64e0c..1cfde71d8f 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -2797,6 +2797,7 @@ pub async fn create_payment_method_for_intent(
created_by: initiator.and_then(|initiator| initiator.to_created_by()),
last_modified_by: initiator.and_then(|initiator| initiator.to_created_by()),
customer_details: None,
+ network_tokenization_data: None,
},
storage_scheme,
)
@@ -2884,6 +2885,7 @@ pub async fn construct_payment_method_object(
created_by: initiator.and_then(|initiator| initiator.to_created_by()),
last_modified_by: initiator.and_then(|initiator| initiator.to_created_by()),
customer_details: None,
+ network_tokenization_data: None,
})
}
@@ -2945,6 +2947,7 @@ pub async fn create_payment_method_for_confirm(
created_by: initiator.and_then(|initiator| initiator.to_created_by()),
last_modified_by: initiator.and_then(|initiator| initiator.to_created_by()),
customer_details: None,
+ network_tokenization_data: None,
},
storage_scheme,
)
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 3f5cbe5286..b21328c2a6 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -206,6 +206,7 @@ impl PaymentMethodsController for PmCards<'_> {
last_modified_by: initiator.and_then(|initiator| initiator.to_created_by()),
customer_details: payment_method_customer_details_encrypted,
locker_fingerprint_id,
+ network_tokenization_data: None, // setting this to None as write path will be introduced in a later PR
},
self.provider.get_account().storage_scheme,
)
@@ -437,6 +438,7 @@ impl PaymentMethodsController for PmCards<'_> {
last_modified_by: initiator
.and_then(|initiator| initiator.to_created_by())
.map(|last_modified_by| last_modified_by.to_string()),
+ network_tokenization_data: None, // setting this to None as write path will be introduced in a later PR
};
let db = &*self.state.store;
let existing_pm = db
@@ -1761,6 +1763,7 @@ pub async fn add_payment_method_data(
metadata: None,
last_used_at: None,
connector_mandate_details: None,
+ network_tokenization_data: None, // setting it to None as write path will be introduced in a later PR
};
db.update_payment_method(
@@ -2443,6 +2446,7 @@ pub async fn update_payment_method_metadata_and_network_token_data_and_last_used
metadata: pm_metadata,
last_used_at: Some(common_utils::date_time::now()),
connector_mandate_details: None,
+ network_tokenization_data: None, // setting this to None as write path will be introduced in a later PR
};
db.update_payment_method(key_store, pm, pm_update, storage_scheme)
@@ -2470,6 +2474,7 @@ pub async fn update_payment_method_network_token_data(
last_modified_by: initiator
.and_then(|initiator| initiator.to_created_by())
.map(|last_modified_by| last_modified_by.to_string()),
+ network_tokenization_data: None, // setting this to None as write path will be introduced in a later PR
};
db.update_payment_method(key_store, pm, pm_update, storage_scheme)
@@ -2591,7 +2596,8 @@ pub async fn update_payment_method_connector_mandate_details_and_network_token_d
.map(|last_modified_by| last_modified_by.to_string()),
metadata: None,
last_used_at: None,
- connector_mandate_details: connector_mandate_details_value,
+ connector_mandate_details: connector_mandate_details_value.map(Box::new),
+ network_tokenization_data: None, // setting this to None as write path will be introduced in a later PR
};
db.update_payment_method(key_store, pm, pm_update, storage_scheme)
diff --git a/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs b/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs
index df3a67a5e8..e0f998d0dd 100644
--- a/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs
+++ b/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs
@@ -402,6 +402,7 @@ impl CardNetworkTokenizeExecutor<'_, domain::TokenizePaymentMethodRequest> {
last_modified_by: initiator
.and_then(|initiator| initiator.to_created_by())
.map(|last_modified_by| last_modified_by.to_string()),
+ network_tokenization_data: None,
};
self.state
.store
diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rs
index f49ece5f6f..7a961da471 100644
--- a/crates/router/src/core/payment_methods/transformers.rs
+++ b/crates/router/src/core/payment_methods/transformers.rs
@@ -1344,6 +1344,7 @@ impl DomainPaymentMethodWrapper {
.and_then(|initiator| initiator.to_created_by()),
customer_details: None,
locker_fingerprint_id: None,
+ network_tokenization_data: None,
}))
}
@@ -1476,6 +1477,7 @@ impl DomainPaymentMethodWrapper {
.and_then(|initiator| initiator.to_created_by()),
customer_details: None,
locker_fingerprint_id: None,
+ network_tokenization_data: None,
}))
}
}
@@ -1581,6 +1583,7 @@ impl TryFrom<CreatePaymentMethodResponse> for DomainPaymentMethodWrapper {
last_modified_by: None,
customer_details: None,
locker_fingerprint_id: None,
+ network_tokenization_data: None,
}))
}
}
diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs
index b7f4fb8e3d..d939f1947e 100644
--- a/crates/router/src/core/payments/tokenization.rs
+++ b/crates/router/src/core/payments/tokenization.rs
@@ -302,7 +302,7 @@ where
save_payment_method_data.attempt_status,
);
pm_status = Some(payment_method_status);
- save_card_and_network_token_in_locker(
+ Box::pin(save_card_and_network_token_in_locker(
state,
customer_id.clone(),
payment_method_status,
@@ -313,7 +313,7 @@ where
payment_method_create_request.clone(),
is_network_tokenization_enabled,
business_profile,
- )
+ ))
.await?
};
let network_token_locker_id = match network_token_resp {
diff --git a/crates/router/src/core/pm_auth.rs b/crates/router/src/core/pm_auth.rs
index ad0ff557b2..54f32ec52b 100644
--- a/crates/router/src/core/pm_auth.rs
+++ b/crates/router/src/core/pm_auth.rs
@@ -539,6 +539,7 @@ async fn store_bank_details_in_payment_methods(
.and_then(|initiator| initiator.to_created_by()),
customer_details: None,
locker_fingerprint_id: None,
+ network_tokenization_data: None,
};
new_entries.push(pm_new);
diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rs
index 9767ee49e6..cedf1096c8 100644
--- a/crates/router/src/core/routing/helpers.rs
+++ b/crates/router/src/core/routing/helpers.rs
@@ -210,6 +210,7 @@ pub async fn update_merchant_active_algorithm_ref(
default_profile: None,
payment_link_config: None,
pm_collect_link_config: None,
+ network_tokenization_credentials: None,
};
let db = &*state.store;
diff --git a/crates/router/src/core/webhooks/network_tokenization_incoming.rs b/crates/router/src/core/webhooks/network_tokenization_incoming.rs
index dbe2b63464..b574b34491 100644
--- a/crates/router/src/core/webhooks/network_tokenization_incoming.rs
+++ b/crates/router/src/core/webhooks/network_tokenization_incoming.rs
@@ -344,6 +344,7 @@ pub async fn handle_metadata_update(
metadata: None,
last_used_at: None,
connector_mandate_details: None,
+ network_tokenization_data: None,
}
} else {
storage::PaymentMethodUpdate::AdditionalDataUpdate {
@@ -363,6 +364,7 @@ pub async fn handle_metadata_update(
metadata: None,
last_used_at: None,
connector_mandate_details: None,
+ network_tokenization_data: None,
}
};
let db = &*state.store;
diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs
index 00d611a8e3..3b78721db0 100644
--- a/crates/router/src/db/events.rs
+++ b/crates/router/src/db/events.rs
@@ -1318,6 +1318,7 @@ mod tests {
merchant_account_type: common_enums::MerchantAccountType::Standard,
product_type: None,
version: common_enums::ApiVersion::V1,
+ network_tokenization_credentials: None,
});
let merchant_account = state
.store
@@ -1403,6 +1404,7 @@ mod tests {
external_vault_details: domain::ExternalVaultDetails::Skip,
billing_processor_id: None,
is_l2_l3_enabled: false,
+ network_tokenization_credentials: None,
payment_method_blocking: None,
});
diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rs
index 44d370089c..e062b50122 100644
--- a/crates/router/src/types/api/admin.rs
+++ b/crates/router/src/types/api/admin.rs
@@ -95,6 +95,16 @@ impl ForeignTryFrom<domain::MerchantAccount> for MerchantAccountResponse {
.map(|config| config.parse_value("pm_collect_link_config"))
.transpose()?;
+ let network_tokenization_credentials = item
+ .network_tokenization_credentials
+ .map(|headers| {
+ headers
+ .into_inner()
+ .expose()
+ .parse_value("network_tokenization_credentials")
+ })
+ .transpose()?;
+
Ok(Self {
merchant_id,
merchant_name: item.merchant_name,
@@ -121,6 +131,7 @@ impl ForeignTryFrom<domain::MerchantAccount> for MerchantAccountResponse {
pm_collect_link_config,
product_type: item.product_type,
merchant_account_type: item.merchant_account_type,
+ network_tokenization_credentials,
})
}
}
@@ -167,6 +178,17 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {
)
})
.transpose()?;
+
+ let network_tokenization_credentials = item
+ .network_tokenization_credentials
+ .map(|headers| {
+ headers
+ .into_inner()
+ .expose()
+ .parse_value("network_tokenization_credentials")
+ })
+ .transpose()?;
+
let masked_outgoing_webhook_custom_http_headers =
outgoing_webhook_custom_http_headers.map(MaskedHeaders::from_headers);
@@ -243,6 +265,7 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {
.map(ForeignFrom::foreign_from),
billing_processor_id: item.billing_processor_id,
is_l2_l3_enabled: Some(item.is_l2_l3_enabled),
+ network_tokenization_credentials,
payment_method_blocking: item.payment_method_blocking.map(ForeignInto::foreign_into),
})
}
@@ -516,6 +539,7 @@ pub async fn create_profile_from_merchant_account(
.attach_printable("error while generating external_vault_details")?,
billing_processor_id: request.billing_processor_id,
is_l2_l3_enabled: request.is_l2_l3_enabled.unwrap_or(false),
+ network_tokenization_credentials: None, // since credentials are at merchant level, they should not be in the profile, tracked in issue #15134
payment_method_blocking: None,
}))
}
diff --git a/crates/router/src/types/domain/user.rs b/crates/router/src/types/domain/user.rs
index 1a2909eb7c..906adec917 100644
--- a/crates/router/src/types/domain/user.rs
+++ b/crates/router/src/types/domain/user.rs
@@ -513,6 +513,7 @@ impl NewUserMerchant {
pm_collect_link_config: None,
product_type: self.get_product_type(),
merchant_account_type: self.merchant_account_type,
+ network_tokenization_credentials: None,
})
}
diff --git a/crates/router/src/utils/user.rs b/crates/router/src/utils/user.rs
index 054ae2fd64..d1dc9392f6 100644
--- a/crates/router/src/utils/user.rs
+++ b/crates/router/src/utils/user.rs
@@ -335,6 +335,7 @@ pub fn create_merchant_account_request_for_org(
pm_collect_link_config: None,
product_type: Some(product_type),
merchant_account_type: None,
+ network_tokenization_credentials: None,
})
}
diff --git a/crates/storage_impl/src/payment_method.rs b/crates/storage_impl/src/payment_method.rs
index 0cadb89165..28ea879a3f 100644
--- a/crates/storage_impl/src/payment_method.rs
+++ b/crates/storage_impl/src/payment_method.rs
@@ -224,26 +224,28 @@ impl<T: DatabaseStore> PaymentMethodInterface for KVRouterStore<T> {
let p_update: PaymentMethodUpdateInternal =
payment_method_update.convert_to_payment_method_update(storage_scheme);
let updated_payment_method = p_update.clone().apply_changeset(payment_method.clone());
- self.update_resource(
- key_store,
- storage_scheme,
- payment_method
- .clone()
- .update_with_payment_method_id(&conn, p_update.clone()),
- updated_payment_method,
- UpdateResourceParams {
- updateable: kv::Updateable::PaymentMethodUpdate(Box::new(
- kv::PaymentMethodUpdateMems {
- orig: payment_method.clone(),
- update_data: p_update.clone(),
- },
- )),
- operation: Op::Update(
- key.clone(),
- &field,
- payment_method.clone().updated_by.as_deref(),
- ),
- },
+ Box::pin(
+ self.update_resource(
+ key_store,
+ storage_scheme,
+ payment_method
+ .clone()
+ .update_with_payment_method_id(&conn, p_update.clone()),
+ updated_payment_method,
+ UpdateResourceParams {
+ updateable: kv::Updateable::PaymentMethodUpdate(Box::new(
+ kv::PaymentMethodUpdateMems {
+ orig: payment_method.clone(),
+ update_data: p_update.clone(),
+ },
+ )),
+ operation: Op::Update(
+ key.clone(),
+ &field,
+ payment_method.clone().updated_by.as_deref(),
+ ),
+ },
+ ),
)
.await
}
diff --git a/migrations/2026-03-11-095341_add_network_tokenization_creds_to_domain_tables/down.sql b/migrations/2026-03-11-095341_add_network_tokenization_creds_to_domain_tables/down.sql
new file mode 100644
index 0000000000..513dc84a39
--- /dev/null
+++ b/migrations/2026-03-11-095341_add_network_tokenization_creds_to_domain_tables/down.sql
@@ -0,0 +1,3 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE merchant_account DROP COLUMN IF EXISTS network_tokenization_credentials;
+ALTER TABLE business_profile DROP COLUMN IF EXISTS network_tokenization_credentials;
\ No newline at end of file
diff --git a/migrations/2026-03-11-095341_add_network_tokenization_creds_to_domain_tables/up.sql b/migrations/2026-03-11-095341_add_network_tokenization_creds_to_domain_tables/up.sql
new file mode 100644
index 0000000000..2b5e57cc13
--- /dev/null
+++ b/migrations/2026-03-11-095341_add_network_tokenization_creds_to_domain_tables/up.sql
@@ -0,0 +1,3 @@
+-- Your SQL goes here
+ALTER TABLE merchant_account ADD COLUMN IF NOT EXISTS network_tokenization_credentials BYTEA;
+ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS network_tokenization_credentials BYTEA;
\ No newline at end of file
diff --git a/migrations/2026-03-12-111614_add_network_token_data_in_payment_methods/down.sql b/migrations/2026-03-12-111614_add_network_token_data_in_payment_methods/down.sql
new file mode 100644
index 0000000000..476622aa55
--- /dev/null
+++ b/migrations/2026-03-12-111614_add_network_token_data_in_payment_methods/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE payment_methods DROP COLUMN IF EXISTS network_tokenization_data;
\ No newline at end of file
diff --git a/migrations/2026-03-12-111614_add_network_token_data_in_payment_methods/up.sql b/migrations/2026-03-12-111614_add_network_token_data_in_payment_methods/up.sql
new file mode 100644
index 0000000000..f595324f19
--- /dev/null
+++ b/migrations/2026-03-12-111614_add_network_token_data_in_payment_methods/up.sql
@@ -0,0 +1,2 @@
+-- Your SQL goes here
+ALTER TABLE payment_methods ADD COLUMN IF NOT EXISTS network_tokenization_data BYTEA;
\ No newline at end of file