Commit 3cfe9fb3 authored by mattwire's avatar mattwire
Browse files

If we get an error during submission, make sure we run Stripe submit next time we submit

parent a179000c
......@@ -62,6 +62,7 @@ CRM.$(function($) {
errorElement.textContent = result.error.message;
document.querySelector('#billing-payment-block').scrollIntoView();
window.scrollBy(0, -50);
form.dataset.submitted = false;
submitButton.removeAttribute('disabled');
}
......@@ -80,6 +81,7 @@ CRM.$(function($) {
amount: getTotalAmount(),
currency: CRM.vars.stripe.currency,
id: CRM.vars.stripe.id,
recur: getIsRecur(),
}).then(function (result) {
// Handle server response (see Step 3)
handleServerResponse(result);
......@@ -254,7 +256,7 @@ CRM.$(function($) {
submitButton.addEventListener('click', submitButtonClick);
function submitButtonClick(event) {
if (form.dataset.submitted) {
if (form.dataset.submitted === true) {
return;
}
form.dataset.submitted = true;
......@@ -461,6 +463,13 @@ CRM.$(function($) {
return totalFee;
}
function getIsRecur() {
if (document.getElementById('is_recur') !== null) {
return Boolean(document.getElementById('is_recur').value);
}
return false;
}
function updateFormElementsFromCreditCardDetails(event) {
if (!event.complete) {
return;
......
CRM.$(function(d){f("civicrm_stripe loaded, dom-ready function firing.");if(window.civicrmStripeHandleReload){f("calling existing civicrmStripeHandleReload.");window.civicrmStripeHandleReload();return}var o;var b;var c;var a;var n=false;window.onbeforeunload=null;window.civicrmStripeHandleReload=function(){f("civicrmStripeHandleReload");var y=document.getElementById("card-element");if((typeof y!=="undefined")&&(y)){if(!y.children.length){f("checkAndLoad from document.ready");l()}}};window.civicrmStripeHandleReload();function t(z){f("paymentIntent confirmation success");var y=document.createElement("input");y.setAttribute("type","hidden");y.setAttribute("name","paymentIntentID");y.setAttribute("value",z.id);c.appendChild(y);c.submit()}function g(y){f("error: "+y.error.message);var z=document.getElementById("card-errors");z.style.display="block";z.textContent=y.error.message;document.querySelector("#billing-payment-block").scrollIntoView();window.scrollBy(0,-50);a.removeAttribute("disabled")}function w(){f("handle card payment");o.createPaymentMethod("card",b).then(function(y){if(y.error){g(y)}else{var z=CRM.url("civicrm/stripe/confirm-payment");d.post(z,{payment_method_id:y.paymentMethod.id,amount:p(),currency:CRM.vars.stripe.currency,id:CRM.vars.stripe.id}).then(function(A){u(A)})}})}function u(y){f("handleServerResponse");if(y.error){g(y)}else{if(y.requires_action){q(y)}else{t(y.paymentIntent)}}}function q(y){o.handleCardAction(y.payment_intent_client_secret).then(function(z){if(z.error){g(z)}else{t(z.paymentIntent)}})}d(document).ajaxComplete(function(A,B,z){if((z.url.match("civicrm(/|%2F)payment(/|%2F)form")!==null)||(z.url.match("civicrm(/|%2F)contact(/|%2F)view(/|%2F)participant")!==null)){if(typeof CRM.vars.stripe==="undefined"){return}var y=j();if(y!==null){if(y!==parseInt(CRM.vars.stripe.id)){f("payment processor changed to id: "+y);if(y===0){return k()}CRM.api3("PaymentProcessor","getvalue",{"return":"user_name",id:y,payment_processor_type_id:CRM.vars.stripe.paymentProcessorTypeID}).done(function(C){var D=C.result;if(D){f("Setting new stripe key to: "+D);CRM.vars.stripe.publishableKey=D}else{return k()}f("checkAndLoad from ajaxComplete");l()})}}}});function k(){f("New payment processor is not Stripe, clearing CRM.vars.stripe");if((typeof b!=="undefined")&&(b)){f("destroying card element");b.destroy();b=undefined}delete (CRM.vars.stripe)}function l(){if(typeof CRM.vars.stripe==="undefined"){f("CRM.vars.stripe not defined! Not a Stripe processor?");return}if(typeof Stripe==="undefined"){if(n){return}n=true;f("Stripe.js is not loaded!");d.getScript("https://js.stripe.com/v3",function(){f("Script loaded and executed.");n=false;e()})}else{e()}}function e(){f("loadStripeBillingBlock");if(typeof o==="undefined"){o=Stripe(CRM.vars.stripe.publishableKey)}var E=o.elements();var B={base:{fontSize:"20px"}};b=E.create("card",{style:B});b.mount("#card-element");f("created new card element",b);document.getElementsByClassName("billing_postal_code-"+CRM.vars.stripe.billingAddressID+"-section")[0].setAttribute("hidden",true);b.addEventListener("change",function(F){s(F)});c=h();if(typeof c.length==="undefined"||c.length===0){f("No billing form!");return}a=x();c.dataset.submitdontprocess=false;var y=c.querySelectorAll('[type="submit"][formnovalidate="1"], [type="submit"][formnovalidate="formnovalidate"], [type="submit"].cancel, [type="submit"].webform-previous'),A;for(A=0;A<y.length;++A){y[A].addEventListener("click",D())}function D(){f("adding submitdontprocess");c.dataset.submitdontprocess=true}a.addEventListener("click",z);function z(F){if(c.dataset.submitted){return}c.dataset.submitted=true;if(typeof CRM.vars.stripe==="undefined"){return c.submit()}f("clearing submitdontprocess");c.dataset.submitdontprocess=false;return C(F)}a.removeAttribute("onclick");m();if(v()){d("[type=submit]").click(function(){r(this.value)});c.addEventListener("keydown",function(F){if(F.keyCode===13){r(this.value);C(event)}});d("#billingcheckbox:input").hide();d('label[for="billingcheckbox"]').hide()}function C(H){H.preventDefault();f("submit handler");if(d(c).valid()===false){f("Form not valid");return false}if(typeof CRM.vars.stripe==="undefined"){f("Submitting - not a stripe processor");return true}if(c.dataset.submitted===true){f("form already submitted");return false}var J=CRM.vars.stripe.id;var G=null;if(v()){J=CRM.vars.stripe.id;if(!d('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]').length){G=J}else{G=c.querySelector('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]:checked').val()}}else{if((c.querySelector(".crm-section.payment_processor-section")!==null)||(c.querySelector(".crm-section.credit_card_info-section")!==null)){J=CRM.vars.stripe.id;if(c.querySelector('input[name="payment_processor_id"]:checked')!==null){G=c.querySelector('input[name="payment_processor_id"]:checked').value}}}if((G===0)||(J===null)||((G===null)&&(J===null))){f("Not a Stripe transaction, or pay-later");return true}else{f("Stripe is the selected payprocessor")}if(typeof CRM.vars.stripe.publishableKey==="undefined"){f("submit missing stripe-pub-key element or value");return true}if(c.dataset.submitdontprocess===true){f("non-payment submit detected - not submitting payment");return true}if(v()){if(d("#billing-payment-block").is(":hidden")){f("no payment processor on webform");return true}var I=d('[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]');if(I.length){if(I.filter(":checked").val()==="0"||I.filter(":checked").val()===0){f("no payment processor selected");return true}}}var F=p();if(F=="0"){f("Total amount is 0");return true}if(c.dataset.submitted===true){alert("Form already submitted. Please wait.");return false}else{c.dataset.submitted=true}a.setAttribute("disabled",true);w();return true}}function v(){if(c!==null){return c.classList.contains("webform-client-form")||c.classList.contains("webform-submission-form")}return false}function h(){var y=d("div#card-element").closest("form").prop("id");if((typeof y==="undefined")||(!y.length)){y=d("input[name=hidden_processor]").closest("form").prop("id")}return document.getElementById(y)}function x(){var y=null;if(v()){y=c.querySelector('[type="submit"].webform-submit');if(!y){y=c.querySelector('[type="submit"].webform-button--submit')}}else{y=c.querySelector('[type="submit"].validate')}return y}function p(){var y=null;if(typeof calculateTotalFee=="function"){y=calculateTotalFee()}else{if(v()){d(".line-item:visible","#wf-crm-billing-items").each(function(){y+=parseFloat(d(this).data("amount"))})}else{if(document.getElementById("total_amount")){return document.getElementById("total_amount").value}}}return y}function s(y){if(!y.complete){return}document.getElementById("billing_postal_code-"+CRM.vars.stripe.billingAddressID).value=y.value.postalCode}function m(){cividiscountElements=c.querySelectorAll("input#discountcode");var y=function(z){if(z.keyCode===13){z.preventDefault();f("adding submitdontprocess");c.dataset.submitdontprocess=true}};for(i=0;i<cividiscountElements.length;++i){cividiscountElements[i].addEventListener("keydown",y)}}function f(y){if((typeof(CRM.vars.stripe)==="undefined")||(Boolean(CRM.vars.stripe.jsDebug)===true)){console.log(new Date().toISOString()+" civicrm_stripe.js: "+y)}}function r(z){var y=null;if(document.getElementById("action")!==null){y=document.getElementById("action")}else{y=document.createElement("input")}y.setAttribute("type","hidden");y.setAttribute("name","op");y.setAttribute("id","action");y.setAttribute("value",z);c.appendChild(y)}function j(){if((typeof c==="undefined")||(!c)){c=h();if(!c){return null}}var y=c.querySelector('input[name="payment_processor_id"]:checked');if(y!==null){return parseInt(y.value)}return null}});
\ No newline at end of file
CRM.$(function(d){f("civicrm_stripe loaded, dom-ready function firing.");if(window.civicrmStripeHandleReload){f("calling existing civicrmStripeHandleReload.");window.civicrmStripeHandleReload();return}var p;var b;var c;var a;var o=false;window.onbeforeunload=null;window.civicrmStripeHandleReload=function(){f("civicrmStripeHandleReload");var z=document.getElementById("card-element");if((typeof z!=="undefined")&&(z)){if(!z.children.length){f("checkAndLoad from document.ready");m()}}};window.civicrmStripeHandleReload();function u(A){f("paymentIntent confirmation success");var z=document.createElement("input");z.setAttribute("type","hidden");z.setAttribute("name","paymentIntentID");z.setAttribute("value",A.id);c.appendChild(z);c.submit()}function h(z){f("error: "+z.error.message);var A=document.getElementById("card-errors");A.style.display="block";A.textContent=z.error.message;document.querySelector("#billing-payment-block").scrollIntoView();window.scrollBy(0,-50);c.dataset.submitted=false;a.removeAttribute("disabled")}function x(){f("handle card payment");p.createPaymentMethod("card",b).then(function(z){if(z.error){h(z)}else{var A=CRM.url("civicrm/stripe/confirm-payment");d.post(A,{payment_method_id:z.paymentMethod.id,amount:q(),currency:CRM.vars.stripe.currency,id:CRM.vars.stripe.id,recur:g()}).then(function(B){v(B)})}})}function v(z){f("handleServerResponse");if(z.error){h(z)}else{if(z.requires_action){r(z)}else{u(z.paymentIntent)}}}function r(z){p.handleCardAction(z.payment_intent_client_secret).then(function(A){if(A.error){h(A)}else{u(A.paymentIntent)}})}d(document).ajaxComplete(function(B,C,A){if((A.url.match("civicrm(/|%2F)payment(/|%2F)form")!==null)||(A.url.match("civicrm(/|%2F)contact(/|%2F)view(/|%2F)participant")!==null)){if(typeof CRM.vars.stripe==="undefined"){return}var z=k();if(z!==null){if(z!==parseInt(CRM.vars.stripe.id)){f("payment processor changed to id: "+z);if(z===0){return l()}CRM.api3("PaymentProcessor","getvalue",{"return":"user_name",id:z,payment_processor_type_id:CRM.vars.stripe.paymentProcessorTypeID}).done(function(D){var E=D.result;if(E){f("Setting new stripe key to: "+E);CRM.vars.stripe.publishableKey=E}else{return l()}f("checkAndLoad from ajaxComplete");m()})}}}});function l(){f("New payment processor is not Stripe, clearing CRM.vars.stripe");if((typeof b!=="undefined")&&(b)){f("destroying card element");b.destroy();b=undefined}delete (CRM.vars.stripe)}function m(){if(typeof CRM.vars.stripe==="undefined"){f("CRM.vars.stripe not defined! Not a Stripe processor?");return}if(typeof Stripe==="undefined"){if(o){return}o=true;f("Stripe.js is not loaded!");d.getScript("https://js.stripe.com/v3",function(){f("Script loaded and executed.");o=false;e()})}else{e()}}function e(){f("loadStripeBillingBlock");if(typeof p==="undefined"){p=Stripe(CRM.vars.stripe.publishableKey)}var F=p.elements();var C={base:{fontSize:"20px"}};b=F.create("card",{style:C});b.mount("#card-element");f("created new card element",b);document.getElementsByClassName("billing_postal_code-"+CRM.vars.stripe.billingAddressID+"-section")[0].setAttribute("hidden",true);b.addEventListener("change",function(G){t(G)});c=j();if(typeof c.length==="undefined"||c.length===0){f("No billing form!");return}a=y();c.dataset.submitdontprocess=false;var z=c.querySelectorAll('[type="submit"][formnovalidate="1"], [type="submit"][formnovalidate="formnovalidate"], [type="submit"].cancel, [type="submit"].webform-previous'),B;for(B=0;B<z.length;++B){z[B].addEventListener("click",E())}function E(){f("adding submitdontprocess");c.dataset.submitdontprocess=true}a.addEventListener("click",A);function A(G){if(c.dataset.submitted===true){return}c.dataset.submitted=true;if(typeof CRM.vars.stripe==="undefined"){return c.submit()}f("clearing submitdontprocess");c.dataset.submitdontprocess=false;return D(G)}a.removeAttribute("onclick");n();if(w()){d("[type=submit]").click(function(){s(this.value)});c.addEventListener("keydown",function(G){if(G.keyCode===13){s(this.value);D(event)}});d("#billingcheckbox:input").hide();d('label[for="billingcheckbox"]').hide()}function D(I){I.preventDefault();f("submit handler");if(d(c).valid()===false){f("Form not valid");return false}if(typeof CRM.vars.stripe==="undefined"){f("Submitting - not a stripe processor");return true}if(c.dataset.submitted===true){f("form already submitted");return false}var K=CRM.vars.stripe.id;var H=null;if(w()){K=CRM.vars.stripe.id;if(!d('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]').length){H=K}else{H=c.querySelector('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]:checked').val()}}else{if((c.querySelector(".crm-section.payment_processor-section")!==null)||(c.querySelector(".crm-section.credit_card_info-section")!==null)){K=CRM.vars.stripe.id;if(c.querySelector('input[name="payment_processor_id"]:checked')!==null){H=c.querySelector('input[name="payment_processor_id"]:checked').value}}}if((H===0)||(K===null)||((H===null)&&(K===null))){f("Not a Stripe transaction, or pay-later");return true}else{f("Stripe is the selected payprocessor")}if(typeof CRM.vars.stripe.publishableKey==="undefined"){f("submit missing stripe-pub-key element or value");return true}if(c.dataset.submitdontprocess===true){f("non-payment submit detected - not submitting payment");return true}if(w()){if(d("#billing-payment-block").is(":hidden")){f("no payment processor on webform");return true}var J=d('[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]');if(J.length){if(J.filter(":checked").val()==="0"||J.filter(":checked").val()===0){f("no payment processor selected");return true}}}var G=q();if(G=="0"){f("Total amount is 0");return true}if(c.dataset.submitted===true){alert("Form already submitted. Please wait.");return false}else{c.dataset.submitted=true}a.setAttribute("disabled",true);x();return true}}function w(){if(c!==null){return c.classList.contains("webform-client-form")||c.classList.contains("webform-submission-form")}return false}function j(){var z=d("div#card-element").closest("form").prop("id");if((typeof z==="undefined")||(!z.length)){z=d("input[name=hidden_processor]").closest("form").prop("id")}return document.getElementById(z)}function y(){var z=null;if(w()){z=c.querySelector('[type="submit"].webform-submit');if(!z){z=c.querySelector('[type="submit"].webform-button--submit')}}else{z=c.querySelector('[type="submit"].validate')}return z}function q(){var z=null;if(typeof calculateTotalFee=="function"){z=calculateTotalFee()}else{if(w()){d(".line-item:visible","#wf-crm-billing-items").each(function(){z+=parseFloat(d(this).data("amount"))})}else{if(document.getElementById("total_amount")){return document.getElementById("total_amount").value}}}return z}function g(){if(document.getElementById("is_recur")!==null){return Boolean(document.getElementById("is_recur").value)}return false}function t(z){if(!z.complete){return}document.getElementById("billing_postal_code-"+CRM.vars.stripe.billingAddressID).value=z.value.postalCode}function n(){cividiscountElements=c.querySelectorAll("input#discountcode");var z=function(A){if(A.keyCode===13){A.preventDefault();f("adding submitdontprocess");c.dataset.submitdontprocess=true}};for(i=0;i<cividiscountElements.length;++i){cividiscountElements[i].addEventListener("keydown",z)}}function f(z){if((typeof(CRM.vars.stripe)==="undefined")||(Boolean(CRM.vars.stripe.jsDebug)===true)){console.log(new Date().toISOString()+" civicrm_stripe.js: "+z)}}function s(A){var z=null;if(document.getElementById("action")!==null){z=document.getElementById("action")}else{z=document.createElement("input")}z.setAttribute("type","hidden");z.setAttribute("name","op");z.setAttribute("id","action");z.setAttribute("value",A);c.appendChild(z)}function k(){if((typeof c==="undefined")||(!c)){c=j();if(!c){return null}}var z=c.querySelector('input[name="payment_processor_id"]:checked');if(z!==null){return parseInt(z.value)}return null}});
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment