feat(customer_v2): customer v2 refactor customer v2 update endpoint (#5490)

Co-authored-by: Narayan Bhat <narayan.bhat@juspay.in>
Co-authored-by: hrithikesh026 <hrithikesh.vm@juspay.in>
Co-authored-by: Prajjwal Kumar <prajjwal.kumar@juspay.in>
Co-authored-by: Sanchith Hegde <sanchith.hegde@juspay.in>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Sahkal Poddar
2024-08-14 14:56:34 +05:30
committed by GitHub
parent 8bcda2cea4
commit 17703fe2cb
28 changed files with 1813 additions and 768 deletions

View File

@ -884,6 +884,104 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
}
}
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
#[async_trait::async_trait]
impl CustomerAddress for api_models::customers::CustomerUpdateRequest {
async fn get_address_update(
&self,
state: &SessionState,
address_details: payments::AddressDetails,
key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme,
merchant_id: id_type::MerchantId,
) -> CustomResult<storage::AddressUpdate, common_utils::errors::CryptoError> {
let encrypted_data = crypto_operation(
&state.into(),
type_name!(storage::Address),
CryptoOperation::BatchEncrypt(AddressDetailsWithPhone::to_encryptable(
AddressDetailsWithPhone {
address: Some(address_details.clone()),
phone_number: self.phone.clone(),
email: self.email.clone(),
},
)),
Identifier::Merchant(merchant_id),
key,
)
.await
.and_then(|val| val.try_into_batchoperation())?;
let encryptable_address = AddressDetailsWithPhone::from_encryptable(encrypted_data)
.change_context(common_utils::errors::CryptoError::EncodingFailed)?;
Ok(storage::AddressUpdate::Update {
city: address_details.city,
country: address_details.country,
line1: encryptable_address.line1,
line2: encryptable_address.line2,
line3: encryptable_address.line3,
zip: encryptable_address.zip,
state: encryptable_address.state,
first_name: encryptable_address.first_name,
last_name: encryptable_address.last_name,
phone_number: encryptable_address.phone_number,
country_code: self.phone_country_code.clone(),
updated_by: storage_scheme.to_string(),
email: encryptable_address.email,
})
}
async fn get_domain_address(
&self,
state: &SessionState,
address_details: payments::AddressDetails,
merchant_id: &id_type::MerchantId,
customer_id: &id_type::CustomerId,
key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme,
) -> CustomResult<domain::CustomerAddress, common_utils::errors::CryptoError> {
let encrypted_data = crypto_operation(
&state.into(),
type_name!(storage::Address),
CryptoOperation::BatchEncrypt(AddressDetailsWithPhone::to_encryptable(
AddressDetailsWithPhone {
address: Some(address_details.clone()),
phone_number: self.phone.clone(),
email: self.email.clone(),
},
)),
Identifier::Merchant(merchant_id.to_owned()),
key,
)
.await
.and_then(|val| val.try_into_batchoperation())?;
let encryptable_address = AddressDetailsWithPhone::from_encryptable(encrypted_data)
.change_context(common_utils::errors::CryptoError::EncodingFailed)?;
let address = domain::Address {
city: address_details.city,
country: address_details.country,
line1: encryptable_address.line1,
line2: encryptable_address.line2,
line3: encryptable_address.line3,
zip: encryptable_address.zip,
state: encryptable_address.state,
first_name: encryptable_address.first_name,
last_name: encryptable_address.last_name,
phone_number: encryptable_address.phone_number,
country_code: self.phone_country_code.clone(),
merchant_id: merchant_id.to_owned(),
address_id: generate_id(consts::ID_LENGTH, "add"),
created_at: common_utils::date_time::now(),
modified_at: common_utils::date_time::now(),
updated_by: storage_scheme.to_string(),
email: encryptable_address.email,
};
Ok(domain::CustomerAddress {
address,
customer_id: customer_id.to_owned(),
})
}
}
pub fn add_apple_pay_flow_metrics(
apple_pay_flow: &Option<domain::ApplePayFlow>,
connector: Option<String>,