fix: introduce net_amount field in payment response (#3115)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Hrithikesh
2024-01-08 19:57:37 +05:30
committed by GitHub
parent 7d43c5a736
commit 23e0c63541
13 changed files with 104 additions and 6 deletions

View File

@ -107,6 +107,7 @@ pub struct PaymentAttempt {
pub attempt_id: String,
pub status: storage_enums::AttemptStatus,
pub amount: i64,
pub net_amount: i64,
pub currency: Option<storage_enums::Currency>,
pub save_to_locker: Option<bool>,
pub connector: Option<String>,
@ -183,6 +184,9 @@ pub struct PaymentAttemptNew {
pub attempt_id: String,
pub status: storage_enums::AttemptStatus,
pub amount: i64,
/// amount + surcharge_amount + tax_amount
/// This field will always be derived before updating in the Database
pub net_amount: i64,
pub currency: Option<storage_enums::Currency>,
// pub auto_capture: Option<bool>,
pub save_to_locker: Option<bool>,
@ -230,6 +234,19 @@ pub struct PaymentAttemptNew {
pub unified_message: Option<String>,
}
impl PaymentAttemptNew {
/// returns amount + surcharge_amount + tax_amount
pub fn calculate_net_amount(&self) -> i64 {
self.amount + self.surcharge_amount.unwrap_or(0) + self.tax_amount.unwrap_or(0)
}
pub fn populate_derived_fields(self) -> Self {
let mut payment_attempt_new = self;
payment_attempt_new.net_amount = payment_attempt_new.calculate_net_amount();
payment_attempt_new
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PaymentAttemptUpdate {
Update {