Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Refactor customer payment method list for v2 #4856

Merged
merged 44 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b88e259
refactor(core): Refactor customer pml for v2
Sarthak1799 Jun 3, 2024
f2d7e05
Merge branch 'main' of github.com:juspay/hyperswitch into refactor-cu…
Sarthak1799 Jun 5, 2024
cd89296
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Jun 5, 2024
a580b35
fix(payment_methods): Fixed clippy errors
Sarthak1799 Jun 5, 2024
4eae216
fix(payment_methods): Fixed clippy errors
Sarthak1799 Jun 5, 2024
51c7d12
fix(payment_methods): Resolved comments
Sarthak1799 Jun 10, 2024
c71e21a
Merge branch 'main' of github.com:juspay/hyperswitch into refactor-cu…
Sarthak1799 Jun 20, 2024
bc62440
fix(payment_methods): Fixed errors
Sarthak1799 Jun 20, 2024
ddd9fd6
fix(payment_methods): Resolved comments
Sarthak1799 Jun 26, 2024
b2c0274
refactor(payment_methods): refactored for v2 flag
Sarthak1799 Jul 1, 2024
2ac2fa9
chore: run formatter
hyperswitch-bot[bot] Jul 1, 2024
d0e505a
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Jul 1, 2024
d19ca37
fix(payment_methods): Fixed errors
Sarthak1799 Jul 2, 2024
d98b862
Merge branch 'main' of github.com:juspay/hyperswitch into refactor-cu…
Sarthak1799 Jul 2, 2024
47874b3
fix(payment_methods): Fixed errors
Sarthak1799 Jul 2, 2024
7a918cd
fix(payment_methods): Fixed errors
Sarthak1799 Jul 2, 2024
a921a06
fix(payment_methods): Fixed errors
Sarthak1799 Jul 2, 2024
dbafd56
fix(payment_methods): Fixed errors
Sarthak1799 Jul 2, 2024
ff414c7
refactor(payment_methods): Refactored a bit
Sarthak1799 Jul 3, 2024
f892342
Merge branch 'main' into refactor-customer-pm-list
Sarthak1799 Jul 3, 2024
f991fca
fix(payment_methods): Fixed errors
Sarthak1799 Jul 3, 2024
c4ffddd
fix(payment_methods): Fixed errors
Sarthak1799 Jul 3, 2024
658a1a2
Merge branch 'main' of github.com:juspay/hyperswitch into refactor-cu…
Sarthak1799 Jul 19, 2024
cf8db57
Merge branch 'main' of github.com:juspay/hyperswitch into refactor-cu…
Sarthak1799 Jul 22, 2024
761dca6
refactor(payment_methods): Refactored
Sarthak1799 Jul 22, 2024
62c91b9
chore: run formatter
hyperswitch-bot[bot] Jul 22, 2024
a681bed
Merge branch 'main' of github.com:juspay/hyperswitch into refactor-cu…
Sarthak1799 Jul 23, 2024
64fc9a4
fix(payment_methods): Fixed errors
Sarthak1799 Jul 23, 2024
8595c68
chore: run formatter
hyperswitch-bot[bot] Jul 23, 2024
4a971ea
fix(payment_methods): Fixed errors
Sarthak1799 Jul 23, 2024
75486a1
chore: run formatter
hyperswitch-bot[bot] Jul 23, 2024
1efda3c
fix(payment_methods): Fixed errors
Sarthak1799 Jul 23, 2024
2049014
fix(payment_methods): Fixed errors
Sarthak1799 Jul 23, 2024
137091b
fix(payment_methods): Resolved comments
Sarthak1799 Jul 25, 2024
9160090
Merge branch 'main' of github.com:juspay/hyperswitch into refactor-cu…
Sarthak1799 Jul 25, 2024
185bc62
chore: run formatter
hyperswitch-bot[bot] Jul 25, 2024
69a2b80
fix(payment_methods): Fixed errors
Sarthak1799 Jul 25, 2024
730b094
Merge branch 'main' into refactor-customer-pm-list
Sarthak1799 Jul 26, 2024
967492e
Merge branch 'main' into refactor-customer-pm-list
Sarthak1799 Jul 26, 2024
298e69a
Merge branch 'main' into refactor-customer-pm-list
Sarthak1799 Jul 27, 2024
5328c9f
fix(payment_methods): Fixed errors
Sarthak1799 Jul 27, 2024
300b09a
Merge branch 'main' of github.com:juspay/hyperswitch into refactor-cu…
Sarthak1799 Jul 30, 2024
e838c6e
Merge branch 'main' of github.com:juspay/hyperswitch into refactor-cu…
Sarthak1799 Aug 1, 2024
29945bf
Merge branch 'main' of github.com:juspay/hyperswitch into refactor-cu…
Sarthak1799 Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/api_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ customer_v2 = []
merchant_account_v2 = []
merchant_connector_account_v2 = []
payment_v2 = []
payment_methods_v2 = []
routing_v2 = []

