mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	refactor(router): make compatibility module, types and utilities public (#197)
This commit is contained in:
		| @ -1,2 +1,2 @@ | |||||||
| pub(crate) mod stripe; | pub mod stripe; | ||||||
| pub(crate) mod wrap; | pub mod wrap; | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
| mod app; | pub mod app; | ||||||
| mod customers; | pub mod customers; | ||||||
| mod payment_intents; | pub mod payment_intents; | ||||||
| mod refunds; | pub mod refunds; | ||||||
| mod setup_intents; | pub mod setup_intents; | ||||||
| use actix_web::{web, Scope}; | use actix_web::{web, Scope}; | ||||||
| mod errors; | pub mod errors; | ||||||
|  |  | ||||||
| use crate::routes; | use crate::routes; | ||||||
| pub struct StripeApis; | pub struct StripeApis; | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| mod types; | pub mod types; | ||||||
|  |  | ||||||
| use actix_web::{delete, get, post, web, HttpRequest, HttpResponse}; | use actix_web::{delete, get, post, web, HttpRequest, HttpResponse}; | ||||||
| use error_stack::report; | use error_stack::report; | ||||||
|  | |||||||
| @ -6,53 +6,53 @@ use serde::{Deserialize, Serialize}; | |||||||
| use crate::{pii, types::api}; | use crate::{pii, types::api}; | ||||||
|  |  | ||||||
| #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)] | #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)] | ||||||
| pub(crate) struct CustomerAddress { | pub struct CustomerAddress { | ||||||
|     pub(crate) city: Option<String>, |     pub city: Option<pii::Secret<String>>, | ||||||
|     pub(crate) country: Option<String>, |     pub country: Option<pii::Secret<String>>, | ||||||
|     pub(crate) line1: Option<String>, |     pub line1: Option<pii::Secret<String>>, | ||||||
|     pub(crate) line2: Option<String>, |     pub line2: Option<pii::Secret<String>>, | ||||||
|     pub(crate) postal_code: Option<String>, |     pub postal_code: Option<pii::Secret<String>>, | ||||||
|     pub(crate) state: Option<String>, |     pub state: Option<pii::Secret<String>>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)] | #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)] | ||||||
| pub(crate) struct CreateCustomerRequest { | pub struct CreateCustomerRequest { | ||||||
|     pub(crate) email: Option<masking::Secret<String, pii::Email>>, |     pub email: Option<masking::Secret<String, pii::Email>>, | ||||||
|     pub(crate) invoice_prefix: Option<String>, |     pub invoice_prefix: Option<String>, | ||||||
|     pub(crate) name: Option<String>, |     pub name: Option<String>, | ||||||
|     pub(crate) phone: Option<masking::Secret<String, masking::WithType>>, |     pub phone: Option<masking::Secret<String>>, | ||||||
|     pub(crate) address: Option<CustomerAddress>, |     pub address: Option<CustomerAddress>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)] | #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)] | ||||||
| pub(crate) struct CustomerUpdateRequest { | pub struct CustomerUpdateRequest { | ||||||
|     pub(crate) metadata: Option<String>, |     pub metadata: Option<String>, | ||||||
|     pub(crate) description: Option<String>, |     pub description: Option<String>, | ||||||
|     pub(crate) email: Option<masking::Secret<String, pii::Email>>, |     pub email: Option<masking::Secret<String, pii::Email>>, | ||||||
|     pub(crate) phone: Option<masking::Secret<String, masking::WithType>>, |     pub phone: Option<masking::Secret<String, masking::WithType>>, | ||||||
|     pub(crate) name: Option<String>, |     pub name: Option<String>, | ||||||
|     pub(crate) address: Option<CustomerAddress>, |     pub address: Option<CustomerAddress>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Serialize, PartialEq, Eq)] | #[derive(Default, Serialize, PartialEq, Eq)] | ||||||
| pub(crate) struct CreateCustomerResponse { | pub struct CreateCustomerResponse { | ||||||
|     id: String, |     pub id: String, | ||||||
|     object: String, |     pub object: String, | ||||||
|     created: u64, |     pub created: u64, | ||||||
|     description: Option<String>, |     pub description: Option<String>, | ||||||
|     email: Option<masking::Secret<String, pii::Email>>, |     pub email: Option<masking::Secret<String, pii::Email>>, | ||||||
|     metadata: Option<serde_json::Value>, |     pub metadata: Option<serde_json::Value>, | ||||||
|     name: Option<String>, |     pub name: Option<String>, | ||||||
|     phone: Option<masking::Secret<String, masking::WithType>>, |     pub phone: Option<masking::Secret<String, masking::WithType>>, | ||||||
| } | } | ||||||
|  |  | ||||||
| pub(crate) type CustomerRetrieveResponse = CreateCustomerResponse; | pub type CustomerRetrieveResponse = CreateCustomerResponse; | ||||||
| pub(crate) type CustomerUpdateResponse = CreateCustomerResponse; | pub type CustomerUpdateResponse = CreateCustomerResponse; | ||||||
|  |  | ||||||
| #[derive(Default, Serialize, PartialEq, Eq)] | #[derive(Default, Serialize, PartialEq, Eq)] | ||||||
| pub(crate) struct CustomerDeleteResponse { | pub struct CustomerDeleteResponse { | ||||||
|     pub(crate) id: String, |     pub id: String, | ||||||
|     pub(crate) deleted: bool, |     pub deleted: bool, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<CreateCustomerRequest> for api::CustomerRequest { | impl From<CreateCustomerRequest> for api::CustomerRequest { | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| mod types; | pub mod types; | ||||||
|  |  | ||||||
| use actix_web::{get, post, web, HttpRequest, HttpResponse}; | use actix_web::{get, post, web, HttpRequest, HttpResponse}; | ||||||
| use api_models::payments as payment_types; | use api_models::payments as payment_types; | ||||||
|  | |||||||
| @ -2,14 +2,18 @@ use api_models::{payments, refunds}; | |||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| use serde_json::Value; | use serde_json::Value; | ||||||
|  |  | ||||||
| use crate::{core::errors, types::api::enums as api_enums}; | use crate::{ | ||||||
|  |     core::errors, | ||||||
|  |     pii::{self, PeekInterface}, | ||||||
|  |     types::api::enums as api_enums, | ||||||
|  | }; | ||||||
|  |  | ||||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct StripeBillingDetails { | pub struct StripeBillingDetails { | ||||||
|     pub(crate) address: Option<payments::AddressDetails>, |     pub address: Option<payments::AddressDetails>, | ||||||
|     pub(crate) email: Option<String>, |     pub email: Option<pii::Secret<String, pii::Email>>, | ||||||
|     pub(crate) name: Option<String>, |     pub name: Option<String>, | ||||||
|     pub(crate) phone: Option<String>, |     pub phone: Option<pii::Secret<String>>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<StripeBillingDetails> for payments::Address { | impl From<StripeBillingDetails> for payments::Address { | ||||||
| @ -17,7 +21,7 @@ impl From<StripeBillingDetails> for payments::Address { | |||||||
|         Self { |         Self { | ||||||
|             address: details.address, |             address: details.address, | ||||||
|             phone: Some(payments::PhoneDetails { |             phone: Some(payments::PhoneDetails { | ||||||
|                 number: details.phone.map(masking::Secret::new), |                 number: details.phone, | ||||||
|                 country_code: None, |                 country_code: None, | ||||||
|             }), |             }), | ||||||
|         } |         } | ||||||
| @ -25,16 +29,16 @@ impl From<StripeBillingDetails> for payments::Address { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct StripeCard { | pub struct StripeCard { | ||||||
|     pub(crate) number: String, |     pub number: pii::Secret<String, pii::CardNumber>, | ||||||
|     pub(crate) exp_month: String, |     pub exp_month: pii::Secret<String>, | ||||||
|     pub(crate) exp_year: String, |     pub exp_year: pii::Secret<String>, | ||||||
|     pub(crate) cvc: String, |     pub cvc: pii::Secret<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||||
| #[serde(rename_all = "snake_case")] | #[serde(rename_all = "snake_case")] | ||||||
| pub(crate) enum StripePaymentMethodType { | pub enum StripePaymentMethodType { | ||||||
|     #[default] |     #[default] | ||||||
|     Card, |     Card, | ||||||
| } | } | ||||||
| @ -47,18 +51,18 @@ impl From<StripePaymentMethodType> for api_enums::PaymentMethodType { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct StripePaymentMethodData { | pub struct StripePaymentMethodData { | ||||||
|     #[serde(rename = "type")] |     #[serde(rename = "type")] | ||||||
|     pub(crate) stype: StripePaymentMethodType, |     pub stype: StripePaymentMethodType, | ||||||
|     pub(crate) billing_details: Option<StripeBillingDetails>, |     pub billing_details: Option<StripeBillingDetails>, | ||||||
|     #[serde(flatten)] |     #[serde(flatten)] | ||||||
|     pub(crate) payment_method_details: Option<StripePaymentMethodDetails>, // enum |     pub payment_method_details: Option<StripePaymentMethodDetails>, // enum | ||||||
|     pub(crate) metadata: Option<Value>, |     pub metadata: Option<Value>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | ||||||
| #[serde(rename_all = "snake_case")] | #[serde(rename_all = "snake_case")] | ||||||
| pub(crate) enum StripePaymentMethodDetails { | pub enum StripePaymentMethodDetails { | ||||||
|     Card(StripeCard), |     Card(StripeCard), | ||||||
|     #[default] |     #[default] | ||||||
|     BankTransfer, |     BankTransfer, | ||||||
| @ -67,11 +71,11 @@ pub(crate) enum StripePaymentMethodDetails { | |||||||
| impl From<StripeCard> for payments::CCard { | impl From<StripeCard> for payments::CCard { | ||||||
|     fn from(card: StripeCard) -> Self { |     fn from(card: StripeCard) -> Self { | ||||||
|         Self { |         Self { | ||||||
|             card_number: masking::Secret::new(card.number), |             card_number: card.number, | ||||||
|             card_exp_month: masking::Secret::new(card.exp_month), |             card_exp_month: card.exp_month, | ||||||
|             card_exp_year: masking::Secret::new(card.exp_year), |             card_exp_year: card.exp_year, | ||||||
|             card_holder_name: masking::Secret::new("stripe_cust".to_owned()), |             card_holder_name: masking::Secret::new("stripe_cust".to_owned()), | ||||||
|             card_cvc: masking::Secret::new(card.cvc), |             card_cvc: card.cvc, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -85,12 +89,12 @@ impl From<StripePaymentMethodDetails> for payments::PaymentMethod { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct Shipping { | pub struct Shipping { | ||||||
|     pub(crate) address: Option<payments::AddressDetails>, |     pub address: Option<payments::AddressDetails>, | ||||||
|     pub(crate) name: Option<String>, |     pub name: Option<String>, | ||||||
|     pub(crate) carrier: Option<String>, |     pub carrier: Option<String>, | ||||||
|     pub(crate) phone: Option<String>, |     pub phone: Option<pii::Secret<String>>, | ||||||
|     pub(crate) tracking_number: Option<String>, |     pub tracking_number: Option<pii::Secret<String>>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<Shipping> for payments::Address { | impl From<Shipping> for payments::Address { | ||||||
| @ -98,33 +102,33 @@ impl From<Shipping> for payments::Address { | |||||||
|         Self { |         Self { | ||||||
|             address: details.address, |             address: details.address, | ||||||
|             phone: Some(payments::PhoneDetails { |             phone: Some(payments::PhoneDetails { | ||||||
|                 number: details.phone.map(masking::Secret::new), |                 number: details.phone, | ||||||
|                 country_code: None, |                 country_code: None, | ||||||
|             }), |             }), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct StripePaymentIntentRequest { | pub struct StripePaymentIntentRequest { | ||||||
|     pub(crate) amount: Option<i64>, //amount in cents, hence passed as integer |     pub amount: Option<i64>, //amount in cents, hence passed as integer | ||||||
|     pub(crate) connector: Option<api_enums::Connector>, |     pub connector: Option<api_enums::Connector>, | ||||||
|     pub(crate) currency: Option<String>, |     pub currency: Option<String>, | ||||||
|     #[serde(rename = "amount_to_capture")] |     #[serde(rename = "amount_to_capture")] | ||||||
|     pub(crate) amount_capturable: Option<i64>, |     pub amount_capturable: Option<i64>, | ||||||
|     pub(crate) confirm: Option<bool>, |     pub confirm: Option<bool>, | ||||||
|     pub(crate) capture_method: Option<api_enums::CaptureMethod>, |     pub capture_method: Option<api_enums::CaptureMethod>, | ||||||
|     pub(crate) customer: Option<String>, |     pub customer: Option<String>, | ||||||
|     pub(crate) description: Option<String>, |     pub description: Option<String>, | ||||||
|     pub(crate) payment_method_data: Option<StripePaymentMethodData>, |     pub payment_method_data: Option<StripePaymentMethodData>, | ||||||
|     pub(crate) receipt_email: Option<String>, |     pub receipt_email: Option<pii::Secret<String, pii::Email>>, | ||||||
|     pub(crate) return_url: Option<String>, |     pub return_url: Option<String>, | ||||||
|     pub(crate) setup_future_usage: Option<api_enums::FutureUsage>, |     pub setup_future_usage: Option<api_enums::FutureUsage>, | ||||||
|     pub(crate) shipping: Option<Shipping>, |     pub shipping: Option<Shipping>, | ||||||
|     pub(crate) billing_details: Option<StripeBillingDetails>, |     pub billing_details: Option<StripeBillingDetails>, | ||||||
|     pub(crate) statement_descriptor: Option<String>, |     pub statement_descriptor: Option<String>, | ||||||
|     pub(crate) statement_descriptor_suffix: Option<String>, |     pub statement_descriptor_suffix: Option<String>, | ||||||
|     pub(crate) metadata: Option<Value>, |     pub metadata: Option<Value>, | ||||||
|     pub(crate) client_secret: Option<String>, |     pub client_secret: Option<pii::Secret<String>>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<StripePaymentIntentRequest> for payments::PaymentsRequest { | impl From<StripePaymentIntentRequest> for payments::PaymentsRequest { | ||||||
| @ -137,15 +141,12 @@ impl From<StripePaymentIntentRequest> for payments::PaymentsRequest { | |||||||
|             amount_to_capture: item.amount_capturable, |             amount_to_capture: item.amount_capturable, | ||||||
|             confirm: item.confirm, |             confirm: item.confirm, | ||||||
|             customer_id: item.customer, |             customer_id: item.customer, | ||||||
|             email: item.receipt_email.map(masking::Secret::new), |             email: item.receipt_email, | ||||||
|             name: item |             name: item | ||||||
|                 .billing_details |                 .billing_details | ||||||
|                 .as_ref() |                 .as_ref() | ||||||
|                 .and_then(|b| b.name.as_ref().map(|x| masking::Secret::new(x.to_owned()))), |                 .and_then(|b| b.name.as_ref().map(|x| masking::Secret::new(x.to_owned()))), | ||||||
|             phone: item |             phone: item.shipping.as_ref().and_then(|s| s.phone.clone()), | ||||||
|                 .shipping |  | ||||||
|                 .as_ref() |  | ||||||
|                 .and_then(|s| s.phone.as_ref().map(|x| masking::Secret::new(x.to_owned()))), |  | ||||||
|             description: item.description, |             description: item.description, | ||||||
|             return_url: item.return_url, |             return_url: item.return_url, | ||||||
|             payment_method_data: item.payment_method_data.as_ref().and_then(|pmd| { |             payment_method_data: item.payment_method_data.as_ref().and_then(|pmd| { | ||||||
| @ -168,7 +169,7 @@ impl From<StripePaymentIntentRequest> for payments::PaymentsRequest { | |||||||
|             statement_descriptor_name: item.statement_descriptor, |             statement_descriptor_name: item.statement_descriptor, | ||||||
|             statement_descriptor_suffix: item.statement_descriptor_suffix, |             statement_descriptor_suffix: item.statement_descriptor_suffix, | ||||||
|             metadata: item.metadata, |             metadata: item.metadata, | ||||||
|             client_secret: item.client_secret, |             client_secret: item.client_secret.map(|s| s.peek().clone()), | ||||||
|             ..Default::default() |             ..Default::default() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -176,7 +177,7 @@ impl From<StripePaymentIntentRequest> for payments::PaymentsRequest { | |||||||
|  |  | ||||||
| #[derive(Clone, Default, Eq, PartialEq, Serialize, Deserialize)] | #[derive(Clone, Default, Eq, PartialEq, Serialize, Deserialize)] | ||||||
| #[serde(rename_all = "snake_case")] | #[serde(rename_all = "snake_case")] | ||||||
| pub(crate) enum StripePaymentStatus { | pub enum StripePaymentStatus { | ||||||
|     Succeeded, |     Succeeded, | ||||||
|     Canceled, |     Canceled, | ||||||
|     #[default] |     #[default] | ||||||
| @ -205,7 +206,7 @@ impl From<api_enums::IntentStatus> for StripePaymentStatus { | |||||||
|  |  | ||||||
| #[derive(Debug, Serialize, Deserialize, Copy, Clone)] | #[derive(Debug, Serialize, Deserialize, Copy, Clone)] | ||||||
| #[serde(rename_all = "snake_case")] | #[serde(rename_all = "snake_case")] | ||||||
| pub(crate) enum CancellationReason { | pub enum CancellationReason { | ||||||
|     Duplicate, |     Duplicate, | ||||||
|     Fraudulent, |     Fraudulent, | ||||||
|     RequestedByCustomer, |     RequestedByCustomer, | ||||||
| @ -223,7 +224,7 @@ impl ToString for CancellationReason { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| #[derive(Debug, Deserialize, Serialize, Copy, Clone)] | #[derive(Debug, Deserialize, Serialize, Copy, Clone)] | ||||||
| pub(crate) struct StripePaymentCancelRequest { | pub struct StripePaymentCancelRequest { | ||||||
|     cancellation_reason: Option<CancellationReason>, |     cancellation_reason: Option<CancellationReason>, | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -237,25 +238,25 @@ impl From<StripePaymentCancelRequest> for payments::PaymentsCancelRequest { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct StripeCaptureRequest { | pub struct StripeCaptureRequest { | ||||||
|     pub(crate) amount_to_capture: Option<i64>, |     pub amount_to_capture: Option<i64>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Eq, PartialEq, Serialize)] | #[derive(Default, Eq, PartialEq, Serialize)] | ||||||
| pub(crate) struct StripePaymentIntentResponse { | pub struct StripePaymentIntentResponse { | ||||||
|     pub(crate) id: Option<String>, |     pub id: Option<String>, | ||||||
|     pub(crate) object: String, |     pub object: String, | ||||||
|     pub(crate) amount: i64, |     pub amount: i64, | ||||||
|     pub(crate) amount_received: Option<i64>, |     pub amount_received: Option<i64>, | ||||||
|     pub(crate) amount_capturable: Option<i64>, |     pub amount_capturable: Option<i64>, | ||||||
|     pub(crate) currency: String, |     pub currency: String, | ||||||
|     pub(crate) status: StripePaymentStatus, |     pub status: StripePaymentStatus, | ||||||
|     pub(crate) client_secret: Option<masking::Secret<String>>, |     pub client_secret: Option<masking::Secret<String>>, | ||||||
|     #[serde(with = "common_utils::custom_serde::iso8601::option")] |     #[serde(with = "common_utils::custom_serde::iso8601::option")] | ||||||
|     pub(crate) created: Option<time::PrimitiveDateTime>, |     pub created: Option<time::PrimitiveDateTime>, | ||||||
|     pub(crate) customer: Option<String>, |     pub customer: Option<String>, | ||||||
|     pub(crate) refunds: Option<Vec<refunds::RefundResponse>>, |     pub refunds: Option<Vec<refunds::RefundResponse>>, | ||||||
|     pub(crate) mandate_id: Option<String>, |     pub mandate_id: Option<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<payments::PaymentsResponse> for StripePaymentIntentResponse { | impl From<payments::PaymentsResponse> for StripePaymentIntentResponse { | ||||||
| @ -334,11 +335,11 @@ fn from_timestamp_to_datetime( | |||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Eq, PartialEq, Serialize)] | #[derive(Default, Eq, PartialEq, Serialize)] | ||||||
| pub(crate) struct StripePaymentIntentListResponse { | pub struct StripePaymentIntentListResponse { | ||||||
|     pub(crate) object: String, |     pub object: String, | ||||||
|     pub(crate) url: String, |     pub url: String, | ||||||
|     pub(crate) has_more: bool, |     pub has_more: bool, | ||||||
|     pub(crate) data: Vec<StripePaymentIntentResponse>, |     pub data: Vec<StripePaymentIntentResponse>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<payments::PaymentListResponse> for StripePaymentIntentListResponse { | impl From<payments::PaymentListResponse> for StripePaymentIntentListResponse { | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| mod types; | pub mod types; | ||||||
|  |  | ||||||
| use actix_web::{get, post, web, HttpRequest, HttpResponse}; | use actix_web::{get, post, web, HttpRequest, HttpResponse}; | ||||||
| use router_env::{tracing, tracing::instrument}; | use router_env::{tracing, tracing::instrument}; | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| mod types; | pub mod types; | ||||||
|  |  | ||||||
| use actix_web::{get, post, web, HttpRequest, HttpResponse}; | use actix_web::{get, post, web, HttpRequest, HttpResponse}; | ||||||
| use api_models::payments as payment_types; | use api_models::payments as payment_types; | ||||||
|  | |||||||
| @ -5,15 +5,16 @@ use serde_json::Value; | |||||||
|  |  | ||||||
| use crate::{ | use crate::{ | ||||||
|     core::errors, |     core::errors, | ||||||
|  |     pii::{self, PeekInterface}, | ||||||
|     types::api::{self as api_types, enums as api_enums}, |     types::api::{self as api_types, enums as api_enums}, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct StripeBillingDetails { | pub struct StripeBillingDetails { | ||||||
|     pub(crate) address: Option<payments::AddressDetails>, |     pub address: Option<payments::AddressDetails>, | ||||||
|     pub(crate) email: Option<String>, |     pub email: Option<pii::Secret<String, pii::Email>>, | ||||||
|     pub(crate) name: Option<String>, |     pub name: Option<String>, | ||||||
|     pub(crate) phone: Option<String>, |     pub phone: Option<pii::Secret<String>>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<StripeBillingDetails> for payments::Address { | impl From<StripeBillingDetails> for payments::Address { | ||||||
| @ -21,7 +22,7 @@ impl From<StripeBillingDetails> for payments::Address { | |||||||
|         Self { |         Self { | ||||||
|             address: details.address, |             address: details.address, | ||||||
|             phone: Some(payments::PhoneDetails { |             phone: Some(payments::PhoneDetails { | ||||||
|                 number: details.phone.map(masking::Secret::new), |                 number: details.phone, | ||||||
|                 country_code: None, |                 country_code: None, | ||||||
|             }), |             }), | ||||||
|         } |         } | ||||||
| @ -29,16 +30,16 @@ impl From<StripeBillingDetails> for payments::Address { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct StripeCard { | pub struct StripeCard { | ||||||
|     pub(crate) number: String, |     pub number: pii::Secret<String, pii::CardNumber>, | ||||||
|     pub(crate) exp_month: String, |     pub exp_month: pii::Secret<String>, | ||||||
|     pub(crate) exp_year: String, |     pub exp_year: pii::Secret<String>, | ||||||
|     pub(crate) cvc: String, |     pub cvc: pii::Secret<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||||
| #[serde(rename_all = "snake_case")] | #[serde(rename_all = "snake_case")] | ||||||
| pub(crate) enum StripePaymentMethodType { | pub enum StripePaymentMethodType { | ||||||
|     #[default] |     #[default] | ||||||
|     Card, |     Card, | ||||||
| } | } | ||||||
| @ -51,18 +52,18 @@ impl From<StripePaymentMethodType> for api_enums::PaymentMethodType { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct StripePaymentMethodData { | pub struct StripePaymentMethodData { | ||||||
|     #[serde(rename = "type")] |     #[serde(rename = "type")] | ||||||
|     pub(crate) stype: StripePaymentMethodType, |     pub stype: StripePaymentMethodType, | ||||||
|     pub(crate) billing_details: Option<StripeBillingDetails>, |     pub billing_details: Option<StripeBillingDetails>, | ||||||
|     #[serde(flatten)] |     #[serde(flatten)] | ||||||
|     pub(crate) payment_method_details: Option<StripePaymentMethodDetails>, // enum |     pub payment_method_details: Option<StripePaymentMethodDetails>, // enum | ||||||
|     pub(crate) metadata: Option<Value>, |     pub metadata: Option<Value>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | ||||||
| #[serde(rename_all = "snake_case")] | #[serde(rename_all = "snake_case")] | ||||||
| pub(crate) enum StripePaymentMethodDetails { | pub enum StripePaymentMethodDetails { | ||||||
|     Card(StripeCard), |     Card(StripeCard), | ||||||
|     #[default] |     #[default] | ||||||
|     BankTransfer, |     BankTransfer, | ||||||
| @ -71,11 +72,11 @@ pub(crate) enum StripePaymentMethodDetails { | |||||||
| impl From<StripeCard> for payments::CCard { | impl From<StripeCard> for payments::CCard { | ||||||
|     fn from(card: StripeCard) -> Self { |     fn from(card: StripeCard) -> Self { | ||||||
|         Self { |         Self { | ||||||
|             card_number: masking::Secret::new(card.number), |             card_number: card.number, | ||||||
|             card_exp_month: masking::Secret::new(card.exp_month), |             card_exp_month: card.exp_month, | ||||||
|             card_exp_year: masking::Secret::new(card.exp_year), |             card_exp_year: card.exp_year, | ||||||
|             card_holder_name: masking::Secret::new("stripe_cust".to_owned()), |             card_holder_name: masking::Secret::new("stripe_cust".to_owned()), | ||||||
|             card_cvc: masking::Secret::new(card.cvc), |             card_cvc: card.cvc, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -89,12 +90,12 @@ impl From<StripePaymentMethodDetails> for payments::PaymentMethod { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, Serialize, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct Shipping { | pub struct Shipping { | ||||||
|     pub(crate) address: Option<payments::AddressDetails>, |     pub address: Option<payments::AddressDetails>, | ||||||
|     pub(crate) name: Option<String>, |     pub name: Option<String>, | ||||||
|     pub(crate) carrier: Option<String>, |     pub carrier: Option<String>, | ||||||
|     pub(crate) phone: Option<String>, |     pub phone: Option<pii::Secret<String>>, | ||||||
|     pub(crate) tracking_number: Option<String>, |     pub tracking_number: Option<pii::Secret<String>>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<Shipping> for payments::Address { | impl From<Shipping> for payments::Address { | ||||||
| @ -102,27 +103,27 @@ impl From<Shipping> for payments::Address { | |||||||
|         Self { |         Self { | ||||||
|             address: details.address, |             address: details.address, | ||||||
|             phone: Some(payments::PhoneDetails { |             phone: Some(payments::PhoneDetails { | ||||||
|                 number: details.phone.map(masking::Secret::new), |                 number: details.phone, | ||||||
|                 country_code: None, |                 country_code: None, | ||||||
|             }), |             }), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | #[derive(Default, PartialEq, Eq, Deserialize, Clone)] | ||||||
| pub(crate) struct StripeSetupIntentRequest { | pub struct StripeSetupIntentRequest { | ||||||
|     pub(crate) confirm: Option<bool>, |     pub confirm: Option<bool>, | ||||||
|     pub(crate) customer: Option<String>, |     pub customer: Option<String>, | ||||||
|     pub(crate) description: Option<String>, |     pub description: Option<String>, | ||||||
|     pub(crate) payment_method_data: Option<StripePaymentMethodData>, |     pub payment_method_data: Option<StripePaymentMethodData>, | ||||||
|     pub(crate) receipt_email: Option<String>, |     pub receipt_email: Option<pii::Secret<String, pii::Email>>, | ||||||
|     pub(crate) return_url: Option<String>, |     pub return_url: Option<String>, | ||||||
|     pub(crate) setup_future_usage: Option<api_enums::FutureUsage>, |     pub setup_future_usage: Option<api_enums::FutureUsage>, | ||||||
|     pub(crate) shipping: Option<Shipping>, |     pub shipping: Option<Shipping>, | ||||||
|     pub(crate) billing_details: Option<StripeBillingDetails>, |     pub billing_details: Option<StripeBillingDetails>, | ||||||
|     pub(crate) statement_descriptor: Option<String>, |     pub statement_descriptor: Option<String>, | ||||||
|     pub(crate) statement_descriptor_suffix: Option<String>, |     pub statement_descriptor_suffix: Option<String>, | ||||||
|     pub(crate) metadata: Option<Value>, |     pub metadata: Option<Value>, | ||||||
|     pub(crate) client_secret: Option<String>, |     pub client_secret: Option<pii::Secret<String>>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<StripeSetupIntentRequest> for payments::PaymentsRequest { | impl From<StripeSetupIntentRequest> for payments::PaymentsRequest { | ||||||
| @ -134,15 +135,12 @@ impl From<StripeSetupIntentRequest> for payments::PaymentsRequest { | |||||||
|             amount_to_capture: None, |             amount_to_capture: None, | ||||||
|             confirm: item.confirm, |             confirm: item.confirm, | ||||||
|             customer_id: item.customer, |             customer_id: item.customer, | ||||||
|             email: item.receipt_email.map(masking::Secret::new), |             email: item.receipt_email, | ||||||
|             name: item |             name: item | ||||||
|                 .billing_details |                 .billing_details | ||||||
|                 .as_ref() |                 .as_ref() | ||||||
|                 .and_then(|b| b.name.as_ref().map(|x| masking::Secret::new(x.to_owned()))), |                 .and_then(|b| b.name.as_ref().map(|x| masking::Secret::new(x.to_owned()))), | ||||||
|             phone: item |             phone: item.shipping.as_ref().and_then(|s| s.phone.clone()), | ||||||
|                 .shipping |  | ||||||
|                 .as_ref() |  | ||||||
|                 .and_then(|s| s.phone.as_ref().map(|x| masking::Secret::new(x.to_owned()))), |  | ||||||
|             description: item.description, |             description: item.description, | ||||||
|             return_url: item.return_url, |             return_url: item.return_url, | ||||||
|             payment_method_data: item.payment_method_data.as_ref().and_then(|pmd| { |             payment_method_data: item.payment_method_data.as_ref().and_then(|pmd| { | ||||||
| @ -165,7 +163,7 @@ impl From<StripeSetupIntentRequest> for payments::PaymentsRequest { | |||||||
|             statement_descriptor_name: item.statement_descriptor, |             statement_descriptor_name: item.statement_descriptor, | ||||||
|             statement_descriptor_suffix: item.statement_descriptor_suffix, |             statement_descriptor_suffix: item.statement_descriptor_suffix, | ||||||
|             metadata: item.metadata, |             metadata: item.metadata, | ||||||
|             client_secret: item.client_secret, |             client_secret: item.client_secret.map(|s| s.peek().clone()), | ||||||
|             ..Default::default() |             ..Default::default() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -173,7 +171,7 @@ impl From<StripeSetupIntentRequest> for payments::PaymentsRequest { | |||||||
|  |  | ||||||
| #[derive(Clone, Default, Eq, PartialEq, Serialize, Deserialize)] | #[derive(Clone, Default, Eq, PartialEq, Serialize, Deserialize)] | ||||||
| #[serde(rename_all = "snake_case")] | #[serde(rename_all = "snake_case")] | ||||||
| pub(crate) enum StripeSetupStatus { | pub enum StripeSetupStatus { | ||||||
|     Succeeded, |     Succeeded, | ||||||
|     Canceled, |     Canceled, | ||||||
|     #[default] |     #[default] | ||||||
| @ -204,7 +202,7 @@ impl From<api_enums::IntentStatus> for StripeSetupStatus { | |||||||
|  |  | ||||||
| #[derive(Debug, Serialize, Deserialize, Copy, Clone)] | #[derive(Debug, Serialize, Deserialize, Copy, Clone)] | ||||||
| #[serde(rename_all = "snake_case")] | #[serde(rename_all = "snake_case")] | ||||||
| pub(crate) enum CancellationReason { | pub enum CancellationReason { | ||||||
|     Duplicate, |     Duplicate, | ||||||
|     Fraudulent, |     Fraudulent, | ||||||
|     RequestedByCustomer, |     RequestedByCustomer, | ||||||
| @ -223,7 +221,7 @@ impl ToString for CancellationReason { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, Deserialize, Serialize, Copy, Clone)] | #[derive(Debug, Deserialize, Serialize, Copy, Clone)] | ||||||
| pub(crate) struct StripePaymentCancelRequest { | pub struct StripePaymentCancelRequest { | ||||||
|     cancellation_reason: Option<CancellationReason>, |     cancellation_reason: Option<CancellationReason>, | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -236,16 +234,16 @@ impl From<StripePaymentCancelRequest> for payments::PaymentsCancelRequest { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| #[derive(Default, Eq, PartialEq, Serialize)] | #[derive(Default, Eq, PartialEq, Serialize)] | ||||||
| pub(crate) struct StripeSetupIntentResponse { | pub struct StripeSetupIntentResponse { | ||||||
|     pub(crate) id: Option<String>, |     pub id: Option<String>, | ||||||
|     pub(crate) object: String, |     pub object: String, | ||||||
|     pub(crate) status: StripeSetupStatus, |     pub status: StripeSetupStatus, | ||||||
|     pub(crate) client_secret: Option<masking::Secret<String>>, |     pub client_secret: Option<masking::Secret<String>>, | ||||||
|     #[serde(with = "common_utils::custom_serde::iso8601::option")] |     #[serde(with = "common_utils::custom_serde::iso8601::option")] | ||||||
|     pub(crate) created: Option<time::PrimitiveDateTime>, |     pub created: Option<time::PrimitiveDateTime>, | ||||||
|     pub(crate) customer: Option<String>, |     pub customer: Option<String>, | ||||||
|     pub(crate) refunds: Option<Vec<refunds::RefundResponse>>, |     pub refunds: Option<Vec<refunds::RefundResponse>>, | ||||||
|     pub(crate) mandate_id: Option<String>, |     pub mandate_id: Option<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<payments::PaymentsResponse> for StripeSetupIntentResponse { | impl From<payments::PaymentsResponse> for StripeSetupIntentResponse { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 ItsMeShashank
					ItsMeShashank