Skip to content

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

fix(platform): add sdk_authorization support for remaining APIs (#11257)

Sandeep Kumar5548f9caaccb
diff --git a/crates/router/src/compatibility/stripe/payment_intents.rs b/crates/router/src/compatibility/stripe/payment_intents.rs
index f884b7aa95..712a264e76 100644
--- a/crates/router/src/compatibility/stripe/payment_intents.rs
+++ b/crates/router/src/compatibility/stripe/payment_intents.rs
@@ -212,10 +212,11 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
allow_platform_self_operation: false,
};
- let (auth_type, _auth_flow) = match auth::get_auth_type_and_flow(req.headers(), api_auth) {
- Ok(auth) => auth,
- Err(err) => return api::log_and_return_error_response(report!(err)),
- };
+ let (auth_type, _auth_flow) =
+ match auth::check_authorization_header_or_get_auth(req.headers(), api_auth) {
+ Ok(auth) => auth,
+ Err(err) => return api::log_and_return_error_response(report!(err)),
+ };
let flow = match json_payload.force_sync {
Some(true) => Flow::PaymentsRetrieveForceSync,
@@ -302,10 +303,11 @@ pub async fn payment_intents_update(
allow_platform_self_operation: false,
};
- let (auth_type, auth_flow) = match auth::get_auth_type_and_flow(req.headers(), api_auth) {
- Ok(auth) => auth,
- Err(err) => return api::log_and_return_error_response(report!(err)),
- };
+ let (auth_type, auth_flow) =
+ match auth::check_authorization_header_or_get_auth(req.headers(), api_auth) {
+ Ok(auth) => auth,
+ Err(err) => return api::log_and_return_error_response(report!(err)),
+ };
let flow = Flow::PaymentsUpdate;
let locking_action = payload.get_locking_input(flow.clone());
@@ -555,10 +557,11 @@ pub async fn payment_intents_cancel(
allow_platform_self_operation: false,
};
- let (auth_type, auth_flow) = match auth::get_auth_type_and_flow(req.headers(), api_auth) {
- Ok(auth) => auth,
- Err(err) => return api::log_and_return_error_response(report!(err)),
- };
+ let (auth_type, auth_flow) =
+ match auth::check_authorization_header_or_get_auth(req.headers(), api_auth) {
+ Ok(auth) => auth,
+ Err(err) => return api::log_and_return_error_response(report!(err)),
+ };
let flow = Flow::PaymentsCancel;
let locking_action = payload.get_locking_input(flow.clone());
diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs
index 99f3c81576..e23b415795 100644
--- a/crates/router/src/routes/payments.rs
+++ b/crates/router/src/routes/payments.rs
@@ -688,10 +688,11 @@ pub async fn payments_retrieve_with_gateway_creds(
allow_platform_self_operation: false,
};
- let (auth_type, _auth_flow) = match auth::get_auth_type_and_flow(req.headers(), api_auth) {
- Ok(auth) => auth,
- Err(err) => return api::log_and_return_error_response(report!(err)),
- };
+ let (auth_type, _auth_flow) =
+ match auth::check_authorization_header_or_get_auth(req.headers(), api_auth) {
+ Ok(auth) => auth,
+ Err(err) => return api::log_and_return_error_response(report!(err)),
+ };
tracing::Span::current().record("payment_id", json_payload.payment_id.get_string_repr());
@@ -717,7 +718,10 @@ pub async fn payments_retrieve_with_gateway_creds(
state,
&req,
payload,
- |state, auth, req, req_state| {
+ |state, auth, mut req, req_state| {
+ if let Some(client_secret) = auth.client_secret {
+ req.client_secret = Some(client_secret);
+ }
payments::payments_core::<
api_types::PSync,
payment_types::PaymentsResponse,
diff --git a/crates/router/src/routes/poll.rs b/crates/router/src/routes/poll.rs
index d974cf41c1..a4d2a4cd44 100644
--- a/crates/router/src/routes/poll.rs
+++ b/crates/router/src/routes/poll.rs
@@ -34,16 +34,27 @@ pub async fn retrieve_poll_status(
let poll_id = PollId {
poll_id: path.into_inner(),
};
+ // Determine auth type based on Authorization header presence
+ let auth: Box<dyn auth::AuthenticateAndFetch<auth::AuthenticationData, _>> =
+ match req.headers().get(actix_web::http::header::AUTHORIZATION) {
+ // If Authorization header is present, use SdkAuthorizationAuth
+ Some(_) => Box::new(auth::SdkAuthorizationAuth {
+ allow_connected_scope_operation: false,
+ allow_platform_self_operation: false,
+ }),
+ // If Authorization header is not present, use PublishableKeyAuth
+ None => Box::new(auth::HeaderAuth(auth::PublishableKeyAuth {
+ allow_connected_scope_operation: false,
+ allow_platform_self_operation: false,
+ })),
+ };
Box::pin(api::server_wrap(
flow,
state,
&req,
poll_id,
|state, auth, req, _| poll::retrieve_poll_status(state, req, auth.platform),
- &auth::HeaderAuth(auth::PublishableKeyAuth {
- allow_connected_scope_operation: false,
- allow_platform_self_operation: false,
- }),
+ &*auth,
api_locking::LockAction::NotApplicable,
))
.await
diff --git a/crates/router/src/routes/subscription.rs b/crates/router/src/routes/subscription.rs
index b645892459..c584e5a5e6 100644
--- a/crates/router/src/routes/subscription.rs
+++ b/crates/router/src/routes/subscription.rs
@@ -426,10 +426,11 @@ pub async fn get_estimate(
allow_connected_scope_operation: false,
allow_platform_self_operation: false,
};
- let (auth_type, _auth_flow) = match auth::get_auth_type_and_flow(req.headers(), api_auth) {
- Ok(auth) => auth,
- Err(err) => return oss_api::log_and_return_error_response(report!(err)),
- };
+ let (auth_type, _auth_flow) =
+ match auth::check_authorization_header_or_get_auth(req.headers(), api_auth) {
+ Ok(auth) => auth,
+ Err(err) => return oss_api::log_and_return_error_response(report!(err)),
+ };
Box::pin(oss_api::server_wrap(
flow,
state,