Address review comments

This commit is contained in:
Anurag Thakur
2025-10-16 14:58:37 +05:30
parent b6c3688690
commit 03a7cd2ef7
5 changed files with 34 additions and 20 deletions

View File

@ -5974,6 +5974,8 @@ pub struct PaymentsConfirmIntentRequest {
#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct PaymentMethodBalanceCheckRequest {
/// The payment method data to be used for the balance check request. It can
/// only be a payment method that supports checking balance e.g. gift card
pub payment_method_data: BalanceCheckPaymentMethodData,
}

View File

@ -1250,12 +1250,13 @@ impl
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
let currency = match data.request.currency {
Some(currency) => currency,
None => Err(errors::ConnectorError::MissingRequiredField {
let currency = data
.request
.currency
.get_required_value("currency")
.change_context(errors::ConnectorError::MissingRequiredField {
field_name: "currency",
})?,
};
})?;
if response.balance.currency != currency {
Ok(RouterData {

View File

@ -711,13 +711,21 @@ impl GiftCardData {
/// Payment Method Balance Check Flow for storing the balance
/// data in Redis.
///
/// For PaySafeCard, it returns a static identifier "paysafecard"
/// as currently we don't have any unique identifier for it.
pub fn get_payment_method_key(&self) -> Secret<String> {
pub fn get_payment_method_key(
&self,
) -> Result<Secret<String>, error_stack::Report<common_utils::errors::ValidationError>> {
match self {
Self::Givex(givex) => givex.number.clone(),
Self::PaySafeCard {} => Secret::new("paysafecard".to_string()),
Self::BhnCardNetwork(bhn) => bhn.account_number.clone(),
Self::Givex(givex) => Ok(givex.number.clone()),
Self::PaySafeCard {} =>
// Generate a validation error here as we don't support balance check flow for it
{
Err(error_stack::Report::new(
common_utils::errors::ValidationError::InvalidValue {
message: "PaySafeCard doesn't support balance check flow".to_string(),
},
))
}
Self::BhnCardNetwork(bhn) => Ok(bhn.account_number.clone()),
}
}
}

View File

@ -1204,14 +1204,14 @@ impl PaymentMethodBalanceKey {
/// payment method to be stored in the HashMap in Redis
#[cfg(feature = "v2")]
#[derive(Clone, Debug, serde::Serialize)]
pub struct PaymentMethodBalanceValue {
pub struct PaymentMethodBalance {
pub balance: common_utils::types::MinorUnit,
pub currency: common_enums::Currency,
}
#[cfg(feature = "v2")]
pub struct PaymentMethodBalanceData<'a> {
pub pm_balance_data: HashMap<PaymentMethodBalanceKey, PaymentMethodBalanceValue>,
pub pm_balance_data: HashMap<PaymentMethodBalanceKey, PaymentMethodBalance>,
pub payment_intent_id: &'a id_type::GlobalPaymentId,
}
@ -1232,9 +1232,7 @@ impl<'a> PaymentMethodBalanceData<'a> {
self.pm_balance_data.is_empty()
}
pub fn get_individual_pm_balance_key_value_pairs(
&self,
) -> Vec<(String, PaymentMethodBalanceValue)> {
pub fn get_individual_pm_balance_key_value_pairs(&self) -> Vec<(String, PaymentMethodBalance)> {
self.pm_balance_data
.iter()
.map(|(pm_balance_key, pm_balance_value)| {

View File

@ -163,17 +163,22 @@ pub async fn payments_check_gift_card_balance_core(
let balance = gift_card_balance.balance;
let currency = gift_card_balance.currency;
let payment_method_key = domain::GiftCardData::from(gift_card_data.clone())
.get_payment_method_key()
.change_context(errors::ApiErrorResponse::InvalidRequestData {
message: "Unable to get unique key for payment method".to_string(),
})?
.expose();
let balance_data = domain::PaymentMethodBalanceData {
payment_intent_id: &payment_intent.id,
pm_balance_data: vec![(
domain::PaymentMethodBalanceKey {
payment_method_type: common_enums::PaymentMethod::GiftCard,
payment_method_subtype: gift_card_data.get_payment_method_type(),
payment_method_key: domain::GiftCardData::from(gift_card_data)
.get_payment_method_key()
.expose(),
payment_method_key,
},
domain::PaymentMethodBalanceValue { balance, currency },
domain::PaymentMethodBalance { balance, currency },
)]
.into_iter()
.collect(),