diff --git a/client/src/components/card-payment-modal/card-payment-modal.component..jsx b/client/src/components/card-payment-modal/card-payment-modal.component.jsx similarity index 92% rename from client/src/components/card-payment-modal/card-payment-modal.component..jsx rename to client/src/components/card-payment-modal/card-payment-modal.component.jsx index eef9f3ddb..ae90d2d9e 100644 --- a/client/src/components/card-payment-modal/card-payment-modal.component..jsx +++ b/client/src/components/card-payment-modal/card-payment-modal.component.jsx @@ -133,15 +133,19 @@ const CardPaymentModalComponent = ({ if (window.intellipay) { // eslint-disable-next-line no-eval eval(response.data); - SetIntellipayCallbackFunctions(); - window.intellipay.autoOpen(); + pollForIntelliPay(() => { + SetIntellipayCallbackFunctions(); + window.intellipay.autoOpen(); + }); } else { const rg = document.createRange(); const node = rg.createContextualFragment(response.data); document.documentElement.appendChild(node); - SetIntellipayCallbackFunctions(); - window.intellipay.isAutoOpen = true; - window.intellipay.initialize(); + pollForIntelliPay(() => { + SetIntellipayCallbackFunctions(); + window.intellipay.isAutoOpen = true; + window.intellipay.initialize(); + }); } } catch (error) { notification.open({ @@ -345,3 +349,27 @@ const CardPaymentModalComponent = ({ }; export default connect(mapStateToProps, mapDispatchToProps)(CardPaymentModalComponent); + +//Poll for window.IntelliPay.fixAmount for 5 seconds. If it doesn't come up, just try anyways to force the possible error. +function pollForIntelliPay(callbackFunction) { + const timeout = 5000; + const interval = 150; // Poll every 100 milliseconds + const startTime = Date.now(); + + function checkFixAmount() { + if (window.intellipay && window.intellipay.fixAmount !== undefined) { + callbackFunction(); + return; + } + + if (Date.now() - startTime >= timeout) { + console.log("Stopped polling IntelliPay after 10 seconds. Attemping to set functions anyways."); + callbackFunction(); + return; + } + + setTimeout(checkFixAmount, interval); + } + + checkFixAmount(); +} diff --git a/client/src/components/card-payment-modal/card-payment-modal.container..jsx b/client/src/components/card-payment-modal/card-payment-modal.container.jsx similarity index 99% rename from client/src/components/card-payment-modal/card-payment-modal.container..jsx rename to client/src/components/card-payment-modal/card-payment-modal.container.jsx index 2f56615bd..48f84b855 100644 --- a/client/src/components/card-payment-modal/card-payment-modal.container..jsx +++ b/client/src/components/card-payment-modal/card-payment-modal.container.jsx @@ -6,7 +6,7 @@ import { createStructuredSelector } from "reselect"; import { toggleModalVisible } from "../../redux/modals/modals.actions"; import { selectCardPayment } from "../../redux/modals/modals.selectors"; import { selectBodyshop } from "../../redux/user/user.selectors"; -import CardPaymentModalComponent from "./card-payment-modal.component."; +import CardPaymentModalComponent from "./card-payment-modal.component"; const mapStateToProps = createStructuredSelector({ cardPaymentModal: selectCardPayment, diff --git a/client/src/pages/manage/manage.page.component.jsx b/client/src/pages/manage/manage.page.component.jsx index 05f599fae..a76bf6e5b 100644 --- a/client/src/pages/manage/manage.page.component.jsx +++ b/client/src/pages/manage/manage.page.component.jsx @@ -31,7 +31,7 @@ import { addAlerts } from "../../redux/application/application.actions.js"; const JobsPage = lazy(() => import("../jobs/jobs.page")); const CardPaymentModalContainer = lazy( - () => import("../../components/card-payment-modal/card-payment-modal.container.") + () => import("../../components/card-payment-modal/card-payment-modal.container.jsx") ); const JobsDetailPage = lazy(() => import("../jobs-detail/jobs-detail.page.container"));