From 4cd65a24f70fdef160eb2d87654f1e30538c3339 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger <131388445+AkshayaFoiger@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:09:53 +0530 Subject: [PATCH] Refactor(Router): [Noon] revert adding new field max_amount to mandate request (#3435) --- .../router/src/connector/noon/transformers.rs | 59 +++++++------------ 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/crates/router/src/connector/noon/transformers.rs b/crates/router/src/connector/noon/transformers.rs index 81f3ab33e2..bbf284848b 100644 --- a/crates/router/src/connector/noon/transformers.rs +++ b/crates/router/src/connector/noon/transformers.rs @@ -1,5 +1,5 @@ use common_utils::pii; -use error_stack::{IntoReport, ResultExt}; +use error_stack::ResultExt; use masking::Secret; use serde::{Deserialize, Serialize}; @@ -7,7 +7,7 @@ use crate::{ connector::utils::{ self as conn_utils, CardData, PaymentsAuthorizeRequestData, RouterData, WalletData, }, - core::{errors, mandate::MandateBehaviour}, + core::errors, services, types::{self, api, storage::enums, transformers::ForeignFrom, ErrorResponse}, utils, @@ -30,13 +30,11 @@ pub enum NoonSubscriptionType { } #[derive(Debug, Serialize)] -#[serde(rename_all = "camelCase")] pub struct NoonSubscriptionData { #[serde(rename = "type")] subscription_type: NoonSubscriptionType, //Short description about the subscription. name: String, - max_amount: String, } #[derive(Debug, Serialize)] @@ -93,7 +91,7 @@ pub struct NoonSubscription { #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct NoonCard { - name_on_card: Option>, + name_on_card: Secret, number_plain: cards::CardNumber, expiry_month: Secret, expiry_year: Secret, @@ -160,7 +158,7 @@ pub struct NoonPayPal { } #[derive(Debug, Serialize)] -#[serde(tag = "type", content = "data", rename_all = "UPPERCASE")] +#[serde(tag = "type", content = "data")] pub enum NoonPaymentData { Card(NoonCard), Subscription(NoonSubscription), @@ -202,7 +200,10 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { _ => ( match item.request.payment_method_data.clone() { api::PaymentMethodData::Card(req_card) => Ok(NoonPaymentData::Card(NoonCard { - name_on_card: req_card.card_holder_name.clone(), + name_on_card: req_card + .card_holder_name + .clone() + .unwrap_or(Secret::new("".to_string())), number_plain: req_card.card_number.clone(), expiry_month: req_card.card_exp_month.clone(), expiry_year: req_card.get_expiry_year_4_digit(), @@ -295,11 +296,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { } }?, Some(item.request.currency), - Some(item.request.order_category.clone().ok_or( - errors::ConnectorError::MissingRequiredField { - field_name: "order_category", - }, - )?), + item.request.order_category.clone(), ), }; @@ -333,33 +330,17 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { }, }); - let subscription = item - .request - .get_setup_mandate_details() - .map(|mandate_data| { - let max_amount = match &mandate_data.mandate_type { - Some(data_models::mandates::MandateDataType::SingleUse(mandate)) - | Some(data_models::mandates::MandateDataType::MultiUse(Some(mandate))) => { - conn_utils::to_currency_base_unit(mandate.amount, mandate.currency) - } - _ => Err(errors::ConnectorError::MissingRequiredField { - field_name: "setup_future_usage.mandate_data.mandate_type", - }) - .into_report(), - }?; - - Ok::>( - NoonSubscriptionData { - subscription_type: NoonSubscriptionType::Unscheduled, - name: name.clone(), - max_amount, - }, - ) - }) - .transpose()?; - - let tokenize_c_c = subscription.is_some().then_some(true); - + let (subscription, tokenize_c_c) = + match item.request.setup_future_usage.is_some().then_some(( + NoonSubscriptionData { + subscription_type: NoonSubscriptionType::Unscheduled, + name: name.clone(), + }, + true, + )) { + Some((a, b)) => (Some(a), Some(b)), + None => (None, None), + }; let order = NoonOrder { amount: conn_utils::to_currency_base_unit(item.request.amount, item.request.currency)?, currency,