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(core): remove connector response table and use payment_attempt instead (#2644)
Abhishek Marrivagu966369b6f2c2
diff --git a/crates/data_models/src/payments/payment_attempt.rs b/crates/data_models/src/payments/payment_attempt.rsindex 734de8fe4a..cdd41ea9db 100644--- a/crates/data_models/src/payments/payment_attempt.rs+++ b/crates/data_models/src/payments/payment_attempt.rs@@ -286,6 +286,8 @@ pub enum PaymentAttemptUpdate {connector_response_reference_id: Option<String>,amount_capturable: Option<i64>,updated_by: String,+ authentication_data: Option<serde_json::Value>,+ encoded_data: Option<String>,},UnresolvedResponseUpdate {status: storage_enums::AttemptStatus,diff --git a/crates/diesel_models/src/connector_response.rs b/crates/diesel_models/src/connector_response.rsdeleted file mode 100644index 863ce28ee0..0000000000--- a/crates/diesel_models/src/connector_response.rs+++ /dev/null@@ -1,122 +0,0 @@-use diesel::{AsChangeset, Identifiable, Insertable, Queryable};-use serde::{Deserialize, Serialize};-use time::PrimitiveDateTime;--use crate::schema::connector_response;--#[derive(Clone, Debug, Deserialize, Serialize, Insertable, router_derive::DebugAsDisplay)]-#[diesel(table_name = connector_response)]-#[serde(deny_unknown_fields)]-pub struct ConnectorResponseNew {- pub payment_id: String,- pub merchant_id: String,- pub attempt_id: String,- #[serde(with = "common_utils::custom_serde::iso8601")]- pub created_at: PrimitiveDateTime,- #[serde(with = "common_utils::custom_serde::iso8601")]- pub modified_at: PrimitiveDateTime,- pub connector_name: Option<String>,- pub connector_transaction_id: Option<String>,- pub authentication_data: Option<serde_json::Value>,- pub encoded_data: Option<String>,- pub updated_by: String,-}--#[derive(Clone, Debug, Deserialize, Serialize, Identifiable, Queryable)]-#[diesel(table_name = connector_response)]-pub struct ConnectorResponse {- pub id: i32,- pub payment_id: String,- pub merchant_id: String,- pub attempt_id: String,- #[serde(with = "common_utils::custom_serde::iso8601")]- pub created_at: PrimitiveDateTime,- #[serde(with = "common_utils::custom_serde::iso8601")]- pub modified_at: PrimitiveDateTime,- pub connector_name: Option<String>,- pub connector_transaction_id: Option<String>,- pub authentication_data: Option<serde_json::Value>,- pub encoded_data: Option<String>,- pub updated_by: String,-}--#[derive(Clone, Default, Debug, Deserialize, AsChangeset, Serialize)]-#[diesel(table_name = connector_response)]-pub struct ConnectorResponseUpdateInternal {- pub connector_transaction_id: Option<String>,- pub authentication_data: Option<serde_json::Value>,- pub modified_at: Option<PrimitiveDateTime>,- pub encoded_data: Option<String>,- pub connector_name: Option<String>,- pub updated_by: String,-}--#[derive(Clone, Debug, Serialize, Deserialize)]-pub enum ConnectorResponseUpdate {- ResponseUpdate {- connector_transaction_id: Option<String>,- authentication_data: Option<serde_json::Value>,- encoded_data: Option<String>,- connector_name: Option<String>,- updated_by: String,- },- ErrorUpdate {- connector_name: Option<String>,- updated_by: String,- },-}--impl ConnectorResponseUpdate {- pub fn apply_changeset(self, source: ConnectorResponse) -> ConnectorResponse {- let connector_response_update: ConnectorResponseUpdateInternal = self.into();- ConnectorResponse {- modified_at: connector_response_update- .modified_at- .unwrap_or_else(common_utils::date_time::now),- connector_name: connector_response_update- .connector_name- .or(source.connector_name),- connector_transaction_id: source- .connector_transaction_id- .or(connector_response_update.connector_transaction_id),- authentication_data: connector_response_update- .authentication_data- .or(source.authentication_data),- encoded_data: connector_response_update- .encoded_data- .or(source.encoded_data),- updated_by: connector_response_update.updated_by,- ..source- }- }-}--impl From<ConnectorResponseUpdate> for ConnectorResponseUpdateInternal {- fn from(connector_response_update: ConnectorResponseUpdate) -> Self {- match connector_response_update {- ConnectorResponseUpdate::ResponseUpdate {- connector_transaction_id,- authentication_data,- encoded_data,- connector_name,- updated_by,- } => Self {- connector_transaction_id,- authentication_data,- encoded_data,- modified_at: Some(common_utils::date_time::now()),- connector_name,- updated_by,- },- ConnectorResponseUpdate::ErrorUpdate {- connector_name,- updated_by,- } => Self {- connector_name,- modified_at: Some(common_utils::date_time::now()),- updated_by,- ..Self::default()- },- }- }-}diff --git a/crates/diesel_models/src/kv.rs b/crates/diesel_models/src/kv.rsindex 81fa7a88ee..f56ef83041 100644--- a/crates/diesel_models/src/kv.rs+++ b/crates/diesel_models/src/kv.rs@@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize};use crate::{address::{Address, AddressNew, AddressUpdateInternal},- connector_response::{ConnectorResponse, ConnectorResponseNew, ConnectorResponseUpdate},errors,payment_attempt::{PaymentAttempt, PaymentAttemptNew, PaymentAttemptUpdate},payment_intent::{PaymentIntentNew, PaymentIntentUpdate},@@ -51,7 +50,6 @@ pub enum Insertable {PaymentIntent(PaymentIntentNew),PaymentAttempt(PaymentAttemptNew),Refund(RefundNew),- ConnectorResponse(ConnectorResponseNew),Address(Box<AddressNew>),ReverseLookUp(ReverseLookupNew),}@@ -62,16 +60,9 @@ pub enum Updateable {PaymentIntentUpdate(PaymentIntentUpdateMems),PaymentAttemptUpdate(PaymentAttemptUpdateMems),RefundUpdate(RefundUpdateMems),- ConnectorResponseUpdate(ConnectorResponseUpdateMems),AddressUpdate(Box<AddressUpdateMems>),}-#[derive(Debug, Serialize, Deserialize)]-pub struct ConnectorResponseUpdateMems {- pub orig: ConnectorResponse,- pub update_data: ConnectorResponseUpdate,-}-#[derive(Debug, Serialize, Deserialize)]pub struct AddressUpdateMems {pub orig: Address,diff --git a/crates/diesel_models/src/lib.rs b/crates/diesel_models/src/lib.rsindex 08d74fb8fd..46a6965b3a 100644--- a/crates/diesel_models/src/lib.rs+++ b/crates/diesel_models/src/lib.rs@@ -4,7 +4,7 @@ pub mod business_profile;pub mod capture;pub mod cards_info;pub mod configs;-pub mod connector_response;+pub mod customers;pub mod dispute;pub mod encryption;@@ -44,10 +44,10 @@ use diesel_impl::{DieselArray, OptionalDieselArray};pub type StorageResult<T> = error_stack::Result<T, errors::DatabaseError>;pub type PgPooledConn = async_bb8_diesel::Connection<diesel::PgConnection>;pub use self::{- address::*, api_keys::*, cards_info::*, configs::*, connector_response::*, customers::*,- dispute::*, ephemeral_key::*, events::*, file::*, locker_mock_up::*, mandate::*,- merchant_account::*, merchant_connector_account::*, payment_attempt::*, payment_intent::*,- payment_method::*, process_tracker::*, refund::*, reverse_lookup::*,+ address::*, api_keys::*, cards_info::*, configs::*, customers::*, dispute::*, ephemeral_key::*,+ events::*, file::*, locker_mock_up::*, mandate::*, merchant_account::*,+ merchant_connector_account::*, payment_attempt::*, payment_intent::*, payment_method::*,+ process_tracker::*, refund::*, reverse_lookup::*,};/// The types and implementations provided by this module are required for the schema generated bydiff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rsindex 0580861061..ce388fea10 100644--- a/crates/diesel_models/src/payment_attempt.rs+++ b/crates/diesel_models/src/payment_attempt.rs@@ -203,6 +203,8 @@ pub enum PaymentAttemptUpdate {connector_response_reference_id: Option<String>,amount_capturable: Option<i64>,updated_by: String,+ authentication_data: Option<serde_json::Value>,+ encoded_data: Option<String>,},UnresolvedResponseUpdate {status: storage_enums::AttemptStatus,@@ -478,6 +480,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {connector_response_reference_id,amount_capturable,updated_by,+ authentication_data,+ encoded_data,} => Self {status: Some(status),connector,@@ -494,6 +498,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {connector_response_reference_id,amount_capturable,updated_by,+ authentication_data,+ encoded_data,..Default::default()},PaymentAttemptUpdate::ErrorUpdate {diff --git a/crates/diesel_models/src/query.rs b/crates/diesel_models/src/query.rsindex ac3eeba443..f315327702 100644--- a/crates/diesel_models/src/query.rs+++ b/crates/diesel_models/src/query.rs@@ -4,7 +4,7 @@ pub mod business_profile;mod capture;pub mod cards_info;pub mod configs;-pub mod connector_response;+pub mod customers;pub mod dispute;pub mod events;diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 9933bf90a5..6c9cea035b 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -157,31 +157,6 @@ diesel::table! {}}-diesel::table! {- use diesel::sql_types::*;- use crate::enums::diesel_exports::*;-- connector_response (id) {- id -> Int4,- #[max_length = 64]- payment_id -> Varchar,- #[max_length = 64]- merchant_id -> Varchar,- #[max_length = 64]- attempt_id -> Varchar,- created_at -> Timestamp,- modified_at -> Timestamp,- #[max_length = 64]- connector_name -> Nullable<Varchar>,- #[max_length = 128]- connector_transaction_id -> Nullable<Varchar>,- authentication_data -> Nullable<Json>,- encoded_data -> Nullable<Text>,- #[max_length = 32]- updated_by -> Varchar,- }-}-diesel::table! {use diesel::sql_types::*;use crate::enums::diesel_exports::*;@@ -932,7 +907,6 @@ diesel::allow_tables_to_appear_in_same_query!(captures,cards_info,configs,- connector_response,customers,dispute,events,diff --git a/crates/drainer/src/lib.rs b/crates/drainer/src/lib.rsindex 19abe9ba3a..7ccfd600d6 100644--- a/crates/drainer/src/lib.rs+++ b/crates/drainer/src/lib.rs@@ -206,7 +206,6 @@ async fn drainer(let payment_attempt = "payment_attempt";let refund = "refund";let reverse_lookup = "reverse_lookup";- let connector_response = "connector_response";let address = "address";match db_op {// TODO: Handle errors@@ -230,13 +229,6 @@ async fn drainer(kv::Insertable::Refund(a) => {macro_util::handle_resp!(a.insert(&conn).await, insert_op, refund)}- kv::Insertable::ConnectorResponse(a) => {- macro_util::handle_resp!(- a.insert(&conn).await,- insert_op,- connector_response- )- }kv::Insertable::Address(addr) => {macro_util::handle_resp!(addr.insert(&conn).await, insert_op, address)}@@ -283,11 +275,6 @@ async fn drainer(refund)}- kv::Updateable::ConnectorResponseUpdate(a) => macro_util::handle_resp!(- a.orig.update(&conn, a.update_data).await,- update_op,- connector_response- ),kv::Updateable::AddressUpdate(a) => macro_util::handle_resp!(a.orig.update(&conn, a.update_data).await,update_op,diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 98ab158e79..a114b20380 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -1578,7 +1578,6 @@ wherepub payment_intent: storage::PaymentIntent,pub payment_attempt: storage::PaymentAttempt,pub multiple_capture_data: Option<types::MultipleCaptureData>,- pub connector_response: storage::ConnectorResponse,pub amount: api::Amount,pub mandate_id: Option<api_models::payments::MandateIds>,pub mandate_connector: Option<MandateConnectorDetails>,@@ -1671,10 +1670,7 @@ pub fn should_call_connector<Op: Debug, F: Clone>(!matches!(payment_data.payment_intent.status,storage_enums::IntentStatus::Failed | storage_enums::IntentStatus::Succeeded- ) && payment_data- .connector_response- .authentication_data- .is_none()+ ) && payment_data.payment_attempt.authentication_data.is_none()}"PaymentStatus" => {matches!(diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex fd9fd7361d..4ee2fd4b94 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -2998,60 +2998,6 @@ impl AttemptType {}}}-- #[instrument(skip_all)]- pub async fn get_or_insert_connector_response(- &self,- payment_attempt: &PaymentAttempt,- db: &dyn StorageInterface,- storage_scheme: storage::enums::MerchantStorageScheme,- ) -> RouterResult<storage::ConnectorResponse> {- match self {- Self::New => db- .insert_connector_response(- payments::PaymentCreate::make_connector_response(payment_attempt),- storage_scheme,- )- .await- .to_duplicate_response(errors::ApiErrorResponse::DuplicatePayment {- payment_id: payment_attempt.payment_id.clone(),- }),- Self::SameOld => db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- &payment_attempt.payment_id,- &payment_attempt.merchant_id,- &payment_attempt.attempt_id,- storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound),- }- }-- #[instrument(skip_all)]- pub async fn get_connector_response(- &self,- db: &dyn StorageInterface,- payment_id: &str,- merchant_id: &str,- attempt_id: &str,- storage_scheme: storage_enums::MerchantStorageScheme,- ) -> RouterResult<storage::ConnectorResponse> {- match self {- Self::New => Err(errors::ApiErrorResponse::InternalServerError)- .into_report()- .attach_printable("Precondition failed, the attempt type should not be `New`"),- Self::SameOld => db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- payment_id,- merchant_id,- attempt_id,- storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound),- }- }}#[inline(always)]diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rsindex 4cd1bae04d..d5d0d2d017 100644--- a/crates/router/src/core/payments/operations/payment_approve.rs+++ b/crates/router/src/core/payments/operations/payment_approve.rs@@ -161,16 +161,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>).await?;- let connector_response = db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- &payment_attempt.payment_id,- &payment_attempt.merchant_id,- &payment_attempt.attempt_id,- storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;-let redirect_response = request.feature_metadata.as_ref()@@ -224,7 +214,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>payment_intent,payment_attempt,currency,- connector_response,amount,email: request.email.clone(),mandate_id: None,diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rsindex 43fdc440e6..f734afef78 100644--- a/crates/router/src/core/payments/operations/payment_cancel.rs+++ b/crates/router/src/core/payments/operations/payment_cancel.rs@@ -106,15 +106,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>).await?;- let connector_response = db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- &payment_attempt.payment_id,- &payment_attempt.merchant_id,- &payment_attempt.attempt_id,- storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;let currency = payment_attempt.currency.get_required_value("currency")?;let amount = payment_attempt.amount.into();@@ -161,7 +152,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>refunds: vec![],disputes: vec![],attempts: None,- connector_response,+sessions_token: vec![],card_cvc: None,creds_identifier,diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rsindex 1cfcbce553..6e794b1ba6 100644--- a/crates/router/src/core/payments/operations/payment_capture.rs+++ b/crates/router/src/core/payments/operations/payment_capture.rs@@ -3,7 +3,6 @@ use std::marker::PhantomData;use api_models::enums::FrmSuggestion;use async_trait::async_trait;use common_utils::ext_traits::AsyncExt;-use diesel_models::connector_response::ConnectorResponse;use error_stack::ResultExt;use router_env::{instrument, tracing};@@ -20,7 +19,7 @@ use crate::{types::{api::{self, PaymentIdTypeExt},domain,- storage::{self, enums, payment_attempt::PaymentAttemptExt, ConnectorResponseExt},+ storage::{self, enums, payment_attempt::PaymentAttemptExt},},utils::OptionExt,};@@ -89,9 +88,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>helpers::validate_capture_method(capture_method)?;- let (multiple_capture_data, connector_response) = if capture_method- == enums::CaptureMethod::ManualMultiple- {+ let multiple_capture_data = if capture_method == enums::CaptureMethod::ManualMultiple {let amount_to_capture = request.amount_to_capture.get_required_value("amount_to_capture")?;@@ -121,37 +118,13 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>.to_not_found_response(errors::ApiErrorResponse::DuplicatePayment {payment_id: payment_id.clone(),})?;- let new_connector_response = db- .insert_connector_response(- ConnectorResponse::make_new_connector_response(- capture.payment_id.clone(),- capture.merchant_id.clone(),- capture.capture_id.clone(),- Some(capture.connector.clone()),- storage_scheme.to_string(),- ),- storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::DuplicatePayment { payment_id })?;- (- Some(MultipleCaptureData::new_for_create(- previous_captures,- capture,- )),- new_connector_response,- )++ Some(MultipleCaptureData::new_for_create(+ previous_captures,+ capture,+ ))} else {- let connector_response = db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- &payment_attempt.payment_id,- &payment_attempt.merchant_id,- &payment_attempt.attempt_id,- storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;- (None, connector_response)+ None};currency = payment_attempt.currency.get_required_value("currency")?;@@ -223,7 +196,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>refunds: vec![],disputes: vec![],attempts: None,- connector_response,sessions_token: vec![],card_cvc: None,creds_identifier,diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rsindex 4e87b38694..038d34ea29 100644--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs@@ -170,16 +170,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>).await?;- let connector_response = db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- &payment_attempt.payment_id,- &payment_attempt.merchant_id,- &payment_attempt.attempt_id,- storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;-let redirect_response = request.feature_metadata.as_ref()@@ -219,7 +209,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>payment_intent,payment_attempt,currency,- connector_response,amount,email: request.email.clone(),mandate_id: None,diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex 5de281a5e6..21f7db3d0b 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -157,77 +157,49 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>}).map(|x| x.transpose());- let (mut payment_attempt, shipping_address, billing_address, connector_response) =- match payment_intent.status {- api_models::enums::IntentStatus::RequiresCustomerAction- | api_models::enums::IntentStatus::RequiresMerchantAction- | api_models::enums::IntentStatus::RequiresPaymentMethod- | api_models::enums::IntentStatus::RequiresConfirmation => {- let attempt_type = helpers::AttemptType::SameOld;-- let attempt_id = payment_intent.active_attempt.get_id();- let connector_response_fut = attempt_type.get_connector_response(+ let (mut payment_attempt, shipping_address, billing_address) = match payment_intent.status {+ api_models::enums::IntentStatus::RequiresCustomerAction+ | api_models::enums::IntentStatus::RequiresMerchantAction+ | api_models::enums::IntentStatus::RequiresPaymentMethod+ | api_models::enums::IntentStatus::RequiresConfirmation => {+ let (payment_attempt, shipping_address, billing_address, _) = futures::try_join!(+ payment_attempt_fut,+ shipping_address_fut,+ billing_address_fut,+ config_update_fut+ )?;++ (payment_attempt, shipping_address, billing_address)+ }+ _ => {+ let (mut payment_attempt, shipping_address, billing_address, _) = futures::try_join!(+ payment_attempt_fut,+ shipping_address_fut,+ billing_address_fut,+ config_update_fut+ )?;++ let attempt_type = helpers::get_attempt_type(+ &payment_intent,+ &payment_attempt,+ request,+ "confirm",+ )?;++ (payment_intent, payment_attempt) = attempt_type+ .modify_payment_intent_and_payment_attempt(+ // 3+ request,+ payment_intent,+ payment_attempt,db,- &payment_intent.payment_id,- &payment_intent.merchant_id,- attempt_id.as_str(),storage_scheme,- );-- let (payment_attempt, shipping_address, billing_address, connector_response, _) =- futures::try_join!(- payment_attempt_fut,- shipping_address_fut,- billing_address_fut,- connector_response_fut,- config_update_fut- )?;-- (- payment_attempt,- shipping_address,- billing_address,- connector_response,)- }- _ => {- let (mut payment_attempt, shipping_address, billing_address, _) = futures::try_join!(- payment_attempt_fut,- shipping_address_fut,- billing_address_fut,- config_update_fut- )?;-- let attempt_type = helpers::get_attempt_type(- &payment_intent,- &payment_attempt,- request,- "confirm",- )?;-- (payment_intent, payment_attempt) = attempt_type- .modify_payment_intent_and_payment_attempt(- // 3- request,- payment_intent,- payment_attempt,- db,- storage_scheme,- )- .await?;-- let connector_response = attempt_type- .get_or_insert_connector_response(&payment_attempt, db, storage_scheme)- .await?;+ .await?;- (- payment_attempt,- shipping_address,- billing_address,- connector_response,- )- }- };+ (payment_attempt, shipping_address, billing_address)+ }+ };payment_intent.order_details = request.get_order_details_as_value()@@ -354,7 +326,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>payment_intent,payment_attempt,currency,- connector_response,amount,email: request.email.clone(),mandate_id: None,diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex adb3c41553..97bb843713 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -62,7 +62,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>let ephemeral_key = Self::get_ephemeral_key(request, state, merchant_account).await;let merchant_id = &merchant_account.merchant_id;let storage_scheme = merchant_account.storage_scheme;- let (payment_intent, payment_attempt, connector_response);+ let (payment_intent, payment_attempt);let money @ (amount, currency) = payments_create_request_validation(request)?;@@ -196,16 +196,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>payment_id: payment_id.clone(),})?;- connector_response = db- .insert_connector_response(- Self::make_connector_response(&payment_attempt),- storage_scheme,- )- .await- .to_duplicate_response(errors::ApiErrorResponse::DuplicatePayment {- payment_id: payment_id.clone(),- })?;-let mandate_id = request.mandate_id.as_ref()@@ -300,7 +290,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>disputes: vec![],attempts: None,force_sync: None,- connector_response,sessions_token: vec![],card_cvc: request.card_cvc.clone(),creds_identifier,@@ -727,24 +716,6 @@ impl PaymentCreate {})}- #[instrument(skip_all)]- pub fn make_connector_response(- payment_attempt: &PaymentAttempt,- ) -> storage::ConnectorResponseNew {- storage::ConnectorResponseNew {- payment_id: payment_attempt.payment_id.clone(),- merchant_id: payment_attempt.merchant_id.clone(),- attempt_id: payment_attempt.attempt_id.clone(),- created_at: payment_attempt.created_at,- modified_at: payment_attempt.modified_at,- connector_name: payment_attempt.connector.clone(),- connector_transaction_id: None,- authentication_data: None,- encoded_data: None,- updated_by: payment_attempt.updated_by.clone(),- }- }-#[instrument(skip_all)]pub async fn get_ephemeral_key(request: &api::PaymentsRequest,diff --git a/crates/router/src/core/payments/operations/payment_method_validate.rs b/crates/router/src/core/payments/operations/payment_method_validate.rsindex 33f6c23c83..7e4fe0951b 100644--- a/crates/router/src/core/payments/operations/payment_method_validate.rs+++ b/crates/router/src/core/payments/operations/payment_method_validate.rs@@ -7,7 +7,7 @@ use error_stack::ResultExt;use router_derive::PaymentOperation;use router_env::{instrument, tracing};-use super::{BoxedOperation, Domain, GetTracker, PaymentCreate, UpdateTracker, ValidateRequest};+use super::{BoxedOperation, Domain, GetTracker, UpdateTracker, ValidateRequest};use crate::{consts,core::{@@ -89,7 +89,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>let merchant_id = &merchant_account.merchant_id;let storage_scheme = merchant_account.storage_scheme;- let (payment_intent, payment_attempt, connector_response);+ let (payment_intent, payment_attempt);let payment_id = payment_id.get_payment_intent_id()@@ -135,19 +135,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>}}?;- connector_response = match db- .insert_connector_response(- PaymentCreate::make_connector_response(&payment_attempt),- storage_scheme,- )- .await- {- Ok(connector_resp) => Ok(connector_resp),- Err(err) => {- Err(err.change_context(errors::ApiErrorResponse::VerificationFailed { data: None }))- }- }?;-let creds_identifier = request.merchant_connector_details.as_ref()@@ -180,7 +167,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>mandate_connector: None,setup_mandate: request.mandate_data.clone().map(Into::into),token: request.payment_token.clone(),- connector_response,payment_method_data: request.payment_method_data.clone(),confirm: Some(true),address: types::PaymentAddress::default(),diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rsindex 415ab3eccf..a6c2561aae 100644--- a/crates/router/src/core/payments/operations/payment_reject.rs+++ b/crates/router/src/core/payments/operations/payment_reject.rs@@ -104,15 +104,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>).await?;- let connector_response = db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- &payment_attempt.payment_id,- &payment_attempt.merchant_id,- &payment_attempt.attempt_id,- storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;let currency = payment_attempt.currency.get_required_value("currency")?;let amount = payment_attempt.amount.into();@@ -147,7 +138,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>refunds: vec![],disputes: vec![],attempts: None,- connector_response,+sessions_token: vec![],card_cvc: None,creds_identifier: None,diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rsindex 60d3bc165a..77c3449496 100644--- a/crates/router/src/core/payments/operations/payment_response.rs+++ b/crates/router/src/core/payments/operations/payment_response.rs@@ -296,10 +296,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(router_data: types::RouterData<F, T, types::PaymentsResponseData>,storage_scheme: enums::MerchantStorageScheme,) -> RouterResult<PaymentData<F>> {- let (capture_update, mut payment_attempt_update, connector_response_update) = match router_data- .response- .clone()- {+ let (capture_update, mut payment_attempt_update) = match router_data.response.clone() {Err(err) => {let (capture_update, attempt_update) = match payment_data.multiple_capture_data {Some(multiple_capture_data) => {@@ -356,14 +353,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>()}};- (- capture_update,- attempt_update,- Some(storage::ConnectorResponseUpdate::ErrorUpdate {- connector_name: Some(router_data.connector.clone()),- updated_by: storage_scheme.to_string(),- }),- )+ (capture_update, attempt_update)}Ok(payments_response) => match payments_response {types::PaymentsResponseData::PreProcessingResponse {@@ -394,7 +384,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(updated_by: storage_scheme.to_string(),};- (None, Some(payment_attempt_update), None)+ (None, Some(payment_attempt_update))}types::PaymentsResponseData::TransactionResponse {resource_id,@@ -409,8 +399,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(| types::ResponseId::EncodedData(id) => Some(id),};- let encoded_data = payment_data.connector_response.encoded_data.clone();- let connector_name = router_data.connector.clone();+ let encoded_data = payment_data.payment_attempt.encoded_data.clone();let authentication_data = redirection_data.map(|data| utils::Encode::<RedirectForm>::encode_to_value(&data))@@ -478,23 +467,13 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(None},updated_by: storage_scheme.to_string(),+ authentication_data,+ encoded_data,}),),};- let connector_response_update = storage::ConnectorResponseUpdate::ResponseUpdate {- connector_transaction_id,- authentication_data,- encoded_data,- connector_name: Some(connector_name),- updated_by: storage_scheme.to_string(),- };-- (- capture_updates,- payment_attempt_update,- Some(connector_response_update),- )+ (capture_updates, payment_attempt_update)}types::PaymentsResponseData::TransactionUnresolvedResponse {resource_id,@@ -519,14 +498,13 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(connector_response_reference_id,updated_by: storage_scheme.to_string(),}),- None,)}- types::PaymentsResponseData::SessionResponse { .. } => (None, None, None),- types::PaymentsResponseData::SessionTokenResponse { .. } => (None, None, None),- types::PaymentsResponseData::TokenizationResponse { .. } => (None, None, None),- types::PaymentsResponseData::ConnectorCustomerResponse { .. } => (None, None, None),- types::PaymentsResponseData::ThreeDSEnrollmentResponse { .. } => (None, None, None),+ types::PaymentsResponseData::SessionResponse { .. } => (None, None),+ types::PaymentsResponseData::SessionTokenResponse { .. } => (None, None),+ types::PaymentsResponseData::TokenizationResponse { .. } => (None, None),+ types::PaymentsResponseData::ConnectorCustomerResponse { .. } => (None, None),+ types::PaymentsResponseData::ThreeDSEnrollmentResponse { .. } => (None, None),types::PaymentsResponseData::MultipleCaptureResponse {capture_sync_response_list,} => match payment_data.multiple_capture_data {@@ -535,13 +513,9 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(&multiple_capture_data,capture_sync_response_list,)?;- (- Some((multiple_capture_data, capture_update_list)),- None,- None,- )+ (Some((multiple_capture_data, capture_update_list)), None)}- None => (None, None, None),+ None => (None, None),},},};@@ -571,40 +545,18 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(// Stage 1let payment_attempt = payment_data.payment_attempt.clone();- let connector_response = payment_data.connector_response.clone();-- let payment_attempt_fut = Box::pin(async move {- Ok::<_, error_stack::Report<errors::ApiErrorResponse>>(match payment_attempt_update {- Some(payment_attempt_update) => db- .update_payment_attempt_with_attempt_id(- payment_attempt,- payment_attempt_update,- storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,- None => payment_attempt,- })- });-- let connector_response_fut = Box::pin(async move {- Ok::<_, error_stack::Report<errors::ApiErrorResponse>>(match connector_response_update {- Some(connector_response_update) => db- .update_connector_response(- connector_response,- connector_response_update,- storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,- None => connector_response,- })- });-- let (payment_attempt, connector_response) =- futures::try_join!(payment_attempt_fut, connector_response_fut)?;- payment_data.payment_attempt = payment_attempt;- payment_data.connector_response = connector_response;++ payment_data.payment_attempt = match payment_attempt_update {+ Some(payment_attempt_update) => db+ .update_payment_attempt_with_attempt_id(+ payment_attempt,+ payment_attempt_update,+ storage_scheme,+ )+ .await+ .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,+ None => payment_attempt,+ };let amount_captured = get_total_amount_captured(router_data.request,diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rsindex 354c62648b..52677ab3cc 100644--- a/crates/router/src/core/payments/operations/payment_session.rs+++ b/crates/router/src/core/payments/operations/payment_session.rs@@ -126,20 +126,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>payment_intent.shipping_address_id = shipping_address.clone().map(|x| x.address_id);payment_intent.billing_address_id = billing_address.clone().map(|x| x.address_id);- let connector_response = db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- &payment_intent.payment_id,- &payment_intent.merchant_id,- &payment_attempt.attempt_id,- storage_scheme,- )- .await- .map_err(|error| {- error- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Database error when finding connector response")- })?;-let customer_details = payments::CustomerDetails {customer_id: payment_intent.customer_id.clone(),name: None,@@ -190,7 +176,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>disputes: vec![],attempts: None,sessions_token: vec![],- connector_response,card_cvc: None,creds_identifier,pm_token: None,diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rsindex e9fa301bf0..5578f6b3dc 100644--- a/crates/router/src/core/payments/operations/payment_start.rs+++ b/crates/router/src/core/payments/operations/payment_start.rs@@ -126,20 +126,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>..CustomerDetails::default()};- let connector_response = db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- &payment_intent.payment_id,- &payment_intent.merchant_id,- &payment_attempt.attempt_id,- storage_scheme,- )- .await- .map_err(|error| {- error- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Database error when finding connector response")- })?;-Ok((Box::new(self),PaymentData {@@ -150,7 +136,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>email: None,mandate_id: None,mandate_connector: None,- connector_response,setup_mandate: None,token: payment_attempt.payment_token.clone(),address: PaymentAddress {diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rsindex 96aac6c9d7..83e7131b26 100644--- a/crates/router/src/core/payments/operations/payment_status.rs+++ b/crates/router/src/core/payments/operations/payment_status.rs@@ -226,7 +226,7 @@ async fn get_tracker_for_sync<PaymentData<F>,Option<CustomerDetails>,)> {- let (payment_intent, payment_attempt, currency, amount);+ let (payment_intent, mut payment_attempt, currency, amount);(payment_intent, payment_attempt) = get_payment_intent_payment_attempt(db,@@ -250,18 +250,7 @@ async fn get_tracker_for_sync<let payment_id_str = payment_attempt.payment_id.clone();- let mut connector_response = db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- &payment_intent.payment_id,- &payment_intent.merchant_id,- &payment_attempt.attempt_id,- storage_scheme,- )- .await- .change_context(errors::ApiErrorResponse::PaymentNotFound)- .attach_printable("Database error when finding connector response")?;-- connector_response.encoded_data = request.param.clone();+ payment_attempt.encoded_data = request.param.clone();currency = payment_attempt.currency.get_required_value("currency")?;amount = payment_attempt.amount.into();@@ -349,7 +338,7 @@ async fn get_tracker_for_sync<format!("Error while retrieving frm_response, merchant_id: {}, payment_id: {payment_id_str}", &merchant_account.merchant_id)});- let contains_encoded_data = connector_response.encoded_data.is_some();+ let contains_encoded_data = payment_attempt.encoded_data.is_some();let creds_identifier = request.merchant_connector_details@@ -373,7 +362,6 @@ async fn get_tracker_for_sync<PaymentData {flow: PhantomData,payment_intent,- connector_response,currency,amount,email: None,diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rsindex 622d097543..0a49c830b7 100644--- a/crates/router/src/core/payments/operations/payment_update.rs+++ b/crates/router/src/core/payments/operations/payment_update.rs@@ -219,20 +219,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>)?;}- let connector_response = db- .find_connector_response_by_payment_id_merchant_id_attempt_id(- &payment_intent.payment_id,- &payment_intent.merchant_id,- &payment_attempt.attempt_id,- storage_scheme,- )- .await- .map_err(|error| {- error- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Database error when finding connector response")- })?;-let mandate_id = request.mandate_id.as_ref()@@ -341,7 +327,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>refunds: vec![],disputes: vec![],attempts: None,- connector_response,sessions_token: vec![],card_cvc: request.card_cvc.clone(),creds_identifier,diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex c625298263..6c6b4ae933 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -460,14 +460,8 @@ wherelet output = Ok(match payment_request {Some(_request) => {- if payments::is_start_pay(&operation)- && payment_data- .connector_response- .authentication_data- .is_some()- {- let redirection_data = payment_data- .connector_response+ if payments::is_start_pay(&operation) && payment_attempt.authentication_data.is_some() {+ let redirection_data = payment_attempt.authentication_data.get_required_value("redirection_data")?;@@ -523,16 +517,15 @@ wheredisplay_to_timestamp: wait_screen_data.display_to_timestamp,}}))- .or(payment_data- .connector_response- .authentication_data- .map(|_| api_models::payments::NextActionData::RedirectToUrl {+ .or(payment_attempt.authentication_data.as_ref().map(|_| {+ api_models::payments::NextActionData::RedirectToUrl {redirect_to_url: helpers::create_startpay_url(server,&payment_attempt,&payment_intent,),- }));+ }+ }));};// next action check for third party sdk session (for ex: Apple pay through trustpay has third party sdk session response)@@ -1056,7 +1049,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSyncData}None => types::ResponseId::NoResponseId,},- encoded_data: payment_data.connector_response.encoded_data,+ encoded_data: payment_data.payment_attempt.encoded_data,capture_method: payment_data.payment_attempt.capture_method,connector_meta: payment_data.payment_attempt.connector_metadata,sync_type: match payment_data.multiple_capture_data {@@ -1356,7 +1349,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthorizbrowser_info,email: payment_data.email,payment_method_data: payment_data.payment_method_data,- connector_transaction_id: payment_data.connector_response.connector_transaction_id,+ connector_transaction_id: payment_data.payment_attempt.connector_transaction_id,redirect_response,connector_meta: payment_data.payment_attempt.connector_metadata,})diff --git a/crates/router/src/db.rs b/crates/router/src/db.rsindex 3efef2c40f..6fe34d8dd6 100644--- a/crates/router/src/db.rs+++ b/crates/router/src/db.rs@@ -5,7 +5,6 @@ pub mod cache;pub mod capture;pub mod cards_info;pub mod configs;-pub mod connector_response;pub mod customers;pub mod dispute;pub mod ephemeral_key;@@ -52,7 +51,6 @@ pub trait StorageInterface:+ api_keys::ApiKeyInterface+ configs::ConfigInterface+ capture::CaptureInterface- + connector_response::ConnectorResponseInterface+ customers::CustomerInterface+ dispute::DisputeInterface+ ephemeral_key::EphemeralKeyInterfacediff --git a/crates/router/src/db/connector_response.rs b/crates/router/src/db/connector_response.rsdeleted file mode 100644index 354231d136..0000000000--- a/crates/router/src/db/connector_response.rs+++ /dev/null@@ -1,343 +0,0 @@-use error_stack::{IntoReport, ResultExt};-use router_env::{instrument, tracing};--use super::{MockDb, Store};-use crate::{- core::errors::{self, CustomResult},- types::storage::{self as storage_type, enums},-};--#[async_trait::async_trait]-pub trait ConnectorResponseInterface {- async fn insert_connector_response(- &self,- connector_response: storage_type::ConnectorResponseNew,- storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError>;-- async fn find_connector_response_by_payment_id_merchant_id_attempt_id(- &self,- payment_id: &str,- merchant_id: &str,- attempt_id: &str,- storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError>;-- async fn update_connector_response(- &self,- this: storage_type::ConnectorResponse,- payment_attempt: storage_type::ConnectorResponseUpdate,- storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError>;-}--#[cfg(not(feature = "kv_store"))]-mod storage {- use error_stack::IntoReport;- use router_env::{instrument, tracing};-- use super::Store;- use crate::{- connection,- core::errors::{self, CustomResult},- types::storage::{self as storage_type, enums},- };-- #[async_trait::async_trait]- impl super::ConnectorResponseInterface for Store {- #[instrument(skip_all)]- async fn insert_connector_response(- &self,- connector_response: storage_type::ConnectorResponseNew,- _storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;- connector_response- .insert(&conn)- .await- .map_err(Into::into)- .into_report()- }-- #[instrument(skip_all)]- async fn find_connector_response_by_payment_id_merchant_id_attempt_id(- &self,- payment_id: &str,- merchant_id: &str,- attempt_id: &str,- _storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;- storage_type::ConnectorResponse::find_by_payment_id_merchant_id_attempt_id(- &conn,- payment_id,- merchant_id,- attempt_id,- )- .await- .map_err(Into::into)- .into_report()- }-- async fn update_connector_response(- &self,- this: storage_type::ConnectorResponse,- connector_response_update: storage_type::ConnectorResponseUpdate,- _storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;- this.update(&conn, connector_response_update)- .await- .map_err(Into::into)- .into_report()- }- }-}--#[cfg(feature = "kv_store")]-mod storage {-- use diesel_models::enums as storage_enums;- use error_stack::{IntoReport, ResultExt};- use redis_interface::HsetnxReply;- use router_env::{instrument, tracing};- use storage_impl::redis::kv_store::{kv_wrapper, KvOperation};-- use super::Store;- use crate::{- connection,- core::errors::{self, CustomResult},- types::storage::{self as storage_type, enums, kv},- utils::db_utils,- };-- #[async_trait::async_trait]- impl super::ConnectorResponseInterface for Store {- #[instrument(skip_all)]- async fn insert_connector_response(- &self,- connector_response: storage_type::ConnectorResponseNew,- storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;-- match storage_scheme {- storage_enums::MerchantStorageScheme::PostgresOnly => connector_response- .insert(&conn)- .await- .map_err(Into::into)- .into_report(),- storage_enums::MerchantStorageScheme::RedisKv => {- let merchant_id = &connector_response.merchant_id;- let payment_id = &connector_response.payment_id;- let attempt_id = &connector_response.attempt_id;-- let key = format!("mid_{merchant_id}_pid_{payment_id}");- let field = format!("connector_resp_{merchant_id}_{payment_id}_{attempt_id}");-- let created_connector_resp = storage_type::ConnectorResponse {- id: Default::default(),- payment_id: connector_response.payment_id.clone(),- merchant_id: connector_response.merchant_id.clone(),- attempt_id: connector_response.attempt_id.clone(),- created_at: connector_response.created_at,- modified_at: connector_response.modified_at,- connector_name: connector_response.connector_name.clone(),- connector_transaction_id: connector_response- .connector_transaction_id- .clone(),- authentication_data: connector_response.authentication_data.clone(),- encoded_data: connector_response.encoded_data.clone(),- updated_by: storage_scheme.to_string(),- };-- let redis_entry = kv::TypedSql {- op: kv::DBOperation::Insert {- insertable: kv::Insertable::ConnectorResponse(- connector_response.clone(),- ),- },- };-- match kv_wrapper::<storage_type::ConnectorResponse, _, _>(- self,- KvOperation::HSetNx(&field, &created_connector_resp, redis_entry),- &key,- )- .await- .change_context(errors::StorageError::KVError)?- .try_into_hsetnx()- {- Ok(HsetnxReply::KeyNotSet) => Err(errors::StorageError::DuplicateValue {- entity: "address",- key: Some(key),- })- .into_report(),- Ok(HsetnxReply::KeySet) => Ok(created_connector_resp),- Err(er) => Err(er).change_context(errors::StorageError::KVError),- }- }- }- }-- #[instrument(skip_all)]- async fn find_connector_response_by_payment_id_merchant_id_attempt_id(- &self,- payment_id: &str,- merchant_id: &str,- attempt_id: &str,- storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError> {- let conn = connection::pg_connection_read(self).await?;- let database_call = || async {- storage_type::ConnectorResponse::find_by_payment_id_merchant_id_attempt_id(- &conn,- payment_id,- merchant_id,- attempt_id,- )- .await- .map_err(Into::into)- .into_report()- };- match storage_scheme {- storage_enums::MerchantStorageScheme::PostgresOnly => database_call().await,- storage_enums::MerchantStorageScheme::RedisKv => {- let key = format!("mid_{merchant_id}_pid_{payment_id}");- let field = format!("connector_resp_{merchant_id}_{payment_id}_{attempt_id}");-- db_utils::try_redis_get_else_try_database_get(- async {- kv_wrapper(- self,- KvOperation::<diesel_models::Address>::HGet(&field),- key,- )- .await?- .try_into_hget()- },- database_call,- )- .await- }- }- }-- async fn update_connector_response(- &self,- this: storage_type::ConnectorResponse,- connector_response_update: storage_type::ConnectorResponseUpdate,- storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError> {- let conn = connection::pg_connection_write(self).await?;- match storage_scheme {- storage_enums::MerchantStorageScheme::PostgresOnly => this- .update(&conn, connector_response_update)- .await- .map_err(Into::into)- .into_report(),- storage_enums::MerchantStorageScheme::RedisKv => {- let key = format!("mid_{}_pid_{}", this.merchant_id, this.payment_id);- let updated_connector_response = connector_response_update- .clone()- .apply_changeset(this.clone());- let redis_value = serde_json::to_string(&updated_connector_response)- .into_report()- .change_context(errors::StorageError::KVError)?;- let field = format!(- "connector_resp_{}_{}_{}",- &updated_connector_response.merchant_id,- &updated_connector_response.payment_id,- &updated_connector_response.attempt_id- );-- let redis_entry = kv::TypedSql {- op: kv::DBOperation::Update {- updatable: kv::Updateable::ConnectorResponseUpdate(- kv::ConnectorResponseUpdateMems {- orig: this,- update_data: connector_response_update,- },- ),- },- };-- kv_wrapper::<(), _, _>(- self,- KvOperation::Hset::<storage_type::ConnectorResponse>(- (&field, redis_value),- redis_entry,- ),- &key,- )- .await- .change_context(errors::StorageError::KVError)?- .try_into_hset()- .change_context(errors::StorageError::KVError)?;-- Ok(updated_connector_response)- }- }- }- }-}--#[async_trait::async_trait]-impl ConnectorResponseInterface for MockDb {- #[instrument(skip_all)]- async fn insert_connector_response(- &self,- new: storage_type::ConnectorResponseNew,- storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError> {- let mut connector_response = self.connector_response.lock().await;- let response = storage_type::ConnectorResponse {- id: connector_response- .len()- .try_into()- .into_report()- .change_context(errors::StorageError::MockDbError)?,- payment_id: new.payment_id,- merchant_id: new.merchant_id,- attempt_id: new.attempt_id,- created_at: new.created_at,- modified_at: new.modified_at,- connector_name: new.connector_name,- connector_transaction_id: new.connector_transaction_id,- authentication_data: new.authentication_data,- encoded_data: new.encoded_data,- updated_by: storage_scheme.to_string(),- };- connector_response.push(response.clone());- Ok(response)- }-- #[instrument(skip_all)]- async fn find_connector_response_by_payment_id_merchant_id_attempt_id(- &self,- _payment_id: &str,- _merchant_id: &str,- _attempt_id: &str,- _storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError> {- // [#172]: Implement function for `MockDb`- Err(errors::StorageError::MockDbError)?- }-- // safety: interface only used for testing- #[allow(clippy::unwrap_used)]- async fn update_connector_response(- &self,- this: storage_type::ConnectorResponse,- connector_response_update: storage_type::ConnectorResponseUpdate,- _storage_scheme: enums::MerchantStorageScheme,- ) -> CustomResult<storage_type::ConnectorResponse, errors::StorageError> {- let mut connector_response = self.connector_response.lock().await;- let response = connector_response- .iter_mut()- .find(|item| item.id == this.id)- .unwrap();- *response = connector_response_update.apply_changeset(response.clone());- Ok(response.clone())- }-}diff --git a/crates/router/src/types/storage.rs b/crates/router/src/types/storage.rsindex 1e7c34a420..c63ff5fb7f 100644--- a/crates/router/src/types/storage.rs+++ b/crates/router/src/types/storage.rs@@ -4,7 +4,6 @@ pub mod business_profile;pub mod capture;pub mod cards_info;pub mod configs;-pub mod connector_response;pub mod customers;pub mod dispute;pub mod enums;@@ -41,11 +40,11 @@ pub use data_models::payments::{};pub use self::{- address::*, api_keys::*, capture::*, cards_info::*, configs::*, connector_response::*,- customers::*, dispute::*, ephemeral_key::*, events::*, file::*, gsm::*, locker_mock_up::*,- mandate::*, merchant_account::*, merchant_connector_account::*, merchant_key_store::*,- payment_link::*, payment_method::*, payout_attempt::*, payouts::*, process_tracker::*,- refund::*, reverse_lookup::*, routing_algorithm::*,+ address::*, api_keys::*, capture::*, cards_info::*, configs::*, customers::*, dispute::*,+ ephemeral_key::*, events::*, file::*, gsm::*, locker_mock_up::*, mandate::*,+ merchant_account::*, merchant_connector_account::*, merchant_key_store::*, payment_link::*,+ payment_method::*, payout_attempt::*, payouts::*, process_tracker::*, refund::*,+ reverse_lookup::*, routing_algorithm::*,};use crate::types::api::routing;diff --git a/crates/router/src/types/storage/connector_response.rs b/crates/router/src/types/storage/connector_response.rsdeleted file mode 100644index c93c231e3d..0000000000--- a/crates/router/src/types/storage/connector_response.rs+++ /dev/null@@ -1,41 +0,0 @@-pub use diesel_models::{- connector_response::{- ConnectorResponse, ConnectorResponseNew, ConnectorResponseUpdate,- ConnectorResponseUpdateInternal,- },- enums::MerchantStorageScheme,-};--pub trait ConnectorResponseExt {- fn make_new_connector_response(- payment_id: String,- merchant_id: String,- attempt_id: String,- connector: Option<String>,- storage_scheme: String,- ) -> ConnectorResponseNew;-}--impl ConnectorResponseExt for ConnectorResponse {- fn make_new_connector_response(- payment_id: String,- merchant_id: String,- attempt_id: String,- connector: Option<String>,- storage_scheme: String,- ) -> ConnectorResponseNew {- let now = common_utils::date_time::now();- ConnectorResponseNew {- payment_id,- merchant_id,- attempt_id,- created_at: now,- modified_at: now,- connector_name: connector,- connector_transaction_id: None,- authentication_data: None,- encoded_data: None,- updated_by: storage_scheme,- }- }-}diff --git a/crates/router/src/types/storage/kv.rs b/crates/router/src/types/storage/kv.rsindex 2afc73e663..6bb6c38e7b 100644--- a/crates/router/src/types/storage/kv.rs+++ b/crates/router/src/types/storage/kv.rs@@ -1,4 +1,4 @@pub use diesel_models::kv::{- AddressUpdateMems, ConnectorResponseUpdateMems, DBOperation, Insertable,- PaymentAttemptUpdateMems, PaymentIntentUpdateMems, RefundUpdateMems, TypedSql, Updateable,+ AddressUpdateMems, DBOperation, Insertable, PaymentAttemptUpdateMems, PaymentIntentUpdateMems,+ RefundUpdateMems, TypedSql, Updateable,};diff --git a/crates/storage_impl/src/connector_response.rs b/crates/storage_impl/src/connector_response.rsdeleted file mode 100644index 7d4ff6df94..0000000000--- a/crates/storage_impl/src/connector_response.rs+++ /dev/null@@ -1,5 +0,0 @@-use diesel_models::connector_response::ConnectorResponse;--use crate::redis::kv_store::KvStorePartition;--impl KvStorePartition for ConnectorResponse {}diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rsindex cef4a8981a..00d8703940 100644--- a/crates/storage_impl/src/lib.rs+++ b/crates/storage_impl/src/lib.rs@@ -8,7 +8,6 @@ use redis::{kv_store::RedisConnInterface, RedisStore};mod address;pub mod config;pub mod connection;-mod connector_response;pub mod database;pub mod errors;mod lookup;diff --git a/crates/storage_impl/src/mock_db.rs b/crates/storage_impl/src/mock_db.rsindex 76bdb1160c..33f3f7a77f 100644--- a/crates/storage_impl/src/mock_db.rs+++ b/crates/storage_impl/src/mock_db.rs@@ -27,7 +27,6 @@ pub struct MockDb {pub customers: Arc<Mutex<Vec<store::Customer>>>,pub refunds: Arc<Mutex<Vec<store::Refund>>>,pub processes: Arc<Mutex<Vec<store::ProcessTracker>>>,- pub connector_response: Arc<Mutex<Vec<store::ConnectorResponse>>>,pub redis: Arc<RedisStore>,pub api_keys: Arc<Mutex<Vec<store::ApiKey>>>,pub ephemeral_keys: Arc<Mutex<Vec<store::EphemeralKey>>>,@@ -57,7 +56,6 @@ impl MockDb {customers: Default::default(),refunds: Default::default(),processes: Default::default(),- connector_response: Default::default(),redis: Arc::new(RedisStore::new(redis).awaitdiff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rsindex e3047221b6..21002917df 100644--- a/crates/storage_impl/src/payments/payment_attempt.rs+++ b/crates/storage_impl/src/payments/payment_attempt.rs@@ -1062,7 +1062,6 @@ impl DataModelExt for PaymentAttemptNew {connector_response_reference_id: self.connector_response_reference_id,multiple_capture_count: self.multiple_capture_count,amount_capturable: self.amount_capturable,-updated_by: self.updated_by,authentication_data: self.authentication_data,encoded_data: self.encoded_data,@@ -1244,6 +1243,8 @@ impl DataModelExt for PaymentAttemptUpdate {connector_response_reference_id,amount_capturable,updated_by,+ authentication_data,+ encoded_data,} => DieselPaymentAttemptUpdate::ResponseUpdate {status,connector,@@ -1259,6 +1260,8 @@ impl DataModelExt for PaymentAttemptUpdate {connector_response_reference_id,amount_capturable,updated_by,+ authentication_data,+ encoded_data,},Self::UnresolvedResponseUpdate {status,@@ -1481,6 +1484,8 @@ impl DataModelExt for PaymentAttemptUpdate {connector_response_reference_id,amount_capturable,updated_by,+ authentication_data,+ encoded_data,} => Self::ResponseUpdate {status,connector,@@ -1496,6 +1501,8 @@ impl DataModelExt for PaymentAttemptUpdate {connector_response_reference_id,amount_capturable,updated_by,+ authentication_data,+ encoded_data,},DieselPaymentAttemptUpdate::UnresolvedResponseUpdate {status,diff --git a/migrations/2023-11-08-144951_drop_connector_response_table/down.sql b/migrations/2023-11-08-144951_drop_connector_response_table/down.sqlnew file mode 100644index 0000000000..ff9ca4e4f9--- /dev/null+++ b/migrations/2023-11-08-144951_drop_connector_response_table/down.sql@@ -0,0 +1,34 @@+-- This file should undo anything in `up.sql`+CREATE TABLE connector_response (+ id SERIAL PRIMARY KEY,+ payment_id VARCHAR(255) NOT NULL,+ merchant_id VARCHAR(255) NOT NULL,+ txn_id VARCHAR(255) NOT NULL,+ created_at TIMESTAMP NOT NULL DEFAULT now()::TIMESTAMP,+ modified_at TIMESTAMP NOT NULL DEFAULT now()::TIMESTAMP,+ connector_name VARCHAR(32) NOT NULL,+ connector_transaction_id VARCHAR(255),+ authentication_data JSON,+ encoded_data TEXT+);++CREATE UNIQUE INDEX connector_response_id_index ON connector_response (payment_id, merchant_id, txn_id);++ALTER TABLE connector_response ALTER COLUMN connector_name DROP NOT NULL;+ALTER TABLE connector_response RENAME COLUMN txn_id TO attempt_id;+ALTER TABLE connector_response+ ALTER COLUMN payment_id TYPE VARCHAR(64),+ ALTER COLUMN merchant_id TYPE VARCHAR(64),+ ALTER COLUMN attempt_id TYPE VARCHAR(64),+ ALTER COLUMN connector_name TYPE VARCHAR(64),+ ALTER COLUMN connector_transaction_id TYPE VARCHAR(128);++++ALTER TABLE connector_response+ALTER COLUMN modified_at DROP DEFAULT;++ALTER TABLE connector_response+ALTER COLUMN created_at DROP DEFAULT;++ALTER TABLE connector_response ADD column updated_by VARCHAR(32) NOT NULL DEFAULT 'postgres_only';diff --git a/migrations/2023-11-08-144951_drop_connector_response_table/up.sql b/migrations/2023-11-08-144951_drop_connector_response_table/up.sqlnew file mode 100644index 0000000000..0059a6b38d--- /dev/null+++ b/migrations/2023-11-08-144951_drop_connector_response_table/up.sql@@ -0,0 +1,2 @@+-- Your SQL goes here+DROP TABLE connector_response; --NOT to run in deployment envs\ No newline at end of file