refactor(connector): added amount conversion framework for klarna and change type of amount to MinorUnit for OrderDetailsWithAmount (#4979)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: swangi-kumari <swangi.12015941@lpu.in>
Co-authored-by: Swangi Kumari <85639103+swangi-kumari@users.noreply.github.com>
This commit is contained in:
Kiran Kumar
2024-10-25 18:29:44 +05:30
committed by GitHub
parent d58f706dc3
commit 2807622ba6
21 changed files with 122 additions and 95 deletions

View File

@ -7,7 +7,8 @@ pub mod authentication;
use std::{
borrow::Cow,
fmt::Display,
ops::{Add, Sub},
iter::Sum,
ops::{Add, Mul, Sub},
primitive::i64,
str::FromStr,
};
@ -483,6 +484,20 @@ impl Sub for MinorUnit {
}
}
impl Mul<u16> for MinorUnit {
type Output = Self;
fn mul(self, a2: u16) -> Self::Output {
Self(self.0 * i64::from(a2))
}
}
impl Sum for MinorUnit {
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
iter.fold(Self(0), |a, b| a + b)
}
}
/// Connector specific types to send
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq)]