refactor(core): Refactor customer payment method list for v2 (#4856)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Sarthak Soni
2024-08-06 20:55:30 +05:30
committed by GitHub
parent 18e328d382
commit 8302272460
11 changed files with 979 additions and 116 deletions

View File

@ -193,7 +193,7 @@ pub struct CustomerPaymentMethodListResponse {
#[derive(Default, Serialize, PartialEq, Eq)]
pub struct PaymentMethodData {
pub id: String,
pub id: Option<String>,
pub object: &'static str,
pub card: Option<CardDetails>,
pub created: Option<time::PrimitiveDateTime>,
@ -222,12 +222,29 @@ impl From<api::CustomerPaymentMethodsListResponse> for CustomerPaymentMethodList
}
}
// Check this in review
impl From<api_types::CustomerPaymentMethod> for PaymentMethodData {
fn from(item: api_types::CustomerPaymentMethod) -> Self {
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
let card = item.card.map(From::from);
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
let card = match item.payment_method_data {
Some(api_types::PaymentMethodListData::Card(card)) => Some(CardDetails::from(card)),
_ => None,
};
Self {
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
))]
id: Some(item.payment_token),
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
id: item.payment_token,
object: "payment_method",
card: item.card.map(From::from),
card,
created: item.created,
}
}