feat(payments): add field manual_retry_allowed in payments response (#1298)

This commit is contained in:
Abhishek Marrivagu
2023-07-03 14:10:59 +05:30
committed by GitHub
parent b967d23251
commit 44b8da430c
3 changed files with 60 additions and 1 deletions

View File

@ -9,7 +9,7 @@ use common_utils::{
use error_stack::{report, IntoReport, ResultExt};
use josekit::jwe;
use masking::{ExposeInterface, PeekInterface};
use router_env::{instrument, tracing};
use router_env::{instrument, logger, tracing};
use storage_models::{enums, payment_intent};
use time::Duration;
use uuid::Uuid;
@ -2375,6 +2375,54 @@ impl AttemptType {
}
}
#[inline(always)]
pub fn is_manual_retry_allowed(
intent_status: &storage_enums::IntentStatus,
attempt_status: &storage_enums::AttemptStatus,
) -> Option<bool> {
match intent_status {
enums::IntentStatus::Failed => match attempt_status {
enums::AttemptStatus::Started
| enums::AttemptStatus::AuthenticationPending
| enums::AttemptStatus::AuthenticationSuccessful
| enums::AttemptStatus::Authorized
| enums::AttemptStatus::Charged
| enums::AttemptStatus::Authorizing
| enums::AttemptStatus::CodInitiated
| enums::AttemptStatus::VoidInitiated
| enums::AttemptStatus::CaptureInitiated
| enums::AttemptStatus::Unresolved
| enums::AttemptStatus::Pending
| enums::AttemptStatus::ConfirmationAwaited
| enums::AttemptStatus::PartialCharged
| enums::AttemptStatus::Voided
| enums::AttemptStatus::AutoRefunded
| enums::AttemptStatus::PaymentMethodAwaited
| enums::AttemptStatus::DeviceDataCollectionPending => {
logger::error!("Payment Attempt should not be in this state because Attempt to Intent status mapping doesn't allow it");
None
}
storage_enums::AttemptStatus::VoidFailed
| storage_enums::AttemptStatus::RouterDeclined
| storage_enums::AttemptStatus::CaptureFailed => Some(false),
storage_enums::AttemptStatus::AuthenticationFailed
| storage_enums::AttemptStatus::AuthorizationFailed
| storage_enums::AttemptStatus::Failure => Some(true),
},
enums::IntentStatus::Cancelled
| enums::IntentStatus::RequiresCapture
| enums::IntentStatus::Processing
| enums::IntentStatus::Succeeded => Some(false),
enums::IntentStatus::RequiresCustomerAction
| enums::IntentStatus::RequiresMerchantAction
| enums::IntentStatus::RequiresPaymentMethod
| enums::IntentStatus::RequiresConfirmation => None,
}
}
pub fn validate_and_add_order_details_to_payment_intent(
payment_intent: &mut storage::payment_intent::PaymentIntent,
request: &api::PaymentsRequest,

View File

@ -464,6 +464,10 @@ where
.and_then(|metadata| metadata.allowed_payment_method_types),
)
.set_ephemeral_key(ephemeral_key_option.map(ForeignFrom::foreign_from))
.set_manual_retry_allowed(helpers::is_manual_retry_allowed(
&payment_intent.status,
&payment_attempt.status,
))
.set_udf(payment_intent.udf)
.set_connector_transaction_id(payment_attempt.connector_transaction_id)
.to_owned(),
@ -508,6 +512,10 @@ where
cancellation_reason: payment_attempt.cancellation_reason,
payment_token: payment_attempt.payment_token,
metadata: payment_intent.metadata,
manual_retry_allowed: helpers::is_manual_retry_allowed(
&payment_intent.status,
&payment_attempt.status,
),
order_details: payment_intent.order_details,
udf: payment_intent.udf,
connector_transaction_id: payment_attempt.connector_transaction_id,