Skip to content

Commit

Permalink
remove try
Browse files Browse the repository at this point in the history
  • Loading branch information
Chikke Srujan authored and Chikke Srujan committed Aug 7, 2024
1 parent 55c4a0a commit a61c407
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
11 changes: 7 additions & 4 deletions crates/router/src/core/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
get_payment_link_config_value, get_payment_link_config_value_based_on_priority,
headers::ACCEPT_LANGUAGE,
routes::SessionState,
services::{self, authentication::try_get_header_value_by_key},
services::{self, authentication::get_header_value_by_key},
types::{
api::payment_link::PaymentLinkResponseExt,
domain,
Expand Down Expand Up @@ -257,7 +257,8 @@ pub async fn initiate_secure_payment_link_flow(
payment_id: String,
request_headers: &header::HeaderMap,
) -> RouterResponse<services::PaymentLinkFormData> {
let locale = try_get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers);
let locale = get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers)?
.map(|val| val.to_string());
let (payment_link, payment_link_details, payment_link_config) = form_payment_link_data(
&state,
merchant_account,
Expand Down Expand Up @@ -354,7 +355,8 @@ pub async fn initiate_payment_link_flow(
payment_id: String,
request_headers: &header::HeaderMap,
) -> RouterResponse<services::PaymentLinkFormData> {
let locale = try_get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers);
let locale = get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers)?
.map(|val| val.to_string());
let (_, payment_details, payment_link_config) = form_payment_link_data(
&state,
merchant_account,
Expand Down Expand Up @@ -637,7 +639,8 @@ pub async fn get_payment_link_status(
payment_id: String,
request_headers: &header::HeaderMap,
) -> RouterResponse<services::PaymentLinkFormData> {
let locale = try_get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers);
let locale = get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers)?
.map(|val| val.to_string());
let db = &*state.store;
let payment_intent = db
.find_payment_intent_by_payment_id_merchant_id(
Expand Down
14 changes: 0 additions & 14 deletions crates/router/src/services/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,20 +1525,6 @@ pub fn get_header_value_by_key(key: String, headers: &HeaderMap) -> RouterResult
.transpose()
}

pub fn try_get_header_value_by_key(key: String, headers: &HeaderMap) -> Option<String> {
headers
.get(key.clone())
.map(|value| {
value.to_str().map(|str| str.to_owned()).map_err(|err| {
logger::warn!("Could not convert {} header to string: {}", key, err);
err
})
})
.transpose()
.ok()
.flatten()
}

pub fn get_jwt_from_authorization_header(headers: &HeaderMap) -> RouterResult<&str> {
headers
.get(crate::headers::AUTHORIZATION)
Expand Down

0 comments on commit a61c407

Please # to comment.