feat: populate payment method details in payments response (#5661)

This commit is contained in:
Kashif
2024-08-26 22:01:35 +05:30
committed by GitHub
parent 138134dfb6
commit 32db5dd1ca
10 changed files with 1958 additions and 100 deletions

View File

@ -1,10 +1,13 @@
use api_models::payments::ExtendedCardInfo;
use api_models::payments::{additional_info as payment_additional_types, ExtendedCardInfo};
use common_enums::enums as api_enums;
use common_utils::{
id_type,
pii::{self, Email},
};
use masking::Secret;
use masking::{
masked_string::{MaskedBankAccount, MaskedIban, MaskedRoutingNumber, MaskedSortCode},
PeekInterface, Secret,
};
use serde::{Deserialize, Serialize};
use time::Date;
@ -581,6 +584,17 @@ impl From<api_models::payments::CardRedirectData> for CardRedirectData {
}
}
impl From<CardRedirectData> for api_models::payments::CardRedirectData {
fn from(value: CardRedirectData) -> Self {
match value {
CardRedirectData::Knet {} => Self::Knet {},
CardRedirectData::Benefit {} => Self::Benefit {},
CardRedirectData::MomoAtm {} => Self::MomoAtm {},
CardRedirectData::CardRedirect {} => Self::CardRedirect {},
}
}
}
impl From<api_models::payments::WalletData> for WalletData {
fn from(value: api_models::payments::WalletData) -> Self {
match value {
@ -800,6 +814,19 @@ impl From<api_models::payments::CryptoData> for CryptoData {
}
}
impl From<CryptoData> for api_models::payments::CryptoData {
fn from(value: CryptoData) -> Self {
let CryptoData {
pay_currency,
network,
} = value;
Self {
pay_currency,
network,
}
}
}
impl From<api_models::payments::UpiData> for UpiData {
fn from(value: api_models::payments::UpiData) -> Self {
match value {
@ -811,6 +838,19 @@ impl From<api_models::payments::UpiData> for UpiData {
}
}
impl From<UpiData> for api_models::payments::additional_info::UpiAdditionalData {
fn from(value: UpiData) -> Self {
match value {
UpiData::UpiCollect(upi) => Self::UpiCollect(Box::new(
payment_additional_types::UpiCollectAdditionalData { vpa_id: upi.vpa_id },
)),
UpiData::UpiIntent(_) => {
Self::UpiIntent(Box::new(api_models::payments::UpiIntentData {}))
}
}
}
}
impl From<api_models::payments::VoucherData> for VoucherData {
fn from(value: api_models::payments::VoucherData) -> Self {
match value {
@ -842,6 +882,66 @@ impl From<api_models::payments::VoucherData> for VoucherData {
}
}
impl From<Box<BoletoVoucherData>> for Box<api_models::payments::BoletoVoucherData> {
fn from(value: Box<BoletoVoucherData>) -> Self {
Self::new(api_models::payments::BoletoVoucherData {
social_security_number: value.social_security_number,
})
}
}
impl From<Box<AlfamartVoucherData>> for Box<api_models::payments::AlfamartVoucherData> {
fn from(_value: Box<AlfamartVoucherData>) -> Self {
Self::new(api_models::payments::AlfamartVoucherData {
first_name: None,
last_name: None,
email: None,
})
}
}
impl From<Box<IndomaretVoucherData>> for Box<api_models::payments::IndomaretVoucherData> {
fn from(_value: Box<IndomaretVoucherData>) -> Self {
Self::new(api_models::payments::IndomaretVoucherData {
first_name: None,
last_name: None,
email: None,
})
}
}
impl From<Box<JCSVoucherData>> for Box<api_models::payments::JCSVoucherData> {
fn from(_value: Box<JCSVoucherData>) -> Self {
Self::new(api_models::payments::JCSVoucherData {
first_name: None,
last_name: None,
email: None,
phone_number: None,
})
}
}
impl From<VoucherData> for api_models::payments::VoucherData {
fn from(value: VoucherData) -> Self {
match value {
VoucherData::Boleto(boleto_data) => Self::Boleto(boleto_data.into()),
VoucherData::Alfamart(alfa_mart) => Self::Alfamart(alfa_mart.into()),
VoucherData::Indomaret(info_maret) => Self::Indomaret(info_maret.into()),
VoucherData::SevenEleven(jcs_data)
| VoucherData::Lawson(jcs_data)
| VoucherData::MiniStop(jcs_data)
| VoucherData::FamilyMart(jcs_data)
| VoucherData::Seicomart(jcs_data)
| VoucherData::PayEasy(jcs_data) => Self::SevenEleven(jcs_data.into()),
VoucherData::Efecty => Self::Efecty,
VoucherData::PagoEfectivo => Self::PagoEfectivo,
VoucherData::RedCompra => Self::RedCompra,
VoucherData::RedPagos => Self::RedPagos,
VoucherData::Oxxo => Self::Oxxo,
}
}
}
impl From<api_models::payments::GiftCardData> for GiftCardData {
fn from(value: api_models::payments::GiftCardData) -> Self {
match value {
@ -854,6 +954,29 @@ impl From<api_models::payments::GiftCardData> for GiftCardData {
}
}
impl From<GiftCardData> for payment_additional_types::GiftCardAdditionalData {
fn from(value: GiftCardData) -> Self {
match value {
GiftCardData::Givex(details) => Self::Givex(Box::new(
payment_additional_types::GivexGiftCardAdditionalData {
last4: details
.number
.peek()
.chars()
.rev()
.take(4)
.collect::<String>()
.chars()
.rev()
.collect::<String>()
.into(),
},
)),
GiftCardData::PaySafeCard {} => Self::PaySafeCard {},
}
}
}
impl From<api_models::payments::CardToken> for CardToken {
fn from(value: api_models::payments::CardToken) -> Self {
let api_models::payments::CardToken {
@ -867,6 +990,15 @@ impl From<api_models::payments::CardToken> for CardToken {
}
}
impl From<CardToken> for payment_additional_types::CardTokenAdditionalData {
fn from(value: CardToken) -> Self {
let CardToken {
card_holder_name, ..
} = value;
Self { card_holder_name }
}
}
impl From<api_models::payments::BankDebitData> for BankDebitData {
fn from(value: api_models::payments::BankDebitData) -> Self {
match value {
@ -907,6 +1039,65 @@ impl From<api_models::payments::BankDebitData> for BankDebitData {
}
}
impl From<BankDebitData> for api_models::payments::additional_info::BankDebitAdditionalData {
fn from(value: BankDebitData) -> Self {
match value {
BankDebitData::AchBankDebit {
account_number,
routing_number,
bank_name,
bank_type,
bank_holder_type,
} => Self::Ach(Box::new(
payment_additional_types::AchBankDebitAdditionalData {
account_number: Secret::from(MaskedBankAccount::from(
account_number.peek().to_owned(),
)),
routing_number: Secret::from(MaskedRoutingNumber::from(
routing_number.peek().to_owned(),
)),
bank_name,
bank_type,
bank_holder_type,
bank_account_holder_name: None,
},
)),
BankDebitData::SepaBankDebit { iban, .. } => Self::Sepa(Box::new(
payment_additional_types::SepaBankDebitAdditionalData {
iban: Secret::from(MaskedIban::from(iban.peek().to_owned())),
bank_account_holder_name: None,
},
)),
BankDebitData::BecsBankDebit {
account_number,
bsb_number,
..
} => Self::Becs(Box::new(
payment_additional_types::BecsBankDebitAdditionalData {
account_number: Secret::from(MaskedBankAccount::from(
account_number.peek().to_owned(),
)),
bsb_number,
bank_account_holder_name: None,
},
)),
BankDebitData::BacsBankDebit {
account_number,
sort_code,
..
} => Self::Bacs(Box::new(
payment_additional_types::BacsBankDebitAdditionalData {
account_number: Secret::from(MaskedBankAccount::from(
account_number.peek().to_owned(),
)),
sort_code: Secret::from(MaskedSortCode::from(sort_code.peek().to_owned())),
bank_account_holder_name: None,
},
)),
}
}
}
impl From<api_models::payments::BankTransferData> for BankTransferData {
fn from(value: api_models::payments::BankTransferData) -> Self {
match value {
@ -954,6 +1145,42 @@ impl From<api_models::payments::BankTransferData> for BankTransferData {
}
}
impl From<BankTransferData> for api_models::payments::additional_info::BankTransferAdditionalData {
fn from(value: BankTransferData) -> Self {
match value {
BankTransferData::AchBankTransfer {} => Self::Ach {},
BankTransferData::SepaBankTransfer {} => Self::Sepa {},
BankTransferData::BacsBankTransfer {} => Self::Bacs {},
BankTransferData::MultibancoBankTransfer {} => Self::Multibanco {},
BankTransferData::PermataBankTransfer {} => Self::Permata {},
BankTransferData::BcaBankTransfer {} => Self::Bca {},
BankTransferData::BniVaBankTransfer {} => Self::BniVa {},
BankTransferData::BriVaBankTransfer {} => Self::BriVa {},
BankTransferData::CimbVaBankTransfer {} => Self::CimbVa {},
BankTransferData::DanamonVaBankTransfer {} => Self::DanamonVa {},
BankTransferData::MandiriVaBankTransfer {} => Self::MandiriVa {},
BankTransferData::Pix { pix_key, cpf, cnpj } => Self::Pix(Box::new(
api_models::payments::additional_info::PixBankTransferAdditionalData {
pix_key: pix_key.map(|pix_key| {
Secret::from(MaskedBankAccount::from(pix_key.peek().to_owned()))
}),
cpf: cpf
.map(|cpf| Secret::from(MaskedBankAccount::from(cpf.peek().to_owned()))),
cnpj: cnpj
.map(|cnpj| Secret::from(MaskedBankAccount::from(cnpj.peek().to_owned()))),
},
)),
BankTransferData::Pse {} => Self::Pse {},
BankTransferData::LocalBankTransfer { bank_code } => Self::LocalBankTransfer(Box::new(
api_models::payments::additional_info::LocalBankTransferAdditionalData {
bank_code: bank_code
.map(|bank_code| Secret::from(MaskedBankAccount::from(bank_code))),
},
)),
}
}
}
impl From<api_models::payments::RealTimePaymentData> for RealTimePaymentData {
fn from(value: api_models::payments::RealTimePaymentData) -> Self {
match value {
@ -965,6 +1192,17 @@ impl From<api_models::payments::RealTimePaymentData> for RealTimePaymentData {
}
}
impl From<RealTimePaymentData> for api_models::payments::RealTimePaymentData {
fn from(value: RealTimePaymentData) -> Self {
match value {
RealTimePaymentData::Fps {} => Self::Fps {},
RealTimePaymentData::DuitNow {} => Self::DuitNow {},
RealTimePaymentData::PromptPay {} => Self::PromptPay {},
RealTimePaymentData::VietQr {} => Self::VietQr {},
}
}
}
impl From<api_models::payments::OpenBankingData> for OpenBankingData {
fn from(value: api_models::payments::OpenBankingData) -> Self {
match value {
@ -973,6 +1211,14 @@ impl From<api_models::payments::OpenBankingData> for OpenBankingData {
}
}
impl From<OpenBankingData> for api_models::payments::OpenBankingData {
fn from(value: OpenBankingData) -> Self {
match value {
OpenBankingData::OpenBankingPIS {} => Self::OpenBankingPIS {},
}
}
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TokenizedCardValue1 {