Skip to content

Commit f1c5336

Browse files
srujanchikkeChikke SrujanNishanth ChallaAprabhat19hyperswitch-bot[bot]
authored
fix(recovery): Populate connector request reference id in revenue recovery record attempt flow. (#8434)
Co-authored-by: Chikke Srujan <[email protected]> Co-authored-by: Nishanth Challa <[email protected]> Co-authored-by: Aprabhat19 <[email protected]> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent ec6d0e4 commit f1c5336

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

crates/hyperswitch_domain_models/src/payments/payment_attempt.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,6 @@ impl PaymentAttempt {
646646
let payment_method_type_data = payment_intent.get_payment_method_type();
647647

648648
let payment_method_subtype_data = payment_intent.get_payment_method_sub_type();
649-
650649
let authentication_type = payment_intent.authentication_type.unwrap_or_default();
651650
Ok(Self {
652651
payment_id: payment_intent.id.clone(),
@@ -752,7 +751,10 @@ impl PaymentAttempt {
752751
.as_ref()
753752
.map(|txn_id| txn_id.get_id().clone());
754753
let connector = request.connector.map(|connector| connector.to_string());
755-
754+
let connector_request_reference_id = payment_intent
755+
.merchant_reference_id
756+
.as_ref()
757+
.map(|id| id.get_string_repr().to_owned());
756758
Ok(Self {
757759
payment_id: payment_intent.id.clone(),
758760
merchant_id: payment_intent.merchant_id.clone(),
@@ -804,7 +806,7 @@ impl PaymentAttempt {
804806
charges: None,
805807
processor_merchant_id: payment_intent.merchant_id.clone(),
806808
created_by: None,
807-
connector_request_reference_id: None,
809+
connector_request_reference_id,
808810
})
809811
}
810812

crates/router/src/core/payments.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,6 +4044,16 @@ where
40444044
)
40454045
.await?,
40464046
));
4047+
operation
4048+
.to_domain()?
4049+
.populate_payment_data(
4050+
state,
4051+
payment_data,
4052+
merchant_context,
4053+
business_profile,
4054+
&connector,
4055+
)
4056+
.await?;
40474057

40484058
let mut router_data = payment_data
40494059
.construct_router_data(

crates/router/src/core/payments/operations/proxy_payments_intent.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use error_stack::ResultExt;
66
use hyperswitch_domain_models::{
77
payment_method_data::PaymentMethodData, payments::PaymentConfirmData,
88
};
9+
use hyperswitch_interfaces::api::ConnectorSpecifications;
910
use masking::PeekInterface;
1011
use router_env::{instrument, tracing};
1112

@@ -15,7 +16,7 @@ use crate::{
1516
errors::{self, CustomResult, RouterResult, StorageErrorExt},
1617
payments::{
1718
operations::{self, ValidateStatusForOperation},
18-
OperationSessionGetters,
19+
OperationSessionGetters, OperationSessionSetters,
1920
},
2021
},
2122
routes::{app::ReqState, SessionState},
@@ -303,6 +304,24 @@ impl<F: Clone + Send + Sync> Domain<F, ProxyPaymentsRequest, PaymentConfirmData<
303304
)> {
304305
Ok((Box::new(self), None, None))
305306
}
307+
#[instrument(skip_all)]
308+
async fn populate_payment_data<'a>(
309+
&'a self,
310+
_state: &SessionState,
311+
payment_data: &mut PaymentConfirmData<F>,
312+
_merchant_context: &domain::MerchantContext,
313+
_business_profile: &domain::Profile,
314+
connector_data: &api::ConnectorData,
315+
) -> CustomResult<(), errors::ApiErrorResponse> {
316+
let connector_request_reference_id = connector_data
317+
.connector
318+
.generate_connector_request_reference_id(
319+
&payment_data.payment_intent,
320+
&payment_data.payment_attempt,
321+
);
322+
payment_data.set_connector_request_reference_id(Some(connector_request_reference_id));
323+
Ok(())
324+
}
306325

307326
async fn perform_routing<'a>(
308327
&'a self,

crates/router/src/routes/payments.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,17 @@ pub async fn payments_get_intent(
232232
header_payload.clone(),
233233
)
234234
},
235-
auth::api_or_client_auth(
235+
auth::api_or_client_or_jwt_auth(
236236
&auth::V2ApiKeyAuth {
237237
is_connected_allowed: false,
238238
is_platform_allowed: false,
239239
},
240240
&auth::V2ClientAuth(common_utils::types::authentication::ResourceId::Payment(
241241
global_payment_id.clone(),
242242
)),
243+
&auth::JWTAuth {
244+
permission: Permission::ProfileRevenueRecoveryRead,
245+
},
243246
req.headers(),
244247
),
245248
api_locking::LockAction::NotApplicable,

crates/router/src/services/authentication.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,27 @@ where
26982698
api_auth
26992699
}
27002700
}
2701-
2701+
#[cfg(feature = "v2")]
2702+
pub fn api_or_client_or_jwt_auth<'a, T, A>(
2703+
api_auth: &'a dyn AuthenticateAndFetch<T, A>,
2704+
client_auth: &'a dyn AuthenticateAndFetch<T, A>,
2705+
jwt_auth: &'a dyn AuthenticateAndFetch<T, A>,
2706+
headers: &HeaderMap,
2707+
) -> &'a dyn AuthenticateAndFetch<T, A>
2708+
where
2709+
{
2710+
if let Ok(val) = HeaderMapStruct::new(headers).get_auth_string_from_header() {
2711+
if val.trim().starts_with("api-key=") {
2712+
api_auth
2713+
} else if is_jwt_auth(headers) {
2714+
jwt_auth
2715+
} else {
2716+
client_auth
2717+
}
2718+
} else {
2719+
api_auth
2720+
}
2721+
}
27022722
#[derive(Debug)]
27032723
pub struct PublishableKeyAuth;
27042724

0 commit comments

Comments
 (0)