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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(payment_methods): remove `psp_tokenization` from API request and response structs (#12461)
Shankar Singh C47724b1d420d
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex cb8fbc7c84..5000c4771a 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -21563,14 +21563,6 @@],"nullable": true},- "psp_tokenization": {- "allOf": [- {- "$ref": "#/components/schemas/PspTokenization"- }- ],- "nullable": true- },"network_tokenization": {"allOf": [{@@ -22528,8 +22520,7 @@"payment_method_subtype","created","requires_cvv",- "is_default",- "psp_tokenization_enabled"+ "is_default"],"properties": {"id": {@@ -22609,10 +22600,6 @@}],"nullable": true- },- "psp_tokenization_enabled": {- "type": "boolean",- "description": "Whether psp_tokenization is enabled for the payment_method, this will be true when at least\none multi-use token with status `Active` is available for the payment method"}}},@@ -22699,14 +22686,6 @@"description": "The return url to which the customer should be redirected to after adding the payment method","nullable": true},- "psp_tokenization": {- "allOf": [- {- "$ref": "#/components/schemas/PspTokenization"- }- ],- "nullable": true- },"network_tokenization": {"allOf": [{@@ -22766,14 +22745,6 @@],"nullable": true},- "psp_tokenization": {- "allOf": [- {- "$ref": "#/components/schemas/PspTokenization"- }- ],- "nullable": true- },"network_tokenization": {"allOf": [{@@ -23168,14 +23139,6 @@],"nullable": true},- "psp_tokenization": {- "allOf": [- {- "$ref": "#/components/schemas/PspTokenization"- }- ],- "nullable": true- },"network_tokenization": {"allOf": [{diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rsindex e3f7106731..4408cde2ef 100644--- a/crates/api_models/src/payment_methods.rs+++ b/crates/api_models/src/payment_methods.rs@@ -153,10 +153,6 @@ pub struct PaymentMethodCreate {#[schema(value_type = Option<Address>)]pub billing: Option<payments::Address>,- /// The tokenization type to be applied- #[schema(value_type = Option<PspTokenization>)]- pub psp_tokenization: Option<common_types::payment_methods::PspTokenization>,-/// The network tokenization configuration if applicable#[schema(value_type = Option<NetworkTokenization>)]pub network_tokenization: Option<common_types::payment_methods::NetworkTokenization>,@@ -543,15 +539,6 @@ impl PaymentMethodCreate {_ => false,}}- pub fn get_tokenize_connector_id(- &self,- ) -> Result<id_type::MerchantConnectorAccountId, error_stack::Report<errors::ValidationError>>- {- self.psp_tokenization- .clone()- .get_required_value("psp_tokenization")- .map(|psp| psp.connector_id)- }}#[cfg(feature = "v1")]@@ -3441,10 +3428,6 @@ pub struct PaymentMethodResponseItem {///The network token details for the payment methodpub network_tokenization: Option<NetworkTokenResponse>,-- /// Whether psp_tokenization is enabled for the payment_method, this will be true when at least- /// one multi-use token with status `Active` is available for the payment method- pub psp_tokenization_enabled: bool,}#[cfg(feature = "v2")]@@ -4411,10 +4394,6 @@ pub struct PaymentMethodSessionRequest {#[schema(value_type = Option<String>)]pub return_url: Option<common_utils::types::Url>,- /// The tokenization type to be applied- #[schema(value_type = Option<PspTokenization>)]- pub psp_tokenization: Option<common_types::payment_methods::PspTokenization>,-/// The network tokenization configuration if applicable#[schema(value_type = Option<NetworkTokenization>)]pub network_tokenization: Option<common_types::payment_methods::NetworkTokenization>,@@ -4443,10 +4422,6 @@ pub struct PaymentMethodsSessionUpdateRequest {#[schema(value_type = Option<Address>)]pub billing: Option<payments::Address>,- /// The tokenization type to be applied- #[schema(value_type = Option<PspTokenization>)]- pub psp_tokenization: Option<common_types::payment_methods::PspTokenization>,-/// The network tokenization configuration if applicable#[schema(value_type = Option<NetworkTokenization>)]pub network_tokenization: Option<common_types::payment_methods::NetworkTokenization>,@@ -4539,10 +4514,6 @@ pub struct PaymentMethodSessionResponse {#[schema(value_type = Option<Address>)]pub billing: Option<payments::Address>,- /// The tokenization type to be applied- #[schema(value_type = Option<PspTokenization>)]- pub psp_tokenization: Option<common_types::payment_methods::PspTokenization>,-/// The network tokenization configuration if applicable#[schema(value_type = Option<NetworkTokenization>)]pub network_tokenization: Option<common_types::payment_methods::NetworkTokenization>,diff --git a/crates/payment_methods/src/client/create.rs b/crates/payment_methods/src/client/create.rsindex 8a38538e67..ed05fff059 100644--- a/crates/payment_methods/src/client/create.rs+++ b/crates/payment_methods/src/client/create.rs@@ -42,7 +42,6 @@ pub struct ModularPMCreateRequest {pub customer_id: id_type::CustomerId, // Payment method data will be saved when customer acceptance is given, hence customer id will always be presentpub payment_method_data: PaymentMethodCreateData,pub billing: Option<payments::Address>,- pub psp_tokenization: Option<common_types::payment_methods::PspTokenization>,pub network_tokenization: Option<common_types::payment_methods::NetworkTokenization>,pub storage_type: Option<common_enums::StorageType>,}@@ -278,7 +277,6 @@ impl TryFrom<&CreatePaymentMethodV1Request> for ModularPMCreateRequest {.billing.as_ref().map(|billing| billing.clone().into()),- psp_tokenization: None,network_tokenization: request.network_tokenization.clone(),storage_type: request.storage_type,})diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rsindex 77c25032f1..acd2416780 100644--- a/crates/router/src/core/payment_methods.rs+++ b/crates/router/src/core/payment_methods.rs@@ -967,8 +967,6 @@ pub(crate) fn get_payment_method_create_request(customer_id,payment_method_data: payment_methods::PaymentMethodCreateData::Card(card_detail),billing: billing_address.map(ToOwned::to_owned),- psp_tokenization: payment_method_session- .and_then(|pm_session| pm_session.psp_tokenization.clone()),network_tokenization: payment_method_session.and_then(|pm_session| pm_session.network_tokenization.clone()),storage_type,@@ -1013,7 +1011,6 @@ pub(crate) fn get_payment_method_create_request(bank_debit_detail,),billing: billing_address.map(ToOwned::to_owned),- psp_tokenization: None,network_tokenization: None,storage_type,};@@ -6073,7 +6070,7 @@ pub async fn payment_methods_session_create(id: payment_methods_session_id,customer_id: request.customer_id.clone(),billing,- psp_tokenization: request.psp_tokenization,+ psp_tokenization: None,network_tokenization: request.network_tokenization,tokenization_data: request.tokenization_data,expires_at,@@ -6157,7 +6154,7 @@ pub async fn payment_methods_session_update(let payment_method_session_domain_model =hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum::GeneralUpdate{billing: Box::new(billing),- psp_tokenization: request.psp_tokenization,+ psp_tokenization: None,network_tokenization: request.network_tokenization,tokenization_data: request.tokenization_data,};@@ -6417,59 +6414,6 @@ pub async fn payment_methods_session_delete_payment_method())}-#[cfg(feature = "v2")]-fn construct_zero_auth_payments_request(- confirm_request: &payment_methods::PaymentMethodSessionConfirmRequest,- payment_method_session: &hyperswitch_domain_models::payment_methods::PaymentMethodSession,- payment_method: &payment_methods::PaymentMethodResponse,- payment_method_subtype: Option<storage_enums::PaymentMethodType>,-) -> RouterResult<api_models::payments::PaymentsRequest> {- use api_models::payments;-- Ok(payments::PaymentsRequest {- amount_details: payments::AmountDetails::new_for_zero_auth_payment(- common_enums::Currency::USD,- ),- payment_method_data: confirm_request.payment_method_data.clone(),- payment_method_type: confirm_request.payment_method_type,- payment_method_subtype,- customer_id: payment_method_session.customer_id.clone(),- customer_present: Some(enums::PresenceOfCustomerDuringPayment::Present),- setup_future_usage: Some(common_enums::FutureUsage::OffSession),- payment_method_id: Some(payment_method.id.clone()),- merchant_reference_id: None,- routing_algorithm_id: None,- capture_method: None,- authentication_type: None,- // We have already passed payment method billing address- billing: None,- shipping: None,- description: None,- return_url: payment_method_session.return_url.clone(),- apply_mit_exemption: None,- statement_descriptor: None,- order_details: None,- allowed_payment_method_types: None,- metadata: None,- connector_metadata: None,- feature_metadata: None,- payment_link_enabled: None,- payment_link_config: None,- request_incremental_authorization: None,- session_expiry: None,- frm_metadata: None,- request_external_three_ds_authentication: None,- customer_acceptance: confirm_request.customer_acceptance.clone(),- browser_info: None,- force_3ds_challenge: None,- is_iframe_redirection_enabled: None,- merchant_connector_details: None,- return_raw_connector_response: None,- enable_partial_authorization: None,- webhook_url: None,- })-}-#[cfg(feature = "v2")]async fn create_zero_auth_payment(state: SessionState,@@ -6600,47 +6544,7 @@ pub async fn payment_methods_session_confirm(}).attach_printable("Failed to update payment methods session from db")?;- let payments_response = match &payment_method_session.psp_tokenization {- Some(common_types::payment_methods::PspTokenization {- tokenization_type: common_enums::TokenizationType::MultiUse,- ..- }) => {- let zero_auth_request = construct_zero_auth_payments_request(- &request,- &payment_method_session,- &payment_method_response,- payment_method.get_payment_method_subtype(),- )?;- let payments_response = Box::pin(create_zero_auth_payment(- state.clone(),- req_state,- platform.clone(),- profile.clone(),- zero_auth_request,- ))- .await?;-- Some(payments_response)- }- Some(common_types::payment_methods::PspTokenization {- tokenization_type: common_enums::TokenizationType::SingleUse,- ..- }) => {- Box::pin(create_single_use_tokenization_flow(- state.clone(),- req_state.clone(),- platform.clone(),- profile.clone(),- &create_payment_method_request.clone(),- &payment_method_response,- &payment_method_session,- request.customer_acceptance.clone(),- ))- .await?;- None- }- None => None,- };+ let payments_response: Option<api_models::payments::PaymentsResponse> = None;let tokenization_response = match (payment_method_session.tokenization_data.clone(),@@ -6740,175 +6644,6 @@ impl pm_types::SavedPMLPaymentsInfo {}}-#[cfg(feature = "v2")]-#[allow(clippy::too_many_arguments)]-async fn create_single_use_tokenization_flow(- state: SessionState,- req_state: routes::app::ReqState,- platform: domain::Platform,- profile: domain::Profile,- payment_method_create_request: &payment_methods::PaymentMethodCreate,- payment_method: &api::PaymentMethodResponse,- payment_method_session: &domain::payment_methods::PaymentMethodSession,- customer_acceptance: Option<common_types::payments::CustomerAcceptance>,-) -> RouterResult<()> {- let customer_id = payment_method_create_request.customer_id.to_owned();- let connector_id = payment_method_create_request- .get_tokenize_connector_id()- .change_context(errors::ApiErrorResponse::MissingRequiredField {- field_name: "psp_tokenization.connector_id",- })- .attach_printable("Failed to get tokenize connector id")?;-- let db = &state.store;-- let merchant_connector_account_details = db- .find_merchant_connector_account_by_id(- &connector_id,- platform.get_processor().get_key_store(),- )- .await- .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {- id: connector_id.get_string_repr().to_owned(),- })- .attach_printable("error while fetching merchant_connector_account from connector_id")?;- let auth_type = merchant_connector_account_details- .get_connector_account_details()- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed while parsing value for ConnectorAuthType")?;-- let payment_method_data_request = types::PaymentMethodTokenizationData {- payment_method_data: domain::PaymentMethodData::try_from(- payment_method_create_request.payment_method_data.clone(),- )- .change_context(errors::ApiErrorResponse::MissingRequiredField {- field_name: "card_cvc",- })- .attach_printable(- "Failed to convert type from Payment Method Create Data to Payment Method Data",- )?,- browser_info: None,- currency: api_models::enums::Currency::default(),- amount: None,- split_payments: None,- mandate_id: None,- setup_future_usage: None,- customer_acceptance,- setup_mandate_details: None,- payment_method_type: None,- capture_method: None,- router_return_url: None,- };-- let payment_method_session_address = types::PaymentAddress::new(- None,- payment_method_session- .billing- .clone()- .map(|address| address.into_inner()),- None,- None,- );-- let mut router_data =- types::RouterData::<api::PaymentMethodToken, _, types::PaymentsResponseData> {- flow: std::marker::PhantomData,- merchant_id: platform.get_provider().get_account().get_id().clone(),- customer_id: None,- connector_customer: None,- connector: merchant_connector_account_details- .connector_name- .to_string(),- payment_id: consts::IRRELEVANT_PAYMENT_INTENT_ID.to_string(), //Static- attempt_id: consts::IRRELEVANT_PAYMENT_ATTEMPT_ID.to_string(), //Static- tenant_id: state.tenant.tenant_id.clone(),- status: common_enums::enums::AttemptStatus::default(),- payment_method: common_enums::enums::PaymentMethod::Card,- payment_method_type: None,- connector_auth_type: auth_type,- description: None,- address: payment_method_session_address,- auth_type: common_enums::enums::AuthenticationType::default(),- connector_meta_data: None,- connector_wallets_details: None,- amount_captured: None,- access_token: None,- session_token: None,- reference_id: None,- payment_method_token: None,- recurring_mandate_payment_data: None,- preprocessing_id: None,- payment_method_balance: None,- connector_api_version: None,- request: payment_method_data_request.clone(),- response: Err(hyperswitch_domain_models::router_data::ErrorResponse::default()),- connector_request_reference_id: payment_method_session.id.get_string_repr().to_string(),- #[cfg(feature = "payouts")]- payout_method_data: None,- #[cfg(feature = "payouts")]- quote_id: None,- test_mode: None,- connector_http_status_code: None,- external_latency: None,- apple_pay_flow: None,- frm_metadata: None,- dispute_id: None,- refund_id: None,- payout_id: None,- connector_response: None,- payment_method_status: None,- minor_amount_captured: None,- integrity_check: Ok(()),- additional_merchant_data: None,- header_payload: None,- connector_mandate_request_reference_id: None,- authentication_id: None,- psd2_sca_exemption_type: None,- raw_connector_response: None,- is_payment_id_from_merchant: None,- l2_l3_data: None,- minor_amount_capturable: None,- authorized_amount: None,- customer_document_details: None,- feature_data: None,- sender_payment_instrument_id: None,- };-- let payment_method_token_response = Box::pin(tokenization::add_token_for_payment_method(- &mut router_data,- payment_method_data_request.clone(),- state.clone(),- &merchant_connector_account_details.clone(),- ))- .await?;-- let token_response = payment_method_token_response.token.map_err(|err| {- errors::ApiErrorResponse::ExternalConnectorError {- code: err.code,- message: err.message,- connector: (merchant_connector_account_details.clone())- .connector_name- .to_string(),- status_code: err.status_code,- reason: err.reason,- }- })?;-- let value = domain::SingleUsePaymentMethodToken::get_single_use_token_from_payment_method_token(- token_response.clone().into(),- connector_id.clone(),- );-- let key = domain::SingleUseTokenKey::store_key(&payment_method.id);-- add_single_use_token_to_store(&state, key, value)- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to store single use token")?;-- Ok(())-}-#[cfg(feature = "v2")]async fn add_single_use_token_to_store(state: &SessionState,diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rsindex fd82140c57..ab34bf35e6 100644--- a/crates/router/src/core/payment_methods/transformers.rs+++ b/crates/router/src/core/payment_methods/transformers.rs@@ -1159,15 +1159,6 @@ impl// TODO: check how we can get this fieldlet recurring_enabled = Some(true);- let psp_tokenization_enabled = item.connector_mandate_details.and_then(|details| {- details.payments.map(|payments| {- payments.values().any(|connector_token_reference| {- connector_token_reference.connector_token_status- == api_enums::ConnectorTokenStatus::Active- })- })- });-let is_default = default_payment_method_id.is_some()&& default_payment_method_id == Some(item.id.clone());@@ -1190,7 +1181,6 @@ implis_default,billing: payment_method_billing,network_tokenization: network_token_resp,- psp_tokenization_enabled: psp_tokenization_enabled.unwrap_or(false),})}}@@ -1233,7 +1223,6 @@ pub fn generate_payment_method_session_response(.billing.map(|address| address.into_inner()).map(From::from),- psp_tokenization: payment_method_session.psp_tokenization,network_tokenization: payment_method_session.network_tokenization,tokenization_data: payment_method_session.tokenization_data,expires_at: payment_method_session.expires_at,diff --git a/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs b/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rsindex 35804a59e1..adcf351184 100644--- a/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs+++ b/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs@@ -382,7 +382,6 @@ impl<F: Clone + Send + Sync> Domain<F, ExternalVaultProxyPaymentsRequest, Paymencustomer_id: Some(customer_id),payment_method_data,billing,- psp_tokenization: None,network_tokenization: None,storage_type: common_enums::StorageType::Persistent, //this field is currently not being used in storing payment methods via external vault};diff --git a/crates/router/src/core/payments/operations/payment_confirm_intent.rs b/crates/router/src/core/payments/operations/payment_confirm_intent.rsindex 88e0683721..d4e7b59dbc 100644--- a/crates/router/src/core/payments/operations/payment_confirm_intent.rs+++ b/crates/router/src/core/payments/operations/payment_confirm_intent.rs@@ -641,7 +641,6 @@ impl<F: Clone + Send + Sync> Domain<F, PaymentsConfirmIntentRequest, PaymentConfcustomer_id: Some(customer_id),payment_method_data: pm_create_data,billing: None,- psp_tokenization: None,network_tokenization: None,storage_type: common_enums::StorageType::Persistent, //since customer acceptance is present, we always store it persistently};diff --git a/crates/router/src/types/api/payment_methods.rs b/crates/router/src/types/api/payment_methods.rsindex 63e5040f0f..524c09e015 100644--- a/crates/router/src/types/api/payment_methods.rs+++ b/crates/router/src/types/api/payment_methods.rs@@ -162,25 +162,6 @@ impl PaymentMethodSessionExt for api_models::payment_methods::PaymentMethodSessi},)?;- utils::when(- payment_method_session.psp_tokenization.is_some() && self.customer_acceptance.is_none(),- || {- Err(report!(errors::ApiErrorResponse::MissingRequiredField {- field_name: "customer_acceptance"- }))- },- )?;-- utils::when(- self.payment_method_type == api_models::enums::PaymentMethod::BankDebit- && self.payment_method_subtype.is_none(),- || {- Err(report!(errors::ApiErrorResponse::MissingRequiredField {- field_name: "payment_method_subtype"- }))- },- )?;-Ok(())}}