mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
fix(connector): [Worldpay] handle multiple ddc submission for CompleteAuthorize (#8741)
This commit is contained in:
@ -1181,7 +1181,7 @@ pub fn build_redirection_form(
|
||||
#loader1 {
|
||||
width: 500px,
|
||||
}
|
||||
@media max-width: 600px {
|
||||
@media (max-width: 600px) {
|
||||
#loader1 {
|
||||
width: 200px
|
||||
}
|
||||
@ -1748,7 +1748,7 @@ pub fn build_redirection_form(
|
||||
#loader1 {
|
||||
width: 500px;
|
||||
}
|
||||
@media max-width: 600px {
|
||||
@media (max-width: 600px) {
|
||||
#loader1 {
|
||||
width: 200px;
|
||||
}
|
||||
@ -1777,7 +1777,21 @@ pub fn build_redirection_form(
|
||||
script {
|
||||
(PreEscaped(format!(
|
||||
r#"
|
||||
var ddcProcessed = false;
|
||||
var timeoutHandle = null;
|
||||
|
||||
function submitCollectionReference(collectionReference) {{
|
||||
if (ddcProcessed) {{
|
||||
console.log("DDC already processed, ignoring duplicate submission");
|
||||
return;
|
||||
}}
|
||||
ddcProcessed = true;
|
||||
|
||||
if (timeoutHandle) {{
|
||||
clearTimeout(timeoutHandle);
|
||||
timeoutHandle = null;
|
||||
}}
|
||||
|
||||
var redirectPathname = window.location.pathname.replace(/payments\/redirect\/([^\/]+)\/([^\/]+)\/[^\/]+/, "payments/$1/$2/redirect/complete/worldpay");
|
||||
var redirectUrl = window.location.origin + redirectPathname;
|
||||
try {{
|
||||
@ -1796,12 +1810,17 @@ pub fn build_redirection_form(
|
||||
window.location.replace(redirectUrl);
|
||||
}}
|
||||
}} catch (error) {{
|
||||
console.error("Error submitting DDC:", error);
|
||||
window.location.replace(redirectUrl);
|
||||
}}
|
||||
}}
|
||||
var allowedHost = "{}";
|
||||
var collectionField = "{}";
|
||||
window.addEventListener("message", function(event) {{
|
||||
if (ddcProcessed) {{
|
||||
console.log("DDC already processed, ignoring message event");
|
||||
return;
|
||||
}}
|
||||
if (event.origin === allowedHost) {{
|
||||
try {{
|
||||
var data = JSON.parse(event.data);
|
||||
@ -1821,8 +1840,13 @@ pub fn build_redirection_form(
|
||||
submitCollectionReference("");
|
||||
}});
|
||||
|
||||
// Redirect within 8 seconds if no collection reference is received
|
||||
window.setTimeout(submitCollectionReference, 8000);
|
||||
// Timeout after 10 seconds and will submit empty collection reference
|
||||
timeoutHandle = window.setTimeout(function() {{
|
||||
if (!ddcProcessed) {{
|
||||
console.log("DDC timeout reached, submitting empty collection reference");
|
||||
submitCollectionReference("");
|
||||
}}
|
||||
}}, 10000);
|
||||
"#,
|
||||
endpoint.host_str().map_or(endpoint.as_ref().split('/').take(3).collect::<Vec<&str>>().join("/"), |host| format!("{}://{}", endpoint.scheme(), host)),
|
||||
collection_id.clone().unwrap_or("".to_string())))
|
||||
|
||||
Reference in New Issue
Block a user