Skip to content

Commit

Permalink
payment method updated_by
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay S authored and Akshay S committed May 13, 2024
1 parent 4839760 commit de27956
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
29 changes: 29 additions & 0 deletions crates/diesel_models/src/payment_method.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use common_enums::MerchantStorageScheme;
use common_utils::pii;
use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
use masking::Secret;
Expand Down Expand Up @@ -40,6 +41,7 @@ pub struct PaymentMethod {
pub status: storage_enums::PaymentMethodStatus,
pub network_transaction_id: Option<String>,
pub client_secret: Option<String>,
pub updated_by : Option<String>,
}

#[derive(
Expand Down Expand Up @@ -75,6 +77,13 @@ pub struct PaymentMethodNew {
pub status: storage_enums::PaymentMethodStatus,
pub network_transaction_id: Option<String>,
pub client_secret: Option<String>,
pub updated_by : Option<String>,
}

impl PaymentMethodNew {
pub fn update_storage_scheme(&mut self, storage_scheme : MerchantStorageScheme){
self.updated_by = Some(storage_scheme.to_string());
}
}

impl Default for PaymentMethodNew {
Expand Down Expand Up @@ -110,6 +119,7 @@ impl Default for PaymentMethodNew {
status: storage_enums::PaymentMethodStatus::Active,
network_transaction_id: Option::default(),
client_secret: Option::default(),
updated_by : Option::default(),
}
}
}
Expand Down Expand Up @@ -149,6 +159,14 @@ pub enum PaymentMethodUpdate {
},
}

impl PaymentMethodUpdate{
pub fn convert_to_payment_method_update(self, storage_scheme : MerchantStorageScheme) -> PaymentMethodUpdateInternal{
let mut update_internal : PaymentMethodUpdateInternal = self.into();
update_internal.updated_by = Some(storage_scheme.to_string());
update_internal
}
}

#[derive(
Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay, Serialize, Deserialize,
)]
Expand All @@ -162,6 +180,7 @@ pub struct PaymentMethodUpdateInternal {
locker_id: Option<String>,
payment_method: Option<storage_enums::PaymentMethod>,
connector_mandate_details: Option<serde_json::Value>,
updated_by : Option<String>
}

impl PaymentMethodUpdateInternal {
Expand All @@ -179,6 +198,7 @@ impl PaymentMethodUpdateInternal {
network_transaction_id,
status,
connector_mandate_details,
updated_by,
..
} = self;

Expand All @@ -191,6 +211,7 @@ impl PaymentMethodUpdateInternal {
status: status.unwrap_or(source.status),
connector_mandate_details: connector_mandate_details
.map_or(source.connector_mandate_details, Some),
updated_by : updated_by.map_or(source.updated_by, Some),
..source
}
}
Expand All @@ -208,6 +229,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
locker_id: None,
payment_method: None,
connector_mandate_details: None,
updated_by : None,
},
PaymentMethodUpdate::PaymentMethodDataUpdate {
payment_method_data,
Expand All @@ -220,6 +242,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
locker_id: None,
payment_method: None,
connector_mandate_details: None,
updated_by: None,
},
PaymentMethodUpdate::LastUsedUpdate { last_used_at } => Self {
metadata: None,
Expand All @@ -230,6 +253,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
locker_id: None,
payment_method: None,
connector_mandate_details: None,
updated_by : None,
},
PaymentMethodUpdate::NetworkTransactionIdAndStatusUpdate {
network_transaction_id,
Expand All @@ -243,6 +267,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
locker_id: None,
payment_method: None,
connector_mandate_details: None,
updated_by : None,
},
PaymentMethodUpdate::StatusUpdate { status } => Self {
metadata: None,
Expand All @@ -253,6 +278,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
locker_id: None,
payment_method: None,
connector_mandate_details: None,
updated_by : None,
},
PaymentMethodUpdate::AdditionalDataUpdate {
payment_method_data,
Expand All @@ -268,6 +294,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
locker_id,
payment_method,
connector_mandate_details: None,
updated_by : None,
},
PaymentMethodUpdate::ConnectorMandateDetailsUpdate {
connector_mandate_details,
Expand All @@ -280,6 +307,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
payment_method: None,
connector_mandate_details,
network_transaction_id: None,
updated_by : None,
},
}
}
Expand Down Expand Up @@ -317,6 +345,7 @@ impl From<&PaymentMethodNew> for PaymentMethod {
status: payment_method_new.status,
network_transaction_id: payment_method_new.network_transaction_id.clone(),
client_secret: payment_method_new.client_secret.clone(),
updated_by : payment_method_new.updated_by.clone(),
}
}
}
2 changes: 2 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@ diesel::table! {
network_transaction_id -> Nullable<Varchar>,
#[max_length = 128]
client_secret -> Nullable<Varchar>,
#[max_length = 32]
updated_by -> Nullable<Varchar>,
}
}

Expand Down
8 changes: 5 additions & 3 deletions crates/router/src/db/payment_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ mod storage {
#[instrument(skip_all)]
async fn insert_payment_method(
&self,
payment_method_new: storage_types::PaymentMethodNew,
mut payment_method_new: storage_types::PaymentMethodNew,
storage_scheme: MerchantStorageScheme,
) -> CustomResult<storage_types::PaymentMethod, errors::StorageError> {
let storage_scheme = decide_storage_scheme::<_,storage_types::PaymentMethod>(&self,storage_scheme, Op::Insert).await;
payment_method_new.update_storage_scheme(storage_scheme);
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
let conn = connection::pg_connection_write(self).await?;
Expand Down Expand Up @@ -291,7 +292,7 @@ mod storage {
MerchantStorageScheme::PostgresOnly => {
let conn = connection::pg_connection_write(self).await?;
payment_method
.update_with_payment_method_id(&conn, payment_method_update.into())
.update_with_payment_method_id(&conn, payment_method_update.convert_to_payment_method_update(storage_scheme))
.await
.map_err(|error| report!(errors::StorageError::from(error)))
}
Expand All @@ -302,7 +303,7 @@ mod storage {
};
let key_str = key.to_string();

let p_update: PaymentMethodUpdateInternal = payment_method_update.into();
let p_update: PaymentMethodUpdateInternal = payment_method_update.convert_to_payment_method_update(storage_scheme);
let updated_payment_method =
p_update.clone().apply_changeset(payment_method.clone());

Expand Down Expand Up @@ -668,6 +669,7 @@ impl PaymentMethodInterface for MockDb {
status: payment_method_new.status,
client_secret: payment_method_new.client_secret,
network_transaction_id: payment_method_new.network_transaction_id,
updated_by : payment_method_new.updated_by,
};
payment_methods.push(payment_method.clone());
Ok(payment_method)
Expand Down

0 comments on commit de27956

Please sign in to comment.