feat: add updated_by to tracker tables (#2604)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Kartikeya Hegde
2023-10-17 11:26:56 +00:00
committed by GitHub
parent 274a78343e
commit 6a74e8cba9
46 changed files with 549 additions and 176 deletions

View File

@ -2,28 +2,6 @@ pub mod errors;
pub mod mandates;
pub mod payments;
// TODO: This decision about using KV mode or not,
// should be taken at a top level rather than pushing it down to individual functions via an enum.
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum MerchantStorageScheme {
#[default]
PostgresOnly,
RedisKv,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum RemoteStorageObject<T: ForeignIDRef> {
ForeignID(String),

View File

@ -47,4 +47,5 @@ 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<String>,
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
pub updated_by: String,
}

View File

@ -4,21 +4,21 @@ use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
use super::PaymentIntent;
use crate::{errors, mandates::MandateDataType, ForeignIDRef, MerchantStorageScheme};
use crate::{errors, mandates::MandateDataType, ForeignIDRef};
#[async_trait::async_trait]
pub trait PaymentAttemptInterface {
async fn insert_payment_attempt(
&self,
payment_attempt: PaymentAttemptNew,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn update_payment_attempt_with_attempt_id(
&self,
this: PaymentAttempt,
payment_attempt: PaymentAttemptUpdate,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(
@ -26,21 +26,21 @@ pub trait PaymentAttemptInterface {
connector_transaction_id: &str,
payment_id: &str,
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_by_merchant_id_connector_txn_id(
&self,
merchant_id: &str,
connector_txn_id: &str,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id(
@ -48,35 +48,35 @@ pub trait PaymentAttemptInterface {
payment_id: &str,
merchant_id: &str,
attempt_id: &str,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_by_attempt_id_merchant_id(
&self,
attempt_id: &str,
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_by_preprocessing_id_merchant_id(
&self,
preprocessing_id: &str,
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_attempts_by_merchant_id_payment_id(
&self,
merchant_id: &str,
payment_id: &str,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError>;
async fn get_filters_for_payments(
&self,
pi: &[PaymentIntent],
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentListFilters, errors::StorageError>;
#[allow(clippy::too_many_arguments)]
@ -88,7 +88,7 @@ pub trait PaymentAttemptInterface {
payment_method: Option<Vec<storage_enums::PaymentMethod>>,
payment_method_type: Option<Vec<storage_enums::PaymentMethodType>>,
authentication_type: Option<Vec<storage_enums::AuthenticationType>>,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<i64, errors::StorageError>;
}
@ -142,6 +142,7 @@ pub struct PaymentAttempt {
pub connector_response_reference_id: Option<String>,
pub amount_capturable: i64,
pub surcharge_metadata: Option<serde_json::Value>,
pub updated_by: String,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@ -201,6 +202,7 @@ pub struct PaymentAttemptNew {
pub multiple_capture_count: Option<i16>,
pub amount_capturable: i64,
pub surcharge_metadata: Option<serde_json::Value>,
pub updated_by: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -218,15 +220,18 @@ pub enum PaymentAttemptUpdate {
business_sub_label: Option<String>,
amount_to_capture: Option<i64>,
capture_method: Option<storage_enums::CaptureMethod>,
updated_by: String,
},
UpdateTrackers {
payment_token: Option<String>,
connector: Option<String>,
straight_through_algorithm: Option<serde_json::Value>,
amount_capturable: Option<i64>,
updated_by: String,
},
AuthenticationTypeUpdate {
authentication_type: storage_enums::AuthenticationType,
updated_by: String,
},
ConfirmUpdate {
amount: i64,
@ -245,15 +250,18 @@ pub enum PaymentAttemptUpdate {
error_code: Option<Option<String>>,
error_message: Option<Option<String>>,
amount_capturable: Option<i64>,
updated_by: String,
},
RejectUpdate {
status: storage_enums::AttemptStatus,
error_code: Option<Option<String>>,
error_message: Option<Option<String>>,
updated_by: String,
},
VoidUpdate {
status: storage_enums::AttemptStatus,
cancellation_reason: Option<String>,
updated_by: String,
},
ResponseUpdate {
status: storage_enums::AttemptStatus,
@ -269,6 +277,7 @@ pub enum PaymentAttemptUpdate {
error_reason: Option<Option<String>>,
connector_response_reference_id: Option<String>,
amount_capturable: Option<i64>,
updated_by: String,
},
UnresolvedResponseUpdate {
status: storage_enums::AttemptStatus,
@ -279,9 +288,11 @@ pub enum PaymentAttemptUpdate {
error_message: Option<Option<String>>,
error_reason: Option<Option<String>>,
connector_response_reference_id: Option<String>,
updated_by: String,
},
StatusUpdate {
status: storage_enums::AttemptStatus,
updated_by: String,
},
ErrorUpdate {
connector: Option<String>,
@ -290,17 +301,21 @@ pub enum PaymentAttemptUpdate {
error_message: Option<Option<String>>,
error_reason: Option<Option<String>>,
amount_capturable: Option<i64>,
updated_by: String,
},
MultipleCaptureCountUpdate {
multiple_capture_count: i16,
updated_by: String,
},
SurchargeAmountUpdate {
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
updated_by: String,
},
AmountToCaptureUpdate {
status: storage_enums::AttemptStatus,
amount_capturable: i64,
updated_by: String,
},
PreprocessingUpdate {
status: storage_enums::AttemptStatus,
@ -309,9 +324,11 @@ pub enum PaymentAttemptUpdate {
preprocessing_step_id: Option<String>,
connector_transaction_id: Option<String>,
connector_response_reference_id: Option<String>,
updated_by: String,
},
SurchargeMetadataUpdate {
surcharge_metadata: Option<serde_json::Value>,
updated_by: String,
},
}

View File

@ -7,33 +7,33 @@ use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
use super::{payment_attempt::PaymentAttempt, PaymentIntent};
use crate::{errors, MerchantStorageScheme, RemoteStorageObject};
use crate::{errors, RemoteStorageObject};
#[async_trait::async_trait]
pub trait PaymentIntentInterface {
async fn update_payment_intent(
&self,
this: PaymentIntent,
payment_intent: PaymentIntentUpdate,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentIntent, errors::StorageError>;
async fn insert_payment_intent(
&self,
new: PaymentIntentNew,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentIntent, errors::StorageError>;
async fn find_payment_intent_by_payment_id_merchant_id(
&self,
payment_id: &str,
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentIntent, errors::StorageError>;
async fn get_active_payment_attempt(
&self,
payment: &mut PaymentIntent,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
#[cfg(feature = "olap")]
@ -41,7 +41,7 @@ pub trait PaymentIntentInterface {
&self,
merchant_id: &str,
filters: &PaymentIntentFetchConstraints,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<Vec<PaymentIntent>, errors::StorageError>;
#[cfg(feature = "olap")]
@ -49,7 +49,7 @@ pub trait PaymentIntentInterface {
&self,
merchant_id: &str,
time_range: &api_models::payments::TimeRange,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<Vec<PaymentIntent>, errors::StorageError>;
#[cfg(feature = "olap")]
@ -57,7 +57,7 @@ pub trait PaymentIntentInterface {
&self,
merchant_id: &str,
constraints: &PaymentIntentFetchConstraints,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<Vec<(PaymentIntent, PaymentAttempt)>, errors::StorageError>;
#[cfg(feature = "olap")]
@ -65,7 +65,7 @@ pub trait PaymentIntentInterface {
&self,
merchant_id: &str,
constraints: &PaymentIntentFetchConstraints,
storage_scheme: MerchantStorageScheme,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> error_stack::Result<Vec<String>, errors::StorageError>;
}
@ -104,6 +104,7 @@ pub struct PaymentIntentNew {
pub merchant_decision: Option<String>,
pub payment_link_id: Option<String>,
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
pub updated_by: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -112,9 +113,11 @@ pub enum PaymentIntentUpdate {
status: storage_enums::IntentStatus,
amount_captured: Option<i64>,
return_url: Option<String>,
updated_by: String,
},
MetadataUpdate {
metadata: pii::SecretSerdeValue,
updated_by: String,
},
ReturnUrlUpdate {
return_url: Option<String>,
@ -122,14 +125,17 @@ pub enum PaymentIntentUpdate {
customer_id: Option<String>,
shipping_address_id: Option<String>,
billing_address_id: Option<String>,
updated_by: String,
},
MerchantStatusUpdate {
status: storage_enums::IntentStatus,
shipping_address_id: Option<String>,
billing_address_id: Option<String>,
updated_by: String,
},
PGStatusUpdate {
status: storage_enums::IntentStatus,
updated_by: String,
},
Update {
amount: i64,
@ -148,22 +154,27 @@ pub enum PaymentIntentUpdate {
order_details: Option<Vec<pii::SecretSerdeValue>>,
metadata: Option<pii::SecretSerdeValue>,
payment_confirm_source: Option<storage_enums::PaymentSource>,
updated_by: String,
},
PaymentAttemptAndAttemptCountUpdate {
active_attempt_id: String,
attempt_count: i16,
updated_by: String,
},
StatusAndAttemptUpdate {
status: storage_enums::IntentStatus,
active_attempt_id: String,
attempt_count: i16,
updated_by: String,
},
ApproveUpdate {
merchant_decision: Option<String>,
updated_by: String,
},
RejectUpdate {
status: storage_enums::IntentStatus,
merchant_decision: Option<String>,
updated_by: String,
},
}
@ -193,6 +204,7 @@ pub struct PaymentIntentUpdateInternal {
// 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<String>,
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
pub updated_by: String,
}
impl PaymentIntentUpdate {
@ -218,6 +230,7 @@ impl PaymentIntentUpdate {
.or(source.shipping_address_id),
modified_at: common_utils::date_time::now(),
order_details: internal_update.order_details.or(source.order_details),
updated_by: internal_update.updated_by,
..source
}
}
@ -243,6 +256,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
order_details,
metadata,
payment_confirm_source,
updated_by,
} => Self {
amount: Some(amount),
currency: Some(currency),
@ -261,11 +275,16 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
order_details,
metadata,
payment_confirm_source,
updated_by,
..Default::default()
},
PaymentIntentUpdate::MetadataUpdate { metadata } => Self {
PaymentIntentUpdate::MetadataUpdate {
metadata,
updated_by,
} => Self {
metadata: Some(metadata),
modified_at: Some(common_utils::date_time::now()),
updated_by,
..Default::default()
},
PaymentIntentUpdate::ReturnUrlUpdate {
@ -274,6 +293,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
customer_id,
shipping_address_id,
billing_address_id,
updated_by,
} => Self {
return_url,
status,
@ -281,22 +301,26 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
shipping_address_id,
billing_address_id,
modified_at: Some(common_utils::date_time::now()),
updated_by,
..Default::default()
},
PaymentIntentUpdate::PGStatusUpdate { status } => Self {
PaymentIntentUpdate::PGStatusUpdate { status, updated_by } => Self {
status: Some(status),
modified_at: Some(common_utils::date_time::now()),
updated_by,
..Default::default()
},
PaymentIntentUpdate::MerchantStatusUpdate {
status,
shipping_address_id,
billing_address_id,
updated_by,
} => Self {
status: Some(status),
shipping_address_id,
billing_address_id,
modified_at: Some(common_utils::date_time::now()),
updated_by,
..Default::default()
},
PaymentIntentUpdate::ResponseUpdate {
@ -306,6 +330,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
amount_captured,
// customer_id,
return_url,
updated_by,
} => Self {
// amount,
// currency: Some(currency),
@ -314,36 +339,47 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
// customer_id,
return_url,
modified_at: Some(common_utils::date_time::now()),
updated_by,
..Default::default()
},
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
active_attempt_id,
attempt_count,
updated_by,
} => Self {
active_attempt_id: Some(active_attempt_id),
attempt_count: Some(attempt_count),
updated_by,
..Default::default()
},
PaymentIntentUpdate::StatusAndAttemptUpdate {
status,
active_attempt_id,
attempt_count,
updated_by,
} => Self {
status: Some(status),
active_attempt_id: Some(active_attempt_id),
attempt_count: Some(attempt_count),
updated_by,
..Default::default()
},
PaymentIntentUpdate::ApproveUpdate { merchant_decision } => Self {
PaymentIntentUpdate::ApproveUpdate {
merchant_decision,
updated_by,
} => Self {
merchant_decision,
updated_by,
..Default::default()
},
PaymentIntentUpdate::RejectUpdate {
status,
merchant_decision,
updated_by,
} => Self {
status: Some(status),
merchant_decision,
updated_by,
..Default::default()
},
}