From 83724e1a74031c35d6db291a5f9bcefc0bb37a67 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger <131388445+AkshayaFoiger@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:48:51 +0530 Subject: [PATCH] fix(connector): mandate noon max amount --- .../stripe/payment_intents/types.rs | 20 +++++- .../router/src/connector/noon/transformers.rs | 67 +++++++++++++------ 2 files changed, 64 insertions(+), 23 deletions(-) diff --git a/crates/router/src/compatibility/stripe/payment_intents/types.rs b/crates/router/src/compatibility/stripe/payment_intents/types.rs index 38007a3110d6..51f938d445c4 100644 --- a/crates/router/src/compatibility/stripe/payment_intents/types.rs +++ b/crates/router/src/compatibility/stripe/payment_intents/types.rs @@ -738,9 +738,25 @@ impl ForeignTryFrom<(Option, Option)> for Option Some(payments::MandateType::MultiUse(None)), + StripeMandateType::MultiUse => Some(payments::MandateType::MultiUse(Some( + payments::MandateAmountData { + amount: mandate.amount.unwrap_or_default(), + currency, + start_date: mandate.start_date, + end_date: mandate.end_date, + metadata: None, + }, + ))), }, - None => Some(api_models::payments::MandateType::MultiUse(None)), + None => Some(api_models::payments::MandateType::MultiUse(Some( + payments::MandateAmountData { + amount: mandate.amount.unwrap_or_default(), + currency, + start_date: mandate.start_date, + end_date: mandate.end_date, + metadata: None, + }, + ))), }, customer_acceptance: Some(payments::CustomerAcceptance { acceptance_type: payments::AcceptanceType::Online, diff --git a/crates/router/src/connector/noon/transformers.rs b/crates/router/src/connector/noon/transformers.rs index bbf284848b59..2ff8f58a910a 100644 --- a/crates/router/src/connector/noon/transformers.rs +++ b/crates/router/src/connector/noon/transformers.rs @@ -1,13 +1,13 @@ use common_utils::pii; -use error_stack::ResultExt; -use masking::Secret; +use error_stack::{IntoReport, ResultExt}; +use masking::{PeekInterface, Secret}; use serde::{Deserialize, Serialize}; use crate::{ connector::utils::{ self as conn_utils, CardData, PaymentsAuthorizeRequestData, RouterData, WalletData, }, - core::errors, + core::{errors, mandate::MandateBehaviour}, services, types::{self, api, storage::enums, transformers::ForeignFrom, ErrorResponse}, utils, @@ -35,6 +35,7 @@ pub struct NoonSubscriptionData { subscription_type: NoonSubscriptionType, //Short description about the subscription. name: String, + max_amount: String, } #[derive(Debug, Serialize)] @@ -91,7 +92,7 @@ pub struct NoonSubscription { #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct NoonCard { - name_on_card: Secret, + name_on_card: Option>, number_plain: cards::CardNumber, expiry_month: Secret, expiry_year: Secret, @@ -158,7 +159,7 @@ pub struct NoonPayPal { } #[derive(Debug, Serialize)] -#[serde(tag = "type", content = "data")] +#[serde(tag = "type", content = "data", rename_all = "UPPERCASE")] pub enum NoonPaymentData { Card(NoonCard), Subscription(NoonSubscription), @@ -200,10 +201,7 @@ 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() - .unwrap_or(Secret::new("".to_string())), + name_on_card: req_card.card_holder_name.clone(), number_plain: req_card.card_number.clone(), expiry_month: req_card.card_exp_month.clone(), expiry_year: req_card.get_expiry_year_4_digit(), @@ -296,7 +294,11 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { } }?, Some(item.request.currency), - item.request.order_category.clone(), + Some(item.request.order_category.clone().ok_or( + errors::ConnectorError::MissingRequiredField { + field_name: "order_category", + }, + )?), ), }; @@ -330,17 +332,40 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { }, }); - 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 subscription: Option = 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) + } + Some(data_models::mandates::MandateDataType::MultiUse(None)) => { + Err(errors::ConnectorError::MissingRequiredField { + field_name: + "setup_future_usage.mandate_data.mandate_type.multi_use.amount", + }) + .into_report() + } + None => 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 order = NoonOrder { amount: conn_utils::to_currency_base_unit(item.request.amount, item.request.currency)?, currency,