Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add surcharge_applicable to payment_intent and remove surcharge_metadata from payment_attempt #2642

Merged
merged 6 commits into from
Oct 19, 2023
Next Next commit
feat: add surcharge_applicable to payment_intent and remove surcharge…
…_metadata from payment_attempt
hrithikesh026 committed Oct 19, 2023
commit f9db6b7c68ecd11f8ceada3f30ae476e942259b6
2 changes: 2 additions & 0 deletions crates/data_models/src/payments.rs
Original file line number Diff line number Diff line change
@@ -47,5 +47,7 @@ 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,
pub surcharge_applicable: Option<bool>,
}
6 changes: 0 additions & 6 deletions crates/data_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
@@ -141,7 +141,6 @@ pub struct PaymentAttempt {
// reference to the payment at connector side
pub connector_response_reference_id: Option<String>,
pub amount_capturable: i64,
pub surcharge_metadata: Option<serde_json::Value>,
pub updated_by: String,
}

@@ -201,7 +200,6 @@ pub struct PaymentAttemptNew {
pub connector_response_reference_id: Option<String>,
pub multiple_capture_count: Option<i16>,
pub amount_capturable: i64,
pub surcharge_metadata: Option<serde_json::Value>,
pub updated_by: String,
}

@@ -323,10 +321,6 @@ pub enum PaymentAttemptUpdate {
connector_response_reference_id: Option<String>,
updated_by: String,
},
SurchargeMetadataUpdate {
surcharge_metadata: Option<serde_json::Value>,
updated_by: String,
},
}

impl ForeignIDRef for PaymentAttempt {
4 changes: 4 additions & 0 deletions crates/data_models/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
@@ -104,7 +104,9 @@ 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,
pub surcharge_applicable: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -204,7 +206,9 @@ 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,
pub surcharge_applicable: Option<bool>,
}

impl PaymentIntentUpdate {
16 changes: 0 additions & 16 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
@@ -57,7 +57,6 @@ pub struct PaymentAttempt {
// reference to the payment at connector side
pub connector_response_reference_id: Option<String>,
pub amount_capturable: i64,
pub surcharge_metadata: Option<serde_json::Value>,
pub updated_by: String,
}

@@ -117,7 +116,6 @@ pub struct PaymentAttemptNew {
pub connector_response_reference_id: Option<String>,
pub multiple_capture_count: Option<i16>,
pub amount_capturable: i64,
pub surcharge_metadata: Option<serde_json::Value>,
pub updated_by: String,
}

@@ -239,10 +237,6 @@ pub enum PaymentAttemptUpdate {
connector_response_reference_id: Option<String>,
updated_by: String,
},
SurchargeMetadataUpdate {
surcharge_metadata: Option<serde_json::Value>,
updated_by: String,
},
}

#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
@@ -278,7 +272,6 @@ pub struct PaymentAttemptUpdateInternal {
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
amount_capturable: Option<i64>,
surcharge_metadata: Option<serde_json::Value>,
updated_by: String,
}

@@ -306,7 +299,6 @@ impl PaymentAttemptUpdate {
preprocessing_step_id: pa_update
.preprocessing_step_id
.or(source.preprocessing_step_id),
surcharge_metadata: pa_update.surcharge_metadata.or(source.surcharge_metadata),
updated_by: pa_update.updated_by,
..source
}
@@ -554,14 +546,6 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
updated_by,
..Default::default()
},
PaymentAttemptUpdate::SurchargeMetadataUpdate {
surcharge_metadata,
updated_by,
} => Self {
surcharge_metadata,
updated_by,
..Default::default()
},
}
}
}
6 changes: 6 additions & 0 deletions crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
@@ -48,7 +48,9 @@ pub struct PaymentIntent {
pub merchant_decision: Option<String>,
pub payment_link_id: Option<String>,
pub payment_confirm_source: Option<storage_enums::PaymentSource>,

pub updated_by: String,
pub surcharge_applicable: Option<bool>,
}

#[derive(
@@ -101,7 +103,9 @@ 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,
pub surcharge_applicable: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -202,7 +206,9 @@ pub struct PaymentIntentUpdateInternal {
pub profile_id: Option<String>,
merchant_decision: Option<String>,
payment_confirm_source: Option<storage_enums::PaymentSource>,

pub updated_by: String,
pub surcharge_applicable: Option<bool>,
}

