Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(router): refactor relay flow addressing comments of /relay feature pr #6954

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
16 changes: 7 additions & 9 deletions crates/hyperswitch_domain_models/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use time::PrimitiveDateTime;

use crate::{router_data::ErrorResponse, router_response_types};

#[derive(Debug, Clone, Deserialize, Serialize)]
#[derive(Debug, Clone)]
pub struct Relay {
pub id: id_type::RelayId,
pub connector_resource_id: String,
Expand All @@ -27,9 +27,7 @@ pub struct Relay {
pub connector_reference_id: Option<String>,
pub error_code: Option<String>,
pub error_message: Option<String>,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub created_at: PrimitiveDateTime,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub modified_at: PrimitiveDateTime,
pub response_data: Option<pii::SecretSerdeValue>,
}
Expand All @@ -42,7 +40,7 @@ impl Relay {
) -> Self {
let relay_id = id_type::RelayId::generate();
Self {
id: relay_id.clone(),
id: relay_id,
connector_resource_id: relay_request.connector_resource_id.clone(),
connector_id: relay_request.connector_id.clone(),
profile_id: profile_id.clone(),
Expand Down Expand Up @@ -81,7 +79,7 @@ impl RelayUpdate {
match response {
Err(error) => Self::ErrorUpdate {
error_code: error.code,
error_message: error.message,
error_message: error.reason.unwrap_or(error.message),
status: common_enums::RelayStatus::Failure,
},
Ok(response) => Self::StatusUpdate {
Expand Down Expand Up @@ -198,7 +196,7 @@ impl super::behaviour::Conversion for Relay {
.request_data
.map(|data| {
serde_json::to_value(data).change_context(ValidationError::InvalidValue {
message: "Failed while decrypting business profile data".to_string(),
message: "Failed to serialize relay request data".to_string(),
})
})
.transpose()?
Expand All @@ -225,13 +223,13 @@ impl super::behaviour::Conversion for Relay {
connector_id: item.connector_id,
profile_id: item.profile_id,
merchant_id: item.merchant_id,
relay_type: enums::RelayType::Refund,
relay_type: item.relay_type,
request_data: item
.request_data
.map(|data| {
serde_json::from_value(data.expose()).change_context(
ValidationError::InvalidValue {
message: "Failed while decrypting business profile data".to_string(),
message: "Failed to deserialize relay request data".to_string(),
},
)
})
Expand All @@ -258,7 +256,7 @@ impl super::behaviour::Conversion for Relay {
.request_data
.map(|data| {
serde_json::to_value(data).change_context(ValidationError::InvalidValue {
message: "Failed while decrypting business profile data".to_string(),
message: "Failed to serialize relay request data".to_string(),
})
})
.transpose()?
Expand Down
9 changes: 8 additions & 1 deletion crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6564,8 +6564,15 @@ pub async fn payment_external_authentication(
&payment_attempt.clone(),
payment_connector_name,
));

let merchant_connector_account_id = merchant_connector_account
.get_mca_id()
.get_required_value("merchant_connector_id")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to fetch merchant connector id")?;

let webhook_url =
helpers::create_webhook_url(&state.base_url, merchant_id, &authentication_connector);
helpers::create_webhook_url(&state.base_url, merchant_id, &merchant_connector_account_id);

let authentication_details = business_profile
.authentication_connector_details
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,13 +1243,13 @@ pub fn create_authorize_url(
pub fn create_webhook_url(
router_base_url: &String,
merchant_id: &id_type::MerchantId,
connector_name: impl std::fmt::Display,
merchant_connector_id: &id_type::MerchantConnectorAccountId,
) -> String {
format!(
"{}/webhooks/{}/{}",
router_base_url,
merchant_id.get_string_repr(),
connector_name
merchant_connector_id.get_string_repr(),
)
}
pub fn create_complete_authorize_url(
Expand Down
22 changes: 19 additions & 3 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
let webhook_url = Some(helpers::create_webhook_url(
router_base_url,
&attempt.merchant_id,
connector_id,
&merchant_connector_account.get_id(),
));

let router_return_url = payment_data
Expand Down Expand Up @@ -2746,10 +2746,18 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
connector_name,
));

let merchant_connector_account_id = payment_data
.payment_attempt
.merchant_connector_id
.clone()
.get_required_value("merchant_connector_id")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Merchant connector id is not present in payment_attempt")?;

let webhook_url = Some(helpers::create_webhook_url(
router_base_url,
&attempt.merchant_id,
connector_name,
&merchant_connector_account_id,
));
let router_return_url = Some(helpers::create_redirect_url(
router_base_url,
Expand Down Expand Up @@ -3765,10 +3773,18 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
})
.transpose()?;

let merchant_connector_account_id = payment_data
.payment_attempt
.merchant_connector_id
.clone()
.get_required_value("merchant_connector_id")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Merchant connector id is not present in payment_attempt")?;

let webhook_url = Some(helpers::create_webhook_url(
router_base_url,
&attempt.merchant_id,
connector_name,
&merchant_connector_account_id,
));
let router_return_url = Some(helpers::create_redirect_url(
router_base_url,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/relay/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn construct_relay_refund_router_data<'a, F>(
let webhook_url = Some(payments::helpers::create_webhook_url(
&state.base_url.clone(),
merchant_id,
connector_name,
&connector_account.get_id(),
));

let supported_connector = &state
Expand Down
9 changes: 8 additions & 1 deletion crates/router/src/core/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,17 @@ pub async fn construct_refund_router_data<'a, F>(
.get_required_value("payment_method_type")
.change_context(errors::ApiErrorResponse::InternalServerError)?;

let merchant_connector_account_id = payment_attempt
.merchant_connector_id
.clone()
.get_required_value("merchant_connector_id")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Merchant connector id is not present in payment_attempt")?;

let webhook_url = Some(helpers::create_webhook_url(
&state.base_url.clone(),
merchant_account.get_id(),
connector_id,
&merchant_connector_account_id,
));
let test_mode: Option<bool> = merchant_connector_account.is_test_mode_on();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- This file should undo anything in `up.sql`

ALTER TABLE relay
ALTER COLUMN created_at SET DEFAULT now()::TIMESTAMP,
ALTER COLUMN modified_at SET DEFAULT now()::TIMESTAMP;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Your SQL goes here

ALTER TABLE relay
ALTER COLUMN created_at DROP DEFAULT,
ALTER COLUMN modified_at DROP DEFAULT;
Loading