Currently, I am in the process of integrating SagePay using the drop-in checkout feature. Our website allows users to choose paying with SagePay, which initializes the drop-in checkout. However, there may be instances where the user decides to switch to another payment method before finalizing the transaction. In such cases, we need to remove or destroy the existing checkout without refreshing the page. I followed the documentation provided for this process:
sp = sagepayCheckout({
merchantSessionKey: sagepaySessionKey
});
sp.form();
// and
sp.destroy();
Nevertheless, when attempting to submit the checkout form after calling the destroy method, an error occurs within the sagepay-dropin.js file (as shown below). Even though the documentation states that destroy() "Removes the iFrame from the container and unregisters any events that may have been registered," it appears that some events still linger during the form submission.
Could you please provide guidance on resolving this issue so that we can successfully submit our checkout form even if a user initially selects SagePay but later switches to a different payment method? Thank you.
sagepay-dropin.js:11 Uncaught TypeError: Cannot read property 'postMessage' of null
at Object.a [as sendMessage] (sagepay-dropin.js:11)
at v (sagepay-dropin.js:11)
at T (sagepay-dropin.js:11)
at HTMLFormElement.<anonymous> (sagepay-dropin.js:11)