mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
ddress review comments
This commit is contained in:
@ -3150,28 +3150,26 @@ pub enum GiftCardData {
|
|||||||
BhnCardNetwork(BHNGiftCardDetails),
|
BhnCardNetwork(BHNGiftCardDetails),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "v2")]
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum BalanceCheckPaymentMethodData {
|
pub enum BalanceCheckPaymentMethodData {
|
||||||
GiftCard(GiftCardData),
|
GiftCard(GiftCardData),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "v2")]
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
|
||||||
pub struct ApplyPaymentMethodDataRequest {
|
pub struct ApplyPaymentMethodDataRequest {
|
||||||
pub payment_methods: Vec<BalanceCheckPaymentMethodData>,
|
pub payment_methods: Vec<BalanceCheckPaymentMethodData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "v2")]
|
|
||||||
#[derive(Debug, serde::Serialize, Clone, ToSchema)]
|
#[derive(Debug, serde::Serialize, Clone, ToSchema)]
|
||||||
pub struct ApplyPaymentMethodDataResponse {
|
pub struct ApplyPaymentMethodDataResponse {
|
||||||
pub remaining_amount: MinorUnit,
|
pub remaining_amount: MinorUnit,
|
||||||
|
#[schema(value_type = Currency)]
|
||||||
|
pub currency: common_enums::Currency,
|
||||||
pub requires_additional_pm_data: bool,
|
pub requires_additional_pm_data: bool,
|
||||||
pub surcharge_details: Option<Vec<ApplyPaymentMethodDataSurchargeResponseItem>>,
|
pub surcharge_details: Option<Vec<ApplyPaymentMethodDataSurchargeResponseItem>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "v2")]
|
|
||||||
#[derive(Debug, serde::Serialize, Clone, ToSchema)]
|
#[derive(Debug, serde::Serialize, Clone, ToSchema)]
|
||||||
pub struct ApplyPaymentMethodDataSurchargeResponseItem {
|
pub struct ApplyPaymentMethodDataSurchargeResponseItem {
|
||||||
#[schema(value_type = PaymentMethod)]
|
#[schema(value_type = PaymentMethod)]
|
||||||
|
|||||||
@ -382,6 +382,7 @@ impl AmountConvertor for MinorUnitForConnector {
|
|||||||
Hash,
|
Hash,
|
||||||
ToSchema,
|
ToSchema,
|
||||||
PartialOrd,
|
PartialOrd,
|
||||||
|
Ord,
|
||||||
)]
|
)]
|
||||||
#[diesel(sql_type = sql_types::BigInt)]
|
#[diesel(sql_type = sql_types::BigInt)]
|
||||||
pub struct MinorUnit(i64);
|
pub struct MinorUnit(i64);
|
||||||
|
|||||||
@ -27,8 +27,6 @@ pub mod external_service_auth;
|
|||||||
pub mod files;
|
pub mod files;
|
||||||
#[cfg(feature = "frm")]
|
#[cfg(feature = "frm")]
|
||||||
pub mod fraud_check;
|
pub mod fraud_check;
|
||||||
#[cfg(feature = "v2")]
|
|
||||||
pub mod gift_card;
|
|
||||||
pub mod gsm;
|
pub mod gsm;
|
||||||
pub mod health_check;
|
pub mod health_check;
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
@ -36,6 +34,8 @@ pub mod locker_migration;
|
|||||||
pub mod mandate;
|
pub mod mandate;
|
||||||
pub mod metrics;
|
pub mod metrics;
|
||||||
pub mod payment_link;
|
pub mod payment_link;
|
||||||
|
#[cfg(feature = "v2")]
|
||||||
|
pub mod payment_method_balance;
|
||||||
pub mod payment_methods;
|
pub mod payment_methods;
|
||||||
pub mod payments;
|
pub mod payments;
|
||||||
#[cfg(feature = "payouts")]
|
#[cfg(feature = "payouts")]
|
||||||
|
|||||||
@ -228,20 +228,17 @@ pub async fn payments_apply_pm_data_core(
|
|||||||
.await
|
.await
|
||||||
.attach_printable("Failed to retrieve payment method balances from redis")?;
|
.attach_printable("Failed to retrieve payment method balances from redis")?;
|
||||||
|
|
||||||
let total_balance: i64 = balances
|
let total_balance: MinorUnit = balances.values().map(|value| value.balance).sum();
|
||||||
.values()
|
|
||||||
.map(|value| value.balance.get_amount_as_i64())
|
|
||||||
.sum();
|
|
||||||
|
|
||||||
let remaining_amount = payment_intent
|
// remaining_amount cannot be negative, hence using max with 0. This situation can arise when
|
||||||
.amount_details
|
// the gift card balance exceeds the order amount
|
||||||
.order_amount
|
let remaining_amount =
|
||||||
.get_amount_as_i64()
|
(payment_intent.amount_details.order_amount - total_balance).max(MinorUnit::zero());
|
||||||
.saturating_sub(total_balance);
|
|
||||||
|
|
||||||
let resp = ApplyPaymentMethodDataResponse {
|
let resp = ApplyPaymentMethodDataResponse {
|
||||||
remaining_amount: MinorUnit::new(remaining_amount),
|
remaining_amount,
|
||||||
requires_additional_pm_data: remaining_amount > 0,
|
currency: payment_intent.amount_details.currency,
|
||||||
|
requires_additional_pm_data: remaining_amount.is_greater_than(0),
|
||||||
surcharge_details: None, // TODO: Implement surcharge recalculation logic
|
surcharge_details: None, // TODO: Implement surcharge recalculation logic
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ use router_env::{env, instrument, logger, tracing, types, Flow};
|
|||||||
|
|
||||||
use super::app::ReqState;
|
use super::app::ReqState;
|
||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
use crate::core::gift_card;
|
use crate::core::payment_method_balance;
|
||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
use crate::core::revenue_recovery::api as recovery;
|
use crate::core::revenue_recovery::api as recovery;
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -3163,15 +3163,17 @@ pub async fn payment_check_gift_card_balance(
|
|||||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||||
domain::Context(auth.merchant_account, auth.key_store),
|
domain::Context(auth.merchant_account, auth.key_store),
|
||||||
));
|
));
|
||||||
Box::pin(gift_card::payments_check_gift_card_balance_core(
|
Box::pin(
|
||||||
state,
|
payment_method_balance::payments_check_gift_card_balance_core(
|
||||||
merchant_context,
|
state,
|
||||||
auth.profile,
|
merchant_context,
|
||||||
req_state,
|
auth.profile,
|
||||||
request,
|
req_state,
|
||||||
header_payload.clone(),
|
request,
|
||||||
payment_id,
|
header_payload.clone(),
|
||||||
))
|
payment_id,
|
||||||
|
),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
},
|
},
|
||||||
auth::api_or_client_auth(
|
auth::api_or_client_auth(
|
||||||
@ -3219,7 +3221,7 @@ pub async fn payments_apply_pm_data(
|
|||||||
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
let merchant_context = domain::MerchantContext::NormalMerchant(Box::new(
|
||||||
domain::Context(auth.merchant_account, auth.key_store),
|
domain::Context(auth.merchant_account, auth.key_store),
|
||||||
));
|
));
|
||||||
Box::pin(gift_card::payments_apply_pm_data_core(
|
Box::pin(payment_method_balance::payments_apply_pm_data_core(
|
||||||
state,
|
state,
|
||||||
merchant_context,
|
merchant_context,
|
||||||
req_state,
|
req_state,
|
||||||
|
|||||||
Reference in New Issue
Block a user