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

@ -1433,6 +1433,9 @@ pub struct PaymentsResponse {
/// ephemeral_key for the customer_id mentioned /// ephemeral_key for the customer_id mentioned
pub ephemeral_key: Option<EphemeralKeyCreateResponse>, pub ephemeral_key: Option<EphemeralKeyCreateResponse>,
/// If true the payment can be retried with same or different payment method which means the confirm call can be made again.
pub manual_retry_allowed: Option<bool>,
/// Any user defined fields can be passed here. /// Any user defined fields can be passed here.
#[schema(value_type = Option<Object>, example = r#"{ "udf1": "some-value", "udf2": "some-value" }"#)] #[schema(value_type = Option<Object>, example = r#"{ "udf1": "some-value", "udf2": "some-value" }"#)]
pub udf: Option<pii::SecretSerdeValue>, pub udf: Option<pii::SecretSerdeValue>,

View File

@ -9,7 +9,7 @@ use common_utils::{
use error_stack::{report, IntoReport, ResultExt}; use error_stack::{report, IntoReport, ResultExt};
use josekit::jwe; use josekit::jwe;
use masking::{ExposeInterface, PeekInterface}; use masking::{ExposeInterface, PeekInterface};
use router_env::{instrument, tracing}; use router_env::{instrument, logger, tracing};
use storage_models::{enums, payment_intent}; use storage_models::{enums, payment_intent};
use time::Duration; use time::Duration;
use uuid::Uuid; 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( pub fn validate_and_add_order_details_to_payment_intent(
payment_intent: &mut storage::payment_intent::PaymentIntent, payment_intent: &mut storage::payment_intent::PaymentIntent,
request: &api::PaymentsRequest, request: &api::PaymentsRequest,

View File

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