Skip to content

Commit

Permalink
add create_webhook_url_using_mca_id fn
Browse files Browse the repository at this point in the history
  • Loading branch information
cookieg13 committed Nov 28, 2024
1 parent be0369f commit 4c94106
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
6 changes: 5 additions & 1 deletion crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6242,8 +6242,12 @@ pub async fn payment_external_authentication(
&payment_attempt.clone(),
payment_connector_name,
));
let merchant_connector_account_id: id_type::MerchantConnectorAccountId = payment_attempt
.merchant_connector_id
.clone()
.ok_or(errors::ApiErrorResponse::InternalServerError)?;
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
7 changes: 4 additions & 3 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,15 +1236,16 @@ 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/{}/{}",
"/webhooks/{}/{}",
router_base_url,
merchant_id.get_string_repr(),
connector_name
merchant_connector_id.get_string_repr(),
)
}

pub fn create_complete_authorize_url(
router_base_url: &String,
payment_attempt: &PaymentAttempt,
Expand Down
31 changes: 23 additions & 8 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 @@ -2322,7 +2322,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
let payment_data = additional_data.payment_data.clone();
let router_base_url = &additional_data.router_base_url;
let connector_name = &additional_data.connector_name;
let attempt = &payment_data.payment_attempt;
let attempt = &payment_data.payment_attempt.clone();
let browser_info: Option<types::BrowserInformation> = attempt
.browser_info
.clone()
Expand Down Expand Up @@ -2368,11 +2368,16 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
attempt,
connector_name,
));

let merchant_connector_account_id: common_utils::id_type::MerchantConnectorAccountId =
payment_data
.payment_attempt
.merchant_connector_id
.clone()
.ok_or(errors::ApiErrorResponse::InternalServerError)?;
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 @@ -3042,11 +3047,16 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ
.map(|customer| customer.clone().into_inner())
});
let amount = payment_data.payment_attempt.get_total_amount();

let merchant_connector_account_id: common_utils::id_type::MerchantConnectorAccountId =
payment_data
.payment_attempt
.merchant_connector_id
.clone()
.ok_or(errors::ApiErrorResponse::InternalServerError)?;
let webhook_url = Some(helpers::create_webhook_url(
router_base_url,
&attempt.merchant_id,
connector_name,
&merchant_connector_account_id,
));

Ok(Self {
Expand Down Expand Up @@ -3245,11 +3255,16 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
.collect::<Result<Vec<_>, _>>()
})
.transpose()?;

let merchant_connector_account_id: common_utils::id_type::MerchantConnectorAccountId =
payment_data
.payment_attempt
.merchant_connector_id
.clone()
.ok_or(errors::ApiErrorResponse::InternalServerError)?;
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
8 changes: 6 additions & 2 deletions crates/router/src/core/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,15 @@ pub async fn construct_refund_router_data<'a, F>(
.payment_method
.get_required_value("payment_method_type")
.change_context(errors::ApiErrorResponse::InternalServerError)?;

let merchant_connector_account_id: common_utils::id_type::MerchantConnectorAccountId =
payment_attempt
.merchant_connector_id
.clone()
.ok_or(errors::ApiErrorResponse::InternalServerError)?;
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

0 comments on commit 4c94106

Please sign in to comment.