Commit b4fec98b authored by mattwire's avatar mattwire
Browse files

Allow submission of drupal webform when there are multiple processors on the...

Allow submission of drupal webform when there are multiple processors on the page (eg. Stripe + Pay later)
parent 3dd8c1f0
## Release 6.1.6
* Fix [#103](https://lab.civicrm.org/extensions/stripe/issues/103) - Allow submission of drupal webform when there are multiple processors on the page (eg. Stripe + Pay later).
## Release 6.1.5
* Send email receipts from Stripe by default (as this was what 5.x did). Add a setting under Administer->CiviContribute->Stripe Settings to enable/disable receipts from Stripe.
......
......@@ -13,8 +13,8 @@
<author>Matthew Wire (MJW Consulting)</author>
<email>mjw@mjwconsult.co.uk</email>
</maintainer>
<releaseDate>2019-09-25</releaseDate>
<version>6.1.5</version>
<releaseDate>2019-10-06</releaseDate>
<version>6.1.6</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.13</ver>
......
......@@ -53,6 +53,12 @@ CRM.$(function($) {
form.submit();
}
function nonStripeSubmit() {
// Disable the submit button to prevent repeated clicks
submitButton.setAttribute('disabled', true);
return form.submit();
}
function displayError(result) {
// Display error.message in your UI.
debugging('error: ' + result.error.message);
......@@ -267,7 +273,7 @@ CRM.$(function($) {
// Take over the click function of the form.
if (typeof CRM.vars.stripe === 'undefined') {
// Submit the form
return form.submit();
return nonStripeSubmit();
}
debugging('clearing submitdontprocess');
form.dataset.submitdontprocess = false;
......@@ -320,18 +326,17 @@ CRM.$(function($) {
return false;
}
var stripeProcessorId = CRM.vars.stripe.id;
var stripeProcessorId = parseInt(CRM.vars.stripe.id);
var chosenProcessorId = null;
// Handle multiple payment options and Stripe not being chosen.
// @fixme this needs refactoring as some is not relevant anymore (with stripe 6.0)
if (getIsDrupalWebform()) {
stripeProcessorId = CRM.vars.stripe.id;
// this element may or may not exist on the webform, but we are dealing with a single (stripe) processor enabled.
if (!$('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]').length) {
chosenProcessorId = stripeProcessorId;
} else {
chosenProcessorId = form.querySelector('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]:checked').val();
chosenProcessorId = parseInt(form.querySelector('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]:checked').value);
}
}
else {
......@@ -340,7 +345,7 @@ CRM.$(function($) {
(form.querySelector(".crm-section.credit_card_info-section") !== null)) {
stripeProcessorId = CRM.vars.stripe.id;
if (form.querySelector('input[name="payment_processor_id"]:checked') !== null) {
chosenProcessorId = form.querySelector('input[name="payment_processor_id"]:checked').value;
chosenProcessorId = parseInt(form.querySelector('input[name="payment_processor_id"]:checked').value);
}
}
}
......@@ -352,7 +357,7 @@ CRM.$(function($) {
if ((chosenProcessorId === 0) || (stripeProcessorId === null) ||
((chosenProcessorId === null) && (stripeProcessorId === null))) {
debugging('Not a Stripe transaction, or pay-later');
return true;
return nonStripeSubmit();
}
else {
debugging('Stripe is the selected payprocessor');
......
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(B,z){f(B+": success - submitting form");var A=document.createElement("input");A.setAttribute("type","hidden");A.setAttribute("name",B);A.setAttribute("value",z.id);c.appendChild(A);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{if(g()===true){u("paymentMethodID",z.paymentMethod)}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}).then(function(B){v(B)})}}})}function v(z){f("handleServerResponse");if(z.error){h(z)}else{if(z.requires_action){r(z)}else{u("paymentIntentID",z.paymentIntent)}}}function r(z){p.handleCardAction(z.payment_intent_client_secret).then(function(A){if(A.error){h(A)}else{u("paymentIntentID",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").checked)}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
CRM.$(function(d){f("civicrm_stripe loaded, dom-ready function firing.");if(window.civicrmStripeHandleReload){f("calling existing civicrmStripeHandleReload.");window.civicrmStripeHandleReload();return}var q;var b;var c;var a;var o=false;window.onbeforeunload=null;window.civicrmStripeHandleReload=function(){f("civicrmStripeHandleReload");var A=document.getElementById("card-element");if((typeof A!=="undefined")&&(A)){if(!A.children.length){f("checkAndLoad from document.ready");m()}}};window.civicrmStripeHandleReload();function v(C,A){f(C+": success - submitting form");var B=document.createElement("input");B.setAttribute("type","hidden");B.setAttribute("name",C);B.setAttribute("value",A.id);c.appendChild(B);c.submit()}function p(){a.setAttribute("disabled",true);return c.submit()}function h(A){f("error: "+A.error.message);var B=document.getElementById("card-errors");B.style.display="block";B.textContent=A.error.message;document.querySelector("#billing-payment-block").scrollIntoView();window.scrollBy(0,-50);c.dataset.submitted=false;a.removeAttribute("disabled")}function y(){f("handle card payment");q.createPaymentMethod("card",b).then(function(A){if(A.error){h(A)}else{if(g()===true){v("paymentMethodID",A.paymentMethod)}else{var B=CRM.url("civicrm/stripe/confirm-payment");d.post(B,{payment_method_id:A.paymentMethod.id,amount:r(),currency:CRM.vars.stripe.currency,id:CRM.vars.stripe.id}).then(function(C){w(C)})}}})}function w(A){f("handleServerResponse");if(A.error){h(A)}else{if(A.requires_action){s(A)}else{v("paymentIntentID",A.paymentIntent)}}}function s(A){q.handleCardAction(A.payment_intent_client_secret).then(function(B){if(B.error){h(B)}else{v("paymentIntentID",B.paymentIntent)}})}d(document).ajaxComplete(function(C,D,B){if((B.url.match("civicrm(/|%2F)payment(/|%2F)form")!==null)||(B.url.match("civicrm(/|%2F)contact(/|%2F)view(/|%2F)participant")!==null)){if(typeof CRM.vars.stripe==="undefined"){return}var A=k();if(A!==null){if(A!==parseInt(CRM.vars.stripe.id)){f("payment processor changed to id: "+A);if(A===0){return l()}CRM.api3("PaymentProcessor","getvalue",{"return":"user_name",id:A,payment_processor_type_id:CRM.vars.stripe.paymentProcessorTypeID}).done(function(E){var F=E.result;if(F){f("Setting new stripe key to: "+F);CRM.vars.stripe.publishableKey=F}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 q==="undefined"){q=Stripe(CRM.vars.stripe.publishableKey)}var G=q.elements();var D={base:{fontSize:"20px"}};b=G.create("card",{style:D});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(H){u(H)});c=j();if(typeof c.length==="undefined"||c.length===0){f("No billing form!");return}a=z();c.dataset.submitdontprocess=false;var A=c.querySelectorAll('[type="submit"][formnovalidate="1"], [type="submit"][formnovalidate="formnovalidate"], [type="submit"].cancel, [type="submit"].webform-previous'),C;for(C=0;C<A.length;++C){A[C].addEventListener("click",F())}function F(){f("adding submitdontprocess");c.dataset.submitdontprocess=true}a.addEventListener("click",B);function B(H){if(c.dataset.submitted===true){return}c.dataset.submitted=true;if(typeof CRM.vars.stripe==="undefined"){return p()}f("clearing submitdontprocess");c.dataset.submitdontprocess=false;return E(H)}a.removeAttribute("onclick");n();if(x()){d("[type=submit]").click(function(){t(this.value)});c.addEventListener("keydown",function(H){if(H.keyCode===13){t(this.value);E(event)}});d("#billingcheckbox:input").hide();d('label[for="billingcheckbox"]').hide()}function E(J){J.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 L=parseInt(CRM.vars.stripe.id);var I=null;if(x()){if(!d('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]').length){I=L}else{I=parseInt(c.querySelector('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]:checked').value)}}else{if((c.querySelector(".crm-section.payment_processor-section")!==null)||(c.querySelector(".crm-section.credit_card_info-section")!==null)){L=CRM.vars.stripe.id;if(c.querySelector('input[name="payment_processor_id"]:checked')!==null){I=parseInt(c.querySelector('input[name="payment_processor_id"]:checked').value)}}}if((I===0)||(L===null)||((I===null)&&(L===null))){f("Not a Stripe transaction, or pay-later");return p()}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(x()){if(d("#billing-payment-block").is(":hidden")){f("no payment processor on webform");return true}var K=d('[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]');if(K.length){if(K.filter(":checked").val()==="0"||K.filter(":checked").val()===0){f("no payment processor selected");return true}}}var H=r();if(H=="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);y();return true}}function x(){if(c!==null){return c.classList.contains("webform-client-form")||c.classList.contains("webform-submission-form")}return false}function j(){var A=d("div#card-element").closest("form").prop("id");if((typeof A==="undefined")||(!A.length)){A=d("input[name=hidden_processor]").closest("form").prop("id")}return document.getElementById(A)}function z(){var A=null;if(x()){A=c.querySelector('[type="submit"].webform-submit');if(!A){A=c.querySelector('[type="submit"].webform-button--submit')}}else{A=c.querySelector('[type="submit"].validate')}return A}function r(){var A=null;if(typeof calculateTotalFee=="function"){A=calculateTotalFee()}else{if(x()){d(".line-item:visible","#wf-crm-billing-items").each(function(){A+=parseFloat(d(this).data("amount"))})}else{if(document.getElementById("total_amount")){return document.getElementById("total_amount").value}}}return A}function g(){if(document.getElementById("is_recur")!==null){return Boolean(document.getElementById("is_recur").checked)}return false}function u(A){if(!A.complete){return}document.getElementById("billing_postal_code-"+CRM.vars.stripe.billingAddressID).value=A.value.postalCode}function n(){cividiscountElements=c.querySelectorAll("input#discountcode");var A=function(B){if(B.keyCode===13){B.preventDefault();f("adding submitdontprocess");c.dataset.submitdontprocess=true}};for(i=0;i<cividiscountElements.length;++i){cividiscountElements[i].addEventListener("keydown",A)}}function f(A){if((typeof(CRM.vars.stripe)==="undefined")||(Boolean(CRM.vars.stripe.jsDebug)===true)){console.log(new Date().toISOString()+" civicrm_stripe.js: "+A)}}function t(B){var A=null;if(document.getElementById("action")!==null){A=document.getElementById("action")}else{A=document.createElement("input")}A.setAttribute("type","hidden");A.setAttribute("name","op");A.setAttribute("id","action");A.setAttribute("value",B);c.appendChild(A)}function k(){if((typeof c==="undefined")||(!c)){c=j();if(!c){return null}}var A=c.querySelector('input[name="payment_processor_id"]:checked');if(A!==null){return parseInt(A.value)}return null}});
\ No newline at end of file
Markdown is supported
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