WooCommerce Square - Version 2.9.0

Version Description

  • 2022.02.17 =
  • New - Added admin notice about v3 major update. PR#707
  • Fix - Trim spaces from postal code at prefix and suffix positions. PR#654
Download this release

Release Info

Developer automattic
Plugin Icon 128x128 WooCommerce Square
Version 2.9.0
Comparing to
See all releases

Code changes from version 2.8.0 to 2.9.0

assets/js/frontend/wc-square.js CHANGED
@@ -39,6 +39,7 @@ jQuery( document ).ready( ( $ ) => {
39
  this.logging_enabled = args.logging_enabled;
40
  this.ajax_wc_checkout_validate_nonce = args.ajax_wc_checkout_validate_nonce;
41
  this.is_manual_order_payment = args.is_manual_order_payment;
 
42
 
43
  if ( $( 'form.checkout' ).length ) {
44
  this.form = $( 'form.checkout' );
@@ -272,6 +273,27 @@ jQuery( document ).ready( ( $ ) => {
272
  if ( e.eventType === 'cardBrandChanged' ) {
273
  this.handle_card_brand_change( e.cardBrand, $input );
274
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  }
276
 
277
  /**
39
  this.logging_enabled = args.logging_enabled;
40
  this.ajax_wc_checkout_validate_nonce = args.ajax_wc_checkout_validate_nonce;
41
  this.is_manual_order_payment = args.is_manual_order_payment;
42
+ this.current_postal_code_value = '';
43
 
44
  if ( $( 'form.checkout' ).length ) {
45
  this.form = $( 'form.checkout' );
273
  if ( e.eventType === 'cardBrandChanged' ) {
274
  this.handle_card_brand_change( e.cardBrand, $input );
275
  }
276
+
277
+ /**
278
+ * @see https://github.com/woocommerce/woocommerce-square/issues/646
279
+ */
280
+ if ( e.field === 'postalCode' ) {
281
+ /**
282
+ * Save postal code in the `current_postal_code_value`
283
+ * variable whenever it is updated.
284
+ */
285
+ this.current_postal_code_value = e.postalCodeValue;
286
+
287
+ /**
288
+ * Trim and set the postal code from the
289
+ * `current_postal_code_value` on blur.
290
+ */
291
+ if ( e.eventType === 'focusClassRemoved' ) {
292
+ this.payment_form.setPostalCode(
293
+ this.current_postal_code_value.trim()
294
+ );
295
+ }
296
+ }
297
  }
298
 
299
  /**
assets/js/frontend/wc-square.min.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";function _toConsumableArray(arr){return _arrayWithoutHoles(arr)||_iterableToArray(arr)||_unsupportedIterableToArray(arr)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(iter){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(iter))return Array.from(iter)}function _arrayWithoutHoles(arr){if(Array.isArray(arr))return _arrayLikeToArray(arr)}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i]}return arr2}function _iterableToArrayLimit(arr,i){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(arr)))return;var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor}jQuery(document).ready(function($){var WC_Square_Payment_Form_Handler=function(){function WC_Square_Payment_Form_Handler(args){var _this=this;_classCallCheck(this,WC_Square_Payment_Form_Handler);this.id=args.id;this.id_dasherized=args.id_dasherized;this.csc_required=args.csc_required;this.enabled_card_types=args.enabled_card_types;this.square_card_types=args.square_card_types;this.ajax_log_nonce=args.ajax_log_nonce;this.ajax_url=args.ajax_url;this.application_id=args.application_id;this.currency_code=args.currency_code;this.general_error=args.general_error;this.input_styles=args.input_styles;this.is_3ds_enabled=args.is_3d_secure_enabled;this.is_add_payment_method_page=args.is_add_payment_method_page;this.is_checkout_registration_enabled=args.is_checkout_registration_enabled;this.is_user_logged_in=args.is_user_logged_in;this.location_id=args.location_id;this.logging_enabled=args.logging_enabled;this.ajax_wc_checkout_validate_nonce=args.ajax_wc_checkout_validate_nonce;this.is_manual_order_payment=args.is_manual_order_payment;if($("form.checkout").length){this.form=$("form.checkout");this.handle_checkout_page()}else if($("form#order_review").length){this.form=$("form#order_review");this.handle_pay_page()}else if($("form#add_payment_method").length){this.form=$("form#add_payment_method");this.handle_add_payment_method_page()}else{this.log("No payment form found!");return}this.params=window.sv_wc_payment_gateway_payment_form_params;$(document.body).on("checkout_error",function(){$("input[name=wc-square-credit-card-payment-nonce]").val("");$("input[name=wc-square-credit-card-buyer-verification-token]").val("")});$(document.body).on("click","#payment_method_".concat(this.id),function(){if(_this.payment_form){_this.log("Recalculating payment form size");_this.payment_form.recalculateSize()}})}_createClass(WC_Square_Payment_Form_Handler,[{key:"handle_checkout_page",value:function handle_checkout_page(){var _this2=this;$(document.body).on("updated_checkout",function(){return _this2.set_payment_fields()});$(document.body).on("updated_checkout",function(){return _this2.handle_saved_payment_methods()});this.form.on("checkout_place_order_".concat(this.id),function(){return _this2.validate_payment_data()})}},{key:"handle_saved_payment_methods",value:function handle_saved_payment_methods(){var id_dasherized=this.id_dasherized;var form_handler=this;var $new_payment_method_selection=$("div.js-wc-".concat(id_dasherized,"-new-payment-method-form"));$("input.js-wc-".concat(this.id_dasherized,"-payment-token")).on("change",function(){var tokenized_payment_method_selected=$("input.js-wc-".concat(id_dasherized,"-payment-token:checked")).val();if(tokenized_payment_method_selected){$new_payment_method_selection.slideUp(200)}else{$new_payment_method_selection.slideDown(200)}}).trigger("change");$("input#createaccount").on("change",function(e){if($(e.target).is(":checked")){form_handler.show_save_payment_checkbox(id_dasherized)}else{form_handler.hide_save_payment_checkbox(id_dasherized)}});if(!$("input#createaccount").is(":checked")){$("input#createaccount").trigger("change")}if(!this.is_user_logged_in&&!this.is_checkout_registration_enabled){this.hide_save_payment_checkbox(id_dasherized)}}},{key:"handle_pay_page",value:function handle_pay_page(){this.set_payment_fields();this.handle_saved_payment_methods();var self=this;this.form.on("submit",function(){if($("#order_review input[name=payment_method]:checked").val()===self.id){return self.validate_payment_data()}})}},{key:"handle_add_payment_method_page",value:function handle_add_payment_method_page(){this.set_payment_fields();var self=this;this.form.on("submit",function(){if($("#add_payment_method input[name=payment_method]:checked").val()===self.id){return self.validate_payment_data()}})}},{key:"set_payment_fields",value:function set_payment_fields(){if(!$("#wc-".concat(this.id_dasherized,"-account-number-hosted")).length){return}if($("#wc-".concat(this.id_dasherized,"-account-number-hosted")).is("iframe")){this.log("Re-adding payment form");for(var _i=0,_Object$entries=Object.entries(this.form_fields);_i<_Object$entries.length;_i++){var _Object$entries$_i=_slicedToArray(_Object$entries[_i],2),_=_Object$entries$_i[0],field=_Object$entries$_i[1];$(field.attr("id")).replaceWith(field)}this.handle_form_loaded()}else{if(this.payment_form){this.log("Destroying payment form");this.payment_form.destroy();this.payment_form=null}this.log("Building payment form");this.payment_form=new SqPaymentForm(this.get_form_params());this.payment_form.build()}}},{key:"get_form_params",value:function get_form_params(){var _this3=this;this.form_fields={card_number:$("#wc-".concat(this.id_dasherized,"-account-number-hosted")),expiration:$("#wc-".concat(this.id_dasherized,"-expiry-hosted")),csc:$("#wc-".concat(this.id_dasherized,"-csc-hosted")),postal_code:$("#wc-".concat(this.id_dasherized,"-postal-code-hosted"))};return{applicationId:this.application_id,locationId:this.location_id,cardNumber:{elementId:this.form_fields.card_number.attr("id"),placeholder:this.form_fields.card_number.data("placeholder")},expirationDate:{elementId:this.form_fields.expiration.attr("id"),placeholder:this.form_fields.expiration.data("placeholder")},cvv:{elementId:this.form_fields.csc.attr("id"),placeholder:this.form_fields.csc.data("placeholder")},postalCode:{elementId:this.form_fields.postal_code.attr("id"),placeholder:this.form_fields.postal_code.data("placeholder")},inputClass:"wc-".concat(this.id_dasherized,"-payment-field"),inputStyles:this.input_styles,callbacks:{inputEventReceived:function inputEventReceived(e){return _this3.handle_input_event(e)},cardNonceResponseReceived:function cardNonceResponseReceived(errors,nonce,cardData){return _this3.handle_card_nonce_response(errors,nonce,cardData)},unsupportedBrowserDetected:function unsupportedBrowserDetected(){return _this3.handle_unsupported_browser()},paymentFormLoaded:function paymentFormLoaded(){return _this3.handle_form_loaded()}}}}},{key:"handle_form_loaded",value:function handle_form_loaded(){this.log("Payment form loaded");this.payment_form.setPostalCode($("#billing_postcode").val());if($("form.checkout").length||$("#billing_postcode").val()){$(".wc-square-credit-card-card-postal-code-parent").addClass("hidden")}}},{key:"handle_input_event",value:function handle_input_event(e){var $input=$("#"+e.elementId);if(e.eventType==="cardBrandChanged"){this.handle_card_brand_change(e.cardBrand,$input)}}},{key:"handle_card_brand_change",value:function handle_card_brand_change(brand,$input){this.log("Card brand changed to ".concat(brand));$input.attr("class",function(i,c){return c.replace(/(^|\s)card-type-\S+/g,"")});var card_class="plain";if(null===brand||"unknown"===brand){brand=""}if(null!==this.square_card_types[brand]){brand=this.square_card_types[brand]}if(brand&&!this.enabled_card_types.includes(brand)){card_class="invalid"}else{card_class=brand}$("input[name=wc-".concat(this.id_dasherized,"-card-type]")).val(brand);$input.addClass("card-type-".concat(card_class))}},{key:"validate_payment_data",value:function validate_payment_data(){if(this.form.is(".processing")){return false}if(this.has_nonce()){this.log("Payment nonce present, placing order");return true}var tokenized_card_id=this.get_tokenized_payment_method_id();if(tokenized_card_id){if(!this.is_3ds_enabled){return true}if(this.has_verification_token()){this.log("Tokenized payment verification token present, placing order");return true}this.log("Requesting verification token for tokenized payment");this.block_ui();this.payment_form.verifyBuyer(tokenized_card_id,this.get_verification_details(),this.handle_verify_buyer_response.bind(this));return false}this.log("Requesting payment nonce");this.block_ui();this.payment_form.requestCardNonce();return false}},{key:"get_tokenized_payment_method_id",value:function get_tokenized_payment_method_id(){return $(".payment_method_".concat(this.id)).find(".js-wc-square-credit-card-payment-token:checked").val()}},{key:"handle_card_nonce_response",value:function handle_card_nonce_response(errors,nonce,cardData){if(errors){return this.handle_errors(errors)}if(!nonce){var message="Nonce is missing from the Square response";this.log(message,"error");this.log_data(message,"response");return this.handle_errors()}this.log("Card data received");this.log(cardData);this.log_data(cardData,"response");if(cardData.last_4){$("input[name=wc-".concat(this.id_dasherized,"-last-four]")).val(cardData.last_4)}if(cardData.exp_month){$("input[name=wc-".concat(this.id_dasherized,"-exp-month]")).val(cardData.exp_month)}if(cardData.exp_year){$("input[name=wc-".concat(this.id_dasherized,"-exp-year]")).val(cardData.exp_year)}if(cardData.billing_postal_code){$("input[name=wc-".concat(this.id_dasherized,"-payment-postcode]")).val(cardData.billing_postal_code)}$("input[name=wc-".concat(this.id_dasherized,"-payment-nonce]")).val(nonce);if(this.is_3ds_enabled){this.log("Verifying buyer");this.payment_form.verifyBuyer(nonce,this.get_verification_details(),this.handle_verify_buyer_response.bind(this));return}this.form.trigger("submit")}},{key:"handle_verify_buyer_response",value:function handle_verify_buyer_response(errors,verification_result){if(errors){$(errors).each(function(index,error){if(!error.field){error.field="none"}});return this.handle_errors(errors)}if(!verification_result||!verification_result.token){var message="Verification token is missing from the Square response";this.log(message,"error");this.log_data(message,"response");return this.handle_errors()}this.log("Verification result received");this.log(verification_result);$("input[name=wc-".concat(this.id_dasherized,"-buyer-verification-token]")).val(verification_result.token);this.form.trigger("submit")}},{key:"get_verification_details",value:function get_verification_details(){var verification_details={billingContact:{familyName:$("#billing_last_name").val()||"",givenName:$("#billing_first_name").val()||"",email:$("#billing_email").val()||"",country:$("#billing_country").val()||"",region:$("#billing_state").val()||"",city:$("#billing_city").val()||"",postalCode:$("#billing_postcode").val()||"",phone:$("#billing_phone").val()||"",addressLines:[$("#billing_address_1").val()||"",$("#billing_address_2").val()||""]},intent:this.get_intent()};if("CHARGE"===verification_details.intent){verification_details.amount=this.get_amount();verification_details.currencyCode=this.currency_code}this.log(verification_details);return verification_details}},{key:"get_intent",value:function get_intent(){var $save_method_input=$("#wc-square-credit-card-tokenize-payment-method");var save_payment_method;if($save_method_input.is("input:checkbox")){save_payment_method=$save_method_input.is(":checked")}else{save_payment_method="true"===$save_method_input.val()}if(!this.get_tokenized_payment_method_id()&&save_payment_method){return"STORE"}return"CHARGE"}},{key:"get_amount",value:function get_amount(){return $("input[name=wc-".concat(this.id_dasherized,"-amount]")).val()}},{key:"handle_unsupported_browser",value:function handle_unsupported_browser(){}},{key:"handle_errors",value:function handle_errors(){var _this4=this;var errors=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;this.log("Error getting payment data","error");$("input[name=wc-square-credit-card-payment-nonce]").val("");$("input[name=wc-square-credit-card-buyer-verification-token]").val("");var messages=[];if(errors){var field_order=["none","cardNumber","expirationDate","cvv","postalCode"];if(errors.length>=1){errors.sort(function(a,b){return field_order.indexOf(a.field)-field_order.indexOf(b.field)})}$(errors).each(function(index,error){if("UNSUPPORTED_CARD_BRAND"===error.type||"VALIDATION_ERROR"===error.type){return messages.push(error.message.replace(/CVV/,"CSC"))}return _this4.log_data(errors,"response")})}if(messages.length===0){messages.push(this.general_error)}if(!this.is_add_payment_method_page&&!this.is_manual_order_payment){this.render_checkout_errors(messages)}else{this.render_errors(messages)}this.unblock_ui()}},{key:"render_errors",value:function render_errors(errors){$(".woocommerce-error, .woocommerce-message").remove();this.form.prepend("<ul class=\"woocommerce-error\"><li>"+errors.join("</li><li>")+"</li></ul>");this.form.removeClass("processing").unblock();this.form.find(".input-text, select").trigger("blur");$("html, body").animate({scrollTop:this.form.offset().top-100},1000)}},{key:"block_ui",value:function block_ui(){this.form.block({message:null,overlayCSS:{background:"#fff",opacity:0.6}})}},{key:"unblock_ui",value:function unblock_ui(){return this.form.unblock()}},{key:"hide_save_payment_checkbox",value:function hide_save_payment_checkbox(id_dasherized){var $parent_row=$("input.js-wc-".concat(id_dasherized,"-tokenize-payment-method")).closest("p.form-row");$parent_row.hide();$parent_row.next().hide()}},{key:"show_save_payment_checkbox",value:function show_save_payment_checkbox(id_dasherized){var $parent_row=$("input.js-wc-".concat(id_dasherized,"-tokenize-payment-method")).closest("p.form-row");$parent_row.slideDown();$parent_row.next().show()}},{key:"has_nonce",value:function has_nonce(){return $("input[name=wc-".concat(this.id_dasherized,"-payment-nonce]")).val()}},{key:"has_verification_token",value:function has_verification_token(){return $("input[name=wc-".concat(this.id_dasherized,"-buyer-verification-token]")).val()}},{key:"log_data",value:function log_data(data,type){if(!this.logging_enabled){return}var ajax_data={action:"wc_"+this.id+"_log_js_data",security:this.ajax_log_nonce,type:type,data:data};$.ajax({url:this.ajax_url,data:ajax_data})}},{key:"log",value:function log(message){var type=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"notice";if(!this.logging_enabled){return}if("error"===type){console.error("Square Error: "+message)}else{console.log("Square: "+message)}}},{key:"render_checkout_errors",value:function render_checkout_errors(square_errors){var _this5=this;var ajax_url=wc_cart_fragments_params.wc_ajax_url.toString().replace("%%endpoint%%",this.id+"_checkout_handler");var square_handler=this;var form_data=this.form.serializeArray();form_data.push({name:"wc_"+this.id+"_checkout_validate_nonce",value:this.ajax_wc_checkout_validate_nonce});return $.ajax({url:ajax_url,method:"post",cache:false,data:form_data,complete:function complete(response){var result=response.responseJSON;if(result.hasOwnProperty("result")&&"failure"===result.result){$(result.messages).map(function(message){var errors=[];$(message).children("li").each(function(){errors.push($(_this5).text().trim())});return square_errors.unshift.apply(square_errors,errors)})}else if(result.hasOwnProperty("success")&&!result.success){square_errors.unshift.apply(square_errors,_toConsumableArray(result.data.messages))}square_handler.render_errors(square_errors)}})}}]);return WC_Square_Payment_Form_Handler}();window.WC_Square_Payment_Form_Handler=WC_Square_Payment_Form_Handler});
2
  //# sourceMappingURL=wc-square.min.js.map
1
+ "use strict";function _toConsumableArray(arr){return _arrayWithoutHoles(arr)||_iterableToArray(arr)||_unsupportedIterableToArray(arr)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(iter){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(iter))return Array.from(iter)}function _arrayWithoutHoles(arr){if(Array.isArray(arr))return _arrayLikeToArray(arr)}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i]}return arr2}function _iterableToArrayLimit(arr,i){if(typeof Symbol==="undefined"||!(Symbol.iterator in Object(arr)))return;var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor}jQuery(document).ready(function($){var WC_Square_Payment_Form_Handler=function(){function WC_Square_Payment_Form_Handler(args){var _this=this;_classCallCheck(this,WC_Square_Payment_Form_Handler);this.id=args.id;this.id_dasherized=args.id_dasherized;this.csc_required=args.csc_required;this.enabled_card_types=args.enabled_card_types;this.square_card_types=args.square_card_types;this.ajax_log_nonce=args.ajax_log_nonce;this.ajax_url=args.ajax_url;this.application_id=args.application_id;this.currency_code=args.currency_code;this.general_error=args.general_error;this.input_styles=args.input_styles;this.is_3ds_enabled=args.is_3d_secure_enabled;this.is_add_payment_method_page=args.is_add_payment_method_page;this.is_checkout_registration_enabled=args.is_checkout_registration_enabled;this.is_user_logged_in=args.is_user_logged_in;this.location_id=args.location_id;this.logging_enabled=args.logging_enabled;this.ajax_wc_checkout_validate_nonce=args.ajax_wc_checkout_validate_nonce;this.is_manual_order_payment=args.is_manual_order_payment;this.current_postal_code_value="";if($("form.checkout").length){this.form=$("form.checkout");this.handle_checkout_page()}else if($("form#order_review").length){this.form=$("form#order_review");this.handle_pay_page()}else if($("form#add_payment_method").length){this.form=$("form#add_payment_method");this.handle_add_payment_method_page()}else{this.log("No payment form found!");return}this.params=window.sv_wc_payment_gateway_payment_form_params;$(document.body).on("checkout_error",function(){$("input[name=wc-square-credit-card-payment-nonce]").val("");$("input[name=wc-square-credit-card-buyer-verification-token]").val("")});$(document.body).on("click","#payment_method_".concat(this.id),function(){if(_this.payment_form){_this.log("Recalculating payment form size");_this.payment_form.recalculateSize()}})}_createClass(WC_Square_Payment_Form_Handler,[{key:"handle_checkout_page",value:function handle_checkout_page(){var _this2=this;$(document.body).on("updated_checkout",function(){return _this2.set_payment_fields()});$(document.body).on("updated_checkout",function(){return _this2.handle_saved_payment_methods()});this.form.on("checkout_place_order_".concat(this.id),function(){return _this2.validate_payment_data()})}},{key:"handle_saved_payment_methods",value:function handle_saved_payment_methods(){var id_dasherized=this.id_dasherized;var form_handler=this;var $new_payment_method_selection=$("div.js-wc-".concat(id_dasherized,"-new-payment-method-form"));$("input.js-wc-".concat(this.id_dasherized,"-payment-token")).on("change",function(){var tokenized_payment_method_selected=$("input.js-wc-".concat(id_dasherized,"-payment-token:checked")).val();if(tokenized_payment_method_selected){$new_payment_method_selection.slideUp(200)}else{$new_payment_method_selection.slideDown(200)}}).trigger("change");$("input#createaccount").on("change",function(e){if($(e.target).is(":checked")){form_handler.show_save_payment_checkbox(id_dasherized)}else{form_handler.hide_save_payment_checkbox(id_dasherized)}});if(!$("input#createaccount").is(":checked")){$("input#createaccount").trigger("change")}if(!this.is_user_logged_in&&!this.is_checkout_registration_enabled){this.hide_save_payment_checkbox(id_dasherized)}}},{key:"handle_pay_page",value:function handle_pay_page(){this.set_payment_fields();this.handle_saved_payment_methods();var self=this;this.form.on("submit",function(){if($("#order_review input[name=payment_method]:checked").val()===self.id){return self.validate_payment_data()}})}},{key:"handle_add_payment_method_page",value:function handle_add_payment_method_page(){this.set_payment_fields();var self=this;this.form.on("submit",function(){if($("#add_payment_method input[name=payment_method]:checked").val()===self.id){return self.validate_payment_data()}})}},{key:"set_payment_fields",value:function set_payment_fields(){if(!$("#wc-".concat(this.id_dasherized,"-account-number-hosted")).length){return}if($("#wc-".concat(this.id_dasherized,"-account-number-hosted")).is("iframe")){this.log("Re-adding payment form");for(var _i=0,_Object$entries=Object.entries(this.form_fields);_i<_Object$entries.length;_i++){var _Object$entries$_i=_slicedToArray(_Object$entries[_i],2),_=_Object$entries$_i[0],field=_Object$entries$_i[1];$(field.attr("id")).replaceWith(field)}this.handle_form_loaded()}else{if(this.payment_form){this.log("Destroying payment form");this.payment_form.destroy();this.payment_form=null}this.log("Building payment form");this.payment_form=new SqPaymentForm(this.get_form_params());this.payment_form.build()}}},{key:"get_form_params",value:function get_form_params(){var _this3=this;this.form_fields={card_number:$("#wc-".concat(this.id_dasherized,"-account-number-hosted")),expiration:$("#wc-".concat(this.id_dasherized,"-expiry-hosted")),csc:$("#wc-".concat(this.id_dasherized,"-csc-hosted")),postal_code:$("#wc-".concat(this.id_dasherized,"-postal-code-hosted"))};return{applicationId:this.application_id,locationId:this.location_id,cardNumber:{elementId:this.form_fields.card_number.attr("id"),placeholder:this.form_fields.card_number.data("placeholder")},expirationDate:{elementId:this.form_fields.expiration.attr("id"),placeholder:this.form_fields.expiration.data("placeholder")},cvv:{elementId:this.form_fields.csc.attr("id"),placeholder:this.form_fields.csc.data("placeholder")},postalCode:{elementId:this.form_fields.postal_code.attr("id"),placeholder:this.form_fields.postal_code.data("placeholder")},inputClass:"wc-".concat(this.id_dasherized,"-payment-field"),inputStyles:this.input_styles,callbacks:{inputEventReceived:function inputEventReceived(e){return _this3.handle_input_event(e)},cardNonceResponseReceived:function cardNonceResponseReceived(errors,nonce,cardData){return _this3.handle_card_nonce_response(errors,nonce,cardData)},unsupportedBrowserDetected:function unsupportedBrowserDetected(){return _this3.handle_unsupported_browser()},paymentFormLoaded:function paymentFormLoaded(){return _this3.handle_form_loaded()}}}}},{key:"handle_form_loaded",value:function handle_form_loaded(){this.log("Payment form loaded");this.payment_form.setPostalCode($("#billing_postcode").val());if($("form.checkout").length||$("#billing_postcode").val()){$(".wc-square-credit-card-card-postal-code-parent").addClass("hidden")}}},{key:"handle_input_event",value:function handle_input_event(e){var $input=$("#"+e.elementId);if(e.eventType==="cardBrandChanged"){this.handle_card_brand_change(e.cardBrand,$input)}if(e.field==="postalCode"){this.current_postal_code_value=e.postalCodeValue;if(e.eventType==="focusClassRemoved"){this.payment_form.setPostalCode(this.current_postal_code_value.trim())}}}},{key:"handle_card_brand_change",value:function handle_card_brand_change(brand,$input){this.log("Card brand changed to ".concat(brand));$input.attr("class",function(i,c){return c.replace(/(^|\s)card-type-\S+/g,"")});var card_class="plain";if(null===brand||"unknown"===brand){brand=""}if(null!==this.square_card_types[brand]){brand=this.square_card_types[brand]}if(brand&&!this.enabled_card_types.includes(brand)){card_class="invalid"}else{card_class=brand}$("input[name=wc-".concat(this.id_dasherized,"-card-type]")).val(brand);$input.addClass("card-type-".concat(card_class))}},{key:"validate_payment_data",value:function validate_payment_data(){if(this.form.is(".processing")){return false}if(this.has_nonce()){this.log("Payment nonce present, placing order");return true}var tokenized_card_id=this.get_tokenized_payment_method_id();if(tokenized_card_id){if(!this.is_3ds_enabled){return true}if(this.has_verification_token()){this.log("Tokenized payment verification token present, placing order");return true}this.log("Requesting verification token for tokenized payment");this.block_ui();this.payment_form.verifyBuyer(tokenized_card_id,this.get_verification_details(),this.handle_verify_buyer_response.bind(this));return false}this.log("Requesting payment nonce");this.block_ui();this.payment_form.requestCardNonce();return false}},{key:"get_tokenized_payment_method_id",value:function get_tokenized_payment_method_id(){return $(".payment_method_".concat(this.id)).find(".js-wc-square-credit-card-payment-token:checked").val()}},{key:"handle_card_nonce_response",value:function handle_card_nonce_response(errors,nonce,cardData){if(errors){return this.handle_errors(errors)}if(!nonce){var message="Nonce is missing from the Square response";this.log(message,"error");this.log_data(message,"response");return this.handle_errors()}this.log("Card data received");this.log(cardData);this.log_data(cardData,"response");if(cardData.last_4){$("input[name=wc-".concat(this.id_dasherized,"-last-four]")).val(cardData.last_4)}if(cardData.exp_month){$("input[name=wc-".concat(this.id_dasherized,"-exp-month]")).val(cardData.exp_month)}if(cardData.exp_year){$("input[name=wc-".concat(this.id_dasherized,"-exp-year]")).val(cardData.exp_year)}if(cardData.billing_postal_code){$("input[name=wc-".concat(this.id_dasherized,"-payment-postcode]")).val(cardData.billing_postal_code)}$("input[name=wc-".concat(this.id_dasherized,"-payment-nonce]")).val(nonce);if(this.is_3ds_enabled){this.log("Verifying buyer");this.payment_form.verifyBuyer(nonce,this.get_verification_details(),this.handle_verify_buyer_response.bind(this));return}this.form.trigger("submit")}},{key:"handle_verify_buyer_response",value:function handle_verify_buyer_response(errors,verification_result){if(errors){$(errors).each(function(index,error){if(!error.field){error.field="none"}});return this.handle_errors(errors)}if(!verification_result||!verification_result.token){var message="Verification token is missing from the Square response";this.log(message,"error");this.log_data(message,"response");return this.handle_errors()}this.log("Verification result received");this.log(verification_result);$("input[name=wc-".concat(this.id_dasherized,"-buyer-verification-token]")).val(verification_result.token);this.form.trigger("submit")}},{key:"get_verification_details",value:function get_verification_details(){var verification_details={billingContact:{familyName:$("#billing_last_name").val()||"",givenName:$("#billing_first_name").val()||"",email:$("#billing_email").val()||"",country:$("#billing_country").val()||"",region:$("#billing_state").val()||"",city:$("#billing_city").val()||"",postalCode:$("#billing_postcode").val()||"",phone:$("#billing_phone").val()||"",addressLines:[$("#billing_address_1").val()||"",$("#billing_address_2").val()||""]},intent:this.get_intent()};if("CHARGE"===verification_details.intent){verification_details.amount=this.get_amount();verification_details.currencyCode=this.currency_code}this.log(verification_details);return verification_details}},{key:"get_intent",value:function get_intent(){var $save_method_input=$("#wc-square-credit-card-tokenize-payment-method");var save_payment_method;if($save_method_input.is("input:checkbox")){save_payment_method=$save_method_input.is(":checked")}else{save_payment_method="true"===$save_method_input.val()}if(!this.get_tokenized_payment_method_id()&&save_payment_method){return"STORE"}return"CHARGE"}},{key:"get_amount",value:function get_amount(){return $("input[name=wc-".concat(this.id_dasherized,"-amount]")).val()}},{key:"handle_unsupported_browser",value:function handle_unsupported_browser(){}},{key:"handle_errors",value:function handle_errors(){var _this4=this;var errors=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;this.log("Error getting payment data","error");$("input[name=wc-square-credit-card-payment-nonce]").val("");$("input[name=wc-square-credit-card-buyer-verification-token]").val("");var messages=[];if(errors){var field_order=["none","cardNumber","expirationDate","cvv","postalCode"];if(errors.length>=1){errors.sort(function(a,b){return field_order.indexOf(a.field)-field_order.indexOf(b.field)})}$(errors).each(function(index,error){if("UNSUPPORTED_CARD_BRAND"===error.type||"VALIDATION_ERROR"===error.type){return messages.push(error.message.replace(/CVV/,"CSC"))}return _this4.log_data(errors,"response")})}if(messages.length===0){messages.push(this.general_error)}if(!this.is_add_payment_method_page&&!this.is_manual_order_payment){this.render_checkout_errors(messages)}else{this.render_errors(messages)}this.unblock_ui()}},{key:"render_errors",value:function render_errors(errors){$(".woocommerce-error, .woocommerce-message").remove();this.form.prepend("<ul class=\"woocommerce-error\"><li>"+errors.join("</li><li>")+"</li></ul>");this.form.removeClass("processing").unblock();this.form.find(".input-text, select").trigger("blur");$("html, body").animate({scrollTop:this.form.offset().top-100},1000)}},{key:"block_ui",value:function block_ui(){this.form.block({message:null,overlayCSS:{background:"#fff",opacity:0.6}})}},{key:"unblock_ui",value:function unblock_ui(){return this.form.unblock()}},{key:"hide_save_payment_checkbox",value:function hide_save_payment_checkbox(id_dasherized){var $parent_row=$("input.js-wc-".concat(id_dasherized,"-tokenize-payment-method")).closest("p.form-row");$parent_row.hide();$parent_row.next().hide()}},{key:"show_save_payment_checkbox",value:function show_save_payment_checkbox(id_dasherized){var $parent_row=$("input.js-wc-".concat(id_dasherized,"-tokenize-payment-method")).closest("p.form-row");$parent_row.slideDown();$parent_row.next().show()}},{key:"has_nonce",value:function has_nonce(){return $("input[name=wc-".concat(this.id_dasherized,"-payment-nonce]")).val()}},{key:"has_verification_token",value:function has_verification_token(){return $("input[name=wc-".concat(this.id_dasherized,"-buyer-verification-token]")).val()}},{key:"log_data",value:function log_data(data,type){if(!this.logging_enabled){return}var ajax_data={action:"wc_"+this.id+"_log_js_data",security:this.ajax_log_nonce,type:type,data:data};$.ajax({url:this.ajax_url,data:ajax_data})}},{key:"log",value:function log(message){var type=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"notice";if(!this.logging_enabled){return}if("error"===type){console.error("Square Error: "+message)}else{console.log("Square: "+message)}}},{key:"render_checkout_errors",value:function render_checkout_errors(square_errors){var _this5=this;var ajax_url=wc_cart_fragments_params.wc_ajax_url.toString().replace("%%endpoint%%",this.id+"_checkout_handler");var square_handler=this;var form_data=this.form.serializeArray();form_data.push({name:"wc_"+this.id+"_checkout_validate_nonce",value:this.ajax_wc_checkout_validate_nonce});return $.ajax({url:ajax_url,method:"post",cache:false,data:form_data,complete:function complete(response){var result=response.responseJSON;if(result.hasOwnProperty("result")&&"failure"===result.result){$(result.messages).map(function(message){var errors=[];$(message).children("li").each(function(){errors.push($(_this5).text().trim())});return square_errors.unshift.apply(square_errors,errors)})}else if(result.hasOwnProperty("success")&&!result.success){square_errors.unshift.apply(square_errors,_toConsumableArray(result.data.messages))}square_handler.render_errors(square_errors)}})}}]);return WC_Square_Payment_Form_Handler}();window.WC_Square_Payment_Form_Handler=WC_Square_Payment_Form_Handler});
2
  //# sourceMappingURL=wc-square.min.js.map
i18n/languages/woocommerce-square.pot CHANGED
@@ -2,10 +2,10 @@
2
  # This file is distributed under the GNU General Public License v3.0.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WooCommerce Square 2.8.0\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://wordpress.org/support/plugin/woocommerce-square\n"
8
- "POT-Creation-Date: 2022-01-24 01:30:17+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
@@ -1857,15 +1857,15 @@ msgstr ""
1857
  msgid "Docs"
1858
  msgstr ""
1859
 
1860
- #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:622
1861
  msgid "%1$s - A minimum of %2$s is required."
1862
  msgstr ""
1863
 
1864
- #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:631
1865
  msgid "Set as %1$s - %2$s is required."
1866
  msgstr ""
1867
 
1868
- #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:854
1869
  msgid "Configure"
1870
  msgstr ""
1871
 
@@ -3228,6 +3228,16 @@ msgid ""
3228
  "has loopback connections enabled."
3229
  msgstr ""
3230
 
 
 
 
 
 
 
 
 
 
 
3231
  #. Plugin URI of the plugin/theme
3232
  msgid "https://woocommerce.com/products/square/"
3233
  msgstr ""
2
  # This file is distributed under the GNU General Public License v3.0.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WooCommerce Square 2.9.0\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://wordpress.org/support/plugin/woocommerce-square\n"
8
+ "POT-Creation-Date: 2022-02-17 06:05:29+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
1857
  msgid "Docs"
1858
  msgstr ""
1859
 
1860
+ #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:621
1861
  msgid "%1$s - A minimum of %2$s is required."
1862
  msgstr ""
1863
 
1864
+ #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:630
1865
  msgid "Set as %1$s - %2$s is required."
1866
  msgstr ""
1867
 
1868
+ #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:853
1869
  msgid "Configure"
1870
  msgstr ""
1871
 
3228
  "has loopback connections enabled."
3229
  msgstr ""
3230
 
3231
+ #: woocommerce-square.php:250
3232
+ msgid ""
3233
+ "Note that our next WooCommerce Square release will be a major update "
3234
+ "(v3.0.0) that will include bumping the minimum PHP support from 5.6 to 7.1 "
3235
+ "and migrating Square's SDK from v2.2 to v15.0.0. This will allow us to "
3236
+ "provide significant enhancements into the future and while we fully test "
3237
+ "all releases, please allow yourself some time and space to similarly test "
3238
+ "the update before applying it to your live sites."
3239
+ msgstr ""
3240
+
3241
  #. Plugin URI of the plugin/theme
3242
  msgid "https://woocommerce.com/products/square/"
3243
  msgstr ""
includes/Plugin.php CHANGED
@@ -42,7 +42,7 @@ class Plugin extends Framework\SV_WC_Payment_Gateway_Plugin {
42
 
43
 
44
  /** plugin version number */
45
- const VERSION = '2.8.0';
46
 
47
  /** plugin ID */
48
  const PLUGIN_ID = 'square';
42
 
43
 
44
  /** plugin version number */
45
+ const VERSION = '2.9.0';
46
 
47
  /** plugin ID */
48
  const PLUGIN_ID = 'square';
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: woocommerce, automattic, royho, woothemes, bor0, mattdallan, menakas, chickenn00dle, jorgeatorres, jamesgallan, achyuthajoy
3
  Tags: credit card, square, woocommerce, inventory sync
4
  Requires at least: 4.6
5
- Tested up to: 5.8
6
  Requires PHP: 5.6
7
- Stable tag: 2.8.0
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -71,6 +71,10 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
71
  2. The payment gateway settings.
72
 
73
  == Changelog ==
 
 
 
 
74
  = 2.8.0 - 2022.01.24 =
75
  * New - Add support for Square stores located in Spain. PR#704
76
 
2
  Contributors: woocommerce, automattic, royho, woothemes, bor0, mattdallan, menakas, chickenn00dle, jorgeatorres, jamesgallan, achyuthajoy
3
  Tags: credit card, square, woocommerce, inventory sync
4
  Requires at least: 4.6
5
+ Tested up to: 5.9
6
  Requires PHP: 5.6
7
+ Stable tag: 2.9.0
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
71
  2. The payment gateway settings.
72
 
73
  == Changelog ==
74
+ = 2.9.0 - 2022.02.17 =
75
+ * New - Added admin notice about v3 major update. PR#707
76
+ * Fix - Trim spaces from postal code at prefix and suffix positions. PR#654
77
+
78
  = 2.8.0 - 2022.01.24 =
79
  * New - Add support for Square stores located in Spain. PR#704
80
 
woocommerce-square.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Plugin Name: WooCommerce Square
4
- * Version: 2.8.0
5
  * Plugin URI: https://woocommerce.com/products/square/
6
  * Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
7
  * Author: WooCommerce
@@ -19,7 +19,8 @@
19
  * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
20
  *
21
  * WC requires at least: 3.0
22
- * WC tested up to: 5.8
 
23
  */
24
 
25
  defined( 'ABSPATH' ) || exit;
@@ -243,6 +244,17 @@ class WooCommerce_Square_Loader {
243
  )
244
  );
245
  }
 
 
 
 
 
 
 
 
 
 
 
246
  }
247
 
248
 
1
  <?php
2
  /**
3
  * Plugin Name: WooCommerce Square
4
+ * Version: 2.9.0
5
  * Plugin URI: https://woocommerce.com/products/square/
6
  * Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
7
  * Author: WooCommerce
19
  * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
20
  *
21
  * WC requires at least: 3.0
22
+ * WC tested up to: 6.2
23
+ * Tested up to: 5.9
24
  */
25
 
26
  defined( 'ABSPATH' ) || exit;
244
  )
245
  );
246
  }
247
+
248
+ wc_square()->get_admin_notice_handler()->add_admin_notice(
249
+ sprintf(
250
+ esc_html__( "Note that our next WooCommerce Square release will be a major update (v3.0.0) that will include bumping the minimum PHP support from 5.6 to 7.1 and migrating Square's SDK from v2.2 to v15.0.0. This will allow us to provide significant enhancements into the future and while we fully test all releases, please allow yourself some time and space to similarly test the update before applying it to your live sites.", 'woocommerce-square' )
251
+ ),
252
+ 'wc-square-v3-upgrade-info',
253
+ array(
254
+ 'notice_class' => 'notice-info',
255
+ 'dismissible' => true,
256
+ )
257
+ );
258
  }
259
 
260