refactor(core): use business_profile to read merchant configs (#2729)

This commit is contained in:
Narayan Bhat
2023-10-31 13:14:45 +05:30
committed by GitHub
parent 9d9fc2a8c5
commit 8c85173ecd
6 changed files with 163 additions and 26 deletions

View File

@ -1891,7 +1891,7 @@ pub(super) fn validate_payment_list_request_for_joins(
pub fn get_handle_response_url(
payment_id: String,
merchant_account: &domain::MerchantAccount,
business_profile: &diesel_models::business_profile::BusinessProfile,
response: api::PaymentsResponse,
connector: String,
) -> RouterResult<api::RedirectionResponse> {
@ -1900,7 +1900,7 @@ pub fn get_handle_response_url(
let redirection_response = make_pg_redirect_response(payment_id, &response, connector);
let return_url = make_merchant_url_with_response(
merchant_account,
business_profile,
redirection_response,
payments_return_url,
response.client_secret.as_ref(),
@ -1908,11 +1908,11 @@ pub fn get_handle_response_url(
)
.attach_printable("Failed to make merchant url with response")?;
make_url_with_signature(&return_url, merchant_account)
make_url_with_signature(&return_url, business_profile)
}
pub fn make_merchant_url_with_response(
merchant_account: &domain::MerchantAccount,
business_profile: &diesel_models::business_profile::BusinessProfile,
redirection_response: api::PgRedirectResponse,
request_return_url: Option<&String>,
client_secret: Option<&masking::Secret<String>>,
@ -1920,7 +1920,7 @@ pub fn make_merchant_url_with_response(
) -> RouterResult<String> {
// take return url if provided in the request else use merchant return url
let url = request_return_url
.or(merchant_account.return_url.as_ref())
.or(business_profile.return_url.as_ref())
.get_required_value("return_url")?;
let status_check = redirection_response.status;
@ -1930,7 +1930,7 @@ pub fn make_merchant_url_with_response(
.into_report()
.attach_printable("Expected client secret to be `Some`")?;
let merchant_url_with_response = if merchant_account.redirect_to_merchant_with_http_post {
let merchant_url_with_response = if business_profile.redirect_to_merchant_with_http_post {
url::Url::parse_with_params(
url,
&[
@ -2024,7 +2024,7 @@ pub fn make_pg_redirect_response(
pub fn make_url_with_signature(
redirect_url: &str,
merchant_account: &domain::MerchantAccount,
business_profile: &diesel_models::business_profile::BusinessProfile,
) -> RouterResult<api::RedirectionResponse> {
let mut url = url::Url::parse(redirect_url)
.into_report()
@ -2034,8 +2034,8 @@ pub fn make_url_with_signature(
let mut base_url = url.clone();
base_url.query_pairs_mut().clear();
let url = if merchant_account.enable_payment_response_hash {
let key = merchant_account
let url = if business_profile.enable_payment_response_hash {
let key = business_profile
.payment_response_hash_key
.as_ref()
.get_required_value("payment_response_hash_key")?;
@ -2063,7 +2063,7 @@ pub fn make_url_with_signature(
return_url: base_url.to_string(),
params: parameters,
return_url_with_query_params: url.to_string(),
http_method: if merchant_account.redirect_to_merchant_with_http_post {
http_method: if business_profile.redirect_to_merchant_with_http_post {
services::Method::Post.to_string()
} else {
services::Method::Get.to_string()