mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
refactor(mandate): move repeated code to a separate function within Mandate impl (#8772)
This commit is contained in:
@ -78,10 +78,26 @@ pub struct MandateNew {
|
|||||||
pub customer_user_agent_extended: Option<String>,
|
pub customer_user_agent_extended: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Mandate {
|
||||||
|
/// Returns customer_user_agent_extended with customer_user_agent as fallback
|
||||||
|
pub fn get_user_agent_extended(&self) -> Option<String> {
|
||||||
|
self.customer_user_agent_extended
|
||||||
|
.clone()
|
||||||
|
.or_else(|| self.customer_user_agent.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MandateNew {
|
impl MandateNew {
|
||||||
pub fn update_storage_scheme(&mut self, storage_scheme: MerchantStorageScheme) {
|
pub fn update_storage_scheme(&mut self, storage_scheme: MerchantStorageScheme) {
|
||||||
self.updated_by = Some(storage_scheme.to_string());
|
self.updated_by = Some(storage_scheme.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns customer_user_agent_extended with customer_user_agent as fallback
|
||||||
|
pub fn get_customer_user_agent_extended(&self) -> Option<String> {
|
||||||
|
self.customer_user_agent_extended
|
||||||
|
.clone()
|
||||||
|
.or_else(|| self.customer_user_agent.clone())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -238,10 +254,7 @@ impl From<&MandateNew> for Mandate {
|
|||||||
merchant_connector_id: mandate_new.merchant_connector_id.clone(),
|
merchant_connector_id: mandate_new.merchant_connector_id.clone(),
|
||||||
updated_by: mandate_new.updated_by.clone(),
|
updated_by: mandate_new.updated_by.clone(),
|
||||||
// Using customer_user_agent as a fallback
|
// Using customer_user_agent as a fallback
|
||||||
customer_user_agent_extended: mandate_new
|
customer_user_agent_extended: mandate_new.get_customer_user_agent_extended(),
|
||||||
.customer_user_agent_extended
|
|
||||||
.clone()
|
|
||||||
.or_else(|| mandate_new.customer_user_agent.clone()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -661,6 +661,8 @@ impl MandateInterface for MockDb {
|
|||||||
_storage_scheme: MerchantStorageScheme,
|
_storage_scheme: MerchantStorageScheme,
|
||||||
) -> CustomResult<storage_types::Mandate, errors::StorageError> {
|
) -> CustomResult<storage_types::Mandate, errors::StorageError> {
|
||||||
let mut mandates = self.mandates.lock().await;
|
let mut mandates = self.mandates.lock().await;
|
||||||
|
let customer_user_agent_extended = mandate_new.get_customer_user_agent_extended();
|
||||||
|
|
||||||
let mandate = storage_types::Mandate {
|
let mandate = storage_types::Mandate {
|
||||||
mandate_id: mandate_new.mandate_id.clone(),
|
mandate_id: mandate_new.mandate_id.clone(),
|
||||||
customer_id: mandate_new.customer_id,
|
customer_id: mandate_new.customer_id,
|
||||||
@ -688,10 +690,7 @@ impl MandateInterface for MockDb {
|
|||||||
connector_mandate_ids: mandate_new.connector_mandate_ids,
|
connector_mandate_ids: mandate_new.connector_mandate_ids,
|
||||||
merchant_connector_id: mandate_new.merchant_connector_id,
|
merchant_connector_id: mandate_new.merchant_connector_id,
|
||||||
updated_by: mandate_new.updated_by,
|
updated_by: mandate_new.updated_by,
|
||||||
// Using customer_user_agent as a fallback
|
customer_user_agent_extended,
|
||||||
customer_user_agent_extended: mandate_new
|
|
||||||
.customer_user_agent_extended
|
|
||||||
.or_else(|| mandate_new.customer_user_agent.clone()),
|
|
||||||
};
|
};
|
||||||
mandates.push(mandate.clone());
|
mandates.push(mandate.clone());
|
||||||
Ok(mandate)
|
Ok(mandate)
|
||||||
|
|||||||
@ -95,6 +95,7 @@ impl MandateResponseExt for MandateResponse {
|
|||||||
let payment_method_type = payment_method
|
let payment_method_type = payment_method
|
||||||
.get_payment_method_subtype()
|
.get_payment_method_subtype()
|
||||||
.map(|pmt| pmt.to_string());
|
.map(|pmt| pmt.to_string());
|
||||||
|
let user_agent = mandate.get_user_agent_extended().unwrap_or_default();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
mandate_id: mandate.mandate_id,
|
mandate_id: mandate.mandate_id,
|
||||||
customer_acceptance: Some(api::payments::CustomerAcceptance {
|
customer_acceptance: Some(api::payments::CustomerAcceptance {
|
||||||
@ -106,11 +107,7 @@ impl MandateResponseExt for MandateResponse {
|
|||||||
accepted_at: mandate.customer_accepted_at,
|
accepted_at: mandate.customer_accepted_at,
|
||||||
online: Some(api::payments::OnlineMandate {
|
online: Some(api::payments::OnlineMandate {
|
||||||
ip_address: mandate.customer_ip_address,
|
ip_address: mandate.customer_ip_address,
|
||||||
// Using customer_user_agent as a fallback
|
user_agent,
|
||||||
user_agent: mandate
|
|
||||||
.customer_user_agent_extended
|
|
||||||
.or(mandate.customer_user_agent)
|
|
||||||
.unwrap_or_default(),
|
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
card,
|
card,
|
||||||
|
|||||||
Reference in New Issue
Block a user