Payment Plugins for Stripe WooCommerce - Version 3.1.9

Version Description

  • Fixed - WP 5.5 rest permission_callback notice
  • Fixed - Conflict with SG Optimizer plugin
  • Fixed - Conflict with https://wordpress.org/plugins/woocommerce-gateway-paypal-express-checkout/ button on checkout page
Download this release

Release Info

Developer mr.clayton
Plugin Icon wp plugin Payment Plugins for Stripe WooCommerce
Version 3.1.9
Comparing to
See all releases

Code changes from version 3.1.8 to 3.1.9

assets/css/stripe.css CHANGED
@@ -256,8 +256,14 @@ li.payment_method_stripe_payment_request {
256
  display: none;
257
  }
258
 
259
- #place_order.wc-stripe-hide {
260
- display: none !important;
 
 
 
 
 
 
261
  }
262
 
263
  .wc-stripe-product-checkout-container {
@@ -617,6 +623,8 @@ li[class*="payment_method_stripe"] .select2-container .select2-selection--single
617
 
618
  li[class*="payment_method_stripe"] .select2-container--default .select2-selection--single .select2-selection__arrow {
619
  height: 42px;
 
 
620
  }
621
 
622
  .blockUI.blockMsg {
256
  display: none;
257
  }
258
 
259
+ #place_order.wc-stripe-hide,
260
+ #payment #place_order.wc-stripe-hide,
261
+ .woocommerce-checkout-review-order #payment #place_order.wc-stripe-hide{
262
+ position: absolute !important;
263
+ z-index: -1000 !important;
264
+ height: 0 !important;
265
+ padding: 0 !important;
266
+ opacity: 0 !important;
267
  }
268
 
