Skip to content

Commit

Permalink
refactor(payment_methods): refactored for v2 flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Jul 1, 2024
1 parent ddd9fd6 commit b2c0274
Showing 14 changed files with 525 additions and 20 deletions.
1 change: 1 addition & 0 deletions crates/api_models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ frm = []
olap = []
openapi = ["common_enums/openapi", "olap", "backwards_compatibility", "business_profile_routing", "connector_choice_mca_id", "recon", "dummy_connector", "olap"]
recon = []
v2 = []

[dependencies]
actix-web = { version = "4.5.1", optional = true }
97 changes: 97 additions & 0 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
@@ -826,6 +826,16 @@ impl serde::Serialize for PaymentMethodList {
}
}

#[cfg(not(feature = "v2"))]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethodsListResponse {
/// List of payment methods for customer
pub customer_payment_methods: Vec<CustomerPaymentMethod>,
/// Returns whether a customer id is not tied to a payment intent (only when the request is made against a client secret)
pub is_guest_customer: Option<bool>,
}

#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethodsListResponse {
/// List of payment methods for customer
@@ -860,6 +870,7 @@ pub struct CustomerDefaultPaymentMethodResponse {
pub payment_method_type: Option<api_enums::PaymentMethodType>,
}

#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethod {
/// Token for payment method in temporary card locker which gets refreshed often
@@ -901,6 +912,92 @@ pub struct CustomerPaymentMethod {
#[schema(value_type = Option<Vec<PaymentExperience>>,example = json!(["redirect_to_url"]))]
pub payment_experience: Option<Vec<api_enums::PaymentExperience>>,

/// PaymentMethod Data from locker
pub payment_method_data: Option<PaymentMethodListData>,

/// Masked bank details from PM auth services
#[schema(example = json!({"mask": "0000"}))]
pub bank: Option<MaskedBankDetails>,

/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>,example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,

/// A timestamp (ISO 8601 code) that determines when the customer was created
#[schema(value_type = Option<PrimitiveDateTime>,example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,

/// Surcharge details for this saved card
pub surcharge_details: Option<SurchargeDetailsResponse>,

/// Whether this payment method requires CVV to be collected
#[schema(example = true)]
pub requires_cvv: bool,

/// A timestamp (ISO 8601 code) that determines when the payment method was last used
#[schema(value_type = Option<PrimitiveDateTime>,example = "2024-02-24T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub last_used_at: Option<time::PrimitiveDateTime>,
/// Indicates if the payment method has been set to default or not
#[schema(example = true)]
pub default_payment_method_set: bool,

/// The billing details of the payment method
#[schema(value_type = Option<Address>)]
pub billing: Option<payments::Address>,
}

#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
pub enum PaymentMethodListData {
Card(CardDetailFromLocker),
#[cfg(feature = "payouts")]
Bank(payouts::Bank),
}

#[cfg(not(feature = "v2"))]
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethod {
/// Token for payment method in temporary card locker which gets refreshed often
#[schema(example = "7ebf443f-a050-4067-84e5-e6f6d4800aef")]
pub payment_token: String,
/// The unique identifier of the customer.
#[schema(example = "pm_iouuy468iyuowqs")]
pub payment_method_id: String,

/// The unique identifier of the customer.
#[schema(value_type = String, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
pub customer_id: id_type::CustomerId,

/// The type of payment method use for the payment.
#[schema(value_type = PaymentMethod,example = "card")]
pub payment_method: api_enums::PaymentMethod,

/// This is a sub-category of payment method.
#[schema(value_type = Option<PaymentMethodType>,example = "credit_card")]
pub payment_method_type: Option<api_enums::PaymentMethodType>,

/// The name of the bank/ provider issuing the payment method to the end user
#[schema(example = "Citibank")]
pub payment_method_issuer: Option<String>,

/// A standard code representing the issuer of payment method
#[schema(value_type = Option<PaymentMethodIssuerCode>,example = "jp_applepay")]
pub payment_method_issuer_code: Option<api_enums::PaymentMethodIssuerCode>,

/// Indicates whether the payment method is eligible for recurring payments
#[schema(example = true)]
pub recurring_enabled: bool,

/// Indicates whether the payment method is eligible for installment payments
#[schema(example = true)]
pub installment_payment_enabled: bool,

/// Type of payment experience enabled with the connector
#[schema(value_type = Option<Vec<PaymentExperience>>,example = json!(["redirect_to_url"]))]
pub payment_experience: Option<Vec<api_enums::PaymentExperience>>,

/// Card details from card locker
#[schema(example = json!({"last4": "1142","exp_month": "03","exp_year": "2030"}))]
pub card: Option<CardDetailFromLocker>,
1 change: 1 addition & 0 deletions crates/router/Cargo.toml
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ payouts = ["api_models/payouts", "common_enums/payouts", "hyperswitch_domain_mod
payout_retry = ["payouts"]
recon = ["email", "api_models/recon"]
retry = []
v2 = ["api_models/v2"]

[dependencies]
actix-cors = "0.6.5"
1 change: 1 addition & 0 deletions crates/router/src/compatibility/stripe.rs
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ pub mod errors;
use crate::routes;
pub struct StripeApis;

#[cfg(not(feature = "v2"))]
impl StripeApis {
pub fn server(state: routes::AppState) -> Scope {
let max_depth = 10;
1 change: 1 addition & 0 deletions crates/router/src/compatibility/stripe/app.rs
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ impl Refunds {

pub struct Customers;

#[cfg(not(feature = "v2"))]
impl Customers {
pub fn server(config: routes::AppState) -> Scope {
web::scope("/customers")
1 change: 1 addition & 0 deletions crates/router/src/compatibility/stripe/customers.rs
Original file line number Diff line number Diff line change
@@ -163,6 +163,7 @@ pub async fn customer_delete(
))
.await
}
#[cfg(not(feature = "v2"))]
#[instrument(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))]
pub async fn list_customer_payment_method_api(
state: web::Data<routes::AppState>,
12 changes: 11 additions & 1 deletion crates/router/src/compatibility/stripe/customers/types.rs
Original file line number Diff line number Diff line change
@@ -222,10 +222,20 @@ impl From<api::CustomerPaymentMethodsListResponse> for CustomerPaymentMethodList
// Check this in review
impl From<api_types::CustomerPaymentMethod> for PaymentMethodData {
fn from(item: api_types::CustomerPaymentMethod) -> Self {
#[cfg(not(feature = "v2"))]
let card = item.card.map(From::from);
#[cfg(feature = "v2")]
let card = match item.payment_method_data {
Some(api_types::PaymentMethodListData::Card(card)) => Some(CardDetails::from(card)),
_ => None
};
Self {
#[cfg(not(feature = "v2"))]
id: Some(item.payment_token),
#[cfg(feature = "v2")]
id: item.payment_token,
object: "payment_method",
card: item.card.map(From::from),
card,
created: item.created,
}
}
Loading

0 comments on commit b2c0274

Please sign in to comment.