Refactor(Router): [Noon] revert adding new field max_amount to mandate request (#3435)

This commit is contained in:
AkshayaFoiger
2024-01-24 16:09:53 +05:30
committed by GitHub
parent 8a019f08ac
commit 4cd65a24f7

View File

@ -1,5 +1,5 @@
use common_utils::pii; use common_utils::pii;
use error_stack::{IntoReport, ResultExt}; use error_stack::ResultExt;
use masking::Secret; use masking::Secret;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -7,7 +7,7 @@ use crate::{
connector::utils::{ connector::utils::{
self as conn_utils, CardData, PaymentsAuthorizeRequestData, RouterData, WalletData, self as conn_utils, CardData, PaymentsAuthorizeRequestData, RouterData, WalletData,
}, },
core::{errors, mandate::MandateBehaviour}, core::errors,
services, services,
types::{self, api, storage::enums, transformers::ForeignFrom, ErrorResponse}, types::{self, api, storage::enums, transformers::ForeignFrom, ErrorResponse},
utils, utils,
@ -30,13 +30,11 @@ pub enum NoonSubscriptionType {
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NoonSubscriptionData { pub struct NoonSubscriptionData {
#[serde(rename = "type")] #[serde(rename = "type")]
subscription_type: NoonSubscriptionType, subscription_type: NoonSubscriptionType,
//Short description about the subscription. //Short description about the subscription.
name: String, name: String,
max_amount: String,
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -93,7 +91,7 @@ pub struct NoonSubscription {
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct NoonCard { pub struct NoonCard {
name_on_card: Option<Secret<String>>, name_on_card: Secret<String>,
number_plain: cards::CardNumber, number_plain: cards::CardNumber,
expiry_month: Secret<String>, expiry_month: Secret<String>,
expiry_year: Secret<String>, expiry_year: Secret<String>,
@ -160,7 +158,7 @@ pub struct NoonPayPal {
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(tag = "type", content = "data", rename_all = "UPPERCASE")] #[serde(tag = "type", content = "data")]
pub enum NoonPaymentData { pub enum NoonPaymentData {
Card(NoonCard), Card(NoonCard),
Subscription(NoonSubscription), Subscription(NoonSubscription),
@ -202,7 +200,10 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest {
_ => ( _ => (
match item.request.payment_method_data.clone() { match item.request.payment_method_data.clone() {
api::PaymentMethodData::Card(req_card) => Ok(NoonPaymentData::Card(NoonCard { 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(), number_plain: req_card.card_number.clone(),
expiry_month: req_card.card_exp_month.clone(), expiry_month: req_card.card_exp_month.clone(),
expiry_year: req_card.get_expiry_year_4_digit(), 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.currency),
Some(item.request.order_category.clone().ok_or( item.request.order_category.clone(),
errors::ConnectorError::MissingRequiredField {
field_name: "order_category",
},
)?),
), ),
}; };
@ -333,33 +330,17 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest {
}, },
}); });
let subscription = item let (subscription, tokenize_c_c) =
.request match item.request.setup_future_usage.is_some().then_some((
.get_setup_mandate_details() NoonSubscriptionData {
.map(|mandate_data| { subscription_type: NoonSubscriptionType::Unscheduled,
let max_amount = match &mandate_data.mandate_type { name: name.clone(),
Some(data_models::mandates::MandateDataType::SingleUse(mandate)) },
| Some(data_models::mandates::MandateDataType::MultiUse(Some(mandate))) => { true,
conn_utils::to_currency_base_unit(mandate.amount, mandate.currency) )) {
} Some((a, b)) => (Some(a), Some(b)),
_ => Err(errors::ConnectorError::MissingRequiredField { None => (None, None),
field_name: "setup_future_usage.mandate_data.mandate_type", };
})
.into_report(),
}?;
Ok::<NoonSubscriptionData, error_stack::Report<errors::ConnectorError>>(
NoonSubscriptionData {
subscription_type: NoonSubscriptionType::Unscheduled,
name: name.clone(),
max_amount,
},
)
})
.transpose()?;
let tokenize_c_c = subscription.is_some().then_some(true);
let order = NoonOrder { let order = NoonOrder {
amount: conn_utils::to_currency_base_unit(item.request.amount, item.request.currency)?, amount: conn_utils::to_currency_base_unit(item.request.amount, item.request.currency)?,
currency, currency,