mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 17:47:54 +08:00
chore: implement custom serializer for payment method list (#373)
This commit is contained in:
@ -167,7 +167,7 @@ fn set_or_reject_duplicate<T, E: de::Error>(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Eq, PartialEq, Hash, Debug, serde::Deserialize)]
|
||||
pub struct ListPaymentMethodResponse {
|
||||
pub payment_method: api_enums::PaymentMethodType,
|
||||
pub payment_method_types: Option<Vec<api_enums::PaymentMethodSubType>>,
|
||||
@ -183,6 +183,32 @@ pub struct ListPaymentMethodResponse {
|
||||
pub payment_experience: Option<Vec<PaymentExperience>>,
|
||||
}
|
||||
|
||||
/// We need a custom serializer to only send relevant fields in ListPaymentMethodResponse
|
||||
/// Currently if the payment method is Wallet or Paylater the relevant fields are `payment_method`
|
||||
/// and `payment_method_issuers`. Otherwise only consider
|
||||
/// `payment_method`,`payment_method_issuers`,`payment_method_types`,`payment_schemes` fields.
|
||||
impl serde::Serialize for ListPaymentMethodResponse {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
use serde::ser::SerializeStruct;
|
||||
let mut state = serializer.serialize_struct("ListPaymentMethodResponse", 4)?;
|
||||
state.serialize_field("payment_method", &self.payment_method)?;
|
||||
match self.payment_method {
|
||||
api_enums::PaymentMethodType::Wallet | api_enums::PaymentMethodType::PayLater => {
|
||||
state.serialize_field("payment_method_issuers", &self.payment_method_issuers)?;
|
||||
}
|
||||
_ => {
|
||||
state.serialize_field("payment_method_issuers", &self.payment_method_issuers)?;
|
||||
state.serialize_field("payment_method_types", &self.payment_method_types)?;
|
||||
state.serialize_field("payment_schemes", &self.payment_schemes)?;
|
||||
}
|
||||
}
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct ListCustomerPaymentMethodsResponse {
|
||||
pub enabled_payment_methods: collections::HashSet<ListPaymentMethodResponse>,
|
||||
|
||||
Reference in New Issue
Block a user