Skip to content

Commit

Permalink
resolve comments
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 3d8f7a6 commit 854ef6a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 47 deletions.
4 changes: 0 additions & 4 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -14035,10 +14035,6 @@
},
"payment_id": {
"type": "string"
},
"locale": {
"type": "string",
"nullable": true
}
}
},
Expand Down
1 change: 0 additions & 1 deletion crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5380,7 +5380,6 @@ pub struct PaymentLinkInitiateRequest {
#[schema(value_type = String)]
pub merchant_id: id_type::MerchantId,
pub payment_id: String,
pub locale: Option<String>,
}

#[derive(Debug, serde::Serialize)]
Expand Down
34 changes: 31 additions & 3 deletions crates/router/src/core/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,22 @@ pub async fn initiate_payment_link_flow(
key_store: domain::MerchantKeyStore,
merchant_id: common_utils::id_type::MerchantId,
payment_id: String,
locale: Option<String>,
request_headers: &header::HeaderMap,
) -> RouterResponse<services::PaymentLinkFormData> {
let locale = request_headers
.get(header::ACCEPT_LANGUAGE)
.map(|value| {
value.to_str().map(|str| str.to_owned()).map_err(|err| {
logger::warn!(
"Could not convert accept-language header to string: {}",
err
);
err
})
})
.transpose()
.ok()
.flatten();
let (_, payment_details, payment_link_config) = form_payment_link_data(
&state,
merchant_account,
Expand Down Expand Up @@ -608,7 +622,6 @@ pub fn get_payment_link_config_based_on_priority(
DEFAULT_ENABLE_SAVED_PAYMENT_METHOD
)
);

let payment_link_config = PaymentLinkConfig {
theme,
logo,
Expand All @@ -618,6 +631,7 @@ pub fn get_payment_link_config_based_on_priority(
enabled_saved_payment_method,
allowed_domains,
};
router_env::logger::debug!("payment_link_config : {:?}", payment_link_config.clone());

Ok((payment_link_config, domain_name))
}
Expand Down Expand Up @@ -648,8 +662,22 @@ pub async fn get_payment_link_status(
key_store: domain::MerchantKeyStore,
merchant_id: common_utils::id_type::MerchantId,
payment_id: String,
locale: Option<String>,
request_headers: &header::HeaderMap,
) -> RouterResponse<services::PaymentLinkFormData> {
let locale = request_headers
.get(header::ACCEPT_LANGUAGE)
.map(|value| {
value.to_str().map(|str| str.to_owned()).map_err(|err| {
logger::warn!(
"Could not convert accept-language header to string: {}",
err
);
err
})
})
.transpose()
.ok()
.flatten();
let db = &*state.store;
let payment_intent = db
.find_payment_intent_by_payment_id_merchant_id(
Expand Down
7 changes: 4 additions & 3 deletions crates/router/src/core/payments/operations/payment_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,15 +1243,16 @@ async fn create_payment_link(
domain_name,
merchant_id.get_string_repr(),
payment_id.clone(),
locale_str,
locale_str.clone(),
);

let secure_link = payment_link_config.allowed_domains.as_ref().map(|_| {
format!(
"{}/payment_link/s/{}/{}",
"{}/payment_link/s/{}/{}?locale={}",
domain_name,
merchant_id.get_string_repr(),
payment_id.clone()
payment_id.clone(),
locale_str,
)
});

Expand Down
41 changes: 5 additions & 36 deletions crates/router/src/routes/payment_link.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use actix_web::{http::header::ACCEPT_LANGUAGE, web, Responder};
use actix_web::{web, Responder};
use router_env::{instrument, tracing, Flow};

use crate::{
Expand Down Expand Up @@ -58,27 +58,12 @@ pub async fn initiate_payment_link(
) -> impl Responder {
let flow = Flow::PaymentLinkInitiate;
let (merchant_id, payment_id) = path.into_inner();
let locale = req
.headers()
.get(ACCEPT_LANGUAGE)
.map(|value| {
value.to_str().map(|str| str.to_owned()).map_err(|err| {
router_env::logger::warn!(
"Could not convert accept-language header to string: {}",
err
);
err
})
})
.transpose()
.ok()
.flatten();

let payload = api_models::payments::PaymentLinkInitiateRequest {
payment_id,
merchant_id: merchant_id.clone(),
locale,
};
let headers = req.headers();
Box::pin(api::server_wrap(
flow,
state,
Expand All @@ -91,7 +76,7 @@ pub async fn initiate_payment_link(
auth.key_store,
payload.merchant_id.clone(),
payload.payment_id.clone(),
payload.locale.clone(),
headers,
)
},
&crate::services::authentication::MerchantIdAuth(merchant_id),
Expand All @@ -110,7 +95,6 @@ pub async fn initiate_secure_payment_link(
let payload = api_models::payments::PaymentLinkInitiateRequest {
payment_id,
merchant_id: merchant_id.clone(),
locale: None,
};
let headers = req.headers();
Box::pin(api::server_wrap(
Expand Down Expand Up @@ -184,27 +168,12 @@ pub async fn payment_link_status(
) -> impl Responder {
let flow = Flow::PaymentLinkStatus;
let (merchant_id, payment_id) = path.into_inner();
let locale = req
.headers()
.get(ACCEPT_LANGUAGE)
.map(|value| {
value.to_str().map(|str| str.to_owned()).map_err(|err| {
router_env::logger::warn!(
"Could not convert accept-language header to string: {}",
err
);
err
})
})
.transpose()
.ok()
.flatten();

let payload = api_models::payments::PaymentLinkInitiateRequest {
payment_id,
merchant_id: merchant_id.clone(),
locale,
};
let headers = req.headers();
Box::pin(api::server_wrap(
flow,
state,
Expand All @@ -217,7 +186,7 @@ pub async fn payment_link_status(
auth.key_store,
payload.merchant_id.clone(),
payload.payment_id.clone(),
payload.locale.clone(),
headers,
)
},
&crate::services::authentication::MerchantIdAuth(merchant_id),
Expand Down

0 comments on commit 854ef6a

Please # to comment.