refactor(wallet): use billing.phone instead of telephone_number (#4329)

This commit is contained in:
Swangi Kumari
2024-04-22 14:46:33 +05:30
committed by GitHub
parent 9bf16b1a07
commit 3e6bc191fd
7 changed files with 52 additions and 28 deletions

View File

@ -2235,7 +2235,7 @@ impl GetAddressFromPaymentMethodData for WalletData {
let phone = PhoneDetails { let phone = PhoneDetails {
// Portuguese country code, this payment method is applicable only in portugal // Portuguese country code, this payment method is applicable only in portugal
country_code: Some("+351".into()), country_code: Some("+351".into()),
number: Some(mb_way_redirect.telephone_number.clone()), number: mb_way_redirect.telephone_number.clone(),
}; };
Some(Address { Some(Address {
@ -2360,7 +2360,7 @@ pub struct MobilePayRedirection {}
pub struct MbWayRedirection { pub struct MbWayRedirection {
/// Telephone number of the shopper. Should be Portuguese phone number. /// Telephone number of the shopper. Should be Portuguese phone number.
#[schema(value_type = String)] #[schema(value_type = String)]
pub telephone_number: Secret<String>, pub telephone_number: Option<Secret<String>>,
} }
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)] #[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]

View File

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use super::result_codes::{FAILURE_CODES, PENDING_CODES, SUCCESSFUL_CODES}; use super::result_codes::{FAILURE_CODES, PENDING_CODES, SUCCESSFUL_CODES};
use crate::{ use crate::{
connector::utils::{self, RouterData}, connector::utils::{self, PhoneDetailsData, RouterData},
core::errors, core::errors,
services, services,
types::{self, domain, storage::enums}, types::{self, domain, storage::enums},
@ -106,14 +106,20 @@ pub enum PaymentDetails {
Mandate, Mandate,
} }
impl TryFrom<&domain::WalletData> for PaymentDetails { impl TryFrom<(&domain::WalletData, &types::PaymentsAuthorizeRouterData)> for PaymentDetails {
type Error = Error; type Error = Error;
fn try_from(wallet_data: &domain::WalletData) -> Result<Self, Self::Error> { fn try_from(
value: (&domain::WalletData, &types::PaymentsAuthorizeRouterData),
) -> Result<Self, Self::Error> {
let (wallet_data, item) = value;
let payment_data = match wallet_data { let payment_data = match wallet_data {
domain::WalletData::MbWayRedirect(data) => Self::Wallet(Box::new(WalletPMData { domain::WalletData::MbWayRedirect(_) => {
let phone_details = item.get_billing_phone()?;
Self::Wallet(Box::new(WalletPMData {
payment_brand: PaymentBrand::Mbway, payment_brand: PaymentBrand::Mbway,
account_id: Some(data.telephone_number.clone()), account_id: Some(phone_details.get_number_with_hash_country_code()?),
})), }))
}
domain::WalletData::AliPayRedirect { .. } => Self::Wallet(Box::new(WalletPMData { domain::WalletData::AliPayRedirect { .. } => Self::Wallet(Box::new(WalletPMData {
payment_brand: PaymentBrand::AliPay, payment_brand: PaymentBrand::AliPay,
account_id: None, account_id: None,
@ -486,7 +492,7 @@ impl
) -> Result<Self, Self::Error> { ) -> Result<Self, Self::Error> {
let (item, wallet_data) = value; let (item, wallet_data) = value;
let txn_details = get_transaction_details(item)?; let txn_details = get_transaction_details(item)?;
let payment_method = PaymentDetails::try_from(wallet_data)?; let payment_method = PaymentDetails::try_from((wallet_data, item.router_data))?;
Ok(Self { Ok(Self {
txn_details, txn_details,

View File

@ -12,7 +12,7 @@ use time::{Duration, OffsetDateTime, PrimitiveDateTime};
use crate::{ use crate::{
connector::utils::{ connector::utils::{
self, AddressDetailsData, BrowserInformationData, CardData, MandateReferenceData, self, AddressDetailsData, BrowserInformationData, CardData, MandateReferenceData,
PaymentsAuthorizeRequestData, RouterData, PaymentsAuthorizeRequestData, PhoneDetailsData, RouterData,
}, },
consts, consts,
core::errors, core::errors,
@ -2023,9 +2023,14 @@ impl TryFrom<&utils::CardIssuer> for CardBrand {
} }
} }
impl<'a> TryFrom<&domain::WalletData> for AdyenPaymentMethod<'a> { impl<'a> TryFrom<(&domain::WalletData, &types::PaymentsAuthorizeRouterData)>
for AdyenPaymentMethod<'a>
{
type Error = Error; type Error = Error;
fn try_from(wallet_data: &domain::WalletData) -> Result<Self, Self::Error> { fn try_from(
value: (&domain::WalletData, &types::PaymentsAuthorizeRouterData),
) -> Result<Self, Self::Error> {
let (wallet_data, item) = value;
match wallet_data { match wallet_data {
domain::WalletData::GooglePay(data) => { domain::WalletData::GooglePay(data) => {
let gpay_data = AdyenGPay { let gpay_data = AdyenGPay {
@ -2080,10 +2085,11 @@ impl<'a> TryFrom<&domain::WalletData> for AdyenPaymentMethod<'a> {
let touch_n_go_data = TouchNGoData {}; let touch_n_go_data = TouchNGoData {};
Ok(AdyenPaymentMethod::TouchNGo(Box::new(touch_n_go_data))) Ok(AdyenPaymentMethod::TouchNGo(Box::new(touch_n_go_data)))
} }
domain::WalletData::MbWayRedirect(data) => { domain::WalletData::MbWayRedirect(_) => {
let phone_details = item.get_billing_phone()?;
let mbway_data = MbwayData { let mbway_data = MbwayData {
payment_type: PaymentType::Mbway, payment_type: PaymentType::Mbway,
telephone_number: data.telephone_number.clone(), telephone_number: phone_details.get_number_with_country_code()?,
}; };
Ok(AdyenPaymentMethod::Mbway(Box::new(mbway_data))) Ok(AdyenPaymentMethod::Mbway(Box::new(mbway_data)))
} }
@ -3000,7 +3006,7 @@ impl<'a>
let auth_type = AdyenAuthType::try_from(&item.router_data.connector_auth_type)?; let auth_type = AdyenAuthType::try_from(&item.router_data.connector_auth_type)?;
let browser_info = get_browser_info(item.router_data)?; let browser_info = get_browser_info(item.router_data)?;
let additional_data = get_additional_data(item.router_data); let additional_data = get_additional_data(item.router_data);
let payment_method = AdyenPaymentMethod::try_from(wallet_data)?; let payment_method = AdyenPaymentMethod::try_from((wallet_data, item.router_data))?;
let shopper_interaction = AdyenShopperInteraction::from(item.router_data); let shopper_interaction = AdyenShopperInteraction::from(item.router_data);
let channel = get_channel_type(&item.router_data.request.payment_method_type); let channel = get_channel_type(&item.router_data.request.payment_method_type);
let (recurring_processing_model, store_payment_method, shopper_reference) = let (recurring_processing_model, store_payment_method, shopper_reference) =

View File

@ -1152,6 +1152,7 @@ pub trait PhoneDetailsData {
fn get_number(&self) -> Result<Secret<String>, Error>; fn get_number(&self) -> Result<Secret<String>, Error>;
fn get_country_code(&self) -> Result<String, Error>; fn get_country_code(&self) -> Result<String, Error>;
fn get_number_with_country_code(&self) -> Result<Secret<String>, Error>; fn get_number_with_country_code(&self) -> Result<Secret<String>, Error>;
fn get_number_with_hash_country_code(&self) -> Result<Secret<String>, Error>;
} }
impl PhoneDetailsData for api::PhoneDetails { impl PhoneDetailsData for api::PhoneDetails {
@ -1170,6 +1171,16 @@ impl PhoneDetailsData for api::PhoneDetails {
let country_code = self.get_country_code()?; let country_code = self.get_country_code()?;
Ok(Secret::new(format!("{}{}", country_code, number.peek()))) Ok(Secret::new(format!("{}{}", country_code, number.peek())))
} }
fn get_number_with_hash_country_code(&self) -> Result<Secret<String>, Error> {
let number = self.get_number()?;
let country_code = self.get_country_code()?;
let number_without_plus = country_code.trim_start_matches('+');
Ok(Secret::new(format!(
"{}#{}",
number_without_plus,
number.peek()
)))
}
} }
pub trait AddressDetailsData { pub trait AddressDetailsData {

View File

@ -190,10 +190,7 @@ pub struct GcashRedirection {}
pub struct MobilePayRedirection {} pub struct MobilePayRedirection {}
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct MbWayRedirection { pub struct MbWayRedirection {}
/// Telephone number of the shopper. Should be Portuguese phone number.
pub telephone_number: Secret<String>,
}
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize)]
@ -665,10 +662,8 @@ impl From<api_models::payments::WalletData> for WalletData {
api_models::payments::WalletData::GooglePayThirdPartySdk(_) => { api_models::payments::WalletData::GooglePayThirdPartySdk(_) => {
Self::GooglePayThirdPartySdk(Box::new(GooglePayThirdPartySdkData {})) Self::GooglePayThirdPartySdk(Box::new(GooglePayThirdPartySdkData {}))
} }
api_models::payments::WalletData::MbWayRedirect(mbway_redirect_data) => { api_models::payments::WalletData::MbWayRedirect(..) => {
Self::MbWayRedirect(Box::new(MbWayRedirection { Self::MbWayRedirect(Box::new(MbWayRedirection {}))
telephone_number: mbway_redirect_data.telephone_number,
}))
} }
api_models::payments::WalletData::MobilePayRedirect(_) => { api_models::payments::WalletData::MobilePayRedirect(_) => {
Self::MobilePayRedirect(Box::new(MobilePayRedirection {})) Self::MobilePayRedirect(Box::new(MobilePayRedirection {}))

View File

@ -1,6 +1,6 @@
use std::{marker::PhantomData, str::FromStr}; use std::{marker::PhantomData, str::FromStr};
use api_models::payments::{Address, AddressDetails}; use api_models::payments::{Address, AddressDetails, PhoneDetails};
use masking::Secret; use masking::Secret;
use router::{ use router::{
configs::settings::Settings, configs::settings::Settings,
@ -87,7 +87,10 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData {
last_name: Some(Secret::new("Doe".to_string())), last_name: Some(Secret::new("Doe".to_string())),
..Default::default() ..Default::default()
}), }),
phone: None, phone: Some(PhoneDetails {
number: Some(Secret::new("8056594427".to_string())),
country_code: Some("+351".to_string()),
}),
email: None, email: None,
}), }),
), ),

View File

@ -1,6 +1,6 @@
use std::str::FromStr; use std::str::FromStr;
use api_models::payments::{Address, AddressDetails}; use api_models::payments::{Address, AddressDetails, PhoneDetails};
use masking::Secret; use masking::Secret;
use router::types::{self, storage::enums, PaymentAddress}; use router::types::{self, storage::enums, PaymentAddress};
@ -65,7 +65,10 @@ impl AdyenTest {
first_name: Some(Secret::new("John".to_string())), first_name: Some(Secret::new("John".to_string())),
last_name: Some(Secret::new("Dough".to_string())), last_name: Some(Secret::new("Dough".to_string())),
}), }),
phone: None, phone: Some(PhoneDetails {
number: Some(Secret::new("8056594427".to_string())),
country_code: Some("+351".to_string()),
}),
email: None, email: None,
}), }),
None, None,