mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
fix(core): fix amount capturable in payments response (#1437)
This commit is contained in:
@ -284,7 +284,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn payment_response_update_tracker<F: Clone, T>(
|
async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
|
||||||
db: &dyn StorageInterface,
|
db: &dyn StorageInterface,
|
||||||
_payment_id: &api::PaymentIdType,
|
_payment_id: &api::PaymentIdType,
|
||||||
mut payment_data: PaymentData<F>,
|
mut payment_data: PaymentData<F>,
|
||||||
@ -428,10 +428,11 @@ async fn payment_response_update_tracker<F: Clone, T>(
|
|||||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,
|
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,
|
||||||
None => payment_data.connector_response,
|
None => payment_data.connector_response,
|
||||||
};
|
};
|
||||||
|
let amount = router_data.request.get_capture_amount();
|
||||||
|
|
||||||
let amount_captured = router_data.amount_captured.or_else(|| {
|
let amount_captured = router_data.amount_captured.or_else(|| {
|
||||||
if router_data.status == enums::AttemptStatus::Charged {
|
if router_data.status == enums::AttemptStatus::Charged {
|
||||||
Some(payment_data.payment_intent.amount)
|
amount
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@ -361,13 +361,15 @@ where
|
|||||||
})
|
})
|
||||||
.transpose()
|
.transpose()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
let amount_captured = payment_intent.amount_captured.unwrap_or_default();
|
||||||
|
let amount_capturable = Some(payment_attempt.amount - amount_captured);
|
||||||
services::ApplicationResponse::Json(
|
services::ApplicationResponse::Json(
|
||||||
response
|
response
|
||||||
.set_payment_id(Some(payment_attempt.payment_id))
|
.set_payment_id(Some(payment_attempt.payment_id))
|
||||||
.set_merchant_id(Some(payment_attempt.merchant_id))
|
.set_merchant_id(Some(payment_attempt.merchant_id))
|
||||||
.set_status(payment_intent.status.foreign_into())
|
.set_status(payment_intent.status.foreign_into())
|
||||||
.set_amount(payment_attempt.amount)
|
.set_amount(payment_attempt.amount)
|
||||||
.set_amount_capturable(None)
|
.set_amount_capturable(amount_capturable)
|
||||||
.set_amount_received(payment_intent.amount_captured)
|
.set_amount_received(payment_intent.amount_captured)
|
||||||
.set_connector(routed_through)
|
.set_connector(routed_through)
|
||||||
.set_client_secret(payment_intent.client_secret.map(masking::Secret::new))
|
.set_client_secret(payment_intent.client_secret.map(masking::Secret::new))
|
||||||
|
|||||||
@ -347,6 +347,34 @@ pub struct AccessTokenRequestData {
|
|||||||
// Add more keys if required
|
// Add more keys if required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Capturable {
|
||||||
|
fn get_capture_amount(&self) -> Option<i64> {
|
||||||
|
Some(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Capturable for PaymentsAuthorizeData {
|
||||||
|
fn get_capture_amount(&self) -> Option<i64> {
|
||||||
|
Some(self.amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Capturable for PaymentsCaptureData {
|
||||||
|
fn get_capture_amount(&self) -> Option<i64> {
|
||||||
|
Some(self.amount_to_capture)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Capturable for CompleteAuthorizeData {
|
||||||
|
fn get_capture_amount(&self) -> Option<i64> {
|
||||||
|
Some(self.amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Capturable for VerifyRequestData {}
|
||||||
|
impl Capturable for PaymentsCancelData {}
|
||||||
|
impl Capturable for PaymentsSessionData {}
|
||||||
|
impl Capturable for PaymentsSyncData {}
|
||||||
|
|
||||||
pub struct AddAccessTokenResult {
|
pub struct AddAccessTokenResult {
|
||||||
pub access_token_result: Result<Option<AccessToken>, ErrorResponse>,
|
pub access_token_result: Result<Option<AccessToken>, ErrorResponse>,
|
||||||
pub connector_supports_access_token: bool,
|
pub connector_supports_access_token: bool,
|
||||||
|
|||||||
Reference in New Issue
Block a user