$(document).ready(function() { $('#PayNow').click(function() { //console.log('hi'); }); }); function LoadCardForm() { const stripe = Stripe('pk_live_51I8nKVJykoRNjRDVxZUvgbRxOHWujvS8eQULXOnRehKslmtJle2xf4nQi0mt80s05w2onTBe9eakN2p6vCJtHSp700Egr55sHl'); const options = { clientSecret: secret, // Fully customizable with appearance API. appearance: {/*...*/}, }; // Set up Stripe.js and Elements to use in checkout form, passing the client secret obtained in a previous step const elements = stripe.elements(options); initialize(); //checkStatus(); document .querySelector('#PayNow') .addEventListener('click', handleSubmit); let emailAddress = ''; // Fetches a payment intent and captures the client secret async function initialize() { setLoading(false); // Create and mount the Payment Element const paymentElement = elements.create('card'); paymentElement.mount('#card-element'); } async function handleSubmit(e) { e.preventDefault(); setLoading(true); const { error } = await stripe.confirmPayment({ elements, confirmParams: { // Make sure to change this to your payment completion page //return_url: 'http://localhost:4242/checkout.html', receipt_email: $('#ContactEmail').val(), }, redirect: 'if_required', }).then(function(result) { //console.log(result); var data = JSON.stringify(result); $.ajax({ type: 'POST', url: '../../../../Components/CWEBO/Assets/AJAX/PaymentMade.php?AccountID='+$('#AccountID').val()+'&ContactID='+$('#ContactID').val(), dataType : 'text', // data type data : 'data='+data, success: function(msg){ //console.log('Worked'); } }); $('#MakePaymentWrapper').html('
Thank you for your payment today. Your confirmation code is '+result.paymentIntent.id+'. Please keep this code for your records.
'); $('#header .icons .red').hide(); }); // This point will only be reached if there is an immediate error when // confirming the payment. Otherwise, your customer will be redirected to // your `return_url`. For some payment methods like iDEAL, your customer will // be redirected to an intermediate site first to authorize the payment, then // redirected to the `return_url`. if (error.type === 'card_error' || error.type === 'validation_error') { showMessage(error.message); } else { showMessage('An unexpected error occurred.'); } setLoading(false); } // Fetches the payment intent status after payment submission async function checkStatus() { const clientSecret = new URLSearchParams(window.location.search).get( 'payment_intent_client_secret' ); if (!clientSecret) { return; } const { paymentIntent } = await stripe.retrievePaymentIntent(clientSecret); switch (paymentIntent.status) { case 'succeeded': showMessage('Payment succeeded!'); break; case 'processing': showMessage('Your payment is processing.'); break; case 'requires_payment_method': showMessage('Your payment was not successful, please try again.'); break; default: showMessage('Something went wrong.'); break; } } // ------- UI helpers ------- function showMessage(messageText) { const messageContainer = document.querySelector('#card-errors'); //messageContainer.classList.remove('hidden'); //messageContainer.textContent = messageText; // setTimeout(function () { // messageContainer.classList.add('hidden'); // messageContainer.textContent = ''; // }, 4000); } // Show a spinner on payment submission function setLoading(isLoading) { if (isLoading) { // Disable the button and show a spinner document.querySelector('#PayNow').disabled = true; document.querySelector('#spinner').classList.remove('hidden'); document.querySelector('#button-text').classList.add('hidden'); } else { document.querySelector('#PayNow').disabled = false; document.querySelector('#spinner').classList.add('hidden'); document.querySelector('#button-text').classList.remove('hidden'); } } } function SaveRegisterCard() { var paymentElement = elements.getElement('card'); //console.log(paymentElement); stripe.createPaymentMethod({ type: 'card', card: paymentElement, billing_details: { name: $('#ContactName').val(), }, }).then(function(result) { var s = stripe('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'); console.log(result.paymentMethod); console.log(s); console.log(customer); s.paymentMethods.attach( result.paymentMethod.id, {customer: $('#AccountStripeID').val()} ); }); } function LoadRegisterCardForm() { initialize(); // Fetches a payment intent and captures the client secret async function initialize() { // Create and mount the Payment Element var style = { base: { color: '#12312d', padding: '10px', } }; const paymentElement = elements.create('card', { style: style }); paymentElement.mount('#card-element'); paymentElement.on('change', ({error}) => { let displayError = document.getElementById('card-errors'); if (error) { displayError.textContent = error.message; } else { displayError.textContent = ''; } }); } }