mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	feat: add a domain type for customer_id (#4705)
				
					
				
			Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
		| @ -1,4 +1,4 @@ | ||||
| use common_utils::{consts, crypto, custom_serde, pii}; | ||||
| use common_utils::{crypto, custom_serde, id_type, pii}; | ||||
| use masking::Secret; | ||||
| use serde::{Deserialize, Serialize}; | ||||
| use utoipa::ToSchema; | ||||
| @ -9,9 +9,8 @@ use crate::payments; | ||||
| #[derive(Debug, Default, Clone, Deserialize, Serialize, ToSchema)] | ||||
| pub struct CustomerRequest { | ||||
|     /// The identifier for the customer object. If not provided the customer ID will be autogenerated. | ||||
|     #[schema(max_length = 255, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")] | ||||
|     #[serde(default = "generate_customer_id")] | ||||
|     pub customer_id: String, | ||||
|     #[schema(value_type = Option<String>, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")] | ||||
|     pub customer_id: Option<id_type::CustomerId>, | ||||
|     /// The identifier for the Merchant Account | ||||
|     #[schema(max_length = 255, example = "y3oqhf46pyzuxjbcn2giaqnb44")] | ||||
|     #[serde(default = "unknown_merchant", skip)] | ||||
| @ -43,9 +42,9 @@ pub struct CustomerRequest { | ||||
|  | ||||
| #[derive(Debug, Clone, Serialize, ToSchema)] | ||||
| pub struct CustomerResponse { | ||||
|     /// The identifier for the customer object. If not provided the customer ID will be autogenerated. | ||||
|     #[schema(max_length = 255, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")] | ||||
|     pub customer_id: String, | ||||
|     /// The identifier for the customer object | ||||
|     #[schema(value_type = String, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")] | ||||
|     pub customer_id: id_type::CustomerId, | ||||
|     /// The customer's name | ||||
|     #[schema(max_length = 255, value_type = Option<String>, example = "Jon Test")] | ||||
|     pub name: crypto::OptionalEncryptableName, | ||||
| @ -78,16 +77,16 @@ pub struct CustomerResponse { | ||||
|     pub default_payment_method_id: Option<String>, | ||||
| } | ||||
|  | ||||
| #[derive(Default, Clone, Debug, Deserialize, Serialize)] | ||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||||
| pub struct CustomerId { | ||||
|     pub customer_id: String, | ||||
|     pub customer_id: id_type::CustomerId, | ||||
| } | ||||
|  | ||||
| #[derive(Default, Debug, Deserialize, Serialize, ToSchema)] | ||||
| #[derive(Debug, Deserialize, Serialize, ToSchema)] | ||||
| pub struct CustomerDeleteResponse { | ||||
|     /// The identifier for the customer object | ||||
|     #[schema(max_length = 255, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")] | ||||
|     pub customer_id: String, | ||||
|     #[schema(value_type = String, max_length = 255, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")] | ||||
|     pub customer_id: id_type::CustomerId, | ||||
|     /// Whether customer was deleted or not | ||||
|     #[schema(example = false)] | ||||
|     pub customer_deleted: bool, | ||||
| @ -99,10 +98,6 @@ pub struct CustomerDeleteResponse { | ||||
|     pub payment_methods_deleted: bool, | ||||
| } | ||||
|  | ||||
| pub fn generate_customer_id() -> String { | ||||
|     common_utils::generate_id(consts::ID_LENGTH, "cus") | ||||
| } | ||||
|  | ||||
| fn unknown_merchant() -> String { | ||||
|     String::from("merchant_unknown") | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Narayan Bhat
					Narayan Bhat