diff --git a/js/civicrm_stripe.js b/js/civicrm_stripe.js index f2ab9df80452d7fe20a69a2b552ef35c2b0d31ce..dfb11c2f89ca7ae2cb3b0b45a1b5ef480c2e205c 100644 --- a/js/civicrm_stripe.js +++ b/js/civicrm_stripe.js @@ -232,8 +232,6 @@ CRM.$(function($) { }; // Pre-fill postcode field with existing value from form - debugging('billingAddressID: ' + CRM.vars.stripe.billingAddressID); - debugging(document.getElementById('billing_postal_code-' + CRM.vars.stripe.billingAddressID).value); var postCode = document.getElementById('billing_postal_code-' + CRM.vars.stripe.billingAddressID).value; debugging('existing postcode: ' + postCode); diff --git a/js/civicrm_stripe.min.js b/js/civicrm_stripe.min.js index 21ccb60c8f2870860fdfb1e929f68e85acb7b5ee..c0e9eb43a032cd83bbff401cc4b6c12487b7f6e2 100644 --- a/js/civicrm_stripe.min.js +++ b/js/civicrm_stripe.min.js @@ -1 +1 @@ -CRM.$(function(c){e("civicrm_stripe loaded, dom-ready function firing.");if(window.civicrmStripeHandleReload){e("calling existing civicrmStripeHandleReload.");window.civicrmStripeHandleReload();return}var p;var a;var b;var t;var n=false;window.onbeforeunload=null;window.civicrmStripeHandleReload=function(){e("civicrmStripeHandleReload");var B=document.getElementById("card-element");if((typeof B!=="undefined")&&(B)){if(!B.children.length){e("checkAndLoad from document.ready");l()}}};window.civicrmStripeHandleReload();function v(D,B){e(D+": success - submitting form");var C=document.createElement("input");C.setAttribute("type","hidden");C.setAttribute("name",D);C.setAttribute("value",B.id);b.appendChild(C);b.submit()}function o(){for(i=0;i<t.length;++i){t[i].setAttribute("disabled",true)}return b.submit()}function g(B){e("error: "+B.error.message);var C=document.getElementById("card-errors");C.style.display="block";C.textContent=B.error.message;document.querySelector("#billing-payment-block").scrollIntoView();window.scrollBy(0,-50);b.dataset.submitted=false;for(i=0;i<t.length;++i){t[i].removeAttribute("disabled")}}function z(){e("handle card payment");p.createPaymentMethod("card",a).then(function(B){if(B.error){g(B)}else{if(f()===true){v("paymentMethodID",B.paymentMethod)}else{var C=CRM.url("civicrm/stripe/confirm-payment");c.post(C,{payment_method_id:B.paymentMethod.id,amount:q(),currency:CRM.vars.stripe.currency,id:CRM.vars.stripe.id,description:document.title}).then(function(D){w(D)})}}})}function w(B){e("handleServerResponse");if(B.error){g(B)}else{if(B.requires_action){r(B)}else{v("paymentIntentID",B.paymentIntent)}}}function r(B){p.handleCardAction(B.payment_intent_client_secret).then(function(C){if(C.error){g(C)}else{v("paymentIntentID",C.paymentIntent)}})}c(document).ajaxComplete(function(D,E,C){if((C.url.match("civicrm(/|%2F)payment(/|%2F)form")!==null)||(C.url.match("civicrm(/|%2F)contact(/|%2F)view(/|%2F)participant")!==null)){if(typeof CRM.vars.stripe==="undefined"){return}var B=j();if(B!==null){if(B!==parseInt(CRM.vars.stripe.id)){e("payment processor changed to id: "+B);if(B===0){return k()}CRM.api3("PaymentProcessor","getvalue",{"return":"user_name",id:B,payment_processor_type_id:CRM.vars.stripe.paymentProcessorTypeID}).done(function(F){var G=F.result;if(G){e("Setting new stripe key to: "+G);CRM.vars.stripe.publishableKey=G}else{return k()}e("checkAndLoad from ajaxComplete");l()})}}}});function k(){e("New payment processor is not Stripe, clearing CRM.vars.stripe");if((typeof a!=="undefined")&&(a)){e("destroying card element");a.destroy();a=undefined}delete (CRM.vars.stripe)}function l(){if(typeof CRM.vars.stripe==="undefined"){e("CRM.vars.stripe not defined! Not a Stripe processor?");return}if(typeof Stripe==="undefined"){if(n){return}n=true;e("Stripe.js is not loaded!");c.getScript("https://js.stripe.com/v3",function(){e("Script loaded and executed.");n=false;d()})}else{d()}}function d(){e("loadStripeBillingBlock");if(typeof p==="undefined"){p=Stripe(CRM.vars.stripe.publishableKey)}var I=p.elements();var F={base:{fontSize:"20px"}};e("billingAddressID: "+CRM.vars.stripe.billingAddressID);e(document.getElementById("billing_postal_code-"+CRM.vars.stripe.billingAddressID).value);var C=document.getElementById("billing_postal_code-"+CRM.vars.stripe.billingAddressID).value;e("existing postcode: "+C);a=I.create("card",{style:F,value:{postalCode:C}});a.mount("#card-element");e("created new card element",a);if(document.getElementById("billing_postal_code-5").value){document.getElementById("billing_postal_code-5").setAttribute("disabled",true)}else{document.getElementsByClassName("billing_postal_code-"+CRM.vars.stripe.billingAddressID+"-section")[0].setAttribute("hidden",true)}a.addEventListener("change",function(J){u(J)});b=h();if(typeof b.length==="undefined"||b.length===0){e("No billing form!");return}t=A();b.dataset.submitdontprocess=false;var B=b.querySelectorAll('[type="submit"][formnovalidate="1"], [type="submit"][formnovalidate="formnovalidate"], [type="submit"].cancel, [type="submit"].webform-previous'),E;for(E=0;E<B.length;++E){B[E].addEventListener("click",H())}function H(){e("adding submitdontprocess");b.dataset.submitdontprocess=true}for(E=0;E<t.length;++E){t[E].addEventListener("click",D)}function D(J){if(b.dataset.submitted===true){return}b.dataset.submitted=true;if(typeof CRM.vars.stripe==="undefined"){return o()}e("clearing submitdontprocess");b.dataset.submitdontprocess=false;return G(J)}for(E=0;E<t.length;++E){t[E].removeAttribute("onclick")}m();if(y()){c("[type=submit]").click(function(){s(this.value)});b.addEventListener("keydown",function(J){if(J.keyCode===13){s(this.value);G(event)}});c("#billingcheckbox:input").hide();c('label[for="billingcheckbox"]').hide()}function G(L){L.preventDefault();e("submit handler");if(c(b).valid()===false){e("Form not valid");return false}if(typeof CRM.vars.stripe==="undefined"){e("Submitting - not a stripe processor");return true}if(b.dataset.submitted===true){e("form already submitted");return false}var N=parseInt(CRM.vars.stripe.id);var K=null;if(y()){if(!c('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]').length){K=N}else{K=parseInt(b.querySelector('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]:checked').value)}}else{if((b.querySelector(".crm-section.payment_processor-section")!==null)||(b.querySelector(".crm-section.credit_card_info-section")!==null)){N=CRM.vars.stripe.id;if(b.querySelector('input[name="payment_processor_id"]:checked')!==null){K=parseInt(b.querySelector('input[name="payment_processor_id"]:checked').value)}}}if((K===0)||(N===null)||((K===null)&&(N===null))){e("Not a Stripe transaction, or pay-later");return o()}else{e("Stripe is the selected payprocessor")}if(typeof CRM.vars.stripe.publishableKey==="undefined"){e("submit missing stripe-pub-key element or value");return true}if(b.dataset.submitdontprocess===true){e("non-payment submit detected - not submitting payment");return true}if(y()){if(c("#billing-payment-block").is(":hidden")){e("no payment processor on webform");return true}var M=c('[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]');if(M.length){if(M.filter(":checked").val()==="0"||M.filter(":checked").val()===0){e("no payment processor selected");return true}}}var J=q();if(J=="0"){e("Total amount is 0");return o()}if(b.dataset.submitted===true){alert("Form already submitted. Please wait.");return false}else{b.dataset.submitted=true}for(E=0;E<t.length;++E){t[E].setAttribute("disabled",true)}z();return true}}function y(){if(b!==null){return b.classList.contains("webform-client-form")||b.classList.contains("webform-submission-form")}return false}function h(){var B=c("div#card-element").closest("form").prop("id");if((typeof B==="undefined")||(!B.length)){B=c("input[name=hidden_processor]").closest("form").prop("id")}return document.getElementById(B)}function A(){var B=null;if(y()){B=b.querySelectorAll('[type="submit"].webform-submit');if(!B){B=b.querySelectorAll('[type="submit"].webform-button--submit')}}else{B=b.querySelectorAll('[type="submit"].validate')}return B}function q(){var B=0;if((document.getElementById("additional_participants")!==null)&&(document.getElementById("additional_participants").value.length!==0)){e("We don't know the final price - registering additional participants")}else{if(document.getElementById("totalTaxAmount")!==null){B=parseFloat(x());e("Calculated amount using internal calculateTaxAmount()")}else{if(typeof calculateTotalFee=="function"){B=parseFloat(calculateTotalFee())}else{if(y()){c(".line-item:visible","#wf-crm-billing-items").each(function(){B+=parseFloat(c(this).data("amount"))})}else{if(document.getElementById("total_amount")){B=parseFloat(document.getElementById("total_amount").value)}}}}}e("getTotalAmount: "+B.toFixed(2));return B.toFixed(2)}function x(){var B=0;if(document.getElementById("totalTaxAmount")===null){return B}B=document.getElementById("totalTaxAmount").textContent.split(" ").pop();return B}function f(){var B=false;if(y()){if(c('input[id$="contribution-installments"]').length!==0&&c('input[id$="contribution-installments"]').val()>1){B=true}}if(document.getElementById("is_recur")!==null){if(document.getElementById("is_recur").type=="hidden"){B=(document.getElementById("is_recur").value==1)}else{B=Boolean(document.getElementById("is_recur").checked)}}else{if(c('input[name="auto_renew"]').length!==0){if(c('input[name="auto_renew"]').prop("checked")){B=true}else{if(document.getElementById("auto_renew").type=="hidden"){B=(document.getElementById("auto_renew").value==1)}else{B=Boolean(document.getElementById("auto_renew").checked)}}}}e("isRecur is "+B);return B}function u(B){if(!B.complete){return}document.getElementById("billing_postal_code-"+CRM.vars.stripe.billingAddressID).value=B.value.postalCode}function m(){cividiscountElements=b.querySelectorAll("input#discountcode");var B=function(C){if(C.keyCode===13){C.preventDefault();e("adding submitdontprocess");b.dataset.submitdontprocess=true}};for(i=0;i<cividiscountElements.length;++i){cividiscountElements[i].addEventListener("keydown",B)}}function e(B){if((typeof(CRM.vars.stripe)==="undefined")||(Boolean(CRM.vars.stripe.jsDebug)===true)){console.log(new Date().toISOString()+" civicrm_stripe.js: "+B)}}function s(C){var B=null;if(document.getElementById("action")!==null){B=document.getElementById("action")}else{B=document.createElement("input")}B.setAttribute("type","hidden");B.setAttribute("name","op");B.setAttribute("id","action");B.setAttribute("value",C);b.appendChild(B)}function j(){if((typeof b==="undefined")||(!b)){b=h();if(!b){return null}}var B=b.querySelector('input[name="payment_processor_id"]:checked');if(B!==null){return parseInt(B.value)}return null}}); \ No newline at end of file +CRM.$(function(c){e("civicrm_stripe loaded, dom-ready function firing.");if(window.civicrmStripeHandleReload){e("calling existing civicrmStripeHandleReload.");window.civicrmStripeHandleReload();return}var p;var a;var b;var t;var n=false;window.onbeforeunload=null;window.civicrmStripeHandleReload=function(){e("civicrmStripeHandleReload");var B=document.getElementById("card-element");if((typeof B!=="undefined")&&(B)){if(!B.children.length){e("checkAndLoad from document.ready");l()}}};window.civicrmStripeHandleReload();function v(D,B){e(D+": success - submitting form");var C=document.createElement("input");C.setAttribute("type","hidden");C.setAttribute("name",D);C.setAttribute("value",B.id);b.appendChild(C);b.submit()}function o(){for(i=0;i<t.length;++i){t[i].setAttribute("disabled",true)}return b.submit()}function g(B){e("error: "+B.error.message);var C=document.getElementById("card-errors");C.style.display="block";C.textContent=B.error.message;document.querySelector("#billing-payment-block").scrollIntoView();window.scrollBy(0,-50);b.dataset.submitted=false;for(i=0;i<t.length;++i){t[i].removeAttribute("disabled")}}function z(){e("handle card payment");p.createPaymentMethod("card",a).then(function(B){if(B.error){g(B)}else{if(f()===true){v("paymentMethodID",B.paymentMethod)}else{var C=CRM.url("civicrm/stripe/confirm-payment");c.post(C,{payment_method_id:B.paymentMethod.id,amount:q(),currency:CRM.vars.stripe.currency,id:CRM.vars.stripe.id,description:document.title}).then(function(D){w(D)})}}})}function w(B){e("handleServerResponse");if(B.error){g(B)}else{if(B.requires_action){r(B)}else{v("paymentIntentID",B.paymentIntent)}}}function r(B){p.handleCardAction(B.payment_intent_client_secret).then(function(C){if(C.error){g(C)}else{v("paymentIntentID",C.paymentIntent)}})}c(document).ajaxComplete(function(D,E,C){if((C.url.match("civicrm(/|%2F)payment(/|%2F)form")!==null)||(C.url.match("civicrm(/|%2F)contact(/|%2F)view(/|%2F)participant")!==null)){if(typeof CRM.vars.stripe==="undefined"){return}var B=j();if(B!==null){if(B!==parseInt(CRM.vars.stripe.id)){e("payment processor changed to id: "+B);if(B===0){return k()}CRM.api3("PaymentProcessor","getvalue",{"return":"user_name",id:B,payment_processor_type_id:CRM.vars.stripe.paymentProcessorTypeID}).done(function(F){var G=F.result;if(G){e("Setting new stripe key to: "+G);CRM.vars.stripe.publishableKey=G}else{return k()}e("checkAndLoad from ajaxComplete");l()})}}}});function k(){e("New payment processor is not Stripe, clearing CRM.vars.stripe");if((typeof a!=="undefined")&&(a)){e("destroying card element");a.destroy();a=undefined}delete (CRM.vars.stripe)}function l(){if(typeof CRM.vars.stripe==="undefined"){e("CRM.vars.stripe not defined! Not a Stripe processor?");return}if(typeof Stripe==="undefined"){if(n){return}n=true;e("Stripe.js is not loaded!");c.getScript("https://js.stripe.com/v3",function(){e("Script loaded and executed.");n=false;d()})}else{d()}}function d(){e("loadStripeBillingBlock");if(typeof p==="undefined"){p=Stripe(CRM.vars.stripe.publishableKey)}var I=p.elements();var F={base:{fontSize:"20px"}};var C=document.getElementById("billing_postal_code-"+CRM.vars.stripe.billingAddressID).value;e("existing postcode: "+C);a=I.create("card",{style:F,value:{postalCode:C}});a.mount("#card-element");e("created new card element",a);if(document.getElementById("billing_postal_code-5").value){document.getElementById("billing_postal_code-5").setAttribute("disabled",true)}else{document.getElementsByClassName("billing_postal_code-"+CRM.vars.stripe.billingAddressID+"-section")[0].setAttribute("hidden",true)}a.addEventListener("change",function(J){u(J)});b=h();if(typeof b.length==="undefined"||b.length===0){e("No billing form!");return}t=A();b.dataset.submitdontprocess=false;var B=b.querySelectorAll('[type="submit"][formnovalidate="1"], [type="submit"][formnovalidate="formnovalidate"], [type="submit"].cancel, [type="submit"].webform-previous'),E;for(E=0;E<B.length;++E){B[E].addEventListener("click",H())}function H(){e("adding submitdontprocess");b.dataset.submitdontprocess=true}for(E=0;E<t.length;++E){t[E].addEventListener("click",D)}function D(J){if(b.dataset.submitted===true){return}b.dataset.submitted=true;if(typeof CRM.vars.stripe==="undefined"){return o()}e("clearing submitdontprocess");b.dataset.submitdontprocess=false;return G(J)}for(E=0;E<t.length;++E){t[E].removeAttribute("onclick")}m();if(y()){c("[type=submit]").click(function(){s(this.value)});b.addEventListener("keydown",function(J){if(J.keyCode===13){s(this.value);G(event)}});c("#billingcheckbox:input").hide();c('label[for="billingcheckbox"]').hide()}function G(L){L.preventDefault();e("submit handler");if(c(b).valid()===false){e("Form not valid");return false}if(typeof CRM.vars.stripe==="undefined"){e("Submitting - not a stripe processor");return true}if(b.dataset.submitted===true){e("form already submitted");return false}var N=parseInt(CRM.vars.stripe.id);var K=null;if(y()){if(!c('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]').length){K=N}else{K=parseInt(b.querySelector('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]:checked').value)}}else{if((b.querySelector(".crm-section.payment_processor-section")!==null)||(b.querySelector(".crm-section.credit_card_info-section")!==null)){N=CRM.vars.stripe.id;if(b.querySelector('input[name="payment_processor_id"]:checked')!==null){K=parseInt(b.querySelector('input[name="payment_processor_id"]:checked').value)}}}if((K===0)||(N===null)||((K===null)&&(N===null))){e("Not a Stripe transaction, or pay-later");return o()}else{e("Stripe is the selected payprocessor")}if(typeof CRM.vars.stripe.publishableKey==="undefined"){e("submit missing stripe-pub-key element or value");return true}if(b.dataset.submitdontprocess===true){e("non-payment submit detected - not submitting payment");return true}if(y()){if(c("#billing-payment-block").is(":hidden")){e("no payment processor on webform");return true}var M=c('[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]');if(M.length){if(M.filter(":checked").val()==="0"||M.filter(":checked").val()===0){e("no payment processor selected");return true}}}var J=q();if(J=="0"){e("Total amount is 0");return o()}if(b.dataset.submitted===true){alert("Form already submitted. Please wait.");return false}else{b.dataset.submitted=true}for(E=0;E<t.length;++E){t[E].setAttribute("disabled",true)}z();return true}}function y(){if(b!==null){return b.classList.contains("webform-client-form")||b.classList.contains("webform-submission-form")}return false}function h(){var B=c("div#card-element").closest("form").prop("id");if((typeof B==="undefined")||(!B.length)){B=c("input[name=hidden_processor]").closest("form").prop("id")}return document.getElementById(B)}function A(){var B=null;if(y()){B=b.querySelectorAll('[type="submit"].webform-submit');if(!B){B=b.querySelectorAll('[type="submit"].webform-button--submit')}}else{B=b.querySelectorAll('[type="submit"].validate')}return B}function q(){var B=0;if((document.getElementById("additional_participants")!==null)&&(document.getElementById("additional_participants").value.length!==0)){e("We don't know the final price - registering additional participants")}else{if(document.getElementById("totalTaxAmount")!==null){B=parseFloat(x());e("Calculated amount using internal calculateTaxAmount()")}else{if(typeof calculateTotalFee=="function"){B=parseFloat(calculateTotalFee())}else{if(y()){c(".line-item:visible","#wf-crm-billing-items").each(function(){B+=parseFloat(c(this).data("amount"))})}else{if(document.getElementById("total_amount")){B=parseFloat(document.getElementById("total_amount").value)}}}}}e("getTotalAmount: "+B.toFixed(2));return B.toFixed(2)}function x(){var B=0;if(document.getElementById("totalTaxAmount")===null){return B}B=document.getElementById("totalTaxAmount").textContent.split(" ").pop();return B}function f(){var B=false;if(y()){if(c('input[id$="contribution-installments"]').length!==0&&c('input[id$="contribution-installments"]').val()>1){B=true}}if(document.getElementById("is_recur")!==null){if(document.getElementById("is_recur").type=="hidden"){B=(document.getElementById("is_recur").value==1)}else{B=Boolean(document.getElementById("is_recur").checked)}}else{if(c('input[name="auto_renew"]').length!==0){if(c('input[name="auto_renew"]').prop("checked")){B=true}else{if(document.getElementById("auto_renew").type=="hidden"){B=(document.getElementById("auto_renew").value==1)}else{B=Boolean(document.getElementById("auto_renew").checked)}}}}e("isRecur is "+B);return B}function u(B){if(!B.complete){return}document.getElementById("billing_postal_code-"+CRM.vars.stripe.billingAddressID).value=B.value.postalCode}function m(){cividiscountElements=b.querySelectorAll("input#discountcode");var B=function(C){if(C.keyCode===13){C.preventDefault();e("adding submitdontprocess");b.dataset.submitdontprocess=true}};for(i=0;i<cividiscountElements.length;++i){cividiscountElements[i].addEventListener("keydown",B)}}function e(B){if((typeof(CRM.vars.stripe)==="undefined")||(Boolean(CRM.vars.stripe.jsDebug)===true)){console.log(new Date().toISOString()+" civicrm_stripe.js: "+B)}}function s(C){var B=null;if(document.getElementById("action")!==null){B=document.getElementById("action")}else{B=document.createElement("input")}B.setAttribute("type","hidden");B.setAttribute("name","op");B.setAttribute("id","action");B.setAttribute("value",C);b.appendChild(B)}function j(){if((typeof b==="undefined")||(!b)){b=h();if(!b){return null}}var B=b.querySelector('input[name="payment_processor_id"]:checked');if(B!==null){return parseInt(B.value)}return null}}); \ No newline at end of file