[dependencies]
Expand Down
17 changes: 12 additions & 5 deletions crates/api_models/src/events/payment.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use common_utils::events::{ApiEventMetric, ApiEventsType};

#[cfg(all(
any(feature = "v2", feature = "v1"),
not(feature = "payment_methods_v2")
))]
use crate::payment_methods::CustomerPaymentMethodsListResponse;
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
use crate::payment_methods::CustomerPaymentMethodsListResponse;
use crate::{
payment_methods::{
CustomerDefaultPaymentMethodResponse, CustomerPaymentMethodsListResponse,
DefaultPaymentMethod, ListCountriesCurrenciesRequest, ListCountriesCurrenciesResponse,
PaymentMethodCollectLinkRenderRequest, PaymentMethodCollectLinkRequest,
PaymentMethodCollectLinkResponse, PaymentMethodDeleteResponse, PaymentMethodListRequest,
PaymentMethodListResponse, PaymentMethodResponse, PaymentMethodUpdate,
CustomerDefaultPaymentMethodResponse, DefaultPaymentMethod, ListCountriesCurrenciesRequest,
ListCountriesCurrenciesResponse, PaymentMethodCollectLinkRenderRequest,
PaymentMethodCollectLinkRequest, PaymentMethodCollectLinkResponse,
PaymentMethodDeleteResponse, PaymentMethodListRequest, PaymentMethodListResponse,
PaymentMethodResponse, PaymentMethodUpdate,
},
payments::{
ExtendedCardInfoResponse, PaymentIdType, PaymentListConstraints,
Expand Down
104 changes: 104 additions & 0 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,19 @@ impl serde::Serialize for PaymentMethodList {
}
}

#[cfg(all(
any(feature = "v2", feature = "v1"),
not(feature = "payment_methods_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(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethodsListResponse {
/// List of payment methods for customer
Expand Down Expand Up @@ -1028,6 +1041,97 @@ pub struct CustomerDefaultPaymentMethodResponse {
pub payment_method_type: Option<api_enums::PaymentMethodType>,
}

#[cfg(all(feature = "v2", feature = "payment_methods_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: Option<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>>,

/// 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(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum PaymentMethodListData {
Card(CardDetailFromLocker),
#[cfg(feature = "payouts")]
Bank(payouts::Bank),
}

#[cfg(all(
any(feature = "v2", feature = "v1"),
not(feature = "payment_methods_v2")
))]
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
pub struct CustomerPaymentMethod {
/// Token for payment method in temporary card locker which gets refreshed often
Expand Down
1 change: 1 addition & 0 deletions crates/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ v1 = ["api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "stor
customer_v2 = ["api_models/customer_v2", "diesel_models/customer_v2", "hyperswitch_domain_models/customer_v2"]
merchant_account_v2 = ["api_models/merchant_account_v2", "diesel_models/merchant_account_v2", "hyperswitch_domain_models/merchant_account_v2"]
payment_v2 = ["api_models/payment_v2", "diesel_models/payment_v2", "hyperswitch_domain_models/payment_v2"]
payment_methods_v2 = ["api_models/payment_methods_v2"]
routing_v2 = ["api_models/routing_v2"]
merchant_connector_account_v2 = ["api_models/merchant_connector_account_v2", "kgraph_utils/merchant_connector_account_v2", "hyperswitch_domain_models/merchant_connector_account_v2", "diesel_models/merchant_connector_account_v2"]

Expand Down
21 changes: 19 additions & 2 deletions crates/router/src/compatibility/stripe/customers/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub struct CustomerPaymentMethodListResponse {

#[derive(Default, Serialize, PartialEq, Eq)]
pub struct PaymentMethodData {
pub id: String,
pub id: Option<String>,
pub object: &'static str,
pub card: Option<CardDetails>,
pub created: Option<time::PrimitiveDateTime>,
Expand Down Expand Up @@ -222,12 +222,29 @@ 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(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
let card = item.card.map(From::from);
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
let card = match item.payment_method_data {
Some(api_types::PaymentMethodListData::Card(card)) => Some(CardDetails::from(card)),
_ => None,
};
Self {
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
id: Some(item.payment_token),
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
id: item.payment_token,
object: "payment_method",
card: item.card.map(From::from),
card,
created: item.created,
}
}
Expand Down
Loading
Loading