mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	refactor(payment_method): [Klarna] store and populate payment_type for klarna_sdk Paylater in response (#4956)
This commit is contained in:
		| @ -1814,7 +1814,9 @@ pub enum AdditionalPaymentData { | ||||
|     Wallet { | ||||
|         apple_pay: Option<ApplepayPaymentMethod>, | ||||
|     }, | ||||
|     PayLater {}, | ||||
|     PayLater { | ||||
|         klarna_sdk: Option<KlarnaSdkPaymentMethod>, | ||||
|     }, | ||||
|     BankTransfer {}, | ||||
|     Crypto {}, | ||||
|     BankDebit {}, | ||||
| @ -1828,6 +1830,12 @@ pub enum AdditionalPaymentData { | ||||
|     CardToken {}, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)] | ||||
|  | ||||
| pub struct KlarnaSdkPaymentMethod { | ||||
|     pub payment_type: Option<String>, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)] | ||||
| #[serde(rename_all = "snake_case")] | ||||
| pub enum BankRedirectData { | ||||
| @ -2761,7 +2769,7 @@ where | ||||
|                 | PaymentMethodDataResponse::Crypto {} | ||||
|                 | PaymentMethodDataResponse::MandatePayment {} | ||||
|                 | PaymentMethodDataResponse::GiftCard {} | ||||
|                 | PaymentMethodDataResponse::PayLater {} | ||||
|                 | PaymentMethodDataResponse::PayLater(_) | ||||
|                 | PaymentMethodDataResponse::Paypal {} | ||||
|                 | PaymentMethodDataResponse::RealTimePayment {} | ||||
|                 | PaymentMethodDataResponse::Upi {} | ||||
| @ -2787,7 +2795,7 @@ pub enum PaymentMethodDataResponse { | ||||
|     Card(Box<CardResponse>), | ||||
|     BankTransfer {}, | ||||
|     Wallet {}, | ||||
|     PayLater {}, | ||||
|     PayLater(Box<PaylaterResponse>), | ||||
|     Paypal {}, | ||||
|     BankRedirect {}, | ||||
|     Crypto {}, | ||||
| @ -2802,6 +2810,17 @@ pub enum PaymentMethodDataResponse { | ||||
|     CardToken {}, | ||||
| } | ||||
|  | ||||
| #[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)] | ||||
| pub struct PaylaterResponse { | ||||
|     klarna_sdk: Option<KlarnaSdkPaymentMethodResponse>, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)] | ||||
|  | ||||
| pub struct KlarnaSdkPaymentMethodResponse { | ||||
|     pub payment_type: Option<String>, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, ToSchema, serde::Serialize)] | ||||
| pub struct PaymentMethodDataResponseWithBilling { | ||||
|     // The struct is flattened in order to provide backwards compatibility | ||||
| @ -3900,11 +3919,24 @@ impl From<AdditionalCardInfo> for CardResponse { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<KlarnaSdkPaymentMethod> for PaylaterResponse { | ||||
|     fn from(klarna_sdk: KlarnaSdkPaymentMethod) -> Self { | ||||
|         Self { | ||||
|             klarna_sdk: Some(KlarnaSdkPaymentMethodResponse { | ||||
|                 payment_type: klarna_sdk.payment_type, | ||||
|             }), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<AdditionalPaymentData> for PaymentMethodDataResponse { | ||||
|     fn from(payment_method_data: AdditionalPaymentData) -> Self { | ||||
|         match payment_method_data { | ||||
|             AdditionalPaymentData::Card(card) => Self::Card(Box::new(CardResponse::from(*card))), | ||||
|             AdditionalPaymentData::PayLater {} => Self::PayLater {}, | ||||
|             AdditionalPaymentData::PayLater { klarna_sdk } => match klarna_sdk { | ||||
|                 Some(sdk) => Self::PayLater(Box::new(PaylaterResponse::from(sdk))), | ||||
|                 None => Self::PayLater(Box::new(PaylaterResponse { klarna_sdk: None })), | ||||
|             }, | ||||
|             AdditionalPaymentData::Wallet { .. } => Self::Wallet {}, | ||||
|             AdditionalPaymentData::BankRedirect { .. } => Self::BankRedirect {}, | ||||
|             AdditionalPaymentData::Crypto {} => Self::Crypto {}, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Swangi Kumari
					Swangi Kumari