Skip to content

Commit

Permalink
feat(payment_methods): bank details support for payment method data i…
Browse files Browse the repository at this point in the history
…n pmt (#2385)
  • Loading branch information
Sarthak1799 authored Oct 5, 2023
1 parent 7fb5c04 commit e86c032
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
20 changes: 20 additions & 0 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -158,6 +159,25 @@ pub struct CardDetailsPaymentMethod {
pub card_holder_name: Option<masking::Secret<String>>,
}

#[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<BankAccountConnectorDetails>,
}

#[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<String>,
Expand Down
19 changes: 17 additions & 2 deletions crates/diesel_models/src/payment_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,19 @@ pub struct TokenizeCoreWorkflow {

#[derive(Debug, Serialize, Deserialize)]
pub enum PaymentMethodUpdate {
MetadataUpdate { metadata: Option<serde_json::Value> },
MetadataUpdate {
metadata: Option<serde_json::Value>,
},
PaymentMethodDataUpdate {
payment_method_data: Option<Encryption>,
},
}

#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = payment_methods)]
pub struct PaymentMethodUpdateInternal {
metadata: Option<serde_json::Value>,
payment_method_data: Option<Encryption>,
}

impl PaymentMethodUpdateInternal {
Expand All @@ -119,7 +125,16 @@ impl PaymentMethodUpdateInternal {
impl From<PaymentMethodUpdate> 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,
},
}
}
}
5 changes: 3 additions & 2 deletions crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1954,8 +1954,9 @@ async fn get_card_details(
.flatten()
.map(|x| x.into_inner().expose())
.and_then(|v| serde_json::from_value::<PaymentMethodsData>(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(
Expand Down

0 comments on commit e86c032

Please sign in to comment.