fix: use non force sync workflow when payment in terminal state (#254)

This commit is contained in:
Nishant Joshi
2022-12-28 15:24:01 +05:30
committed by GitHub
parent 0280f49172
commit 7348d76cad
2 changed files with 17 additions and 24 deletions

View File

@ -994,13 +994,16 @@ pub(crate) fn validate_amount_to_capture(
) )
} }
pub fn can_call_connector(status: storage_enums::IntentStatus) -> bool { pub fn can_call_connector(status: &storage_enums::AttemptStatus) -> bool {
matches!( !matches!(
status, status,
storage_enums::IntentStatus::Failed storage_enums::AttemptStatus::Charged
| storage_enums::IntentStatus::Processing | storage_enums::AttemptStatus::AutoRefunded
| storage_enums::IntentStatus::Succeeded | storage_enums::AttemptStatus::Voided
| storage_enums::IntentStatus::RequiresCustomerAction | storage_enums::AttemptStatus::CodInitiated
| storage_enums::AttemptStatus::Authorized
| storage_enums::AttemptStatus::Started
| storage_enums::AttemptStatus::Failure
) )
} }

View File

@ -9,7 +9,7 @@ use router_env::{instrument, tracing};
use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, ValidateRequest}; use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, ValidateRequest};
use crate::{ use crate::{
core::{ core::{
errors::{self, ApiErrorResponse, CustomResult, RouterResult, StorageErrorExt}, errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments::{helpers, operations, CustomerDetails, PaymentAddress, PaymentData}, payments::{helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
}, },
db::StorageInterface, db::StorageInterface,
@ -19,7 +19,7 @@ use crate::{
storage::{self, enums}, storage::{self, enums},
transformers::ForeignInto, transformers::ForeignInto,
}, },
utils::{self, OptionExt}, utils::OptionExt,
}; };
#[derive(Debug, Clone, Copy, PaymentOperation)] #[derive(Debug, Clone, Copy, PaymentOperation)]
@ -109,7 +109,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentStatus {
&'a self, &'a self,
state: &'a AppState, state: &'a AppState,
payment_attempt: &storage::PaymentAttempt, payment_attempt: &storage::PaymentAttempt,
) -> CustomResult<(), ApiErrorResponse> { ) -> CustomResult<(), errors::ApiErrorResponse> {
helpers::add_domain_task_to_pt(self, state, payment_attempt).await helpers::add_domain_task_to_pt(self, state, payment_attempt).await
} }
@ -118,7 +118,7 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest> for PaymentStatus {
merchant_account: &storage::MerchantAccount, merchant_account: &storage::MerchantAccount,
state: &AppState, state: &AppState,
request_connector: Option<api_enums::Connector>, request_connector: Option<api_enums::Connector>,
) -> CustomResult<api::ConnectorCallType, ApiErrorResponse> { ) -> CustomResult<api::ConnectorCallType, errors::ApiErrorResponse> {
helpers::get_connector_default(merchant_account, state, request_connector).await helpers::get_connector_default(merchant_account, state, request_connector).await
} }
} }
@ -249,18 +249,6 @@ async fn get_tracker_for_sync<
let billing_address = let billing_address =
helpers::get_address_by_id(db, payment_intent.billing_address_id.clone()).await?; helpers::get_address_by_id(db, payment_intent.billing_address_id.clone()).await?;
utils::when(
request.force_sync && !helpers::can_call_connector(payment_intent.status),
|| {
Err(ApiErrorResponse::InvalidRequestData {
message: format!(
"cannot perform force_sync as status: {}",
payment_intent.status
),
})
},
)?;
let refunds = db let refunds = db
.find_refund_by_payment_id_merchant_id(&payment_id_str, merchant_id, storage_scheme) .find_refund_by_payment_id_merchant_id(&payment_id_str, merchant_id, storage_scheme)
.await .await
@ -271,7 +259,6 @@ async fn get_tracker_for_sync<
PaymentData { PaymentData {
flow: PhantomData, flow: PhantomData,
payment_intent, payment_intent,
payment_attempt,
connector_response, connector_response,
currency, currency,
amount, amount,
@ -285,7 +272,10 @@ async fn get_tracker_for_sync<
}, },
confirm: Some(request.force_sync), confirm: Some(request.force_sync),
payment_method_data: None, payment_method_data: None,
force_sync: Some(request.force_sync), force_sync: Some(
request.force_sync && helpers::can_call_connector(&payment_attempt.status),
),
payment_attempt,
refunds, refunds,
sessions_token: vec![], sessions_token: vec![],
card_cvc: None, card_cvc: None,