fix(core): introduce new attempt and intent status to handle multiple partial captures (#2802)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com>
This commit is contained in:
Hrithikesh
2023-11-17 10:04:34 +05:30
committed by GitHub
parent f735fb0551
commit cb88be01f2
46 changed files with 600 additions and 59 deletions

View File

@ -19,7 +19,10 @@ use serde::Serializer;
use crate::{
consts,
core::errors::{self, CustomResult},
core::{
errors::{self, CustomResult},
payments::PaymentData,
},
pii::PeekInterface,
types::{self, api, transformers::ForeignTryFrom, PaymentsCancelData, ResponseId},
utils::{OptionExt, ValueExt},
@ -74,6 +77,49 @@ pub trait RouterData {
#[cfg(feature = "payouts")]
fn get_quote_id(&self) -> Result<String, Error>;
}
pub trait PaymentResponseRouterData {
fn get_attempt_status_for_db_update<F>(
&self,
payment_data: &PaymentData<F>,
) -> enums::AttemptStatus
where
F: Clone;
}
impl<Flow, Request, Response> PaymentResponseRouterData
for types::RouterData<Flow, Request, Response>
where
Request: types::Capturable,
{
fn get_attempt_status_for_db_update<F>(
&self,
payment_data: &PaymentData<F>,
) -> enums::AttemptStatus
where
F: Clone,
{
match self.status {
enums::AttemptStatus::Voided => {
if payment_data.payment_intent.amount_captured > Some(0) {
enums::AttemptStatus::PartialCharged
} else {
self.status
}
}
enums::AttemptStatus::Charged => {
let captured_amount = types::Capturable::get_capture_amount(&self.request);
if Some(payment_data.payment_intent.amount) == captured_amount {
enums::AttemptStatus::Charged
} else {
enums::AttemptStatus::PartialCharged
}
}
_ => self.status,
}
}
}
pub const SELECTED_PAYMENT_METHOD: &str = "Selected payment method";
pub fn get_unimplemented_payment_method_error_message(connector: &str) -> String {