mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 01:57:45 +08:00 
			
		
		
		
	feat(customer): customer v2 refactor for customer create end point (#5350)
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:
		| @ -4,12 +4,16 @@ pub mod payment_intents; | ||||
| pub mod refunds; | ||||
| pub mod setup_intents; | ||||
| pub mod webhooks; | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| use actix_web::{web, Scope}; | ||||
| pub mod errors; | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| use crate::routes; | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| pub struct StripeApis; | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| impl StripeApis { | ||||
|     pub fn server(state: routes::AppState) -> Scope { | ||||
|         let max_depth = 10; | ||||
|  | ||||
| @ -1,6 +1,8 @@ | ||||
| use actix_web::{web, Scope}; | ||||
|  | ||||
| use super::{customers::*, payment_intents::*, refunds::*, setup_intents::*, webhooks::*}; | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| use super::customers::*; | ||||
| use super::{payment_intents::*, refunds::*, setup_intents::*, webhooks::*}; | ||||
| use crate::routes::{self, mandates, webhooks}; | ||||
|  | ||||
| pub struct PaymentIntents; | ||||
| @ -76,6 +78,7 @@ impl Refunds { | ||||
|  | ||||
| pub struct Customers; | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| impl Customers { | ||||
|     pub fn server(config: routes::AppState) -> Scope { | ||||
|         web::scope("/customers") | ||||
|  | ||||
| @ -1,9 +1,14 @@ | ||||
| pub mod types; | ||||
| #[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 common_utils::id_type; | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| use error_stack::report; | ||||
| #[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 crate::{ | ||||
|     compatibility::{stripe::errors, wrap}, | ||||
|     core::{api_locking, customers, payment_methods::cards}, | ||||
| @ -12,6 +17,7 @@ use crate::{ | ||||
|     types::api::{customers as customer_types, payment_methods}, | ||||
| }; | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| #[instrument(skip_all, fields(flow = ?Flow::CustomersCreate))] | ||||
| pub async fn customer_create( | ||||
|     state: web::Data<routes::AppState>, | ||||
| @ -52,15 +58,15 @@ pub async fn customer_create( | ||||
|     )) | ||||
|     .await | ||||
| } | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| #[instrument(skip_all, fields(flow = ?Flow::CustomersRetrieve))] | ||||
| pub async fn customer_retrieve( | ||||
|     state: web::Data<routes::AppState>, | ||||
|     req: HttpRequest, | ||||
|     path: web::Path<id_type::CustomerId>, | ||||
| ) -> HttpResponse { | ||||
|     let payload = customer_types::CustomerId { | ||||
|         customer_id: path.into_inner(), | ||||
|     }; | ||||
|     let payload = customer_types::CustomerId::new_customer_id_struct(path.into_inner()); | ||||
|  | ||||
|     let flow = Flow::CustomersRetrieve; | ||||
|  | ||||
| @ -86,6 +92,8 @@ pub async fn customer_retrieve( | ||||
|     )) | ||||
|     .await | ||||
| } | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| #[instrument(skip_all, fields(flow = ?Flow::CustomersUpdate))] | ||||
| pub async fn customer_update( | ||||
|     state: web::Data<routes::AppState>, | ||||
| @ -129,15 +137,15 @@ pub async fn customer_update( | ||||
|     )) | ||||
|     .await | ||||
| } | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| #[instrument(skip_all, fields(flow = ?Flow::CustomersDelete))] | ||||
| pub async fn customer_delete( | ||||
|     state: web::Data<routes::AppState>, | ||||
|     req: HttpRequest, | ||||
|     path: web::Path<id_type::CustomerId>, | ||||
| ) -> HttpResponse { | ||||
|     let payload = customer_types::CustomerId { | ||||
|         customer_id: path.into_inner(), | ||||
|     }; | ||||
|     let payload = customer_types::CustomerId::new_customer_id_struct(path.into_inner()); | ||||
|  | ||||
|     let flow = Flow::CustomersDelete; | ||||
|  | ||||
| @ -163,6 +171,8 @@ pub async fn customer_delete( | ||||
|     )) | ||||
|     .await | ||||
| } | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| #[instrument(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] | ||||
| pub async fn list_customer_payment_method_api( | ||||
|     state: web::Data<routes::AppState>, | ||||
|  | ||||
| @ -1,17 +1,17 @@ | ||||
| use std::{convert::From, default::Default}; | ||||
|  | ||||
| use api_models::{payment_methods as api_types, payments}; | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| use common_utils::{crypto::Encryptable, date_time}; | ||||
| use common_utils::{ | ||||
|     crypto::Encryptable, | ||||
|     date_time, id_type, | ||||
|     id_type, | ||||
|     pii::{self, Email}, | ||||
| }; | ||||
| use serde::{Deserialize, Serialize}; | ||||
|  | ||||
| use crate::{ | ||||
|     logger, | ||||
|     types::{api, api::enums as api_enums}, | ||||
| }; | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| use crate::logger; | ||||
| use crate::types::{api, api::enums as api_enums}; | ||||
|  | ||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||
| pub struct Shipping { | ||||
| @ -117,6 +117,7 @@ impl From<StripeAddressDetails> for payments::AddressDetails { | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| impl From<CreateCustomerRequest> for api::CustomerRequest { | ||||
|     fn from(req: CreateCustomerRequest) -> Self { | ||||
|         Self { | ||||
| @ -132,6 +133,7 @@ impl From<CreateCustomerRequest> for api::CustomerRequest { | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| impl From<CustomerUpdateRequest> for api::CustomerRequest { | ||||
|     fn from(req: CustomerUpdateRequest) -> Self { | ||||
|         Self { | ||||
| @ -146,6 +148,7 @@ impl From<CustomerUpdateRequest> for api::CustomerRequest { | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] | ||||
| impl From<api::CustomerResponse> for CreateCustomerResponse { | ||||
|     fn from(cust: api::CustomerResponse) -> Self { | ||||
|         let cust = cust.into_inner(); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Sahkal Poddar
					Sahkal Poddar