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:
Narayan Bhat
2024-05-30 16:19:10 +05:30
committed by GitHub
parent f192fa3866
commit 93d61d1053
106 changed files with 1150 additions and 490 deletions

View File

@ -1,5 +1,6 @@
pub mod types;
use actix_web::{web, HttpRequest, HttpResponse};
use common_utils::id_type;
use error_stack::report;
use router_env::{instrument, tracing, Flow};
@ -55,7 +56,7 @@ pub async fn customer_create(
pub async fn customer_retrieve(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<String>,
path: web::Path<id_type::CustomerId>,
) -> HttpResponse {
let payload = customer_types::CustomerId {
customer_id: path.into_inner(),
@ -90,7 +91,7 @@ pub async fn customer_update(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
req: HttpRequest,
path: web::Path<String>,
path: web::Path<id_type::CustomerId>,
form_payload: web::Bytes,
) -> HttpResponse {
let payload: types::CustomerUpdateRequest = match qs_config.deserialize_bytes(&form_payload) {
@ -102,7 +103,7 @@ pub async fn customer_update(
let customer_id = path.into_inner();
let mut cust_update_req: customer_types::CustomerRequest = payload.into();
cust_update_req.customer_id = customer_id;
cust_update_req.customer_id = Some(customer_id);
let flow = Flow::CustomersUpdate;
@ -132,7 +133,7 @@ pub async fn customer_update(
pub async fn customer_delete(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<String>,
path: web::Path<id_type::CustomerId>,
) -> HttpResponse {
let payload = customer_types::CustomerId {
customer_id: path.into_inner(),
@ -166,7 +167,7 @@ pub async fn customer_delete(
pub async fn list_customer_payment_method_api(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<String>,
path: web::Path<id_type::CustomerId>,
json_payload: web::Query<payment_methods::PaymentMethodListRequest>,
) -> HttpResponse {
let payload = json_payload.into_inner();
@ -193,7 +194,7 @@ pub async fn list_customer_payment_method_api(
auth.merchant_account,
auth.key_store,
Some(req),
Some(customer_id.as_str()),
Some(&customer_id),
)
},
&auth::ApiKeyAuth,

View File

@ -3,7 +3,7 @@ use std::{convert::From, default::Default};
use api_models::{payment_methods as api_types, payments};
use common_utils::{
crypto::Encryptable,
date_time,
date_time, id_type,
pii::{self, Email},
};
use serde::{Deserialize, Serialize};
@ -80,9 +80,9 @@ pub struct CustomerUpdateRequest {
pub tax_exempt: Option<String>, // not used
}
#[derive(Default, Serialize, PartialEq, Eq)]
#[derive(Serialize, PartialEq, Eq)]
pub struct CreateCustomerResponse {
pub id: String,
pub id: id_type::CustomerId,
pub object: String,
pub created: u64,
pub description: Option<String>,
@ -95,9 +95,9 @@ pub struct CreateCustomerResponse {
pub type CustomerRetrieveResponse = CreateCustomerResponse;
pub type CustomerUpdateResponse = CreateCustomerResponse;
#[derive(Default, Serialize, PartialEq, Eq)]
#[derive(Serialize, PartialEq, Eq)]
pub struct CustomerDeleteResponse {
pub id: String,
pub id: id_type::CustomerId,
pub deleted: bool,
}
@ -120,7 +120,7 @@ impl From<StripeAddressDetails> for payments::AddressDetails {
impl From<CreateCustomerRequest> for api::CustomerRequest {
fn from(req: CreateCustomerRequest) -> Self {
Self {
customer_id: api_models::customers::generate_customer_id(),
customer_id: Some(common_utils::generate_customer_id_of_default_length()),
name: req.name,
phone: req.phone,
email: req.email,

View File

@ -5,6 +5,7 @@ use common_utils::{
crypto::Encryptable,
date_time,
ext_traits::StringExt,
id_type,
pii::{IpAddress, SecretSerdeValue, UpiVpaMaskingStrategy},
types::MinorUnit,
};
@ -246,7 +247,7 @@ pub struct StripePaymentIntentRequest {
pub amount_capturable: Option<i64>,
pub confirm: Option<bool>,
pub capture_method: Option<api_enums::CaptureMethod>,
pub customer: Option<String>,
pub customer: Option<id_type::CustomerId>,
pub description: Option<String>,
pub payment_method_data: Option<StripePaymentMethodData>,
pub receipt_email: Option<Email>,
@ -466,7 +467,7 @@ pub struct StripePaymentIntentResponse {
pub status: StripePaymentStatus,
pub client_secret: Option<masking::Secret<String>>,
pub created: Option<i64>,
pub customer: Option<String>,
pub customer: Option<id_type::CustomerId>,
pub refunds: Option<Vec<stripe_refunds::StripeRefundResponse>>,
pub mandate: Option<String>,
pub metadata: Option<SecretSerdeValue>,
@ -609,7 +610,7 @@ impl Charges {
#[derive(Clone, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct StripePaymentListConstraints {
pub customer: Option<String>,
pub customer: Option<id_type::CustomerId>,
pub starting_after: Option<String>,
pub ending_before: Option<String>,
#[serde(default = "default_limit")]

View File

@ -1,7 +1,7 @@
use std::str::FromStr;
use api_models::payments;
use common_utils::{date_time, ext_traits::StringExt, pii as secret};
use common_utils::{date_time, ext_traits::StringExt, id_type, pii as secret};
use error_stack::ResultExt;
use router_env::logger;
use serde::{Deserialize, Serialize};
@ -152,7 +152,7 @@ impl From<Shipping> for payments::Address {
#[derive(Default, Deserialize, Clone)]
pub struct StripeSetupIntentRequest {
pub confirm: Option<bool>,
pub customer: Option<String>,
pub customer: Option<id_type::CustomerId>,
pub connector: Option<Vec<api_enums::RoutableConnectors>>,
pub description: Option<String>,
pub currency: Option<String>,
@ -461,7 +461,7 @@ pub struct StripeSetupIntentResponse {
pub metadata: Option<secret::SecretSerdeValue>,
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
pub customer: Option<String>,
pub customer: Option<id_type::CustomerId>,
pub refunds: Option<Vec<stripe_refunds::StripeRefundResponse>>,
pub mandate_id: Option<String>,
pub next_action: Option<StripeNextAction>,
@ -538,7 +538,7 @@ impl From<payments::PaymentsResponse> for StripeSetupIntentResponse {
#[derive(Clone, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct StripePaymentListConstraints {
pub customer: Option<String>,
pub customer: Option<id_type::CustomerId>,
pub starting_after: Option<String>,
pub ending_before: Option<String>,
#[serde(default = "default_limit")]