mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
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:
@ -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(
|
||||
|
||||
@ -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
|
||||
|
||||
@ -30,6 +30,12 @@ use super::blocklist;
|
||||
use super::currency;
|
||||
#[cfg(feature = "dummy_connector")]
|
||||
use super::dummy_connector::*;
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "customer_v2"),
|
||||
feature = "oltp"
|
||||
))]
|
||||
use super::ephemeral_key::*;
|
||||
#[cfg(any(feature = "olap", feature = "oltp"))]
|
||||
use super::payment_methods::*;
|
||||
#[cfg(feature = "payouts")]
|
||||
@ -48,6 +54,8 @@ use super::poll::retrieve_poll_status;
|
||||
use super::routing;
|
||||
#[cfg(feature = "olap")]
|
||||
use super::verification::{apple_pay_merchant_registration, retrieve_apple_pay_verified_domains};
|
||||
#[cfg(feature = "oltp")]
|
||||
use super::webhooks::*;
|
||||
#[cfg(feature = "olap")]
|
||||
use super::{
|
||||
admin::*, api_keys::*, apple_pay_certificates_migration, connector_onboarding::*, disputes::*,
|
||||
@ -56,8 +64,6 @@ use super::{
|
||||
use super::{cache::*, health::*};
|
||||
#[cfg(any(feature = "olap", feature = "oltp"))]
|
||||
use super::{configs::*, customers::*, mandates::*, payments::*, refunds::*};
|
||||
#[cfg(feature = "oltp")]
|
||||
use super::{ephemeral_key::*, webhooks::*};
|
||||
#[cfg(feature = "olap")]
|
||||
pub use crate::analytics::opensearch::OpenSearchClient;
|
||||
#[cfg(feature = "olap")]
|
||||
@ -886,7 +892,11 @@ impl Customers {
|
||||
{
|
||||
route = route
|
||||
.service(web::resource("").route(web::post().to(customers_create)))
|
||||
.service(web::resource("/{id}").route(web::put().to(customers_update)))
|
||||
.service(
|
||||
web::resource("/{id}")
|
||||
.route(web::put().to(customers_update))
|
||||
.route(web::post().to(customers_retrieve)),
|
||||
)
|
||||
}
|
||||
#[cfg(all(feature = "oltp", feature = "v2", feature = "payment_methods_v2"))]
|
||||
{
|
||||
@ -1260,7 +1270,11 @@ impl MerchantConnectorAccount {
|
||||
|
||||
pub struct EphemeralKey;
|
||||
|
||||
#[cfg(feature = "oltp")]
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "customer_v2"),
|
||||
feature = "oltp"
|
||||
))]
|
||||
impl EphemeralKey {
|
||||
pub fn server(config: AppState) -> Scope {
|
||||
web::scope("/ephemeral_keys")
|
||||
|
||||
@ -78,6 +78,38 @@ pub async fn customers_retrieve(
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "customer_v2"))]
|
||||
#[instrument(skip_all, fields(flow = ?Flow::CustomersRetrieve))]
|
||||
pub async fn customers_retrieve(
|
||||
state: web::Data<AppState>,
|
||||
req: HttpRequest,
|
||||
path: web::Path<String>,
|
||||
) -> HttpResponse {
|
||||
let flow = Flow::CustomersRetrieve;
|
||||
|
||||
let payload = web::Json(customers::GlobalId::new(path.into_inner())).into_inner();
|
||||
|
||||
let auth = if auth::is_jwt_auth(req.headers()) {
|
||||
Box::new(auth::JWTAuth(Permission::CustomerRead))
|
||||
} else {
|
||||
match auth::is_ephemeral_auth(req.headers()) {
|
||||
Ok(auth) => auth,
|
||||
Err(err) => return api::log_and_return_error_response(err),
|
||||
}
|
||||
};
|
||||
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state,
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req, _| retrieve_customer(state, auth.merchant_account, auth.key_store, req),
|
||||
&*auth,
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
#[instrument(skip_all, fields(flow = ?Flow::CustomersList))]
|
||||
pub async fn customers_list(state: web::Data<AppState>, req: HttpRequest) -> HttpResponse {
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
use router_env::{instrument, tracing, Flow};
|
||||
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
use super::AppState;
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
use crate::{
|
||||
core::{api_locking, payments::helpers},
|
||||
services::{api, authentication as auth},
|
||||
types::api::customers,
|
||||
};
|
||||
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
#[instrument(skip_all, fields(flow = ?Flow::EphemeralKeyCreate))]
|
||||
pub async fn ephemeral_key_create(
|
||||
state: web::Data<AppState>,
|
||||
@ -34,6 +39,7 @@ pub async fn ephemeral_key_create(
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
#[instrument(skip_all, fields(flow = ?Flow::EphemeralKeyDelete))]
|
||||
pub async fn ephemeral_key_delete(
|
||||
state: web::Data<AppState>,
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
use api_models::customers;
|
||||
#[cfg(all(feature = "v2", feature = "customer_v2"))]
|
||||
pub use api_models::customers::GlobalId;
|
||||
pub use api_models::customers::{
|
||||
CustomerDeleteResponse, CustomerId, CustomerRequest, CustomerUpdateRequest, UpdateCustomerId,
|
||||
};
|
||||
@ -58,6 +60,7 @@ impl ForeignFrom<customer::Customer> for CustomerResponse {
|
||||
default_billing_address: None,
|
||||
default_shipping_address: None,
|
||||
default_payment_method_id: cust.default_payment_method_id,
|
||||
id: cust.id,
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user