From 980aa448634de86f11fb67aabefc15884f1b8ced Mon Sep 17 00:00:00 2001 From: ItsMeShashank Date: Thu, 5 Oct 2023 20:56:44 +0530 Subject: [PATCH] refactor(router): remove the payment type column in payment intent (#2462) --- crates/data_models/src/payments/payment_intent.rs | 2 -- crates/diesel_models/src/payment_intent.rs | 2 -- crates/diesel_models/src/schema.rs | 1 - crates/router/src/core/payment_methods/cards.rs | 15 ++++++++++++++- crates/router/src/core/payments/helpers.rs | 3 --- .../core/payments/operations/payment_create.rs | 5 ----- crates/storage_impl/src/mock_db/payment_intent.rs | 1 - .../storage_impl/src/payments/payment_intent.rs | 5 ----- .../down.sql | 6 ------ .../up.sql | 11 ----------- 10 files changed, 14 insertions(+), 37 deletions(-) delete mode 100644 migrations/2023-10-04-120026_add_payment_type_column_in_payment_intent/down.sql delete mode 100644 migrations/2023-10-04-120026_add_payment_type_column_in_payment_intent/up.sql diff --git a/crates/data_models/src/payments/payment_intent.rs b/crates/data_models/src/payments/payment_intent.rs index db182839b952..b3bf8af8c36b 100644 --- a/crates/data_models/src/payments/payment_intent.rs +++ b/crates/data_models/src/payments/payment_intent.rs @@ -105,7 +105,6 @@ pub struct PaymentIntent { // Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment pub merchant_decision: Option, pub payment_confirm_source: Option, - pub payment_type: Option, } #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] @@ -145,7 +144,6 @@ pub struct PaymentIntentNew { pub profile_id: Option, pub merchant_decision: Option, pub payment_confirm_source: Option, - pub payment_type: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs index a6de1137de2c..1212c9d52424 100644 --- a/crates/diesel_models/src/payment_intent.rs +++ b/crates/diesel_models/src/payment_intent.rs @@ -47,7 +47,6 @@ pub struct PaymentIntent { // Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment pub merchant_decision: Option, pub payment_confirm_source: Option, - pub payment_type: Option, } #[derive( @@ -99,7 +98,6 @@ pub struct PaymentIntentNew { pub profile_id: Option, pub merchant_decision: Option, pub payment_confirm_source: Option, - pub payment_type: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index f1ebcdb4346f..3a6e2cd2a936 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -609,7 +609,6 @@ diesel::table! { #[max_length = 64] merchant_decision -> Nullable, payment_confirm_source -> Nullable, - payment_type -> Nullable, } } diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index f5428592da1d..bcb52164471d 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -861,6 +861,19 @@ pub async fn list_payment_methods( .await .transpose()?; + let payment_type = payment_attempt.as_ref().map(|pa| { + let amount = api::Amount::from(pa.amount); + let mandate_type = if pa.mandate_id.is_some() { + Some(api::MandateTransactionType::RecurringMandateTransaction) + } else if pa.mandate_details.is_some() { + Some(api::MandateTransactionType::NewMandateTransaction) + } else { + None + }; + + helpers::infer_payment_type(&amount, mandate_type.as_ref()) + }); + let all_mcas = db .find_merchant_connector_account_by_merchant_id_and_disabled_list( &merchant_account.merchant_id, @@ -1280,8 +1293,8 @@ pub async fn list_payment_methods( api::PaymentMethodListResponse { redirect_url: merchant_account.return_url, merchant_name: merchant_account.merchant_name, + payment_type, payment_methods: payment_method_responses, - payment_type: payment_intent.as_ref().and_then(|pi| pi.payment_type), mandate_payment: payment_attempt.and_then(|inner| inner.mandate_details).map( |d| match d { data_models::mandates::MandateDataType::SingleUse(i) => { diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 3417e9db4e25..440d284d0ccb 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -2398,7 +2398,6 @@ mod tests { profile_id: None, merchant_decision: None, payment_confirm_source: None, - payment_type: Some(api_enums::PaymentType::Normal), }; let req_cs = Some("1".to_string()); let merchant_fulfillment_time = Some(900); @@ -2446,7 +2445,6 @@ mod tests { profile_id: None, merchant_decision: None, payment_confirm_source: None, - payment_type: Some(api_enums::PaymentType::Normal), }; let req_cs = Some("1".to_string()); let merchant_fulfillment_time = Some(10); @@ -2494,7 +2492,6 @@ mod tests { profile_id: None, merchant_decision: None, payment_confirm_source: None, - payment_type: Some(api_enums::PaymentType::Normal), }; let req_cs = Some("1".to_string()); let merchant_fulfillment_time = Some(10); diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 8971aaeed336..17d8d5f6c3d7 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -77,8 +77,6 @@ impl GetTracker, api::PaymentsRequest> for Pa core_utils::validate_and_get_business_profile(db, request.profile_id.as_ref(), merchant_id) .await?; - let payment_type = helpers::infer_payment_type(&amount, mandate_type.as_ref()); - let ( token, payment_method, @@ -147,7 +145,6 @@ impl GetTracker, api::PaymentsRequest> for Pa request, shipping_address.clone().map(|x| x.address_id), billing_address.clone().map(|x| x.address_id), - payment_type, attempt_id, state, ) @@ -606,7 +603,6 @@ impl PaymentCreate { request: &api::PaymentsRequest, shipping_address_id: Option, billing_address_id: Option, - payment_type: enums::PaymentType, active_attempt_id: String, state: &AppState, ) -> RouterResult { @@ -681,7 +677,6 @@ impl PaymentCreate { profile_id: Some(profile_id), merchant_decision: None, payment_confirm_source: None, - payment_type: Some(payment_type), }) } diff --git a/crates/storage_impl/src/mock_db/payment_intent.rs b/crates/storage_impl/src/mock_db/payment_intent.rs index ff8ae44758a0..43d7207d452a 100644 --- a/crates/storage_impl/src/mock_db/payment_intent.rs +++ b/crates/storage_impl/src/mock_db/payment_intent.rs @@ -106,7 +106,6 @@ impl PaymentIntentInterface for MockDb { profile_id: new.profile_id, merchant_decision: new.merchant_decision, payment_confirm_source: new.payment_confirm_source, - payment_type: new.payment_type, }; payment_intents.push(payment_intent.clone()); Ok(payment_intent) diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs index f30d26e30d7e..8352158be052 100644 --- a/crates/storage_impl/src/payments/payment_intent.rs +++ b/crates/storage_impl/src/payments/payment_intent.rs @@ -91,7 +91,6 @@ impl PaymentIntentInterface for KVRouterStore { profile_id: new.profile_id.clone(), merchant_decision: new.merchant_decision.clone(), payment_confirm_source: new.payment_confirm_source, - payment_type: new.payment_type, }; match self @@ -708,7 +707,6 @@ impl DataModelExt for PaymentIntentNew { profile_id: self.profile_id, merchant_decision: self.merchant_decision, payment_confirm_source: self.payment_confirm_source, - payment_type: self.payment_type, } } @@ -746,7 +744,6 @@ impl DataModelExt for PaymentIntentNew { profile_id: storage_model.profile_id, merchant_decision: storage_model.merchant_decision, payment_confirm_source: storage_model.payment_confirm_source, - payment_type: storage_model.payment_type, } } } @@ -789,7 +786,6 @@ impl DataModelExt for PaymentIntent { profile_id: self.profile_id, merchant_decision: self.merchant_decision, payment_confirm_source: self.payment_confirm_source, - payment_type: self.payment_type, } } @@ -828,7 +824,6 @@ impl DataModelExt for PaymentIntent { profile_id: storage_model.profile_id, merchant_decision: storage_model.merchant_decision, payment_confirm_source: storage_model.payment_confirm_source, - payment_type: storage_model.payment_type, } } } diff --git a/migrations/2023-10-04-120026_add_payment_type_column_in_payment_intent/down.sql b/migrations/2023-10-04-120026_add_payment_type_column_in_payment_intent/down.sql deleted file mode 100644 index 74f43b254fd9..000000000000 --- a/migrations/2023-10-04-120026_add_payment_type_column_in_payment_intent/down.sql +++ /dev/null @@ -1,6 +0,0 @@ --- This file should undo anything in `up.sql` - -ALTER TABLE payment_intent -DROP COLUMN payment_type; - -DROP TYPE "PaymentType"; diff --git a/migrations/2023-10-04-120026_add_payment_type_column_in_payment_intent/up.sql b/migrations/2023-10-04-120026_add_payment_type_column_in_payment_intent/up.sql deleted file mode 100644 index 622f24b48b3f..000000000000 --- a/migrations/2023-10-04-120026_add_payment_type_column_in_payment_intent/up.sql +++ /dev/null @@ -1,11 +0,0 @@ --- Your SQL goes here - -CREATE TYPE "PaymentType" AS ENUM ( - 'normal', - 'new_mandate', - 'setup_mandate', - 'recurring_mandate' -); - -ALTER TABLE payment_intent -ADD COLUMN payment_type "PaymentType";