Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [Noon] add new field max_amount to mandate request #3589

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions crates/router/src/compatibility/stripe/payment_intents/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,25 @@ impl ForeignTryFrom<(Option<MandateData>, Option<String>)> for Option<payments::
metadata: None,
},
)),
StripeMandateType::MultiUse => 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,
Expand Down
81 changes: 45 additions & 36 deletions crates/router/src/connector/noon/transformers.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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, RevokeMandateRequestData,
RouterData, WalletData,
},
core::errors,
core::{errors, mandate::MandateBehaviour},
services,
types::{self, api, storage::enums, transformers::ForeignFrom, ErrorResponse},
utils,
Expand Down Expand Up @@ -37,7 +37,7 @@ pub struct NoonSubscriptionData {
subscription_type: NoonSubscriptionType,
//Short description about the subscription.
name: String,
max_amount: Option<String>,
max_amount: String,
}

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct NoonSubscription {
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NoonCard {
name_on_card: Secret<String>,
name_on_card: Option<Secret<String>>,
number_plain: cards::CardNumber,
expiry_month: Secret<String>,
expiry_year: Secret<String>,
Expand Down Expand Up @@ -161,7 +161,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),
Expand Down Expand Up @@ -204,10 +204,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(),
Expand Down Expand Up @@ -300,7 +297,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",
},
)?),
),
};

Expand Down Expand Up @@ -334,32 +335,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(),
max_amount: item
.request
.setup_mandate_details
.clone()
.and_then(|mandate_details| match mandate_details.mandate_type {
Some(data_models::mandates::MandateDataType::SingleUse(mandate))
| Some(data_models::mandates::MandateDataType::MultiUse(Some(
mandate,
))) => Some(
conn_utils::to_currency_base_unit(mandate.amount, mandate.currency)
.ok(),
),
_ => None,
let subscription: Option<NoonSubscriptionData> = 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",
})
.flatten(),
},
true,
)) {
Some((a, b)) => (Some(a), Some(b)),
None => (None, None),
};
.into_report()
}
None => Err(errors::ConnectorError::MissingRequiredField {
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 {
amount: conn_utils::to_currency_base_unit(item.request.amount, item.request.currency)?,
currency,
Expand Down
Loading