From e86c0325f51d06ecfcbc810f3320c97850716825 Mon Sep 17 00:00:00 2001 From: Sarthak Soni <76486416+Sarthak1799@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:18:10 +0530 Subject: [PATCH] feat(payment_methods): bank details support for payment method data in pmt (#2385) --- crates/api_models/src/payment_methods.rs | 20 +++++++++++++++++++ crates/diesel_models/src/payment_method.rs | 19 ++++++++++++++++-- .../router/src/core/payment_methods/cards.rs | 5 +++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs index 4e67ed4d45fe..e69b9fc82641 100644 --- a/crates/api_models/src/payment_methods.rs +++ b/crates/api_models/src/payment_methods.rs @@ -147,6 +147,7 @@ pub struct PaymentMethodResponse { #[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] pub enum PaymentMethodsData { Card(CardDetailsPaymentMethod), + BankDetails(PaymentMethodDataBankCreds), } #[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] pub struct CardDetailsPaymentMethod { @@ -158,6 +159,25 @@ pub struct CardDetailsPaymentMethod { pub card_holder_name: Option>, } +#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct PaymentMethodDataBankCreds { + pub mask: String, + pub hash: String, + pub payment_method_type: api_enums::PaymentMethodType, + pub connector_details: Vec, +} + +#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize)] +pub struct BankAccountConnectorDetails { + pub connector: String, + pub account_id: String, + pub access_token: BankAccountAccessCreds, +} + +#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize)] +pub enum BankAccountAccessCreds { + AccessToken(String), +} #[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)] pub struct CardDetailFromLocker { pub scheme: Option, diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs index 8029c20038a5..d8b46c1932ef 100644 --- a/crates/diesel_models/src/payment_method.rs +++ b/crates/diesel_models/src/payment_method.rs @@ -99,13 +99,19 @@ pub struct TokenizeCoreWorkflow { #[derive(Debug, Serialize, Deserialize)] pub enum PaymentMethodUpdate { - MetadataUpdate { metadata: Option }, + MetadataUpdate { + metadata: Option, + }, + PaymentMethodDataUpdate { + payment_method_data: Option, + }, } #[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)] #[diesel(table_name = payment_methods)] pub struct PaymentMethodUpdateInternal { metadata: Option, + payment_method_data: Option, } impl PaymentMethodUpdateInternal { @@ -119,7 +125,16 @@ impl PaymentMethodUpdateInternal { impl From for PaymentMethodUpdateInternal { fn from(payment_method_update: PaymentMethodUpdate) -> Self { match payment_method_update { - PaymentMethodUpdate::MetadataUpdate { metadata } => Self { metadata }, + PaymentMethodUpdate::MetadataUpdate { metadata } => Self { + metadata, + payment_method_data: None, + }, + PaymentMethodUpdate::PaymentMethodDataUpdate { + payment_method_data, + } => Self { + metadata: None, + payment_method_data, + }, } } } diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 20a3e130eb25..c0c0a3f00f1a 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -1954,8 +1954,9 @@ async fn get_card_details( .flatten() .map(|x| x.into_inner().expose()) .and_then(|v| serde_json::from_value::(v).ok()) - .map(|pmd| match pmd { - PaymentMethodsData::Card(crd) => api::CardDetailFromLocker::from(crd), + .and_then(|pmd| match pmd { + PaymentMethodsData::Card(crd) => Some(api::CardDetailFromLocker::from(crd)), + _ => None, }); Ok(Some(