From a801fed85aac4df11d77c738afec6bedc8e56849 Mon Sep 17 00:00:00 2001 From: Narayanbhat166 Date: Fri, 20 Dec 2024 15:05:08 +0530 Subject: [PATCH] chore: add extra information enum and make customer_payment_methods as optional --- api-reference-v2/openapi_spec.json | 52 ++++++++++++++----- crates/api_models/src/payment_methods.rs | 19 +++++-- crates/api_models/src/payments.rs | 4 +- crates/openapi/src/openapi_v2.rs | 1 + .../src/core/payments/payment_methods.rs | 5 +- 5 files changed, 57 insertions(+), 24 deletions(-) diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index ecef9128be1d..7ebbac68e88f 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -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.", @@ -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": { diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs index ddb88fe7a84f..41c588af49d0 100644 --- a/crates/api_models/src/payment_methods.rs +++ b/crates/api_models/src/payment_methods.rs @@ -1252,6 +1252,18 @@ pub struct ResponsePaymentMethodTypes { pub pm_auth_connector: Option, } +#[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, + }, + Bank { + bank_names: Vec, + }, +} + #[cfg(all(feature = "v2", feature = "payment_methods_v2"))] #[derive(Debug, Clone, serde::Serialize, ToSchema, PartialEq)] pub struct ResponsePaymentMethodTypes { @@ -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>, - - /// The list of banks enabled, if applicable for a payment method type - pub bank_names: Option>, + /// payment method subtype specific information + pub extra_information: Option, /// 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. diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 7daa985e7991..ff6abbd94e76 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -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)] - pub customer_payment_methods: Vec, + #[schema(value_type = Option>)] + pub customer_payment_methods: Option>, } #[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)] diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs index fb60a57e6e95..d693fe24961a 100644 --- a/crates/openapi/src/openapi_v2.rs +++ b/crates/openapi/src/openapi_v2.rs @@ -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, diff --git a/crates/router/src/core/payments/payment_methods.rs b/crates/router/src/core/payments/payment_methods.rs index 5f6cefc69fc1..6ed436ae3c77 100644 --- a/crates/router/src/core/payments/payment_methods.rs +++ b/crates/router/src/core/payments/payment_methods.rs @@ -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, } } }