Skip to content

Commit

Permalink
fix: Set headers as optional in ob flows (#6305)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 authored Oct 17, 2024
1 parent 2798f57 commit 9576ee3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 55 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ crates/euclid @juspay/hyperswitch-routing
crates/euclid_macros @juspay/hyperswitch-routing
crates/euclid_wasm @juspay/hyperswitch-routing
crates/kgraph_utils @juspay/hyperswitch-routing
crates/pm_auth @juspay/hyperswitch-routing
crates/router/src/routes/routing.rs @juspay/hyperswitch-routing
crates/router/src/core/routing @juspay/hyperswitch-routing
crates/router/src/core/routing.rs @juspay/hyperswitch-routing
Expand Down
5 changes: 0 additions & 5 deletions crates/api_models/src/pm_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use common_utils::{
id_type, impl_api_event_type,
};

use crate::enums as api_enums;

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub struct LinkTokenCreateRequest {
Expand All @@ -14,9 +12,6 @@ pub struct LinkTokenCreateRequest {
pub payment_id: id_type::PaymentId, // payment_id to be passed in req body for redis pm_auth connector name fetch
pub payment_method: PaymentMethod, // payment_method to be used for filtering pm_auth connector
pub payment_method_type: PaymentMethodType, // payment_method_type to be used for filtering pm_auth connector
pub client_platform: api_enums::ClientPlatform, // Client Platform to perform platform based processing
pub android_package_name: Option<String>, // Android Package name to be sent for Android platform
pub redirect_uri: Option<String>, // Merchant redirect_uri to be sent in case of IOS platform
}

#[derive(Debug, Clone, serde::Serialize)]
Expand Down
30 changes: 11 additions & 19 deletions crates/pm_auth/src/connector/plaid/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,20 @@ impl TryFrom<&types::LinkTokenRouterData> for PlaidLinkTokenRequest {
)?,
},
android_package_name: match item.request.client_platform {
api_models::enums::ClientPlatform::Android => {
Some(item.request.android_package_name.clone().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "android_package_name",
},
)?)
Some(api_models::enums::ClientPlatform::Android) => {
item.request.android_package_name.clone()
}
api_models::enums::ClientPlatform::Ios
| api_models::enums::ClientPlatform::Web
| api_models::enums::ClientPlatform::Unknown => None,
Some(api_models::enums::ClientPlatform::Ios)
| Some(api_models::enums::ClientPlatform::Web)
| Some(api_models::enums::ClientPlatform::Unknown)
| None => None,
},
redirect_uri: match item.request.client_platform {
api_models::enums::ClientPlatform::Ios => {
Some(item.request.redirect_uri.clone().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "redirect_uri",
},
)?)
}
api_models::enums::ClientPlatform::Android
| api_models::enums::ClientPlatform::Web
| api_models::enums::ClientPlatform::Unknown => None,
Some(api_models::enums::ClientPlatform::Ios) => item.request.redirect_uri.clone(),
Some(api_models::enums::ClientPlatform::Android)
| Some(api_models::enums::ClientPlatform::Web)
| Some(api_models::enums::ClientPlatform::Unknown)
| None => None,
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pm_auth/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct LinkTokenRequest {
pub country_codes: Option<Vec<String>>,
pub language: Option<String>,
pub user_info: Option<id_type::CustomerId>,
pub client_platform: api_enums::ClientPlatform,
pub client_platform: Option<api_enums::ClientPlatform>,
pub android_package_name: Option<String>,
pub redirect_uri: Option<String>,
}
Expand Down
34 changes: 12 additions & 22 deletions crates/router/src/connector/plaid/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,15 @@ impl TryFrom<&types::PaymentsPostProcessingRouterData> for PlaidLinkTokenRequest
match item.request.payment_method_data {
domain::PaymentMethodData::OpenBanking(ref data) => match data {
domain::OpenBankingData::OpenBankingPIS { .. } => {
let headers = item.header_payload.clone().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "header_payload",
},
)?;
let headers = item.header_payload.clone();

let platform = headers.x_client_platform.ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "x_client_platform",
},
)?;
let platform = headers
.as_ref()
.and_then(|headers| headers.x_client_platform.clone());

