Payment Plugins for Stripe WooCommerce - Version 3.2.7

Version Description

  • Added - Better support for mixed cart/checkout page using Elementor
  • Added - wc_stripe_save_order_meta action added so custom data can be added to order
  • Added - Improved support for WooCommerce Multilingual
Download this release

Release Info

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

Code changes from version 3.2.6 to 3.2.7

assets/js/frontend/ach-payments.js CHANGED
@@ -77,7 +77,7 @@
77
  $.post({
78
  url: this.params.routes.link_token,
79
  dataType: 'json',
80
- data: {wp_rest_nonce: this.params.rest_nonce}
81
  }).done(function (response) {
82
  resolve(response.token);
83
  }.bind(this)).fail(function (xhr, textStatus, errorThrown) {
77
  $.post({
78
  url: this.params.routes.link_token,
79
  dataType: 'json',
80
+ data: {_wpnonce: this.params.rest_nonce}
81
  }).done(function (response) {
82
  resolve(response.token);
83
  }.bind(this)).fail(function (xhr, textStatus, errorThrown) {
assets/js/frontend/credit-card.js CHANGED
@@ -502,7 +502,7 @@
502
  method: 'POST',
503
  url: this.params.routes.checkout_payment,
504
  dataType: 'json',
505
- data: $.extend({}, this.fields.toJson(), {'wp_rest_nonce': this.params.rest_nonce})
506
  }).done(function (result) {
507
  if (result.result && result.result === 'success') {
508
  window.location = result.redirect;
502
  method: 'POST',
503
  url: this.params.routes.checkout_payment,
504
  dataType: 'json',
505
+ data: $.extend({}, this.fields.toJson(), {'_wpnonce': this.params.rest_nonce})
506
  }).done(function (result) {
507
  if (result.result && result.result === 'success') {
508
  window.location = result.redirect;
assets/js/frontend/wc-stripe.js CHANGED
@@ -27,7 +27,11 @@
27
  };
28
 
29
  wc_stripe.BaseGateway.prototype.get_page = function () {
30
- return wc_stripe_params_v3.page;
 
 
 
 
31
  };
32
 
33
  wc_stripe.BaseGateway.prototype.set_nonce = function (value) {
@@ -1284,7 +1288,7 @@
1284
  dataType: 'json',
1285
  method: 'POST',
1286
  data: {
1287
- shipping_address: this.map_address(data.shippingAddress),
1288
  shipping_method: shipping_method,
1289
  page_id: this.get_page(),
1290
  currency: this.get_currency()
@@ -1568,7 +1572,7 @@
1568
  return [k, this.params[k].value];
1569
  }.bind(this)));
1570
 
1571
- if ('checkout' === page) {
1572
  $('form.checkout').on('change', '.input-text, select', this.onChange.bind(this));
1573
  $('form.checkout').on('change', '[name="ship_to_different_address"]', this.on_ship_to_address_change.bind(this));
1574
  this.init_i18n();
27
  };
28
 
29
  wc_stripe.BaseGateway.prototype.get_page = function () {
30
+ var page = wc_stripe_params_v3.page;
31
+ if ('cart' === page && $(document.body).is('.woocommerce-checkout')) {
32
+ page = 'checkout';
33
+ }
34
+ return page;
35
  };
36
 
37
  wc_stripe.BaseGateway.prototype.set_nonce = function (value) {
1288
  dataType: 'json',
1289
  method: 'POST',
1290
  data: {
1291
+ address: this.map_address(data.shippingAddress),
1292
  shipping_method: shipping_method,
1293
  page_id: this.get_page(),
1294
  currency: this.get_currency()
1572
  return [k, this.params[k].value];
1573
  }.bind(this)));
1574
 
1575
+ if ('checkout' === page || ('cart' === page && $(document.body).is('.woocommerce-checkout'))) {
1576
  $('form.checkout').on('change', '.input-text, select', this.onChange.bind(this));
1577
  $('form.checkout').on('change', '[name="ship_to_different_address"]', this.on_ship_to_address_change.bind(this));
1578
  this.init_i18n();
assets/js/frontend/wc-stripe.min.js CHANGED
@@ -1 +1 @@
1
- !function(i,o){i.wc_stripe={};var s=null;"undefined"==typeof wc_stripe_checkout_fields&&(i.wc_stripe_checkout_fields=[]),wc_stripe.BaseGateway=function(t,e){this.params=t,this.gateway_id=this.params.gateway_id,this.container=void 0===e?"li.payment_method_".concat(this.gateway_id):e,o(this.container).length||(this.container=".payment_method_".concat(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=s,this.elements=s.elements(o.extend({},{locale:"auto"},this.get_element_options())),this.fields=r,this.initialize()},wc_stripe.BaseGateway.prototype.get_page=function(){return wc_stripe_params_v3.page},wc_stripe.BaseGateway.prototype.set_nonce=function(t){this.fields.set(this.gateway_id+"_token_key",t),o(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 o('[name="payment_method"]:checked').val()===this.gateway_id},wc_stripe.BaseGateway.prototype.is_saved_method_selected=function(){return this.is_gateway_selected()&&"saved"===o('[name="'+this.gateway_id+'_payment_type_key"]:checked').val()},wc_stripe.BaseGateway.prototype.has_checkout_error=function(){return 0<o("#wc_stripe_checkout_error").length&&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){console.log(t)},wc_stripe.BaseGateway.prototype.get_error_message=function(t){return"object"==typeof t&&t.code&&(t=wc_stripe_messages[t.code]||t.message),t},wc_stripe.BaseGateway.prototype.submit_message=function(t){o(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove();var e=o(this.message_container);e.closest("form").length&&(e=e.closest("form")),e.prepend(t),e.removeClass("processing").unblock(),e.find(".input-text, select, input:checkbox").blur(),o.scroll_to_notices?o.scroll_to_notices(e):o("html, body").animate({scrollTop:e.offset().top-100},1e3)},wc_stripe.BaseGateway.prototype.get_first_name=function(t){return o("#"+t+"_first_name").val()},wc_stripe.BaseGateway.prototype.get_last_name=function(t){return o("#"+t+"_last_name").val()},wc_stripe.BaseGateway.prototype.get_shipping_prefix=function(){return this.needs_shipping()&&0<o('[name="ship_to_different_address"]').length&&o('[name="ship_to_different_address"]').is(":checked")?"shipping":"billing"},wc_stripe.BaseGateway.prototype.should_save_method=function(){return o("#"+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()||o(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 o(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(){var t=o(this.container).find(".woocommerce_".concat(this.gateway_id,"_gateway_data")).data("gateway");return void 0===t&&this.is_current_page("checkout")&&(t=o("form.checkout").find(".woocommerce_".concat(this.gateway_id,"_gateway_data")).data("gateway")),t},wc_stripe.BaseGateway.prototype.set_gateway_data=function(t){o(this.container).find(".woocommerce_".concat(this.gateway_id,"_gateway_data")).data("gateway",t)},wc_stripe.BaseGateway.prototype.get_customer_name=function(t){return this.fields.get(t+"_first_name")+" "+this.fields.get(t+"_last_name")},wc_stripe.BaseGateway.prototype.get_customer_email=function(){return this.fields.get("billing_email")},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.fields.get(t+e[s])+"_";return i},wc_stripe.BaseGateway.prototype.block=function(){o().block&&o.blockUI({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.BaseGateway.prototype.unblock=function(){o().block&&o.unblockUI()},wc_stripe.BaseGateway.prototype.get_form=function(){return o(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){o('[name="payment_method"][value="'+t+'"]').prop("checked",!0).trigger("click")},wc_stripe.BaseGateway.prototype.set_selected_shipping_methods=function(t){if(this.fields.set("shipping_method",t),t&&o('[name^="shipping_method"]').length)for(var e in t){var i=t[e];o('[name="shipping_method['+e+']"][value="'+i+'"]').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.payment_request_options=this.get_payment_request_options(),this.paymentRequest=s.paymentRequest(this.payment_request_options),this.payment_request_options.requestShipping&&(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))}catch(t){return void this.submit_error(t.message)}},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.fields.requestFieldInWallet("billing_email"),requestPayerPhone:this.fields.requestFieldInWallet("billing_phone"),requestShipping:function(){if(this.needs_shipping()){var t=this.get_shipping_prefix();if(this.is_current_page("checkout")&&!this.is_valid_address(this.get_address_object(t),t,["email","phone"])||!this.is_current_page("checkout"))return!0}return!1}.bind(this)()},e=this.get_display_items(),i=this.get_shipping_options();return e&&(t.displayItems=e),t.requestShipping&&i&&(t.shippingOptions=i),t},wc_stripe.BaseGateway.prototype.get_payment_request_update=function(t){var e={currency:this.get_currency().toLowerCase(),total:{amount:parseInt(this.get_total_price_cents()),label:this.params.total_label,pending:!0}},i=this.get_display_items(),s=this.get_shipping_options();return i&&(e.displayItems=i),this.payment_request_options.requestShipping&&s&&(e.shippingOptions=s),t&&(e=o.extend(!0,{},e,t)),e},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(t){try{this.payment_response=t,this.populate_checkout_fields(t),t.complete("success"),this.on_token_received(t.paymentMethod)}catch(e){i.alert(e)}},wc_stripe.BaseGateway.prototype.populate_checkout_fields=function(t){this.set_nonce(t.paymentMethod.id),this.update_addresses(t)},wc_stripe.BaseGateway.prototype.update_addresses=function(t){t.payerName&&this.fields.set("name",t.payerName,"billing"),t.payerEmail&&this.fields.set("email",t.payerEmail,"billing"),t.payerPhone&&this.fields.set("phone",t.payerPhone,"billing"),t.shippingAddress&&this.populate_shipping_fields(t.shippingAddress),t.paymentMethod.billing_details.address&&this.populate_billing_fields(t.paymentMethod.billing_details.address)},wc_stripe.BaseGateway.prototype.populate_address_fields=function(t,e){for(var i in t)null!==t[i]&&this.fields.set(i,t[i],e)},wc_stripe.BaseGateway.prototype.populate_billing_fields=function(t){this.populate_address_fields(t,"billing")},wc_stripe.BaseGateway.prototype.populate_shipping_fields=function(t){this.populate_address_fields(t,"shipping")},wc_stripe.BaseGateway.prototype.get_address_fields=function(){return["first_name","last_name","country","address_1","address_2","city","state","postcode","phone","email"]},wc_stripe.BaseGateway.prototype.get_address_object=function(e){var i={};return this.get_address_fields().forEach(function(t){i[t]=this.fields.get(t,e)}.bind(this)),i},wc_stripe.BaseGateway.prototype.is_current_page=function(t){return this.get_page()===t},wc_stripe.BaseGateway.prototype.is_valid_address=function(t,e,i){if(o.isEmptyObject(t))return!1;var s=this.get_address_fields();void 0!==i&&i.forEach(function(t){-1<s.indexOf(t)&&s.splice(s.indexOf(t),1)});for(var a=0;a<s.length;a++){var n=s[a];if(this.fields.required(e+"_"+n)&&(!t[n]||"undefined"==typeof t[n]||!this.fields.isValid(n,t[n],t)))return!1}return!0},wc_stripe.BaseGateway.prototype.ajax_before_send=function(t){0<this.params.user_id&&t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)},wc_stripe.BaseGateway.prototype.process_checkout=function(){return new Promise(function(){this.block(),o.ajax({url:this.params.routes.checkout,method:"POST",dataType:"json",data:o.extend({},this.serialize_fields(),{payment_method:this.gateway_id,page_id:this.get_page(),currency:this.get_currency()}),beforeSend:this.ajax_before_send.bind(this)}).done(function(t){t.reload?i.location.reload():"success"===t.result?i.location=t.redirect:(t.messages&&this.submit_error(t.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 e,i=t.find("input").filter(function(t,e){return!o(e).is('[name^="add-to-cart"]')}.bind(this)).serializeArray(),s={};for(e in i){var a=i[e];s[a.name]=a.value}return s.payment_method=this.gateway_id,s},wc_stripe.BaseGateway.prototype.serialize_fields=function(){return o.extend({},this.fields.toJson(),o(document.body).triggerHandler("wc_stripe_process_checkout_data",[this,this.fields]))},wc_stripe.BaseGateway.prototype.map_shipping_methods=function(t){var e={};return"default"===t||1<(t=t.match(/^([\w+]):(.+)$/)).length&&(e[t[1]]=t[2]),e},wc_stripe.BaseGateway.prototype.maybe_set_ship_to_different=function(){o('[name="ship_to_different_address"]').length&&o('[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(s){return new Promise(function(e,i){o.ajax({url:this.params.routes.shipping_address,method:"POST",dataType:"json",data:{address:this.map_address(s.shippingAddress),payment_method:this.gateway_id,page_id:this.get_page(),currency:this.get_currency()},beforeSend:this.ajax_before_send.bind(this)}).done(function(t){t.code?(s.updateWith(t.data.newData),i(t.data)):(s.updateWith(t.data.newData),this.fields.set("shipping_method",t.data.shipping_method),e(t.data))}.bind(this)).fail(function(){}.bind(this))}.bind(this))},wc_stripe.BaseGateway.prototype.update_shipping_method=function(s){return new Promise(function(e,i){o.ajax({url:this.params.routes.shipping_method,method:"POST",dataType:"json",data:{shipping_method:s.shippingOption.id,payment_method:this.gateway_id,currency:this.get_currency(),page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)}).done(function(t){t.code?(s.updateWith(t.data.newData),i(t.data)):(this.set_selected_shipping_methods(t.data.shipping_methods),s.updateWith(t.data.newData),e(t.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,o(document.body).on("update_checkout",this.update_checkout.bind(this)),o(document.body).on("updated_checkout",this.updated_checkout.bind(this)),o(document.body).on("cfw_updated_checkout",this.updated_checkout.bind(this)),o(document.body).on("checkout_error",this.checkout_error.bind(this)),o(this.token_selector).closest("form").on("checkout_place_order_"+this.gateway_id,this.checkout_place_order.bind(this)),o(document.body).on("wc_stripe_new_method_"+this.gateway_id,this.on_show_new_methods.bind(this)),o(document.body).on("wc_stripe_saved_method_"+this.gateway_id,this.on_show_saved_methods.bind(this)),o(document.body).on("wc_stripe_payment_method_selected",this.on_payment_method_selected.bind(this)),this.banner_enabled()&&o(".woocommerce-billing-fields").length&&o(".wc-stripe-banner-checkout").css("max-width",o(".woocommerce-billing-fields").outerWidth(!0)),this.order_review()},wc_stripe.CheckoutGateway.prototype.order_review=function(){var t,e=i.location.href.match(/order_review.+payment_method=([\w]+).+payment_nonce=(.+)/);e&&1<e.length&&(t=e[1],e=e[2],this.gateway_id===t&&(this.payment_token_received=!0,this.set_nonce(e),this.set_use_new_option(!0)))},wc_stripe.CheckoutGateway.prototype.update_shipping_address=function(){return wc_stripe.BaseGateway.prototype.update_shipping_address.apply(this,arguments).then(function(t){this.populate_address_fields(t.address,this.get_shipping_prefix()),this.fields.toFormFields({update_shipping_method:!1})}.bind(this))},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!(o('[name="terms"]').length&&!o('[name="terms"]').is(":checked"))},wc_stripe.CheckoutGateway.prototype.get_payment_method=function(){return o('[name="payment_method"]:checked').val()},wc_stripe.CheckoutGateway.prototype.set_use_new_option=function(t){o("#"+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(){o().block&&o("form.checkout").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.CheckoutGateway.prototype.unblock=function(){o().block&&o("form.checkout").unblock()},wc_stripe.CheckoutGateway.prototype.hide_place_order=function(){o("#place_order").addClass("wc-stripe-hide")},wc_stripe.CheckoutGateway.prototype.show_place_order=function(){o("#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,o('[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(["checkout","order_pay"].indexOf(this.get_page())<0)return!0;var t=!0;return(t=this.fields.validateFields("billing"))?this.needs_shipping()&&o("#ship-to-different-address-checkbox").is(":checked")?(t=this.fields.validateFields("shipping"))||this.submit_error(this.params.messages.required_field):(t=this.is_valid_checkout())||this.submit_error(this.params.messages.terms):this.submit_error(this.params.messages.required_field),t},wc_stripe.CheckoutGateway.prototype.cart_contains_subscription=function(){return"undefined"!=typeof wc_stripe_cart_contains_subscription&&!0===wc_stripe_cart_contains_subscription},wc_stripe.ProductGateway=function(){this.message_container="div.product",o("form.cart").on("found_variation",this.found_variation.bind(this)),o("form.cart").on("reset_data",this.reset_variation_data.bind(this)),this.buttonWidth=o("form.cart div.quantity").outerWidth(!0)+o(".single_add_to_cart_button").outerWidth();var t=o(".single_add_to_cart_button").css("marginLeft");t&&(this.buttonWidth+=parseInt(t.replace("px",""))),o(this.container).css("max-width",this.buttonWidth+"px")},wc_stripe.ProductGateway.prototype.get_quantity=function(){return parseInt(o('[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)},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 0<o('[name="variation_id"]').length},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(e,i){this.block(),o.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()?o('[name="variation_id"]').val():0,qty:o('[name="quantity"]').val(),payment_method:this.gateway_id,currency:this.get_currency(),page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)}).done(function(t){this.unblock(),t.code?(this.submit_error(t.message),i(t)):(this.set_total_price(t.data.total),this.set_total_price_cents(t.data.totalCents),this.set_display_items(t.data.displayItems),e(t.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(e,i){o.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:o('[name="quantity"]').val(),currency:this.get_currency(),payment_method:this.gateway_id},beforeSend:this.ajax_before_send.bind(this)}).done(function(t){t.code?(this.cart_calculation_error=!0,i(t)):(this.set_total_price(t.data.total),this.set_total_price_cents(t.data.totalCents),this.set_display_items(t.data.displayItems),e(t.data))}.bind(this)).fail(function(){}.bind(this))}.bind(this))},wc_stripe.CartGateway=function(){this.message_container="div.woocommerce",o(document.body).on("updated_wc_div",this.updated_html.bind(this)),o(document.body).on("updated_cart_totals",this.updated_html.bind(this)),o(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(){o(".cart_totals").addClass("stripe_cart_gateway_active")},wc_stripe.GooglePay=function(){};var a={apiVersion:2,apiVersionMinor:0},n={type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY"],allowedCardNetworks:["AMEX","DISCOVER","INTERAC","JCB","MASTERCARD","VISA"]}};wc_stripe.GooglePay.prototype.update_addresses=function(t){this.populate_billing_fields(t.paymentMethodData.info.billingAddress),t.shippingAddress&&this.populate_shipping_fields(t.shippingAddress),t.email&&this.fields.set("email",t.email,"billing")},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(s){return new Promise(function(e,i){var t="default"==s.shippingOptionData.id?null:s.shippingOptionData.id;o.when(o.ajax({url:this.params.routes.payment_data,dataType:"json",method:"POST",data:{shipping_address:this.map_address(s.shippingAddress),shipping_method:t,page_id:this.get_page(),currency:this.get_currency()},beforeSend:this.ajax_before_send.bind(this)})).done(function(t){t.code?i(t.data.data):e(t.data)}.bind(this)).fail(function(){i()}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.on_payment_data_changed=function(i){return new Promise(function(e){this.update_payment_data(i).then(function(t){e(t.paymentRequestUpdate),this.set_selected_shipping_methods(t.shipping_methods),this.payment_data_updated(t,i)}.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,e={environment:this.params.environment,merchantInfo:this.get_merchant_info(),paymentDataCallbacks:{onPaymentAuthorized:function(){return new Promise(function(t){t({transactionState:"SUCCESS"})}.bind(this))}}};return this.needs_shipping()&&(t=this.get_shipping_prefix(),(!this.is_current_page("checkout")||this.is_valid_address(this.get_address_object(t),t,["email","phone"]))&&this.is_current_page("checkout")||(e.paymentDataCallbacks.onPaymentDataChanged=this.on_payment_data_changed.bind(this))),e},wc_stripe.GooglePay.prototype.build_payment_request=function(){var t=o.extend({},a,{emailRequired:this.fields.requestFieldInWallet("billing_email"),merchantInfo:this.get_merchant_info(),allowedPaymentMethods:[o.extend({type:"CARD",tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:"stripe","stripe:version":"2018-10-31","stripe:publishableKey":this.params.api_key}}},n)],shippingAddressRequired:function(){if(this.needs_shipping()){var t=this.get_shipping_prefix();if(this.is_current_page("checkout")&&!this.is_valid_address(this.get_address_object(t),t,["email","phone"])||!this.is_current_page("checkout"))return!0}return!1}.bind(this)(),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.fields.requestFieldInWallet("billing_phone")},t.shippingAddressRequired?(t.shippingAddressParameters={},t.shippingOptionRequired=!0,t.shippingOptionParameters={shippingOptions:this.get_shipping_options()},t.callbackIntents=["SHIPPING_ADDRESS","SHIPPING_OPTION","PAYMENT_AUTHORIZATION"]):t.callbackIntents=["PAYMENT_AUTHORIZATION"],this.payment_request_options=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 e=o.extend({},a);e.allowedPaymentMethods=[n],this.paymentsClient.isReadyToPay(e).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=o(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.update_addresses(t),this.on_token_received(e)}.bind(this))["catch"](function(t){"CANCELED"!==t.statusCode&&(t.statusMessage&&-1<t.statusMessage.indexOf("paymentDataRequest.callbackIntent")?this.submit_error_code("DEVELOPER_ERROR_WHITELIST"):this.submit_error(t.message))}.bind(this))},wc_stripe.ApplePay=function(){},wc_stripe.ApplePay.prototype.initialize=function(){this.createPaymentRequest(),this.canMakePayment()},wc_stripe.ApplePay.prototype.create_button=function(){this.$button&&this.$button.remove(),this.$button=o(this.params.button),this.$button.on("click",this.start.bind(this)),this.append_button()},wc_stripe.ApplePay.prototype.canMakePayment=function(){return new Promise(function(e){this.paymentRequest.canMakePayment().then(function(t){t&&t.applePay&&(this.can_pay=!0,this.create_button(),o(this.container).show(),e(t))}.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.createPaymentRequestButton(),this.canMakePayment(),this.paymentRequestButton.on("click",this.button_click.bind(this))},wc_stripe.PaymentRequest.prototype.button_click=function(t){},wc_stripe.PaymentRequest.prototype.createPaymentRequestButton=function(){this.paymentRequestButton&&this.paymentRequestButton.destroy(),this.paymentRequestButton=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(e){this.paymentRequest.canMakePayment().then(function(t){t&&!t.applePay&&(this.can_pay=!0,this.create_button(),o(this.container).show(),e(t))}.bind(this))}.bind(this))},wc_stripe.PaymentRequest.prototype.create_button=function(){this.paymentRequestButton.mount("#wc-stripe-payment-request-container")},wc_stripe.CheckoutFields=function(t,e){this.params=t,this.page=e,this.fields=new Map(Object.keys(this.params).map(function(t){return null===this.params[t].value&&(this.params[t].value=""),[t,this.params[t].value]}.bind(this))),"checkout"===e&&(o("form.checkout").on("change",".input-text, select",this.onChange.bind(this)),o("form.checkout").on("change",'[name="ship_to_different_address"]',this.on_ship_to_address_change.bind(this)),this.init_i18n(),o('[name="ship_to_different_address"]').is(":checked")?this.update_required_fields(o("#shipping_country").val(),"shipping_country"):this.update_required_fields(o("#billing_country").val(),"billing_country"))},wc_stripe.CheckoutFields.prototype.init_i18n=function(){"undefined"!=typeof wc_address_i18n_params?this.locales=o.parseJSON(wc_address_i18n_params.locale.replace(/&quot;/g,'"')):this.locales=null},wc_stripe.CheckoutFields.prototype.onChange=function(t){try{var e=t.currentTarget.name,i=t.currentTarget.value;this.fields.set(e,i),"billing_country"!==e&&"shipping_country"!==e||this.update_required_fields(i,e)}catch(s){console.log(s)}},wc_stripe.CheckoutFields.prototype.update_required_fields=function(t,e){if(this.locales){var i,s=-1<e.indexOf("billing_")?"billing_":"shipping_",t="undefined"!=typeof this.locales[t]?this.locales[t]:this.locales["default"],a=o.extend(!0,{},this.locales["default"],t);for(i in a){var n=s+i;this.params[n]&&(this.params[n]=o.extend(!0,{},this.params[n],a[i]))}}},wc_stripe.CheckoutFields.prototype.on_ship_to_address_change=function(t){o(t.currentTarget).is(":checked")&&this.update_required_fields(o("#shipping_country").val(),"shipping_country")},wc_stripe.CheckoutFields.prototype.requestFieldInWallet=function(t){return"checkout"===this.page?this.required(t)&&this.isEmpty(t):"order_pay"!==this.page&&this.required(t)},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){var i;return this[t]&&"function"==typeof this[t]?i=this[t]().get.call(this,e):null!=(i=this.fields.get(t))&&""!==i||void 0!==e&&(i=e),void 0===i?"":i},wc_stripe.CheckoutFields.prototype.required=function(t){return!(!this.params[t]||"undefined"==typeof this.params[t].required)&&this.params[t].required},wc_stripe.CheckoutFields.prototype.isEmpty=function(t){if(this.fields.has(t)){t=this.fields.get(t);return null==t||"string"==typeof t&&0===t.trim().length}return!0},wc_stripe.CheckoutFields.prototype.isValid=function(t){if(this[t]&&"function"==typeof this[t])return this[t]().isValid.apply(this,Array.prototype.slice.call(arguments,1))},wc_stripe.CheckoutFields.prototype.first_name=function(){return{set:function(t,e){this.fields.set(e+"_first_name",t)},get:function(t){return this.fields.get(t+"_first_name")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.last_name=function(){return{set:function(t,e){this.fields.set(e+"_last_name",t)},get:function(t){return this.fields.get(t+"_last_name")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.address_1=function(){return{set:function(t,e){this.fields.set(e+"_address_1",t)},get:function(t){return this.fields.get(t+"_address_1")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.address_2=function(){return{set:function(t,e){this.fields.set(e+"_address_2",t)},get:function(t){return this.fields.get(t+"_address_2")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.name=function(){return{set:function(t,e){t=t.split(" ");0<t.length&&this.fields.set(e+"_first_name",t[0]),1<t.length&&this.fields.set(e+"_last_name",t[1])},get:function(t){return this.fields.get(t+"_first_name")+" "+this.fields.get(t+"_last_name")}}},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")},isValid:function(t){return"string"==typeof t&&0<t.length}}},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")},isValid:function(t){return"string"==typeof t&&0<t.length}}},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")},isValid:function(t){return"string"==typeof t&&2===t.length}}},wc_stripe.CheckoutFields.prototype.state=function(){return{set:function(i,t){2<(i=i.toUpperCase()).length&&"checkout"===this.page&&o("#"+t+"_state option").each(function(){var t=o(this),e=t.text().toUpperCase();i===e&&(i=t.val())}),this.fields.set(t+"_state",i)},get:function(t){return this.fields.get(t+"_state")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.city=function(){return{set:function(t,e){this.fields.set(e+"_city",t)},get:function(t){return this.fields.get(t+"_city")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.postcode=function(){return{set:function(t,e){this.fields.set(e+"_postcode",t)},get:function(t){return this.fields.get(t+"_postcode")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.recipient=function(){return wc_stripe.CheckoutFields.prototype.name.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.payerName=function(){return wc_stripe.CheckoutFields.prototype.name.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.payerEmail=function(){return wc_stripe.CheckoutFields.prototype.email.apply(this,arguments)},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.countryCode=function(){return wc_stripe.CheckoutFields.prototype.country.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.address1=function(){return wc_stripe.CheckoutFields.prototype.address_1.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.address2=function(){return wc_stripe.CheckoutFields.prototype.address_2.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.line1=function(){return wc_stripe.CheckoutFields.prototype.address_1.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.line2=function(){return wc_stripe.CheckoutFields.prototype.address_2.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.addressLine=function(){return{set:function(t,e){0<t.length&&this.fields.set(e+"_address_1",t[0]),1<t.length&&this.fields.set(e+"_address_2",t[1])},get:function(t){return[this.fields.get(t+"_address_1"),this.fields.get(t+"_address_2")]},isValid:function(t){return 0<t.length&&("string"==typeof t[0]&&0<t[0].length)}}},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.locality=function(){return wc_stripe.CheckoutFields.prototype.city.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.postal_code=function(){return wc_stripe.CheckoutFields.prototype.postcode.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.postalCode=function(){return wc_stripe.CheckoutFields.prototype.postcode.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.toJson=function(){var i={};return this.fields.forEach(function(t,e){i[e]=t}),i},wc_stripe.CheckoutFields.prototype.toFormFields=function(t){var i=[];this.fields.forEach(function(t,e){e='[name="'+e+'"]';o(e).length&&""!==t&&(o(e).val()!==t&&o(e).is("select")&&i.push(e),o(e).val(t))}),0<i.length&&o(i.join(",")).trigger("change"),void 0!==t&&o(document.body).trigger("update_checkout",t)},wc_stripe.CheckoutFields.prototype.validateFields=function(t){for(var e in this.params){var i=this.params[e];if(-1<e.indexOf(t)&&i.required&&o("#"+e).length&&o("#"+e).is(":visible")){i=o("#"+e).val();if(null==i||0===i.length)return!1}}return!0};try{s=Stripe(wc_stripe_params_v3.api_key,{stripeAccount:wc_stripe_params_v3.account})}catch(t){return i.alert(t),console.log(t)}var r=new wc_stripe.CheckoutFields(wc_stripe_checkout_fields,wc_stripe_params_v3.page)}(window,jQuery);
1
+ !function(i,o){i.wc_stripe={};var s=null;"undefined"==typeof wc_stripe_checkout_fields&&(i.wc_stripe_checkout_fields=[]),wc_stripe.BaseGateway=function(t,e){this.params=t,this.gateway_id=this.params.gateway_id,this.container=void 0===e?"li.payment_method_".concat(this.gateway_id):e,o(this.container).length||(this.container=".payment_method_".concat(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=s,this.elements=s.elements(o.extend({},{locale:"auto"},this.get_element_options())),this.fields=r,this.initialize()},wc_stripe.BaseGateway.prototype.get_page=function(){var t=wc_stripe_params_v3.page;return"cart"===t&&o(document.body).is(".woocommerce-checkout")&&(t="checkout"),t},wc_stripe.BaseGateway.prototype.set_nonce=function(t){this.fields.set(this.gateway_id+"_token_key",t),o(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 o('[name="payment_method"]:checked').val()===this.gateway_id},wc_stripe.BaseGateway.prototype.is_saved_method_selected=function(){return this.is_gateway_selected()&&"saved"===o('[name="'+this.gateway_id+'_payment_type_key"]:checked').val()},wc_stripe.BaseGateway.prototype.has_checkout_error=function(){return 0<o("#wc_stripe_checkout_error").length&&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){console.log(t)},wc_stripe.BaseGateway.prototype.get_error_message=function(t){return"object"==typeof t&&t.code&&(t=wc_stripe_messages[t.code]||t.message),t},wc_stripe.BaseGateway.prototype.submit_message=function(t){o(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove();var e=o(this.message_container);e.closest("form").length&&(e=e.closest("form")),e.prepend(t),e.removeClass("processing").unblock(),e.find(".input-text, select, input:checkbox").blur(),o.scroll_to_notices?o.scroll_to_notices(e):o("html, body").animate({scrollTop:e.offset().top-100},1e3)},wc_stripe.BaseGateway.prototype.get_first_name=function(t){return o("#"+t+"_first_name").val()},wc_stripe.BaseGateway.prototype.get_last_name=function(t){return o("#"+t+"_last_name").val()},wc_stripe.BaseGateway.prototype.get_shipping_prefix=function(){return this.needs_shipping()&&0<o('[name="ship_to_different_address"]').length&&o('[name="ship_to_different_address"]').is(":checked")?"shipping":"billing"},wc_stripe.BaseGateway.prototype.should_save_method=function(){return o("#"+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()||o(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 o(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(){var t=o(this.container).find(".woocommerce_".concat(this.gateway_id,"_gateway_data")).data("gateway");return void 0===t&&this.is_current_page("checkout")&&(t=o("form.checkout").find(".woocommerce_".concat(this.gateway_id,"_gateway_data")).data("gateway")),t},wc_stripe.BaseGateway.prototype.set_gateway_data=function(t){o(this.container).find(".woocommerce_".concat(this.gateway_id,"_gateway_data")).data("gateway",t)},wc_stripe.BaseGateway.prototype.get_customer_name=function(t){return this.fields.get(t+"_first_name")+" "+this.fields.get(t+"_last_name")},wc_stripe.BaseGateway.prototype.get_customer_email=function(){return this.fields.get("billing_email")},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.fields.get(t+e[s])+"_";return i},wc_stripe.BaseGateway.prototype.block=function(){o().block&&o.blockUI({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.BaseGateway.prototype.unblock=function(){o().block&&o.unblockUI()},wc_stripe.BaseGateway.prototype.get_form=function(){return o(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){o('[name="payment_method"][value="'+t+'"]').prop("checked",!0).trigger("click")},wc_stripe.BaseGateway.prototype.set_selected_shipping_methods=function(t){if(this.fields.set("shipping_method",t),t&&o('[name^="shipping_method"]').length)for(var e in t){var i=t[e];o('[name="shipping_method['+e+']"][value="'+i+'"]').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.payment_request_options=this.get_payment_request_options(),this.paymentRequest=s.paymentRequest(this.payment_request_options),this.payment_request_options.requestShipping&&(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))}catch(t){return void this.submit_error(t.message)}},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.fields.requestFieldInWallet("billing_email"),requestPayerPhone:this.fields.requestFieldInWallet("billing_phone"),requestShipping:function(){if(this.needs_shipping()){var t=this.get_shipping_prefix();if(this.is_current_page("checkout")&&!this.is_valid_address(this.get_address_object(t),t,["email","phone"])||!this.is_current_page("checkout"))return!0}return!1}.bind(this)()},e=this.get_display_items(),i=this.get_shipping_options();return e&&(t.displayItems=e),t.requestShipping&&i&&(t.shippingOptions=i),t},wc_stripe.BaseGateway.prototype.get_payment_request_update=function(t){var e={currency:this.get_currency().toLowerCase(),total:{amount:parseInt(this.get_total_price_cents()),label:this.params.total_label,pending:!0}},i=this.get_display_items(),s=this.get_shipping_options();return i&&(e.displayItems=i),this.payment_request_options.requestShipping&&s&&(e.shippingOptions=s),t&&(e=o.extend(!0,{},e,t)),e},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(t){try{this.payment_response=t,this.populate_checkout_fields(t),t.complete("success"),this.on_token_received(t.paymentMethod)}catch(e){i.alert(e)}},wc_stripe.BaseGateway.prototype.populate_checkout_fields=function(t){this.set_nonce(t.paymentMethod.id),this.update_addresses(t)},wc_stripe.BaseGateway.prototype.update_addresses=function(t){t.payerName&&this.fields.set("name",t.payerName,"billing"),t.payerEmail&&this.fields.set("email",t.payerEmail,"billing"),t.payerPhone&&this.fields.set("phone",t.payerPhone,"billing"),t.shippingAddress&&this.populate_shipping_fields(t.shippingAddress),t.paymentMethod.billing_details.address&&this.populate_billing_fields(t.paymentMethod.billing_details.address)},wc_stripe.BaseGateway.prototype.populate_address_fields=function(t,e){for(var i in t)null!==t[i]&&this.fields.set(i,t[i],e)},wc_stripe.BaseGateway.prototype.populate_billing_fields=function(t){this.populate_address_fields(t,"billing")},wc_stripe.BaseGateway.prototype.populate_shipping_fields=function(t){this.populate_address_fields(t,"shipping")},wc_stripe.BaseGateway.prototype.get_address_fields=function(){return["first_name","last_name","country","address_1","address_2","city","state","postcode","phone","email"]},wc_stripe.BaseGateway.prototype.get_address_object=function(e){var i={};return this.get_address_fields().forEach(function(t){i[t]=this.fields.get(t,e)}.bind(this)),i},wc_stripe.BaseGateway.prototype.is_current_page=function(t){return this.get_page()===t},wc_stripe.BaseGateway.prototype.is_valid_address=function(t,e,i){if(o.isEmptyObject(t))return!1;var s=this.get_address_fields();void 0!==i&&i.forEach(function(t){-1<s.indexOf(t)&&s.splice(s.indexOf(t),1)});for(var a=0;a<s.length;a++){var n=s[a];if(this.fields.required(e+"_"+n)&&(!t[n]||"undefined"==typeof t[n]||!this.fields.isValid(n,t[n],t)))return!1}return!0},wc_stripe.BaseGateway.prototype.ajax_before_send=function(t){0<this.params.user_id&&t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)},wc_stripe.BaseGateway.prototype.process_checkout=function(){return new Promise(function(){this.block(),o.ajax({url:this.params.routes.checkout,method:"POST",dataType:"json",data:o.extend({},this.serialize_fields(),{payment_method:this.gateway_id,page_id:this.get_page(),currency:this.get_currency()}),beforeSend:this.ajax_before_send.bind(this)}).done(function(t){t.reload?i.location.reload():"success"===t.result?i.location=t.redirect:(t.messages&&this.submit_error(t.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 e,i=t.find("input").filter(function(t,e){return!o(e).is('[name^="add-to-cart"]')}.bind(this)).serializeArray(),s={};for(e in i){var a=i[e];s[a.name]=a.value}return s.payment_method=this.gateway_id,s},wc_stripe.BaseGateway.prototype.serialize_fields=function(){return o.extend({},this.fields.toJson(),o(document.body).triggerHandler("wc_stripe_process_checkout_data",[this,this.fields]))},wc_stripe.BaseGateway.prototype.map_shipping_methods=function(t){var e={};return"default"===t||1<(t=t.match(/^([\w+]):(.+)$/)).length&&(e[t[1]]=t[2]),e},wc_stripe.BaseGateway.prototype.maybe_set_ship_to_different=function(){o('[name="ship_to_different_address"]').length&&o('[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(s){return new Promise(function(e,i){o.ajax({url:this.params.routes.shipping_address,method:"POST",dataType:"json",data:{address:this.map_address(s.shippingAddress),payment_method:this.gateway_id,page_id:this.get_page(),currency:this.get_currency()},beforeSend:this.ajax_before_send.bind(this)}).done(function(t){t.code?(s.updateWith(t.data.newData),i(t.data)):(s.updateWith(t.data.newData),this.fields.set("shipping_method",t.data.shipping_method),e(t.data))}.bind(this)).fail(function(){}.bind(this))}.bind(this))},wc_stripe.BaseGateway.prototype.update_shipping_method=function(s){return new Promise(function(e,i){o.ajax({url:this.params.routes.shipping_method,method:"POST",dataType:"json",data:{shipping_method:s.shippingOption.id,payment_method:this.gateway_id,currency:this.get_currency(),page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)}).done(function(t){t.code?(s.updateWith(t.data.newData),i(t.data)):(this.set_selected_shipping_methods(t.data.shipping_methods),s.updateWith(t.data.newData),e(t.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,o(document.body).on("update_checkout",this.update_checkout.bind(this)),o(document.body).on("updated_checkout",this.updated_checkout.bind(this)),o(document.body).on("cfw_updated_checkout",this.updated_checkout.bind(this)),o(document.body).on("checkout_error",this.checkout_error.bind(this)),o(this.token_selector).closest("form").on("checkout_place_order_"+this.gateway_id,this.checkout_place_order.bind(this)),o(document.body).on("wc_stripe_new_method_"+this.gateway_id,this.on_show_new_methods.bind(this)),o(document.body).on("wc_stripe_saved_method_"+this.gateway_id,this.on_show_saved_methods.bind(this)),o(document.body).on("wc_stripe_payment_method_selected",this.on_payment_method_selected.bind(this)),this.banner_enabled()&&o(".woocommerce-billing-fields").length&&o(".wc-stripe-banner-checkout").css("max-width",o(".woocommerce-billing-fields").outerWidth(!0)),this.order_review()},wc_stripe.CheckoutGateway.prototype.order_review=function(){var t,e=i.location.href.match(/order_review.+payment_method=([\w]+).+payment_nonce=(.+)/);e&&1<e.length&&(t=e[1],e=e[2],this.gateway_id===t&&(this.payment_token_received=!0,this.set_nonce(e),this.set_use_new_option(!0)))},wc_stripe.CheckoutGateway.prototype.update_shipping_address=function(){return wc_stripe.BaseGateway.prototype.update_shipping_address.apply(this,arguments).then(function(t){this.populate_address_fields(t.address,this.get_shipping_prefix()),this.fields.toFormFields({update_shipping_method:!1})}.bind(this))},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!(o('[name="terms"]').length&&!o('[name="terms"]').is(":checked"))},wc_stripe.CheckoutGateway.prototype.get_payment_method=function(){return o('[name="payment_method"]:checked').val()},wc_stripe.CheckoutGateway.prototype.set_use_new_option=function(t){o("#"+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(){o().block&&o("form.checkout").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.CheckoutGateway.prototype.unblock=function(){o().block&&o("form.checkout").unblock()},wc_stripe.CheckoutGateway.prototype.hide_place_order=function(){o("#place_order").addClass("wc-stripe-hide")},wc_stripe.CheckoutGateway.prototype.show_place_order=function(){o("#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,o('[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(["checkout","order_pay"].indexOf(this.get_page())<0)return!0;var t=!0;return(t=this.fields.validateFields("billing"))?this.needs_shipping()&&o("#ship-to-different-address-checkbox").is(":checked")?(t=this.fields.validateFields("shipping"))||this.submit_error(this.params.messages.required_field):(t=this.is_valid_checkout())||this.submit_error(this.params.messages.terms):this.submit_error(this.params.messages.required_field),t},wc_stripe.CheckoutGateway.prototype.cart_contains_subscription=function(){return"undefined"!=typeof wc_stripe_cart_contains_subscription&&!0===wc_stripe_cart_contains_subscription},wc_stripe.ProductGateway=function(){this.message_container="div.product",o("form.cart").on("found_variation",this.found_variation.bind(this)),o("form.cart").on("reset_data",this.reset_variation_data.bind(this)),this.buttonWidth=o("form.cart div.quantity").outerWidth(!0)+o(".single_add_to_cart_button").outerWidth();var t=o(".single_add_to_cart_button").css("marginLeft");t&&(this.buttonWidth+=parseInt(t.replace("px",""))),o(this.container).css("max-width",this.buttonWidth+"px")},wc_stripe.ProductGateway.prototype.get_quantity=function(){return parseInt(o('[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)},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 0<o('[name="variation_id"]').length},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(e,i){this.block(),o.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()?o('[name="variation_id"]').val():0,qty:o('[name="quantity"]').val(),payment_method:this.gateway_id,currency:this.get_currency(),page_id:this.get_page()},beforeSend:this.ajax_before_send.bind(this)}).done(function(t){this.unblock(),t.code?(this.submit_error(t.message),i(t)):(this.set_total_price(t.data.total),this.set_total_price_cents(t.data.totalCents),this.set_display_items(t.data.displayItems),e(t.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(e,i){o.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:o('[name="quantity"]').val(),currency:this.get_currency(),payment_method:this.gateway_id},beforeSend:this.ajax_before_send.bind(this)}).done(function(t){t.code?(this.cart_calculation_error=!0,i(t)):(this.set_total_price(t.data.total),this.set_total_price_cents(t.data.totalCents),this.set_display_items(t.data.displayItems),e(t.data))}.bind(this)).fail(function(){}.bind(this))}.bind(this))},wc_stripe.CartGateway=function(){this.message_container="div.woocommerce",o(document.body).on("updated_wc_div",this.updated_html.bind(this)),o(document.body).on("updated_cart_totals",this.updated_html.bind(this)),o(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(){o(".cart_totals").addClass("stripe_cart_gateway_active")},wc_stripe.GooglePay=function(){};var a={apiVersion:2,apiVersionMinor:0},n={type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY"],allowedCardNetworks:["AMEX","DISCOVER","INTERAC","JCB","MASTERCARD","VISA"]}};wc_stripe.GooglePay.prototype.update_addresses=function(t){this.populate_billing_fields(t.paymentMethodData.info.billingAddress),t.shippingAddress&&this.populate_shipping_fields(t.shippingAddress),t.email&&this.fields.set("email",t.email,"billing")},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(s){return new Promise(function(e,i){var t="default"==s.shippingOptionData.id?null:s.shippingOptionData.id;o.when(o.ajax({url:this.params.routes.payment_data,dataType:"json",method:"POST",data:{address:this.map_address(s.shippingAddress),shipping_method:t,page_id:this.get_page(),currency:this.get_currency()},beforeSend:this.ajax_before_send.bind(this)})).done(function(t){t.code?i(t.data.data):e(t.data)}.bind(this)).fail(function(){i()}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.on_payment_data_changed=function(i){return new Promise(function(e){this.update_payment_data(i).then(function(t){e(t.paymentRequestUpdate),this.set_selected_shipping_methods(t.shipping_methods),this.payment_data_updated(t,i)}.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,e={environment:this.params.environment,merchantInfo:this.get_merchant_info(),paymentDataCallbacks:{onPaymentAuthorized:function(){return new Promise(function(t){t({transactionState:"SUCCESS"})}.bind(this))}}};return this.needs_shipping()&&(t=this.get_shipping_prefix(),(!this.is_current_page("checkout")||this.is_valid_address(this.get_address_object(t),t,["email","phone"]))&&this.is_current_page("checkout")||(e.paymentDataCallbacks.onPaymentDataChanged=this.on_payment_data_changed.bind(this))),e},wc_stripe.GooglePay.prototype.build_payment_request=function(){var t=o.extend({},a,{emailRequired:this.fields.requestFieldInWallet("billing_email"),merchantInfo:this.get_merchant_info(),allowedPaymentMethods:[o.extend({type:"CARD",tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:"stripe","stripe:version":"2018-10-31","stripe:publishableKey":this.params.api_key}}},n)],shippingAddressRequired:function(){if(this.needs_shipping()){var t=this.get_shipping_prefix();if(this.is_current_page("checkout")&&!this.is_valid_address(this.get_address_object(t),t,["email","phone"])||!this.is_current_page("checkout"))return!0}return!1}.bind(this)(),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.fields.requestFieldInWallet("billing_phone")},t.shippingAddressRequired?(t.shippingAddressParameters={},t.shippingOptionRequired=!0,t.shippingOptionParameters={shippingOptions:this.get_shipping_options()},t.callbackIntents=["SHIPPING_ADDRESS","SHIPPING_OPTION","PAYMENT_AUTHORIZATION"]):t.callbackIntents=["PAYMENT_AUTHORIZATION"],this.payment_request_options=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 e=o.extend({},a);e.allowedPaymentMethods=[n],this.paymentsClient.isReadyToPay(e).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=o(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.update_addresses(t),this.on_token_received(e)}.bind(this))["catch"](function(t){"CANCELED"!==t.statusCode&&(t.statusMessage&&-1<t.statusMessage.indexOf("paymentDataRequest.callbackIntent")?this.submit_error_code("DEVELOPER_ERROR_WHITELIST"):this.submit_error(t.message))}.bind(this))},wc_stripe.ApplePay=function(){},wc_stripe.ApplePay.prototype.initialize=function(){this.createPaymentRequest(),this.canMakePayment()},wc_stripe.ApplePay.prototype.create_button=function(){this.$button&&this.$button.remove(),this.$button=o(this.params.button),this.$button.on("click",this.start.bind(this)),this.append_button()},wc_stripe.ApplePay.prototype.canMakePayment=function(){return new Promise(function(e){this.paymentRequest.canMakePayment().then(function(t){t&&t.applePay&&(this.can_pay=!0,this.create_button(),o(this.container).show(),e(t))}.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.createPaymentRequestButton(),this.canMakePayment(),this.paymentRequestButton.on("click",this.button_click.bind(this))},wc_stripe.PaymentRequest.prototype.button_click=function(t){},wc_stripe.PaymentRequest.prototype.createPaymentRequestButton=function(){this.paymentRequestButton&&this.paymentRequestButton.destroy(),this.paymentRequestButton=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(e){this.paymentRequest.canMakePayment().then(function(t){t&&!t.applePay&&(this.can_pay=!0,this.create_button(),o(this.container).show(),e(t))}.bind(this))}.bind(this))},wc_stripe.PaymentRequest.prototype.create_button=function(){this.paymentRequestButton.mount("#wc-stripe-payment-request-container")},wc_stripe.CheckoutFields=function(t,e){this.params=t,this.page=e,this.fields=new Map(Object.keys(this.params).map(function(t){return null===this.params[t].value&&(this.params[t].value=""),[t,this.params[t].value]}.bind(this))),("checkout"===e||"cart"===e&&o(document.body).is(".woocommerce-checkout"))&&(o("form.checkout").on("change",".input-text, select",this.onChange.bind(this)),o("form.checkout").on("change",'[name="ship_to_different_address"]',this.on_ship_to_address_change.bind(this)),this.init_i18n(),o('[name="ship_to_different_address"]').is(":checked")?this.update_required_fields(o("#shipping_country").val(),"shipping_country"):this.update_required_fields(o("#billing_country").val(),"billing_country"))},wc_stripe.CheckoutFields.prototype.init_i18n=function(){"undefined"!=typeof wc_address_i18n_params?this.locales=o.parseJSON(wc_address_i18n_params.locale.replace(/&quot;/g,'"')):this.locales=null},wc_stripe.CheckoutFields.prototype.onChange=function(t){try{var e=t.currentTarget.name,i=t.currentTarget.value;this.fields.set(e,i),"billing_country"!==e&&"shipping_country"!==e||this.update_required_fields(i,e)}catch(s){console.log(s)}},wc_stripe.CheckoutFields.prototype.update_required_fields=function(t,e){if(this.locales){var i,s=-1<e.indexOf("billing_")?"billing_":"shipping_",t="undefined"!=typeof this.locales[t]?this.locales[t]:this.locales["default"],a=o.extend(!0,{},this.locales["default"],t);for(i in a){var n=s+i;this.params[n]&&(this.params[n]=o.extend(!0,{},this.params[n],a[i]))}}},wc_stripe.CheckoutFields.prototype.on_ship_to_address_change=function(t){o(t.currentTarget).is(":checked")&&this.update_required_fields(o("#shipping_country").val(),"shipping_country")},wc_stripe.CheckoutFields.prototype.requestFieldInWallet=function(t){return"checkout"===this.page?this.required(t)&&this.isEmpty(t):"order_pay"!==this.page&&this.required(t)},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){var i;return this[t]&&"function"==typeof this[t]?i=this[t]().get.call(this,e):null!=(i=this.fields.get(t))&&""!==i||void 0!==e&&(i=e),void 0===i?"":i},wc_stripe.CheckoutFields.prototype.required=function(t){return!(!this.params[t]||"undefined"==typeof this.params[t].required)&&this.params[t].required},wc_stripe.CheckoutFields.prototype.isEmpty=function(t){if(this.fields.has(t)){t=this.fields.get(t);return null==t||"string"==typeof t&&0===t.trim().length}return!0},wc_stripe.CheckoutFields.prototype.isValid=function(t){if(this[t]&&"function"==typeof this[t])return this[t]().isValid.apply(this,Array.prototype.slice.call(arguments,1))},wc_stripe.CheckoutFields.prototype.first_name=function(){return{set:function(t,e){this.fields.set(e+"_first_name",t)},get:function(t){return this.fields.get(t+"_first_name")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.last_name=function(){return{set:function(t,e){this.fields.set(e+"_last_name",t)},get:function(t){return this.fields.get(t+"_last_name")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.address_1=function(){return{set:function(t,e){this.fields.set(e+"_address_1",t)},get:function(t){return this.fields.get(t+"_address_1")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.address_2=function(){return{set:function(t,e){this.fields.set(e+"_address_2",t)},get:function(t){return this.fields.get(t+"_address_2")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.name=function(){return{set:function(t,e){t=t.split(" ");0<t.length&&this.fields.set(e+"_first_name",t[0]),1<t.length&&this.fields.set(e+"_last_name",t[1])},get:function(t){return this.fields.get(t+"_first_name")+" "+this.fields.get(t+"_last_name")}}},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")},isValid:function(t){return"string"==typeof t&&0<t.length}}},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")},isValid:function(t){return"string"==typeof t&&0<t.length}}},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")},isValid:function(t){return"string"==typeof t&&2===t.length}}},wc_stripe.CheckoutFields.prototype.state=function(){return{set:function(i,t){2<(i=i.toUpperCase()).length&&"checkout"===this.page&&o("#"+t+"_state option").each(function(){var t=o(this),e=t.text().toUpperCase();i===e&&(i=t.val())}),this.fields.set(t+"_state",i)},get:function(t){return this.fields.get(t+"_state")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.city=function(){return{set:function(t,e){this.fields.set(e+"_city",t)},get:function(t){return this.fields.get(t+"_city")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.postcode=function(){return{set:function(t,e){this.fields.set(e+"_postcode",t)},get:function(t){return this.fields.get(t+"_postcode")},isValid:function(t){return"string"==typeof t&&0<t.length}}},wc_stripe.CheckoutFields.prototype.recipient=function(){return wc_stripe.CheckoutFields.prototype.name.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.payerName=function(){return wc_stripe.CheckoutFields.prototype.name.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.payerEmail=function(){return wc_stripe.CheckoutFields.prototype.email.apply(this,arguments)},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.countryCode=function(){return wc_stripe.CheckoutFields.prototype.country.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.address1=function(){return wc_stripe.CheckoutFields.prototype.address_1.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.address2=function(){return wc_stripe.CheckoutFields.prototype.address_2.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.line1=function(){return wc_stripe.CheckoutFields.prototype.address_1.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.line2=function(){return wc_stripe.CheckoutFields.prototype.address_2.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.addressLine=function(){return{set:function(t,e){0<t.length&&this.fields.set(e+"_address_1",t[0]),1<t.length&&this.fields.set(e+"_address_2",t[1])},get:function(t){return[this.fields.get(t+"_address_1"),this.fields.get(t+"_address_2")]},isValid:function(t){return 0<t.length&&("string"==typeof t[0]&&0<t[0].length)}}},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.locality=function(){return wc_stripe.CheckoutFields.prototype.city.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.postal_code=function(){return wc_stripe.CheckoutFields.prototype.postcode.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.postalCode=function(){return wc_stripe.CheckoutFields.prototype.postcode.apply(this,arguments)},wc_stripe.CheckoutFields.prototype.toJson=function(){var i={};return this.fields.forEach(function(t,e){i[e]=t}),i},wc_stripe.CheckoutFields.prototype.toFormFields=function(t){var i=[];this.fields.forEach(function(t,e){e='[name="'+e+'"]';o(e).length&&""!==t&&(o(e).val()!==t&&o(e).is("select")&&i.push(e),o(e).val(t))}),0<i.length&&o(i.join(",")).trigger("change"),void 0!==t&&o(document.body).trigger("update_checkout",t)},wc_stripe.CheckoutFields.prototype.validateFields=function(t){for(var e in this.params){var i=this.params[e];if(-1<e.indexOf(t)&&i.required&&o("#"+e).length&&o("#"+e).is(":visible")){i=o("#"+e).val();if(null==i||0===i.length)return!1}}return!0};try{s=Stripe(wc_stripe_params_v3.api_key,{stripeAccount:wc_stripe_params_v3.account})}catch(t){return i.alert(t),console.log(t)}var r=new wc_stripe.CheckoutFields(wc_stripe_checkout_fields,wc_stripe_params_v3.page)}(window,jQuery);
i18n/languages/woo-stripe-payment.pot CHANGED
@@ -2,14 +2,14 @@
2
  # This file is distributed under the same license as the Stripe For WooCommerce plugin.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Stripe For WooCommerce 3.2.6\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woo-stripe-payment\n"
7
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
8
  "Language-Team: LANGUAGE <LL@li.org>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
- "POT-Creation-Date: 2020-10-29T01:39:02+00:00\n"
13
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
  "X-Generator: WP-CLI 2.4.0\n"
15
  "X-Domain: woo-stripe-payment\n"
@@ -30,7 +30,7 @@ msgstr ""
30
  msgid "Payment Plugins, support@paymentplugins.com"
31
  msgstr ""
32
 
33
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:103
34
  #: includes/admin/meta-boxes/views/html-product-data.php:14
35
  #: includes/gateways/settings/ach-settings-v2.php:9
36
  #: includes/gateways/settings/ach-settings.php:9
@@ -41,11 +41,11 @@ msgstr ""
41
  msgid "Enabled"
42
  msgstr ""
43
 
44
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:108
45
  msgid "If enabled, your site can accept %s payments through Stripe."
46
  msgstr ""
47
 
48
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:112
49
  #: includes/gateways/settings/ach-settings-v2.php:64
50
  #: includes/gateways/settings/ach-settings.php:66
51
  #: includes/gateways/settings/applepay-settings.php:20
@@ -55,7 +55,7 @@ msgstr ""
55
  msgid "General Settings"
56
  msgstr ""
57
 
58
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:116
59
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:47
60
  #: includes/gateways/settings/ach-settings-v2.php:68
61
  #: includes/gateways/settings/ach-settings.php:70
@@ -66,7 +66,7 @@ msgstr ""
66
  msgid "Title"
67
  msgstr ""
68
 
69
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:122
70
  #: includes/gateways/settings/ach-settings-v2.php:74
71
  #: includes/gateways/settings/ach-settings.php:76
72
  #: includes/gateways/settings/applepay-settings.php:30
@@ -76,7 +76,7 @@ msgstr ""
76
  msgid "Description"
77
  msgstr ""
78
 
79
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:125
80
  #: includes/gateways/settings/ach-settings-v2.php:77
81
  #: includes/gateways/settings/ach-settings.php:79
82
  #: includes/gateways/settings/applepay-settings.php:33
@@ -86,15 +86,15 @@ msgstr ""
86
  msgid "Leave blank if you don't want a description to show for the gateway."
87
  msgstr ""
88
 
89
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:177
90
  msgid "Order %s"
91
  msgstr ""
92
 
93
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:277
94
  msgid "Gateway will appear when store currency is <strong>%s</strong>"
95
  msgstr ""
96
 
97
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:280
98
  msgid " & billing country is <strong>%s</strong>"
99
  msgstr ""
100
 
@@ -103,144 +103,144 @@ msgid "Please fill out all required fields."
103
  msgstr ""
104
 
105
  #: includes/abstract/abstract-wc-payment-gateway-stripe.php:422
106
- #: includes/controllers/class-wc-stripe-controller-cart.php:136
107
- #: includes/controllers/class-wc-stripe-controller-cart.php:196
108
- #: includes/controllers/class-wc-stripe-controller-googlepay.php:137
109
  #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:103
110
  msgid "Total"
111
  msgstr ""
112
 
113
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:482
114
  msgid "User must be logged in."
115
  msgstr ""
116
 
117
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:494
118
  msgid "Error saving your payment method. Reason: %s"
119
  msgstr ""
120
 
121
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:509
122
  msgid "Error saving payment method. Reason: %s"
123
  msgstr ""
124
 
125
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:528
126
  msgid "Order refunded in Stripe. Amount: %s"
127
  msgstr ""
128
 
129
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:566
130
  msgid "Order amount captured in Stripe. Amount: %s"
131
  msgstr ""
132
 
133
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:576
134
  msgid "Error capturing charge in Stripe. Reason: %s"
135
  msgstr ""
136
 
137
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:597
138
  msgid "Error voiding charge. Reason: %s"
139
  msgstr ""
140
 
141
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:599
142
  msgid "Charge voided in Stripe."
143
  msgstr ""
144
 
145
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:769
146
  msgid "n/a"
147
  msgstr ""
148
 
149
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:797
150
  #: includes/admin/meta-boxes/views/html-order-pay.php:42
151
  msgid "New Card"
152
  msgstr ""
153
 
154
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:801
155
  #: includes/admin/meta-boxes/views/html-order-pay.php:30
156
  msgid "Saved Cards"
157
  msgstr ""
158
 
159
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1008
160
  msgid "Attemp to save payment method failed. Reason: %s"
161
  msgstr ""
162
 
163
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1030
164
  msgid "We were not able to save your payment method. To prevent billing issues with your subscription, please add a payment method to the subscription."
165
  msgstr ""
166
 
167
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1032
168
  msgid "We were not able to save your payment method. Reason: %s"
169
  msgstr ""
170
 
171
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1066
172
  msgid "Payment Method Token"
173
  msgstr ""
174
 
175
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1086
176
  msgid "Recurring payment for order failed. Reason: %s"
177
  msgstr ""
178
 
179
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1099
180
  msgid "Recurring payment captured in Stripe. Payment method: %s"
181
  msgstr ""
182
 
183
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1101
184
  msgid "Recurring payment authorized in Stripe. Payment method: %s"
185
  msgstr ""
186
 
187
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1104
188
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1363
189
  msgid "Customer must manually complete payment for payment method %s"
190
  msgstr ""
191
 
192
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1120
193
  msgid "Error saving payment method for subscription. Reason: %s"
194
  msgstr ""
195
 
196
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1181
197
  #: includes/abstract/abstract-wc-stripe-payment.php:219
198
  msgid "Order %1$s from %2$s"
199
  msgstr ""
200
 
201
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1350
202
  msgid "Pre-order payment for order failed. Reason: %s"
203
  msgstr ""
204
 
205
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1358
206
  msgid "Pre-order payment captured in Stripe. Payment method: %s"
207
  msgstr ""
208
 
209
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1360
210
  msgid "Pre-order payment authorized in Stripe. Payment method: %s"
211
  msgstr ""
212
 
213
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1432
214
  msgid "Cannot process payment"
215
  msgstr ""
216
 
217
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1440
218
  msgid "Increase your conversion rate by offering %1$s on your Product and Cart pages, or at the top of the checkout page. <br/><strong>Note:</strong> you can control which products display %s by going to the product edit page."
219
  msgstr ""
220
 
221
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1551
222
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1582
223
  #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:189
224
  #: includes/wc-stripe-functions.php:405
225
  #: includes/wc-stripe-functions.php:470
226
  msgid "Shipping"
227
  msgstr ""
228
 
229
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1559
230
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1585
231
  #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:199
232
  #: includes/wc-stripe-functions.php:422
233
  #: includes/wc-stripe-functions.php:478
234
  msgid "Discount"
235
  msgstr ""
236
 
237
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1562
238
  #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:221
239
  #: includes/wc-stripe-functions.php:430
240
  msgid "Tax"
241
  msgstr ""
242
 
243
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1592
244
  #: includes/wc-stripe-functions.php:489
245
  msgid "Fees"
246
  msgstr ""
@@ -266,12 +266,13 @@ msgid "Transaction Id cannot be empty."
266
  msgstr ""
267
 
268
  #: includes/abstract/abstract-wc-stripe-payment.php:286
269
- #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:116
270
  msgid "Error processing payment. Reason: %s"
271
  msgstr ""
272
 
273
  #: includes/abstract/abstract-wc-stripe-rest-controller.php:58
274
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:26
 
275
  msgid "You do not have permissions to access this resource."
276
  msgstr ""
277
 
@@ -301,19 +302,19 @@ msgid ""
301
  " Stripe is requesting that all merchants switch. %1$sUpdate Integration%2$s"
302
  msgstr ""
303
 
304
- #: includes/admin/class-wc-stripe-admin-settings.php:72
305
  msgid "Local Gateways"
306
  msgstr ""
307
 
308
- #: includes/admin/class-wc-stripe-admin-settings.php:88
309
  msgid "Stripe Email Options"
310
  msgstr ""
311
 
312
- #: includes/admin/class-wc-stripe-admin-settings.php:92
313
  msgid "Email Receipt"
314
  msgstr ""
315
 
316
- #: includes/admin/class-wc-stripe-admin-settings.php:95
317
  msgid "If enabled, an email receipt will be sent to the customer by Stripe when the order is processed."
318
  msgstr ""
319
 
@@ -357,7 +358,7 @@ msgstr ""
357
 
358
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:25
359
  #: includes/admin/settings/class-wc-stripe-api-settings.php:38
360
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:190
361
  msgid "Live"
362
  msgstr ""
363
 
@@ -515,7 +516,7 @@ msgid "API Settings"
515
  msgstr ""
516
 
517
  #: includes/admin/settings/class-wc-stripe-api-settings.php:37
518
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:190
519
  msgid "Test"
520
  msgstr ""
521
 
@@ -690,7 +691,7 @@ msgstr ""
690
  msgid "Payment authorization failed."
691
  msgstr ""
692
 
693
- #: includes/class-wc-stripe-rest-api.php:42
694
  msgid "%1$s is an invalid controller name."
695
  msgstr ""
696
 
@@ -702,48 +703,48 @@ msgstr ""
702
  msgid "Quantity must be greater than zero."
703
  msgstr ""
704
 
705
- #: includes/controllers/class-wc-stripe-controller-checkout.php:273
706
  msgid "Some required fields were missing. Please click %1$shere%2$s to complete your payment."
707
  msgstr ""
708
 
709
- #: includes/controllers/class-wc-stripe-controller-checkout.php:322
710
  msgid "Please review your order details then click Place Order."
711
  msgstr ""
712
 
713
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:88
714
  msgid "You cannot register your domain until you have configured your Live API keys."
715
  msgstr ""
716
 
717
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:117
718
  msgid "Domain registered successfully. You can confirm in your Stripe Dashboard at https://dashboard.stripe.com/account/apple_pay."
719
  msgstr ""
720
 
721
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:141
722
  msgid "You must configure your secret key before creating webhooks."
723
  msgstr ""
724
 
725
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:154
726
  msgid "There is already a webhook configured for this site. If you want to delete the webhook, login to your Stripe Dashboard."
727
  msgstr ""
728
 
729
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:188
730
  msgid "Webhook created in Stripe for %s environment. You can test your webhook by logging in to the Stripe dashboard"
731
  msgstr ""
732
 
733
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:211
734
  msgid "Mode: %s. Invalid secret key. Please check your entry."
735
  msgstr ""
736
 
737
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:223
738
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:226
739
  msgid "Mode: %s. Invalid publishable key. Please check your entry."
740
  msgstr ""
741
 
742
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:232
743
  msgid "Connection test to Stripe was successful. Mode: %s."
744
  msgstr ""
745
 
746
- #: includes/controllers/class-wc-stripe-controller-googlepay.php:87
747
  msgid "Your shipping address is not serviceable."
748
  msgstr ""
749
 
@@ -751,16 +752,16 @@ msgstr ""
751
  msgid "Invalid amount entered."
752
  msgstr ""
753
 
754
- #: includes/controllers/class-wc-stripe-controller-order-actions.php:182
755
- #: includes/controllers/class-wc-stripe-controller-order-actions.php:185
756
  msgid "Order total must be greater than zero."
757
  msgstr ""
758
 
759
- #: includes/controllers/class-wc-stripe-controller-order-actions.php:195
760
  msgid "This order has already been processed. Transaction ID: %1$s. Payment method: %2$s"
761
  msgstr ""
762
 
763
- #: includes/controllers/class-wc-stripe-controller-order-actions.php:204
764
  msgid "Order customer Id and payment method customer Id do not match."
765
  msgstr ""
766
 
@@ -797,15 +798,15 @@ msgstr ""
797
  msgid "Bank Payment"
798
  msgstr ""
799
 
800
- #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:242
801
  msgid "Saved Banks"
802
  msgstr ""
803
 
804
- #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:246
805
  msgid "New Bank"
806
  msgstr ""
807
 
808
- #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:290
809
  msgid "You must set the API mode to live in order to enable the Plaid development environment."
810
  msgstr ""
811
 
2
  # This file is distributed under the same license as the Stripe For WooCommerce plugin.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Stripe For WooCommerce 3.2.7\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woo-stripe-payment\n"
7
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
8
  "Language-Team: LANGUAGE <LL@li.org>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
+ "POT-Creation-Date: 2020-11-08T03:34:23+00:00\n"
13
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
  "X-Generator: WP-CLI 2.4.0\n"
15
  "X-Domain: woo-stripe-payment\n"
30
  msgid "Payment Plugins, support@paymentplugins.com"
31
  msgstr ""
32
 
33
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:102
34
  #: includes/admin/meta-boxes/views/html-product-data.php:14
35
  #: includes/gateways/settings/ach-settings-v2.php:9
36
  #: includes/gateways/settings/ach-settings.php:9
41
  msgid "Enabled"
42
  msgstr ""
43
 
44
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:107
45
  msgid "If enabled, your site can accept %s payments through Stripe."
46
  msgstr ""
47
 
48
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:111
49
  #: includes/gateways/settings/ach-settings-v2.php:64
50
  #: includes/gateways/settings/ach-settings.php:66
51
  #: includes/gateways/settings/applepay-settings.php:20
55
  msgid "General Settings"
56
  msgstr ""
57
 
58
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:115
59
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:47
60
  #: includes/gateways/settings/ach-settings-v2.php:68
61
  #: includes/gateways/settings/ach-settings.php:70
66
  msgid "Title"
67
  msgstr ""
68
 
69
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:121
70
  #: includes/gateways/settings/ach-settings-v2.php:74
71
  #: includes/gateways/settings/ach-settings.php:76
72
  #: includes/gateways/settings/applepay-settings.php:30
76
  msgid "Description"
77
  msgstr ""
78
 
79
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:124
80
  #: includes/gateways/settings/ach-settings-v2.php:77
81
  #: includes/gateways/settings/ach-settings.php:79
82
  #: includes/gateways/settings/applepay-settings.php:33
86
  msgid "Leave blank if you don't want a description to show for the gateway."
87
  msgstr ""
88
 
89
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:176
90
  msgid "Order %s"
91
  msgstr ""
92
 
93
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:276
94
  msgid "Gateway will appear when store currency is <strong>%s</strong>"
95
  msgstr ""
96
 
97
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:279
98
  msgid " & billing country is <strong>%s</strong>"
99
  msgstr ""
100
 
103
  msgstr ""
104
 
105
  #: includes/abstract/abstract-wc-payment-gateway-stripe.php:422
106
+ #: includes/controllers/class-wc-stripe-controller-cart.php:134
107
+ #: includes/controllers/class-wc-stripe-controller-cart.php:192
108
+ #: includes/controllers/class-wc-stripe-controller-googlepay.php:135
109
  #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:103
110
  msgid "Total"
111
  msgstr ""
112
 
113
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:491
114
  msgid "User must be logged in."
115
  msgstr ""
116
 
117
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:503
118
  msgid "Error saving your payment method. Reason: %s"
119
  msgstr ""
120
 
121
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:518
122
  msgid "Error saving payment method. Reason: %s"
123
  msgstr ""
124
 
125
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:537
126
  msgid "Order refunded in Stripe. Amount: %s"
127
  msgstr ""
128
 
129
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:575
130
  msgid "Order amount captured in Stripe. Amount: %s"
131
  msgstr ""
132
 
133
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:585
134
  msgid "Error capturing charge in Stripe. Reason: %s"
135
  msgstr ""
136
 
137
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:606
138
  msgid "Error voiding charge. Reason: %s"
139
  msgstr ""
140
 
141
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:608
142
  msgid "Charge voided in Stripe."
143
  msgstr ""
144
 
145
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:778
146
  msgid "n/a"
147
  msgstr ""
148
 
149
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:806
150
  #: includes/admin/meta-boxes/views/html-order-pay.php:42
151
  msgid "New Card"
152
  msgstr ""
153
 
154
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:810
155
  #: includes/admin/meta-boxes/views/html-order-pay.php:30
156
  msgid "Saved Cards"
157
  msgstr ""
158
 
159
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1017
160
  msgid "Attemp to save payment method failed. Reason: %s"
161
  msgstr ""
162
 
163
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1039
164
  msgid "We were not able to save your payment method. To prevent billing issues with your subscription, please add a payment method to the subscription."
165
  msgstr ""
166
 
167
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1041
168
  msgid "We were not able to save your payment method. Reason: %s"
169
  msgstr ""
170
 
171
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1075
172
  msgid "Payment Method Token"
173
  msgstr ""
174
 
175
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1095
176
  msgid "Recurring payment for order failed. Reason: %s"
177
  msgstr ""
178
 
179
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1108
180
  msgid "Recurring payment captured in Stripe. Payment method: %s"
181
  msgstr ""
182
 
183
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1110
184
  msgid "Recurring payment authorized in Stripe. Payment method: %s"
185
  msgstr ""
186
 
187
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1113
188
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1381
189
  msgid "Customer must manually complete payment for payment method %s"
190
  msgstr ""
191
 
192
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1129
193
  msgid "Error saving payment method for subscription. Reason: %s"
194
  msgstr ""
195
 
196
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1190
197
  #: includes/abstract/abstract-wc-stripe-payment.php:219
198
  msgid "Order %1$s from %2$s"
199
  msgstr ""
200
 
201
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1368
202
  msgid "Pre-order payment for order failed. Reason: %s"
203
  msgstr ""
204
 
205
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1376
206
  msgid "Pre-order payment captured in Stripe. Payment method: %s"
207
  msgstr ""
208
 
209
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1378
210
  msgid "Pre-order payment authorized in Stripe. Payment method: %s"
211
  msgstr ""
212
 
213
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1450
214
  msgid "Cannot process payment"
215
  msgstr ""
216
 
217
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1458
218
  msgid "Increase your conversion rate by offering %1$s on your Product and Cart pages, or at the top of the checkout page. <br/><strong>Note:</strong> you can control which products display %s by going to the product edit page."
219
  msgstr ""
220
 
221
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1569
222
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1600
223
  #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:189
224
  #: includes/wc-stripe-functions.php:405
225
  #: includes/wc-stripe-functions.php:470
226
  msgid "Shipping"
227
  msgstr ""
228
 
229
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1577
230
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1603
231
  #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:199
232
  #: includes/wc-stripe-functions.php:422
233
  #: includes/wc-stripe-functions.php:478
234
  msgid "Discount"
235
  msgstr ""
236
 
237
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1580
238
  #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:221
239
  #: includes/wc-stripe-functions.php:430
240
  msgid "Tax"
241
  msgstr ""
242
 
243
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1610
244
  #: includes/wc-stripe-functions.php:489
245
  msgid "Fees"
246
  msgstr ""
266
  msgstr ""
267
 
268
  #: includes/abstract/abstract-wc-stripe-payment.php:286
269
+ #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:122
270
  msgid "Error processing payment. Reason: %s"
271
  msgstr ""
272
 
273
  #: includes/abstract/abstract-wc-stripe-rest-controller.php:58
274
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:234
275
+ #: includes/controllers/class-wc-stripe-controller-order-actions.php:325
276
  msgid "You do not have permissions to access this resource."
277
  msgstr ""
278
 
302
  " Stripe is requesting that all merchants switch. %1$sUpdate Integration%2$s"
303
  msgstr ""
304
 
305
+ #: includes/admin/class-wc-stripe-admin-settings.php:71
306
  msgid "Local Gateways"
307
  msgstr ""
308
 
309
+ #: includes/admin/class-wc-stripe-admin-settings.php:87
310
  msgid "Stripe Email Options"
311
  msgstr ""
312
 
313
+ #: includes/admin/class-wc-stripe-admin-settings.php:91
314
  msgid "Email Receipt"
315
  msgstr ""
316
 
317
+ #: includes/admin/class-wc-stripe-admin-settings.php:94
318
  msgid "If enabled, an email receipt will be sent to the customer by Stripe when the order is processed."
319
  msgstr ""
320
 
358
 
359
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:25
360
  #: includes/admin/settings/class-wc-stripe-api-settings.php:38
361
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:184
362
  msgid "Live"
363
  msgstr ""
364
 
516
  msgstr ""
517
 
518
  #: includes/admin/settings/class-wc-stripe-api-settings.php:37
519
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:184
520
  msgid "Test"
521
  msgstr ""
522
 
691
  msgid "Payment authorization failed."
692
  msgstr ""
693
 
694
+ #: includes/class-wc-stripe-rest-api.php:39
695
  msgid "%1$s is an invalid controller name."
696
  msgstr ""
697
 
703
  msgid "Quantity must be greater than zero."
704
  msgstr ""
705
 
706
+ #: includes/controllers/class-wc-stripe-controller-checkout.php:263
707
  msgid "Some required fields were missing. Please click %1$shere%2$s to complete your payment."
708
  msgstr ""
709
 
710
+ #: includes/controllers/class-wc-stripe-controller-checkout.php:312
711
  msgid "Please review your order details then click Place Order."
712
  msgstr ""
713
 
714
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:82
715
  msgid "You cannot register your domain until you have configured your Live API keys."
716
  msgstr ""
717
 
718
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:111
719
  msgid "Domain registered successfully. You can confirm in your Stripe Dashboard at https://dashboard.stripe.com/account/apple_pay."
720
  msgstr ""
721
 
722
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:135
723
  msgid "You must configure your secret key before creating webhooks."
724
  msgstr ""
725
 
726
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:148
727
  msgid "There is already a webhook configured for this site. If you want to delete the webhook, login to your Stripe Dashboard."
728
  msgstr ""
729
 
730
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:182
731
  msgid "Webhook created in Stripe for %s environment. You can test your webhook by logging in to the Stripe dashboard"
732
  msgstr ""
733
 
734
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:205
735
  msgid "Mode: %s. Invalid secret key. Please check your entry."
736
  msgstr ""
737
 
738
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:217
739
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:220
740
  msgid "Mode: %s. Invalid publishable key. Please check your entry."
741
  msgstr ""
742
 
743
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:226
744
  msgid "Connection test to Stripe was successful. Mode: %s."
745
  msgstr ""
746
 
747
+ #: includes/controllers/class-wc-stripe-controller-googlepay.php:85
748
  msgid "Your shipping address is not serviceable."
749
  msgstr ""
750
 
752
  msgid "Invalid amount entered."
753
  msgstr ""
754
 
755
+ #: includes/controllers/class-wc-stripe-controller-order-actions.php:181
756
+ #: includes/controllers/class-wc-stripe-controller-order-actions.php:184
757
  msgid "Order total must be greater than zero."
758
  msgstr ""
759
 
760
+ #: includes/controllers/class-wc-stripe-controller-order-actions.php:194
761
  msgid "This order has already been processed. Transaction ID: %1$s. Payment method: %2$s"
762
  msgstr ""
763
 
764
+ #: includes/controllers/class-wc-stripe-controller-order-actions.php:203
765
  msgid "Order customer Id and payment method customer Id do not match."
766
  msgstr ""
767
 
798
  msgid "Bank Payment"
799
  msgstr ""
800
 
801
+ #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:248
802
  msgid "Saved Banks"
803
  msgstr ""
804
 
805
+ #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:252
806
  msgid "New Bank"
807
  msgstr ""
808
 
809
+ #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:296
810
  msgid "You must set the API mode to live in order to enable the Plaid development environment."
811
  msgstr ""
812
 
includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php CHANGED
@@ -42,7 +42,6 @@ abstract class WC_Payment_Gateway_Stripe_Local_Payment extends WC_Payment_Gatewa
42
  add_filter( 'wc_stripe_local_gateway_tabs', array( $this, 'local_gateway_tab' ) );
43
  remove_filter( 'wc_stripe_settings_nav_tabs', array( $this, 'admin_nav_tab' ) );
44
  add_filter( 'wc_stripe_local_gateways_tab', array( $this, 'admin_nav_tab' ) );
45
- add_action( 'woocommerce_update_options_checkout_' . $this->id, array( $this, 'process_admin_options' ) );
46
  }
47
 
48
  /**
@@ -142,8 +141,8 @@ abstract class WC_Payment_Gateway_Stripe_Local_Payment extends WC_Payment_Gatewa
142
  ),
143
  'element_params' => $this->get_element_params(),
144
  'routes' => array(
145
- 'order_pay' => wc_stripe()->rest_api->checkout->rest_url( 'order-pay' ),
146
- 'delete_source' => wc_stripe()->rest_api->checkout->rest_url( 'source' )
147
  )
148
  )
149
  );
42
  add_filter( 'wc_stripe_local_gateway_tabs', array( $this, 'local_gateway_tab' ) );
43
  remove_filter( 'wc_stripe_settings_nav_tabs', array( $this, 'admin_nav_tab' ) );
44
  add_filter( 'wc_stripe_local_gateways_tab', array( $this, 'admin_nav_tab' ) );
 
45
  }
46
 
47
  /**
141
  ),
142
  'element_params' => $this->get_element_params(),
143
  'routes' => array(
144
+ 'order_pay' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->checkout->rest_uri( 'order-pay' ) ),
145
+ 'delete_source' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->checkout->rest_uri( 'source' ) )
146
  )
147
  )
148
  );
includes/abstract/abstract-wc-payment-gateway-stripe.php CHANGED
@@ -407,14 +407,14 @@ abstract class WC_Payment_Gateway_Stripe extends WC_Payment_Gateway {
407
  'required_field' => __( 'Please fill out all required fields.', 'woo-stripe-payment' )
408
  ),
409
  'routes' => array(
410
- 'setup_intent' => wc_stripe()->rest_api->payment_intent->rest_url( 'setup-intent' ),
411
- 'sync_intent' => wc_stripe()->rest_api->payment_intent->rest_url( 'sync-payment-intent' ),
412
- 'add_to_cart' => wc_stripe()->rest_api->cart->rest_url( 'add-to-cart' ),
413
- 'cart_calculation' => wc_stripe()->rest_api->cart->rest_url( 'cart-calculation' ),
414
- 'shipping_method' => wc_stripe()->rest_api->cart->rest_url( 'shipping-method' ),
415
- 'shipping_address' => wc_stripe()->rest_api->cart->rest_url( 'shipping-address' ),
416
- 'checkout' => wc_stripe()->rest_api->checkout->rest_url( 'checkout' ),
417
- 'checkout_payment' => wc_stripe()->rest_api->checkout->rest_url( 'checkout/payment' )
418
  ),
419
  'rest_nonce' => wp_create_nonce( 'wp_rest' ),
420
  'banner_enabled' => $this->banner_checkout_enabled(),
@@ -442,7 +442,6 @@ abstract class WC_Payment_Gateway_Stripe extends WC_Payment_Gateway {
442
  $order->update_meta_data( WC_Stripe_Constants::MODE, wc_stripe_mode() );
443
  $order->update_meta_data( WC_Stripe_Constants::CHARGE_STATUS, $charge->status );
444
  $order->update_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token() );
445
- $order->save();
446
 
447
  // if WCS is active and there are subscriptions in the order, save meta data
448
  if ( wcs_stripe_active() && wcs_order_contains_subscription( $order ) ) {
@@ -456,6 +455,16 @@ abstract class WC_Payment_Gateway_Stripe extends WC_Payment_Gateway {
456
  $subscription->save();
457
  }
458
  }
 
 
 
 
 
 
 
 
 
 
459
  }
460
 
461
  /**
@@ -1244,7 +1253,6 @@ abstract class WC_Payment_Gateway_Stripe extends WC_Payment_Gateway {
1244
  $order->update_meta_data( WC_Stripe_Constants::MODE, wc_stripe_mode() );
1245
  $order->update_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token() );
1246
  $order->update_meta_data( WC_Stripe_Constants::CUSTOMER_ID, wc_stripe_get_customer_id( $order->get_user_id() ) );
1247
- $order->save();
1248
 
1249
  if ( wcs_stripe_active() && wcs_order_contains_subscription( $order ) ) {
1250
  foreach ( wcs_get_subscriptions_for_order( $order ) as $subscription ) {
@@ -1259,6 +1267,16 @@ abstract class WC_Payment_Gateway_Stripe extends WC_Payment_Gateway {
1259
  $subscription->save();
1260
  }
1261
  }
 
 
 
 
 
 
 
 
 
 
1262
  }
1263
 
1264
  /**
407
  'required_field' => __( 'Please fill out all required fields.', 'woo-stripe-payment' )
408
  ),
409
  'routes' => array(
410
+ 'setup_intent' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->payment_intent->rest_uri( 'setup-intent' ) ),
411
+ 'sync_intent' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->payment_intent->rest_uri( 'sync-payment-intent' ) ),
412
+ 'add_to_cart' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->cart->rest_uri( 'add-to-cart' ) ),
413
+ 'cart_calculation' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->cart->rest_uri( 'cart-calculation' ) ),
414
+ 'shipping_method' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->cart->rest_uri( 'shipping-method' ) ),
415
+ 'shipping_address' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->cart->rest_uri( 'shipping-address' ) ),
416
+ 'checkout' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->checkout->rest_uri( 'checkout' ) ),
417
+ 'checkout_payment' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->checkout->rest_uri( 'checkout/payment' ) )
418
  ),
419
  'rest_nonce' => wp_create_nonce( 'wp_rest' ),
420
  'banner_enabled' => $this->banner_checkout_enabled(),
442
  $order->update_meta_data( WC_Stripe_Constants::MODE, wc_stripe_mode() );
443
  $order->update_meta_data( WC_Stripe_Constants::CHARGE_STATUS, $charge->status );
444
  $order->update_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token() );
 
445
 
446
  // if WCS is active and there are subscriptions in the order, save meta data
447
  if ( wcs_stripe_active() && wcs_order_contains_subscription( $order ) ) {
455
  $subscription->save();
456
  }
457
  }
458
+ /**
459
+ * @param WC_Order $order
460
+ * @param WC_Payment_Gateway_Stripe $this
461
+ * @param \Stripe\Charge $charge
462
+ *
463
+ * @since 3.2.7
464
+ */
465
+ do_action( 'wc_stripe_save_order_meta', $order, $this, $charge );
466
+
467
+ $order->save();
468
  }
469
 
470
  /**
1253
  $order->update_meta_data( WC_Stripe_Constants::MODE, wc_stripe_mode() );
1254
  $order->update_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token() );
1255
  $order->update_meta_data( WC_Stripe_Constants::CUSTOMER_ID, wc_stripe_get_customer_id( $order->get_user_id() ) );
 
1256
 
1257
  if ( wcs_stripe_active() && wcs_order_contains_subscription( $order ) ) {
1258
  foreach ( wcs_get_subscriptions_for_order( $order ) as $subscription ) {
1267
  $subscription->save();
1268
  }
1269
  }
1270
+ /**
1271
+ * @param WC_Order $order
1272
+ * @param WC_Payment_Gateway_Stripe $this
1273
+ * @param null $charge
1274
+ *
1275
+ * @since 3.2.7
1276
+ */
1277
+ do_action( 'wc_stripe_save_order_meta', $order, $this, null );
1278
+
1279
+ $order->save();
1280
  }
1281
 
1282
  /**
includes/admin/class-wc-stripe-admin-assets.php CHANGED
@@ -1,110 +1,110 @@
1
- <?php
2
- defined( 'ABSPATH' ) || exit();
3
-
4
- /**
5
- *
6
- * @package Stripe/Admin
7
- */
8
- class WC_Stripe_Admin_Assets {
9
-
10
- public function __construct() {
11
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
12
-
13
- add_action( 'wp_print_scripts', array( __CLASS__, 'localize_scripts' ) );
14
-
15
- add_action( 'admin_footer', array( __CLASS__, 'localize_scripts' ) );
16
- add_action( 'wc_stripe_localize_stripe_advanced_settings', array( __CLASS__, 'localize_advanced_scripts' ) );
17
- }
18
-
19
- public function enqueue_scripts() {
20
- global $current_section, $wc_stripe_subsection;
21
- $screen = get_current_screen();
22
- $screen_id = $screen ? $screen->id : '';
23
- $js_path = wc_stripe()->assets_url() . 'js/';
24
- $css_path = wc_stripe()->assets_url() . 'css/';
25
-
26
- wp_register_script( 'wc-stripe-admin-settings', $js_path . 'admin/admin-settings.js', array(
27
- 'jquery',
28
- 'jquery-blockui'
29
- ), wc_stripe()->version, true );
30
- wp_register_script( 'wc-stripe-meta-boxes-order', $js_path . 'admin/meta-boxes-order.js', array(
31
- 'jquery',
32
- 'jquery-blockui'
33
- ), wc_stripe()->version, true );
34
- wp_register_script( 'wc-stripe-meta-boxes-subscription', $js_path . 'admin/meta-boxes-subscription.js', array(
35
- 'jquery',
36
- 'jquery-blockui'
37
- ), wc_stripe()->version, true );
38
- wp_register_script(
39
- 'wc-stripe-product-data',
40
- $js_path . 'admin/meta-boxes-product-data.js',
41
- array(
42
- 'jquery',
43
- 'jquery-blockui',
44
- 'jquery-ui-sortable',
45
- 'jquery-ui-widget',
46
- 'jquery-ui-core',
47
- 'jquery-tiptip',
48
- ),
49
- wc_stripe()->version(),
50
- true
51
- );
52
- wp_register_style( 'wc-stripe-admin-style', $css_path . 'admin/admin.css', array(), wc_stripe()->version );
53
-
54
- if ( strpos( $screen_id, 'wc-settings' ) !== false ) {
55
- if ( isset( $_REQUEST['section'] ) && preg_match( '/stripe_[\w]*/', $_REQUEST['section'] ) ) {
56
- wp_enqueue_script( 'wc-stripe-admin-settings' );
57
- wp_enqueue_style( 'wc-stripe-admin-style' );
58
- wp_style_add_data( 'wc-stripe-admin-style', 'rtl', 'replace' );
59
- wp_enqueue_script( 'stripe-help-widget', $js_path . 'admin/help-widget.js', array(), wc_stripe()->version(), true );
60
- wp_localize_script(
61
- 'wc-stripe-admin-settings',
62
- 'wc_stripe_setting_params',
63
- array(
64
- 'routes' => array(
65
- 'apple_domain' => wc_stripe()->rest_api->settings->rest_url( 'apple-domain' ),
66
- 'create_webhook' => wc_stripe()->rest_api->settings->rest_url( 'create-webook' ),
67
- 'connection_test' => wc_stripe()->rest_api->settings->rest_url( 'connection-test' ),
68
- ),
69
- 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
70
- )
71
- );
72
- }
73
- }
74
- if ( $screen_id === 'shop_order' ) {
75
- wp_enqueue_style( 'wc-stripe-admin-style' );
76
- }
77
- if ( $screen_id === 'product' ) {
78
- wp_enqueue_script( 'wc-stripe-product-data' );
79
- wp_enqueue_style( 'wc-stripe-admin-style' );
80
- wp_localize_script(
81
- 'wc-stripe-product-data',
82
- 'wc_stripe_product_params',
83
- array(
84
- '_wpnonce' => wp_create_nonce( 'wp_rest' ),
85
- 'routes' => array(
86
- 'enable_gateway' => wc_stripe()->rest_api->product_data->rest_url( 'gateway' ),
87
- 'save' => wc_stripe()->rest_api->product_data->rest_url( 'save' ),
88
- ),
89
- )
90
- );
91
- }
92
- }
93
-
94
- public static function localize_scripts() {
95
- global $current_section, $wc_stripe_subsection;
96
- if ( ! empty( $current_section ) ) {
97
- $wc_stripe_subsection = isset( $_GET['sub_section'] ) ? sanitize_title( $_GET['sub_section'] ) : '';
98
- do_action( 'wc_stripe_localize_' . $current_section . '_settings' );
99
- // added for WC 3.0.0 compatability.
100
- remove_action( 'admin_footer', array( __CLASS__, 'localize_scripts' ) );
101
- }
102
- }
103
-
104
- public static function localize_advanced_scripts() {
105
- global $current_section, $wc_stripe_subsection;
106
- do_action( 'wc_stripe_localize_' . $wc_stripe_subsection . '_settings' );
107
- }
108
- }
109
-
110
- new WC_Stripe_Admin_Assets();
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @package Stripe/Admin
7
+ */
8
+ class WC_Stripe_Admin_Assets {
9
+
10
+ public function __construct() {
11
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
12
+
13
+ add_action( 'wp_print_scripts', array( __CLASS__, 'localize_scripts' ) );
14
+
15
+ add_action( 'admin_footer', array( __CLASS__, 'localize_scripts' ) );
16
+ add_action( 'wc_stripe_localize_stripe_advanced_settings', array( __CLASS__, 'localize_advanced_scripts' ) );
17
+ }
18
+
19
+ public function enqueue_scripts() {
20
+ global $current_section, $wc_stripe_subsection;
21
+ $screen = get_current_screen();
22
+ $screen_id = $screen ? $screen->id : '';
23
+ $js_path = wc_stripe()->assets_url() . 'js/';
24
+ $css_path = wc_stripe()->assets_url() . 'css/';
25
+
26
+ wp_register_script( 'wc-stripe-admin-settings', $js_path . 'admin/admin-settings.js', array(
27
+ 'jquery',
28
+ 'jquery-blockui'
29
+ ), wc_stripe()->version, true );
30
+ wp_register_script( 'wc-stripe-meta-boxes-order', $js_path . 'admin/meta-boxes-order.js', array(
31
+ 'jquery',
32
+ 'jquery-blockui'
33
+ ), wc_stripe()->version, true );
34
+ wp_register_script( 'wc-stripe-meta-boxes-subscription', $js_path . 'admin/meta-boxes-subscription.js', array(
35
+ 'jquery',
36
+ 'jquery-blockui'
37
+ ), wc_stripe()->version, true );
38
+ wp_register_script(
39
+ 'wc-stripe-product-data',
40
+ $js_path . 'admin/meta-boxes-product-data.js',
41
+ array(
42
+ 'jquery',
43
+ 'jquery-blockui',
44
+ 'jquery-ui-sortable',
45
+ 'jquery-ui-widget',
46
+ 'jquery-ui-core',
47
+ 'jquery-tiptip',
48
+ ),
49
+ wc_stripe()->version(),
50
+ true
51
+ );
52
+ wp_register_style( 'wc-stripe-admin-style', $css_path . 'admin/admin.css', array(), wc_stripe()->version );
53
+
54
+ if ( strpos( $screen_id, 'wc-settings' ) !== false ) {
55
+ if ( isset( $_REQUEST['section'] ) && preg_match( '/stripe_[\w]*/', $_REQUEST['section'] ) ) {
56
+ wp_enqueue_script( 'wc-stripe-admin-settings' );
57
+ wp_enqueue_style( 'wc-stripe-admin-style' );
58
+ wp_style_add_data( 'wc-stripe-admin-style', 'rtl', 'replace' );
59
+ wp_enqueue_script( 'stripe-help-widget', $js_path . 'admin/help-widget.js', array(), wc_stripe()->version(), true );
60
+ wp_localize_script(
61
+ 'wc-stripe-admin-settings',
62
+ 'wc_stripe_setting_params',
63
+ array(
64
+ 'routes' => array(
65
+ 'apple_domain' => wc_stripe()->rest_api->settings->rest_url( 'apple-domain' ),
66
+ 'create_webhook' => wc_stripe()->rest_api->settings->rest_url( 'create-webook' ),
67
+ 'connection_test' => wc_stripe()->rest_api->settings->rest_url( 'connection-test' ),
68
+ ),
69
+ 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
70
+ )
71
+ );
72
+ }
73
+ }
74
+ if ( $screen_id === 'shop_order' ) {
75
+ wp_enqueue_style( 'wc-stripe-admin-style' );
76
+ }
77
+ if ( $screen_id === 'product' ) {
78
+ wp_enqueue_script( 'wc-stripe-product-data' );
79
+ wp_enqueue_style( 'wc-stripe-admin-style' );
80
+ wp_localize_script(
81
+ 'wc-stripe-product-data',
82
+ 'wc_stripe_product_params',
83
+ array(
84
+ '_wpnonce' => wp_create_nonce( 'wp_rest' ),
85
+ 'routes' => array(
86
+ 'enable_gateway' => wc_stripe()->rest_api->product_data->rest_url( 'gateway' ),
87
+ 'save' => wc_stripe()->rest_api->product_data->rest_url( 'save' ),
88
+ ),
89
+ )
90
+ );
91
+ }
92
+ }
93
+
94
+ public static function localize_scripts() {
95
+ global $current_section, $wc_stripe_subsection;
96
+ if ( ! empty( $current_section ) ) {
97
+ $wc_stripe_subsection = isset( $_GET['sub_section'] ) ? sanitize_title( $_GET['sub_section'] ) : '';
98
+ do_action( 'wc_stripe_localize_' . $current_section . '_settings' );
99
+ // added for WC 3.0.0 compatability.
100
+ remove_action( 'admin_footer', array( __CLASS__, 'localize_scripts' ) );
101
+ }
102
+ }
103
+
104
+ public static function localize_advanced_scripts() {
105
+ global $current_section, $wc_stripe_subsection;
106
+ do_action( 'wc_stripe_localize_' . $wc_stripe_subsection . '_settings' );
107
+ }
108
+ }
109
+
110
+ new WC_Stripe_Admin_Assets();
includes/admin/class-wc-stripe-admin-settings.php CHANGED
@@ -11,7 +11,6 @@ class WC_Stripe_Admin_Settings {
11
 
12
  public static function init() {
13
  add_action( 'woocommerce_settings_checkout', array( __CLASS__, 'output' ) );
14
- add_action( 'woocommerce_stripe_settings_checkout_stripe_advanced', array( __CLASS__, 'output_advanced_settings' ) );
15
  add_filter( 'wc_stripe_settings_nav_tabs', array( __CLASS__, 'admin_settings_tabs' ), 20 );
16
  add_action( 'woocommerce_update_options_checkout', array( __CLASS__, 'save' ) );
17
  add_filter( 'woocommerce_get_settings_email', array( __CLASS__, 'get_email_settings' ) );
11
 
12
  public static function init() {
13
  add_action( 'woocommerce_settings_checkout', array( __CLASS__, 'output' ) );
 
14
  add_filter( 'wc_stripe_settings_nav_tabs', array( __CLASS__, 'admin_settings_tabs' ), 20 );
15
  add_action( 'woocommerce_update_options_checkout', array( __CLASS__, 'save' ) );
16
  add_filter( 'woocommerce_get_settings_email', array( __CLASS__, 'get_email_settings' ) );
includes/admin/meta-boxes/class-wc-stripe-admin-order-metaboxes.php CHANGED
@@ -1,104 +1,111 @@
1
- <?php
2
- defined( 'ABSPATH' ) || exit();
3
-
4
- /**
5
- *
6
- * @package Stripe/Admin
7
- * @author PaymentPlugins
8
- *
9
- */
10
- class WC_Stripe_Admin_Order_Metaboxes {
11
-
12
- public static function init() {
13
- add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ), 10, 2 );
14
- }
15
-
16
- /**
17
- *
18
- * @param string $post_type
19
- * @param WP_Post $post
20
- */
21
- public static function add_meta_boxes( $post_type, $post ) {
22
- // only add meta box if shop_order and Stripe gateway was used.
23
- if ( $post_type !== 'shop_order' ) {
24
- return;
25
- }
26
-
27
- add_action( 'woocommerce_admin_order_data_after_order_details', array( __CLASS__, 'pay_order_section' ) );
28
-
29
- $order = wc_get_order( $post->ID );
30
- $payment_method = $order->get_payment_method();
31
- if ( $payment_method ) {
32
- $gateways = WC()->payment_gateways()->payment_gateways();
33
- if ( isset( $gateways[ $payment_method ] ) ) {
34
- $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
35
- if ( $gateway instanceof WC_Payment_Gateway_Stripe ) {
36
- add_action( 'woocommerce_admin_order_data_after_billing_address', array( __CLASS__, 'charge_data_view' ) );
37
- }
38
- }
39
- }
40
- self::enqueue_scripts();
41
- }
42
-
43
- /**
44
- *
45
- * @param WC_Order $order
46
- */
47
- public static function charge_data_view( $order ) {
48
- if ( ( $transaction_id = $order->get_transaction_id() ) ) {
49
- include 'views/html-order-charge-data.php';
50
- }
51
- }
52
-
53
- /**
54
- *
55
- * @param WC_Order $order
56
- */
57
- public static function pay_order_section( $order ) {
58
- if ( $order->get_type() === 'shop_order' && $order->has_status( array( 'pending', 'auto-draft' ) ) ) {
59
- include 'views/html-order-pay.php';
60
- $payment_methods = array();
61
- foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
62
- if ( $gateway instanceof WC_Payment_Gateway_Stripe ) {
63
- $payment_methods = array_merge( $payment_methods, WC_Payment_Tokens::get_customer_tokens( $order->get_user_id(), $gateway->id ) );
64
- }
65
- }
66
- wp_enqueue_script( 'wc-stripe-elements', 'https://js.stripe.com/v3/', array(), wc_stripe()->version, true );
67
- wp_localize_script(
68
- 'wc-stripe-elements',
69
- 'wc_stripe_order_pay_params',
70
- array(
71
- 'api_key' => wc_stripe_get_publishable_key(),
72
- 'payment_methods' => array_map(
73
- function ( $payment_method ) {
74
- return $payment_method->to_json();
75
- },
76
- $payment_methods
77
- ),
78
- 'order_status' => $order->get_status(),
79
- )
80
- );
81
- wp_enqueue_script( 'wc-stripe-admin-modals', wc_stripe()->assets_url( 'js/admin/modals.js' ), array( 'wc-backbone-modal', 'jquery-blockui' ), wc_stripe()->version, true );
82
- }
83
- }
84
-
85
- public static function enqueue_scripts() {
86
- wp_enqueue_script( 'wc-stripe-order-metabox', wc_stripe()->assets_url( 'js/admin/meta-boxes-order.js' ), array( 'jquery', 'jquery-blockui' ), wc_stripe()->version(), true );
87
-
88
- wp_localize_script(
89
- 'wc-stripe-order-metabox',
90
- 'wc_stripe_order_metabox_params',
91
- array(
92
- '_wpnonce' => wp_create_nonce( 'wp_rest' ),
93
- 'routes' => array(
94
- 'charge_view' => wc_stripe()->rest_api->order_actions->rest_url( 'charge-view' ),
95
- 'capture' => wc_stripe()->rest_api->order_actions->rest_url( 'capture' ),
96
- 'void' => wc_stripe()->rest_api->order_actions->rest_url( 'void' ),
97
- 'pay' => wc_stripe()->rest_api->order_actions->rest_url( 'pay' ),
98
- 'payment_methods' => wc_stripe()->rest_api->order_actions->rest_url( 'customer-payment-methods' ),
99
- ),
100
- )
101
- );
102
- }
103
- }
104
- WC_Stripe_Admin_Order_Metaboxes::init();
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @package Stripe/Admin
7
+ * @author PaymentPlugins
8
+ *
9
+ */
10
+ class WC_Stripe_Admin_Order_Metaboxes {
11
+
12
+ public static function init() {
13
+ add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ), 10, 2 );
14
+ }
15
+
16
+ /**
17
+ *
18
+ * @param string $post_type
19
+ * @param WP_Post $post
20
+ */
21
+ public static function add_meta_boxes( $post_type, $post ) {
22
+ // only add meta box if shop_order and Stripe gateway was used.
23
+ if ( $post_type !== 'shop_order' ) {
24
+ return;
25
+ }
26
+
27
+ add_action( 'woocommerce_admin_order_data_after_order_details', array( __CLASS__, 'pay_order_section' ) );
28
+
29
+ $order = wc_get_order( $post->ID );
30
+ $payment_method = $order->get_payment_method();
31
+ if ( $payment_method ) {
32
+ $gateways = WC()->payment_gateways()->payment_gateways();
33
+ if ( isset( $gateways[ $payment_method ] ) ) {
34
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
35
+ if ( $gateway instanceof WC_Payment_Gateway_Stripe ) {
36
+ add_action( 'woocommerce_admin_order_data_after_billing_address', array( __CLASS__, 'charge_data_view' ) );
37
+ }
38
+ }
39
+ }
40
+ self::enqueue_scripts();
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @param WC_Order $order
46
+ */
47
+ public static function charge_data_view( $order ) {
48
+ if ( ( $transaction_id = $order->get_transaction_id() ) ) {
49
+ include 'views/html-order-charge-data.php';
50
+ }
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @param WC_Order $order
56
+ */
57
+ public static function pay_order_section( $order ) {
58
+ if ( $order->get_type() === 'shop_order' && $order->has_status( array( 'pending', 'auto-draft' ) ) ) {
59
+ include 'views/html-order-pay.php';
60
+ $payment_methods = array();
61
+ foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
62
+ if ( $gateway instanceof WC_Payment_Gateway_Stripe ) {
63
+ $payment_methods = array_merge( $payment_methods, WC_Payment_Tokens::get_customer_tokens( $order->get_user_id(), $gateway->id ) );
64
+ }
65
+ }
66
+ wp_enqueue_script( 'wc-stripe-elements', 'https://js.stripe.com/v3/', array(), wc_stripe()->version, true );
67
+ wp_localize_script(
68
+ 'wc-stripe-elements',
69
+ 'wc_stripe_order_pay_params',
70
+ array(
71
+ 'api_key' => wc_stripe_get_publishable_key(),
72
+ 'payment_methods' => array_map(
73
+ function ( $payment_method ) {
74
+ return $payment_method->to_json();
75
+ },
76
+ $payment_methods
77
+ ),
78
+ 'order_status' => $order->get_status(),
79
+ )
80
+ );
81
+ wp_enqueue_script( 'wc-stripe-admin-modals', wc_stripe()->assets_url( 'js/admin/modals.js' ), array(
82
+ 'wc-backbone-modal',
83
+ 'jquery-blockui'
84
+ ), wc_stripe()->version, true );
85
+ }
86
+ }
87
+
88
+ public static function enqueue_scripts() {
89
+ wp_enqueue_script( 'wc-stripe-order-metabox', wc_stripe()->assets_url( 'js/admin/meta-boxes-order.js' ), array(
90
+ 'jquery',
91
+ 'jquery-blockui'
92
+ ), wc_stripe()->version(), true );
93
+
94
+ wp_localize_script(
95
+ 'wc-stripe-order-metabox',
96
+ 'wc_stripe_order_metabox_params',
97
+ array(
98
+ '_wpnonce' => wp_create_nonce( 'wp_rest' ),
99
+ 'routes' => array(
100
+ 'charge_view' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->order_actions->rest_uri( 'charge-view' ) ),
101
+ 'capture' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->order_actions->rest_uri( 'capture' ) ),
102
+ 'void' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->order_actions->rest_uri( 'void' ) ),
103
+ 'pay' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->order_actions->rest_uri( 'pay' ) ),
104
+ 'payment_methods' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->order_actions->rest_uri( 'customer-payment-methods' ) ),
105
+ ),
106
+ )
107
+ );
108
+ }
109
+ }
110
+
111
+ WC_Stripe_Admin_Order_Metaboxes::init();
includes/class-stripe.php CHANGED
@@ -25,7 +25,7 @@ class WC_Stripe_Manager {
25
  *
26
  * @var string
27
  */
28
- public $version = '3.2.6';
29
 
30
  /**
31
  *
@@ -323,7 +323,7 @@ class WC_Stripe_Manager {
323
  }
324
  switch ( $type ) {
325
  case 'frontend':
326
- return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) && ! WC()->is_rest_api_request();
327
  default:
328
  return true;
329
  }
25
  *
26
  * @var string
27
  */
28
+ public $version = '3.2.7';
29
 
30
  /**
31
  *
323
  }
324
  switch ( $type ) {
325
  case 'frontend':
326
+ return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) && ! WC_Stripe_Rest_API::is_wp_rest_request();
327
  default:
328
  return true;
329
  }
includes/class-wc-stripe-frontend-scripts.php CHANGED
@@ -190,7 +190,7 @@ class WC_Stripe_Frontend_Scripts {
190
  }
191
 
192
  public function print_footer_scripts() {
193
- if ( is_checkout() && ! isset( $wp->query_vars['order_pay'] ) ) {
194
  $available_gateways = array_keys( WC()->payment_gateways()->get_available_payment_gateways() );
195
  $gateways = array_filter( WC()->payment_gateways()->payment_gateways(), function ( $gateway ) use ( $available_gateways ) {
196
  return $gateway instanceof WC_Payment_Gateway_Stripe && $gateway->is_available() && ( ! in_array( $gateway->id, $available_gateways ) || ! $gateway->has_enqueued_scripts( $this ) );
190
  }
191
 
192
  public function print_footer_scripts() {
193
+ if ( is_checkout() && ! isset( $wp->query_vars['order_pay'] ) && ! is_order_received_page() ) {
194
  $available_gateways = array_keys( WC()->payment_gateways()->get_available_payment_gateways() );
195
  $gateways = array_filter( WC()->payment_gateways()->payment_gateways(), function ( $gateway ) use ( $available_gateways ) {
196
  return $gateway instanceof WC_Payment_Gateway_Stripe && $gateway->is_available() && ( ! in_array( $gateway->id, $available_gateways ) || ! $gateway->has_enqueued_scripts( $this ) );
includes/class-wc-stripe-rest-api.php CHANGED
@@ -25,13 +25,10 @@ class WC_Stripe_Rest_API {
25
 
26
  public function __construct() {
27
  $this->include_classes();
 
28
  add_action( 'rest_api_init', array( $this, 'register_routes' ) );
29
  }
30
 
31
- public static function init() {
32
- add_action( 'init', array( __CLASS__, 'add_3rd_party_hooks' ), 1 );
33
- }
34
-
35
  /**
36
  *
37
  * @param WC_Stripe_Rest_Controller $key
@@ -129,19 +126,39 @@ class WC_Stripe_Rest_API {
129
  }
130
 
131
  /**
132
- * @since 3.2.5
 
 
 
133
  */
134
- public static function add_3rd_party_hooks() {
135
- if ( self::is_rest_api_request() ) {
136
- add_filter( 'wcml_load_multi_currency_in_ajax', function ( $bool ) {
137
- return true;
138
- } );
139
- add_filter( 'wcml_client_currency', function ( $currency ) {
140
- return isset( $_POST['currency'] ) ? $_POST['currency'] : $currency;
141
- } );
142
  }
143
 
 
144
  }
145
- }
146
 
147
- WC_Stripe_Rest_API::init();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  public function __construct() {
27
  $this->include_classes();
28
+ add_action( 'wc_ajax_wc_stripe_frontend_request', array( $this, 'process_frontend_request' ) );
29
  add_action( 'rest_api_init', array( $this, 'register_routes' ) );
30
  }
31
 
 
 
 
 
32
  /**
33
  *
34
  * @param WC_Stripe_Rest_Controller $key
126
  }
127
 
128
  /**
129
+ * Return true if this is a WP rest request. This function is a wrapper for WC()->is_rest_api_request()
130
+ * if it exists.
131
+ * @return bool
132
+ * @since 3.2.7
133
  */
134
+ public static function is_wp_rest_request() {
135
+ if ( function_exists( 'WC' ) && property_exists( WC(), 'is_rest_api_request' ) ) {
136
+ return WC()->is_rest_api_request();
 
 
 
 
 
137
  }
138
 
139
+ return ! empty( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], trailingslashit( rest_get_url_prefix() ) ) !== false;
140
  }
 
141
 
142
+ /**
143
+ * @since 3.2.7
144
+ */
145
+ public function process_frontend_request() {
146
+ if ( isset( $_GET['path'] ) ) {
147
+ global $wp;
148
+ $wp->set_query_var( 'rest_route', sanitize_text_field( $_GET['path'] ) );
149
+ rest_api_loaded();
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Return an endpoint for ajax requests that integrate with the WP Rest API.
155
+ *
156
+ * @param string $path
157
+ *
158
+ * @return string
159
+ * @since 3.2.7
160
+ */
161
+ public static function get_endpoint( $path ) {
162
+ return add_query_arg( 'path', '/' . trim( $path, '/' ), WC_AJAX::get_endpoint( 'wc_stripe_frontend_request' ) );
163
+ }
164
+ }
includes/controllers/class-wc-stripe-controller-cart.php CHANGED
@@ -1,376 +1,366 @@
1
- <?php
2
- defined( 'ABSPATH' ) || exit();
3
-
4
- /**
5
- * Controller class that perfors cart operations for client side requests.
6
- *
7
- * @author PaymentPlugins
8
- * @package Stripe/Controllers
9
- *
10
- */
11
- class WC_Stripe_Controller_Cart extends WC_Stripe_Rest_Controller {
12
-
13
- use WC_Stripe_Controller_Cart_Trait;
14
- use WC_Stripe_Controller_Frontend_Trait;
15
-
16
- protected $namespace = 'cart';
17
-
18
- public function register_routes() {
19
- register_rest_route(
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
- 'payment_method' => array( 'required' => true ),
41
- 'address' => array( 'required' => true, 'validate_callback' => array( $this, 'validate_shipping_address' ) )
42
- ),
43
- )
44
- );
45
- register_rest_route(
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,
56
- 'validate_callback' => array( $this, 'validate_quantity' ),
57
- ),
58
- 'payment_method' => array( 'required' => true ),
59
- ),
60
- )
61
- );
62
- /**
63
- *
64
- * @since 3.0.6
65
- */
66
- register_rest_route(
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,
77
- 'validate_callback' => array( $this, 'validate_quantity' ),
78
- ),
79
- 'payment_method' => array( 'required' => true ),
80
- ),
81
- )
82
- );
83
- }
84
-
85
- /**
86
- *
87
- * @param int $qty
88
- * @param WP_REST_Request $request
89
- */
90
- public function validate_quantity( $qty, $request ) {
91
- if ( $qty == 0 ) {
92
- return $this->add_validation_error( new WP_Error( 'cart-error', __( 'Quantity must be greater than zero.', 'woo-stripe-payment' ) ) );
93
- }
94
-
95
- return true;
96
- }
97
-
98
- /**
99
- * Update the shipping method chosen by the customer.
100
- *
101
- * @param WP_REST_Request $request
102
- */
103
- public function update_shipping_method( $request ) {
104
- $this->cart_includes();
105
- wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
106
- wc_maybe_define_constant( 'DOING_AJAX', true );
107
-
108
- $payment_method = $request->get_param( 'payment_method' );
109
- /**
110
- *
111
- * @var WC_Payment_Gateway_Stripe $gateway
112
- */
113
- $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
114
-
115
- wc_stripe_update_shipping_methods( $this->get_shipping_method_from_request( $request ) );
116
-
117
- $this->add_ready_to_calc_shipping();
118
-
119
- // if this request is coming from product page, stash cart and use product cart
120
- if ( 'product' == $request->get_param( 'page_id' ) ) {
121
- wc_stripe_stash_cart( WC()->cart );
122
- } else {
123
- WC()->cart->calculate_totals();
124
- }
125
-
126
- $response = rest_ensure_response(
127
- apply_filters(
128
- 'wc_stripe_update_shipping_method_response',
129
- array(
130
- 'data' => $gateway->get_update_shipping_method_response(
131
- array(
132
- 'newData' => array(
133
- 'status' => 'success',
134
- 'total' => array(
135
- 'amount' => wc_stripe_add_number_precision( WC()->cart->total ),
136
- 'label' => __( 'Total', 'woo-stripe-payment' ),
137
- 'pending' => false,
138
- ),
139
- 'displayItems' => $gateway->get_display_items(),
140
- 'shippingOptions' => $gateway->get_formatted_shipping_methods(),
141
- ),
142
- 'shipping_methods' => WC()->session->get( 'chosen_shipping_methods', array() ),
143
- )
144
- ),
145
- )
146
- )
147
- );
148
- if ( 'product' == $request->get_param( 'page_id' ) ) {
149
- wc_stripe_restore_cart( WC()->cart );
150
- }
151
-
152
- return $response;
153
- }
154
-
155
- /**
156
- *
157
- * @param WP_REST_Request $request
158
- */
159
- public function update_shipping_address( $request ) {
160
- $this->cart_includes();
161
- wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
162
- wc_maybe_define_constant( 'DOING_AJAX', true );
163
-
164
- $address = $request->get_param( 'address' );
165
- $payment_method = $request->get_param( 'payment_method' );
166
- /**
167
- *
168
- * @var WC_Payment_Gateway_Stripe $gateway
169
- */
170
- $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
171
- try {
172
- wc_stripe_update_customer_location( $address );
173
-
174
- $this->add_ready_to_calc_shipping();
175
-
176
- if ( 'product' == $request->get_param( 'page_id' ) ) {
177
- wc_stripe_stash_cart( WC()->cart );
178
- } else {
179
- WC()->cart->calculate_totals();
180
- }
181
-
182
- if ( ! $this->has_shipping_methods( $gateway->get_shipping_packages() ) ) {
183
- throw new Exception( 'No valid shipping methods.' );
184
- }
185
-
186
- $response = rest_ensure_response(
187
- apply_filters(
188
- 'wc_stripe_update_shipping_method_response',
189
- array(
190
- 'data' => $gateway->get_update_shipping_address_response(
191
- array(
192
- 'newData' => array(
193
- 'status' => 'success',
194
- 'total' => array(
195
- 'amount' => wc_stripe_add_number_precision( WC()->cart->total ),
196
- 'label' => __( 'Total', 'woo-stripe-payment' ),
197
- 'pending' => false,
198
- ),
199
- 'displayItems' => $gateway->get_display_items(),
200
- 'shippingOptions' => $gateway->get_formatted_shipping_methods(),
201
- ),
202
- 'address' => $address,
203
- 'shipping_method' => WC()->session->get( 'chosen_shipping_methods', array() )
204
- )
205
- ),
206
- )
207
- )
208
- );
209
- } catch ( Exception $e ) {
210
- $response = new WP_Error(
211
- 'address-error',
212
- $e->getMessage(),
213
- array(
214
- 'status' => 200,
215
- 'newData' => array( 'status' => 'invalid_shipping_address' ),
216
- )
217
- );
218
- }
219
- if ( 'product' == $request->get_param( 'page_id' ) ) {
220
- wc_stripe_restore_cart( WC()->cart );
221
- }
222
-
223
- return $response;
224
- }
225
-
226
- /**
227
- *
228
- * @param WP_REST_Request $request
229
- *
230
- * @return WP_REST_Response
231
- */
232
- public function add_to_cart( $request ) {
233
- $this->cart_includes();
234
- // WC 3.0.0 requires WOOCOMMERCE_CART to be defined.
235
- wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
236
- wc_maybe_define_constant( 'DOING_AJAX', true );
237
-
238
- $payment_method = $request->get_param( 'payment_method' );
239
- /**
240
- *
241
- * @var WC_Payment_Gateway_Stripe $gateway
242
- */
243
- $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
244
-
245
- $product_id = $request->get_param( 'product_id' );
246
- $qty = $request->get_param( 'qty' );
247
- $variation_id = $request->get_param( 'variation_id' );
248
-
249
- // stash cart so clean calculation can be performed.
250
- wc_stripe_stash_cart( WC()->cart, false );
251
-
252
- if ( WC()->cart->add_to_cart( $product_id, $qty, $variation_id ) == false ) {
253
- return new WP_Error( 'cart-error', $this->get_error_messages(), array( 'status' => 200 ) );
254
- } else {
255
- $response = rest_ensure_response(
256
- apply_filters(
257
- 'wc_stripe_add_to_cart_response',
258
- array(
259
- 'data' => $gateway->add_to_cart_response(
260
- array(
261
- 'total' => round( WC()->cart->total, 2 ),
262
- 'subtotal' => round( WC()->cart->subtotal, 2 ),
263
- 'totalCents' => wc_stripe_add_number_precision( WC()->cart->total ),
264
- 'displayItems' => $gateway->get_display_items( 'cart' ),
265
- 'shippingOptions' => $gateway->get_formatted_shipping_methods(),
266
- )
267
- ),
268
- ),
269
- $gateway,
270
- $request
271
- )
272
- );
273
- // save the product cart so it can be used for shipping calculations etc.
274
- wc_stripe_stash_product_cart( WC()->cart );
275
- // put cart contents back to how they were before.
276
- wc_stripe_restore_cart( WC()->cart );
277
-
278
- return $response;
279
- }
280
- }
281
-
282
- /**
283
- * Performs a cart calculation
284
- *
285
- * @param WP_REST_Request $request
286
- */
287
- public function cart_calculation( $request ) {
288
- $this->cart_includes();
289
- // WC 3.0.0 requires WOOCOMMERCE_CART to be defined.
290
- wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
291
- wc_maybe_define_constant( 'DOING_AJAX', true );
292
-
293
- $product_id = $request->get_param( 'product_id' );
294
- $qty = $request->get_param( 'qty' );
295
- $variation_id = $request->get_param( 'variation_id' ) == null ? 0 : $request->get_param( 'variation_id' );
296
-
297
- wc_stripe_stash_cart( WC()->cart, false );
298
-
299
- if ( WC()->cart->add_to_cart( $product_id, $qty, $variation_id ) ) {
300
- $payment_method = $request->get_param( 'payment_method' );
301
- /**
302
- *
303
- * @var WC_Payment_Gateway_Stripe $gateway
304
- */
305
- $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
306
- $response = rest_ensure_response(
307
- apply_filters(
308
- 'wc_stripe_add_to_cart_response',
309
- array(
310
- 'data' => $gateway->add_to_cart_response(
311
- array(
312
- 'total' => round( WC()->cart->total, 2 ),
313
- 'subtotal' => round( WC()->cart->subtotal, 2 ),
314
- 'totalCents' => wc_stripe_add_number_precision( WC()->cart->total ),
315
- 'displayItems' => $gateway->get_display_items( 'cart' ),
316
- 'shippingOptions' => $gateway->get_shipping_methods(),
317
- )
318
- ),
319
- ),
320
- $gateway,
321
- $request
322
- )
323
- );
324
- } else {
325
- $response = new WP_Error( 'cart-error', $this->get_error_messages(), array( 'status' => 200 ) );
326
- }
327
- wc_stripe_stash_product_cart( WC()->cart );
328
- wc_stripe_restore_cart( WC()->cart );
329
- wc_clear_notices();
330
-
331
- return $response;
332
- }
333
-
334
- protected function get_error_messages() {
335
- return $this->get_messages( 'error' );
336
- }
337
-
338
- /**
339
- *
340
- * {@inheritDoc}
341
- *
342
- * @see WC_Stripe_Rest_Controller::get_messages()
343
- */
344
- protected function get_messages( $types = 'all' ) {
345
- $notices = wc_get_notices();
346
- $message = '';
347
- if ( $types !== 'all' ) {
348
- $types = (array) $types;
349
- foreach ( $notices as $type => $notice ) {
350
- if ( ! in_array( $type, $types ) ) {
351
- unset( $notices[ $type ] );
352
- }
353
- }
354
- }
355
- foreach ( $notices as $notice ) {
356
- $message .= sprintf( ' %s', $notice );
357
- }
358
-
359
- return trim( $message );
360
- }
361
-
362
- /**
363
- * Return true if the provided packages have shipping methods.
364
- *
365
- * @param array $packages
366
- */
367
- private function has_shipping_methods( $packages ) {
368
- foreach ( $packages as $i => $package ) {
369
- if ( ! empty( $package['rates'] ) ) {
370
- return true;
371
- }
372
- }
373
-
374
- return false;
375
- }
376
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * Controller class that perfors cart operations for client side requests.
6
+ *
7
+ * @author PaymentPlugins
8
+ * @package Stripe/Controllers
9
+ *
10
+ */
11
+ class WC_Stripe_Controller_Cart extends WC_Stripe_Rest_Controller {
12
+
13
+ use WC_Stripe_Controller_Cart_Trait;
14
+ use WC_Stripe_Controller_Frontend_Trait;
15
+
16
+ protected $namespace = 'cart';
17
+
18
+ public function register_routes() {
19
+ register_rest_route(
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
+ 'payment_method' => array( 'required' => true ),
41
+ 'address' => array( 'required' => true, 'validate_callback' => array( $this, 'validate_shipping_address' ) )
42
+ ),
43
+ )
44
+ );
45
+ register_rest_route(
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,
56
+ 'validate_callback' => array( $this, 'validate_quantity' ),
57
+ ),
58
+ 'payment_method' => array( 'required' => true ),
59
+ ),
60
+ )
61
+ );
62
+ /**
63
+ *
64
+ * @since 3.0.6
65
+ */
66
+ register_rest_route(
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,
77
+ 'validate_callback' => array( $this, 'validate_quantity' ),
78
+ ),
79
+ 'payment_method' => array( 'required' => true ),
80
+ ),
81
+ )
82
+ );
83
+ }
84
+
85
+ /**
86
+ *
87
+ * @param int $qty
88
+ * @param WP_REST_Request $request
89
+ */
90
+ public function validate_quantity( $qty, $request ) {
91
+ if ( $qty == 0 ) {
92
+ return $this->add_validation_error( new WP_Error( 'cart-error', __( 'Quantity must be greater than zero.', 'woo-stripe-payment' ) ) );
93
+ }
94
+
95
+ return true;
96
+ }
97
+
98
+ /**
99
+ * Update the shipping method chosen by the customer.
100
+ *
101
+ * @param WP_REST_Request $request
102
+ */
103
+ public function update_shipping_method( $request ) {
104
+ wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
105
+
106
+ $payment_method = $request->get_param( 'payment_method' );
107
+ /**
108
+ *
109
+ * @var WC_Payment_Gateway_Stripe $gateway
110
+ */
111
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
112
+
113
+ wc_stripe_update_shipping_methods( $this->get_shipping_method_from_request( $request ) );
114
+
115
+ $this->add_ready_to_calc_shipping();
116
+
117
+ // if this request is coming from product page, stash cart and use product cart
118
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
119
+ wc_stripe_stash_cart( WC()->cart );
120
+ } else {
121
+ WC()->cart->calculate_totals();
122
+ }
123
+
124
+ $response = rest_ensure_response(
125
+ apply_filters(
126
+ 'wc_stripe_update_shipping_method_response',
127
+ array(
128
+ 'data' => $gateway->get_update_shipping_method_response(
129
+ array(
130
+ 'newData' => array(
131
+ 'status' => 'success',
132
+ 'total' => array(
133
+ 'amount' => wc_stripe_add_number_precision( WC()->cart->total ),
134
+ 'label' => __( 'Total', 'woo-stripe-payment' ),
135
+ 'pending' => false,
136
+ ),
137
+ 'displayItems' => $gateway->get_display_items(),
138
+ 'shippingOptions' => $gateway->get_formatted_shipping_methods(),
139
+ ),
140
+ 'shipping_methods' => WC()->session->get( 'chosen_shipping_methods', array() ),
141
+ )
142
+ ),
143
+ )
144
+ )
145
+ );
146
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
147
+ wc_stripe_restore_cart( WC()->cart );
148
+ }
149
+
150
+ return $response;
151
+ }
152
+
153
+ /**
154
+ *
155
+ * @param WP_REST_Request $request
156
+ */
157
+ public function update_shipping_address( $request ) {
158
+ wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
159
+
160
+ $address = $request->get_param( 'address' );
161
+ $payment_method = $request->get_param( 'payment_method' );
162
+ /**
163
+ *
164
+ * @var WC_Payment_Gateway_Stripe $gateway
165
+ */
166
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
167
+ try {
168
+ wc_stripe_update_customer_location( $address );
169
+
170
+ $this->add_ready_to_calc_shipping();
171
+
172
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
173
+ wc_stripe_stash_cart( WC()->cart );
174
+ } else {
175
+ WC()->cart->calculate_totals();
176
+ }
177
+
178
+ if ( ! $this->has_shipping_methods( $gateway->get_shipping_packages() ) ) {
179
+ throw new Exception( 'No valid shipping methods.' );
180
+ }
181
+
182
+ $response = rest_ensure_response(
183
+ apply_filters(
184
+ 'wc_stripe_update_shipping_method_response',
185
+ array(
186
+ 'data' => $gateway->get_update_shipping_address_response(
187
+ array(
188
+ 'newData' => array(
189
+ 'status' => 'success',
190
+ 'total' => array(
191
+ 'amount' => wc_stripe_add_number_precision( WC()->cart->total ),
192
+ 'label' => __( 'Total', 'woo-stripe-payment' ),
193
+ 'pending' => false,
194
+ ),
195
+ 'displayItems' => $gateway->get_display_items(),
196
+ 'shippingOptions' => $gateway->get_formatted_shipping_methods(),
197
+ ),
198
+ 'address' => $address,
199
+ 'shipping_method' => WC()->session->get( 'chosen_shipping_methods', array() )
200
+ )
201
+ ),
202
+ )
203
+ )
204
+ );
205
+ } catch ( Exception $e ) {
206
+ $response = new WP_Error(
207
+ 'address-error',
208
+ $e->getMessage(),
209
+ array(
210
+ 'status' => 200,
211
+ 'newData' => array( 'status' => 'invalid_shipping_address' ),
212
+ )
213
+ );
214
+ }
215
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
216
+ wc_stripe_restore_cart( WC()->cart );
217
+ }
218
+
219
+ return $response;
220
+ }
221
+
222
+ /**
223
+ *
224
+ * @param WP_REST_Request $request
225
+ *
226
+ * @return WP_REST_Response
227
+ */
228
+ public function add_to_cart( $request ) {
229
+ wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
230
+
231
+ $payment_method = $request->get_param( 'payment_method' );
232
+ /**
233
+ *
234
+ * @var WC_Payment_Gateway_Stripe $gateway
235
+ */
236
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
237
+
238
+ $product_id = $request->get_param( 'product_id' );
239
+ $qty = $request->get_param( 'qty' );
240
+ $variation_id = $request->get_param( 'variation_id' );
241
+
242
+ // stash cart so clean calculation can be performed.
243
+ wc_stripe_stash_cart( WC()->cart, false );
244
+
245
+ if ( WC()->cart->add_to_cart( $product_id, $qty, $variation_id ) == false ) {
246
+ return new WP_Error( 'cart-error', $this->get_error_messages(), array( 'status' => 200 ) );
247
+ } else {
248
+ $response = rest_ensure_response(
249
+ apply_filters(
250
+ 'wc_stripe_add_to_cart_response',
251
+ array(
252
+ 'data' => $gateway->add_to_cart_response(
253
+ array(
254
+ 'total' => round( WC()->cart->total, 2 ),
255
+ 'subtotal' => round( WC()->cart->subtotal, 2 ),
256
+ 'totalCents' => wc_stripe_add_number_precision( WC()->cart->total ),
257
+ 'displayItems' => $gateway->get_display_items( 'cart' ),
258
+ 'shippingOptions' => $gateway->get_formatted_shipping_methods(),
259
+ )
260
+ ),
261
+ ),
262
+ $gateway,
263
+ $request
264
+ )
265
+ );
266
+ // save the product cart so it can be used for shipping calculations etc.
267
+ wc_stripe_stash_product_cart( WC()->cart );
268
+ // put cart contents back to how they were before.
269
+ wc_stripe_restore_cart( WC()->cart );
270
+
271
+ return $response;
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Performs a cart calculation
277
+ *
278
+ * @param WP_REST_Request $request
279
+ */
280
+ public function cart_calculation( $request ) {
281
+ wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
282
+
283
+ $product_id = $request->get_param( 'product_id' );
284
+ $qty = $request->get_param( 'qty' );
285
+ $variation_id = $request->get_param( 'variation_id' ) == null ? 0 : $request->get_param( 'variation_id' );
286
+
287
+ wc_stripe_stash_cart( WC()->cart, false );
288
+
289
+ if ( WC()->cart->add_to_cart( $product_id, $qty, $variation_id ) ) {
290
+ $payment_method = $request->get_param( 'payment_method' );
291
+ /**
292
+ *
293
+ * @var WC_Payment_Gateway_Stripe $gateway
294
+ */
295
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
296
+ $response = rest_ensure_response(
297
+ apply_filters(
298
+ 'wc_stripe_add_to_cart_response',
299
+ array(
300
+ 'data' => $gateway->add_to_cart_response(
301
+ array(
302
+ 'total' => round( WC()->cart->total, 2 ),
303
+ 'subtotal' => round( WC()->cart->subtotal, 2 ),
304
+ 'totalCents' => wc_stripe_add_number_precision( WC()->cart->total ),
305
+ 'displayItems' => $gateway->get_display_items( 'cart' ),
306
+ 'shippingOptions' => $gateway->get_shipping_methods(),
307
+ )
308
+ ),
309
+ ),
310
+ $gateway,
311
+ $request
312
+ )
313
+ );
314
+ } else {
315
+ $response = new WP_Error( 'cart-error', $this->get_error_messages(), array( 'status' => 200 ) );
316
+ }
317
+ wc_stripe_stash_product_cart( WC()->cart );
318
+ wc_stripe_restore_cart( WC()->cart );
319
+ wc_clear_notices();
320
+
321
+ return $response;
322
+ }
323
+
324
+ protected function get_error_messages() {
325
+ return $this->get_messages( 'error' );
326
+ }
327
+
328
+ /**
329
+ *
330
+ * {@inheritDoc}
331
+ *
332
+ * @see WC_Stripe_Rest_Controller::get_messages()
333
+ */
334
+ protected function get_messages( $types = 'all' ) {
335
+ $notices = wc_get_notices();
336
+ $message = '';
337
+ if ( $types !== 'all' ) {
338
+ $types = (array) $types;
339
+ foreach ( $notices as $type => $notice ) {
340
+ if ( ! in_array( $type, $types ) ) {
341
+ unset( $notices[ $type ] );
342
+ }
343
+ }
344
+ }
345
+ foreach ( $notices as $notice ) {
346
+ $message .= sprintf( ' %s', $notice );
347
+ }
348
+
349
+ return trim( $message );
350
+ }
351
+
352
+ /**
353
+ * Return true if the provided packages have shipping methods.
354
+ *
355
+ * @param array $packages
356
+ */
357
+ private function has_shipping_methods( $packages ) {
358
+ foreach ( $packages as $i => $package ) {
359
+ if ( ! empty( $package['rates'] ) ) {
360
+ return true;
361
+ }
362
+ }
363
+
364
+ return false;
365
+ }
366
+ }
 
 
 
 
 
 
 
 
 
 
includes/controllers/class-wc-stripe-controller-checkout.php CHANGED
@@ -72,8 +72,6 @@ class WC_Stripe_Controller_Checkout extends WC_Stripe_Rest_Controller {
72
  * @return WP_REST_Response
73
  */
74
  public function process_checkout( $request ) {
75
- $this->frontend_includes( $request );
76
- wc_maybe_define_constant( 'DOING_AJAX', true );
77
  $this->actions();
78
  $checkout = WC()->checkout();
79
  $payment_method = $request->get_param( 'payment_method' );
@@ -119,13 +117,8 @@ class WC_Stripe_Controller_Checkout extends WC_Stripe_Rest_Controller {
119
  * @since 3.2.3
120
  */
121
  public function process_payment( $request ) {
122
- wc_maybe_define_constant( 'DOING_AJAX', true );
123
  wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
124
- $this->frontend_includes( $request );;
125
  try {
126
- if ( ! isset( $request['wp_rest_nonce'] ) || ! wp_verify_nonce( $request['wp_rest_nonce'], 'wp_rest' ) ) {
127
- throw new Exception( 'You are not authorized.' );
128
- }
129
  $order_id = absint( WC()->session->get( 'order_awaiting_payment' ) );
130
  $order = wc_get_order( $order_id );
131
 
@@ -156,8 +149,6 @@ class WC_Stripe_Controller_Checkout extends WC_Stripe_Rest_Controller {
156
  * @since 3.1.8
157
  */
158
  public function process_order_pay( $request ) {
159
- $this->frontend_includes( $request );
160
-
161
  global $wp;
162
 
163
  $wp->query_vars['order-pay'] = $request->get_param( 'order_id' );
@@ -185,7 +176,6 @@ class WC_Stripe_Controller_Checkout extends WC_Stripe_Rest_Controller {
185
  * @since 3.1.7
186
  */
187
  public function delete_source( $request ) {
188
- $this->frontend_includes( $request );
189
  $order_id = WC()->session->get( 'order_awaiting_payment', null );
190
  if ( $order_id ) {
191
  $order = wc_get_order( $order_id );
72
  * @return WP_REST_Response
73
  */
74
  public function process_checkout( $request ) {
 
 
75
  $this->actions();
76
  $checkout = WC()->checkout();
77
  $payment_method = $request->get_param( 'payment_method' );
117
  * @since 3.2.3
118
  */
119
  public function process_payment( $request ) {
 
120
  wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
 
121
  try {
 
 
 
122
  $order_id = absint( WC()->session->get( 'order_awaiting_payment' ) );
123
  $order = wc_get_order( $order_id );
124
 
149
  * @since 3.1.8
150
  */
151
  public function process_order_pay( $request ) {
 
 
152
  global $wp;
153
 
154
  $wp->query_vars['order-pay'] = $request->get_param( 'order_id' );
176
  * @since 3.1.7
177
  */
178
  public function delete_source( $request ) {
 
179
  $order_id = WC()->session->get( 'order_awaiting_payment', null );
180
  if ( $order_id ) {
181
  $order = wc_get_order( $order_id );
includes/controllers/class-wc-stripe-controller-gateway-settings.php CHANGED
@@ -18,13 +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' => function () {
22
- if ( current_user_can( 'manage_woocommerce' ) ) {
23
- return true;
24
- }
25
-
26
- return new WP_Error( 'permission-error', __( 'You do not have permissions to access this resource.', 'woo-stripe-payment' ), array( 'status' => 403 ) );
27
- }
28
  )
29
  );
30
  register_rest_route(
@@ -33,7 +27,7 @@ class WC_Stripe_Controller_Gateway_Settings extends WC_Stripe_Rest_Controller {
33
  array(
34
  'methods' => WP_REST_Server::CREATABLE,
35
  'callback' => array( $this, 'create_webhook' ),
36
- 'permission_callback' => array( $this, 'admin_permission_check' )
37
  )
38
  );
39
  register_rest_route(
@@ -42,7 +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( $this, 'admin_permission_check' )
46
  )
47
  );
48
  }
@@ -231,4 +225,12 @@ class WC_Stripe_Controller_Gateway_Settings extends WC_Stripe_Rest_Controller {
231
 
232
  return rest_ensure_response( array( 'message' => sprintf( __( 'Connection test to Stripe was successful. Mode: %s.', 'woo-stripe-payment' ), $mode ) ) );
233
  }
 
 
 
 
 
 
 
 
234
  }
18
  array(
19
  'methods' => WP_REST_Server::CREATABLE,
20
  'callback' => array( $this, 'register_apple_domain' ),
21
+ 'permission_callback' => array( $this, 'shop_manager_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, 'shop_manager_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, 'shop_manager_permission_check' )
40
  )
41
  );
42
  }
225
 
226
  return rest_ensure_response( array( 'message' => sprintf( __( 'Connection test to Stripe was successful. Mode: %s.', 'woo-stripe-payment' ), $mode ) ) );
227
  }
228
+
229
+ public function shop_manager_permission_check() {
230
+ if ( current_user_can( 'manage_woocommerce' ) ) {
231
+ return true;
232
+ }
233
+
234
+ return new WP_Error( 'permission-error', __( 'You do not have permissions to access this resource.', 'woo-stripe-payment' ), array( 'status' => 403 ) );
235
+ }
236
  }
includes/controllers/class-wc-stripe-controller-googlepay.php CHANGED
@@ -1,172 +1,170 @@
1
- <?php
2
- defined( 'ABSPATH' ) || exit();
3
-
4
- if ( ! class_exists( 'WC_Stripe_Rest_Controller' ) ) {
5
- return;
6
- }
7
-
8
- /**
9
- *
10
- * @author PaymentPlugins
11
- * @package Stripe/Controllers
12
- */
13
- class WC_Stripe_Controller_GooglePay extends WC_Stripe_Rest_Controller {
14
-
15
- use WC_Stripe_Controller_Cart_Trait;
16
- use WC_Stripe_Controller_Frontend_Trait;
17
-
18
- protected $namespace = 'googlepay';
19
-
20
- /**
21
- *
22
- * @var WC_Payment_Gateway_Stripe_GooglePay
23
- */
24
- private $gateway;
25
-
26
- /**
27
- *
28
- * @var string
29
- */
30
- private $shipping_method_id;
31
-
32
- /**
33
- *
34
- * @var string
35
- */
36
- private $reason_code;
37
-
38
- public function register_routes() {
39
- register_rest_route(
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, 'validate_callback' => array( $this, 'validate_shipping_address' ) ),
48
- 'shipping_method' => array( 'required' => false )
49
- ),
50
- )
51
- );
52
- }
53
-
54
- /**
55
- * Update the WC shipping data from the Google payment sheet.
56
- *
57
- * @param WP_REST_Request $request
58
- */
59
- public function update_shipping_data( $request ) {
60
- $this->cart_includes();
61
- wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
62
- wc_maybe_define_constant( 'DOING_AJAX', true );
63
-
64
- $address = $request->get_param( 'shipping_address' );
65
- $this->shipping_method_id = ( ( $method_id = $request->get_param( 'shipping_method' ) ) ? $method_id : 'default' );
66
-
67
- $this->gateway = WC()->payment_gateways()->payment_gateways()['stripe_googlepay'];
68
-
69
- $this->add_ready_to_calc_shipping();
70
-
71
- try {
72
-
73
- wc_stripe_update_customer_location( $address );
74
-
75
- wc_stripe_update_shipping_methods( $this->get_shipping_method_from_request( $request ) );
76
-
77
- if ( 'product' == $request->get_param( 'page_id' ) ) {
78
- wc_stripe_stash_cart( WC()->cart );
79
- }
80
-
81
- // update the WC cart with the new shipping options
82
- WC()->cart->calculate_totals();
83
-
84
- // if shipping address is not serviceable, throw an error.
85
- if ( ! wc_stripe_shipping_address_serviceable( $this->gateway->get_shipping_packages() ) ) {
86
- $this->reason_code = 'SHIPPING_ADDRESS_UNSERVICEABLE';
87
- throw new Exception( __( 'Your shipping address is not serviceable.', 'woo-stripe-payment' ) );
88
- }
89
-
90
- $response = rest_ensure_response(
91
- apply_filters(
92
- 'wc_stripe_googlepay_paymentdata_response',
93
- array(
94
- 'data' => array(
95
- 'shipping_methods' => $this->get_shipping_methods(),
96
- 'paymentRequestUpdate' => $this->get_payment_response_data(),
97
- 'address' => $address
98
- ),
99
- )
100
- )
101
- );
102
- if ( 'product' == $request->get_param( 'page_id' ) ) {
103
- wc_stripe_restore_cart( WC()->cart );
104
- }
105
-
106
- return $response;
107
- } catch ( Exception $e ) {
108
- return new WP_Error(
109
- 'payment-data-error',
110
- $e->getMessage(),
111
- array(
112
- 'status' => 200,
113
- 'data' => array(
114
- 'error' => array(
115
- 'reason' => $this->reason_code,
116
- 'message' => $e->getMessage(),
117
- 'intent' => 'SHIPPING_ADDRESS',
118
- ),
119
- ),
120
- )
121
- );
122
- }
123
- }
124
-
125
- /**
126
- * Return a formatted array of response data required by the Google payment sheet.
127
- */
128
- public function get_payment_response_data() {
129
- $shipping_options = $this->gateway->get_formatted_shipping_methods();
130
-
131
- return array(
132
- 'newTransactionInfo' => array(
133
- 'currencyCode' => get_woocommerce_currency(),
134
- 'totalPriceStatus' => 'FINAL',
135
- 'totalPrice' => strval( round( WC()->cart->total, 2 ) ),
136
- 'displayItems' => $this->gateway->get_display_items(),
137
- 'totalPriceLabel' => __( 'Total', 'woo-stripe-payment' ),
138
- ),
139
- 'newShippingOptionParameters' => array(
140
- 'shippingOptions' => $shipping_options,
141
- 'defaultSelectedOptionId' => $this->get_default_shipping_method( $shipping_options ),
142
- ),
143
- );
144
- }
145
-
146
- private function get_shipping_methods() {
147
- return WC()->session->get( 'chosen_shipping_methods', array() );
148
- }
149
-
150
- /**
151
- * Returns a default shipping method based on the chosen shipping methods.
152
- *
153
- * @param array $methods
154
- *
155
- * @return string
156
- */
157
- private function get_default_shipping_method( $methods ) {
158
- $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods', array() );
159
- $method_ids = wp_list_pluck( $methods, 'id' );
160
- foreach ( $chosen_shipping_methods as $idx => $method ) {
161
- $method_id = sprintf( '%s:%s', $idx, $method );
162
- if ( in_array( $method_id, $method_ids ) ) {
163
- $this->shipping_method_id = $method_id;
164
- }
165
- }
166
- if ( ! $this->shipping_method_id ) {
167
- $this->shipping_method_id = current( $method_ids );
168
- }
169
-
170
- return $this->shipping_method_id;
171
- }
172
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Stripe_Rest_Controller' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @author PaymentPlugins
11
+ * @package Stripe/Controllers
12
+ */
13
+ class WC_Stripe_Controller_GooglePay extends WC_Stripe_Rest_Controller {
14
+
15
+ use WC_Stripe_Controller_Cart_Trait;
16
+ use WC_Stripe_Controller_Frontend_Trait;
17
+
18
+ protected $namespace = 'googlepay';
19
+
20
+ /**
21
+ *
22
+ * @var WC_Payment_Gateway_Stripe_GooglePay
23
+ */
24
+ private $gateway;
25
+
26
+ /**
27
+ *
28
+ * @var string
29
+ */
30
+ private $shipping_method_id;
31
+
32
+ /**
33
+ *
34
+ * @var string
35
+ */
36
+ private $reason_code;
37
+
38
+ public function register_routes() {
39
+ register_rest_route(
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
+ 'address' => array( 'required' => true, 'validate_callback' => array( $this, 'validate_shipping_address' ) ),
48
+ 'shipping_method' => array( 'required' => false )
49
+ ),
50
+ )
51
+ );
52
+ }
53
+
54
+ /**
55
+ * Update the WC shipping data from the Google payment sheet.
56
+ *
57
+ * @param WP_REST_Request $request
58
+ */
59
+ public function update_shipping_data( $request ) {
60
+ wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
61
+
62
+ $address = $request->get_param( 'address' );
63
+ $this->shipping_method_id = ( ( $method_id = $request->get_param( 'shipping_method' ) ) ? $method_id : 'default' );
64
+
65
+ $this->gateway = WC()->payment_gateways()->payment_gateways()['stripe_googlepay'];
66
+
67
+ $this->add_ready_to_calc_shipping();
68
+
69
+ try {
70
+
71
+ wc_stripe_update_customer_location( $address );
72
+
73
+ wc_stripe_update_shipping_methods( $this->get_shipping_method_from_request( $request ) );
74
+
75
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
76
+ wc_stripe_stash_cart( WC()->cart );
77
+ }
78
+
79
+ // update the WC cart with the new shipping options
80
+ WC()->cart->calculate_totals();
81
+
82
+ // if shipping address is not serviceable, throw an error.
83
+ if ( ! wc_stripe_shipping_address_serviceable( $this->gateway->get_shipping_packages() ) ) {
84
+ $this->reason_code = 'SHIPPING_ADDRESS_UNSERVICEABLE';
85
+ throw new Exception( __( 'Your shipping address is not serviceable.', 'woo-stripe-payment' ) );
86
+ }
87
+
88
+ $response = rest_ensure_response(
89
+ apply_filters(
90
+ 'wc_stripe_googlepay_paymentdata_response',
91
+ array(
92
+ 'data' => array(
93
+ 'shipping_methods' => $this->get_shipping_methods(),
94
+ 'paymentRequestUpdate' => $this->get_payment_response_data(),
95
+ 'address' => $address
96
+ ),
97
+ )
98
+ )
99
+ );
100
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
101
+ wc_stripe_restore_cart( WC()->cart );
102
+ }
103
+
104
+ return $response;
105
+ } catch ( Exception $e ) {
106
+ return new WP_Error(
107
+ 'payment-data-error',
108
+ $e->getMessage(),
109
+ array(
110
+ 'status' => 200,
111
+ 'data' => array(
112
+ 'error' => array(
113
+ 'reason' => $this->reason_code,
114
+ 'message' => $e->getMessage(),
115
+ 'intent' => 'SHIPPING_ADDRESS',
116
+ ),
117
+ ),
118
+ )
119
+ );
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Return a formatted array of response data required by the Google payment sheet.
125
+ */
126
+ public function get_payment_response_data() {
127
+ $shipping_options = $this->gateway->get_formatted_shipping_methods();
128
+
129
+ return array(
130
+ 'newTransactionInfo' => array(
131
+ 'currencyCode' => get_woocommerce_currency(),
132
+ 'totalPriceStatus' => 'FINAL',
133
+ 'totalPrice' => strval( round( WC()->cart->total, 2 ) ),
134
+ 'displayItems' => $this->gateway->get_display_items(),
135
+ 'totalPriceLabel' => __( 'Total', 'woo-stripe-payment' ),
136
+ ),
137
+ 'newShippingOptionParameters' => array(
138
+ 'shippingOptions' => $shipping_options,
139
+ 'defaultSelectedOptionId' => $this->get_default_shipping_method( $shipping_options ),
140
+ ),
141
+ );
142
+ }
143
+
144
+ private function get_shipping_methods() {
145
+ return WC()->session->get( 'chosen_shipping_methods', array() );
146
+ }
147
+
148
+ /**
149
+ * Returns a default shipping method based on the chosen shipping methods.
150
+ *
151
+ * @param array $methods
152
+ *
153
+ * @return string
154
+ */
155
+ private function get_default_shipping_method( $methods ) {
156
+ $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods', array() );
157
+ $method_ids = wp_list_pluck( $methods, 'id' );
158
+ foreach ( $chosen_shipping_methods as $idx => $method ) {
159
+ $method_id = sprintf( '%s:%s', $idx, $method );
160
+ if ( in_array( $method_id, $method_ids ) ) {
161
+ $this->shipping_method_id = $method_id;
162
+ }
163
+ }
164
+ if ( ! $this->shipping_method_id ) {
165
+ $this->shipping_method_id = current( $method_ids );
166
+ }
167
+
168
+ return $this->shipping_method_id;
169
+ }
170
+ }
 
 
includes/controllers/class-wc-stripe-controller-order-actions.php CHANGED
@@ -1,318 +1,334 @@
1
- <?php
2
- defined( 'ABSPATH' ) || exit();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @package Stripe/Controllers
8
- *
9
- */
10
- class WC_Stripe_Controller_Order_Actions extends WC_Stripe_Rest_Controller {
11
-
12
- use WC_Stripe_Controller_Frontend_Trait;
13
-
14
- protected $namespace = 'order~action';
15
-
16
- public function register_routes() {
17
- register_rest_route(
18
- $this->rest_uri(),
19
- 'capture',
20
- array(
21
- 'methods' => WP_REST_Server::CREATABLE,
22
- 'callback' => array( $this, 'capture' ),
23
- 'permission_callback' => array( $this, 'admin_permission_check' ),
24
- 'args' => array(
25
- 'order_id' => array(
26
- 'required' => true,
27
- 'type' => 'int',
28
- 'validate_callback' => array( $this, 'validate_order_id' ),
29
- ),
30
- 'amount' => array(
31
- 'required' => true,
32
- 'type' => 'float',
33
- ),
34
- ),
35
- )
36
- );
37
- register_rest_route(
38
- $this->rest_uri(),
39
- 'void',
40
- array(
41
- 'methods' => WP_REST_Server::CREATABLE,
42
- 'callback' => array( $this, 'void' ),
43
- 'permission_callback' => array( $this, 'admin_permission_check' ),
44
- 'args' => array(
45
- 'order_id' => array(
46
- 'required' => true,
47
- 'type' => 'number',
48
- 'validate_callback' => array(
49
- $this,
50
- 'validate_order_id',
51
- ),
52
- ),
53
- ),
54
- )
55
- );
56
- register_rest_route(
57
- $this->rest_uri(),
58
- 'pay',
59
- array(
60
- 'methods' => WP_REST_Server::CREATABLE,
61
- 'callback' => array( $this, 'process_payment' ),
62
- 'permission_callback' => array( $this, 'admin_permission_check' ),
63
- 'args' => array(
64
- 'order_id' => array(
65
- 'required' => true,
66
- 'type' => 'number',
67
- 'validate_callback' => array(
68
- $this,
69
- 'validate_order_id',
70
- ),
71
- ),
72
- ),
73
- )
74
- );
75
- register_rest_route(
76
- $this->rest_uri(),
77
- 'customer-payment-methods',
78
- array(
79
- 'methods' => WP_REST_Server::READABLE,
80
- 'callback' => array( $this, 'customer_payment_methods' ),
81
- 'permission_callback' => array( $this, 'admin_permission_check' ),
82
- 'args' => array(
83
- 'customer_id' => array(
84
- 'required' => true,
85
- 'type' => 'number',
86
- ),
87
- ),
88
- )
89
- );
90
- register_rest_route(
91
- $this->rest_uri(),
92
- 'charge-view',
93
- array(
94
- 'methods' => WP_REST_Server::READABLE,
95
- 'callback' => array( $this, 'charge_view' ),
96
- 'permission_callback' => array( $this, 'admin_permission_check' ),
97
- 'args' => array(
98
- 'order_id' => array(
99
- 'required' => true,
100
- 'type' => 'number',
101
- ),
102
- ),
103
- )
104
- );
105
- }
106
-
107
- /**
108
- * Return true if the order_id is a valid post.
109
- *
110
- * @param int $order_id
111
- */
112
- public function validate_order_id( $order_id ) {
113
- return null !== get_post( $order_id );
114
- }
115
-
116
- /**
117
- *
118
- * @param WP_REST_Request $request
119
- */
120
- public function capture( $request ) {
121
- $order_id = $request->get_param( 'order_id' );
122
- $order = wc_get_order( $order_id );
123
- $amount = $request->get_param( 'amount' );
124
- if ( ! is_numeric( $amount ) ) {
125
- return new WP_Error(
126
- 'invalid_data',
127
- __( 'Invalid amount entered.', 'woo-stripe-payment' ),
128
- array(
129
- 'success' => false,
130
- 'status' => 200,
131
- )
132
- );
133
- }
134
- try {
135
- /**
136
- *
137
- * @var WC_Payment_Gateway_Stripe $gateway
138
- */
139
- $gateway = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
140
- $result = $gateway->capture_charge( $amount, $order );
141
- if ( is_wp_error( $result ) ) {
142
- throw new Exception( $result->get_error_message() );
143
- }
144
-
145
- return rest_ensure_response( array() );
146
- } catch ( Exception $e ) {
147
- return new WP_Error( 'capture-error', $e->getMessage(), array( 'status' => 200 ) );
148
- }
149
- }
150
-
151
- /**
152
- *
153
- * @param WP_REST_Request $request
154
- */
155
- public function void( $request ) {
156
- $order_id = $request->get_param( 'order_id' );
157
- $order = wc_get_order( $order_id );
158
- /**
159
- * When the order's status is set to cancelled, the wc_stripe_order_cancelled
160
- * function is called, which voids the charge.
161
- */
162
- $order->update_status( 'cancelled' );
163
-
164
- return rest_ensure_response( array() );
165
- }
166
-
167
- /**
168
- * Process a payment as an admin.
169
- *
170
- * @param WP_REST_Request $request
171
- */
172
- public function process_payment( $request ) {
173
- $this->frontend_includes();
174
- $order_id = $request->get_param( 'order_id' );
175
- $payment_type = $request->get_param( 'payment_type' );
176
- $order = wc_get_order( $order_id );
177
- $use_token = $payment_type === 'token';
178
- try {
179
- // perform some validations
180
- if ( $order->get_total() == 0 ) {
181
- if ( ! wcs_stripe_active() ) {
182
- throw new Exception( __( 'Order total must be greater than zero.', 'woo-stripe-payment' ) );
183
- } else {
184
- if ( ! wcs_order_contains_subscription( $order ) ) {
185
- throw new Exception( __( 'Order total must be greater than zero.', 'woo-stripe-payment' ) );
186
- }
187
- }
188
- }
189
- // update the order's customer ID if it has changed.
190
- if ( $order->get_customer_id() != $request->get_param( 'customer_id' ) ) {
191
- $order->set_customer_id( $request->get_param( 'customer_id' ) );
192
- }
193
-
194
- if ( $order->get_transaction_id() ) {
195
- throw new Exception( sprintf( __( 'This order has already been processed. Transaction ID: %1$s. Payment method: %2$s', 'woo-stripe-payment' ), $order->get_transaction_id(), $order->get_payment_method_title() ) );
196
- }
197
- if ( ! $use_token ) {
198
- // only credit card payments are allowed for one off payments as an admin.
199
- $payment_method = 'stripe_cc';
200
- } elseif ( $payment_type === 'token' ) {
201
- $token_id = intval( $request->get_param( 'payment_token_id' ) );
202
- $token = WC_Payment_Tokens::get( $token_id );
203
- if ( $token->get_user_id() !== $order->get_customer_id() ) {
204
- throw new Exception( __( 'Order customer Id and payment method customer Id do not match.', 'woo-stripe-payment' ) );
205
- }
206
- $payment_method = $token->get_gateway_id();
207
- }
208
- /**
209
- *
210
- * @var WC_Payment_Gateway_Stripe $gateway
211
- */
212
- $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
213
- // temporarily set the charge type of the gateway to whatever the admin has selected.
214
- $gateway->settings['charge_type'] = $request->get_param( 'wc_stripe_charge_type' );
215
- // set the payment gateway to the order.
216
- $order->set_payment_method( $gateway->id );
217
- $order->save();
218
- if ( ! $use_token ) {
219
- $_POST[ $gateway->token_key ] = $request->get_param( 'payment_nonce' );
220
- } else {
221
- $gateway->set_payment_method_token( $token->get_token() );
222
- }
223
-
224
- // set intent attribute off_session. Stripe requires confirm to be true to use off session.
225
- add_filter( 'wc_stripe_payment_intent_args', function ( $args ) {
226
- $args['confirm'] = true;
227
- $args['off_session'] = true;
228
-
229
- return $args;
230
- } );
231
-
232
- $result = $gateway->process_payment( $order_id );
233
-
234
- if ( isset( $result['result'] ) && $result['result'] === 'success' ) {
235
- return rest_ensure_response( array( 'success' => true ) );
236
- } else {
237
- // create a new order since updates to the order were made during the process_payment call.
238
- $order = wc_get_order( $order_id );
239
- $order->update_status( 'pending' );
240
-
241
- return new WP_Error(
242
- 'order-error',
243
- $this->get_error_messages(),
244
- array(
245
- 'status' => 200,
246
- 'success' => false,
247
- )
248
- );
249
- }
250
- } catch ( Exception $e ) {
251
- return new WP_Error( 'order-error', '<div class="woocommerce-error">' . $e->getMessage() . '</div>', array( 'status' => 200 ) );
252
- }
253
- }
254
-
255
- /**
256
- *
257
- * @param WP_REST_Request $request
258
- */
259
- public function customer_payment_methods( $request ) {
260
- $customer_id = $request->get_param( 'customer_id' );
261
- $tokens = array();
262
- foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
263
- if ( $gateway instanceof WC_Payment_Gateway_Stripe ) {
264
- $tokens = array_merge( $tokens, WC_Payment_Tokens::get_customer_tokens( $customer_id, $gateway->id ) );
265
- }
266
- }
267
-
268
- return rest_ensure_response(
269
- array(
270
- 'payment_methods' => array_map(
271
- function ( $payment_method ) {
272
- return $payment_method->to_json();
273
- },
274
- $tokens
275
- ),
276
- )
277
- );
278
- }
279
-
280
- /**
281
- *
282
- * @param WP_REST_Request $request
283
- */
284
- public function charge_view( $request ) {
285
- $order = wc_get_order( absint( $request->get_param( 'order_id' ) ) );
286
- /**
287
- *
288
- * @var WC_Payment_Gateway_Stripe $payment_method
289
- */
290
- $payment_method = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
291
- try {
292
- // fetch the charge so data is up to date.
293
- $charge = WC_Stripe_Gateway::load( wc_stripe_order_mode( $order ) )->charges->retrieve( $order->get_transaction_id() );
294
-
295
- if ( is_wp_error( $charge ) ) {
296
- throw new Exception( $charge->get_error_message() );
297
- }
298
- $order->update_meta_data( WC_Stripe_Constants::CHARGE_STATUS, $charge->status );
299
- $order->save();
300
- ob_start();
301
- include wc_stripe()->plugin_path() . 'includes/admin/meta-boxes/views/html-charge-data-subview.php';
302
- $html = ob_get_clean();
303
-
304
- return rest_ensure_response(
305
- array(
306
- 'data' => array(
307
- 'order_id' => $order->get_id(),
308
- 'order_number' => $order->get_order_number(),
309
- 'charge' => $charge->jsonSerialize(),
310
- 'html' => $html,
311
- ),
312
- )
313
- );
314
- } catch ( Exception $e ) {
315
- return new WP_Error( 'charge-error', $e->getMessage(), array( 'status' => 200 ) );
316
- }
317
- }
318
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @package Stripe/Controllers
8
+ *
9
+ */
10
+ class WC_Stripe_Controller_Order_Actions extends WC_Stripe_Rest_Controller {
11
+
12
+ use WC_Stripe_Controller_Frontend_Trait;
13
+
14
+ protected $namespace = 'order~action';
15
+
16
+ public function register_routes() {
17
+ register_rest_route(
18
+ $this->rest_uri(),
19
+ 'capture',
20
+ array(
21
+ 'methods' => WP_REST_Server::CREATABLE,
22
+ 'callback' => array( $this, 'capture' ),
23
+ 'permission_callback' => array( $this, 'order_actions_permission_check' ),
24
+ 'args' => array(
25
+ 'order_id' => array(
26
+ 'required' => true,
27
+ 'type' => 'int',
28
+ 'validate_callback' => array( $this, 'validate_order_id' ),
29
+ ),
30
+ 'amount' => array(
31
+ 'required' => true,
32
+ 'type' => 'float',
33
+ ),
34
+ ),
35
+ )
36
+ );
37
+ register_rest_route(
38
+ $this->rest_uri(),
39
+ 'void',
40
+ array(
41
+ 'methods' => WP_REST_Server::CREATABLE,
42
+ 'callback' => array( $this, 'void' ),
43
+ 'permission_callback' => array( $this, 'order_actions_permission_check' ),
44
+ 'args' => array(
45
+ 'order_id' => array(
46
+ 'required' => true,
47
+ 'type' => 'number',
48
+ 'validate_callback' => array(
49
+ $this,
50
+ 'validate_order_id',
51
+ ),
52
+ ),
53
+ ),
54
+ )
55
+ );
56
+ register_rest_route(
57
+ $this->rest_uri(),
58
+ 'pay',
59
+ array(
60
+ 'methods' => WP_REST_Server::CREATABLE,
61
+ 'callback' => array( $this, 'process_payment' ),
62
+ 'permission_callback' => array( $this, 'order_actions_permission_check' ),
63
+ 'args' => array(
64
+ 'order_id' => array(
65
+ 'required' => true,
66
+ 'type' => 'number',
67
+ 'validate_callback' => array(
68
+ $this,
69
+ 'validate_order_id',
70
+ ),
71
+ ),
72
+ ),
73
+ )
74
+ );
75
+ register_rest_route(
76
+ $this->rest_uri(),
77
+ 'customer-payment-methods',
78
+ array(
79
+ 'methods' => WP_REST_Server::READABLE,
80
+ 'callback' => array( $this, 'customer_payment_methods' ),
81
+ 'permission_callback' => array( $this, 'order_actions_permission_check' ),
82
+ 'args' => array(
83
+ 'customer_id' => array(
84
+ 'required' => true,
85
+ 'type' => 'number',
86
+ ),
87
+ ),
88
+ )
89
+ );
90
+ register_rest_route(
91
+ $this->rest_uri(),
92
+ 'charge-view',
93
+ array(
94
+ 'methods' => WP_REST_Server::READABLE,
95
+ 'callback' => array( $this, 'charge_view' ),
96
+ 'permission_callback' => array( $this, 'order_actions_permission_check' ),
97
+ 'args' => array(
98
+ 'order_id' => array(
99
+ 'required' => true,
100
+ 'type' => 'number',
101
+ ),
102
+ ),
103
+ )
104
+ );
105
+ }
106
+
107
+ /**
108
+ * Return true if the order_id is a valid post.
109
+ *
110
+ * @param int $order_id
111
+ */
112
+ public function validate_order_id( $order_id ) {
113
+ return null !== get_post( $order_id );
114
+ }
115
+
116
+ /**
117
+ *
118
+ * @param WP_REST_Request $request
119
+ */
120
+ public function capture( $request ) {
121
+ $order_id = $request->get_param( 'order_id' );
122
+ $order = wc_get_order( $order_id );
123
+ $amount = $request->get_param( 'amount' );
124
+ if ( ! is_numeric( $amount ) ) {
125
+ return new WP_Error(
126
+ 'invalid_data',
127
+ __( 'Invalid amount entered.', 'woo-stripe-payment' ),
128
+ array(
129
+ 'success' => false,
130
+ 'status' => 200,
131
+ )
132
+ );
133
+ }
134
+ try {
135
+ /**
136
+ *
137
+ * @var WC_Payment_Gateway_Stripe $gateway
138
+ */
139
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
140
+ $result = $gateway->capture_charge( $amount, $order );
141
+ if ( is_wp_error( $result ) ) {
142
+ throw new Exception( $result->get_error_message() );
143
+ }
144
+
145
+ return rest_ensure_response( array() );
146
+ } catch ( Exception $e ) {
147
+ return new WP_Error( 'capture-error', $e->getMessage(), array( 'status' => 200 ) );
148
+ }
149
+ }
150
+
151
+ /**
152
+ *
153
+ * @param WP_REST_Request $request
154
+ */
155
+ public function void( $request ) {
156
+ $order_id = $request->get_param( 'order_id' );
157
+ $order = wc_get_order( $order_id );
158
+ /**
159
+ * When the order's status is set to cancelled, the wc_stripe_order_cancelled
160
+ * function is called, which voids the charge.
161
+ */
162
+ $order->update_status( 'cancelled' );
163
+
164
+ return rest_ensure_response( array() );
165
+ }
166
+
167
+ /**
168
+ * Process a payment as an admin.
169
+ *
170
+ * @param WP_REST_Request $request
171
+ */
172
+ public function process_payment( $request ) {
173
+ $order_id = $request->get_param( 'order_id' );
174
+ $payment_type = $request->get_param( 'payment_type' );
175
+ $order = wc_get_order( $order_id );
176
+ $use_token = $payment_type === 'token';
177
+ try {
178
+ // perform some validations
179
+ if ( $order->get_total() == 0 ) {
180
+ if ( ! wcs_stripe_active() ) {
181
+ throw new Exception( __( 'Order total must be greater than zero.', 'woo-stripe-payment' ) );
182
+ } else {
183
+ if ( ! wcs_order_contains_subscription( $order ) ) {
184
+ throw new Exception( __( 'Order total must be greater than zero.', 'woo-stripe-payment' ) );
185
+ }
186
+ }
187
+ }
188
+ // update the order's customer ID if it has changed.
189
+ if ( $order->get_customer_id() != $request->get_param( 'customer_id' ) ) {
190
+ $order->set_customer_id( $request->get_param( 'customer_id' ) );
191
+ }
192
+
193
+ if ( $order->get_transaction_id() ) {
194
+ throw new Exception( sprintf( __( 'This order has already been processed. Transaction ID: %1$s. Payment method: %2$s', 'woo-stripe-payment' ), $order->get_transaction_id(), $order->get_payment_method_title() ) );
195
+ }
196
+ if ( ! $use_token ) {
197
+ // only credit card payments are allowed for one off payments as an admin.
198
+ $payment_method = 'stripe_cc';
199
+ } elseif ( $payment_type === 'token' ) {
200
+ $token_id = intval( $request->get_param( 'payment_token_id' ) );
201
+ $token = WC_Payment_Tokens::get( $token_id );
202
+ if ( $token->get_user_id() !== $order->get_customer_id() ) {
203
+ throw new Exception( __( 'Order customer Id and payment method customer Id do not match.', 'woo-stripe-payment' ) );
204
+ }
205
+ $payment_method = $token->get_gateway_id();
206
+ }
207
+ /**
208
+ *
209
+ * @var WC_Payment_Gateway_Stripe $gateway
210
+ */
211
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
212
+ // temporarily set the charge type of the gateway to whatever the admin has selected.
213
+ $gateway->settings['charge_type'] = $request->get_param( 'wc_stripe_charge_type' );
214
+ // set the payment gateway to the order.
215
+ $order->set_payment_method( $gateway->id );
216
+ $order->save();
217
+ if ( ! $use_token ) {
218
+ $_POST[ $gateway->token_key ] = $request->get_param( 'payment_nonce' );
219
+ } else {
220
+ $gateway->set_payment_method_token( $token->get_token() );
221
+ }
222
+
223
+ // set intent attribute off_session. Stripe requires confirm to be true to use off session.
224
+ add_filter( 'wc_stripe_payment_intent_args', function ( $args ) {
225
+ $args['confirm'] = true;
226
+ $args['off_session'] = true;
227
+
228
+ return $args;
229
+ } );
230
+
231
+ $result = $gateway->process_payment( $order_id );
232
+
233
+ if ( isset( $result['result'] ) && $result['result'] === 'success' ) {
234
+ return rest_ensure_response( array( 'success' => true ) );
235
+ } else {
236
+ // create a new order since updates to the order were made during the process_payment call.
237
+ $order = wc_get_order( $order_id );
238
+ $order->update_status( 'pending' );
239
+
240
+ return new WP_Error(
241
+ 'order-error',
242
+ $this->get_error_messages(),
243
+ array(
244
+ 'status' => 200,
245
+ 'success' => false,
246
+ )
247
+ );
248
+ }
249
+ } catch ( Exception $e ) {
250
+ return new WP_Error( 'order-error', '<div class="woocommerce-error">' . $e->getMessage() . '</div>', array( 'status' => 200 ) );
251
+ }
252
+ }
253
+
254
+ /**
255
+ *
256
+ * @param WP_REST_Request $request
257
+ */
258
+ public function customer_payment_methods( $request ) {
259
+ $customer_id = $request->get_param( 'customer_id' );
260
+ $tokens = array();
261
+ foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
262
+ if ( $gateway instanceof WC_Payment_Gateway_Stripe ) {
263
+ $tokens = array_merge( $tokens, WC_Payment_Tokens::get_customer_tokens( $customer_id, $gateway->id ) );
264
+ }
265
+ }
266
+
267
+ return rest_ensure_response(
268
+ array(
269
+ 'payment_methods' => array_map(
270
+ function ( $payment_method ) {
271
+ return $payment_method->to_json();
272
+ },
273
+ $tokens
274
+ ),
275
+ )
276
+ );
277
+ }
278
+
279
+ /**
280
+ *
281
+ * @param WP_REST_Request $request
282
+ */
283
+ public function charge_view( $request ) {
284
+ $order = wc_get_order( absint( $request->get_param( 'order_id' ) ) );
285
+ /**
286
+ *
287
+ * @var WC_Payment_Gateway_Stripe $payment_method
288
+ */
289
+ $payment_method = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
290
+ try {
291
+ // fetch the charge so data is up to date.
292
+ $charge = WC_Stripe_Gateway::load( wc_stripe_order_mode( $order ) )->charges->retrieve( $order->get_transaction_id() );
293
+
294
+ if ( is_wp_error( $charge ) ) {
295
+ throw new Exception( $charge->get_error_message() );
296
+ }
297
+ $order->update_meta_data( WC_Stripe_Constants::CHARGE_STATUS, $charge->status );
298
+ $order->save();
299
+ ob_start();
300
+ include wc_stripe()->plugin_path() . 'includes/admin/meta-boxes/views/html-charge-data-subview.php';
301
+ $html = ob_get_clean();
302
+
303
+ return rest_ensure_response(
304
+ array(
305
+ 'data' => array(
306
+ 'order_id' => $order->get_id(),
307
+ 'order_number' => $order->get_order_number(),
308
+ 'charge' => $charge->jsonSerialize(),
309
+ 'html' => $html,
310
+ ),
311
+ )
312
+ );
313
+ } catch ( Exception $e ) {
314
+ return new WP_Error( 'charge-error', $e->getMessage(), array( 'status' => 200 ) );
315
+ }
316
+ }
317
+
318
+ /**
319
+ * @param $request
320
+ */
321
+ public function order_actions_permission_check( $request ) {
322
+ if ( ! current_user_can( 'edit_shop_orders' ) ) {
323
+ return new WP_Error(
324
+ 'permission-error',
325
+ __( 'You do not have permissions to access this resource.', 'woo-stripe-payment' ),
326
+ array(
327
+ 'status' => 403,
328
+ )
329
+ );
330
+ }
331
+
332
+ return true;
333
+ }
334
+ }
includes/controllers/class-wc-stripe-controller-plaid.php CHANGED
@@ -11,7 +11,7 @@ class WC_Stripe_Controller_Plaid extends WC_Stripe_Rest_Controller {
11
  register_rest_route( $this->rest_uri(), 'link-token', array(
12
  'methods' => WP_REST_Server::CREATABLE,
13
  'callback' => array( $this, 'get_link_token' ),
14
- 'permission_callback' => array( $this, 'validate_rest_nonce' )
15
  ) );
16
  }
17
 
11
  register_rest_route( $this->rest_uri(), 'link-token', array(
12
  'methods' => WP_REST_Server::CREATABLE,
13
  'callback' => array( $this, 'get_link_token' ),
14
+ 'permission_callback' => '__return_true'
15
  ) );
16
  }
17
 
includes/gateways/class-wc-payment-gateway-stripe-ach.php CHANGED
@@ -47,8 +47,14 @@ class WC_Payment_Gateway_Stripe_ACH extends WC_Payment_Gateway_Stripe {
47
  */
48
  public function is_available() {
49
  $is_available = parent::is_available();
 
 
 
50
 
51
- return $is_available && get_woocommerce_currency() == 'USD';
 
 
 
52
  }
53
 
54
  /**
@@ -89,7 +95,7 @@ class WC_Payment_Gateway_Stripe_ACH extends WC_Payment_Gateway_Stripe {
89
  'client_name' => $this->get_option( 'client_name' ),
90
  'fees_enabled' => $this->fees_enabled(),
91
  'routes' => array(
92
- 'link_token' => wc_stripe()->rest_api->plaid->rest_url( 'link-token' )
93
  )
94
  )
95
  );
47
  */
48
  public function is_available() {
49
  $is_available = parent::is_available();
50
+ global $wp;
51
+ if ( isset( $wp->query_vars['order-pay'] ) ) {
52
+ $order = wc_get_order( absint( $wp->query_vars['order-pay'] ) );
53
 
54
+ return $is_available && $order->get_currency() === 'USD';
55
+ }
56
+
57
+ return $is_available && get_woocommerce_currency() === 'USD';
58
  }
59
 
60
  /**
95
  'client_name' => $this->get_option( 'client_name' ),
96
  'fees_enabled' => $this->fees_enabled(),
97
  'routes' => array(
98
+ 'link_token' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->plaid->rest_uri( 'link-token' ) )
99
  )
100
  )
101
  );
includes/gateways/class-wc-payment-gateway-stripe-googlepay.php CHANGED
@@ -101,7 +101,7 @@ class WC_Payment_Gateway_Stripe_GooglePay extends WC_Payment_Gateway_Stripe {
101
  'button_color' => $this->get_option( 'button_color' ),
102
  'button_style' => $this->get_option( 'button_style' ),
103
  'total_price_label' => __( 'Total', 'woo-stripe-payment' ),
104
- 'routes' => array( 'payment_data' => wc_stripe()->rest_api->googlepay->rest_url( 'shipping-data' ) ),
105
  'messages' => array( 'invalid_amount' => __( 'Please update you product quantity before using Google Pay.', 'woo-stripe-payment' ) )
106
  )
107
  );
101
  'button_color' => $this->get_option( 'button_color' ),
102
  'button_style' => $this->get_option( 'button_style' ),
103
  'total_price_label' => __( 'Total', 'woo-stripe-payment' ),
104
+ 'routes' => array( 'payment_data' => WC_Stripe_Rest_API::get_endpoint( wc_stripe()->rest_api->googlepay->rest_uri( 'shipping-data' ) ) ),
105
  'messages' => array( 'invalid_amount' => __( 'Please update you product quantity before using Google Pay.', 'woo-stripe-payment' ) )
106
  )
107
  );
includes/traits/wc-stripe-controller-traits.php CHANGED
@@ -94,7 +94,6 @@ trait WC_Stripe_Controller_Frontend_Trait {
94
  * @since 3.2.2
95
  */
96
  public function validate_rest_nonce( $request ) {
97
- $this->frontend_includes( $request );
98
  if ( ! isset( $request['wp_rest_nonce'] ) || ! wp_verify_nonce( $request['wp_rest_nonce'], 'wp_rest' ) ) {
99
  return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) );
100
  }
94
  * @since 3.2.2
95
  */
96
  public function validate_rest_nonce( $request ) {
 
97
  if ( ! isset( $request['wp_rest_nonce'] ) || ! wp_verify_nonce( $request['wp_rest_nonce'], 'wp_rest' ) ) {
98
  return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) );
99
  }
includes/traits/wc-stripe-settings-trait.php CHANGED
@@ -1,189 +1,189 @@
1
- <?php
2
- defined( 'ABSPATH' ) || exit();
3
-
4
- /**
5
- *
6
- * @author Payment Plugins
7
- * @since 3.1.0
8
- *
9
- */
10
- trait WC_Stripe_Settings_Trait {
11
-
12
- protected $tab_title;
13
-
14
- private $admin_output = false;
15
-
16
- public function admin_nav_tab( $tabs ) {
17
- $tabs[ $this->id ] = $this->tab_title;
18
-
19
- return $tabs;
20
- }
21
-
22
- public function is_active( $key ) {
23
- return $this->get_option( $key ) === 'yes';
24
- }
25
-
26
- public function admin_options() {
27
- if ( $this->admin_output ) {
28
- return;
29
- }
30
- $this->display_errors();
31
- $this->output_settings_nav();
32
- printf( '<input type="hidden" id="wc_stripe_prefix" name="wc_stripe_prefix" value="%1$s"/>', $this->get_prefix() );
33
- echo '<div class="wc-stripe-settings-container ' . $this->id . '">';
34
- parent::admin_options();
35
- echo '</div>';
36
- $this->admin_output = true;
37
- }
38
-
39
- public function output_settings_nav() {
40
- include wc_stripe()->plugin_path() . 'includes/admin/views/html-settings-nav.php';
41
- }
42
-
43
- /**
44
- * Display admin error messages.
45
- */
46
- public function display_errors() {
47
- if ( $this->get_errors() ) {
48
- echo '<div id="woocommerce_errors" class="error notice inline is-dismissible">';
49
- foreach ( $this->get_errors() as $error ) {
50
- echo '<p>' . wp_kses_post( $error ) . '</p>';
51
- }
52
- echo '</div>';
53
- }
54
- }
55
-
56
- public function get_prefix() {
57
- return $this->plugin_id . $this->id . '_';
58
- }
59
-
60
- public function generate_multiselect_html( $key, $data ) {
61
- $value = (array) $this->get_option( $key, array() );
62
- $data['options'] = array_merge( array_flip( $value ), $data['options'] );
63
-
64
- return parent::generate_multiselect_html( $key, $data );
65
- }
66
-
67
- public function get_custom_attribute_html( $attribs ) {
68
- if ( ! empty( $attribs['custom_attributes'] ) && is_array( $attribs['custom_attributes'] ) ) {
69
- foreach ( $attribs['custom_attributes'] as $k => $v ) {
70
- if ( is_array( $v ) ) {
71
- $attribs['custom_attributes'][ $k ] = htmlspecialchars( wp_json_encode( $v ) );
72
- }
73
- }
74
- }
75
-
76
- return parent::get_custom_attribute_html( $attribs );
77
- }
78
-
79
- public function generate_description_html( $key, $data ) {
80
- $field_key = $this->get_field_key( $key );
81
- $data = wp_parse_args(
82
- $data,
83
- array(
84
- 'class' => '',
85
- 'style' => '',
86
- 'description' => '',
87
- )
88
- );
89
- ob_start();
90
- include wc_stripe()->plugin_path() . 'includes/admin/views/html-description.php';
91
-
92
- return ob_get_clean();
93
- }
94
-
95
- public function generate_paragraph_html( $key, $data ) {
96
- $field_key = $this->get_field_key( $key );
97
- $defaults = array(
98
- 'title' => '',
99
- 'label' => '',
100
- 'class' => '',
101
- 'css' => '',
102
- 'desc_tip' => false,
103
- 'description' => '',
104
- 'custom_attributes' => array(),
105
- );
106
- $data = wp_parse_args( $data, $defaults );
107
- if ( ! $data['label'] ) {
108
- $data['label'] = $data['title'];
109
- }
110
- ob_start();
111
- include wc_stripe()->plugin_path() . 'includes/admin/views/html-paragraph.php';
112
-
113
- return ob_get_clean();
114
- }
115
-
116
- public function generate_stripe_button_html( $key, $data ) {
117
- $field_key = $this->get_field_key( $key );
118
- $data = wp_parse_args(
119
- $data,
120
- array(
121
- 'title' => '',
122
- 'class' => '',
123
- 'style' => '',
124
- 'description' => '',
125
- 'desc_tip' => false,
126
- 'id' => 'wc-stripe-button_' . $key,
127
- 'disabled' => false,
128
- 'css' => '',
129
- )
130
- );
131
- ob_start();
132
- include wc_stripe()->plugin_path() . 'includes/admin/views/html-button.php';
133
-
134
- return ob_get_clean();
135
- }
136
-
137
- public function generate_button_demo_html( $key, $data ) {
138
- $field_key = $this->get_field_key( $key );
139
- $data = wp_parse_args(
140
- $data,
141
- array(
142
- 'title' => '',
143
- 'class' => '',
144
- 'style' => '',
145
- 'description' => '',
146
- 'desc_tip' => false,
147
- 'id' => 'wc-stripe-button-demo',
148
- )
149
- );
150
- ob_start();
151
- include wc_stripe()->plugin_path() . 'includes/admin/views/html-button-demo.php';
152
-
153
- return ob_get_clean();
154
- }
155
-
156
- /**
157
- * Added override to provide more control on which fields are saved and which are skipped.
158
- * This plugin
159
- * has custom setting fields like "paragraph" that are for info display only and not for saving.
160
- *
161
- * {@inheritDoc}
162
- *
163
- * @see WC_Settings_API::process_admin_options()
164
- */
165
- public function process_admin_options() {
166
- $this->init_settings();
167
-
168
- $post_data = $this->get_post_data();
169
-
170
- $skip_types = array( 'title', 'paragraph', 'button', 'description', 'button_demo', 'stripe_button' );
171
-
172
- foreach ( $this->get_form_fields() as $key => $field ) {
173
- $skip = isset( $field['skip'] ) && $field['skip'] == true;
174
- if ( ! in_array( $this->get_field_type( $field ), $skip_types ) && ! $skip ) {
175
- try {
176
- $this->settings[ $key ] = $this->get_field_value( $key, $field, $post_data );
177
- } catch ( Exception $e ) {
178
- $this->add_error( $e->getMessage() );
179
- }
180
- }
181
- }
182
-
183
- return update_option( $this->get_option_key(), apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' );
184
- }
185
-
186
- public function get_stripe_documentation_url() {
187
- return sprintf( 'https://docs.paymentplugins.com/wc-stripe/config/#/%s', $this->id );
188
- }
189
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author Payment Plugins
7
+ * @since 3.1.0
8
+ *
9
+ */
10
+ trait WC_Stripe_Settings_Trait {
11
+
12
+ protected $tab_title;
13
+
14
+ private $admin_output = false;
15
+
16
+ public function admin_nav_tab( $tabs ) {
17
+ $tabs[ $this->id ] = $this->tab_title;
18
+
19
+ return $tabs;
20
+ }
21
+
22
+ public function is_active( $key ) {
23
+ return $this->get_option( $key ) === 'yes';
24
+ }
25
+
26
+ public function admin_options() {
27
+ if ( $this->admin_output ) {
28
+ return;
29
+ }
30
+ $this->display_errors();
31
+ $this->output_settings_nav();
32
+ printf( '<input type="hidden" id="wc_stripe_prefix" name="wc_stripe_prefix" value="%1$s"/>', $this->get_prefix() );
33
+ echo '<div class="wc-stripe-settings-container ' . $this->id . '">';
34
+ parent::admin_options();
35
+ echo '</div>';
36
+ $this->admin_output = true;
37
+ }
38
+
39
+ public function output_settings_nav() {
40
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-settings-nav.php';
41
+ }
42
+
43
+ /**
44
+ * Display admin error messages.
45
+ */
46
+ public function display_errors() {
47
+ if ( $this->get_errors() ) {
48
+ echo '<div id="woocommerce_errors" class="error notice inline is-dismissible">';
49
+ foreach ( $this->get_errors() as $error ) {
50
+ echo '<p>' . wp_kses_post( $error ) . '</p>';
51
+ }
52
+ echo '</div>';
53
+ }
54
+ }
55
+
56
+ public function get_prefix() {
57
+ return $this->plugin_id . $this->id . '_';
58
+ }
59
+
60
+ public function generate_multiselect_html( $key, $data ) {
61
+ $value = (array) $this->get_option( $key, array() );
62
+ $data['options'] = array_merge( array_flip( $value ), $data['options'] );
63
+
64
+ return parent::generate_multiselect_html( $key, $data );
65
+ }
66
+
67
+ public function get_custom_attribute_html( $attribs ) {
68
+ if ( ! empty( $attribs['custom_attributes'] ) && is_array( $attribs['custom_attributes'] ) ) {
69
+ foreach ( $attribs['custom_attributes'] as $k => $v ) {
70
+ if ( is_array( $v ) ) {
71
+ $attribs['custom_attributes'][ $k ] = htmlspecialchars( wp_json_encode( $v ) );
72
+ }
73
+ }
74
+ }
75
+
76
+ return parent::get_custom_attribute_html( $attribs );
77
+ }
78
+
79
+ public function generate_description_html( $key, $data ) {
80
+ $field_key = $this->get_field_key( $key );
81
+ $data = wp_parse_args(
82
+ $data,
83
+ array(
84
+ 'class' => '',
85
+ 'style' => '',
86
+ 'description' => '',
87
+ )
88
+ );
89
+ ob_start();
90
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-description.php';
91
+
92
+ return ob_get_clean();
93
+ }
94
+
95
+ public function generate_paragraph_html( $key, $data ) {
96
+ $field_key = $this->get_field_key( $key );
97
+ $defaults = array(
98
+ 'title' => '',
99
+ 'label' => '',
100
+ 'class' => '',
101
+ 'css' => '',
102
+ 'desc_tip' => false,
103
+ 'description' => '',
104
+ 'custom_attributes' => array(),
105
+ );
106
+ $data = wp_parse_args( $data, $defaults );
107
+ if ( ! $data['label'] ) {
108
+ $data['label'] = $data['title'];
109
+ }
110
+ ob_start();
111
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-paragraph.php';
112
+
113
+ return ob_get_clean();
114
+ }
115
+
116
+ public function generate_stripe_button_html( $key, $data ) {
117
+ $field_key = $this->get_field_key( $key );
118
+ $data = wp_parse_args(
119
+ $data,
120
+ array(
121
+ 'title' => '',
122
+ 'class' => '',
123
+ 'style' => '',
124
+ 'description' => '',
125
+ 'desc_tip' => false,
126
+ 'id' => 'wc-stripe-button_' . $key,
127
+ 'disabled' => false,
128
+ 'css' => '',
129
+ )
130
+ );
131
+ ob_start();
132
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-button.php';
133
+
134
+ return ob_get_clean();
135
+ }
136
+
137
+ public function generate_button_demo_html( $key, $data ) {
138
+ $field_key = $this->get_field_key( $key );
139
+ $data = wp_parse_args(
140
+ $data,
141
+ array(
142
+ 'title' => '',
143
+ 'class' => '',
144
+ 'style' => '',
145
+ 'description' => '',
146
+ 'desc_tip' => false,
147
+ 'id' => 'wc-stripe-button-demo',
148
+ )
149
+ );
150
+ ob_start();
151
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-button-demo.php';
152
+
153
+ return ob_get_clean();
154
+ }
155
+
156
+ /**
157
+ * Added override to provide more control on which fields are saved and which are skipped.
158
+ * This plugin
159
+ * has custom setting fields like "paragraph" that are for info display only and not for saving.
160
+ *
161
+ * {@inheritDoc}
162
+ *
163
+ * @see WC_Settings_API::process_admin_options()
164
+ */
165
+ public function process_admin_options() {
166
+ $this->init_settings();
167
+
168
+ $post_data = $this->get_post_data();
169
+
170
+ $skip_types = array( 'title', 'paragraph', 'button', 'description', 'button_demo', 'stripe_button' );
171
+
172
+ foreach ( $this->get_form_fields() as $key => $field ) {
173
+ $skip = isset( $field['skip'] ) && $field['skip'] == true;
174
+ if ( ! in_array( $this->get_field_type( $field ), $skip_types ) && ! $skip ) {
175
+ try {
176
+ $this->settings[ $key ] = $this->get_field_value( $key, $field, $post_data );
177
+ } catch ( Exception $e ) {
178
+ $this->add_error( $e->getMessage() );
179
+ }
180
+ }
181
+ }
182
+
183
+ return update_option( $this->get_option_key(), apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' );
184
+ }
185
+
186
+ public function get_stripe_documentation_url() {
187
+ return sprintf( 'https://docs.paymentplugins.com/wc-stripe/config/#/%s', $this->id );
188
+ }
189
+ }
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.2.6
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.2.6 =
62
  * Fixed - Apple Pay duplicate button in express checkout
63
  * Added - Transaction url in order details
4
  Requires at least: 3.0.1
5
  Tested up to: 5.5
6
  Requires PHP: 5.6
7
+ Stable tag: 3.2.7
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.2.7 =
62
+ * Added - Better support for mixed cart/checkout page using Elementor
63
+ * Added - wc_stripe_save_order_meta action added so custom data can be added to order
64
+ * Added - Improved support for WooCommerce Multilingual
65
  = 3.2.6 =
66
  * Fixed - Apple Pay duplicate button in express checkout
67
  * Added - Transaction url in order details
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.2.6
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.2.7
7
  * Author: Payment Plugins, support@paymentplugins.com
8
  * Text Domain: woo-stripe-payment
9
  * Domain Path: /i18n/languages/