mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
fix: surcharge related status and rules fix (#2974)
Co-authored-by: Bernard Eugine <114725419+bernard-eugine@users.noreply.github.com>
This commit is contained in:
@ -113,7 +113,8 @@ where
|
||||
enums::AttemptStatus::Charged => {
|
||||
let captured_amount =
|
||||
types::Capturable::get_capture_amount(&self.request, payment_data);
|
||||
if Some(payment_data.payment_attempt.get_total_amount()) == captured_amount {
|
||||
let total_capturable_amount = payment_data.payment_attempt.get_total_amount();
|
||||
if Some(total_capturable_amount) == captured_amount {
|
||||
enums::AttemptStatus::Charged
|
||||
} else if captured_amount.is_some() {
|
||||
enums::AttemptStatus::PartialCharged
|
||||
|
||||
@ -1693,7 +1693,8 @@ pub(crate) fn validate_status_with_capture_method(
|
||||
field_name: "payment.status".to_string(),
|
||||
current_flow: "captured".to_string(),
|
||||
current_value: status.to_string(),
|
||||
states: "requires_capture, partially_captured, processing".to_string()
|
||||
states: "requires_capture, partially_captured_and_capturable, processing"
|
||||
.to_string()
|
||||
}))
|
||||
},
|
||||
)
|
||||
|
||||
@ -693,6 +693,15 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
|
||||
let m_error_message = error_message.clone();
|
||||
let m_db = state.clone().store;
|
||||
|
||||
let surcharge_amount = payment_data
|
||||
.surcharge_details
|
||||
.as_ref()
|
||||
.map(|surcharge_details| surcharge_details.surcharge_amount);
|
||||
let tax_amount = payment_data
|
||||
.surcharge_details
|
||||
.as_ref()
|
||||
.map(|surcharge_details| surcharge_details.tax_on_surcharge_amount);
|
||||
|
||||
let payment_attempt_fut = tokio::spawn(
|
||||
async move {
|
||||
m_db.update_payment_attempt_with_attempt_id(
|
||||
@ -716,6 +725,8 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
|
||||
amount_capturable: Some(authorized_amount),
|
||||
updated_by: storage_scheme.to_string(),
|
||||
merchant_connector_id,
|
||||
surcharge_amount,
|
||||
tax_amount,
|
||||
},
|
||||
storage_scheme,
|
||||
)
|
||||
|
||||
@ -372,8 +372,6 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
|
||||
} else {
|
||||
None
|
||||
},
|
||||
surcharge_amount: router_data.request.get_surcharge_amount(),
|
||||
tax_amount: router_data.request.get_tax_on_surcharge_amount(),
|
||||
updated_by: storage_scheme.to_string(),
|
||||
unified_code: option_gsm.clone().map(|gsm| gsm.unified_code),
|
||||
unified_message: option_gsm.map(|gsm| gsm.unified_message),
|
||||
@ -497,8 +495,6 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
|
||||
} else {
|
||||
None
|
||||
},
|
||||
surcharge_amount: router_data.request.get_surcharge_amount(),
|
||||
tax_amount: router_data.request.get_tax_on_surcharge_amount(),
|
||||
updated_by: storage_scheme.to_string(),
|
||||
authentication_data,
|
||||
encoded_data,
|
||||
|
||||
@ -382,8 +382,6 @@ where
|
||||
} else {
|
||||
None
|
||||
},
|
||||
surcharge_amount: None,
|
||||
tax_amount: None,
|
||||
updated_by: storage_scheme.to_string(),
|
||||
authentication_data,
|
||||
encoded_data,
|
||||
@ -410,8 +408,6 @@ where
|
||||
status: storage_enums::AttemptStatus::Failure,
|
||||
error_reason: Some(error_response.reason.clone()),
|
||||
amount_capturable: Some(0),
|
||||
surcharge_amount: None,
|
||||
tax_amount: None,
|
||||
updated_by: storage_scheme.to_string(),
|
||||
unified_code: option_gsm.clone().map(|gsm| gsm.unified_code),
|
||||
unified_message: option_gsm.map(|gsm| gsm.unified_message),
|
||||
|
||||
@ -551,12 +551,6 @@ pub trait Capturable {
|
||||
{
|
||||
None
|
||||
}
|
||||
fn get_surcharge_amount(&self) -> Option<i64> {
|
||||
None
|
||||
}
|
||||
fn get_tax_on_surcharge_amount(&self) -> Option<i64> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Capturable for PaymentsAuthorizeData {
|
||||
@ -570,16 +564,6 @@ impl Capturable for PaymentsAuthorizeData {
|
||||
.map(|surcharge_details| surcharge_details.final_amount);
|
||||
final_amount.or(Some(self.amount))
|
||||
}
|
||||
fn get_surcharge_amount(&self) -> Option<i64> {
|
||||
self.surcharge_details
|
||||
.as_ref()
|
||||
.map(|surcharge_details| surcharge_details.surcharge_amount)
|
||||
}
|
||||
fn get_tax_on_surcharge_amount(&self) -> Option<i64> {
|
||||
self.surcharge_details
|
||||
.as_ref()
|
||||
.map(|surcharge_details| surcharge_details.tax_on_surcharge_amount)
|
||||
}
|
||||
}
|
||||
|
||||
impl Capturable for PaymentsCaptureData {
|
||||
@ -620,7 +604,7 @@ impl Capturable for PaymentsSyncData {
|
||||
payment_data
|
||||
.payment_attempt
|
||||
.amount_to_capture
|
||||
.or(Some(payment_data.payment_attempt.get_total_amount()))
|
||||
.or_else(|| Some(payment_data.payment_attempt.get_total_amount()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -135,8 +135,6 @@ impl ProcessTrackerWorkflow<AppState> for PaymentsSyncWorkflow {
|
||||
consts::REQUEST_TIMEOUT_ERROR_MESSAGE_FROM_PSYNC.to_string(),
|
||||
)),
|
||||
amount_capturable: Some(0),
|
||||
surcharge_amount: None,
|
||||
tax_amount: None,
|
||||
updated_by: merchant_account.storage_scheme.to_string(),
|
||||
unified_code: None,
|
||||
unified_message: None,
|
||||
|
||||
Reference in New Issue
Block a user