Skip to content

Commit

Permalink
feat: populate payment method details in payments response (#5661)
Browse files Browse the repository at this point in the history
(cherry picked from commit 32db5dd)
  • Loading branch information
kashif-m committed Sep 5, 2024
1 parent db04ded commit eeb97e0
Show file tree
Hide file tree
Showing 10 changed files with 2,369 additions and 96 deletions.
734 changes: 722 additions & 12 deletions api-reference-v2/openapi_spec.json

Large diffs are not rendered by default.

734 changes: 722 additions & 12 deletions api-reference/openapi_spec.json

Large diffs are not rendered by default.

210 changes: 165 additions & 45 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
fmt,
num::NonZeroI64,
};

pub mod additional_info;
use cards::CardNumber;
use common_utils::{
consts::default_payments_list_limit,
Expand Down Expand Up @@ -2026,25 +2026,57 @@ pub enum AdditionalPaymentData {
Card(Box<AdditionalCardInfo>),
BankRedirect {
bank_name: Option<common_enums::BankNames>,
#[serde(flatten)]
details: Option<additional_info::BankRedirectDetails>,
},
Wallet {
apple_pay: Option<ApplepayPaymentMethod>,
},
PayLater {
klarna_sdk: Option<KlarnaSdkPaymentMethod>,
},
BankTransfer {},
Crypto {},
BankDebit {},
BankTransfer {
#[serde(flatten)]
details: Option<additional_info::BankTransferAdditionalData>,
},
Crypto {
#[serde(flatten)]
details: Option<CryptoData>,
},
BankDebit {
#[serde(flatten)]
details: Option<additional_info::BankDebitAdditionalData>,
},
MandatePayment {},
Reward {},
RealTimePayment {},
Upi {},
GiftCard {},
Voucher {},
CardRedirect {},
CardToken {},
OpenBanking {},
RealTimePayment {
#[serde(flatten)]
details: Option<RealTimePaymentData>,
},
Upi {
#[serde(flatten)]
details: Option<additional_info::UpiAdditionalData>,
},
GiftCard {
#[serde(flatten)]
details: Option<additional_info::GiftCardAdditionalData>,
},
Voucher {
#[serde(flatten)]
details: Option<VoucherData>,
},
CardRedirect {
#[serde(flatten)]
details: Option<CardRedirectData>,
},
CardToken {
#[serde(flatten)]
details: Option<additional_info::CardTokenAdditionalData>,
},
OpenBanking {
#[serde(flatten)]
details: Option<OpenBankingData>,
},
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -3011,21 +3043,21 @@ where
{
match payment_method_data {
PaymentMethodDataResponse::Reward {} => serializer.serialize_str("reward"),
PaymentMethodDataResponse::BankDebit {}
| PaymentMethodDataResponse::BankRedirect {}
PaymentMethodDataResponse::BankDebit(_)
| PaymentMethodDataResponse::BankRedirect(_)
| PaymentMethodDataResponse::Card(_)
| PaymentMethodDataResponse::CardRedirect {}
| PaymentMethodDataResponse::CardToken {}
| PaymentMethodDataResponse::Crypto {}
| PaymentMethodDataResponse::CardRedirect(_)
| PaymentMethodDataResponse::CardToken(_)
| PaymentMethodDataResponse::Crypto(_)
| PaymentMethodDataResponse::MandatePayment {}
| PaymentMethodDataResponse::GiftCard {}
| PaymentMethodDataResponse::GiftCard(_)
| PaymentMethodDataResponse::PayLater(_)
| PaymentMethodDataResponse::RealTimePayment {}
| PaymentMethodDataResponse::Upi {}
| PaymentMethodDataResponse::RealTimePayment(_)
| PaymentMethodDataResponse::Upi(_)
| PaymentMethodDataResponse::Wallet {}
| PaymentMethodDataResponse::BankTransfer {}
| PaymentMethodDataResponse::OpenBanking {}
| PaymentMethodDataResponse::Voucher {} => {
| PaymentMethodDataResponse::BankTransfer(_)
| PaymentMethodDataResponse::OpenBanking(_)
| PaymentMethodDataResponse::Voucher(_) => {
payment_method_data_response.serialize(serializer)
}
}
Expand All @@ -3041,23 +3073,88 @@ where
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum PaymentMethodDataResponse {
#[serde(rename = "card")]
Card(Box<CardResponse>),
BankTransfer {},
BankTransfer(Box<BankTransferResponse>),
Wallet {},
PayLater(Box<PaylaterResponse>),
BankRedirect {},
Crypto {},
BankDebit {},
#[schema(value_type = BankRedirectAdditionalData)]
BankRedirect(Box<additional_info::BankRedirectAdditionalData>),
Crypto(Box<CryptoResponse>),
BankDebit(Box<BankDebitResponse>),
MandatePayment {},
Reward {},
RealTimePayment {},
Upi {},
Voucher {},
GiftCard {},
CardRedirect {},
CardToken {},
OpenBanking {},
RealTimePayment(Box<RealTimePaymentDataResponse>),
Upi(Box<UpiResponse>),
Voucher(Box<VoucherResponse>),
GiftCard(Box<GiftCardResponse>),
CardRedirect(Box<CardRedirectResponse>),
CardToken(Box<CardTokenResponse>),
OpenBanking(Box<OpenBankingResponse>),
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct BankDebitResponse {
#[serde(flatten)]
#[schema(value_type = BankDebitAdditionalData)]
details: Option<additional_info::BankDebitAdditionalData>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct BankTransferResponse {
#[serde(flatten)]
#[schema(value_type = BankTransferAdditionalData)]
details: Option<additional_info::BankTransferAdditionalData>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct CardRedirectResponse {
#[serde(flatten)]
details: Option<CardRedirectData>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct CardTokenResponse {
#[serde(flatten)]
#[schema(value_type = CardTokenAdditionalData)]
details: Option<additional_info::CardTokenAdditionalData>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct CryptoResponse {
#[serde(flatten)]
details: Option<CryptoData>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct GiftCardResponse {
#[serde(flatten)]
#[schema(value_type = GiftCardAdditionalData)]
details: Option<additional_info::GiftCardAdditionalData>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct OpenBankingResponse {
#[serde(flatten)]
details: Option<OpenBankingData>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct RealTimePaymentDataResponse {
#[serde(flatten)]
details: Option<RealTimePaymentData>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct UpiResponse {
#[serde(flatten)]
#[schema(value_type = UpiAdditionalData)]
details: Option<additional_info::UpiAdditionalData>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct VoucherResponse {
#[serde(flatten)]
details: Option<VoucherData>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
Expand Down Expand Up @@ -4299,19 +4396,42 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {
None => Self::PayLater(Box::new(PaylaterResponse { klarna_sdk: None })),
},
AdditionalPaymentData::Wallet { .. } => Self::Wallet {},
AdditionalPaymentData::BankRedirect { .. } => Self::BankRedirect {},
AdditionalPaymentData::Crypto {} => Self::Crypto {},
AdditionalPaymentData::BankDebit {} => Self::BankDebit {},
AdditionalPaymentData::BankRedirect { bank_name, details } => {
Self::BankRedirect(Box::new(additional_info::BankRedirectAdditionalData {
bank_name,
details,
}))
}
AdditionalPaymentData::Crypto { details } => {
Self::Crypto(Box::new(CryptoResponse { details }))
}
AdditionalPaymentData::BankDebit { details } => {
Self::BankDebit(Box::new(BankDebitResponse { details }))
}
AdditionalPaymentData::MandatePayment {} => Self::MandatePayment {},
AdditionalPaymentData::Reward {} => Self::Reward {},
AdditionalPaymentData::RealTimePayment {} => Self::RealTimePayment {},
AdditionalPaymentData::Upi {} => Self::Upi {},
AdditionalPaymentData::BankTransfer {} => Self::BankTransfer {},
AdditionalPaymentData::Voucher {} => Self::Voucher {},
AdditionalPaymentData::GiftCard {} => Self::GiftCard {},
AdditionalPaymentData::CardRedirect {} => Self::CardRedirect {},
AdditionalPaymentData::CardToken {} => Self::CardToken {},
AdditionalPaymentData::OpenBanking {} => Self::OpenBanking {},
AdditionalPaymentData::RealTimePayment { details } => {
Self::RealTimePayment(Box::new(RealTimePaymentDataResponse { details }))
}
AdditionalPaymentData::Upi { details } => Self::Upi(Box::new(UpiResponse { details })),
AdditionalPaymentData::BankTransfer { details } => {
Self::BankTransfer(Box::new(BankTransferResponse { details }))
}
AdditionalPaymentData::Voucher { details } => {
Self::Voucher(Box::new(VoucherResponse { details }))
}
AdditionalPaymentData::GiftCard { details } => {
Self::GiftCard(Box::new(GiftCardResponse { details }))
}
AdditionalPaymentData::CardRedirect { details } => {
Self::CardRedirect(Box::new(CardRedirectResponse { details }))
}
AdditionalPaymentData::CardToken { details } => {
Self::CardToken(Box::new(CardTokenResponse { details }))
}
AdditionalPaymentData::OpenBanking { details } => {
Self::OpenBanking(Box::new(OpenBankingResponse { details }))
}
}
}
}
Expand Down
Loading

0 comments on commit eeb97e0

Please # to comment.