Fixed the Collect JS loading after first instance issue.
This commit is contained in:
@@ -152,14 +152,38 @@ function open_manual_payment_form(frm) {
|
|||||||
`
|
`
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// Destroy CollectJS instance if close button is clicked
|
||||||
primary_action_label: "Close",
|
primary_action_label: "Close",
|
||||||
primary_action() {
|
primary_action() {
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
|
// Destroy CollectJS Instance if closed with the X button
|
||||||
|
dialog.$wrapper.on("hidden.bs.modal", function () {
|
||||||
|
|
||||||
|
// Remove leftover backdrop (fix dark screen)
|
||||||
|
document.querySelectorAll(".modal-backdrop").forEach(el => el.remove());
|
||||||
|
|
||||||
|
// Restore body scroll + click
|
||||||
|
document.body.classList.remove("modal-open");
|
||||||
|
document.body.style.overflow = "";
|
||||||
|
|
||||||
|
// safely remove dialog
|
||||||
|
dialog.$wrapper.remove();
|
||||||
|
|
||||||
|
// WClean CollectJS
|
||||||
|
if (window.CollectJS) {
|
||||||
|
try {
|
||||||
|
delete window.CollectJS;
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
// Prefill
|
// Prefill
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const nameEl = document.getElementById(`cardholder_name_${uid}`);
|
const nameEl = document.getElementById(`cardholder_name_${uid}`);
|
||||||
@@ -172,11 +196,19 @@ function open_manual_payment_form(frm) {
|
|||||||
|
|
||||||
// Load CollectJS once
|
// Load CollectJS once
|
||||||
function loadCollectJS(callback) {
|
function loadCollectJS(callback) {
|
||||||
if (window.CollectJS) {
|
|
||||||
callback();
|
// Remove existing script if it exists
|
||||||
return;
|
const existingScript = document.querySelector('script[src*="Collect.js"]');
|
||||||
|
if (existingScript) {
|
||||||
|
existingScript.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset global
|
||||||
|
if (window.CollectJS) {
|
||||||
|
delete window.CollectJS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create fresh script every instance
|
||||||
const script = document.createElement("script");
|
const script = document.createElement("script");
|
||||||
script.src = "https://secure.nmi.com/token/Collect.js";
|
script.src = "https://secure.nmi.com/token/Collect.js";
|
||||||
|
|
||||||
@@ -185,7 +217,11 @@ function open_manual_payment_form(frm) {
|
|||||||
"HKx4XR-G549wT-8bZ2YJ-3kbG28"
|
"HKx4XR-G549wT-8bZ2YJ-3kbG28"
|
||||||
);
|
);
|
||||||
|
|
||||||
script.onload = callback;
|
script.onload = () => {
|
||||||
|
console.log("CollectJS loaded fresh");
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +231,6 @@ function open_manual_payment_form(frm) {
|
|||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
||||||
// DO NOT clear anything — new IDs = fresh mount
|
|
||||||
|
|
||||||
CollectJS.configure({
|
CollectJS.configure({
|
||||||
variant: "inline",
|
variant: "inline",
|
||||||
|
|||||||
Reference in New Issue
Block a user