Skip to content

Commit be4b43f

Browse files
fix(authentication): fixed notification_url and updated authentication bug (#8843)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 9e8df84 commit be4b43f

File tree

1 file changed

+78
-76
lines changed

1 file changed

+78
-76
lines changed

crates/router/src/core/unified_authentication_service.rs

Lines changed: 78 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ pub async fn authentication_eligibility_core(
939939
let notification_url = match authentication_connector {
940940
common_enums::AuthenticationConnectors::Juspaythreedsserver => {
941941
Some(url::Url::parse(&format!(
942-
"{base_url}/{merchant_id}/{authentication_id}/sync",
942+
"{base_url}/authentication/{merchant_id}/{authentication_id}/sync",
943943
base_url = state.base_url,
944944
merchant_id = merchant_id.get_string_repr(),
945945
authentication_id = authentication_id.get_string_repr()
@@ -1416,29 +1416,6 @@ pub async fn authentication_sync_core(
14161416
id: profile_id.get_string_repr().to_owned(),
14171417
})?;
14181418

1419-
let (authentication_value, eci) = match auth_flow {
1420-
AuthFlow::Client => (None, None),
1421-
AuthFlow::Merchant => {
1422-
if let Some(common_enums::TransactionStatus::Success) = authentication.trans_status {
1423-
let tokenised_data = crate::core::payment_methods::vault::get_tokenized_data(
1424-
&state,
1425-
authentication_id.get_string_repr(),
1426-
false,
1427-
merchant_context.get_merchant_key_store().key.get_inner(),
1428-
)
1429-
.await
1430-
.inspect_err(|err| router_env::logger::error!(tokenized_data_result=?err))
1431-
.attach_printable("cavv not present after authentication status is success")?;
1432-
(
1433-
Some(masking::Secret::new(tokenised_data.value1)),
1434-
authentication.eci.clone(),
1435-
)
1436-
} else {
1437-
(None, None)
1438-
}
1439-
}
1440-
};
1441-
14421419
let (authentication_connector, three_ds_connector_account) =
14431420
auth_utils::get_authentication_connector_data(
14441421
&state,
@@ -1448,21 +1425,20 @@ pub async fn authentication_sync_core(
14481425
)
14491426
.await?;
14501427

1451-
if let Some(trans_status) = authentication.trans_status.clone() {
1452-
if trans_status.is_pending() {
1453-
let post_auth_response =
1454-
<ExternalAuthentication as UnifiedAuthenticationService>::post_authentication(
1455-
&state,
1456-
&business_profile,
1457-
None,
1458-
&three_ds_connector_account,
1459-
&authentication_connector.to_string(),
1460-
&authentication_id,
1461-
common_enums::PaymentMethod::Card,
1462-
merchant_id,
1463-
Some(&authentication),
1464-
)
1465-
.await?;
1428+
let updated_authentication = match authentication.trans_status.clone() {
1429+
Some(trans_status) if trans_status.clone().is_pending() => {
1430+
let post_auth_response = ExternalAuthentication::post_authentication(
1431+
&state,
1432+
&business_profile,
1433+
None,
1434+
&three_ds_connector_account,
1435+
&authentication_connector.to_string(),
1436+
&authentication_id,
1437+
common_enums::PaymentMethod::Card,
1438+
merchant_id,
1439+
Some(&authentication),
1440+
)
1441+
.await?;
14661442

14671443
utils::external_authentication_update_trackers(
14681444
&state,
@@ -1475,14 +1451,41 @@ pub async fn authentication_sync_core(
14751451
None,
14761452
None,
14771453
)
1478-
.await?;
1454+
.await?
14791455
}
1480-
}
1456+
1457+
_ => authentication,
1458+
};
1459+
1460+
let (authentication_value, eci) = match auth_flow {
1461+
AuthFlow::Client => (None, None),
1462+
AuthFlow::Merchant => {
1463+
if let Some(common_enums::TransactionStatus::Success) =
1464+
updated_authentication.trans_status
1465+
{
1466+
let tokenised_data = crate::core::payment_methods::vault::get_tokenized_data(
1467+
&state,
1468+
authentication_id.get_string_repr(),
1469+
false,
1470+
merchant_context.get_merchant_key_store().key.get_inner(),
1471+
)
1472+
.await
1473+
.inspect_err(|err| router_env::logger::error!(tokenized_data_result=?err))
1474+
.attach_printable("cavv not present after authentication status is success")?;
1475+
(
1476+
Some(masking::Secret::new(tokenised_data.value1)),
1477+
updated_authentication.eci.clone(),
1478+
)
1479+
} else {
1480+
(None, None)
1481+
}
1482+
}
1483+
};
14811484

14821485
let acquirer_details = Some(AcquirerDetails {
1483-
acquirer_bin: authentication.acquirer_bin.clone(),
1484-
acquirer_merchant_id: authentication.acquirer_merchant_id.clone(),
1485-
merchant_country_code: authentication.acquirer_country_code.clone(),
1486+
acquirer_bin: updated_authentication.acquirer_bin.clone(),
1487+
acquirer_merchant_id: updated_authentication.acquirer_merchant_id.clone(),
1488+
merchant_country_code: updated_authentication.acquirer_country_code.clone(),
14861489
});
14871490

14881491
let encrypted_data = domain::types::crypto_operation(
@@ -1491,8 +1494,8 @@ pub async fn authentication_sync_core(
14911494
domain::types::CryptoOperation::BatchDecrypt(
14921495
hyperswitch_domain_models::authentication::EncryptedAuthentication::to_encryptable(
14931496
hyperswitch_domain_models::authentication::EncryptedAuthentication {
1494-
billing_address: authentication.billing_address,
1495-
shipping_address: authentication.shipping_address,
1497+
billing_address: updated_authentication.billing_address,
1498+
shipping_address: updated_authentication.shipping_address,
14961499
},
14971500
),
14981501
),
@@ -1513,7 +1516,7 @@ pub async fn authentication_sync_core(
15131516
.change_context(ApiErrorResponse::InternalServerError)
15141517
.attach_printable("Unable to get encrypted data for authentication after encryption")?;
15151518

1516-
let email_decrypted = authentication
1519+
let email_decrypted = updated_authentication
15171520
.email
15181521
.clone()
15191522
.async_lift(|inner| async {
@@ -1536,7 +1539,7 @@ pub async fn authentication_sync_core(
15361539
.change_context(ApiErrorResponse::InternalServerError)
15371540
.attach_printable("Unable to encrypt email")?;
15381541

1539-
let browser_info = authentication
1542+
let browser_info = updated_authentication
15401543
.browser_info
15411544
.clone()
15421545
.map(|browser_info| {
@@ -1545,16 +1548,16 @@ pub async fn authentication_sync_core(
15451548
.transpose()
15461549
.change_context(ApiErrorResponse::InternalServerError)?;
15471550

1548-
let amount = authentication
1551+
let amount = updated_authentication
15491552
.amount
15501553
.ok_or(ApiErrorResponse::InternalServerError)
15511554
.attach_printable("amount failed to get amount from authentication table")?;
1552-
let currency = authentication
1555+
let currency = updated_authentication
15531556
.currency
15541557
.ok_or(ApiErrorResponse::InternalServerError)
15551558
.attach_printable("currency failed to get currency from authentication table")?;
15561559

1557-
let authentication_connector = authentication
1560+
let authentication_connector = updated_authentication
15581561
.authentication_connector
15591562
.map(|connector| common_enums::AuthenticationConnectors::from_str(&connector))
15601563
.transpose()
@@ -1588,51 +1591,50 @@ pub async fn authentication_sync_core(
15881591
let response = AuthenticationSyncResponse {
15891592
authentication_id: authentication_id.clone(),
15901593
merchant_id: merchant_id.clone(),
1591-
status: authentication.authentication_status,
1592-
client_secret: authentication
1594+
status: updated_authentication.authentication_status,
1595+
client_secret: updated_authentication
15931596
.authentication_client_secret
15941597
.map(masking::Secret::new),
15951598
amount,
15961599
currency,
15971600
authentication_connector,
1598-
force_3ds_challenge: authentication.force_3ds_challenge,
1599-
return_url: authentication.return_url.clone(),
1600-
created_at: authentication.created_at,
1601-
profile_id: authentication.profile_id.clone(),
1602-
psd2_sca_exemption_type: authentication.psd2_sca_exemption_type,
1601+
force_3ds_challenge: updated_authentication.force_3ds_challenge,
1602+
return_url: updated_authentication.return_url.clone(),
1603+
created_at: updated_authentication.created_at,
1604+
profile_id: updated_authentication.profile_id.clone(),
1605+
psd2_sca_exemption_type: updated_authentication.psd2_sca_exemption_type,
16031606
acquirer_details,
1604-
error_message: authentication.error_message.clone(),
1605-
error_code: authentication.error_code.clone(),
1607+
error_message: updated_authentication.error_message.clone(),
1608+
error_code: updated_authentication.error_code.clone(),
16061609
authentication_value,
1607-
threeds_server_transaction_id: authentication.threeds_server_transaction_id.clone(),
1608-
maximum_supported_3ds_version: authentication.maximum_supported_version.clone(),
1609-
connector_authentication_id: authentication.connector_authentication_id.clone(),
1610-
three_ds_method_data: authentication.three_ds_method_data.clone(),
1611-
three_ds_method_url: authentication.three_ds_method_url.clone(),
1612-
message_version: authentication.message_version.clone(),
1613-
connector_metadata: authentication.connector_metadata.clone(),
1614-
directory_server_id: authentication.directory_server_id.clone(),
1610+
threeds_server_transaction_id: updated_authentication.threeds_server_transaction_id.clone(),
1611+
maximum_supported_3ds_version: updated_authentication.maximum_supported_version.clone(),
1612+
connector_authentication_id: updated_authentication.connector_authentication_id.clone(),
1613+
three_ds_method_data: updated_authentication.three_ds_method_data.clone(),
1614+
three_ds_method_url: updated_authentication.three_ds_method_url.clone(),
1615+
message_version: updated_authentication.message_version.clone(),
1616+
connector_metadata: updated_authentication.connector_metadata.clone(),
1617+
directory_server_id: updated_authentication.directory_server_id.clone(),
16151618
billing,
16161619
shipping,
16171620
browser_information: browser_info,
16181621
email: email_decrypted,
1619-
transaction_status: authentication.trans_status.clone(),
1620-
acs_url: authentication.acs_url.clone(),
1621-
challenge_request: authentication.challenge_request.clone(),
1622-
acs_reference_number: authentication.acs_reference_number.clone(),
1623-
acs_trans_id: authentication.acs_trans_id.clone(),
1624-
acs_signed_content: authentication.acs_signed_content,
1622+
transaction_status: updated_authentication.trans_status.clone(),
1623+
acs_url: updated_authentication.acs_url.clone(),
1624+
challenge_request: updated_authentication.challenge_request.clone(),
1625+
acs_reference_number: updated_authentication.acs_reference_number.clone(),
1626+
acs_trans_id: updated_authentication.acs_trans_id.clone(),
1627+
acs_signed_content: updated_authentication.acs_signed_content,
16251628
three_ds_requestor_url: business_profile
16261629
.authentication_connector_details
16271630
.clone()
16281631
.map(|details| details.three_ds_requestor_url),
16291632
three_ds_requestor_app_url: business_profile
16301633
.authentication_connector_details
16311634
.and_then(|details| details.three_ds_requestor_app_url),
1632-
profile_acquirer_id: authentication.profile_acquirer_id.clone(),
1635+
profile_acquirer_id: updated_authentication.profile_acquirer_id.clone(),
16331636
eci,
16341637
};
1635-
16361638
Ok(hyperswitch_domain_models::api::ApplicationResponse::Json(
16371639
response,
16381640
))

0 commit comments

Comments
 (0)