Skip to content

Commit fbf3c03

Browse files
refactor(storage): update paymentintent object to provide a relation with attempts (#2502)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 8a396a2 commit fbf3c03

36 files changed

+875
-856
lines changed

Cargo.lock

Lines changed: 578 additions & 586 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/data_models/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,28 @@ pub enum MerchantStorageScheme {
2323
PostgresOnly,
2424
RedisKv,
2525
}
26+
27+
#[derive(Clone, Debug, Eq, PartialEq)]
28+
pub enum RemoteStorageObject<T: ForeignIDRef> {
29+
ForeignID(String),
30+
Object(T),
31+
}
32+
33+
impl<T: ForeignIDRef> From<T> for RemoteStorageObject<T> {
34+
fn from(value: T) -> Self {
35+
Self::Object(value)
36+
}
37+
}
38+
39+
pub trait ForeignIDRef {
40+
fn foreign_id(&self) -> String;
41+
}
42+
43+
impl<T: ForeignIDRef> RemoteStorageObject<T> {
44+
pub fn get_id(&self) -> String {
45+
match self {
46+
Self::ForeignID(id) => id.clone(),
47+
Self::Object(i) => i.foreign_id(),
48+
}
49+
}
50+
}

crates/data_models/src/payments.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
1+
use common_utils::pii;
2+
use time::PrimitiveDateTime;
3+
14
pub mod payment_attempt;
25
pub mod payment_intent;
6+
7+
use common_enums as storage_enums;
8+
9+
use self::payment_attempt::PaymentAttempt;
10+
use crate::RemoteStorageObject;
11+
12+
#[derive(Clone, Debug, Eq, PartialEq)]
13+
pub struct PaymentIntent {
14+
pub id: i32,
15+
pub payment_id: String,
16+
pub merchant_id: String,
17+
pub status: storage_enums::IntentStatus,
18+
pub amount: i64,
19+
pub currency: Option<storage_enums::Currency>,
20+
pub amount_captured: Option<i64>,
21+
pub customer_id: Option<String>,
22+
pub description: Option<String>,
23+
pub return_url: Option<String>,
24+
pub metadata: Option<pii::SecretSerdeValue>,
25+
pub connector_id: Option<String>,
26+
pub shipping_address_id: Option<String>,
27+
pub billing_address_id: Option<String>,
28+
pub statement_descriptor_name: Option<String>,
29+
pub statement_descriptor_suffix: Option<String>,
30+
pub created_at: PrimitiveDateTime,
31+
pub modified_at: PrimitiveDateTime,
32+
pub last_synced: Option<PrimitiveDateTime>,
33+
pub setup_future_usage: Option<storage_enums::FutureUsage>,
34+
pub off_session: Option<bool>,
35+
pub client_secret: Option<String>,
36+
pub active_attempt: RemoteStorageObject<PaymentAttempt>,
37+
pub business_country: Option<storage_enums::CountryAlpha2>,
38+
pub business_label: Option<String>,
39+
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
40+
pub allowed_payment_method_types: Option<serde_json::Value>,
41+
pub connector_metadata: Option<serde_json::Value>,
42+
pub feature_metadata: Option<serde_json::Value>,
43+
pub attempt_count: i16,
44+
pub profile_id: Option<String>,
45+
pub payment_link_id: Option<String>,
46+
// Denotes the action(approve or reject) taken by merchant in case of manual review.
47+
// 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
48+
pub merchant_decision: Option<String>,
49+
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
50+
}

crates/data_models/src/payments/payment_attempt.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use common_enums as storage_enums;
33
use serde::{Deserialize, Serialize};
44
use time::PrimitiveDateTime;
55

6-
use super::payment_intent::PaymentIntent;
7-
use crate::{errors, mandates::MandateDataType, MerchantStorageScheme};
6+
use super::PaymentIntent;
7+
use crate::{errors, mandates::MandateDataType, ForeignIDRef, MerchantStorageScheme};
88

99
#[async_trait::async_trait]
1010
pub trait PaymentAttemptInterface {
@@ -314,3 +314,9 @@ pub enum PaymentAttemptUpdate {
314314
surcharge_metadata: Option<serde_json::Value>,
315315
},
316316
}
317+
318+
impl ForeignIDRef for PaymentAttempt {
319+
fn foreign_id(&self) -> String {
320+
self.attempt_id.clone()
321+
}
322+
}

crates/data_models/src/payments/payment_intent.rs

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use common_utils::{
66
use serde::{Deserialize, Serialize};
77
use time::PrimitiveDateTime;
88

9-
use crate::{errors, MerchantStorageScheme};
9+
use super::{payment_attempt::PaymentAttempt, PaymentIntent};
10+
use crate::{errors, MerchantStorageScheme, RemoteStorageObject};
1011
#[async_trait::async_trait]
1112
pub trait PaymentIntentInterface {
1213
async fn update_payment_intent(
@@ -29,6 +30,12 @@ pub trait PaymentIntentInterface {
2930
storage_scheme: MerchantStorageScheme,
3031
) -> error_stack::Result<PaymentIntent, errors::StorageError>;
3132

33+
async fn get_active_payment_attempt(
34+
&self,
35+
payment: &mut PaymentIntent,
36+
storage_scheme: MerchantStorageScheme,
37+
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
38+
3239
#[cfg(feature = "olap")]
3340
async fn filter_payment_intent_by_constraints(
3441
&self,
@@ -51,10 +58,7 @@ pub trait PaymentIntentInterface {
5158
merchant_id: &str,
5259
constraints: &PaymentIntentFetchConstraints,
5360
storage_scheme: MerchantStorageScheme,
54-
) -> error_stack::Result<
55-
Vec<(PaymentIntent, super::payment_attempt::PaymentAttempt)>,
56-
errors::StorageError,
57-
>;
61+
) -> error_stack::Result<Vec<(PaymentIntent, PaymentAttempt)>, errors::StorageError>;
5862

5963
#[cfg(feature = "olap")]
6064
async fn get_filtered_active_attempt_ids_for_total_count(
@@ -65,50 +69,7 @@ pub trait PaymentIntentInterface {
6569
) -> error_stack::Result<Vec<String>, errors::StorageError>;
6670
}
6771

68-
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
69-
pub struct PaymentIntent {
70-
pub id: i32,
71-
pub payment_id: String,
72-
pub merchant_id: String,
73-
pub status: storage_enums::IntentStatus,
74-
pub amount: i64,
75-
pub currency: Option<storage_enums::Currency>,
76-
pub amount_captured: Option<i64>,
77-
pub customer_id: Option<String>,
78-
pub description: Option<String>,
79-
pub return_url: Option<String>,
80-
pub metadata: Option<pii::SecretSerdeValue>,
81-
pub connector_id: Option<String>,
82-
pub shipping_address_id: Option<String>,
83-
pub billing_address_id: Option<String>,
84-
pub statement_descriptor_name: Option<String>,
85-
pub statement_descriptor_suffix: Option<String>,
86-
#[serde(with = "common_utils::custom_serde::iso8601")]
87-
pub created_at: PrimitiveDateTime,
88-
#[serde(with = "common_utils::custom_serde::iso8601")]
89-
pub modified_at: PrimitiveDateTime,
90-
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
91-
pub last_synced: Option<PrimitiveDateTime>,
92-
pub setup_future_usage: Option<storage_enums::FutureUsage>,
93-
pub off_session: Option<bool>,
94-
pub client_secret: Option<String>,
95-
pub active_attempt_id: String,
96-
pub business_country: Option<storage_enums::CountryAlpha2>,
97-
pub business_label: Option<String>,
98-
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
99-
pub allowed_payment_method_types: Option<serde_json::Value>,
100-
pub connector_metadata: Option<serde_json::Value>,
101-
pub feature_metadata: Option<serde_json::Value>,
102-
pub attempt_count: i16,
103-
pub profile_id: Option<String>,
104-
// Denotes the action(approve or reject) taken by merchant in case of manual review.
105-
// 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
106-
pub merchant_decision: Option<String>,
107-
pub payment_link_id: Option<String>,
108-
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
109-
}
110-
111-
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
72+
#[derive(Clone, Debug, Eq, PartialEq)]
11273
pub struct PaymentIntentNew {
11374
pub payment_id: String,
11475
pub merchant_id: String,
@@ -125,16 +86,13 @@ pub struct PaymentIntentNew {
12586
pub billing_address_id: Option<String>,
12687
pub statement_descriptor_name: Option<String>,
12788
pub statement_descriptor_suffix: Option<String>,
128-
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
12989
pub created_at: Option<PrimitiveDateTime>,
130-
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
13190
pub modified_at: Option<PrimitiveDateTime>,
132-
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
13391
pub last_synced: Option<PrimitiveDateTime>,
13492
pub setup_future_usage: Option<storage_enums::FutureUsage>,
13593
pub off_session: Option<bool>,
13694
pub client_secret: Option<String>,
137-
pub active_attempt_id: String,
95+
pub active_attempt: RemoteStorageObject<PaymentAttempt>,
13896
pub business_country: Option<storage_enums::CountryAlpha2>,
13997
pub business_label: Option<String>,
14098
pub order_details: Option<Vec<pii::SecretSerdeValue>>,

crates/diesel_models/src/kv.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use crate::{
66
connector_response::{ConnectorResponse, ConnectorResponseNew, ConnectorResponseUpdate},
77
errors,
88
payment_attempt::{PaymentAttempt, PaymentAttemptNew, PaymentAttemptUpdate},
9-
payment_intent::{PaymentIntent, PaymentIntentNew, PaymentIntentUpdate},
9+
payment_intent::{PaymentIntentNew, PaymentIntentUpdate},
1010
refund::{Refund, RefundNew, RefundUpdate},
1111
reverse_lookup::ReverseLookupNew,
12+
PaymentIntent,
1213
};
1314

1415
#[derive(Debug, Serialize, Deserialize)]

crates/diesel_models/src/payment_intent.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ pub enum PaymentIntentUpdate {
165165

166166
#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
167167
#[diesel(table_name = payment_intent)]
168-
169168
pub struct PaymentIntentUpdateInternal {
170169
pub amount: Option<i64>,
171170
pub currency: Option<storage_enums::Currency>,

crates/diesel_models/src/query/payment_attempt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ use crate::{
1515
payment_attempt::{
1616
PaymentAttempt, PaymentAttemptNew, PaymentAttemptUpdate, PaymentAttemptUpdateInternal,
1717
},
18-
payment_intent::PaymentIntent,
1918
query::generics::db_metrics,
2019
schema::payment_attempt::dsl,
21-
PgPooledConn, StorageResult,
20+
PaymentIntent, PgPooledConn, StorageResult,
2221
};
2322

2423
impl PaymentAttemptNew {

crates/drainer/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ async fn drainer_handler(
122122
active_tasks.fetch_add(1, atomic::Ordering::Release);
123123

124124
let stream_name = utils::get_drainer_stream_name(store.clone(), stream_index);
125-
let drainer_result = drainer(store.clone(), max_read_count, stream_name.as_str()).await;
125+
let drainer_result =
126+
Box::pin(drainer(store.clone(), max_read_count, stream_name.as_str())).await;
126127

127128
if let Err(error) = drainer_result {
128129
logger::error!(?error)

crates/router/src/connector/trustpay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl ConnectorCommon for Trustpay {
115115

116116
match response {
117117
Ok(response_data) => {
118-
let error_list = response_data.errors.clone().unwrap_or(vec![]);
118+
let error_list = response_data.errors.clone().unwrap_or_default();
119119
let option_error_code_message = get_error_code_error_message_based_on_priority(
120120
self.clone(),
121121
error_list.into_iter().map(|errors| errors.into()).collect(),

0 commit comments

Comments
 (0)