Skip to content

Commit 966369b

Browse files
refactor(core): remove connector response table and use payment_attempt instead (#2644)
1 parent e67e808 commit 966369b

35 files changed

+155
-979
lines changed

crates/data_models/src/payments/payment_attempt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ pub enum PaymentAttemptUpdate {
286286
connector_response_reference_id: Option<String>,
287287
amount_capturable: Option<i64>,
288288
updated_by: String,
289+
authentication_data: Option<serde_json::Value>,
290+
encoded_data: Option<String>,
289291
},
290292
UnresolvedResponseUpdate {
291293
status: storage_enums::AttemptStatus,

crates/diesel_models/src/connector_response.rs

Lines changed: 0 additions & 122 deletions
This file was deleted.

crates/diesel_models/src/kv.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize};
33

44
use crate::{
55
address::{Address, AddressNew, AddressUpdateInternal},
6-
connector_response::{ConnectorResponse, ConnectorResponseNew, ConnectorResponseUpdate},
76
errors,
87
payment_attempt::{PaymentAttempt, PaymentAttemptNew, PaymentAttemptUpdate},
98
payment_intent::{PaymentIntentNew, PaymentIntentUpdate},
@@ -51,7 +50,6 @@ pub enum Insertable {
5150
PaymentIntent(PaymentIntentNew),
5251
PaymentAttempt(PaymentAttemptNew),
5352
Refund(RefundNew),
54-
ConnectorResponse(ConnectorResponseNew),
5553
Address(Box<AddressNew>),
5654
ReverseLookUp(ReverseLookupNew),
5755
}
@@ -62,16 +60,9 @@ pub enum Updateable {
6260
PaymentIntentUpdate(PaymentIntentUpdateMems),
6361
PaymentAttemptUpdate(PaymentAttemptUpdateMems),
6462
RefundUpdate(RefundUpdateMems),
65-
ConnectorResponseUpdate(ConnectorResponseUpdateMems),
6663
AddressUpdate(Box<AddressUpdateMems>),
6764
}
6865

69-
#[derive(Debug, Serialize, Deserialize)]
70-
pub struct ConnectorResponseUpdateMems {
71-
pub orig: ConnectorResponse,
72-
pub update_data: ConnectorResponseUpdate,
73-
}
74-
7566
#[derive(Debug, Serialize, Deserialize)]
7667
pub struct AddressUpdateMems {
7768
pub orig: Address,

crates/diesel_models/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod business_profile;
44
pub mod capture;
55
pub mod cards_info;
66
pub mod configs;
7-
pub mod connector_response;
7+
88
pub mod customers;
99
pub mod dispute;
1010
pub mod encryption;
@@ -44,10 +44,10 @@ use diesel_impl::{DieselArray, OptionalDieselArray};
4444
pub type StorageResult<T> = error_stack::Result<T, errors::DatabaseError>;
4545
pub type PgPooledConn = async_bb8_diesel::Connection<diesel::PgConnection>;
4646
pub use self::{
47-
address::*, api_keys::*, cards_info::*, configs::*, connector_response::*, customers::*,
48-
dispute::*, ephemeral_key::*, events::*, file::*, locker_mock_up::*, mandate::*,
49-
merchant_account::*, merchant_connector_account::*, payment_attempt::*, payment_intent::*,
50-
payment_method::*, process_tracker::*, refund::*, reverse_lookup::*,
47+
address::*, api_keys::*, cards_info::*, configs::*, customers::*, dispute::*, ephemeral_key::*,
48+
events::*, file::*, locker_mock_up::*, mandate::*, merchant_account::*,
49+
merchant_connector_account::*, payment_attempt::*, payment_intent::*, payment_method::*,
50+
process_tracker::*, refund::*, reverse_lookup::*,
5151
};
5252

5353
/// The types and implementations provided by this module are required for the schema generated by

crates/diesel_models/src/payment_attempt.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ pub enum PaymentAttemptUpdate {
203203
connector_response_reference_id: Option<String>,
204204
amount_capturable: Option<i64>,
205205
updated_by: String,
206+
authentication_data: Option<serde_json::Value>,
207+
encoded_data: Option<String>,
206208
},
207209
UnresolvedResponseUpdate {
208210
status: storage_enums::AttemptStatus,
@@ -478,6 +480,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
478480
connector_response_reference_id,
479481
amount_capturable,
480482
updated_by,
483+
authentication_data,
484+
encoded_data,
481485
} => Self {
482486
status: Some(status),
483487
connector,
@@ -494,6 +498,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
494498
connector_response_reference_id,
495499
amount_capturable,
496500
updated_by,
501+
authentication_data,
502+
encoded_data,
497503
..Default::default()
498504
},
499505
PaymentAttemptUpdate::ErrorUpdate {

crates/diesel_models/src/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod business_profile;
44
mod capture;
55
pub mod cards_info;
66
pub mod configs;
7-
pub mod connector_response;
7+
88
pub mod customers;
99
pub mod dispute;
1010
pub mod events;

crates/diesel_models/src/schema.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -157,31 +157,6 @@ diesel::table! {
157157
}
158158
}
159159

160-
diesel::table! {
161-
use diesel::sql_types::*;
162-
use crate::enums::diesel_exports::*;
163-
164-
connector_response (id) {
165-
id -> Int4,
166-
#[max_length = 64]
167-
payment_id -> Varchar,
168-
#[max_length = 64]
169-
merchant_id -> Varchar,
170-
#[max_length = 64]
171-
attempt_id -> Varchar,
172-
created_at -> Timestamp,
173-
modified_at -> Timestamp,
174-
#[max_length = 64]
175-
connector_name -> Nullable<Varchar>,
176-
#[max_length = 128]
177-
connector_transaction_id -> Nullable<Varchar>,
178-
authentication_data -> Nullable<Json>,
179-
encoded_data -> Nullable<Text>,
180-
#[max_length = 32]
181-
updated_by -> Varchar,
182-
}
183-
}
184-
185160
diesel::table! {
186161
use diesel::sql_types::*;
187162
use crate::enums::diesel_exports::*;
@@ -932,7 +907,6 @@ diesel::allow_tables_to_appear_in_same_query!(
932907
captures,
933908
cards_info,
934909
configs,
935-
connector_response,
936910
customers,
937911
dispute,
938912
events,

crates/drainer/src/lib.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ async fn drainer(
206206
let payment_attempt = "payment_attempt";
207207
let refund = "refund";
208208
let reverse_lookup = "reverse_lookup";
209-
let connector_response = "connector_response";
210209
let address = "address";
211210
match db_op {
212211
// TODO: Handle errors
@@ -230,13 +229,6 @@ async fn drainer(
230229
kv::Insertable::Refund(a) => {
231230
macro_util::handle_resp!(a.insert(&conn).await, insert_op, refund)
232231
}
233-
kv::Insertable::ConnectorResponse(a) => {
234-
macro_util::handle_resp!(
235-
a.insert(&conn).await,
236-
insert_op,
237-
connector_response
238-
)
239-
}
240232
kv::Insertable::Address(addr) => {
241233
macro_util::handle_resp!(addr.insert(&conn).await, insert_op, address)
242234
}
@@ -283,11 +275,6 @@ async fn drainer(
283275
refund
284276
)
285277
}
286-
kv::Updateable::ConnectorResponseUpdate(a) => macro_util::handle_resp!(
287-
a.orig.update(&conn, a.update_data).await,
288-
update_op,
289-
connector_response
290-
),
291278
kv::Updateable::AddressUpdate(a) => macro_util::handle_resp!(
292279
a.orig.update(&conn, a.update_data).await,
293280
update_op,

crates/router/src/core/payments.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,6 @@ where
15781578
pub payment_intent: storage::PaymentIntent,
15791579
pub payment_attempt: storage::PaymentAttempt,
15801580
pub multiple_capture_data: Option<types::MultipleCaptureData>,
1581-
pub connector_response: storage::ConnectorResponse,
15821581
pub amount: api::Amount,
15831582
pub mandate_id: Option<api_models::payments::MandateIds>,
15841583
pub mandate_connector: Option<MandateConnectorDetails>,
@@ -1671,10 +1670,7 @@ pub fn should_call_connector<Op: Debug, F: Clone>(
16711670
!matches!(
16721671
payment_data.payment_intent.status,
16731672
storage_enums::IntentStatus::Failed | storage_enums::IntentStatus::Succeeded
1674-
) && payment_data
1675-
.connector_response
1676-
.authentication_data
1677-
.is_none()
1673+
) && payment_data.payment_attempt.authentication_data.is_none()
16781674
}
16791675
"PaymentStatus" => {
16801676
matches!(

crates/router/src/core/payments/helpers.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,60 +2998,6 @@ impl AttemptType {
29982998
}
29992999
}
30003000
}
3001-
3002-
#[instrument(skip_all)]
3003-
pub async fn get_or_insert_connector_response(
3004-
&self,
3005-
payment_attempt: &PaymentAttempt,
3006-
db: &dyn StorageInterface,
3007-
storage_scheme: storage::enums::MerchantStorageScheme,
3008-
) -> RouterResult<storage::ConnectorResponse> {
3009-
match self {
3010-
Self::New => db
3011-
.insert_connector_response(
3012-
payments::PaymentCreate::make_connector_response(payment_attempt),
3013-
storage_scheme,
3014-
)
3015-
.await
3016-
.to_duplicate_response(errors::ApiErrorResponse::DuplicatePayment {
3017-
payment_id: payment_attempt.payment_id.clone(),
3018-
}),
3019-
Self::SameOld => db
3020-
.find_connector_response_by_payment_id_merchant_id_attempt_id(
3021-
&payment_attempt.payment_id,
3022-
&payment_attempt.merchant_id,
3023-
&payment_attempt.attempt_id,
3024-
storage_scheme,
3025-
)
3026-
.await
3027-
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound),
3028-
}
3029-
}
3030-
3031-
#[instrument(skip_all)]
3032-
pub async fn get_connector_response(
3033-
&self,
3034-
db: &dyn StorageInterface,
3035-
payment_id: &str,
3036-
merchant_id: &str,
3037-
attempt_id: &str,
3038-
storage_scheme: storage_enums::MerchantStorageScheme,
3039-
) -> RouterResult<storage::ConnectorResponse> {
3040-
match self {
3041-
Self::New => Err(errors::ApiErrorResponse::InternalServerError)
3042-
.into_report()
3043-
.attach_printable("Precondition failed, the attempt type should not be `New`"),
3044-
Self::SameOld => db
3045-
.find_connector_response_by_payment_id_merchant_id_attempt_id(
3046-
payment_id,
3047-
merchant_id,
3048-
attempt_id,
3049-
storage_scheme,
3050-
)
3051-
.await
3052-
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound),
3053-
}
3054-
}
30553001
}
30563002

30573003
#[inline(always)]

0 commit comments

Comments
 (0)