Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(revenue_recovery): queue reported transactions for the recovery report workflow (#15209)
CHALLA NISHANTH BABUb1650edc1f24
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex b81cb6e415..cbbf8737f0 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -5059,7 +5059,7 @@"content": {"application/json": {"schema": {- "$ref": "#/components/schemas/RecoveryPaymentsResponse"+ "$ref": "#/components/schemas/RecoveryPaymentsCreateResponse"},"example": {"id": "12_pay_01a3868d94a471219b5c4bc71638e2zc",@@ -5070,7 +5070,7 @@}},"400": {- "description": "Missing or invalid mandatory fields, or the invoice takes no more transactions",+ "description": "Missing or invalid mandatory fields, or, on `internal_triggers`, the invoice takes no more transactions","content": {"application/json": {"schema": {@@ -32357,6 +32357,17 @@},"additionalProperties": false},+ "RecoveryPaymentsCreateResponse": {+ "oneOf": [+ {+ "$ref": "#/components/schemas/RecoveryPaymentsResponse"+ },+ {+ "$ref": "#/components/schemas/RecoveryRequestAccepted"+ }+ ],+ "description": "The answer to a reported transaction, which depends on the `revenue_recovery_trigger_model` of\nthe profile."+ },"RecoveryPaymentsResponse": {"type": "object","required": [@@ -32386,14 +32397,28 @@"nullable": true,"maxLength": 30,"minLength": 30+ }+ }+ },+ "RecoveryRequestAccepted": {+ "type": "object",+ "description": "A transaction reported on a profile whose `revenue_recovery_trigger_model` is\n`external_triggers`, accepted to be recorded right after the answer.",+ "required": [+ "merchant_reference_id",+ "connector_transaction_id"+ ],+ "properties": {+ "merchant_reference_id": {+ "type": "string",+ "description": "Unique identifier of the invoice in the merchant's billing system against which the\ntransaction is being recorded.",+ "example": "invoice_mbabizu24mvu3mela5njyh",+ "maxLength": 30,+ "minLength": 30},- "next_retry": {- "allOf": [- {- "$ref": "#/components/schemas/RecoveryNextRetry"- }- ],- "nullable": true+ "connector_transaction_id": {+ "type": "string",+ "description": "Unique identifier of the transaction at the payment connector.",+ "example": "993672945374576J"}}},diff --git a/crates/api_models/src/events/payment.rs b/crates/api_models/src/events/payment.rsindex e4e156697f..83bc2d7d49 100644--- a/crates/api_models/src/events/payment.rs+++ b/crates/api_models/src/events/payment.rs@@ -6,8 +6,8 @@ use common_utils::id_type::GlobalPaymentMethodId;use super::{PaymentAttemptListRequest, PaymentAttemptListResponse, PaymentStartRedirectionRequest,PaymentsCreateIntentRequest, PaymentsGetIntentRequest, PaymentsIntentResponse, PaymentsRequest,- RecoveryPaymentListResponse, RecoveryPaymentsCreate, RecoveryPaymentsResponse,- RevenueRecoveryGetIntentResponse,+ RecoveryPaymentListResponse, RecoveryPaymentsCreate, RecoveryPaymentsCreateResponse,+ RecoveryPaymentsResponse, RevenueRecoveryGetIntentResponse,};#[cfg(feature = "v2")]use crate::payment_methods::{@@ -593,6 +593,13 @@ impl ApiEventMetric for RecoveryPaymentsResponse {}}+#[cfg(feature = "v2")]+impl ApiEventMetric for RecoveryPaymentsCreateResponse {+ fn get_api_event_type(&self) -> Option<ApiEventsType> {+ None+ }+}+#[cfg(feature = "v2")]impl ApiEventMetric for RecoveryPaymentListResponse {fn get_api_event_type(&self) -> Option<ApiEventsType> {diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 1ab6b6fac1..efa6eb14e9 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -2415,11 +2415,38 @@ pub struct RecoveryPaymentsResponse {example = "invoice_mbabizu24mvu3mela5njyh")]pub merchant_reference_id: Option<id_type::PaymentReferenceId>,+}- /// When to trigger the next retry of the invoice. Sent when the `revenue_recovery_trigger_model` of the profile is `external_triggers` and the transaction was made off session with the customer absent. Any other transaction is only recorded.- #[schema(value_type = Option<RecoveryNextRetry>)]- #[serde(skip_serializing_if = "Option::is_none")]- pub next_retry: Option<common_payments_types::RecoveryNextRetry>,+/// A transaction reported on a profile whose `revenue_recovery_trigger_model` is+/// `external_triggers`, accepted to be recorded right after the answer.+#[cfg(feature = "v2")]+#[derive(Debug, serde::Serialize, Clone, ToSchema)]+pub struct RecoveryRequestAccepted {+ /// Unique identifier of the invoice in the merchant's billing system against which the+ /// transaction is being recorded.+ #[schema(+ value_type = String,+ min_length = 30,+ max_length = 30,+ example = "invoice_mbabizu24mvu3mela5njyh"+ )]+ pub merchant_reference_id: id_type::PaymentReferenceId,++ /// Unique identifier of the transaction at the payment connector.+ #[schema(example = "993672945374576J")]+ pub connector_transaction_id: String,+}++/// The answer to a reported transaction, which depends on the `revenue_recovery_trigger_model` of+/// the profile.+#[cfg(feature = "v2")]+#[derive(Debug, serde::Serialize, Clone, ToSchema)]+#[serde(untagged)]+pub enum RecoveryPaymentsCreateResponse {+ /// On `internal_triggers`, the transaction is recorded before the answer.+ Recorded(RecoveryPaymentsResponse),+ /// On `external_triggers`, the transaction is recorded after the answer.+ Accepted(RecoveryRequestAccepted),}/// The next retry of an invoice whose retries the merchant triggers, sent by webhook after eachdiff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex e32488246c..a0a46bea39 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -1031,6 +1031,8 @@ Never share your secret api keys. Keep them guarded and secure.api_models::process_tracker::revenue_recovery::RevenueRecoveryResponse,api_models::payments::RecoveryPaymentsCreate,api_models::payments::RecoveryPaymentsResponse,+ api_models::payments::RecoveryRequestAccepted,+ api_models::payments::RecoveryPaymentsCreateResponse,api_models::payments::RecoveryRetryWebhookDetails,api_models::payments::CustomRecoveryPaymentMethodData,api_models::payments::AdditionalCardInfo,diff --git a/crates/openapi/src/routes/revenue_recovery.rs b/crates/openapi/src/routes/revenue_recovery.rsindex 05304b9c9b..fb4339a665 100644--- a/crates/openapi/src/routes/revenue_recovery.rs+++ b/crates/openapi/src/routes/revenue_recovery.rs@@ -151,14 +151,14 @@ pub async fn revenue_recovery_pt_retrieve_api() {}(status = 200,description = "Revenue Recovery Transaction Recorded Successfully",- body = RecoveryPaymentsResponse,+ body = RecoveryPaymentsCreateResponse,example = json!({"id": "12_pay_01a3868d94a471219b5c4bc71638e2zc","intent_status": "failed","merchant_reference_id": "invoice_mbabizu24mvu3mela5njyh"})),- (status = 400, description = "Missing or invalid mandatory fields, or the invoice takes no more transactions", body = GenericErrorResponseOpenApi),+ (status = 400, description = "Missing or invalid mandatory fields, or, on `internal_triggers`, the invoice takes no more transactions", body = GenericErrorResponseOpenApi),(status = 404, description = "Resource missing"),(status = 500, description = "Internal server error"),),diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.tomlindex 1961674519..3eb4723052 100644--- a/crates/router/Cargo.toml+++ b/crates/router/Cargo.toml@@ -269,7 +269,7 @@ rustls = { version = "0.23", default-features = false, features = [] }rustls-pemfile = "2"serde = { version = "1.0.219", features = ["derive"] }-serde_json = "1.0.140"+serde_json = { version = "1.0.140", features = ["raw_value"] }serde_path_to_error = "0.1.17"serde_qs = "0.12.0"serde_with = "3.12.0"diff --git a/crates/router/src/core/revenue_recovery/api.rs b/crates/router/src/core/revenue_recovery/api.rsindex 48b8612161..9be75f8422 100644--- a/crates/router/src/core/revenue_recovery/api.rs+++ b/crates/router/src/core/revenue_recovery/api.rs@@ -4,6 +4,7 @@ use common_types::payments::{RecoveryConnectorAccounts, RecoveryConnectorDetailsuse common_utils::id_type;use error_stack::{report, FutureExt, ResultExt};use hyperswitch_domain_models::{payments as payments_domain, platform::Platform};+use hyperswitch_masking::Secret;use super::{external_triggers, trigger_model::RecoveryTrigger};use crate::{@@ -310,11 +311,12 @@ pub async fn custom_revenue_recovery_core(platform: Platform,profile: domain::Profile,request: api_models::payments::RecoveryPaymentsCreate,-) -> RouterResponse<payments_api::RecoveryPaymentsResponse> {+ request_body: Secret<String>,+) -> RouterResponse<payments_api::RecoveryPaymentsCreateResponse> {validate_recovery_amounts(&request)?;validate_customer_information(&request)?;- let (updated_recovery_intent, next_retry) = match RecoveryTrigger::from_profile_settings(+ let response = match RecoveryTrigger::from_profile_settings(profile.revenue_recovery_trigger_model,profile.revenue_recovery_config.as_ref(),&request,@@ -333,27 +335,31 @@ pub async fn custom_revenue_recovery_core(&payment_merchant_connector_id,)).await?;- (updated_recovery_intent, None)+ payments_api::RecoveryPaymentsCreateResponse::Recorded(+ payments_api::RecoveryPaymentsResponse {+ id: updated_recovery_intent.payment_id,+ intent_status: updated_recovery_intent.status,+ merchant_reference_id: updated_recovery_intent.merchant_reference_id,+ },+ )}- RecoveryTrigger::External {- connector,- retry_config,- } => {- Box::pin(external_triggers::record_transaction_and_get_next_retry(- &state,- &req_state,- &platform,- &profile,- &request,- connector,- retry_config,- ))- .await?+ RecoveryTrigger::External { connector } => {+ payments_api::RecoveryPaymentsCreateResponse::Accepted(+ Box::pin(external_triggers::accept_recovery_request(+ &state,+ &platform,+ &profile,+ &request,+ &request_body,+ connector,+ ))+ .await?,+ )}};Ok(hyperswitch_domain_models::api::ApplicationResponse::Json(- get_recovery_payments_response(&updated_recovery_intent, next_retry),+ response,))}@@ -468,18 +474,6 @@ async fn record_transaction_and_schedule_retries(Ok(updated_recovery_intent)}-fn get_recovery_payments_response(- recovery_intent: &hyperswitch_domain_models::revenue_recovery::RecoveryPaymentIntent,- next_retry: Option<common_types::payments::RecoveryNextRetry>,-) -> payments_api::RecoveryPaymentsResponse {- payments_api::RecoveryPaymentsResponse {- id: recovery_intent.payment_id.to_owned(),- intent_status: recovery_intent.status.to_owned(),- merchant_reference_id: recovery_intent.merchant_reference_id.to_owned(),- next_retry,- }-}-/// Finds or creates the invoice of the transaction.pub(super) async fn get_or_create_invoice(state: &SessionState,@@ -506,7 +500,7 @@ pub(super) async fn get_or_create_invoice(}/// Records the transaction against the invoice.-pub(super) async fn record_transaction(+async fn record_transaction(state: &SessionState,req_state: &ReqState,platform: &Platform,@@ -588,13 +582,14 @@ pub async fn cancel_revenue_recovery_core(})})?;+ let response = api_payments::RecoveryPaymentsResponse {+ id: cancelled_intent.id,+ intent_status: cancelled_intent.status,+ merchant_reference_id: cancelled_intent.merchant_reference_id,+ };+Ok(hyperswitch_domain_models::api::ApplicationResponse::Json(- get_recovery_payments_response(- &hyperswitch_domain_models::revenue_recovery::RecoveryPaymentIntent::from(- &cancelled_intent,- ),- cancelled_intent.get_external_trigger_next_retry(),- ),+ response,))}diff --git a/crates/router/src/core/revenue_recovery/external_triggers.rs b/crates/router/src/core/revenue_recovery/external_triggers.rsindex ffc98f51e8..36029a1bfd 100644--- a/crates/router/src/core/revenue_recovery/external_triggers.rs+++ b/crates/router/src/core/revenue_recovery/external_triggers.rs@@ -13,11 +13,11 @@ use common_utils::{types::keymanager,};use diesel_models::{business_profile::RevenueRecoveryConfig, process_tracker::business_status};-use error_stack::{report, ResultExt};+use error_stack::ResultExt;use hyperswitch_domain_models::{payments::{get_next_retry_for_intent_status, PaymentIntent, PaymentIntentData},platform::Platform,- revenue_recovery::{RecoveryPaymentAttempt, RecoveryPaymentIntent},+ revenue_recovery::RecoveryPaymentAttempt,type_encryption::{crypto_operation, CryptoOperation},ApiModelToDieselModelConvertor,};@@ -36,7 +36,7 @@ use crate::{core::{api_locking::{LockAction, LockingInput},configs::dimension_state::{self, DimensionsWithProcessorMerchantIdAndConnector},- errors::{self, RouterResult, StorageErrorExt},+ errors::{self, RouterResult},payments::{self,operations::{@@ -45,7 +45,7 @@ use crate::{},webhooks::recovery_incoming::RevenueRecoveryAttempt,},- routes::{app::ReqState, lock_utils, metrics, SessionState},+ routes::{lock_utils, metrics, SessionState},types::{api as api_types, domain,storage::{@@ -93,166 +93,6 @@ impl NextRetryDecision {}}-/// Records a transaction the merchant reports and, when it was made off session with the customer-/// absent, works out when they should trigger the next retry. The reports of an invoice are handled-/// one at a time, as each one builds on the state the last one left, and no connector sync is there-/// to correct a report handled out of turn.-pub(super) async fn record_transaction_and_get_next_retry(- state: &SessionState,- req_state: &ReqState,- platform: &Platform,- profile: &domain::Profile,- request: &RecoveryPaymentsCreate,- connector: RecoveryConnector,- retry_config: &RevenueRecoveryConfig,-) -> RouterResult<(RecoveryPaymentIntent, Option<RecoveryNextRetry>)> {- let invoice_lock = LockAction::Hold {- input: LockingInput {- unique_locking_key: request.merchant_reference_id.get_string_repr().to_owned(),- api_identifier: lock_utils::ApiIdentifier::Payments,- override_lock_retries: None,- },- };- let merchant_id = platform.get_processor().get_account().get_id().to_owned();-- invoice_lock- .clone()- .perform_locking_action(state, merchant_id.clone())- .await?;-- let result = Box::pin(handle_merchant_report(- state,- req_state,- platform,- profile,- request,- connector,- retry_config,- ))- .await;-- if let Err(error) = invoice_lock.free_lock_action(state, merchant_id).await {- logger::error!(?error, "Failed to release the lock of the invoice");- }-- result-}--/// Records the transaction and decides the next retry. A transaction made on session or with the-/// customer present is only recorded: it is not a retry, so what the invoice last told the merchant-/// stays as it was.-///-/// Once the transaction is recorded the merchant must get an answer, because reporting it again is-/// refused as a duplicate. So the steps after recording log their failures rather than fail the-/// request, apart from reading the invoice back, which fails only if the database just went away.-async fn handle_merchant_report(- state: &SessionState,- req_state: &ReqState,- platform: &Platform,- profile: &domain::Profile,- request: &RecoveryPaymentsCreate,- connector: RecoveryConnector,- retry_config: &RevenueRecoveryConfig,-) -> RouterResult<(RecoveryPaymentIntent, Option<RecoveryNextRetry>)> {- // A value sent in the request takes priority over the one on the profile.- let request = &RecoveryPaymentsCreate {- enable_partial_authorization: request- .enable_partial_authorization- .or(Some(retry_config.enable_partial_authorization.into())),- ..request.clone()- };-- let invoice = api::get_or_create_invoice(state, req_state, platform, profile, request).await?;-- PaymentAttemptRecord- .validate_status_for_operation(invoice.status)- .map_err(|_| {- report!(errors::ApiErrorResponse::PreconditionFailed {- message: format!(- "The invoice is `{}` and takes no more transactions",- invoice.status- ),- })- })?;-- let previous_recovery_metadata = invoice- .feature_metadata- .as_ref()- .and_then(|feature_metadata| feature_metadata.revenue_recovery.as_ref());- let is_existing_invoice = previous_recovery_metadata.is_some();- let is_same_card = previous_recovery_metadata.is_some_and(|recovery_metadata| {- recovery_metadata- .billing_connector_payment_details- .payment_processor_token- == *request- .payment_method_data- .primary_processor_payment_method_token- .peek()- });- let previous_trigger_state = previous_recovery_metadata- .and_then(|recovery_metadata| recovery_metadata.external_trigger_state.clone());-- let (recovery_attempt, _) = Box::pin(api::record_transaction(- state,- req_state,- platform,- profile,- request,- &invoice,- &RecoveryConnectorDetails::ReportedByMerchant {- connector: connector.into(),- },- ))- .await?;-- let is_merchant_initiated = request- .customer_present- .unwrap_or(common_enums::PresenceOfCustomerDuringPayment::Absent)- == common_enums::PresenceOfCustomerDuringPayment::Absent- && request- .setup_future_usage- .unwrap_or(common_enums::FutureUsage::OffSession)- .is_off_session();-- reset_card_history_after_a_charge(state, request).await;-- let payment_intent = read_invoice(state, platform, profile, &invoice.payment_id).await?;- let updated_invoice = RecoveryPaymentIntent::from(&payment_intent);-- if !is_merchant_initiated {- return Ok((updated_invoice, None));- }-- let (trigger_state, assigned_ab_algorithm) = Box::pin(decide_recovery_request_retry(- state,- platform,- profile,- retry_config,- request,- &recovery_attempt,- &payment_intent,- previous_trigger_state.as_ref(),- is_existing_invoice,- is_same_card,- ))- .await;- let next_retry = trigger_state.next_retry;- if let Err(error) = save_trigger_state(- state,- platform,- profile,- payment_intent,- trigger_state,- assigned_ab_algorithm,- )- .await- {- logger::error!(?error, "Failed to save the recovery state of the invoice");- }-- Ok((updated_invoice, Some(next_retry)))-}-/// The recovery state of an invoice after a merchant-initiated recovery request: its next retry/// and what the request after it needs, with the A/B arm the decision assigned. The request/// markers are left for the caller.@@ -814,19 +654,51 @@ fn reason_name(reason: RecoveryNoRetryReason) -> &'static str {}}+/// Accepts a transaction the merchant reported and queues it for the recovery request workflow,+/// which records it. The invoice is not read here: the workflow refuses one that takes no more+/// transactions, which also covers an invoice that closes while the recovery request waits.+pub(super) async fn accept_recovery_request(+ state: &SessionState,+ platform: &Platform,+ profile: &domain::Profile,+ request: &RecoveryPaymentsCreate,+ request_body: &Secret<String>,+ connector: RecoveryConnector,+) -> RouterResult<api_models::payments::RecoveryRequestAccepted> {+ queue_recovery_request(state, platform, profile, request, request_body, connector)+ .await+ .inspect_err(|error| {+ record_received_recovery_request(match error.current_context() {+ errors::ApiErrorResponse::GenericDuplicateError { .. } => "duplicate",+ _ => "failed",+ })+ })?;+ record_received_recovery_request("queued");++ Ok(api_models::payments::RecoveryRequestAccepted {+ merchant_reference_id: request.merchant_reference_id.clone(),+ connector_transaction_id: request.connector_transaction_id.clone(),+ })+}++fn record_received_recovery_request(outcome: &'static str) {+ metrics::REVENUE_RECOVERY_REQUEST_RECEIVED+ .add(1, router_env::metric_attributes!(("outcome", outcome)));+}+/// Queues a transaction the merchant reported, to be recorded and answered by the recovery request-/// workflow, and returns the recovery request's id, which its job id is built from. A transaction+/// workflow, under the recovery request's id, which its job id is built from. A transaction/// already reported in the profile is refused, as its job id is taken, whatever became of that/// job. The job keeps `request_body`, the request exactly as the merchant sent it, and reads/// `request` back from it.-pub(crate) async fn queue_recovery_request(+async fn queue_recovery_request(state: &SessionState,platform: &Platform,profile: &domain::Profile,request: &RecoveryPaymentsCreate,request_body: &Secret<String>,connector: RecoveryConnector,-) -> RouterResult<String> {+) -> RouterResult<()> {let recovery_request_id = get_recovery_request_id(profile.get_id(),&request.merchant_reference_id,@@ -890,7 +762,7 @@ pub(crate) async fn queue_recovery_request(connector_transaction_id = %request.connector_transaction_id,"Recovery request queued");- Ok(recovery_request_id)+ Ok(())}/// The id of a recovery request, the same for every request for a transaction: the profile, thediff --git a/crates/router/src/core/revenue_recovery/trigger_model.rs b/crates/router/src/core/revenue_recovery/trigger_model.rsindex 9a7ca0a351..2f32b7a1ce 100644--- a/crates/router/src/core/revenue_recovery/trigger_model.rs+++ b/crates/router/src/core/revenue_recovery/trigger_model.rs@@ -13,23 +13,20 @@ use crate::{/// start of the API. The model comes from the profile alone. The fields of the request are only/// checked against it, and from here on each model has exactly what it needs.#[derive(Debug)]-pub(super) enum RecoveryTrigger<'a> {+pub(super) enum RecoveryTrigger {/// Hyperswitch triggers the retries through these connector accounts.Internal {billing_merchant_connector_id: id_type::MerchantConnectorAccountId,payment_merchant_connector_id: id_type::MerchantConnectorAccountId,},- /// The merchant triggers the retries on this processor, within these limits.- External {- connector: RecoveryConnector,- retry_config: &'a RevenueRecoveryConfig,- },+ /// The merchant triggers the retries on this processor, within the limits of the profile.+ External { connector: RecoveryConnector },}-impl<'a> RecoveryTrigger<'a> {+impl RecoveryTrigger {pub(super) fn from_profile_settings(trigger_model: common_enums::RevenueRecoveryTriggerModel,- retry_config: Option<&'a RevenueRecoveryConfig>,+ retry_config: Option<&RevenueRecoveryConfig>,request: &RecoveryPaymentsCreate,) -> RouterResult<Self> {match trigger_model {@@ -52,16 +49,13 @@ impl<'a> RecoveryTrigger<'a> {let connector = request.connector.get_required_value("connector")?;// Profiles are refused without it, this holds for one saved before that check.- let retry_config = retry_config.ok_or_else(|| {+ retry_config.ok_or_else(|| {report!(errors::ApiErrorResponse::PreconditionFailed {message: "The `revenue_recovery_config` of the profile is required when its `revenue_recovery_trigger_model` is `external_triggers`".to_owned(),})})?;- Ok(Self::External {- connector,- retry_config,- })+ Ok(Self::External { connector })}}}diff --git a/crates/router/src/core/webhooks/recovery_incoming.rs b/crates/router/src/core/webhooks/recovery_incoming.rsindex 8edbefcb90..c38ea593cc 100644--- a/crates/router/src/core/webhooks/recovery_incoming.rs+++ b/crates/router/src/core/webhooks/recovery_incoming.rs@@ -341,6 +341,7 @@ impl RevenueRecoveryInvoice {}).await}+/// Fills in partial authorization from the billing connector account when the invoice/// itself does not carry a value.fn with_default_partial_authorization(mut self, default: bool) -> Self {diff --git a/crates/router/src/routes/metrics.rs b/crates/router/src/routes/metrics.rsindex 29887afe71..7c2de5bdb3 100644--- a/crates/router/src/routes/metrics.rs+++ b/crates/router/src/routes/metrics.rs@@ -382,6 +382,16 @@ counter_metric!(unit: "1",);+counter_metric!(+ REVENUE_RECOVERY_REQUEST_RECEIVED,+ GLOBAL_METER,+ name: "revenue_recovery.recovery_request.received",+ description: "Recovery requests by how the API answered them (queued; duplicate, refused as \+ the transaction is already reported; failed, answered with an error so the \+ merchant sends the recovery request again). Every queued request ends in one \+ `revenue_recovery.recovery_request.outcome`",+ unit: "1",+);counter_metric!(REVENUE_RECOVERY_REQUEST_OUTCOME,GLOBAL_METER,diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rsindex 43651c1b2e..aa660f18c3 100644--- a/crates/router/src/routes/payments.rs+++ b/crates/router/src/routes/payments.rs@@ -327,10 +327,23 @@ pub async fn payment_link_create(pub async fn recovery_payments_create(state: web::Data<app::AppState>,req: actix_web::HttpRequest,- json_payload: web::Json<payment_types::RecoveryPaymentsCreate>,+ json_payload: web::Json<Box<serde_json::value::RawValue>>,) -> impl Responder {let flow = Flow::RecoveryPaymentsCreate;- let mut payload = json_payload.into_inner();+ let request_body = json_payload.into_inner();+ let payload =+ match serde_json::from_str::<payment_types::RecoveryPaymentsCreate>(request_body.get()) {+ Ok(payload) => payload,+ Err(error) => {+ return actix_web::HttpResponse::from_error(+ crate::utils::error_parser::custom_json_error_handler(+ actix_web::error::JsonPayloadError::Deserialize(error),+ &req,+ ),+ );+ }+ };+ let request_body = Secret::new(request_body.get().to_owned());Box::pin(api::server_wrap(flow,state,@@ -343,6 +356,7 @@ pub async fn recovery_payments_create(auth.platform,auth.profile,req_payload,+ request_body.clone(),)},&auth::V2ApiKeyAuth {