Skip to content

Commit

Permalink
club the amount changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranKBR committed Jul 25, 2024
1 parent bc0a254 commit 5c2ac69
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
6 changes: 2 additions & 4 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4317,6 +4317,8 @@ pub struct OrderDetailsWithAmount {
pub quantity: u16,
/// the amount per quantity of product
pub amount: i64,
//minor amount change for OrderDetailsWithAmount
pub minor_amount: MinorUnit,
// Does the order includes shipping
pub requires_shipping: Option<bool>,
/// The image URL of the product
Expand All @@ -4331,10 +4333,6 @@ pub struct OrderDetailsWithAmount {
pub brand: Option<String>,
/// Type of the product that is being purchased
pub product_type: Option<ProductType>,

//minor amount change for OrderDetailsWithAmount
pub minor_amount: MinorUnit,

}

#[derive(Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
Expand Down
6 changes: 4 additions & 2 deletions crates/router/src/connector/klarna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ pub mod transformers;

use api_models::enums;
use base64::Engine;
use common_utils::{request::RequestContent, types::{AmountConvertor, MinorUnit, MinorUnitForConnector}};
use common_utils::{
request::RequestContent,
types::{AmountConvertor, MinorUnit, MinorUnitForConnector},
};
use error_stack::{report, ResultExt};
use masking::PeekInterface;
use router_env::logger;
Expand Down Expand Up @@ -33,7 +36,6 @@ pub struct Klarna {
amount_converter: &'static (dyn AmountConvertor<Output = MinorUnit> + Sync),
}


impl Klarna {
pub fn new() -> &'static Self {
&Self {
Expand Down
15 changes: 7 additions & 8 deletions crates/router/src/connector/klarna/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ pub struct KlarnaRouterData<T> {
}

impl<T> From<(MinorUnit, T)> for KlarnaRouterData<T> {
fn from(
(amount, router_data): (
MinorUnit,
T,
),
) -> Self {
fn from((amount, router_data): (MinorUnit, T)) -> Self {
Self {
amount,
router_data,
Expand Down Expand Up @@ -153,7 +148,9 @@ impl TryFrom<&KlarnaRouterData<&types::PaymentsSessionRouterData>> for KlarnaSes
name: data.product_name.clone(),
quantity: data.quantity,
unit_price: data.minor_amount,
total_amount: MinorUnit::new(i64::from(data.quantity) * (data.minor_amount.get_amount_as_i64())),
total_amount: MinorUnit::new(
i64::from(data.quantity) * (data.minor_amount.get_amount_as_i64()),
),
})
.collect(),
shipping_address: get_address_info(item.router_data.get_optional_shipping())
Expand Down Expand Up @@ -206,7 +203,9 @@ impl TryFrom<&KlarnaRouterData<&types::PaymentsAuthorizeRouterData>> for KlarnaP
name: data.product_name.clone(),
quantity: data.quantity,
unit_price: data.minor_amount,
total_amount: MinorUnit::new(i64::from(data.quantity) * (data.minor_amount.get_amount_as_i64())),
total_amount: MinorUnit::new(
i64::from(data.quantity) * (data.minor_amount.get_amount_as_i64()),
),
})
.collect(),
merchant_reference1: Some(item.router_data.connector_request_reference_id.clone()),
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,14 +1226,14 @@ pub fn change_order_details_to_new_type(
product_name: order_details.product_name,
quantity: order_details.quantity,
amount: order_amount.get_amount_as_i64(),
minor_amount: order_amount,
product_img_link: order_details.product_img_link,
requires_shipping: order_details.requires_shipping,
product_id: order_details.product_id,
category: order_details.category,
sub_category: order_details.sub_category,
brand: order_details.brand,
product_type: order_details.product_type,
minor_amount:order_amount,
}])
}

Expand Down
4 changes: 3 additions & 1 deletion crates/router/src/types/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ impl ConnectorData {
enums::Connector::Itaubank => {
Ok(ConnectorEnum::Old(Box::new(connector::Itaubank::new())))
}
enums::Connector::Klarna => Ok(ConnectorEnum::Old(Box::new(connector::Klarna::new()))),
enums::Connector::Klarna => {
Ok(ConnectorEnum::Old(Box::new(connector::Klarna::new())))
}
enums::Connector::Mollie => Ok(ConnectorEnum::Old(Box::new(&connector::Mollie))),
enums::Connector::Nmi => Ok(ConnectorEnum::Old(Box::new(connector::Nmi::new()))),
enums::Connector::Noon => Ok(ConnectorEnum::Old(Box::new(connector::Noon::new()))),
Expand Down

0 comments on commit 5c2ac69

Please sign in to comment.