(()=>{class e{constructor(e,t,o){this.jQuery=e,this.body=t,this.form=o}setup(){this.jQuery(this.body).on("init_checkout",()=>this.initCheckout())}initCheckout(){const e=this.form.querySelector(".pronamic-pay-mollie-card-field");if(null===e)return;const t=e.dataset.mollieProfileId,o=JSON.parse(e.dataset.mollieOptions);this.mollie=Mollie(t,o),this.checkoutPlaceOrderListener=(e,t)=>this.checkoutPlaceOrder(e,t),this.jQuery(this.form).on("checkout_place_order",this.checkoutPlaceOrderListener),this.jQuery(this.body).on("updated_checkout",()=>this.updatedCheckout()),this.mollieCardComponent=this.mollie.createComponent("card")}updatedCheckout(){this.cardElement&&this.mollieCardComponent.unmount(),this.cardElement=this.form.querySelector(".pronamic-pay-mollie-card-field"),null!==this.cardElement&&this.mollieCardComponent.mount(this.cardElement)}checkoutPlaceOrder(e,t){return"pronamic_pay_credit_card"!==t.get_payment_method()||(this.mollie.createToken().then(e=>this.processTokenResponse(e)),!1)}processTokenResponse(e){if(e.error)return;const t=document.getElementById("pronamic_pay_mollie_card_token");t&&(t.value=e.token),this.jQuery(this.form).off("checkout_place_order",this.checkoutPlaceOrderListener),this.jQuery(this.form).submit(),this.jQuery(this.form).on("checkout_place_order",this.checkoutPlaceOrderListener)}}jQuery&&document.forms.checkout&&new e(jQuery,document.body,document.forms.checkout).setup()})();