mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-04 05:59:48 +08:00 
			
		
		
		
	feat(pm_auth): Added balance check for PM auth bank account (#5054)
This commit is contained in:
		@ -1,7 +1,7 @@
 | 
			
		||||
use std::collections::HashMap;
 | 
			
		||||
 | 
			
		||||
use common_enums::{PaymentMethod, PaymentMethodType};
 | 
			
		||||
use common_utils::id_type;
 | 
			
		||||
use common_utils::{id_type, types as util_types};
 | 
			
		||||
use masking::{PeekInterface, Secret};
 | 
			
		||||
use serde::{Deserialize, Serialize};
 | 
			
		||||
 | 
			
		||||
@ -120,7 +120,7 @@ pub struct PlaidBankAccountCredentialsRequest {
 | 
			
		||||
    options: Option<BankAccountCredentialsOptions>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Deserialize, Eq, PartialEq)]
 | 
			
		||||
#[derive(Debug, Deserialize, PartialEq)]
 | 
			
		||||
 | 
			
		||||
pub struct PlaidBankAccountCredentialsResponse {
 | 
			
		||||
    pub accounts: Vec<PlaidBankAccountCredentialsAccounts>,
 | 
			
		||||
@ -135,19 +135,20 @@ pub struct BankAccountCredentialsOptions {
 | 
			
		||||
    account_ids: Vec<String>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Deserialize, Eq, PartialEq)]
 | 
			
		||||
#[derive(Debug, Deserialize, PartialEq)]
 | 
			
		||||
 | 
			
		||||
pub struct PlaidBankAccountCredentialsAccounts {
 | 
			
		||||
    pub account_id: String,
 | 
			
		||||
    pub name: String,
 | 
			
		||||
    pub subtype: Option<String>,
 | 
			
		||||
    pub balances: Option<PlaidBankAccountCredentialsBalances>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Deserialize, Eq, PartialEq)]
 | 
			
		||||
#[derive(Debug, Deserialize, PartialEq)]
 | 
			
		||||
pub struct PlaidBankAccountCredentialsBalances {
 | 
			
		||||
    pub available: Option<i32>,
 | 
			
		||||
    pub current: Option<i32>,
 | 
			
		||||
    pub limit: Option<i32>,
 | 
			
		||||
    pub available: Option<util_types::FloatMajorUnit>,
 | 
			
		||||
    pub current: Option<util_types::FloatMajorUnit>,
 | 
			
		||||
    pub limit: Option<util_types::FloatMajorUnit>,
 | 
			
		||||
    pub iso_currency_code: Option<String>,
 | 
			
		||||
    pub unofficial_currency_code: Option<String>,
 | 
			
		||||
    pub last_updated_datetime: Option<String>,
 | 
			
		||||
@ -242,16 +243,27 @@ impl<F, T>
 | 
			
		||||
        let mut id_to_subtype = HashMap::new();
 | 
			
		||||
 | 
			
		||||
        accounts_info.into_iter().for_each(|acc| {
 | 
			
		||||
            id_to_subtype.insert(acc.account_id, (acc.subtype, acc.name));
 | 
			
		||||
            id_to_subtype.insert(
 | 
			
		||||
                acc.account_id,
 | 
			
		||||
                (
 | 
			
		||||
                    acc.subtype,
 | 
			
		||||
                    acc.name,
 | 
			
		||||
                    acc.balances.and_then(|balance| balance.available),
 | 
			
		||||
                ),
 | 
			
		||||
            );
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        account_numbers.ach.into_iter().for_each(|ach| {
 | 
			
		||||
            let (acc_type, acc_name) =
 | 
			
		||||
                if let Some((_type, name)) = id_to_subtype.get(&ach.account_id) {
 | 
			
		||||
                    (_type.to_owned(), Some(name.clone()))
 | 
			
		||||
                } else {
 | 
			
		||||
                    (None, None)
 | 
			
		||||
                };
 | 
			
		||||
            let (acc_type, acc_name, available_balance) = if let Some((
 | 
			
		||||
                _type,
 | 
			
		||||
                name,
 | 
			
		||||
                available_balance,
 | 
			
		||||
            )) = id_to_subtype.get(&ach.account_id)
 | 
			
		||||
            {
 | 
			
		||||
                (_type.to_owned(), Some(name.clone()), *available_balance)
 | 
			
		||||
            } else {
 | 
			
		||||
                (None, None, None)
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            let account_details =
 | 
			
		||||
                types::PaymentMethodTypeDetails::Ach(types::BankAccountDetailsAch {
 | 
			
		||||
@ -266,17 +278,19 @@ impl<F, T>
 | 
			
		||||
                payment_method: PaymentMethod::BankDebit,
 | 
			
		||||
                account_id: ach.account_id.into(),
 | 
			
		||||
                account_type: acc_type,
 | 
			
		||||
                balance: available_balance,
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            bank_account_vec.push(bank_details_new);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        account_numbers.bacs.into_iter().for_each(|bacs| {
 | 
			
		||||
            let (acc_type, acc_name) =
 | 
			
		||||
                if let Some((_type, name)) = id_to_subtype.get(&bacs.account_id) {
 | 
			
		||||
                    (_type.to_owned(), Some(name.clone()))
 | 
			
		||||
            let (acc_type, acc_name, available_balance) =
 | 
			
		||||
                if let Some((_type, name, available_balance)) = id_to_subtype.get(&bacs.account_id)
 | 
			
		||||
                {
 | 
			
		||||
                    (_type.to_owned(), Some(name.clone()), *available_balance)
 | 
			
		||||
                } else {
 | 
			
		||||
                    (None, None)
 | 
			
		||||
                    (None, None, None)
 | 
			
		||||
                };
 | 
			
		||||
 | 
			
		||||
            let account_details =
 | 
			
		||||
@ -292,17 +306,19 @@ impl<F, T>
 | 
			
		||||
                payment_method: PaymentMethod::BankDebit,
 | 
			
		||||
                account_id: bacs.account_id.into(),
 | 
			
		||||
                account_type: acc_type,
 | 
			
		||||
                balance: available_balance,
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            bank_account_vec.push(bank_details_new);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        account_numbers.international.into_iter().for_each(|sepa| {
 | 
			
		||||
            let (acc_type, acc_name) =
 | 
			
		||||
                if let Some((_type, name)) = id_to_subtype.get(&sepa.account_id) {
 | 
			
		||||
                    (_type.to_owned(), Some(name.clone()))
 | 
			
		||||
            let (acc_type, acc_name, available_balance) =
 | 
			
		||||
                if let Some((_type, name, available_balance)) = id_to_subtype.get(&sepa.account_id)
 | 
			
		||||
                {
 | 
			
		||||
                    (_type.to_owned(), Some(name.clone()), *available_balance)
 | 
			
		||||
                } else {
 | 
			
		||||
                    (None, None)
 | 
			
		||||
                    (None, None, None)
 | 
			
		||||
                };
 | 
			
		||||
 | 
			
		||||
            let account_details =
 | 
			
		||||
@ -318,6 +334,7 @@ impl<F, T>
 | 
			
		||||
                payment_method: PaymentMethod::BankDebit,
 | 
			
		||||
                account_id: sepa.account_id.into(),
 | 
			
		||||
                account_type: acc_type,
 | 
			
		||||
                balance: available_balance,
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            bank_account_vec.push(bank_details_new);
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user