Skip to content

Commit

Permalink
chore: add extra information enum and make customer_payment_methods a…
Browse files Browse the repository at this point in the history
…s optional
  • Loading branch information
Narayanbhat166 committed Dec 20, 2024
1 parent 7618c9d commit a801fed
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
52 changes: 38 additions & 14 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -13947,6 +13947,38 @@
"awaiting_data"
]
},
"PaymentMethodSubtypeSpecificData": {
"oneOf": [
{
"type": "object",
"required": [
"card_networks"
],
"properties": {
"card_networks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CardNetworkTypes"
}
}
}
},
{
"type": "object",
"required": [
"bank_names"
],
"properties": {
"bank_names": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BankCodeResponse"
}
}
}
}
]
},
"PaymentMethodType": {
"type": "string",
"description": "Indicates the sub type of payment method. Eg: 'google_pay' & 'apple_pay' for wallets.",
Expand Down Expand Up @@ -18858,20 +18890,12 @@
"payment_method_subtype": {
"$ref": "#/components/schemas/PaymentMethodType"
},
"card_networks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CardNetworkTypes"
},
"description": "The list of card networks enabled, if applicable for a payment method type",
"nullable": true
},
"bank_names": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BankCodeResponse"
},
"description": "The list of banks enabled, if applicable for a payment method type",
"extra_information": {
"allOf": [
{
"$ref": "#/components/schemas/PaymentMethodSubtypeSpecificData"
}
],
"nullable": true
},
"required_fields": {
Expand Down
19 changes: 14 additions & 5 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,18 @@ pub struct ResponsePaymentMethodTypes {
pub pm_auth_connector: Option<String>,
}

#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, Clone, serde::Serialize, ToSchema, PartialEq)]
#[serde(untagged)] // Untagged used for serialization only
pub enum PaymentMethodSubtypeSpecificData {
Card {
card_networks: Vec<CardNetworkTypes>,
},
Bank {
bank_names: Vec<BankCodeResponse>,
},
}

#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, Clone, serde::Serialize, ToSchema, PartialEq)]
pub struct ResponsePaymentMethodTypes {
Expand All @@ -1263,11 +1275,8 @@ pub struct ResponsePaymentMethodTypes {
#[schema(example = "klarna", value_type = PaymentMethodType)]
pub payment_method_subtype: common_enums::PaymentMethodType,

/// The list of card networks enabled, if applicable for a payment method type
pub card_networks: Option<Vec<CardNetworkTypes>>,

/// The list of banks enabled, if applicable for a payment method type
pub bank_names: Option<Vec<BankCodeResponse>>,
/// payment method subtype specific information
pub extra_information: Option<PaymentMethodSubtypeSpecificData>,

/// Required fields for the payment_method_type.
/// This is the union of all the required fields for the payment method type enabled in all the connectors.
Expand Down
4 changes: 2 additions & 2 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6472,8 +6472,8 @@ pub struct PaymentMethodListResponseForPayments {

/// The list of payment methods that are saved by the given customer
/// This field is only returned if the customer_id is provided in the request
#[schema(value_type = Vec<CustomerPaymentMethod>)]
pub customer_payment_methods: Vec<payment_methods::CustomerPaymentMethod>,
#[schema(value_type = Option<Vec<CustomerPaymentMethod>>)]
pub customer_payment_methods: Option<Vec<payment_methods::CustomerPaymentMethod>>,
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
Expand Down
1 change: 1 addition & 0 deletions crates/openapi/src/openapi_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payment_methods::PaymentMethodListRequest,
api_models::payment_methods::PaymentMethodListResponse,
api_models::payment_methods::ResponsePaymentMethodsEnabled,
api_models::payment_methods::PaymentMethodSubtypeSpecificData,
api_models::payment_methods::ResponsePaymentMethodTypes,
api_models::payment_methods::PaymentExperienceTypes,
api_models::payment_methods::CardNetworkTypes,
Expand Down
5 changes: 2 additions & 3 deletions crates/router/src/core/payments/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,14 @@ impl RequiredFieldsAndSurchargeForEnabledPaymentMethodTypes {
payment_method_subtype: payment_methods_enabled.payment_method_subtype,
required_fields: payment_methods_enabled.required_field,
surcharge_details: payment_methods_enabled.surcharge,
card_networks: None,
bank_names: None,
extra_information: None,
}
})
.collect();

api_models::payments::PaymentMethodListResponseForPayments {
payment_methods_enabled: response_payment_methods,
customer_payment_methods: Vec::new(),
customer_payment_methods: None,
}
}
}
Expand Down

0 comments on commit a801fed

Please sign in to comment.