269
  .wc-stripe-product-checkout-container {
623
 
624
  li[class*="payment_method_stripe"] .select2-container--default .select2-selection--single .select2-selection__arrow {
625
  height: 42px;
626
+ top: 1px;
627
+ right: 1px;
628
  }
629
 
630
  .blockUI.blockMsg {
assets/js/frontend/wc-stripe.js CHANGED
@@ -1488,7 +1488,7 @@
1488
 
1489
  wc_stripe.CheckoutFields.prototype.get = function (k, prefix) {
1490
  if (this[k] && typeof this[k] === 'function') {
1491
- return this[k]().get.call(this, v, prefix);
1492
  } else {
1493
  return this.fields.get(k);
1494
  }
1488
 
1489
  wc_stripe.CheckoutFields.prototype.get = function (k, prefix) {
1490
  if (this[k] && typeof this[k] === 'function') {
1491
+ return this[k]().get.call(this, prefix);
1492
  } else {
1493
  return this.fields.get(k);
1494
  }
assets/js/frontend/wc-stripe.min.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){t.wc_stripe={};var i=null;"undefined"==typeof wc_stripe_checkout_fields&&(wc_stripe_checkout_fields=[]),wc_stripe.BaseGateway=function(t){this.params=t,this.gateway_id=this.params.gateway_id,this.container="li.payment_method_"+this.gateway_id,this.token_selector=this.params.token_selector,this.saved_method_selector=this.params.saved_method_selector,this.payment_token_received=!1,this.stripe=i,this.elements=i.elements(e.extend({},{locale:"auto"},this.get_element_options())),this.mappings=new wc_stripe.CheckoutFields(wc_stripe_checkout_fields),this.initialize()},wc_stripe.BaseGateway.prototype.get_page=function(){return wc_stripe_params_v3.page},wc_stripe.BaseGateway.prototype.set_nonce=function(t){this.mappings.set(this.gateway_id+"_token_key",t),e(this.token_selector).val(t)},wc_stripe.BaseGateway.prototype.get_element_options=function(){return{}},wc_stripe.BaseGateway.prototype.initialize=function(){},wc_stripe.BaseGateway.prototype.create_button=function(){},wc_stripe.BaseGateway.prototype.is_gateway_selected=function(){return e('[name="payment_method"]:checked').val()===this.gateway_id},wc_stripe.BaseGateway.prototype.is_saved_method_selected=function(){return this.is_gateway_selected()&&"saved"===e('[name="'+this.gateway_id+'_payment_type_key"]:checked').val()},wc_stripe.BaseGateway.prototype.has_checkout_error=function(){return e("#wc_stripe_checkout_error").length>0&&this.is_gateway_selected()},wc_stripe.BaseGateway.prototype.submit_error=function(t){-1==(t=this.get_error_message(t)).indexOf("</ul>")&&(t='<div class="woocommerce-error">'+t+"</div>"),this.submit_message(t)},wc_stripe.BaseGateway.prototype.submit_error_code=function(t){},wc_stripe.BaseGateway.prototype.get_error_message=function(t){return"object"==typeof t&&t.code&&(t=wc_stripe_messages[t.code]?wc_stripe_messages[t.code]:t.message),t},wc_stripe.BaseGateway.prototype.submit_message=function(t){e(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove();var i=e(this.message_container);i.closest("form").length&&(i=i.closest("form")),i.prepend(t),i.removeClass("processing").unblock(),i.find(".input-text, select, input:checkbox").blur(),e.scroll_to_notices?e.scroll_to_notices(i):e("html, body").animate({scrollTop:i.offset().top-100},1e3)},wc_stripe.BaseGateway.prototype.get_first_name=function(t){return e("#"+t+"_first_name").val()},wc_stripe.BaseGateway.prototype.get_last_name=function(t){return e("#"+t+"_last_name").val()},wc_stripe.BaseGateway.prototype.should_save_method=function(){return e("#"+this.gateway_id+"_save_source_key").is(":checked")},wc_stripe.BaseGateway.prototype.is_add_payment_method_page=function(){return"add_payment_method"===this.get_page()||e(document.body).hasClass("woocommerce-add-payment-method")},wc_stripe.BaseGateway.prototype.is_change_payment_method=function(){return"change_payment_method"===this.get_page()},wc_stripe.BaseGateway.prototype.get_selected_payment_method=function(){return e(this.saved_method_selector).val()},wc_stripe.BaseGateway.prototype.needs_shipping=function(){return this.get_gateway_data().needs_shipping},wc_stripe.BaseGateway.prototype.get_currency=function(){return this.get_gateway_data().currency},wc_stripe.BaseGateway.prototype.get_gateway_data=function(){return e("#"+this.gateway_id+"_"+this.get_page()+"_data").data("gateway")},wc_stripe.BaseGateway.prototype.set_gateway_data=function(t){e("#"+this.gateway_id+"_"+this.get_page()+"_data").data("gateway",t)},wc_stripe.BaseGateway.prototype.get_customer_name=function(t){return e(t+"_first_name").val()+" "+e(t+"_last_name").val()},wc_stripe.BaseGateway.prototype.get_customer_email=function(){return e("#billing_email").val()},wc_stripe.BaseGateway.prototype.get_address_field_hash=function(t){for(var e=["_first_name","_last_name","_address_1","_address_2","_postcode","_city","_state","_country"],i="",s=0;s<e.length;s++)i+=this.mappings.get(t+e[s])+"_";return i},wc_stripe.BaseGateway.prototype.block=function(){e.blockUI({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.BaseGateway.prototype.unblock=function(){e.unblockUI()},wc_stripe.BaseGateway.prototype.get_form=function(){return e(this.token_selector).closest("form")},wc_stripe.BaseGateway.prototype.get_total_price=function(){return this.get_gateway_data().total},wc_stripe.BaseGateway.prototype.get_total_price_cents=function(){return this.get_gateway_data().total_cents},wc_stripe.BaseGateway.prototype.set_total_price=function(t){var e=this.get_gateway_data();e.total=t,this.set_gateway_data(e)},wc_stripe.BaseGateway.prototype.set_total_price_cents=function(t){var e=this.get_gateway_data();e.total_cents=t,this.set_gateway_data(e)},wc_stripe.BaseGateway.prototype.set_payment_method=function(t){e('[name="payment_method"][value="'+t+'"]').prop("checked",!0).trigger("click")},wc_stripe.BaseGateway.prototype.set_selected_shipping_methods=function(t){if(t&&e('[name^="shipping_method"]').length)for(var i in t){var s=t[i];e('[name="shipping_method['+i+']"][value="'+s+'"]').prop("checked",!0).trigger("change")}},wc_stripe.BaseGateway.prototype.on_token_received=function(t){this.payment_token_received=!0,this.set_nonce(t.id),this.process_checkout()},wc_stripe.BaseGateway.prototype.createPaymentRequest=function(){try{this.paymentRequest=i.paymentRequest(this.get_payment_request_options())}catch(t){return void this.submit_error(t.message)}this.needs_shipping()&&(this.paymentRequest.on("shippingaddresschange",this.update_shipping_address.bind(this)),this.paymentRequest.on("shippingoptionchange",this.update_shipping_method.bind(this))),this.paymentRequest.on("paymentmethod",this.on_payment_method_received.bind(this))},wc_stripe.BaseGateway.prototype.get_payment_request_options=function(){var t={country:this.params.country_code,currency:this.get_currency().toLowerCase(),total:{amount:this.get_total_price_cents(),label:this.params.total_label,pending:!0},requestPayerName:!0,requestPayerEmail:this.mappings.required("billing_email"),requestPayerPhone:this.mappings.required("billing_phone"),requestShipping:this.needs_shipping()},e=this.get_display_items(),i=this.get_shipping_options();return e&&(t.displayItems=e),this.needs_shipping()&&i&&(t.shippingOptions=i),t},wc_stripe.BaseGateway.prototype.get_payment_request_update=function(t){var i={currency:this.get_currency().toLowerCase(),total:{amount:parseInt(this.get_total_price_cents()),label:this.params.total_label,pending:!0}},s=this.get_display_items(),a=this.get_shipping_options();return s&&(i.displayItems=s),this.needs_shipping()&&a&&(i.shippingOptions=a),t&&(i=e.extend(!0,{},i,t)),i},wc_stripe.BaseGateway.prototype.get_display_items=function(){return this.get_gateway_data().items},wc_stripe.BaseGateway.prototype.set_display_items=function(t){var e=this.get_gateway_data();e.items=t,this.set_gateway_data(e)},wc_stripe.BaseGateway.prototype.get_shipping_options=function(){return this.get_gateway_data().shipping_options},wc_stripe.BaseGateway.prototype.set_shipping_options=function(t){var e=this.get_gateway_data();e.shipping_options=t,this.set_gateway_data(e)},wc_stripe.BaseGateway.prototype.map_address=function(t){return{city:t.city,postcode:t.postalCode,state:t.region,country:t.country}},wc_stripe.BaseGateway.prototype.on_payment_method_received=function(e){try{this.payment_response=e,this.populate_checkout_fields(e),e.complete("success"),this.on_token_received(e.paymentMethod)}catch(e){t.alert(e)}},wc_stripe.BaseGateway.prototype.populate_checkout_fields=function(t){this.set_nonce(t.paymentMethod.id),this.populate_address_fields(t)},wc_stripe.BaseGateway.prototype.populate_address_fields=function(t){if(t.payerName&&this.mappings.set("name",t.payerName,"billing"),t.payerEmail&&this.mappings.set("email",t.payerEmail,"billing"),t.payerPhone&&this.mappings.set("phone",t.payerPhone,"billing"),t.shippingAddress){var i=t.shippingAddress;for(var s in i)this.mappings.set(s,i[s],"shipping")}if(t.paymentMethod.billing_details.address){i=t.paymentMethod.billing_details.address;for(var s in i)this.mappings.set(s,i[s],"billing")}"checkout"===this.get_page()&&(this.maybe_set_ship_to_different(),this.mappings.toFormFields(),e('[name="billing_country"]').trigger("change"))},wc_stripe.BaseGateway.prototype.address_mappings=function(){return new wc_stripe.CheckoutFields},wc_stripe.BaseGateway.prototype.ajax_before_send=function(t){this.params.user_id>0&&t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)},wc_stripe.BaseGateway.prototype.process_checkout=function(){return new Promise(function(i,s){this.block(),e.ajax({url:this.params.routes.checkout,method:"POST",dataType:"json",data:e.extend({},this.serialize_fields(),{payment_method:this.gateway_id,page_id:this.get_page()}),beforeSend:this.ajax_before_send.bind(this)}).done(function(e){e.reload?t.location.reload():"success"===e.result?t.location=e.redirect:(e.messages&&this.submit_error(e.messages),this.unblock())}.bind(this)).fail(function(t,e,i){this.unblock(),this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.BaseGateway.prototype.serialize_form=function(t){var i=t.find("input").filter(function(t,i){return!e(i).is('[name^="add-to-cart"]')}.bind(this)).serializeArray(),s={};for(var a in i){var n=i[a];s[n.name]=n.value}return s.payment_method=this.gateway_id,s},wc_stripe.BaseGateway.prototype.serialize_fields=function(){return this.mappings.toJson()},wc_stripe.BaseGateway.prototype.map_shipping_methods=function(t){var e={};if("default"!==t){var i=t.match(/^([\w+]):(.+)$/);i.length>1&&(e[i[1]]=i[2])}return e},wc_stripe.BaseGateway.prototype.maybe_set_ship_to_different=function(){e('[name="ship_to_different_address"]').length&&e('[name="ship_to_different_address"]').prop("checked",this.get_address_field_hash("billing")!==this.get_address_field_hash("shipping")).trigger("change")},wc_stripe.BaseGateway.prototype.update_shipping_address=function(t){return new Promise(function(i,s){e.ajax({url:this.params.routes.shipping_address,method:"POST",dataType:"json",data:{address:this.map_address(t.shippingAddress),payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)}).done(function(e){e.code?(t.updateWith(e.data.newData),s(e.data)):(t.updateWith(e.data.newData),i(e.data))}.bind(this)).fail(function(t,e,i){}.bind(this))}.bind(this))},wc_stripe.BaseGateway.prototype.update_shipping_method=function(t){return new Promise(function(i,s){e.ajax({url:this.params.routes.shipping_method,method:"POST",dataType:"json",data:{shipping_method:t.shippingOption.id,payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)}).done(function(e){e.code?(t.updateWith(e.data.newData),s(e.data)):(this.set_selected_shipping_methods(e.data.shipping_methods),t.updateWith(e.data.newData),i(e.data))}.bind(this)).fail(function(t,e,i){this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.CheckoutGateway=function(){this.message_container="li.payment_method_"+this.gateway_id,this.banner_container="li.banner_payment_method_"+this.gateway_id,e(document.body).on("update_checkout",this.update_checkout.bind(this)),e(document.body).on("updated_checkout",this.updated_checkout.bind(this)),e(document.body).on("checkout_error",this.checkout_error.bind(this)),e(this.token_selector).closest("form").on("checkout_place_order_"+this.gateway_id,this.checkout_place_order.bind(this)),e(document.body).on("wc_stripe_new_method_"+this.gateway_id,this.on_show_new_methods.bind(this)),e(document.body).on("wc_stripe_saved_method_"+this.gateway_id,this.on_show_saved_methods.bind(this)),e(document.body).on("wc_stripe_payment_method_selected",this.on_payment_method_selected.bind(this)),this.banner_enabled()&&e(".woocommerce-billing-fields").length&&e(".wc-stripe-banner-checkout").css("max-width",e(".woocommerce-billing-fields").outerWidth(!0)),this.order_review()},wc_stripe.CheckoutGateway.prototype.order_review=function(){var e=t.location.href.match(/order_review.+payment_method=([\w]+).+payment_nonce=(.+)/);if(e&&e.length>1){var i=e[1],s=e[2];this.gateway_id===i&&(this.payment_token_received=!0,this.set_nonce(s),this.set_use_new_option(!0))}},wc_stripe.CheckoutGateway.prototype.updated_checkout=function(){},wc_stripe.CheckoutGateway.prototype.update_checkout=function(){},wc_stripe.CheckoutGateway.prototype.checkout_error=function(){this.has_checkout_error()&&(this.payment_token_received=!1,this.payment_response=null,this.show_payment_button(),this.hide_place_order())},wc_stripe.CheckoutGateway.prototype.is_valid_checkout=function(){return!(e('[name="terms"]').length&&!e('[name="terms"]').is(":checked"))},wc_stripe.CheckoutGateway.prototype.get_payment_method=function(){return e('[name="payment_method"]:checked').val()},wc_stripe.CheckoutGateway.prototype.set_use_new_option=function(t){e("#"+this.gateway_id+"_use_new").prop("checked",t).trigger("change")},wc_stripe.CheckoutGateway.prototype.checkout_place_order=function(){return this.is_valid_checkout()?!!this.is_saved_method_selected()||this.payment_token_received:(this.submit_error(this.params.messages.terms),!1)},wc_stripe.CheckoutGateway.prototype.on_token_received=function(t){this.payment_token_received=!0,this.set_nonce(t.id),this.hide_payment_button(),this.show_place_order()},wc_stripe.CheckoutGateway.prototype.block=function(){e("form.checkout").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.CheckoutGateway.prototype.unblock=function(){e("form.checkout").unblock()},wc_stripe.CheckoutGateway.prototype.hide_place_order=function(){e("#place_order").addClass("wc-stripe-hide")},wc_stripe.CheckoutGateway.prototype.show_place_order=function(){e("#place_order").removeClass("wc-stripe-hide")},wc_stripe.CheckoutGateway.prototype.on_show_new_methods=function(){this.payment_token_received?(this.show_place_order(),this.hide_payment_button()):(this.hide_place_order(),this.show_payment_button())},wc_stripe.CheckoutGateway.prototype.on_show_saved_methods=function(){this.hide_payment_button(),this.show_place_order()},wc_stripe.CheckoutGateway.prototype.show_payment_button=function(){this.$button&&this.$button.show()},wc_stripe.CheckoutGateway.prototype.hide_payment_button=function(){this.$button&&this.$button.hide()},wc_stripe.CheckoutGateway.prototype.trigger_payment_method_selected=function(){this.on_payment_method_selected(null,e('[name="payment_method"]:checked').val())},wc_stripe.CheckoutGateway.prototype.on_payment_method_selected=function(t,e){e===this.gateway_id?this.payment_token_received||this.is_saved_method_selected()?(this.hide_payment_button(),this.show_place_order()):(this.show_payment_button(),this.hide_place_order()):(this.hide_payment_button(),e.indexOf("stripe_")<0&&this.show_place_order())},wc_stripe.CheckoutGateway.prototype.banner_enabled=function(){return"1"===this.params.banner_enabled},wc_stripe.CheckoutGateway.prototype.checkout_fields_valid=function(){if("undefined"==typeof wc_stripe_checkout_fields||"checkout"!==this.get_page())return!0;function t(t,i){for(var s in i){var a=i[s];if(s.indexOf(t)>-1&&a.required&&e("#"+s).length){var n=e("#"+s).val();if(void 0===n||0==n.length)return void(valid=!1)}}}return valid=!0,t("billing",wc_stripe_checkout_fields),this.needs_shipping()&&e("#ship-to-different-address-checkbox").is(":checked")&&t("shipping",wc_stripe_checkout_fields),valid&&(valid=this.is_valid_checkout()),valid},wc_stripe.ProductGateway=function(){this.message_container="div.product",e("form.cart").on("found_variation",this.found_variation.bind(this)),e("form.cart").on("reset_data",this.reset_variation_data.bind(this)),this.buttonWidth=e("div.quantity").outerWidth(!0)+e(".single_add_to_cart_button").outerWidth();var t=e(".single_add_to_cart_button").css("marginLeft");t&&(this.buttonWidth+=parseInt(t.replace("px",""))),e(this.container).css("max-width",this.buttonWidth+"px")},wc_stripe.ProductGateway.prototype.get_quantity=function(){return parseInt(e('[name="quantity"]').val())},wc_stripe.ProductGateway.prototype.set_rest_nonce=function(t,e){this.params.rest_nonce=e},wc_stripe.ProductGateway.prototype.found_variation=function(t,e){var i=this.get_gateway_data();i.product.price=e.display_price,i.needs_shipping=!e.is_virtual,i.product.variation=e,this.set_gateway_data(i),this.enable_payment_button()},wc_stripe.ProductGateway.prototype.reset_variation_data=function(){var t=this.get_product_data();t.variation=!1,this.set_product_data(t),this.disable_payment_button()},wc_stripe.ProductGateway.prototype.disable_payment_button=function(){this.$button&&this.get_button().prop("disabled",!0).addClass("disabled")},wc_stripe.ProductGateway.prototype.enable_payment_button=function(){this.$button&&this.get_button().prop("disabled",!1).removeClass("disabled")},wc_stripe.ProductGateway.prototype.get_button=function(){return this.$button},wc_stripe.ProductGateway.prototype.is_variable_product=function(){return e('[name="variation_id"]').length>0},wc_stripe.ProductGateway.prototype.variable_product_selected=function(){return!1!==this.get_product_data().variation},wc_stripe.ProductGateway.prototype.get_product_data=function(){return this.get_gateway_data().product},wc_stripe.ProductGateway.prototype.set_product_data=function(t){var e=this.get_gateway_data();e.product=t,this.set_gateway_data(e)},wc_stripe.ProductGateway.prototype.add_to_cart=function(){return new Promise(function(t,i){this.block(),e.ajax({url:this.params.routes.add_to_cart,method:"POST",dataType:"json",data:{product_id:this.get_product_data().id,variation_id:this.is_variable_product()?e('[name="variation_id"]').val():0,qty:e('[name="quantity"]').val(),payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)}).done(function(e,s,a){this.unblock(),e.code?(this.submit_error(e.message),i(e)):(this.set_total_price(e.data.total),this.set_total_price_cents(e.data.totalCents),this.set_display_items(e.data.displayItems),t(e.data))}.bind(this)).fail(function(t,e,i){this.unblock(),this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.ProductGateway.prototype.cart_calculation=function(t){return new Promise(function(i,s){e.ajax({url:this.params.routes.cart_calculation,method:"POST",dataType:"json",data:{product_id:this.get_product_data().id,variation_id:this.is_variable_product()&&t?t:0,qty:e('[name="quantity"]').val(),payment_method:this.gateway_id},beforeSend:this.ajax_before_send.bind(this)}).done(function(t,e,a){t.code?(this.cart_calculation_error=!0,s(t)):(this.set_total_price(t.data.total),this.set_total_price_cents(t.data.totalCents),this.set_display_items(t.data.displayItems),i(t.data))}.bind(this)).fail(function(t,e,i){}.bind(this))}.bind(this))},wc_stripe.CartGateway=function(){this.message_container="div.woocommerce",e(document.body).on("updated_wc_div",this.updated_html.bind(this)),e(document.body).on("updated_cart_totals",this.updated_html.bind(this)),e(document.body).on("wc_cart_emptied",this.cart_emptied.bind(this))},wc_stripe.CartGateway.prototype.submit_error=function(t){this.submit_message(this.get_error_message(t))},wc_stripe.CartGateway.prototype.updated_html=function(t){},wc_stripe.CartGateway.prototype.cart_emptied=function(t){},wc_stripe.CartGateway.prototype.add_cart_totals_class=function(){e(".cart_totals").addClass("stripe_cart_gateway_active")},wc_stripe.GooglePay=function(){};const s={apiVersion:2,apiVersionMinor:0},a={type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY"],allowedCardNetworks:["AMEX","DISCOVER","INTERAC","JCB","MASTERCARD","VISA"]}};wc_stripe.GooglePay.prototype.populate_address_fields=function(t){var i=t.paymentMethodData.info.billingAddress;for(var s in i)this.mappings.set(s,i[s],"billing");if(t.shippingAddress)for(var s in t.shippingAddress)this.mappings.set(s,t.shippingAddress[s],"shipping");t.email&&this.mappings.set("email",t.email,"billing"),"checkout"===this.get_page()&&(this.maybe_set_ship_to_different(),this.mappings.toFormFields(),e('[name="billing_country"]').trigger("change"))},wc_stripe.GooglePay.prototype.map_address=function(t){return{city:t.locality,postcode:t.postalCode,state:t.administrativeArea,country:t.countryCode}},wc_stripe.GooglePay.prototype.update_payment_data=function(t){return new Promise(function(i,s){var a="default"==t.shippingOptionData.id?null:t.shippingOptionData.id;e.when(e.ajax({url:this.params.routes.payment_data,dataType:"json",method:"POST",data:{shipping_address:this.map_address(t.shippingAddress),shipping_method:a,page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)})).done(function(t){t.code?s(t.data.data):i(t.data)}.bind(this)).fail(function(){s()}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.on_payment_data_changed=function(t){return new Promise(function(e,i){this.update_payment_data(t).then(function(i){e(i.paymentRequestUpdate),this.set_selected_shipping_methods(i.shipping_methods),this.payment_data_updated(i,t)}.bind(this)).catch(function(t){e(t)}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.payment_data_updated=function(t){},wc_stripe.GooglePay.prototype.get_merchant_info=function(){var t={merchantId:this.params.merchant_id,merchantName:this.params.merchant_name};return"TEST"===this.params.environment&&delete t.merchantId,t},wc_stripe.GooglePay.prototype.get_payment_options=function(){var t={environment:this.params.environment,merchantInfo:this.get_merchant_info()};return this.needs_shipping()&&this.get_total_price_cents()>0?t.paymentDataCallbacks={onPaymentDataChanged:this.on_payment_data_changed.bind(this),onPaymentAuthorized:function(t){return new Promise(function(t,e){t({transactionState:"SUCCESS"})}.bind(this))}.bind(this)}:t.paymentDataCallbacks={onPaymentAuthorized:function(t){return new Promise(function(t,e){t({transactionState:"SUCCESS"})}.bind(this))}},t},wc_stripe.GooglePay.prototype.build_payment_request=function(){var t=e.extend({},s,{emailRequired:this.mappings.required("billing_email"),merchantInfo:this.get_merchant_info(),allowedPaymentMethods:[e.extend({type:"CARD",tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:"stripe","stripe:version":"2018-10-31","stripe:publishableKey":this.params.api_key}}},a)],shippingAddressRequired:this.needs_shipping()&&this.get_total_price_cents()>0,transactionInfo:{currencyCode:this.get_currency(),totalPriceStatus:"ESTIMATED",totalPrice:this.get_total_price().toString(),displayItems:this.get_display_items(),totalPriceLabel:this.params.total_price_label}});return t.allowedPaymentMethods[0].parameters.billingAddressRequired=!0,t.allowedPaymentMethods[0].parameters.billingAddressParameters={format:"FULL",phoneNumberRequired:this.mappings.required("billing_phone")},this.needs_shipping()&&this.get_total_price_cents()>0?(t.shippingAddressParameters={},t.shippingOptionRequired=!0,t.shippingOptionParameters={shippingOptions:this.get_shipping_options()},t.callbackIntents=["SHIPPING_ADDRESS","SHIPPING_OPTION","PAYMENT_AUTHORIZATION"]):t.callbackIntents=["PAYMENT_AUTHORIZATION"],t},wc_stripe.GooglePay.prototype.createPaymentsClient=function(){this.paymentsClient=new google.payments.api.PaymentsClient(this.get_payment_options())},wc_stripe.GooglePay.prototype.isReadyToPay=function(){return new Promise(function(t){var i=e.extend({},s);i.allowedPaymentMethods=[a],this.paymentsClient.isReadyToPay(i).then(function(){this.can_pay=!0,this.create_button(),t()}.bind(this)).catch(function(t){this.submit_error(t)}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.create_button=function(){this.$button&&this.$button.remove(),this.$button=e(this.paymentsClient.createButton({onClick:this.start.bind(this),buttonColor:this.params.button_color,buttonType:this.params.button_style})),this.$button.addClass("gpay-button-container")},wc_stripe.GooglePay.prototype.start=function(){this.createPaymentsClient(),this.paymentsClient.loadPaymentData(this.build_payment_request()).then(function(t){var e=JSON.parse(t.paymentMethodData.tokenizationData.token);this.populate_address_fields(t),this.on_token_received(e)}.bind(this)).catch(function(t){"CANCELED"!==t.statusCode&&(t.statusMessage&&t.statusMessage.indexOf("paymentDataRequest.callbackIntent")>-1?this.submit_error_code("DEVELOPER_ERROR_WHITELIST"):this.submit_error(t.statusMessage))}.bind(this))},wc_stripe.ApplePay=function(){},wc_stripe.ApplePay.prototype.initialize=function(){var t=".apple-pay-button";["checkout","order_pay"].indexOf(this.get_page())<0&&(t=this.container+" .apple-pay-button"),e(document.body).on("click",t,this.start.bind(this)),this.createPaymentRequest(),this.canMakePayment()},wc_stripe.ApplePay.prototype.create_button=function(){this.$button&&this.$button.remove(),this.$button=e(this.params.button),this.append_button()},wc_stripe.ApplePay.prototype.canMakePayment=function(){return new Promise(function(t,i){this.paymentRequest.canMakePayment().then(function(i){i&&i.applePay&&(this.can_pay=!0,this.create_button(),e(this.container).show(),t(i))}.bind(this))}.bind(this))},wc_stripe.ApplePay.prototype.start=function(t){t.preventDefault(),this.paymentRequest.update(this.get_payment_request_update({total:{pending:!1}})),this.paymentRequest.show()},wc_stripe.PaymentRequest=function(){},wc_stripe.PaymentRequest.prototype.initialize=function(){this.createPaymentRequest(),this.canMakePayment(),this.paymentRequestButton=this.createPaymentRequestButton(),this.paymentRequestButton.on("click",this.button_click.bind(this))},wc_stripe.PaymentRequest.prototype.button_click=function(t){},wc_stripe.PaymentRequest.prototype.createPaymentRequestButton=function(){return this.elements.create("paymentRequestButton",{paymentRequest:this.paymentRequest,style:{paymentRequestButton:{type:this.params.button.type,theme:this.params.button.theme,height:this.params.button.height}}})},wc_stripe.PaymentRequest.prototype.canMakePayment=function(){return new Promise(function(t,i){this.paymentRequest.canMakePayment().then(function(i){i&&!i.applePay&&(this.can_pay=!0,this.create_button(),e(this.container).show(),t(i))}.bind(this))}.bind(this))},wc_stripe.PaymentRequest.prototype.create_button=function(){this.paymentRequestButton.mount("#wc-stripe-payment-request-container")},wc_stripe.CheckoutFields=function(t){this.params=t,this.fields=new Map(Object.keys(this.params).map(function(t){return[t,this.params[t].value]}.bind(this)))},wc_stripe.CheckoutFields.prototype.set=function(t,e,i){this[t]&&"function"==typeof this[t]?this[t]().set.call(this,e,i):this.fields.set(t,e)},wc_stripe.CheckoutFields.prototype.get=function(t,e){return this[t]&&"function"==typeof this[t]?this[t]().get.call(this,v,e):this.fields.get(t)},wc_stripe.CheckoutFields.prototype.required=function(t){return this.params[t]&&this.params[t].required},wc_stripe.CheckoutFields.prototype.name=function(){return{set:function(t,e){var i=t.split(" ");this.fields.set(e+"_first_name",i[0]),this.fields.set(e+"_last_name",i[1])},get:function(t){return this.fields.get(t+"_first_name")+" "+this.fields.get(t+"_last_name")}}},wc_stripe.CheckoutFields.prototype.payerName=function(){return wc_stripe.CheckoutFields.prototype.name.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.email=function(){return{set:function(t,e){this.fields.set(e+"_email",t)},get:function(t){return this.fields.get(t+"_email")}}},wc_stripe.CheckoutFields.prototype.payerEmail=function(){return wc_stripe.CheckoutFields.prototype.email.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.phone=function(){return{set:function(t,e){this.fields.set(e+"_phone",t)},get:function(t){return this.fields.get(t+"_phone")}}},wc_stripe.CheckoutFields.prototype.payerPhone=function(){return wc_stripe.CheckoutFields.prototype.phone.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.phoneNumber=function(){return wc_stripe.CheckoutFields.prototype.phone.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.recipient=function(){return{set:function(t,e){var i=t.split(" ");i.length>0&&this.fields.set(e+"_first_name",i[0]),i.length>1&&this.fields.set(e+"_last_name",i[1])},get:function(t){return this.fields.get(t+"_first_name")+" "+this.fields.get(t+"_last_name")}}},wc_stripe.CheckoutFields.prototype.country=function(){return{set:function(t,e){this.fields.set(e+"_country",t)},get:function(t){return this.fields.get(t+"_country")}}},wc_stripe.CheckoutFields.prototype.countryCode=function(){return wc_stripe.CheckoutFields.prototype.country.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.address1=function(){return{set:function(t,e){this.fields.set(e+"_address_1",t)},get:function(t){return this.fields.get(t+"_address_1")}}},wc_stripe.CheckoutFields.prototype.address2=function(){return{set:function(t,e){this.fields.set(e+"_address_2",t)},get:function(t){this.fields.get(t+"_address_2")}}},wc_stripe.CheckoutFields.prototype.line1=function(){return wc_stripe.CheckoutFields.prototype.address1.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.line2=function(){return wc_stripe.CheckoutFields.prototype.address2.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.addressLine=function(){return{set:function(t,e){t.length>0&&this.fields.set(e+"_address_1",t[0]),t.length>1&&this.fields.set(e+"_address_2",t[1])},get:function(t){return[this.fields.get(t+"_address_1"),this.fields.get(t+"_address_2")]}}},wc_stripe.CheckoutFields.prototype.state=function(){return{set:function(t,e){this.fields.set(e+"_state",t)},get:function(t){return this.fields.get(t+"_state")}}},wc_stripe.CheckoutFields.prototype.region=function(){return wc_stripe.CheckoutFields.prototype.state.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.administrativeArea=function(){return wc_stripe.CheckoutFields.prototype.state.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.city=function(){return{set:function(t,e){this.fields.set(e+"_city",t)},get:function(t){this.fields.get(t+"_city")}}},wc_stripe.CheckoutFields.prototype.locality=function(){return wc_stripe.CheckoutFields.prototype.city.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.postal_code=function(){return{set:function(t,e){this.fields.set(e+"_postcode",t)},get:function(t){this.fields.get(t+"_postcode")}}},wc_stripe.CheckoutFields.prototype.postalCode=function(){return wc_stripe.CheckoutFields.prototype.postal_code.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.toJson=function(){var t={};return this.fields.forEach(function(e,i){t[i]=e}),t},wc_stripe.CheckoutFields.prototype.toFormFields=function(){this.fields.forEach(function(t,i){e(i='[name="'+i+'"]').length&&""!==t&&e(i).val(t)})};try{i=Stripe(wc_stripe_params_v3.api_key,{stripeAccount:wc_stripe_params_v3.account})}catch(e){return t.alert(e),void console.log(e)}}(window,jQuery);
1
+ !function(t,e){t.wc_stripe={};var i=null;"undefined"==typeof wc_stripe_checkout_fields&&(wc_stripe_checkout_fields=[]),wc_stripe.BaseGateway=function(t){this.params=t,this.gateway_id=this.params.gateway_id,this.container="li.payment_method_"+this.gateway_id,this.token_selector=this.params.token_selector,this.saved_method_selector=this.params.saved_method_selector,this.payment_token_received=!1,this.stripe=i,this.elements=i.elements(e.extend({},{locale:"auto"},this.get_element_options())),this.mappings=new wc_stripe.CheckoutFields(wc_stripe_checkout_fields),this.initialize()},wc_stripe.BaseGateway.prototype.get_page=function(){return wc_stripe_params_v3.page},wc_stripe.BaseGateway.prototype.set_nonce=function(t){this.mappings.set(this.gateway_id+"_token_key",t),e(this.token_selector).val(t)},wc_stripe.BaseGateway.prototype.get_element_options=function(){return{}},wc_stripe.BaseGateway.prototype.initialize=function(){},wc_stripe.BaseGateway.prototype.create_button=function(){},wc_stripe.BaseGateway.prototype.is_gateway_selected=function(){return e('[name="payment_method"]:checked').val()===this.gateway_id},wc_stripe.BaseGateway.prototype.is_saved_method_selected=function(){return this.is_gateway_selected()&&"saved"===e('[name="'+this.gateway_id+'_payment_type_key"]:checked').val()},wc_stripe.BaseGateway.prototype.has_checkout_error=function(){return e("#wc_stripe_checkout_error").length>0&&this.is_gateway_selected()},wc_stripe.BaseGateway.prototype.submit_error=function(t){-1==(t=this.get_error_message(t)).indexOf("</ul>")&&(t='<div class="woocommerce-error">'+t+"</div>"),this.submit_message(t)},wc_stripe.BaseGateway.prototype.submit_error_code=function(t){},wc_stripe.BaseGateway.prototype.get_error_message=function(t){return"object"==typeof t&&t.code&&(t=wc_stripe_messages[t.code]?wc_stripe_messages[t.code]:t.message),t},wc_stripe.BaseGateway.prototype.submit_message=function(t){e(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove();var i=e(this.message_container);i.closest("form").length&&(i=i.closest("form")),i.prepend(t),i.removeClass("processing").unblock(),i.find(".input-text, select, input:checkbox").blur(),e.scroll_to_notices?e.scroll_to_notices(i):e("html, body").animate({scrollTop:i.offset().top-100},1e3)},wc_stripe.BaseGateway.prototype.get_first_name=function(t){return e("#"+t+"_first_name").val()},wc_stripe.BaseGateway.prototype.get_last_name=function(t){return e("#"+t+"_last_name").val()},wc_stripe.BaseGateway.prototype.should_save_method=function(){return e("#"+this.gateway_id+"_save_source_key").is(":checked")},wc_stripe.BaseGateway.prototype.is_add_payment_method_page=function(){return"add_payment_method"===this.get_page()||e(document.body).hasClass("woocommerce-add-payment-method")},wc_stripe.BaseGateway.prototype.is_change_payment_method=function(){return"change_payment_method"===this.get_page()},wc_stripe.BaseGateway.prototype.get_selected_payment_method=function(){return e(this.saved_method_selector).val()},wc_stripe.BaseGateway.prototype.needs_shipping=function(){return this.get_gateway_data().needs_shipping},wc_stripe.BaseGateway.prototype.get_currency=function(){return this.get_gateway_data().currency},wc_stripe.BaseGateway.prototype.get_gateway_data=function(){return e("#"+this.gateway_id+"_"+this.get_page()+"_data").data("gateway")},wc_stripe.BaseGateway.prototype.set_gateway_data=function(t){e("#"+this.gateway_id+"_"+this.get_page()+"_data").data("gateway",t)},wc_stripe.BaseGateway.prototype.get_customer_name=function(t){return e(t+"_first_name").val()+" "+e(t+"_last_name").val()},wc_stripe.BaseGateway.prototype.get_customer_email=function(){return e("#billing_email").val()},wc_stripe.BaseGateway.prototype.get_address_field_hash=function(t){for(var e=["_first_name","_last_name","_address_1","_address_2","_postcode","_city","_state","_country"],i="",s=0;s<e.length;s++)i+=this.mappings.get(t+e[s])+"_";return i},wc_stripe.BaseGateway.prototype.block=function(){e.blockUI({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.BaseGateway.prototype.unblock=function(){e.unblockUI()},wc_stripe.BaseGateway.prototype.get_form=function(){return e(this.token_selector).closest("form")},wc_stripe.BaseGateway.prototype.get_total_price=function(){return this.get_gateway_data().total},wc_stripe.BaseGateway.prototype.get_total_price_cents=function(){return this.get_gateway_data().total_cents},wc_stripe.BaseGateway.prototype.set_total_price=function(t){var e=this.get_gateway_data();e.total=t,this.set_gateway_data(e)},wc_stripe.BaseGateway.prototype.set_total_price_cents=function(t){var e=this.get_gateway_data();e.total_cents=t,this.set_gateway_data(e)},wc_stripe.BaseGateway.prototype.set_payment_method=function(t){e('[name="payment_method"][value="'+t+'"]').prop("checked",!0).trigger("click")},wc_stripe.BaseGateway.prototype.set_selected_shipping_methods=function(t){if(t&&e('[name^="shipping_method"]').length)for(var i in t){var s=t[i];e('[name="shipping_method['+i+']"][value="'+s+'"]').prop("checked",!0).trigger("change")}},wc_stripe.BaseGateway.prototype.on_token_received=function(t){this.payment_token_received=!0,this.set_nonce(t.id),this.process_checkout()},wc_stripe.BaseGateway.prototype.createPaymentRequest=function(){try{this.paymentRequest=i.paymentRequest(this.get_payment_request_options())}catch(t){return void this.submit_error(t.message)}this.needs_shipping()&&(this.paymentRequest.on("shippingaddresschange",this.update_shipping_address.bind(this)),this.paymentRequest.on("shippingoptionchange",this.update_shipping_method.bind(this))),this.paymentRequest.on("paymentmethod",this.on_payment_method_received.bind(this))},wc_stripe.BaseGateway.prototype.get_payment_request_options=function(){var t={country:this.params.country_code,currency:this.get_currency().toLowerCase(),total:{amount:this.get_total_price_cents(),label:this.params.total_label,pending:!0},requestPayerName:!0,requestPayerEmail:this.mappings.required("billing_email"),requestPayerPhone:this.mappings.required("billing_phone"),requestShipping:this.needs_shipping()},e=this.get_display_items(),i=this.get_shipping_options();return e&&(t.displayItems=e),this.needs_shipping()&&i&&(t.shippingOptions=i),t},wc_stripe.BaseGateway.prototype.get_payment_request_update=function(t){var i={currency:this.get_currency().toLowerCase(),total:{amount:parseInt(this.get_total_price_cents()),label:this.params.total_label,pending:!0}},s=this.get_display_items(),a=this.get_shipping_options();return s&&(i.displayItems=s),this.needs_shipping()&&a&&(i.shippingOptions=a),t&&(i=e.extend(!0,{},i,t)),i},wc_stripe.BaseGateway.prototype.get_display_items=function(){return this.get_gateway_data().items},wc_stripe.BaseGateway.prototype.set_display_items=function(t){var e=this.get_gateway_data();e.items=t,this.set_gateway_data(e)},wc_stripe.BaseGateway.prototype.get_shipping_options=function(){return this.get_gateway_data().shipping_options},wc_stripe.BaseGateway.prototype.set_shipping_options=function(t){var e=this.get_gateway_data();e.shipping_options=t,this.set_gateway_data(e)},wc_stripe.BaseGateway.prototype.map_address=function(t){return{city:t.city,postcode:t.postalCode,state:t.region,country:t.country}},wc_stripe.BaseGateway.prototype.on_payment_method_received=function(e){try{this.payment_response=e,this.populate_checkout_fields(e),e.complete("success"),this.on_token_received(e.paymentMethod)}catch(e){t.alert(e)}},wc_stripe.BaseGateway.prototype.populate_checkout_fields=function(t){this.set_nonce(t.paymentMethod.id),this.populate_address_fields(t)},wc_stripe.BaseGateway.prototype.populate_address_fields=function(t){if(t.payerName&&this.mappings.set("name",t.payerName,"billing"),t.payerEmail&&this.mappings.set("email",t.payerEmail,"billing"),t.payerPhone&&this.mappings.set("phone",t.payerPhone,"billing"),t.shippingAddress){var i=t.shippingAddress;for(var s in i)this.mappings.set(s,i[s],"shipping")}if(t.paymentMethod.billing_details.address){i=t.paymentMethod.billing_details.address;for(var s in i)this.mappings.set(s,i[s],"billing")}"checkout"===this.get_page()&&(this.maybe_set_ship_to_different(),this.mappings.toFormFields(),e('[name="billing_country"]').trigger("change"))},wc_stripe.BaseGateway.prototype.address_mappings=function(){return new wc_stripe.CheckoutFields},wc_stripe.BaseGateway.prototype.ajax_before_send=function(t){this.params.user_id>0&&t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)},wc_stripe.BaseGateway.prototype.process_checkout=function(){return new Promise(function(i,s){this.block(),e.ajax({url:this.params.routes.checkout,method:"POST",dataType:"json",data:e.extend({},this.serialize_fields(),{payment_method:this.gateway_id,page_id:this.get_page()}),beforeSend:this.ajax_before_send.bind(this)}).done(function(e){e.reload?t.location.reload():"success"===e.result?t.location=e.redirect:(e.messages&&this.submit_error(e.messages),this.unblock())}.bind(this)).fail(function(t,e,i){this.unblock(),this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.BaseGateway.prototype.serialize_form=function(t){var i=t.find("input").filter(function(t,i){return!e(i).is('[name^="add-to-cart"]')}.bind(this)).serializeArray(),s={};for(var a in i){var n=i[a];s[n.name]=n.value}return s.payment_method=this.gateway_id,s},wc_stripe.BaseGateway.prototype.serialize_fields=function(){return this.mappings.toJson()},wc_stripe.BaseGateway.prototype.map_shipping_methods=function(t){var e={};if("default"!==t){var i=t.match(/^([\w+]):(.+)$/);i.length>1&&(e[i[1]]=i[2])}return e},wc_stripe.BaseGateway.prototype.maybe_set_ship_to_different=function(){e('[name="ship_to_different_address"]').length&&e('[name="ship_to_different_address"]').prop("checked",this.get_address_field_hash("billing")!==this.get_address_field_hash("shipping")).trigger("change")},wc_stripe.BaseGateway.prototype.update_shipping_address=function(t){return new Promise(function(i,s){e.ajax({url:this.params.routes.shipping_address,method:"POST",dataType:"json",data:{address:this.map_address(t.shippingAddress),payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)}).done(function(e){e.code?(t.updateWith(e.data.newData),s(e.data)):(t.updateWith(e.data.newData),i(e.data))}.bind(this)).fail(function(t,e,i){}.bind(this))}.bind(this))},wc_stripe.BaseGateway.prototype.update_shipping_method=function(t){return new Promise(function(i,s){e.ajax({url:this.params.routes.shipping_method,method:"POST",dataType:"json",data:{shipping_method:t.shippingOption.id,payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)}).done(function(e){e.code?(t.updateWith(e.data.newData),s(e.data)):(this.set_selected_shipping_methods(e.data.shipping_methods),t.updateWith(e.data.newData),i(e.data))}.bind(this)).fail(function(t,e,i){this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.CheckoutGateway=function(){this.message_container="li.payment_method_"+this.gateway_id,this.banner_container="li.banner_payment_method_"+this.gateway_id,e(document.body).on("update_checkout",this.update_checkout.bind(this)),e(document.body).on("updated_checkout",this.updated_checkout.bind(this)),e(document.body).on("checkout_error",this.checkout_error.bind(this)),e(this.token_selector).closest("form").on("checkout_place_order_"+this.gateway_id,this.checkout_place_order.bind(this)),e(document.body).on("wc_stripe_new_method_"+this.gateway_id,this.on_show_new_methods.bind(this)),e(document.body).on("wc_stripe_saved_method_"+this.gateway_id,this.on_show_saved_methods.bind(this)),e(document.body).on("wc_stripe_payment_method_selected",this.on_payment_method_selected.bind(this)),this.banner_enabled()&&e(".woocommerce-billing-fields").length&&e(".wc-stripe-banner-checkout").css("max-width",e(".woocommerce-billing-fields").outerWidth(!0)),this.order_review()},wc_stripe.CheckoutGateway.prototype.order_review=function(){var e=t.location.href.match(/order_review.+payment_method=([\w]+).+payment_nonce=(.+)/);if(e&&e.length>1){var i=e[1],s=e[2];this.gateway_id===i&&(this.payment_token_received=!0,this.set_nonce(s),this.set_use_new_option(!0))}},wc_stripe.CheckoutGateway.prototype.updated_checkout=function(){},wc_stripe.CheckoutGateway.prototype.update_checkout=function(){},wc_stripe.CheckoutGateway.prototype.checkout_error=function(){this.has_checkout_error()&&(this.payment_token_received=!1,this.payment_response=null,this.show_payment_button(),this.hide_place_order())},wc_stripe.CheckoutGateway.prototype.is_valid_checkout=function(){return!(e('[name="terms"]').length&&!e('[name="terms"]').is(":checked"))},wc_stripe.CheckoutGateway.prototype.get_payment_method=function(){return e('[name="payment_method"]:checked').val()},wc_stripe.CheckoutGateway.prototype.set_use_new_option=function(t){e("#"+this.gateway_id+"_use_new").prop("checked",t).trigger("change")},wc_stripe.CheckoutGateway.prototype.checkout_place_order=function(){return this.is_valid_checkout()?!!this.is_saved_method_selected()||this.payment_token_received:(this.submit_error(this.params.messages.terms),!1)},wc_stripe.CheckoutGateway.prototype.on_token_received=function(t){this.payment_token_received=!0,this.set_nonce(t.id),this.hide_payment_button(),this.show_place_order()},wc_stripe.CheckoutGateway.prototype.block=function(){e("form.checkout").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.CheckoutGateway.prototype.unblock=function(){e("form.checkout").unblock()},wc_stripe.CheckoutGateway.prototype.hide_place_order=function(){e("#place_order").addClass("wc-stripe-hide")},wc_stripe.CheckoutGateway.prototype.show_place_order=function(){e("#place_order").removeClass("wc-stripe-hide")},wc_stripe.CheckoutGateway.prototype.on_show_new_methods=function(){this.payment_token_received?(this.show_place_order(),this.hide_payment_button()):(this.hide_place_order(),this.show_payment_button())},wc_stripe.CheckoutGateway.prototype.on_show_saved_methods=function(){this.hide_payment_button(),this.show_place_order()},wc_stripe.CheckoutGateway.prototype.show_payment_button=function(){this.$button&&this.$button.show()},wc_stripe.CheckoutGateway.prototype.hide_payment_button=function(){this.$button&&this.$button.hide()},wc_stripe.CheckoutGateway.prototype.trigger_payment_method_selected=function(){this.on_payment_method_selected(null,e('[name="payment_method"]:checked').val())},wc_stripe.CheckoutGateway.prototype.on_payment_method_selected=function(t,e){e===this.gateway_id?this.payment_token_received||this.is_saved_method_selected()?(this.hide_payment_button(),this.show_place_order()):(this.show_payment_button(),this.hide_place_order()):(this.hide_payment_button(),e.indexOf("stripe_")<0&&this.show_place_order())},wc_stripe.CheckoutGateway.prototype.banner_enabled=function(){return"1"===this.params.banner_enabled},wc_stripe.CheckoutGateway.prototype.checkout_fields_valid=function(){if("undefined"==typeof wc_stripe_checkout_fields||"checkout"!==this.get_page())return!0;function t(t,i){for(var s in i){var a=i[s];if(s.indexOf(t)>-1&&a.required&&e("#"+s).length){var n=e("#"+s).val();if(void 0===n||0==n.length)return void(valid=!1)}}}return valid=!0,t("billing",wc_stripe_checkout_fields),this.needs_shipping()&&e("#ship-to-different-address-checkbox").is(":checked")&&t("shipping",wc_stripe_checkout_fields),valid&&(valid=this.is_valid_checkout()),valid},wc_stripe.ProductGateway=function(){this.message_container="div.product",e("form.cart").on("found_variation",this.found_variation.bind(this)),e("form.cart").on("reset_data",this.reset_variation_data.bind(this)),this.buttonWidth=e("div.quantity").outerWidth(!0)+e(".single_add_to_cart_button").outerWidth();var t=e(".single_add_to_cart_button").css("marginLeft");t&&(this.buttonWidth+=parseInt(t.replace("px",""))),e(this.container).css("max-width",this.buttonWidth+"px")},wc_stripe.ProductGateway.prototype.get_quantity=function(){return parseInt(e('[name="quantity"]').val())},wc_stripe.ProductGateway.prototype.set_rest_nonce=function(t,e){this.params.rest_nonce=e},wc_stripe.ProductGateway.prototype.found_variation=function(t,e){var i=this.get_gateway_data();i.product.price=e.display_price,i.needs_shipping=!e.is_virtual,i.product.variation=e,this.set_gateway_data(i),this.enable_payment_button()},wc_stripe.ProductGateway.prototype.reset_variation_data=function(){var t=this.get_product_data();t.variation=!1,this.set_product_data(t),this.disable_payment_button()},wc_stripe.ProductGateway.prototype.disable_payment_button=function(){this.$button&&this.get_button().prop("disabled",!0).addClass("disabled")},wc_stripe.ProductGateway.prototype.enable_payment_button=function(){this.$button&&this.get_button().prop("disabled",!1).removeClass("disabled")},wc_stripe.ProductGateway.prototype.get_button=function(){return this.$button},wc_stripe.ProductGateway.prototype.is_variable_product=function(){return e('[name="variation_id"]').length>0},wc_stripe.ProductGateway.prototype.variable_product_selected=function(){return!1!==this.get_product_data().variation},wc_stripe.ProductGateway.prototype.get_product_data=function(){return this.get_gateway_data().product},wc_stripe.ProductGateway.prototype.set_product_data=function(t){var e=this.get_gateway_data();e.product=t,this.set_gateway_data(e)},wc_stripe.ProductGateway.prototype.add_to_cart=function(){return new Promise(function(t,i){this.block(),e.ajax({url:this.params.routes.add_to_cart,method:"POST",dataType:"json",data:{product_id:this.get_product_data().id,variation_id:this.is_variable_product()?e('[name="variation_id"]').val():0,qty:e('[name="quantity"]').val(),payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)}).done(function(e,s,a){this.unblock(),e.code?(this.submit_error(e.message),i(e)):(this.set_total_price(e.data.total),this.set_total_price_cents(e.data.totalCents),this.set_display_items(e.data.displayItems),t(e.data))}.bind(this)).fail(function(t,e,i){this.unblock(),this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.ProductGateway.prototype.cart_calculation=function(t){return new Promise(function(i,s){e.ajax({url:this.params.routes.cart_calculation,method:"POST",dataType:"json",data:{product_id:this.get_product_data().id,variation_id:this.is_variable_product()&&t?t:0,qty:e('[name="quantity"]').val(),payment_method:this.gateway_id},beforeSend:this.ajax_before_send.bind(this)}).done(function(t,e,a){t.code?(this.cart_calculation_error=!0,s(t)):(this.set_total_price(t.data.total),this.set_total_price_cents(t.data.totalCents),this.set_display_items(t.data.displayItems),i(t.data))}.bind(this)).fail(function(t,e,i){}.bind(this))}.bind(this))},wc_stripe.CartGateway=function(){this.message_container="div.woocommerce",e(document.body).on("updated_wc_div",this.updated_html.bind(this)),e(document.body).on("updated_cart_totals",this.updated_html.bind(this)),e(document.body).on("wc_cart_emptied",this.cart_emptied.bind(this))},wc_stripe.CartGateway.prototype.submit_error=function(t){this.submit_message(this.get_error_message(t))},wc_stripe.CartGateway.prototype.updated_html=function(t){},wc_stripe.CartGateway.prototype.cart_emptied=function(t){},wc_stripe.CartGateway.prototype.add_cart_totals_class=function(){e(".cart_totals").addClass("stripe_cart_gateway_active")},wc_stripe.GooglePay=function(){};const s={apiVersion:2,apiVersionMinor:0},a={type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY"],allowedCardNetworks:["AMEX","DISCOVER","INTERAC","JCB","MASTERCARD","VISA"]}};wc_stripe.GooglePay.prototype.populate_address_fields=function(t){var i=t.paymentMethodData.info.billingAddress;for(var s in i)this.mappings.set(s,i[s],"billing");if(t.shippingAddress)for(var s in t.shippingAddress)this.mappings.set(s,t.shippingAddress[s],"shipping");t.email&&this.mappings.set("email",t.email,"billing"),"checkout"===this.get_page()&&(this.maybe_set_ship_to_different(),this.mappings.toFormFields(),e('[name="billing_country"]').trigger("change"))},wc_stripe.GooglePay.prototype.map_address=function(t){return{city:t.locality,postcode:t.postalCode,state:t.administrativeArea,country:t.countryCode}},wc_stripe.GooglePay.prototype.update_payment_data=function(t){return new Promise(function(i,s){var a="default"==t.shippingOptionData.id?null:t.shippingOptionData.id;e.when(e.ajax({url:this.params.routes.payment_data,dataType:"json",method:"POST",data:{shipping_address:this.map_address(t.shippingAddress),shipping_method:a,page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)})).done(function(t){t.code?s(t.data.data):i(t.data)}.bind(this)).fail(function(){s()}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.on_payment_data_changed=function(t){return new Promise(function(e,i){this.update_payment_data(t).then(function(i){e(i.paymentRequestUpdate),this.set_selected_shipping_methods(i.shipping_methods),this.payment_data_updated(i,t)}.bind(this)).catch(function(t){e(t)}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.payment_data_updated=function(t){},wc_stripe.GooglePay.prototype.get_merchant_info=function(){var t={merchantId:this.params.merchant_id,merchantName:this.params.merchant_name};return"TEST"===this.params.environment&&delete t.merchantId,t},wc_stripe.GooglePay.prototype.get_payment_options=function(){var t={environment:this.params.environment,merchantInfo:this.get_merchant_info()};return this.needs_shipping()&&this.get_total_price_cents()>0?t.paymentDataCallbacks={onPaymentDataChanged:this.on_payment_data_changed.bind(this),onPaymentAuthorized:function(t){return new Promise(function(t,e){t({transactionState:"SUCCESS"})}.bind(this))}.bind(this)}:t.paymentDataCallbacks={onPaymentAuthorized:function(t){return new Promise(function(t,e){t({transactionState:"SUCCESS"})}.bind(this))}},t},wc_stripe.GooglePay.prototype.build_payment_request=function(){var t=e.extend({},s,{emailRequired:this.mappings.required("billing_email"),merchantInfo:this.get_merchant_info(),allowedPaymentMethods:[e.extend({type:"CARD",tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:"stripe","stripe:version":"2018-10-31","stripe:publishableKey":this.params.api_key}}},a)],shippingAddressRequired:this.needs_shipping()&&this.get_total_price_cents()>0,transactionInfo:{currencyCode:this.get_currency(),totalPriceStatus:"ESTIMATED",totalPrice:this.get_total_price().toString(),displayItems:this.get_display_items(),totalPriceLabel:this.params.total_price_label}});return t.allowedPaymentMethods[0].parameters.billingAddressRequired=!0,t.allowedPaymentMethods[0].parameters.billingAddressParameters={format:"FULL",phoneNumberRequired:this.mappings.required("billing_phone")},this.needs_shipping()&&this.get_total_price_cents()>0?(t.shippingAddressParameters={},t.shippingOptionRequired=!0,t.shippingOptionParameters={shippingOptions:this.get_shipping_options()},t.callbackIntents=["SHIPPING_ADDRESS","SHIPPING_OPTION","PAYMENT_AUTHORIZATION"]):t.callbackIntents=["PAYMENT_AUTHORIZATION"],t},wc_stripe.GooglePay.prototype.createPaymentsClient=function(){this.paymentsClient=new google.payments.api.PaymentsClient(this.get_payment_options())},wc_stripe.GooglePay.prototype.isReadyToPay=function(){return new Promise(function(t){var i=e.extend({},s);i.allowedPaymentMethods=[a],this.paymentsClient.isReadyToPay(i).then(function(){this.can_pay=!0,this.create_button(),t()}.bind(this)).catch(function(t){this.submit_error(t)}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.create_button=function(){this.$button&&this.$button.remove(),this.$button=e(this.paymentsClient.createButton({onClick:this.start.bind(this),buttonColor:this.params.button_color,buttonType:this.params.button_style})),this.$button.addClass("gpay-button-container")},wc_stripe.GooglePay.prototype.start=function(){this.createPaymentsClient(),this.paymentsClient.loadPaymentData(this.build_payment_request()).then(function(t){var e=JSON.parse(t.paymentMethodData.tokenizationData.token);this.populate_address_fields(t),this.on_token_received(e)}.bind(this)).catch(function(t){"CANCELED"!==t.statusCode&&(t.statusMessage&&t.statusMessage.indexOf("paymentDataRequest.callbackIntent")>-1?this.submit_error_code("DEVELOPER_ERROR_WHITELIST"):this.submit_error(t.statusMessage))}.bind(this))},wc_stripe.ApplePay=function(){},wc_stripe.ApplePay.prototype.initialize=function(){var t=".apple-pay-button";["checkout","order_pay"].indexOf(this.get_page())<0&&(t=this.container+" .apple-pay-button"),e(document.body).on("click",t,this.start.bind(this)),this.createPaymentRequest(),this.canMakePayment()},wc_stripe.ApplePay.prototype.create_button=function(){this.$button&&this.$button.remove(),this.$button=e(this.params.button),this.append_button()},wc_stripe.ApplePay.prototype.canMakePayment=function(){return new Promise(function(t,i){this.paymentRequest.canMakePayment().then(function(i){i&&i.applePay&&(this.can_pay=!0,this.create_button(),e(this.container).show(),t(i))}.bind(this))}.bind(this))},wc_stripe.ApplePay.prototype.start=function(t){t.preventDefault(),this.paymentRequest.update(this.get_payment_request_update({total:{pending:!1}})),this.paymentRequest.show()},wc_stripe.PaymentRequest=function(){},wc_stripe.PaymentRequest.prototype.initialize=function(){this.createPaymentRequest(),this.canMakePayment(),this.paymentRequestButton=this.createPaymentRequestButton(),this.paymentRequestButton.on("click",this.button_click.bind(this))},wc_stripe.PaymentRequest.prototype.button_click=function(t){},wc_stripe.PaymentRequest.prototype.createPaymentRequestButton=function(){return this.elements.create("paymentRequestButton",{paymentRequest:this.paymentRequest,style:{paymentRequestButton:{type:this.params.button.type,theme:this.params.button.theme,height:this.params.button.height}}})},wc_stripe.PaymentRequest.prototype.canMakePayment=function(){return new Promise(function(t,i){this.paymentRequest.canMakePayment().then(function(i){i&&!i.applePay&&(this.can_pay=!0,this.create_button(),e(this.container).show(),t(i))}.bind(this))}.bind(this))},wc_stripe.PaymentRequest.prototype.create_button=function(){this.paymentRequestButton.mount("#wc-stripe-payment-request-container")},wc_stripe.CheckoutFields=function(t){this.params=t,this.fields=new Map(Object.keys(this.params).map(function(t){return[t,this.params[t].value]}.bind(this)))},wc_stripe.CheckoutFields.prototype.set=function(t,e,i){this[t]&&"function"==typeof this[t]?this[t]().set.call(this,e,i):this.fields.set(t,e)},wc_stripe.CheckoutFields.prototype.get=function(t,e){return this[t]&&"function"==typeof this[t]?this[t]().get.call(this,e):this.fields.get(t)},wc_stripe.CheckoutFields.prototype.required=function(t){return this.params[t]&&this.params[t].required},wc_stripe.CheckoutFields.prototype.name=function(){return{set:function(t,e){var i=t.split(" ");this.fields.set(e+"_first_name",i[0]),this.fields.set(e+"_last_name",i[1])},get:function(t){return this.fields.get(t+"_first_name")+" "+this.fields.get(t+"_last_name")}}},wc_stripe.CheckoutFields.prototype.payerName=function(){return wc_stripe.CheckoutFields.prototype.name.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.email=function(){return{set:function(t,e){this.fields.set(e+"_email",t)},get:function(t){return this.fields.get(t+"_email")}}},wc_stripe.CheckoutFields.prototype.payerEmail=function(){return wc_stripe.CheckoutFields.prototype.email.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.phone=function(){return{set:function(t,e){this.fields.set(e+"_phone",t)},get:function(t){return this.fields.get(t+"_phone")}}},wc_stripe.CheckoutFields.prototype.payerPhone=function(){return wc_stripe.CheckoutFields.prototype.phone.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.phoneNumber=function(){return wc_stripe.CheckoutFields.prototype.phone.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.recipient=function(){return{set:function(t,e){var i=t.split(" ");i.length>0&&this.fields.set(e+"_first_name",i[0]),i.length>1&&this.fields.set(e+"_last_name",i[1])},get:function(t){return this.fields.get(t+"_first_name")+" "+this.fields.get(t+"_last_name")}}},wc_stripe.CheckoutFields.prototype.country=function(){return{set:function(t,e){this.fields.set(e+"_country",t)},get:function(t){return this.fields.get(t+"_country")}}},wc_stripe.CheckoutFields.prototype.countryCode=function(){return wc_stripe.CheckoutFields.prototype.country.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.address1=function(){return{set:function(t,e){this.fields.set(e+"_address_1",t)},get:function(t){return this.fields.get(t+"_address_1")}}},wc_stripe.CheckoutFields.prototype.address2=function(){return{set:function(t,e){this.fields.set(e+"_address_2",t)},get:function(t){this.fields.get(t+"_address_2")}}},wc_stripe.CheckoutFields.prototype.line1=function(){return wc_stripe.CheckoutFields.prototype.address1.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.line2=function(){return wc_stripe.CheckoutFields.prototype.address2.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.addressLine=function(){return{set:function(t,e){t.length>0&&this.fields.set(e+"_address_1",t[0]),t.length>1&&this.fields.set(e+"_address_2",t[1])},get:function(t){return[this.fields.get(t+"_address_1"),this.fields.get(t+"_address_2")]}}},wc_stripe.CheckoutFields.prototype.state=function(){return{set:function(t,e){this.fields.set(e+"_state",t)},get:function(t){return this.fields.get(t+"_state")}}},wc_stripe.CheckoutFields.prototype.region=function(){return wc_stripe.CheckoutFields.prototype.state.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.administrativeArea=function(){return wc_stripe.CheckoutFields.prototype.state.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.city=function(){return{set:function(t,e){this.fields.set(e+"_city",t)},get:function(t){this.fields.get(t+"_city")}}},wc_stripe.CheckoutFields.prototype.locality=function(){return wc_stripe.CheckoutFields.prototype.city.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.postal_code=function(){return{set:function(t,e){this.fields.set(e+"_postcode",t)},get:function(t){this.fields.get(t+"_postcode")}}},wc_stripe.CheckoutFields.prototype.postalCode=function(){return wc_stripe.CheckoutFields.prototype.postal_code.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.toJson=function(){var t={};return this.fields.forEach(function(e,i){t[i]=e}),t},wc_stripe.CheckoutFields.prototype.toFormFields=function(){this.fields.forEach(function(t,i){e(i='[name="'+i+'"]').length&&""!==t&&e(i).val(t)})};try{i=Stripe(wc_stripe_params_v3.api_key,{stripeAccount:wc_stripe_params_v3.account})}catch(e){return t.alert(e),void console.log(e)}}(window,jQuery);
includes/class-stripe.php CHANGED
@@ -25,7 +25,7 @@ class WC_Stripe_Manager {
25
  *
26
  * @var string
27
  */
28
- public $version = '3.1.8';
29
 
30
  /**
31
  *
@@ -235,7 +235,10 @@ class WC_Stripe_Manager {
235
 
236
  $api_class = apply_filters( 'wc_stripe_rest_api_class', 'WC_Stripe_Rest_API' );
237
  $this->rest_api = new $api_class();
238
- $this->scripts = new WC_Stripe_Frontend_Scripts();
 
 
 
239
 
240
  // allow other plugins to provide their own settings classes.
241
  $setting_classes = apply_filters( 'wc_stripe_setting_classes', array(
@@ -284,6 +287,10 @@ class WC_Stripe_Manager {
284
  * @return WC_Stripe_Frontend_Scripts
285
  */
286
  public function scripts() {
 
 
 
 
287
  return $this->scripts;
288
  }
289
 
@@ -302,6 +309,24 @@ class WC_Stripe_Manager {
302
  }
303
  }
304
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  }
306
 
307
  /**
25
  *
26
  * @var string
27
  */
28
+ public $version = '3.1.9';
29
 
30
  /**
31
  *
235
 
236
  $api_class = apply_filters( 'wc_stripe_rest_api_class', 'WC_Stripe_Rest_API' );
237
  $this->rest_api = new $api_class();
238
+
239
+ if ( $this->is_request( 'frontend' ) ) {
240
+ $this->scripts = new WC_Stripe_Frontend_Scripts();
241
+ }
242
 
243
  // allow other plugins to provide their own settings classes.
244
  $setting_classes = apply_filters( 'wc_stripe_setting_classes', array(
287
  * @return WC_Stripe_Frontend_Scripts
288
  */
289
  public function scripts() {
290
+ if ( is_null( $this->scripts ) ) {
291
+ $this->scripts = new WC_Stripe_Frontend_Scripts();
292
+ }
293
+
294
  return $this->scripts;
295
  }
296
 
309
  }
310
  }
311
  }
312
+
313
+ /**
314
+ * @param string $type
315
+ *
316
+ * @return bool
317
+ * @since 3.1.9
318
+ */
319
+ public function is_request( $type ) {
320
+ if ( ! did_action( 'before_woocommerce_init' ) ) {
321
+ return false;
322
+ }
323
+ switch ( $type ) {
324
+ case 'frontend':
325
+ return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) && ! WC()->is_rest_api_request();
326
+ default:
327
+ return true;
328
+ }
329
+ }
330
  }
331
 
332
  /**
includes/class-wc-stripe-frontend-scripts.php CHANGED
@@ -17,6 +17,8 @@ class WC_Stripe_Frontend_Scripts {
17
 
18
  public $localized_scripts = array();
19
 
 
 
20
  public $global_scripts = array(
21
  'external' => 'https://js.stripe.com/v3/',
22
  'gpay' => 'https://pay.google.com/gp/p/js/pay.js',
@@ -25,6 +27,8 @@ class WC_Stripe_Frontend_Scripts {
25
 
26
  public function __construct() {
27
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
 
 
28
  }
29
 
30
  /**
@@ -37,20 +41,27 @@ class WC_Stripe_Frontend_Scripts {
37
  }
38
 
39
  // register scripts that aren't part of gateways
40
- $this->register_script(
41
- 'wc-stripe',
42
- $this->assets_url( 'js/frontend/wc-stripe' . $this->get_min() . '.js' ),
43
  array(
44
  'jquery',
45
  $this->get_handle( 'external' ),
46
- 'woocommerce',
47
- )
48
- );
49
 
50
  $this->register_script( 'form-handler', $this->assets_url( 'js/frontend/form-handler.js' ), array( 'selectWoo' ) );
51
 
52
- $this->localize_script(
53
- 'wc-stripe',
 
 
 
 
 
 
 
 
 
 
54
  array(
55
  'api_key' => wc_stripe_get_publishable_key(),
56
  'account' => wc_stripe_get_account_id(),
@@ -58,9 +69,7 @@ class WC_Stripe_Frontend_Scripts {
58
  ),
59
  'wc_stripe_params_v3'
60
  );
61
-
62
- $this->localize_script(
63
- 'form-handler',
64
  array(
65
  'no_results' => __(
66
  'No matches found',
@@ -68,18 +77,12 @@ class WC_Stripe_Frontend_Scripts {
68
  ),
69
  )
70
  );
71
-
72
  $this->localize_script( 'wc-stripe', wc_stripe_get_error_messages(), 'wc_stripe_messages' );
73
-
74
  $this->localize_script( 'wc-stripe', wc_stripe_get_checkout_fields(), 'wc_stripe_checkout_fields' );
75
 
76
- // mini cart is not relevant on cart and checkout page.
77
- if ( ! is_checkout() && ! is_cart() ) {
78
- foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
79
- if ( $gateway instanceof WC_Payment_Gateway_Stripe && $gateway->is_available() && $gateway->mini_cart_enabled() ) {
80
- $gateway->enqueue_frontend_scripts( 'mini_cart' );
81
- }
82
- }
83
  }
84
  }
85
 
@@ -134,10 +137,13 @@ class WC_Stripe_Frontend_Scripts {
134
  if ( ! $object_name ) {
135
  $object_name = str_replace( '-', '_', $handle ) . '_params';
136
  }
137
- $data = apply_filters( 'wc_stripe_localize_script_' . $name, $data, $object_name );
138
- if ( $data ) {
139
- $this->localized_scripts[] = $handle;
140
- wp_localize_script( $handle, $object_name, $data );
 
 
 
141
  }
142
  }
143
  }
17
 
18
  public $localized_scripts = array();
19
 
20
+ public $localized_data = array();
21
+
22
  public $global_scripts = array(
23
  'external' => 'https://js.stripe.com/v3/',
24
  'gpay' => 'https://pay.google.com/gp/p/js/pay.js',
27
 
28
  public function __construct() {
29
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
30
+ add_action( 'wp_print_scripts', array( $this, 'localize_scripts' ), 5 );
31
+ add_action( 'wp_print_footer_scripts', array( $this, 'localize_scripts' ), 5 );
32
  }
33
 
34
  /**
41
  }
42
 
43
  // register scripts that aren't part of gateways
44
+ $this->register_script( 'wc-stripe', $this->assets_url( 'js/frontend/wc-stripe' . $this->get_min() . '.js' ),
 
 
45
  array(
46
  'jquery',
47
  $this->get_handle( 'external' ),
48
+ 'woocommerce'
49
+ ) );
 
50
 
51
  $this->register_script( 'form-handler', $this->assets_url( 'js/frontend/form-handler.js' ), array( 'selectWoo' ) );
52
 
53
+ // mini cart is not relevant on cart and checkout page.
54
+ if ( ! is_checkout() && ! is_cart() ) {
55
+ foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
56
+ if ( $gateway instanceof WC_Payment_Gateway_Stripe && $gateway->is_available() && $gateway->mini_cart_enabled() ) {
57
+ $gateway->enqueue_frontend_scripts( 'mini_cart' );
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ public function localize_scripts() {
64
+ $this->localize_script( 'wc-stripe',
65
  array(
66
  'api_key' => wc_stripe_get_publishable_key(),
67
  'account' => wc_stripe_get_account_id(),
69
  ),
70
  'wc_stripe_params_v3'
71
  );
72
+ $this->localize_script( 'form-handler',
 
 
73
  array(
74
  'no_results' => __(
75
  'No matches found',
77
  ),
78
  )
79
  );
 
80
  $this->localize_script( 'wc-stripe', wc_stripe_get_error_messages(), 'wc_stripe_messages' );
 
81
  $this->localize_script( 'wc-stripe', wc_stripe_get_checkout_fields(), 'wc_stripe_checkout_fields' );
82
 
83
+ // don't need to call localize_scripts twice.
84
+ if ( doing_action( 'wp_print_scripts' ) ) {
85
+ remove_action( 'wp_print_footer_scripts', array( $this, 'localize_scripts' ), 5 );
 
 
 
 
86
  }
87
  }
88
 
137
  if ( ! $object_name ) {
138
  $object_name = str_replace( '-', '_', $handle ) . '_params';
139
  }
140
+ if ( ! in_array( $object_name, $this->localized_data ) ) {
141
+ $data = apply_filters( 'wc_stripe_localize_script_' . $name, $data, $object_name );
142
+ if ( $data ) {
143
+ $this->localized_scripts[] = $handle;
144
+ $this->localized_data[] = $object_name;
145
+ wp_localize_script( $handle, $object_name, $data );
146
+ }
147
  }
148
  }
149
  }
includes/controllers/class-wc-stripe-controller-cart.php CHANGED
@@ -20,21 +20,23 @@ class WC_Stripe_Controller_Cart extends WC_Stripe_Rest_Controller {
20
  $this->rest_uri(),
21
  'shipping-method',
22
  array(
23
- 'methods' => WP_REST_Server::CREATABLE,
24
- 'callback' => array( $this, 'update_shipping_method' ),
25
- 'args' => array(
 
26
  'shipping_method' => array( 'required' => true ),
27
  'payment_method' => array( 'required' => true ),
28
- ),
29
  )
30
  );
31
  register_rest_route(
32
  $this->rest_uri(),
33
  'shipping-address',
34
  array(
35
- 'methods' => WP_REST_Server::CREATABLE,
36
- 'callback' => array( $this, 'update_shipping_address' ),
37
- 'args' => array(
 
38
  'address' => array( 'required' => true ),
39
  'payment_method' => array( 'required' => true ),
40
  ),
@@ -44,9 +46,10 @@ class WC_Stripe_Controller_Cart extends WC_Stripe_Rest_Controller {
44
  $this->rest_uri(),
45
  'add-to-cart',
46
  array(
47
- 'methods' => WP_REST_Server::CREATABLE,
48
- 'callback' => array( $this, 'add_to_cart' ),
49
- 'args' => array(
 
50
  'product_id' => array( 'required' => true ),
51
  'qty' => array(
52
  'required' => true,
@@ -64,9 +67,10 @@ class WC_Stripe_Controller_Cart extends WC_Stripe_Rest_Controller {
64
  $this->rest_uri(),
65
  'cart-calculation',
66
  array(
67
- 'methods' => WP_REST_Server::CREATABLE,
68
- 'callback' => array( $this, 'cart_calculation' ),
69
- 'args' => array(
 
70
  'product_id' => array( 'required' => true ),
71
  'qty' => array(
72
  'required' => true,
20
  $this->rest_uri(),
21
  'shipping-method',
22
  array(
23
+ 'methods' => WP_REST_Server::CREATABLE,
24
+ 'callback' => array( $this, 'update_shipping_method' ),
25
+ 'permission_callback' => '__return_true',
26
+ 'args' => array(
27
  'shipping_method' => array( 'required' => true ),
28
  'payment_method' => array( 'required' => true ),
29
+ )
30
  )
31
  );
32
  register_rest_route(
33
  $this->rest_uri(),
34
  'shipping-address',
35
  array(
36
+ 'methods' => WP_REST_Server::CREATABLE,
37
+ 'callback' => array( $this, 'update_shipping_address' ),
38
+ 'permission_callback' => '__return_true',
39
+ 'args' => array(
40
  'address' => array( 'required' => true ),
41
  'payment_method' => array( 'required' => true ),
42
  ),
46
  $this->rest_uri(),
47
  'add-to-cart',
48
  array(
49
+ 'methods' => WP_REST_Server::CREATABLE,
50
+ 'callback' => array( $this, 'add_to_cart' ),
51
+ 'permission_callback' => '__return_true',
52
+ 'args' => array(
53
  'product_id' => array( 'required' => true ),
54
  'qty' => array(
55
  'required' => true,
67
  $this->rest_uri(),
68
  'cart-calculation',
69
  array(
70
+ 'methods' => WP_REST_Server::CREATABLE,
71
+ 'callback' => array( $this, 'cart_calculation' ),
72
+ 'permission_callback' => '__return_true',
73
+ 'args' => array(
74
  'product_id' => array( 'required' => true ),
75
  'qty' => array(
76
  'required' => true,
includes/controllers/class-wc-stripe-controller-checkout.php CHANGED
@@ -30,30 +30,27 @@ class WC_Stripe_Controller_Checkout extends WC_Stripe_Rest_Controller {
30
  $this->rest_uri(),
31
  'checkout',
32
  array(
33
- 'methods' => WP_REST_Server::CREATABLE,
34
- 'callback' => array(
35
- $this,
36
- 'process_checkout',
37
- ),
38
  )
39
  );
40
  register_rest_route(
41
  $this->rest_uri(),
42
  'order-pay',
43
  array(
44
- 'methods' => WP_REST_Server::CREATABLE,
45
- 'callback' => array(
46
- $this,
47
- 'process_order_pay',
48
- ),
49
  )
50
  );
51
  register_rest_route(
52
  $this->rest_uri(),
53
  'source',
54
  array(
55
- 'methods' => WP_REST_Server::DELETABLE,
56
- 'callback' => array( $this, 'delete_source' ),
 
57
  )
58
  );
59
  }
30
  $this->rest_uri(),
31
  'checkout',
32
  array(
33
+ 'methods' => WP_REST_Server::CREATABLE,
34
+ 'callback' => array( $this, 'process_checkout' ),
35
+ 'permission_callback' => '__return_true',
 
 
36
  )
37
  );
38
  register_rest_route(
39
  $this->rest_uri(),
40
  'order-pay',
41
  array(
42
+ 'methods' => WP_REST_Server::CREATABLE,
43
+ 'callback' => array( $this, 'process_order_pay' ),
44
+ 'permission_callback' => '__return_true',
 
 
45
  )
46
  );
47
  register_rest_route(
48
  $this->rest_uri(),
49
  'source',
50
  array(
51
+ 'methods' => WP_REST_Server::DELETABLE,
52
+ 'callback' => array( $this, 'delete_source' ),
53
+ 'permission_callback' => '__return_true',
54
  )
55
  );
56
  }
includes/controllers/class-wc-stripe-controller-gateway-settings.php CHANGED
@@ -18,10 +18,7 @@ class WC_Stripe_Controller_Gateway_Settings extends WC_Stripe_Rest_Controller {
18
  array(
19
  'methods' => WP_REST_Server::CREATABLE,
20
  'callback' => array( $this, 'register_apple_domain' ),
21
- 'permission_callback' => array(
22
- $this,
23
- 'admin_permission_check',
24
- ),
25
  )
26
  );
27
  register_rest_route(
@@ -30,10 +27,7 @@ class WC_Stripe_Controller_Gateway_Settings extends WC_Stripe_Rest_Controller {
30
  array(
31
  'methods' => WP_REST_Server::CREATABLE,
32
  'callback' => array( $this, 'create_webhook' ),
33
- 'permission_callback' => array(
34
- $this,
35
- 'admin_permission_check',
36
- ),
37
  )
38
  );
39
  register_rest_route(
@@ -42,10 +36,7 @@ class WC_Stripe_Controller_Gateway_Settings extends WC_Stripe_Rest_Controller {
42
  array(
43
  'methods' => WP_REST_Server::CREATABLE,
44
  'callback' => array( $this, 'connection_test' ),
45
- 'permission_callback' => array(
46
- $this,
47
- 'admin_permission_check',
48
- ),
49
  )
50
  );
51
  }
18
  array(
19
  'methods' => WP_REST_Server::CREATABLE,
20
  'callback' => array( $this, 'register_apple_domain' ),
21
+ 'permission_callback' => array( $this, 'admin_permission_check' )
 
 
 
22
  )
23
  );
24
  register_rest_route(
27
  array(
28
  'methods' => WP_REST_Server::CREATABLE,
29
  'callback' => array( $this, 'create_webhook' ),
30
+ 'permission_callback' => array( $this, 'admin_permission_check' )
 
 
 
31
  )
32
  );
33
  register_rest_route(
36
  array(
37
  'methods' => WP_REST_Server::CREATABLE,
38
  'callback' => array( $this, 'connection_test' ),
39
+ 'permission_callback' => array( $this, 'admin_permission_check' )
 
 
 
40
  )
41
  );
42
  }
includes/controllers/class-wc-stripe-controller-googlepay.php CHANGED
@@ -40,9 +40,10 @@ class WC_Stripe_Controller_GooglePay extends WC_Stripe_Rest_Controller {
40
  $this->rest_uri(),
41
  'shipping-data',
42
  array(
43
- 'methods' => WP_REST_Server::CREATABLE,
44
- 'callback' => array( $this, 'update_shipping_data' ),
45
- 'args' => array(
 
46
  'shipping_address' => array( 'required' => true ),
47
  'shipping_method' => array( 'required' => false )
48
  ),
40
  $this->rest_uri(),
41
  'shipping-data',
42
  array(
43
+ 'methods' => WP_REST_Server::CREATABLE,
44
+ 'callback' => array( $this, 'update_shipping_data' ),
45
+ 'permission_callback' => '__return_true',
46
+ 'args' => array(
47
  'shipping_address' => array( 'required' => true ),
48
  'shipping_method' => array( 'required' => false )
49
  ),
includes/controllers/class-wc-stripe-controller-payment-intent.php CHANGED
@@ -17,8 +17,9 @@ class WC_Stripe_Controller_Payment_Intent extends WC_Stripe_Rest_Controller {
17
  $this->rest_uri(),
18
  'setup-intent',
19
  array(
20
- 'methods' => WP_REST_Server::READABLE,
21
- 'callback' => array(
 
22
  $this,
23
  'create_setup_intent',
24
  ),
@@ -28,9 +29,10 @@ class WC_Stripe_Controller_Payment_Intent extends WC_Stripe_Rest_Controller {
28
  $this->rest_uri(),
29
  'sync-payment-intent',
30
  array(
31
- 'methods' => WP_REST_Server::CREATABLE,
32
- 'callback' => array( $this, 'sync_payment_intent' ),
33
- 'args' => array(
 
34
  'order_id' => array( 'required' => true ),
35
  'client_secret' => array( 'required' => true ),
36
  ),
17
  $this->rest_uri(),
18
  'setup-intent',
19
  array(
20
+ 'methods' => WP_REST_Server::READABLE,
21
+ 'permission_callback' => '__return_true',
22
+ 'callback' => array(
23
  $this,
24
  'create_setup_intent',
25
  ),
29
  $this->rest_uri(),
30
  'sync-payment-intent',
31
  array(
32
+ 'methods' => WP_REST_Server::CREATABLE,
33
+ 'callback' => array( $this, 'sync_payment_intent' ),
34
+ 'permission_callback' => '__return_true',
35
+ 'args' => array(
36
  'order_id' => array( 'required' => true ),
37
  'client_secret' => array( 'required' => true ),
38
  ),
includes/controllers/class-wc-stripe-controller-payment-method.php CHANGED
@@ -17,11 +17,9 @@ class WC_Stripe_Controller_Payment_Method extends WC_Stripe_Rest_Controller {
17
  $this->rest_uri(),
18
  'token',
19
  array(
20
- 'methods' => WP_REST_Server::CREATABLE,
21
- 'callback' => array(
22
- $this,
23
- 'payment_method_from_token',
24
- ),
25
  )
26
  );
27
  }
17
  $this->rest_uri(),
18
  'token',
19
  array(
20
+ 'methods' => WP_REST_Server::CREATABLE,
21
+ 'callback' => array( $this, 'payment_method_from_token' ),
22
+ 'permission_callback' => '__return_true'
 
 
23
  )
24
  );
25
  }
includes/controllers/class-wc-stripe-controller-product-data.php CHANGED
@@ -19,10 +19,7 @@ class WC_Stripe_Controller_Product_Data extends WC_Stripe_Rest_Controller {
19
  array(
20
  'methods' => WP_REST_Server::CREATABLE,
21
  'callback' => array( $this, 'toggle_gateway' ),
22
- 'permission_callback' => array(
23
- $this,
24
- 'admin_permission_check',
25
- ),
26
  )
27
  );
28
  register_rest_route(
@@ -31,10 +28,7 @@ class WC_Stripe_Controller_Product_Data extends WC_Stripe_Rest_Controller {
31
  array(
32
  'methods' => WP_REST_Server::CREATABLE,
33
  'callback' => array( $this, 'save' ),
34
- 'permission_callback' => array(
35
- $this,
36
- 'admin_permission_check',
37
- ),
38
  )
39
  );
40
  }
@@ -50,6 +44,7 @@ class WC_Stripe_Controller_Product_Data extends WC_Stripe_Rest_Controller {
50
  $option = new WC_Stripe_Product_Gateway_Option( $product, $payment_method );
51
  $option->set_option( 'enabled', ! $option->enabled() );
52
  $option->save();
 
53
  return rest_ensure_response( array( 'enabled' => $option->enabled() ) );
54
  }
55
 
@@ -66,7 +61,7 @@ class WC_Stripe_Controller_Product_Data extends WC_Stripe_Rest_Controller {
66
  $loop = 0;
67
  foreach ( $gateways as $gateway ) {
68
  $order[ $gateway ] = $loop;
69
- $loop++;
70
  }
71
  $product->update_meta_data( WC_Stripe_Constants::PRODUCT_GATEWAY_ORDER, $order );
72
 
@@ -78,6 +73,7 @@ class WC_Stripe_Controller_Product_Data extends WC_Stripe_Rest_Controller {
78
  $product->update_meta_data( '_stripe_button_position', $request->get_param( 'position' ) );
79
 
80
  $product->save();
 
81
  return rest_ensure_response( array( 'order' => $order ) );
82
  }
83
  }
19
  array(
20
  'methods' => WP_REST_Server::CREATABLE,
21
  'callback' => array( $this, 'toggle_gateway' ),
22
+ 'permission_callback' => array( $this, 'admin_permission_check' )
 
 
 
23
  )
24
  );
25
  register_rest_route(
28
  array(
29
  'methods' => WP_REST_Server::CREATABLE,
30
  'callback' => array( $this, 'save' ),
31
+ 'permission_callback' => array( $this, 'admin_permission_check' ),
 
 
 
32
  )
33
  );
34
  }
44
  $option = new WC_Stripe_Product_Gateway_Option( $product, $payment_method );
45
  $option->set_option( 'enabled', ! $option->enabled() );
46
  $option->save();
47
+
48
  return rest_ensure_response( array( 'enabled' => $option->enabled() ) );
49
  }
50
 
61
  $loop = 0;
62
  foreach ( $gateways as $gateway ) {
63
  $order[ $gateway ] = $loop;
64
+ $loop ++;
65
  }
66
  $product->update_meta_data( WC_Stripe_Constants::PRODUCT_GATEWAY_ORDER, $order );
67
 
73
  $product->update_meta_data( '_stripe_button_position', $request->get_param( 'position' ) );
74
 
75
  $product->save();
76
+
77
  return rest_ensure_response( array( 'order' => $order ) );
78
  }
79
  }
includes/controllers/class-wc-stripe-controller-webhook.php CHANGED
@@ -18,11 +18,9 @@ class WC_Stripe_Controller_Webhook extends WC_Stripe_Rest_Controller {
18
  $this->rest_uri(),
19
  'webhook',
20
  array(
21
- 'methods' => WP_REST_Server::CREATABLE,
22
- 'callback' => array(
23
- $this,
24
- 'webhook',
25
- ),
26
  )
27
  );
28
  }
@@ -50,6 +48,7 @@ class WC_Stripe_Controller_Webhook extends WC_Stripe_Rest_Controller {
50
  return rest_ensure_response( apply_filters( 'wc_stripe_webhook_response', array(), $event, $request ) );
51
  } catch ( \Stripe\Error\SignatureVerification $e ) {
52
  wc_stripe_log_info( __( 'Invalid signature received. Verify that your webhook secret is correct.', 'woo-stripe-payment' ) );
 
53
  return $this->send_error_response( __( 'Invalid signature received. Verify that your webhook secret is correct.', 'woo-stripe-payment' ), 401 );
54
  } catch ( Exception $e ) {
55
  return $this->send_error_response( $e->getMessage() );
18
  $this->rest_uri(),
19
  'webhook',
20
  array(
21
+ 'methods' => WP_REST_Server::CREATABLE,
22
+ 'callback' => array( $this, 'webhook' ),
23
+ 'permission_callback' => '__return_true'
 
 
24
  )
25
  );
26
  }
48
  return rest_ensure_response( apply_filters( 'wc_stripe_webhook_response', array(), $event, $request ) );
49
  } catch ( \Stripe\Error\SignatureVerification $e ) {
50
  wc_stripe_log_info( __( 'Invalid signature received. Verify that your webhook secret is correct.', 'woo-stripe-payment' ) );
51
+
52
  return $this->send_error_response( __( 'Invalid signature received. Verify that your webhook secret is correct.', 'woo-stripe-payment' ), 401 );
53
  } catch ( Exception $e ) {
54
  return $this->send_error_response( $e->getMessage() );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: stripe, ach, klarna, credit card, apple pay, google pay, ideal, sepa, sofo
4
  Requires at least: 3.0.1
5
  Tested up to: 5.5
6
  Requires PHP: 5.6
7
- Stable tag: 3.1.8
8
  Copyright: Payment Plugins
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -58,6 +58,10 @@ If you're site is not loading over https, then Stripe won't render the Payment R
58
  8. Edit payment gateways on the product page
59
 
60
  == Changelog ==
 
 
 
 
61
  = 3.1.8 =
62
  * Fixed - Do not redirect to order received page if customer has not completed local payment process
63
  * Fixed - Disable Apple Pay button on variation product when no default product is selected
4
  Requires at least: 3.0.1
5
  Tested up to: 5.5
6
  Requires PHP: 5.6
7
+ Stable tag: 3.1.9
8
  Copyright: Payment Plugins
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
58
  8. Edit payment gateways on the product page
59
 
60
  == Changelog ==
61
+ = 3.1.9 =
62
+ * Fixed - WP 5.5 rest permission_callback notice
63
+ * Fixed - Conflict with SG Optimizer plugin
64
+ * Fixed - Conflict with https://wordpress.org/plugins/woocommerce-gateway-paypal-express-checkout/ button on checkout page
65
  = 3.1.8 =
66
  * Fixed - Do not redirect to order received page if customer has not completed local payment process
67
  * Fixed - Disable Apple Pay button on variation product when no default product is selected
stripe-payments.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Stripe For WooCommerce
4
  * Plugin URI: https://docs.paymentplugins.com/wc-stripe/config/
5
  * Description: Accept credit cards, Google Pay, Apple Pay, ACH, Klarna and more using Stripe.
6
- * Version: 3.1.8
7
  * Author: Payment Plugins, support@paymentplugins.com
8
  * Text Domain: woo-stripe-payment
9
  * Domain Path: /i18n/languages/
3
  * Plugin Name: Stripe For WooCommerce
4
  * Plugin URI: https://docs.paymentplugins.com/wc-stripe/config/
5
  * Description: Accept credit cards, Google Pay, Apple Pay, ACH, Klarna and more using Stripe.
6
+ * Version: 3.1.9
7
  * Author: Payment Plugins, support@paymentplugins.com
8
  * Text Domain: woo-stripe-payment
9
  * Domain Path: /i18n/languages/