Skip to content

Commit 48a0de4

Browse files
committed
add create_webhook_url fn changes
1 parent c595f10 commit 48a0de4

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

crates/router/src/core/payments.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -6564,15 +6564,16 @@ pub async fn payment_external_authentication(
65646564
&payment_attempt.clone(),
65656565
payment_connector_name,
65666566
));
6567-
let merchant_connector_account_id = merchant_connector_account
6568-
.get_mca_id()
6569-
.ok_or(errors::ApiErrorResponse::InternalServerError)
6570-
.attach_printable("Error while finding mca_id from merchant_connector_account")?;
6567+
let mca_id_option = merchant_connector_account.get_mca_id(); // Bind temporary value
6568+
let merchant_connector_account_id_or_connector_name = mca_id_option
6569+
.as_ref()
6570+
.map(|mca_id| mca_id.get_string_repr())
6571+
.unwrap_or(&authentication_connector);
65716572

65726573
let webhook_url = helpers::create_webhook_url(
65736574
&state.base_url,
65746575
merchant_id,
6575-
&merchant_connector_account_id.get_string_repr().to_string(),
6576+
merchant_connector_account_id_or_connector_name,
65766577
);
65776578

65786579
let authentication_details = business_profile

crates/router/src/core/payments/helpers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1241,9 +1241,9 @@ pub fn create_authorize_url(
12411241
}
12421242

12431243
pub fn create_webhook_url(
1244-
router_base_url: &String,
1244+
router_base_url: &str,
12451245
merchant_id: &id_type::MerchantId,
1246-
merchant_connector_id_or_connector_name: &String,
1246+
merchant_connector_id_or_connector_name: &str,
12471247
) -> String {
12481248
format!(
12491249
"{}/webhooks/{}/{}",

crates/router/src/core/payments/transformers.rs

+16-18
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
224224
let webhook_url = Some(helpers::create_webhook_url(
225225
router_base_url,
226226
&attempt.merchant_id,
227-
&merchant_connector_account.get_id().get_string_repr().to_string(),
227+
merchant_connector_account.get_id().get_string_repr(),
228228
));
229229

230230
let router_return_url = payment_data
@@ -2745,17 +2745,17 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
27452745
attempt,
27462746
connector_name,
27472747
));
2748-
let merchant_connector_account_id = payment_data
2748+
let merchant_connector_account_id_or_connector_name = payment_data
27492749
.payment_attempt
2750-
.clone()
27512750
.merchant_connector_id
2752-
.map(|mca_id| mca_id.get_string_repr().to_string())
2753-
.unwrap_or(connector_name.to_string());
2751+
.as_ref()
2752+
.map(|mca_id| mca_id.get_string_repr())
2753+
.unwrap_or(connector_name);
27542754

27552755
let webhook_url = Some(helpers::create_webhook_url(
27562756
router_base_url,
27572757
&attempt.merchant_id,
2758-
&merchant_connector_account_id,
2758+
merchant_connector_account_id_or_connector_name,
27592759
));
27602760
let router_return_url = Some(helpers::create_redirect_url(
27612761
router_base_url,
@@ -3575,17 +3575,16 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ
35753575
.map(|customer| customer.clone().into_inner())
35763576
});
35773577
let amount = payment_data.payment_attempt.get_total_amount();
3578-
let merchant_connector_account_id = payment_data
3578+
let merchant_connector_account_id_or_connector_name = payment_data
35793579
.payment_attempt
35803580
.merchant_connector_id
3581-
.clone()
3582-
.get_required_value("merchant_connector_id")
3583-
.change_context(errors::ApiErrorResponse::InternalServerError)
3584-
.attach_printable("Merchant connector id is not present in payment_attempt")?;
3581+
.as_ref()
3582+
.map(|mca_id| mca_id.get_string_repr())
3583+
.unwrap_or(connector_name);
35853584
let webhook_url = Some(helpers::create_webhook_url(
35863585
router_base_url,
35873586
&attempt.merchant_id,
3588-
&merchant_connector_account_id.get_string_repr().to_string(),
3587+
merchant_connector_account_id_or_connector_name,
35893588
));
35903589

35913590
Ok(Self {
@@ -3784,17 +3783,16 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
37843783
.collect::<Result<Vec<_>, _>>()
37853784
})
37863785
.transpose()?;
3787-
let merchant_connector_account_id = payment_data
3786+
let merchant_connector_account_id_or_connector_name = payment_data
37883787
.payment_attempt
37893788
.merchant_connector_id
3790-
.clone()
3791-
.get_required_value("merchant_connector_id")
3792-
.change_context(errors::ApiErrorResponse::InternalServerError)
3793-
.attach_printable("Merchant connector id is not present in payment_attempt")?;
3789+
.as_ref()
3790+
.map(|mca_id| mca_id.get_string_repr())
3791+
.unwrap_or(connector_name);
37943792
let webhook_url = Some(helpers::create_webhook_url(
37953793
router_base_url,
37963794
&attempt.merchant_id,
3797-
&merchant_connector_account_id.get_string_repr().to_string(),
3795+
merchant_connector_account_id_or_connector_name,
37983796
));
37993797
let router_return_url = Some(helpers::create_redirect_url(
38003798
router_base_url,

crates/router/src/core/relay/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub async fn construct_relay_refund_router_data<'a, F>(
3232
let webhook_url = Some(payments::helpers::create_webhook_url(
3333
&state.base_url.clone(),
3434
merchant_id,
35-
&connector_account.get_id().get_string_repr().to_string(),
35+
connector_account.get_id().get_string_repr(),
3636
));
3737

3838
let supported_connector = &state

crates/router/src/core/utils.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,16 @@ pub async fn construct_refund_router_data<'a, F>(
285285
.payment_method
286286
.get_required_value("payment_method_type")
287287
.change_context(errors::ApiErrorResponse::InternalServerError)?;
288-
let merchant_connector_account_id = payment_attempt
288+
let merchant_connector_account_id_or_connector_name = payment_attempt
289289
.merchant_connector_id
290-
.clone()
291-
.get_required_value("merchant_connector_id")
292-
.change_context(errors::ApiErrorResponse::InternalServerError)
293-
.attach_printable("Merchant connector id is not present in payment_attempt")?;
290+
.as_ref()
291+
.map(|mca_id| mca_id.get_string_repr())
292+
.unwrap_or(connector_id);
293+
294294
let webhook_url = Some(helpers::create_webhook_url(
295295
&state.base_url.clone(),
296296
merchant_account.get_id(),
297-
&merchant_connector_account_id.get_string_repr().to_string(),
297+
merchant_connector_account_id_or_connector_name,
298298
));
299299
let test_mode: Option<bool> = merchant_connector_account.is_test_mode_on();
300300

0 commit comments

Comments
 (0)