impl PaymentIntentUpdate {
2 changes: 1 addition & 1 deletion crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
@@ -559,7 +559,6 @@ diesel::table! {
#[max_length = 128]
connector_response_reference_id -> Nullable<Varchar>,
amount_capturable -> Int8,
surcharge_metadata -> Nullable<Jsonb>,
#[max_length = 32]
updated_by -> Varchar,
}
@@ -622,6 +621,7 @@ diesel::table! {
payment_confirm_source -> Nullable<PaymentSource>,
#[max_length = 32]
updated_by -> Varchar,
surcharge_applicable -> Nullable<Bool>,
}
}

11 changes: 10 additions & 1 deletion crates/router/src/core/payment_methods.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,10 @@ use data_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent};
use diesel_models::enums;

use crate::{
core::{errors::RouterResult, payments::helpers},
core::{
errors::RouterResult,
payments::{helpers, PaymentData},
},
routes::AppState,
types::api::{self, payments},
};
@@ -26,6 +29,12 @@ pub trait PaymentMethodRetrieve {
payment_intent: &PaymentIntent,
payment_attempt: &PaymentAttempt,
) -> RouterResult<(Option<payments::PaymentMethodData>, Option<String>)>;

fn update_payment_data_before_session_connector_call<F: Clone>(
_payment_data: &mut PaymentData<F>,
) -> RouterResult<()> {
Ok(())
}
}