let (is_android, is_ios) = match platform {
common_enums::ClientPlatform::Android => (true, false),
common_enums::ClientPlatform::Ios => (false, true),
Some(common_enums::ClientPlatform::Android) => (true, false),
Some(common_enums::ClientPlatform::Ios) => (false, true),
_ => (false, false),
};

Expand Down Expand Up @@ -208,20 +202,16 @@ impl TryFrom<&types::PaymentsPostProcessingRouterData> for PlaidLinkTokenRequest
.ok_or(errors::ConnectorError::MissingConnectorTransactionID)?,
},
android_package_name: if is_android {
Some(headers.x_app_id.ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "x-app-id",
},
)?)
headers
.as_ref()
.and_then(|headers| headers.x_app_id.clone())
} else {
None
},
redirect_uri: if is_ios {
Some(headers.x_redirect_uri.ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "x_redirect_uri",
},
)?)
headers
.as_ref()
.and_then(|headers| headers.x_redirect_uri.clone())
} else {
None
},
Expand Down
12 changes: 9 additions & 3 deletions crates/router/src/core/pm_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub async fn create_link_token(
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
payload: api_models::pm_auth::LinkTokenCreateRequest,
headers: Option<api_models::payments::HeaderPayload>,
) -> RouterResponse<api_models::pm_auth::LinkTokenCreateResponse> {
let db = &*state.store;

Expand Down Expand Up @@ -165,9 +166,13 @@ pub async fn create_link_token(
)?]),
language: payload.language,
user_info: payment_intent.and_then(|pi| pi.customer_id),
client_platform: payload.client_platform,
android_package_name: payload.android_package_name,
redirect_uri: payload.redirect_uri,
client_platform: headers
.as_ref()
.and_then(|header| header.x_client_platform.clone()),
android_package_name: headers.as_ref().and_then(|header| header.x_app_id.clone()),
redirect_uri: headers
.as_ref()
.and_then(|header| header.x_redirect_uri.clone()),
},
response: Ok(pm_auth_types::LinkTokenResponse {
link_token: "".to_string(),
Expand Down Expand Up @@ -211,6 +216,7 @@ pub async fn create_link_token(
_merchant_account: domain::MerchantAccount,
_key_store: domain::MerchantKeyStore,
_payload: api_models::pm_auth::LinkTokenCreateRequest,
_headers: Option<api_models::payments::HeaderPayload>,
) -> RouterResponse<api_models::pm_auth::LinkTokenCreateResponse> {
todo!()
}
Expand Down
21 changes: 16 additions & 5 deletions crates/router/src/routes/pm_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use actix_web::{web, HttpRequest, Responder};
use api_models as api_types;
use router_env::{instrument, tracing, types::Flow};

use crate::{core::api_locking, routes::AppState, services::api as oss_api};
use crate::{
core::api_locking, routes::AppState, services::api, types::transformers::ForeignTryFrom,
};

#[instrument(skip_all, fields(flow = ?Flow::PmAuthLinkTokenCreate))]
pub async fn link_token_create(
Expand All @@ -17,9 +19,17 @@ pub async fn link_token_create(
&payload,
) {
Ok((auth, _auth_flow)) => (auth, _auth_flow),
Err(e) => return oss_api::log_and_return_error_response(e),
Err(e) => return api::log_and_return_error_response(e),
};
Box::pin(oss_api::server_wrap(

let header_payload = match api_types::payments::HeaderPayload::foreign_try_from(req.headers()) {
Ok(headers) => headers,
Err(err) => {
return api::log_and_return_error_response(err);
}
};

Box::pin(api::server_wrap(
flow,
state,
&req,
Expand All @@ -30,6 +40,7 @@ pub async fn link_token_create(
auth.merchant_account,
auth.key_store,
payload,
Some(header_payload.clone()),
)
},
&*auth,
Expand All @@ -51,9 +62,9 @@ pub async fn exchange_token(
&payload,
) {
Ok((auth, _auth_flow)) => (auth, _auth_flow),
Err(e) => return oss_api::log_and_return_error_response(e),
Err(e) => return api::log_and_return_error_response(e),
};
Box::pin(oss_api::server_wrap(
Box::pin(api::server_wrap(
flow,
state,
&req,
Expand Down

0 comments on commit 9576ee3

Please sign in to comment.