mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 09:38:33 +08:00
Address review comments
This commit is contained in:
@ -5974,6 +5974,8 @@ pub struct PaymentsConfirmIntentRequest {
|
|||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct PaymentMethodBalanceCheckRequest {
|
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,
|
pub payment_method_data: BalanceCheckPaymentMethodData,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1250,12 +1250,13 @@ impl
|
|||||||
event_builder.map(|i| i.set_response_body(&response));
|
event_builder.map(|i| i.set_response_body(&response));
|
||||||
router_env::logger::info!(connector_response=?response);
|
router_env::logger::info!(connector_response=?response);
|
||||||
|
|
||||||
let currency = match data.request.currency {
|
let currency = data
|
||||||
Some(currency) => currency,
|
.request
|
||||||
None => Err(errors::ConnectorError::MissingRequiredField {
|
.currency
|
||||||
|
.get_required_value("currency")
|
||||||
|
.change_context(errors::ConnectorError::MissingRequiredField {
|
||||||
field_name: "currency",
|
field_name: "currency",
|
||||||
})?,
|
})?;
|
||||||
};
|
|
||||||
|
|
||||||
if response.balance.currency != currency {
|
if response.balance.currency != currency {
|
||||||
Ok(RouterData {
|
Ok(RouterData {
|
||||||
|
|||||||
@ -711,13 +711,21 @@ impl GiftCardData {
|
|||||||
/// Payment Method Balance Check Flow for storing the balance
|
/// Payment Method Balance Check Flow for storing the balance
|
||||||
/// data in Redis.
|
/// data in Redis.
|
||||||
///
|
///
|
||||||
/// For PaySafeCard, it returns a static identifier "paysafecard"
|
pub fn get_payment_method_key(
|
||||||
/// as currently we don't have any unique identifier for it.
|
&self,
|
||||||
pub fn get_payment_method_key(&self) -> Secret<String> {
|
) -> Result<Secret<String>, error_stack::Report<common_utils::errors::ValidationError>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Givex(givex) => givex.number.clone(),
|
Self::Givex(givex) => Ok(givex.number.clone()),
|
||||||
Self::PaySafeCard {} => Secret::new("paysafecard".to_string()),
|
Self::PaySafeCard {} =>
|
||||||
Self::BhnCardNetwork(bhn) => bhn.account_number.clone(),
|
// 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()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1204,14 +1204,14 @@ impl PaymentMethodBalanceKey {
|
|||||||
/// payment method to be stored in the HashMap in Redis
|
/// payment method to be stored in the HashMap in Redis
|
||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
#[derive(Clone, Debug, serde::Serialize)]
|
#[derive(Clone, Debug, serde::Serialize)]
|
||||||
pub struct PaymentMethodBalanceValue {
|
pub struct PaymentMethodBalance {
|
||||||
pub balance: common_utils::types::MinorUnit,
|
pub balance: common_utils::types::MinorUnit,
|
||||||
pub currency: common_enums::Currency,
|
pub currency: common_enums::Currency,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
pub struct PaymentMethodBalanceData<'a> {
|
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,
|
pub payment_intent_id: &'a id_type::GlobalPaymentId,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1232,9 +1232,7 @@ impl<'a> PaymentMethodBalanceData<'a> {
|
|||||||
self.pm_balance_data.is_empty()
|
self.pm_balance_data.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_individual_pm_balance_key_value_pairs(
|
pub fn get_individual_pm_balance_key_value_pairs(&self) -> Vec<(String, PaymentMethodBalance)> {
|
||||||
&self,
|
|
||||||
) -> Vec<(String, PaymentMethodBalanceValue)> {
|
|
||||||
self.pm_balance_data
|
self.pm_balance_data
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(pm_balance_key, pm_balance_value)| {
|
.map(|(pm_balance_key, pm_balance_value)| {
|
||||||
|
|||||||
@ -163,17 +163,22 @@ pub async fn payments_check_gift_card_balance_core(
|
|||||||
let balance = gift_card_balance.balance;
|
let balance = gift_card_balance.balance;
|
||||||
let currency = gift_card_balance.currency;
|
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 {
|
let balance_data = domain::PaymentMethodBalanceData {
|
||||||
payment_intent_id: &payment_intent.id,
|
payment_intent_id: &payment_intent.id,
|
||||||
pm_balance_data: vec![(
|
pm_balance_data: vec![(
|
||||||
domain::PaymentMethodBalanceKey {
|
domain::PaymentMethodBalanceKey {
|
||||||
payment_method_type: common_enums::PaymentMethod::GiftCard,
|
payment_method_type: common_enums::PaymentMethod::GiftCard,
|
||||||
payment_method_subtype: gift_card_data.get_payment_method_type(),
|
payment_method_subtype: gift_card_data.get_payment_method_type(),
|
||||||
payment_method_key: domain::GiftCardData::from(gift_card_data)
|
payment_method_key,
|
||||||
.get_payment_method_key()
|
|
||||||
.expose(),
|
|
||||||
},
|
},
|
||||||
domain::PaymentMethodBalanceValue { balance, currency },
|
domain::PaymentMethodBalance { balance, currency },
|
||||||
)]
|
)]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|||||||
Reference in New Issue
Block a user