mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	feat(core): [Payouts] Add payout_method_details to response (#5887)
Co-authored-by: Chikke Srujan <chikke.srujan@Chikke-Srujan-N7WRTY72X7.local> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com>
This commit is contained in:
		| @ -3,8 +3,9 @@ use std::collections::HashMap; | ||||
| use cards::CardNumber; | ||||
| use common_utils::{ | ||||
|     consts::default_payouts_list_limit, | ||||
|     crypto, id_type, link_utils, | ||||
|     crypto, id_type, link_utils, payout_method_utils, | ||||
|     pii::{self, Email}, | ||||
|     transformers::ForeignFrom, | ||||
|     types::{UnifiedCode, UnifiedMessage}, | ||||
| }; | ||||
| use masking::Secret; | ||||
| @ -418,6 +419,25 @@ pub struct PayoutCreateResponse { | ||||
|     #[schema(value_type = Option<PayoutType>, example = "bank")] | ||||
|     pub payout_type: Option<api_enums::PayoutType>, | ||||
|  | ||||
|     /// The payout method details for the payout | ||||
|     #[schema(value_type = Option<PayoutMethodDataResponse>, example = json!(r#"{ | ||||
|         "card": { | ||||
|             "last4": "2503", | ||||
|             "card_type": null, | ||||
|             "card_network": null, | ||||
|             "card_issuer": null, | ||||
|             "card_issuing_country": null, | ||||
|             "card_isin": "400000", | ||||
|             "card_extended_bin": null, | ||||
|             "card_exp_month": "08", | ||||
|             "card_exp_year": "25", | ||||
|             "card_holder_name": null, | ||||
|             "payment_checks": null, | ||||
|             "authentication_data": null | ||||
|         } | ||||
|     }"#))] | ||||
|     pub payout_method_data: Option<PayoutMethodDataResponse>, | ||||
|  | ||||
|     /// The billing address for the payout | ||||
|     #[schema(value_type = Option<Address>, example = json!(r#"{ | ||||
|         "address": { | ||||
| @ -550,6 +570,18 @@ pub struct PayoutCreateResponse { | ||||
|     pub unified_message: Option<UnifiedMessage>, | ||||
| } | ||||
|  | ||||
| /// The payout method information for response | ||||
| #[derive(Debug, Clone, Deserialize, Serialize, ToSchema)] | ||||
| #[serde(rename_all = "snake_case")] | ||||
| pub enum PayoutMethodDataResponse { | ||||
|     #[schema(value_type = CardAdditionalData)] | ||||
|     Card(Box<payout_method_utils::CardAdditionalData>), | ||||
|     #[schema(value_type = BankAdditionalData)] | ||||
|     Bank(Box<payout_method_utils::BankAdditionalData>), | ||||
|     #[schema(value_type = WalletAdditionalData)] | ||||
|     Wallet(Box<payout_method_utils::WalletAdditionalData>), | ||||
| } | ||||
|  | ||||
| #[derive( | ||||
|     Default, Debug, serde::Serialize, Clone, PartialEq, ToSchema, router_derive::PolymorphicSchema, | ||||
| )] | ||||
| @ -844,3 +876,107 @@ pub struct PayoutLinkStatusDetails { | ||||
|     pub ui_config: link_utils::GenericLinkUiConfigFormData, | ||||
|     pub test_mode: bool, | ||||
| } | ||||
|  | ||||
| impl From<Bank> for payout_method_utils::BankAdditionalData { | ||||
|     fn from(bank_data: Bank) -> Self { | ||||
|         match bank_data { | ||||
|             Bank::Ach(AchBankTransfer { | ||||
|                 bank_name, | ||||
|                 bank_country_code, | ||||
|                 bank_city, | ||||
|                 bank_account_number, | ||||
|                 bank_routing_number, | ||||
|             }) => Self::Ach(Box::new( | ||||
|                 payout_method_utils::AchBankTransferAdditionalData { | ||||
|                     bank_name, | ||||
|                     bank_country_code, | ||||
|                     bank_city, | ||||
|                     bank_account_number: bank_account_number.into(), | ||||
|                     bank_routing_number: bank_routing_number.into(), | ||||
|                 }, | ||||
|             )), | ||||
|             Bank::Bacs(BacsBankTransfer { | ||||
|                 bank_name, | ||||
|                 bank_country_code, | ||||
|                 bank_city, | ||||
|                 bank_account_number, | ||||
|                 bank_sort_code, | ||||
|             }) => Self::Bacs(Box::new( | ||||
|                 payout_method_utils::BacsBankTransferAdditionalData { | ||||
|                     bank_name, | ||||
|                     bank_country_code, | ||||
|                     bank_city, | ||||
|                     bank_account_number: bank_account_number.into(), | ||||
|                     bank_sort_code: bank_sort_code.into(), | ||||
|                 }, | ||||
|             )), | ||||
|             Bank::Sepa(SepaBankTransfer { | ||||
|                 bank_name, | ||||
|                 bank_country_code, | ||||
|                 bank_city, | ||||
|                 iban, | ||||
|                 bic, | ||||
|             }) => Self::Sepa(Box::new( | ||||
|                 payout_method_utils::SepaBankTransferAdditionalData { | ||||
|                     bank_name, | ||||
|                     bank_country_code, | ||||
|                     bank_city, | ||||
|                     iban: iban.into(), | ||||
|                     bic: bic.map(From::from), | ||||
|                 }, | ||||
|             )), | ||||
|             Bank::Pix(PixBankTransfer { | ||||
|                 bank_name, | ||||
|                 bank_branch, | ||||
|                 bank_account_number, | ||||
|                 pix_key, | ||||
|                 tax_id, | ||||
|             }) => Self::Pix(Box::new( | ||||
|                 payout_method_utils::PixBankTransferAdditionalData { | ||||
|                     bank_name, | ||||
|                     bank_branch, | ||||
|                     bank_account_number: bank_account_number.into(), | ||||
|                     pix_key: pix_key.into(), | ||||
|                     tax_id: tax_id.map(From::from), | ||||
|                 }, | ||||
|             )), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<Wallet> for payout_method_utils::WalletAdditionalData { | ||||
|     fn from(wallet_data: Wallet) -> Self { | ||||
|         match wallet_data { | ||||
|             Wallet::Paypal(Paypal { | ||||
|                 email, | ||||
|                 telephone_number, | ||||
|                 paypal_id, | ||||
|             }) => Self::Paypal(Box::new(payout_method_utils::PaypalAdditionalData { | ||||
|                 email: email.map(ForeignFrom::foreign_from), | ||||
|                 telephone_number: telephone_number.map(From::from), | ||||
|                 paypal_id: paypal_id.map(From::from), | ||||
|             })), | ||||
|             Wallet::Venmo(Venmo { telephone_number }) => { | ||||
|                 Self::Venmo(Box::new(payout_method_utils::VenmoAdditionalData { | ||||
|                     telephone_number: telephone_number.map(From::from), | ||||
|                 })) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<payout_method_utils::AdditionalPayoutMethodData> for PayoutMethodDataResponse { | ||||
|     fn from(additional_data: payout_method_utils::AdditionalPayoutMethodData) -> Self { | ||||
|         match additional_data { | ||||
|             payout_method_utils::AdditionalPayoutMethodData::Card(card_data) => { | ||||
|                 Self::Card(card_data) | ||||
|             } | ||||
|             payout_method_utils::AdditionalPayoutMethodData::Bank(bank_data) => { | ||||
|                 Self::Bank(bank_data) | ||||
|             } | ||||
|             payout_method_utils::AdditionalPayoutMethodData::Wallet(wallet_data) => { | ||||
|                 Self::Wallet(wallet_data) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Sakil Mostak
					Sakil Mostak