mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
fix: handle session and confirm flow discrepancy in surcharge details (#2696)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -16,6 +16,7 @@ use crate::{
|
||||
admin, disputes,
|
||||
enums::{self as api_enums},
|
||||
ephemeral_key::EphemeralKeyCreateResponse,
|
||||
payment_methods::{Surcharge, SurchargeDetailsResponse},
|
||||
refunds,
|
||||
};
|
||||
|
||||
@ -319,6 +320,23 @@ pub struct RequestSurchargeDetails {
|
||||
pub tax_amount: Option<i64>,
|
||||
}
|
||||
|
||||
impl RequestSurchargeDetails {
|
||||
pub fn is_surcharge_zero(&self) -> bool {
|
||||
self.surcharge_amount == 0 && self.tax_amount.unwrap_or(0) == 0
|
||||
}
|
||||
pub fn get_surcharge_details_object(&self, original_amount: i64) -> SurchargeDetailsResponse {
|
||||
let surcharge_amount = self.surcharge_amount;
|
||||
let tax_on_surcharge_amount = self.tax_amount.unwrap_or(0);
|
||||
SurchargeDetailsResponse {
|
||||
surcharge: Surcharge::Fixed(self.surcharge_amount),
|
||||
tax_on_surcharge: None,
|
||||
surcharge_amount,
|
||||
tax_on_surcharge_amount,
|
||||
final_amount: original_amount + surcharge_amount + tax_on_surcharge_amount,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
pub struct HeaderPayload {
|
||||
pub payment_confirm_source: Option<api_enums::PaymentSource>,
|
||||
@ -810,6 +828,36 @@ pub enum PaymentMethodData {
|
||||
GiftCard(Box<GiftCardData>),
|
||||
}
|
||||
|
||||
impl PaymentMethodData {
|
||||
pub fn get_payment_method_type_if_session_token_type(
|
||||
&self,
|
||||
) -> Option<api_enums::PaymentMethodType> {
|
||||
match self {
|
||||
Self::Wallet(wallet) => match wallet {
|
||||
WalletData::ApplePay(_) => Some(api_enums::PaymentMethodType::ApplePay),
|
||||
WalletData::GooglePay(_) => Some(api_enums::PaymentMethodType::GooglePay),
|
||||
WalletData::PaypalSdk(_) => Some(api_enums::PaymentMethodType::Paypal),
|
||||
_ => None,
|
||||
},
|
||||
Self::PayLater(pay_later) => match pay_later {
|
||||
PayLaterData::KlarnaSdk { .. } => Some(api_enums::PaymentMethodType::Klarna),
|
||||
_ => None,
|
||||
},
|
||||
Self::Card(_)
|
||||
| Self::CardRedirect(_)
|
||||
| Self::BankRedirect(_)
|
||||
| Self::BankDebit(_)
|
||||
| Self::BankTransfer(_)
|
||||
| Self::Crypto(_)
|
||||
| Self::MandatePayment
|
||||
| Self::Reward
|
||||
| Self::Upi(_)
|
||||
| Self::Voucher(_)
|
||||
| Self::GiftCard(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GetPaymentMethodType {
|
||||
fn get_payment_method_type(&self) -> api_enums::PaymentMethodType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user