feat(revenue_recovery): Invoke attempt list instead of payment get in recovery webhooks flow (#8393)

Co-authored-by: Aniket Burman <aniket.burman@Aniket-Burman-JDXHW2PH34.local>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Aniket Burman <93077964+aniketburman014@users.noreply.github.com>
Co-authored-by: Chikke Srujan <chikke.srujan@Chikke-Srujan-V9P7D4K9V0.local>
This commit is contained in:
chikke srujan
2025-06-20 01:24:09 -07:00
committed by GitHub
parent 7943fb4bfb
commit fc72c3eee8
14 changed files with 99 additions and 49 deletions

View File

@ -4989,6 +4989,7 @@ impl
let revenue_recovery = feature_metadata.revenue_recovery.as_ref().map(|recovery| {
api_models::payments::PaymentAttemptRevenueRecoveryData {
attempt_triggered_by: recovery.attempt_triggered_by,
charge_id: recovery.charge_id.clone(),
}
});
Self { revenue_recovery }

View File

@ -1539,7 +1539,7 @@ pub async fn push_metrics_with_update_window_for_contract_based_routing(
routing_events::RoutingEngine::IntelligentRouter,
routing_events::ApiMethod::Grpc)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("ContractRouting-Intelligent-Router: Failed to contruct RoutingEventsBuilder")?
.attach_printable("ContractRouting-Intelligent-Router: Failed to construct RoutingEventsBuilder")?
.trigger_event(state, closure)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)

View File

@ -467,45 +467,49 @@ impl RevenueRecoveryAttempt {
)>,
errors::RevenueRecoveryError,
> {
let attempt_response = Box::pin(payments::payments_core::<
router_flow_types::payments::PSync,
api_payments::PaymentsResponse,
_,
_,
_,
hyperswitch_domain_models::payments::PaymentStatusData<
router_flow_types::payments::PSync,
>,
>(
state.clone(),
req_state.clone(),
merchant_context.clone(),
profile.clone(),
payments::operations::PaymentGet,
api_payments::PaymentsRetrieveRequest {
force_sync: false,
expand_attempts: true,
param: None,
all_keys_required: None,
merchant_connector_details: None,
},
payment_intent.payment_id.clone(),
payments::CallConnectorAction::Avoid,
hyperswitch_domain_models::payments::HeaderPayload::default(),
))
.await;
let attempt_response =
Box::pin(payments::payments_list_attempts_using_payment_intent_id::<
payments::operations::PaymentGetListAttempts,
api_payments::PaymentAttemptListResponse,
_,
payments::operations::payment_attempt_list::PaymentGetListAttempts,
hyperswitch_domain_models::payments::PaymentAttemptListData<
payments::operations::PaymentGetListAttempts,
>,
>(
state.clone(),
req_state.clone(),
merchant_context.clone(),
profile.clone(),
payments::operations::PaymentGetListAttempts,
api_payments::PaymentAttemptListRequest {
payment_intent_id: payment_intent.payment_id.clone(),
},
payment_intent.payment_id.clone(),
hyperswitch_domain_models::payments::HeaderPayload::default(),
))
.await;
let response = match attempt_response {
Ok(services::ApplicationResponse::JsonWithHeaders((payments_response, _))) => {
let final_attempt =
self.0
.connector_transaction_id
.as_ref()
.and_then(|transaction_id| {
payments_response
.find_attempt_in_attempts_list_using_connector_transaction_id(
transaction_id,
)
});
let final_attempt = self
.0
.charge_id
.as_ref()
.map(|charge_id| {
payments_response
.find_attempt_in_attempts_list_using_charge_id(charge_id.clone())
})
.unwrap_or_else(|| {
self.0
.connector_transaction_id
.as_ref()
.and_then(|transaction_id| {
payments_response
.find_attempt_in_attempts_list_using_connector_transaction_id(
transaction_id,
)
})
});
let payment_attempt =
final_attempt.map(|attempt_res| revenue_recovery::RecoveryPaymentAttempt {
attempt_id: attempt_res.id.to_owned(),
@ -613,6 +617,7 @@ impl RevenueRecoveryAttempt {
revenue_recovery: Some(api_payments::PaymentAttemptRevenueRecoveryData {
// Since we are recording the external paymenmt attempt, this is hardcoded to External
attempt_triggered_by: triggered_by,
charge_id: self.0.charge_id.clone(),
}),
};