fix(core): fix amount capturable in payments response (#1437)

This commit is contained in:
Prasunna Soppa
2023-06-15 12:13:09 +05:30
committed by GitHub
parent 7db94a6208
commit 5bc1aaba59
3 changed files with 34 additions and 3 deletions

View File

@ -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,
_payment_id: &api::PaymentIdType,
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)?,
None => payment_data.connector_response,
};
let amount = router_data.request.get_capture_amount();
let amount_captured = router_data.amount_captured.or_else(|| {
if router_data.status == enums::AttemptStatus::Charged {
Some(payment_data.payment_intent.amount)
amount
} else {
None
}

View File

@ -361,13 +361,15 @@ where
})
.transpose()
.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(
response
.set_payment_id(Some(payment_attempt.payment_id))
.set_merchant_id(Some(payment_attempt.merchant_id))
.set_status(payment_intent.status.foreign_into())
.set_amount(payment_attempt.amount)
.set_amount_capturable(None)
.set_amount_capturable(amount_capturable)
.set_amount_received(payment_intent.amount_captured)
.set_connector(routed_through)
.set_client_secret(payment_intent.client_secret.map(masking::Secret::new))

View File

@ -347,6 +347,34 @@ pub struct AccessTokenRequestData {
// 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 access_token_result: Result<Option<AccessToken>, ErrorResponse>,
pub connector_supports_access_token: bool,