#[async_trait::async_trait]
23 changes: 2 additions & 21 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
@@ -818,19 +818,6 @@ where
{
let call_connectors_start_time = Instant::now();
let mut join_handlers = Vec::with_capacity(connectors.len());
let surcharge_metadata = payment_data
.payment_attempt
.surcharge_metadata
.as_ref()
.map(|surcharge_metadata_value| {
surcharge_metadata_value
.clone()
.parse_value::<SurchargeMetadata>("SurchargeMetadata")
})
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to Deserialize SurchargeMetadata")?;

for session_connector_data in connectors.iter() {
let connector_id = session_connector_data.connector.connector.id();

@@ -843,14 +830,7 @@ where
false,
)
.await?;
payment_data.surcharge_details =
surcharge_metadata.as_ref().and_then(|surcharge_metadata| {
let payment_method_type = session_connector_data.payment_method_type;
surcharge_metadata
.surcharge_results
.get(&payment_method_type.to_string())
.cloned()
});
Ctx::update_payment_data_before_session_connector_call::<F>(&mut payment_data)?;

let router_data = payment_data
.construct_router_data(
@@ -1485,6 +1465,7 @@ where
pub ephemeral_key: Option<ephemeral_key::EphemeralKey>,
pub redirect_response: Option<api_models::payments::RedirectResponse>,
pub surcharge_details: Option<SurchargeDetailsResponse>,
pub session_surcharge_details: Option<SurchargeMetadata>,
pub frm_message: Option<FraudCheck>,
pub payment_link_data: Option<api_models::payments::PaymentLinkResponse>,
}
4 changes: 3 additions & 1 deletion crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
@@ -2409,6 +2409,7 @@ mod tests {
profile_id: None,
merchant_decision: None,
payment_confirm_source: None,
surcharge_applicable: None,
updated_by: storage_enums::MerchantStorageScheme::PostgresOnly.to_string(),
};
let req_cs = Some("1".to_string());
@@ -2458,6 +2459,7 @@ mod tests {
profile_id: None,
merchant_decision: None,
payment_confirm_source: None,
surcharge_applicable: None,
updated_by: storage_enums::MerchantStorageScheme::PostgresOnly.to_string(),
};
let req_cs = Some("1".to_string());
@@ -2507,6 +2509,7 @@ mod tests {
profile_id: None,
merchant_decision: None,
payment_confirm_source: None,
surcharge_applicable: None,
updated_by: storage_enums::MerchantStorageScheme::PostgresOnly.to_string(),
};
let req_cs = Some("1".to_string());
@@ -2900,7 +2903,6 @@ impl AttemptType {
multiple_capture_count: None,
connector_response_reference_id: None,
amount_capturable: old_payment_attempt.amount,
surcharge_metadata: old_payment_attempt.surcharge_metadata,
updated_by: storage_scheme.to_string(),
}
}
Original file line number Diff line number Diff line change
@@ -252,6 +252,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data: None,
redirect_response,
surcharge_details: None,
session_surcharge_details: None,
frm_message: frm_response.ok(),
payment_link_data: None,
},
Original file line number Diff line number Diff line change
@@ -172,6 +172,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data: None,
redirect_response: None,
surcharge_details: None,
session_surcharge_details: None,
frm_message: None,
payment_link_data: None,
},
Original file line number Diff line number Diff line change
@@ -234,6 +234,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data,
redirect_response: None,
surcharge_details: None,
session_surcharge_details: None,
frm_message: None,
payment_link_data: None,
},
Original file line number Diff line number Diff line change
@@ -247,6 +247,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data: None,
redirect_response,
surcharge_details: None,
session_surcharge_details: None,
frm_message: None,
payment_link_data: None,
},
Original file line number Diff line number Diff line change
@@ -382,6 +382,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data: None,
redirect_response: None,
surcharge_details,
session_surcharge_details: None,
frm_message: None,
payment_link_data: None,
},
Original file line number Diff line number Diff line change
@@ -310,6 +310,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data: None,
redirect_response: None,
surcharge_details: None,
session_surcharge_details: None,
frm_message: None,
payment_link_data,
},
@@ -720,6 +721,7 @@ impl PaymentCreate {
merchant_decision: None,
payment_link_id,
payment_confirm_source: None,
surcharge_applicable: None,
updated_by: merchant_account.storage_scheme.to_string(),
})
}
Original file line number Diff line number Diff line change
@@ -198,6 +198,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data: None,
redirect_response: None,
surcharge_details: None,
session_surcharge_details: None,
frm_message: None,
payment_link_data: None,
},
@@ -401,6 +402,7 @@ impl PaymentMethodValidate {
profile_id: Default::default(),
merchant_decision: Default::default(),
payment_confirm_source: Default::default(),
surcharge_applicable: Default::default(),
payment_link_id: Default::default(),
updated_by: storage_scheme.to_string(),
}
Original file line number Diff line number Diff line change
@@ -158,6 +158,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data: None,
redirect_response: None,
surcharge_details: None,
session_surcharge_details: None,
frm_message: frm_response.ok(),
payment_link_data: None,
},
Original file line number Diff line number Diff line change
@@ -200,6 +200,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data: None,
redirect_response: None,
surcharge_details: None,
session_surcharge_details: None,
frm_message: None,
payment_link_data: None,
},
Original file line number Diff line number Diff line change
@@ -174,6 +174,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data: None,
redirect_response: None,
surcharge_details: None,
session_surcharge_details: None,
frm_message: None,
payment_link_data: None,
},
Original file line number Diff line number Diff line change
@@ -411,6 +411,7 @@ async fn get_tracker_for_sync<
redirect_response: None,
payment_link_data: None,
surcharge_details: None,
session_surcharge_details: None,
frm_message: frm_response.ok(),
},
None,
Original file line number Diff line number Diff line change
@@ -353,6 +353,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
multiple_capture_data: None,
redirect_response: None,
surcharge_details: None,
session_surcharge_details: None,
frm_message: None,
payment_link_data: None,
},
1 change: 0 additions & 1 deletion crates/storage_impl/src/mock_db/payment_attempt.rs
Original file line number Diff line number Diff line change
@@ -140,7 +140,6 @@ impl PaymentAttemptInterface for MockDb {
multiple_capture_count: payment_attempt.multiple_capture_count,
connector_response_reference_id: None,
amount_capturable: payment_attempt.amount_capturable,
surcharge_metadata: payment_attempt.surcharge_metadata,
updated_by: storage_scheme.to_string(),
};
payment_attempts.push(payment_attempt.clone());
1 change: 1 addition & 0 deletions crates/storage_impl/src/mock_db/payment_intent.rs
Original file line number Diff line number Diff line change
@@ -104,6 +104,7 @@ impl PaymentIntentInterface for MockDb {
payment_link_id: new.payment_link_id,
payment_confirm_source: new.payment_confirm_source,
updated_by: storage_scheme.to_string(),
surcharge_applicable: new.surcharge_applicable,
};
payment_intents.push(payment_intent.clone());
Ok(payment_intent)
Loading