var StripePlugin = function(){};

StripePlugin.Init = function(callBack){
    
const stripe = Stripe(document.getElementById("stripeKey").value);
const appearance = {};
const options = {};

const clientSecret = document.getElementById("clientSecret").value;
const elements = stripe.elements({clientSecret, appearance });
const paymentElement = elements.create('payment', options);
      paymentElement.mount('#payment-element');

 const paymentForm = document.querySelector('#payment-form');
        paymentForm.addEventListener('submit', async (e) => {
          // Avoid a full page POST request.
          e.preventDefault();
          let errorMessage = document.getElementById("error-message");
           
          // Disable the form from submitting twice.
          paymentForm.querySelector('button').disabled = true;

          // Confirm the card payment that was created server side:
          const {error, paymentIntent } = await stripe.confirmPayment({
            elements,
            redirect: "if_required"
            /*confirmParams: {
              return_url: "if_required"  
            }*/
          });
          if(error) {
              
            errorMessage.innerHTML = error.message;
            // Re-enable the form so the customer can resubmit.
            paymentForm.querySelector('button').disabled = false;
            return;
          }
          else  {
                callBack();
            }
        });
};

StripePlugin.Valid = function(callBack){
    console.log("Execute Strip");
    
    callBack();
};
