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() {
|
||||
dialog.hide();
|
||||
dialog.hide();
|
||||
}
|
||||
});
|
||||
|
||||
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
|
||||
setTimeout(() => {
|
||||
const nameEl = document.getElementById(`cardholder_name_${uid}`);
|
||||
@@ -172,11 +196,19 @@ function open_manual_payment_form(frm) {
|
||||
|
||||
// Load CollectJS once
|
||||
function loadCollectJS(callback) {
|
||||
if (window.CollectJS) {
|
||||
callback();
|
||||
return;
|
||||
|
||||
// Remove existing script if it exists
|
||||
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");
|
||||
script.src = "https://secure.nmi.com/token/Collect.js";
|
||||
|
||||
@@ -185,7 +217,11 @@ function open_manual_payment_form(frm) {
|
||||
"HKx4XR-G549wT-8bZ2YJ-3kbG28"
|
||||
);
|
||||
|
||||
script.onload = callback;
|
||||
script.onload = () => {
|
||||
console.log("CollectJS loaded fresh");
|
||||
callback();
|
||||
};
|
||||
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
|
||||
@@ -195,7 +231,6 @@ function open_manual_payment_form(frm) {
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
// DO NOT clear anything — new IDs = fresh mount
|
||||
|
||||
CollectJS.configure({
|
||||
variant: "inline",
|
||||
|
||||
Reference in New Issue
Block a user