feat(router): adding generic tokenization endpoint (#7905)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Shivansh Mathur
2025-05-27 11:39:36 +05:30
committed by GitHub
parent c4a5e3ac16
commit 49a178ed20
60 changed files with 1450 additions and 38 deletions

View File

@ -22,6 +22,8 @@ use common_utils::{
};
use crate::customers::CustomerListRequest;
#[cfg(feature = "tokenization_v2")]
use crate::tokenization;
#[allow(unused_imports)]
use crate::{
admin::*,
@ -228,3 +230,8 @@ impl ApiEventMetric for PaymentMethodSessionResponse {
})
}
}
#[cfg(feature = "tokenization_v2")]
impl ApiEventMetric for tokenization::GenericTokenizationRequest {}
#[cfg(feature = "tokenization_v2")]
impl ApiEventMetric for tokenization::GenericTokenizationResponse {}

View File

@ -40,6 +40,8 @@ pub mod refunds;
pub mod relay;
pub mod routing;
pub mod surcharge_decision_configs;
#[cfg(feature = "tokenization_v2")]
pub mod tokenization;
pub mod user;
pub mod user_role;
pub mod verifications;

View File

@ -2861,6 +2861,10 @@ pub struct PaymentMethodSessionRequest {
/// If not provided, the session will expire in 15 minutes
#[schema(example = 900, default = 900)]
pub expires_in: Option<u32>,
/// Contains data to be passed on to tokenization service ( if present ) to create token_id for given JSON data
#[schema(value_type = Option<serde_json::Value>)]
pub tokenization_data: Option<pii::SecretSerdeValue>,
}
#[cfg(feature = "v2")]
@ -2877,6 +2881,10 @@ pub struct PaymentMethodsSessionUpdateRequest {
/// The network tokenization configuration if applicable
#[schema(value_type = Option<NetworkTokenization>)]
pub network_tokenization: Option<common_types::payment_methods::NetworkTokenization>,
/// Contains data to be passed on to tokenization service ( if present ) to create token_id for given JSON data
#[schema(value_type = Option<serde_json::Value>)]
pub tokenization_data: Option<pii::SecretSerdeValue>,
}
#[cfg(feature = "v2")]
@ -2941,6 +2949,10 @@ pub struct PaymentMethodSessionResponse {
#[schema(value_type = Option<NetworkTokenization>)]
pub network_tokenization: Option<common_types::payment_methods::NetworkTokenization>,
/// Contains data to be passed on to tokenization service ( if present ) to create token_id for given JSON data
#[schema(value_type = Option<serde_json::Value>)]
pub tokenization_data: Option<pii::SecretSerdeValue>,
/// The iso timestamp when the session will expire
/// Trying to retrieve the session or any operations on the session after this time will result in an error
#[schema(value_type = PrimitiveDateTime, example = "2023-01-18T11:04:09.922Z")]
@ -2966,6 +2978,10 @@ pub struct PaymentMethodSessionResponse {
/// The payment method that was created using this payment method session
#[schema(value_type = Option<Vec<String>>)]
pub associated_payment_methods: Option<Vec<id_type::GlobalPaymentMethodId>>,
/// The token-id created if there is tokenization_data present
#[schema(value_type = Option<String>, example = "12345_tok_01926c58bc6e77c09e809964e72af8c8")]
pub associated_token_id: Option<id_type::GlobalTokenId>,
}
#[cfg(feature = "v2")]

View File

@ -0,0 +1,30 @@
use common_enums;
use common_utils::id_type::{GlobalCustomerId, GlobalTokenId};
use masking::Secret;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
use utoipa::{schema, ToSchema};
#[cfg(all(feature = "v2", feature = "tokenization_v2"))]
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct GenericTokenizationResponse {
/// Unique identifier returned by the tokenization service
#[schema(value_type = String, example = "12345_tok_01926c58bc6e77c09e809964e72af8c8")]
pub id: GlobalTokenId,
/// Created time of the tokenization id
#[schema(value_type = PrimitiveDateTime,example = "2024-02-24T11:04:09.922Z")]
pub created_at: PrimitiveDateTime,
/// Status of the tokenization id created
#[schema(value_type = String,example = "enabled")]
pub flag: common_enums::TokenizationFlag,
}
#[cfg(all(feature = "v2", feature = "tokenization_v2"))]
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct GenericTokenizationRequest {
/// Customer ID for which the tokenization is requested
#[schema(value_type = String, example = "12345_cus_01926c58bc6e77c09e809964e72af8c8")]
pub customer_id: GlobalCustomerId,
/// Request for tokenization which contains the data to be tokenized
#[schema(value_type = Object,example = json!({ "city": "NY", "unit": "245" }))]
pub token_request: masking::Secret<serde_json::Value>,
}