feat(customer_v2): add route for customer retrieve v2 (#5516)

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>
Co-authored-by: Sahkal Poddar <sahkalpoddar@Sahkals-MacBook-Air.local>
This commit is contained in:
Sahkal Poddar
2024-08-22 20:24:56 +05:30
committed by GitHub
parent ca40e06f8f
commit 914cab0d7b
14 changed files with 247 additions and 74 deletions

View File

@ -439,6 +439,7 @@ pub async fn retrieve_customer(
) -> errors::CustomerResponse<customers::CustomerResponse> {
let db = state.store.as_ref();
let key_manager_state = &(&state).into();
let response = db
.find_customer_by_customer_id_merchant_id(
key_manager_state,
@ -462,6 +463,33 @@ pub async fn retrieve_customer(
))
}
#[cfg(all(feature = "v2", feature = "customer_v2"))]
#[instrument(skip(state))]
pub async fn retrieve_customer(
state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: customers::GlobalId,
) -> errors::CustomerResponse<customers::CustomerResponse> {
let db = state.store.as_ref();
let key_manager_state = &(&state).into();
let response = db
.find_customer_by_global_id(
key_manager_state,
&req.id,
merchant_account.get_id(),
&key_store,
merchant_account.storage_scheme,
)
.await
.switch()?;
Ok(services::ApplicationResponse::Json(
customers::CustomerResponse::foreign_from(response),
))
}
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
#[instrument(skip(state))]
pub async fn list_customers(

View File

@ -1437,6 +1437,19 @@ pub(crate) async fn get_payment_method_create_request(
}
}
#[cfg(all(feature = "v2", feature = "customer_v2"))]
pub async fn get_customer_from_details<F: Clone>(
_state: &SessionState,
_customer_id: Option<id_type::CustomerId>,
_merchant_id: &id_type::MerchantId,
_payment_data: &mut PaymentData<F>,
_merchant_key_store: &domain::MerchantKeyStore,
_storage_scheme: enums::MerchantStorageScheme,
) -> CustomResult<Option<domain::Customer>, errors::StorageError> {
todo!()
}
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
pub async fn get_customer_from_details<F: Clone>(
state: &SessionState,
customer_id: Option<id_type::CustomerId>,
@ -1449,7 +1462,6 @@ pub async fn get_customer_from_details<F: Clone>(
None => Ok(None),
Some(customer_id) => {
let db = &*state.store;
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
let customer = db
.find_customer_optional_by_customer_id_merchant_id(
&state.into(),
@ -1460,17 +1472,6 @@ pub async fn get_customer_from_details<F: Clone>(
)
.await?;
#[cfg(all(feature = "v2", feature = "customer_v2"))]
let customer = db
.find_optional_by_merchant_id_merchant_reference_id(
&state.into(),
&customer_id,
merchant_id,
merchant_key_store,
storage_scheme,
)
.await?;
payment_data.email = payment_data.email.clone().or_else(|| {
customer.as_ref().and_then(|inner| {
inner