Skip to content
Snippets Groups Projects
Commit dd41651e authored by mattwire's avatar mattwire
Browse files

Use minifier extension to minify js/css assets

parent d409cbb8
Branches
Tags
1 merge request!1096.4
......@@ -13,11 +13,16 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
use CRM_Core_Payment_MJWTrait;
/**
*
* @var string
*/
const API_VERSION = '2019-12-03';
/**
* @var string
*/
const MIN_VERSION_MJWSHARED = '0.7';
/**
* Mode of operation: live or test.
*
......@@ -349,13 +354,18 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
['template' => 'CRM/Core/Payment/Stripe/Card.tpl', 'weight' => -1]);
// Add CSS via region (it won't load on drupal webform if added via \Civi::resources()->addStyleFile)
$min = ((boolean) \Civi::settings()->get('stripe_jsdebug')) ? '' : '.min';
CRM_Core_Region::instance('billing-block')->add([
'styleUrl' => \Civi::resources()->getUrl(E::LONG_NAME, "css/elements{$min}.css", TRUE),
'styleUrl' => \Civi::service('asset_builder')->getUrl(
'elements.css',
['path' => \Civi::resources()->getPath(E::LONG_NAME, 'css/elements.css')]
),
'weight' => -1,
]);
CRM_Core_Region::instance('billing-block')->add([
'scriptUrl' => \Civi::resources()->getUrl(E::LONG_NAME, "js/civicrm_stripe{$min}.js", TRUE),
'scriptUrl' => \Civi::service('asset_builder')->getUrl(
'civicrmStripe.js',
['path' => \Civi::resources()->getPath(E::LONG_NAME, 'js/civicrm_stripe.js')]
)
]);
}
......
......@@ -10,8 +10,6 @@ use CRM_Stripe_ExtensionUtil as E;
*/
class CRM_Stripe_Check {
const MIN_VERSION_MJWSHARED = '0.6';
public static function checkRequirements(&$messages) {
$extensions = civicrm_api3('Extension', 'get', [
'full_name' => "mjwshared",
......@@ -27,12 +25,12 @@ class CRM_Stripe_Check {
);
}
if (version_compare($extensions['values'][$extensions['id']]['version'], self::MIN_VERSION_MJWSHARED) === -1) {
if (version_compare($extensions['values'][$extensions['id']]['version'], CRM_Core_Payment_Stripe::MIN_VERSION_MJWSHARED) === -1) {
$messages[] = new CRM_Utils_Check_Message(
'stripe_requirements',
E::ts('The Stripe extension requires the mjwshared extension version %1 or greater but your system has version %2.',
[
1 => self::MIN_VERSION_MJWSHARED,
1 => CRM_Core_Payment_Stripe::MIN_VERSION_MJWSHARED,
2 => $extensions['values'][$extensions['id']]['version']
]),
E::ts('Stripe: Missing Requirements'),
......
#card-element{padding:2%;margin:2% auto;max-width:800px;background-color:ghostwhite;-webkit-box-shadow:10px 10px 7px -6px rgba(0,0,0,0.81);-moz-box-shadow:10px 10px 7px -6px rgba(0,0,0,0.81);box-shadow:10px 10px 7px -6px rgba(0,0,0,0.81)}#card-errors{margin:2%;display:none}
\ No newline at end of file
CRM.$(function(g){f("civicrmStripeConfirm loaded");if(typeof CRM.vars.stripe==="undefined"){f("CRM.vars.stripe not defined! Not a Stripe processor?");return}switch(CRM.vars.stripe.paymentIntentStatus){case"succeeded":case"cancelled":f("paymentIntent: ".CRM.vars.stripe.paymentIntentStatus);return}a();if(typeof h==="undefined"){h=Stripe(CRM.vars.stripe.publishableKey)}c();var h;var e=false;window.onbeforeunload=null;function d(i){f("handleServerResponse");if(i.error){}else{if(i.requires_action){b(i)}else{f("success - payment captured")}}}function b(i){switch(CRM.vars.stripe.paymentIntentMethod){case"automatic":h.handleCardPayment(i.payment_intent_client_secret).then(function(j){if(j.error){c()}else{f("card payment success");c()}});break;case"manual":h.handleCardAction(i.payment_intent_client_secret).then(function(j){if(j.error){c()}else{f("card action success");c()}});break}}function c(){f("handle card confirm");var i=CRM.url("civicrm/stripe/confirm-payment");g.post(i,{payment_intent_id:CRM.vars.stripe.paymentIntentID,capture:true,id:CRM.vars.stripe.id}).then(function(j){d(j)})}function a(){if(typeof Stripe==="undefined"){if(e){return}e=true;f("Stripe.js is not loaded!");g.getScript("https://js.stripe.com/v3",function(){f("Script loaded and executed.");e=false})}}function f(i){if((typeof(CRM.vars.stripe)==="undefined")||(Boolean(CRM.vars.stripe.jsDebug)===true)){console.log(new Date().toISOString()+" civicrm_stripe.js: "+i)}}});
\ No newline at end of file
CRM.$(function(e){h("civicrm_stripe loaded, dom-ready function firing.");if(window.civicrmStripeHandleReload){h("calling existing civicrmStripeHandleReload.");window.civicrmStripeHandleReload();return}var u;var b;var c;var y;var s=false;window.onbeforeunload=null;window.civicrmStripeHandleReload=function(){h("civicrmStripeHandleReload");var F=document.getElementById("card-element");if((typeof F!=="undefined")&&(F)){if(!F.children.length){h("checkAndLoad from document.ready");q()}}d("crmBillingFormReloadComplete")};window.civicrmStripeHandleReload();function z(H,F){h(H+": success - submitting form");var G=document.createElement("input");G.setAttribute("type","hidden");G.setAttribute("name",H);G.setAttribute("value",F.id);c.appendChild(G);e('div#priceset input[type="checkbox"]').each(function(){CRM.$(this).attr("name",CRM.$(this).attr("name")+"["+CRM.$(this).attr("id").split("_").pop()+"]");CRM.$(this).removeAttr("required");CRM.$(this).removeClass("required");CRM.$(this).removeAttr("aria-required")});c.submit()}function t(){for(i=0;i<y.length;++i){y[i].setAttribute("disabled",true)}return c.submit()}function k(G,H){h("error: "+G.message);var F=document.getElementById("card-errors");F.style.display="block";F.textContent=G.message;c.dataset.submitted=false;for(i=0;i<y.length;++i){y[i].removeAttribute("disabled")}d("crmBillingFormNotValid");if(H){l("error","",G.message,"#card-element")}}function D(){h("handle card payment");u.createPaymentMethod("card",b).then(function(F){if(F.error){k(F.error,true)}else{if(j()||a()){z("paymentMethodID",F.paymentMethod)}else{var G=CRM.url("civicrm/stripe/confirm-payment");e.post(G,{payment_method_id:F.paymentMethod.id,amount:v().toFixed(2),currency:CRM.vars.stripe.currency,id:CRM.vars.stripe.id,description:document.title,csrfToken:CRM.vars.stripe.csrfToken}).then(function(H){A(H)})}}})}function A(F){h("handleServerResponse");if(F.error){k(F.error,true)}else{if(F.requires_action){w(F)}else{z("paymentIntentID",F.paymentIntent)}}}function w(F){u.handleCardAction(F.payment_intent_client_secret).then(function(G){if(G.error){k(G.error,true)}else{z("paymentIntentID",G.paymentIntent)}})}e(document).ajaxComplete(function(H,I,G){if((G.url.match("civicrm(/|%2F)payment(/|%2F)form")!==null)||(G.url.match("civicrm(/|%2F)contact(/|%2F)view(/|%2F)participant")!==null)){if(typeof CRM.vars.stripe==="undefined"){return}var F=o();if(F!==null){if(F!==parseInt(CRM.vars.stripe.id)){h("payment processor changed to id: "+F);if(F===0){return p()}CRM.api3("PaymentProcessor","getvalue",{"return":"user_name",id:F,payment_processor_type_id:CRM.vars.stripe.paymentProcessorTypeID}).done(function(J){var K=J.result;if(K){h("Setting new stripe key to: "+K);CRM.vars.stripe.publishableKey=K}else{return p()}h("checkAndLoad from ajaxComplete");q()})}}}});function p(){h("New payment processor is not Stripe, clearing CRM.vars.stripe");if((typeof b!=="undefined")&&(b)){h("destroying card element");b.destroy();b=undefined}delete (CRM.vars.stripe)}function q(){if(typeof CRM.vars.stripe==="undefined"){h("CRM.vars.stripe not defined! Not a Stripe processor?");return}if(typeof Stripe==="undefined"){if(s){return}s=true;h("Stripe.js is not loaded!");e.getScript("https://js.stripe.com/v3",function(){h("Script loaded and executed.");s=false;g()})}else{g()}}function g(){h("loadStripeBillingBlock");if(typeof u==="undefined"){u=Stripe(CRM.vars.stripe.publishableKey)}var M=u.elements({locale:CRM.vars.stripe.locale});var J={base:{fontSize:"20px"}};var G=document.getElementById("billing_postal_code-"+CRM.vars.stripe.billingAddressID).value;h("existing postcode: "+G);b=M.create("card",{style:J,value:{postalCode:G}});b.mount("#card-element");h("created new card element",b);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)}b.addEventListener("change",function(N){m(N)});c=n();if(typeof c.length==="undefined"||c.length===0){h("No billing form!");return}f();y=E();c.dataset.submitdontprocess=false;var F=c.querySelectorAll('[type="submit"][formnovalidate="1"], [type="submit"][formnovalidate="formnovalidate"], [type="submit"].cancel, [type="submit"].webform-previous'),I;for(I=0;I<F.length;++I){F[I].addEventListener("click",L())}function L(){h("adding submitdontprocess");c.dataset.submitdontprocess=true}for(I=0;I<y.length;++I){y[I].addEventListener("click",H)}function H(N){if(c.dataset.submitted===true){return}c.dataset.submitted=true;if(typeof CRM.vars.stripe==="undefined"){return t()}h("clearing submitdontprocess");c.dataset.submitdontprocess=false;return K(N)}for(I=0;I<y.length;++I){y[I].removeAttribute("onclick")}r();if(C()){e("[type=submit]").click(function(){x(this.value)});c.addEventListener("keydown",function(N){if(N.code==="Enter"){x(this.value);K(N)}});e("#billingcheckbox:input").hide();e('label[for="billingcheckbox"]').hide()}function K(P){P.preventDefault();h("submit handler");if((e(c).valid()===false)||e(c).data("crmBillingFormValid")===false){h("Form not valid");e("div#card-errors").hide();l("error","",ts("Please check and fill in all required fields!"),"#crm-container");d("crmBillingFormNotValid");return false}var Q=CRM.$("#card-errors").text();if(CRM.$("#card-element.StripeElement--empty").length&&(v()!==0)){h("card details not entered!");if(!Q){Q=ts("Please enter your card details!")}l("error","",Q,"#card-element");d("crmBillingFormNotValid");return false}if(CRM.$("#card-element.StripeElement--invalid").length){if(!Q){Q=ts("Please check your card details!")}h("card details not valid!");l("error","",Q,"#card-element");d("crmBillingFormNotValid");return false}if(!(typeof grecaptcha==="undefined"||(grecaptcha&&grecaptcha.getResponse().length!==0))){h("recaptcha active and not valid");e("div#card-errors").hide();l("error","",ts("Please complete the reCaptcha"),".recaptcha-section");d("crmBillingFormNotValid");return false}if(typeof CRM.vars.stripe==="undefined"){h("Submitting - not a stripe processor");return true}if(c.dataset.submitted===true){h("form already submitted");return false}var S=parseInt(CRM.vars.stripe.id);var O=null;if(C()){if(!e('input[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]').length){O=S}else{O=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)){S=CRM.vars.stripe.id;if(c.querySelector('input[name="payment_processor_id"]:checked')!==null){O=parseInt(c.querySelector('input[name="payment_processor_id"]:checked').value)}}}if((O===0)||(S===null)||((O===null)&&(S===null))){h("Not a Stripe transaction, or pay-later");return t()}else{h("Stripe is the selected payprocessor")}if(typeof CRM.vars.stripe.publishableKey==="undefined"){h("submit missing stripe-pub-key element or value");return true}if(c.dataset.submitdontprocess===true){h("non-payment submit detected - not submitting payment");return true}if(C()){if(e("#billing-payment-block").is(":hidden")){h("no payment processor on webform");return true}var R=e('[name="submitted[civicrm_1_contribution_1_contribution_payment_processor_id]"]');if(R.length){if(R.filter(":checked").val()==="0"||R.filter(":checked").val()===0){h("no payment processor selected");return true}}}var N=v();if(N===0){h("Total amount is 0");return t()}if(c.dataset.submitted===true){alert("Form already submitted. Please wait.");return false}else{c.dataset.submitted=true}for(I=0;I<y.length;++I){y[I].setAttribute("disabled",true)}D();return true}}function C(){if(c!==null){return c.classList.contains("webform-client-form")||c.classList.contains("webform-submission-form")}return false}function n(){var F=e("div#card-element").closest("form").prop("id");if((typeof F==="undefined")||(!F.length)){F=e("input[name=hidden_processor]").closest("form").prop("id")}return document.getElementById(F)}function E(){var F=null;if(C()){F=c.querySelectorAll('[type="submit"].webform-submit');if(!F){F=c.querySelectorAll('[type="submit"].webform-button--submit')}}else{F=c.querySelectorAll('[type="submit"].validate')}return F}function v(){var F=0;if(a()){F=null}else{if(document.getElementById("totalTaxAmount")!==null){F=parseFloat(B());h("Calculated amount using internal calculateTaxAmount()")}else{if(typeof calculateTotalFee=="function"){F=parseFloat(calculateTotalFee())}else{if(C()){e(".line-item:visible","#wf-crm-billing-items").each(function(){F+=parseFloat(e(this).data("amount"))})}else{if(document.getElementById("total_amount")){F=parseFloat(document.getElementById("total_amount").value)}}}}}h("getTotalAmount: "+F);return F}function B(){var F=0;if(document.getElementById("totalTaxAmount")===null){return F}if(document.getElementById("totalTaxAmount").textContent.length===0){F=document.getElementById("total_amount").value}else{F=document.getElementById("totalTaxAmount").textContent.split(" ").pop()}return F}function j(){var F=false;if(C()){if(e('input[id$="contribution-installments"]').length!==0&&e('input[id$="contribution-installments"]').val()>1){F=true}}if(document.getElementById("is_recur")!==null){if(document.getElementById("is_recur").type=="hidden"){F=(document.getElementById("is_recur").value==1)}else{F=Boolean(document.getElementById("is_recur").checked)}}else{if(e('input[name="auto_renew"]').length!==0){if(e('input[name="auto_renew"]').prop("checked")){F=true}else{if(document.getElementById("auto_renew").type=="hidden"){F=(document.getElementById("auto_renew").value==1)}else{F=Boolean(document.getElementById("auto_renew").checked)}}}}h("isRecur is "+F);return F}function m(G){if(G.empty){e("div#card-errors").hide()}else{if(G.error){k(G.error,false)}else{if(G.complete){e("div#card-errors").hide();var F=document.getElementById("billing_postal_code-"+CRM.vars.stripe.billingAddressID);if(F){F.value=G.value.postalCode}}}}}function r(){cividiscountElements=c.querySelectorAll("input#discountcode");var F=function(G){if(G.code==="Enter"){G.preventDefault();h("adding submitdontprocess");c.dataset.submitdontprocess=true}};for(i=0;i<cividiscountElements.length;++i){cividiscountElements[i].addEventListener("keydown",F)}}function f(){e("div.label span.crm-marker").each(function(){e(this).closest("div").next("div").find("input").addClass("required")});e('div#priceset input[type="checkbox"]').each(function(){e(this).attr("name",e(this).attr("name").split("[").shift())});var F=e(c).validate();F.settings.errorClass="error alert-danger";F.settings.ignore=".select2-offscreen, [readonly], :hidden:not(.crm-select2)"}function a(){if((document.getElementById("additional_participants")!==null)&&(document.getElementById("additional_participants").value.length!==0)){h("We don't know the final price - registering additional participants");return true}return false}function x(G){var F=null;if(document.getElementById("action")!==null){F=document.getElementById("action")}else{F=document.createElement("input")}F.setAttribute("type","hidden");F.setAttribute("name","op");F.setAttribute("id","action");F.setAttribute("value",G);c.appendChild(F)}function o(){if((typeof c==="undefined")||(!c)){c=n();if(!c){return null}}var F=c.querySelector('input[name="payment_processor_id"]:checked');if(F!==null){return parseInt(F.value)}return null}function h(F){if((typeof(CRM.vars.stripe)==="undefined")||(Boolean(CRM.vars.stripe.jsDebug)===true)){console.log(new Date().toISOString()+" civicrm_stripe.js: "+F)}}function d(F){h("Firing Event: "+F);e(c).trigger(F)}function l(H,J,I,G){if(typeof Swal==="function"){var F={icon:H,text:I};if(J){F.title=J}if(G){F.onAfterClose=function(){window.scrollTo(e(G).position())}}Swal.fire(F)}}});
\ No newline at end of file
......@@ -106,8 +106,10 @@ function stripe_civicrm_alterContent( &$content, $context, $tplName, &$object )
if (($context == 'form' && !empty($object->_paymentProcessor['class_name']))
|| (($context == 'page') && !empty($object->_isPaymentProcessor))) {
if (!isset(\Civi::$statics[E::LONG_NAME]['stripeJSLoaded']) || $object instanceof CRM_Financial_Form_Payment) {
$min = ((boolean) \Civi::settings()->get('stripe_jsdebug')) ? '' : '.min';
$stripeJSURL = \Civi::resources()->getUrl(E::LONG_NAME, "js/civicrm_stripe{$min}.js", TRUE);
$stripeJSURL = \Civi::service('asset_builder')->getUrl(
'civicrmStripe.js',
['path' => \Civi::resources()->getPath(E::LONG_NAME, 'js/civicrm_stripe.js')]
);
$content .= "<script src='{$stripeJSURL}'></script>";
\Civi::$statics[E::LONG_NAME]['stripeJSLoaded'] = TRUE;
}
......@@ -138,8 +140,10 @@ function stripe_civicrm_buildForm($formName, &$form) {
switch ($formName) {
case 'CRM_Contribute_Form_Contribution_ThankYou':
case 'CRM_Event_Form_Registration_ThankYou':
$min = ((boolean) \Civi::settings()->get('stripe_jsdebug')) ? '' : '.min';
\Civi::resources()->addScriptFile(E::LONG_NAME, "js/civicrmStripeConfirm{$min}.js", TRUE);
\Civi::resources()->addScriptUrl(\Civi::service('asset_builder')->getUrl(
'civicrmStripeConfirm.js',
['path' => \Civi::resources()->getPath(E::LONG_NAME, 'js/civicrmStripeConfirm.js')]
));
// This is a fairly nasty way of matching and retrieving our paymentIntent as it is no longer available.
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment