Payment Plugins for Stripe WooCommerce - Version 3.1.6

Version Description

  • Updated - WC tested to 4.3.0
  • Updated - Bumped PHP min version to 5.6
  • Updated - Stripe php lib version 7.39.0
  • Updated - Apple domain registration check for existing domain
  • Fixed - Notice on cart page when payment request button active and cart emptied
  • Fixed - Google Pay fee line item in wallet
  • Added - New filters for API requests
Download this release

Release Info

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

Code changes from version 3.1.5 to 3.1.6

Files changed (107) hide show
  1. assets/css/stripe.css +3 -0
  2. assets/js/frontend/applepay-cart.js +12 -0
  3. assets/js/frontend/local-payment.js +13 -8
  4. assets/js/frontend/payment-request.js +12 -0
  5. assets/js/frontend/wc-stripe.js +3 -0
  6. assets/js/frontend/wc-stripe.min.js +1 -1
  7. i18n/languages/woo-stripe-payment.pot +544 -561
  8. includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php +265 -268
  9. includes/abstract/abstract-wc-payment-gateway-stripe.php +1387 -1330
  10. includes/abstract/abstract-wc-payment-token-stripe.php +178 -173
  11. includes/abstract/abstract-wc-stripe-payment.php +238 -231
  12. includes/abstract/abstract-wc-stripe-rest-controller.php +104 -105
  13. includes/abstract/abstract-wc-stripe-settings.php +27 -29
  14. includes/admin/class-wc-stripe-admin-assets.php +99 -99
  15. includes/admin/class-wc-stripe-admin-menus.php +39 -45
  16. includes/admin/class-wc-stripe-admin-notices.php +67 -59
  17. includes/admin/class-wc-stripe-admin-settings.php +89 -104
  18. includes/admin/class-wc-stripe-admin-user-edit.php +109 -114
  19. includes/admin/meta-boxes/class-wc-stripe-admin-meta-box-product-data.php +92 -97
  20. includes/admin/meta-boxes/class-wc-stripe-admin-order-metaboxes.php +104 -105
  21. includes/admin/meta-boxes/views/html-charge-data-subview.php +90 -88
  22. includes/admin/meta-boxes/views/html-order-actions.php +52 -46
  23. includes/admin/meta-boxes/views/html-order-charge-data.php +37 -37
  24. includes/admin/meta-boxes/views/html-order-pay.php +59 -59
  25. includes/admin/meta-boxes/views/html-product-data.php +82 -62
  26. includes/admin/settings/class-wc-stripe-api-settings.php +188 -175
  27. includes/admin/views/html-ach-fee.php +33 -29
  28. includes/admin/views/html-button-demo.php +17 -13
  29. includes/admin/views/html-button.php +16 -13
  30. includes/admin/views/html-description.php +1 -1
  31. includes/admin/views/html-paragraph.php +15 -14
  32. includes/admin/views/html-settings-local-payments-nav.php +17 -12
  33. includes/admin/views/html-settings-nav.php +25 -18
  34. includes/admin/views/html-stripe-connect.php +19 -14
  35. includes/admin/views/html-user-profile.php +95 -95
  36. includes/class-stripe.php +304 -295
  37. includes/class-wc-stripe-api-operation.php +134 -0
  38. includes/class-wc-stripe-constants.php +46 -46
  39. includes/class-wc-stripe-customer-manager.php +195 -182
  40. includes/class-wc-stripe-field-manager.php +256 -246
  41. includes/class-wc-stripe-frontend-notices.php +58 -58
  42. includes/class-wc-stripe-frontend-scripts.php +162 -148
  43. includes/class-wc-stripe-gateway-ach.php +0 -99
  44. includes/class-wc-stripe-gateway-conversions.php +36 -40
  45. includes/class-wc-stripe-gateway.php +444 -495
  46. includes/class-wc-stripe-install.php +40 -36
  47. includes/class-wc-stripe-payment-charge-local.php +74 -71
  48. includes/class-wc-stripe-payment-charge.php +179 -173
  49. includes/class-wc-stripe-payment-factory.php +42 -42
  50. includes/class-wc-stripe-payment-intent.php +337 -321
  51. includes/class-wc-stripe-product-gateway-option.php +109 -102
  52. includes/class-wc-stripe-product-option.php +103 -102
  53. includes/class-wc-stripe-redirect-handler.php +91 -92
  54. includes/class-wc-stripe-rest-api.php +113 -119
  55. includes/class-wc-stripe-update.php +67 -62
  56. includes/controllers/class-wc-stripe-controller-cart.php +358 -335
  57. includes/controllers/class-wc-stripe-controller-checkout.php +265 -229
  58. includes/controllers/class-wc-stripe-controller-gateway-settings.php +237 -194
  59. includes/controllers/class-wc-stripe-controller-googlepay.php +160 -154
  60. includes/controllers/class-wc-stripe-controller-order-actions.php +318 -300
  61. includes/controllers/class-wc-stripe-controller-payment-intent.php +89 -88
  62. includes/controllers/class-wc-stripe-controller-payment-method.php +52 -49
  63. includes/controllers/class-wc-stripe-controller-product-data.php +83 -79
  64. includes/controllers/class-wc-stripe-controller-webhook.php +62 -58
  65. includes/gateways/class-wc-payment-gateway-stripe-ach-v2.php +0 -233
  66. includes/gateways/class-wc-payment-gateway-stripe-ach.php +352 -331
  67. includes/gateways/class-wc-payment-gateway-stripe-alipay.php +33 -34
  68. includes/gateways/class-wc-payment-gateway-stripe-applepay.php +115 -90
  69. includes/gateways/class-wc-payment-gateway-stripe-bancontact.php +33 -34
  70. includes/gateways/class-wc-payment-gateway-stripe-cc.php +173 -164
  71. includes/gateways/class-wc-payment-gateway-stripe-eps.php +32 -33
  72. includes/gateways/class-wc-payment-gateway-stripe-fpx.php +38 -39
  73. includes/gateways/class-wc-payment-gateway-stripe-giropay.php +32 -33
  74. includes/gateways/class-wc-payment-gateway-stripe-googlepay.php +329 -278
  75. includes/gateways/class-wc-payment-gateway-stripe-ideal.php +34 -35
  76. includes/gateways/class-wc-payment-gateway-stripe-klarna.php +298 -277
  77. includes/gateways/class-wc-payment-gateway-stripe-multibanco.php +32 -33
  78. includes/gateways/class-wc-payment-gateway-stripe-p24.php +32 -33
  79. includes/gateways/class-wc-payment-gateway-stripe-payment-request.php +98 -87
  80. includes/gateways/class-wc-payment-gateway-stripe-sepa.php +64 -60
  81. includes/gateways/class-wc-payment-gateway-stripe-sofort.php +37 -43
  82. includes/gateways/class-wc-payment-gateway-stripe-wechat.php +73 -67
  83. includes/gateways/settings/ach-settings-v2.php +115 -101
  84. includes/gateways/settings/ach-settings.php +124 -102
  85. includes/gateways/settings/applepay-settings.php +125 -112
  86. includes/gateways/settings/cc-settings.php +148 -139
  87. includes/gateways/settings/googlepay-settings.php +153 -126
  88. includes/gateways/settings/payment-request-settings.php +115 -95
  89. includes/tokens/class-wc-payment-token-stripe-ach.php +85 -83
  90. includes/tokens/class-wc-payment-token-stripe-applepay.php +17 -16
  91. includes/tokens/class-wc-payment-token-stripe-cc.php +126 -122
  92. includes/tokens/class-wc-payment-token-stripe-googlepay.php +21 -21
  93. includes/tokens/class-wc-payment-token-stripe-local-payment.php +40 -41
  94. includes/traits/wc-stripe-controller-cart-trait.php +28 -25
  95. includes/traits/wc-stripe-payment-token-traits.php +38 -65
  96. includes/traits/wc-stripe-payment-traits.php +122 -101
  97. includes/traits/wc-stripe-settings-trait.php +178 -160
  98. includes/updates/update-3.0.7.php +38 -42
  99. includes/updates/update-3.1.0.php +55 -60
  100. includes/updates/update-3.1.1.php +7 -7
  101. includes/updates/update-3.1.6.php +5 -0
  102. includes/wc-stripe-functions.php +1243 -1175
  103. includes/wc-stripe-hooks.php +29 -28
  104. includes/wc-stripe-webhook-functions.php +150 -149
  105. readme.txt +10 -2
  106. stripe-payments.php +5 -6
  107. stripe-php-6.40.0/CHANGELOG.md +0 -578
assets/css/stripe.css CHANGED
@@ -593,4 +593,7 @@ li[class*=payment_method_stripe_] div.wc-stripe_payment_request-container.has_to
593
  }
594
  #wc-stripe-card-element.StripeElement--webkit-autofill{
595
  background-color: transparent !important;
 
 
 
596
  }
593
  }
594
  #wc-stripe-card-element.StripeElement--webkit-autofill{
595
  background-color: transparent !important;
596
+ }
597
+ #wc_stripe_local_payment_stripe_klarna .stripe-klarna-categories{
598
+ list-style: none;
599
  }
assets/js/frontend/applepay-cart.js CHANGED
@@ -33,6 +33,9 @@
33
  * @return {[type]}
34
  */
35
  ApplePay.prototype.updated_html = function() {
 
 
 
36
  if (this.can_pay) {
37
  this.create_button();
38
  $(this.container).show().addClass('active').parent().addClass('active');
@@ -40,6 +43,15 @@
40
  }
41
  }
42
 
 
 
 
 
 
 
 
 
 
43
  new ApplePay();
44
 
45
  }(jQuery, window.wc_stripe))
33
  * @return {[type]}
34
  */
35
  ApplePay.prototype.updated_html = function() {
36
+ if (!$(this.container).length) {
37
+ this.can_pay = false;
38
+ }
39
  if (this.can_pay) {
40
  this.create_button();
41
  $(this.container).show().addClass('active').parent().addClass('active');
43
  }
44
  }
45
 
46
+ /**
47
+ * Called when the cart has been emptied
48
+ * @param {[type]} e [description]
49
+ * @return {[type]} [description]
50
+ */
51
+ ApplePay.prototype.cart_emptied = function(e) {
52
+ this.can_pay = false;
53
+ }
54
+
55
  new ApplePay();
56
 
57
  }(jQuery, window.wc_stripe))
assets/js/frontend/local-payment.js CHANGED
@@ -238,9 +238,12 @@
238
  }
239
 
240
  Klarna.prototype.category_change = function(e) {
241
- $('[id^="klarna-instance-"]').slideUp();
242
- var category = $('[name="klarna_category"]:checked').val();
243
- $('#klarna-instance-' + category).slideDown();
 
 
 
244
  }
245
 
246
  Klarna.prototype.hashChange = function(e) {
@@ -256,16 +259,16 @@
256
  window.Klarna.Payments.init({
257
  client_token: source.klarna.client_token
258
  }, function(response) {
259
-
260
  }.bind(this));
261
  this.payment_categories = source.klarna.payment_method_categories.split(",");
262
- this.render_ui();
263
  this.show_place_order();
264
  }
265
  }
266
  }
267
 
268
- Klarna.prototype.render_ui = function() {
269
  if (this.payment_categories.length > 0) {
270
  $('#wc_stripe_local_payment_stripe_klarna').show();
271
  for (var i = 0; i < this.payment_categories.length; i++) {
@@ -285,7 +288,9 @@
285
  }
286
  }
287
  }
288
- $('[id^="klarna-category-"]:visible [name="klarna_category"]').first().prop('checked', true).trigger('change');
 
 
289
  }
290
  }
291
 
@@ -327,7 +332,7 @@
327
 
328
  Klarna.prototype.updated_checkout = function() {
329
  if (this.payment_categories) {
330
- this.render_ui();
331
  }
332
  }
333
 
238
  }
239
 
240
  Klarna.prototype.category_change = function(e) {
241
+ var $el = $(e.currentTarget);
242
+ if ($el.is(':checked')) {
243
+ $('[id^="klarna-instance-"]').slideUp();
244
+ var category = $('[name="klarna_category"]:checked').val();
245
+ $('#klarna-instance-' + category).slideDown();
246
+ }
247
  }
248
 
249
  Klarna.prototype.hashChange = function(e) {
259
  window.Klarna.Payments.init({
260
  client_token: source.klarna.client_token
261
  }, function(response) {
262
+
263
  }.bind(this));
264
  this.payment_categories = source.klarna.payment_method_categories.split(",");
265
+ this.render_ui(true);
266
  this.show_place_order();
267
  }
268
  }
269
  }
270
 
271
+ Klarna.prototype.render_ui = function(trigger_change) {
272
  if (this.payment_categories.length > 0) {
273
  $('#wc_stripe_local_payment_stripe_klarna').show();
274
  for (var i = 0; i < this.payment_categories.length; i++) {
288
  }
289
  }
290
  }
291
+ if (trigger_change) {
292
+ $('[id^="klarna-category-"]:visible [name="klarna_category"]').first().prop('checked', true).trigger('change');
293
+ }
294
  }
295
  }
296
 
332
 
333
  Klarna.prototype.updated_checkout = function() {
334
  if (this.payment_categories) {
335
+ this.render_ui(false);
336
  }
337
  }
338
 
assets/js/frontend/payment-request.js CHANGED
@@ -147,6 +147,9 @@
147
  * @return {[type]} [description]
148
  */
149
  PaymentRequest.prototype.updated_html = function() {
 
 
 
150
  if (this.can_pay) {
151
  this.paymentRequestButton.destroy();
152
  this.initialize();
@@ -160,6 +163,15 @@
160
  }
161
  }));
162
  }
 
 
 
 
 
 
 
 
 
163
  }
164
 
165
  // Checkout page functionality
147
  * @return {[type]} [description]
148
  */
149
  PaymentRequest.prototype.updated_html = function() {
150
+ if (!$(this.container).length) {
151
+ this.can_pay = false;
152
+ }
153
  if (this.can_pay) {
154
  this.paymentRequestButton.destroy();
155
  this.initialize();
163
  }
164
  }));
165
  }
166
+
167
+ /**
168
+ * Called when the cart has been emptied
169
+ * @param {[type]} e [description]
170
+ * @return {[type]} [description]
171
+ */
172
+ PaymentRequest.prototype.cart_emptied = function(e) {
173
+ this.can_pay = false;
174
+ }
175
  }
176
 
177
  // Checkout page functionality
assets/js/frontend/wc-stripe.js CHANGED
@@ -1150,6 +1150,7 @@
1150
  // cart events
1151
  $(document.body).on('updated_wc_div', this.updated_html.bind(this));
1152
  $(document.body).on('updated_cart_totals', this.updated_html.bind(this));
 
1153
  }
1154
 
1155
  wc_stripe.CartGateway.prototype.needs_shipping = function() {
@@ -1172,6 +1173,8 @@
1172
 
1173
  }
1174
 
 
 
1175
  wc_stripe.CartGateway.prototype.add_cart_totals_class = function() {
1176
  $('.cart_totals').addClass('stripe_cart_gateway_active');
1177
  }
1150
  // cart events
1151
  $(document.body).on('updated_wc_div', this.updated_html.bind(this));
1152
  $(document.body).on('updated_cart_totals', this.updated_html.bind(this));
1153
+ $(document.body).on('wc_cart_emptied', this.cart_emptied.bind(this));
1154
  }
1155
 
1156
  wc_stripe.CartGateway.prototype.needs_shipping = function() {
1173
 
1174
  }
1175
 
1176
+ wc_stripe.CartGateway.prototype.cart_emptied = function(e) {}
1177
+
1178
  wc_stripe.CartGateway.prototype.add_cart_totals_class = function() {
1179
  $('.cart_totals').addClass('stripe_cart_gateway_active');
1180
  }
assets/js/frontend/wc-stripe.min.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){t.wc_stripe={};var i=null;wc_stripe.BaseGateway=function(t){this.params=t,this.gateway_id=this.params.gateway_id,this.token_selector=this.params.token_selector,this.saved_method_selector=this.params.saved_method_selector,this.payment_intent_selector=this.params.payment_intent_selector,this.payment_token_received=!1,this.stripe=i,this.elements=i.elements(e.extend({},{locale:"auto"},this.get_element_options())),this.initialize()},wc_stripe.BaseGateway.prototype.get_page=function(){return wc_stripe_params_v3.page},wc_stripe.BaseGateway.prototype.set_nonce=function(t){e(this.token_selector).val(t)},wc_stripe.BaseGateway.prototype.get_element_options=function(){return{}},wc_stripe.BaseGateway.prototype.initialize=function(){},wc_stripe.BaseGateway.prototype.create_button=function(){},wc_stripe.BaseGateway.prototype.is_gateway_selected=function(){return e('[name="payment_method"]:checked').val()===this.gateway_id},wc_stripe.BaseGateway.prototype.is_saved_method_selected=function(){return this.is_gateway_selected()&&"saved"===e('[name="'+this.gateway_id+'_payment_type_key"]:checked').val()},wc_stripe.BaseGateway.prototype.has_checkout_error=function(){return e("#wc_stripe_checkout_error").length>0&&this.is_gateway_selected()},wc_stripe.BaseGateway.prototype.submit_error=function(t){-1==(t=this.get_error_message(t)).indexOf("</ul>")&&(t='<div class="woocommerce-error">'+t+"</div>"),this.submit_message(t)},wc_stripe.BaseGateway.prototype.submit_error_code=function(t){},wc_stripe.BaseGateway.prototype.get_error_message=function(t){return"object"==typeof t&&t.code&&(t=wc_stripe_messages[t.code]?wc_stripe_messages[t.code]:t.message),t},wc_stripe.BaseGateway.prototype.submit_message=function(t){e(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove();var i=e(this.message_container);i.closest("form").length&&(i=i.closest("form")),i.prepend(t),i.removeClass("processing").unblock(),i.find(".input-text, select, input:checkbox").blur(),e.scroll_to_notices?e.scroll_to_notices(i):e("html, body").animate({scrollTop:i.offset().top-100},1e3)},wc_stripe.BaseGateway.prototype.get_first_name=function(t){return e("#"+t+"_first_name").val()},wc_stripe.BaseGateway.prototype.get_last_name=function(t){return e("#"+t+"_last_name").val()},wc_stripe.BaseGateway.prototype.should_save_method=function(){return e("#"+this.gateway_id+"_save_source_key").is(":checked")},wc_stripe.BaseGateway.prototype.is_add_payment_method_page=function(){return e(document.body).hasClass("woocommerce-add-payment-method")},wc_stripe.BaseGateway.prototype.get_selected_payment_method=function(){return e(this.saved_method_selector).val()},wc_stripe.BaseGateway.prototype.needs_shipping=function(){return"1"===this.params.needs_shipping},wc_stripe.BaseGateway.prototype.get_currency=function(){return e("#wc_stripe_currency").val()},wc_stripe.BaseGateway.prototype.get_country=function(){return e("#wc_stripe_country").val()},wc_stripe.BaseGateway.prototype.get_customer_name=function(t){return e(t+"_first_name").val()+" "+e(t+"_last_name").val()},wc_stripe.BaseGateway.prototype.get_customer_email=function(){return e("#billing_email").val()},wc_stripe.BaseGateway.prototype.get_address_field_hash=function(t){for(var i=["_first_name","_last_name","_address_1","_address_2","_postcode","_city","_state","_country"],a="",n=0;n<i.length;n++)a+=e(t+i[n]).val()+"_";return a},wc_stripe.BaseGateway.prototype.block=function(){e.blockUI({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.BaseGateway.prototype.unblock=function(){e.unblockUI()},wc_stripe.BaseGateway.prototype.get_form=function(){return e(this.token_selector).closest("form")},wc_stripe.BaseGateway.prototype.get_total_price=function(){return e("#wc_stripe_order_total").data("amount")},wc_stripe.BaseGateway.prototype.get_total_price_cents=function(){return e("#wc_stripe_order_total_cents").data("amount")},wc_stripe.BaseGateway.prototype.set_total_price=function(t){e("#wc_stripe_order_total").data("amount",t)},wc_stripe.BaseGateway.prototype.set_total_price_cents=function(t){e("#wc_stripe_order_total_cents").data("amount",t)},wc_stripe.BaseGateway.prototype.set_payment_method=function(t){e('[name="payment_method"][value="'+t+'"]').prop("checked",!0).trigger("click")},wc_stripe.BaseGateway.prototype.set_selected_shipping_methods=function(t){if(t&&e('[name^="shipping_method"]').length)for(var i in t){var a=t[i];e('[name="shipping_method['+i+']"][value="'+a+'"]').prop("checked",!0).trigger("change")}},wc_stripe.BaseGateway.prototype.on_token_received=function(t){this.payment_token_received=!0,e(this.token_selector).val(t.id),this.process_checkout()},wc_stripe.BaseGateway.prototype.createPaymentRequest=function(){try{this.paymentRequest=i.paymentRequest(this.get_payment_request_options())}catch(t){return void this.submit_error(t.message)}this.needs_shipping()&&(this.paymentRequest.on("shippingaddresschange",this.update_shipping_address.bind(this)),this.paymentRequest.on("shippingoptionchange",this.update_shipping_method.bind(this))),this.paymentRequest.on("paymentmethod",this.on_payment_method_received.bind(this))},wc_stripe.BaseGateway.prototype.get_payment_request_options=function(){var t={country:this.params.country_code,currency:this.get_currency().toLowerCase(),total:{amount:this.get_total_price_cents(),label:this.params.total_label,pending:!0},requestPayerName:!0,requestPayerEmail:e("#billing_email").length>0,requestPayerPhone:e("#billing_phone").length>0,requestShipping:this.needs_shipping()},i=this.get_display_items(),a=this.get_shipping_options();return i&&(t.displayItems=i),this.needs_shipping()&&a&&(t.shippingOptions=a),t},wc_stripe.BaseGateway.prototype.get_payment_request_update=function(t){var i={currency:this.get_currency().toLowerCase(),total:{amount:parseInt(this.get_total_price_cents()),label:this.params.total_label,pending:!0}},a=this.get_display_items(),n=this.get_shipping_options();return a&&(i.displayItems=a),this.needs_shipping()&&n&&(i.shippingOptions=n),t&&(i=e.extend(!0,{},i,t)),i},wc_stripe.BaseGateway.prototype.get_display_items=function(){return e("#wc_stripe_display_items").data("items")},wc_stripe.BaseGateway.prototype.set_display_items=function(t){e("#wc_stripe_display_items").data("items",t)},wc_stripe.BaseGateway.prototype.get_shipping_options=function(){return e("#wc_stripe_shipping_options").data("items")},wc_stripe.BaseGateway.prototype.set_shipping_options=function(t){e("#wc_stripe_shipping_options").data("items",t)},wc_stripe.BaseGateway.prototype.map_address=function(t){return{city:t.city,postcode:t.postalCode,state:t.region,country:t.country}},wc_stripe.BaseGateway.prototype.on_payment_method_received=function(e){try{this.payment_response=e,this.populate_checkout_fields(e),e.complete("success"),this.on_token_received(e.paymentMethod)}catch(e){t.alert(e)}},wc_stripe.BaseGateway.prototype.populate_checkout_fields=function(t){e(this.token_selector).val(t.paymentMethod.id),this.populate_address_fields(t)},wc_stripe.BaseGateway.prototype.populate_address_fields=function(t){var i=this.address_mappings();if(t.payerName&&i.payerName.set(t.payerName),t.payerEmail&&i.payerEmail.set(t.payerEmail),t.payerPhone&&i.payerPhone.set(t.payerPhone),t.shippingAddress){var a=t.shippingAddress;for(var n in a)i[n]&&i[n].set.call(this,a[n],"#shipping")}if(t.paymentMethod.billing_details.address){a=t.paymentMethod.billing_details.address;for(var n in a)i[n]&&i[n].set.call(this,a[n],"#billing")}this.maybe_set_ship_to_different(),e('[name="billing_country"]').trigger("change")},wc_stripe.BaseGateway.prototype.address_mappings=function(){return{payerName:{set:function(t,i){var a=t.split(" ");a.length>0&&e("#billing_first_name").val(a[0]),a.length>1&&e("#billing_last_name").val(a[1])},get:function(t){return e("#billing_first_name").val()+" "+e("#billing_last_name").val()}},payerEmail:{set:function(t){e("#billing_email").val(t)},get:function(){return e("#billing_email").val()}},payerPhone:{set:function(t){e("#billing_phone").val(t)},get:function(){return e("#billing_phone").val()}},recipient:{set:function(t,i){var a=t.split(" ");a.length>0&&e(i+"_first_name").val(a[0]),a.length>1&&e(i+"_last_name").val(a[1])},get:function(t){return e(t+"_first_name").val()+" "+e(t+"_last_name").val()}},country:{set:function(t,i){e(i+"_country").val(t)},get:function(t){return e(t+"_country").val()}},addressLine:{set:function(t,i){t.length>0&&e(i+"_address_1").val(t[0]),t.length>1&&e(i+"_address_2").val(t[1])},get:function(t){return[e(t+"_address_1").val(),e(t+"_address_2").val()]}},line1:{set:function(t,i){e(i+"_address_1").val(t)},get:function(t){return e(t+"_address_1").val()}},line2:{set:function(t,i){e(i+"_address_2").val(t)},get:function(t){return e(t+"_address_2").val()}},region:{set:function(t,i){e(i+"_state").val(t)},get:function(t){e(t+"_state").val()}},state:{set:function(t,i){e(i+"_state").val(t)},get:function(t){e(t+"_state").val()}},city:{set:function(t,i){e(i+"_city").val(t)},get:function(t){e(t+"_city").val()}},postalCode:{set:function(t,i){e(i+"_postcode").val(t)},get:function(t){e(t+"_postcode").val()}},postal_code:{set:function(t,i){e(i+"_postcode").val(t)},get:function(t){e(t+"_postcode").val()}}}},wc_stripe.BaseGateway.prototype.process_checkout=function(){return new Promise(function(i,a){this.block(),e.ajax({url:this.params.routes.checkout,method:"POST",dataType:"json",data:e.extend({},this.serialize_form(this.get_form()),{payment_method:this.gateway_id,page_id:this.get_page()}),beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)}).done(function(e){e.reload?t.location.reload():"success"===e.result?t.location=e.redirect:(e.messages&&this.submit_error(e.messages),this.unblock())}.bind(this)).fail(function(t,e,i){this.unblock(),this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.BaseGateway.prototype.serialize_form=function(t){var i=t.find("input").filter(function(t,i){return!e(i).is('[name^="add-to-cart"]')}.bind(this)).serializeArray(),a={};for(var n in i){var s=i[n];a[s.name]=s.value}return a.payment_method=this.gateway_id,a},wc_stripe.BaseGateway.prototype.map_shipping_methods=function(t){var e={};if("default"!==t){var i=t.match(/^(\d):(.+)$/);i.length>1&&(e[i[1]]=i[2])}return e},wc_stripe.BaseGateway.prototype.maybe_set_ship_to_different=function(){e('[name="ship_to_different_address"]').length&&e('[name="ship_to_different_address"]').prop("checked",this.get_address_field_hash("#billing")!==this.get_address_field_hash("#shipping")).trigger("change")},wc_stripe.BaseGateway.prototype.update_shipping_address=function(t){return new Promise(function(i,a){e.ajax({url:this.params.routes.shipping_address,method:"POST",dataType:"json",data:{address:this.map_address(t.shippingAddress),payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)}).done(function(e){e.code?(t.updateWith(e.data.newData),a(e.data)):(t.updateWith(e.data.newData),i(e.data))}.bind(this)).fail(function(t,e,i){}.bind(this))}.bind(this))},wc_stripe.BaseGateway.prototype.update_shipping_method=function(t){return new Promise(function(i,a){e.ajax({url:this.params.routes.shipping_method,method:"POST",dataType:"json",data:{shipping_methods:this.map_shipping_methods(t.shippingOption.id),payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)}).done(function(e){e.code?(t.updateWith(e.data.newData),a(e.data)):(this.set_selected_shipping_methods(e.data.shipping_methods),t.updateWith(e.data.newData),i(e.data))}.bind(this)).fail(function(t,e,i){this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.CheckoutGateway=function(){this.container=this.message_container="li.payment_method_"+this.gateway_id,this.banner_container="li.banner_payment_method_"+this.gateway_id,e(document.body).on("update_checkout",this.update_checkout.bind(this)),e(document.body).on("updated_checkout",this.updated_checkout.bind(this)),e(document.body).on("checkout_error",this.checkout_error.bind(this)),e(this.token_selector).closest("form").on("checkout_place_order_"+this.gateway_id,this.checkout_place_order.bind(this)),e(document.body).on("wc_stripe_new_method_"+this.gateway_id,this.on_show_new_methods.bind(this)),e(document.body).on("wc_stripe_saved_method_"+this.gateway_id,this.on_show_saved_methods.bind(this)),e(document.body).on("wc_stripe_payment_method_selected",this.on_payment_method_selected.bind(this)),this.banner_enabled()&&e(".woocommerce-billing-fields").length&&e(".wc-stripe-banner-checkout").css("max-width",e(".woocommerce-billing-fields").outerWidth(!0)),this.order_review()},wc_stripe.CheckoutGateway.prototype.order_review=function(){var e=t.location.href.match(/order_review.+payment_method=([\w]+).+payment_nonce=(.+)/);if(e&&e.length>1){var i=e[1],a=e[2];this.gateway_id===i&&(this.payment_token_received=!0,this.set_nonce(a),this.set_use_new_option(!0))}},wc_stripe.CheckoutGateway.prototype.updated_checkout=function(){},wc_stripe.CheckoutGateway.prototype.update_checkout=function(){},wc_stripe.CheckoutGateway.prototype.checkout_error=function(){this.has_checkout_error()&&(this.payment_token_received=!1,this.payment_response=null,this.show_payment_button(),this.hide_place_order())},wc_stripe.CheckoutGateway.prototype.is_valid_checkout=function(){return!(e('[name="terms"]').length&&!e('[name="terms"]').is(":checked"))},wc_stripe.CheckoutGateway.prototype.get_payment_method=function(){return e('[name="payment_method"]:checked').val()},wc_stripe.CheckoutGateway.prototype.set_use_new_option=function(t){e("#"+this.gateway_id+"_use_new").prop("checked",t).trigger("change")},wc_stripe.CheckoutGateway.prototype.checkout_place_order=function(){return this.is_valid_checkout()?!!this.is_saved_method_selected()||this.payment_token_received:(this.submit_error(this.params.messages.terms),!1)},wc_stripe.CheckoutGateway.prototype.on_token_received=function(t){this.payment_token_received=!0,e(this.token_selector).val(t.id),this.hide_payment_button(),this.show_place_order()},wc_stripe.CheckoutGateway.prototype.block=function(){e("form.checkout").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.CheckoutGateway.prototype.unblock=function(){e("form.checkout").unblock()},wc_stripe.CheckoutGateway.prototype.hide_place_order=function(){e("#place_order").addClass("wc-stripe-hide")},wc_stripe.CheckoutGateway.prototype.show_place_order=function(){e("#place_order").removeClass("wc-stripe-hide")},wc_stripe.CheckoutGateway.prototype.on_show_new_methods=function(){this.payment_token_received?(this.show_place_order(),this.hide_payment_button()):(this.hide_place_order(),this.show_payment_button())},wc_stripe.CheckoutGateway.prototype.on_show_saved_methods=function(){this.hide_payment_button(),this.show_place_order()},wc_stripe.CheckoutGateway.prototype.show_payment_button=function(){this.$button&&this.$button.show()},wc_stripe.CheckoutGateway.prototype.hide_payment_button=function(){this.$button&&this.$button.hide()},wc_stripe.CheckoutGateway.prototype.trigger_payment_method_selected=function(){this.on_payment_method_selected(null,e('[name="payment_method"]:checked').val())},wc_stripe.CheckoutGateway.prototype.on_payment_method_selected=function(t,e){e===this.gateway_id?this.payment_token_received||this.is_saved_method_selected()?(this.hide_payment_button(),this.show_place_order()):(this.show_payment_button(),this.hide_place_order()):(this.hide_payment_button(),e.indexOf("stripe_")<0&&this.show_place_order())},wc_stripe.CheckoutGateway.prototype.banner_enabled=function(){return"1"===this.params.banner_enabled},wc_stripe.CheckoutGateway.prototype.checkout_fields_valid=function(){if("undefined"==typeof wc_stripe_checkout_fields)return!0;var t=Object.keys(wc_stripe_checkout_fields.billing),i=Object.keys(wc_stripe_checkout_fields.shipping);function a(t,i){for(var a=0;a<t.length;a++){if(i[t[a]].required){var n=e("#"+t[a]).val();if(void 0===n||0==n.length)return void(valid=!1)}}}return valid=!0,a(t,wc_stripe_checkout_fields.billing),this.needs_shipping()&&e("#ship-to-different-address-checkbox").is(":checked")&&a(i,wc_stripe_checkout_fields.shipping),valid=this.is_valid_checkout(),valid},wc_stripe.ProductGateway=function(){this.container="li.payment_method_"+this.gateway_id,this.message_container="div.product",e(document.body).on("wc_stripe_updated_rest_nonce",this.set_rest_nonce.bind(this)),e("form.cart").on("found_variation",this.found_variation.bind(this)),e("form.cart").on("reset_data",this.reset_variation_data.bind(this)),this.buttonWidth=e("div.quantity").outerWidth(!0)+e(".single_add_to_cart_button").outerWidth(),(marginLeft=e(".single_add_to_cart_button").css("marginLeft"))&&(this.buttonWidth+=parseInt(marginLeft.replace("px",""))),e(this.container).css("max-width",this.buttonWidth+"px")},wc_stripe.ProductGateway.prototype.get_quantity=function(){return parseInt(e('[name="quantity"]').val())},wc_stripe.ProductGateway.prototype.set_rest_nonce=function(t,e){this.params.rest_nonce=e},wc_stripe.ProductGateway.prototype.found_variation=function(t,e){var i=this.get_product_data();i.price=e.display_price,i.needs_shipping=!e.is_virtual,i.variation=e,this.set_product_data(i),this.enable_payment_button()},wc_stripe.ProductGateway.prototype.reset_variation_data=function(){this.disable_payment_button()},wc_stripe.ProductGateway.prototype.disable_payment_button=function(){this.$button&&this.get_button().prop("disabled",!0).addClass("disabled")},wc_stripe.ProductGateway.prototype.enable_payment_button=function(){this.$button&&this.get_button().prop("disabled",!1).removeClass("disabled")},wc_stripe.ProductGateway.prototype.get_button=function(){return this.$button},wc_stripe.ProductGateway.prototype.is_variable_product=function(){return e('[name="variation_id"]').length>0},wc_stripe.ProductGateway.prototype.needs_shipping=function(){return this.get_product_data().needs_shipping},wc_stripe.ProductGateway.prototype.get_product_data=function(){return e("#wc_stripe_product_data").data("product")},wc_stripe.ProductGateway.prototype.set_product_data=function(t){e("#wc_stripe_product_data").data("product",t)},wc_stripe.ProductGateway.prototype.add_to_cart=function(){return new Promise(function(t,i){this.block(),e.ajax({url:this.params.routes.add_to_cart,method:"POST",dataType:"json",data:{product_id:e("#product_id").val(),variation_id:this.is_variable_product()?e('[name="variation_id"]').val():0,qty:e('[name="quantity"]').val(),payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)}).done(function(a,n,s){this.unblock(),e(document.body).triggerHandler("wc_stripe_updated_rest_nonce",s.getResponseHeader("X-WP-Nonce")),a.code?(this.submit_error(a.message),i(a)):(this.set_total_price(a.data.total),this.set_total_price_cents(a.data.totalCents),this.set_display_items(a.data.displayItems),t(a.data))}.bind(this)).fail(function(t,e,i){this.unblock(),this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.ProductGateway.prototype.cart_calculation=function(t){return new Promise(function(i,a){e.ajax({url:this.params.routes.cart_calculation,method:"POST",dataType:"json",data:{product_id:e("#product_id").val(),variation_id:this.is_variable_product()&&t?t:0,qty:e('[name="quantity"]').val(),payment_method:this.gateway_id},beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)}).done(function(t,a,n){e(document.body).triggerHandler("wc_stripe_updated_rest_nonce",n.getResponseHeader("X-WP-Nonce")),t.code?this.cart_calculation_error=!0:(this.set_total_price(t.data.total),this.set_total_price_cents(t.data.totalCents),this.set_display_items(t.data.displayItems),i(t.data))}.bind(this)).fail(function(t,e,i){}.bind(this))}.bind(this))},wc_stripe.CartGateway=function(){this.container="li.payment_method_"+this.gateway_id,this.message_container="div.woocommerce",e(document.body).on("updated_wc_div",this.updated_html.bind(this)),e(document.body).on("updated_cart_totals",this.updated_html.bind(this))},wc_stripe.CartGateway.prototype.needs_shipping=function(){return 1===e("#wc_stripe_needs_shipping").data("value")},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.add_cart_totals_class=function(){e(".cart_totals").addClass("stripe_cart_gateway_active")},wc_stripe.GooglePay=function(){};const a={apiVersion:2,apiVersionMinor:0},n={type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY"],allowedCardNetworks:["AMEX","DISCOVER","INTERAC","JCB","MASTERCARD","VISA"]}};wc_stripe.GooglePay.prototype.address_mappings=function(t){return{name:{set:function(t,i){var a=t.split(" ");e(i+"_first_name").val(a[0]),e(i+"_last_name").val(a[1])},get:function(t){return e(t+"_first_name").val()+e(t+"_last_name").val()}},postalCode:{set:function(t,i){e(i+"_postcode").val(t)},get:function(t){return e(t+"_postcode").val()}},countryCode:{set:function(t,i){e(i+"_country").val(t)},get:function(t){return e(t+"_country").val()}},phoneNumber:{set:function(t,i){e("#billing_phone").val(t)},get:function(){return"#billing_phone".val()}},address1:{set:function(t,i){e(i+"_address_1").val(t)},get:function(t){return e(t+"_address_1").val()}},address2:{set:function(t,i){e(i+"_address_2").val(t)},get:function(t){return e(t+"_address_2").val()}},locality:{set:function(t,i){e(i+"_city").val(t)},get:function(t){return e(t+"_city").val()}},administrativeArea:{set:function(t,i){e(i+"_state").val(t)},get:function(t){return e(t+"_state").val()}}}},wc_stripe.GooglePay.prototype.serialize_form=function(t){return e.extend({},wc_stripe.BaseGateway.prototype.serialize_form.apply(this,arguments),{order_review:!this.dynamic_price_enabled()})},wc_stripe.GooglePay.prototype.populate_address_fields=function(t){var i=t.paymentMethodData.info.billingAddress,a=this.address_mappings();for(var n in i)a[n]&&a[n].set.call(this,i[n],"#billing");if(t.shippingAddress)for(var n in t.shippingAddress)a[n]&&a[n].set.call(this,t.shippingAddress[n],"#shipping");t.email&&e("#billing_email").val(t.email),this.maybe_set_ship_to_different(),e('[name="billing_country"]').trigger("change")},wc_stripe.GooglePay.prototype.map_address=function(t){return{city:t.locality,postcode:t.postalCode,state:t.administrativeArea,country:t.countryCode}},wc_stripe.GooglePay.prototype.update_payment_data=function(t){return new Promise(function(i,a){e.when(e.ajax({url:this.params.routes.payment_data,dataType:"json",method:"POST",data:{shipping_address:this.map_address(t.shippingAddress),shipping_methods:this.map_shipping_methods(t.shippingOptionData.id),shipping_method_id:t.shippingOptionData.id,page_id:this.get_page()},beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)})).done(function(t){t.code?a(t.data.data):i(t.data)}.bind(this)).fail(function(){a()}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.on_payment_data_changed=function(t){return new Promise(function(e,i){this.update_payment_data(t).then(function(i){e(i.paymentRequestUpdate),this.set_selected_shipping_methods(i.shipping_methods),this.payment_data_updated(i,t)}.bind(this)).catch(function(t){e(t)}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.payment_data_updated=function(t){},wc_stripe.GooglePay.prototype.get_googlepay_display_items=function(){return e("#googlepay_display_items").data("items")},wc_stripe.GooglePay.prototype.set_googlepay_display_items=function(t){e("#googlepay_display_items").data("items",t)},wc_stripe.GooglePay.prototype.get_shipping_options=function(){return e("#googlepay_shipping_options").data("items")},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.dynamic_price_enabled=function(){return"1"===this.params.dynamic_price},wc_stripe.GooglePay.prototype.get_payment_options=function(){var t={environment:this.params.environment,merchantInfo:this.get_merchant_info()};return this.dynamic_price_enabled()&&(this.needs_shipping()&&this.get_total_price_cents()>0?t.paymentDataCallbacks={onPaymentDataChanged:this.on_payment_data_changed.bind(this),onPaymentAuthorized:function(t){return new Promise(function(t,e){t({transactionState:"SUCCESS"})}.bind(this))}.bind(this)}:t.paymentDataCallbacks={onPaymentAuthorized:function(t){return new Promise(function(t,e){t({transactionState:"SUCCESS"})}.bind(this))}}),t},wc_stripe.GooglePay.prototype.build_payment_request=function(){var t=e.extend({},a,{emailRequired:!0,merchantInfo:this.get_merchant_info(),allowedPaymentMethods:[e.extend({type:"CARD",tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:"stripe","stripe:version":"2018-10-31","stripe:publishableKey":this.params.api_key}}},n)],shippingAddressRequired:this.needs_shipping()&&this.get_total_price_cents()>0,transactionInfo:{currencyCode:this.get_currency(),totalPriceStatus:"ESTIMATED",totalPrice:this.get_total_price().toString(),displayItems:this.get_googlepay_display_items(),totalPriceLabel:this.params.total_price_label}});return t.allowedPaymentMethods[0].parameters.billingAddressRequired=!0,t.allowedPaymentMethods[0].parameters.billingAddressParameters={format:"FULL",phoneNumberRequired:e("#billing_phone").length>0},this.dynamic_price_enabled()&&(this.needs_shipping()&&this.get_total_price_cents()>0?(t.shippingAddressParameters={},t.shippingOptionRequired=!0,t.shippingOptionParameters={shippingOptions:this.get_shipping_options()},t.callbackIntents=["SHIPPING_ADDRESS","SHIPPING_OPTION","PAYMENT_AUTHORIZATION"]):t.callbackIntents=["PAYMENT_AUTHORIZATION"]),t},wc_stripe.GooglePay.prototype.createPaymentsClient=function(){this.paymentsClient=new google.payments.api.PaymentsClient(this.get_payment_options())},wc_stripe.GooglePay.prototype.isReadyToPay=function(){return new Promise(function(t){var i=e.extend({},a);i.allowedPaymentMethods=[n],this.paymentsClient.isReadyToPay(i).then(function(){this.can_pay=!0,this.create_button(),t()}.bind(this)).catch(function(t){this.submit_error(t)}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.create_button=function(){this.$button&&this.$button.remove(),this.$button=e(this.paymentsClient.createButton({onClick:this.start.bind(this),buttonColor:this.params.button_color,buttonType:this.params.button_style})),this.$button.addClass("gpay-button-container")},wc_stripe.GooglePay.prototype.start=function(){this.createPaymentsClient(),this.paymentsClient.loadPaymentData(this.build_payment_request()).then(function(t){var e=JSON.parse(t.paymentMethodData.tokenizationData.token);this.populate_address_fields(t),this.on_token_received(e)}.bind(this)).catch(function(t){"CANCELED"!==t.statusCode&&(t.statusMessage&&t.statusMessage.indexOf("paymentDataRequest.callbackIntent")>-1?this.submit_error_code("DEVELOPER_ERROR_WHITELIST"):this.submit_error(t.statusMessage))}.bind(this))},wc_stripe.ApplePay=function(){},wc_stripe.ApplePay.prototype.initialize=function(){e(document.body).on("click",".apple-pay-button",this.start.bind(this)),this.createPaymentRequest(),this.canMakePayment()},wc_stripe.ApplePay.prototype.create_button=function(){this.$button&&this.$button.remove(),this.$button=e(this.params.button),this.append_button()},wc_stripe.ApplePay.prototype.canMakePayment=function(){return new Promise(function(t,i){this.paymentRequest.canMakePayment().then(function(i){i&&i.applePay&&(this.can_pay=!0,this.create_button(),e(this.container).show(),t(i))}.bind(this))}.bind(this))},wc_stripe.ApplePay.prototype.start=function(t){t.preventDefault(),this.paymentRequest.update(this.get_payment_request_update({total:{pending:!1}})),this.paymentRequest.show()},wc_stripe.PaymentRequest=function(){},wc_stripe.PaymentRequest.prototype.initialize=function(){this.createPaymentRequest(),this.canMakePayment(),this.paymentRequestButton=this.createPaymentRequestButton(),this.paymentRequestButton.on("click",this.button_click.bind(this))},wc_stripe.PaymentRequest.prototype.button_click=function(t){},wc_stripe.PaymentRequest.prototype.createPaymentRequestButton=function(){return this.elements.create("paymentRequestButton",{paymentRequest:this.paymentRequest,style:{paymentRequestButton:{type:this.params.button.type,theme:this.params.button.theme,height:this.params.button.height}}})},wc_stripe.PaymentRequest.prototype.canMakePayment=function(){return new Promise(function(t,i){this.paymentRequest.canMakePayment().then(function(i){i&&!i.applePay&&(this.can_pay=!0,this.create_button(),e(this.container).show(),t(i))}.bind(this))}.bind(this))},wc_stripe.PaymentRequest.prototype.create_button=function(){this.paymentRequestButton.mount("#wc-stripe-payment-request-container")};try{i=Stripe(wc_stripe_params_v3.api_key,{stripeAccount:wc_stripe_params_v3.account})}catch(e){return t.alert(e),void console.log(e)}}(window,jQuery);
1
+ !function(t,e){t.wc_stripe={};var i=null;wc_stripe.BaseGateway=function(t){this.params=t,this.gateway_id=this.params.gateway_id,this.token_selector=this.params.token_selector,this.saved_method_selector=this.params.saved_method_selector,this.payment_intent_selector=this.params.payment_intent_selector,this.payment_token_received=!1,this.stripe=i,this.elements=i.elements(e.extend({},{locale:"auto"},this.get_element_options())),this.initialize()},wc_stripe.BaseGateway.prototype.get_page=function(){return wc_stripe_params_v3.page},wc_stripe.BaseGateway.prototype.set_nonce=function(t){e(this.token_selector).val(t)},wc_stripe.BaseGateway.prototype.get_element_options=function(){return{}},wc_stripe.BaseGateway.prototype.initialize=function(){},wc_stripe.BaseGateway.prototype.create_button=function(){},wc_stripe.BaseGateway.prototype.is_gateway_selected=function(){return e('[name="payment_method"]:checked').val()===this.gateway_id},wc_stripe.BaseGateway.prototype.is_saved_method_selected=function(){return this.is_gateway_selected()&&"saved"===e('[name="'+this.gateway_id+'_payment_type_key"]:checked').val()},wc_stripe.BaseGateway.prototype.has_checkout_error=function(){return e("#wc_stripe_checkout_error").length>0&&this.is_gateway_selected()},wc_stripe.BaseGateway.prototype.submit_error=function(t){-1==(t=this.get_error_message(t)).indexOf("</ul>")&&(t='<div class="woocommerce-error">'+t+"</div>"),this.submit_message(t)},wc_stripe.BaseGateway.prototype.submit_error_code=function(t){},wc_stripe.BaseGateway.prototype.get_error_message=function(t){return"object"==typeof t&&t.code&&(t=wc_stripe_messages[t.code]?wc_stripe_messages[t.code]:t.message),t},wc_stripe.BaseGateway.prototype.submit_message=function(t){e(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove();var i=e(this.message_container);i.closest("form").length&&(i=i.closest("form")),i.prepend(t),i.removeClass("processing").unblock(),i.find(".input-text, select, input:checkbox").blur(),e.scroll_to_notices?e.scroll_to_notices(i):e("html, body").animate({scrollTop:i.offset().top-100},1e3)},wc_stripe.BaseGateway.prototype.get_first_name=function(t){return e("#"+t+"_first_name").val()},wc_stripe.BaseGateway.prototype.get_last_name=function(t){return e("#"+t+"_last_name").val()},wc_stripe.BaseGateway.prototype.should_save_method=function(){return e("#"+this.gateway_id+"_save_source_key").is(":checked")},wc_stripe.BaseGateway.prototype.is_add_payment_method_page=function(){return e(document.body).hasClass("woocommerce-add-payment-method")},wc_stripe.BaseGateway.prototype.get_selected_payment_method=function(){return e(this.saved_method_selector).val()},wc_stripe.BaseGateway.prototype.needs_shipping=function(){return"1"===this.params.needs_shipping},wc_stripe.BaseGateway.prototype.get_currency=function(){return e("#wc_stripe_currency").val()},wc_stripe.BaseGateway.prototype.get_country=function(){return e("#wc_stripe_country").val()},wc_stripe.BaseGateway.prototype.get_customer_name=function(t){return e(t+"_first_name").val()+" "+e(t+"_last_name").val()},wc_stripe.BaseGateway.prototype.get_customer_email=function(){return e("#billing_email").val()},wc_stripe.BaseGateway.prototype.get_address_field_hash=function(t){for(var i=["_first_name","_last_name","_address_1","_address_2","_postcode","_city","_state","_country"],a="",n=0;n<i.length;n++)a+=e(t+i[n]).val()+"_";return a},wc_stripe.BaseGateway.prototype.block=function(){e.blockUI({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.BaseGateway.prototype.unblock=function(){e.unblockUI()},wc_stripe.BaseGateway.prototype.get_form=function(){return e(this.token_selector).closest("form")},wc_stripe.BaseGateway.prototype.get_total_price=function(){return e("#wc_stripe_order_total").data("amount")},wc_stripe.BaseGateway.prototype.get_total_price_cents=function(){return e("#wc_stripe_order_total_cents").data("amount")},wc_stripe.BaseGateway.prototype.set_total_price=function(t){e("#wc_stripe_order_total").data("amount",t)},wc_stripe.BaseGateway.prototype.set_total_price_cents=function(t){e("#wc_stripe_order_total_cents").data("amount",t)},wc_stripe.BaseGateway.prototype.set_payment_method=function(t){e('[name="payment_method"][value="'+t+'"]').prop("checked",!0).trigger("click")},wc_stripe.BaseGateway.prototype.set_selected_shipping_methods=function(t){if(t&&e('[name^="shipping_method"]').length)for(var i in t){var a=t[i];e('[name="shipping_method['+i+']"][value="'+a+'"]').prop("checked",!0).trigger("change")}},wc_stripe.BaseGateway.prototype.on_token_received=function(t){this.payment_token_received=!0,e(this.token_selector).val(t.id),this.process_checkout()},wc_stripe.BaseGateway.prototype.createPaymentRequest=function(){try{this.paymentRequest=i.paymentRequest(this.get_payment_request_options())}catch(t){return void this.submit_error(t.message)}this.needs_shipping()&&(this.paymentRequest.on("shippingaddresschange",this.update_shipping_address.bind(this)),this.paymentRequest.on("shippingoptionchange",this.update_shipping_method.bind(this))),this.paymentRequest.on("paymentmethod",this.on_payment_method_received.bind(this))},wc_stripe.BaseGateway.prototype.get_payment_request_options=function(){var t={country:this.params.country_code,currency:this.get_currency().toLowerCase(),total:{amount:this.get_total_price_cents(),label:this.params.total_label,pending:!0},requestPayerName:!0,requestPayerEmail:e("#billing_email").length>0,requestPayerPhone:e("#billing_phone").length>0,requestShipping:this.needs_shipping()},i=this.get_display_items(),a=this.get_shipping_options();return i&&(t.displayItems=i),this.needs_shipping()&&a&&(t.shippingOptions=a),t},wc_stripe.BaseGateway.prototype.get_payment_request_update=function(t){var i={currency:this.get_currency().toLowerCase(),total:{amount:parseInt(this.get_total_price_cents()),label:this.params.total_label,pending:!0}},a=this.get_display_items(),n=this.get_shipping_options();return a&&(i.displayItems=a),this.needs_shipping()&&n&&(i.shippingOptions=n),t&&(i=e.extend(!0,{},i,t)),i},wc_stripe.BaseGateway.prototype.get_display_items=function(){return e("#wc_stripe_display_items").data("items")},wc_stripe.BaseGateway.prototype.set_display_items=function(t){e("#wc_stripe_display_items").data("items",t)},wc_stripe.BaseGateway.prototype.get_shipping_options=function(){return e("#wc_stripe_shipping_options").data("items")},wc_stripe.BaseGateway.prototype.set_shipping_options=function(t){e("#wc_stripe_shipping_options").data("items",t)},wc_stripe.BaseGateway.prototype.map_address=function(t){return{city:t.city,postcode:t.postalCode,state:t.region,country:t.country}},wc_stripe.BaseGateway.prototype.on_payment_method_received=function(e){try{this.payment_response=e,this.populate_checkout_fields(e),e.complete("success"),this.on_token_received(e.paymentMethod)}catch(e){t.alert(e)}},wc_stripe.BaseGateway.prototype.populate_checkout_fields=function(t){e(this.token_selector).val(t.paymentMethod.id),this.populate_address_fields(t)},wc_stripe.BaseGateway.prototype.populate_address_fields=function(t){var i=this.address_mappings();if(t.payerName&&i.payerName.set(t.payerName),t.payerEmail&&i.payerEmail.set(t.payerEmail),t.payerPhone&&i.payerPhone.set(t.payerPhone),t.shippingAddress){var a=t.shippingAddress;for(var n in a)i[n]&&i[n].set.call(this,a[n],"#shipping")}if(t.paymentMethod.billing_details.address){a=t.paymentMethod.billing_details.address;for(var n in a)i[n]&&i[n].set.call(this,a[n],"#billing")}this.maybe_set_ship_to_different(),e('[name="billing_country"]').trigger("change")},wc_stripe.BaseGateway.prototype.address_mappings=function(){return{payerName:{set:function(t,i){var a=t.split(" ");a.length>0&&e("#billing_first_name").val(a[0]),a.length>1&&e("#billing_last_name").val(a[1])},get:function(t){return e("#billing_first_name").val()+" "+e("#billing_last_name").val()}},payerEmail:{set:function(t){e("#billing_email").val(t)},get:function(){return e("#billing_email").val()}},payerPhone:{set:function(t){e("#billing_phone").val(t)},get:function(){return e("#billing_phone").val()}},recipient:{set:function(t,i){var a=t.split(" ");a.length>0&&e(i+"_first_name").val(a[0]),a.length>1&&e(i+"_last_name").val(a[1])},get:function(t){return e(t+"_first_name").val()+" "+e(t+"_last_name").val()}},country:{set:function(t,i){e(i+"_country").val(t)},get:function(t){return e(t+"_country").val()}},addressLine:{set:function(t,i){t.length>0&&e(i+"_address_1").val(t[0]),t.length>1&&e(i+"_address_2").val(t[1])},get:function(t){return[e(t+"_address_1").val(),e(t+"_address_2").val()]}},line1:{set:function(t,i){e(i+"_address_1").val(t)},get:function(t){return e(t+"_address_1").val()}},line2:{set:function(t,i){e(i+"_address_2").val(t)},get:function(t){return e(t+"_address_2").val()}},region:{set:function(t,i){e(i+"_state").val(t)},get:function(t){e(t+"_state").val()}},state:{set:function(t,i){e(i+"_state").val(t)},get:function(t){e(t+"_state").val()}},city:{set:function(t,i){e(i+"_city").val(t)},get:function(t){e(t+"_city").val()}},postalCode:{set:function(t,i){e(i+"_postcode").val(t)},get:function(t){e(t+"_postcode").val()}},postal_code:{set:function(t,i){e(i+"_postcode").val(t)},get:function(t){e(t+"_postcode").val()}}}},wc_stripe.BaseGateway.prototype.process_checkout=function(){return new Promise(function(i,a){this.block(),e.ajax({url:this.params.routes.checkout,method:"POST",dataType:"json",data:e.extend({},this.serialize_form(this.get_form()),{payment_method:this.gateway_id,page_id:this.get_page()}),beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)}).done(function(e){e.reload?t.location.reload():"success"===e.result?t.location=e.redirect:(e.messages&&this.submit_error(e.messages),this.unblock())}.bind(this)).fail(function(t,e,i){this.unblock(),this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.BaseGateway.prototype.serialize_form=function(t){var i=t.find("input").filter(function(t,i){return!e(i).is('[name^="add-to-cart"]')}.bind(this)).serializeArray(),a={};for(var n in i){var s=i[n];a[s.name]=s.value}return a.payment_method=this.gateway_id,a},wc_stripe.BaseGateway.prototype.map_shipping_methods=function(t){var e={};if("default"!==t){var i=t.match(/^(\d):(.+)$/);i.length>1&&(e[i[1]]=i[2])}return e},wc_stripe.BaseGateway.prototype.maybe_set_ship_to_different=function(){e('[name="ship_to_different_address"]').length&&e('[name="ship_to_different_address"]').prop("checked",this.get_address_field_hash("#billing")!==this.get_address_field_hash("#shipping")).trigger("change")},wc_stripe.BaseGateway.prototype.update_shipping_address=function(t){return new Promise(function(i,a){e.ajax({url:this.params.routes.shipping_address,method:"POST",dataType:"json",data:{address:this.map_address(t.shippingAddress),payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)}).done(function(e){e.code?(t.updateWith(e.data.newData),a(e.data)):(t.updateWith(e.data.newData),i(e.data))}.bind(this)).fail(function(t,e,i){}.bind(this))}.bind(this))},wc_stripe.BaseGateway.prototype.update_shipping_method=function(t){return new Promise(function(i,a){e.ajax({url:this.params.routes.shipping_method,method:"POST",dataType:"json",data:{shipping_methods:this.map_shipping_methods(t.shippingOption.id),payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)}).done(function(e){e.code?(t.updateWith(e.data.newData),a(e.data)):(this.set_selected_shipping_methods(e.data.shipping_methods),t.updateWith(e.data.newData),i(e.data))}.bind(this)).fail(function(t,e,i){this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.CheckoutGateway=function(){this.container=this.message_container="li.payment_method_"+this.gateway_id,this.banner_container="li.banner_payment_method_"+this.gateway_id,e(document.body).on("update_checkout",this.update_checkout.bind(this)),e(document.body).on("updated_checkout",this.updated_checkout.bind(this)),e(document.body).on("checkout_error",this.checkout_error.bind(this)),e(this.token_selector).closest("form").on("checkout_place_order_"+this.gateway_id,this.checkout_place_order.bind(this)),e(document.body).on("wc_stripe_new_method_"+this.gateway_id,this.on_show_new_methods.bind(this)),e(document.body).on("wc_stripe_saved_method_"+this.gateway_id,this.on_show_saved_methods.bind(this)),e(document.body).on("wc_stripe_payment_method_selected",this.on_payment_method_selected.bind(this)),this.banner_enabled()&&e(".woocommerce-billing-fields").length&&e(".wc-stripe-banner-checkout").css("max-width",e(".woocommerce-billing-fields").outerWidth(!0)),this.order_review()},wc_stripe.CheckoutGateway.prototype.order_review=function(){var e=t.location.href.match(/order_review.+payment_method=([\w]+).+payment_nonce=(.+)/);if(e&&e.length>1){var i=e[1],a=e[2];this.gateway_id===i&&(this.payment_token_received=!0,this.set_nonce(a),this.set_use_new_option(!0))}},wc_stripe.CheckoutGateway.prototype.updated_checkout=function(){},wc_stripe.CheckoutGateway.prototype.update_checkout=function(){},wc_stripe.CheckoutGateway.prototype.checkout_error=function(){this.has_checkout_error()&&(this.payment_token_received=!1,this.payment_response=null,this.show_payment_button(),this.hide_place_order())},wc_stripe.CheckoutGateway.prototype.is_valid_checkout=function(){return!(e('[name="terms"]').length&&!e('[name="terms"]').is(":checked"))},wc_stripe.CheckoutGateway.prototype.get_payment_method=function(){return e('[name="payment_method"]:checked').val()},wc_stripe.CheckoutGateway.prototype.set_use_new_option=function(t){e("#"+this.gateway_id+"_use_new").prop("checked",t).trigger("change")},wc_stripe.CheckoutGateway.prototype.checkout_place_order=function(){return this.is_valid_checkout()?!!this.is_saved_method_selected()||this.payment_token_received:(this.submit_error(this.params.messages.terms),!1)},wc_stripe.CheckoutGateway.prototype.on_token_received=function(t){this.payment_token_received=!0,e(this.token_selector).val(t.id),this.hide_payment_button(),this.show_place_order()},wc_stripe.CheckoutGateway.prototype.block=function(){e("form.checkout").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},wc_stripe.CheckoutGateway.prototype.unblock=function(){e("form.checkout").unblock()},wc_stripe.CheckoutGateway.prototype.hide_place_order=function(){e("#place_order").addClass("wc-stripe-hide")},wc_stripe.CheckoutGateway.prototype.show_place_order=function(){e("#place_order").removeClass("wc-stripe-hide")},wc_stripe.CheckoutGateway.prototype.on_show_new_methods=function(){this.payment_token_received?(this.show_place_order(),this.hide_payment_button()):(this.hide_place_order(),this.show_payment_button())},wc_stripe.CheckoutGateway.prototype.on_show_saved_methods=function(){this.hide_payment_button(),this.show_place_order()},wc_stripe.CheckoutGateway.prototype.show_payment_button=function(){this.$button&&this.$button.show()},wc_stripe.CheckoutGateway.prototype.hide_payment_button=function(){this.$button&&this.$button.hide()},wc_stripe.CheckoutGateway.prototype.trigger_payment_method_selected=function(){this.on_payment_method_selected(null,e('[name="payment_method"]:checked').val())},wc_stripe.CheckoutGateway.prototype.on_payment_method_selected=function(t,e){e===this.gateway_id?this.payment_token_received||this.is_saved_method_selected()?(this.hide_payment_button(),this.show_place_order()):(this.show_payment_button(),this.hide_place_order()):(this.hide_payment_button(),e.indexOf("stripe_")<0&&this.show_place_order())},wc_stripe.CheckoutGateway.prototype.banner_enabled=function(){return"1"===this.params.banner_enabled},wc_stripe.CheckoutGateway.prototype.checkout_fields_valid=function(){if("undefined"==typeof wc_stripe_checkout_fields)return!0;var t=Object.keys(wc_stripe_checkout_fields.billing),i=Object.keys(wc_stripe_checkout_fields.shipping);function a(t,i){for(var a=0;a<t.length;a++){if(i[t[a]].required){var n=e("#"+t[a]).val();if(void 0===n||0==n.length)return void(valid=!1)}}}return valid=!0,a(t,wc_stripe_checkout_fields.billing),this.needs_shipping()&&e("#ship-to-different-address-checkbox").is(":checked")&&a(i,wc_stripe_checkout_fields.shipping),valid=this.is_valid_checkout(),valid},wc_stripe.ProductGateway=function(){this.container="li.payment_method_"+this.gateway_id,this.message_container="div.product",e(document.body).on("wc_stripe_updated_rest_nonce",this.set_rest_nonce.bind(this)),e("form.cart").on("found_variation",this.found_variation.bind(this)),e("form.cart").on("reset_data",this.reset_variation_data.bind(this)),this.buttonWidth=e("div.quantity").outerWidth(!0)+e(".single_add_to_cart_button").outerWidth(),(marginLeft=e(".single_add_to_cart_button").css("marginLeft"))&&(this.buttonWidth+=parseInt(marginLeft.replace("px",""))),e(this.container).css("max-width",this.buttonWidth+"px")},wc_stripe.ProductGateway.prototype.get_quantity=function(){return parseInt(e('[name="quantity"]').val())},wc_stripe.ProductGateway.prototype.set_rest_nonce=function(t,e){this.params.rest_nonce=e},wc_stripe.ProductGateway.prototype.found_variation=function(t,e){var i=this.get_product_data();i.price=e.display_price,i.needs_shipping=!e.is_virtual,i.variation=e,this.set_product_data(i),this.enable_payment_button()},wc_stripe.ProductGateway.prototype.reset_variation_data=function(){this.disable_payment_button()},wc_stripe.ProductGateway.prototype.disable_payment_button=function(){this.$button&&this.get_button().prop("disabled",!0).addClass("disabled")},wc_stripe.ProductGateway.prototype.enable_payment_button=function(){this.$button&&this.get_button().prop("disabled",!1).removeClass("disabled")},wc_stripe.ProductGateway.prototype.get_button=function(){return this.$button},wc_stripe.ProductGateway.prototype.is_variable_product=function(){return e('[name="variation_id"]').length>0},wc_stripe.ProductGateway.prototype.needs_shipping=function(){return this.get_product_data().needs_shipping},wc_stripe.ProductGateway.prototype.get_product_data=function(){return e("#wc_stripe_product_data").data("product")},wc_stripe.ProductGateway.prototype.set_product_data=function(t){e("#wc_stripe_product_data").data("product",t)},wc_stripe.ProductGateway.prototype.add_to_cart=function(){return new Promise(function(t,i){this.block(),e.ajax({url:this.params.routes.add_to_cart,method:"POST",dataType:"json",data:{product_id:e("#product_id").val(),variation_id:this.is_variable_product()?e('[name="variation_id"]').val():0,qty:e('[name="quantity"]').val(),payment_method:this.gateway_id,page_id:this.get_page()},beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)}).done(function(a,n,s){this.unblock(),e(document.body).triggerHandler("wc_stripe_updated_rest_nonce",s.getResponseHeader("X-WP-Nonce")),a.code?(this.submit_error(a.message),i(a)):(this.set_total_price(a.data.total),this.set_total_price_cents(a.data.totalCents),this.set_display_items(a.data.displayItems),t(a.data))}.bind(this)).fail(function(t,e,i){this.unblock(),this.submit_error(i)}.bind(this))}.bind(this))},wc_stripe.ProductGateway.prototype.cart_calculation=function(t){return new Promise(function(i,a){e.ajax({url:this.params.routes.cart_calculation,method:"POST",dataType:"json",data:{product_id:e("#product_id").val(),variation_id:this.is_variable_product()&&t?t:0,qty:e('[name="quantity"]').val(),payment_method:this.gateway_id},beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)}).done(function(t,a,n){e(document.body).triggerHandler("wc_stripe_updated_rest_nonce",n.getResponseHeader("X-WP-Nonce")),t.code?this.cart_calculation_error=!0:(this.set_total_price(t.data.total),this.set_total_price_cents(t.data.totalCents),this.set_display_items(t.data.displayItems),i(t.data))}.bind(this)).fail(function(t,e,i){}.bind(this))}.bind(this))},wc_stripe.CartGateway=function(){this.container="li.payment_method_"+this.gateway_id,this.message_container="div.woocommerce",e(document.body).on("updated_wc_div",this.updated_html.bind(this)),e(document.body).on("updated_cart_totals",this.updated_html.bind(this)),e(document.body).on("wc_cart_emptied",this.cart_emptied.bind(this))},wc_stripe.CartGateway.prototype.needs_shipping=function(){return 1===e("#wc_stripe_needs_shipping").data("value")},wc_stripe.CartGateway.prototype.submit_error=function(t){this.submit_message(this.get_error_message(t))},wc_stripe.CartGateway.prototype.updated_html=function(t){},wc_stripe.CartGateway.prototype.cart_emptied=function(t){},wc_stripe.CartGateway.prototype.add_cart_totals_class=function(){e(".cart_totals").addClass("stripe_cart_gateway_active")},wc_stripe.GooglePay=function(){};const a={apiVersion:2,apiVersionMinor:0},n={type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY"],allowedCardNetworks:["AMEX","DISCOVER","INTERAC","JCB","MASTERCARD","VISA"]}};wc_stripe.GooglePay.prototype.address_mappings=function(t){return{name:{set:function(t,i){var a=t.split(" ");e(i+"_first_name").val(a[0]),e(i+"_last_name").val(a[1])},get:function(t){return e(t+"_first_name").val()+e(t+"_last_name").val()}},postalCode:{set:function(t,i){e(i+"_postcode").val(t)},get:function(t){return e(t+"_postcode").val()}},countryCode:{set:function(t,i){e(i+"_country").val(t)},get:function(t){return e(t+"_country").val()}},phoneNumber:{set:function(t,i){e("#billing_phone").val(t)},get:function(){return"#billing_phone".val()}},address1:{set:function(t,i){e(i+"_address_1").val(t)},get:function(t){return e(t+"_address_1").val()}},address2:{set:function(t,i){e(i+"_address_2").val(t)},get:function(t){return e(t+"_address_2").val()}},locality:{set:function(t,i){e(i+"_city").val(t)},get:function(t){return e(t+"_city").val()}},administrativeArea:{set:function(t,i){e(i+"_state").val(t)},get:function(t){return e(t+"_state").val()}}}},wc_stripe.GooglePay.prototype.serialize_form=function(t){return e.extend({},wc_stripe.BaseGateway.prototype.serialize_form.apply(this,arguments),{order_review:!this.dynamic_price_enabled()})},wc_stripe.GooglePay.prototype.populate_address_fields=function(t){var i=t.paymentMethodData.info.billingAddress,a=this.address_mappings();for(var n in i)a[n]&&a[n].set.call(this,i[n],"#billing");if(t.shippingAddress)for(var n in t.shippingAddress)a[n]&&a[n].set.call(this,t.shippingAddress[n],"#shipping");t.email&&e("#billing_email").val(t.email),this.maybe_set_ship_to_different(),e('[name="billing_country"]').trigger("change")},wc_stripe.GooglePay.prototype.map_address=function(t){return{city:t.locality,postcode:t.postalCode,state:t.administrativeArea,country:t.countryCode}},wc_stripe.GooglePay.prototype.update_payment_data=function(t){return new Promise(function(i,a){e.when(e.ajax({url:this.params.routes.payment_data,dataType:"json",method:"POST",data:{shipping_address:this.map_address(t.shippingAddress),shipping_methods:this.map_shipping_methods(t.shippingOptionData.id),shipping_method_id:t.shippingOptionData.id,page_id:this.get_page()},beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",this.params.rest_nonce)}.bind(this)})).done(function(t){t.code?a(t.data.data):i(t.data)}.bind(this)).fail(function(){a()}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.on_payment_data_changed=function(t){return new Promise(function(e,i){this.update_payment_data(t).then(function(i){e(i.paymentRequestUpdate),this.set_selected_shipping_methods(i.shipping_methods),this.payment_data_updated(i,t)}.bind(this)).catch(function(t){e(t)}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.payment_data_updated=function(t){},wc_stripe.GooglePay.prototype.get_googlepay_display_items=function(){return e("#googlepay_display_items").data("items")},wc_stripe.GooglePay.prototype.set_googlepay_display_items=function(t){e("#googlepay_display_items").data("items",t)},wc_stripe.GooglePay.prototype.get_shipping_options=function(){return e("#googlepay_shipping_options").data("items")},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.dynamic_price_enabled=function(){return"1"===this.params.dynamic_price},wc_stripe.GooglePay.prototype.get_payment_options=function(){var t={environment:this.params.environment,merchantInfo:this.get_merchant_info()};return this.dynamic_price_enabled()&&(this.needs_shipping()&&this.get_total_price_cents()>0?t.paymentDataCallbacks={onPaymentDataChanged:this.on_payment_data_changed.bind(this),onPaymentAuthorized:function(t){return new Promise(function(t,e){t({transactionState:"SUCCESS"})}.bind(this))}.bind(this)}:t.paymentDataCallbacks={onPaymentAuthorized:function(t){return new Promise(function(t,e){t({transactionState:"SUCCESS"})}.bind(this))}}),t},wc_stripe.GooglePay.prototype.build_payment_request=function(){var t=e.extend({},a,{emailRequired:!0,merchantInfo:this.get_merchant_info(),allowedPaymentMethods:[e.extend({type:"CARD",tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:"stripe","stripe:version":"2018-10-31","stripe:publishableKey":this.params.api_key}}},n)],shippingAddressRequired:this.needs_shipping()&&this.get_total_price_cents()>0,transactionInfo:{currencyCode:this.get_currency(),totalPriceStatus:"ESTIMATED",totalPrice:this.get_total_price().toString(),displayItems:this.get_googlepay_display_items(),totalPriceLabel:this.params.total_price_label}});return t.allowedPaymentMethods[0].parameters.billingAddressRequired=!0,t.allowedPaymentMethods[0].parameters.billingAddressParameters={format:"FULL",phoneNumberRequired:e("#billing_phone").length>0},this.dynamic_price_enabled()&&(this.needs_shipping()&&this.get_total_price_cents()>0?(t.shippingAddressParameters={},t.shippingOptionRequired=!0,t.shippingOptionParameters={shippingOptions:this.get_shipping_options()},t.callbackIntents=["SHIPPING_ADDRESS","SHIPPING_OPTION","PAYMENT_AUTHORIZATION"]):t.callbackIntents=["PAYMENT_AUTHORIZATION"]),t},wc_stripe.GooglePay.prototype.createPaymentsClient=function(){this.paymentsClient=new google.payments.api.PaymentsClient(this.get_payment_options())},wc_stripe.GooglePay.prototype.isReadyToPay=function(){return new Promise(function(t){var i=e.extend({},a);i.allowedPaymentMethods=[n],this.paymentsClient.isReadyToPay(i).then(function(){this.can_pay=!0,this.create_button(),t()}.bind(this)).catch(function(t){this.submit_error(t)}.bind(this))}.bind(this))},wc_stripe.GooglePay.prototype.create_button=function(){this.$button&&this.$button.remove(),this.$button=e(this.paymentsClient.createButton({onClick:this.start.bind(this),buttonColor:this.params.button_color,buttonType:this.params.button_style})),this.$button.addClass("gpay-button-container")},wc_stripe.GooglePay.prototype.start=function(){this.createPaymentsClient(),this.paymentsClient.loadPaymentData(this.build_payment_request()).then(function(t){var e=JSON.parse(t.paymentMethodData.tokenizationData.token);this.populate_address_fields(t),this.on_token_received(e)}.bind(this)).catch(function(t){"CANCELED"!==t.statusCode&&(t.statusMessage&&t.statusMessage.indexOf("paymentDataRequest.callbackIntent")>-1?this.submit_error_code("DEVELOPER_ERROR_WHITELIST"):this.submit_error(t.statusMessage))}.bind(this))},wc_stripe.ApplePay=function(){},wc_stripe.ApplePay.prototype.initialize=function(){e(document.body).on("click",".apple-pay-button",this.start.bind(this)),this.createPaymentRequest(),this.canMakePayment()},wc_stripe.ApplePay.prototype.create_button=function(){this.$button&&this.$button.remove(),this.$button=e(this.params.button),this.append_button()},wc_stripe.ApplePay.prototype.canMakePayment=function(){return new Promise(function(t,i){this.paymentRequest.canMakePayment().then(function(i){i&&i.applePay&&(this.can_pay=!0,this.create_button(),e(this.container).show(),t(i))}.bind(this))}.bind(this))},wc_stripe.ApplePay.prototype.start=function(t){t.preventDefault(),this.paymentRequest.update(this.get_payment_request_update({total:{pending:!1}})),this.paymentRequest.show()},wc_stripe.PaymentRequest=function(){},wc_stripe.PaymentRequest.prototype.initialize=function(){this.createPaymentRequest(),this.canMakePayment(),this.paymentRequestButton=this.createPaymentRequestButton(),this.paymentRequestButton.on("click",this.button_click.bind(this))},wc_stripe.PaymentRequest.prototype.button_click=function(t){},wc_stripe.PaymentRequest.prototype.createPaymentRequestButton=function(){return this.elements.create("paymentRequestButton",{paymentRequest:this.paymentRequest,style:{paymentRequestButton:{type:this.params.button.type,theme:this.params.button.theme,height:this.params.button.height}}})},wc_stripe.PaymentRequest.prototype.canMakePayment=function(){return new Promise(function(t,i){this.paymentRequest.canMakePayment().then(function(i){i&&!i.applePay&&(this.can_pay=!0,this.create_button(),e(this.container).show(),t(i))}.bind(this))}.bind(this))},wc_stripe.PaymentRequest.prototype.create_button=function(){this.paymentRequestButton.mount("#wc-stripe-payment-request-container")};try{i=Stripe(wc_stripe_params_v3.api_key,{stripeAccount:wc_stripe_params_v3.account})}catch(e){return t.alert(e),void console.log(e)}}(window,jQuery);
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.1.5\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-06-21T15:23:09+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,212 +30,212 @@ msgstr ""
30
  msgid "Payment Plugins, support@paymentplugins.com"
31
  msgstr ""
32
 
33
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:109
34
- #: includes/admin/meta-boxes/views/html-product-data.php:13
35
- #: includes/gateways/settings/ach-settings-v2.php:7
36
- #: includes/gateways/settings/ach-settings.php:7
37
- #: includes/gateways/settings/applepay-settings.php:7
38
  #: includes/gateways/settings/cc-settings.php:4
39
- #: includes/gateways/settings/googlepay-settings.php:10
40
- #: includes/gateways/settings/payment-request-settings.php:8
41
  msgid "Enabled"
42
  msgstr ""
43
 
44
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:113
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:117
49
- #: includes/gateways/settings/ach-settings-v2.php:58
50
- #: includes/gateways/settings/ach-settings.php:59
51
- #: includes/gateways/settings/applepay-settings.php:13
52
- #: includes/gateways/settings/cc-settings.php:13
53
- #: includes/gateways/settings/googlepay-settings.php:16
54
- #: includes/gateways/settings/payment-request-settings.php:14
55
  msgid "General Settings"
56
  msgstr ""
57
 
58
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:120
59
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:47
60
- #: includes/gateways/settings/ach-settings-v2.php:61
61
- #: includes/gateways/settings/ach-settings.php:62
62
- #: includes/gateways/settings/applepay-settings.php:16
63
- #: includes/gateways/settings/cc-settings.php:16
64
- #: includes/gateways/settings/googlepay-settings.php:30
65
- #: includes/gateways/settings/payment-request-settings.php:17
66
  msgid "Title"
67
  msgstr ""
68
 
69
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:126
70
- #: includes/gateways/settings/ach-settings-v2.php:67
71
- #: includes/gateways/settings/ach-settings.php:68
72
- #: includes/gateways/settings/applepay-settings.php:22
73
- #: includes/gateways/settings/cc-settings.php:22
74
- #: includes/gateways/settings/googlepay-settings.php:36
75
- #: includes/gateways/settings/payment-request-settings.php:23
76
  msgid "Description"
77
  msgstr ""
78
 
79
- #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:128
80
- #: includes/gateways/settings/ach-settings-v2.php:69
81
- #: includes/gateways/settings/ach-settings.php:70
82
- #: includes/gateways/settings/applepay-settings.php:24
83
- #: includes/gateways/settings/cc-settings.php:24
84
- #: includes/gateways/settings/googlepay-settings.php:38
85
- #: includes/gateways/settings/payment-request-settings.php:25
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:244
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:247
98
  msgid " & billing country is <strong>%s</strong>"
99
  msgstr ""
100
 
101
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:349
102
- #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:114
103
  msgid "Error processing payment. Reason: %s"
104
  msgstr ""
105
 
106
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:356
107
- msgid "Charge %s is pending. Payment Method: %s. Payment will be completed once charge.succeeded webhook received from Stripe."
108
  msgstr ""
109
 
110
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:364
111
- msgid "Order %s successful in Stripe. Charge: %s. Payment Method: %s"
112
  msgstr ""
113
 
114
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:364
115
  msgid "charge"
116
  msgstr ""
117
 
118
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:364
119
  msgid "authorization"
120
  msgstr ""
121
 
122
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:407
123
- #: includes/controllers/class-wc-stripe-controller-cart.php:135
124
- #: includes/controllers/class-wc-stripe-controller-cart.php:184
125
- #: includes/controllers/class-wc-stripe-controller-googlepay.php:129
126
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:74
127
  msgid "Total"
128
  msgstr ""
129
 
130
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:465
131
  msgid "User must be logged in."
132
  msgstr ""
133
 
134
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:477
135
  msgid "Error saving your payment method. Reason: %s"
136
  msgstr ""
137
 
138
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:491
139
  msgid "Error saving payment method. Reason: %s"
140
  msgstr ""
141
 
142
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:508
143
  msgid "Order refunded in Stripe. Amount: %s"
144
  msgstr ""
145
 
146
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:537
147
  msgid "Order amount captured in Stripe. Amount: %s"
148
  msgstr ""
149
 
150
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:541
151
  msgid "Error capturing charge in Stripe. Reason: %s"
152
  msgstr ""
153
 
154
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:561
155
  msgid "Error voiding charge. Reason: %s"
156
  msgstr ""
157
 
158
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:563
159
  msgid "Charge voided in Stripe."
160
  msgstr ""
161
 
162
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:723
163
  msgid "n/a"
164
  msgstr ""
165
 
166
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:746
167
  #: includes/admin/meta-boxes/views/html-order-pay.php:42
168
  msgid "New Card"
169
  msgstr ""
170
 
171
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:750
172
  #: includes/admin/meta-boxes/views/html-order-pay.php:30
173
  msgid "Saved Cards"
174
  msgstr ""
175
 
176
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:911
177
  msgid "Attemp to save payment method failed. Reason: %s"
178
  msgstr ""
179
 
180
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:931
181
  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."
182
  msgstr ""
183
 
184
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:933
185
  msgid "We were not able to save your payment method. Reason: %s"
186
  msgstr ""
187
 
188
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:965
189
  msgid "Payment Method Token"
190
  msgstr ""
191
 
192
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:984
193
  msgid "Recurring payment for order failed. Reason: %s"
194
  msgstr ""
195
 
196
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:996
197
  msgid "Recurring payment captured in Stripe. Payment method: %s"
198
  msgstr ""
199
 
200
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:998
201
  msgid "Recurring payment authorized in Stripe. Payment method: %s"
202
  msgstr ""
203
 
204
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1001
205
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1249
206
  msgid "Customer must manually complete payment for payment method %s"
207
  msgstr ""
208
 
209
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1017
210
  msgid "Error saving payment method for subscription. Reason: %s"
211
  msgstr ""
212
 
213
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1075
214
- #: includes/abstract/abstract-wc-stripe-payment.php:175
215
- msgid "Order %s from %s"
216
  msgstr ""
217
 
218
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1236
219
  msgid "Pre-order payment for order failed. Reason: %s"
220
  msgstr ""
221
 
222
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1244
223
  msgid "Pre-order payment captured in Stripe. Payment method: %s"
224
  msgstr ""
225
 
226
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1246
227
  msgid "Pre-order payment authorized in Stripe. Payment method: %s"
228
  msgstr ""
229
 
230
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1320
231
  msgid "Cannot process payment"
232
  msgstr ""
233
 
234
- #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1328
235
  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."
236
  msgstr ""
237
 
238
- #: includes/abstract/abstract-wc-stripe-payment.php:103
239
  msgid "Transaction Id cannot be empty."
240
  msgstr ""
241
 
@@ -243,55 +243,55 @@ msgstr ""
243
  msgid "You do not have permissions to access this resource."
244
  msgstr ""
245
 
246
- #: includes/admin/class-wc-stripe-admin-menus.php:25
247
  msgid "Stripe Gateway"
248
  msgstr ""
249
 
250
- #: includes/admin/class-wc-stripe-admin-menus.php:29
251
- #: includes/class-wc-stripe-install.php:30
252
  msgid "Settings"
253
  msgstr ""
254
 
255
- #: includes/admin/class-wc-stripe-admin-menus.php:30
256
  msgid "Logs"
257
  msgstr ""
258
 
259
- #: includes/admin/class-wc-stripe-admin-menus.php:31
260
- #: includes/admin/views/html-settings-nav.php:17
261
- #: includes/class-wc-stripe-install.php:31
262
  msgid "Documentation"
263
  msgstr ""
264
 
265
  #: includes/admin/class-wc-stripe-admin-notices.php:51
266
  msgid ""
267
- "At Stripe's request we have updated how the Stripe for WooCommerce\r\n"
268
- "\t\t\t\t\t\t\t\t\tplugin integrates with Stripe. This new integration offers even more security and \r\n"
269
- "\t\t\t\t\t\t\t\t\tStripe is requesting that all merchants switch. %sUpdate Integration%s"
270
  msgstr ""
271
 
272
- #: includes/admin/class-wc-stripe-admin-settings.php:79
273
  msgid "Local Gateways"
274
  msgstr ""
275
 
276
- #: includes/admin/class-wc-stripe-admin-settings.php:90
277
  msgid "Stripe Email Options"
278
  msgstr ""
279
 
280
- #: includes/admin/class-wc-stripe-admin-settings.php:93
281
  msgid "Email Receipt"
282
  msgstr ""
283
 
284
- #: includes/admin/class-wc-stripe-admin-settings.php:96
285
  msgid "If enabled, an email receipt will be sent to the customer by Stripe when the order is processed."
286
  msgstr ""
287
 
288
- #: includes/admin/meta-boxes/class-wc-stripe-admin-meta-box-product-data.php:25
289
  msgid "Stripe Settings"
290
  msgstr ""
291
 
292
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:9
293
- #: includes/admin/views/html-user-profile.php:34
294
- #: includes/admin/views/html-user-profile.php:68
295
  msgid "Actions"
296
  msgstr ""
297
 
@@ -300,13 +300,13 @@ msgid "capture amount"
300
  msgstr ""
301
 
302
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:14
303
- #: includes/admin/meta-boxes/views/html-order-actions.php:42
304
  #: includes/admin/meta-boxes/views/html-order-pay.php:23
305
- #: includes/admin/meta-boxes/views/html-product-data.php:36
306
- #: includes/gateways/settings/applepay-settings.php:41
307
- #: includes/gateways/settings/cc-settings.php:41
308
- #: includes/gateways/settings/googlepay-settings.php:55
309
- #: includes/gateways/settings/payment-request-settings.php:42
310
  msgid "Capture"
311
  msgstr ""
312
 
@@ -319,13 +319,13 @@ msgid "Charge Data"
319
  msgstr ""
320
 
321
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:24
322
- #: includes/admin/settings/class-wc-stripe-api-settings.php:38
323
  msgid "Mode"
324
  msgstr ""
325
 
326
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:25
327
- #: includes/admin/settings/class-wc-stripe-api-settings.php:42
328
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:147
329
  msgid "Live"
330
  msgstr ""
331
 
@@ -342,14 +342,14 @@ msgid "Customer"
342
  msgstr ""
343
 
344
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:45
345
- #: includes/admin/views/html-user-profile.php:32
346
- #: includes/admin/views/html-user-profile.php:66
347
  msgid "Payment Method"
348
  msgstr ""
349
 
350
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:51
351
- #: includes/admin/views/html-ach-fee.php:10
352
- #: includes/gateways/settings/payment-request-settings.php:73
353
  msgid "Type"
354
  msgstr ""
355
 
@@ -379,39 +379,39 @@ msgstr ""
379
  msgid "Riska Data"
380
  msgstr ""
381
 
382
- #: includes/admin/meta-boxes/views/html-charge-data-subview.php:80
383
  msgid "Score"
384
  msgstr ""
385
 
386
- #: includes/admin/meta-boxes/views/html-charge-data-subview.php:84
387
  msgid "Level"
388
  msgstr ""
389
 
390
- #: includes/admin/meta-boxes/views/html-order-actions.php:1
391
  msgid "Charge Status"
392
  msgstr ""
393
 
394
- #: includes/admin/meta-boxes/views/html-order-actions.php:5
395
  msgid "Authorization Expires"
396
  msgstr ""
397
 
398
- #: includes/admin/meta-boxes/views/html-order-actions.php:12
399
  msgid "There are no actions available at this time."
400
  msgstr ""
401
 
402
- #: includes/admin/meta-boxes/views/html-order-actions.php:21
403
  msgid "Capture Charge"
404
  msgstr ""
405
 
406
- #: includes/admin/meta-boxes/views/html-order-actions.php:29
407
  msgid "Total available to capture"
408
  msgstr ""
409
 
410
- #: includes/admin/meta-boxes/views/html-order-actions.php:33
411
  msgid "Amount To Capture"
412
  msgstr ""
413
 
414
- #: includes/admin/meta-boxes/views/html-order-actions.php:43
415
  msgid "Cancel"
416
  msgstr ""
417
 
@@ -428,20 +428,20 @@ msgid "Admins can process customer orders over the phone using this functionalit
428
  msgstr ""
429
 
430
  #: includes/admin/meta-boxes/views/html-order-pay.php:21
431
- #: includes/admin/meta-boxes/views/html-product-data.php:14
432
- #: includes/gateways/settings/applepay-settings.php:37
433
- #: includes/gateways/settings/cc-settings.php:37
434
- #: includes/gateways/settings/googlepay-settings.php:51
435
- #: includes/gateways/settings/payment-request-settings.php:38
436
  msgid "Charge Type"
437
  msgstr ""
438
 
439
  #: includes/admin/meta-boxes/views/html-order-pay.php:24
440
- #: includes/admin/meta-boxes/views/html-product-data.php:37
441
- #: includes/gateways/settings/applepay-settings.php:42
442
- #: includes/gateways/settings/cc-settings.php:42
443
- #: includes/gateways/settings/googlepay-settings.php:56
444
- #: includes/gateways/settings/payment-request-settings.php:43
445
  msgid "Authorize"
446
  msgstr ""
447
 
@@ -453,127 +453,127 @@ msgstr ""
453
  msgid "In this section you can control which gateways are displayed on the product page."
454
  msgstr ""
455
 
456
- #: includes/admin/meta-boxes/views/html-product-data.php:12
457
  msgid "Method"
458
  msgstr ""
459
 
460
- #: includes/admin/meta-boxes/views/html-product-data.php:48
461
  msgid "Button Position"
462
  msgstr ""
463
 
464
- #: includes/admin/meta-boxes/views/html-product-data.php:50
465
  msgid "Below add to cart"
466
  msgstr ""
467
 
468
- #: includes/admin/meta-boxes/views/html-product-data.php:51
469
  msgid "Above add to cart"
470
  msgstr ""
471
 
472
- #: includes/admin/meta-boxes/views/html-product-data.php:54
473
  msgid "The location of the payment buttons in relation to the Add to Cart button."
474
  msgstr ""
475
 
476
- #: includes/admin/meta-boxes/views/html-product-data.php:59
477
  msgid "Save"
478
  msgstr ""
479
 
480
  #: includes/admin/settings/class-wc-stripe-api-settings.php:15
481
- #: includes/admin/settings/class-wc-stripe-api-settings.php:35
482
  msgid "API Settings"
483
  msgstr ""
484
 
485
- #: includes/admin/settings/class-wc-stripe-api-settings.php:41
486
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:147
487
  msgid "Test"
488
  msgstr ""
489
 
490
- #: includes/admin/settings/class-wc-stripe-api-settings.php:45
491
  msgid "The mode determines if you are processing test transactions or live transactions on your site. Test mode allows you to simulate payments so you can test your integration."
492
  msgstr ""
493
 
494
- #: includes/admin/settings/class-wc-stripe-api-settings.php:49
495
  msgid "Account ID"
496
  msgstr ""
497
 
498
- #: includes/admin/settings/class-wc-stripe-api-settings.php:52
499
  msgid "This is your Stripe Connect ID and serves as a unique identifier."
500
  msgstr ""
501
 
502
- #: includes/admin/settings/class-wc-stripe-api-settings.php:56
503
  msgid "Connect Stripe Account"
504
  msgstr ""
505
 
506
- #: includes/admin/settings/class-wc-stripe-api-settings.php:57
507
  msgid "Click to Connect"
508
  msgstr ""
509
 
510
- #: includes/admin/settings/class-wc-stripe-api-settings.php:59
511
  msgid "We make it easy to connect Stripe to your site. Click the Connect button to go through our connect flow."
512
  msgstr ""
513
 
 
514
  #: includes/admin/settings/class-wc-stripe-api-settings.php:63
515
- #: includes/admin/settings/class-wc-stripe-api-settings.php:64
516
  msgid "Connection Test"
517
  msgstr ""
518
 
519
- #: includes/admin/settings/class-wc-stripe-api-settings.php:66
520
  msgid "Click this button to perform a connection test. If successful, your site is connected to Stripe."
521
  msgstr ""
522
 
523
- #: includes/admin/settings/class-wc-stripe-api-settings.php:70
524
  msgid "Webhook url"
525
  msgstr ""
526
 
527
- #: includes/admin/settings/class-wc-stripe-api-settings.php:73
528
- msgid "<strong>Important:</strong> the webhook url is called by Stripe when events occur in your account, like a source becomes chargeable. You must add this webhook to your Stripe Dashboard if you are using any of the local gateways. %sWebhook guide%s"
529
  msgstr ""
530
 
531
- #: includes/admin/settings/class-wc-stripe-api-settings.php:77
532
  msgid "Live Webhook Secret"
533
  msgstr ""
534
 
535
- #: includes/admin/settings/class-wc-stripe-api-settings.php:78
536
- #: includes/admin/settings/class-wc-stripe-api-settings.php:88
537
- msgid "The webhook secret is used to authenticate webhooks sent from Stripe. It ensures no 3rd party can send you events, pretending to be Stripe. %sWebhook guide%s"
538
  msgstr ""
539
 
540
- #: includes/admin/settings/class-wc-stripe-api-settings.php:87
541
  msgid "Test Webhook Secret"
542
  msgstr ""
543
 
544
- #: includes/admin/settings/class-wc-stripe-api-settings.php:96
545
  msgid "Debug Log"
546
  msgstr ""
547
 
548
- #: includes/admin/settings/class-wc-stripe-api-settings.php:100
549
  msgid "When enabled, the plugin logs important errors and info that can help you troubleshoot potential issues."
550
  msgstr ""
551
 
552
- #: includes/admin/settings/class-wc-stripe-api-settings.php:105
553
  msgid "%s Your Stripe account has been connected. You can now accept Live and Test payments. You can Re-Connect if you want to recycle your API keys for security."
554
  msgstr ""
555
 
556
- #: includes/admin/settings/class-wc-stripe-api-settings.php:121
557
  msgid "Click To Re-Connect"
558
  msgstr ""
559
 
560
- #: includes/admin/settings/class-wc-stripe-api-settings.php:138
561
  msgid "Please try again."
562
  msgstr ""
563
 
564
- #: includes/admin/settings/class-wc-stripe-api-settings.php:141
565
  msgid "We were not able to connect your Stripe account. Reason: %s"
566
  msgstr ""
567
 
568
- #: includes/admin/settings/class-wc-stripe-api-settings.php:161
569
  msgid "Your Stripe account has been connected to your WooCommerce store. You may now accept payments in Live and Test mode."
570
  msgstr ""
571
 
572
- #: includes/admin/views/html-ach-fee.php:18
573
  msgid "Taxable"
574
  msgstr ""
575
 
576
- #: includes/admin/views/html-ach-fee.php:22
577
  msgid "Value"
578
  msgstr ""
579
 
@@ -585,39 +585,39 @@ msgstr ""
585
  msgid "Live ID"
586
  msgstr ""
587
 
588
- #: includes/admin/views/html-user-profile.php:19
589
  msgid "Test ID"
590
  msgstr ""
591
 
592
- #: includes/admin/views/html-user-profile.php:26
593
  msgid "Stripe Live Payment Methods"
594
  msgstr ""
595
 
596
- #: includes/admin/views/html-user-profile.php:31
597
- #: includes/admin/views/html-user-profile.php:65
598
  msgid "Payment Gateway"
599
  msgstr ""
600
 
601
- #: includes/admin/views/html-user-profile.php:33
602
- #: includes/admin/views/html-user-profile.php:67
603
  msgid "Token"
604
  msgstr ""
605
 
606
- #: includes/admin/views/html-user-profile.php:50
607
- #: includes/admin/views/html-user-profile.php:84
608
  msgid "No Action"
609
  msgstr ""
610
 
611
- #: includes/admin/views/html-user-profile.php:51
612
- #: includes/admin/views/html-user-profile.php:85
613
  msgid "Delete"
614
  msgstr ""
615
 
616
- #: includes/admin/views/html-user-profile.php:58
617
  msgid "No live payment methods saved"
618
  msgstr ""
619
 
620
- #: includes/admin/views/html-user-profile.php:60
621
  msgid "Stripe Test Payment Methods"
622
  msgstr ""
623
 
@@ -626,109 +626,105 @@ msgid "No test payment methods saved"
626
  msgstr ""
627
 
628
  #: includes/admin/views/html-user-profile.php:94
629
- msgid "%snote:%s payment methods will be deleted in Stripe if you use the delete action."
630
  msgstr ""
631
 
632
- #: includes/class-wc-stripe-customer-manager.php:33
633
- #: includes/class-wc-stripe-customer-manager.php:42
634
  msgid "Error saving customer. Reason: %s"
635
  msgstr ""
636
 
637
- #: includes/class-wc-stripe-frontend-notices.php:37
638
  msgid "Your payment is being processed and your order status will be updated once the funds are received."
639
  msgstr ""
640
 
641
- #: includes/class-wc-stripe-frontend-scripts.php:65
642
  msgid "No matches found"
643
  msgstr ""
644
 
645
- #: includes/class-wc-stripe-gateway-ach.php:51
646
- msgid "Please update your ACH environment to Production to match your Stripe API Mode."
647
- msgstr ""
648
-
649
- #: includes/class-wc-stripe-redirect-handler.php:39
650
  msgid "Error retrieving payment source. Reason: %s"
651
  msgstr ""
652
 
653
- #: includes/class-wc-stripe-redirect-handler.php:54
654
  msgid "Payment authorization failed. Please select another payment method."
655
  msgstr ""
656
 
657
- #: includes/class-wc-stripe-redirect-handler.php:55
658
  msgid "Payment authorization failed."
659
  msgstr ""
660
 
661
- #: includes/class-wc-stripe-rest-api.php:45
662
  msgid "%1$s is an invalid controller name."
663
  msgstr ""
664
 
665
- #: includes/class-wc-stripe-update.php:44
666
  msgid "Thank you for updating Stripe for WooCommerce to version %1$s."
667
  msgstr ""
668
 
669
- #: includes/controllers/class-wc-stripe-controller-cart.php:98
670
  msgid "Quantity must be greater than zero."
671
  msgstr ""
672
 
673
- #: includes/controllers/class-wc-stripe-controller-checkout.php:183
674
- msgid "Some required fields were missing. Please click %shere%s to complete your payment."
675
  msgstr ""
676
 
677
- #: includes/controllers/class-wc-stripe-controller-checkout.php:216
678
  msgid "Please review your order details then click Place Order."
679
  msgstr ""
680
 
681
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:83
682
  msgid "You cannot register your domain until you have configured your Live API keys."
683
  msgstr ""
684
 
685
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:99
686
  msgid "Domain registered successfully. You can confirm in your Stripe Dashboard at https://dashboard.stripe.com/account/apple_pay."
687
  msgstr ""
688
 
689
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:116
690
  msgid "You must configure your secret key before creating webhooks."
691
  msgstr ""
692
 
693
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:125
694
  msgid "There is already a webhook configured for this site. If you want to delete the webhook, login to your Stripe Dashboard."
695
  msgstr ""
696
 
697
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:147
698
  msgid "Webhook created in Stripe for %s environment. You can test your webhook by logging in to the Stripe dashboard"
699
  msgstr ""
700
 
701
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:167
702
  msgid "Mode: %s. Invalid secret key. Please check your entry."
703
  msgstr ""
704
 
705
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:180
706
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:183
707
  msgid "Mode: %s. Invalid publishable key. Please check your entry."
708
  msgstr ""
709
 
710
- #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:191
711
  msgid "Connection test to Stripe was successful. Mode: %s."
712
  msgstr ""
713
 
714
- #: includes/controllers/class-wc-stripe-controller-googlepay.php:92
715
  msgid "Your shipping address is not serviceable."
716
  msgstr ""
717
 
718
- #: includes/controllers/class-wc-stripe-controller-order-actions.php:123
719
  msgid "Invalid amount entered."
720
  msgstr ""
721
 
722
- #: includes/controllers/class-wc-stripe-controller-order-actions.php:174
723
- #: includes/controllers/class-wc-stripe-controller-order-actions.php:177
724
  msgid "Order total must be greater than zero."
725
  msgstr ""
726
 
727
- #: includes/controllers/class-wc-stripe-controller-order-actions.php:187
728
- msgid "This order has already been processed. Transaction ID: %s. Payment method: %s"
729
  msgstr ""
730
 
731
- #: includes/controllers/class-wc-stripe-controller-order-actions.php:196
732
  msgid "Order customer Id and payment method customer Id do not match."
733
  msgstr ""
734
 
@@ -736,98 +732,91 @@ msgstr ""
736
  msgid "Error creating payment intent. Reason: %s"
737
  msgstr ""
738
 
739
- #: includes/controllers/class-wc-stripe-controller-payment-intent.php:70
740
  msgid "Invalid order id provided"
741
  msgstr ""
742
 
743
- #: includes/controllers/class-wc-stripe-controller-payment-intent.php:76
744
  msgid "You are not authorized to update this order."
745
  msgstr ""
746
 
747
- #: includes/controllers/class-wc-stripe-controller-webhook.php:46
748
- #: includes/controllers/class-wc-stripe-controller-webhook.php:47
749
  msgid "Invalid signature received. Verify that your webhook secret is correct."
750
  msgstr ""
751
 
752
- #: includes/gateways/class-wc-payment-gateway-stripe-ach-v2.php:26
753
  #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:26
754
  msgid "ACH"
755
  msgstr ""
756
 
757
- #: includes/gateways/class-wc-payment-gateway-stripe-ach-v2.php:29
758
  #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:29
759
  msgid "Stripe ACH"
760
  msgstr ""
761
 
762
- #: includes/gateways/class-wc-payment-gateway-stripe-ach-v2.php:30
763
  #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:30
764
  msgid "ACH gateway that integrates with your Stripe account."
765
  msgstr ""
766
 
767
- #: includes/gateways/class-wc-payment-gateway-stripe-ach-v2.php:32
768
  #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:32
769
  msgid "Bank Payment"
770
  msgstr ""
771
 
772
- #: includes/gateways/class-wc-payment-gateway-stripe-ach-v2.php:126
773
- #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:203
774
  msgid "Saved Banks"
775
  msgstr ""
776
 
777
- #: includes/gateways/class-wc-payment-gateway-stripe-ach-v2.php:130
778
- #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:207
779
  msgid "New Bank"
780
  msgstr ""
781
 
782
- #: includes/gateways/class-wc-payment-gateway-stripe-ach-v2.php:171
783
- #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:243
784
  msgid "You must set the API mode to live in order to enable the Plaid development environment."
785
  msgstr ""
786
 
787
- #: includes/gateways/class-wc-payment-gateway-stripe-alipay.php:25
788
- #: includes/gateways/class-wc-payment-gateway-stripe-alipay.php:28
789
- #: includes/gateways/class-wc-payment-gateway-stripe-alipay.php:31
790
  msgid "Alipay"
791
  msgstr ""
792
 
793
- #: includes/gateways/class-wc-payment-gateway-stripe-alipay.php:29
794
  msgid "Alipay gateway that integrates with your Stripe account."
795
  msgstr ""
796
 
797
- #: includes/gateways/class-wc-payment-gateway-stripe-applepay.php:21
798
- #: includes/gateways/settings/applepay-settings.php:17
799
  msgid "Apple Pay"
800
  msgstr ""
801
 
802
- #: includes/gateways/class-wc-payment-gateway-stripe-applepay.php:24
803
  msgid "Stripe Apple Pay"
804
  msgstr ""
805
 
806
- #: includes/gateways/class-wc-payment-gateway-stripe-applepay.php:25
807
  msgid "Apple Pay gateway that integrates with your Stripe account."
808
  msgstr ""
809
 
810
- #: includes/gateways/class-wc-payment-gateway-stripe-applepay.php:64
811
  msgid "Please update you product quantity before using Apple Pay."
812
  msgstr ""
813
 
814
- #: includes/gateways/class-wc-payment-gateway-stripe-applepay.php:65
815
- #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:71
816
  msgid "Please select a product option before updating quantity."
817
  msgstr ""
818
 
819
- #: includes/gateways/class-wc-payment-gateway-stripe-bancontact.php:25
820
- #: includes/gateways/class-wc-payment-gateway-stripe-bancontact.php:28
821
- #: includes/gateways/class-wc-payment-gateway-stripe-bancontact.php:31
822
  msgid "Bancontact"
823
  msgstr ""
824
 
825
- #: includes/gateways/class-wc-payment-gateway-stripe-bancontact.php:29
826
  msgid "Bancontact gateway that integrates with your Stripe account."
827
  msgstr ""
828
 
829
  #: includes/gateways/class-wc-payment-gateway-stripe-cc.php:19
830
- #: includes/gateways/settings/cc-settings.php:17
831
  msgid "Credit Cards"
832
  msgstr ""
833
 
@@ -839,38 +828,38 @@ msgstr ""
839
  msgid "Credit card gateway that integrates with your Stripe account."
840
  msgstr ""
841
 
842
- #: includes/gateways/class-wc-payment-gateway-stripe-eps.php:24
843
- #: includes/gateways/class-wc-payment-gateway-stripe-eps.php:27
844
- #: includes/gateways/class-wc-payment-gateway-stripe-eps.php:30
845
  msgid "EPS"
846
  msgstr ""
847
 
848
- #: includes/gateways/class-wc-payment-gateway-stripe-eps.php:28
849
  msgid "EPS gateway that integrates with your Stripe account."
850
  msgstr ""
851
 
 
852
  #: includes/gateways/class-wc-payment-gateway-stripe-fpx.php:26
853
- #: includes/gateways/class-wc-payment-gateway-stripe-fpx.php:27
854
- #: includes/gateways/class-wc-payment-gateway-stripe-fpx.php:30
855
  msgid "FPX"
856
  msgstr ""
857
 
858
- #: includes/gateways/class-wc-payment-gateway-stripe-fpx.php:28
859
  msgid "FPX gateway that integrates with your Stripe account."
860
  msgstr ""
861
 
862
- #: includes/gateways/class-wc-payment-gateway-stripe-giropay.php:24
863
- #: includes/gateways/class-wc-payment-gateway-stripe-giropay.php:27
864
- #: includes/gateways/class-wc-payment-gateway-stripe-giropay.php:30
865
  msgid "Giropay"
866
  msgstr ""
867
 
868
- #: includes/gateways/class-wc-payment-gateway-stripe-giropay.php:28
869
  msgid "Giropay gateway that integrates with your Stripe account."
870
  msgstr ""
871
 
872
  #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:20
873
- #: includes/gateways/settings/googlepay-settings.php:31
874
  msgid "Google Pay"
875
  msgstr ""
876
 
@@ -882,143 +871,141 @@ msgstr ""
882
  msgid "Google Pay gateway that integrates with your Stripe account."
883
  msgstr ""
884
 
885
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:79
886
  msgid "Please update you product quantity before using Google Pay."
887
  msgstr ""
888
 
889
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:92
890
  msgid "Subscription"
891
  msgstr ""
892
 
893
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:122
894
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:174
895
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:194
896
- #: includes/wc-stripe-functions.php:374
897
- #: includes/wc-stripe-functions.php:422
898
  msgid "Shipping"
899
  msgstr ""
900
 
901
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:130
902
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:195
903
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:204
904
- #: includes/wc-stripe-functions.php:390
905
- #: includes/wc-stripe-functions.php:430
906
  msgid "Discount"
907
  msgstr ""
908
 
909
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:141
910
- #: includes/wc-stripe-functions.php:441
911
  msgid "Fees"
912
  msgstr ""
913
 
914
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:203
915
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:225
916
- #: includes/wc-stripe-functions.php:398
917
  msgid "Tax"
918
  msgstr ""
919
 
920
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:234
921
- #: includes/wc-stripe-functions.php:512
922
  msgid "Waiting..."
923
  msgstr ""
924
 
925
- #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:235
926
- #: includes/wc-stripe-functions.php:513
927
  msgid "loading shipping methods..."
928
  msgstr ""
929
 
 
930
  #: includes/gateways/class-wc-payment-gateway-stripe-ideal.php:28
931
- #: includes/gateways/class-wc-payment-gateway-stripe-ideal.php:29
932
- #: includes/gateways/class-wc-payment-gateway-stripe-ideal.php:32
933
  msgid "iDEAL"
934
  msgstr ""
935
 
936
- #: includes/gateways/class-wc-payment-gateway-stripe-ideal.php:30
937
  msgid "Ideal gateway that integrates with your Stripe account."
938
  msgstr ""
939
 
940
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:23
941
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:26
942
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:29
943
  msgid "Klarna"
944
  msgstr ""
945
 
946
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:27
947
  msgid "Klarna gateway that integrates with your Stripe account."
948
  msgstr ""
949
 
950
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:104
951
  msgid "Payment Categories"
952
  msgstr ""
953
 
954
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:110
955
- msgid "Thes are the payment categories that will be displayed on the checkout page if they are supported. Note, depending on the customer's billing country, not all enabled options may show."
956
  msgstr ""
957
 
958
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:217
959
  msgid "Fee"
960
  msgstr ""
961
 
962
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:256
963
  msgid "Pay Now"
964
  msgstr ""
965
 
966
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:257
967
  msgid "Pay Later"
968
  msgstr ""
969
 
970
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:258
971
  msgid "Pay Over Time"
972
  msgstr ""
973
 
974
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:269
975
- msgid "Click %shere%s for Klarna test payment methods."
976
  msgstr ""
977
 
978
- #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:274
979
  msgid "Your purchase is not approved."
980
  msgstr ""
981
 
982
- #: includes/gateways/class-wc-payment-gateway-stripe-multibanco.php:24
983
- #: includes/gateways/class-wc-payment-gateway-stripe-multibanco.php:27
984
- #: includes/gateways/class-wc-payment-gateway-stripe-multibanco.php:30
985
  msgid "Multibanco"
986
  msgstr ""
987
 
988
- #: includes/gateways/class-wc-payment-gateway-stripe-multibanco.php:28
989
  msgid "Multibanco gateway that integrates with your Stripe account."
990
  msgstr ""
991
 
992
- #: includes/gateways/class-wc-payment-gateway-stripe-p24.php:24
993
- #: includes/gateways/class-wc-payment-gateway-stripe-p24.php:27
994
  msgid "Przelewy24"
995
  msgstr ""
996
 
997
- #: includes/gateways/class-wc-payment-gateway-stripe-p24.php:28
998
  msgid "P24 gateway that integrates with your Stripe account."
999
  msgstr ""
1000
 
1001
- #: includes/gateways/class-wc-payment-gateway-stripe-p24.php:30
1002
  msgid "P24"
1003
  msgstr ""
1004
 
1005
- #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:22
1006
  msgid "PaymentRequest Gateway"
1007
  msgstr ""
1008
 
1009
- #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:25
1010
  msgid "Stripe Payment Request"
1011
  msgstr ""
1012
 
1013
- #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:26
1014
  msgid "Gateway that renders based on the user's browser. Chrome payment methods, Microsoft pay, etc."
1015
  msgstr ""
1016
 
1017
- #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:69
1018
  msgid "Please update you product quantity before paying."
1019
  msgstr ""
1020
 
1021
- #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:70
1022
  msgid "Adding to cart..."
1023
  msgstr ""
1024
 
@@ -1035,812 +1022,808 @@ msgstr ""
1035
  msgid "Sepa gateway that integrates with your Stripe account."
1036
  msgstr ""
1037
 
1038
- #: includes/gateways/class-wc-payment-gateway-stripe-sepa.php:32
1039
  msgid ""
1040
- "By providing your IBAN and confirming this payment, you are\r\n"
1041
- "\t\t\tauthorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account\r\n"
1042
- "\t\t\tand your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the\r\n"
1043
  "\t\t\tterms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited."
1044
  msgstr ""
1045
 
1046
- #: includes/gateways/class-wc-payment-gateway-stripe-sepa.php:48
1047
  msgid "Company Name"
1048
  msgstr ""
1049
 
1050
- #: includes/gateways/class-wc-payment-gateway-stripe-sepa.php:52
1051
  msgid "The name of your company that will appear in the SEPA mandate."
1052
  msgstr ""
1053
 
1054
- #: includes/gateways/class-wc-payment-gateway-stripe-sepa.php:58
1055
  msgid "SEPA Test Accounts"
1056
  msgstr ""
1057
 
1058
- #: includes/gateways/class-wc-payment-gateway-stripe-sofort.php:26
1059
- #: includes/gateways/class-wc-payment-gateway-stripe-sofort.php:29
1060
  msgid "Sofort"
1061
  msgstr ""
1062
 
1063
- #: includes/gateways/class-wc-payment-gateway-stripe-sofort.php:30
1064
  msgid "Sofort gateway that integrates with your Stripe account."
1065
  msgstr ""
1066
 
1067
- #: includes/gateways/class-wc-payment-gateway-stripe-sofort.php:32
1068
  msgid "SOFORT"
1069
  msgstr ""
1070
 
1071
- #: includes/gateways/class-wc-payment-gateway-stripe-wechat.php:25
1072
- #: includes/gateways/class-wc-payment-gateway-stripe-wechat.php:28
1073
- #: includes/gateways/class-wc-payment-gateway-stripe-wechat.php:31
1074
  msgid "WeChat"
1075
  msgstr ""
1076
 
1077
- #: includes/gateways/class-wc-payment-gateway-stripe-wechat.php:29
1078
  msgid "WeChat gateway that integrates with your Stripe account."
1079
  msgstr ""
1080
 
1081
- #: includes/gateways/class-wc-payment-gateway-stripe-wechat.php:64
1082
  msgid "Scan the QR code using your WeChat app. Once scanned click the Place Order button."
1083
  msgstr ""
1084
 
1085
- #: includes/gateways/settings/ach-settings-v2.php:4
1086
- #: includes/gateways/settings/ach-settings.php:4
1087
  msgid "For US customers only."
1088
  msgstr ""
1089
 
1090
- #: includes/gateways/settings/ach-settings-v2.php:4
1091
- #: includes/gateways/settings/ach-settings.php:4
1092
- msgid "Read through our %sdocumentation%s to configure ACH payments"
1093
  msgstr ""
1094
 
1095
- #: includes/gateways/settings/ach-settings-v2.php:10
1096
- #: includes/gateways/settings/ach-settings.php:10
1097
  msgid "If enabled, your site can accept ACH payments through Stripe."
1098
  msgstr ""
1099
 
1100
- #: includes/gateways/settings/ach-settings-v2.php:13
1101
- #: includes/gateways/settings/ach-settings.php:13
1102
  msgid "Plaid Environment"
1103
  msgstr ""
1104
 
1105
- #: includes/gateways/settings/ach-settings-v2.php:15
1106
- #: includes/gateways/settings/ach-settings.php:16
1107
  msgid "Sandbox"
1108
  msgstr ""
1109
 
1110
- #: includes/gateways/settings/ach-settings-v2.php:16
1111
- #: includes/gateways/settings/ach-settings.php:17
1112
  msgid "Development"
1113
  msgstr ""
1114
 
1115
- #: includes/gateways/settings/ach-settings-v2.php:17
1116
- #: includes/gateways/settings/ach-settings.php:18
1117
  msgid "Production"
1118
  msgstr ""
1119
 
1120
- #: includes/gateways/settings/ach-settings-v2.php:19
1121
  msgid "This setting determines the Plaid environment you are connecting with. When you are ready to accept live transactions, switch this option to Production.<br><strong>Production</strong> - accept live ACH payments <br><strong>Development</strong> - use real bank login details with test transactions <br><strong>Sandbox</strong> - test integration using test credentials"
1122
  msgstr ""
1123
 
1124
- #: includes/gateways/settings/ach-settings-v2.php:62
1125
- #: includes/gateways/settings/ach-settings.php:63
1126
  msgid "ACH Payment"
1127
  msgstr ""
1128
 
1129
- #: includes/gateways/settings/ach-settings-v2.php:73
1130
- #: includes/gateways/settings/ach-settings.php:74
1131
  msgid "Client Name"
1132
  msgstr ""
1133
 
1134
- #: includes/gateways/settings/ach-settings-v2.php:75
1135
- #: includes/gateways/settings/ach-settings.php:76
1136
  msgid "The name that appears on the ACH payment screen."
1137
  msgstr ""
1138
 
1139
- #: includes/gateways/settings/ach-settings-v2.php:79
1140
- #: includes/gateways/settings/ach-settings.php:80
1141
  msgid "ACH Display"
1142
  msgstr ""
1143
 
1144
- #: includes/gateways/settings/ach-settings-v2.php:88
1145
- #: includes/gateways/settings/ach-settings.php:89
1146
  msgid "ACH Fee"
1147
  msgstr ""
1148
 
1149
- #: includes/gateways/settings/ach-settings-v2.php:95
1150
- #: includes/gateways/settings/ach-settings.php:96
1151
  msgid "None"
1152
  msgstr ""
1153
 
1154
- #: includes/gateways/settings/ach-settings-v2.php:96
1155
- #: includes/gateways/settings/ach-settings.php:97
1156
  msgid "Amount"
1157
  msgstr ""
1158
 
1159
- #: includes/gateways/settings/ach-settings-v2.php:97
1160
- #: includes/gateways/settings/ach-settings.php:98
1161
  msgid "Percentage"
1162
  msgstr ""
1163
 
1164
- #: includes/gateways/settings/ach-settings-v2.php:99
1165
- #: includes/gateways/settings/ach-settings.php:100
1166
  msgid "You can assign a fee to the order for ACH payments. Amount is a static amount and percentage is a percentage of the cart amount."
1167
  msgstr ""
1168
 
1169
- #: includes/gateways/settings/ach-settings.php:20
1170
  msgid "The active Plaid environment. You must set API mode to live to use Plaid's development environment."
1171
  msgstr ""
1172
 
1173
- #: includes/gateways/settings/ach-settings.php:28
1174
  msgid "ID that identifies your Plaid account."
1175
  msgstr ""
1176
 
1177
- #: includes/gateways/settings/ach-settings.php:34
1178
  msgid "Used to identify ACH payments initiated from your site."
1179
  msgstr ""
1180
 
1181
- #: includes/gateways/settings/ach-settings.php:41
1182
  msgid "Sandbox Secret"
1183
  msgstr ""
1184
 
1185
- #: includes/gateways/settings/ach-settings.php:43
1186
  msgid "Key that acts as a password when connecting to Plaid's sandbox environment."
1187
  msgstr ""
1188
 
1189
- #: includes/gateways/settings/ach-settings.php:47
1190
  msgid "Development Secret"
1191
  msgstr ""
1192
 
1193
- #: includes/gateways/settings/ach-settings.php:49
1194
  msgid "Development allows you to test real bank credentials with test transactions."
1195
  msgstr ""
1196
 
1197
- #: includes/gateways/settings/ach-settings.php:53
1198
  msgid "Production Secret"
1199
  msgstr ""
1200
 
1201
- #: includes/gateways/settings/ach-settings.php:55
1202
  msgid "Key that acts as a password when connecting to Plaid's production environment."
1203
  msgstr ""
1204
 
1205
- #: includes/gateways/settings/applepay-settings.php:4
1206
  msgid "Register Domain"
1207
  msgstr ""
1208
 
1209
- #: includes/gateways/settings/applepay-settings.php:4
1210
- msgid "This plugin attemps to add the domain association file to your server automatically when you click the Register Domain button. If that fails due to file permssions, you must add the <strong>%s.well-known/apple-developer-merchantid-domain-association%s</strong> file to your domain and register your domain within the Stripe Dashboard."
1211
  msgstr ""
1212
 
1213
- #: includes/gateways/settings/applepay-settings.php:4
1214
  msgid "In order for Apple Pay to display, you must test with an iOS device and have a payment method saved in the Apple Wallet."
1215
  msgstr ""
1216
 
1217
- #: includes/gateways/settings/applepay-settings.php:10
1218
- #: includes/gateways/settings/payment-request-settings.php:11
1219
  msgid "If enabled, your site can accept Apple Pay payments through Stripe."
1220
  msgstr ""
1221
 
1222
- #: includes/gateways/settings/applepay-settings.php:28
1223
- #: includes/gateways/settings/cc-settings.php:28
1224
- #: includes/gateways/settings/googlepay-settings.php:42
1225
- #: includes/gateways/settings/payment-request-settings.php:29
1226
  msgid "Credit Card Display"
1227
  msgstr ""
1228
 
1229
- #: includes/gateways/settings/applepay-settings.php:44
1230
- #: includes/gateways/settings/cc-settings.php:44
1231
- #: includes/gateways/settings/payment-request-settings.php:45
1232
  msgid "This option determines whether the customer's funds are captured immediately or authorized and can be captured at a later date."
1233
  msgstr ""
1234
 
1235
- #: includes/gateways/settings/applepay-settings.php:48
1236
- #: includes/gateways/settings/googlepay-settings.php:62
1237
- #: includes/gateways/settings/payment-request-settings.php:49
1238
  msgid "Payment Sections"
1239
  msgstr ""
1240
 
1241
- #: includes/gateways/settings/applepay-settings.php:51
1242
- #: includes/gateways/settings/googlepay-settings.php:65
1243
- #: includes/gateways/settings/payment-request-settings.php:52
1244
  msgid "Product Page"
1245
  msgstr ""
1246
 
1247
- #: includes/gateways/settings/applepay-settings.php:52
1248
- #: includes/gateways/settings/googlepay-settings.php:66
1249
- #: includes/gateways/settings/payment-request-settings.php:53
1250
  msgid "Cart Page"
1251
  msgstr ""
1252
 
1253
- #: includes/gateways/settings/applepay-settings.php:53
1254
- #: includes/gateways/settings/googlepay-settings.php:67
1255
- #: includes/gateways/settings/payment-request-settings.php:54
1256
  msgid "Top of Checkout"
1257
  msgstr ""
1258
 
1259
- #: includes/gateways/settings/applepay-settings.php:59
1260
- #: includes/gateways/settings/cc-settings.php:47
1261
- #: includes/gateways/settings/googlepay-settings.php:73
1262
- #: includes/gateways/settings/payment-request-settings.php:60
1263
  msgid "Order Status"
1264
  msgstr ""
1265
 
1266
- #: includes/gateways/settings/applepay-settings.php:63
1267
- #: includes/gateways/settings/cc-settings.php:51
1268
- #: includes/gateways/settings/googlepay-settings.php:77
1269
- #: includes/gateways/settings/payment-request-settings.php:64
1270
  msgid "Default"
1271
  msgstr ""
1272
 
1273
- #: includes/gateways/settings/applepay-settings.php:66
1274
- #: includes/gateways/settings/cc-settings.php:54
1275
- #: includes/gateways/settings/googlepay-settings.php:80
1276
- #: includes/gateways/settings/payment-request-settings.php:67
1277
  msgid "This is the status of the order once payment is complete. If <b>Default</b> is selected, then WooCommerce will set the order status automatically based on internal logic which states if a product is virtual and downloadable then status is set to complete. Products that require shipping are set to Processing. Default is the recommended setting as it allows standard WooCommerce code to process the order status."
1278
  msgstr ""
1279
 
1280
- #: includes/gateways/settings/applepay-settings.php:69
1281
- #: includes/gateways/settings/payment-request-settings.php:70
1282
  msgid "Button Settings"
1283
  msgstr ""
1284
 
1285
- #: includes/gateways/settings/applepay-settings.php:72
1286
- #: includes/gateways/settings/googlepay-settings.php:122
1287
  msgid "Button Design"
1288
  msgstr ""
1289
 
1290
- #: includes/gateways/settings/applepay-settings.php:76
1291
  msgid "Black Button"
1292
  msgstr ""
1293
 
1294
- #: includes/gateways/settings/applepay-settings.php:77
1295
  msgid "White With Black Line"
1296
  msgstr ""
1297
 
1298
- #: includes/gateways/settings/applepay-settings.php:78
1299
  msgid "White Button"
1300
  msgstr ""
1301
 
1302
- #: includes/gateways/settings/applepay-settings.php:80
1303
  msgid "This is the style for all Apple Pay buttons presented on your store."
1304
  msgstr ""
1305
 
1306
- #: includes/gateways/settings/applepay-settings.php:83
1307
  msgid "Checkout button type"
1308
  msgstr ""
1309
 
1310
- #: includes/gateways/settings/applepay-settings.php:86
1311
- #: includes/gateways/settings/applepay-settings.php:96
1312
- #: includes/gateways/settings/applepay-settings.php:106
1313
  msgid "Standard Button"
1314
  msgstr ""
1315
 
1316
- #: includes/gateways/settings/applepay-settings.php:87
1317
- #: includes/gateways/settings/applepay-settings.php:97
1318
- #: includes/gateways/settings/applepay-settings.php:107
1319
  msgid "Buy with Apple Pay"
1320
  msgstr ""
1321
 
1322
- #: includes/gateways/settings/applepay-settings.php:93
1323
  msgid "Cart button type"
1324
  msgstr ""
1325
 
1326
- #: includes/gateways/settings/applepay-settings.php:103
1327
  msgid "Product button type"
1328
  msgstr ""
1329
 
1330
- #: includes/gateways/settings/cc-settings.php:7
1331
  msgid "If enabled, your site can accept credit card payments through Stripe."
1332
  msgstr ""
1333
 
1334
- #: includes/gateways/settings/cc-settings.php:10
1335
- msgid "%sTest cards%s"
1336
  msgstr ""
1337
 
1338
- #: includes/gateways/settings/cc-settings.php:58
1339
  msgid "Allow Credit Card Save"
1340
  msgstr ""
1341
 
1342
- #: includes/gateways/settings/cc-settings.php:60
1343
  msgid "If enabled, a checkbox will be available on the checkout page allowing your customers to save their credit card. The payment methods are stored securely in Stripe's vault and never touch your server. Note: if the cart contains a subscription, there will be no checkbox because the payment method will be saved automatically. There will also be no checkbox for guest checkout as a user must be logged in to save a payment method."
1344
  msgstr ""
1345
 
1346
- #: includes/gateways/settings/cc-settings.php:63
1347
  msgid "Force 3D Secure"
1348
  msgstr ""
1349
 
1350
- #: includes/gateways/settings/cc-settings.php:66
1351
- msgid "Stripe internally determines when 3D secure should be presented based on their SCA engine. If <strong>Force 3D Secure</strong> is enabled, 3D Secure will be forced for ALL credit card transactions. In test mode 3D secure only shows for %s3DS Test Cards%s regardless of this setting."
1352
  msgstr ""
1353
 
1354
- #: includes/gateways/settings/cc-settings.php:69
1355
  msgid "Generic Errors"
1356
  msgstr ""
1357
 
1358
- #: includes/gateways/settings/cc-settings.php:72
1359
  msgid "If enabled, credit card errors will be generic when presented to the customer. Merchants may prefer to not provide details on why a card was not accepted for security purposes."
1360
  msgstr ""
1361
 
1362
- #: includes/gateways/settings/cc-settings.php:93
1363
  msgid "Credit Card Form"
1364
  msgstr ""
1365
 
1366
- #: includes/gateways/settings/cc-settings.php:96
1367
  msgid "Card Form"
1368
  msgstr ""
1369
 
1370
- #: includes/gateways/settings/cc-settings.php:99
1371
  msgid "Stripe form"
1372
  msgstr ""
1373
 
1374
- #: includes/gateways/settings/cc-settings.php:100
1375
  msgid "Custom form"
1376
  msgstr ""
1377
 
1378
- #: includes/gateways/settings/cc-settings.php:102
1379
  msgid "The Stripe form option displays a CC form rendered by Stripe. It works well with most themes. The custom card forms are offered if you want more options on the CC form design."
1380
  msgstr ""
1381
 
1382
- #: includes/gateways/settings/cc-settings.php:105
1383
  msgid "Custom Form"
1384
  msgstr ""
1385
 
1386
- #: includes/gateways/settings/cc-settings.php:109
1387
  msgid "The design of the credit card form."
1388
  msgstr ""
1389
 
1390
- #: includes/gateways/settings/cc-settings.php:118
1391
  msgid "Postal Code"
1392
  msgstr ""
1393
 
1394
- #: includes/gateways/settings/cc-settings.php:120
1395
  msgid "If enabled, the CC form will show the postal code on the checkout page. If disabled, the billing field's postal code will be used. The postal code will show on the Add Payment Method page for security reasons."
1396
  msgstr ""
1397
 
1398
- #: includes/gateways/settings/googlepay-settings.php:4
1399
  msgid "GPay Business Console"
1400
  msgstr ""
1401
 
1402
- #: includes/gateways/settings/googlepay-settings.php:4
1403
  msgid "When test mode is enabled, Google Pay will work without a merchant ID, allowing you to capture the necessary screenshots the Google API team needs to approve your integration request."
1404
  msgstr ""
1405
 
1406
- #: includes/gateways/settings/googlepay-settings.php:7
1407
- msgid "If you don't want to request a Google Merchant ID, you can use the %sPayment Request Gateway%s which has a Google Pay integration through Stripe via the Chrome browser."
1408
  msgstr ""
1409
 
1410
- #: includes/gateways/settings/googlepay-settings.php:13
1411
  msgid "If enabled, your site can accept Google Pay payments through Stripe."
1412
  msgstr ""
1413
 
1414
- #: includes/gateways/settings/googlepay-settings.php:19
1415
  msgid "Dynamic Price"
1416
  msgstr ""
1417
 
1418
- #: includes/gateways/settings/googlepay-settings.php:22
1419
  msgid "If enabled, the Google Payment sheet will show the order line items. You must have Google whitelist you for callback intents."
1420
  msgstr ""
1421
 
1422
- #: includes/gateways/settings/googlepay-settings.php:25
1423
  msgid "Merchant ID"
1424
  msgstr ""
1425
 
1426
- #: includes/gateways/settings/googlepay-settings.php:27
1427
  msgid "Your Google Merchant ID is given to you by the Google API team once you register for Google Pay. While testing in TEST mode you can leave this value blank and Google Pay will work."
1428
  msgstr ""
1429
 
1430
- #: includes/gateways/settings/googlepay-settings.php:58
1431
  msgid "This option determines whether the customer's funds are capture immediately or authorized and can be captured at a later date."
1432
  msgstr ""
1433
 
1434
- #: includes/gateways/settings/googlepay-settings.php:83
1435
  msgid "Merchant Name"
1436
  msgstr ""
1437
 
1438
- #: includes/gateways/settings/googlepay-settings.php:85
1439
  msgid "The name of your business as it appears on the Google Pay payment sheet."
1440
  msgstr ""
1441
 
1442
- #: includes/gateways/settings/googlepay-settings.php:89
1443
  msgid "Icon"
1444
  msgstr ""
1445
 
1446
- #: includes/gateways/settings/googlepay-settings.php:92
1447
  msgid "With Outline"
1448
  msgstr ""
1449
 
1450
- #: includes/gateways/settings/googlepay-settings.php:93
1451
  msgid "Standard"
1452
  msgstr ""
1453
 
1454
- #: includes/gateways/settings/googlepay-settings.php:96
1455
  msgid "This is the icon style that appears next to the gateway on the checkout page. Google's API team typically requires the With Outline option on the checkout page for branding purposes."
1456
  msgstr ""
1457
 
1458
- #: includes/gateways/settings/googlepay-settings.php:99
1459
  msgid "Button Options"
1460
  msgstr ""
1461
 
1462
- #: includes/gateways/settings/googlepay-settings.php:102
1463
  msgid "Button Color"
1464
  msgstr ""
1465
 
1466
- #: includes/gateways/settings/googlepay-settings.php:106
1467
  msgid "Black"
1468
  msgstr ""
1469
 
1470
- #: includes/gateways/settings/googlepay-settings.php:107
1471
  msgid "White"
1472
  msgstr ""
1473
 
1474
- #: includes/gateways/settings/googlepay-settings.php:109
1475
  msgid "The button color of the GPay button."
1476
  msgstr ""
1477
 
1478
- #: includes/gateways/settings/googlepay-settings.php:112
1479
  msgid "Button Style"
1480
  msgstr ""
1481
 
1482
- #: includes/gateways/settings/googlepay-settings.php:116
1483
  msgid "Long"
1484
  msgstr ""
1485
 
1486
- #: includes/gateways/settings/googlepay-settings.php:117
1487
  msgid "Short"
1488
  msgstr ""
1489
 
1490
- #: includes/gateways/settings/googlepay-settings.php:119
1491
  msgid "The button style of the GPay button."
1492
  msgstr ""
1493
 
1494
- #: includes/gateways/settings/googlepay-settings.php:124
1495
  msgid "If you can't see the Google Pay button, try switching to a Chrome browser."
1496
  msgstr ""
1497
 
1498
- #: includes/gateways/settings/payment-request-settings.php:4
1499
  msgid ""
1500
- "The PaymentRequest gateway uses your customer's browser to render payment options like Google Pay and Microsoft Pay. You can either use the Google Pay gateway for example, or this gateway.\r\n"
1501
  "\t\t\t\t\t\tThe difference is this gateway uses Stripe's PaymentRequest Button rather than render a Google Pay specific button."
1502
  msgstr ""
1503
 
1504
- #: includes/gateways/settings/payment-request-settings.php:18
1505
  msgid "Browser Payments"
1506
  msgstr ""
1507
 
1508
- #: includes/gateways/settings/payment-request-settings.php:75
1509
  msgid "default"
1510
  msgstr ""
1511
 
1512
- #: includes/gateways/settings/payment-request-settings.php:77
1513
  msgid "buy"
1514
  msgstr ""
1515
 
1516
- #: includes/gateways/settings/payment-request-settings.php:79
1517
  msgid "This defines the type of button that will display."
1518
  msgstr ""
1519
 
1520
- #: includes/gateways/settings/payment-request-settings.php:82
1521
  msgid "Theme"
1522
  msgstr ""
1523
 
1524
- #: includes/gateways/settings/payment-request-settings.php:84
1525
  msgid "dark"
1526
  msgstr ""
1527
 
1528
- #: includes/gateways/settings/payment-request-settings.php:85
1529
  msgid "light"
1530
  msgstr ""
1531
 
1532
- #: includes/gateways/settings/payment-request-settings.php:86
1533
  msgid "light-outline"
1534
  msgstr ""
1535
 
1536
- #: includes/gateways/settings/payment-request-settings.php:88
1537
  msgid "This defines the color scheme for the button."
1538
  msgstr ""
1539
 
1540
- #: includes/gateways/settings/payment-request-settings.php:91
1541
  msgid "Height"
1542
  msgstr ""
1543
 
1544
- #: includes/gateways/settings/payment-request-settings.php:93
1545
  msgid "The height of the button. Max height is 64"
1546
  msgstr ""
1547
 
1548
- #: includes/tokens/class-wc-payment-token-stripe-ach.php:68
1549
- #: includes/tokens/class-wc-payment-token-stripe-ach.php:73
1550
- #: includes/tokens/class-wc-payment-token-stripe-cc.php:86
1551
  msgid "Type Ending In"
1552
  msgstr ""
1553
 
1554
- #: includes/tokens/class-wc-payment-token-stripe-ach.php:70
1555
  msgid "{bank_name} ending in {last4}"
1556
  msgstr ""
1557
 
1558
- #: includes/tokens/class-wc-payment-token-stripe-ach.php:75
1559
  msgid "{bank_name} **** {last4}"
1560
  msgstr ""
1561
 
1562
- #: includes/tokens/class-wc-payment-token-stripe-cc.php:88
1563
  msgid "{brand} ending in {last4}"
1564
  msgstr ""
1565
 
1566
- #: includes/tokens/class-wc-payment-token-stripe-cc.php:91
1567
  msgid "Type Masked Number"
1568
  msgstr ""
1569
 
1570
- #: includes/tokens/class-wc-payment-token-stripe-cc.php:96
1571
  msgid "Type Dash Masked Number"
1572
  msgstr ""
1573
 
1574
- #: includes/tokens/class-wc-payment-token-stripe-cc.php:101
1575
  msgid "Type Last 4"
1576
  msgstr ""
1577
 
1578
- #: includes/tokens/class-wc-payment-token-stripe-cc.php:106
1579
  msgid "Type Dash & Last 4"
1580
  msgstr ""
1581
 
1582
- #: includes/tokens/class-wc-payment-token-stripe-cc.php:111
1583
  msgid "Last Four"
1584
  msgstr ""
1585
 
1586
- #: includes/tokens/class-wc-payment-token-stripe-cc.php:116
1587
  msgid "Card Type"
1588
  msgstr ""
1589
 
1590
- #: includes/tokens/class-wc-payment-token-stripe-local-payment.php:31
1591
  msgid "Gateway Title"
1592
  msgstr ""
1593
 
1594
- #: includes/traits/wc-stripe-payment-token-traits.php:25
1595
- msgid "Error deleting Stripe card. Token Id: %s"
1596
- msgstr ""
1597
-
1598
- #: includes/updates/update-3.1.0.php:31
1599
- #: includes/updates/update-3.1.0.php:60
1600
  msgid "Stripe For WooCommerce Update"
1601
  msgstr ""
1602
 
1603
- #: includes/updates/update-3.1.0.php:33
1604
  msgid "Greetings from Payment Plugins,"
1605
  msgstr ""
1606
 
1607
- #: includes/updates/update-3.1.0.php:34
1608
  msgid "At Stripe's request, we have updated Stripe for WooCommerce to use the new Stripe Connect integration. This new integration offers even more security. Stripe is requesting that all merchants switch."
1609
  msgstr ""
1610
 
1611
- #: includes/updates/update-3.1.0.php:35
1612
- msgid "Click %shere%s to be redirected to your Stripe API settings page then click the <strong>Click to Connect</strong> button."
1613
  msgstr ""
1614
 
1615
- #: includes/updates/update-3.1.0.php:44
1616
  msgid "Kind Regards,"
1617
  msgstr ""
1618
 
1619
- #: includes/wc-stripe-functions.php:747
1620
  msgid "Bootstrap form"
1621
  msgstr ""
1622
 
1623
- #: includes/wc-stripe-functions.php:781
1624
  msgid "Simple form"
1625
  msgstr ""
1626
 
1627
- #: includes/wc-stripe-functions.php:814
1628
  msgid "Minimalist form"
1629
  msgstr ""
1630
 
1631
- #: includes/wc-stripe-functions.php:848
1632
  msgid "Inline Form"
1633
  msgstr ""
1634
 
1635
- #: includes/wc-stripe-functions.php:884
1636
  msgid "Rounded Form"
1637
  msgstr ""
1638
 
1639
- #: includes/wc-stripe-functions.php:1092
1640
  msgid "There was an error processing your credit card."
1641
  msgstr ""
1642
 
1643
- #: includes/wc-stripe-functions.php:1093
1644
  msgid "Your card number is incomplete."
1645
  msgstr ""
1646
 
1647
- #: includes/wc-stripe-functions.php:1094
1648
  msgid "The card number is incorrect. Check the card's number or use a different card."
1649
  msgstr ""
1650
 
1651
- #: includes/wc-stripe-functions.php:1095
1652
  msgid "The card's security code is incorrect. Check the card's security code or use a different card."
1653
  msgstr ""
1654
 
1655
- #: includes/wc-stripe-functions.php:1096
1656
  msgid "The card's ZIP code is incorrect. Check the card's ZIP code or use a different card."
1657
  msgstr ""
1658
 
1659
- #: includes/wc-stripe-functions.php:1097
1660
- #: includes/wc-stripe-functions.php:1102
1661
  msgid "The card number is invalid. Check the card details or use a different card."
1662
  msgstr ""
1663
 
1664
- #: includes/wc-stripe-functions.php:1098
1665
  msgid "This value provided to the field contains characters that are unsupported by the field."
1666
  msgstr ""
1667
 
1668
- #: includes/wc-stripe-functions.php:1099
1669
  msgid "The card's security code is invalid. Check the card's security code or use a different card."
1670
  msgstr ""
1671
 
1672
- #: includes/wc-stripe-functions.php:1100
1673
  msgid "The card's expiration month is incorrect. Check the expiration date or use a different card."
1674
  msgstr ""
1675
 
1676
- #: includes/wc-stripe-functions.php:1101
1677
  msgid "The card's expiration year is incorrect. Check the expiration date or use a different card."
1678
  msgstr ""
1679
 
1680
- #: includes/wc-stripe-functions.php:1103
1681
  msgid "The card's address is incorrect. Check the card's address or use a different card."
1682
  msgstr ""
1683
 
1684
- #: includes/wc-stripe-functions.php:1104
1685
  msgid "The card has expired. Check the expiration date or use a different card."
1686
  msgstr ""
1687
 
1688
- #: includes/wc-stripe-functions.php:1105
1689
  msgid "The card has been declined."
1690
  msgstr ""
1691
 
1692
- #: includes/wc-stripe-functions.php:1106
1693
  msgid "Your card's expiration year is in the past."
1694
  msgstr ""
1695
 
1696
- #: includes/wc-stripe-functions.php:1107
1697
  msgid "The bank account number provided is invalid (e.g., missing digits). Bank account information varies from country to country. We recommend creating validations in your entry forms based on the bank account formats we provide."
1698
  msgstr ""
1699
 
1700
- #: includes/wc-stripe-functions.php:1108
1701
  msgid "The specified amount is greater than the maximum amount allowed. Use a lower amount and try again."
1702
  msgstr ""
1703
 
1704
- #: includes/wc-stripe-functions.php:1109
1705
  msgid "The specified amount is less than the minimum amount allowed. Use a higher amount and try again."
1706
  msgstr ""
1707
 
1708
- #: includes/wc-stripe-functions.php:1110
1709
  msgid "The payment requires authentication to proceed. If your customer is off session, notify your customer to return to your application and complete the payment. If you provided the error_on_requires_action parameter, then your customer should try another card that does not require authentication."
1710
  msgstr ""
1711
 
1712
- #: includes/wc-stripe-functions.php:1111
1713
  msgid "The transfer or payout could not be completed because the associated account does not have a sufficient balance available. Create a new transfer or payout using an amount less than or equal to the account's available balance."
1714
  msgstr ""
1715
 
1716
- #: includes/wc-stripe-functions.php:1112
1717
  msgid "The bank account provided can not be used to charge, either because it is not verified yet or it is not supported."
1718
  msgstr ""
1719
 
1720
- #: includes/wc-stripe-functions.php:1113
1721
  msgid "The bank account provided already exists on the specified Customer object. If the bank account should also be attached to a different customer, include the correct customer ID when making the request again."
1722
  msgstr ""
1723
 
1724
- #: includes/wc-stripe-functions.php:1114
1725
  msgid "The bank account provided cannot be used for payouts. A different bank account must be used."
1726
  msgstr ""
1727
 
1728
- #: includes/wc-stripe-functions.php:1115
1729
  msgid "Your Connect platform is attempting to share an unverified bank account with a connected account."
1730
  msgstr ""
1731
 
1732
- #: includes/wc-stripe-functions.php:1116
1733
  msgid "The bank account cannot be verified, either because the microdeposit amounts provided do not match the actual amounts, or because verification has failed too many times."
1734
  msgstr ""
1735
 
1736
- #: includes/wc-stripe-functions.php:1117
1737
  msgid "This card has been declined too many times. You can try to charge this card again after 24 hours. We suggest reaching out to your customer to make sure they have entered all of their information correctly and that there are no issues with their card."
1738
  msgstr ""
1739
 
1740
- #: includes/wc-stripe-functions.php:1118
1741
  msgid "The charge you're attempting to capture has already been captured. Update the request with an uncaptured charge ID."
1742
  msgstr ""
1743
 
1744
- #: includes/wc-stripe-functions.php:1119
1745
  msgid "The charge you're attempting to refund has already been refunded. Update the request to use the ID of a charge that has not been refunded."
1746
  msgstr ""
1747
 
1748
- #: includes/wc-stripe-functions.php:1120
1749
  msgid "The charge you're attempting to refund has been charged back. Check the disputes documentation to learn how to respond to the dispute."
1750
  msgstr ""
1751
 
1752
- #: includes/wc-stripe-functions.php:1121
1753
  msgid "This charge would cause you to exceed your rolling-window processing limit for this source type. Please retry the charge later, or contact us to request a higher processing limit."
1754
  msgstr ""
1755
 
1756
- #: includes/wc-stripe-functions.php:1122
1757
  msgid "The charge cannot be captured as the authorization has expired. Auth and capture charges must be captured within seven days."
1758
  msgstr ""
1759
 
1760
- #: includes/wc-stripe-functions.php:1123
1761
  msgid "One or more provided parameters was not allowed for the given operation on the Charge. Check our API reference or the returned error message to see which values were not correct for that Charge."
1762
  msgstr ""
1763
 
1764
- #: includes/wc-stripe-functions.php:1124
1765
  msgid "The email address is invalid (e.g., not properly formatted). Check that the email address is properly formatted and only includes allowed characters."
1766
  msgstr ""
1767
 
1768
- #: includes/wc-stripe-functions.php:1125
1769
  msgid "The idempotency key provided is currently being used in another request. This occurs if your integration is making duplicate requests simultaneously."
1770
  msgstr ""
1771
 
1772
- #: includes/wc-stripe-functions.php:1126
1773
  msgid "The specified amount is invalid. The charge amount must be a positive integer in the smallest currency unit, and not exceed the minimum or maximum amount."
1774
  msgstr ""
1775
 
1776
- #: includes/wc-stripe-functions.php:1127
1777
  msgid "The source cannot be used because it is not in the correct state (e.g., a charge request is trying to use a source with a pending, failed, or consumed source). Check the status of the source you are attempting to use."
1778
  msgstr ""
1779
 
1780
- #: includes/wc-stripe-functions.php:1128
1781
  msgid "Both a customer and source ID have been provided, but the source has not been saved to the customer. To create a charge for a customer with a specified source, you must first save the card details."
1782
  msgstr ""
1783
 
1784
- #: includes/wc-stripe-functions.php:1129
1785
  msgid "The ZIP code provided was incorrect."
1786
  msgstr ""
1787
 
1788
- #: includes/wc-stripe-functions.php:1130
1789
  msgid "An error occurred while processing the card. Try again later or with a different payment method."
1790
  msgstr ""
1791
 
1792
- #: includes/wc-stripe-functions.php:1131
1793
  msgid "The card does not support this type of purchase."
1794
  msgstr ""
1795
 
1796
- #: includes/wc-stripe-functions.php:1132
1797
- #: includes/wc-stripe-functions.php:1135
1798
- #: includes/wc-stripe-functions.php:1137
1799
  msgid "The card has been declined for an unknown reason."
1800
  msgstr ""
1801
 
1802
- #: includes/wc-stripe-functions.php:1133
1803
  msgid "The customer has exceeded the balance or credit limit available on their card."
1804
  msgstr ""
1805
 
1806
- #: includes/wc-stripe-functions.php:1134
1807
  msgid "The card does not support the specified currency."
1808
  msgstr ""
1809
 
1810
- #: includes/wc-stripe-functions.php:1136
1811
  msgid "The payment has been declined as Stripe suspects it is fraudulent."
1812
  msgstr ""
1813
 
1814
- #: includes/wc-stripe-functions.php:1138
1815
  msgid "The PIN entered is incorrect. "
1816
  msgstr ""
1817
 
1818
- #: includes/wc-stripe-functions.php:1139
1819
  msgid "The card has insufficient funds to complete the purchase."
1820
  msgstr ""
1821
 
1822
- #: includes/wc-stripe-functions.php:1140
1823
  msgid "Please select a payment method before proceeding."
1824
  msgstr ""
1825
 
1826
- #: includes/wc-stripe-functions.php:1141
1827
  msgid "Please enter your IBAN before proceeding."
1828
  msgstr ""
1829
 
1830
- #: includes/wc-stripe-functions.php:1142
1831
  msgid "Please select a bank before proceeding"
1832
  msgstr ""
1833
 
1834
- #: includes/wc-stripe-webhook-functions.php:80
1835
  msgid "Charge.succeeded webhook received. Payment has been completed."
1836
  msgstr ""
1837
 
1838
- #: includes/wc-stripe-webhook-functions.php:117
1839
- msgid "payment_intent.succeeded webhook recieved. Payment has been completed."
1840
  msgstr ""
1841
 
1842
  #: stripe-payments.php:17
1843
- msgid "Your PHP version is %s but Stripe requires version 5.4+."
1844
  msgstr ""
1845
 
1846
  #: templates/cart/payment-methods.php:13
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.1.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-07-03T16:13:39+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:101
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
37
+ #: includes/gateways/settings/applepay-settings.php:11
38
  #: includes/gateways/settings/cc-settings.php:4
39
+ #: includes/gateways/settings/googlepay-settings.php:22
40
+ #: includes/gateways/settings/payment-request-settings.php:12
41
  msgid "Enabled"
42
  msgstr ""
43
 
44
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:106
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:110
49
+ #: includes/gateways/settings/ach-settings-v2.php:64
50
+ #: includes/gateways/settings/ach-settings.php:73
51
+ #: includes/gateways/settings/applepay-settings.php:20
52
+ #: includes/gateways/settings/cc-settings.php:17
53
+ #: includes/gateways/settings/googlepay-settings.php:31
54
+ #: includes/gateways/settings/payment-request-settings.php:21
55
  msgid "General Settings"
56
  msgstr ""
57
 
58
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:114
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:77
62
+ #: includes/gateways/settings/applepay-settings.php:24
63
+ #: includes/gateways/settings/cc-settings.php:21
64
+ #: includes/gateways/settings/googlepay-settings.php:48
65
+ #: includes/gateways/settings/payment-request-settings.php:25
66
  msgid "Title"
67
  msgstr ""
68
 
69
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:120
70
+ #: includes/gateways/settings/ach-settings-v2.php:74
71
+ #: includes/gateways/settings/ach-settings.php:83
72
+ #: includes/gateways/settings/applepay-settings.php:30
73
+ #: includes/gateways/settings/cc-settings.php:27
74
+ #: includes/gateways/settings/googlepay-settings.php:54
75
+ #: includes/gateways/settings/payment-request-settings.php:31
76
  msgid "Description"
77
  msgstr ""
78
 
79
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:123
80
+ #: includes/gateways/settings/ach-settings-v2.php:77
81
+ #: includes/gateways/settings/ach-settings.php:86
82
+ #: includes/gateways/settings/applepay-settings.php:33
83
+ #: includes/gateways/settings/cc-settings.php:30
84
+ #: includes/gateways/settings/googlepay-settings.php:57
85
+ #: includes/gateways/settings/payment-request-settings.php:34
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:172
90
  msgid "Order %s"
91
  msgstr ""
92
 
93
+ #: includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php:241
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:244
98
  msgid " & billing country is <strong>%s</strong>"
99
  msgstr ""
100
 
101
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:344
102
+ #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:115
103
  msgid "Error processing payment. Reason: %s"
104
  msgstr ""
105
 
106
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:352
107
+ msgid "Charge %1$s is pending. Payment Method: %2$s. Payment will be completed once charge.succeeded webhook received from Stripe."
108
  msgstr ""
109
 
110
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:360
111
+ msgid "Order %1$s successful in Stripe. Charge: %2$s. Payment Method: %3$s"
112
  msgstr ""
113
 
114
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:360
115
  msgid "charge"
116
  msgstr ""
117
 
118
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:360
119
  msgid "authorization"
120
  msgstr ""
121
 
122
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:404
123
+ #: includes/controllers/class-wc-stripe-controller-cart.php:128
124
+ #: includes/controllers/class-wc-stripe-controller-cart.php:187
125
+ #: includes/controllers/class-wc-stripe-controller-googlepay.php:135
126
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:101
127
  msgid "Total"
128
  msgstr ""
129
 
130
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:463
131
  msgid "User must be logged in."
132
  msgstr ""
133
 
134
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:475
135
  msgid "Error saving your payment method. Reason: %s"
136
  msgstr ""
137
 
138
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:490
139
  msgid "Error saving payment method. Reason: %s"
140
  msgstr ""
141
 
142
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:509
143
  msgid "Order refunded in Stripe. Amount: %s"
144
  msgstr ""
145
 
146
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:547
147
  msgid "Order amount captured in Stripe. Amount: %s"
148
  msgstr ""
149
 
150
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:557
151
  msgid "Error capturing charge in Stripe. Reason: %s"
152
  msgstr ""
153
 
154
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:578
155
  msgid "Error voiding charge. Reason: %s"
156
  msgstr ""
157
 
158
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:580
159
  msgid "Charge voided in Stripe."
160
  msgstr ""
161
 
162
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:750
163
  msgid "n/a"
164
  msgstr ""
165
 
166
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:778
167
  #: includes/admin/meta-boxes/views/html-order-pay.php:42
168
  msgid "New Card"
169
  msgstr ""
170
 
171
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:782
172
  #: includes/admin/meta-boxes/views/html-order-pay.php:30
173
  msgid "Saved Cards"
174
  msgstr ""
175
 
176
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:955
177
  msgid "Attemp to save payment method failed. Reason: %s"
178
  msgstr ""
179
 
180
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:977
181
  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."
182
  msgstr ""
183
 
184
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:979
185
  msgid "We were not able to save your payment method. Reason: %s"
186
  msgstr ""
187
 
188
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1013
189
  msgid "Payment Method Token"
190
  msgstr ""
191
 
192
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1033
193
  msgid "Recurring payment for order failed. Reason: %s"
194
  msgstr ""
195
 
196
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1046
197
  msgid "Recurring payment captured in Stripe. Payment method: %s"
198
  msgstr ""
199
 
200
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1048
201
  msgid "Recurring payment authorized in Stripe. Payment method: %s"
202
  msgstr ""
203
 
204
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1051
205
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1308
206
  msgid "Customer must manually complete payment for payment method %s"
207
  msgstr ""
208
 
209
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1067
210
  msgid "Error saving payment method for subscription. Reason: %s"
211
  msgstr ""
212
 
213
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1126
214
+ #: includes/abstract/abstract-wc-stripe-payment.php:182
215
+ msgid "Order %1$s from %2$s"
216
  msgstr ""
217
 
218
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1295
219
  msgid "Pre-order payment for order failed. Reason: %s"
220
  msgstr ""
221
 
222
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1303
223
  msgid "Pre-order payment captured in Stripe. Payment method: %s"
224
  msgstr ""
225
 
226
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1305
227
  msgid "Pre-order payment authorized in Stripe. Payment method: %s"
228
  msgstr ""
229
 
230
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1377
231
  msgid "Cannot process payment"
232
  msgstr ""
233
 
234
+ #: includes/abstract/abstract-wc-payment-gateway-stripe.php:1385
235
  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."
236
  msgstr ""
237
 
238
+ #: includes/abstract/abstract-wc-stripe-payment.php:104
239
  msgid "Transaction Id cannot be empty."
240
  msgstr ""
241
 
243
  msgid "You do not have permissions to access this resource."
244
  msgstr ""
245
 
246
+ #: includes/admin/class-wc-stripe-admin-menus.php:19
247
  msgid "Stripe Gateway"
248
  msgstr ""
249
 
250
+ #: includes/admin/class-wc-stripe-admin-menus.php:23
251
+ #: includes/class-wc-stripe-install.php:32
252
  msgid "Settings"
253
  msgstr ""
254
 
255
+ #: includes/admin/class-wc-stripe-admin-menus.php:24
256
  msgid "Logs"
257
  msgstr ""
258
 
259
+ #: includes/admin/class-wc-stripe-admin-menus.php:25
260
+ #: includes/admin/views/html-settings-nav.php:24
261
+ #: includes/class-wc-stripe-install.php:33
262
  msgid "Documentation"
263
  msgstr ""
264
 
265
  #: includes/admin/class-wc-stripe-admin-notices.php:51
266
  msgid ""
267
+ "At Stripe's request we have updated how the Stripe for WooCommerce\n"
268
+ " plugin integrates with Stripe. This new integration offers even more security and \n"
269
+ " Stripe is requesting that all merchants switch. %1$sUpdate Integration%2$s"
270
  msgstr ""
271
 
272
+ #: includes/admin/class-wc-stripe-admin-settings.php:61
273
  msgid "Local Gateways"
274
  msgstr ""
275
 
276
+ #: includes/admin/class-wc-stripe-admin-settings.php:73
277
  msgid "Stripe Email Options"
278
  msgstr ""
279
 
280
+ #: includes/admin/class-wc-stripe-admin-settings.php:77
281
  msgid "Email Receipt"
282
  msgstr ""
283
 
284
+ #: includes/admin/class-wc-stripe-admin-settings.php:80
285
  msgid "If enabled, an email receipt will be sent to the customer by Stripe when the order is processed."
286
  msgstr ""
287
 
288
+ #: includes/admin/meta-boxes/class-wc-stripe-admin-meta-box-product-data.php:19
289
  msgid "Stripe Settings"
290
  msgstr ""
291
 
292
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:9
293
+ #: includes/admin/views/html-user-profile.php:36
294
+ #: includes/admin/views/html-user-profile.php:69
295
  msgid "Actions"
296
  msgstr ""
297
 
300
  msgstr ""
301
 
302
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:14
303
+ #: includes/admin/meta-boxes/views/html-order-actions.php:48
304
  #: includes/admin/meta-boxes/views/html-order-pay.php:23
305
+ #: includes/admin/meta-boxes/views/html-product-data.php:51
306
+ #: includes/gateways/settings/applepay-settings.php:52
307
+ #: includes/gateways/settings/cc-settings.php:49
308
+ #: includes/gateways/settings/googlepay-settings.php:76
309
+ #: includes/gateways/settings/payment-request-settings.php:53
310
  msgid "Capture"
311
  msgstr ""
312
 
319
  msgstr ""
320
 
321
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:24
322
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:34
323
  msgid "Mode"
324
  msgstr ""
325
 
326
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:25
327
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:38
328
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:193
329
  msgid "Live"
330
  msgstr ""
331
 
342
  msgstr ""
343
 
344
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:45
345
+ #: includes/admin/views/html-user-profile.php:34
346
+ #: includes/admin/views/html-user-profile.php:67
347
  msgid "Payment Method"
348
  msgstr ""
349
 
350
  #: includes/admin/meta-boxes/views/html-charge-data-subview.php:51
351
+ #: includes/admin/views/html-ach-fee.php:12
352
+ #: includes/gateways/settings/payment-request-settings.php:86
353
  msgid "Type"
354
  msgstr ""
355
 
379
  msgid "Riska Data"
380
  msgstr ""
381
 
382
+ #: includes/admin/meta-boxes/views/html-charge-data-subview.php:81
383
  msgid "Score"
384
  msgstr ""
385
 
386
+ #: includes/admin/meta-boxes/views/html-charge-data-subview.php:86
387
  msgid "Level"
388
  msgstr ""
389
 
390
+ #: includes/admin/meta-boxes/views/html-order-actions.php:2
391
  msgid "Charge Status"
392
  msgstr ""
393
 
394
+ #: includes/admin/meta-boxes/views/html-order-actions.php:9
395
  msgid "Authorization Expires"
396
  msgstr ""
397
 
398
+ #: includes/admin/meta-boxes/views/html-order-actions.php:18
399
  msgid "There are no actions available at this time."
400
  msgstr ""
401
 
402
+ #: includes/admin/meta-boxes/views/html-order-actions.php:27
403
  msgid "Capture Charge"
404
  msgstr ""
405
 
406
+ #: includes/admin/meta-boxes/views/html-order-actions.php:35
407
  msgid "Total available to capture"
408
  msgstr ""
409
 
410
+ #: includes/admin/meta-boxes/views/html-order-actions.php:39
411
  msgid "Amount To Capture"
412
  msgstr ""
413
 
414
+ #: includes/admin/meta-boxes/views/html-order-actions.php:49
415
  msgid "Cancel"
416
  msgstr ""
417
 
428
  msgstr ""
429
 
430
  #: includes/admin/meta-boxes/views/html-order-pay.php:21
431
+ #: includes/admin/meta-boxes/views/html-product-data.php:15
432
+ #: includes/gateways/settings/applepay-settings.php:48
433
+ #: includes/gateways/settings/cc-settings.php:45
434
+ #: includes/gateways/settings/googlepay-settings.php:72
435
+ #: includes/gateways/settings/payment-request-settings.php:49
436
  msgid "Charge Type"
437
  msgstr ""
438
 
439
  #: includes/admin/meta-boxes/views/html-order-pay.php:24
440
+ #: includes/admin/meta-boxes/views/html-product-data.php:53
441
+ #: includes/gateways/settings/applepay-settings.php:53
442
+ #: includes/gateways/settings/cc-settings.php:50
443
+ #: includes/gateways/settings/googlepay-settings.php:77
444
+ #: includes/gateways/settings/payment-request-settings.php:54
445
  msgid "Authorize"
446
  msgstr ""
447
 
453
  msgid "In this section you can control which gateways are displayed on the product page."
454
  msgstr ""
455
 
456
+ #: includes/admin/meta-boxes/views/html-product-data.php:13
457
  msgid "Method"
458
  msgstr ""
459
 
460
+ #: includes/admin/meta-boxes/views/html-product-data.php:64
461
  msgid "Button Position"
462
  msgstr ""
463
 
464
+ #: includes/admin/meta-boxes/views/html-product-data.php:66
465
  msgid "Below add to cart"
466
  msgstr ""
467
 
468
+ #: includes/admin/meta-boxes/views/html-product-data.php:67
469
  msgid "Above add to cart"
470
  msgstr ""
471
 
472
+ #: includes/admin/meta-boxes/views/html-product-data.php:70
473
  msgid "The location of the payment buttons in relation to the Add to Cart button."
474
  msgstr ""
475
 
476
+ #: includes/admin/meta-boxes/views/html-product-data.php:79
477
  msgid "Save"
478
  msgstr ""
479
 
480
  #: includes/admin/settings/class-wc-stripe-api-settings.php:15
481
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:30
482
  msgid "API Settings"
483
  msgstr ""
484
 
485
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:37
486
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:193
487
  msgid "Test"
488
  msgstr ""
489
 
490
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:42
491
  msgid "The mode determines if you are processing test transactions or live transactions on your site. Test mode allows you to simulate payments so you can test your integration."
492
  msgstr ""
493
 
494
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:46
495
  msgid "Account ID"
496
  msgstr ""
497
 
498
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:51
499
  msgid "This is your Stripe Connect ID and serves as a unique identifier."
500
  msgstr ""
501
 
502
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:55
503
  msgid "Connect Stripe Account"
504
  msgstr ""
505
 
506
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:56
507
  msgid "Click to Connect"
508
  msgstr ""
509
 
510
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:58
511
  msgid "We make it easy to connect Stripe to your site. Click the Connect button to go through our connect flow."
512
  msgstr ""
513
 
514
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:62
515
  #: includes/admin/settings/class-wc-stripe-api-settings.php:63
 
516
  msgid "Connection Test"
517
  msgstr ""
518
 
519
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:65
520
  msgid "Click this button to perform a connection test. If successful, your site is connected to Stripe."
521
  msgstr ""
522
 
523
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:69
524
  msgid "Webhook url"
525
  msgstr ""
526
 
527
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:72
528
+ msgid "<strong>Important:</strong> the webhook url is called by Stripe when events occur in your account, like a source becomes chargeable. You must add this webhook to your Stripe Dashboard if you are using any of the local gateways. %1$sWebhook guide%2$s"
529
  msgstr ""
530
 
531
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:76
532
  msgid "Live Webhook Secret"
533
  msgstr ""
534
 
535
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:77
536
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:83
537
+ msgid "The webhook secret is used to authenticate webhooks sent from Stripe. It ensures no 3rd party can send you events, pretending to be Stripe. %1$sWebhook guide%2$s"
538
  msgstr ""
539
 
540
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:82
541
  msgid "Test Webhook Secret"
542
  msgstr ""
543
 
544
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:87
545
  msgid "Debug Log"
546
  msgstr ""
547
 
548
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:91
549
  msgid "When enabled, the plugin logs important errors and info that can help you troubleshoot potential issues."
550
  msgstr ""
551
 
552
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:96
553
  msgid "%s Your Stripe account has been connected. You can now accept Live and Test payments. You can Re-Connect if you want to recycle your API keys for security."
554
  msgstr ""
555
 
556
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:118
557
  msgid "Click To Re-Connect"
558
  msgstr ""
559
 
560
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:136
561
  msgid "Please try again."
562
  msgstr ""
563
 
564
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:139
565
  msgid "We were not able to connect your Stripe account. Reason: %s"
566
  msgstr ""
567
 
568
+ #: includes/admin/settings/class-wc-stripe-api-settings.php:168
569
  msgid "Your Stripe account has been connected to your WooCommerce store. You may now accept payments in Live and Test mode."
570
  msgstr ""
571
 
572
+ #: includes/admin/views/html-ach-fee.php:20
573
  msgid "Taxable"
574
  msgstr ""
575
 
576
+ #: includes/admin/views/html-ach-fee.php:27
577
  msgid "Value"
578
  msgstr ""
579
 
585
  msgid "Live ID"
586
  msgstr ""
587
 
588
+ #: includes/admin/views/html-user-profile.php:20
589
  msgid "Test ID"
590
  msgstr ""
591
 
592
+ #: includes/admin/views/html-user-profile.php:28
593
  msgid "Stripe Live Payment Methods"
594
  msgstr ""
595
 
596
+ #: includes/admin/views/html-user-profile.php:33
597
+ #: includes/admin/views/html-user-profile.php:66
598
  msgid "Payment Gateway"
599
  msgstr ""
600
 
601
+ #: includes/admin/views/html-user-profile.php:35
602
+ #: includes/admin/views/html-user-profile.php:68
603
  msgid "Token"
604
  msgstr ""
605
 
606
+ #: includes/admin/views/html-user-profile.php:52
607
+ #: includes/admin/views/html-user-profile.php:85
608
  msgid "No Action"
609
  msgstr ""
610
 
611
+ #: includes/admin/views/html-user-profile.php:53
612
+ #: includes/admin/views/html-user-profile.php:86
613
  msgid "Delete"
614
  msgstr ""
615
 
616
+ #: includes/admin/views/html-user-profile.php:59
617
  msgid "No live payment methods saved"
618
  msgstr ""
619
 
620
+ #: includes/admin/views/html-user-profile.php:61
621
  msgid "Stripe Test Payment Methods"
622
  msgstr ""
623
 
626
  msgstr ""
627
 
628
  #: includes/admin/views/html-user-profile.php:94
629
+ msgid "%1$snote:%2$s payment methods will be deleted in Stripe if you use the delete action."
630
  msgstr ""
631
 
632
+ #: includes/class-wc-stripe-customer-manager.php:29
633
+ #: includes/class-wc-stripe-customer-manager.php:38
634
  msgid "Error saving customer. Reason: %s"
635
  msgstr ""
636
 
637
+ #: includes/class-wc-stripe-frontend-notices.php:35
638
  msgid "Your payment is being processed and your order status will be updated once the funds are received."
639
  msgstr ""
640
 
641
+ #: includes/class-wc-stripe-frontend-scripts.php:67
642
  msgid "No matches found"
643
  msgstr ""
644
 
645
+ #: includes/class-wc-stripe-redirect-handler.php:35
 
 
 
 
646
  msgid "Error retrieving payment source. Reason: %s"
647
  msgstr ""
648
 
649
+ #: includes/class-wc-stripe-redirect-handler.php:51
650
  msgid "Payment authorization failed. Please select another payment method."
651
  msgstr ""
652
 
653
+ #: includes/class-wc-stripe-redirect-handler.php:52
654
  msgid "Payment authorization failed."
655
  msgstr ""
656
 
657
+ #: includes/class-wc-stripe-rest-api.php:41
658
  msgid "%1$s is an invalid controller name."
659
  msgstr ""
660
 
661
+ #: includes/class-wc-stripe-update.php:46
662
  msgid "Thank you for updating Stripe for WooCommerce to version %1$s."
663
  msgstr ""
664
 
665
+ #: includes/controllers/class-wc-stripe-controller-cart.php:87
666
  msgid "Quantity must be greater than zero."
667
  msgstr ""
668
 
669
+ #: includes/controllers/class-wc-stripe-controller-checkout.php:199
670
+ msgid "Some required fields were missing. Please click %1$shere%2$s to complete your payment."
671
  msgstr ""
672
 
673
+ #: includes/controllers/class-wc-stripe-controller-checkout.php:248
674
  msgid "Please review your order details then click Place Order."
675
  msgstr ""
676
 
677
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:91
678
  msgid "You cannot register your domain until you have configured your Live API keys."
679
  msgstr ""
680
 
681
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:120
682
  msgid "Domain registered successfully. You can confirm in your Stripe Dashboard at https://dashboard.stripe.com/account/apple_pay."
683
  msgstr ""
684
 
685
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:144
686
  msgid "You must configure your secret key before creating webhooks."
687
  msgstr ""
688
 
689
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:157
690
  msgid "There is already a webhook configured for this site. If you want to delete the webhook, login to your Stripe Dashboard."
691
  msgstr ""
692
 
693
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:191
694
  msgid "Webhook created in Stripe for %s environment. You can test your webhook by logging in to the Stripe dashboard"
695
  msgstr ""
696
 
697
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:214
698
  msgid "Mode: %s. Invalid secret key. Please check your entry."
699
  msgstr ""
700
 
701
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:226
702
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:229
703
  msgid "Mode: %s. Invalid publishable key. Please check your entry."
704
  msgstr ""
705
 
706
+ #: includes/controllers/class-wc-stripe-controller-gateway-settings.php:235
707
  msgid "Connection test to Stripe was successful. Mode: %s."
708
  msgstr ""
709
 
710
+ #: includes/controllers/class-wc-stripe-controller-googlepay.php:89
711
  msgid "Your shipping address is not serviceable."
712
  msgstr ""
713
 
714
+ #: includes/controllers/class-wc-stripe-controller-order-actions.php:125
715
  msgid "Invalid amount entered."
716
  msgstr ""
717
 
718
+ #: includes/controllers/class-wc-stripe-controller-order-actions.php:179
719
+ #: includes/controllers/class-wc-stripe-controller-order-actions.php:182
720
  msgid "Order total must be greater than zero."
721
  msgstr ""
722
 
723
+ #: includes/controllers/class-wc-stripe-controller-order-actions.php:192
724
+ msgid "This order has already been processed. Transaction ID: %1$s. Payment method: %2$s"
725
  msgstr ""
726
 
727
+ #: includes/controllers/class-wc-stripe-controller-order-actions.php:201
728
  msgid "Order customer Id and payment method customer Id do not match."
729
  msgstr ""
730
 
732
  msgid "Error creating payment intent. Reason: %s"
733
  msgstr ""
734
 
735
+ #: includes/controllers/class-wc-stripe-controller-payment-intent.php:72
736
  msgid "Invalid order id provided"
737
  msgstr ""
738
 
739
+ #: includes/controllers/class-wc-stripe-controller-payment-intent.php:78
740
  msgid "You are not authorized to update this order."
741
  msgstr ""
742
 
743
+ #: includes/controllers/class-wc-stripe-controller-webhook.php:52
744
+ #: includes/controllers/class-wc-stripe-controller-webhook.php:53
745
  msgid "Invalid signature received. Verify that your webhook secret is correct."
746
  msgstr ""
747
 
 
748
  #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:26
749
  msgid "ACH"
750
  msgstr ""
751
 
 
752
  #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:29
753
  msgid "Stripe ACH"
754
  msgstr ""
755
 
 
756
  #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:30
757
  msgid "ACH gateway that integrates with your Stripe account."
758
  msgstr ""
759
 
 
760
  #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:32
761
  msgid "Bank Payment"
762
  msgstr ""
763
 
764
+ #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:217
 
765
  msgid "Saved Banks"
766
  msgstr ""
767
 
768
+ #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:221
 
769
  msgid "New Bank"
770
  msgstr ""
771
 
772
+ #: includes/gateways/class-wc-payment-gateway-stripe-ach.php:265
 
773
  msgid "You must set the API mode to live in order to enable the Plaid development environment."
774
  msgstr ""
775
 
776
+ #: includes/gateways/class-wc-payment-gateway-stripe-alipay.php:24
777
+ #: includes/gateways/class-wc-payment-gateway-stripe-alipay.php:27
778
+ #: includes/gateways/class-wc-payment-gateway-stripe-alipay.php:30
779
  msgid "Alipay"
780
  msgstr ""
781
 
782
+ #: includes/gateways/class-wc-payment-gateway-stripe-alipay.php:28
783
  msgid "Alipay gateway that integrates with your Stripe account."
784
  msgstr ""
785
 
786
+ #: includes/gateways/class-wc-payment-gateway-stripe-applepay.php:22
787
+ #: includes/gateways/settings/applepay-settings.php:25
788
  msgid "Apple Pay"
789
  msgstr ""
790
 
791
+ #: includes/gateways/class-wc-payment-gateway-stripe-applepay.php:25
792
  msgid "Stripe Apple Pay"
793
  msgstr ""
794
 
795
+ #: includes/gateways/class-wc-payment-gateway-stripe-applepay.php:26
796
  msgid "Apple Pay gateway that integrates with your Stripe account."
797
  msgstr ""
798
 
799
+ #: includes/gateways/class-wc-payment-gateway-stripe-applepay.php:85
800
  msgid "Please update you product quantity before using Apple Pay."
801
  msgstr ""
802
 
803
+ #: includes/gateways/class-wc-payment-gateway-stripe-applepay.php:86
804
+ #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:78
805
  msgid "Please select a product option before updating quantity."
806
  msgstr ""
807
 
808
+ #: includes/gateways/class-wc-payment-gateway-stripe-bancontact.php:24
809
+ #: includes/gateways/class-wc-payment-gateway-stripe-bancontact.php:27
810
+ #: includes/gateways/class-wc-payment-gateway-stripe-bancontact.php:30
811
  msgid "Bancontact"
812
  msgstr ""
813
 
814
+ #: includes/gateways/class-wc-payment-gateway-stripe-bancontact.php:28
815
  msgid "Bancontact gateway that integrates with your Stripe account."
816
  msgstr ""
817
 
818
  #: includes/gateways/class-wc-payment-gateway-stripe-cc.php:19
819
+ #: includes/gateways/settings/cc-settings.php:22
820
  msgid "Credit Cards"
821
  msgstr ""
822
 
828
  msgid "Credit card gateway that integrates with your Stripe account."
829
  msgstr ""
830
 
831
+ #: includes/gateways/class-wc-payment-gateway-stripe-eps.php:23
832
+ #: includes/gateways/class-wc-payment-gateway-stripe-eps.php:26
833
+ #: includes/gateways/class-wc-payment-gateway-stripe-eps.php:29
834
  msgid "EPS"
835
  msgstr ""
836
 
837
+ #: includes/gateways/class-wc-payment-gateway-stripe-eps.php:27
838
  msgid "EPS gateway that integrates with your Stripe account."
839
  msgstr ""
840
 
841
+ #: includes/gateways/class-wc-payment-gateway-stripe-fpx.php:25
842
  #: includes/gateways/class-wc-payment-gateway-stripe-fpx.php:26
843
+ #: includes/gateways/class-wc-payment-gateway-stripe-fpx.php:29
 
844
  msgid "FPX"
845
  msgstr ""
846
 
847
+ #: includes/gateways/class-wc-payment-gateway-stripe-fpx.php:27
848
  msgid "FPX gateway that integrates with your Stripe account."
849
  msgstr ""
850
 
851
+ #: includes/gateways/class-wc-payment-gateway-stripe-giropay.php:23
852
+ #: includes/gateways/class-wc-payment-gateway-stripe-giropay.php:26
853
+ #: includes/gateways/class-wc-payment-gateway-stripe-giropay.php:29
854
  msgid "Giropay"
855
  msgstr ""
856
 
857
+ #: includes/gateways/class-wc-payment-gateway-stripe-giropay.php:27
858
  msgid "Giropay gateway that integrates with your Stripe account."
859
  msgstr ""
860
 
861
  #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:20
862
+ #: includes/gateways/settings/googlepay-settings.php:49
863
  msgid "Google Pay"
864
  msgstr ""
865
 
871
  msgid "Google Pay gateway that integrates with your Stripe account."
872
  msgstr ""
873
 
874
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:103
875
  msgid "Please update you product quantity before using Google Pay."
876
  msgstr ""
877
 
878
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:117
879
  msgid "Subscription"
880
  msgstr ""
881
 
882
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:147
883
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:198
884
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:202
885
+ #: includes/wc-stripe-functions.php:401
886
+ #: includes/wc-stripe-functions.php:457
887
  msgid "Shipping"
888
  msgstr ""
889
 
890
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:155
891
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:220
892
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:212
893
+ #: includes/wc-stripe-functions.php:418
894
+ #: includes/wc-stripe-functions.php:465
895
  msgid "Discount"
896
  msgstr ""
897
 
898
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:166
899
+ #: includes/wc-stripe-functions.php:476
900
  msgid "Fees"
901
  msgstr ""
902
 
903
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:234
904
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:234
905
+ #: includes/wc-stripe-functions.php:426
906
  msgid "Tax"
907
  msgstr ""
908
 
909
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:274
 
910
  msgid "Waiting..."
911
  msgstr ""
912
 
913
+ #: includes/gateways/class-wc-payment-gateway-stripe-googlepay.php:275
 
914
  msgid "loading shipping methods..."
915
  msgstr ""
916
 
917
+ #: includes/gateways/class-wc-payment-gateway-stripe-ideal.php:27
918
  #: includes/gateways/class-wc-payment-gateway-stripe-ideal.php:28
919
+ #: includes/gateways/class-wc-payment-gateway-stripe-ideal.php:31
 
920
  msgid "iDEAL"
921
  msgstr ""
922
 
923
+ #: includes/gateways/class-wc-payment-gateway-stripe-ideal.php:29
924
  msgid "Ideal gateway that integrates with your Stripe account."
925
  msgstr ""
926
 
927
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:22
928
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:25
929
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:28
930
  msgid "Klarna"
931
  msgstr ""
932
 
933
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:26
934
  msgid "Klarna gateway that integrates with your Stripe account."
935
  msgstr ""
936
 
937
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:102
938
  msgid "Payment Categories"
939
  msgstr ""
940
 
941
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:108
942
+ msgid "These are the payment categories that will be displayed on the checkout page if they are supported. Note, depending on the customer's billing country, not all enabled options may show."
943
  msgstr ""
944
 
945
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:226
946
  msgid "Fee"
947
  msgstr ""
948
 
949
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:270
950
  msgid "Pay Now"
951
  msgstr ""
952
 
953
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:271
954
  msgid "Pay Later"
955
  msgstr ""
956
 
957
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:272
958
  msgid "Pay Over Time"
959
  msgstr ""
960
 
961
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:288
962
+ msgid "Click %1$shere%2$s for Klarna test payment methods."
963
  msgstr ""
964
 
965
+ #: includes/gateways/class-wc-payment-gateway-stripe-klarna.php:294
966
  msgid "Your purchase is not approved."
967
  msgstr ""
968
 
969
+ #: includes/gateways/class-wc-payment-gateway-stripe-multibanco.php:23
970
+ #: includes/gateways/class-wc-payment-gateway-stripe-multibanco.php:26
971
+ #: includes/gateways/class-wc-payment-gateway-stripe-multibanco.php:29
972
  msgid "Multibanco"
973
  msgstr ""
974
 
975
+ #: includes/gateways/class-wc-payment-gateway-stripe-multibanco.php:27
976
  msgid "Multibanco gateway that integrates with your Stripe account."
977
  msgstr ""
978
 
979
+ #: includes/gateways/class-wc-payment-gateway-stripe-p24.php:23
980
+ #: includes/gateways/class-wc-payment-gateway-stripe-p24.php:26
981
  msgid "Przelewy24"
982
  msgstr ""
983
 
984
+ #: includes/gateways/class-wc-payment-gateway-stripe-p24.php:27
985
  msgid "P24 gateway that integrates with your Stripe account."
986
  msgstr ""
987
 
988
+ #: includes/gateways/class-wc-payment-gateway-stripe-p24.php:29
989
  msgid "P24"
990
  msgstr ""
991
 
992
+ #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:23
993
  msgid "PaymentRequest Gateway"
994
  msgstr ""
995
 
996
+ #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:26
997
  msgid "Stripe Payment Request"
998
  msgstr ""
999
 
1000
+ #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:27
1001
  msgid "Gateway that renders based on the user's browser. Chrome payment methods, Microsoft pay, etc."
1002
  msgstr ""
1003
 
1004
+ #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:76
1005
  msgid "Please update you product quantity before paying."
1006
  msgstr ""
1007
 
1008
+ #: includes/gateways/class-wc-payment-gateway-stripe-payment-request.php:77
1009
  msgid "Adding to cart..."
1010
  msgstr ""
1011
 
1022
  msgid "Sepa gateway that integrates with your Stripe account."
1023
  msgstr ""
1024
 
1025
+ #: includes/gateways/class-wc-payment-gateway-stripe-sepa.php:33
1026
  msgid ""
1027
+ "By providing your IBAN and confirming this payment, you are\n"
1028
+ "\t\t\tauthorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account\n"
1029
+ "\t\t\tand your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the\n"
1030
  "\t\t\tterms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited."
1031
  msgstr ""
1032
 
1033
+ #: includes/gateways/class-wc-payment-gateway-stripe-sepa.php:51
1034
  msgid "Company Name"
1035
  msgstr ""
1036
 
1037
+ #: includes/gateways/class-wc-payment-gateway-stripe-sepa.php:55
1038
  msgid "The name of your company that will appear in the SEPA mandate."
1039
  msgstr ""
1040
 
1041
+ #: includes/gateways/class-wc-payment-gateway-stripe-sepa.php:62
1042
  msgid "SEPA Test Accounts"
1043
  msgstr ""
1044
 
1045
+ #: includes/gateways/class-wc-payment-gateway-stripe-sofort.php:24
1046
+ #: includes/gateways/class-wc-payment-gateway-stripe-sofort.php:27
1047
  msgid "Sofort"
1048
  msgstr ""
1049
 
1050
+ #: includes/gateways/class-wc-payment-gateway-stripe-sofort.php:28
1051
  msgid "Sofort gateway that integrates with your Stripe account."
1052
  msgstr ""
1053
 
1054
+ #: includes/gateways/class-wc-payment-gateway-stripe-sofort.php:30
1055
  msgid "SOFORT"
1056
  msgstr ""
1057
 
1058
+ #: includes/gateways/class-wc-payment-gateway-stripe-wechat.php:24
1059
+ #: includes/gateways/class-wc-payment-gateway-stripe-wechat.php:27
1060
+ #: includes/gateways/class-wc-payment-gateway-stripe-wechat.php:30
1061
  msgid "WeChat"
1062
  msgstr ""
1063
 
1064
+ #: includes/gateways/class-wc-payment-gateway-stripe-wechat.php:28
1065
  msgid "WeChat gateway that integrates with your Stripe account."
1066
  msgstr ""
1067
 
1068
+ #: includes/gateways/class-wc-payment-gateway-stripe-wechat.php:70
1069
  msgid "Scan the QR code using your WeChat app. Once scanned click the Place Order button."
1070
  msgstr ""
1071
 
1072
+ #: includes/gateways/settings/ach-settings-v2.php:5
1073
+ #: includes/gateways/settings/ach-settings.php:5
1074
  msgid "For US customers only."
1075
  msgstr ""
1076
 
1077
+ #: includes/gateways/settings/ach-settings-v2.php:6
1078
+ #: includes/gateways/settings/ach-settings.php:6
1079
+ msgid "Read through our %1$sdocumentation%2$s to configure ACH payments"
1080
  msgstr ""
1081
 
1082
+ #: includes/gateways/settings/ach-settings-v2.php:14
1083
+ #: includes/gateways/settings/ach-settings.php:14
1084
  msgid "If enabled, your site can accept ACH payments through Stripe."
1085
  msgstr ""
1086
 
1087
+ #: includes/gateways/settings/ach-settings-v2.php:18
1088
+ #: includes/gateways/settings/ach-settings.php:18
1089
  msgid "Plaid Environment"
1090
  msgstr ""
1091
 
1092
+ #: includes/gateways/settings/ach-settings-v2.php:20
1093
+ #: includes/gateways/settings/ach-settings.php:21
1094
  msgid "Sandbox"
1095
  msgstr ""
1096
 
1097
+ #: includes/gateways/settings/ach-settings-v2.php:21
1098
+ #: includes/gateways/settings/ach-settings.php:22
1099
  msgid "Development"
1100
  msgstr ""
1101
 
1102
+ #: includes/gateways/settings/ach-settings-v2.php:22
1103
+ #: includes/gateways/settings/ach-settings.php:23
1104
  msgid "Production"
1105
  msgstr ""
1106
 
1107
+ #: includes/gateways/settings/ach-settings-v2.php:24
1108
  msgid "This setting determines the Plaid environment you are connecting with. When you are ready to accept live transactions, switch this option to Production.<br><strong>Production</strong> - accept live ACH payments <br><strong>Development</strong> - use real bank login details with test transactions <br><strong>Sandbox</strong> - test integration using test credentials"
1109
  msgstr ""
1110
 
1111
+ #: includes/gateways/settings/ach-settings-v2.php:69
1112
+ #: includes/gateways/settings/ach-settings.php:78
1113
  msgid "ACH Payment"
1114
  msgstr ""
1115
 
1116
+ #: includes/gateways/settings/ach-settings-v2.php:82
1117
+ #: includes/gateways/settings/ach-settings.php:91
1118
  msgid "Client Name"
1119
  msgstr ""
1120
 
1121
+ #: includes/gateways/settings/ach-settings-v2.php:84
1122
+ #: includes/gateways/settings/ach-settings.php:93
1123
  msgid "The name that appears on the ACH payment screen."
1124
  msgstr ""
1125
 
1126
+ #: includes/gateways/settings/ach-settings-v2.php:88
1127
+ #: includes/gateways/settings/ach-settings.php:97
1128
  msgid "ACH Display"
1129
  msgstr ""
1130
 
1131
+ #: includes/gateways/settings/ach-settings-v2.php:98
1132
+ #: includes/gateways/settings/ach-settings.php:107
1133
  msgid "ACH Fee"
1134
  msgstr ""
1135
 
1136
+ #: includes/gateways/settings/ach-settings-v2.php:108
1137
+ #: includes/gateways/settings/ach-settings.php:117
1138
  msgid "None"
1139
  msgstr ""
1140
 
1141
+ #: includes/gateways/settings/ach-settings-v2.php:109
1142
+ #: includes/gateways/settings/ach-settings.php:118
1143
  msgid "Amount"
1144
  msgstr ""
1145
 
1146
+ #: includes/gateways/settings/ach-settings-v2.php:110
1147
+ #: includes/gateways/settings/ach-settings.php:119
1148
  msgid "Percentage"
1149
  msgstr ""
1150
 
1151
+ #: includes/gateways/settings/ach-settings-v2.php:113
1152
+ #: includes/gateways/settings/ach-settings.php:122
1153
  msgid "You can assign a fee to the order for ACH payments. Amount is a static amount and percentage is a percentage of the cart amount."
1154
  msgstr ""
1155
 
1156
+ #: includes/gateways/settings/ach-settings.php:26
1157
  msgid "The active Plaid environment. You must set API mode to live to use Plaid's development environment."
1158
  msgstr ""
1159
 
1160
+ #: includes/gateways/settings/ach-settings.php:36
1161
  msgid "ID that identifies your Plaid account."
1162
  msgstr ""
1163
 
1164
+ #: includes/gateways/settings/ach-settings.php:43
1165
  msgid "Used to identify ACH payments initiated from your site."
1166
  msgstr ""
1167
 
1168
+ #: includes/gateways/settings/ach-settings.php:51
1169
  msgid "Sandbox Secret"
1170
  msgstr ""
1171
 
1172
+ #: includes/gateways/settings/ach-settings.php:54
1173
  msgid "Key that acts as a password when connecting to Plaid's sandbox environment."
1174
  msgstr ""
1175
 
1176
+ #: includes/gateways/settings/ach-settings.php:58
1177
  msgid "Development Secret"
1178
  msgstr ""
1179
 
1180
+ #: includes/gateways/settings/ach-settings.php:61
1181
  msgid "Development allows you to test real bank credentials with test transactions."
1182
  msgstr ""
1183
 
1184
+ #: includes/gateways/settings/ach-settings.php:65
1185
  msgid "Production Secret"
1186
  msgstr ""
1187
 
1188
+ #: includes/gateways/settings/ach-settings.php:68
1189
  msgid "Key that acts as a password when connecting to Plaid's production environment."
1190
  msgstr ""
1191
 
1192
+ #: includes/gateways/settings/applepay-settings.php:5
1193
  msgid "Register Domain"
1194
  msgstr ""
1195
 
1196
+ #: includes/gateways/settings/applepay-settings.php:5
1197
+ msgid "This plugin attemps to add the domain association file to your server automatically when you click the Register Domain button. If that fails due to file permssions, you must add the <strong>%1$s.well-known/apple-developer-merchantid-domain-association%2$s</strong> file to your domain and register your domain within the Stripe Dashboard."
1198
  msgstr ""
1199
 
1200
+ #: includes/gateways/settings/applepay-settings.php:7
1201
  msgid "In order for Apple Pay to display, you must test with an iOS device and have a payment method saved in the Apple Wallet."
1202
  msgstr ""
1203
 
1204
+ #: includes/gateways/settings/applepay-settings.php:16
1205
+ #: includes/gateways/settings/payment-request-settings.php:17
1206
  msgid "If enabled, your site can accept Apple Pay payments through Stripe."
1207
  msgstr ""
1208
 
1209
+ #: includes/gateways/settings/applepay-settings.php:37
1210
+ #: includes/gateways/settings/cc-settings.php:34
1211
+ #: includes/gateways/settings/googlepay-settings.php:61
1212
+ #: includes/gateways/settings/payment-request-settings.php:38
1213
  msgid "Credit Card Display"
1214
  msgstr ""
1215
 
1216
+ #: includes/gateways/settings/applepay-settings.php:56
1217
+ #: includes/gateways/settings/cc-settings.php:53
1218
+ #: includes/gateways/settings/payment-request-settings.php:57
1219
  msgid "This option determines whether the customer's funds are captured immediately or authorized and can be captured at a later date."
1220
  msgstr ""
1221
 
1222
+ #: includes/gateways/settings/applepay-settings.php:60
1223
+ #: includes/gateways/settings/googlepay-settings.php:84
1224
+ #: includes/gateways/settings/payment-request-settings.php:61
1225
  msgid "Payment Sections"
1226
  msgstr ""
1227
 
1228
+ #: includes/gateways/settings/applepay-settings.php:63
1229
+ #: includes/gateways/settings/googlepay-settings.php:87
1230
+ #: includes/gateways/settings/payment-request-settings.php:64
1231
  msgid "Product Page"
1232
  msgstr ""
1233
 
1234
+ #: includes/gateways/settings/applepay-settings.php:64
1235
+ #: includes/gateways/settings/googlepay-settings.php:88
1236
+ #: includes/gateways/settings/payment-request-settings.php:65
1237
  msgid "Cart Page"
1238
  msgstr ""
1239
 
1240
+ #: includes/gateways/settings/applepay-settings.php:65
1241
+ #: includes/gateways/settings/googlepay-settings.php:89
1242
+ #: includes/gateways/settings/payment-request-settings.php:66
1243
  msgid "Top of Checkout"
1244
  msgstr ""
1245
 
1246
+ #: includes/gateways/settings/applepay-settings.php:72
1247
+ #: includes/gateways/settings/cc-settings.php:57
1248
+ #: includes/gateways/settings/googlepay-settings.php:96
1249
+ #: includes/gateways/settings/payment-request-settings.php:73
1250
  msgid "Order Status"
1251
  msgstr ""
1252
 
1253
+ #: includes/gateways/settings/applepay-settings.php:75
1254
+ #: includes/gateways/settings/cc-settings.php:60
1255
+ #: includes/gateways/settings/googlepay-settings.php:99
1256
+ #: includes/gateways/settings/payment-request-settings.php:76
1257
  msgid "Default"
1258
  msgstr ""
1259
 
1260
+ #: includes/gateways/settings/applepay-settings.php:77
1261
+ #: includes/gateways/settings/cc-settings.php:62
1262
+ #: includes/gateways/settings/googlepay-settings.php:101
1263
+ #: includes/gateways/settings/payment-request-settings.php:78
1264
  msgid "This is the status of the order once payment is complete. If <b>Default</b> is selected, then WooCommerce will set the order status automatically based on internal logic which states if a product is virtual and downloadable then status is set to complete. Products that require shipping are set to Processing. Default is the recommended setting as it allows standard WooCommerce code to process the order status."
1265
  msgstr ""
1266
 
1267
+ #: includes/gateways/settings/applepay-settings.php:81
1268
+ #: includes/gateways/settings/payment-request-settings.php:82
1269
  msgid "Button Settings"
1270
  msgstr ""
1271
 
1272
+ #: includes/gateways/settings/applepay-settings.php:85
1273
+ #: includes/gateways/settings/googlepay-settings.php:149
1274
  msgid "Button Design"
1275
  msgstr ""
1276
 
1277
+ #: includes/gateways/settings/applepay-settings.php:89
1278
  msgid "Black Button"
1279
  msgstr ""
1280
 
1281
+ #: includes/gateways/settings/applepay-settings.php:90
1282
  msgid "White With Black Line"
1283
  msgstr ""
1284
 
1285
+ #: includes/gateways/settings/applepay-settings.php:91
1286
  msgid "White Button"
1287
  msgstr ""
1288
 
1289
+ #: includes/gateways/settings/applepay-settings.php:93
1290
  msgid "This is the style for all Apple Pay buttons presented on your store."
1291
  msgstr ""
1292
 
1293
+ #: includes/gateways/settings/applepay-settings.php:96
1294
  msgid "Checkout button type"
1295
  msgstr ""
1296
 
1297
+ #: includes/gateways/settings/applepay-settings.php:99
1298
+ #: includes/gateways/settings/applepay-settings.php:109
1299
+ #: includes/gateways/settings/applepay-settings.php:119
1300
  msgid "Standard Button"
1301
  msgstr ""
1302
 
1303
+ #: includes/gateways/settings/applepay-settings.php:100
1304
+ #: includes/gateways/settings/applepay-settings.php:110
1305
+ #: includes/gateways/settings/applepay-settings.php:120
1306
  msgid "Buy with Apple Pay"
1307
  msgstr ""
1308
 
1309
+ #: includes/gateways/settings/applepay-settings.php:106
1310
  msgid "Cart button type"
1311
  msgstr ""
1312
 
1313
+ #: includes/gateways/settings/applepay-settings.php:116
1314
  msgid "Product button type"
1315
  msgstr ""
1316
 
1317
+ #: includes/gateways/settings/cc-settings.php:9
1318
  msgid "If enabled, your site can accept credit card payments through Stripe."
1319
  msgstr ""
1320
 
1321
+ #: includes/gateways/settings/cc-settings.php:13
1322
+ msgid "%1$sTest cards%2$s"
1323
  msgstr ""
1324
 
1325
+ #: includes/gateways/settings/cc-settings.php:68
1326
  msgid "Allow Credit Card Save"
1327
  msgstr ""
1328
 
1329
+ #: includes/gateways/settings/cc-settings.php:70
1330
  msgid "If enabled, a checkbox will be available on the checkout page allowing your customers to save their credit card. The payment methods are stored securely in Stripe's vault and never touch your server. Note: if the cart contains a subscription, there will be no checkbox because the payment method will be saved automatically. There will also be no checkbox for guest checkout as a user must be logged in to save a payment method."
1331
  msgstr ""
1332
 
1333
+ #: includes/gateways/settings/cc-settings.php:73
1334
  msgid "Force 3D Secure"
1335
  msgstr ""
1336
 
1337
+ #: includes/gateways/settings/cc-settings.php:78
1338
+ msgid "Stripe internally determines when 3D secure should be presented based on their SCA engine. If <strong>Force 3D Secure</strong> is enabled, 3D Secure will be forced for ALL credit card transactions. In test mode 3D secure only shows for %1$s3DS Test Cards%2$s regardless of this setting."
1339
  msgstr ""
1340
 
1341
+ #: includes/gateways/settings/cc-settings.php:81
1342
  msgid "Generic Errors"
1343
  msgstr ""
1344
 
1345
+ #: includes/gateways/settings/cc-settings.php:86
1346
  msgid "If enabled, credit card errors will be generic when presented to the customer. Merchants may prefer to not provide details on why a card was not accepted for security purposes."
1347
  msgstr ""
1348
 
1349
+ #: includes/gateways/settings/cc-settings.php:108
1350
  msgid "Credit Card Form"
1351
  msgstr ""
1352
 
1353
+ #: includes/gateways/settings/cc-settings.php:111
1354
  msgid "Card Form"
1355
  msgstr ""
1356
 
1357
+ #: includes/gateways/settings/cc-settings.php:114
1358
  msgid "Stripe form"
1359
  msgstr ""
1360
 
1361
+ #: includes/gateways/settings/cc-settings.php:115
1362
  msgid "Custom form"
1363
  msgstr ""
1364
 
1365
+ #: includes/gateways/settings/cc-settings.php:118
1366
  msgid "The Stripe form option displays a CC form rendered by Stripe. It works well with most themes. The custom card forms are offered if you want more options on the CC form design."
1367
  msgstr ""
1368
 
1369
+ #: includes/gateways/settings/cc-settings.php:121
1370
  msgid "Custom Form"
1371
  msgstr ""
1372
 
1373
+ #: includes/gateways/settings/cc-settings.php:125
1374
  msgid "The design of the credit card form."
1375
  msgstr ""
1376
 
1377
+ #: includes/gateways/settings/cc-settings.php:130
1378
  msgid "Postal Code"
1379
  msgstr ""
1380
 
1381
+ #: includes/gateways/settings/cc-settings.php:133
1382
  msgid "If enabled, the CC form will show the postal code on the checkout page. If disabled, the billing field's postal code will be used. The postal code will show on the Add Payment Method page for security reasons."
1383
  msgstr ""
1384
 
1385
+ #: includes/gateways/settings/googlepay-settings.php:5
1386
  msgid "GPay Business Console"
1387
  msgstr ""
1388
 
1389
+ #: includes/gateways/settings/googlepay-settings.php:7
1390
  msgid "When test mode is enabled, Google Pay will work without a merchant ID, allowing you to capture the necessary screenshots the Google API team needs to approve your integration request."
1391
  msgstr ""
1392
 
1393
+ #: includes/gateways/settings/googlepay-settings.php:14
1394
+ msgid "If you don't want to request a Google Merchant ID, you can use the %1$sPayment Request Gateway%2$s which has a Google Pay integration through Stripe via the Chrome browser."
1395
  msgstr ""
1396
 
1397
+ #: includes/gateways/settings/googlepay-settings.php:27
1398
  msgid "If enabled, your site can accept Google Pay payments through Stripe."
1399
  msgstr ""
1400
 
1401
+ #: includes/gateways/settings/googlepay-settings.php:34
1402
  msgid "Dynamic Price"
1403
  msgstr ""
1404
 
1405
+ #: includes/gateways/settings/googlepay-settings.php:38
1406
  msgid "If enabled, the Google Payment sheet will show the order line items. You must have Google whitelist you for callback intents."
1407
  msgstr ""
1408
 
1409
+ #: includes/gateways/settings/googlepay-settings.php:42
1410
  msgid "Merchant ID"
1411
  msgstr ""
1412
 
1413
+ #: includes/gateways/settings/googlepay-settings.php:44
1414
  msgid "Your Google Merchant ID is given to you by the Google API team once you register for Google Pay. While testing in TEST mode you can leave this value blank and Google Pay will work."
1415
  msgstr ""
1416
 
1417
+ #: includes/gateways/settings/googlepay-settings.php:80
1418
  msgid "This option determines whether the customer's funds are capture immediately or authorized and can be captured at a later date."
1419
  msgstr ""
1420
 
1421
+ #: includes/gateways/settings/googlepay-settings.php:105
1422
  msgid "Merchant Name"
1423
  msgstr ""
1424
 
1425
+ #: includes/gateways/settings/googlepay-settings.php:107
1426
  msgid "The name of your business as it appears on the Google Pay payment sheet."
1427
  msgstr ""
1428
 
1429
+ #: includes/gateways/settings/googlepay-settings.php:111
1430
  msgid "Icon"
1431
  msgstr ""
1432
 
1433
+ #: includes/gateways/settings/googlepay-settings.php:114
1434
  msgid "With Outline"
1435
  msgstr ""
1436
 
1437
+ #: includes/gateways/settings/googlepay-settings.php:115
1438
  msgid "Standard"
1439
  msgstr ""
1440
 
1441
+ #: includes/gateways/settings/googlepay-settings.php:119
1442
  msgid "This is the icon style that appears next to the gateway on the checkout page. Google's API team typically requires the With Outline option on the checkout page for branding purposes."
1443
  msgstr ""
1444
 
1445
+ #: includes/gateways/settings/googlepay-settings.php:123
1446
  msgid "Button Options"
1447
  msgstr ""
1448
 
1449
+ #: includes/gateways/settings/googlepay-settings.php:126
1450
  msgid "Button Color"
1451
  msgstr ""
1452
 
1453
+ #: includes/gateways/settings/googlepay-settings.php:130
1454
  msgid "Black"
1455
  msgstr ""
1456
 
1457
+ #: includes/gateways/settings/googlepay-settings.php:131
1458
  msgid "White"
1459
  msgstr ""
1460
 
1461
+ #: includes/gateways/settings/googlepay-settings.php:134
1462
  msgid "The button color of the GPay button."
1463
  msgstr ""
1464
 
1465
+ #: includes/gateways/settings/googlepay-settings.php:137
1466
  msgid "Button Style"
1467
  msgstr ""
1468
 
1469
+ #: includes/gateways/settings/googlepay-settings.php:141
1470
  msgid "Long"
1471
  msgstr ""
1472
 
1473
+ #: includes/gateways/settings/googlepay-settings.php:142
1474
  msgid "Short"
1475
  msgstr ""
1476
 
1477
+ #: includes/gateways/settings/googlepay-settings.php:145
1478
  msgid "The button style of the GPay button."
1479
  msgstr ""
1480
 
1481
+ #: includes/gateways/settings/googlepay-settings.php:151
1482
  msgid "If you can't see the Google Pay button, try switching to a Chrome browser."
1483
  msgstr ""
1484
 
1485
+ #: includes/gateways/settings/payment-request-settings.php:5
1486
  msgid ""
1487
+ "The PaymentRequest gateway uses your customer's browser to render payment options like Google Pay and Microsoft Pay. You can either use the Google Pay gateway for example, or this gateway.\n"
1488
  "\t\t\t\t\t\tThe difference is this gateway uses Stripe's PaymentRequest Button rather than render a Google Pay specific button."
1489
  msgstr ""
1490
 
1491
+ #: includes/gateways/settings/payment-request-settings.php:26
1492
  msgid "Browser Payments"
1493
  msgstr ""
1494
 
1495
+ #: includes/gateways/settings/payment-request-settings.php:88
1496
  msgid "default"
1497
  msgstr ""
1498
 
1499
+ #: includes/gateways/settings/payment-request-settings.php:90
1500
  msgid "buy"
1501
  msgstr ""
1502
 
1503
+ #: includes/gateways/settings/payment-request-settings.php:94
1504
  msgid "This defines the type of button that will display."
1505
  msgstr ""
1506
 
1507
+ #: includes/gateways/settings/payment-request-settings.php:98
1508
  msgid "Theme"
1509
  msgstr ""
1510
 
1511
+ #: includes/gateways/settings/payment-request-settings.php:100
1512
  msgid "dark"
1513
  msgstr ""
1514
 
1515
+ #: includes/gateways/settings/payment-request-settings.php:101
1516
  msgid "light"
1517
  msgstr ""
1518
 
1519
+ #: includes/gateways/settings/payment-request-settings.php:102
1520
  msgid "light-outline"
1521
  msgstr ""
1522
 
1523
+ #: includes/gateways/settings/payment-request-settings.php:106
1524
  msgid "This defines the color scheme for the button."
1525
  msgstr ""
1526
 
1527
+ #: includes/gateways/settings/payment-request-settings.php:110
1528
  msgid "Height"
1529
  msgstr ""
1530
 
1531
+ #: includes/gateways/settings/payment-request-settings.php:113
1532
  msgid "The height of the button. Max height is 64"
1533
  msgstr ""
1534
 
1535
+ #: includes/tokens/class-wc-payment-token-stripe-ach.php:70
1536
+ #: includes/tokens/class-wc-payment-token-stripe-ach.php:75
1537
+ #: includes/tokens/class-wc-payment-token-stripe-cc.php:90
1538
  msgid "Type Ending In"
1539
  msgstr ""
1540
 
1541
+ #: includes/tokens/class-wc-payment-token-stripe-ach.php:72
1542
  msgid "{bank_name} ending in {last4}"
1543
  msgstr ""
1544
 
1545
+ #: includes/tokens/class-wc-payment-token-stripe-ach.php:77
1546
  msgid "{bank_name} **** {last4}"
1547
  msgstr ""
1548
 
1549
+ #: includes/tokens/class-wc-payment-token-stripe-cc.php:92
1550
  msgid "{brand} ending in {last4}"
1551
  msgstr ""
1552
 
1553
+ #: includes/tokens/class-wc-payment-token-stripe-cc.php:95
1554
  msgid "Type Masked Number"
1555
  msgstr ""
1556
 
1557
+ #: includes/tokens/class-wc-payment-token-stripe-cc.php:100
1558
  msgid "Type Dash Masked Number"
1559
  msgstr ""
1560
 
1561
+ #: includes/tokens/class-wc-payment-token-stripe-cc.php:105
1562
  msgid "Type Last 4"
1563
  msgstr ""
1564
 
1565
+ #: includes/tokens/class-wc-payment-token-stripe-cc.php:110
1566
  msgid "Type Dash & Last 4"
1567
  msgstr ""
1568
 
1569
+ #: includes/tokens/class-wc-payment-token-stripe-cc.php:115
1570
  msgid "Last Four"
1571
  msgstr ""
1572
 
1573
+ #: includes/tokens/class-wc-payment-token-stripe-cc.php:120
1574
  msgid "Card Type"
1575
  msgstr ""
1576
 
1577
+ #: includes/tokens/class-wc-payment-token-stripe-local-payment.php:30
1578
  msgid "Gateway Title"
1579
  msgstr ""
1580
 
1581
+ #: includes/updates/update-3.1.0.php:28
1582
+ #: includes/updates/update-3.1.0.php:55
 
 
 
 
1583
  msgid "Stripe For WooCommerce Update"
1584
  msgstr ""
1585
 
1586
+ #: includes/updates/update-3.1.0.php:30
1587
  msgid "Greetings from Payment Plugins,"
1588
  msgstr ""
1589
 
1590
+ #: includes/updates/update-3.1.0.php:31
1591
  msgid "At Stripe's request, we have updated Stripe for WooCommerce to use the new Stripe Connect integration. This new integration offers even more security. Stripe is requesting that all merchants switch."
1592
  msgstr ""
1593
 
1594
+ #: includes/updates/update-3.1.0.php:32
1595
+ msgid "Click %1$shere%2$s to be redirected to your Stripe API settings page then click the <strong>Click to Connect</strong> button."
1596
  msgstr ""
1597
 
1598
+ #: includes/updates/update-3.1.0.php:35
1599
  msgid "Kind Regards,"
1600
  msgstr ""
1601
 
1602
+ #: includes/wc-stripe-functions.php:808
1603
  msgid "Bootstrap form"
1604
  msgstr ""
1605
 
1606
+ #: includes/wc-stripe-functions.php:834
1607
  msgid "Simple form"
1608
  msgstr ""
1609
 
1610
+ #: includes/wc-stripe-functions.php:857
1611
  msgid "Minimalist form"
1612
  msgstr ""
1613
 
1614
+ #: includes/wc-stripe-functions.php:883
1615
  msgid "Inline Form"
1616
  msgstr ""
1617
 
1618
+ #: includes/wc-stripe-functions.php:905
1619
  msgid "Rounded Form"
1620
  msgstr ""
1621
 
1622
+ #: includes/wc-stripe-functions.php:1120
1623
  msgid "There was an error processing your credit card."
1624
  msgstr ""
1625
 
1626
+ #: includes/wc-stripe-functions.php:1121
1627
  msgid "Your card number is incomplete."
1628
  msgstr ""
1629
 
1630
+ #: includes/wc-stripe-functions.php:1122
1631
  msgid "The card number is incorrect. Check the card's number or use a different card."
1632
  msgstr ""
1633
 
1634
+ #: includes/wc-stripe-functions.php:1123
1635
  msgid "The card's security code is incorrect. Check the card's security code or use a different card."
1636
  msgstr ""
1637
 
1638
+ #: includes/wc-stripe-functions.php:1124
1639
  msgid "The card's ZIP code is incorrect. Check the card's ZIP code or use a different card."
1640
  msgstr ""
1641
 
1642
+ #: includes/wc-stripe-functions.php:1125
1643
+ #: includes/wc-stripe-functions.php:1130
1644
  msgid "The card number is invalid. Check the card details or use a different card."
1645
  msgstr ""
1646
 
1647
+ #: includes/wc-stripe-functions.php:1126
1648
  msgid "This value provided to the field contains characters that are unsupported by the field."
1649
  msgstr ""
1650
 
1651
+ #: includes/wc-stripe-functions.php:1127
1652
  msgid "The card's security code is invalid. Check the card's security code or use a different card."
1653
  msgstr ""
1654
 
1655
+ #: includes/wc-stripe-functions.php:1128
1656
  msgid "The card's expiration month is incorrect. Check the expiration date or use a different card."
1657
  msgstr ""
1658
 
1659
+ #: includes/wc-stripe-functions.php:1129
1660
  msgid "The card's expiration year is incorrect. Check the expiration date or use a different card."
1661
  msgstr ""
1662
 
1663
+ #: includes/wc-stripe-functions.php:1131
1664
  msgid "The card's address is incorrect. Check the card's address or use a different card."
1665
  msgstr ""
1666
 
1667
+ #: includes/wc-stripe-functions.php:1132
1668
  msgid "The card has expired. Check the expiration date or use a different card."
1669
  msgstr ""
1670
 
1671
+ #: includes/wc-stripe-functions.php:1133
1672
  msgid "The card has been declined."
1673
  msgstr ""
1674
 
1675
+ #: includes/wc-stripe-functions.php:1134
1676
  msgid "Your card's expiration year is in the past."
1677
  msgstr ""
1678
 
1679
+ #: includes/wc-stripe-functions.php:1135
1680
  msgid "The bank account number provided is invalid (e.g., missing digits). Bank account information varies from country to country. We recommend creating validations in your entry forms based on the bank account formats we provide."
1681
  msgstr ""
1682
 
1683
+ #: includes/wc-stripe-functions.php:1136
1684
  msgid "The specified amount is greater than the maximum amount allowed. Use a lower amount and try again."
1685
  msgstr ""
1686
 
1687
+ #: includes/wc-stripe-functions.php:1137
1688
  msgid "The specified amount is less than the minimum amount allowed. Use a higher amount and try again."
1689
  msgstr ""
1690
 
1691
+ #: includes/wc-stripe-functions.php:1138
1692
  msgid "The payment requires authentication to proceed. If your customer is off session, notify your customer to return to your application and complete the payment. If you provided the error_on_requires_action parameter, then your customer should try another card that does not require authentication."
1693
  msgstr ""
1694
 
1695
+ #: includes/wc-stripe-functions.php:1139
1696
  msgid "The transfer or payout could not be completed because the associated account does not have a sufficient balance available. Create a new transfer or payout using an amount less than or equal to the account's available balance."
1697
  msgstr ""
1698
 
1699
+ #: includes/wc-stripe-functions.php:1140
1700
  msgid "The bank account provided can not be used to charge, either because it is not verified yet or it is not supported."
1701
  msgstr ""
1702
 
1703
+ #: includes/wc-stripe-functions.php:1141
1704
  msgid "The bank account provided already exists on the specified Customer object. If the bank account should also be attached to a different customer, include the correct customer ID when making the request again."
1705
  msgstr ""
1706
 
1707
+ #: includes/wc-stripe-functions.php:1142
1708
  msgid "The bank account provided cannot be used for payouts. A different bank account must be used."
1709
  msgstr ""
1710
 
1711
+ #: includes/wc-stripe-functions.php:1143
1712
  msgid "Your Connect platform is attempting to share an unverified bank account with a connected account."
1713
  msgstr ""
1714
 
1715
+ #: includes/wc-stripe-functions.php:1144
1716
  msgid "The bank account cannot be verified, either because the microdeposit amounts provided do not match the actual amounts, or because verification has failed too many times."
1717
  msgstr ""
1718
 
1719
+ #: includes/wc-stripe-functions.php:1145
1720
  msgid "This card has been declined too many times. You can try to charge this card again after 24 hours. We suggest reaching out to your customer to make sure they have entered all of their information correctly and that there are no issues with their card."
1721
  msgstr ""
1722
 
1723
+ #: includes/wc-stripe-functions.php:1146
1724
  msgid "The charge you're attempting to capture has already been captured. Update the request with an uncaptured charge ID."
1725
  msgstr ""
1726
 
1727
+ #: includes/wc-stripe-functions.php:1147
1728
  msgid "The charge you're attempting to refund has already been refunded. Update the request to use the ID of a charge that has not been refunded."
1729
  msgstr ""
1730
 
1731
+ #: includes/wc-stripe-functions.php:1148
1732
  msgid "The charge you're attempting to refund has been charged back. Check the disputes documentation to learn how to respond to the dispute."
1733
  msgstr ""
1734
 
1735
+ #: includes/wc-stripe-functions.php:1149
1736
  msgid "This charge would cause you to exceed your rolling-window processing limit for this source type. Please retry the charge later, or contact us to request a higher processing limit."
1737
  msgstr ""
1738
 
1739
+ #: includes/wc-stripe-functions.php:1150
1740
  msgid "The charge cannot be captured as the authorization has expired. Auth and capture charges must be captured within seven days."
1741
  msgstr ""
1742
 
1743
+ #: includes/wc-stripe-functions.php:1151
1744
  msgid "One or more provided parameters was not allowed for the given operation on the Charge. Check our API reference or the returned error message to see which values were not correct for that Charge."
1745
  msgstr ""
1746
 
1747
+ #: includes/wc-stripe-functions.php:1152
1748
  msgid "The email address is invalid (e.g., not properly formatted). Check that the email address is properly formatted and only includes allowed characters."
1749
  msgstr ""
1750
 
1751
+ #: includes/wc-stripe-functions.php:1153
1752
  msgid "The idempotency key provided is currently being used in another request. This occurs if your integration is making duplicate requests simultaneously."
1753
  msgstr ""
1754
 
1755
+ #: includes/wc-stripe-functions.php:1154
1756
  msgid "The specified amount is invalid. The charge amount must be a positive integer in the smallest currency unit, and not exceed the minimum or maximum amount."
1757
  msgstr ""
1758
 
1759
+ #: includes/wc-stripe-functions.php:1155
1760
  msgid "The source cannot be used because it is not in the correct state (e.g., a charge request is trying to use a source with a pending, failed, or consumed source). Check the status of the source you are attempting to use."
1761
  msgstr ""
1762
 
1763
+ #: includes/wc-stripe-functions.php:1156
1764
  msgid "Both a customer and source ID have been provided, but the source has not been saved to the customer. To create a charge for a customer with a specified source, you must first save the card details."
1765
  msgstr ""
1766
 
1767
+ #: includes/wc-stripe-functions.php:1157
1768
  msgid "The ZIP code provided was incorrect."
1769
  msgstr ""
1770
 
1771
+ #: includes/wc-stripe-functions.php:1158
1772
  msgid "An error occurred while processing the card. Try again later or with a different payment method."
1773
  msgstr ""
1774
 
1775
+ #: includes/wc-stripe-functions.php:1159
1776
  msgid "The card does not support this type of purchase."
1777
  msgstr ""
1778
 
1779
+ #: includes/wc-stripe-functions.php:1160
1780
+ #: includes/wc-stripe-functions.php:1163
1781
+ #: includes/wc-stripe-functions.php:1165
1782
  msgid "The card has been declined for an unknown reason."
1783
  msgstr ""
1784
 
1785
+ #: includes/wc-stripe-functions.php:1161
1786
  msgid "The customer has exceeded the balance or credit limit available on their card."
1787
  msgstr ""
1788
 
1789
+ #: includes/wc-stripe-functions.php:1162
1790
  msgid "The card does not support the specified currency."
1791
  msgstr ""
1792
 
1793
+ #: includes/wc-stripe-functions.php:1164
1794
  msgid "The payment has been declined as Stripe suspects it is fraudulent."
1795
  msgstr ""
1796
 
1797
+ #: includes/wc-stripe-functions.php:1166
1798
  msgid "The PIN entered is incorrect. "
1799
  msgstr ""
1800
 
1801
+ #: includes/wc-stripe-functions.php:1167
1802
  msgid "The card has insufficient funds to complete the purchase."
1803
  msgstr ""
1804
 
1805
+ #: includes/wc-stripe-functions.php:1168
1806
  msgid "Please select a payment method before proceeding."
1807
  msgstr ""
1808
 
1809
+ #: includes/wc-stripe-functions.php:1169
1810
  msgid "Please enter your IBAN before proceeding."
1811
  msgstr ""
1812
 
1813
+ #: includes/wc-stripe-functions.php:1170
1814
  msgid "Please select a bank before proceeding"
1815
  msgstr ""
1816
 
1817
+ #: includes/wc-stripe-webhook-functions.php:81
1818
  msgid "Charge.succeeded webhook received. Payment has been completed."
1819
  msgstr ""
1820
 
1821
+ #: includes/wc-stripe-webhook-functions.php:119
1822
+ msgid "payment_intent.succeeded webhook received. Payment has been completed."
1823
  msgstr ""
1824
 
1825
  #: stripe-payments.php:17
1826
+ msgid "Your PHP version is %s but Stripe requires version 5.6+."
1827
  msgstr ""
1828
 
1829
  #: templates/cart/payment-methods.php:13
includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php CHANGED
@@ -1,268 +1,265 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe' )) {
5
- return;
6
- }
7
- /**
8
- * Local payment method classes should extend this abstract class
9
- *
10
- * @package Stripe/Abstract
11
- * @author Payment Plugins
12
- *
13
- */
14
- abstract class WC_Payment_Gateway_Stripe_Local_Payment extends WC_Payment_Gateway_Stripe {
15
-
16
- protected $tab_title = '';
17
-
18
- /**
19
- * Currencies this gateway accepts
20
- *
21
- * @var array
22
- */
23
- protected $currencies = [];
24
-
25
- protected $local_payment_type = '';
26
-
27
- public $countries = [];
28
-
29
- protected $local_payment_description = '';
30
-
31
- public function __construct() {
32
- $this->token_type = 'Stripe_Local';
33
- $this->template_name = 'local-payment.php';
34
- parent::__construct ();
35
- $this->settings[ 'method_format' ] = 'gateway_title';
36
- $this->settings[ 'charge_type' ] = 'capture';
37
- $this->settings[ 'order_status' ] = 'default';
38
- }
39
-
40
- public function hooks() {
41
- parent::hooks ();
42
- add_filter ( 'wc_stripe_local_gateway_tabs', [
43
- $this, 'local_gateway_tab'
44
- ] );
45
- remove_filter ( 'wc_stripe_settings_nav_tabs', array(
46
- $this, 'admin_nav_tab'
47
- ) );
48
- add_filter ( 'wc_stripe_local_gateways_tab', array(
49
- $this, 'admin_nav_tab'
50
- ) );
51
- add_action ( 'woocommerce_settings_checkout_stripe_local_gateways_' . $this->id, array(
52
- $this, 'admin_options'
53
- ) );
54
- add_action ( 'wc_stripe_settings_before_options_stripe_local_gateways_' . $this->id, array(
55
- $this, 'navigation_menu'
56
- ) );
57
- add_action ( 'woocommerce_update_options_checkout_stripe_local_gateways_' . $this->id, array(
58
- $this, 'process_admin_options'
59
- ) );
60
- }
61
-
62
- /**
63
- *
64
- * @param \Stripe\Source $source
65
- * @param WC_Order $order
66
- */
67
- public function get_source_redirect_url($source, $order) {
68
- return $source->redirect->url;
69
- }
70
-
71
- public function output_settings_nav() {
72
- parent::output_settings_nav ();
73
- include wc_stripe ()->plugin_path () . 'includes/admin/views/html-settings-local-payments-nav.php';
74
- }
75
-
76
- public function init_form_fields() {
77
- $this->form_fields = apply_filters ( 'wc_stripe_form_fields_' . $this->id, $this->get_local_payment_settings () );
78
- }
79
-
80
- public function init_supports() {
81
- $this->supports = [ 'tokenization', 'products',
82
- 'refunds'
83
- ];
84
- }
85
-
86
- public function process_payment($order_id) {
87
- $result = parent::process_payment ( $order_id );
88
-
89
- if (defined ( WC_Stripe_Constants::WOOCOMMERCE_STRIPE_ORDER_PAY ) && $result[ 'result' ] == 'success') {
90
- wp_send_json ( [ 'success' => true,
91
- 'redirect' => $result[ 'redirect' ]
92
- ], 200 );
93
- exit ();
94
- }
95
- return $result;
96
- }
97
-
98
- /**
99
- * Return an array of form fields for the gateway.
100
- *
101
- * @return array
102
- */
103
- public function get_local_payment_settings() {
104
- return [
105
- 'desc' => array( 'type' => 'description',
106
- 'description' => $this->get_payment_description ()
107
- ),
108
- 'enabled' => array(
109
- 'title' => __ ( 'Enabled', 'woo-stripe-payment' ),
110
- 'type' => 'checkbox',
111
- 'default' => 'no', 'value' => 'yes',
112
- 'desc_tip' => true,
113
- 'description' => sprintf ( __ ( 'If enabled, your site can accept %s payments through Stripe.', 'woo-stripe-payment' ), $this->get_method_title () )
114
- ),
115
- 'general_settings' => array(
116
- 'type' => 'title',
117
- 'title' => __ ( 'General Settings', 'woo-stripe-payment' )
118
- ),
119
- 'title_text' => array( 'type' => 'text',
120
- 'title' => __ ( 'Title', 'woo-stripe-payment' ),
121
- 'default' => $this->get_method_title (),
122
- 'desc_tip' => true,
123
- 'description' => sprintf ( __ ( 'Title of the %s gateway' ), $this->get_method_title () )
124
- ),
125
- 'description' => array(
126
- 'title' => __ ( 'Description', 'woo-stripe-payment' ),
127
- 'type' => 'text', 'default' => '',
128
- 'description' => __ ( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
129
- 'desc_tip' => true
130
- )
131
- ];
132
- }
133
-
134
- public function get_localized_params() {
135
- return array_merge_recursive ( parent::get_localized_params (), [
136
- 'local_payment_type' => $this->local_payment_type,
137
- 'return_url' => add_query_arg ( [
138
- '_payment_nonce' => wp_create_nonce ( 'local-payment' ),
139
- 'wc-stripe-local-gateway' => $this->id
140
- ], wc_get_checkout_url () ),
141
- 'element_params' => $this->get_element_params (),
142
- 'routes' => [
143
- 'order_pay' => wc_stripe ()->rest_api->checkout->rest_url ( 'order-pay' )
144
- ]
145
- ] );
146
- }
147
-
148
- public function get_element_params() {
149
- return [
150
- 'style' => [
151
- 'base' => [
152
- 'padding' => '10px 12px',
153
- 'color' => '#32325d',
154
- 'fontFamily' => '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',
155
- 'fontSmoothing' => 'antialiased',
156
- 'fontSize' => '16px',
157
- '::placeholder' => [
158
- 'color' => '#aab7c4'
159
- ]
160
- ],
161
- 'invalid' => [
162
- 'color' => '#fa755a'
163
- ]
164
- ]
165
- ];
166
- }
167
-
168
- /**
169
- *
170
- * @param WC_Order $order
171
- */
172
- public function get_source_args($order) {
173
- return [ 'type' => $this->local_payment_type,
174
- 'amount' => wc_stripe_add_number_precision ( $order->get_total (), $order->get_currency () ),
175
- 'currency' => $order->get_currency (),
176
- 'statement_descriptor' => sprintf ( __ ( 'Order %s', 'woo-stripe-payment' ), $order->get_order_number () ),
177
- 'owner' => [
178
- 'name' => $this->payment_object->get_name_from_order ( $order, 'billing' ),
179
- 'email' => $order->get_billing_email ()
180
- ],
181
- 'redirect' => [
182
- 'return_url' => $this->get_local_payment_return_url ( $order )
183
- ]
184
- ];
185
- }
186
-
187
- /**
188
- *
189
- * @param WC_Order $order
190
- * @return string
191
- */
192
- protected function get_local_payment_return_url($order) {
193
- global $wp;
194
- if (isset ( $wp->query_vars[ 'order-pay' ] )) {
195
- $url = $order->get_checkout_payment_url ();
196
- } else {
197
- $url = wc_get_checkout_url ();
198
- }
199
- return add_query_arg ( [
200
- '_payment_nonce' => wp_create_nonce ( 'local-payment' ),
201
- 'wc-stripe-local-gateway' => $this->id
202
- ], $url );
203
- }
204
-
205
- public function is_local_payment_available() {
206
- global $wp;
207
- if (isset ( $wp->query_vars[ 'order-pay' ] )) {
208
- $order = wc_get_order ( absint ( $wp->query_vars[ 'order-pay' ] ) );
209
- $currency = $order->get_currency ();
210
- $billing_country = $order->get_billing_country ();
211
- } else {
212
- $currency = get_woocommerce_currency ();
213
- $customer = WC ()->customer;
214
- $billing_country = $customer ? $customer->get_billing_country () : null;
215
- if (! $billing_country) {
216
- $billing_country = WC ()->countries->get_base_country ();
217
- }
218
- }
219
- if (empty ( $this->countries )) {
220
- return in_array ( $currency, $this->currencies );
221
- } else {
222
- return $billing_country && in_array ( $currency, $this->currencies ) && in_array ( $billing_country, $this->countries );
223
- }
224
- }
225
-
226
- public function get_payment_token($method_id, $method_details = []) {
227
- /**
228
- *
229
- * @var WC_Payment_Token_Stripe_Local $token
230
- */
231
- $token = parent::get_payment_token ( $method_id, $method_details );
232
- $token->set_gateway_title ( $this->title );
233
- return $token;
234
- }
235
-
236
- /**
237
- * Return a description for (for admin sections) describing the required currency & or billing country(s).
238
- *
239
- * @return string
240
- */
241
- protected function get_payment_description() {
242
- $desc = '';
243
- if ($this->currencies) {
244
- $desc .= sprintf ( __ ( 'Gateway will appear when store currency is <strong>%s</strong>', 'woo-stripe-payment' ), implode ( ', ', $this->currencies ) );
245
- }
246
- if ($this->countries) {
247
- $desc .= sprintf ( __ ( ' & billing country is <strong>%s</strong>', 'woo-stripe-payment' ), implode ( ', ', $this->countries ) );
248
- }
249
- return $desc;
250
- }
251
-
252
- /**
253
- * Return a description of the payment method.
254
- */
255
- public function get_local_payment_description() {
256
- return apply_filters ( 'wc_stripe_local_payment_description', $this->local_payment_description );
257
- }
258
-
259
- /**
260
- *
261
- * @since 3.1.3
262
- * @param string $text
263
- * @return string
264
- */
265
- public function get_order_button_text($text) {
266
- return apply_filters ( 'wc_stripe_order_button_text', $text, $this );
267
- }
268
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ * Local payment method classes should extend this abstract class
10
+ *
11
+ * @package Stripe/Abstract
12
+ * @author Payment Plugins
13
+ *
14
+ */
15
+ abstract class WC_Payment_Gateway_Stripe_Local_Payment extends WC_Payment_Gateway_Stripe {
16
+
17
+ protected $tab_title = '';
18
+
19
+ /**
20
+ * Currencies this gateway accepts
21
+ *get_source_args
22
+ * @var array
23
+ */
24
+ protected $currencies = array();
25
+
26
+ protected $local_payment_type = '';
27
+
28
+ public $countries = array();
29
+
30
+ protected $local_payment_description = '';
31
+
32
+ public function __construct() {
33
+ $this->token_type = 'Stripe_Local';
34
+ $this->template_name = 'local-payment.php';
35
+ parent::__construct();
36
+ $this->settings['method_format'] = 'gateway_title';
37
+ $this->settings['charge_type'] = 'capture';
38
+ $this->settings['order_status'] = 'default';
39
+ }
40
+
41
+ public function hooks() {
42
+ parent::hooks();
43
+ add_filter( 'wc_stripe_local_gateway_tabs', array( $this, 'local_gateway_tab' ) );
44
+ remove_filter( 'wc_stripe_settings_nav_tabs', array( $this, 'admin_nav_tab' ) );
45
+ add_filter( 'wc_stripe_local_gateways_tab', array( $this, 'admin_nav_tab' ) );
46
+ add_action( 'woocommerce_settings_checkout_stripe_local_gateways_' . $this->id, array( $this, 'admin_options' ) );
47
+ add_action( 'wc_stripe_settings_before_options_stripe_local_gateways_' . $this->id, array( $this, 'navigation_menu' ) );
48
+ add_action( 'woocommerce_update_options_checkout_stripe_local_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
49
+ }
50
+
51
+ /**
52
+ *
53
+ * @param \Stripe\Source $source
54
+ * @param WC_Order $order
55
+ */
56
+ public function get_source_redirect_url( $source, $order ) {
57
+ return $source->redirect->url;
58
+ }
59
+
60
+ public function output_settings_nav() {
61
+ parent::output_settings_nav();
62
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-settings-local-payments-nav.php';
63
+ }
64
+
65
+ public function init_form_fields() {
66
+ $this->form_fields = apply_filters( 'wc_stripe_form_fields_' . $this->id, $this->get_local_payment_settings() );
67
+ }
68
+
69
+ public function init_supports() {
70
+ $this->supports = array( 'tokenization', 'products', 'refunds' );
71
+ }
72
+
73
+ public function process_payment( $order_id ) {
74
+ $result = parent::process_payment( $order_id );
75
+
76
+ if ( defined( WC_Stripe_Constants::WOOCOMMERCE_STRIPE_ORDER_PAY ) && $result['result'] == 'success' ) {
77
+ wp_send_json(
78
+ array(
79
+ 'success' => true,
80
+ 'redirect' => $result['redirect'],
81
+ ),
82
+ 200
83
+ );
84
+ exit();
85
+ }
86
+ return $result;
87
+ }
88
+
89
+ /**
90
+ * Return an array of form fields for the gateway.
91
+ *
92
+ * @return array
93
+ */
94
+ public function get_local_payment_settings() {
95
+ return array(
96
+ 'desc' => array(
97
+ 'type' => 'description',
98
+ 'description' => $this->get_payment_description(),
99
+ ),
100
+ 'enabled' => array(
101
+ 'title' => __( 'Enabled', 'woo-stripe-payment' ),
102
+ 'type' => 'checkbox',
103
+ 'default' => 'no',
104
+ 'value' => 'yes',
105
+ 'desc_tip' => true,
106
+ 'description' => sprintf( __( 'If enabled, your site can accept %s payments through Stripe.', 'woo-stripe-payment' ), $this->get_method_title() ),
107
+ ),
108
+ 'general_settings' => array(
109
+ 'type' => 'title',
110
+ 'title' => __( 'General Settings', 'woo-stripe-payment' ),
111
+ ),
112
+ 'title_text' => array(
113
+ 'type' => 'text',
114
+ 'title' => __( 'Title', 'woo-stripe-payment' ),
115
+ 'default' => $this->get_method_title(),
116
+ 'desc_tip' => true,
117
+ 'description' => sprintf( __( 'Title of the %s gateway' ), $this->get_method_title() ),
118
+ ),
119
+ 'description' => array(
120
+ 'title' => __( 'Description', 'woo-stripe-payment' ),
121
+ 'type' => 'text',
122
+ 'default' => '',
123
+ 'description' => __( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
124
+ 'desc_tip' => true,
125
+ ),
126
+ );
127
+ }
128
+
129
+ public function get_localized_params() {
130
+ return array_merge_recursive(
131
+ parent::get_localized_params(),
132
+ array(
133
+ 'local_payment_type' => $this->local_payment_type,
134
+ 'return_url' => add_query_arg(
135
+ array(
136
+ '_payment_nonce' => wp_create_nonce( 'local-payment' ),
137
+ 'wc-stripe-local-gateway' => $this->id,
138
+ ),
139
+ wc_get_checkout_url()
140
+ ),
141
+ 'element_params' => $this->get_element_params(),
142
+ 'routes' => array( 'order_pay' => wc_stripe()->rest_api->checkout->rest_url( 'order-pay' ) ),
143
+ )
144
+ );
145
+ }
146
+
147
+ public function get_element_params() {
148
+ return array(
149
+ 'style' => array(
150
+ 'base' => array(
151
+ 'padding' => '10px 12px',
152
+ 'color' => '#32325d',
153
+ 'fontFamily' => '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',
154
+ 'fontSmoothing' => 'antialiased',
155
+ 'fontSize' => '16px',
156
+ '::placeholder' => array( 'color' => '#aab7c4' ),
157
+ ),
158
+ 'invalid' => array( 'color' => '#fa755a' ),
159
+ ),
160
+ );
161
+ }
162
+
163
+ /**
164
+ *
165
+ * @param WC_Order $order
166
+ */
167
+ public function get_source_args( $order ) {
168
+ return array(
169
+ 'type' => $this->local_payment_type,
170
+ 'amount' => wc_stripe_add_number_precision( $order->get_total(), $order->get_currency() ),
171
+ 'currency' => $order->get_currency(),
172
+ 'statement_descriptor' => sprintf( __( 'Order %s', 'woo-stripe-payment' ), $order->get_order_number() ),
173
+ 'owner' => array(
174
+ 'name' => $this->payment_object->get_name_from_order( $order, 'billing' ),
175
+ 'email' => $order->get_billing_email(),
176
+ ),
177
+ 'redirect' => array( 'return_url' => $this->get_local_payment_return_url( $order ) ),
178
+ );
179
+ }
180
+
181
+ /**
182
+ *
183
+ * @param WC_Order $order
184
+ * @return string
185
+ */
186
+ protected function get_local_payment_return_url( $order ) {
187
+ global $wp;
188
+ if ( isset( $wp->query_vars['order-pay'] ) ) {
189
+ $url = $order->get_checkout_payment_url();
190
+ } else {
191
+ $url = wc_get_checkout_url();
192
+ }
193
+ return add_query_arg(
194
+ array(
195
+ '_payment_nonce' => wp_create_nonce( 'local-payment' ),
196
+ 'wc-stripe-local-gateway' => $this->id,
197
+ ),
198
+ $url
199
+ );
200
+ }
201
+
202
+ public function is_local_payment_available() {
203
+ global $wp;
204
+ if ( isset( $wp->query_vars['order-pay'] ) ) {
205
+ $order = wc_get_order( absint( $wp->query_vars['order-pay'] ) );
206
+ $currency = $order->get_currency();
207
+ $billing_country = $order->get_billing_country();
208
+ } else {
209
+ $currency = get_woocommerce_currency();
210
+ $customer = WC()->customer;
211
+ $billing_country = $customer ? $customer->get_billing_country() : null;
212
+ if ( ! $billing_country ) {
213
+ $billing_country = WC()->countries->get_base_country();
214
+ }
215
+ }
216
+ if ( empty( $this->countries ) ) {
217
+ return in_array( $currency, $this->currencies );
218
+ } else {
219
+ return $billing_country && in_array( $currency, $this->currencies ) && in_array( $billing_country, $this->countries );
220
+ }
221
+ }
222
+
223
+ public function get_payment_token( $method_id, $method_details = array() ) {
224
+ /**
225
+ *
226
+ * @var WC_Payment_Token_Stripe_Local $token
227
+ */
228
+ $token = parent::get_payment_token( $method_id, $method_details );
229
+ $token->set_gateway_title( $this->title );
230
+ return $token;
231
+ }
232
+
233
+ /**
234
+ * Return a description for (for admin sections) describing the required currency & or billing country(s).
235
+ *
236
+ * @return string
237
+ */
238
+ protected function get_payment_description() {
239
+ $desc = '';
240
+ if ( $this->currencies ) {
241
+ $desc .= sprintf( __( 'Gateway will appear when store currency is <strong>%s</strong>', 'woo-stripe-payment' ), implode( ', ', $this->currencies ) );
242
+ }
243
+ if ( $this->countries ) {
244
+ $desc .= sprintf( __( ' & billing country is <strong>%s</strong>', 'woo-stripe-payment' ), implode( ', ', $this->countries ) );
245
+ }
246
+ return $desc;
247
+ }
248
+
249
+ /**
250
+ * Return a description of the payment method.
251
+ */
252
+ public function get_local_payment_description() {
253
+ return apply_filters( 'wc_stripe_local_payment_description', $this->local_payment_description );
254
+ }
255
+
256
+ /**
257
+ *
258
+ * @since 3.1.3
259
+ * @param string $text
260
+ * @return string
261
+ */
262
+ public function get_order_button_text( $text ) {
263
+ return apply_filters( 'wc_stripe_order_button_text', $text, $this );
264
+ }
265
+ }
 
 
 
includes/abstract/abstract-wc-payment-gateway-stripe.php CHANGED
@@ -1,1330 +1,1387 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway' )) {
5
- return;
6
- }
7
-
8
- require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-payment-intent.php' );
9
- require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-payment-charge.php' );
10
- require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-payment-charge-local.php' );
11
-
12
- require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/traits/wc-stripe-payment-traits.php' );
13
-
14
- /**
15
- *
16
- * @since 3.0.0
17
- * @author PaymentPlugins
18
- * @package Stripe/Abstract
19
- *
20
- */
21
- abstract class WC_Payment_Gateway_Stripe extends WC_Payment_Gateway {
22
-
23
- use WC_Stripe_Settings_Trait;
24
-
25
- /**
26
- *
27
- * @var WC_Stripe_Payment
28
- */
29
- public $payment_object;
30
-
31
- /**
32
- *
33
- * @var string
34
- */
35
- public $token_key;
36
-
37
- /**
38
- *
39
- * @var string
40
- */
41
- public $saved_method_key;
42
-
43
- /**
44
- *
45
- * @var string
46
- */
47
- public $payment_type_key;
48
-
49
- /**
50
- *
51
- * @var string
52
- */
53
- public $payment_intent_key;
54
-
55
- /**
56
- *
57
- * @var string
58
- */
59
- public $save_source_key;
60
-
61
- /**
62
- *
63
- * @var string
64
- */
65
- public $template_name;
66
-
67
- /**
68
- *
69
- * @var bool
70
- */
71
- protected $checkout_error = false;
72
-
73
- /**
74
- * Used to create an instance of a WC_Payment_Token
75
- *
76
- * @var string
77
- */
78
- protected $token_type;
79
-
80
- /**
81
- *
82
- * @var WC_Stripe_Gateway
83
- */
84
- protected $gateway;
85
-
86
- /**
87
- *
88
- * @var WP_Error
89
- */
90
- protected $wp_error;
91
-
92
- /**
93
- *
94
- * @var string
95
- */
96
- protected $payment_method_token = null;
97
-
98
- /**
99
- *
100
- * @var string
101
- */
102
- protected $new_source_token = null;
103
-
104
- /**
105
- * Is the payment method synchronous or asynchronous
106
- *
107
- * @var bool
108
- */
109
- public $synchronous = true;
110
-
111
- /**
112
- *
113
- * @var array
114
- */
115
- protected $post_payment_processes = [];
116
-
117
- /**
118
- *
119
- * @var bool
120
- */
121
- public $processing_payment = false;
122
-
123
- public function __construct() {
124
- $this->token_key = $this->id . '_token_key';
125
- $this->saved_method_key = $this->id . '_saved_method_key';
126
- $this->save_source_key = $this->id . '_save_source_key';
127
- $this->payment_type_key = $this->id . '_payment_type_key';
128
- $this->payment_intent_key = $this->id . '_payment_intent_key';
129
- $this->has_fields = true;
130
- $this->init_form_fields ();
131
- $this->init_settings ();
132
- $this->title = $this->get_option ( 'title_text' );
133
- $this->description = $this->get_option ( 'description' );
134
- $this->hooks ();
135
- $this->init_supports ();
136
- $this->gateway = WC_Stripe_Gateway::load ();
137
-
138
- $this->payment_object = $this->get_payment_object ();
139
- }
140
-
141
- public function hooks() {
142
- add_filter ( 'wc_stripe_settings_nav_tabs', array(
143
- $this, 'admin_nav_tab'
144
- ) );
145
- add_action ( 'woocommerce_settings_checkout_' . $this->id, [
146
- $this, 'enqueue_admin_scripts'
147
- ] );
148
- add_action ( 'woocommerce_update_options_payment_gateways_' . $this->id, [
149
- $this, 'process_admin_options'
150
- ] );
151
- add_filter ( 'woocommerce_payment_methods_list_item', [
152
- $this, 'payment_methods_list_item'
153
- ], 10, 2 );
154
- add_action ( 'wc_stripe_payment_token_deleted_' . $this->id, [
155
- $this, 'delete_payment_method'
156
- ], 10, 2 );
157
- add_filter ( 'woocommerce_subscription_payment_meta', [
158
- $this, 'subscription_payment_meta'
159
- ], 10, 2 );
160
- add_action ( 'woocommerce_scheduled_subscription_payment_' . $this->id, [
161
- $this, 'scheduled_subscription_payment'
162
- ], 10, 2 );
163
- if (! is_admin ()) {
164
- add_action ( 'woocommerce_subscriptions_pre_update_payment_method', [
165
- $this,
166
- 'subscriptions_pre_update_payment_method'
167
- ], 10, 3 );
168
- add_action ( 'woocommerce_subscription_payment_method_updated_to_' . $this->id, [
169
- $this,
170
- 'subscription_payment_method_updated'
171
- ] );
172
- }
173
- add_action ( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array(
174
- $this, 'process_pre_order_payment'
175
- ) );
176
- }
177
-
178
- public function init_supports() {
179
- $this->supports = array( 'tokenization', 'products',
180
- 'subscriptions', 'add_payment_method',
181
- 'subscription_cancellation',
182
- 'multiple_subscriptions',
183
- 'subscription_amount_changes',
184
- 'subscription_date_changes',
185
- 'default_credit_card_form', 'refunds',
186
- 'pre-orders',
187
- 'subscription_payment_method_change_admin',
188
- 'subscription_reactivation',
189
- 'subscription_suspension',
190
- 'subscription_payment_method_change_customer'
191
- );
192
- }
193
-
194
- public function init_form_fields() {
195
- $this->form_fields = include wc_stripe ()->plugin_path () . 'includes/gateways/settings/' . str_replace ( [
196
- 'stripe_', '_'
197
- ], [ '', '-'
198
- ], $this->id ) . '-settings.php';
199
- $this->form_fields = apply_filters ( 'wc_stripe_form_fields_' . $this->id, $this->form_fields );
200
- }
201
-
202
- public function get_method_formats() {
203
- $class_name = 'WC_Payment_Token_' . $this->token_type;
204
- if (class_exists ( $class_name )) {
205
- /**
206
- *
207
- * @var WC_Payment_Token_Stripe
208
- */
209
- $token = new $class_name ();
210
- return $token->get_formats ();
211
- }
212
- return array();
213
- }
214
-
215
- public function enqueue_admin_scripts() {}
216
-
217
- public function payment_fields() {
218
- $this->enqueue_frontend_scripts ();
219
- wc_stripe_token_field ( $this );
220
- wc_stripe_payment_intent_field ( $this );
221
- wc_stripe_get_template ( 'checkout/stripe-payment-method.php', array(
222
- 'gateway' => $this,
223
- 'tokens' => is_add_payment_method_page () ? null : $this->get_tokens ()
224
- ) );
225
- }
226
-
227
- /**
228
- * Output the product payment fields.
229
- */
230
- public function product_fields() {
231
- global $product;
232
- $this->enqueue_frontend_scripts ( 'product' );
233
- wc_stripe_token_field ( $this );
234
- wc_stripe_get_template ( 'product/' . $this->template_name, array(
235
- 'gateway' => $this, 'product' => $product
236
- ) );
237
- }
238
-
239
- public function cart_fields() {
240
- $this->enqueue_frontend_scripts ( 'cart' );
241
- wc_stripe_token_field ( $this );
242
- wc_stripe_get_template ( 'cart/' . $this->template_name, array(
243
- 'gateway' => $this
244
- ) );
245
- }
246
-
247
- /**
248
- * Enqueue scripts needed by the gateway on the frontend of the WC shop.
249
- *
250
- * @param WC_Stripe_Frontend_Scripts $scripts
251
- */
252
- public function enqueue_frontend_scripts($page = '') {
253
- global $wp;
254
- if ($page) {
255
- if ('product' === $page) {
256
- $this->enqueue_product_scripts ( wc_stripe ()->scripts () );
257
- } elseif ('cart' === $page) {
258
- $this->enqueue_cart_scripts ( wc_stripe ()->scripts () );
259
- } elseif ('checkout' === $page) {
260
- $this->enqueue_checkout_scripts ( wc_stripe ()->scripts () );
261
- } else {
262
- $this->enqueue_frontend_scripts ();
263
- }
264
- } else {
265
- if (is_add_payment_method_page ()) {
266
- $this->enqueue_add_payment_method_scripts ( wc_stripe ()->scripts () );
267
- }
268
- if (is_checkout ()) {
269
- $this->enqueue_checkout_scripts ( wc_stripe ()->scripts () );
270
- }
271
- if (is_cart ()) {
272
- $this->enqueue_cart_scripts ( wc_stripe ()->scripts () );
273
- }
274
- if (is_product ()) {
275
- $this->enqueue_product_scripts ( wc_stripe ()->scripts () );
276
- }
277
- }
278
- if (! empty ( wc_stripe ()->scripts ()->enqueued_scripts )) {
279
- wc_stripe ()->scripts ()->enqueue_script ( 'form-handler' );
280
- wp_enqueue_style ( wc_stripe ()->scripts ()->prefix . 'styles', wc_stripe ()->assets_url () . 'css/stripe.css', array(), wc_stripe ()->version () );
281
- }
282
- }
283
-
284
- /**
285
- * Enqueue scripts needed by the gateway on the checkout page.
286
- *
287
- * @param WC_Stripe_Frontend_Scripts $scripts
288
- */
289
- public function enqueue_checkout_scripts($scripts) {}
290
-
291
- /**
292
- * Enqueue scripts needed by the gateway on the add payment method page.
293
- *
294
- * @param WC_Stripe_Frontend_Scripts $scripts
295
- */
296
- public function enqueue_add_payment_method_scripts($scripts) {
297
- $this->enqueue_checkout_scripts ( $scripts );
298
- }
299
-
300
- /**
301
- * Enqueue scripts needed by the gateway on the cart page.
302
- *
303
- * @param WC_Stripe_Frontend_Scripts $scripts
304
- */
305
- public function enqueue_cart_scripts($scripts) {}
306
-
307
- /**
308
- * Enqueue scripts needed by the gateway on the product page.
309
- *
310
- * @param WC_Stripe_Frontend_Scripts $scripts
311
- */
312
- public function enqueue_product_scripts($scripts) {}
313
-
314
- /**
315
- *
316
- * {@inheritDoc}
317
- *
318
- * @see WC_Payment_Gateway::process_payment()
319
- */
320
- public function process_payment($order_id) {
321
- $order = wc_get_order ( $order_id );
322
-
323
- if ($this->is_change_payment_method_request ()) {
324
- return [ 'result' => 'success',
325
- 'redirect' => $order->get_view_order_url ()
326
- ];
327
- }
328
-
329
- do_action ( 'wc_stripe_before_process_payment', $order, $this->id );
330
-
331
- if (wc_notice_count ( 'error' ) > 0) {
332
- return $this->get_order_error ();
333
- }
334
- $this->processing_payment = true;
335
-
336
- if ($this->order_contains_pre_order ( $order ) && $this->pre_order_requires_tokenization ( $order )) {
337
- return $this->process_pre_order ( $order );
338
- }
339
-
340
- // if order total is zero, then save meta but don't process payment.
341
- if ($order->get_total () == 0) {
342
- return $this->process_zero_total_order ( $order );
343
- }
344
-
345
- $result = $this->payment_object->process_payment ( $order, $this );
346
-
347
- if (is_wp_error ( $result )) {
348
- wc_add_notice ( $this->is_active ( 'generic_error' ) ? $this->get_generic_error ( $result ) : $result->get_error_message (), 'error' );
349
- $order->update_status ( 'failed', sprintf ( __ ( 'Error processing payment. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message () ) );
350
- return $this->get_order_error ();
351
- }
352
-
353
- if ($result->complete_payment) {
354
- $this->save_order_meta ( $order, $result->charge );
355
- if ('pending' === $result->charge->status) {
356
- $order->update_status ( apply_filters ( 'wc_stripe_pending_charge_status', 'on-hold', $order, $this ), sprintf ( __ ( 'Charge %s is pending. Payment Method: %s. Payment will be completed once charge.succeeded webhook received from Stripe.', 'woo-stripe-payment' ), $order->get_transaction_id (), $order->get_payment_method_title () ) );
357
- } else {
358
- if ($result->charge->captured) {
359
- $order->payment_complete ( $result->charge->id );
360
- } else {
361
- $order_status = $this->get_option ( 'order_status' );
362
- $order->update_status ( apply_filters ( 'wc_stripe_authorized_order_status', 'default' === $order_status ? 'on-hold' : $order_status, $order, $this ) );
363
- }
364
- $order->add_order_note ( sprintf ( __ ( 'Order %s successful in Stripe. Charge: %s. Payment Method: %s', 'woo-stripe-payment' ), $result->charge->captured ? __ ( 'charge', 'woo-stripe-payment' ) : __ ( 'authorization', 'woo-stripe-payment' ), $order->get_transaction_id (), $order->get_payment_method_title () ) );
365
- }
366
-
367
- $this->trigger_post_payment_processes ( $order, $this );
368
-
369
- WC ()->cart->empty_cart ();
370
-
371
- return [ 'result' => 'success',
372
- 'redirect' => $order->get_checkout_order_received_url ()
373
- ];
374
- } else {
375
- return [ 'result' => 'success',
376
- 'redirect' => $result->redirect
377
- ];
378
- }
379
- }
380
-
381
- /**
382
- *
383
- * @return array
384
- */
385
- public function get_localized_params() {
386
- return array( 'gateway_id' => $this->id,
387
- 'api_key' => wc_stripe_get_publishable_key (),
388
- 'saved_method_selector' => '[name="' . $this->saved_method_key . '"]',
389
- 'token_selector' => '[name="' . $this->token_key . '"]',
390
- 'payment_intent_selector' => '[name="' . $this->payment_intent_key . '"]',
391
- 'messages' => array(
392
- 'terms' => __ ( 'Please read and accept the terms and conditions to proceed with your order.', 'woocommerce' )
393
- ),
394
- 'routes' => array(
395
- 'setup_intent' => wc_stripe ()->rest_api->payment_intent->rest_url ( 'setup-intent' ),
396
- 'sync_intent' => wc_stripe ()->rest_api->payment_intent->rest_url ( 'sync-payment-intent' ),
397
- 'add_to_cart' => wc_stripe ()->rest_api->cart->rest_url ( 'add-to-cart' ),
398
- 'cart_calculation' => wc_stripe ()->rest_api->cart->rest_url ( 'cart-calculation' ),
399
- 'shipping_method' => wc_stripe ()->rest_api->cart->rest_url ( 'shipping-method' ),
400
- 'shipping_address' => wc_stripe ()->rest_api->cart->rest_url ( 'shipping-address' ),
401
- 'checkout' => wc_stripe ()->rest_api->checkout->rest_url ( 'checkout' )
402
- ),
403
- 'rest_nonce' => wp_create_nonce ( 'wp_rest' ),
404
- 'needs_shipping' => $this->get_needs_shipping (),
405
- 'banner_enabled' => $this->banner_checkout_enabled (),
406
- 'currency' => get_woocommerce_currency (),
407
- 'total_label' => __ ( 'Total', 'woo-stripe-payment' ),
408
- 'country_code' => wc_get_base_location ()[ 'country' ]
409
- );
410
- }
411
-
412
- /**
413
- * Save the Stripe data to the order.
414
- *
415
- * @param WC_Order $order
416
- * @param \Stripe\Charge $charge
417
- */
418
- public function save_order_meta($order, $charge) {
419
- /**
420
- *
421
- * @var WC_Payment_Token_Stripe $token
422
- */
423
- $token = $this->get_payment_token ( $this->get_payment_method_from_charge ( $charge ), $charge->payment_method_details );
424
- $order->set_transaction_id ( $charge->id );
425
- $order->set_payment_method_title ( $token->get_payment_method_title () );
426
- $order->update_meta_data ( WC_Stripe_Constants::MODE, wc_stripe_mode () );
427
- $order->update_meta_data ( WC_Stripe_Constants::CHARGE_STATUS, $charge->status );
428
- $order->update_meta_data ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token () );
429
- $order->save ();
430
-
431
- // if WCS is active and there are subscriptions in the order, save meta data
432
- if (wcs_stripe_active () && wcs_order_contains_subscription ( $order )) {
433
- foreach ( wcs_get_subscriptions_for_order ( $order ) as $subscription ) {
434
- $subscription->set_transaction_id ( $charge->id );
435
- $subscription->set_payment_method_title ( $token->get_payment_method_title () );
436
- $subscription->update_meta_data ( WC_Stripe_Constants::MODE, wc_stripe_mode () );
437
- $subscription->update_meta_data ( WC_Stripe_Constants::CHARGE_STATUS, $charge->status );
438
- $subscription->update_meta_data ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token () );
439
- $subscription->update_meta_data ( WC_Stripe_Constants::CUSTOMER_ID, wc_stripe_get_customer_id ( $order->get_user_id () ) );
440
- $subscription->save ();
441
- }
442
- }
443
- }
444
-
445
- /**
446
- * Given a charge object, return the ID of the payment method used for the charge.
447
- *
448
- * @since 3.0.6
449
- * @param \Stripe\Charge $charge
450
- */
451
- public function get_payment_method_from_charge($charge) {
452
- return $this->payment_object->get_payment_method_from_charge ( $charge );
453
- }
454
-
455
- /**
456
- *
457
- * {@inheritDoc}
458
- *
459
- * @see WC_Payment_Gateway::add_payment_method()
460
- */
461
- public function add_payment_method() {
462
- $user_id = get_current_user_id ();
463
- try {
464
- if (! is_user_logged_in ()) {
465
- throw new Exception ( __ ( 'User must be logged in.', 'woo-stripe-payment' ) );
466
- }
467
-
468
- $customer_id = wc_stripe_get_customer_id ( $user_id );
469
-
470
- if (empty ( $customer_id )) {
471
- $customer_id = $this->create_customer ( $user_id );
472
- }
473
-
474
- $result = $this->create_payment_method ( $this->get_new_source_token (), $customer_id );
475
-
476
- if (is_wp_error ( $result )) {
477
- wc_add_notice ( sprintf ( __ ( 'Error saving your payment method. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message () ), 'error' );
478
- return array( 'result' => 'error'
479
- );
480
- }
481
- $result->set_user_id ( $user_id );
482
- $result->save ();
483
- WC_Payment_Tokens::set_users_default ( $user_id, $result->get_id () );
484
-
485
- do_action ( 'wc_stripe_add_payment_method_success', $result );
486
-
487
- return array( 'result' => 'success',
488
- 'redirect' => wc_get_account_endpoint_url ( 'payment-methods' )
489
- );
490
- } catch ( \Stripe\Error\Base $e ) {
491
- wc_add_notice ( sprintf ( __ ( 'Error saving payment method. Reason: %s', 'woo-stripe-payment' ), $e->getMessage () ), 'error' );
492
- return array( 'result' => 'error'
493
- );
494
- }
495
- }
496
-
497
- /**
498
- *
499
- * {@inheritDoc}
500
- *
501
- * @see WC_Payment_Gateway::process_refund()
502
- */
503
- public function process_refund($order_id, $amount = null, $reason = '') {
504
- $order = wc_get_order ( $order_id );
505
- $result = $this->payment_object->process_refund ( $order, $amount );
506
-
507
- if (! is_wp_error ( $result )) {
508
- $order->add_order_note ( sprintf ( __ ( 'Order refunded in Stripe. Amount: %s', 'woo-stripe-payment' ), wc_price ( $amount, array(
509
- 'currency' => $order->get_currency ()
510
- ) ) ) );
511
- }
512
- return $result;
513
- }
514
-
515
- /**
516
- * Captures the charge for the Stripe order.
517
- *
518
- * @param float $amount
519
- * @param WC_Order $order
520
- */
521
- public function capture_charge($amount, $order) {
522
- $result = $this->retrieve_charge ( $order->get_transaction_id (), wc_stripe_order_mode ( $order ) );
523
-
524
- if (is_wp_error ( $result )) {
525
- return;
526
- } else {
527
- if (! $result->captured) {
528
- $result = $this->payment_object->capture_charge ( $amount, $order );
529
-
530
- if (! is_wp_error ( $result )) {
531
- remove_action ( 'woocommerce_order_status_completed', 'wc_stripe_order_status_completed' );
532
- $order->payment_complete ();
533
- if ($amount != $order->get_total ()) {
534
- $order->set_total ( $amount );
535
- $order->save ();
536
- }
537
- $order->add_order_note ( sprintf ( __ ( 'Order amount captured in Stripe. Amount: %s', 'woo-stripe-payment' ), wc_price ( $amount, array(
538
- 'currency' => $order->get_currency ()
539
- ) ) ) );
540
- } else {
541
- $order->add_order_note ( sprintf ( __ ( 'Error capturing charge in Stripe. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message () ) );
542
- }
543
- }
544
- }
545
- return $result;
546
- }
547
-
548
- /**
549
- * Void the Stripe charge.
550
- *
551
- * @param WC_Order $order
552
- */
553
- public function void_charge($order) {
554
- // @3.1.1 - check added so errors aren't encountered if the order can't be voided
555
- if (! $this->payment_object->can_void_order ( $order )) {
556
- return;
557
- }
558
- $result = $this->payment_object->void_charge ( $order );
559
-
560
- if (is_wp_error ( $result )) {
561
- $order->add_order_note ( sprintf ( __ ( 'Error voiding charge. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message () ) );
562
- } else {
563
- $order->add_order_note ( __ ( 'Charge voided in Stripe.', 'woo-stripe-payment' ) );
564
- }
565
- }
566
-
567
- /**
568
- * Return the \Stripe\Charge object
569
- *
570
- * @param String $charge_id
571
- * @param String $mode
572
- * @return WP_Error|\Stripe\Charge
573
- */
574
- public function retrieve_charge($charge_id, $mode = '') {
575
- return $this->gateway->get_charge ( $charge_id, $mode );
576
- }
577
-
578
- /**
579
- *
580
- * @param string $method_id
581
- * @param \Stripe\Card|array $method_details
582
- */
583
- public function get_payment_token($method_id, $method_details = null) {
584
- $class_name = 'WC_Payment_Token_' . $this->token_type;
585
- if (class_exists ( $class_name )) {
586
- /**
587
- *
588
- * @var WC_Payment_Token_Stripe $token
589
- */
590
- $token = new $class_name ( '', $method_details );
591
- $token->set_token ( $method_id );
592
- $token->set_gateway_id ( $this->id );
593
- $token->set_format ( $this->get_option ( 'method_format' ) );
594
- $token->set_environment ( wc_stripe_mode () );
595
- if ($method_details) {
596
- $token->details_to_props ( $method_details );
597
- }
598
- return $token;
599
- }
600
- }
601
-
602
- /**
603
- * Return a failed order response.
604
- *
605
- * @return array
606
- */
607
- public function get_order_error() {
608
- wc_stripe_set_checkout_error ();
609
- return array(
610
- 'result' => WC_Stripe_Constants::FAILURE
611
- );
612
- }
613
-
614
- /**
615
- * Return the payment source the customer has chosen to use.
616
- * This can be a saved source
617
- * or a one time use source.
618
- */
619
- public function get_payment_source() {
620
- if ($this->use_saved_source ()) {
621
- return $this->get_saved_source_id ();
622
- } else {
623
- if ($this->payment_method_token) {
624
- return $this->payment_method_token;
625
- }
626
- return $this->get_new_source_token ();
627
- }
628
- }
629
-
630
- /**
631
- * Returns the payment method the customer wants to use.
632
- * This can be a saved payment method
633
- * or a new payment method.
634
- */
635
- public function get_payment_method_from_request() {
636
- return $this->get_payment_source ();
637
- }
638
-
639
- public function get_payment_intent_id() {
640
- return ! empty ( $_POST[ $this->payment_intent_key ] ) ? $_POST[ $this->payment_intent_key ] : '';
641
- }
642
-
643
- /**
644
- * Return true of the customer is using a saved payment method.
645
- */
646
- public function use_saved_source() {
647
- return ( ! empty ( $_POST[ $this->payment_type_key ] ) && $_POST[ $this->payment_type_key ] === 'saved' ) || $this->payment_method_token;
648
- }
649
-
650
- /**
651
- *
652
- * @deprecated
653
- *
654
- */
655
- public function get_new_source_id() {
656
- return $this->get_new_source_token ();
657
- }
658
-
659
- public function get_new_source_token() {
660
- return null != $this->new_source_token ? $this->new_source_token : ( ! empty ( $_POST[ $this->token_key ] ) ? $_POST[ $this->token_key ] : '' );
661
- }
662
-
663
- public function get_saved_source_id() {
664
- return ! empty ( $_POST[ $this->saved_method_key ] ) ? $_POST[ $this->saved_method_key ] : $this->payment_method_token;
665
- }
666
-
667
- /**
668
- * Create a customer in the stripe gateway.
669
- *
670
- * @param int $user_id
671
- */
672
- public function create_customer($user_id) {
673
- $customer = WC ()->customer;
674
- $customer_id = $this->gateway->create_customer ( array(
675
- 'email' => $customer->get_email (),
676
- 'name' => sprintf ( '%s %s', $customer->get_first_name (), $customer->get_last_name () ),
677
- 'phone' => $customer->get_billing_phone ()
678
- ) );
679
- if (! is_wp_error ( $customer )) {
680
- wc_stripe_save_customer ( $customer_id, $user_id );
681
- return $customer->id;
682
- } else {
683
- return $customer;
684
- }
685
- }
686
-
687
- /**
688
- * Creates a payment method in Stripe.
689
- *
690
- * @param string $id
691
- * payment method id
692
- * @param string $customer_id
693
- * WC Stripe customer ID
694
- * @return WC_Payment_Token_Stripe|WP_Error
695
- */
696
- public function create_payment_method($id, $customer_id) {
697
- $token = $this->get_payment_token ( $id );
698
- $token->set_customer_id ( $customer_id );
699
-
700
- $result = $token->save_payment_method ();
701
-
702
- if (is_wp_error ( $result )) {
703
- return $result;
704
- } else {
705
- $token->set_token ( $result->id );
706
- $token->details_to_props ( $result );
707
- return $token;
708
- }
709
- }
710
-
711
- /**
712
- *
713
- * @param array $item
714
- * @param WC_Payment_Token_Stripe_CC $payment_token
715
- */
716
- public function payment_methods_list_item($item, $payment_token) {
717
- if ($payment_token->get_type () === $this->token_type) {
718
- $item[ 'method' ][ 'last4' ] = $payment_token->get_last4 ();
719
- $item[ 'method' ][ 'brand' ] = ucfirst ( $payment_token->get_brand () );
720
- if ($payment_token->has_expiration ()) {
721
- $item[ 'expires' ] = sprintf ( '%s / %s', $payment_token->get_exp_month (), $payment_token->get_exp_year () );
722
- } else {
723
- $item[ 'expires' ] = __ ( 'n/a', 'woo-stripe-payment' );
724
- }
725
- $item[ 'wc_stripe_method' ] = true;
726
- }
727
- return $item;
728
- }
729
-
730
- /**
731
- *
732
- * @param string $token_id
733
- * @param WC_Payment_Token_Stripe $token
734
- */
735
- public function delete_payment_method($token_id, $token) {
736
- $token->delete_from_stripe ();
737
- }
738
-
739
- public function saved_payment_methods($tokens = array()) {
740
- wc_stripe_get_template ( 'payment-methods.php', array(
741
- 'tokens' => $tokens, 'gateway' => $this
742
- ) );
743
- }
744
-
745
- public function get_new_method_label() {
746
- return __ ( 'New Card', 'woo-stripe-payment' );
747
- }
748
-
749
- public function get_saved_methods_label() {
750
- return __ ( 'Saved Cards', 'woo-stripe-payment' );
751
- }
752
-
753
- /**
754
- * Return true if shipping is needed.
755
- * Shipping is based on things like if the cart or product needs shipping.
756
- *
757
- * @return bool
758
- */
759
- public function get_needs_shipping() {
760
- if (is_checkout () || is_cart ()) {
761
- global $wp;
762
- if (wcs_stripe_active () && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment) {
763
- return false;
764
- }
765
- // return false if this is the order pay page. Gateways that have payment sheets don't need
766
- // to make any changes to the order.
767
- if (! empty ( $wp->query_vars[ 'order-pay' ] )) {
768
- return false;
769
- }
770
- return WC ()->cart->needs_shipping ();
771
- }
772
- if (is_product ()) {
773
- global $product;
774
- return is_a ( $product, 'WC_Product' ) && $product->needs_shipping ();
775
- }
776
- }
777
-
778
- /**
779
- * Return true of the payment method should be saved.
780
- *
781
- * @param WC_Order $order
782
- * @return bool
783
- */
784
- public function should_save_payment_method($order) {
785
- if (! $this->use_saved_source ()) {
786
- if (wcs_stripe_active ()) {
787
- if (wcs_order_contains_subscription ( $order ) && $this->supports ( 'subscriptions' )) {
788
- return true;
789
- }
790
- if (wcs_cart_contains_renewal ()) {
791
- return true;
792
- }
793
- }
794
- if (! empty ( $_POST[ $this->save_source_key ] )) {
795
- return true;
796
- }
797
- }
798
- return false;
799
- }
800
-
801
- /**
802
- * Returns true if the save payment method checkbox can be displayed.
803
- *
804
- * @return boolean
805
- */
806
- public function show_save_source() {
807
- global $wp;
808
- if (wcs_stripe_active ()) {
809
- if (WC_Subscriptions_Cart::cart_contains_subscription ()) {
810
- return false;
811
- }
812
- if (WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment) {
813
- return false;
814
- }
815
- if (wcs_cart_contains_renewal ()) {
816
- return false;
817
- }
818
- }
819
- // @since 3.1.5
820
- if (wc_stripe_pre_orders_active () && WC_Pre_Orders_Cart::cart_contains_pre_order ()) {
821
- return ! WC_Pre_Orders_Product::product_is_charged_upon_release ( WC_Pre_Orders_Cart::get_pre_order_product () );
822
- }
823
- return is_user_logged_in () && is_checkout () && $this->is_active ( 'save_card_enabled' );
824
- }
825
-
826
- /**
827
- * Returns a formatted array of items for display in the payment gateway's payment sheet.
828
- *
829
- * @param bool $encode
830
- * @return []
831
- */
832
- public function get_display_items($encode = false) {}
833
-
834
- /**
835
- * Returns a formatted array of shipping methods for display in the payment gateway's
836
- * payment sheet.
837
- *
838
- * @param bool $encode
839
- * @return []
840
- */
841
- public function get_shipping_methods($encode = false) {}
842
-
843
- /**
844
- * Return true if product page checkout is enabled for this gateway
845
- *
846
- * @return bool
847
- */
848
- public function product_checkout_enabled() {
849
- return in_array ( 'product', $this->get_option ( 'payment_sections', [] ) );
850
- }
851
-
852
- /**
853
- * Return true if cart page checkout is enabled for this gateway
854
- *
855
- * @return bool
856
- */
857
- public function cart_checkout_enabled() {
858
- return in_array ( 'cart', $this->get_option ( 'payment_sections', [] ) );
859
- }
860
-
861
- /**
862
- * Return true if checkout page banner is enabled for this gateway
863
- *
864
- * @return bool
865
- */
866
- public function banner_checkout_enabled() {
867
- global $wp;
868
- return empty ( $wp->query_vars[ 'order-pay' ] ) && $this->supports ( 'wc_stripe_banner_checkout' ) && in_array ( 'checkout_banner', $this->get_option ( 'payment_sections', [] ) );
869
- }
870
-
871
- /**
872
- * Decorate the response with data specific to the gateway.
873
- *
874
- * @param [] $data
875
- */
876
- public function add_to_cart_response($data) {
877
- return $data;
878
- }
879
-
880
- /**
881
- * Decorate the update shipping method reponse with data.
882
- *
883
- * @param [] $data
884
- */
885
- public function get_update_shipping_method_response($data) {
886
- return $data;
887
- }
888
-
889
- /**
890
- * Decorate the update shipping address respond with data.
891
- *
892
- * @param [] $data
893
- */
894
- public function get_update_shipping_address_response($data) {
895
- return apply_filters ( 'wc_stripe_update_shipping_address_response', $data );
896
- }
897
-
898
- /**
899
- * Save the customer's payment method.
900
- * If the payment method has already been saved to the customer
901
- * then simply return true.
902
- *
903
- * @param string $id
904
- * @param WC_Order $order
905
- * @return WP_Error|bool
906
- */
907
- public function save_payment_method($id, $order) {
908
- $token = $this->create_payment_method ( $id, wc_stripe_get_customer_id ( $order->get_user_id () ) );
909
- if (is_wp_error ( $token )) {
910
- $this->wp_error = $token;
911
- $order->add_order_note ( sprintf ( __ ( 'Attemp to save payment method failed. Reason: %s', 'woo-stripe-payment' ), $token->get_error_message () ) );
912
- return $token;
913
- }
914
- $token->set_user_id ( $order->get_user_id () );
915
- $token->save ();
916
-
917
- // set token value so it can be used for other processes.
918
- $this->payment_method_token = $token->get_token ();
919
- return true;
920
- }
921
-
922
- /**
923
- * Set an error on the order.
924
- * This error is used on the frontend to alert customer's to a failed payment method save.
925
- *
926
- * @param WC_Order $order
927
- * @param WP_Error $error
928
- */
929
- public function set_payment_save_error($order, $error) {
930
- if (wcs_stripe_active () && wcs_order_contains_subscription ( $order )) {
931
- $message = __ ( 'We were not able to save your payment method. To prevent billing issues with your subscription, please add a payment method to the subscription.', 'woo-stripe-payment' );
932
- } else {
933
- $message = sprintf ( __ ( 'We were not able to save your payment method. Reason: %s', 'woo-stripe-payment' ), $error->get_error_message () );
934
- }
935
- $order->update_meta_data ( '_wc_stripe_order_error', $message );
936
- $order->save ();
937
- }
938
-
939
- /**
940
- *
941
- * @param string $token_id
942
- * @param int $user_id
943
- * @return null|WC_Payment_Token_Stripe_CC
944
- */
945
- public function get_token($token_id, $user_id) {
946
- $tokens = WC_Payment_Tokens::get_customer_tokens ( $user_id, $this->id );
947
- foreach ( $tokens as $token ) {
948
- if ($token_id === $token->get_token ()) {
949
- return $token;
950
- }
951
- }
952
- return null;
953
- }
954
-
955
- /**
956
- *
957
- * @param array $payment_meta
958
- * @param WC_Subscription $subscription
959
- */
960
- public function subscription_payment_meta($payment_meta, $subscription) {
961
- $payment_meta[ $this->id ] = array(
962
- 'post_meta' => array(
963
- WC_Stripe_Constants::PAYMENT_METHOD_TOKEN => array(
964
- 'value' => $this->get_order_meta_data ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $subscription ),
965
- 'label' => __ ( 'Payment Method Token', 'woo-stripe-payment' )
966
- )
967
- )
968
- );
969
- return $payment_meta;
970
- }
971
-
972
- /**
973
- *
974
- * @param float $amount
975
- * @param WC_Order $order
976
- */
977
- public function scheduled_subscription_payment($amount, $order) {
978
- $this->processing_payment = true;
979
-
980
- $result = $this->payment_object->scheduled_subscription_payment ( $amount, $order );
981
-
982
- if (is_wp_error ( $result )) {
983
- $order->update_status ( 'failed' );
984
- $order->add_order_note ( sprintf ( __ ( 'Recurring payment for order failed. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message () ) );
985
- return;
986
- }
987
-
988
- $this->save_order_meta ( $order, $result->charge );
989
-
990
- // set the payment method token that was used to process the renewal order.
991
- $this->payment_method_token = $order->get_meta ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN );
992
-
993
- if ($result->complete_payment) {
994
- if ($result->charge->captured) {
995
- $order->payment_complete ( $result->charge->id );
996
- $order->add_order_note ( sprintf ( __ ( 'Recurring payment captured in Stripe. Payment method: %s', 'woo-stripe-payment' ), $order->get_payment_method_title () ) );
997
- } else {
998
- $order->update_status ( apply_filters ( 'wc_stripe_authorized_renewal_order_status', 'on-hold', $order, $this ), sprintf ( __ ( 'Recurring payment authorized in Stripe. Payment method: %s', 'woo-stripe-payment' ), $order->get_payment_method_title () ) );
999
- }
1000
- } else {
1001
- $order->update_status ( 'pending', sprintf ( __ ( 'Customer must manually complete payment for payment method %s', 'woo-stripe-payment' ), $order->get_payment_method_title () ) );
1002
- }
1003
- }
1004
-
1005
- /**
1006
- *
1007
- * @param WC_Subscription $subscription
1008
- * @param string $new_payment_method
1009
- * @param string $old_payment_method
1010
- */
1011
- public function subscriptions_pre_update_payment_method($subscription, $new_payment_method, $old_payment_method) {
1012
- if ($new_payment_method === $this->id) {
1013
- // customer is using a new payment method so we need to save it.
1014
- if (! $this->use_saved_source ()) {
1015
- $result = $this->save_payment_method ( $this->get_new_source_token (), $subscription );
1016
- if (is_wp_error ( $result )) {
1017
- wc_add_notice ( sprintf ( __ ( 'Error saving payment method for subscription. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message () ), 'error' );
1018
- // redirect to change payment method page.
1019
- wp_safe_redirect ( $subscription->get_view_order_url () );
1020
- exit ();
1021
- }
1022
- } else {
1023
- if (! $this->payment_method_token) {
1024
- // set the payment method token so it can be used downstream.
1025
- $this->payment_method_token = $this->get_payment_source ();
1026
- }
1027
- }
1028
- }
1029
- }
1030
-
1031
- /**
1032
- * Update the subscription with the new meta data for the gateway.
1033
- * Save any new method the customer is trying to use.
1034
- *
1035
- * @param WC_Subscription $subscription
1036
- */
1037
- public function subscription_payment_method_updated($subscription) {
1038
- $token = $this->get_token ( $this->payment_method_token, $subscription->get_user_id () );
1039
-
1040
- // update the meta data needed by the gateway to process a subscription payment.
1041
- $subscription->update_meta_data ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $this->payment_method_token );
1042
- $subscription->set_payment_method_title ( $token->get_payment_method_title () );
1043
- $subscription->save ();
1044
- }
1045
-
1046
- /**
1047
- * Return true if this request is to change the payment method of a WC Subscription.
1048
- *
1049
- * @return bool
1050
- */
1051
- public function is_change_payment_method_request() {
1052
- return wcs_stripe_active () && did_action ( 'woocommerce_subscriptions_pre_update_payment_method' );
1053
- }
1054
-
1055
- /**
1056
- * Sets the ID of a payment token.
1057
- *
1058
- * @param string $id
1059
- */
1060
- public function set_payment_method_token($id) {
1061
- $this->payment_method_token = $id;
1062
- }
1063
-
1064
- public function set_new_source_token($token) {
1065
- $this->new_source_token = $token;
1066
- }
1067
-
1068
- /**
1069
- *
1070
- * @deprecated
1071
- *
1072
- * @param WC_Order $order
1073
- */
1074
- public function get_order_description($order) {
1075
- return sprintf ( __ ( 'Order %s from %s', 'woo-stripe-payment' ), $order->get_order_number (), get_bloginfo ( 'name' ) );
1076
- }
1077
-
1078
- /**
1079
- *
1080
- * @param WC_Order $order
1081
- */
1082
- public function process_zero_total_order($order) {
1083
- // save payment method if necessary
1084
- if ($this->should_save_payment_method ( $order )) {
1085
- $result = $this->save_payment_method ( $this->get_new_source_token (), $order );
1086
- if (is_wp_error ( $result )) {
1087
- wc_add_notice ( $result->get_error_message (), 'error' );
1088
- return $this->get_order_error ();
1089
- }
1090
- } else {
1091
- $this->payment_method_token = $this->get_saved_source_id ();
1092
- }
1093
- $this->save_zero_total_meta ( $order );
1094
- $order_status = $this->get_option ( 'order_status' );
1095
- if ('capture' === $this->get_option ( 'charge_type' )) {
1096
- $order->payment_complete ();
1097
- } else {
1098
- $order_status = $this->get_option ( 'order_status' );
1099
- $order->update_status ( apply_filters ( 'wc_stripe_authorized_order_status', 'default' === $order_status ? 'on-hold' : $order_status, $order, $this ) );
1100
- }
1101
- WC ()->cart->empty_cart ();
1102
- return array( 'result' => 'success',
1103
- 'redirect' => $order->get_checkout_order_received_url ()
1104
- );
1105
- }
1106
-
1107
- public function process_pre_order($order) {
1108
- // maybe save payment method
1109
- if (! $this->use_saved_source ()) {
1110
- $result = $this->save_payment_method ( $this->get_new_source_token (), $order );
1111
- if (is_wp_error ( $result )) {
1112
- wc_add_notice ( $result->get_error_message (), 'error' );
1113
- return $this->get_order_error ();
1114
- }
1115
- } else {
1116
- $this->payment_method_token = $this->get_saved_source_id ();
1117
- }
1118
- WC_Pre_Orders_Order::mark_order_as_pre_ordered ( $order );
1119
- $this->save_zero_total_meta ( $order );
1120
-
1121
- return array( 'result' => 'success',
1122
- 'redirect' => $order->get_checkout_order_received_url ()
1123
- );
1124
- }
1125
-
1126
- /**
1127
- *
1128
- * @param WC_Order $order
1129
- */
1130
- protected function save_zero_total_meta($order) {
1131
- $token = $this->get_token ( $this->payment_method_token, $order->get_user_id () );
1132
- $order->set_payment_method_title ( $token->get_payment_method_title () );
1133
- $order->update_meta_data ( WC_Stripe_Constants::MODE, wc_stripe_mode () );
1134
- $order->update_meta_data ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token () );
1135
- $order->update_meta_data ( WC_Stripe_Constants::CUSTOMER_ID, wc_stripe_get_customer_id ( $order->get_user_id () ) );
1136
- $order->save ();
1137
-
1138
- if (wcs_stripe_active () && wcs_order_contains_subscription ( $order )) {
1139
- foreach ( wcs_get_subscriptions_for_order ( $order ) as $subscription ) {
1140
- /**
1141
- *
1142
- * @var WC_Subscription $subscription
1143
- */
1144
- $subscription->set_payment_method_title ( $token->get_payment_method_title () );
1145
- $subscription->update_meta_data ( WC_Stripe_Constants::MODE, wc_stripe_mode () );
1146
- $subscription->update_meta_data ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token () );
1147
- $subscription->update_meta_data ( WC_Stripe_Constants::CUSTOMER_ID, wc_stripe_get_customer_id ( $order->get_user_id () ) );
1148
- $subscription->save ();
1149
- }
1150
- }
1151
- }
1152
-
1153
- /**
1154
- * Pre orders can't be mixed with regular products.
1155
- *
1156
- * @param WC_Order $order
1157
- */
1158
- protected function order_contains_pre_order($order) {
1159
- return wc_stripe_pre_orders_active () && WC_Pre_Orders_Order::order_contains_pre_order ( $order );
1160
- }
1161
-
1162
- /**
1163
- *
1164
- * @param WC_Order $order
1165
- * @return boolean
1166
- */
1167
- protected function pre_order_requires_tokenization($order) {
1168
- return WC_Pre_Orders_Order::order_requires_payment_tokenization ( $order );
1169
- }
1170
-
1171
- /**
1172
- * Sets a lock on the order.
1173
- * Default behavior is a 2 minute lock.
1174
- *
1175
- * @param WC_Order|int $order
1176
- */
1177
- public function set_order_lock($order) {
1178
- $order_id = ( is_object ( $order ) ? $order->get_id () : $order );
1179
- set_transient ( 'stripe_lock_order_' . $order_id, $order_id, apply_filters ( 'wc_stripe_set_order_lock', 2 * MINUTE_IN_SECONDS ) );
1180
- }
1181
-
1182
- /**
1183
- * Removes the lock on the order
1184
- *
1185
- * @param WC_Order|int $order
1186
- */
1187
- public function release_order_lock($order) {
1188
- delete_transient ( 'stripe_lock_order_' . ( is_object ( $order ) ? $order->get_id () : $order ) );
1189
- }
1190
-
1191
- /**
1192
- * Returns true of the order has been locked.
1193
- * If the lock exists and is greater than current time
1194
- * method returns true;
1195
- *
1196
- * @param WC_Order|int $order
1197
- */
1198
- public function has_order_lock($order) {
1199
- $lock = get_transient ( 'stripe_lock_order_' . ( is_object ( $order ) ? $order->get_id () : $order ) );
1200
- return $lock !== false;
1201
- }
1202
-
1203
- public function set_post_payment_process($callback) {
1204
- $this->post_payment_processes[] = $callback;
1205
- }
1206
-
1207
- /**
1208
- *
1209
- * @param WC_Order $order
1210
- * @param WC_Payment_Gateway_Stripe $gateway
1211
- */
1212
- public function trigger_post_payment_processes($order, $gateway) {
1213
- foreach ( $this->post_payment_processes as $callback ) {
1214
- call_user_func_array ( $callback, func_get_args () );
1215
- }
1216
- }
1217
-
1218
- public function validate_payment_sections_field($key, $value) {
1219
- if (empty ( $value )) {
1220
- $value = [];
1221
- }
1222
- return $value;
1223
- }
1224
-
1225
- /**
1226
- *
1227
- * @param WC_Order $order
1228
- */
1229
- public function process_pre_order_payment($order) {
1230
- $this->processing_payment = true;
1231
-
1232
- $result = $this->payment_object->process_pre_order_payment ( $order );
1233
-
1234
- if (is_wp_error ( $result )) {
1235
- $order->update_status ( 'failed' );
1236
- $order->add_order_note ( sprintf ( __ ( 'Pre-order payment for order failed. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message () ) );
1237
- } else {
1238
- if ($result->complete_payment) {
1239
-
1240
- $this->save_order_meta ( $order, $result->charge );
1241
-
1242
- if ($result->charge->captured) {
1243
- $order->payment_complete ( $result->charge->id );
1244
- $order->add_order_note ( sprintf ( __ ( 'Pre-order payment captured in Stripe. Payment method: %s', 'woo-stripe-payment' ), $order->get_payment_method_title () ) );
1245
- } else {
1246
- $order->update_status ( apply_filters ( 'wc_stripe_authorized_preorder_order_status', 'on-hold', $order, $this ), sprintf ( __ ( 'Pre-order payment authorized in Stripe. Payment method: %s', 'woo-stripe-payment' ), $order->get_payment_method_title () ) );
1247
- }
1248
- } else {
1249
- $order->update_status ( 'pending', sprintf ( __ ( 'Customer must manually complete payment for payment method %s', 'woo-stripe-payment' ), $order->get_payment_method_title () ) );
1250
- }
1251
- }
1252
- }
1253
-
1254
- /**
1255
- * Given a meta key, see if there is a value for that key in another plugin.
1256
- * This acts as a lazy conversion
1257
- * method for merchants that have switched to our plugin from other plugins.
1258
- *
1259
- * @since 3.1.0
1260
- * @param string $meta_key
1261
- * @param WC_Order $order
1262
- * @param string $context
1263
- */
1264
- public function get_order_meta_data($meta_key, $order, $context = 'view') {
1265
- $value = $order->get_meta ( $meta_key, true, $context );
1266
- // value is empty so check metadata from other plugins
1267
- if (empty ( $value )) {
1268
- $keys = [];
1269
- switch ($meta_key) {
1270
- case WC_Stripe_Constants::PAYMENT_METHOD_TOKEN :
1271
- $keys = [
1272
- WC_Stripe_Constants::SOURCE_ID
1273
- ];
1274
- break;
1275
- case WC_Stripe_Constants::CUSTOMER_ID :
1276
- $keys = [
1277
- WC_Stripe_Constants::STRIPE_CUSTOMER_ID
1278
- ];
1279
- break;
1280
- case WC_Stripe_Constants::PAYMENT_INTENT_ID :
1281
- $keys = [
1282
- WC_Stripe_Constants::STRIPE_INTENT_ID
1283
- ];
1284
- }
1285
- if ($keys) {
1286
- $meta_data = $order->get_meta_data ();
1287
- if ($meta_data) {
1288
- $keys = array_intersect ( wp_list_pluck ( $meta_data, 'key' ), $keys );
1289
- $array_keys = array_keys ( $keys );
1290
- if (! empty ( $array_keys )) {
1291
- $value = $meta_data[ current ( $array_keys ) ]->value;
1292
- update_post_meta ( $order->get_id (), $meta_key, $value );
1293
- }
1294
- }
1295
- }
1296
- }
1297
-
1298
- return $value;
1299
- }
1300
-
1301
- /**
1302
- * Gateways can override this method to add attributes to the Stripe object before it's
1303
- * sent to Stripe.
1304
- *
1305
- * @param array $args
1306
- * @param WC_Order $order
1307
- */
1308
- public function add_stripe_order_args(&$args, $order) {}
1309
-
1310
- /**
1311
- *
1312
- * @since 3.1.1
1313
- * @param WP_Error $result
1314
- */
1315
- public function get_generic_error($result = null) {
1316
- $messages = wc_stripe_get_error_messages ();
1317
- if (isset ( $messages[ "{$this->id}_generic" ] )) {
1318
- return $messages[ "{$this->id}_generic" ];
1319
- }
1320
- return null != $result ? $result->get_error_message () : __ ( 'Cannot process payment', 'woo-stripe-payment' );
1321
- }
1322
-
1323
- /**
1324
- *
1325
- * @since 3.1.2
1326
- */
1327
- private function get_payment_section_description() {
1328
- return sprintf ( __ ( '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.', 'woo-stripe-payment' ), $this->get_method_title () );
1329
- }
1330
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
5
+ return;
6
+ }
7
+
8
+ require_once( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-payment-intent.php' );
9
+ require_once( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-payment-charge.php' );
10
+ require_once( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-payment-charge-local.php' );
11
+
12
+ require_once( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/traits/wc-stripe-payment-traits.php' );
13
+
14
+ /**
15
+ *
16
+ * @since 3.0.0
17
+ * @author PaymentPlugins
18
+ * @package Stripe/Abstract
19
+ *
20
+ */
21
+ abstract class WC_Payment_Gateway_Stripe extends WC_Payment_Gateway {
22
+
23
+ use WC_Stripe_Settings_Trait;
24
+
25
+ /**
26
+ *
27
+ * @var WC_Stripe_Payment
28
+ */
29
+ public $payment_object;
30
+
31
+ /**
32
+ *
33
+ * @var string
34
+ */
35
+ public $token_key;
36
+
37
+ /**
38
+ *
39
+ * @var string
40
+ */
41
+ public $saved_method_key;
42
+
43
+ /**
44
+ *
45
+ * @var string
46
+ */
47
+ public $payment_type_key;
48
+
49
+ /**
50
+ *
51
+ * @var string
52
+ */
53
+ public $payment_intent_key;
54
+
55
+ /**
56
+ *
57
+ * @var string
58
+ */
59
+ public $save_source_key;
60
+
61
+ /**
62
+ *
63
+ * @var string
64
+ */
65
+ public $template_name;
66
+
67
+ /**
68
+ *
69
+ * @var bool
70
+ */
71
+ protected $checkout_error = false;
72
+
73
+ /**
74
+ * Used to create an instance of a WC_Payment_Token
75
+ *
76
+ * @var string
77
+ */
78
+ protected $token_type;
79
+
80
+ /**
81
+ *
82
+ * @var WC_Stripe_Gateway
83
+ */
84
+ protected $gateway;
85
+
86
+ /**
87
+ *
88
+ * @var WP_Error
89
+ */
90
+ protected $wp_error;
91
+
92
+ /**
93
+ *
94
+ * @var string
95
+ */
96
+ protected $payment_method_token = null;
97
+
98
+ /**
99
+ *
100
+ * @var string
101
+ */
102
+ protected $new_source_token = null;
103
+
104
+ /**
105
+ * Is the payment method synchronous or asynchronous
106
+ *
107
+ * @var bool
108
+ */
109
+ public $synchronous = true;
110
+
111
+ /**
112
+ *
113
+ * @var array
114
+ */
115
+ protected $post_payment_processes = array();
116
+
117
+ /**
118
+ *
119
+ * @var bool
120
+ */
121
+ public $processing_payment = false;
122
+
123
+ public function __construct() {
124
+ $this->token_key = $this->id . '_token_key';
125
+ $this->saved_method_key = $this->id . '_saved_method_key';
126
+ $this->save_source_key = $this->id . '_save_source_key';
127
+ $this->payment_type_key = $this->id . '_payment_type_key';
128
+ $this->payment_intent_key = $this->id . '_payment_intent_key';
129
+ $this->has_fields = true;
130
+ $this->init_form_fields();
131
+ $this->init_settings();
132
+ $this->title = $this->get_option( 'title_text' );
133
+ $this->description = $this->get_option( 'description' );
134
+ $this->hooks();
135
+ $this->init_supports();
136
+ $this->gateway = WC_Stripe_Gateway::load();
137
+
138
+ $this->payment_object = $this->get_payment_object();
139
+ }
140
+
141
+ public function hooks() {
142
+ add_filter( 'wc_stripe_settings_nav_tabs', array( $this, 'admin_nav_tab' ) );
143
+ add_action( 'woocommerce_settings_checkout_' . $this->id, array( $this, 'enqueue_admin_scripts' ) );
144
+ add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
145
+ add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'payment_methods_list_item' ), 10, 2 );
146
+ add_action( 'wc_stripe_payment_token_deleted_' . $this->id, array( $this, 'delete_payment_method' ), 10, 2 );
147
+ add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'subscription_payment_meta' ), 10, 2 );
148
+ add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
149
+ if ( ! is_admin() ) {
150
+ add_action( 'woocommerce_subscriptions_pre_update_payment_method', array( $this, 'subscriptions_pre_update_payment_method' ), 10, 3 );
151
+ add_action( 'woocommerce_subscription_payment_method_updated_to_' . $this->id, array( $this, 'subscription_payment_method_updated' ) );
152
+ }
153
+ add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_payment' ) );
154
+ }
155
+
156
+ public function init_supports() {
157
+ $this->supports = array(
158
+ 'tokenization',
159
+ 'products',
160
+ 'subscriptions',
161
+ 'add_payment_method',
162
+ 'subscription_cancellation',
163
+ 'multiple_subscriptions',
164
+ 'subscription_amount_changes',
165
+ 'subscription_date_changes',
166
+ 'default_credit_card_form',
167
+ 'refunds',
168
+ 'pre-orders',
169
+ 'subscription_payment_method_change_admin',
170
+ 'subscription_reactivation',
171
+ 'subscription_suspension',
172
+ 'subscription_payment_method_change_customer',
173
+ );
174
+ }
175
+
176
+ public function init_form_fields() {
177
+ $this->form_fields = include wc_stripe()->plugin_path() . 'includes/gateways/settings/' . str_replace( array( 'stripe_', '_' ), array(
178
+ '',
179
+ '-'
180
+ ), $this->id ) .
181
+ '-settings.php';
182
+ $this->form_fields = apply_filters( 'wc_stripe_form_fields_' . $this->id, $this->form_fields );
183
+ }
184
+
185
+ public function get_method_formats() {
186
+ $class_name = 'WC_Payment_Token_' . $this->token_type;
187
+ if ( class_exists( $class_name ) ) {
188
+ /**
189
+ *
190
+ * @var WC_Payment_Token_Stripe
191
+ */
192
+ $token = new $class_name();
193
+
194
+ return $token->get_formats();
195
+ }
196
+
197
+ return array();
198
+ }
199
+
200
+ public function enqueue_admin_scripts() {
201
+ }
202
+
203
+ public function payment_fields() {
204
+ $this->enqueue_frontend_scripts();
205
+ wc_stripe_token_field( $this );
206
+ wc_stripe_payment_intent_field( $this );
207
+ wc_stripe_get_template(
208
+ 'checkout/stripe-payment-method.php',
209
+ array(
210
+ 'gateway' => $this,
211
+ 'tokens' => is_add_payment_method_page() ? null : $this->get_tokens(),
212
+ )
213
+ );
214
+ }
215
+
216
+ /**
217
+ * Output the product payment fields.
218
+ */
219
+ public function product_fields() {
220
+ global $product;
221
+ $this->enqueue_frontend_scripts( 'product' );
222
+ wc_stripe_token_field( $this );
223
+ wc_stripe_get_template(
224
+ 'product/' . $this->template_name,
225
+ array(
226
+ 'gateway' => $this,
227
+ 'product' => $product,
228
+ )
229
+ );
230
+ }
231
+
232
+ public function cart_fields() {
233
+ $this->enqueue_frontend_scripts( 'cart' );
234
+ wc_stripe_token_field( $this );
235
+ wc_stripe_get_template( 'cart/' . $this->template_name, array( 'gateway' => $this ) );
236
+ }
237
+
238
+ /**
239
+ * Enqueue scripts needed by the gateway on the frontend of the WC shop.
240
+ *
241
+ * @param WC_Stripe_Frontend_Scripts $scripts
242
+ */
243
+ public function enqueue_frontend_scripts( $page = '' ) {
244
+ global $wp;
245
+ if ( $page ) {
246
+ if ( 'product' === $page ) {
247
+ $this->enqueue_product_scripts( wc_stripe()->scripts() );
248
+ } elseif ( 'cart' === $page ) {
249
+ $this->enqueue_cart_scripts( wc_stripe()->scripts() );
250
+ } elseif ( 'checkout' === $page ) {
251
+ $this->enqueue_checkout_scripts( wc_stripe()->scripts() );
252
+ } else {
253
+ $this->enqueue_frontend_scripts();
254
+ }
255
+ } else {
256
+ if ( is_add_payment_method_page() ) {
257
+ $this->enqueue_add_payment_method_scripts( wc_stripe()->scripts() );
258
+ }
259
+ if ( is_checkout() ) {
260
+ $this->enqueue_checkout_scripts( wc_stripe()->scripts() );
261
+ }
262
+ if ( is_cart() ) {
263
+ $this->enqueue_cart_scripts( wc_stripe()->scripts() );
264
+ }
265
+ if ( is_product() ) {
266
+ $this->enqueue_product_scripts( wc_stripe()->scripts() );
267
+ }
268
+ }
269
+ if ( ! empty( wc_stripe()->scripts()->enqueued_scripts ) ) {
270
+ wc_stripe()->scripts()->enqueue_script( 'form-handler' );
271
+ wp_enqueue_style( wc_stripe()->scripts()->prefix . 'styles', wc_stripe()->assets_url( 'css/stripe.css' ), array(), wc_stripe()->version() );
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Enqueue scripts needed by the gateway on the checkout page.
277
+ *
278
+ * @param WC_Stripe_Frontend_Scripts $scripts
279
+ */
280
+ public function enqueue_checkout_scripts( $scripts ) {
281
+ }
282
+
283
+ /**
284
+ * Enqueue scripts needed by the gateway on the add payment method page.
285
+ *
286
+ * @param WC_Stripe_Frontend_Scripts $scripts
287
+ */
288
+ public function enqueue_add_payment_method_scripts( $scripts ) {
289
+ $this->enqueue_checkout_scripts( $scripts );
290
+ }
291
+
292
+ /**
293
+ * Enqueue scripts needed by the gateway on the cart page.
294
+ *
295
+ * @param WC_Stripe_Frontend_Scripts $scripts
296
+ */
297
+ public function enqueue_cart_scripts( $scripts ) {
298
+ }
299
+
300
+ /**
301
+ * Enqueue scripts needed by the gateway on the product page.
302
+ *
303
+ * @param WC_Stripe_Frontend_Scripts $scripts
304
+ */
305
+ public function enqueue_product_scripts( $scripts ) {
306
+ }
307
+
308
+ /**
309
+ *
310
+ * {@inheritDoc}
311
+ *
312
+ * @see WC_Payment_Gateway::process_payment()
313
+ */
314
+ public function process_payment( $order_id ) {
315
+ $order = wc_get_order( $order_id );
316
+
317
+ if ( $this->is_change_payment_method_request() ) {
318
+ return array(
319
+ 'result' => 'success',
320
+ 'redirect' => $order->get_view_order_url(),
321
+ );
322
+ }
323
+
324
+ do_action( 'wc_stripe_before_process_payment', $order, $this->id );
325
+
326
+ if ( wc_notice_count( 'error' ) > 0 ) {
327
+ return $this->get_order_error();
328
+ }
329
+ $this->processing_payment = true;
330
+
331
+ if ( $this->order_contains_pre_order( $order ) && $this->pre_order_requires_tokenization( $order ) ) {
332
+ return $this->process_pre_order( $order );
333
+ }
334
+
335
+ // if order total is zero, then save meta but don't process payment.
336
+ if ( $order->get_total() == 0 ) {
337
+ return $this->process_zero_total_order( $order );
338
+ }
339
+
340
+ $result = $this->payment_object->process_payment( $order, $this );
341
+
342
+ if ( is_wp_error( $result ) ) {
343
+ wc_add_notice( $this->is_active( 'generic_error' ) ? $this->get_generic_error( $result ) : $result->get_error_message(), 'error' );
344
+ $order->update_status( 'failed', sprintf( __( 'Error processing payment. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ) );
345
+
346
+ return $this->get_order_error();
347
+ }
348
+
349
+ if ( $result->complete_payment ) {
350
+ $this->save_order_meta( $order, $result->charge );
351
+ if ( 'pending' === $result->charge->status ) {
352
+ $order->update_status( apply_filters( 'wc_stripe_pending_charge_status', 'on-hold', $order, $this ), sprintf( __( 'Charge %1$s is pending. Payment Method: %2$s. Payment will be completed once charge.succeeded webhook received from Stripe.', 'woo-stripe-payment' ), $order->get_transaction_id(), $order->get_payment_method_title() ) );
353
+ } else {
354
+ if ( $result->charge->captured ) {
355
+ $order->payment_complete( $result->charge->id );
356
+ } else {
357
+ $order_status = $this->get_option( 'order_status' );
358
+ $order->update_status( apply_filters( 'wc_stripe_authorized_order_status', 'default' === $order_status ? 'on-hold' : $order_status, $order, $this ) );
359
+ }
360
+ $order->add_order_note( sprintf( __( 'Order %1$s successful in Stripe. Charge: %2$s. Payment Method: %3$s', 'woo-stripe-payment' ), $result->charge->captured ? __( 'charge', 'woo-stripe-payment' ) : __( 'authorization', 'woo-stripe-payment' ), $order->get_transaction_id(), $order->get_payment_method_title() ) );
361
+ }
362
+
363
+ $this->trigger_post_payment_processes( $order, $this );
364
+
365
+ WC()->cart->empty_cart();
366
+
367
+ return array(
368
+ 'result' => 'success',
369
+ 'redirect' => $order->get_checkout_order_received_url(),
370
+ );
371
+ } else {
372
+ return array(
373
+ 'result' => 'success',
374
+ 'redirect' => $result->redirect,
375
+ );
376
+ }
377
+ }
378
+
379
+ /**
380
+ *
381
+ * @return array
382
+ */
383
+ public function get_localized_params() {
384
+ return array(
385
+ 'gateway_id' => $this->id,
386
+ 'api_key' => wc_stripe_get_publishable_key(),
387
+ 'saved_method_selector' => '[name="' . $this->saved_method_key . '"]',
388
+ 'token_selector' => '[name="' . $this->token_key . '"]',
389
+ 'payment_intent_selector' => '[name="' . $this->payment_intent_key . '"]',
390
+ 'messages' => array( 'terms' => __( 'Please read and accept the terms and conditions to proceed with your order.', 'woocommerce' ) ),
391
+ 'routes' => array(
392
+ 'setup_intent' => wc_stripe()->rest_api->payment_intent->rest_url( 'setup-intent' ),
393
+ 'sync_intent' => wc_stripe()->rest_api->payment_intent->rest_url( 'sync-payment-intent' ),
394
+ 'add_to_cart' => wc_stripe()->rest_api->cart->rest_url( 'add-to-cart' ),
395
+ 'cart_calculation' => wc_stripe()->rest_api->cart->rest_url( 'cart-calculation' ),
396
+ 'shipping_method' => wc_stripe()->rest_api->cart->rest_url( 'shipping-method' ),
397
+ 'shipping_address' => wc_stripe()->rest_api->cart->rest_url( 'shipping-address' ),
398
+ 'checkout' => wc_stripe()->rest_api->checkout->rest_url( 'checkout' ),
399
+ ),
400
+ 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
401
+ 'needs_shipping' => $this->get_needs_shipping(),
402
+ 'banner_enabled' => $this->banner_checkout_enabled(),
403
+ 'currency' => get_woocommerce_currency(),
404
+ 'total_label' => __( 'Total', 'woo-stripe-payment' ),
405
+ 'country_code' => wc_get_base_location()['country'],
406
+ );
407
+ }
408
+
409
+ /**
410
+ * Save the Stripe data to the order.
411
+ *
412
+ * @param WC_Order $order
413
+ * @param \Stripe\Charge $charge
414
+ */
415
+ public function save_order_meta( $order, $charge ) {
416
+ /**
417
+ *
418
+ * @var WC_Payment_Token_Stripe $token
419
+ */
420
+ $token = $this->get_payment_token( $this->get_payment_method_from_charge( $charge ), $charge->payment_method_details );
421
+ $order->set_transaction_id( $charge->id );
422
+ $order->set_payment_method_title( $token->get_payment_method_title() );
423
+ $order->update_meta_data( WC_Stripe_Constants::MODE, wc_stripe_mode() );
424
+ $order->update_meta_data( WC_Stripe_Constants::CHARGE_STATUS, $charge->status );
425
+ $order->update_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token() );
426
+ $order->save();
427
+
428
+ // if WCS is active and there are subscriptions in the order, save meta data
429
+ if ( wcs_stripe_active() && wcs_order_contains_subscription( $order ) ) {
430
+ foreach ( wcs_get_subscriptions_for_order( $order ) as $subscription ) {
431
+ $subscription->set_transaction_id( $charge->id );
432
+ $subscription->set_payment_method_title( $token->get_payment_method_title() );
433
+ $subscription->update_meta_data( WC_Stripe_Constants::MODE, wc_stripe_mode() );
434
+ $subscription->update_meta_data( WC_Stripe_Constants::CHARGE_STATUS, $charge->status );
435
+ $subscription->update_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token() );
436
+ $subscription->update_meta_data( WC_Stripe_Constants::CUSTOMER_ID, wc_stripe_get_customer_id( $order->get_user_id() ) );
437
+ $subscription->save();
438
+ }
439
+ }
440
+ }
441
+
442
+ /**
443
+ * Given a charge object, return the ID of the payment method used for the charge.
444
+ *
445
+ * @param \Stripe\Charge $charge
446
+ *
447
+ * @since 3.0.6
448
+ */
449
+ public function get_payment_method_from_charge( $charge ) {
450
+ return $this->payment_object->get_payment_method_from_charge( $charge );
451
+ }
452
+
453
+ /**
454
+ *
455
+ * {@inheritDoc}
456
+ *
457
+ * @see WC_Payment_Gateway::add_payment_method()
458
+ */
459
+ public function add_payment_method() {
460
+ $user_id = get_current_user_id();
461
+ try {
462
+ if ( ! is_user_logged_in() ) {
463
+ throw new Exception( __( 'User must be logged in.', 'woo-stripe-payment' ) );
464
+ }
465
+
466
+ $customer_id = wc_stripe_get_customer_id( $user_id );
467
+
468
+ if ( empty( $customer_id ) ) {
469
+ $customer_id = $this->create_customer( $user_id );
470
+ }
471
+
472
+ $result = $this->create_payment_method( $this->get_new_source_token(), $customer_id );
473
+
474
+ if ( is_wp_error( $result ) ) {
475
+ wc_add_notice( sprintf( __( 'Error saving your payment method. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ), 'error' );
476
+
477
+ return array( 'result' => 'error' );
478
+ }
479
+ $result->set_user_id( $user_id );
480
+ $result->save();
481
+ WC_Payment_Tokens::set_users_default( $user_id, $result->get_id() );
482
+
483
+ do_action( 'wc_stripe_add_payment_method_success', $result );
484
+
485
+ return array(
486
+ 'result' => 'success',
487
+ 'redirect' => wc_get_account_endpoint_url( 'payment-methods' ),
488
+ );
489
+ } catch ( \Stripe\Error\Base $e ) {
490
+ wc_add_notice( sprintf( __( 'Error saving payment method. Reason: %s', 'woo-stripe-payment' ), $e->getMessage() ), 'error' );
491
+
492
+ return array( 'result' => 'error' );
493
+ }
494
+ }
495
+
496
+ /**
497
+ *
498
+ * {@inheritDoc}
499
+ *
500
+ * @see WC_Payment_Gateway::process_refund()
501
+ */
502
+ public function process_refund( $order_id, $amount = null, $reason = '' ) {
503
+ $order = wc_get_order( $order_id );
504
+ $result = $this->payment_object->process_refund( $order, $amount );
505
+
506
+ if ( ! is_wp_error( $result ) ) {
507
+ $order->add_order_note(
508
+ sprintf(
509
+ __( 'Order refunded in Stripe. Amount: %s', 'woo-stripe-payment' ),
510
+ wc_price(
511
+ $amount,
512
+ array(
513
+ 'currency' => $order->get_currency(),
514
+ )
515
+ )
516
+ )
517
+ );
518
+ }
519
+
520
+ return $result;
521
+ }
522
+
523
+ /**
524
+ * Captures the charge for the Stripe order.
525
+ *
526
+ * @param float $amount
527
+ * @param WC_Order $order
528
+ */
529
+ public function capture_charge( $amount, $order ) {
530
+ $result = $this->gateway->charges->mode( wc_stripe_order_mode( $order ) )->retrieve( $order->get_transaction_id() );
531
+
532
+ if ( is_wp_error( $result ) ) {
533
+ return;
534
+ } else {
535
+ if ( ! $result->captured ) {
536
+ $result = $this->payment_object->capture_charge( $amount, $order );
537
+
538
+ if ( ! is_wp_error( $result ) ) {
539
+ remove_action( 'woocommerce_order_status_completed', 'wc_stripe_order_status_completed' );
540
+ $order->payment_complete();
541
+ if ( $amount != $order->get_total() ) {
542
+ $order->set_total( $amount );
543
+ $order->save();
544
+ }
545
+ $order->add_order_note(
546
+ sprintf(
547
+ __( 'Order amount captured in Stripe. Amount: %s', 'woo-stripe-payment' ),
548
+ wc_price(
549
+ $amount,
550
+ array(
551
+ 'currency' => $order->get_currency(),
552
+ )
553
+ )
554
+ )
555
+ );
556
+ } else {
557
+ $order->add_order_note( sprintf( __( 'Error capturing charge in Stripe. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ) );
558
+ }
559
+ }
560
+ }
561
+
562
+ return $result;
563
+ }
564
+
565
+ /**
566
+ * Void the Stripe charge.
567
+ *
568
+ * @param WC_Order $order
569
+ */
570
+ public function void_charge( $order ) {
571
+ // @3.1.1 - check added so errors aren't encountered if the order can't be voided
572
+ if ( ! $this->payment_object->can_void_order( $order ) ) {
573
+ return;
574
+ }
575
+ $result = $this->payment_object->void_charge( $order );
576
+
577
+ if ( is_wp_error( $result ) ) {
578
+ $order->add_order_note( sprintf( __( 'Error voiding charge. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ) );
579
+ } else {
580
+ $order->add_order_note( __( 'Charge voided in Stripe.', 'woo-stripe-payment' ) );
581
+ }
582
+ }
583
+
584
+ /**
585
+ * Return the \Stripe\Charge object
586
+ *
587
+ * @param String $charge_id
588
+ * @param String $mode
589
+ *
590
+ * @return WP_Error|\Stripe\Charge
591
+ */
592
+ public function retrieve_charge( $charge_id, $mode = '' ) {
593
+ return $this->gateway->charges->mode( $mode )->retrieve( $charge_id );
594
+ }
595
+
596
+ /**
597
+ *
598
+ * @param string $method_id
599
+ * @param \Stripe\Card|array $method_details
600
+ */
601
+ public function get_payment_token( $method_id, $method_details = null ) {
602
+ $class_name = 'WC_Payment_Token_' . $this->token_type;
603
+ if ( class_exists( $class_name ) ) {
604
+ /**
605
+ *
606
+ * @var WC_Payment_Token_Stripe $token
607
+ */
608
+ $token = new $class_name( '', $method_details );
609
+ $token->set_token( $method_id );
610
+ $token->set_gateway_id( $this->id );
611
+ $token->set_format( $this->get_option( 'method_format' ) );
612
+ $token->set_environment( wc_stripe_mode() );
613
+ if ( $method_details ) {
614
+ $token->details_to_props( $method_details );
615
+ }
616
+
617
+ return $token;
618
+ }
619
+ }
620
+
621
+ /**
622
+ * Return a failed order response.
623
+ *
624
+ * @return array
625
+ */
626
+ public function get_order_error() {
627
+ wc_stripe_set_checkout_error();
628
+
629
+ return array( 'result' => WC_Stripe_Constants::FAILURE );
630
+ }
631
+
632
+ /**
633
+ * Return the payment source the customer has chosen to use.
634
+ * This can be a saved source
635
+ * or a one time use source.
636
+ */
637
+ public function get_payment_source() {
638
+ if ( $this->use_saved_source() ) {
639
+ return $this->get_saved_source_id();
640
+ } else {
641
+ if ( $this->payment_method_token ) {
642
+ return $this->payment_method_token;
643
+ }
644
+
645
+ return $this->get_new_source_token();
646
+ }
647
+ }
648
+
649
+ /**
650
+ * Returns the payment method the customer wants to use.
651
+ * This can be a saved payment method
652
+ * or a new payment method.
653
+ */
654
+ public function get_payment_method_from_request() {
655
+ return $this->get_payment_source();
656
+ }
657
+
658
+ public function get_payment_intent_id() {
659
+ return ! empty( $_POST[ $this->payment_intent_key ] ) ? $_POST[ $this->payment_intent_key ] : '';
660
+ }
661
+
662
+ /**
663
+ * Return true of the customer is using a saved payment method.
664
+ */
665
+ public function use_saved_source() {
666
+ return ( ! empty( $_POST[ $this->payment_type_key ] ) && $_POST[ $this->payment_type_key ] === 'saved' ) || $this->payment_method_token;
667
+ }
668
+
669
+ /**
670
+ *
671
+ * @deprecated
672
+ *
673
+ */
674
+ public function get_new_source_id() {
675
+ return $this->get_new_source_token();
676
+ }
677
+
678
+ public function get_new_source_token() {
679
+ return null != $this->new_source_token ? $this->new_source_token : ( ! empty( $_POST[ $this->token_key ] ) ? $_POST[ $this->token_key ] : '' );
680
+ }
681
+
682
+ public function get_saved_source_id() {
683
+ return ! empty( $_POST[ $this->saved_method_key ] ) ? $_POST[ $this->saved_method_key ] : $this->payment_method_token;
684
+ }
685
+
686
+ /**
687
+ * Create a customer in the stripe gateway.
688
+ *
689
+ * @param int $user_id
690
+ */
691
+ public function create_customer( $user_id ) {
692
+ $customer = WC()->customer;
693
+ $response = $this->gateway->customers->create(
694
+ apply_filters( 'wc_stripe_customer_args', array(
695
+ 'email' => $customer->get_email(),
696
+ 'name' => sprintf( '%s %s', $customer->get_first_name(), $customer->get_last_name() ),
697
+ 'phone' => $customer->get_billing_phone(),
698
+ 'metadata' => array(
699
+ 'user_id' => $customer->get_id(),
700
+ 'username' => $customer->get_username(),
701
+ 'website' => get_site_url(),
702
+ ),
703
+ ) )
704
+ );
705
+ if ( ! is_wp_error( $response ) ) {
706
+ wc_stripe_save_customer( $response->id, $user_id );
707
+ }
708
+
709
+ return $customer;
710
+ }
711
+
712
+ /**
713
+ * Creates a payment method in Stripe.
714
+ *
715
+ * @param string $id
716
+ * payment method id
717
+ * @param string $customer_id
718
+ * WC Stripe customer ID
719
+ *
720
+ * @return WC_Payment_Token_Stripe|WP_Error
721
+ */
722
+ public function create_payment_method( $id, $customer_id ) {
723
+ $token = $this->get_payment_token( $id );
724
+ $token->set_customer_id( $customer_id );
725
+
726
+ $result = $token->save_payment_method();
727
+
728
+ if ( is_wp_error( $result ) ) {
729
+ return $result;
730
+ } else {
731
+ $token->set_token( $result->id );
732
+ $token->details_to_props( $result );
733
+
734
+ return $token;
735
+ }
736
+ }
737
+
738
+ /**
739
+ *
740
+ * @param array $item
741
+ * @param WC_Payment_Token_Stripe_CC $payment_token
742
+ */
743
+ public function payment_methods_list_item( $item, $payment_token ) {
744
+ if ( $payment_token->get_type() === $this->token_type ) {
745
+ $item['method']['last4'] = $payment_token->get_last4();
746
+ $item['method']['brand'] = ucfirst( $payment_token->get_brand() );
747
+ if ( $payment_token->has_expiration() ) {
748
+ $item['expires'] = sprintf( '%s / %s', $payment_token->get_exp_month(), $payment_token->get_exp_year() );
749
+ } else {
750
+ $item['expires'] = __( 'n/a', 'woo-stripe-payment' );
751
+ }
752
+ $item['wc_stripe_method'] = true;
753
+ }
754
+
755
+ return $item;
756
+ }
757
+
758
+ /**
759
+ *
760
+ * @param string $token_id
761
+ * @param WC_Payment_Token_Stripe $token
762
+ */
763
+ public function delete_payment_method( $token_id, $token ) {
764
+ $token->delete_from_stripe();
765
+ }
766
+
767
+ public function saved_payment_methods( $tokens = array() ) {
768
+ wc_stripe_get_template(
769
+ 'payment-methods.php',
770
+ array(
771
+ 'tokens' => $tokens,
772
+ 'gateway' => $this,
773
+ )
774
+ );
775
+ }
776
+
777
+ public function get_new_method_label() {
778
+ return __( 'New Card', 'woo-stripe-payment' );
779
+ }
780
+
781
+ public function get_saved_methods_label() {
782
+ return __( 'Saved Cards', 'woo-stripe-payment' );
783
+ }
784
+
785
+ /**
786
+ * Return true if shipping is needed.
787
+ * Shipping is based on things like if the cart or product needs shipping.
788
+ *
789
+ * @return bool
790
+ */
791
+ public function get_needs_shipping() {
792
+ if ( is_checkout() || is_cart() ) {
793
+ global $wp;
794
+ if ( wcs_stripe_active() && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment ) {
795
+ return false;
796
+ }
797
+ // return false if this is the order pay page. Gateways that have payment sheets don't need
798
+ // to make any changes to the order.
799
+ if ( ! empty( $wp->query_vars['order-pay'] ) ) {
800
+ return false;
801
+ }
802
+
803
+ return WC()->cart->needs_shipping();
804
+ }
805
+ if ( is_product() ) {
806
+ global $product;
807
+
808
+ return is_a( $product, 'WC_Product' ) && $product->needs_shipping();
809
+ }
810
+ }
811
+
812
+ /**
813
+ * Return true of the payment method should be saved.
814
+ *
815
+ * @param WC_Order $order
816
+ *
817
+ * @return bool
818
+ */
819
+ public function should_save_payment_method( $order ) {
820
+ if ( ! $this->use_saved_source() ) {
821
+ if ( wcs_stripe_active() ) {
822
+ if ( wcs_order_contains_subscription( $order ) && $this->supports( 'subscriptions' ) ) {
823
+ return true;
824
+ }
825
+ if ( wcs_cart_contains_renewal() ) {
826
+ return true;
827
+ }
828
+ }
829
+ if ( ! empty( $_POST[ $this->save_source_key ] ) ) {
830
+ return true;
831
+ }
832
+ }
833
+
834
+ return false;
835
+ }
836
+
837
+ /**
838
+ * Returns true if the save payment method checkbox can be displayed.
839
+ *
840
+ * @return boolean
841
+ */
842
+ public function show_save_source() {
843
+ global $wp;
844
+ if ( wcs_stripe_active() ) {
845
+ if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
846
+ return false;
847
+ }
848
+ if ( WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment ) {
849
+ return false;
850
+ }
851
+ if ( wcs_cart_contains_renewal() ) {
852
+ return false;
853
+ }
854
+ }
855
+ // @since 3.1.5
856
+ if ( wc_stripe_pre_orders_active() && WC_Pre_Orders_Cart::cart_contains_pre_order() ) {
857
+ return ! WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() );
858
+ }
859
+
860
+ return is_user_logged_in() && is_checkout() && $this->is_active( 'save_card_enabled' );
861
+ }
862
+
863
+ /**
864
+ * Returns a formatted array of items for display in the payment gateway's payment sheet.
865
+ *
866
+ * @param bool $encode
867
+ *
868
+ * @return []
869
+ */
870
+ public function get_display_items( $encode = false ) {
871
+ }
872
+
873
+ /**
874
+ * Returns a formatted array of shipping methods for display in the payment gateway's
875
+ * payment sheet.
876
+ *
877
+ * @param bool $encode
878
+ *
879
+ * @return []
880
+ */
881
+ public function get_shipping_methods( $encode = false ) {
882
+ }
883
+
884
+ /**
885
+ * Return true if product page checkout is enabled for this gateway
886
+ *
887
+ * @return bool
888
+ */
889
+ public function product_checkout_enabled() {
890
+ return in_array( 'product', $this->get_option( 'payment_sections', array() ) );
891
+ }
892
+
893
+ /**
894
+ * Return true if cart page checkout is enabled for this gateway
895
+ *
896
+ * @return bool
897
+ */
898
+ public function cart_checkout_enabled() {
899
+ return in_array( 'cart', $this->get_option( 'payment_sections', array() ) );
900
+ }
901
+
902
+ /**
903
+ * Return true if checkout page banner is enabled for this gateway
904
+ *
905
+ * @return bool
906
+ */
907
+ public function banner_checkout_enabled() {
908
+ global $wp;
909
+
910
+ return empty( $wp->query_vars['order-pay'] ) && $this->supports( 'wc_stripe_banner_checkout' ) &&
911
+ in_array( 'checkout_banner', $this->get_option( 'payment_sections', array() ) );
912
+ }
913
+
914
+ /**
915
+ * Decorate the response with data specific to the gateway.
916
+ *
917
+ * @param [] $data
918
+ */
919
+ public function add_to_cart_response( $data ) {
920
+ return $data;
921
+ }
922
+
923
+ /**
924
+ * Decorate the update shipping method reponse with data.
925
+ *
926
+ * @param [] $data
927
+ */
928
+ public function get_update_shipping_method_response( $data ) {
929
+ return $data;
930
+ }
931
+
932
+ /**
933
+ * Decorate the update shipping address respond with data.
934
+ *
935
+ * @param [] $data
936
+ */
937
+ public function get_update_shipping_address_response( $data ) {
938
+ return apply_filters( 'wc_stripe_update_shipping_address_response', $data );
939
+ }
940
+
941
+ /**
942
+ * Save the customer's payment method.
943
+ * If the payment method has already been saved to the customer
944
+ * then simply return true.
945
+ *
946
+ * @param string $id
947
+ * @param WC_Order $order
948
+ *
949
+ * @return WP_Error|bool
950
+ */
951
+ public function save_payment_method( $id, $order ) {
952
+ $token = $this->create_payment_method( $id, wc_stripe_get_customer_id( $order->get_user_id() ) );
953
+ if ( is_wp_error( $token ) ) {
954
+ $this->wp_error = $token;
955
+ $order->add_order_note( sprintf( __( 'Attemp to save payment method failed. Reason: %s', 'woo-stripe-payment' ), $token->get_error_message() ) );
956
+
957
+ return $token;
958
+ }
959
+ $token->set_user_id( $order->get_user_id() );
960
+ $token->save();
961
+
962
+ // set token value so it can be used for other processes.
963
+ $this->payment_method_token = $token->get_token();
964
+
965
+ return true;
966
+ }
967
+
968
+ /**
969
+ * Set an error on the order.
970
+ * This error is used on the frontend to alert customer's to a failed payment method save.
971
+ *
972
+ * @param WC_Order $order
973
+ * @param WP_Error $error
974
+ */
975
+ public function set_payment_save_error( $order, $error ) {
976
+ if ( wcs_stripe_active() && wcs_order_contains_subscription( $order ) ) {
977
+ $message = __( 'We were not able to save your payment method. To prevent billing issues with your subscription, please add a payment method to the subscription.', 'woo-stripe-payment' );
978
+ } else {
979
+ $message = sprintf( __( 'We were not able to save your payment method. Reason: %s', 'woo-stripe-payment' ), $error->get_error_message() );
980
+ }
981
+ $order->update_meta_data( '_wc_stripe_order_error', $message );
982
+ $order->save();
983
+ }
984
+
985
+ /**
986
+ *
987
+ * @param string $token_id
988
+ * @param int $user_id
989
+ *
990
+ * @return null|WC_Payment_Token_Stripe_CC
991
+ */
992
+ public function get_token( $token_id, $user_id ) {
993
+ $tokens = WC_Payment_Tokens::get_customer_tokens( $user_id, $this->id );
994
+ foreach ( $tokens as $token ) {
995
+ if ( $token_id === $token->get_token() ) {
996
+ return $token;
997
+ }
998
+ }
999
+
1000
+ return null;
1001
+ }
1002
+
1003
+ /**
1004
+ *
1005
+ * @param array $payment_meta
1006
+ * @param WC_Subscription $subscription
1007
+ */
1008
+ public function subscription_payment_meta( $payment_meta, $subscription ) {
1009
+ $payment_meta[ $this->id ] = array(
1010
+ 'post_meta' => array(
1011
+ WC_Stripe_Constants::PAYMENT_METHOD_TOKEN => array(
1012
+ 'value' => $this->get_order_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $subscription ),
1013
+ 'label' => __( 'Payment Method Token', 'woo-stripe-payment' ),
1014
+ ),
1015
+ ),
1016
+ );
1017
+
1018
+ return $payment_meta;
1019
+ }
1020
+
1021
+ /**
1022
+ *
1023
+ * @param float $amount
1024
+ * @param WC_Order $order
1025
+ */
1026
+ public function scheduled_subscription_payment( $amount, $order ) {
1027
+ $this->processing_payment = true;
1028
+
1029
+ $result = $this->payment_object->scheduled_subscription_payment( $amount, $order );
1030
+
1031
+ if ( is_wp_error( $result ) ) {
1032
+ $order->update_status( 'failed' );
1033
+ $order->add_order_note( sprintf( __( 'Recurring payment for order failed. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ) );
1034
+
1035
+ return;
1036
+ }
1037
+
1038
+ $this->save_order_meta( $order, $result->charge );
1039
+
1040
+ // set the payment method token that was used to process the renewal order.
1041
+ $this->payment_method_token = $order->get_meta( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN );
1042
+
1043
+ if ( $result->complete_payment ) {
1044
+ if ( $result->charge->captured ) {
1045
+ $order->payment_complete( $result->charge->id );
1046
+ $order->add_order_note( sprintf( __( 'Recurring payment captured in Stripe. Payment method: %s', 'woo-stripe-payment' ), $order->get_payment_method_title() ) );
1047
+ } else {
1048
+ $order->update_status( apply_filters( 'wc_stripe_authorized_renewal_order_status', 'on-hold', $order, $this ), sprintf( __( 'Recurring payment authorized in Stripe. Payment method: %s', 'woo-stripe-payment' ), $order->get_payment_method_title() ) );
1049
+ }
1050
+ } else {
1051
+ $order->update_status( 'pending', sprintf( __( 'Customer must manually complete payment for payment method %s', 'woo-stripe-payment' ), $order->get_payment_method_title() ) );
1052
+ }
1053
+ }
1054
+
1055
+ /**
1056
+ *
1057
+ * @param WC_Subscription $subscription
1058
+ * @param string $new_payment_method
1059
+ * @param string $old_payment_method
1060
+ */
1061
+ public function subscriptions_pre_update_payment_method( $subscription, $new_payment_method, $old_payment_method ) {
1062
+ if ( $new_payment_method === $this->id ) {
1063
+ // customer is using a new payment method so we need to save it.
1064
+ if ( ! $this->use_saved_source() ) {
1065
+ $result = $this->save_payment_method( $this->get_new_source_token(), $subscription );
1066
+ if ( is_wp_error( $result ) ) {
1067
+ wc_add_notice( sprintf( __( 'Error saving payment method for subscription. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ), 'error' );
1068
+ // redirect to change payment method page.
1069
+ wp_safe_redirect( $subscription->get_view_order_url() );
1070
+ exit();
1071
+ }
1072
+ } else {
1073
+ if ( ! $this->payment_method_token ) {
1074
+ // set the payment method token so it can be used downstream.
1075
+ $this->payment_method_token = $this->get_payment_source();
1076
+ }
1077
+ }
1078
+ }
1079
+ }
1080
+
1081
+ /**
1082
+ * Update the subscription with the new meta data for the gateway.
1083
+ * Save any new method the customer is trying to use.
1084
+ *
1085
+ * @param WC_Subscription $subscription
1086
+ */
1087
+ public function subscription_payment_method_updated( $subscription ) {
1088
+ $token = $this->get_token( $this->payment_method_token, $subscription->get_user_id() );
1089
+
1090
+ // update the meta data needed by the gateway to process a subscription payment.
1091
+ $subscription->update_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $this->payment_method_token );
1092
+ $subscription->set_payment_method_title( $token->get_payment_method_title() );
1093
+ $subscription->save();
1094
+ }
1095
+
1096
+ /**
1097
+ * Return true if this request is to change the payment method of a WC Subscription.
1098
+ *
1099
+ * @return bool
1100
+ */
1101
+ public function is_change_payment_method_request() {
1102
+ return wcs_stripe_active() && did_action( 'woocommerce_subscriptions_pre_update_payment_method' );
1103
+ }
1104
+
1105
+ /**
1106
+ * Sets the ID of a payment token.
1107
+ *
1108
+ * @param string $id
1109
+ */
1110
+ public function set_payment_method_token( $id ) {
1111
+ $this->payment_method_token = $id;
1112
+ }
1113
+
1114
+ public function set_new_source_token( $token ) {
1115
+ $this->new_source_token = $token;
1116
+ }
1117
+
1118
+ /**
1119
+ *
1120
+ * @param WC_Order $order
1121
+ *
1122
+ * @deprecated
1123
+ *
1124
+ */
1125
+ public function get_order_description( $order ) {
1126
+ return sprintf( __( 'Order %1$s from %2$s', 'woo-stripe-payment' ), $order->get_order_number(), get_bloginfo( 'name' ) );
1127
+ }
1128
+
1129
+ /**
1130
+ *
1131
+ * @param WC_Order $order
1132
+ */
1133
+ public function process_zero_total_order( $order ) {
1134
+ // save payment method if necessary
1135
+ if ( $this->should_save_payment_method( $order ) ) {
1136
+ $result = $this->save_payment_method( $this->get_new_source_token(), $order );
1137
+ if ( is_wp_error( $result ) ) {
1138
+ wc_add_notice( $result->get_error_message(), 'error' );
1139
+
1140
+ return $this->get_order_error();
1141
+ }
1142
+ } else {
1143
+ $this->payment_method_token = $this->get_saved_source_id();
1144
+ }
1145
+ $this->save_zero_total_meta( $order );
1146
+ $order_status = $this->get_option( 'order_status' );
1147
+ if ( 'capture' === $this->get_option( 'charge_type' ) ) {
1148
+ $order->payment_complete();
1149
+ } else {
1150
+ $order_status = $this->get_option( 'order_status' );
1151
+ $order->update_status( apply_filters( 'wc_stripe_authorized_order_status', 'default' === $order_status ? 'on-hold' : $order_status, $order, $this ) );
1152
+ }
1153
+ WC()->cart->empty_cart();
1154
+
1155
+ return array(
1156
+ 'result' => 'success',
1157
+ 'redirect' => $order->get_checkout_order_received_url(),
1158
+ );
1159
+ }
1160
+
1161
+ public function process_pre_order( $order ) {
1162
+ // maybe save payment method
1163
+ if ( ! $this->use_saved_source() ) {
1164
+ $result = $this->save_payment_method( $this->get_new_source_token(), $order );
1165
+ if ( is_wp_error( $result ) ) {
1166
+ wc_add_notice( $result->get_error_message(), 'error' );
1167
+
1168
+ return $this->get_order_error();
1169
+ }
1170
+ } else {
1171
+ $this->payment_method_token = $this->get_saved_source_id();
1172
+ }
1173
+ WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
1174
+ $this->save_zero_total_meta( $order );
1175
+
1176
+ return array(
1177
+ 'result' => 'success',
1178
+ 'redirect' => $order->get_checkout_order_received_url(),
1179
+ );
1180
+ }
1181
+
1182
+ /**
1183
+ *
1184
+ * @param WC_Order $order
1185
+ */
1186
+ protected function save_zero_total_meta( $order ) {
1187
+ $token = $this->get_token( $this->payment_method_token, $order->get_user_id() );
1188
+ $order->set_payment_method_title( $token->get_payment_method_title() );
1189
+ $order->update_meta_data( WC_Stripe_Constants::MODE, wc_stripe_mode() );
1190
+ $order->update_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token() );
1191
+ $order->update_meta_data( WC_Stripe_Constants::CUSTOMER_ID, wc_stripe_get_customer_id( $order->get_user_id() ) );
1192
+ $order->save();
1193
+
1194
+ if ( wcs_stripe_active() && wcs_order_contains_subscription( $order ) ) {
1195
+ foreach ( wcs_get_subscriptions_for_order( $order ) as $subscription ) {
1196
+ /**
1197
+ *
1198
+ * @var WC_Subscription $subscription
1199
+ */
1200
+ $subscription->set_payment_method_title( $token->get_payment_method_title() );
1201
+ $subscription->update_meta_data( WC_Stripe_Constants::MODE, wc_stripe_mode() );
1202
+ $subscription->update_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $token->get_token() );
1203
+ $subscription->update_meta_data( WC_Stripe_Constants::CUSTOMER_ID, wc_stripe_get_customer_id( $order->get_user_id() ) );
1204
+ $subscription->save();
1205
+ }
1206
+ }
1207
+ }
1208
+
1209
+ /**
1210
+ * Pre orders can't be mixed with regular products.
1211
+ *
1212
+ * @param WC_Order $order
1213
+ */
1214
+ protected function order_contains_pre_order( $order ) {
1215
+ return wc_stripe_pre_orders_active() && WC_Pre_Orders_Order::order_contains_pre_order( $order );
1216
+ }
1217
+
1218
+ /**
1219
+ *
1220
+ * @param WC_Order $order
1221
+ *
1222
+ * @return boolean
1223
+ */
1224
+ protected function pre_order_requires_tokenization( $order ) {
1225
+ return WC_Pre_Orders_Order::order_requires_payment_tokenization( $order );
1226
+ }
1227
+
1228
+ /**
1229
+ * Sets a lock on the order.
1230
+ * Default behavior is a 2 minute lock.
1231
+ *
1232
+ * @param WC_Order|int $order
1233
+ */
1234
+ public function set_order_lock( $order ) {
1235
+ $order_id = ( is_object( $order ) ? $order->get_id() : $order );
1236
+ set_transient( 'stripe_lock_order_' . $order_id, $order_id, apply_filters( 'wc_stripe_set_order_lock', 2 * MINUTE_IN_SECONDS ) );
1237
+ }
1238
+
1239
+ /**
1240
+ * Removes the lock on the order
1241
+ *
1242
+ * @param WC_Order|int $order
1243
+ */
1244
+ public function release_order_lock( $order ) {
1245
+ delete_transient( 'stripe_lock_order_' . ( is_object( $order ) ? $order->get_id() : $order ) );
1246
+ }
1247
+
1248
+ /**
1249
+ * Returns true of the order has been locked.
1250
+ * If the lock exists and is greater than current time
1251
+ * method returns true;
1252
+ *
1253
+ * @param WC_Order|int $order
1254
+ */
1255
+ public function has_order_lock( $order ) {
1256
+ $lock = get_transient( 'stripe_lock_order_' . ( is_object( $order ) ? $order->get_id() : $order ) );
1257
+
1258
+ return $lock !== false;
1259
+ }
1260
+
1261
+ public function set_post_payment_process( $callback ) {
1262
+ $this->post_payment_processes[] = $callback;
1263
+ }
1264
+
1265
+ /**
1266
+ *
1267
+ * @param WC_Order $order
1268
+ * @param WC_Payment_Gateway_Stripe $gateway
1269
+ */
1270
+ public function trigger_post_payment_processes( $order, $gateway ) {
1271
+ foreach ( $this->post_payment_processes as $callback ) {
1272
+ call_user_func_array( $callback, func_get_args() );
1273
+ }
1274
+ }
1275
+
1276
+ public function validate_payment_sections_field( $key, $value ) {
1277
+ if ( empty( $value ) ) {
1278
+ $value = array();
1279
+ }
1280
+
1281
+ return $value;
1282
+ }
1283
+
1284
+ /**
1285
+ *
1286
+ * @param WC_Order $order
1287
+ */
1288
+ public function process_pre_order_payment( $order ) {
1289
+ $this->processing_payment = true;
1290
+
1291
+ $result = $this->payment_object->process_pre_order_payment( $order );
1292
+
1293
+ if ( is_wp_error( $result ) ) {
1294
+ $order->update_status( 'failed' );
1295
+ $order->add_order_note( sprintf( __( 'Pre-order payment for order failed. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ) );
1296
+ } else {
1297
+ if ( $result->complete_payment ) {
1298
+
1299
+ $this->save_order_meta( $order, $result->charge );
1300
+
1301
+ if ( $result->charge->captured ) {
1302
+ $order->payment_complete( $result->charge->id );
1303
+ $order->add_order_note( sprintf( __( 'Pre-order payment captured in Stripe. Payment method: %s', 'woo-stripe-payment' ), $order->get_payment_method_title() ) );
1304
+ } else {
1305
+ $order->update_status( apply_filters( 'wc_stripe_authorized_preorder_order_status', 'on-hold', $order, $this ), sprintf( __( 'Pre-order payment authorized in Stripe. Payment method: %s', 'woo-stripe-payment' ), $order->get_payment_method_title() ) );
1306
+ }
1307
+ } else {
1308
+ $order->update_status( 'pending', sprintf( __( 'Customer must manually complete payment for payment method %s', 'woo-stripe-payment' ), $order->get_payment_method_title() ) );
1309
+ }
1310
+ }
1311
+ }
1312
+
1313
+ /**
1314
+ * Given a meta key, see if there is a value for that key in another plugin.
1315
+ * This acts as a lazy conversion
1316
+ * method for merchants that have switched to our plugin from other plugins.
1317
+ *
1318
+ * @param string $meta_key
1319
+ * @param WC_Order $order
1320
+ * @param string $context
1321
+ *
1322
+ * @since 3.1.0
1323
+ */
1324
+ public function get_order_meta_data( $meta_key, $order, $context = 'view' ) {
1325
+ $value = $order->get_meta( $meta_key, true, $context );
1326
+ // value is empty so check metadata from other plugins
1327
+ if ( empty( $value ) ) {
1328
+ $keys = array();
1329
+ switch ( $meta_key ) {
1330
+ case WC_Stripe_Constants::PAYMENT_METHOD_TOKEN:
1331
+ $keys = array( WC_Stripe_Constants::SOURCE_ID );
1332
+ break;
1333
+ case WC_Stripe_Constants::CUSTOMER_ID:
1334
+ $keys = array( WC_Stripe_Constants::STRIPE_CUSTOMER_ID );
1335
+ break;
1336
+ case WC_Stripe_Constants::PAYMENT_INTENT_ID:
1337
+ $keys = array( WC_Stripe_Constants::STRIPE_INTENT_ID );
1338
+ }
1339
+ if ( $keys ) {
1340
+ $meta_data = $order->get_meta_data();
1341
+ if ( $meta_data ) {
1342
+ $keys = array_intersect( wp_list_pluck( $meta_data, 'key' ), $keys );
1343
+ $array_keys = array_keys( $keys );
1344
+ if ( ! empty( $array_keys ) ) {
1345
+ $value = $meta_data[ current( $array_keys ) ]->value;
1346
+ update_post_meta( $order->get_id(), $meta_key, $value );
1347
+ }
1348
+ }
1349
+ }
1350
+ }
1351
+
1352
+ return $value;
1353
+ }
1354
+
1355
+ /**
1356
+ * Gateways can override this method to add attributes to the Stripe object before it's
1357
+ * sent to Stripe.
1358
+ *
1359
+ * @param array $args
1360
+ * @param WC_Order $order
1361
+ */
1362
+ public function add_stripe_order_args( &$args, $order ) {
1363
+ }
1364
+
1365
+ /**
1366
+ *
1367
+ * @param WP_Error $result
1368
+ *
1369
+ * @since 3.1.1
1370
+ */
1371
+ public function get_generic_error( $result = null ) {
1372
+ $messages = wc_stripe_get_error_messages();
1373
+ if ( isset( $messages["{$this->id}_generic"] ) ) {
1374
+ return $messages["{$this->id}_generic"];
1375
+ }
1376
+
1377
+ return null != $result ? $result->get_error_message() : __( 'Cannot process payment', 'woo-stripe-payment' );
1378
+ }
1379
+
1380
+ /**
1381
+ *
1382
+ * @since 3.1.2
1383
+ */
1384
+ private function get_payment_section_description() {
1385
+ return sprintf( __( '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.', 'woo-stripe-payment' ), $this->get_method_title() );
1386
+ }
1387
+ }
includes/abstract/abstract-wc-payment-token-stripe.php CHANGED
@@ -1,173 +1,178 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/traits/wc-stripe-payment-token-traits.php' );
5
-
6
- /**
7
- *
8
- * @since 3.0.0
9
- * @author PaymentPlugins
10
- * @package Stripe/Abstract
11
- *
12
- */
13
- abstract class WC_Payment_Token_Stripe extends WC_Payment_Token {
14
-
15
- protected $has_expiration = false;
16
-
17
- protected $object_type = 'payment_token';
18
-
19
- /**
20
- *
21
- * @since 3.1.0
22
- * @var string
23
- */
24
- protected $stripe_payment_type;
25
-
26
- protected $extra_data = array( 'format' => '',
27
- 'environment' => 'production', 'brand' => '',
28
- 'customer_id' => ''
29
- );
30
-
31
- protected $stripe_data = array();
32
-
33
- /**
34
- * The format of the payment method
35
- *
36
- * @var string
37
- */
38
- protected $format = '';
39
-
40
- public function __construct($token = '') {
41
- // use reflection to merge all extra data keys.
42
- $this->extra_data = array_merge ( $this->extra_data, $this->get_stripe_data ( $this ) );
43
- parent::__construct ( $token );
44
- }
45
-
46
- /**
47
- *
48
- * @param mixed $details
49
- */
50
- public abstract function details_to_props($details);
51
-
52
- public function set_format($value) {
53
- $this->format = $value;
54
- }
55
-
56
- public function set_environment($value) {
57
- $this->set_prop ( 'environment', $value );
58
- }
59
-
60
- public function set_customer_id($value) {
61
- $this->set_prop ( 'customer_id', $value );
62
- }
63
-
64
- public function get_format() {
65
- return $this->format;
66
- }
67
-
68
- public function get_environment() {
69
- return $this->get_prop ( 'environment' );
70
- }
71
-
72
- public function get_customer_id() {
73
- return $this->get_prop ( 'customer_id' );
74
- }
75
-
76
- /**
77
- * Return a human readable representation of the payment method.
78
- */
79
- public function get_payment_method_title($format = '') {
80
- $format = empty ( $format ) ? $this->get_format () : $format;
81
- $format = $this->get_formats ()[ $format ][ 'format' ];
82
- $data = $this->get_props_data ();
83
- return apply_filters ( 'wc_stripe_payment_method_title', str_replace ( array_keys ( $data ), $data, $format ), $this );
84
- }
85
-
86
- public function get_props_data() {
87
- $data = array();
88
- foreach ( $this->extra_data as $k => $v ) {
89
- if (method_exists ( $this, "get_{$k}" )) {
90
- $data[ '{' . $k . '}' ] = $this->{"get_$k"} ();
91
- } else {
92
- $data[ '{' . $k . '}' ] = $this->get_prop ( $k );
93
- }
94
- }
95
- return $data;
96
- }
97
-
98
- /**
99
- * Returns an array of merged attributes comprised of the $stripe_data property.
100
- *
101
- * @param object $instance
102
- */
103
- public function get_stripe_data($instance) {
104
- $data = array();
105
- try {
106
- $class = new ReflectionClass ( $instance );
107
- $props = $class->getDefaultProperties ();
108
- if (isset ( $props[ 'stripe_data' ] )) {
109
- $data = $props[ 'stripe_data' ];
110
- }
111
- if (is_subclass_of ( get_parent_class ( $instance ), 'WC_Payment_Token_Stripe' )) {
112
- $data = array_merge ( $this->get_stripe_data ( get_parent_class ( $instance ) ), $data );
113
- }
114
- return $data;
115
- } catch ( Exception $e ) {
116
- return array();
117
- }
118
- }
119
-
120
- /**
121
- * Return a json array of data that represents the object.
122
- *
123
- * @return array
124
- */
125
- public function to_json() {
126
- return apply_filters ( 'wc_stripe_get_' . $this->object_type . '_json', array(
127
- 'id' => $this->get_id (),
128
- 'type' => $this->get_type (),
129
- 'token' => $this->get_token (),
130
- 'title' => $this->get_payment_method_title (),
131
- 'gateway' => $this->get_gateway_id ()
132
- ) );
133
- }
134
-
135
- /**
136
- * Return formats used by the token to display a human readable title.
137
- */
138
- public abstract function get_formats();
139
-
140
- public function get_brand($context = 'view') {
141
- return wc_get_credit_card_type_label ( $this->get_prop ( 'brand', $context ) );
142
- }
143
-
144
- public function set_brand($value) {
145
- $this->set_prop ( 'brand', $value );
146
- }
147
-
148
- public function get_html_classes() {
149
- return '';
150
- }
151
-
152
- public function has_expiration() {
153
- return $this->has_expiration;
154
- }
155
-
156
- /**
157
- *
158
- * @since 3.1.0
159
- */
160
- public abstract function delete_from_stripe();
161
-
162
- /**
163
- *
164
- * @since 3.1.0
165
- */
166
- public abstract function save_payment_method();
167
-
168
- public static function token_exists($token_id, $user_id) {
169
- global $wpdb;
170
- $count = $wpdb->get_var ( $wpdb->prepare ( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_payment_tokens WHERE token = %s AND gateway_id LIKE %s AND user_id = %d", $token_id, '%stripe_%', $user_id ) );
171
- return $count > 0;
172
- }
173
- }
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ require_once( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/traits/wc-stripe-payment-token-traits.php' );
5
+
6
+ /**
7
+ *
8
+ * @since 3.0.0
9
+ * @author PaymentPlugins
10
+ * @package Stripe/Abstract
11
+ *
12
+ */
13
+ abstract class WC_Payment_Token_Stripe extends WC_Payment_Token {
14
+
15
+ protected $has_expiration = false;
16
+
17
+ protected $object_type = 'payment_token';
18
+
19
+ /**
20
+ *
21
+ * @since 3.1.0
22
+ * @var string
23
+ */
24
+ protected $stripe_payment_type;
25
+
26
+ protected $extra_data = array(
27
+ 'format' => '',
28
+ 'environment' => 'production',
29
+ 'brand' => '',
30
+ 'customer_id' => '',
31
+ );
32
+
33
+ protected $stripe_data = array();
34
+
35
+ /**
36
+ * The format of the payment method
37
+ *
38
+ * @var string
39
+ */
40
+ protected $format = '';
41
+
42
+ public function __construct( $token = '' ) {
43
+ // use reflection to merge all extra data keys.
44
+ $this->extra_data = array_merge( $this->extra_data, $this->get_stripe_data( $this ) );
45
+ parent::__construct( $token );
46
+ }
47
+
48
+ /**
49
+ *
50
+ * @param mixed $details
51
+ */
52
+ public abstract function details_to_props( $details );
53
+
54
+ public function set_format( $value ) {
55
+ $this->format = $value;
56
+ }
57
+
58
+ public function set_environment( $value ) {
59
+ $this->set_prop( 'environment', $value );
60
+ }
61
+
62
+ public function set_customer_id( $value ) {
63
+ $this->set_prop( 'customer_id', $value );
64
+ }
65
+
66
+ public function get_format() {
67
+ return $this->format;
68
+ }
69
+
70
+ public function get_environment() {
71
+ return $this->get_prop( 'environment' );
72
+ }
73
+
74
+ public function get_customer_id() {
75
+ return $this->get_prop( 'customer_id' );
76
+ }
77
+
78
+ /**
79
+ * Return a human readable representation of the payment method.
80
+ */
81
+ public function get_payment_method_title( $format = '' ) {
82
+ $format = empty( $format ) ? $this->get_format() : $format;
83
+ $format = $this->get_formats()[ $format ]['format'];
84
+ $data = $this->get_props_data();
85
+ return apply_filters( 'wc_stripe_payment_method_title', str_replace( array_keys( $data ), $data, $format ), $this );
86
+ }
87
+
88
+ public function get_props_data() {
89
+ $data = array();
90
+ foreach ( $this->extra_data as $k => $v ) {
91
+ if ( method_exists( $this, "get_{$k}" ) ) {
92
+ $data[ '{' . $k . '}' ] = $this->{"get_$k"}();
93
+ } else {
94
+ $data[ '{' . $k . '}' ] = $this->get_prop( $k );
95
+ }
96
+ }
97
+ return $data;
98
+ }
99
+
100
+ /**
101
+ * Returns an array of merged attributes comprised of the $stripe_data property.
102
+ *
103
+ * @param object $instance
104
+ */
105
+ public function get_stripe_data( $instance ) {
106
+ $data = array();
107
+ try {
108
+ $class = new ReflectionClass( $instance );
109
+ $props = $class->getDefaultProperties();
110
+ if ( isset( $props['stripe_data'] ) ) {
111
+ $data = $props['stripe_data'];
112
+ }
113
+ if ( is_subclass_of( get_parent_class( $instance ), 'WC_Payment_Token_Stripe' ) ) {
114
+ $data = array_merge( $this->get_stripe_data( get_parent_class( $instance ) ), $data );
115
+ }
116
+ return $data;
117
+ } catch ( Exception $e ) {
118
+ return array();
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Return a json array of data that represents the object.
124
+ *
125
+ * @return array
126
+ */
127
+ public function to_json() {
128
+ return apply_filters(
129
+ 'wc_stripe_get_' . $this->object_type . '_json',
130
+ array(
131
+ 'id' => $this->get_id(),
132
+ 'type' => $this->get_type(),
133
+ 'token' => $this->get_token(),
134
+ 'title' => $this->get_payment_method_title(),
135
+ 'gateway' => $this->get_gateway_id(),
136
+ )
137
+ );
138
+ }
139
+
140
+ /**
141
+ * Return formats used by the token to display a human readable title.
142
+ */
143
+ public abstract function get_formats();
144
+
145
+ public function get_brand( $context = 'view' ) {
146
+ return wc_get_credit_card_type_label( $this->get_prop( 'brand', $context ) );
147
+ }
148
+
149
+ public function set_brand( $value ) {
150
+ $this->set_prop( 'brand', $value );
151
+ }
152
+
153
+ public function get_html_classes() {
154
+ return '';
155
+ }
156
+
157
+ public function has_expiration() {
158
+ return $this->has_expiration;
159
+ }
160
+
161
+ /**
162
+ *
163
+ * @since 3.1.0
164
+ */
165
+ public abstract function delete_from_stripe();
166
+
167
+ /**
168
+ *
169
+ * @since 3.1.0
170
+ */
171
+ public abstract function save_payment_method();
172
+
173
+ public static function token_exists( $token_id, $user_id ) {
174
+ global $wpdb;
175
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_payment_tokens WHERE token = %s AND gateway_id LIKE %s AND user_id = %d", $token_id, '%stripe_%', $user_id ) );
176
+ return $count > 0;
177
+ }
178
+ }
includes/abstract/abstract-wc-stripe-payment.php CHANGED
@@ -1,231 +1,238 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @since 3.1.0
8
- *
9
- */
10
- abstract class WC_Stripe_Payment {
11
-
12
- /**
13
- *
14
- * @var WC_Payment_Gateway_Stripe
15
- */
16
- protected $payment_method;
17
-
18
- /**
19
- *
20
- * @var WC_Stripe_Gateway
21
- */
22
- protected $gateway;
23
-
24
- /**
25
- *
26
- * @param WC_Payment_Gateway_Stripe $payment_method
27
- * @param WC_Stripe_Gateway $gateway
28
- */
29
- public function __construct($payment_method, $gateway) {
30
- $this->payment_method = $payment_method;
31
- $this->gateway = $gateway;
32
- }
33
-
34
- public function get_gateway() {
35
- return $this->gateway;
36
- }
37
-
38
- /**
39
- * Process the payment for the order.
40
- *
41
- * @param WC_Order $order
42
- * @param WC_Payment_Gateway_Stripe $payment_method
43
- */
44
- public abstract function process_payment($order);
45
-
46
- /**
47
- *
48
- * @param float $amount
49
- * @param WC_Order $order
50
- */
51
- public abstract function capture_charge($amount, $order);
52
-
53
- /**
54
- *
55
- * @param WC_Order $order
56
- */
57
- public abstract function void_charge($order);
58
-
59
- /**
60
- *
61
- * @param \Stripe\Charge $charge
62
- */
63
- public abstract function get_payment_method_from_charge($charge);
64
-
65
- /**
66
- *
67
- * @param array $args
68
- * @param WC_Order $order
69
- */
70
- public abstract function add_order_payment_method(&$args, $order);
71
-
72
- /**
73
- *
74
- * @param float $amount
75
- * @param WC_Order $order
76
- */
77
- public abstract function scheduled_subscription_payment($amount, $order);
78
-
79
- /**
80
- *
81
- * @param WC_Order $order
82
- */
83
- public abstract function process_pre_order_payment($order);
84
-
85
- /**
86
- * Return true if the charge can be voided.
87
- *
88
- * @param WC_Order $order
89
- */
90
- public abstract function can_void_order($order);
91
-
92
- /**
93
- *
94
- * @param WC_Order $order
95
- * @param float $amount
96
- * @throws Exception
97
- */
98
- public function process_refund($order, $amount = null) {
99
- $amount_in_cents = wc_stripe_add_number_precision ( $amount, $order->get_currency () );
100
- $charge = $order->get_transaction_id ();
101
- try {
102
- if (empty ( $charge )) {
103
- throw new Exception ( __ ( 'Transaction Id cannot be empty.', 'woo-stripe-payment' ) );
104
- }
105
- $result = $this->gateway->refund ( array(
106
- 'charge' => $charge,
107
- 'amount' => $amount_in_cents
108
- ), wc_stripe_order_mode ( $order ) );
109
- if (! is_wp_error ( $result )) {
110
- return true;
111
- }
112
- return $result;
113
- } catch ( Exception $e ) {
114
- return new WP_Error ( 'refund-error', $e->getMessage () );
115
- }
116
- }
117
-
118
- /**
119
- * Return a failed order response.
120
- *
121
- * @return array
122
- */
123
- public function order_error() {
124
- wc_stripe_set_checkout_error ();
125
- return [ 'result' => 'failure'
126
- ];
127
- }
128
-
129
- /**
130
- *
131
- * @param array $args
132
- * @param WC_Order $order
133
- */
134
- public function add_general_order_args(&$args, $order) {
135
- $this->add_order_amount ( $args, $order );
136
- $this->add_order_currency ( $args, $order );
137
- $this->add_order_description ( $args, $order );
138
- $this->add_order_shipping_address ( $args, $order );
139
- $this->add_order_metadata ( $args, $order );
140
- $this->add_order_payment_method ( $args, $order );
141
- }
142
-
143
- /**
144
- *
145
- * @param array $args
146
- * @param WC_Order $order
147
- */
148
- public function add_order_metadata(&$args, $order) {
149
- $meta_data = [
150
- 'gateway_id' => $this->payment_method->id,
151
- 'order_id' => $order->get_order_number (),
152
- 'user_id' => $order->get_user_id (),
153
- 'customer_id' => wc_stripe_get_customer_id ( $order->get_user_id () ),
154
- 'ip_address' => $order->get_customer_ip_address (),
155
- 'user_agent' => isset ( $_SERVER[ 'HTTP_USER_AGENT' ] ) ? $_SERVER[ 'HTTP_USER_AGENT' ] : 'unavailable',
156
- 'partner' => 'PaymentPlugins',
157
- 'created' => time ()
158
- ];
159
- foreach ( $order->get_items ( 'line_item' ) as $item ) {
160
- /**
161
- *
162
- * @var WC_Order_Item_Product $item
163
- */
164
- $meta_data[ 'product_' . $item->get_product_id () ] = sprintf ( '%s x %s', $item->get_name (), $item->get_quantity () );
165
- }
166
- $args[ 'metadata' ] = apply_filters ( 'wc_stripe_order_meta_data', $meta_data, $order );
167
- }
168
-
169
- /**
170
- *
171
- * @param array $args
172
- * @param WC_Order $order
173
- */
174
- public function add_order_description(&$args, $order) {
175
- $args[ 'description' ] = sprintf ( __ ( 'Order %s from %s', 'woo-stripe-payment' ), $order->get_order_number (), get_bloginfo ( 'name' ) );
176
- }
177
-
178
- /**
179
- *
180
- * @param array $args
181
- * @param WC_Order $order
182
- * @param float $amount
183
- */
184
- public function add_order_amount(&$args, $order, $amount = null) {
185
- $args[ 'amount' ] = wc_stripe_add_number_precision ( $amount ? $amount : $order->get_total (), $order->get_currency () );
186
- }
187
-
188
- /**
189
- *
190
- * @param array $args
191
- * @param WC_Order $order
192
- */
193
- public function add_order_currency(&$args, $order) {
194
- $args[ 'currency' ] = $order->get_currency ();
195
- }
196
-
197
- /**
198
- *
199
- * @param array $args
200
- * @param WC_Order $order
201
- */
202
- public function add_order_shipping_address(&$args, $order) {
203
- if (wc_stripe_order_has_shipping_address ( $order )) {
204
- $args[ 'shipping' ] = [
205
- 'address' => [
206
- 'city' => $order->get_shipping_city (),
207
- 'country' => $order->get_shipping_country (),
208
- 'line1' => $order->get_shipping_address_1 (),
209
- 'line2' => $order->get_shipping_address_2 (),
210
- 'postal_code' => $order->get_shipping_postcode (),
211
- 'state' => $order->get_shipping_state ()
212
- ],
213
- 'name' => $this->get_name_from_order ( $order, 'shipping' )
214
- ];
215
- } else {
216
- $args[ 'shipping' ] = [];
217
- }
218
- }
219
-
220
- /**
221
- *
222
- * @param WC_Order $order
223
- */
224
- public function get_name_from_order($order, $type) {
225
- if ($type === 'billing') {
226
- return sprintf ( '%s %s', $order->get_billing_first_name (), $order->get_billing_last_name () );
227
- } else {
228
- return sprintf ( '%s %s', $order->get_shipping_first_name (), $order->get_shipping_last_name () );
229
- }
230
- }
231
- }
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @since 3.1.0
8
+ * @package Stripe/Abstract
9
+ *
10
+ */
11
+ abstract class WC_Stripe_Payment {
12
+
13
+ /**
14
+ *
15
+ * @var WC_Payment_Gateway_Stripe
16
+ */
17
+ protected $payment_method;
18
+
19
+ /**
20
+ *
21
+ * @var WC_Stripe_Gateway
22
+ */
23
+ protected $gateway;
24
+
25
+ /**
26
+ *
27
+ * @param WC_Payment_Gateway_Stripe $payment_method
28
+ * @param WC_Stripe_Gateway $gateway
29
+ */
30
+ public function __construct( $payment_method, $gateway ) {
31
+ $this->payment_method = $payment_method;
32
+ $this->gateway = $gateway;
33
+ }
34
+
35
+ public function get_gateway() {
36
+ return $this->gateway;
37
+ }
38
+
39
+ /**
40
+ * Process the payment for the order.
41
+ *
42
+ * @param WC_Order $order
43
+ * @param WC_Payment_Gateway_Stripe $payment_method
44
+ */
45
+ public abstract function process_payment( $order );
46
+
47
+ /**
48
+ *
49
+ * @param float $amount
50
+ * @param WC_Order $order
51
+ */
52
+ public abstract function capture_charge( $amount, $order );
53
+
54
+ /**
55
+ *
56
+ * @param WC_Order $order
57
+ */
58
+ public abstract function void_charge( $order );
59
+
60
+ /**
61
+ *
62
+ * @param \Stripe\Charge $charge
63
+ */
64
+ public abstract function get_payment_method_from_charge( $charge );
65
+
66
+ /**
67
+ *
68
+ * @param array $args
69
+ * @param WC_Order $order
70
+ */
71
+ public abstract function add_order_payment_method( &$args, $order );
72
+
73
+ /**
74
+ *
75
+ * @param float $amount
76
+ * @param WC_Order $order
77
+ */
78
+ public abstract function scheduled_subscription_payment( $amount, $order );
79
+
80
+ /**
81
+ *
82
+ * @param WC_Order $order
83
+ */
84
+ public abstract function process_pre_order_payment( $order );
85
+
86
+ /**
87
+ * Return true if the charge can be voided.
88
+ *
89
+ * @param WC_Order $order
90
+ */
91
+ public abstract function can_void_order( $order );
92
+
93
+ /**
94
+ *
95
+ * @param WC_Order $order
96
+ * @param float $amount
97
+ *
98
+ * @throws Exception
99
+ */
100
+ public function process_refund( $order, $amount = null ) {
101
+ $charge = $order->get_transaction_id();
102
+ try {
103
+ if ( empty( $charge ) ) {
104
+ throw new Exception( __( 'Transaction Id cannot be empty.', 'woo-stripe-payment' ) );
105
+ }
106
+ $result = $this->gateway->refunds->mode( wc_stripe_order_mode( $order ) )->create(
107
+ array(
108
+ 'charge' => $charge,
109
+ 'amount' => wc_stripe_add_number_precision(
110
+ $amount,
111
+ $order->get_currency()
112
+ ),
113
+ )
114
+ );
115
+ if ( ! is_wp_error( $result ) ) {
116
+ return true;
117
+ }
118
+
119
+ return $result;
120
+ } catch ( Exception $e ) {
121
+ return new WP_Error( 'refund-error', $e->getMessage() );
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Return a failed order response.
127
+ *
128
+ * @return array
129
+ */
130
+ public function order_error() {
131
+ wc_stripe_set_checkout_error();
132
+
133
+ return array( 'result' => 'failure' );
134
+ }
135
+
136
+ /**
137
+ *
138
+ * @param array $args
139
+ * @param WC_Order $order
140
+ */
141
+ public function add_general_order_args( &$args, $order ) {
142
+ $this->add_order_amount( $args, $order );
143
+ $this->add_order_currency( $args, $order );
144
+ $this->add_order_description( $args, $order );
145
+ $this->add_order_shipping_address( $args, $order );
146
+ $this->add_order_metadata( $args, $order );
147
+ $this->add_order_payment_method( $args, $order );
148
+ }
149
+
150
+ /**
151
+ *
152
+ * @param array $args
153
+ * @param WC_Order $order
154
+ */
155
+ public function add_order_metadata( &$args, $order ) {
156
+ $meta_data = array(
157
+ 'gateway_id' => $this->payment_method->id,
158
+ 'order_id' => $order->get_order_number(),
159
+ 'user_id' => $order->get_user_id(),
160
+ 'customer_id' => wc_stripe_get_customer_id( $order->get_user_id() ),
161
+ 'ip_address' => $order->get_customer_ip_address(),
162
+ 'user_agent' => isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'unavailable',
163
+ 'partner' => 'PaymentPlugins',
164
+ 'created' => time(),
165
+ );
166
+ foreach ( $order->get_items( 'line_item' ) as $item ) {
167
+ /**
168
+ *
169
+ * @var WC_Order_Item_Product $item
170
+ */
171
+ $meta_data[ 'product_' . $item->get_product_id() ] = sprintf( '%s x %s', $item->get_name(), $item->get_quantity() );
172
+ }
173
+ $args['metadata'] = apply_filters( 'wc_stripe_order_meta_data', $meta_data, $order );
174
+ }
175
+
176
+ /**
177
+ *
178
+ * @param array $args
179
+ * @param WC_Order $order
180
+ */
181
+ public function add_order_description( &$args, $order ) {
182
+ $args['description'] = sprintf( __( 'Order %1$s from %2$s', 'woo-stripe-payment' ), $order->get_order_number(), get_bloginfo( 'name' ) );
183
+ }
184
+
185
+ /**
186
+ *
187
+ * @param array $args
188
+ * @param WC_Order $order
189
+ * @param float $amount
190
+ */
191
+ public function add_order_amount( &$args, $order, $amount = null ) {
192
+ $args['amount'] = wc_stripe_add_number_precision( $amount ? $amount : $order->get_total(), $order->get_currency() );
193
+ }
194
+
195
+ /**
196
+ *
197
+ * @param array $args
198
+ * @param WC_Order $order
199
+ */
200
+ public function add_order_currency( &$args, $order ) {
201
+ $args['currency'] = $order->get_currency();
202
+ }
203
+
204
+ /**
205
+ *
206
+ * @param array $args
207
+ * @param WC_Order $order
208
+ */
209
+ public function add_order_shipping_address( &$args, $order ) {
210
+ if ( wc_stripe_order_has_shipping_address( $order ) ) {
211
+ $args['shipping'] = array(
212
+ 'address' => array(
213
+ 'city' => $order->get_shipping_city(),
214
+ 'country' => $order->get_shipping_country(),
215
+ 'line1' => $order->get_shipping_address_1(),
216
+ 'line2' => $order->get_shipping_address_2(),
217
+ 'postal_code' => $order->get_shipping_postcode(),
218
+ 'state' => $order->get_shipping_state(),
219
+ ),
220
+ 'name' => $this->get_name_from_order( $order, 'shipping' ),
221
+ );
222
+ } else {
223
+ $args['shipping'] = array();
224
+ }
225
+ }
226
+
227
+ /**
228
+ *
229
+ * @param WC_Order $order
230
+ */
231
+ public function get_name_from_order( $order, $type ) {
232
+ if ( $type === 'billing' ) {
233
+ return sprintf( '%s %s', $order->get_billing_first_name(), $order->get_billing_last_name() );
234
+ } else {
235
+ return sprintf( '%s %s', $order->get_shipping_first_name(), $order->get_shipping_last_name() );
236
+ }
237
+ }
238
+ }
includes/abstract/abstract-wc-stripe-rest-controller.php CHANGED
@@ -1,105 +1,104 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @package Stripe/Abstract
8
- *
9
- */
10
- abstract class WC_Stripe_Rest_Controller {
11
-
12
- protected $namespace = '';
13
-
14
- /**
15
- *
16
- * @var WP_Error
17
- */
18
- protected $error = null;
19
-
20
- /**
21
- *
22
- * @param string $route
23
- */
24
- protected function register_authenticated_route($route) {
25
- $routes = get_option ( 'wc_stripe_authenticated_routes', array() );
26
- $route = '/' . trim ( $route, '/' );
27
- $routes[ md5 ( $route ) ] = $route;
28
- update_option ( 'wc_stripe_authenticated_routes', $routes );
29
- }
30
-
31
- /**
32
- * Register all routes that the controller uses.
33
- */
34
- abstract public function register_routes();
35
-
36
- public function rest_uri($uri = '') {
37
- $rest_uri = wc_stripe ()->rest_api->rest_uri () . ( ! empty ( $this->namespace ) ? $this->namespace : '' );
38
- if ($uri) {
39
- $rest_uri = trailingslashit ( $rest_uri ) . $uri;
40
- }
41
- return trim ( $rest_uri, '/' );
42
- }
43
-
44
- public function rest_url($uri = '') {
45
- $rest_url = wc_stripe ()->rest_api->rest_url () . ( ! empty ( $this->namespace ) ? trailingslashit ( $this->namespace ) : '' );
46
- if ($uri) {
47
- $rest_url = trailingslashit ( $rest_url ) . $uri;
48
- }
49
- return $rest_url;
50
- }
51
-
52
- /**
53
- *
54
- * @param WP_REST_Request $request
55
- */
56
- public function admin_permission_check($request) {
57
- if (! current_user_can ( 'administrator' )) {
58
- return new WP_Error ( 'permission-error', __ ( 'You do not have permissions to access this resource.', 'woo-stripe-payment' ), array(
59
- 'status' => 403
60
- ) );
61
- }
62
-
63
- return true;
64
- }
65
-
66
- protected function get_error_messages() {
67
- return $this->get_messages ( 'error' );
68
- }
69
-
70
- protected function get_messages($types = 'all') {
71
- $notices = wc_get_notices ();
72
- if ($types !== 'all') {
73
- $types = ( array ) $types;
74
- foreach ( $notices as $type => $notice ) {
75
- if (! in_array ( $type, $types )) {
76
- unset ( $notices[ $type ] );
77
- }
78
- }
79
- }
80
- wc_set_notices ( $notices );
81
- ob_start ();
82
- $messages = wc_print_notices ();
83
- return ob_get_clean ();
84
- }
85
-
86
- /**
87
- * Allows a status code of 200 to be returned even if there is a validation error.
88
- *
89
- * @param WP_Error $error
90
- */
91
- protected function add_validation_error($error) {
92
- $data = $error->get_error_data ();
93
- if (! is_array ( $data )) {
94
- $data = [];
95
- }
96
- $error->add_data ( array_merge ( $data, [
97
- 'status' => 200
98
- ] ) );
99
- $this->error = $error;
100
- add_filter ( 'rest_request_before_callbacks', function ($response) {
101
- return $this->error ? $this->error : response;
102
- } );
103
- return $error;
104
- }
105
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @package Stripe/Abstract
8
+ *
9
+ */
10
+ abstract class WC_Stripe_Rest_Controller {
11
+
12
+ protected $namespace = '';
13
+
14
+ /**
15
+ *
16
+ * @var WP_Error
17
+ */
18
+ protected $error = null;
19
+
20
+ /**
21
+ *
22
+ * @param string $route
23
+ */
24
+ protected function register_authenticated_route( $route ) {
25
+ $routes = get_option( 'wc_stripe_authenticated_routes', array() );
26
+ $route = '/' . trim( $route, '/' );
27
+ $routes[ md5( $route ) ] = $route;
28
+ update_option( 'wc_stripe_authenticated_routes', $routes );
29
+ }
30
+
31
+ /**
32
+ * Register all routes that the controller uses.
33
+ */
34
+ abstract public function register_routes();
35
+
36
+ public function rest_uri( $uri = '' ) {
37
+ $rest_uri = wc_stripe()->rest_api->rest_uri() . ( ! empty( $this->namespace ) ? $this->namespace : '' );
38
+ if ( $uri ) {
39
+ $rest_uri = trailingslashit( $rest_uri ) . $uri;
40
+ }
41
+ return trim( $rest_uri, '/' );
42
+ }
43
+
44
+ public function rest_url( $uri = '' ) {
45
+ $rest_url = wc_stripe()->rest_api->rest_url() . ( ! empty( $this->namespace ) ? trailingslashit( $this->namespace ) : '' );
46
+ if ( $uri ) {
47
+ $rest_url = trailingslashit( $rest_url ) . $uri;
48
+ }
49
+ return $rest_url;
50
+ }
51
+
52
+ /**
53
+ *
54
+ * @param WP_REST_Request $request
55
+ */
56
+ public function admin_permission_check( $request ) {
57
+ if ( ! current_user_can( 'administrator' ) ) {
58
+ return new WP_Error( 'permission-error', __( 'You do not have permissions to access this resource.', 'woo-stripe-payment' ), array( 'status' => 403 ) );
59
+ }
60
+
61
+ return true;
62
+ }
63
+
64
+ protected function get_error_messages() {
65
+ return $this->get_messages( 'error' );
66
+ }
67
+
68
+ protected function get_messages( $types = 'all' ) {
69
+ $notices = wc_get_notices();
70
+ if ( $types !== 'all' ) {
71
+ $types = (array) $types;
72
+ foreach ( $notices as $type => $notice ) {
73
+ if ( ! in_array( $type, $types ) ) {
74
+ unset( $notices[ $type ] );
75
+ }
76
+ }
77
+ }
78
+ wc_set_notices( $notices );
79
+ ob_start();
80
+ $messages = wc_print_notices();
81
+ return ob_get_clean();
82
+ }
83
+
84
+ /**
85
+ * Allows a status code of 200 to be returned even if there is a validation error.
86
+ *
87
+ * @param WP_Error $error
88
+ */
89
+ protected function add_validation_error( $error ) {
90
+ $data = $error->get_error_data();
91
+ if ( ! is_array( $data ) ) {
92
+ $data = array();
93
+ }
94
+ $error->add_data( array_merge( $data, array( 'status' => 200 ) ) );
95
+ $this->error = $error;
96
+ add_filter(
97
+ 'rest_request_before_callbacks',
98
+ function ( $response ) {
99
+ return $this->error ? $this->error : response;
100
+ }
101
+ );
102
+ return $error;
103
+ }
104
+ }
 
includes/abstract/abstract-wc-stripe-settings.php CHANGED
@@ -1,29 +1,27 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @package Stripe/Abstract
8
- *
9
- */
10
- abstract class WC_Stripe_Settings_API extends WC_Settings_API {
11
-
12
- use WC_Stripe_Settings_Trait;
13
-
14
- public function __construct() {
15
- $this->init_form_fields ();
16
- $this->init_settings ();
17
- $this->hooks ();
18
- }
19
-
20
- public function hooks() {
21
- add_action ( 'wc_stripe_localize_' . $this->id . '_settings', array(
22
- $this, 'localize_settings'
23
- ) );
24
- }
25
-
26
- public function localize_settings() {
27
- return $this->settings;
28
- }
29
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @package Stripe/Abstract
8
+ *
9
+ */
10
+ abstract class WC_Stripe_Settings_API extends WC_Settings_API {
11
+
12
+ use WC_Stripe_Settings_Trait;
13
+
14
+ public function __construct() {
15
+ $this->init_form_fields();
16
+ $this->init_settings();
17
+ $this->hooks();
18
+ }
19
+
20
+ public function hooks() {
21
+ add_action( 'wc_stripe_localize_' . $this->id . '_settings', array( $this, 'localize_settings' ) );
22
+ }
23
+
24
+ public function localize_settings() {
25
+ return $this->settings;
26
+ }
27
+ }
 
 
includes/admin/class-wc-stripe-admin-assets.php CHANGED
@@ -1,99 +1,99 @@
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(
12
- $this, 'enqueue_scripts'
13
- ) );
14
-
15
- add_action ( 'wp_print_scripts', array( __CLASS__,
16
- 'localize_scripts'
17
- ) );
18
-
19
- add_action ( 'admin_footer', array( __CLASS__,
20
- 'localize_scripts'
21
- ) );
22
- add_action ( 'wc_stripe_localize_stripe_advanced_settings', array(
23
- __CLASS__, 'localize_advanced_scripts'
24
- ) );
25
- }
26
-
27
- public function enqueue_scripts() {
28
- global $current_section, $wc_stripe_subsection;
29
- $screen = get_current_screen ();
30
- $screen_id = $screen ? $screen->id : '';
31
- $js_path = wc_stripe ()->assets_url () . 'js/';
32
- $css_path = wc_stripe ()->assets_url () . 'css/';
33
-
34
- wp_register_script ( 'wc-stripe-admin-settings', $js_path . 'admin/admin-settings.js', array(
35
- 'jquery', 'jquery-blockui'
36
- ), wc_stripe ()->version, true );
37
- wp_register_script ( 'wc-stripe-meta-boxes-order', $js_path . 'admin/meta-boxes-order.js', array(
38
- 'jquery', 'jquery-blockui'
39
- ), wc_stripe ()->version, true );
40
- wp_register_script ( 'wc-stripe-meta-boxes-subscription', $js_path . 'admin/meta-boxes-subscription.js', array(
41
- 'jquery', 'jquery-blockui'
42
- ), wc_stripe ()->version, true );
43
- wp_register_script ( 'wc-stripe-product-data', $js_path . 'admin/meta-boxes-product-data.js', array(
44
- 'jquery', 'jquery-blockui',
45
- 'jquery-ui-sortable', 'jquery-ui-widget',
46
- 'jquery-ui-core', 'jquery-tiptip'
47
- ), wc_stripe ()->version (), true );
48
- wp_register_style ( 'wc-stripe-admin-style', $css_path . 'admin/admin.css', array(), wc_stripe ()->version );
49
-
50
- if (strpos ( $screen_id, 'wc-settings' ) !== false) {
51
- if (isset ( $_REQUEST[ 'section' ] ) && preg_match ( '/stripe_[\w]*/', $_REQUEST[ 'section' ] )) {
52
- wp_enqueue_script ( 'wc-stripe-admin-settings' );
53
- wp_enqueue_style ( 'wc-stripe-admin-style' );
54
- wp_enqueue_script ( 'stripe-help-widget', $js_path . 'admin/help-widget.js', array(), wc_stripe ()->version (), true );
55
- ;
56
- wp_localize_script ( 'wc-stripe-admin-settings', 'wc_stripe_setting_params', [
57
- 'routes' => [
58
- 'apple_domain' => wc_stripe ()->rest_api->settings->rest_url ( 'apple-domain' ),
59
- 'create_webhook' => wc_stripe ()->rest_api->settings->rest_url ( 'create-webook' ),
60
- 'connection_test' => wc_stripe ()->rest_api->settings->rest_url ( 'connection-test' )
61
- ],
62
- 'rest_nonce' => wp_create_nonce ( 'wp_rest' )
63
- ] );
64
- }
65
- }
66
- if ($screen_id === 'shop_order') {
67
- wp_enqueue_style ( 'wc-stripe-admin-style' );
68
- }
69
- if ($screen_id === 'product') {
70
- wp_enqueue_script ( 'wc-stripe-product-data' );
71
- wp_enqueue_style ( 'wc-stripe-admin-style' );
72
- wp_localize_script ( 'wc-stripe-product-data', 'wc_stripe_product_params', [
73
- '_wpnonce' => wp_create_nonce ( 'wp_rest' ),
74
- 'routes' => [
75
- 'enable_gateway' => wc_stripe ()->rest_api->product_data->rest_url ( 'gateway' ),
76
- 'save' => wc_stripe ()->rest_api->product_data->rest_url ( 'save' )
77
- ]
78
- ] );
79
- }
80
- }
81
-
82
- public static function localize_scripts() {
83
- global $current_section, $wc_stripe_subsection;
84
- if (! empty ( $current_section )) {
85
- $wc_stripe_subsection = isset ( $_GET[ 'sub_section' ] ) ? sanitize_title ( $_GET[ 'sub_section' ] ) : '';
86
- do_action ( 'wc_stripe_localize_' . $current_section . '_settings' );
87
- // added for WC 3.0.0 compatability.
88
- remove_action ( 'admin_footer', array(
89
- __CLASS__, 'localize_scripts'
90
- ) );
91
- }
92
- }
93
-
94
- public static function localize_advanced_scripts() {
95
- global $current_section, $wc_stripe_subsection;
96
- do_action ( 'wc_stripe_localize_' . $wc_stripe_subsection . '_settings' );
97
- }
98
- }
99
- 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( 'jquery', 'jquery-blockui' ), wc_stripe()->version, true );
27
+ wp_register_script( 'wc-stripe-meta-boxes-order', $js_path . 'admin/meta-boxes-order.js', array( 'jquery', 'jquery-blockui' ), wc_stripe()->version, true );
28
+ wp_register_script( 'wc-stripe-meta-boxes-subscription', $js_path . 'admin/meta-boxes-subscription.js', array( 'jquery', 'jquery-blockui' ), wc_stripe()->version, true );
29
+ wp_register_script(
30
+ 'wc-stripe-product-data',
31
+ $js_path . 'admin/meta-boxes-product-data.js',
32
+ array(
33
+ 'jquery',
34
+ 'jquery-blockui',
35
+ 'jquery-ui-sortable',
36
+ 'jquery-ui-widget',
37
+ 'jquery-ui-core',
38
+ 'jquery-tiptip',
39
+ ),
40
+ wc_stripe()->version(),
41
+ true
42
+ );
43
+ wp_register_style( 'wc-stripe-admin-style', $css_path . 'admin/admin.css', array(), wc_stripe()->version );
44
+
45
+ if ( strpos( $screen_id, 'wc-settings' ) !== false ) {
46
+ if ( isset( $_REQUEST['section'] ) && preg_match( '/stripe_[\w]*/', $_REQUEST['section'] ) ) {
47
+ wp_enqueue_script( 'wc-stripe-admin-settings' );
48
+ wp_enqueue_style( 'wc-stripe-admin-style' );
49
+ wp_enqueue_script( 'stripe-help-widget', $js_path . 'admin/help-widget.js', array(), wc_stripe()->version(), true );
50
+ wp_localize_script(
51
+ 'wc-stripe-admin-settings',
52
+ 'wc_stripe_setting_params',
53
+ array(
54
+ 'routes' => array(
55
+ 'apple_domain' => wc_stripe()->rest_api->settings->rest_url( 'apple-domain' ),
56
+ 'create_webhook' => wc_stripe()->rest_api->settings->rest_url( 'create-webook' ),
57
+ 'connection_test' => wc_stripe()->rest_api->settings->rest_url( 'connection-test' ),
58
+ ),
59
+ 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
60
+ )
61
+ );
62
+ }
63
+ }
64
+ if ( $screen_id === 'shop_order' ) {
65
+ wp_enqueue_style( 'wc-stripe-admin-style' );
66
+ }
67
+ if ( $screen_id === 'product' ) {
68
+ wp_enqueue_script( 'wc-stripe-product-data' );
69
+ wp_enqueue_style( 'wc-stripe-admin-style' );
70
+ wp_localize_script(
71
+ 'wc-stripe-product-data',
72
+ 'wc_stripe_product_params',
73
+ array(
74
+ '_wpnonce' => wp_create_nonce( 'wp_rest' ),
75
+ 'routes' => array(
76
+ 'enable_gateway' => wc_stripe()->rest_api->product_data->rest_url( 'gateway' ),
77
+ 'save' => wc_stripe()->rest_api->product_data->rest_url( 'save' ),
78
+ ),
79
+ )
80
+ );
81
+ }
82
+ }
83
+
84
+ public static function localize_scripts() {
85
+ global $current_section, $wc_stripe_subsection;
86
+ if ( ! empty( $current_section ) ) {
87
+ $wc_stripe_subsection = isset( $_GET['sub_section'] ) ? sanitize_title( $_GET['sub_section'] ) : '';
88
+ do_action( 'wc_stripe_localize_' . $current_section . '_settings' );
89
+ // added for WC 3.0.0 compatability.
90
+ remove_action( 'admin_footer', array( __CLASS__, 'localize_scripts' ) );
91
+ }
92
+ }
93
+
94
+ public static function localize_advanced_scripts() {
95
+ global $current_section, $wc_stripe_subsection;
96
+ do_action( 'wc_stripe_localize_' . $wc_stripe_subsection . '_settings' );
97
+ }
98
+ }
99
+ new WC_Stripe_Admin_Assets();
includes/admin/class-wc-stripe-admin-menus.php CHANGED
@@ -1,45 +1,39 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.0.0
7
- * @package Stripe/Admin
8
- *
9
- */
10
- class WC_Stripe_Admin_Menus {
11
-
12
- public static function init() {
13
- add_action ( 'admin_menu', array( __CLASS__,
14
- 'admin_menu'
15
- ), 10 );
16
- add_action ( 'admin_menu', array( __CLASS__,
17
- 'sub_menu'
18
- ), 20 );
19
- add_action ( 'admin_head', array( __CLASS__,
20
- 'remove_submenu'
21
- ) );
22
- }
23
-
24
- public static function admin_menu() {
25
- add_menu_page ( __ ( 'Stripe Gateway', 'woo-stripe-payment' ), __ ( 'Stripe Gateway', 'woo-stripe-payment' ), 'manage_woocommerce', 'wc_stripe', null, null, '7.458' );
26
- }
27
-
28
- public static function sub_menu() {
29
- add_submenu_page ( 'wc_stripe', __ ( 'Settings', 'woo-stripe-payment' ), __ ( 'Settings', 'woo-stripe-payment' ), 'manage_woocommerce', admin_url ( 'admin.php?page=wc-settings&tab=checkout&section=stripe_api' ) );
30
- add_submenu_page ( 'wc_stripe', __ ( 'Logs', 'woo-stripe-payment' ), __ ( 'Logs', 'woo-stripe-payment' ), 'manage_woocommerce', admin_url ( 'admin.php?page=wc-status&tab=logs' ) );
31
- add_submenu_page ( 'wc_stripe', __ ( 'Documentation', 'woo-stripe-payment' ), __ ( 'Documentation', 'woo-stripe-payment' ), 'manage_woocommerce', 'https://docs.paymentplugins.com/wc-stripe/config' );
32
- }
33
-
34
- public static function remove_submenu() {
35
- global $submenu;
36
- if (isset ( $submenu[ 'wc_stripe' ] )) {
37
- unset ( $submenu[ 'wc_stripe' ][ 0 ] );
38
- }
39
- }
40
-
41
- public static function data_migration_page() {
42
- include 'views/html-data-migration.php';
43
- }
44
- }
45
- WC_Stripe_Admin_Menus::init ();
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @since 3.0.0
7
+ * @package Stripe/Admin
8
+ *
9
+ */
10
+ class WC_Stripe_Admin_Menus {
11
+
12
+ public static function init() {
13
+ add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ), 10 );
14
+ add_action( 'admin_menu', array( __CLASS__, 'sub_menu' ), 20 );
15
+ add_action( 'admin_head', array( __CLASS__, 'remove_submenu' ) );
16
+ }
17
+
18
+ public static function admin_menu() {
19
+ add_menu_page( __( 'Stripe Gateway', 'woo-stripe-payment' ), __( 'Stripe Gateway', 'woo-stripe-payment' ), 'manage_woocommerce', 'wc_stripe', null, null, '7.458' );
20
+ }
21
+
22
+ public static function sub_menu() {
23
+ add_submenu_page( 'wc_stripe', __( 'Settings', 'woo-stripe-payment' ), __( 'Settings', 'woo-stripe-payment' ), 'manage_woocommerce', admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe_api' ) );
24
+ add_submenu_page( 'wc_stripe', __( 'Logs', 'woo-stripe-payment' ), __( 'Logs', 'woo-stripe-payment' ), 'manage_woocommerce', admin_url( 'admin.php?page=wc-status&tab=logs' ) );
25
+ add_submenu_page( 'wc_stripe', __( 'Documentation', 'woo-stripe-payment' ), __( 'Documentation', 'woo-stripe-payment' ), 'manage_woocommerce', 'https://docs.paymentplugins.com/wc-stripe/config' );
26
+ }
27
+
28
+ public static function remove_submenu() {
29
+ global $submenu;
30
+ if ( isset( $submenu['wc_stripe'] ) ) {
31
+ unset( $submenu['wc_stripe'][0] );
32
+ }
33
+ }
34
+
35
+ public static function data_migration_page() {
36
+ include 'views/html-data-migration.php';
37
+ }
38
+ }
39
+ WC_Stripe_Admin_Menus::init();
 
 
 
 
 
 
includes/admin/class-wc-stripe-admin-notices.php CHANGED
@@ -1,59 +1,67 @@
1
- <?php
2
-
3
- namespace PaymentPlugins;
4
-
5
- defined ( 'ABSPATH' ) || exit ();
6
-
7
- /**
8
- *
9
- * @since 3.1.0
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Stripe_Admin_Notices {
14
-
15
- public static function init() {
16
- add_action ( 'admin_notices', [ __CLASS__,
17
- 'notices'
18
- ] );
19
- }
20
-
21
- public static function notices() {
22
- $messages = [];
23
- foreach ( static::get_notices () as $key => $notice ) {
24
- if ($notice[ 'callback' ] ()) {
25
- $screen = get_current_screen ();
26
- $screen_id = $screen ? $screen->id : '';
27
- ob_start ();
28
- echo '<div class="notice notice-info woocommerce-message"><p>' . $notice[ 'message' ] () . '</p></div>';
29
- $message = ob_get_clean ();
30
- if (strstr ( $screen_id, 'wc-settings' )) {
31
- $messages[] = $message;
32
- } else {
33
- echo $message;
34
- }
35
- }
36
- }
37
- // in WC 4.0 admin notices don't show on the WC Settings pages so adding this workaround.
38
- if ($messages) {
39
- wp_localize_script ( 'wc-stripe-admin-settings', 'wc_stripe_admin_notices', $messages );
40
- }
41
- }
42
-
43
- public static function get_notices() {
44
- return [
45
- 'connect_notice' => [
46
- 'callback' => function () {
47
- return ( ! isset ( $_GET[ '_stripe_connect_nonce' ] ) && ( ! wc_stripe ()->api_settings->get_option ( 'account_id' ) && get_option ( 'wc_stripe_connect_notice', 'no' ) == 'yes' ) );
48
- },
49
- 'message' => function () {
50
- wp_enqueue_style ( 'wc-stripe-styles', wc_stripe ()->assets_url ( 'css/admin/admin.css' ), [], wc_stripe ()->version () );
51
- return sprintf ( __ ( 'At Stripe\'s request we have updated how the Stripe for WooCommerce
52
- plugin integrates with Stripe. This new integration offers even more security and
53
- Stripe is requesting that all merchants switch. %sUpdate Integration%s', 'woo-stripe-payment' ), '<a href="' . wc_stripe ()->api_settings->get_connect_url () . '" class="stripe-connect light-blue do-stripe-connect"><span>', '</span></a>' );
54
- }
55
- ]
56
- ];
57
- }
58
- }
59
- \PaymentPlugins\WC_Stripe_Admin_Notices::init ();
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace PaymentPlugins;
4
+
5
+ defined( 'ABSPATH' ) || exit();
6
+
7
+ /**
8
+ *
9
+ * @since 3.1.0
10
+ * @author PaymentPlugins
11
+ *
12
+ */
13
+ class WC_Stripe_Admin_Notices {
14
+
15
+ public static function init() {
16
+ add_action( 'admin_notices', array( __CLASS__, 'notices' ) );
17
+ }
18
+
19
+ public static function notices() {
20
+ $messages = array();
21
+ foreach ( static::get_notices() as $key => $notice ) {
22
+ if ( $notice['callback']() ) {
23
+ $screen = get_current_screen();
24
+ $screen_id = $screen ? $screen->id : '';
25
+ ob_start();
26
+ echo '<div class="notice notice-info woocommerce-message"><p>' . $notice['message']() . '</p></div>';
27
+ $message = ob_get_clean();
28
+ if ( strstr( $screen_id, 'wc-settings' ) ) {
29
+ $messages[] = $message;
30
+ } else {
31
+ echo $message;
32
+ }
33
+ }
34
+ }
35
+ // in WC 4.0 admin notices don't show on the WC Settings pages so adding this workaround.
36
+ if ( $messages ) {
37
+ wp_localize_script( 'wc-stripe-admin-settings', 'wc_stripe_admin_notices', $messages );
38
+ }
39
+ }
40
+
41
+ public static function get_notices() {
42
+ return array(
43
+ 'connect_notice' => array(
44
+ 'callback' => function () {
45
+ return ( ! isset( $_GET['_stripe_connect_nonce'] ) &&
46
+ ( ! wc_stripe()->api_settings->get_option( 'account_id' ) && get_option( 'wc_stripe_connect_notice', 'no' ) == 'yes' ) );
47
+ },
48
+ 'message' => function () {
49
+ wp_enqueue_style( 'wc-stripe-styles', wc_stripe()->assets_url( 'css/admin/admin.css' ), array(), wc_stripe()->version() );
50
+ return sprintf(
51
+ __(
52
+ 'At Stripe\'s request we have updated how the Stripe for WooCommerce
53
+ plugin integrates with Stripe. This new integration offers even more security and
54
+ Stripe is requesting that all merchants switch. %1$sUpdate Integration%2$s',
55
+ 'woo-stripe-payment'
56
+ ),
57
+ ' <a href = "' .
58
+ wc_stripe()->api_settings->get_connect_url() . '" class = "stripe-connect light-blue do-stripe-connect" > < span > ',
59
+ ' < / span > < / a > '
60
+ );
61
+ },
62
+ ),
63
+ );
64
+ }
65
+ }
66
+ \PaymentPlugins\WC_Stripe_Admin_Notices::init();
67
+
includes/admin/class-wc-stripe-admin-settings.php CHANGED
@@ -1,104 +1,89 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @package Stripe/Admin
7
- * @author User
8
- *
9
- */
10
- class WC_Stripe_Admin_Settings {
11
-
12
- public static function init() {
13
- add_action ( 'woocommerce_settings_checkout', array(
14
- __CLASS__, 'output'
15
- ) );
16
- add_action ( 'woocommerce_settings_checkout_stripe_advanced', array(
17
- __CLASS__, 'output_advanced_settings'
18
- ) );
19
- add_action ( 'woocommerce_settings_checkout_stripe_local_gateways', array(
20
- __CLASS__, 'output_local_gateways'
21
- ) );
22
- add_action ( 'woocommerce_update_options_checkout_stripe_local_gateways', array(
23
- __CLASS__, 'save_local_gateway'
24
- ) );
25
- add_filter ( 'wc_stripe_settings_nav_tabs', array(
26
- __CLASS__, 'admin_settings_tabs'
27
- ), 20 );
28
- add_action ( 'wc_stripe_settings_before_options_stripe_advanced', array(
29
- __CLASS__, 'before_options'
30
- ) );
31
- add_action ( 'wc_stripe_settings_before_options_stripe_local_gateways', array(
32
- __CLASS__, 'before_options'
33
- ) );
34
- add_action ( 'woocommerce_update_options_checkout', array(
35
- __CLASS__, 'deprecated_save'
36
- ) );
37
- add_filter ( 'woocommerce_get_settings_email', array(
38
- __CLASS__, 'get_email_settings'
39
- ) );
40
- }
41
-
42
- public static function output() {
43
- global $current_section;
44
- do_action ( 'woocommerce_settings_checkout_' . $current_section );
45
- }
46
-
47
- public static function output_advanced_settings() {
48
- self::output_custom_section ( '' );
49
- }
50
-
51
- public static function output_local_gateways() {
52
- self::output_custom_section ( 'stripe_ideal' );
53
- }
54
-
55
- public static function output_custom_section($sub_section = '') {
56
- global $current_section, $wc_stripe_subsection;
57
- $wc_stripe_subsection = isset ( $_GET[ 'stripe_sub_section' ] ) ? sanitize_title ( $_GET[ 'stripe_sub_section' ] ) : $sub_section;
58
- do_action ( 'woocommerce_settings_checkout_' . $current_section . '_' . $wc_stripe_subsection );
59
- }
60
-
61
- public static function save_local_gateway() {
62
- self::save_custom_section ( 'stripe_ideal' );
63
- }
64
-
65
- public static function save_custom_section($sub_section = '') {
66
- global $current_section, $wc_stripe_subsection;
67
- $wc_stripe_subsection = isset ( $_GET[ 'stripe_sub_section' ] ) ? sanitize_title ( $_GET[ 'stripe_sub_section' ] ) : $sub_section;
68
- do_action ( 'woocommerce_update_options_checkout_' . $current_section . '_' . $wc_stripe_subsection );
69
- }
70
-
71
- public static function deprecated_save() {
72
- global $current_section;
73
- if ($current_section && ! did_action ( 'woocommerce_update_options_checkout_' . $current_section )) {
74
- do_action ( 'woocommerce_update_options_checkout_' . $current_section );
75
- }
76
- }
77
-
78
- public static function admin_settings_tabs($tabs) {
79
- $tabs[ 'stripe_local_gateways' ] = __ ( 'Local Gateways', 'woo-stripe-payment' );
80
- return $tabs;
81
- }
82
-
83
- public static function before_options() {
84
- global $current_section, $wc_stripe_subsection;
85
- do_action ( 'wc_stripe_settings_before_options_' . $current_section . '_' . $wc_stripe_subsection );
86
- }
87
-
88
- public static function get_email_settings($settings) {
89
- $settings[] = [ 'type' => 'title',
90
- 'title' => __ ( 'Stripe Email Options', 'woo-stripe-payment' )
91
- ];
92
- $settings[] = [ 'type' => 'checkbox',
93
- 'title' => __ ( 'Email Receipt', 'woo-stripe-payment' ),
94
- 'id' => 'woocommerce_stripe_email_receipt',
95
- 'autoload' => false,
96
- 'desc' => __ ( 'If enabled, an email receipt will be sent to the customer by Stripe when the order is processed.', 'woo-stripe-payment' )
97
- ];
98
- $settings[] = [ 'type' => 'sectionend',
99
- 'id' => 'stripe_email'
100
- ];
101
- return $settings;
102
- }
103
- }
104
- WC_Stripe_Admin_Settings::init ();
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @package Stripe/Admin
7
+ * @author User
8
+ *
9
+ */
10
+ class WC_Stripe_Admin_Settings {
11
+
12
+ public static function init() {
13
+ add_action( 'woocommerce_settings_checkout', array( __CLASS__, 'output' ) );
14
+ add_action( 'woocommerce_settings_checkout_stripe_advanced', array( __CLASS__, 'output_advanced_settings' ) );
15
+ add_action( 'woocommerce_settings_checkout_stripe_local_gateways', array( __CLASS__, 'output_local_gateways' ) );
16
+ add_action( 'woocommerce_update_options_checkout_stripe_local_gateways', array( __CLASS__, 'save_local_gateway' ) );
17
+ add_filter( 'wc_stripe_settings_nav_tabs', array( __CLASS__, 'admin_settings_tabs' ), 20 );
18
+ add_action( 'wc_stripe_settings_before_options_stripe_advanced', array( __CLASS__, 'before_options' ) );
19
+ add_action( 'wc_stripe_settings_before_options_stripe_local_gateways', array( __CLASS__, 'before_options' ) );
20
+ add_action( 'woocommerce_update_options_checkout', array( __CLASS__, 'deprecated_save' ) );
21
+ add_filter( 'woocommerce_get_settings_email', array( __CLASS__, 'get_email_settings' ) );
22
+ }
23
+
24
+ public static function output() {
25
+ global $current_section;
26
+ do_action( 'woocommerce_settings_checkout_' . $current_section );
27
+ }
28
+
29
+ public static function output_advanced_settings() {
30
+ self::output_custom_section( '' );
31
+ }
32
+
33
+ public static function output_local_gateways() {
34
+ self::output_custom_section( 'stripe_ideal' );
35
+ }
36
+
37
+ public static function output_custom_section( $sub_section = '' ) {
38
+ global $current_section, $wc_stripe_subsection;
39
+ $wc_stripe_subsection = isset( $_GET['stripe_sub_section'] ) ? sanitize_title( $_GET['stripe_sub_section'] ) : $sub_section;
40
+ do_action( 'woocommerce_settings_checkout_' . $current_section . '_' . $wc_stripe_subsection );
41
+ }
42
+
43
+ public static function save_local_gateway() {
44
+ self::save_custom_section( 'stripe_ideal' );
45
+ }
46
+
47
+ public static function save_custom_section( $sub_section = '' ) {
48
+ global $current_section, $wc_stripe_subsection;
49
+ $wc_stripe_subsection = isset( $_GET['stripe_sub_section'] ) ? sanitize_title( $_GET['stripe_sub_section'] ) : $sub_section;
50
+ do_action( 'woocommerce_update_options_checkout_' . $current_section . '_' . $wc_stripe_subsection );
51
+ }
52
+
53
+ public static function deprecated_save() {
54
+ global $current_section;
55
+ if ( $current_section && ! did_action( 'woocommerce_update_options_checkout_' . $current_section ) ) {
56
+ do_action( 'woocommerce_update_options_checkout_' . $current_section );
57
+ }
58
+ }
59
+
60
+ public static function admin_settings_tabs( $tabs ) {
61
+ $tabs['stripe_local_gateways'] = __( 'Local Gateways', 'woo-stripe-payment' );
62
+ return $tabs;
63
+ }
64
+
65
+ public static function before_options() {
66
+ global $current_section, $wc_stripe_subsection;
67
+ do_action( 'wc_stripe_settings_before_options_' . $current_section . '_' . $wc_stripe_subsection );
68
+ }
69
+
70
+ public static function get_email_settings( $settings ) {
71
+ $settings[] = array(
72
+ 'type' => 'title',
73
+ 'title' => __( 'Stripe Email Options', 'woo-stripe-payment' ),
74
+ );
75
+ $settings[] = array(
76
+ 'type' => 'checkbox',
77
+ 'title' => __( 'Email Receipt', 'woo-stripe-payment' ),
78
+ 'id' => 'woocommerce_stripe_email_receipt',
79
+ 'autoload' => false,
80
+ 'desc' => __( 'If enabled, an email receipt will be sent to the customer by Stripe when the order is processed.', 'woo-stripe-payment' ),
81
+ );
82
+ $settings[] = array(
83
+ 'type' => 'sectionend',
84
+ 'id' => 'stripe_email',
85
+ );
86
+ return $settings;
87
+ }
88
+ }
89
+ WC_Stripe_Admin_Settings::init();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/admin/class-wc-stripe-admin-user-edit.php CHANGED
@@ -1,114 +1,109 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.0.0
7
- * @package Stripe/Admin
8
- * @author PaymentPlugins
9
- *
10
- */
11
- class WC_Stripe_Admin_User_Edit {
12
-
13
- public static function init() {
14
- add_action ( 'edit_user_profile', array(
15
- __CLASS__, 'output'
16
- ) );
17
- add_action ( 'show_user_profile', array(
18
- __CLASS__, 'output'
19
- ) );
20
- add_action ( 'edit_user_profile_update', array(
21
- __CLASS__, 'save'
22
- ) );
23
- add_action ( 'personal_options_update', array(
24
- __CLASS__, 'save'
25
- ) );
26
- }
27
-
28
- /**
29
- *
30
- * @param WP_User $user
31
- */
32
- public static function output($user) {
33
- // enquue scripts
34
- wp_enqueue_style ( 'wc-stripe-admin-style' );
35
-
36
- remove_filter ( 'woocommerce_get_customer_payment_tokens', 'wc_stripe_get_customer_payment_tokens' );
37
- // get payment methods for all environments.
38
- $tokens = WC_Payment_Tokens::get_customer_tokens ( $user->ID );
39
- $payment_methods = array( 'live' => array(),
40
- 'test' => array()
41
- );
42
- foreach ( $tokens as $token ) {
43
- if ($token instanceof WC_Payment_Token_Stripe) {
44
- if ('live' === $token->get_environment ()) {
45
- $payment_methods[ 'live' ][] = $token;
46
- } else {
47
- $payment_methods[ 'test' ][] = $token;
48
- }
49
- }
50
- }
51
- include wc_stripe ()->plugin_path () . 'includes/admin/views/html-user-profile.php';
52
- }
53
-
54
- /**
55
- *
56
- * @param int $user_id
57
- */
58
- public static function save($user_id) {
59
- $modes = array( 'test', 'live'
60
- );
61
- if (isset ( $_POST[ 'wc_stripe_live_id' ] )) {
62
- $old_live_id = wc_stripe_get_customer_id ( $user_id, 'live' );
63
- wc_stripe_save_customer ( wc_clean ( $_POST[ 'wc_stripe_live_id' ] ), $user_id, 'live' );
64
- }
65
- if (isset ( $_POST[ 'wc_stripe_test_id' ] )) {
66
- $old_test_id = wc_stripe_get_customer_id ( $user_id, 'test' );
67
- wc_stripe_save_customer ( wc_clean ( $_POST[ 'wc_stripe_test_id' ] ), $user_id, 'test' );
68
- }
69
-
70
- // check if admin want's to delete any payment methods
71
- foreach ( $modes as $mode ) {
72
- if (isset ( $_POST[ $mode . '_payment_method_actions' ] )) {
73
- switch (wc_clean ( $_POST[ $mode . '_payment_method_actions' ] )) {
74
- case 'delete' :
75
- if (isset ( $_POST[ 'payment_methods' ], $_POST[ 'payment_methods' ][ $mode ] )) {
76
- $tokens = $_POST[ 'payment_methods' ][ $mode ];
77
- foreach ( $tokens as $token_id ) {
78
- WC_Payment_Tokens::delete ( absint ( $token_id ) );
79
- }
80
- }
81
- break;
82
- }
83
- }
84
- }
85
-
86
- $changes = array(
87
- 'live' => $old_live_id !== wc_stripe_get_customer_id ( $user_id, 'live' ),
88
- 'test' => $old_test_id !== wc_stripe_get_customer_id ( $user_id, 'test' )
89
- );
90
- $gateway = WC_Stripe_Gateway::load ();
91
-
92
- // this will prevent the payment method from being deleted in Stripe. We only want to remove the tokens
93
- // from the WC tables.
94
- remove_action ( 'woocommerce_payment_token_deleted', 'wc_stripe_woocommerce_payment_token_deleted', 10 );
95
-
96
- // if the value has changed, then remove old payment methods and import new ones.
97
- foreach ( $changes as $mode => $change ) {
98
- if ($change) {
99
- // Delete all current payment methods in WC then save new ones.
100
- $tokens = WC_Payment_Tokens::get_customer_tokens ( $user_id );
101
- foreach ( $tokens as $token ) {
102
- if ($token instanceof WC_Payment_Token_Stripe) {
103
- if ($mode === $token->get_environment ()) {
104
- WC_Payment_Tokens::delete ( $token->get_id () );
105
- }
106
- }
107
- }
108
- // import payment methods from Stripe.
109
- WC_Stripe_Customer_Manager::sync_payment_methods ( wc_stripe_get_customer_id ( $user_id, $mode ), $user_id );
110
- }
111
- }
112
- }
113
- }
114
- WC_Stripe_Admin_User_Edit::init ();
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @since 3.0.0
7
+ * @package Stripe/Admin
8
+ * @author PaymentPlugins
9
+ *
10
+ */
11
+ class WC_Stripe_Admin_User_Edit {
12
+
13
+ public static function init() {
14
+ add_action( 'edit_user_profile', array( __CLASS__, 'output' ) );
15
+ add_action( 'show_user_profile', array( __CLASS__, 'output' ) );
16
+ add_action( 'edit_user_profile_update', array( __CLASS__, 'save' ) );
17
+ add_action( 'personal_options_update', array( __CLASS__, 'save' ) );
18
+ }
19
+
20
+ /**
21
+ *
22
+ * @param WP_User $user
23
+ */
24
+ public static function output( $user ) {
25
+ // enquue scripts
26
+ wp_enqueue_style( 'wc-stripe-admin-style' );
27
+
28
+ remove_filter( 'woocommerce_get_customer_payment_tokens', 'wc_stripe_get_customer_payment_tokens' );
29
+ // get payment methods for all environments.
30
+ $tokens = WC_Payment_Tokens::get_customer_tokens( $user->ID );
31
+ $payment_methods = array(
32
+ 'live' => array(),
33
+ 'test' => array(),
34
+ );
35
+ foreach ( $tokens as $token ) {
36
+ if ( $token instanceof WC_Payment_Token_Stripe ) {
37
+ if ( 'live' === $token->get_environment() ) {
38
+ $payment_methods['live'][] = $token;
39
+ } else {
40
+ $payment_methods['test'][] = $token;
41
+ }
42
+ }
43
+ }
44
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-user-profile.php';
45
+ }
46
+
47
+ /**
48
+ *
49
+ * @param int $user_id
50
+ */
51
+ public static function save( $user_id ) {
52
+ $modes = array( 'test', 'live' );
53
+ if ( isset( $_POST['wc_stripe_live_id'] ) ) {
54
+ $old_live_id = wc_stripe_get_customer_id( $user_id, 'live' );
55
+ wc_stripe_save_customer( wc_clean( $_POST['wc_stripe_live_id'] ), $user_id, 'live' );
56
+ }
57
+ if ( isset( $_POST['wc_stripe_test_id'] ) ) {
58
+ $old_test_id = wc_stripe_get_customer_id( $user_id, 'test' );
59
+ wc_stripe_save_customer( wc_clean( $_POST['wc_stripe_test_id'] ), $user_id, 'test' );
60
+ }
61
+
62
+ // check if admin want's to delete any payment methods
63
+ foreach ( $modes as $mode ) {
64
+ if ( isset( $_POST[ $mode . '_payment_method_actions' ] ) ) {
65
+ switch ( wc_clean( $_POST[ $mode . '_payment_method_actions' ] ) ) {
66
+ case 'delete':
67
+ if ( isset( $_POST['payment_methods'], $_POST['payment_methods'][ $mode ] ) ) {
68
+ $tokens = $_POST['payment_methods'][ $mode ];
69
+ foreach ( $tokens as $token_id ) {
70
+ WC_Payment_Tokens::delete( absint( $token_id ) );
71
+ }
72
+ }
73
+ break;
74
+ }
75
+ }
76
+ }
77
+
78
+ $changes = array(
79
+ 'live' => $old_live_id !== wc_stripe_get_customer_id( $user_id, 'live' ),
80
+ 'test' => $old_test_id !== wc_stripe_get_customer_id( $user_id, 'test' ),
81
+ );
82
+ $gateway = WC_Stripe_Gateway::load();
83
+
84
+ // this will prevent the payment method from being deleted in Stripe. We only want to remove the tokens
85
+ // from the WC tables.
86
+ remove_action( 'woocommerce_payment_token_deleted', 'wc_stripe_woocommerce_payment_token_deleted', 10 );
87
+
88
+ // want results to return tokens for all modes
89
+ remove_action( 'woocommerce_get_customer_payment_tokens', 'wc_stripe_get_customer_payment_tokens' );
90
+
91
+ // if the value has changed, then remove old payment methods and import new ones.
92
+ foreach ( $changes as $mode => $change ) {
93
+ if ( $change ) {
94
+ // Delete all current payment methods in WC then save new ones.
95
+ $tokens = WC_Payment_Tokens::get_customer_tokens( $user_id );
96
+ foreach ( $tokens as $token ) {
97
+ if ( $token instanceof WC_Payment_Token_Stripe ) {
98
+ if ( $mode === $token->get_environment() ) {
99
+ WC_Payment_Tokens::delete( $token->get_id() );
100
+ }
101
+ }
102
+ }
103
+ // import payment methods from Stripe.
104
+ WC_Stripe_Customer_Manager::sync_payment_methods( wc_stripe_get_customer_id( $user_id, $mode ), $user_id, $mode );
105
+ }
106
+ }
107
+ }
108
+ }
109
+ WC_Stripe_Admin_User_Edit::init();
 
 
 
 
 
includes/admin/meta-boxes/class-wc-stripe-admin-meta-box-product-data.php CHANGED
@@ -1,97 +1,92 @@
1
- <?php
2
-
3
- namespace PaymentPlugins;
4
-
5
- class WC_Stripe_Admin_Meta_Box_Product_Data {
6
-
7
- private static $_gateways = [];
8
-
9
- private static $_options = [];
10
-
11
- public static function init() {
12
- add_filter ( 'woocommerce_product_data_tabs', [
13
- __CLASS__, 'product_data_tabs'
14
- ] );
15
- add_action ( 'woocommerce_product_data_panels', [
16
- __CLASS__, 'output_panel'
17
- ] );
18
- add_action ( 'woocommerce_admin_process_product_object', [
19
- __CLASS__, 'save'
20
- ] );
21
- }
22
-
23
- public static function product_data_tabs($tabs) {
24
- $tabs[ 'stripe' ] = [
25
- 'label' => __ ( 'Stripe Settings', 'woo-stripe-payment' ),
26
- 'target' => 'stripe_product_data',
27
- 'class' => [], 'priority' => 100
28
- ];
29
- return $tabs;
30
- }
31
-
32
- public static function output_panel() {
33
- global $product_object;
34
-
35
- self::init_gateways ( $product_object );
36
-
37
- include 'views/html-product-data.php';
38
- }
39
-
40
- private static function init_gateways($product) {
41
- $order = $product->get_meta ( \WC_Stripe_Constants::PRODUCT_GATEWAY_ORDER );
42
- $order = ! $order ? [] : $order;
43
- foreach ( WC ()->payment_gateways ()->payment_gateways () as $gateway ) {
44
- if ($gateway->supports ( 'wc_stripe_product_checkout' )) {
45
- if (isset ( $order[ $gateway->id ] )) {
46
- self::$_gateways[ $order[ $gateway->id ] ] = $gateway;
47
- } else {
48
- self::$_gateways[] = $gateway;
49
- }
50
- self::$_options[ $gateway->id ] = new \WC_Stripe_Product_Gateway_Option ( $product, $gateway );
51
- }
52
- }
53
- ksort ( self::$_gateways );
54
- }
55
-
56
- private static function get_product_option($gateway_id) {
57
- return self::$_options[ $gateway_id ];
58
- }
59
-
60
- private static function get_payment_gateways() {
61
- foreach ( self::$_gateways as $gateway ) {
62
- $gateways[ $gateway->id ] = $gateway;
63
- }
64
- return $gateways;
65
- }
66
-
67
- /**
68
- *
69
- * @param \WC_Product $product
70
- */
71
- public static function save($product) {
72
- // only update the settings if something has been changed.
73
- if (empty ( $_POST[ 'wc_stripe_update_product' ] )) {
74
- return;
75
- }
76
- $loop = 0;
77
- $order = [];
78
- self::init_gateways ( $product );
79
- $payment_gateways = self::get_payment_gateways ();
80
-
81
- if (isset ( $_POST[ 'stripe_gateway_order' ] )) {
82
- foreach ( $_POST[ 'stripe_gateway_order' ] as $i => $gateway ) {
83
- $order[ $gateway ] = $loop;
84
- if (isset ( $_POST[ 'stripe_capture_type' ] )) {
85
- self::get_product_option ( $gateway )->set_option ( 'charge_type', $_POST[ 'stripe_capture_type' ][ $i ] );
86
- self::get_product_option ( $gateway )->save ();
87
- }
88
- $loop ++;
89
- }
90
- }
91
- if (isset ( $_POST[ '_stripe_button_position' ] )) {
92
- $product->update_meta_data ( '_stripe_button_position', wc_clean ( $_POST[ '_stripe_button_position' ] ) );
93
- }
94
- $product->update_meta_data ( \WC_Stripe_Constants::PRODUCT_GATEWAY_ORDER, $order );
95
- }
96
- }
97
- \PaymentPlugins\WC_Stripe_Admin_Meta_Box_Product_Data::init ();
1
+ <?php
2
+
3
+ namespace PaymentPlugins;
4
+
5
+ class WC_Stripe_Admin_Meta_Box_Product_Data {
6
+
7
+ private static $_gateways = array();
8
+
9
+ private static $_options = array();
10
+
11
+ public static function init() {
12
+ add_filter( 'woocommerce_product_data_tabs', array( __CLASS__, 'product_data_tabs' ) );
13
+ add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'output_panel' ) );
14
+ add_action( 'woocommerce_admin_process_product_object', array( __CLASS__, 'save' ) );
15
+ }
16
+
17
+ public static function product_data_tabs( $tabs ) {
18
+ $tabs['stripe'] = array(
19
+ 'label' => __( 'Stripe Settings', 'woo-stripe-payment' ),
20
+ 'target' => 'stripe_product_data',
21
+ 'class' => array(),
22
+ 'priority' => 100,
23
+ );
24
+ return $tabs;
25
+ }
26
+
27
+ public static function output_panel() {
28
+ global $product_object;
29
+
30
+ self::init_gateways( $product_object );
31
+
32
+ include 'views/html-product-data.php';
33
+ }
34
+
35
+ private static function init_gateways( $product ) {
36
+ $order = $product->get_meta( \WC_Stripe_Constants::PRODUCT_GATEWAY_ORDER );
37
+ $order = ! $order ? array() : $order;
38
+ foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
39
+ if ( $gateway->supports( 'wc_stripe_product_checkout' ) ) {
40
+ if ( isset( $order[ $gateway->id ] ) ) {
41
+ self::$_gateways[ $order[ $gateway->id ] ] = $gateway;
42
+ } else {
43
+ self::$_gateways[] = $gateway;
44
+ }
45
+ self::$_options[ $gateway->id ] = new \WC_Stripe_Product_Gateway_Option( $product, $gateway );
46
+ }
47
+ }
48
+ ksort( self::$_gateways );
49
+ }
50
+
51
+ private static function get_product_option( $gateway_id ) {
52
+ return self::$_options[ $gateway_id ];
53
+ }
54
+
55
+ private static function get_payment_gateways() {
56
+ foreach ( self::$_gateways as $gateway ) {
57
+ $gateways[ $gateway->id ] = $gateway;
58
+ }
59
+ return $gateways;
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @param \WC_Product $product
65
+ */
66
+ public static function save( $product ) {
67
+ // only update the settings if something has been changed.
68
+ if ( empty( $_POST['wc_stripe_update_product'] ) ) {
69
+ return;
70
+ }
71
+ $loop = 0;
72
+ $order = array();
73
+ self::init_gateways( $product );
74
+ $payment_gateways = self::get_payment_gateways();
75
+
76
+ if ( isset( $_POST['stripe_gateway_order'] ) ) {
77
+ foreach ( $_POST['stripe_gateway_order'] as $i => $gateway ) {
78
+ $order[ $gateway ] = $loop;
79
+ if ( isset( $_POST['stripe_capture_type'] ) ) {
80
+ self::get_product_option( $gateway )->set_option( 'charge_type', $_POST['stripe_capture_type'][ $i ] );
81
+ self::get_product_option( $gateway )->save();
82
+ }
83
+ $loop++;
84
+ }
85
+ }
86
+ if ( isset( $_POST['_stripe_button_position'] ) ) {
87
+ $product->update_meta_data( '_stripe_button_position', wc_clean( $_POST['_stripe_button_position'] ) );
88
+ }
89
+ $product->update_meta_data( \WC_Stripe_Constants::PRODUCT_GATEWAY_ORDER, $order );
90
+ }
91
+ }
92
+ \PaymentPlugins\WC_Stripe_Admin_Meta_Box_Product_Data::init();
 
 
 
 
 
includes/admin/meta-boxes/class-wc-stripe-admin-order-metaboxes.php CHANGED
@@ -1,105 +1,104 @@
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__,
14
- 'add_meta_boxes'
15
- ), 10, 2 );
16
- }
17
-
18
- /**
19
- *
20
- * @param string $post_type
21
- * @param WP_Post $post
22
- */
23
- public static function add_meta_boxes($post_type, $post) {
24
- // only add meta box if shop_order and Stripe gateway was used.
25
- if ($post_type !== 'shop_order') {
26
- return;
27
- }
28
-
29
- add_action ( 'woocommerce_admin_order_data_after_order_details', array(
30
- __CLASS__, 'pay_order_section'
31
- ) );
32
-
33
- $order = wc_get_order ( $post->ID );
34
- $payment_method = $order->get_payment_method ();
35
- if ($payment_method) {
36
- $gateways = WC ()->payment_gateways ()->payment_gateways ();
37
- if (isset ( $gateways[ $payment_method ] )) {
38
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $payment_method ];
39
- if ($gateway instanceof WC_Payment_Gateway_Stripe) {
40
- add_action ( 'woocommerce_admin_order_data_after_billing_address', array(
41
- __CLASS__, 'charge_data_view'
42
- ) );
43
- }
44
- }
45
- }
46
- self::enqueue_scripts ();
47
- }
48
-
49
- /**
50
- *
51
- * @param WC_Order $order
52
- */
53
- public static function charge_data_view($order) {
54
- if (( $transaction_id = $order->get_transaction_id () )) {
55
- include 'views/html-order-charge-data.php';
56
- }
57
- }
58
-
59
- /**
60
- *
61
- * @param WC_Order $order
62
- */
63
- public static function pay_order_section($order) {
64
- if ($order->get_type () === 'shop_order' && $order->has_status ( [
65
- 'pending', 'auto-draft'
66
- ] )) {
67
- include 'views/html-order-pay.php';
68
- $payment_methods = array();
69
- foreach ( WC ()->payment_gateways ()->payment_gateways () as $gateway ) {
70
- if ($gateway instanceof WC_Payment_Gateway_Stripe) {
71
- $payment_methods = array_merge ( $payment_methods, WC_Payment_Tokens::get_customer_tokens ( $order->get_user_id (), $gateway->id ) );
72
- }
73
- }
74
- wp_enqueue_script ( 'wc-stripe-elements', 'https://js.stripe.com/v3/', array(), wc_stripe ()->version, true );
75
- wp_localize_script ( 'wc-stripe-elements', 'wc_stripe_order_pay_params', array(
76
- 'api_key' => wc_stripe_get_publishable_key (),
77
- 'payment_methods' => array_map ( function ($payment_method) {
78
- return $payment_method->to_json ();
79
- }, $payment_methods ),
80
- 'order_status' => $order->get_status ()
81
- ) );
82
- wp_enqueue_script ( 'wc-stripe-admin-modals', wc_stripe ()->assets_url ( 'js/admin/modals.js' ), array(
83
- 'wc-backbone-modal', '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', 'jquery-blockui'
91
- ), wc_stripe ()->version (), true );
92
-
93
- wp_localize_script ( 'wc-stripe-order-metabox', 'wc_stripe_order_metabox_params', array(
94
- '_wpnonce' => wp_create_nonce ( 'wp_rest' ),
95
- 'routes' => array(
96
- 'charge_view' => wc_stripe ()->rest_api->order_actions->rest_url ( 'charge-view' ),
97
- 'capture' => wc_stripe ()->rest_api->order_actions->rest_url ( 'capture' ),
98
- 'void' => wc_stripe ()->rest_api->order_actions->rest_url ( 'void' ),
99
- 'pay' => wc_stripe ()->rest_api->order_actions->rest_url ( 'pay' ),
100
- 'payment_methods' => wc_stripe ()->rest_api->order_actions->rest_url ( 'customer-payment-methods' )
101
- )
102
- ) );
103
- }
104
- }
105
- 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( '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();
 
includes/admin/meta-boxes/views/html-charge-data-subview.php CHANGED
@@ -1,88 +1,90 @@
1
- <?php
2
- /**
3
- * @var \Stripe\Charge $charge
4
- */
5
- ?>
6
- <?php if(!$order->has_status('cancelled')):?>
7
- <?php if(($charge->status === 'pending' && !$charge->captured) || ($charge->status === 'succeeded' && !$charge->captured)):?>
8
- <div class="charge-actions">
9
- <h2><?php _e('Actions', 'woo-stripe-payment')?></h2>
10
- <div>
11
- <input type="text" class="wc_input_price" name="capture_amount"
12
- value="<?php echo $order->get_total()?>"
13
- placeholder="<?php _e('capture amount', 'woo-stripe-payment')?>" />
14
- <button class="button button-secondary do-api-capture"><?php _e('Capture', 'woo-stripe-payment')?></button>
15
- <button class="button button-secondary do-api-cancel"><?php _e('Void', 'woo-stripe-payment')?></button>
16
- </div>
17
- </div>
18
- <?php endif;?>
19
- <?php endif;?>
20
- <div class="data-container">
21
- <div class="charge-data column-6">
22
- <h3><?php _e('Charge Data', 'woo-stripe-payment')?></h3>
23
- <div class="metadata">
24
- <label><?php _e('Mode', 'woo-stripe-payment')?></label>:&nbsp;
25
- <?php $charge->livemode ? _e('Live', 'woo-stripe-payment') : _e('Test', 'wo0o-stripe')?>
26
- </div>
27
- <div class="metadata">
28
- <label><?php _e('Status', 'woo-stripe-payment')?></label>:&nbsp;
29
- <?php echo $charge->status;?>
30
- </div>
31
- <?php if(($payment_intent_id = $order->get_meta('_payment_intent_id', true))):?>
32
- <div class="metadata">
33
- <label><?php _e('Payment Intent', 'woo-stripe-payment')?></label>:&nbsp;
34
- <?php echo $payment_intent_id?>
35
- </div>
36
- <?php endif;?>
37
- <?php if(isset($charge->customer)):?>
38
- <div class="metadata">
39
- <label><?php _e('Customer', 'woo-stripe-payment')?></label>:&nbsp;
40
- <?php echo $charge->customer?>
41
- </div>
42
- <?php endif;?>
43
- </div>
44
- <div class="payment-data column-6">
45
- <h3><?php _e('Payment Method', 'woo-stripe-payment')?></h3>
46
- <div class="metadata">
47
- <label><?php _e('Title', 'woo-stripe-payment')?></label>:&nbsp;
48
- <?php echo $order->get_payment_method_title()?>
49
- </div>
50
- <div class="metadata">
51
- <label><?php _e('Type', 'woo-stripe-payment')?></label>:&nbsp;
52
- <?php echo $charge->payment_method_details->type;?>
53
- </div>
54
- <?php if(isset($charge->payment_method_details->card)):?>
55
- <div class="metadata">
56
- <label><?php _e('Exp', 'woo-stripe-payment')?>:&nbsp;</label>
57
- <?php printf('%02d / %s', $charge->payment_method_details->card->exp_month, $charge->payment_method_details->card->exp_year)?>
58
- </div>
59
- <div class="metadata">
60
- <label><?php _e('Fingerprint', 'woo-stripe-payment')?>:&nbsp;</label>
61
- <?php echo $charge->payment_method_details->card->fingerprint;?>
62
- </div>
63
- <div class="metadata">
64
- <label><?php _e('CVC check', 'woo-stripe-payment')?>:&nbsp;</label>
65
- <?php echo $charge->payment_method_details->card->checks->cvc_check;?>
66
- </div>
67
- <div class="metadata">
68
- <label><?php _e('Postal check', 'woo-stripe-payment')?>:&nbsp;</label>
69
- <?php echo $charge->payment_method_details->card->checks->address_postal_code_check;?>
70
- </div>
71
- <div class="metadata">
72
- <label><?php _e('Street check', 'woo-stripe-payment')?>:&nbsp;</label>
73
- <?php echo $charge->payment_method_details->card->checks->address_line1_check;?>
74
- </div>
75
- <?php endif;?>
76
- </div>
77
- <div class="payment-data column-6">
78
- <h3><?php _e('Riska Data', 'woo-stripe-payment')?></h3>
79
- <div class="metadata">
80
- <label><?php _e('Score', 'woo-stripe-payment')?></label>
81
- <?php echo $charge->outcome->risk_score;?>
82
- </div>
83
- <div class="metadata">
84
- <label><?php _e('Level', 'woo-stripe-payment')?></label>
85
- <?php echo $charge->outcome->risk_level;?>
86
- </div>
87
- </div>
88
- </div>
 
 
1
+ <?php
2
+ /**
3
+ * @var \Stripe\Charge $charge
4
+ */
5
+ ?>
6
+ <?php if ( ! $order->has_status( 'cancelled' ) ) : ?>
7
+ <?php if ( ( $charge->status === 'pending' && ! $charge->captured ) || ( $charge->status === 'succeeded' && ! $charge->captured ) ) : ?>
8
+ <div class="charge-actions">
9
+ <h2><?php _e( 'Actions', 'woo-stripe-payment' ); ?></h2>
10
+ <div>
11
+ <input type="text" class="wc_input_price" name="capture_amount"
12
+ value="<?php echo $order->get_total(); ?>"
13
+ placeholder="<?php _e( 'capture amount', 'woo-stripe-payment' ); ?>"/>
14
+ <button class="button button-secondary do-api-capture"><?php _e( 'Capture', 'woo-stripe-payment' ); ?></button>
15
+ <button class="button button-secondary do-api-cancel"><?php _e( 'Void', 'woo-stripe-payment' ); ?></button>
16
+ </div>
17
+ </div>
18
+ <?php endif; ?>
19
+ <?php endif; ?>
20
+ <div class="data-container">
21
+ <div class="charge-data column-6">
22
+ <h3><?php _e( 'Charge Data', 'woo-stripe-payment' ); ?></h3>
23
+ <div class="metadata">
24
+ <label><?php _e( 'Mode', 'woo-stripe-payment' ); ?></label>:&nbsp;
25
+ <?php $charge->livemode ? _e( 'Live', 'woo-stripe-payment' ) : _e( 'Test', 'wo0o-stripe' ); ?>
26
+ </div>
27
+ <div class="metadata">
28
+ <label><?php _e( 'Status', 'woo-stripe-payment' ); ?></label>:&nbsp;
29
+ <?php echo $charge->status; ?>
30
+ </div>
31
+ <?php if ( ( $payment_intent_id = $order->get_meta( '_payment_intent_id', true ) ) ) : ?>
32
+ <div class="metadata">
33
+ <label><?php _e( 'Payment Intent', 'woo-stripe-payment' ); ?></label>:&nbsp;
34
+ <?php echo $payment_intent_id; ?>
35
+ </div>
36
+ <?php endif; ?>
37
+ <?php if ( isset( $charge->customer ) ) : ?>
38
+ <div class="metadata">
39
+ <label><?php _e( 'Customer', 'woo-stripe-payment' ); ?></label>:&nbsp;
40
+ <?php echo $charge->customer; ?>
41
+ </div>
42
+ <?php endif; ?>
43
+ </div>
44
+ <div class="payment-data column-6">
45
+ <h3><?php _e( 'Payment Method', 'woo-stripe-payment' ); ?></h3>
46
+ <div class="metadata">
47
+ <label><?php _e( 'Title', 'woo-stripe-payment' ); ?></label>:&nbsp;
48
+ <?php echo $order->get_payment_method_title(); ?>
49
+ </div>
50
+ <div class="metadata">
51
+ <label><?php _e( 'Type', 'woo-stripe-payment' ); ?></label>:&nbsp;
52
+ <?php echo $charge->payment_method_details->type; ?>
53
+ </div>
54
+ <?php if ( isset( $charge->payment_method_details->card ) ) : ?>
55
+ <div class="metadata">
56
+ <label><?php _e( 'Exp', 'woo-stripe-payment' ); ?>:&nbsp;</label>
57
+ <?php printf( '%02d / %s', $charge->payment_method_details->card->exp_month, $charge->payment_method_details->card->exp_year ); ?>
58
+ </div>
59
+ <div class="metadata">
60
+ <label><?php _e( 'Fingerprint', 'woo-stripe-payment' ); ?>:&nbsp;</label>
61
+ <?php echo $charge->payment_method_details->card->fingerprint; ?>
62
+ </div>
63
+ <div class="metadata">
64
+ <label><?php _e( 'CVC check', 'woo-stripe-payment' ); ?>:&nbsp;</label>
65
+ <?php echo $charge->payment_method_details->card->checks->cvc_check; ?>
66
+ </div>
67
+ <div class="metadata">
68
+ <label><?php _e( 'Postal check', 'woo-stripe-payment' ); ?>:&nbsp;</label>
69
+ <?php echo $charge->payment_method_details->card->checks->address_postal_code_check; ?>
70
+ </div>
71
+ <div class="metadata">
72
+ <label><?php _e( 'Street check', 'woo-stripe-payment' ); ?>:&nbsp;</label>
73
+ <?php echo $charge->payment_method_details->card->checks->address_line1_check; ?>
74
+ </div>
75
+ <?php endif; ?>
76
+ </div>
77
+ <div class="payment-data column-6">
78
+ <h3><?php _e( 'Riska Data', 'woo-stripe-payment' ); ?></h3>
79
+ <?php if ( isset( $charge->outcome->risk_score ) ) { ?>
80
+ <div class="metadata">
81
+ <label><?php _e( 'Score', 'woo-stripe-payment' ); ?></label>
82
+ <?php echo $charge->outcome->risk_score; ?>
83
+ </div>
84
+ <?php } ?>
85
+ <div class="metadata">
86
+ <label><?php _e( 'Level', 'woo-stripe-payment' ); ?></label>
87
+ <?php echo $charge->outcome->risk_level; ?>
88
+ </div>
89
+ </div>
90
+ </div>
includes/admin/meta-boxes/views/html-order-actions.php CHANGED
@@ -1,47 +1,53 @@
1
- <p><b><?php _e('Charge Status', 'woo-stripe-payment')?>:</b>&nbsp;<?php echo ucfirst(str_replace('_', ' ', $status))?></p>
2
- <?php if($status === 'pending' && $order->get_meta('_authorization_exp_at')):
3
- $date = new DateTime('@' . $order->get_meta('_authorization_exp_at'));
4
- ?>
5
- <p><b><?php _e('Authorization Expires', 'woo-stripe-payment')?>:</b>&nbsp;<?php echo date_format($date, 'M d Y, h:i A e')?>
6
- <?php endif;?>
7
- <?php
8
- switch ($status) {
9
- case 'succeeded' :
10
- case 'faied' :
11
- ?>
12
- <p><?php _e ( 'There are no actions available at this time.', 'woo-stripe-payment' )?></p>
 
 
 
 
 
 
13
  <?php
14
- return;
15
- }
16
- $can_settle = $status === 'pending';
17
- ?>
18
- <div id="wc-stripe-actions">
19
- <div class="wc-stripe-buttons-container">
20
- <?php if($can_settle):?>
21
- <button type="button" class="button capture-charge"><?php esc_html_e('Capture Charge', 'woo-stripe-payment')?></button>
22
- <?php endif;?>
23
- </div>
24
- <div class="wc-order-data-row wc-order-capture-charge"
25
- style="display: none;">
26
- <div class="wc-order-capture-charge-container">
27
- <table class="wc-order-capture-charge">
28
- <tr>
29
- <td class="label"><?php esc_html_e('Total available to capture', 'woo-stripe-payment')?>:</td>
30
- <td class="total"><?php echo wc_price($order->get_total())?></td>
31
- </tr>
32
- <tr>
33
- <td class="label"><?php esc_html_e('Amount To Capture', 'woo-stripe-payment')?>:</td>
34
- <td class="total"><input type="text" id="worldpay_capture_amount"
35
- name="capture_amount" class="wc_input_price" />
36
- <div class="clear"></div></td>
37
- </tr>
38
- </table>
39
- </div>
40
- <div class="clear"></div>
41
- <div class="capture-actions">
42
- <button type="button" class="button button-primary do-api-capture"><?php esc_html_e( 'Capture', 'woo-stripe-payment' ); ?></button>
43
- <button type="button" class="button cancel-action"><?php esc_html_e( 'Cancel', 'woo-stripe-payment' ); ?></button>
44
- </div>
45
- <div class="clear"></div>
46
- </div>
47
- </div>
1
+ <p>
2
+ <b><?php _e( 'Charge Status', 'woo-stripe-payment' ); ?>:</b>&nbsp;<?php echo ucfirst( str_replace( '_', ' ', $status ) ); ?></p>
3
+ <?php
4
+
5
+ if ( $status === 'pending' && $order->get_meta( '_authorization_exp_at' ) ) :
6
+ $date = new DateTime( '@' . $order->get_meta( '_authorization_exp_at' ) );
7
+ ?>
8
+ <p>
9
+ <b><?php _e( 'Authorization Expires', 'woo-stripe-payment' ); ?>:</b>&nbsp;<?php echo date_format( $date, 'M d Y, h:i A e' ); ?>
10
+ <?php endif; ?>
11
+ <?php
12
+
13
+ switch ( $status ) {
14
+ case 'succeeded':
15
+ case 'faied':
16
+ ?>
17
+
18
+ <p><?php _e( 'There are no actions available at this time.', 'woo-stripe-payment' ); ?></p>
19
  <?php
20
+ return;
21
+ }
22
+ $can_settle = $status === 'pending';
23
+ ?>
24
+ <div id="wc-stripe-actions">
25
+ <div class="wc-stripe-buttons-container">
26
+ <?php if ( $can_settle ) : ?>
27
+ <button type="button" class="button capture-charge"><?php esc_html_e( 'Capture Charge', 'woo-stripe-payment' ); ?></button>
28
+ <?php endif; ?>
29
+ </div>
30
+ <div class="wc-order-data-row wc-order-capture-charge"
31
+ style="display: none;">
32
+ <div class="wc-order-capture-charge-container">
33
+ <table class="wc-order-capture-charge">
34
+ <tr>
35
+ <td class="label"><?php esc_html_e( 'Total available to capture', 'woo-stripe-payment' ); ?>:</td>
36
+ <td class="total"><?php echo wc_price( $order->get_total() ); ?></td>
37
+ </tr>
38
+ <tr>
39
+ <td class="label"><?php esc_html_e( 'Amount To Capture', 'woo-stripe-payment' ); ?>:</td>
40
+ <td class="total"><input type="text" id="worldpay_capture_amount"
41
+ name="capture_amount" class="wc_input_price" />
42
+ <div class="clear"></div></td>
43
+ </tr>
44
+ </table>
45
+ </div>
46
+ <div class="clear"></div>
47
+ <div class="capture-actions">
48
+ <button type="button" class="button button-primary do-api-capture"><?php esc_html_e( 'Capture', 'woo-stripe-payment' ); ?></button>
49
+ <button type="button" class="button cancel-action"><?php esc_html_e( 'Cancel', 'woo-stripe-payment' ); ?></button>
50
+ </div>
51
+ <div class="clear"></div>
52
+ </div>
53
+ </div>
includes/admin/meta-boxes/views/html-order-charge-data.php CHANGED
@@ -1,37 +1,37 @@
1
- <div class="transaction-data">
2
- <h3><?php _e('Transaction Data / Actions', 'woo-stripe-payment')?></h3>
3
- <a href="#" class="do-transaction-view"
4
- data-order="<?php echo $order->get_id()?>"></a>
5
- </div>
6
- <script type="text/template" id="tmpl-wc-stripe-view-transaction">
7
- <div class="wc-backbone-modal">
8
- <div class="wc-backbone-modal-content wc-transaction-data">
9
- <section class="wc-backbone-modal-main" role="main">
10
- <header class="wc-backbone-modal-header">
11
- <h1>Transaction #{{ data.charge.id }}</h1>
12
- <button
13
- class="modal-close modal-close-link dashicons dashicons-no-alt">
14
- <span class="screen-reader-text">Close modal panel</span>
15
- </button>
16
- </header>
17
- <article class="wc-transaction-data-container">
18
- {{{ data.html }}}
19
- </article>
20
- <footer>
21
- <div class="inner">
22
-
23
- </div>
24
- </footer>
25
- </section>
26
- </div>
27
- </div>
28
- <div class="wc-backbone-modal-backdrop modal-close"></div>
29
- </script>
30
- <style>
31
- #order_data .order_data_column .transaction-data a.disabled:before {
32
- content: '';
33
- background: url(<?php echo plugins_url('assets/images/wpspin.gif', WC_PLUGIN_FILE)?>)
34
- no-repeat center top;
35
- padding: 0px 10px;
36
- }
37
- </style>
1
+ <div class="transaction-data">
2
+ <h3><?php _e( 'Transaction Data / Actions', 'woo-stripe-payment' ); ?></h3>
3
+ <a href="#" class="do-transaction-view"
4
+ data-order="<?php echo $order->get_id(); ?>"></a>
5
+ </div>
6
+ <script type="text/template" id="tmpl-wc-stripe-view-transaction">
7
+ <div class="wc-backbone-modal">
8
+ <div class="wc-backbone-modal-content wc-transaction-data">
9
+ <section class="wc-backbone-modal-main" role="main">
10
+ <header class="wc-backbone-modal-header">
11
+ <h1>Transaction #{{ data.charge.id }}</h1>
12
+ <button
13
+ class="modal-close modal-close-link dashicons dashicons-no-alt">
14
+ <span class="screen-reader-text">Close modal panel</span>
15
+ </button>
16
+ </header>
17
+ <article class="wc-transaction-data-container">
18
+ {{{ data.html }}}
19
+ </article>
20
+ <footer>
21
+ <div class="inner">
22
+
23
+ </div>
24
+ </footer>
25
+ </section>
26
+ </div>
27
+ </div>
28
+ <div class="wc-backbone-modal-backdrop modal-close"></div>
29
+ </script>
30
+ <style>
31
+ #order_data .order_data_column .transaction-data a.disabled:before {
32
+ content: '';
33
+ background: url(<?php echo plugins_url('assets/images/wpspin.gif', WC_PLUGIN_FILE)?>)
34
+ no-repeat center top;
35
+ padding: 0px 10px;
36
+ }
37
+ </style>
includes/admin/meta-boxes/views/html-order-pay.php CHANGED
@@ -1,59 +1,59 @@
1
- <p class="form-field form-field-wide">
2
- <button class="button button-secondary wc-stripe-pay-order"><?php _e('Pay for Order', 'woo-stripe-payment')?></button>
3
- <?php echo wc_help_tip(__('Admins can process customer orders over the phone using this functionality.', 'woo-stripe-payment'))?>
4
- </p>
5
- <script type="text/template" id="tmpl-wc-stripe-modal-pay-order">
6
- <div class="wc-backbone-modal">
7
- <div class="wc-backbone-modal-content">
8
- <section class="wc-backbone-modal-main" role="main">
9
- <header class="wc-backbone-modal-header">
10
- <h1><?php esc_html_e( 'Pay for Order', 'woocommerce' ); ?></h1>
11
- <button
12
- class="modal-close modal-close-link dashicons dashicons-no-alt">
13
- <span class="screen-reader-text">Close modal panel</span>
14
- </button>
15
- </header>
16
- <article>
17
- <form id="wc-stripe-pay-order-form">
18
- <input type="hidden" name="customer_id" value="{{{data.customer_id}}}"/>
19
- <input type="hidden" name="order_id" value="{{{data.order_id}}}"/>
20
- <div class="modal-wide option">
21
- <label><?php _e('Charge Type', 'woo-stripe-payment')?></label>
22
- <select name="wc_stripe_charge_type" class="wc-select2">
23
- <option value="capture"><?php _e('Capture', 'woo-stripe-payment')?></value>
24
- <option value="authorize"><?php _e('Authorize', 'woo-stripe-payment')?></value>
25
- </select>
26
- </div>
27
- <#if(data.payment_methods.length){#>
28
- <div class="modal-wide">
29
- <input type="radio" value="token" name="payment_type" checked/>
30
- <label class=""><?php _e('Saved Cards', 'woo-stripe-payment')?></label>
31
- <div class="token-container show_if_token hide_if_nonce">
32
- <select name="payment_token_id" class="wc-select2">
33
- <#_.each(data.payment_methods, function(method){#>
34
- <option value="{{{method.id}}}">{{{method.title}}}</option>
35
- <#})#>
36
- </select>
37
- </div>
38
- </div>
39
- <#}#>
40
- <div class="modal-wide">
41
- <input type="radio" value="nonce" name="payment_type" class="" <#if(!data.payment_methods.length){#>checked<#}#>/>
42
- <label class=""><?php _e('New Card', 'woo-stripe-payment')?></label>
43
- <input type="hidden" name="payment_nonce"/>
44
- <div id="wc-stripe-card-container" class="wc-stripe-card-container show_if_nonce hide_if_token">
45
- <div id="card-element"></div>
46
- </div>
47
- <div>
48
- </form>
49
- </article>
50
- <footer>
51
- <div class="inner">
52
- <button id="pay-order" class="button button-primary button-large"><?php esc_html_e( 'Pay', 'woo-stripe-payment' ); ?></button>
53
- </div>
54
- </footer>
55
- </section>
56
- </div>
57
- </div>
58
- <div class="wc-backbone-modal-backdrop modal-close"></div>
59
- </script>
1
+ <p class="form-field form-field-wide">
2
+ <button class="button button-secondary wc-stripe-pay-order"><?php _e( 'Pay for Order', 'woo-stripe-payment' ); ?></button>
3
+ <?php echo wc_help_tip( __( 'Admins can process customer orders over the phone using this functionality.', 'woo-stripe-payment' ) ); ?>
4
+ </p>
5
+ <script type="text/template" id="tmpl-wc-stripe-modal-pay-order">
6
+ <div class="wc-backbone-modal">
7
+ <div class="wc-backbone-modal-content">
8
+ <section class="wc-backbone-modal-main" role="main">
9
+ <header class="wc-backbone-modal-header">
10
+ <h1><?php esc_html_e( 'Pay for Order', 'woocommerce' ); ?></h1>
11
+ <button
12
+ class="modal-close modal-close-link dashicons dashicons-no-alt">
13
+ <span class="screen-reader-text">Close modal panel</span>
14
+ </button>
15
+ </header>
16
+ <article>
17
+ <form id="wc-stripe-pay-order-form">
18
+ <input type="hidden" name="customer_id" value="{{{data.customer_id}}}"/>
19
+ <input type="hidden" name="order_id" value="{{{data.order_id}}}"/>
20
+ <div class="modal-wide option">
21
+ <label><?php _e( 'Charge Type', 'woo-stripe-payment' ); ?></label>
22
+ <select name="wc_stripe_charge_type" class="wc-select2">
23
+ <option value="capture"><?php _e( 'Capture', 'woo-stripe-payment' ); ?></value>
24
+ <option value="authorize"><?php _e( 'Authorize', 'woo-stripe-payment' ); ?></value>
25
+ </select>
26
+ </div>
27
+ <#if(data.payment_methods.length){#>
28
+ <div class="modal-wide">
29
+ <input type="radio" value="token" name="payment_type" checked/>
30
+ <label class=""><?php _e( 'Saved Cards', 'woo-stripe-payment' ); ?></label>
31
+ <div class="token-container show_if_token hide_if_nonce">
32
+ <select name="payment_token_id" class="wc-select2">
33
+ <#_.each(data.payment_methods, function(method){#>
34
+ <option value="{{{method.id}}}">{{{method.title}}}</option>
35
+ <#})#>
36
+ </select>
37
+ </div>
38
+ </div>
39
+ <#}#>
40
+ <div class="modal-wide">
41
+ <input type="radio" value="nonce" name="payment_type" class="" <#if(!data.payment_methods.length){#>checked<#}#>/>
42
+ <label class=""><?php _e( 'New Card', 'woo-stripe-payment' ); ?></label>
43
+ <input type="hidden" name="payment_nonce"/>
44
+ <div id="wc-stripe-card-container" class="wc-stripe-card-container show_if_nonce hide_if_token">
45
+ <div id="card-element"></div>
46
+ </div>
47
+ <div>
48
+ </form>
49
+ </article>
50
+ <footer>
51
+ <div class="inner">
52
+ <button id="pay-order" class="button button-primary button-large"><?php esc_html_e( 'Pay', 'woo-stripe-payment' ); ?></button>
53
+ </div>
54
+ </footer>
55
+ </section>
56
+ </div>
57
+ </div>
58
+ <div class="wc-backbone-modal-backdrop modal-close"></div>
59
+ </script>
includes/admin/meta-boxes/views/html-product-data.php CHANGED
@@ -1,62 +1,82 @@
1
- <div id="stripe_product_data"
2
- class="panel woocommerce_stripe_panel woocommerce_options_panel hidden">
3
- <p>
4
- <?php _e('In this section you can control which gateways are displayed on the product page.', 'woo-stripe-payment')?>
5
- </p>
6
- <div class="options_group">
7
- <input type="hidden" id="wc_stripe_update_product" name="wc_stripe_update_product"/>
8
- <table class="wc-stripe-product-table wc_gateways">
9
- <thead>
10
- <tr>
11
- <th></th>
12
- <th><?php _e('Method', 'woo-stripe-payment')?></th>
13
- <th><?php _e('Enabled', 'woo-stripe-payment')?></th>
14
- <th><?php _e('Charge Type', 'woo-stripe-payment')?>
15
- </thead>
16
- <tbody class="ui-sortable">
17
- <?php foreach(self::get_payment_gateways() as $gateway):?>
18
- <tr data-gateway_id="<?php echo $gateway->id?>">
19
- <td class="sort">
20
- <div class="wc-item-reorder-nav">
21
- <button type="button" class="wc-move-up" tabindex="0" aria-hidden="false" aria-label="<?php /* Translators: %s Payment gateway name. */ echo esc_attr( sprintf( __( 'Move the "%s" payment method up', 'woocommerce' ), $gateway->get_method_title() ) ); ?>"><?php esc_html_e( 'Move up', 'woocommerce' ); ?></button>
22
- <button type="button" class="wc-move-down" tabindex="0" aria-hidden="false" aria-label="<?php /* Translators: %s Payment gateway name. */ echo esc_attr( sprintf( __( 'Move the "%s" payment method down', 'woocommerce' ), $gateway->get_method_title() ) ); ?>"><?php esc_html_e( 'Move down', 'woocommerce' ); ?></button>
23
- <input type="hidden" name="stripe_gateway_order[]" value="<?php echo esc_attr( $gateway->id ); ?>" />
24
- </div>
25
- </td>
26
- <td>
27
- <?php echo $gateway->get_method_title()?>
28
- </td>
29
- <td>
30
- <a class="wc-stripe-product-gateway-enabled" href="#">
31
- <span class="woocommerce-input-toggle woocommerce-input-toggle--<?php if(!self::get_product_option($gateway->id)->enabled()){?>disabled<?php }else{?>enabled<?php }?>"></span>
32
- </a>
33
- </td>
34
- <td>
35
- <select name="stripe_capture_type[]" class="wc-enhanced-select" style="width: 100px">
36
- <option value="capture" <?php selected('capture', self::get_product_option($gateway->id)->get_option('charge_type'))?>><?php _e('Capture', 'woo-stripe-payment')?></option>
37
- <option value="authorize" <?php selected('authorize', self::get_product_option($gateway->id)->get_option('charge_type'))?>><?php _e('Authorize', 'woo-stripe-payment')?></option>
38
- </select>
39
- </td>
40
- </tr>
41
- <?php endforeach;?>
42
- </tbody>
43
- </table>
44
- <?php
45
- woocommerce_wp_select ( [
46
- 'id' => '_stripe_button_position',
47
- 'value' => (($position = $product_object->get_meta ( '_stripe_button_position' )) ? $position : 'bottom'),
48
- 'label' => __ ( 'Button Position', 'woo-stripe-payment' ),
49
- 'options' => [
50
- 'bottom' => __ ( 'Below add to cart', 'woo-stripe-payment' ),
51
- 'top' => __ ( 'Above add to cart', 'woo-stripe-payment' )
52
- ],
53
- 'desc_tip' => true,
54
- 'description' => __('The location of the payment buttons in relation to the Add to Cart button.', 'woo-stripe-payment')
55
- ] );
56
- ?>
57
- </div>
58
- <p>
59
- <button class="button button-secondary wc-stripe-save-product-data"><?php _e('Save', 'woo-stripe-payment')?></button>
60
- <span class="spinner"></span>
61
- </p>
62
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="stripe_product_data"
2
+ class="panel woocommerce_stripe_panel woocommerce_options_panel hidden">
3
+ <p>
4
+ <?php _e( 'In this section you can control which gateways are displayed on the product page.', 'woo-stripe-payment' ); ?>
5
+ </p>
6
+ <div class="options_group">
7
+ <input type="hidden" id="wc_stripe_update_product"
8
+ name="wc_stripe_update_product" />
9
+ <table class="wc-stripe-product-table wc_gateways">
10
+ <thead>
11
+ <tr>
12
+ <th></th>
13
+ <th><?php _e( 'Method', 'woo-stripe-payment' ); ?></th>
14
+ <th><?php _e( 'Enabled', 'woo-stripe-payment' ); ?></th>
15
+ <th><?php _e( 'Charge Type', 'woo-stripe-payment' ); ?>
16
+
17
+
18
+ </thead>
19
+ <tbody class="ui-sortable">
20
+ <?php foreach ( self::get_payment_gateways() as $gateway ) : ?>
21
+ <tr data-gateway_id="<?php echo $gateway->id; ?>">
22
+ <td class="sort">
23
+ <div class="wc-item-reorder-nav">
24
+ <button type="button" class="wc-move-up" tabindex="0"
25
+ aria-hidden="false"
26
+ aria-label="<?php /* Translators: %s Payment gateway name. */ echo esc_attr( sprintf( __( 'Move the "%s" payment method up', 'woocommerce' ), $gateway->get_method_title() ) ); ?>"><?php esc_html_e( 'Move up', 'woocommerce' ); ?></button>
27
+ <button type="button" class="wc-move-down" tabindex="0"
28
+ aria-hidden="false"
29
+ aria-label="<?php /* Translators: %s Payment gateway name. */ echo esc_attr( sprintf( __( 'Move the "%s" payment method down', 'woocommerce' ), $gateway->get_method_title() ) ); ?>"><?php esc_html_e( 'Move down', 'woocommerce' ); ?></button>
30
+ <input type="hidden" name="stripe_gateway_order[]"
31
+ value="<?php echo esc_attr( $gateway->id ); ?>" />
32
+ </div>
33
+ </td>
34
+ <td>
35
+ <?php echo $gateway->get_method_title(); ?>
36
+ </td>
37
+ <td><a class="wc-stripe-product-gateway-enabled" href="#"> <span
38
+ class="woocommerce-input-toggle woocommerce-input-toggle--
39
+ <?php
40
+ if ( ! self::get_product_option( $gateway->id )->enabled() ) {
41
+ ?>
42
+ disabled
43
+ <?php
44
+ } else {
45
+ ?>
46
+ enabled<?php } ?>"></span>
47
+ </a></td>
48
+ <td><select name="stripe_capture_type[]" class="wc-enhanced-select"
49
+ style="width: 100px">
50
+ <option value="capture"
51
+ <?php selected( 'capture', self::get_product_option( $gateway->id )->get_option( 'charge_type' ) ); ?>><?php _e( 'Capture', 'woo-stripe-payment' ); ?></option>
52
+ <option value="authorize"
53
+ <?php selected( 'authorize', self::get_product_option( $gateway->id )->get_option( 'charge_type' ) ); ?>><?php _e( 'Authorize', 'woo-stripe-payment' ); ?></option>
54
+ </select></td>
55
+ </tr>
56
+ <?php endforeach; ?>
57
+ </tbody>
58
+ </table>
59
+ <?php
60
+ woocommerce_wp_select(
61
+ array(
62
+ 'id' => '_stripe_button_position',
63
+ 'value' => ( ( $position = $product_object->get_meta( '_stripe_button_position' ) ) ? $position : 'bottom' ),
64
+ 'label' => __( 'Button Position', 'woo-stripe-payment' ),
65
+ 'options' => array(
66
+ 'bottom' => __( 'Below add to cart', 'woo-stripe-payment' ),
67
+ 'top' => __( 'Above add to cart', 'woo-stripe-payment' ),
68
+ ),
69
+ 'desc_tip' => true,
70
+ 'description' => __(
71
+ 'The location of the payment buttons in relation to the Add to Cart button.',
72
+ 'woo-stripe-payment'
73
+ ),
74
+ )
75
+ );
76
+ ?>
77
+ </div>
78
+ <p>
79
+ <button class="button button-secondary wc-stripe-save-product-data"><?php _e( 'Save', 'woo-stripe-payment' ); ?></button>
80
+ <span class="spinner"></span>
81
+ </p>
82
+ </div>
includes/admin/settings/class-wc-stripe-api-settings.php CHANGED
@@ -1,175 +1,188 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author Payment Plugins
7
- * @since 3.0.0
8
- * @package Stripe/Classes
9
- *
10
- */
11
- class WC_Stripe_API_Settings extends WC_Stripe_Settings_API {
12
-
13
- public function __construct() {
14
- $this->id = 'stripe_api';
15
- $this->tab_title = __ ( 'API Settings', 'woo-stripe-payment' );
16
- parent::__construct ();
17
- }
18
-
19
- public function hooks() {
20
- parent::hooks ();
21
- add_action ( 'woocommerce_update_options_checkout_' . $this->id, array(
22
- $this, 'process_admin_options'
23
- ) );
24
- add_filter ( 'wc_stripe_settings_nav_tabs', array(
25
- $this, 'admin_nav_tab'
26
- ) );
27
- add_action ( 'woocommerce_settings_checkout_' . $this->id, array(
28
- $this, 'admin_options'
29
- ) );
30
- }
31
-
32
- public function init_form_fields() {
33
- $this->form_fields = array(
34
- 'title' => array( 'type' => 'title',
35
- 'title' => __ ( 'API Settings', 'woo-stripe-payment' )
36
- ),
37
- 'mode' => array( 'type' => 'select',
38
- 'title' => __ ( 'Mode', 'woo-stripe-payment' ),
39
- 'class' => 'wc-enhanced-select',
40
- 'options' => array(
41
- 'test' => __ ( 'Test', 'woo-stripe-payment' ),
42
- 'live' => __ ( 'Live', 'woo-stripe-payment' )
43
- ), 'default' => 'test',
44
- 'desc_tip' => true,
45
- 'description' => __ ( 'The mode determines if you are processing test transactions or live transactions on your site. Test mode allows you to simulate payments so you can test your integration.', 'woo-stripe-payment' )
46
- ),
47
- 'account_id' => array(
48
- 'type' => 'paragraph',
49
- 'title' => __ ( 'Account ID', 'woo-stripe-payment' ),
50
- 'text' => '', 'class' => '',
51
- 'default' => '', 'desc_tip' => true,
52
- 'description' => __ ( 'This is your Stripe Connect ID and serves as a unique identifier.', 'woo-stripe-payment' )
53
- ),
54
- 'stripe_connect' => array(
55
- 'type' => 'stripe_connect',
56
- 'title' => __ ( 'Connect Stripe Account', 'woo-stripe-payment' ),
57
- 'label' => __ ( 'Click to Connect', 'woo-stripe-payment' ),
58
- 'class' => 'do-stripe-connect',
59
- 'description' => __ ( 'We make it easy to connect Stripe to your site. Click the Connect button to go through our connect flow.', 'woo-stripe-payment' )
60
- ),
61
- 'connection_test' => array(
62
- 'type' => 'stripe_button',
63
- 'title' => __ ( 'Connection Test', 'woo-stripe-payment' ),
64
- 'label' => __ ( 'Connection Test', 'woo-stripe-payment' ),
65
- 'class' => 'wc-stripe-connection-test button-secondary',
66
- 'description' => __ ( 'Click this button to perform a connection test. If successful, your site is connected to Stripe.', 'woo-stripe-payment' )
67
- ),
68
- 'webhook_url' => array(
69
- 'type' => 'paragraph',
70
- 'title' => __ ( 'Webhook url', 'woo-stripe-payment' ),
71
- 'class' => 'wc-stripe-webhook',
72
- 'text' => wc_stripe ()->rest_api->webhook->rest_url ( 'webhook' ),
73
- 'description' => sprintf ( __ ( '<strong>Important:</strong> the webhook url is called by Stripe when events occur in your account, like a source becomes chargeable. You must add this webhook to your Stripe Dashboard if you are using any of the local gateways. %sWebhook guide%s', 'woo-stripe-payment' ), '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config/#/webhooks?id=configure-webhooks">', '</a>' )
74
- ),
75
- 'webhook_secret_live' => array(
76
- 'type' => 'password',
77
- 'title' => __ ( 'Live Webhook Secret', 'woo-stripe-payment' ),
78
- 'description' => sprintf ( __ ( 'The webhook secret is used to authenticate webhooks sent from Stripe. It ensures no 3rd party can send you events, pretending to be Stripe. %sWebhook guide%s', 'woo-stripe-payment' ), '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config/#/webhooks?id=configure-webhooks">', '</a>' ),
79
- 'custom_attributes' => array(
80
- 'data-show-if' => array(
81
- 'mode' => 'live'
82
- )
83
- )
84
- ),
85
- 'webhook_secret_test' => array(
86
- 'type' => 'password',
87
- 'title' => __ ( 'Test Webhook Secret', 'woo-stripe-payment' ),
88
- 'description' => sprintf ( __ ( 'The webhook secret is used to authenticate webhooks sent from Stripe. It ensures no 3rd party can send you events, pretending to be Stripe. %sWebhook guide%s', 'woo-stripe-payment' ), '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config/#/webhooks?id=configure-webhooks">', '</a>' ),
89
- 'custom_attributes' => array(
90
- 'data-show-if' => array(
91
- 'mode' => 'test'
92
- )
93
- )
94
- ),
95
- 'debug_log' => array(
96
- 'title' => __ ( 'Debug Log', 'woo-stripe-payment' ),
97
- 'type' => 'checkbox',
98
- 'desc_tip' => true,
99
- 'default' => 'yes',
100
- 'description' => __ ( 'When enabled, the plugin logs important errors and info that can help you troubleshoot potential issues.', 'woo-stripe-payment' )
101
- )
102
- );
103
- if ($this->get_option ( 'account_id' )) {
104
- $this->form_fields[ 'account_id' ][ 'text' ] = $this->get_option ( 'account_id' );
105
- $this->form_fields[ 'stripe_connect' ][ 'description' ] = sprintf ( __ ( '%s Your Stripe account has been connected. You can now accept Live and Test payments. You can Re-Connect if you want to recycle your API keys for security.', 'woo-stripe-payment' ), '<span class="dashicons dashicons-yes stipe-connect-active"></span>' );
106
- $this->form_fields[ 'stripe_connect' ][ 'active' ] = true;
107
- } else {
108
- unset ( $this->form_fields[ 'account_id' ], $this->form_fields[ 'connection_test' ], $this->form_fields[ 'mode' ], $this->form_fields[ 'webhook_url' ] );
109
- }
110
- }
111
-
112
- public function generate_stripe_connect_html($key, $data) {
113
- $field_key = $this->get_field_key ( $key );
114
- $data = wp_parse_args ( $data, array(
115
- 'class' => '', 'style' => '',
116
- 'description' => '', 'desc_tip' => false,
117
- 'css' => '', 'active' => false
118
- ) );
119
- $data[ 'connect_url' ] = $this->get_connect_url ();
120
- if ($data[ 'active' ]) {
121
- $data[ 'label' ] = __ ( 'Click To Re-Connect', 'woo-stripe-payment' );
122
- }
123
- ob_start ();
124
- include wc_stripe ()->plugin_path () . 'includes/admin/views/html-stripe-connect.php';
125
- return ob_get_clean ();
126
- }
127
-
128
- public function admin_options() {
129
- // Check if user is being returned from Stripe Connect
130
- if (isset ( $_GET[ '_stripe_connect_nonce' ] ) && wp_verify_nonce ( $_GET[ '_stripe_connect_nonce' ], 'stripe-connect' )) {
131
- if (isset ( $_GET[ 'error' ] )) {
132
- $error = json_decode ( base64_decode ( wc_clean ( $_GET[ 'error' ] ) ) );
133
- if (property_exists ( $error, 'message' )) {
134
- $message = $error->message;
135
- } elseif (property_exists ( $error, 'raw' )) {
136
- $message = $error->raw->message;
137
- } else {
138
- $message = __ ( 'Please try again.', 'woo-stripe-payment' );
139
- }
140
- wc_stripe_log_error ( sprintf ( 'Error connecting to Stripe account. Reason: %s', $message ) );
141
- $this->add_error ( sprintf ( __ ( 'We were not able to connect your Stripe account. Reason: %s', 'woo-stripe-payment' ), $message ) );
142
- } elseif (isset ( $_GET[ 'response' ] )) {
143
- $response = json_decode ( base64_decode ( $_GET[ 'response' ] ) );
144
-
145
- // save the token to the api settings
146
- $this->settings[ 'account_id' ] = $response->live->stripe_user_id;
147
- $this->settings[ 'refresh_token' ] = $response->live->refresh_token;
148
-
149
- $this->settings[ 'secret_key_live' ] = $response->live->access_token;
150
- $this->settings[ 'publishable_key_live' ] = $response->live->stripe_publishable_key;
151
-
152
- $this->settings[ 'secret_key_test' ] = $response->test->access_token;
153
- $this->settings[ 'publishable_key_test' ] = $response->test->stripe_publishable_key;
154
-
155
- update_option ( $this->get_option_key (), $this->settings );
156
-
157
- delete_option ( 'wc_stripe_connect_notice' );
158
-
159
- $this->init_form_fields ();
160
-
161
- echo '<div class="updated inline notice-success is-dismissible "><p>' . __ ( 'Your Stripe account has been connected to your WooCommerce store. You may now accept payments in Live and Test mode.', 'woo-stripe-payment' ) . '</p></div>';
162
- }
163
- }
164
- parent::admin_options ();
165
- }
166
-
167
- public function get_connect_url() {
168
- return sprintf ( 'https://connect.stripe.com/oauth/authorize?response_type=code&client_id=%s&stripe_landing=login&scope=read_write&state=%s', wc_stripe ()->client_id, base64_encode ( wp_json_encode ( [
169
- 'redirect' => sprintf ( admin_url ( 'admin.php?page=wc-settings&tab=checkout&section=stripe_api&_stripe_connect_nonce=%s' ), wp_create_nonce ( 'stripe-connect' ) ),
170
- 'location' => get_option ( 'woocommerce_default_country', 'US' ),
171
- 'website' => get_site_url (),
172
- 'email' => get_bloginfo ( 'admin_email' )
173
- ] ) ) );
174
- }
175
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author Payment Plugins
7
+ * @since 3.0.0
8
+ * @package Stripe/Classes
9
+ *
10
+ */
11
+ class WC_Stripe_API_Settings extends WC_Stripe_Settings_API {
12
+
13
+ public function __construct() {
14
+ $this->id = 'stripe_api';
15
+ $this->tab_title = __( 'API Settings', 'woo-stripe-payment' );
16
+ parent::__construct();
17
+ }
18
+
19
+ public function hooks() {
20
+ parent::hooks();
21
+ add_action( 'woocommerce_update_options_checkout_' . $this->id, array( $this, 'process_admin_options' ) );
22
+ add_filter( 'wc_stripe_settings_nav_tabs', array( $this, 'admin_nav_tab' ) );
23
+ add_action( 'woocommerce_settings_checkout_' . $this->id, array( $this, 'admin_options' ) );
24
+ }
25
+
26
+ public function init_form_fields() {
27
+ $this->form_fields = array(
28
+ 'title' => array(
29
+ 'type' => 'title',
30
+ 'title' => __( 'API Settings', 'woo-stripe-payment' ),
31
+ ),
32
+ 'mode' => array(
33
+ 'type' => 'select',
34
+ 'title' => __( 'Mode', 'woo-stripe-payment' ),
35
+ 'class' => 'wc-enhanced-select',
36
+ 'options' => array(
37
+ 'test' => __( 'Test', 'woo-stripe-payment' ),
38
+ 'live' => __( 'Live', 'woo-stripe-payment' ),
39
+ ),
40
+ 'default' => 'test',
41
+ 'desc_tip' => true,
42
+ 'description' => __( 'The mode determines if you are processing test transactions or live transactions on your site. Test mode allows you to simulate payments so you can test your integration.', 'woo-stripe-payment' ),
43
+ ),
44
+ 'account_id' => array(
45
+ 'type' => 'paragraph',
46
+ 'title' => __( 'Account ID', 'woo-stripe-payment' ),
47
+ 'text' => '',
48
+ 'class' => '',
49
+ 'default' => '',
50
+ 'desc_tip' => true,
51
+ 'description' => __( 'This is your Stripe Connect ID and serves as a unique identifier.', 'woo-stripe-payment' ),
52
+ ),
53
+ 'stripe_connect' => array(
54
+ 'type' => 'stripe_connect',
55
+ 'title' => __( 'Connect Stripe Account', 'woo-stripe-payment' ),
56
+ 'label' => __( 'Click to Connect', 'woo-stripe-payment' ),
57
+ 'class' => 'do-stripe-connect',
58
+ 'description' => __( 'We make it easy to connect Stripe to your site. Click the Connect button to go through our connect flow.', 'woo-stripe-payment' ),
59
+ ),
60
+ 'connection_test' => array(
61
+ 'type' => 'stripe_button',
62
+ 'title' => __( 'Connection Test', 'woo-stripe-payment' ),
63
+ 'label' => __( 'Connection Test', 'woo-stripe-payment' ),
64
+ 'class' => 'wc-stripe-connection-test button-secondary',
65
+ 'description' => __( 'Click this button to perform a connection test. If successful, your site is connected to Stripe.', 'woo-stripe-payment' ),
66
+ ),
67
+ 'webhook_url' => array(
68
+ 'type' => 'paragraph',
69
+ 'title' => __( 'Webhook url', 'woo-stripe-payment' ),
70
+ 'class' => 'wc-stripe-webhook',
71
+ 'text' => wc_stripe()->rest_api->webhook->rest_url( 'webhook' ),
72
+ 'description' => sprintf( __( '<strong>Important:</strong> the webhook url is called by Stripe when events occur in your account, like a source becomes chargeable. You must add this webhook to your Stripe Dashboard if you are using any of the local gateways. %1$sWebhook guide%2$s', 'woo-stripe-payment' ), '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config/#/webhooks?id=configure-webhooks">', '</a>' ),
73
+ ),
74
+ 'webhook_secret_live' => array(
75
+ 'type' => 'password',
76
+ 'title' => __( 'Live Webhook Secret', 'woo-stripe-payment' ),
77
+ 'description' => sprintf( __( 'The webhook secret is used to authenticate webhooks sent from Stripe. It ensures no 3rd party can send you events, pretending to be Stripe. %1$sWebhook guide%2$s', 'woo-stripe-payment' ), '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config/#/webhooks?id=configure-webhooks">', '</a>' ),
78
+ 'custom_attributes' => array( 'data-show-if' => array( 'mode' => 'live' ) ),
79
+ ),
80
+ 'webhook_secret_test' => array(
81
+ 'type' => 'password',
82
+ 'title' => __( 'Test Webhook Secret', 'woo-stripe-payment' ),
83
+ 'description' => sprintf( __( 'The webhook secret is used to authenticate webhooks sent from Stripe. It ensures no 3rd party can send you events, pretending to be Stripe. %1$sWebhook guide%2$s', 'woo-stripe-payment' ), '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config/#/webhooks?id=configure-webhooks">', '</a>' ),
84
+ 'custom_attributes' => array( 'data-show-if' => array( 'mode' => 'test' ) ),
85
+ ),
86
+ 'debug_log' => array(
87
+ 'title' => __( 'Debug Log', 'woo-stripe-payment' ),
88
+ 'type' => 'checkbox',
89
+ 'desc_tip' => true,
90
+ 'default' => 'yes',
91
+ 'description' => __( 'When enabled, the plugin logs important errors and info that can help you troubleshoot potential issues.', 'woo-stripe-payment' ),
92
+ ),
93
+ );
94
+ if ( $this->get_option( 'account_id' ) ) {
95
+ $this->form_fields['account_id']['text'] = $this->get_option( 'account_id' );
96
+ $this->form_fields['stripe_connect']['description'] = sprintf( __( '%s Your Stripe account has been connected. You can now accept Live and Test payments. You can Re-Connect if you want to recycle your API keys for security.', 'woo-stripe-payment' ), '<span class="dashicons dashicons-yes stipe-connect-active"></span>' );
97
+ $this->form_fields['stripe_connect']['active'] = true;
98
+ } else {
99
+ unset( $this->form_fields['account_id'], $this->form_fields['connection_test'], $this->form_fields['mode'], $this->form_fields['webhook_url'] );
100
+ }
101
+ }
102
+
103
+ public function generate_stripe_connect_html( $key, $data ) {
104
+ $field_key = $this->get_field_key( $key );
105
+ $data = wp_parse_args(
106
+ $data,
107
+ array(
108
+ 'class' => '',
109
+ 'style' => '',
110
+ 'description' => '',
111
+ 'desc_tip' => false,
112
+ 'css' => '',
113
+ 'active' => false,
114
+ )
115
+ );
116
+ $data['connect_url'] = $this->get_connect_url();
117
+ if ( $data['active'] ) {
118
+ $data['label'] = __( 'Click To Re-Connect', 'woo-stripe-payment' );
119
+ }
120
+ ob_start();
121
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-stripe-connect.php';
122
+
123
+ return ob_get_clean();
124
+ }
125
+
126
+ public function admin_options() {
127
+ // Check if user is being returned from Stripe Connect
128
+ if ( isset( $_GET['_stripe_connect_nonce'] ) && wp_verify_nonce( $_GET['_stripe_connect_nonce'], 'stripe-connect' ) ) {
129
+ if ( isset( $_GET['error'] ) ) {
130
+ $error = json_decode( base64_decode( wc_clean( $_GET['error'] ) ) );
131
+ if ( property_exists( $error, 'message' ) ) {
132
+ $message = $error->message;
133
+ } elseif ( property_exists( $error, 'raw' ) ) {
134
+ $message = $error->raw->message;
135
+ } else {
136
+ $message = __( 'Please try again.', 'woo-stripe-payment' );
137
+ }
138
+ wc_stripe_log_error( sprintf( 'Error connecting to Stripe account. Reason: %s', $message ) );
139
+ $this->add_error( sprintf( __( 'We were not able to connect your Stripe account. Reason: %s', 'woo-stripe-payment' ), $message ) );
140
+ } elseif ( isset( $_GET['response'] ) ) {
141
+ $response = json_decode( base64_decode( $_GET['response'] ) );
142
+
143
+ // save the token to the api settings
144
+ $this->settings['account_id'] = $response->live->stripe_user_id;
145
+ $this->settings['refresh_token'] = $response->live->refresh_token;
146
+
147
+ $this->settings['secret_key_live'] = $response->live->access_token;
148
+ $this->settings['publishable_key_live'] = $response->live->stripe_publishable_key;
149
+
150
+ $this->settings['secret_key_test'] = $response->test->access_token;
151
+ $this->settings['publishable_key_test'] = $response->test->stripe_publishable_key;
152
+
153
+ update_option( $this->get_option_key(), $this->settings );
154
+
155
+ delete_option( 'wc_stripe_connect_notice' );
156
+
157
+ /**
158
+ * @param array $response
159
+ * @param WC_Stripe_API_Settings $this
160
+ *
161
+ * @since 3.1.6
162
+ */
163
+ do_action( 'wc_stripe_connect_settings', $response, $this );
164
+
165
+ $this->init_form_fields();
166
+
167
+ echo '<div class="updated inline notice-success is-dismissible "><p>' .
168
+ __( 'Your Stripe account has been connected to your WooCommerce store. You may now accept payments in Live and Test mode.', 'woo-stripe-payment' ) .
169
+ '</p></div>';
170
+ }
171
+ }
172
+ parent::admin_options();
173
+ }
174
+
175
+ public function get_connect_url() {
176
+ return sprintf(
177
+ 'https://connect.stripe.com/oauth/authorize?response_type=code&client_id=%s&stripe_landing=login&scope=read_write&state=%s',
178
+ wc_stripe()->client_id,
179
+ base64_encode(
180
+ wp_json_encode(
181
+ array(
182
+ 'redirect' => add_query_arg( '_stripe_connect_nonce', wp_create_nonce( 'stripe-connect' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe_api' ) )
183
+ )
184
+ )
185
+ )
186
+ );
187
+ }
188
+ }
includes/admin/views/html-ach-fee.php CHANGED
@@ -1,29 +1,33 @@
1
- <tr valign="top">
2
- <th scope="row" class="titledesc">
3
- <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
4
- </th>
5
- <td class="forminp">
6
- <fieldset>
7
- <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
8
- <div class="wc-stripe-fee-container">
9
- <div class="wc-stripe-fee-col">
10
- <label><?php _e('Type', 'woo-stripe-payment')?></label>
11
- <select class="select wc-enhanced-select ach-fee" name="<?php echo esc_attr( $field_key ); ?>[type]" id="<?php echo esc_attr( $field_key ); ?>[type]" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?>>
12
- <?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
13
- <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( (string) $option_key, esc_attr( $this->get_option( $key )['type'] ) ); ?>><?php echo esc_attr( $option_value ); ?></option>
14
- <?php endforeach; ?>
15
- </select>
16
- </div>
17
- <div class="wc-stripe-fee-col">
18
- <label><?php _e('Taxable', 'woo-stripe-payment')?></label>
19
- <input type="checkbox" name="<?php echo esc_attr( $field_key ); ?>[taxable]" id="<?php echo esc_attr( $field_key ); ?>[taxable]" value="yes" <?php checked($this->get_option('fee')['taxable'], 'yes')?>/>
20
- </div>
21
- <div class="wc-stripe-fee-col">
22
- <label><?php _e('Value', 'woo-stripe-payment')?></label>
23
- <input class="input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>[value]" id="<?php echo esc_attr( $field_key ); ?>[value]" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( $this->get_option( $key )['value'] ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?> />
24
- </div>
25
- </div>
26
- <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
27
- </fieldset>
28
- </td>
29
- </tr>
 
 
 
 
1
+ <tr valign="top">
2
+ <th scope="row" class="titledesc"><label
3
+ for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
4
+ </th>
5
+ <td class="forminp">
6
+ <fieldset>
7
+ <legend class="screen-reader-text">
8
+ <span><?php echo wp_kses_post( $data['title'] ); ?></span>
9
+ </legend>
10
+ <div class="wc-stripe-fee-container">
11
+ <div class="wc-stripe-fee-col">
12
+ <label><?php _e( 'Type', 'woo-stripe-payment' ); ?></label> <select class="select wc-enhanced-select ach-fee" name="<?php echo esc_attr( $field_key ); ?>[type]" id="<?php echo esc_attr( $field_key ); ?>[type]" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?>>
13
+ <?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
14
+ <option value="<?php echo esc_attr( $option_key ); ?>"
15
+ <?php selected( (string) $option_key, esc_attr( $this->get_option( $key )['type'] ) ); ?>><?php echo esc_attr( $option_value ); ?></option>
16
+ <?php endforeach; ?>
17
+ </select>
18
+ </div>
19
+ <div class="wc-stripe-fee-col">
20
+ <label><?php _e( 'Taxable', 'woo-stripe-payment' ); ?></label> <input
21
+ type="checkbox"
22
+ name="<?php echo esc_attr( $field_key ); ?>[taxable]"
23
+ id="<?php echo esc_attr( $field_key ); ?>[taxable]" value="yes"
24
+ <?php checked( $this->get_option( 'fee' )['taxable'], 'yes' ); ?> />
25
+ </div>
26
+ <div class="wc-stripe-fee-col">
27
+ <label><?php _e( 'Value', 'woo-stripe-payment' ); ?></label> <input class="input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>[value]" id="<?php echo esc_attr( $field_key ); ?>[value]" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( $this->get_option( $key )['value'] ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?> />
28
+ </div>
29
+ </div>
30
+ <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
31
+ </fieldset>
32
+ </td>
33
+ </tr>
includes/admin/views/html-button-demo.php CHANGED
@@ -1,13 +1,17 @@
1
- <tr valign="top">
2
- <th scope="row" class="titledesc">
3
- <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
4
- </th>
5
- <td class="forminp">
6
- <fieldset>
7
- <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
8
- <label for="<?php echo esc_attr( $field_key ); ?>">
9
- <div id="<?php echo $data['id']?>"></div>
10
- <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
11
- </fieldset>
12
- </td>
13
- </tr>
 
 
 
 
1
+ <tr valign="top">
2
+ <th scope="row" class="titledesc"><label
3
+ for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
4
+ </th>
5
+ <td class="forminp">
6
+ <fieldset>
7
+ <legend class="screen-reader-text">
8
+ <span><?php echo wp_kses_post( $data['title'] ); ?></span>
9
+ </legend>
10
+ <label for="<?php echo esc_attr( $field_key ); ?>">
11
+ <div id="<?php echo $data['id']; ?>"></div>
12
+ <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
13
+
14
+
15
+ </fieldset>
16
+ </td>
17
+ </tr>
includes/admin/views/html-button.php CHANGED
@@ -1,13 +1,16 @@
1
- <tr valign="top">
2
- <th scope="row" class="titledesc">
3
- <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
4
- </th>
5
- <td class="forminp">
6
- <fieldset>
7
- <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
8
- <label for="<?php echo esc_attr( $field_key ); ?>">
9
- <button type="submit" <?php disabled( $data['disabled'], true ); ?> class="<?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo $field_key?>" <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?>><?php echo wp_kses_post( $data['label'] ); ?></button></label><br/>
10
- <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
11
- </fieldset>
12
- </td>
13
- </tr>
 
 
 
1
+ <tr valign="top">
2
+ <th scope="row" class="titledesc"><label
3
+ for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
4
+ </th>
5
+ <td class="forminp">
6
+ <fieldset>
7
+ <legend class="screen-reader-text">
8
+ <span><?php echo wp_kses_post( $data['title'] ); ?></span>
9
+ </legend>
10
+ <label for="<?php echo esc_attr( $field_key ); ?>">
11
+ <button type="submit" <?php disabled( $data['disabled'], true ); ?> class="<?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo $field_key; ?>" <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?>><?php echo wp_kses_post( $data['label'] ); ?></button>
12
+ </label><br />
13
+ <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
14
+ </fieldset>
15
+ </td>
16
+ </tr>
includes/admin/views/html-description.php CHANGED
@@ -1 +1 @@
1
- <p class="<?php echo $data['class']?>"><?php echo wp_kses_post( $data['description'] ); ?></p>
1
+ <p class="<?php echo $data['class']; ?>"><?php echo wp_kses_post( $data['description'] ); ?></p>
includes/admin/views/html-paragraph.php CHANGED
@@ -1,14 +1,15 @@
1
- <tr valign="top">
2
- <th scope="row" class="titledesc"><label
3
- for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
4
- </th>
5
- <td class="forminp">
6
- <fieldset>
7
- <legend class="screen-reader-text">
8
- <span><?php echo wp_kses_post( $data['title'] ); ?></span>
9
- </legend>
10
- <p class="<?php echo esc_attr( $data['class'] );?>" <?php echo $this->get_custom_attribute_html( $data );?>><?php echo $data['text']?></p>
11
- <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
12
- </fieldset>
13
- </td>
14
- </tr>
 
1
+ <tr valign="top">
2
+ <th scope="row" class="titledesc"><label
3
+ for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
4
+ </th>
5
+ <td class="forminp">
6
+ <fieldset>
7
+ <legend class="screen-reader-text">
8
+ <span><?php echo wp_kses_post( $data['title'] ); ?></span>
9
+ </legend>
10
+ <p class="<?php echo esc_attr( $data['class'] ); ?>"
11
+ <?php echo $this->get_custom_attribute_html( $data ); ?>><?php echo $data['text']; ?></p>
12
+ <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
13
+ </fieldset>
14
+ </td>
15
+ </tr>
includes/admin/views/html-settings-local-payments-nav.php CHANGED
@@ -1,12 +1,17 @@
1
- <?php
2
- global $wc_stripe_subsection;
3
- $tabs = apply_filters ( 'wc_stripe_local_gateways_tab', array() );
4
- ?>
5
- <div class="wc-stripe-advanced-settings-nav local-gateways">
6
- <?php foreach($tabs as $id => $tab):?>
7
- <a
8
- class="nav-link <?php if($wc_stripe_subsection === $id){echo 'nav-link-active';}?>"
9
- href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe_local_gateways&stripe_sub_section=' . $id)?>"><?php echo esc_attr($tab)?></a>
10
- <?php endforeach;?>
11
- </div>
12
- <div class="clear"></div>
 
 
 
 
 
1
+ <?php
2
+ global $wc_stripe_subsection;
3
+ $tabs = apply_filters( 'wc_stripe_local_gateways_tab', array() );
4
+ ?>
5
+ <div class="wc-stripe-advanced-settings-nav local-gateways">
6
+ <?php foreach ( $tabs as $id => $tab ) : ?>
7
+ <a
8
+ class="nav-link
9
+ <?php
10
+ if ( $wc_stripe_subsection === $id ) {
11
+ echo 'nav-link-active';}
12
+ ?>
13
+ "
14
+ href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe_local_gateways&stripe_sub_section=' . $id ); ?>"><?php echo esc_attr( $tab ); ?></a>
15
+ <?php endforeach; ?>
16
+ </div>
17
+ <div class="clear"></div>
includes/admin/views/html-settings-nav.php CHANGED
@@ -1,18 +1,25 @@
1
- <?php
2
- global $current_section;
3
- $tabs = apply_filters('wc_stripe_settings_nav_tabs', array());
4
- ?>
5
- <div class="wc-stripe-settings-logo">
6
- <img src="<?php echo wc_stripe()->assets_url() . 'img/stripe_logo.svg'?>"/>
7
- </div>
8
- <div class="stripe-settings-nav">
9
- <?php foreach($tabs as $id => $tab):?>
10
- <a
11
- class="nav-tab <?php if($current_section === $id){echo 'nav-tab-active';}?>"
12
- href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $id)?>"><?php echo esc_attr($tab)?></a>
13
- <?php endforeach;?>
14
- </div>
15
- <div class="clear"></div>
16
- <div class="wc-stripe-docs">
17
- <a target="_blank" class="button button-secondary" href="https://docs.paymentplugins.com/wc-stripe/config/#/<?php echo $current_section?>"><?php _e('Documentation', 'woo-stripe-payment')?></a>
18
- </div>
 
 
 
 
 
 
 
1
+ <?php
2
+ global $current_section;
3
+ $tabs = apply_filters( 'wc_stripe_settings_nav_tabs', array() );
4
+ ?>
5
+ <div class="wc-stripe-settings-logo">
6
+ <img
7
+ src="<?php echo wc_stripe()->assets_url() . 'img/stripe_logo.svg'; ?>" />
8
+ </div>
9
+ <div class="stripe-settings-nav">
10
+ <?php foreach ( $tabs as $id => $tab ) : ?>
11
+ <a
12
+ class="nav-tab
13
+ <?php
14
+ if ( $current_section === $id ) {
15
+ echo 'nav-tab-active';}
16
+ ?>
17
+ "
18
+ href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $id ); ?>"><?php echo esc_attr( $tab ); ?></a>
19
+ <?php endforeach; ?>
20
+ </div>
21
+ <div class="clear"></div>
22
+ <div class="wc-stripe-docs">
23
+ <a target="_blank" class="button button-secondary"
24
+ href="https://docs.paymentplugins.com/wc-stripe/config/#/<?php echo $current_section; ?>"><?php _e( 'Documentation', 'woo-stripe-payment' ); ?></a>
25
+ </div>
includes/admin/views/html-stripe-connect.php CHANGED
@@ -1,14 +1,19 @@
1
- <tr valign="top">
2
- <th scope="row" class="titledesc">
3
- <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
4
- </th>
5
- <td class="forminp<?php if($data['active']){?> active<?php }?>">
6
- <fieldset>
7
- <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
8
- <label for="<?php echo esc_attr( $field_key ); ?>">
9
- <a href="<?php echo $data['connect_url']?>" type="submit" class="stripe-connect light-blue <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo $field_key?>" <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?>><span><?php echo wp_kses_post( $data['label'] ); ?></span></a>
10
- </label>
11
- <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
12
- </fieldset>
13
- </td>
14
- </tr>
 
 
 
 
 
1
+ <tr valign="top">
2
+ <th scope="row" class="titledesc"><label
3
+ for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?></label>
4
+ </th>
5
+ <td class="forminp
6
+ <?php
7
+ if ( $data['active'] ) {
8
+ ?>
9
+ active<?php } ?>">
10
+ <fieldset>
11
+ <legend class="screen-reader-text">
12
+ <span><?php echo wp_kses_post( $data['title'] ); ?></span>
13
+ </legend>
14
+ <label for="<?php echo esc_attr( $field_key ); ?>"> <a href="<?php echo $data['connect_url']; ?>" type="submit" class="stripe-connect light-blue <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo $field_key; ?>" <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?>><span><?php echo wp_kses_post( $data['label'] ); ?></span></a>
15
+ </label>
16
+ <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
17
+ </fieldset>
18
+ </td>
19
+ </tr>
includes/admin/views/html-user-profile.php CHANGED
@@ -1,95 +1,95 @@
1
- <?php
2
- /**
3
- * @var WP_User $user
4
- */
5
- ?>
6
- <div class="wc-stripe-user-info">
7
- <h2><?php _e('Stripe Customer ID\'s', 'woo-stripe-payment')?></h2>
8
- <p><?php _e('If you change a customer ID, the customer\'s payment methods will be imported from your Stripe account.')?></p>
9
- <p><?php _e('If you remove a customer ID, the customer\'s payment methods will be removed from the WC payment methods table.')?></p>
10
- <table class="form-table">
11
- <tbody>
12
- <tr>
13
- <th><?php _e('Live ID', 'woo-stripe-payment')?></th>
14
- <td>
15
- <input type="text" id="wc_stripe_live_id" name="wc_stripe_live_id" value="<?php echo wc_stripe_get_customer_id($user->ID, 'live')?>"/>
16
- </td>
17
- </tr>
18
- <tr>
19
- <th><?php _e('Test ID', 'woo-stripe-payment')?></th>
20
- <td>
21
- <input type="text" id="wc_stripe_test_id" name="wc_stripe_test_id" value="<?php echo wc_stripe_get_customer_id($user->ID, 'test')?>"/>
22
- </td>
23
- </tr>
24
- </tbody>
25
- </table>
26
- <h2><?php _e('Stripe Live Payment Methods', 'woo-stripe-payment')?></h2>
27
- <?php if($payment_methods['live']):?>
28
- <table class="wc-stripe-payment-methods">
29
- <thead>
30
- <tr>
31
- <th><?php _e('Payment Gateway', 'woo-stripe-payment')?></th>
32
- <th><?php _e('Payment Method', 'woo-stripe-payment')?></th>
33
- <th><?php _e('Token', 'woo-stripe-payment')?></th>
34
- <th><?php _e('Actions', 'woo-stripe-payment')?></th>
35
- </tr>
36
- </thead>
37
- <tbody>
38
- <?php foreach($payment_methods['live'] as $token):?>
39
- <tr>
40
- <td><?php echo $token->get_gateway_id()?></td>
41
- <td><?php echo $token->get_payment_method_title()?></td>
42
- <td><?php echo $token->get_token()?></td>
43
- <td><input type="checkbox" name="payment_methods[live][]" value="<?php echo $token->get_id()?>"/></td>
44
- </tr>
45
- <?php endforeach;?>
46
- <tr>
47
- <th><?php _e('Action', 'delete')?></th>
48
- <td>
49
- <select name="live_payment_method_actions">
50
- <option value="none" selected><?php _e('No Action', 'woo-stripe-payment')?></option>
51
- <option value="delete"><?php _e('Delete', 'woo-stripe-payment')?></option>
52
- </select>
53
- </td>
54
- </tr>
55
- </tbody>
56
- </table>
57
- <?php else:?>
58
- <?php _e('No live payment methods saved', 'woo-stripe-payment')?>
59
- <?php endif;?>
60
- <h2><?php _e('Stripe Test Payment Methods', 'woo-stripe-payment')?></h2>
61
- <?php if($payment_methods['test']):?>
62
- <table class="wc-stripe-payment-methods">
63
- <thead>
64
- <tr>
65
- <th><?php _e('Payment Gateway', 'woo-stripe-payment')?></th>
66
- <th><?php _e('Payment Method', 'woo-stripe-payment')?></th>
67
- <th><?php _e('Token', 'woo-stripe-payment')?></th>
68
- <th><?php _e('Actions', 'woo-stripe-payment')?></th>
69
- </tr>
70
- </thead>
71
- <tbody>
72
- <?php foreach($payment_methods['test'] as $token):?>
73
- <tr>
74
- <td><?php echo $token->get_gateway_id()?></td>
75
- <td><?php echo $token->get_payment_method_title()?></td>
76
- <td><?php echo $token->get_token()?></td>
77
- <td><input type="checkbox" name="payment_methods[test][]" value="<?php echo $token->get_id()?>"/></td>
78
- </tr>
79
- <?php endforeach;?>
80
- <tr>
81
- <th><?php _e('Action', 'delete')?></th>
82
- <td>
83
- <select name="test_payment_method_actions">
84
- <option value="none" selected><?php _e('No Action', 'woo-stripe-payment')?></option>
85
- <option value="delete"><?php _e('Delete', 'woo-stripe-payment')?></option>
86
- </select>
87
- </td>
88
- </tr>
89
- </tbody>
90
- </table>
91
- <?php else:?>
92
- <?php _e('No test payment methods saved', 'woo-stripe-payment')?>
93
- <?php endif;?>
94
- <?php printf(__('%snote:%s payment methods will be deleted in Stripe if you use the delete action.', 'woo-stripe-payment'), '<strong>', '</strong>')?>
95
- </div>
1
+ <?php
2
+ /**
3
+ * @var WP_User $user
4
+ */
5
+ ?>
6
+ <div class="wc-stripe-user-info">
7
+ <h2><?php _e( 'Stripe Customer ID\'s', 'woo-stripe-payment' ); ?></h2>
8
+ <p><?php _e( 'If you change a customer ID, the customer\'s payment methods will be imported from your Stripe account.' ); ?></p>
9
+ <p><?php _e( 'If you remove a customer ID, the customer\'s payment methods will be removed from the WC payment methods table.' ); ?></p>
10
+ <table class="form-table">
11
+ <tbody>
12
+ <tr>
13
+ <th><?php _e( 'Live ID', 'woo-stripe-payment' ); ?></th>
14
+ <td><input type="text" id="wc_stripe_live_id"
15
+ name="wc_stripe_live_id"
16
+ value="<?php echo wc_stripe_get_customer_id( $user->ID, 'live' ); ?>" />
17
+ </td>
18
+ </tr>
19
+ <tr>
20
+ <th><?php _e( 'Test ID', 'woo-stripe-payment' ); ?></th>
21
+ <td><input type="text" id="wc_stripe_test_id"
22
+ name="wc_stripe_test_id"
23
+ value="<?php echo wc_stripe_get_customer_id( $user->ID, 'test' ); ?>" />
24
+ </td>
25
+ </tr>
26
+ </tbody>
27
+ </table>
28
+ <h2><?php _e( 'Stripe Live Payment Methods', 'woo-stripe-payment' ); ?></h2>
29
+ <?php if ( $payment_methods['live'] ) : ?>
30
+ <table class="wc-stripe-payment-methods">
31
+ <thead>
32
+ <tr>
33
+ <th><?php _e( 'Payment Gateway', 'woo-stripe-payment' ); ?></th>
34
+ <th><?php _e( 'Payment Method', 'woo-stripe-payment' ); ?></th>
35
+ <th><?php _e( 'Token', 'woo-stripe-payment' ); ?></th>
36
+ <th><?php _e( 'Actions', 'woo-stripe-payment' ); ?></th>
37
+ </tr>
38
+ </thead>
39
+ <tbody>
40
+ <?php foreach ( $payment_methods['live'] as $token ) : ?>
41
+ <tr>
42
+ <td><?php echo $token->get_gateway_id(); ?></td>
43
+ <td><?php echo $token->get_payment_method_title(); ?></td>
44
+ <td><?php echo $token->get_token(); ?></td>
45
+ <td><input type="checkbox" name="payment_methods[live][]"
46
+ value="<?php echo $token->get_id(); ?>" /></td>
47
+ </tr>
48
+ <?php endforeach; ?>
49
+ <tr>
50
+ <th><?php _e( 'Action', 'delete' ); ?></th>
51
+ <td><select name="live_payment_method_actions">
52
+ <option value="none" selected><?php _e( 'No Action', 'woo-stripe-payment' ); ?></option>
53
+ <option value="delete"><?php _e( 'Delete', 'woo-stripe-payment' ); ?></option>
54
+ </select></td>
55
+ </tr>
56
+ </tbody>
57
+ </table>
58
+ <?php else : ?>
59
+ <?php _e( 'No live payment methods saved', 'woo-stripe-payment' ); ?>
60
+ <?php endif; ?>
61
+ <h2><?php _e( 'Stripe Test Payment Methods', 'woo-stripe-payment' ); ?></h2>
62
+ <?php if ( $payment_methods['test'] ) : ?>
63
+ <table class="wc-stripe-payment-methods">
64
+ <thead>
65
+ <tr>
66
+ <th><?php _e( 'Payment Gateway', 'woo-stripe-payment' ); ?></th>
67
+ <th><?php _e( 'Payment Method', 'woo-stripe-payment' ); ?></th>
68
+ <th><?php _e( 'Token', 'woo-stripe-payment' ); ?></th>
69
+ <th><?php _e( 'Actions', 'woo-stripe-payment' ); ?></th>
70
+ </tr>
71
+ </thead>
72
+ <tbody>
73
+ <?php foreach ( $payment_methods['test'] as $token ) : ?>
74
+ <tr>
75
+ <td><?php echo $token->get_gateway_id(); ?></td>
76
+ <td><?php echo $token->get_payment_method_title(); ?></td>
77
+ <td><?php echo $token->get_token(); ?></td>
78
+ <td><input type="checkbox" name="payment_methods[test][]"
79
+ value="<?php echo $token->get_id(); ?>" /></td>
80
+ </tr>
81
+ <?php endforeach; ?>
82
+ <tr>
83
+ <th><?php _e( 'Action', 'delete' ); ?></th>
84
+ <td><select name="test_payment_method_actions">
85
+ <option value="none" selected><?php _e( 'No Action', 'woo-stripe-payment' ); ?></option>
86
+ <option value="delete"><?php _e( 'Delete', 'woo-stripe-payment' ); ?></option>
87
+ </select></td>
88
+ </tr>
89
+ </tbody>
90
+ </table>
91
+ <?php else : ?>
92
+ <?php _e( 'No test payment methods saved', 'woo-stripe-payment' ); ?>
93
+ <?php endif; ?>
94
+ <?php printf( __( '%1$snote:%2$s payment methods will be deleted in Stripe if you use the delete action.', 'woo-stripe-payment' ), '<strong>', '</strong>' ); ?>
95
+ </div>
includes/class-stripe.php CHANGED
@@ -1,295 +1,304 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- * Singleton class that handles plugin functionality like class loading.
6
- *
7
- * @since 3.0.0
8
- * @author PaymentPlugins
9
- * @package Stripe/Classes
10
- *
11
- */
12
- class WC_Stripe_Manager {
13
-
14
- public static $_instance;
15
-
16
- public static function instance() {
17
- if (self::$_instance == null) {
18
- self::$_instance = new self ();
19
- }
20
- return self::$_instance;
21
- }
22
-
23
- /**
24
- *
25
- * @var string
26
- */
27
- public $version = '3.1.5';
28
-
29
- /**
30
- *
31
- * @var WC_Stripe_Settings_API
32
- */
33
- public $api_settings;
34
-
35
- /**
36
- *
37
- * @var WC_Stripe_Rest_API
38
- */
39
- public $rest_api;
40
-
41
- /**
42
- *
43
- * @var string
44
- */
45
- public $client_id = 'ca_Gp4vLOJiqHJLZGxakHW7JdbBlcgWK8Up';
46
-
47
- /**
48
- * Test client id;
49
- *
50
- * @var string
51
- */
52
- // public $client_id = 'ca_Gp4vL3V6FpTguYoZIehD5COPeI80rLpV';
53
-
54
- /**
55
- *
56
- * @var WC_Stripe_Frontend_Scripts
57
- */
58
- private $scripts;
59
-
60
- /**
61
- *
62
- * @var array
63
- */
64
- private $payment_gateways;
65
-
66
- public function __construct() {
67
- add_action ( 'plugins_loaded', array( $this,
68
- 'plugins_loaded'
69
- ), 10 );
70
- add_action ( 'init', array( $this, 'init'
71
- ) );
72
- add_action ( 'admin_init', array( $this,
73
- 'admin_init'
74
- ) );
75
- add_action ( 'woocommerce_init', array( $this,
76
- 'woocommerce_dependencies'
77
- ) );
78
- $this->includes ();
79
- }
80
-
81
- /**
82
- * Return the plugin version.
83
- *
84
- * @return string
85
- */
86
- public function version() {
87
- return $this->version;
88
- }
89
-
90
- /**
91
- * Return the url for the plugin assets.
92
- *
93
- * @return string
94
- */
95
- public function assets_url($uri = '') {
96
- $url = WC_STRIPE_ASSETS . $uri;
97
- if (! preg_match ( '/(\.js)|(\.css)|(\.svg)|(\.png)/', $uri )) {
98
- return trailingslashit ( $url );
99
- }
100
- return $url;
101
- }
102
-
103
- /**
104
- * Return the dir path for the plugin.
105
- *
106
- * @return string
107
- */
108
- public function plugin_path() {
109
- return WC_STRIPE_PLUGIN_FILE_PATH;
110
- }
111
-
112
- public function plugins_loaded() {
113
- load_plugin_textdomain ( 'woo-stripe-payment', false, dirname ( WC_STRIPE_PLUGIN_NAME ) . '/i18n/languages' );
114
- }
115
-
116
- /**
117
- * Function that is hooked in to the Wordpress init action.
118
- */
119
- public function init() {}
120
-
121
- public function includes() {
122
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-install.php';
123
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-update.php';
124
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-rest-api.php';
125
-
126
- if (is_admin ()) {
127
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/class-wc-stripe-admin-menus.php';
128
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/class-wc-stripe-admin-assets.php';
129
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/class-wc-stripe-admin-settings.php';
130
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/meta-boxes/class-wc-stripe-admin-order-metaboxes.php';
131
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/meta-boxes/class-wc-stripe-admin-meta-box-product-data.php';
132
- }
133
- }
134
-
135
- /**
136
- * Function that is hooked in to the Wordpress admin_init action.
137
- */
138
- public function admin_init() {}
139
-
140
- public function woocommerce_dependencies() {
141
- // load functions
142
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/wc-stripe-functions.php';
143
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/wc-stripe-webhook-functions.php';
144
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/wc-stripe-hooks.php';
145
-
146
- // constants
147
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-constants.php';
148
-
149
- // traits
150
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/traits/wc-stripe-settings-trait.php';
151
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/traits/wc-stripe-controller-cart-trait.php';
152
-
153
- // load factories
154
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-payment-factory.php';
155
-
156
- // load gateways
157
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-payment-gateway-stripe.php';
158
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php';
159
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-cc.php';
160
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-applepay.php';
161
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-googlepay.php';
162
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-ach.php';
163
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-payment-request.php';
164
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-ideal.php';
165
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-p24.php';
166
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-klarna.php';
167
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-giropay.php';
168
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-eps.php';
169
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-multibanco.php';
170
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-sepa.php';
171
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-sofort.php';
172
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-wechat.php';
173
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-bancontact.php';
174
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-fpx.php';
175
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-alipay.php';
176
-
177
- // tokens
178
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-payment-token-stripe.php';
179
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/tokens/class-wc-payment-token-stripe-cc.php';
180
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/tokens/class-wc-payment-token-stripe-applepay.php';
181
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/tokens/class-wc-payment-token-stripe-googlepay.php';
182
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/tokens/class-wc-payment-token-stripe-local-payment.php';
183
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/tokens/class-wc-payment-token-stripe-ach.php';
184
-
185
- // main classes
186
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-frontend-scripts.php';
187
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-field-manager.php';
188
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-rest-api.php';
189
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-gateway.php';
190
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-gateway-ach.php';
191
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-customer-manager.php';
192
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-gateway-conversions.php';
193
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-frontend-notices.php';
194
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-redirect-handler.php';
195
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-product-gateway-option.php';
196
-
197
- // settings
198
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-stripe-settings.php';
199
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/settings/class-wc-stripe-api-settings.php';
200
-
201
- if (is_admin ()) {
202
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/class-wc-stripe-admin-notices.php';
203
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/class-wc-stripe-admin-user-edit.php';
204
- }
205
-
206
- $this->payment_gateways = apply_filters ( 'wc_stripe_payment_gateways', array(
207
- 'WC_Payment_Gateway_Stripe_CC',
208
- 'WC_Payment_Gateway_Stripe_ApplePay',
209
- 'WC_Payment_Gateway_Stripe_GooglePay',
210
- 'WC_Payment_Gateway_Stripe_Payment_Request',
211
- 'WC_Payment_Gateway_Stripe_ACH',
212
- 'WC_Payment_Gateway_Stripe_Ideal',
213
- 'WC_Payment_Gateway_Stripe_P24',
214
- 'WC_Payment_Gateway_Stripe_Klarna',
215
- 'WC_Payment_Gateway_Stripe_Bancontact',
216
- 'WC_Payment_Gateway_Stripe_Giropay',
217
- 'WC_Payment_Gateway_Stripe_EPS',
218
- 'WC_Payment_Gateway_Stripe_Multibanco',
219
- 'WC_Payment_Gateway_Stripe_Sepa',
220
- 'WC_Payment_Gateway_Stripe_Sofort',
221
- 'WC_Payment_Gateway_Stripe_WeChat',
222
- 'WC_Payment_Gateway_Stripe_FPX',
223
- 'WC_Payment_Gateway_Stripe_Alipay'
224
- ) );
225
-
226
- $api_class = apply_filters ( 'wc_stripe_rest_api_class', 'WC_Stripe_Rest_API' );
227
- $this->rest_api = new $api_class ();
228
- $this->scripts = new WC_Stripe_Frontend_Scripts ();
229
-
230
- // allow other plugins to provide their own settings classes.
231
- $setting_classes = apply_filters ( 'wc_stripe_setting_classes', array(
232
- 'api_settings' => 'WC_Stripe_API_Settings'
233
- ) );
234
- foreach ( $setting_classes as $id => $class_name ) {
235
- if (class_exists ( $class_name )) {
236
- $this->{$id} = new $class_name ();
237
- }
238
- }
239
- }
240
-
241
- /**
242
- * Return the plugin template path.
243
- */
244
- public function template_path() {
245
- return 'woo-stripe-payment';
246
- }
247
-
248
- /**
249
- * Return the plguins default directory path for template files.
250
- */
251
- public function default_template_path() {
252
- return WC_STRIPE_PLUGIN_FILE_PATH . 'templates/';
253
- }
254
-
255
- /**
256
- *
257
- * @return string
258
- */
259
- public function rest_uri() {
260
- return 'wc-stripe/v1/';
261
- }
262
-
263
- /**
264
- *
265
- * @return string
266
- */
267
- public function rest_url() {
268
- return get_rest_url ( null, $this->rest_uri () );
269
- }
270
-
271
- /**
272
- *
273
- * @return WC_Stripe_Frontend_Scripts
274
- */
275
- public function scripts() {
276
- return $this->scripts;
277
- }
278
-
279
- public function payment_gateways() {
280
- return $this->payment_gateways;
281
- }
282
- }
283
-
284
- /**
285
- * Returns the global instance of the WC_Stripe_Manager.
286
- *
287
- * @package Stripe/Functions
288
- * @return WC_Stripe_Manager
289
- */
290
- function wc_stripe() {
291
- return WC_Stripe_Manager::instance ();
292
- }
293
-
294
- // load singleton
295
- wc_stripe ();
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * Singleton class that handles plugin functionality like class loading.
6
+ *
7
+ * @since 3.0.0
8
+ * @author PaymentPlugins
9
+ * @package Stripe/Classes
10
+ *
11
+ */
12
+ class WC_Stripe_Manager {
13
+
14
+ public static $_instance;
15
+
16
+ public static function instance() {
17
+ if ( self::$_instance == null ) {
18
+ self::$_instance = new self();
19
+ }
20
+
21
+ return self::$_instance;
22
+ }
23
+
24
+ /**
25
+ *
26
+ * @var string
27
+ */
28
+ public $version = '3.1.6';
29
+
30
+ /**
31
+ *
32
+ * @var WC_Stripe_Settings_API
33
+ */
34
+ public $api_settings;
35
+
36
+ /**
37
+ *
38
+ * @var WC_Stripe_Rest_API
39
+ */
40
+ public $rest_api;
41
+
42
+ /**
43
+ *
44
+ * @var string
45
+ */
46
+ public $client_id = 'ca_Gp4vLOJiqHJLZGxakHW7JdbBlcgWK8Up';
47
+
48
+ /**
49
+ * Test client id;
50
+ *
51
+ * @var string
52
+ */
53
+ //public $client_id = 'ca_Gp4vL3V6FpTguYoZIehD5COPeI80rLpV';
54
+
55
+ /**
56
+ *
57
+ * @var WC_Stripe_Frontend_Scripts
58
+ */
59
+ private $scripts;
60
+
61
+ /**
62
+ *
63
+ * @var array
64
+ */
65
+ private $payment_gateways;
66
+
67
+ public function __construct() {
68
+ add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 10 );
69
+ add_action( 'init', array( $this, 'init' ) );
70
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
71
+ add_action( 'woocommerce_init', array( $this, 'woocommerce_dependencies' ) );
72
+ $this->includes();
73
+ }
74
+
75
+ /**
76
+ * Return the plugin version.
77
+ *
78
+ * @return string
79
+ */
80
+ public function version() {
81
+ return $this->version;
82
+ }
83
+
84
+ /**
85
+ * Return the url for the plugin assets.
86
+ *
87
+ * @return string
88
+ */
89
+ public function assets_url( $uri = '' ) {
90
+ $url = WC_STRIPE_ASSETS . $uri;
91
+ if ( ! preg_match( '/(\.js)|(\.css)|(\.svg)|(\.png)/', $uri ) ) {
92
+ return trailingslashit( $url );
93
+ }
94
+
95
+ return $url;
96
+ }
97
+
98
+ /**
99
+ * Return the dir path for the plugin.
100
+ *
101
+ * @return string
102
+ */
103
+ public function plugin_path() {
104
+ return WC_STRIPE_PLUGIN_FILE_PATH;
105
+ }
106
+
107
+ public function plugins_loaded() {
108
+ load_plugin_textdomain( 'woo-stripe-payment', false, dirname( WC_STRIPE_PLUGIN_NAME ) . '/i18n/languages' );
109
+ }
110
+
111
+ /**
112
+ * Function that is hooked in to the WordPress init action.
113
+ */
114
+ public function init() {
115
+ }
116
+
117
+ public function includes() {
118
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-install.php';
119
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-update.php';
120
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-rest-api.php';
121
+
122
+ if ( is_admin() ) {
123
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/class-wc-stripe-admin-menus.php';
124
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/class-wc-stripe-admin-assets.php';
125
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/class-wc-stripe-admin-settings.php';
126
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/meta-boxes/class-wc-stripe-admin-order-metaboxes.php';
127
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/meta-boxes/class-wc-stripe-admin-meta-box-product-data.php';
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Function that is hooked in to the WordPress admin_init action.
133
+ */
134
+ public function admin_init() {
135
+ }
136
+
137
+ public function woocommerce_dependencies() {
138
+ // load functions
139
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/wc-stripe-functions.php';
140
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/wc-stripe-webhook-functions.php';
141
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/wc-stripe-hooks.php';
142
+
143
+ // constants
144
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-constants.php';
145
+
146
+ // traits
147
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/traits/wc-stripe-settings-trait.php';
148
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/traits/wc-stripe-controller-cart-trait.php';
149
+
150
+ // load factories
151
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-payment-factory.php';
152
+
153
+ // load gateways
154
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-payment-gateway-stripe.php';
155
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-payment-gateway-stripe-local-payment.php';
156
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-cc.php';
157
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-applepay.php';
158
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-googlepay.php';
159
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-ach.php';
160
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-payment-request.php';
161
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-ideal.php';
162
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-p24.php';
163
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-klarna.php';
164
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-giropay.php';
165
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-eps.php';
166
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-multibanco.php';
167
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-sepa.php';
168
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-sofort.php';
169
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-wechat.php';
170
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-bancontact.php';
171
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-fpx.php';
172
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/gateways/class-wc-payment-gateway-stripe-alipay.php';
173
+
174
+ // tokens
175
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-payment-token-stripe.php';
176
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/tokens/class-wc-payment-token-stripe-cc.php';
177
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/tokens/class-wc-payment-token-stripe-applepay.php';
178
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/tokens/class-wc-payment-token-stripe-googlepay.php';
179
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/tokens/class-wc-payment-token-stripe-local-payment.php';
180
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/tokens/class-wc-payment-token-stripe-ach.php';
181
+
182
+ // main classes
183
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-frontend-scripts.php';
184
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-field-manager.php';
185
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-rest-api.php';
186
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-gateway.php';
187
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-customer-manager.php';
188
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-gateway-conversions.php';
189
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-frontend-notices.php';
190
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-redirect-handler.php';
191
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-product-gateway-option.php';
192
+
193
+ // settings
194
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-stripe-settings.php';
195
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/settings/class-wc-stripe-api-settings.php';
196
+
197
+ if ( is_admin() ) {
198
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/class-wc-stripe-admin-notices.php';
199
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/admin/class-wc-stripe-admin-user-edit.php';
200
+ }
201
+
202
+ $this->payment_gateways = apply_filters(
203
+ 'wc_stripe_payment_gateways',
204
+ array(
205
+ 'WC_Payment_Gateway_Stripe_CC',
206
+ 'WC_Payment_Gateway_Stripe_ApplePay',
207
+ 'WC_Payment_Gateway_Stripe_GooglePay',
208
+ 'WC_Payment_Gateway_Stripe_Payment_Request',
209
+ 'WC_Payment_Gateway_Stripe_ACH',
210
+ 'WC_Payment_Gateway_Stripe_Ideal',
211
+ 'WC_Payment_Gateway_Stripe_P24',
212
+ 'WC_Payment_Gateway_Stripe_Klarna',
213
+ 'WC_Payment_Gateway_Stripe_Bancontact',
214
+ 'WC_Payment_Gateway_Stripe_Giropay',
215
+ 'WC_Payment_Gateway_Stripe_EPS',
216
+ 'WC_Payment_Gateway_Stripe_Multibanco',
217
+ 'WC_Payment_Gateway_Stripe_Sepa',
218
+ 'WC_Payment_Gateway_Stripe_Sofort',
219
+ 'WC_Payment_Gateway_Stripe_WeChat',
220
+ 'WC_Payment_Gateway_Stripe_FPX',
221
+ 'WC_Payment_Gateway_Stripe_Alipay',
222
+ )
223
+ );
224
+
225
+ $api_class = apply_filters( 'wc_stripe_rest_api_class', 'WC_Stripe_Rest_API' );
226
+ $this->rest_api = new $api_class();
227
+ $this->scripts = new WC_Stripe_Frontend_Scripts();
228
+
229
+ // allow other plugins to provide their own settings classes.
230
+ $setting_classes = apply_filters( 'wc_stripe_setting_classes', array( 'api_settings' => 'WC_Stripe_API_Settings' ) );
231
+ foreach ( $setting_classes as $id => $class_name ) {
232
+ if ( class_exists( $class_name ) ) {
233
+ $this->{$id} = new $class_name();
234
+ }
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Return the plugin template path.
240
+ */
241
+ public function template_path() {
242
+ return 'woo-stripe-payment';
243
+ }
244
+
245
+ /**
246
+ * Return the plguins default directory path for template files.
247
+ */
248
+ public function default_template_path() {
249
+ return WC_STRIPE_PLUGIN_FILE_PATH . 'templates/';
250
+ }
251
+
252
+ /**
253
+ *
254
+ * @return string
255
+ */
256
+ public function rest_uri() {
257
+ return 'wc-stripe/v1/';
258
+ }
259
+
260
+ /**
261
+ *
262
+ * @return string
263
+ */
264
+ public function rest_url() {
265
+ return get_rest_url( null, $this->rest_uri() );
266
+ }
267
+
268
+ /**
269
+ *
270
+ * @return WC_Stripe_Frontend_Scripts
271
+ */
272
+ public function scripts() {
273
+ return $this->scripts;
274
+ }
275
+
276
+ public function payment_gateways() {
277
+ return $this->payment_gateways;
278
+ }
279
+
280
+ /**
281
+ * Schedule actions required by the plugin
282
+ * @since 3.1.6
283
+ */
284
+ public function scheduled_actions() {
285
+ if ( function_exists( 'WC' ) ) {
286
+ if ( ! WC()->queue()->get_next( 'wc_stripe_remove_order_locks' ) ) {
287
+ WC()->queue()->schedule_recurring( strtotime( 'today midnight' ), DAY_IN_SECONDS, 'wc_stripe_remove_order_locks' );
288
+ }
289
+ }
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Returns the global instance of the WC_Stripe_Manager.
295
+ *
296
+ * @return WC_Stripe_Manager
297
+ * @package Stripe/Functions
298
+ */
299
+ function wc_stripe() {
300
+ return WC_Stripe_Manager::instance();
301
+ }
302
+
303
+ // load singleton
304
+ wc_stripe();
includes/class-wc-stripe-api-operation.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * Used as a wrapper for API requests to Stripe.
6
+ * Allows method chaining so things like mode can
7
+ * be set intuitively.
8
+ *
9
+ * @package Stripe/Classes
10
+ * @author PaymentPlugins
11
+ * @since 3.1.6
12
+ */
13
+ class WC_Stripe_API_Operation {
14
+
15
+ /**
16
+ *
17
+ * @var \Stripe\StripeClient
18
+ */
19
+ private $client;
20
+
21
+ /**
22
+ *
23
+ * @var string
24
+ */
25
+ private $property;
26
+
27
+ /**
28
+ *
29
+ * @var \Stripe\Service\AbstractService
30
+ */
31
+ private $service;
32
+
33
+ /**
34
+ *
35
+ * @var WC_Stripe_Gateway
36
+ */
37
+ private $gateway;
38
+
39
+ /**
40
+ *
41
+ * @var string
42
+ */
43
+ private $mode = '';
44
+
45
+ /**
46
+ *
47
+ * @param WC_Stripe_Gateway $gateway
48
+ * @param \Stripe\StripeClient $client
49
+ * @param string $property
50
+ *
51
+ * @throws InvalidArgumentException
52
+ */
53
+ public function __construct( $gateway, $client, $property ) {
54
+ $this->client = $client;
55
+ $this->property = $property;
56
+ $this->gateway = $gateway;
57
+
58
+ $service = $this->client->__get( $property );
59
+
60
+ if ( ! $service ) {
61
+ throw new InvalidArgumentException( sprintf( 'Property %s is not a valid entry', $property ) );
62
+ }
63
+
64
+ $this->service = $service;
65
+ }
66
+
67
+ /**
68
+ * Wrapper for Stripe API operations.
69
+ * This way, all exceptions can be caught gracefully.
70
+ *
71
+ * @param string $method
72
+ * @param array $args
73
+ *
74
+ * @throws InvalidArgumentException
75
+ */
76
+ public function __call( $method, $args ) {
77
+ if ( ! method_exists( $this->service, $method ) ) {
78
+ throw new InvalidArgumentException( sprintf( 'Method %s does not exist for class %s.', $method, get_class( $this->service ) ) );
79
+ }
80
+ $args = $this->parse_args( $args, $method );
81
+ try {
82
+ /**
83
+ * Filters arguments before they are sent to the service for an API request.
84
+ *
85
+ * @param array $args The array of arguments that will be passed to the service method.
86
+ * @param string $property The name of the service being called.
87
+ * @param string $method The method of the service. Ex: create, delete, retrieve
88
+ *
89
+ * @since 3.1.6
90
+ */
91
+ $args = apply_filters( 'wc_stripe_api_request_args', $args, $this->property, $method );
92
+
93
+ return $this->service->{$method}( ...$args );
94
+ } catch ( \Stripe\Exception\ApiErrorException $e ) {
95
+ return $this->gateway->get_wp_error( $e, $this->property . '-error' );
96
+ } catch ( \Stripe\Exception\UnexpectedValueException $e ) {
97
+ return new WP_Error( 'stripe-error', $e->getMessage(), $e );
98
+ }
99
+ }
100
+
101
+ /**
102
+ *
103
+ * @param string $mode
104
+ *
105
+ * @return $this
106
+ */
107
+ public function mode( $mode ) {
108
+ $this->mode = $mode;
109
+
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * Given an array of arguments, add method defaults to the array of args based on their existance.
115
+ *
116
+ * @param array $args
117
+ * @param string $method
118
+ */
119
+ private function parse_args( $args, $method ) {
120
+ $reflection_method = new ReflectionMethod( get_class( $this->service ), $method );
121
+ $num_args = $reflection_method->getNumberOfParameters();
122
+
123
+ // loop through each
124
+ foreach ( $reflection_method->getParameters() as $parameter ) {
125
+ if ( ! isset( $args[ $parameter->getPosition() ] ) && $parameter->isOptional() ) {
126
+ $args[ $parameter->getPosition() ] = $parameter->getDefaultValue();
127
+ }
128
+ }
129
+ // merge options
130
+ $args[ $num_args - 1 ] = wp_parse_args( $args[ $num_args - 1 ], $this->gateway->get_api_options( $this->mode ) );
131
+
132
+ return $args;
133
+ }
134
+ }
includes/class-wc-stripe-constants.php CHANGED
@@ -1,46 +1,46 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.1.0
7
- * @author Payment Plugins
8
- *
9
- */
10
- class WC_Stripe_Constants {
11
-
12
- const CUSTOMER_ID = '_wc_stripe_customer';
13
-
14
- const PAYMENT_METHOD_TOKEN = '_payment_method_token';
15
-
16
- const PAYMENT_INTENT_ID = '_payment_intent_id';
17
-
18
- const PAYMENT_INTENT = '_payment_intent';
19
-
20
- const MODE = '_wc_stripe_mode';
21
-
22
- const CHARGE_STATUS = '_wc_stripe_charge_status';
23
-
24
- const SOURCE_ID = '_stripe_source_id';
25
-
26
- const STRIPE_INTENT_ID = '_stripe_intent_id';
27
-
28
- const STRIPE_CUSTOMER_ID = '_stripe_customer_id';
29
-
30
- const SUCCESS = 'success';
31
-
32
- const FAILURE = 'failure';
33
-
34
- const WOOCOMMERCE_STRIPE_ORDER_PAY = 'WOOCOMMERCE_STRIPE_ORDER_PAY';
35
-
36
- const PRODUCT_GATEWAY_ORDER = '_stripe_gateway_order';
37
-
38
- const BUTTON_POSITION = '_stripe_button_position';
39
-
40
- /**
41
- *
42
- * @since 3.1.3
43
- * @var unknown
44
- */
45
- const REDIRECT_HANDLER = 'redirect_handler';
46
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @since 3.1.0
7
+ * @author Payment Plugins
8
+ *
9
+ */
10
+ class WC_Stripe_Constants {
11
+
12
+ const CUSTOMER_ID = '_wc_stripe_customer';
13
+
14
+ const PAYMENT_METHOD_TOKEN = '_payment_method_token';
15
+
16
+ const PAYMENT_INTENT_ID = '_payment_intent_id';
17
+
18
+ const PAYMENT_INTENT = '_payment_intent';
19
+
20
+ const MODE = '_wc_stripe_mode';
21
+
22
+ const CHARGE_STATUS = '_wc_stripe_charge_status';
23
+
24
+ const SOURCE_ID = '_stripe_source_id';
25
+
26
+ const STRIPE_INTENT_ID = '_stripe_intent_id';
27
+
28
+ const STRIPE_CUSTOMER_ID = '_stripe_customer_id';
29
+
30
+ const SUCCESS = 'success';
31
+
32
+ const FAILURE = 'failure';
33
+
34
+ const WOOCOMMERCE_STRIPE_ORDER_PAY = 'WOOCOMMERCE_STRIPE_ORDER_PAY';
35
+
36
+ const PRODUCT_GATEWAY_ORDER = '_stripe_gateway_order';
37
+
38
+ const BUTTON_POSITION = '_stripe_button_position';
39
+
40
+ /**
41
+ *
42
+ * @since 3.1.3
43
+ * @var unknown
44
+ */
45
+ const REDIRECT_HANDLER = 'redirect_handler';
46
+ }
includes/class-wc-stripe-customer-manager.php CHANGED
@@ -1,182 +1,195 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- * Class that manages customer creation and custom updates.
6
- *
7
- * @since 3.0.0
8
- * @package Stripe/Classes
9
- * @author PaymentPlugins
10
- *
11
- */
12
- class WC_Stripe_Customer_Manager {
13
-
14
- public function __construct() {
15
- add_action ( 'woocommerce_checkout_update_customer', array(
16
- $this, 'checkout_update_customer'
17
- ), 10, 2 );
18
- add_action ( 'wp_loaded', array( $this,
19
- 'wp_loaded'
20
- ) );
21
- }
22
-
23
- /**
24
- *
25
- * @param WC_Customer $customer
26
- * @param array $data
27
- */
28
- public function checkout_update_customer($customer, $data) {
29
- if ($this->user_has_id ( $customer )) {
30
- if ($this->should_update_customer ( $customer )) {
31
- $result = $this->update_customer ( $customer );
32
- if (is_wp_error ( $result )) {
33
- wc_add_notice ( __ ( 'Error saving customer. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message () );
34
- }
35
- }
36
- } else {
37
- // create the customer
38
- $customer_id = $this->create_customer ( $customer );
39
- if (! is_wp_error ( $customer_id )) {
40
- wc_stripe_save_customer ( $customer_id, $customer->get_id () );
41
- } else {
42
- wc_add_notice ( __ ( 'Error saving customer. Reason: %s', 'woo-stripe-payment' ), $customer_id->get_error_message () );
43
- }
44
- }
45
- }
46
-
47
- /**
48
- *
49
- * @param WC_Customer $customer
50
- */
51
- private function create_customer($customer) {
52
- return WC_Stripe_Gateway::load ()->create_customer ( apply_filters ( 'wc_stripe_customer_args', array(
53
- 'email' => $customer->get_email (),
54
- 'name' => sprintf ( '%s %s', $customer->get_first_name (), $customer->get_last_name () ),
55
- 'phone' => $customer->get_billing_phone (),
56
- 'metadata' => array(
57
- 'user_id' => $customer->get_id (),
58
- 'username' => $customer->get_username (),
59
- 'website' => get_site_url ()
60
- )
61
- ) ) );
62
- }
63
-
64
- /**
65
- *
66
- * @param WC_Customer $customer
67
- */
68
- private function update_customer($customer) {
69
- return WC_Stripe_Gateway::load ()->update_customer ( wc_stripe_get_customer_id ( $customer->get_id () ), array(
70
- 'email' => $customer->get_billing_email (),
71
- 'name' => sprintf ( '%s %s', $customer->get_billing_first_name (), $customer->get_billing_last_name () ),
72
- 'phone' => $customer->get_billing_phone ()
73
- ) );
74
- }
75
-
76
- /**
77
- * Check if the Stripe customer has been created for the WC user.
78
- * If there is no Stripe customer then
79
- * create one and save it to the WC user.
80
- */
81
- public function wp_loaded() {
82
- $customer = WC ()->customer;
83
- if ($customer && $customer->get_id ()) {
84
- if (! $this->user_has_id ( $customer )) {
85
- $customer_id = $this->create_customer ( $customer );
86
- if (! is_wp_error ( $customer_id )) {
87
- wc_stripe_save_customer ( $customer_id, $customer->get_id () );
88
- }
89
- }
90
- }
91
- }
92
-
93
- /**
94
- *
95
- * @param WC_Customer $customer
96
- */
97
- private function user_has_id($customer) {
98
- $id = wc_stripe_get_customer_id ( $customer->get_id () );
99
-
100
- // this customer may have an ID from another plugin. Check that too.
101
- if (empty ( $id )) {
102
- $id = get_user_option ( '_stripe_customer_id', $customer->get_id () );
103
- if (! empty ( $id )) {
104
- // validate that this customer exists in the Stripe gateway
105
- $response = WC_Stripe_Gateway::load ()->fetch_customer ( $id );
106
- if (! is_wp_error ( $response )) {
107
- // id exists so save customer ID to this plugin's format.
108
- wc_stripe_save_customer ( $id, $customer->get_id () );
109
-
110
- // load this customer's payment methods
111
- $this->sync_payment_methods ( $id, $customer->get_id () );
112
- } else {
113
- $id = '';
114
- }
115
- }
116
- }
117
- return ! empty ( $id );
118
- }
119
-
120
- /**
121
- * Syncs the WC database payment methods with the payment methods stored in Stripe.
122
- *
123
- * @since 3.1.0
124
- * @param string $customer_id
125
- * @param int $user_id
126
- */
127
- public static function sync_payment_methods($customer_id, $user_id) {
128
- $payment_methods = WC_Stripe_Gateway::load ()->fetch_payment_methods ( $customer_id );
129
-
130
- if (! is_wp_error ( $payment_methods )) {
131
- foreach ( $payment_methods->data as $payment_method ) {
132
- if (! WC_Payment_Token_Stripe::token_exists ( $payment_method->id, $user_id )) {
133
- $payment_gateways = WC ()->payment_gateways ()->payment_gateways ();
134
- $gateway_id = null;
135
-
136
- if (strstr ( $payment_method->id, 'pm_' ) || strstr ( $payment_method->id, 'src_' )) {
137
- $gateway_id = 'stripe_cc';
138
- } elseif (strstr ( $payment_method->id, 'card_' )) {
139
- $gateway_id = 'stripe_googlepay';
140
- }
141
- /**
142
- *
143
- * @var WC_Payment_Gateway_Stripe_CC $payment_gateway
144
- */
145
- $payment_gateway = $payment_gateways[ $gateway_id ];
146
- $token = $payment_gateway->get_payment_token ( $payment_method->id, $payment_method );
147
- $token->set_environment ( $payment_method->livemode ? 'live' : 'test' );
148
- $token->set_user_id ( $user_id );
149
- $token->set_customer_id ( $customer_id );
150
- $token->save ();
151
- }
152
- }
153
- } else {
154
- wc_stripe_log_info ( sprintf ( 'Payment methods for customer %s could not be synced. Reason: %s', $customer_id, $payment_methods->get_error_message () ) );
155
- }
156
- }
157
-
158
- /**
159
- * Returns true if the customer should be updated in Stripe.
160
- *
161
- * @param WC_Customer $customer
162
- * @return bool
163
- */
164
- private function should_update_customer($customer) {
165
- $changes = $customer->get_changes ();
166
- if (! empty ( $changes[ 'billing' ] )) {
167
- return array_intersect_key ( $changes[ 'billing' ], array_flip ( $this->get_attribute_keys () ) );
168
- }
169
- return false;
170
- }
171
-
172
- /**
173
- * Returns an array of user attributes.
174
- *
175
- * @return array
176
- */
177
- private function get_attribute_keys() {
178
- return [ 'first_name', 'last_name', 'email'
179
- ];
180
- }
181
- }
182
- new WC_Stripe_Customer_Manager ();
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * Class that manages customer creation and custom updates.
6
+ *
7
+ * @since 3.0.0
8
+ * @package Stripe/Classes
9
+ * @author PaymentPlugins
10
+ *
11
+ */
12
+ class WC_Stripe_Customer_Manager {
13
+
14
+ public function __construct() {
15
+ add_action( 'woocommerce_checkout_update_customer', array( $this, 'checkout_update_customer' ), 10, 2 );
16
+ add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );
17
+ }
18
+
19
+ /**
20
+ *
21
+ * @param WC_Customer $customer
22
+ * @param array $data
23
+ */
24
+ public function checkout_update_customer( $customer, $data ) {
25
+ if ( $this->user_has_id( $customer ) ) {
26
+ if ( $this->should_update_customer( $customer ) ) {
27
+ $result = $this->update_customer( $customer );
28
+ if ( is_wp_error( $result ) ) {
29
+ wc_add_notice( __( 'Error saving customer. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() );
30
+ }
31
+ }
32
+ } else {
33
+ // create the customer
34
+ $response = $this->create_customer( $customer );
35
+ if ( ! is_wp_error( $response ) ) {
36
+ wc_stripe_save_customer( $response->id, $customer->get_id() );
37
+ } else {
38
+ wc_add_notice( __( 'Error saving customer. Reason: %s', 'woo-stripe-payment' ), $response->get_error_message() );
39
+ }
40
+ }
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @param WC_Customer $customer
46
+ *
47
+ * @return \Stripe\Customer|WP_Error
48
+ */
49
+ private function create_customer( $customer ) {
50
+ return WC_Stripe_Gateway::load()->customers->create(
51
+ apply_filters(
52
+ 'wc_stripe_customer_args',
53
+ array(
54
+ 'email' => $customer->get_email(),
55
+ 'name' => sprintf( '%s %s', $customer->get_first_name(), $customer->get_last_name() ),
56
+ 'phone' => $customer->get_billing_phone(),
57
+ 'metadata' => array(
58
+ 'user_id' => $customer->get_id(),
59
+ 'username' => $customer->get_username(),
60
+ 'website' => get_site_url(),
61
+ ),
62
+ )
63
+ )
64
+ );
65
+ }
66
+
67
+ /**
68
+ *
69
+ * @param WC_Customer $customer
70
+ */
71
+ private function update_customer( $customer ) {
72
+ return WC_Stripe_Gateway::load()->customers->update(
73
+ wc_stripe_get_customer_id( $customer->get_id() ),
74
+ apply_filters( 'wc_stripe_update_customer_args', array(
75
+ 'email' => $customer->get_billing_email(),
76
+ 'name' => sprintf( '%s %s', $customer->get_billing_first_name(), $customer->get_billing_last_name() ),
77
+ 'phone' => $customer->get_billing_phone(),
78
+ ) )
79
+ );
80
+ }
81
+
82
+ /**
83
+ * Check if the Stripe customer has been created for the WC user.
84
+ * If there is no Stripe customer then
85
+ * create one and save it to the WC user.
86
+ */
87
+ public function wp_loaded() {
88
+ $customer = WC()->customer;
89
+ if ( $customer && $customer->get_id() ) {
90
+ if ( ! $this->user_has_id( $customer ) ) {
91
+ $response = $this->create_customer( $customer );
92
+ if ( ! is_wp_error( $response ) ) {
93
+ wc_stripe_save_customer( $response->id, $customer->get_id() );
94
+ }
95
+ }
96
+ }
97
+ }
98
+
99
+ /**
100
+ *
101
+ * @param WC_Customer $customer
102
+ */
103
+ private function user_has_id( $customer ) {
104
+ $id = wc_stripe_get_customer_id( $customer->get_id() );
105
+
106
+ // this customer may have an ID from another plugin. Check that too.
107
+ if ( empty( $id ) ) {
108
+ $id = get_user_option( '_stripe_customer_id', $customer->get_id() );
109
+ if ( ! empty( $id ) ) {
110
+ // validate that this customer exists in the Stripe gateway
111
+ $response = WC_Stripe_Gateway::load()->customers->retrieve( $id );
112
+ if ( ! is_wp_error( $response ) ) {
113
+ // id exists so save customer ID to this plugin's format.
114
+ wc_stripe_save_customer( $id, $customer->get_id() );
115
+
116
+ // load this customer's payment methods
117
+ $this->sync_payment_methods( $id, $customer->get_id() );
118
+ } else {
119
+ $id = '';
120
+ }
121
+ }
122
+ }
123
+
124
+ return ! empty( $id );
125
+ }
126
+
127
+ /**
128
+ * Syncs the WC database payment methods with the payment methods stored in Stripe.
129
+ *
130
+ * @param string $customer_id
131
+ * @param int $user_id
132
+ *
133
+ * @since 3.1.0
134
+ */
135
+ public static function sync_payment_methods( $customer_id, $user_id, $mode = '' ) {
136
+ $payment_methods = WC_Stripe_Gateway::load()->paymentMethods->mode( $mode )->all( array(
137
+ 'customer' => $customer_id,
138
+ 'type' => 'card',
139
+ ) );
140
+
141
+ if ( ! is_wp_error( $payment_methods ) ) {
142
+ foreach ( $payment_methods->data as $payment_method ) {
143
+ if ( ! WC_Payment_Token_Stripe::token_exists( $payment_method->id, $user_id ) ) {
144
+ $payment_gateways = WC()->payment_gateways()->payment_gateways();
145
+ $gateway_id = null;
146
+
147
+ if ( strstr( $payment_method->id, 'pm_' ) || strstr( $payment_method->id, 'src_' ) ) {
148
+ $gateway_id = 'stripe_cc';
149
+ } elseif ( strstr( $payment_method->id, 'card_' ) ) {
150
+ $gateway_id = 'stripe_googlepay';
151
+ }
152
+ /**
153
+ *
154
+ * @var WC_Payment_Gateway_Stripe_CC $payment_gateway
155
+ */
156
+ $payment_gateway = $payment_gateways[ $gateway_id ];
157
+ $token = $payment_gateway->get_payment_token( $payment_method->id, $payment_method );
158
+ $token->set_environment( $payment_method->livemode ? 'live' : 'test' );
159
+ $token->set_user_id( $user_id );
160
+ $token->set_customer_id( $customer_id );
161
+ $token->save();
162
+ }
163
+ }
164
+ } else {
165
+ wc_stripe_log_info( sprintf( 'Payment methods for customer %s could not be synced. Reason: %s', $customer_id, $payment_methods->get_error_message() ) );
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Returns true if the customer should be updated in Stripe.
171
+ *
172
+ * @param WC_Customer $customer
173
+ *
174
+ * @return bool
175
+ */
176
+ private function should_update_customer( $customer ) {
177
+ $changes = $customer->get_changes();
178
+ if ( ! empty( $changes['billing'] ) ) {
179
+ return array_intersect_key( $changes['billing'], array_flip( $this->get_attribute_keys() ) );
180
+ }
181
+
182
+ return false;
183
+ }
184
+
185
+ /**
186
+ * Returns an array of user attributes.
187
+ *
188
+ * @return array
189
+ */
190
+ private function get_attribute_keys() {
191
+ return array( 'first_name', 'last_name', 'email' );
192
+ }
193
+ }
194
+
195
+ new WC_Stripe_Customer_Manager();
includes/class-wc-stripe-field-manager.php CHANGED
@@ -1,246 +1,256 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.0.0
7
- * @package Stripe/Classes
8
- * @author Payment Plugins
9
- *
10
- */
11
- class WC_Stripe_Field_Manager {
12
-
13
- private static $_cart_priority = 30;
14
-
15
- private static $_product_button_position;
16
-
17
- public static function init() {
18
- add_action ( 'woocommerce_checkout_before_customer_details', array(
19
- __CLASS__, 'output_banner_checkout_fields'
20
- ) );
21
- add_action ( 'woocommerce_before_add_to_cart_form', array(
22
- __CLASS__, 'before_add_to_cart'
23
- ) );
24
- add_action ( 'init', [ __CLASS__,
25
- 'init_action'
26
- ] );
27
- add_action ( 'woocommerce_review_order_after_order_total', [
28
- __CLASS__, 'output_checkout_fields'
29
- ] );
30
- add_action ( 'before_woocommerce_add_payment_method', array(
31
- __CLASS__, 'add_payment_method_fields'
32
- ) );
33
- add_action ( 'before_woocommerce_pay', array(
34
- __CLASS__, 'change_payment_request'
35
- ) );
36
- /*
37
- * add_action ( 'woocommerce_quantity_input_args', array(
38
- * __CLASS__, 'quantity_input_value'
39
- * ) );
40
- */
41
- add_action ( 'woocommerce_pay_order_after_submit', array(
42
- __CLASS__, 'pay_order_fields'
43
- ) );
44
- }
45
-
46
- public static function init_action() {
47
- self::$_cart_priority = apply_filters ( 'wc_stripe_cart_buttons_order', 30 );
48
- add_action ( 'woocommerce_proceed_to_checkout', [
49
- __CLASS__, 'output_cart_fields'
50
- ], self::$_cart_priority );
51
- }
52
-
53
- public static function output_banner_checkout_fields() {
54
- $gateways = [];
55
- foreach ( WC ()->payment_gateways ()->get_available_payment_gateways () as $gateway ) {
56
- if ($gateway->supports ( 'wc_stripe_banner_checkout' ) && $gateway->banner_checkout_enabled ()) {
57
- $gateways[ $gateway->id ] = $gateway;
58
- }
59
- }
60
- if ($gateways) {
61
- wc_stripe_get_template ( 'checkout/checkout-banner.php', [
62
- 'gateways' => $gateways
63
- ] );
64
- }
65
- }
66
-
67
- public static function output_checkout_fields() {
68
- self::output_required_fields ();
69
-
70
- wp_localize_script ( 'wc-checkout', 'wc_stripe_checkout_fields', [
71
- 'billing' => WC ()->checkout ()->get_checkout_fields ( 'billing' ),
72
- 'shipping' => WC ()->checkout ()->get_checkout_fields ( 'shipping' )
73
- ] );
74
-
75
- do_action ( 'wc_stripe_output_checkout_fields' );
76
- }
77
-
78
- public static function before_add_to_cart() {
79
- global $product;
80
- self::$_product_button_position = $product->get_meta ( WC_Stripe_Constants::BUTTON_POSITION );
81
- if (empty ( self::$_product_button_position )) {
82
- self::$_product_button_position = 'bottom';
83
- }
84
-
85
- if ('bottom' == self::$_product_button_position) {
86
- $action = 'woocommerce_after_add_to_cart_button';
87
- } else {
88
- $action = 'woocommerce_before_add_to_cart_button';
89
- }
90
- add_action ( $action, array( __CLASS__,
91
- 'output_product_checkout_fields'
92
- ) );
93
- }
94
-
95
- public static function output_product_checkout_fields() {
96
- global $product;
97
- $gateways = [];
98
- $ordering = $product->get_meta ( WC_Stripe_Constants::PRODUCT_GATEWAY_ORDER );
99
- $ordering = ! $ordering ? [] : $ordering;
100
-
101
- foreach ( WC ()->payment_gateways ()->get_available_payment_gateways () as $id => $gateway ) {
102
- /**
103
- *
104
- * @var WC_Payment_Gateway_Stripe $gateway
105
- */
106
- if ($gateway->supports ( 'wc_stripe_product_checkout' )) {
107
- $option = new WC_Stripe_Product_Gateway_Option ( $product, $gateway );
108
- if ($option->enabled ()) {
109
- if (isset ( $ordering[ $gateway->id ] )) {
110
- $gateways[ $ordering[ $gateway->id ] ] = $gateway;
111
- } else {
112
- $gateways[] = $gateway;
113
- }
114
- }
115
- }
116
- }
117
- ksort ( $gateways );
118
-
119
- if (count ( $gateways ) > 0) {
120
-
121
- self::output_required_fields ();
122
- printf ( '<input type="hidden" id="product_id" name="product_id", value="%s"/>', $product->get_id () );
123
- printf ( '<input type="hidden" id="wc_stripe_product_data" data-product="%s"/>', htmlspecialchars ( wp_json_encode ( [
124
- 'product_id' => $product->get_id (),
125
- 'price' => $product->get_price (),
126
- 'needs_shipping' => $product->needs_shipping ()
127
- ] ) ) );
128
- printf ( '<input type="hidden" id="wc_stripe_display_items" data-items="%s"/>', htmlspecialchars ( wp_json_encode ( [
129
- [
130
- 'amount' => wc_stripe_add_number_precision ( $product->get_price () ),
131
- 'label' => esc_attr ( $product->get_name () ),
132
- 'pending' => true
133
- ]
134
- ] ) ) );
135
- printf ( '<input type="hidden" id="wc_stripe_shipping_options" data-items="%s"/>', htmlspecialchars ( wp_json_encode ( [] ) ) );
136
- printf ( '<input type="hidden" id="wc_stripe_order_total_cents" data-amount="%s"/>', wc_stripe_add_number_precision ( $product->get_price () ) );
137
-
138
- self::output_fields ( 'billing' );
139
-
140
- // don't always need shipping fields but doesn't hurt to output them anyway.
141
- self::output_fields ( 'shipping' );
142
-
143
- wc_stripe_get_template ( 'product/payment-methods.php', [
144
- 'position' => self::$_product_button_position,
145
- 'gateways' => $gateways
146
- ] );
147
- }
148
- }
149
-
150
- public static function output_cart_fields() {
151
- $gateways = [];
152
- foreach ( WC ()->payment_gateways ()->get_available_payment_gateways () as $id => $gateway ) {
153
- /**
154
- *
155
- * @var WC_Payment_Gateway_Stripe $gateway
156
- */
157
- if ($gateway->supports ( 'wc_stripe_cart_checkout' ) && $gateway->cart_checkout_enabled ()) {
158
- $gateways[ $gateway->id ] = $gateway;
159
- }
160
- }
161
- if (! empty ( $gateways )) {
162
- echo '<form id="wc-stripe-cart-form">';
163
- self::output_required_fields ();
164
-
165
- self::output_fields ( 'billing' );
166
-
167
- if (WC ()->cart->needs_shipping ()) {
168
- self::output_needs_shipping ( true );
169
- self::output_fields ( 'shipping' );
170
- } else {
171
- self::output_needs_shipping ( false );
172
- }
173
-
174
- wc_stripe_get_template ( 'cart/payment-methods.php', [
175
- 'gateways' => $gateways,
176
- 'after' => self::$_cart_priority > 20,
177
- 'cart_total' => WC ()->cart->total
178
- ] );
179
- echo '</form>';
180
- }
181
- }
182
-
183
- public static function change_payment_request() {
184
- if (wcs_stripe_active () && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment) {
185
- $subscription = wcs_get_subscription ( absint ( $_GET[ 'change_payment_method' ] ) );
186
- self::output_required_fields ( $subscription );
187
- }
188
- }
189
-
190
- public static function add_payment_method_fields() {
191
- wc_stripe_hidden_field ( 'billing_first_name', '', WC ()->customer->get_first_name () );
192
- wc_stripe_hidden_field ( 'billing_last_name', '', WC ()->customer->get_last_name () );
193
- }
194
-
195
- public static function pay_order_fields() {
196
- global $wp;
197
- $order = wc_get_order ( absint ( $wp->query_vars[ 'order-pay' ] ) );
198
- self::output_required_fields ( $order );
199
- }
200
-
201
- /**
202
- *
203
- * @param WC_Order $order
204
- */
205
- public static function output_required_fields($order = null) {
206
- printf ( '<input type="hidden" id="%1$s" value="%2$s"/>', 'wc_stripe_currency', $order ? $order->get_currency () : get_woocommerce_currency () );
207
- printf ( '<input type="hidden" id="%1$s" data-amount="%2$s"/>', 'wc_stripe_order_total', $order ? $order->get_total () : WC ()->cart->total );
208
- if (is_cart () || is_checkout ()) {
209
- printf ( '<input type="hidden" id="wc_stripe_display_items" data-items="%s"/>', wc_stripe_get_display_items ( true, $order ) );
210
- printf ( '<input type="hidden" id="wc_stripe_shipping_options" data-items="%s"/>', wc_stripe_get_shipping_options ( true, $order ) );
211
- printf ( '<input type="hidden" id="wc_stripe_order_total_cents" data-amount="%s"/>', wc_stripe_add_number_precision ( ( $order ? $order->get_total () : WC ()->cart->total ), ( $order ? $order->get_currency () : '' ) ) );
212
- }
213
- }
214
-
215
- public static function output_fields($prefix) {
216
- $fields = WC ()->checkout ()->get_checkout_fields ( $prefix );
217
- foreach ( $fields as $key => $field ) {
218
- printf ( '<input type="hidden" id="%1$s" name="%1$s" value="%2$s"/>', $key, WC ()->checkout ()->get_value ( $key ) );
219
- }
220
- }
221
-
222
- public static function output_needs_shipping($needs_shipping) {
223
- printf ( '<input type="hidden" id="wc_stripe_needs_shipping" data-value="%s" />', $needs_shipping );
224
- }
225
-
226
- /**
227
- *
228
- * @deprecated
229
- *
230
- * @param array $args
231
- */
232
- public static function quantity_input_value($args) {
233
- if (is_product ()) {
234
- foreach ( WC ()->payment_gateways ()->get_available_payment_gateways () as $id => $gateway ) {
235
- if ($gateway->supports ( 'wc_stripe_product_checkout' )) {
236
- $args[ 'min_value' ] = 0;
237
- break;
238
- }
239
- }
240
- }
241
- return $args;
242
- }
243
- }
244
- if (! is_admin ()) {
245
- WC_Stripe_Field_Manager::init ();
246
- }
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @since 3.0.0
7
+ * @package Stripe/Classes
8
+ * @author Payment Plugins
9
+ *
10
+ */
11
+ class WC_Stripe_Field_Manager {
12
+
13
+ private static $_cart_priority = 30;
14
+
15
+ private static $_product_button_position;
16
+
17
+ public static function init() {
18
+ add_action( 'woocommerce_checkout_before_customer_details', array( __CLASS__, 'output_banner_checkout_fields' ) );
19
+ add_action( 'woocommerce_before_add_to_cart_form', array( __CLASS__, 'before_add_to_cart' ) );
20
+ add_action( 'init', array( __CLASS__, 'init_action' ) );
21
+ add_action( 'woocommerce_review_order_after_order_total', array( __CLASS__, 'output_checkout_fields' ) );
22
+ add_action( 'before_woocommerce_add_payment_method', array( __CLASS__, 'add_payment_method_fields' ) );
23
+ add_action( 'before_woocommerce_pay', array( __CLASS__, 'change_payment_request' ) );
24
+ add_action( 'woocommerce_pay_order_after_submit', array( __CLASS__, 'pay_order_fields' ) );
25
+ }
26
+
27
+ public static function init_action() {
28
+ self::$_cart_priority = apply_filters( 'wc_stripe_cart_buttons_order', 30 );
29
+ add_action( 'woocommerce_proceed_to_checkout', array( __CLASS__, 'output_cart_fields' ), self::$_cart_priority );
30
+ }
31
+
32
+ public static function output_banner_checkout_fields() {
33
+ $gateways = array();
34
+ foreach ( WC()->payment_gateways()->get_available_payment_gateways() as $gateway ) {
35
+ if ( $gateway->supports( 'wc_stripe_banner_checkout' ) && $gateway->banner_checkout_enabled() ) {
36
+ $gateways[ $gateway->id ] = $gateway;
37
+ }
38
+ }
39
+ if ( $gateways ) {
40
+ wc_stripe_get_template( 'checkout/checkout-banner.php', array( 'gateways' => $gateways ) );
41
+ }
42
+ }
43
+
44
+ public static function output_checkout_fields() {
45
+ self::output_required_fields( 'checkout' );
46
+
47
+ wp_localize_script(
48
+ 'wc-checkout',
49
+ 'wc_stripe_checkout_fields',
50
+ array(
51
+ 'billing' => WC()->checkout()->get_checkout_fields( 'billing' ),
52
+ 'shipping' => WC()->checkout()->get_checkout_fields( 'shipping' ),
53
+ )
54
+ );
55
+
56
+ do_action( 'wc_stripe_output_checkout_fields' );
57
+ }
58
+
59
+ public static function before_add_to_cart() {
60
+ global $product;
61
+ self::$_product_button_position = $product->get_meta( WC_Stripe_Constants::BUTTON_POSITION );
62
+ if ( empty( self::$_product_button_position ) ) {
63
+ self::$_product_button_position = 'bottom';
64
+ }
65
+
66
+ if ( 'bottom' == self::$_product_button_position ) {
67
+ $action = 'woocommerce_after_add_to_cart_button';
68
+ } else {
69
+ $action = 'woocommerce_before_add_to_cart_button';
70
+ }
71
+ add_action( $action, array( __CLASS__, 'output_product_checkout_fields' ) );
72
+ }
73
+
74
+ public static function output_product_checkout_fields() {
75
+ global $product;
76
+ $gateways = array();
77
+ $ordering = $product->get_meta( WC_Stripe_Constants::PRODUCT_GATEWAY_ORDER );
78
+ $ordering = ! $ordering ? array() : $ordering;
79
+
80
+ foreach ( WC()->payment_gateways()->get_available_payment_gateways() as $id => $gateway ) {
81
+ /**
82
+ *
83
+ * @var WC_Payment_Gateway_Stripe $gateway
84
+ */
85
+ if ( $gateway->supports( 'wc_stripe_product_checkout' ) ) {
86
+ $option = new WC_Stripe_Product_Gateway_Option( $product, $gateway );
87
+ if ( $option->enabled() ) {
88
+ if ( isset( $ordering[ $gateway->id ] ) ) {
89
+ $gateways[ $ordering[ $gateway->id ] ] = $gateway;
90
+ } else {
91
+ $gateways[] = $gateway;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ ksort( $gateways );
97
+
98
+ if ( count( $gateways ) > 0 ) {
99
+
100
+ self::output_required_fields( 'product' );
101
+
102
+ wc_stripe_get_template(
103
+ 'product/payment-methods.php',
104
+ array(
105
+ 'position' => self::$_product_button_position,
106
+ 'gateways' => $gateways,
107
+ )
108
+ );
109
+ }
110
+ }
111
+
112
+ public static function output_cart_fields() {
113
+ $gateways = array();
114
+ foreach ( WC()->payment_gateways()->get_available_payment_gateways() as $id => $gateway ) {
115
+ /**
116
+ *
117
+ * @var WC_Payment_Gateway_Stripe $gateway
118
+ */
119
+ if ( $gateway->supports( 'wc_stripe_cart_checkout' ) && $gateway->cart_checkout_enabled() ) {
120
+ $gateways[ $gateway->id ] = $gateway;
121
+ }
122
+ }
123
+ if ( ! empty( $gateways ) ) {
124
+ echo '<form id="wc-stripe-cart-form">';
125
+
126
+ self::output_required_fields( 'cart' );
127
+
128
+ wc_stripe_get_template(
129
+ 'cart/payment-methods.php',
130
+ array(
131
+ 'gateways' => $gateways,
132
+ 'after' => self::$_cart_priority > 20,
133
+ 'cart_total' => WC()->cart->total,
134
+ )
135
+ );
136
+ echo '</form>';
137
+ }
138
+ }
139
+
140
+ public static function change_payment_request() {
141
+ if ( wcs_stripe_active() && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment ) {
142
+ $subscription = wcs_get_subscription( absint( $_GET['change_payment_method'] ) );
143
+ self::output_required_fields( 'checkout', $subscription );
144
+ }
145
+ }
146
+
147
+ public static function add_payment_method_fields() {
148
+ wc_stripe_hidden_field( 'billing_first_name', '', WC()->customer->get_first_name() );
149
+ wc_stripe_hidden_field( 'billing_last_name', '', WC()->customer->get_last_name() );
150
+ }
151
+
152
+ public static function pay_order_fields() {
153
+ global $wp;
154
+ $order = wc_get_order( absint( $wp->query_vars['order-pay'] ) );
155
+ self::output_required_fields( 'checkout', $order );
156
+ }
157
+
158
+ /**
159
+ * @param string $page
160
+ * @param WC_Order $order
161
+ */
162
+ public static function output_required_fields( $page, $order = null ) {
163
+ printf( '<input type="hidden" id="%1$s" value="%2$s"/>', 'wc_stripe_currency', $order ? $order->get_currency() : get_woocommerce_currency() );
164
+ printf( '<input type="hidden" id="%1$s" data-amount="%2$s"/>', 'wc_stripe_order_total', $order ? $order->get_total() : WC()->cart->total );
165
+ if ( in_array( $page, array( 'cart', 'checkout' ) ) ) {
166
+ printf( '<input type="hidden" id="wc_stripe_display_items" data-items="%s"/>', wc_stripe_get_display_items( true, $order ) );
167
+ printf( '<input type="hidden" id="wc_stripe_shipping_options" data-items="%s"/>', wc_stripe_get_shipping_options( true, $order ) );
168
+ printf( '<input type="hidden" id="wc_stripe_order_total_cents" data-amount="%s"/>', wc_stripe_add_number_precision( ( $order ? $order->get_total() : WC()->cart->total ), ( $order ? $order->get_currency() : '' ) ) );
169
+
170
+ if ( 'cart' === $page ) {
171
+ self::output_fields( 'billing' );
172
+
173
+ if ( WC()->cart->needs_shipping() ) {
174
+ self::output_needs_shipping( true );
175
+ self::output_fields( 'shipping' );
176
+ } else {
177
+ self::output_needs_shipping( false );
178
+ }
179
+ }
180
+
181
+ } elseif ( 'product' === $page ) {
182
+ global $product;
183
+
184
+ self::output_fields( 'billing' );
185
+
186
+ if ( $product->needs_shipping() ) {
187
+ self::output_fields( 'shipping' );
188
+ }
189
+ printf( '<input type="hidden" id="product_id" name="product_id", value="%s"/>', $product->get_id() );
190
+ printf(
191
+ '<input type="hidden" id="wc_stripe_product_data" data-product="%s"/>',
192
+ htmlspecialchars(
193
+ wp_json_encode(
194
+ array(
195
+ 'product_id' => $product->get_id(),
196
+ 'price' => $product->get_price(),
197
+ 'needs_shipping' => $product->needs_shipping(),
198
+ )
199
+ )
200
+ )
201
+ );
202
+ printf(
203
+ '<input type="hidden" id="wc_stripe_display_items" data-items="%s"/>',
204
+ htmlspecialchars(
205
+ wp_json_encode(
206
+ array(
207
+ array(
208
+ 'amount' => wc_stripe_add_number_precision( $product->get_price() ),
209
+ 'label' => esc_attr( $product->get_name() ),
210
+ 'pending' => true,
211
+ ),
212
+ )
213
+ )
214
+ )
215
+ );
216
+ printf( '<input type="hidden" id="wc_stripe_shipping_options" data-items="%s"/>', htmlspecialchars( wp_json_encode( array() ) ) );
217
+ printf( '<input type="hidden" id="wc_stripe_order_total_cents" data-amount="%s"/>', wc_stripe_add_number_precision( $product->get_price() ) );
218
+
219
+ }
220
+ }
221
+
222
+ public static function output_fields( $prefix ) {
223
+ $fields = WC()->checkout()->get_checkout_fields( $prefix );
224
+ foreach ( $fields as $key => $field ) {
225
+ printf( '<input type="hidden" id="%1$s" name="%1$s" value="%2$s"/>', $key, WC()->checkout()->get_value( $key ) );
226
+ }
227
+ }
228
+
229
+ public static function output_needs_shipping( $needs_shipping ) {
230
+ printf( '<input type="hidden" id="wc_stripe_needs_shipping" data-value="%s" />', $needs_shipping );
231
+ }
232
+
233
+ /**
234
+ *
235
+ * @param array $args
236
+ *
237
+ * @deprecated
238
+ *
239
+ */
240
+ public static function quantity_input_value( $args ) {
241
+ if ( is_product() ) {
242
+ foreach ( WC()->payment_gateways()->get_available_payment_gateways() as $id => $gateway ) {
243
+ if ( $gateway->supports( 'wc_stripe_product_checkout' ) ) {
244
+ $args['min_value'] = 0;
245
+ break;
246
+ }
247
+ }
248
+ }
249
+
250
+ return $args;
251
+ }
252
+ }
253
+
254
+ if ( ! is_admin() ) {
255
+ WC_Stripe_Field_Manager::init();
256
+ }
includes/class-wc-stripe-frontend-notices.php CHANGED
@@ -1,58 +1,58 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
- /**
4
- * Class that manages frontend notices for customers.
5
- *
6
- * @author PaymentPlugins
7
- * @package Stripe/Classes
8
- * @since 3.0.0
9
- *
10
- */
11
- class WC_Stripe_Frontend_Notices {
12
-
13
- public static function init() {
14
- add_action ( 'wp_enqueue_scripts', [
15
- __CLASS__, 'enqueue_scripts'
16
- ] );
17
- }
18
-
19
- public static function enqueue_scripts() {
20
- if (isset ( $wp->query_vars[ 'order-received' ] )) {
21
- $scripts = wc_stripe ()->scripts ();
22
- $order_id = absint ( $wp->query_vars[ 'order-received' ] );
23
- $order = wc_get_order ( $order_id );
24
- $notices = [];
25
- if (( $message = $order->get_meta ( '_wc_stripe_order_error', true ) )) {
26
- $notices[] = wc_get_template_html ( "notices/notice.php", [
27
- 'messages' => [ $message
28
- ]
29
- ] );
30
- }
31
- if ($order->has_status ( 'on-hold' )) {
32
- $payment_method = $order->get_payment_method ();
33
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $payment_method ];
34
- if ($gateway instanceof WC_Payment_Gateway_Stripe_Local_Payment) {
35
- $notices[] = wc_get_template_html ( "notices/notice.php", [
36
- 'messages' => [
37
- __ ( 'Your payment is being processed and your order status will be updated once the funds are received.', 'woo-stripe-payment' )
38
- ]
39
- ] );
40
- }
41
- if ($notices) {
42
- self::enqueue_notices ( $notices );
43
- }
44
- }
45
- }
46
- }
47
-
48
- public static function enqueue_notices($notices) {
49
- $scripts->enqueue_script ( 'notices', $scripts->assets_url ( 'js/frontend/notices.js' ), [
50
- 'jquery'
51
- ], wc_stripe ()->version (), true );
52
- $scripts->localize_script ( 'notices', [
53
- 'container' => '.woocommerce-order',
54
- 'notices' => $notices
55
- ] );
56
- }
57
- }
58
- WC_Stripe_Frontend_Notices::init ();
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * Class that manages frontend notices for customers.
6
+ *
7
+ * @author PaymentPlugins
8
+ * @package Stripe/Classes
9
+ * @since 3.0.0
10
+ *
11
+ */
12
+ class WC_Stripe_Frontend_Notices {
13
+
14
+ public static function init() {
15
+ add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
16
+ }
17
+
18
+ public static function enqueue_scripts() {
19
+ if ( isset( $wp->query_vars['order-received'] ) ) {
20
+ $scripts = wc_stripe()->scripts();
21
+ $order_id = absint( $wp->query_vars['order-received'] );
22
+ $order = wc_get_order( $order_id );
23
+ $notices = array();
24
+ if ( ( $message = $order->get_meta( '_wc_stripe_order_error', true ) ) ) {
25
+ $notices[] = wc_get_template_html( 'notices/notice.php', array( 'messages' => array( $message ) ) );
26
+ }
27
+ if ( $order->has_status( 'on-hold' ) ) {
28
+ $payment_method = $order->get_payment_method();
29
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
30
+ if ( $gateway instanceof WC_Payment_Gateway_Stripe_Local_Payment ) {
31
+ $notices[] = wc_get_template_html(
32
+ 'notices/notice.php',
33
+ array(
34
+ 'messages' => array(
35
+ __( 'Your payment is being processed and your order status will be updated once the funds are received.', 'woo-stripe-payment' ),
36
+ ),
37
+ )
38
+ );
39
+ }
40
+ if ( $notices ) {
41
+ self::enqueue_notices( $notices );
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ public static function enqueue_notices( $notices ) {
48
+ $scripts->enqueue_script( 'notices', $scripts->assets_url( 'js/frontend/notices.js' ), array( 'jquery' ), wc_stripe()->version(), true );
49
+ $scripts->localize_script(
50
+ 'notices',
51
+ array(
52
+ 'container' => '.woocommerce-order',
53
+ 'notices' => $notices,
54
+ )
55
+ );
56
+ }
57
+ }
58
+ WC_Stripe_Frontend_Notices::init();
includes/class-wc-stripe-frontend-scripts.php CHANGED
@@ -1,148 +1,162 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- * Handles scrip enqueuement and output of params needed by the plugin.
6
- *
7
- * @package Stripe/Classes
8
- * @author PaymentPlugins
9
- *
10
- */
11
- class WC_Stripe_Frontend_Scripts {
12
-
13
- public $prefix = 'wc-stripe-';
14
-
15
- public $registered_scripts = array();
16
-
17
- public $enqueued_scripts = array();
18
-
19
- public $localized_scripts = array();
20
-
21
- public $global_scripts = array(
22
- 'external' => 'https://js.stripe.com/v3/',
23
- 'gpay' => 'https://pay.google.com/gp/p/js/pay.js',
24
- 'plaid' => 'https://cdn.plaid.com/link/v2/stable/link-initialize.js'
25
- );
26
-
27
- public function __construct() {
28
- add_action ( 'wp_enqueue_scripts', array( $this,
29
- 'enqueue_scripts'
30
- ) );
31
- add_action ( 'woocommerce_review_order_before_payment', array(
32
- $this, 'enqueue_checkout_scripts'
33
- ) );
34
- add_action ( 'woocommerce_pay_order_after_submit', array(
35
- $this, 'enqueue_checkout_scripts'
36
- ) );
37
- }
38
-
39
- /**
40
- * Enqueue all frontend scripts needed by the plugin
41
- */
42
- public function enqueue_scripts() {
43
- // register global scripts
44
- foreach ( $this->global_scripts as $handle => $src ) {
45
- $this->register_script ( $handle, $src );
46
- }
47
-
48
- // register scripts that aren't part of gateways
49
- $this->register_script ( 'wc-stripe', $this->assets_url ( 'js/frontend/wc-stripe' . $this->get_min () . '.js' ), [
50
- 'jquery', $this->get_handle ( 'external' ),
51
- 'woocommerce'
52
- ] );
53
-
54
- $this->register_script ( 'form-handler', $this->assets_url ( 'js/frontend/form-handler.js' ), [
55
- 'selectWoo'
56
- ] );
57
-
58
- wp_localize_script ( $this->get_handle ( 'wc-stripe' ), 'wc_stripe_params_v3', [
59
- 'api_key' => wc_stripe_get_publishable_key (),
60
- 'account' => wc_stripe_get_account_id (),
61
- 'page' => $this->get_page_id ()
62
- ] );
63
-
64
- wp_localize_script ( $this->get_handle ( 'form-handler' ), 'wc_stripe_form_handler_params', [
65
- 'no_results' => __ ( 'No matches found', 'woo-stripe-payment' )
66
- ] );
67
-
68
- wp_localize_script ( $this->get_handle ( 'wc-stripe' ), 'wc_stripe_messages', wc_stripe_get_error_messages () );
69
- }
70
-
71
- public function enqueue_checkout_scripts() {
72
- $data = wc_stripe_get_local_payment_params ();
73
- // only enqueue local payment script if there are local payment gateways that have been enabled.
74
- if (! empty ( $data[ 'gateways' ] ) && ! in_array ( $this->get_handle ( 'local-payment' ), $this->enqueued_scripts )) {
75
- $this->enqueue_script ( 'local-payment', $this->assets_url ( 'js/frontend/local-payment.js' ), [
76
- $this->get_handle ( 'external' ),
77
- $this->get_handle ( 'wc-stripe' )
78
- ] );
79
- $this->localize_script ( 'local-payment', $data );
80
- }
81
- }
82
-
83
- public function register_script($handle, $src, $deps = [], $version = '', $footer = true) {
84
- $version = empty ( $version ) ? wc_stripe ()->version () : $version;
85
- $this->registered_scripts[] = $this->get_handle ( $handle );
86
- wp_register_script ( $this->get_handle ( $handle ), $src, $deps, $version, $footer );
87
- }
88
-
89
- public function enqueue_script($handle, $src = '', $deps = [], $version = '', $footer = true) {
90
- $handle = $this->get_handle ( $handle );
91
- $version = empty ( $version ) ? wc_stripe ()->version () : $version;
92
- if (! in_array ( $handle, $this->registered_scripts )) {
93
- $this->register_script ( $handle, $src, $deps, $version, $footer );
94
- }
95
- $this->enqueued_scripts[] = $handle;
96
- wp_enqueue_script ( $handle );
97
- }
98
-
99
- /**
100
- *
101
- * @param string $handle
102
- * @param array $data
103
- */
104
- public function localize_script($handle, $data) {
105
- $handle = $this->get_handle ( $handle );
106
- if (wp_script_is ( $handle ) && ! in_array ( $handle, $this->localized_scripts )) {
107
- $name = str_replace ( $this->prefix, '', $handle );
108
- $data = apply_filters ( 'wc_stripe_localize_script_' . $name, $data, $name );
109
- if ($data) {
110
- $this->localized_scripts[] = $handle;
111
- $object_name = str_replace ( '-', '_', $handle ) . '_params';
112
- wp_localize_script ( $handle, $object_name, $data );
113
- }
114
- }
115
- }
116
-
117
- public function get_handle($handle) {
118
- return strpos ( $handle, $this->prefix ) === false ? $this->prefix . $handle : $handle;
119
- }
120
-
121
- /**
122
- *
123
- * @param string $uri
124
- */
125
- public function assets_url($uri = '') {
126
- return untrailingslashit ( wc_stripe ()->assets_url ( $uri ) );
127
- }
128
-
129
- public function get_min() {
130
- return $suffix = SCRIPT_DEBUG ? '' : '.min';
131
- }
132
-
133
- private function get_page_id() {
134
- if (is_product ()) {
135
- return 'product';
136
- }
137
- if (is_cart ()) {
138
- return 'cart';
139
- }
140
- if (is_checkout ()) {
141
- return 'checkout';
142
- }
143
- if (is_add_payment_method_page ()) {
144
- return 'add_payment_method';
145
- }
146
- return '';
147
- }
148
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * Handles scrip enqueuement and output of params needed by the plugin.
6
+ *
7
+ * @package Stripe/Classes
8
+ * @author PaymentPlugins
9
+ */
10
+ class WC_Stripe_Frontend_Scripts {
11
+
12
+ public $prefix = 'wc-stripe-';
13
+
14
+ public $registered_scripts = array();
15
+
16
+ public $enqueued_scripts = array();
17
+
18
+ public $localized_scripts = array();
19
+
20
+ public $global_scripts = array(
21
+ 'external' => 'https://js.stripe.com/v3/',
22
+ 'gpay' => 'https://pay.google.com/gp/p/js/pay.js',
23
+ 'plaid' => 'https://cdn.plaid.com/link/v2/stable/link-initialize.js',
24
+ );
25
+
26
+ public function __construct() {
27
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
28
+ add_action( 'woocommerce_review_order_before_payment', array( $this, 'enqueue_checkout_scripts' ) );
29
+ add_action( 'woocommerce_pay_order_after_submit', array( $this, 'enqueue_checkout_scripts' ) );
30
+ }
31
+
32
+ /**
33
+ * Enqueue all frontend scripts needed by the plugin
34
+ */
35
+ public function enqueue_scripts() {
36
+ // register global scripts
37
+ foreach ( $this->global_scripts as $handle => $src ) {
38
+ $this->register_script( $handle, $src );
39
+ }
40
+
41
+ // register scripts that aren't part of gateways
42
+ $this->register_script(
43
+ 'wc-stripe',
44
+ $this->assets_url( 'js/frontend/wc-stripe' . $this->get_min() . '.js' ),
45
+ array(
46
+ 'jquery',
47
+ $this->get_handle( 'external' ),
48
+ 'woocommerce',
49
+ )
50
+ );
51
+
52
+ $this->register_script( 'form-handler', $this->assets_url( 'js/frontend/form-handler.js' ), array( 'selectWoo' ) );
53
+
54
+ $this->localize_script(
55
+ 'wc-stripe',
56
+ array(
57
+ 'api_key' => wc_stripe_get_publishable_key(),
58
+ 'account' => wc_stripe_get_account_id(),
59
+ 'page' => $this->get_page_id(),
60
+ ),
61
+ 'wc_stripe_params_v3'
62
+ );
63
+
64
+ $this->localize_script(
65
+ 'form-handler',
66
+ array(
67
+ 'no_results' => __(
68
+ 'No matches found',
69
+ 'woo-stripe-payment'
70
+ ),
71
+ )
72
+ );
73
+
74
+ $this->localize_script( 'wc-stripe', wc_stripe_get_error_messages(), 'wc_stripe_messages' );
75
+ }
76
+
77
+ public function enqueue_checkout_scripts() {
78
+ $data = wc_stripe_get_local_payment_params();
79
+ // only enqueue local payment script if there are local payment gateways that have been enabled.
80
+ if ( ! empty( $data['gateways'] ) && ! in_array( $this->get_handle( 'local-payment' ), $this->enqueued_scripts ) ) {
81
+ $this->enqueue_script(
82
+ 'local-payment',
83
+ $this->assets_url( 'js/frontend/local-payment.js' ),
84
+ array(
85
+ $this->get_handle( 'external' ),
86
+ $this->get_handle( 'wc-stripe' ),
87
+ )
88
+ );
89
+ $this->localize_script( 'local-payment', $data );
90
+ }
91
+ }
92
+
93
+ public function register_script( $handle, $src, $deps = array(), $version = '', $footer = true ) {
94
+ $version = empty( $version ) ? wc_stripe()->version() : $version;
95
+ $this->registered_scripts[] = $this->get_handle( $handle );
96
+ wp_register_script( $this->get_handle( $handle ), $src, $deps, $version, $footer );
97
+ }
98
+
99
+ public function enqueue_script( $handle, $src = '', $deps = array(), $version = '', $footer = true ) {
100
+ $handle = $this->get_handle( $handle );
101
+ $version = empty( $version ) ? wc_stripe()->version() : $version;
102
+ if ( ! in_array( $handle, $this->registered_scripts ) ) {
103
+ $this->register_script( $handle, $src, $deps, $version, $footer );
104
+ }
105
+ $this->enqueued_scripts[] = $handle;
106
+ wp_enqueue_script( $handle );
107
+ }
108
+
109
+ /**
110
+ *
111
+ * @param string $handle
112
+ * @param array $data
113
+ * @param string $object_name
114
+ */
115
+ public function localize_script( $handle, $data, $object_name = '' ) {
116
+ $handle = $this->get_handle( $handle );
117
+ if ( wp_script_is( $handle, 'registered' ) ) {
118
+ $name = str_replace( $this->prefix, '', $handle );
119
+ if ( ! $object_name ) {
120
+ $object_name = str_replace( '-', '_', $handle ) . '_params';
121
+ }
122
+ $data = apply_filters( 'wc_stripe_localize_script_' . $name, $data, $object_name );
123
+ if ( $data ) {
124
+ $this->localized_scripts[] = $handle;
125
+ wp_localize_script( $handle, $object_name, $data );
126
+ }
127
+ }
128
+ }
129
+
130
+ public function get_handle( $handle ) {
131
+ return strpos( $handle, $this->prefix ) === false ? $this->prefix . $handle : $handle;
132
+ }
133
+
134
+ /**
135
+ *
136
+ * @param string $uri
137
+ */
138
+ public function assets_url( $uri = '' ) {
139
+ return untrailingslashit( wc_stripe()->assets_url( $uri ) );
140
+ }
141
+
142
+ public function get_min() {
143
+ return $suffix = SCRIPT_DEBUG ? '' : '.min';
144
+ }
145
+
146
+ private function get_page_id() {
147
+ if ( is_product() ) {
148
+ return 'product';
149
+ }
150
+ if ( is_cart() ) {
151
+ return 'cart';
152
+ }
153
+ if ( is_checkout() ) {
154
+ return 'checkout';
155
+ }
156
+ if ( is_add_payment_method_page() ) {
157
+ return 'add_payment_method';
158
+ }
159
+
160
+ return '';
161
+ }
162
+ }
includes/class-wc-stripe-gateway-ach.php DELETED
@@ -1,99 +0,0 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.1.0
7
- * @author Payment Plugins
8
- *
9
- */
10
- class WC_Stripe_Gateway_ACH extends WC_Stripe_Gateway {
11
-
12
- private $public_token = '';
13
-
14
- private $account_id = '';
15
-
16
- private $environment = '';
17
-
18
- public function set_public_token($public_token) {
19
- $this->public_token = $public_token;
20
- }
21
-
22
- public function set_account_id($account_id) {
23
- $this->account_id = $account_id;
24
- }
25
-
26
- public function set_plaid_environment($environment) {
27
- $this->environment = $environment;
28
- }
29
-
30
- /**
31
- *
32
- * {@inheritDoc}
33
- *
34
- * @see WC_Stripe_Gateway::charge()
35
- */
36
- public function charge($args, $mode = '') {
37
- $mode = empty ( $mode ) ? wc_stripe_mode () : $mode;
38
- $args = [ 'charge' => $args, 'mode' => $mode,
39
- 'account_id' => wc_stripe ()->api_settings->get_option ( 'account_id' ),
40
- 'plaid' => [
41
- 'public_token' => $this->public_token,
42
- 'account_id' => $this->account_id,
43
- 'environment' => $this->environment
44
- ]
45
- ];
46
- try {
47
- // validate env and mode to prevent conflicts
48
- if ($mode == 'live' && in_array ( $this->environment, [
49
- 'sandbox', 'development'
50
- ] )) {
51
- throw new Exception ( __ ( 'Please update your ACH environment to Production to match your Stripe API Mode.', 'woo-stripe-payment' ) );
52
- }
53
- $response = $this->do_request ( 'POST', '', $args, $mode );
54
- return $response;
55
- } catch ( Exception $e ) {
56
- return new WP_Error ( 'charge-error', $e->getMessage () );
57
- }
58
- }
59
-
60
- private function do_request($method, $uri, $args, $mode) {
61
- $response = wp_safe_remote_post ( $this->base_url ( $uri, $mode ), [
62
- 'headers' => [
63
- 'Content-Type' => 'application/json'
64
- ], /**
65
- * 20 second timeout
66
- */
67
- 'timeout' => 20,
68
- 'body' => wp_json_encode ( $args )
69
- ] );
70
- if (is_wp_error ( $response )) {
71
- throw new Exception ( $response->get_error_message () );
72
- } else {
73
- $body = json_decode ( $response[ 'body' ], true );
74
- if ($response[ 'response' ][ 'code' ] > 299) {
75
- throw new Exception ( $body[ 'message' ] );
76
- } else {
77
- $obj = \Stripe\Util\Util::convertToStripeObject ( $body, null );
78
- $obj->setLastResponse ( $response );
79
- return $obj;
80
- }
81
- }
82
- }
83
-
84
- /**
85
- *
86
- * @param string $uri
87
- */
88
- private function base_url($uri, $mode) {
89
- $url = '';
90
- switch ($mode) {
91
- case 'live' :
92
- case 'test' :
93
- $url = 'https://api.plaid.paymentplugins.com/v1/stripe/';
94
- // $url = 'http://localhost:8080/v1/stripe/';
95
- break;
96
- }
97
- return $url . $uri;
98
- }
99
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-wc-stripe-gateway-conversions.php CHANGED
@@ -1,40 +1,36 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.1.0
7
- * @author Payment Plugins
8
- *
9
- */
10
- class WC_Stripe_Gateway_Conversion {
11
-
12
- public static function init() {
13
- add_filter ( 'woocommerce_order_get_payment_method', array(
14
- __CLASS__, 'convert_payment_method'
15
- ), 10, 2 );
16
- add_filter ( 'woocommerce_subscription_get_payment_method', array(
17
- __CLASS__, 'convert_payment_method'
18
- ), 10, 2 );
19
- }
20
-
21
- /**
22
- *
23
- * @param string $payment_method
24
- * @param WC_Order $order
25
- */
26
- public static function convert_payment_method($payment_method, $order) {
27
- $old_payment_method = $payment_method;
28
-
29
- switch ($payment_method) {
30
- case 'stripe' :
31
- $payment_method = 'stripe_cc';
32
- break;
33
- }
34
- if ($payment_method != $old_payment_method && ! empty ( $payment_method )) {
35
- update_post_meta ( $order->get_id (), '_payment_method', $payment_method );
36
- }
37
- return $payment_method;
38
- }
39
- }
40
- WC_Stripe_Gateway_Conversion::init ();
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @since 3.1.0
7
+ * @author Payment Plugins
8
+ *
9
+ */
10
+ class WC_Stripe_Gateway_Conversion {
11
+
12
+ public static function init() {
13
+ add_filter( 'woocommerce_order_get_payment_method', array( __CLASS__, 'convert_payment_method' ), 10, 2 );
14
+ add_filter( 'woocommerce_subscription_get_payment_method', array( __CLASS__, 'convert_payment_method' ), 10, 2 );
15
+ }
16
+
17
+ /**
18
+ *
19
+ * @param string $payment_method
20
+ * @param WC_Order $order
21
+ */
22
+ public static function convert_payment_method( $payment_method, $order ) {
23
+ $old_payment_method = $payment_method;
24
+
25
+ switch ( $payment_method ) {
26
+ case 'stripe':
27
+ $payment_method = 'stripe_cc';
28
+ break;
29
+ }
30
+ if ( $payment_method != $old_payment_method && ! empty( $payment_method ) ) {
31
+ update_post_meta( $order->get_id(), '_payment_method', $payment_method );
32
+ }
33
+ return $payment_method;
34
+ }
35
+ }
36
+ WC_Stripe_Gateway_Conversion::init();
 
 
 
 
includes/class-wc-stripe-gateway.php CHANGED
@@ -1,495 +1,444 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- use Stripe\ApiOperations\Create;
5
- use Stripe\ApiOperations\Retrieve;
6
- use Stripe\ApiOperations\Update;
7
- use Stripe\ApiOperations\All;
8
-
9
- /**
10
- * Gateway class that abstracts all API calls to Stripe.
11
- *
12
- * @author Payment Plugins
13
- * @package Stripe/Classes
14
- *
15
- */
16
- class WC_Stripe_Gateway {
17
-
18
- /**
19
- *
20
- * @since 3.0.5
21
- * @var Stripe mode (test, live)
22
- */
23
- private $mode = null;
24
-
25
- private $messages = [];
26
-
27
- /**
28
- *
29
- * @since 3.0.8
30
- * @var unknown
31
- */
32
- private $secret_key = null;
33
-
34
- public function __construct($mode = null, $secret_key = null) {
35
- if (null != $mode) {
36
- $this->mode = $mode;
37
- }
38
- if (null != $secret_key) {
39
- $this->secret_key = $secret_key;
40
- }
41
-
42
- $this->messages = wc_stripe_get_error_messages ();
43
- }
44
-
45
- public static function init() {
46
- \Stripe\Stripe::setAppInfo ( 'Wordpress woo-stripe-payment', wc_stripe ()->version (), 'https://wordpress.org/plugins/woo-stripe-payment/', 'pp_partner_FdPtriN2Q7JLOe' );
47
- \Stripe\Stripe::setApiVersion ( '2020-03-02' );
48
- }
49
-
50
- /**
51
- *
52
- * @since 3.1.0
53
- * @param string $mode
54
- * @param string $secret_key
55
- * @return WC_Stripe_Gateway
56
- */
57
- public static function load($mode = null, $secret_key = null) {
58
- $class = apply_filters ( 'wc_stripe_gateway_class', 'WC_Stripe_Gateway' );
59
- return new $class ( $mode, $secret_key );
60
- }
61
-
62
- /**
63
- *
64
- * @since 3.1.0
65
- * @param unknown $mode
66
- */
67
- public function set_mode($mode) {
68
- $this->mode = $mode;
69
- }
70
-
71
- /**
72
- * Create a customer within Stripe.
73
- *
74
- * @param array $args
75
- * @return WP_Error|string
76
- */
77
- public function create_customer($args, $mode = '') {
78
- try {
79
- $customer = \Stripe\Customer::create ( apply_filters ( 'wc_stripe_create_customer_args', $args ), $this->get_api_options () );
80
- return $customer->id;
81
- } catch ( \Stripe\Error\Base $e ) {
82
- return $this->get_wp_error ( $e, 'customer-error' );
83
- }
84
- }
85
-
86
- public function update_customer($id, $args, $mode = '') {
87
- try {
88
- return \Stripe\Customer::update ( $id, $args, $this->get_api_options ( $mode ) );
89
- } catch ( \Stripe\Error\Base $e ) {
90
- return $this->get_wp_error ( $e, 'customer-error' );
91
- }
92
- }
93
-
94
- public function charge($args, $mode = '') {
95
- try {
96
- return \Stripe\Charge::create ( $args, $this->get_api_options ( $mode ) );
97
- } catch ( \Stripe\Error\Base $e ) {
98
- return $this->get_wp_error ( $e, 'charge-error' );
99
- }
100
- }
101
-
102
- /**
103
- *
104
- * @param array $args
105
- * @param string $mode
106
- * @return WP_Error|\Stripe\PaymentIntent
107
- */
108
- public function create_payment_intent($args, $mode = '') {
109
- try {
110
- return \Stripe\PaymentIntent::create ( $args, $this->get_api_options ( $mode ) );
111
- } catch ( \Stripe\Error\Base $e ) {
112
- return $this->get_wp_error ( $e, 'payment-intent-error' );
113
- }
114
- }
115
-
116
- public function create_setup_intent($args, $mode = '') {
117
- try {
118
- return \Stripe\SetupIntent::create ( $args, $this->get_api_options ( $mode ) );
119
- } catch ( \Stripe\Error\Base $e ) {
120
- return $this->get_wp_error ( $e, 'setup-intent-error' );
121
- }
122
- }
123
-
124
- /**
125
- *
126
- * @param \Stripe\PaymentIntent $intent
127
- * @param array $args
128
- * @param string $mode
129
- */
130
- public function update_payment_intent($id, $args, $mode = '') {
131
- try {
132
- return \Stripe\PaymentIntent::update ( $id, $args, $this->get_api_options ( $mode ) );
133
- } catch ( \Stripe\Error\Base $e ) {
134
- return $this->get_wp_error ( $e, 'payment-intent-error' );
135
- }
136
- }
137
-
138
- /**
139
- *
140
- * @param \Stripe\PaymentIntent $intent
141
- * @param array $args
142
- * @param string $mode
143
- */
144
- public function confirm_payment_intent($intent, $args = [], $mode = '') {
145
- try {
146
- return $intent->confirm ( $args, $this->get_api_options ( $mode ) );
147
- } catch ( \Stripe\Error\Base $e ) {
148
- return $this->get_wp_error ( $e, 'payment-intent-error' );
149
- }
150
- }
151
-
152
- /**
153
- *
154
- * @param string $id
155
- * @param string $mode
156
- * @return WP_Error|\Stripe\PaymentIntent
157
- */
158
- public function fetch_payment_intent($id, $mode = '') {
159
- try {
160
- return \Stripe\PaymentIntent::retrieve ( $id, $this->get_api_options ( $mode ) );
161
- } catch ( \Stripe\Error\Base $e ) {
162
- return $this->get_wp_error ( $e, 'payment-intent-error' );
163
- }
164
- }
165
-
166
- public function capture_payment_intent($id, $args = [], $mode = '') {
167
- try {
168
- $payment_intent = $this->fetch_payment_intent ( $id, $mode );
169
- return $payment_intent->capture ( $args, $this->get_api_options ( $mode ) );
170
- } catch ( \Stripe\Error\Base $e ) {
171
- return $this->get_wp_error ( $e, 'payment-intent-error' );
172
- }
173
- }
174
-
175
- /**
176
- *
177
- * @param \Stripe\PaymentIntent|string $id
178
- * @param string $mode
179
- */
180
- public function cancel_payment_intent($id, $mode = '') {
181
- try {
182
- if (! is_object ( $id )) {
183
- $payment_intent = $this->fetch_payment_intent ( $id, $mode );
184
- } else {
185
- $payment_intent = $id;
186
- }
187
- return $payment_intent->cancel ( [], $this->get_api_options ( $mode ) );
188
- } catch ( \Stripe\Error\Base $e ) {
189
- return $this->get_wp_error ( $e, 'payment-intent-error' );
190
- }
191
- }
192
-
193
- /**
194
- *
195
- * @param string $id
196
- * @param string $mode
197
- * @return WP_Error|\Stripe\SetupIntent
198
- */
199
- public function fetch_setup_intent($id, $mode = '') {
200
- try {
201
- return \Stripe\SetupIntent::retrieve ( $id, $this->get_api_options ( $mode ) );
202
- } catch ( \Stripe\Error\Base $e ) {
203
- return $this->get_wp_error ( $e, 'setup-intent-error' );
204
- }
205
- }
206
-
207
- public function capture($id, $args, $mode = '') {
208
- $charge = $this->get_charge ( $id, $mode );
209
- if (! is_wp_error ( $charge )) {
210
- try {
211
- return $charge->capture ( $args, $this->get_api_options ( $mode ) );
212
- } catch ( \Stripe\Error\Base $e ) {
213
- return $this->get_wp_error ( $e, 'catpure-error' );
214
- }
215
- } else {
216
- return $charge;
217
- }
218
- }
219
-
220
- /**
221
- *
222
- * @param string $charge_id
223
- * @param string $mode
224
- * @return \Stripe\Charge|WP_Error
225
- */
226
- public function get_charge($charge_id, $mode = '') {
227
- try {
228
- return \Stripe\Charge::retrieve ( $charge_id, $this->get_api_options ( $mode ) );
229
- } catch ( \Stripe\Error\Base $e ) {
230
- return $this->get_wp_error ( $e, 'charge-error' );
231
- }
232
- }
233
-
234
- public function refund($args, $mode = '') {
235
- try {
236
- return \Stripe\Refund::create ( $args, $this->get_api_options ( $mode ) );
237
- } catch ( \Stripe\Error\Base $e ) {
238
- return $this->get_wp_error ( $e, 'refund-error' );
239
- }
240
- }
241
-
242
- public function get_payment_method($id, $mode = '') {
243
- try {
244
- return \Stripe\PaymentMethod::retrieve ( $id, $this->get_api_options ( $mode ) );
245
- } catch ( \Stripe\Error\Base $e ) {
246
- return $this->get_wp_error ( $e, 'payment-method' );
247
- }
248
- }
249
-
250
- /**
251
- *
252
- * @param \Stripe\PaymentMethod $payment_method
253
- * @param array $args
254
- * @param string $mode
255
- */
256
- public function attach_payment_method($payment_method, $args = [], $mode = '') {
257
- try {
258
- return $payment_method->attach ( $args, $this->get_api_options ( $mode ) );
259
- } catch ( \Stripe\Error\Base $e ) {
260
- return $this->get_wp_error ( $e, 'attach-payment-error' );
261
- }
262
- }
263
-
264
- public function fetch_payment_method($id, $mode = '') {
265
- try {
266
- return \Stripe\PaymentMethod::retrieve ( $id, $this->get_api_options ( $mode ) );
267
- } catch ( \Stripe\Error\Base $e ) {
268
- return $this->get_wp_error ( $e, 'fetch-payment-error' );
269
- }
270
- }
271
-
272
- /**
273
- *
274
- * @param \Stripe\PaymentMethod $payment_method
275
- * @param string $mode
276
- */
277
- public function delete_payment_method($payment_method, $mode = '') {
278
- try {
279
- return $payment_method->detach ( [], $this->get_api_options ( $mode ) );
280
- } catch ( \Stripe\Error\Base $e ) {
281
- return $this->get_wp_error ( $e, 'delete-source-error' );
282
- }
283
- }
284
-
285
- /**
286
- *
287
- * @param string $id
288
- * @param string $customer
289
- * @param string $mode
290
- */
291
- public function delete_card($id, $customer, $mode = '') {
292
- try {
293
- \Stripe\Customer::deleteSource ( $customer, $id, null, $this->get_api_options ( $mode ) );
294
- } catch ( \Stripe\Error\Base $e ) {
295
- return $this->get_wp_error ( $e, 'delete-source-error' );
296
- }
297
- }
298
-
299
- /**
300
- *
301
- * @param array $args
302
- * @param string $mode
303
- * @return WP_Error|\Stripe\PaymentMethod
304
- */
305
- public function create_payment_method($args, $mode = '') {
306
- try {
307
- return \Stripe\PaymentMethod::create ( $args, $this->get_api_options ( $mode ) );
308
- } catch ( \Stripe\Error\Base $e ) {
309
- return $this->get_wp_error ( $e, 'payment-method-error' );
310
- }
311
- }
312
-
313
- /**
314
- *
315
- * @param string $id
316
- * @param string $mode
317
- * @return WP_Error|\Stripe\Source
318
- *
319
- */
320
- public function fetch_payment_source($id, $mode = '') {
321
- try {
322
- return \Stripe\Source::retrieve ( $id, $this->get_api_options ( $mode ) );
323
- } catch ( \Stripe\Error\Base $e ) {
324
- return $this->get_wp_error ( $e, 'source-error' );
325
- }
326
- }
327
-
328
- /**
329
- *
330
- * @param string $customer_id
331
- * @param string $id
332
- * @param string $mode
333
- * @return WP_Error|\Stripe\Source
334
- */
335
- public function create_customer_source($customer_id, $id, $mode = '') {
336
- try {
337
- return \Stripe\Customer::createSource ( $customer_id, [
338
- 'source' => $id
339
- ], $this->get_api_options ( $mode ) );
340
- } catch ( \Stripe\Error\Base $e ) {
341
- return $this->get_wp_error ( $e, 'source-error' );
342
- }
343
- }
344
-
345
- /**
346
- *
347
- * @param array $args
348
- * @param string $mode
349
- * @return WP_Error|\Stripe\Source
350
- */
351
- public function create_source($args, $mode = '') {
352
- try {
353
- return \Stripe\Source::create ( $args, $this->get_api_options ( $mode ) );
354
- } catch ( \Stripe\Error\Base $e ) {
355
- return $this->get_wp_error ( $e, 'source-error' );
356
- }
357
- }
358
-
359
- /**
360
- *
361
- * @since 3.0.2
362
- * @param string $source_id
363
- * @param array $args
364
- * @param string $mode
365
- */
366
- public function update_source($source_id, $args, $mode = '') {
367
- try {
368
- return \Stripe\Source::update ( $source_id, $args, $this->get_api_options ( $mode ) );
369
- } catch ( \Stripe\Error\Base $e ) {
370
- return $this->get_wp_error ( $e, 'source-error' );
371
- }
372
- }
373
-
374
- public function fetch_customer($customer_id, $mode = '') {
375
- try {
376
- return \Stripe\Customer::retrieve ( $customer_id, $this->get_api_options ( $mode ) );
377
- } catch ( \Stripe\Error\Base $e ) {
378
- return $this->get_wp_error ( $e, 'customer-error' );
379
- }
380
- }
381
-
382
- public function fetch_customers($mode = '') {
383
- try {
384
- return \Stripe\Customer::all ( [
385
- 'limit' => 1
386
- ], $this->get_api_options ( $mode ) );
387
- } catch ( \Stripe\Error\Base $e ) {
388
- return $this->get_wp_error ( $e, 'customer-error' );
389
- }
390
- }
391
-
392
- public function fetch_payment_methods($customer_id, $mode = '', $type = 'card') {
393
- try {
394
- return \Stripe\PaymentMethod::all ( [
395
- 'customer' => $customer_id,
396
- 'type' => $type
397
- ], $this->get_api_options ( $mode ) );
398
- } catch ( \Stripe\Error\Base $e ) {
399
- return $this->get_wp_error ( $e, 'source-error' );
400
- }
401
- }
402
-
403
- public function register_domain($domain, $mode = '') {
404
- try {
405
- \Stripe\ApplePayDomain::create ( [
406
- 'domain_name' => $domain
407
- ], $this->get_api_options ( $mode ) );
408
- } catch ( \Stripe\Error\Base $e ) {
409
- return $this->get_wp_error ( $e, 'domain-error' );
410
- }
411
- }
412
-
413
- public function webhooks($mode = '') {
414
- try {
415
- return \Stripe\WebhookEndpoint::all ( [
416
- 'limit' => 100
417
- ], $this->get_api_options ( $mode ) );
418
- } catch ( \Stripe\Error\Base $e ) {
419
- return $this->get_wp_error ( $e, 'webhook-error' );
420
- }
421
- }
422
-
423
- public function create_webhook($url, $events, $mode = '') {
424
- try {
425
- return \Stripe\WebhookEndpoint::create ( [
426
- 'url' => $url,
427
- 'enabled_events' => $events
428
- ], $this->get_api_options ( $mode ) );
429
- } catch ( \Stripe\Error\Base $e ) {
430
- return $this->get_wp_error ( $e, 'webhook-error' );
431
- }
432
- }
433
-
434
- public function update_webhook($id, $params, $mode = '') {
435
- try {
436
- return \Stripe\WebhookEndpoint::update ( $id, $params, $this->get_api_options ( $mode ) );
437
- } catch ( \Stripe\Error\Base $e ) {
438
- return $this->get_wp_error ( $e, 'webhook-error' );
439
- }
440
- }
441
-
442
- public function fetch_webhook($id, $mode = '') {
443
- try {
444
- return \Stripe\WebhookEndpoint::retrieve ( $id, $this->get_api_options ( $mode ) );
445
- } catch ( \Stripe\Error\Base $e ) {
446
- return $this->get_wp_error ( $e, 'webhook-error' );
447
- }
448
- }
449
-
450
- private function get_api_options($mode = '') {
451
- if (empty ( $mode ) && $this->mode != null) {
452
- $mode = $this->mode;
453
- }
454
- $args = [
455
- 'api_key' => $this->secret_key ? $this->secret_key : wc_stripe_get_secret_key ( $mode )
456
- ];
457
- return apply_filters ( 'wc_stripe_api_options', $args );
458
- }
459
-
460
- /**
461
- *
462
- * @param mixed $err
463
- */
464
- private function get_error_message($err) {
465
- if (is_a ( $err, '\Stripe\Error\Base' )) {
466
- $err = $err->getJsonBody ()[ 'error' ];
467
- }
468
- if (is_array ( $err )) {
469
- if (isset ( $err[ 'decline_code' ] ) && isset ( $this->messages[ $err[ 'decline_code' ] ] )) {
470
- return $this->messages[ $err[ 'decline_code' ] ];
471
- }
472
- if (isset ( $err[ 'code' ] ) && isset ( $this->messages[ $err[ 'code' ] ] )) {
473
- return $this->messages[ $err[ 'code' ] ];
474
- }
475
- if (isset ( $err[ 'message' ] )) {
476
- return $err[ 'message' ];
477
- }
478
- }
479
- if (is_string ( $err )) {
480
- return $err;
481
- }
482
- }
483
-
484
- /**
485
- *
486
- * @todo use in future version to replace manual returns of WP_Error in each method
487
- * @since 3.1.1
488
- * @param \Stripe\Error\Base $e
489
- */
490
- private function get_wp_error($e, $code = 'stripe-error') {
491
- $err = $e->getJsonBody ()[ 'error' ];
492
- return new WP_Error ( $code, $this->get_error_message ( $err ), $err );
493
- }
494
- }
495
- WC_Stripe_Gateway::init ();
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ require_once( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-wc-stripe-api-operation.php' );
5
+
6
+ /**
7
+ * Gateway class that abstracts all API calls to Stripe.
8
+ *
9
+ * @author Payment Plugins
10
+ * @package Stripe/Classes
11
+ *
12
+ * @property \Stripe\Service\AccountLinkService $accountLinks
13
+ * @property \Stripe\Service\AccountService $accounts
14
+ * @property \Stripe\Service\ApplePayDomainService $applePayDomains
15
+ * @property \Stripe\Service\ApplicationFeeService $applicationFees
16
+ * @property \Stripe\Service\BalanceService $balance
17
+ * @property \Stripe\Service\BalanceTransactionService $balanceTransactions
18
+ * @property \Stripe\Service\BillingPortal\BillingPortalServiceFactory $billingPortal
19
+ * @property \Stripe\Service\ChargeService $charges
20
+ * @property \Stripe\Service\Checkout\CheckoutServiceFactory $checkout
21
+ * @property \Stripe\Service\CountrySpecService $countrySpecs
22
+ * @property \Stripe\Service\CouponService $coupons
23
+ * @property \Stripe\Service\CreditNoteService $creditNotes
24
+ * @property \Stripe\Service\CustomerService $customers
25
+ * @property \Stripe\Service\DisputeService $disputes
26
+ * @property \Stripe\Service\EphemeralKeyService $ephemeralKeys
27
+ * @property \Stripe\Service\EventService $events
28
+ * @property \Stripe\Service\ExchangeRateService $exchangeRates
29
+ * @property \Stripe\Service\FileLinkService $fileLinks
30
+ * @property \Stripe\Service\FileService $files
31
+ * @property \Stripe\Service\InvoiceItemService $invoiceItems
32
+ * @property \Stripe\Service\InvoiceService $invoices
33
+ * @property \Stripe\Service\Issuing\IssuingServiceFactory $issuing
34
+ * @property \Stripe\Service\MandateService $mandates
35
+ * @property \Stripe\Service\OrderReturnService $orderReturns
36
+ * @property \Stripe\Service\OrderService $orders
37
+ * @property \Stripe\Service\PaymentIntentService $paymentIntents
38
+ * @property \Stripe\Service\PaymentMethodService $paymentMethods
39
+ * @property \Stripe\Service\PayoutService $payouts
40
+ * @property \Stripe\Service\PlanService $plans
41
+ * @property \Stripe\Service\PriceService $prices
42
+ * @property \Stripe\Service\ProductService $products
43
+ * @property \Stripe\Service\Radar\RadarServiceFactory $radar
44
+ * @property \Stripe\Service\RefundService $refunds
45
+ * @property \Stripe\Service\Reporting\ReportingServiceFactory $reporting
46
+ * @property \Stripe\Service\ReviewService $reviews
47
+ * @property \Stripe\Service\SetupIntentService $setupIntents
48
+ * @property \Stripe\Service\Sigma\SigmaServiceFactory $sigma
49
+ * @property \Stripe\Service\SkuService $skus
50
+ * @property \Stripe\Service\SourceService $sources
51
+ * @property \Stripe\Service\SubscriptionItemService $subscriptionItems
52
+ * @property \Stripe\Service\SubscriptionScheduleService $subscriptionSchedules
53
+ * @property \Stripe\Service\SubscriptionService $subscriptions
54
+ * @property \Stripe\Service\TaxRateService $taxRates
55
+ * @property \Stripe\Service\Terminal\TerminalServiceFactory $terminal
56
+ * @property \Stripe\Service\TokenService $tokens
57
+ * @property \Stripe\Service\TopupService $topups
58
+ * @property \Stripe\Service\TransferService $transfers
59
+ * @property \Stripe\Service\WebhookEndpointService $webhookEndpoints
60
+ */
61
+ class WC_Stripe_Gateway {
62
+
63
+ /**
64
+ *
65
+ * @since 3.0.5
66
+ * @var Stripe mode (test, live)
67
+ */
68
+ private $mode = null;
69
+
70
+ private $messages = array();
71
+
72
+ /**
73
+ *
74
+ * @since 3.0.8
75
+ * @var string
76
+ */
77
+ private $secret_key = null;
78
+
79
+ /**
80
+ *
81
+ * @var \Stripe\StripeClient
82
+ */
83
+ private $client = null;
84
+
85
+ public function __construct( $mode = null, $secret_key = null ) {
86
+ if ( null != $mode ) {
87
+ $this->mode = $mode;
88
+ }
89
+ if ( null != $secret_key ) {
90
+ $this->secret_key = $secret_key;
91
+ }
92
+ $this->client = new \Stripe\StripeClient( array( 'stripe_version' => '2020-03-02' ) );
93
+ }
94
+
95
+ public static function init() {
96
+ \Stripe\Stripe::setAppInfo( 'WordPress woo-stripe-payment', wc_stripe()->version(), 'https://wordpress.org/plugins/woo-stripe-payment/', 'pp_partner_FdPtriN2Q7JLOe' );
97
+ }
98
+
99
+ public function __get( $key ) {
100
+ return new WC_Stripe_API_Operation( $this, $this->client, $key );
101
+ }
102
+
103
+ /**
104
+ *
105
+ * @param string $mode
106
+ * @param string $secret_key
107
+ *
108
+ * @return WC_Stripe_Gateway
109
+ * @since 3.1.0
110
+ */
111
+ public static function load( $mode = null, $secret_key = null ) {
112
+ $class = apply_filters( 'wc_stripe_gateway_class', 'WC_Stripe_Gateway' );
113
+
114
+ return new $class( $mode, $secret_key );
115
+ }
116
+
117
+ /**
118
+ *
119
+ * @param string $mode
120
+ *
121
+ * @since 3.1.0
122
+ */
123
+ public function set_mode( $mode ) {
124
+ $this->mode = $mode;
125
+ }
126
+
127
+ /**
128
+ * Create a customer within Stripe.
129
+ *
130
+ * @param array $args
131
+ *
132
+ * @return WP_Error|string
133
+ */
134
+ public function create_customer( $args, $mode = '' ) {
135
+ return $this->customers->create( apply_filters( 'wc_stripe_create_customer_args', $args ), $this->get_api_options( $mode ) );
136
+
137
+ }
138
+
139
+ public function update_customer( $id, $args, $mode = '' ) {
140
+ return $this->customers->update( $id, $args, $this->get_api_options( $mode ) );
141
+ }
142
+
143
+ public function charge( $args, $mode = '' ) {
144
+ return $this->charges->create( $args, $this->get_api_options( $mode ) );
145
+ }
146
+
147
+ /**
148
+ *
149
+ * @param array $args
150
+ * @param string $mode
151
+ *
152
+ * @return WP_Error|\Stripe\PaymentIntent
153
+ */
154
+ public function create_payment_intent( $args, $mode = '' ) {
155
+ return $this->paymentIntents->create( $args, $this->get_api_options( $mode ) );
156
+ }
157
+
158
+ public function create_setup_intent( $args, $mode = '' ) {
159
+ return $this->setupIntents->create( $args, $this->get_api_options( $mode ) );
160
+ }
161
+
162
+ /**
163
+ *
164
+ * @param \Stripe\PaymentIntent $intent
165
+ * @param array $args
166
+ * @param string $mode
167
+ */
168
+ public function update_payment_intent( $id, $args, $mode = '' ) {
169
+ return $this->paymentIntents->update( $id, $args, $this->get_api_options( $mode ) );
170
+ }
171
+
172
+ /**
173
+ *
174
+ * @param \Stripe\PaymentIntent $intent
175
+ * @param array $args
176
+ * @param string $mode
177
+ */
178
+ public function confirm_payment_intent( $id, $args = array(), $mode = '' ) {
179
+ return $this->paymentIntents->confirm( $id, $args, $this->get_api_options( $mode ) );
180
+ }
181
+
182
+ /**
183
+ *
184
+ * @param string $id
185
+ * @param string $mode
186
+ *
187
+ * @return WP_Error|\Stripe\PaymentIntent
188
+ */
189
+ public function fetch_payment_intent( $id, $mode = '' ) {
190
+ return $this->paymentIntents->retrieve( $id, array(), $this->get_api_options( $mode ) );
191
+ }
192
+
193
+ public function capture_payment_intent( $id, $args = array(), $mode = '' ) {
194
+ return $this->paymentIntents->capture( $id, $args, $this->get_api_options( $mode ) );
195
+ }
196
+
197
+ /**
198
+ *
199
+ * @param \Stripe\PaymentIntent|string $id
200
+ * @param string $mode
201
+ */
202
+ public function cancel_payment_intent( $id, $mode = '' ) {
203
+ return $this->paymentIntents->cancel( $id, array(), $this->get_api_options( $mode ) );
204
+ }
205
+
206
+ /**
207
+ *
208
+ * @param string $id
209
+ * @param string $mode
210
+ *
211
+ * @return WP_Error|\Stripe\SetupIntent
212
+ */
213
+ public function fetch_setup_intent( $id, $mode = '' ) {
214
+ return $this->setupIntents->retrieve( $id, array(), $this->get_api_options( $mode ) );
215
+ }
216
+
217
+ public function capture( $id, $args, $mode = '' ) {
218
+ return $this->charges->capture( $id, $args, $this->get_api_options( $mode ) );
219
+ }
220
+
221
+ /**
222
+ *
223
+ * @param string $charge_id
224
+ * @param string $mode
225
+ *
226
+ * @return \Stripe\Charge|WP_Error
227
+ */
228
+ public function get_charge( $charge_id, $mode = '' ) {
229
+ return $this->charges->retrieve( $charge_id, array(), $this->get_api_options( $mode ) );
230
+ }
231
+
232
+ public function refund( $args, $mode = '' ) {
233
+ return $this->refunds->create( $args, $this->get_api_options( $mode ) );
234
+ }
235
+
236
+ public function get_payment_method( $id, $mode = '' ) {
237
+ return \Stripe\PaymentMethod::retrieve( $id, $this->get_api_options( $mode ) );
238
+ }
239
+
240
+ /**
241
+ *
242
+ * @param \Stripe\PaymentMethod $payment_method
243
+ * @param array $args
244
+ * @param string $mode
245
+ */
246
+ public function attach_payment_method( $id, $args = array(), $mode = '' ) {
247
+ return $this->paymentMethods->attach( $id, $args, $this->get_api_options( $mode ) );
248
+ }
249
+
250
+ public function fetch_payment_method( $id, $mode = '' ) {
251
+ return $this->paymentMethods->retrieve( $id, null, $this->get_api_options( $mode ) );
252
+ }
253
+
254
+ /**
255
+ *
256
+ * @param \Stripe\PaymentMethod $payment_method
257
+ * @param string $mode
258
+ */
259
+ public function delete_payment_method( $id, $mode = '' ) {
260
+ return $this->paymentMethods->detach( $id, array(), $this->get_api_options( $mode ) );
261
+ }
262
+
263
+ /**
264
+ *
265
+ * @param string $id
266
+ * @param string $customer
267
+ * @param string $mode
268
+ */
269
+ public function delete_card( $id, $customer, $mode = '' ) {
270
+ return $this->sources->detach( $customer, $id, null, $this->get_api_options( $mode ) );
271
+ }
272
+
273
+ /**
274
+ *
275
+ * @param array $args
276
+ * @param string $mode
277
+ *
278
+ * @return WP_Error|\Stripe\PaymentMethod
279
+ */
280
+ public function create_payment_method( $args, $mode = '' ) {
281
+ return $this->paymentMethods->create( $args, $this->get_api_options( $mode ) );
282
+ }
283
+
284
+ /**
285
+ *
286
+ * @param string $id
287
+ * @param string $mode
288
+ *
289
+ * @return WP_Error|\Stripe\Source
290
+ *
291
+ */
292
+ public function fetch_payment_source( $id, $mode = '' ) {
293
+ return $this->sources->retrieve( $id, null, $this->get_api_options( $mode ) );
294
+ }
295
+
296
+ /**
297
+ *
298
+ * @param string $customer_id
299
+ * @param string $id
300
+ * @param string $mode
301
+ *
302
+ * @return WP_Error|\Stripe\Source
303
+ */
304
+ public function create_customer_source( $customer_id, $id, $mode = '' ) {
305
+ return $this->customers->createSource( $customer_id, array( 'source' => $id ), $this->get_api_options( $mode ) );
306
+ }
307
+
308
+ /**
309
+ *
310
+ * @param array $args
311
+ * @param string $mode
312
+ *
313
+ * @return WP_Error|\Stripe\Source
314
+ */
315
+ public function create_source( $args, $mode = '' ) {
316
+ return $this->sources->create( $args, $this->get_api_options( $mode ) );
317
+ }
318
+
319
+ /**
320
+ *
321
+ * @param string $source_id
322
+ * @param array $args
323
+ * @param string $mode
324
+ *
325
+ * @since 3.0.2
326
+ */
327
+ public function update_source( $source_id, $args, $mode = '' ) {
328
+ return $this->sources->update( $source_id, $args, $this->get_api_options( $mode ) );
329
+ }
330
+
331
+ public function fetch_customer( $customer_id, $mode = '' ) {
332
+ return $this->customers->retrieve( $customer_id, null, $this->get_api_options( $mode ) );
333
+ }
334
+
335
+ public function fetch_customers( $mode = '' ) {
336
+ return $this->customers->all( array( 'limit' => 1 ), $this->get_api_options( $mode ) );
337
+ }
338
+
339
+ public function fetch_payment_methods( $customer_id, $mode = '', $type = 'card' ) {
340
+ return $this->paymentMethods->all(
341
+ array(
342
+ 'customer' => $customer_id,
343
+ 'type' => $type,
344
+ ),
345
+ $this->get_api_options( $mode )
346
+ );
347
+ }
348
+
349
+ public function register_domain( $domain, $mode = '' ) {
350
+ return $this->applePayDomains->create( array( 'domain_name' => $domain ), $this->get_api_options( $mode ) );
351
+ }
352
+
353
+ /**
354
+ *
355
+ * @param string $mode
356
+ *
357
+ * @since 3.1.6
358
+ */
359
+ public function fetch_domains( $mode = '' ) {
360
+ return $this->applePayDomains->all( array( 'limit' => 50 ), $this->get_api_options( $mode ) );
361
+ }
362
+
363
+ /**
364
+ *
365
+ * @param \Stripe\ApplePayDomain $domain
366
+ * @param string $mode
367
+ *
368
+ * @since 3.1.6
369
+ */
370
+ public function delete_domain( $id, $mode = '' ) {
371
+ return $this->applePayDomains->delete( $id, array(), $this->get_api_options( $mode ) );
372
+ }
373
+
374
+ public function webhooks( $mode = '' ) {
375
+ return $this->webhookEndpoints->all( array( 'limit' => 100 ), $this->get_api_options( $mode ) );
376
+ }
377
+
378
+ public function create_webhook( $url, $events, $mode = '' ) {
379
+ return $this->webhookEndpoints->create(
380
+ array(
381
+ 'url' => $url,
382
+ 'enabled_events' => $events,
383
+ ),
384
+ $this->get_api_options( $mode )
385
+ );
386
+ }
387
+
388
+ public function update_webhook( $id, $params, $mode = '' ) {
389
+ return $this->webhookEndpoints->update( $id, $params, $this->get_api_options( $mode ) );
390
+ }
391
+
392
+ public function fetch_webhook( $id, $mode = '' ) {
393
+ return $this->webhookEndpoints->retrieve( $id, null, $this->get_api_options( $mode ) );
394
+ }
395
+
396
+ public function get_api_options( $mode = '' ) {
397
+ if ( empty( $mode ) && $this->mode != null ) {
398
+ $mode = $this->mode;
399
+ }
400
+ $args = array( 'api_key' => $this->secret_key ? $this->secret_key : wc_stripe_get_secret_key( $mode ) );
401
+
402
+ return apply_filters( 'wc_stripe_api_options', $args );
403
+ }
404
+
405
+ /**
406
+ *
407
+ * @param mixed $err
408
+ */
409
+ private function get_error_message( $err ) {
410
+ if ( is_a( $err, '\Stripe\Exception\ApiErrorException' ) ) {
411
+ $err = $err->getError();
412
+ }
413
+ if ( is_array( $err ) || $err instanceof \Stripe\ErrorObject ) {
414
+ $this->messages = ! $this->messages ? wc_stripe_get_error_messages() : $this->messages;
415
+ if ( isset( $err['decline_code'] ) && isset( $this->messages[ $err['decline_code'] ] ) ) {
416
+ return $this->messages[ $err['decline_code'] ];
417
+ }
418
+ if ( isset( $err['code'] ) && isset( $this->messages[ $err['code'] ] ) ) {
419
+ return $this->messages[ $err['code'] ];
420
+ }
421
+ if ( isset( $err['message'] ) ) {
422
+ return $err['message'];
423
+ }
424
+ }
425
+ if ( is_string( $err ) ) {
426
+ return $err;
427
+ }
428
+ }
429
+
430
+ /**
431
+ *
432
+ * @param \Stripe\Exception\ApiErrorException $e
433
+ *
434
+ * @since 3.1.1
435
+ * @todo use in future version to replace manual returns of WP_Error in each method
436
+ */
437
+ public function get_wp_error( $e, $code = 'stripe-error' ) {
438
+ $err = $e->getJsonBody()['error'];
439
+
440
+ return new WP_Error( $code, $this->get_error_message( $err ), $err );
441
+ }
442
+ }
443
+
444
+ WC_Stripe_Gateway::init();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-wc-stripe-install.php CHANGED
@@ -1,36 +1,40 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @package Stripe/Classes
7
- *
8
- */
9
- class WC_Stripe_Install {
10
-
11
- public static function init() {
12
- add_filter ( 'plugin_action_links_' . WC_STRIPE_PLUGIN_NAME, array(
13
- __CLASS__, 'plugin_action_links'
14
- ) );
15
- register_activation_hook ( WC_STRIPE_PLUGIN_NAME, array(
16
- __CLASS__, 'install'
17
- ) );
18
- }
19
-
20
- public static function install() {
21
- update_option ( 'stripe_wc_version', wc_stripe ()->version () );
22
- }
23
-
24
- /**
25
- *
26
- * @param array $links
27
- */
28
- public static function plugin_action_links($links) {
29
- $action_links = array(
30
- 'settings' => sprintf ( '<a href="%1$s">%2$s</a>', admin_url ( 'admin.php?page=wc-settings&tab=checkout&section=stripe_api' ), esc_html__ ( 'Settings', 'woo-stripe-payment' ) ),
31
- 'docs' => sprintf ( '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config">%s</a>', __ ( 'Documentation', 'woo-stripe-payment' ) )
32
- );
33
- return array_merge ( $action_links, $links );
34
- }
35
- }
36
- WC_Stripe_Install::init ();
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @package Stripe/Classes
7
+ *
8
+ */
9
+ class WC_Stripe_Install {
10
+
11
+ public static function init() {
12
+ add_filter( 'plugin_action_links_' . WC_STRIPE_PLUGIN_NAME, array( __CLASS__, 'plugin_action_links' ) );
13
+ register_activation_hook( WC_STRIPE_PLUGIN_NAME, array( __CLASS__, 'install' ) );
14
+ }
15
+
16
+ public static function install() {
17
+ update_option( 'stripe_wc_version', wc_stripe()->version() );
18
+
19
+ /**
20
+ * Schedule required actions. Actions are scheduled during install as they only need to be setup
21
+ * once.
22
+ */
23
+ wc_stripe()->scheduled_actions();
24
+ }
25
+
26
+ /**
27
+ *
28
+ * @param array $links
29
+ */
30
+ public static function plugin_action_links( $links ) {
31
+ $action_links = array(
32
+ 'settings' => sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe_api' ), esc_html__( 'Settings', 'woo-stripe-payment' ) ),
33
+ 'docs' => sprintf( '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config">%s</a>', __( 'Documentation', 'woo-stripe-payment' ) ),
34
+ );
35
+
36
+ return array_merge( $action_links, $links );
37
+ }
38
+ }
39
+
40
+ WC_Stripe_Install::init();
includes/class-wc-stripe-payment-charge-local.php CHANGED
@@ -1,71 +1,74 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @since 3.1.1
8
- * @package Stripe/Classes
9
- *
10
- */
11
- class WC_Stripe_Payment_Charge_Local extends WC_Stripe_Payment_Charge {
12
-
13
- /**
14
- *
15
- * @param WC_Order $order
16
- */
17
- public function process_payment($order) {
18
-
19
- /**
20
- * If there is no order lock, then this is not being processed via a webhook
21
- */
22
- if (! $this->payment_method->has_order_lock ( $order )) {
23
- try {
24
- $source_id = $this->payment_method->get_new_source_token ();
25
- if (! empty ( $source_id )) {
26
- // source was created client side.
27
- $source = $this->gateway->fetch_payment_source ( $source_id );
28
-
29
- if (is_wp_error ( $source )) {
30
- throw new Exception ( $source->get_error_message () );
31
- }
32
-
33
- // update the source's metadata with the order id
34
- $this->gateway->update_source ( $source_id, [
35
- 'metadata' => [
36
- 'order_id' => $order->get_id (),
37
- 'created' => time ()
38
- ]
39
- ], wc_stripe_order_mode ( $order ) );
40
- } else {
41
- // create the source
42
- $args = $this->payment_method->get_source_args ( $order );
43
- $args[ 'metadata' ][ 'order_id' ] = $order->get_id ();
44
- $args[ 'metadata' ][ 'created' ] = time ();
45
- $source = $this->gateway->create_source ( $args, wc_stripe_order_mode ( $order ) );
46
- }
47
-
48
- if (is_wp_error ( $source )) {
49
- throw new Exception ( $source->get_error_message () );
50
- }
51
-
52
- $order->update_meta_data ( WC_Stripe_Constants::SOURCE_ID, $source->id );
53
- $order->update_meta_data ( WC_Stripe_Constants::MODE, wc_stripe_mode () );
54
-
55
- $order->save ();
56
-
57
- return ( object ) [
58
- 'complete_payment' => false,
59
- 'redirect' => $this->payment_method->get_source_redirect_url ( $source, $order )
60
- ];
61
- } catch ( Exception $e ) {
62
- return new WP_Error ( 'source-error', $e->getMessage () );
63
- }
64
- } else {
65
- /**
66
- * There is an order lock so this order is ready to be processed.
67
- */
68
- return parent::process_payment ( $order );
69
- }
70
- }
71
- }
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @since 3.1.1
8
+ * @package Stripe/Classes
9
+ *
10
+ */
11
+ class WC_Stripe_Payment_Charge_Local extends WC_Stripe_Payment_Charge {
12
+
13
+ /**
14
+ *
15
+ * @param WC_Order $order
16
+ */
17
+ public function process_payment( $order ) {
18
+
19
+ /**
20
+ * If there is no order lock, then this is not being processed via a webhook
21
+ */
22
+ if ( ! $this->payment_method->has_order_lock( $order ) ) {
23
+ try {
24
+ $source_id = $this->payment_method->get_new_source_token();
25
+ if ( ! empty( $source_id ) ) {
26
+ // source was created client side.
27
+ $source = $this->gateway->sources->mode( wc_stripe_order_mode( $order ) )->retrieve( $source_id );
28
+
29
+ if ( is_wp_error( $source ) ) {
30
+ return $source;
31
+ }
32
+
33
+ // update the source's metadata with the order id
34
+ $this->gateway->sources->mode( wc_stripe_order_mode( $order ) )->update(
35
+ $source_id,
36
+ array(
37
+ 'metadata' => array(
38
+ 'order_id' => $order->get_id(),
39
+ 'created' => time(),
40
+ ),
41
+ )
42
+ );
43
+ } else {
44
+ // create the source
45
+ $args = $this->payment_method->get_source_args( $order );
46
+ $args['metadata']['order_id'] = $order->get_id();
47
+ $args['metadata']['created'] = time();
48
+ $source = $this->gateway->sources->mode( wc_stripe_order_mode( $order ) )->create( $args );
49
+ }
50
+
51
+ if ( is_wp_error( $source ) ) {
52
+ throw new Exception( $source->get_error_message() );
53
+ }
54
+
55
+ $order->update_meta_data( WC_Stripe_Constants::SOURCE_ID, $source->id );
56
+ $order->update_meta_data( WC_Stripe_Constants::MODE, wc_stripe_mode() );
57
+
58
+ $order->save();
59
+
60
+ return (object) array(
61
+ 'complete_payment' => false,
62
+ 'redirect' => $this->payment_method->get_source_redirect_url( $source, $order ),
63
+ );
64
+ } catch ( Exception $e ) {
65
+ return new WP_Error( 'source-error', $e->getMessage() );
66
+ }
67
+ } else {
68
+ /**
69
+ * There is an order lock so this order is ready to be processed.
70
+ */
71
+ return parent::process_payment( $order );
72
+ }
73
+ }
74
+ }
includes/class-wc-stripe-payment-charge.php CHANGED
@@ -1,173 +1,179 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-stripe-payment.php' );
5
-
6
- /**
7
- *
8
- * @author Payment Plugins
9
- * @since 3.1.0
10
- *
11
- */
12
- class WC_Stripe_Payment_Charge extends WC_Stripe_Payment {
13
-
14
- /**
15
- *
16
- * {@inheritDoc}
17
- *
18
- * @see WC_Stripe_Payment::process_payment()
19
- */
20
- public function process_payment($order) {
21
- if ($this->payment_method->should_save_payment_method ( $order )) {
22
- $result = $this->payment_method->save_payment_method ( $this->payment_method->get_new_source_token (), $order );
23
- if (is_wp_error ( $result )) {
24
- return $result;
25
- }
26
- }
27
-
28
- $args = $this->get_order_charge_args ( $args, $order );
29
-
30
- $charge = $this->gateway->charge ( $args, wc_stripe_order_mode ( $order ) );
31
-
32
- wc_stripe_log_info ( 'Stripe charge: ' . print_r ( $charge, true ) );
33
-
34
- if (is_wp_error ( $charge )) {
35
- return $charge;
36
- }
37
-
38
- return ( object ) [ 'complete_payment' => true,
39
- 'charge' => $charge
40
- ];
41
- }
42
-
43
- /**
44
- *
45
- * {@inheritDoc}
46
- *
47
- * @see WC_Stripe_Payment::capture_charge()
48
- */
49
- public function capture_charge($amount, $order) {
50
- return $this->gateway->capture ( $order->get_transaction_id (), array(
51
- 'amount' => wc_stripe_add_number_precision ( $amount, $order->get_currency () )
52
- ), wc_stripe_order_mode ( $order ) );
53
- }
54
-
55
- /**
56
- *
57
- * {@inheritDoc}
58
- *
59
- * @see WC_Stripe_Payment::void_charge()
60
- */
61
- public function void_charge($order) {
62
- return $this->gateway->refund ( array(
63
- 'charge' => $order->get_transaction_id ()
64
- ), wc_stripe_order_mode ( $order ) );
65
- }
66
-
67
- public function scheduled_subscription_payment($amount, $order) {
68
- $this->get_order_charge_args ( $args, $order );
69
-
70
- $args[ 'source' ] = $order->get_meta ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN );
71
-
72
- if (( $customer_id = $order->get_meta ( WC_Stripe_Constants::CUSTOMER_ID ) )) {
73
- $args[ 'customer' ] = $customer_id;
74
- } elseif (( $customer_id = wc_stripe_get_customer_id ( $order->get_customer_id (), wc_stripe_order_mode ( $order ) ) )) {
75
- $args[ 'customer' ] = $customer_id;
76
- }
77
-
78
- $charge = $this->gateway->charge ( $args, wc_stripe_order_mode ( $order ) );
79
-
80
- if (is_wp_error ( $charge )) {
81
- return $charge;
82
- } else {
83
- return ( object ) [
84
- 'complete_payment' => true,
85
- 'charge' => $charge
86
- ];
87
- }
88
- }
89
-
90
- /**
91
- *
92
- * {@inheritDoc}
93
- *
94
- * @see WC_Stripe_Payment::process_pre_order_payment()
95
- */
96
- public function process_pre_order_payment($order) {
97
- $this->get_order_charge_args ( $args, $order );
98
-
99
- $args[ 'source' ] = $order->get_meta ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN );
100
-
101
- if (( $customer_id = $order->get_meta ( WC_Stripe_Constants::CUSTOMER_ID ) )) {
102
- $args[ 'customer' ] = $customer_id;
103
- } elseif (( $customer_id = wc_stripe_get_customer_id ( $order->get_customer_id (), wc_stripe_order_mode ( $order ) ) )) {
104
- $args[ 'customer' ] = $customer_id;
105
- }
106
-
107
- $charge = $this->gateway->charge ( $args, wc_stripe_order_mode ( $order ) );
108
-
109
- if (is_wp_error ( $charge )) {
110
- return $charge;
111
- } else {
112
- return ( object ) [
113
- 'complete_payment' => true,
114
- 'charge' => $charge
115
- ];
116
- }
117
- }
118
-
119
- /**
120
- *
121
- * @param array $args
122
- * @param WC_Order $order
123
- */
124
- public function get_order_charge_args(&$args, $order) {
125
- $this->add_general_order_args ( $args, $order );
126
-
127
- if (get_option ( 'woocommerce_stripe_email_receipt', 'no' ) === 'yes' && ( $email = $order->get_billing_email () )) {
128
- $args[ 'receipt_email' ] = $email;
129
- }
130
- $args[ 'capture' ] = $this->payment_method->get_option ( 'charge_type' ) === 'capture';
131
-
132
- $customer_id = wc_stripe_get_customer_id ( $order->get_user_id () );
133
-
134
- // only add customer ID if user is paying with a saved payment method
135
- if ($customer_id && $this->payment_method->use_saved_source ()) {
136
- $args[ 'customer' ] = $customer_id;
137
- }
138
-
139
- $this->payment_method->add_stripe_order_args ( $args, $order );
140
-
141
- return apply_filters ( 'wc_stripe_charge_order_args', $args, $order, $this->payment_method->id );
142
- }
143
-
144
- /**
145
- *
146
- * {@inheritDoc}
147
- *
148
- * @see WC_Stripe_Payment::get_payment_method_from_charge()
149
- */
150
- public function get_payment_method_from_charge($charge) {
151
- return $charge->source->id;
152
- }
153
-
154
- /**
155
- *
156
- * {@inheritDoc}
157
- *
158
- * @see WC_Stripe_Payment::add_order_payment_method()
159
- */
160
- public function add_order_payment_method(&$args, $order) {
161
- $args[ 'source' ] = $this->payment_method->get_payment_method_from_request ();
162
- }
163
-
164
- /**
165
- *
166
- * {@inheritDoc}
167
- *
168
- * @see WC_Stripe_Payment::can_void_charge()
169
- */
170
- public function can_void_order($order) {
171
- return $order->get_transaction_id ();
172
- }
173
- }
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ require_once( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-stripe-payment.php' );
5
+
6
+ /**
7
+ *
8
+ * @package Stripe/Classes
9
+ * @author Payment Plugins
10
+ * @since 3.1.0
11
+ *
12
+ */
13
+ class WC_Stripe_Payment_Charge extends WC_Stripe_Payment {
14
+
15
+ /**
16
+ *
17
+ * {@inheritDoc}
18
+ *
19
+ * @see WC_Stripe_Payment::process_payment()
20
+ */
21
+ public function process_payment( $order ) {
22
+ if ( $this->payment_method->should_save_payment_method( $order ) ) {
23
+ $result = $this->payment_method->save_payment_method( $this->payment_method->get_new_source_token(), $order );
24
+ if ( is_wp_error( $result ) ) {
25
+ return $result;
26
+ }
27
+ }
28
+
29
+ $args = $this->get_order_charge_args( $args, $order );
30
+
31
+ $charge = $this->gateway->charges->mode( wc_stripe_order_mode( $order ) )->create( $args );
32
+
33
+ wc_stripe_log_info( 'Stripe charge: ' . print_r( $charge, true ) );
34
+
35
+ if ( is_wp_error( $charge ) ) {
36
+ return $charge;
37
+ }
38
+
39
+ return (object) array(
40
+ 'complete_payment' => true,
41
+ 'charge' => $charge,
42
+ );
43
+ }
44
+
45
+ /**
46
+ *
47
+ * {@inheritDoc}
48
+ *
49
+ * @see WC_Stripe_Payment::capture_charge()
50
+ */
51
+ public function capture_charge( $amount, $order ) {
52
+ return $this->gateway->charges->mode( wc_stripe_order_mode( $order ) )->capture(
53
+ $order->get_transaction_id(),
54
+ array(
55
+ 'amount' => wc_stripe_add_number_precision(
56
+ $amount,
57
+ $order->get_currency()
58
+ ),
59
+ )
60
+ );
61
+ }
62
+
63
+ /**
64
+ *
65
+ * {@inheritDoc}
66
+ *
67
+ * @see WC_Stripe_Payment::void_charge()
68
+ */
69
+ public function void_charge( $order ) {
70
+ return $this->gateway->refunds->mode( wc_stripe_order_mode( $order ) )->create( array( 'charge' => $order->get_transaction_id() ) );
71
+ }
72
+
73
+ public function scheduled_subscription_payment( $amount, $order ) {
74
+ $this->get_order_charge_args( $args, $order );
75
+
76
+ $args['source'] = $order->get_meta( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN );
77
+
78
+ if ( ( $customer_id = $order->get_meta( WC_Stripe_Constants::CUSTOMER_ID ) ) ) {
79
+ $args['customer'] = $customer_id;
80
+ } elseif ( ( $customer_id = wc_stripe_get_customer_id( $order->get_customer_id(), wc_stripe_order_mode( $order ) ) ) ) {
81
+ $args['customer'] = $customer_id;
82
+ }
83
+
84
+ $charge = $this->gateway->charges->mode( wc_stripe_order_mode( $order ) )->create( $args );
85
+
86
+ if ( is_wp_error( $charge ) ) {
87
+ return $charge;
88
+ } else {
89
+ return (object) array(
90
+ 'complete_payment' => true,
91
+ 'charge' => $charge,
92
+ );
93
+ }
94
+ }
95
+
96
+ /**
97
+ *
98
+ * {@inheritDoc}
99
+ *
100
+ * @see WC_Stripe_Payment::process_pre_order_payment()
101
+ */
102
+ public function process_pre_order_payment( $order ) {
103
+ $this->get_order_charge_args( $args, $order );
104
+
105
+ $args['source'] = $order->get_meta( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN );
106
+
107
+ if ( ( $customer_id = $order->get_meta( WC_Stripe_Constants::CUSTOMER_ID ) ) ) {
108
+ $args['customer'] = $customer_id;
109
+ } elseif ( ( $customer_id = wc_stripe_get_customer_id( $order->get_customer_id(), wc_stripe_order_mode( $order ) ) ) ) {
110
+ $args['customer'] = $customer_id;
111
+ }
112
+
113
+ $charge = $this->gateway->charges->mode( wc_stripe_order_mode( $order ) )->create( $args );
114
+
115
+ if ( is_wp_error( $charge ) ) {
116
+ return $charge;
117
+ } else {
118
+ return (object) array(
119
+ 'complete_payment' => true,
120
+ 'charge' => $charge,
121
+ );
122
+ }
123
+ }
124
+
125
+ /**
126
+ *
127
+ * @param array $args
128
+ * @param WC_Order $order
129
+ */
130
+ public function get_order_charge_args( &$args, $order ) {
131
+ $this->add_general_order_args( $args, $order );
132
+
133
+ if ( get_option( 'woocommerce_stripe_email_receipt', 'no' ) === 'yes' && ( $email = $order->get_billing_email() ) ) {
134
+ $args['receipt_email'] = $email;
135
+ }
136
+ $args['capture'] = $this->payment_method->get_option( 'charge_type' ) === 'capture';
137
+
138
+ $customer_id = wc_stripe_get_customer_id( $order->get_user_id() );
139
+
140
+ // only add customer ID if user is paying with a saved payment method
141
+ if ( $customer_id && $this->payment_method->use_saved_source() ) {
142
+ $args['customer'] = $customer_id;
143
+ }
144
+
145
+ $this->payment_method->add_stripe_order_args( $args, $order );
146
+
147
+ return apply_filters( 'wc_stripe_charge_order_args', $args, $order, $this->payment_method->id );
148
+ }
149
+
150
+ /**
151
+ *
152
+ * {@inheritDoc}
153
+ *
154
+ * @see WC_Stripe_Payment::get_payment_method_from_charge()
155
+ */
156
+ public function get_payment_method_from_charge( $charge ) {
157
+ return $charge->source->id;
158
+ }
159
+
160
+ /**
161
+ *
162
+ * {@inheritDoc}
163
+ *
164
+ * @see WC_Stripe_Payment::add_order_payment_method()
165
+ */
166
+ public function add_order_payment_method( &$args, $order ) {
167
+ $args['source'] = $this->payment_method->get_payment_method_from_request();
168
+ }
169
+
170
+ /**
171
+ *
172
+ * {@inheritDoc}
173
+ *
174
+ * @see WC_Stripe_Payment::can_void_charge()
175
+ */
176
+ public function can_void_order( $order ) {
177
+ return $order->get_transaction_id();
178
+ }
179
+ }
includes/class-wc-stripe-payment-factory.php CHANGED
@@ -1,42 +1,42 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @since 3.1.1
8
- * @package Stripe/Classes
9
- *
10
- */
11
- class WC_Stripe_Payment_Factory {
12
-
13
- private static $classes = [
14
- 'charge' => 'WC_Stripe_Payment_Charge',
15
- 'payment_intent' => 'WC_Stripe_Payment_Intent',
16
- 'local_charge' => 'WC_Stripe_Payment_Charge_Local'
17
- ];
18
-
19
- /**
20
- *
21
- * @param string $type
22
- * @param WC_Payment_Gateway_Stripe $payment_method
23
- * @param WC_Stripe_Gateway $gateway
24
- */
25
- public static function load($type, $payment_method, $gateway) {
26
- $classes = apply_filters ( 'wc_stripe_payment_classes', self::$classes );
27
- if (! isset ( $classes[ $type ] )) {
28
- throw Exception ( 'No class defined for type ' . $type );
29
- }
30
- $classname = $classes[ $type ];
31
-
32
- $args = func_get_args ();
33
-
34
- if (count ( $args ) > 3) {
35
- $args = array_slice ( $args, 3 );
36
- $instance = new $classname ( $payment_method, $gateway, ...$args );
37
- } else {
38
- $instance = new $classname ( $payment_method, $gateway );
39
- }
40
- return $instance;
41
- }
42
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @since 3.1.1
8
+ * @package Stripe/Classes
9
+ *
10
+ */
11
+ class WC_Stripe_Payment_Factory {
12
+
13
+ private static $classes = array(
14
+ 'charge' => 'WC_Stripe_Payment_Charge',
15
+ 'payment_intent' => 'WC_Stripe_Payment_Intent',
16
+ 'local_charge' => 'WC_Stripe_Payment_Charge_Local',
17
+ );
18
+
19
+ /**
20
+ *
21
+ * @param string $type
22
+ * @param WC_Payment_Gateway_Stripe $payment_method
23
+ * @param WC_Stripe_Gateway $gateway
24
+ */
25
+ public static function load( $type, $payment_method, $gateway ) {
26
+ $classes = apply_filters( 'wc_stripe_payment_classes', self::$classes );
27
+ if ( ! isset( $classes[ $type ] ) ) {
28
+ throw Exception( 'No class defined for type ' . $type );
29
+ }
30
+ $classname = $classes[ $type ];
31
+
32
+ $args = func_get_args();
33
+
34
+ if ( count( $args ) > 3 ) {
35
+ $args = array_slice( $args, 3 );
36
+ $instance = new $classname( $payment_method, $gateway, ...$args );
37
+ } else {
38
+ $instance = new $classname( $payment_method, $gateway );
39
+ }
40
+ return $instance;
41
+ }
42
+ }
includes/class-wc-stripe-payment-intent.php CHANGED
@@ -1,321 +1,337 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-stripe-payment.php' );
5
-
6
- /**
7
- *
8
- * @author Payment Plugins
9
- * @since 3.1.0
10
- *
11
- */
12
- class WC_Stripe_Payment_Intent extends WC_Stripe_Payment {
13
-
14
- /**
15
- *
16
- * {@inheritDoc}
17
- *
18
- * @see WC_Stripe_Payment::process_payment()
19
- */
20
- public function process_payment($order) {
21
- // first check to see if a payment intent can be used
22
- if (( $intent = $this->can_use_payment_intent ( $order ) )) {
23
- $intent_id = $intent[ 'id' ];
24
- if ($this->can_update_payment_intent ( $order )) {
25
- $intent = $this->gateway->update_payment_intent ( $intent_id, $this->get_payment_intent_args ( $order, false ) );
26
- } else {
27
- $intent = $this->gateway->fetch_payment_intent ( $intent_id );
28
- }
29
- } else {
30
- $intent = $this->gateway->create_payment_intent ( $this->get_payment_intent_args ( $order ) );
31
- }
32
-
33
- if (is_wp_error ( $intent )) {
34
- return $intent;
35
- }
36
-
37
- // always update the order with the payment intent.
38
- $order->update_meta_data ( WC_Stripe_Constants::PAYMENT_INTENT_ID, $intent->id );
39
- $order->update_meta_data ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $intent->payment_method );
40
- $order->update_meta_data ( WC_Stripe_Constants::MODE, wc_stripe_mode () );
41
- // serialize the the intent and save to the order. The intent will be used to analyze if anything
42
- // has changed.
43
- $order->update_meta_data ( WC_Stripe_Constants::PAYMENT_INTENT, $intent->jsonSerialize () );
44
- $order->save ();
45
-
46
- if ($intent->status === 'requires_confirmation') {
47
- $intent = $this->gateway->confirm_payment_intent ( $intent );
48
- if (is_wp_error ( $intent )) {
49
- return $intent;
50
- }
51
- }
52
-
53
- // the intent was processed.
54
- if ($intent->status === 'succeeded' || $intent->status === 'requires_capture') {
55
-
56
- if (isset ( $intent[ 'setup_future_usage' ] ) && 'off_session' === $intent[ 'setup_future_usage' ]) {
57
- $result = $this->payment_method->save_payment_method ( $this->payment_method->get_new_source_token (), $order );
58
- if (is_wp_error ( $result )) {
59
- $this->payment_method->set_payment_save_error ( $order, $result );
60
- }
61
- }
62
-
63
- // payment has been processed.
64
- $charges = $intent->charges;
65
- if (count ( $charges->data ) > 0) {
66
- $charge = $charges->data[ 0 ];
67
- return ( object ) [
68
- 'complete_payment' => true,
69
- 'charge' => $charge
70
- ];
71
- }
72
- }
73
- if ($intent->status === 'requires_source_action' || $intent->status === 'requires_action') {
74
- return ( object ) [
75
- 'complete_payment' => false,
76
- 'redirect' => $this->payment_method->get_payment_intent_checkout_url ( $intent, $order )
77
- ];
78
- }
79
- if ($intent->status === 'requires_source' || $intent->status === 'requires_payment_method') {
80
- return ( object ) [
81
- 'complete_payment' => false,
82
- 'redirect' => $this->payment_method->get_payment_intent_checkout_url ( $intent, $order )
83
- ];
84
- }
85
- }
86
-
87
- public function scheduled_subscription_payment($amount, $order) {
88
- $args = $this->get_payment_intent_args ( $order );
89
-
90
- $args[ 'confirm' ] = true;
91
- $args[ 'off_session' ] = true;
92
- $args[ 'payment_method' ] = $this->payment_method->get_order_meta_data ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $order );
93
-
94
- if (( $customer = $this->payment_method->get_order_meta_data ( WC_Stripe_Constants::CUSTOMER_ID, $order ) )) {
95
- $args[ 'customer' ] = $customer;
96
- }
97
-
98
- $intent = $this->gateway->create_payment_intent ( $args, wc_stripe_order_mode ( $order ) );
99
-
100
- if (is_wp_error ( $intent )) {
101
- return $intent;
102
- } else {
103
- $order->update_meta_data ( WC_Stripe_Constants::PAYMENT_INTENT_ID, $intent->id );
104
-
105
- $charge = $intent->charges->data[ 0 ];
106
-
107
- if ($intent->status === 'succeeded' || $intent->status === 'requires_capture') {
108
-
109
- return ( object ) [
110
- 'complete_payment' => true,
111
- 'charge' => $charge
112
- ];
113
- } else {
114
- return ( object ) [
115
- 'complete_payment' => false,
116
- 'charge' => $charge
117
- ];
118
- }
119
- }
120
- }
121
-
122
- /**
123
- *
124
- * {@inheritDoc}
125
- *
126
- * @see WC_Stripe_Payment::process_pre_order_payment()
127
- */
128
- public function process_pre_order_payment($order) {
129
- $args = $this->get_payment_intent_args ( $order );
130
-
131
- $args[ 'confirm' ] = true;
132
- $args[ 'off_session' ] = true;
133
- $args[ 'payment_method' ] = $this->payment_method->get_order_meta_data ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $order );
134
-
135
- if (( $customer = $this->payment_method->get_order_meta_data ( WC_Stripe_Constants::CUSTOMER_ID, $order ) )) {
136
- $args[ 'customer' ] = $customer;
137
- }
138
-
139
- $intent = $this->gateway->create_payment_intent ( $args, wc_stripe_order_mode ( $order ) );
140
-
141
- if (is_wp_error ( $intent )) {
142
- return $intent;
143
- } else {
144
- $order->update_meta_data ( '_payment_intent_id', $intent->id );
145
-
146
- $charge = $intent->charges->data[ 0 ];
147
-
148
- if ($intent->status === 'succeeded' || $intent->status === 'requires_capture') {
149
- return ( object ) [
150
- 'complete_payment' => true,
151
- 'charge' => $charge
152
- ];
153
- } else {
154
- return ( object ) [
155
- 'complete_payment' => false,
156
- 'charge' => $charge
157
- ];
158
- }
159
- }
160
- }
161
-
162
- /**
163
- * Compares the order's saved intent to the order's attributes.
164
- * If there is a delta, then the payment intent can be updated. The intent should
165
- * only be updated if this is the checkout page.
166
- *
167
- * @param WC_Order $order
168
- */
169
- public function can_update_payment_intent($order) {
170
- if (! is_checkout () || defined ( WC_Stripe_Constants::REDIRECT_HANDLER )) {
171
- return false;
172
- }
173
- $intent = $order->get_meta ( WC_Stripe_Constants::PAYMENT_INTENT );
174
- if ($intent) {
175
- $order_hash = implode ( '_', [
176
- wc_stripe_add_number_precision ( $order->get_total (), $order->get_currency () ),
177
- wc_stripe_get_customer_id ( $order->get_user_id () ),
178
- $this->payment_method->get_payment_method_from_request (),
179
- $this->payment_method->get_payment_method_type ()
180
- ] );
181
- $intent_hash = implode ( '_', [
182
- $intent[ 'amount' ],
183
- $intent[ 'customer' ],
184
- $intent[ 'payment_method' ],
185
- isset ( $intent[ 'payment_method_types' ] ) ? $intent[ 'payment_method_types' ][ 0 ] : ''
186
- ] );
187
- return $order_hash !== $intent_hash;
188
- }
189
- return false;
190
- }
191
-
192
- /**
193
- *
194
- * @param WC_Order $order
195
- */
196
- public function get_payment_intent_args($order, $new = true) {
197
- $this->add_general_order_args ( $args, $order );
198
-
199
- if ($new) {
200
- $args[ 'confirmation_method' ] = $this->payment_method->get_confirmation_method ( $order );
201
- $args[ 'capture_method' ] = $this->payment_method->get_option ( 'charge_type' ) === 'capture' ? 'automatic' : 'manual';
202
- $args[ 'confirm' ] = false;
203
- }
204
-
205
- if (get_option ( 'woocommerce_stripe_email_receipt', 'no' ) === 'yes' && ( $email = $order->get_billing_email () )) {
206
- $args[ 'receipt_email' ] = $email;
207
- }
208
-
209
- if (( $customer_id = wc_stripe_get_customer_id ( $order->get_customer_id () ) )) {
210
- $args[ 'customer' ] = $customer_id;
211
- }
212
-
213
- if ($this->payment_method->should_save_payment_method ( $order )) {
214
- $args[ 'setup_future_usage' ] = 'off_session';
215
- }
216
-
217
- $args[ 'payment_method_types' ][] = $this->payment_method->get_payment_method_type ();
218
-
219
- $this->payment_method->add_stripe_order_args ( $args, $order );
220
-
221
- return apply_filters ( 'wc_stripe_payment_intent_args', $args, $order, $this );
222
- }
223
-
224
- /**
225
- *
226
- * {@inheritDoc}
227
- *
228
- * @see WC_Stripe_Payment::capture_charge()
229
- */
230
- public function capture_charge($amount, $order) {
231
- $payment_intent = $this->payment_method->get_order_meta_data ( WC_Stripe_Constants::PAYMENT_INTENT_ID, $order );
232
- if (empty ( $payment_intent )) {
233
- $charge = $this->gateway->get_charge ( $order->get_transaction_id (), wc_stripe_order_mode ( $order ) );
234
- $payment_intent = $charge->payment_intent;
235
- $order->update_meta_data ( WC_Stripe_Constants::PAYMENT_INTENT_ID, $payment_intent );
236
- $order->save ();
237
- }
238
- return $this->gateway->capture_payment_intent ( $payment_intent, array(
239
- 'amount_to_capture' => wc_stripe_add_number_precision ( $amount, $order->get_currency () )
240
- ), wc_stripe_order_mode ( $order ) );
241
- }
242
-
243
- /**
244
- *
245
- * {@inheritDoc}
246
- *
247
- * @see WC_Stripe_Payment::void_charge()
248
- */
249
- public function void_charge($order) {
250
- // fetch the intent and check its status
251
- $payment_intent = $this->gateway->fetch_payment_intent ( $order->get_meta ( WC_Stripe_Constants::PAYMENT_INTENT_ID ), wc_stripe_order_mode ( $order ) );
252
- if (is_wp_error ( $payment_intent )) {
253
- return $payment_intent;
254
- }
255
- $statuses = array( 'requires_payment_method',
256
- 'requires_capture', 'requires_confirmation',
257
- 'requires_action'
258
- );
259
- if ('canceled' !== $payment_intent->status) {
260
- if (in_array ( $payment_intent->status, $statuses )) {
261
- return $this->gateway->cancel_payment_intent ( $payment_intent, wc_stripe_order_mode ( $order ) );
262
- } elseif ('succeeded' === $payment_intent->status) {
263
- return $this->process_refund ( $order, $order->get_total () );
264
- }
265
- }
266
- }
267
-
268
- /**
269
- *
270
- * {@inheritDoc}
271
- *
272
- * @see WC_Stripe_Payment::get_payment_method_from_charge()
273
- */
274
- public function get_payment_method_from_charge($charge) {
275
- return $charge->payment_method;
276
- }
277
-
278
- /**
279
- *
280
- * {@inheritDoc}
281
- *
282
- * @see WC_Stripe_Payment::add_order_payment_method()
283
- */
284
- public function add_order_payment_method(&$args, $order) {
285
- $args[ 'payment_method' ] = $this->payment_method->get_payment_method_from_request ();
286
- if (empty ( $args[ 'payment_method' ] )) {
287
- unset ( $args[ 'payment_method' ] );
288
- }
289
- }
290
-
291
- /**
292
- *
293
- * @param WC_Order $order
294
- */
295
- public function can_use_payment_intent($order) {
296
- $intent = $order->get_meta ( WC_Stripe_Constants::PAYMENT_INTENT );
297
-
298
- if ($intent) {
299
- if ($intent[ 'confirmation_method' ] != $this->payment_method->get_confirmation_method ( $order )) {
300
- return false;
301
- }
302
-
303
- // compare the active environment to the order's environment
304
- if (wc_stripe_order_mode ( $order ) != wc_stripe_mode ()) {
305
- return false;
306
- }
307
- return $intent;
308
- }
309
- return false;
310
- }
311
-
312
- /**
313
- *
314
- * {@inheritDoc}
315
- *
316
- * @see WC_Stripe_Payment::can_void_charge()
317
- */
318
- public function can_void_order($order) {
319
- return $order->get_meta ( WC_Stripe_Constants::PAYMENT_INTENT_ID );
320
- }
321
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ require_once( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-stripe-payment.php' );
5
+
6
+ /**
7
+ *
8
+ * @package Stripe/Classes
9
+ * @author Payment Plugins
10
+ * @since 3.1.0
11
+ *
12
+ */
13
+ class WC_Stripe_Payment_Intent extends WC_Stripe_Payment {
14
+
15
+ /**
16
+ *
17
+ * {@inheritDoc}
18
+ *
19
+ * @see WC_Stripe_Payment::process_payment()
20
+ */
21
+ public function process_payment( $order ) {
22
+ // first check to see if a payment intent can be used
23
+ if ( ( $intent = $this->can_use_payment_intent( $order ) ) ) {
24
+ $intent_id = $intent['id'];
25
+ if ( $this->can_update_payment_intent( $order ) ) {
26
+ $intent = $this->gateway->paymentIntents->update( $intent_id, $this->get_payment_intent_args( $order, false ) );
27
+ } else {
28
+ $intent = $this->gateway->paymentIntents->retrieve( $intent_id );
29
+ }
30
+ } else {
31
+ $intent = $this->gateway->paymentIntents->create( $this->get_payment_intent_args( $order ) );
32
+ }
33
+
34
+ if ( is_wp_error( $intent ) ) {
35
+ return $intent;
36
+ }
37
+
38
+ // always update the order with the payment intent.
39
+ $order->update_meta_data( WC_Stripe_Constants::PAYMENT_INTENT_ID, $intent->id );
40
+ $order->update_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $intent->payment_method );
41
+ $order->update_meta_data( WC_Stripe_Constants::MODE, wc_stripe_mode() );
42
+ // serialize the the intent and save to the order. The intent will be used to analyze if anything
43
+ // has changed.
44
+ $order->update_meta_data( WC_Stripe_Constants::PAYMENT_INTENT, $intent->jsonSerialize() );
45
+ $order->save();
46
+
47
+ if ( $intent->status === 'requires_confirmation' ) {
48
+ $intent = $this->gateway->paymentIntents->confirm( $intent->id );
49
+ if ( is_wp_error( $intent ) ) {
50
+ return $intent;
51
+ }
52
+ }
53
+
54
+ // the intent was processed.
55
+ if ( $intent->status === 'succeeded' || $intent->status === 'requires_capture' ) {
56
+
57
+ if ( isset( $intent['setup_future_usage'] ) && 'off_session' === $intent['setup_future_usage'] ) {
58
+ $result = $this->payment_method->save_payment_method( $this->payment_method->get_new_source_token(), $order );
59
+ if ( is_wp_error( $result ) ) {
60
+ $this->payment_method->set_payment_save_error( $order, $result );
61
+ }
62
+ }
63
+
64
+ // payment has been processed.
65
+ $charges = $intent->charges;
66
+ if ( count( $charges->data ) > 0 ) {
67
+ $charge = $charges->data[0];
68
+
69
+ return (object) array(
70
+ 'complete_payment' => true,
71
+ 'charge' => $charge,
72
+ );
73
+ }
74
+ }
75
+ if ( $intent->status === 'requires_source_action' || $intent->status === 'requires_action' ) {
76
+ return (object) array(
77
+ 'complete_payment' => false,
78
+ 'redirect' => $this->payment_method->get_payment_intent_checkout_url( $intent, $order ),
79
+ );
80
+ }
81
+ if ( $intent->status === 'requires_source' || $intent->status === 'requires_payment_method' ) {
82
+ return (object) array(
83
+ 'complete_payment' => false,
84
+ 'redirect' => $this->payment_method->get_payment_intent_checkout_url( $intent, $order ),
85
+ );
86
+ }
87
+ }
88
+
89
+ public function scheduled_subscription_payment( $amount, $order ) {
90
+ $args = $this->get_payment_intent_args( $order );
91
+
92
+ $args['confirm'] = true;
93
+ $args['off_session'] = true;
94
+ $args['payment_method'] = $this->payment_method->get_order_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $order );
95
+
96
+ if ( ( $customer = $this->payment_method->get_order_meta_data( WC_Stripe_Constants::CUSTOMER_ID, $order ) ) ) {
97
+ $args['customer'] = $customer;
98
+ }
99
+
100
+ $intent = $this->gateway->paymentIntents->mode( wc_stripe_order_mode( $order ) )->create( $args );
101
+
102
+ if ( is_wp_error( $intent ) ) {
103
+ return $intent;
104
+ } else {
105
+ $order->update_meta_data( WC_Stripe_Constants::PAYMENT_INTENT_ID, $intent->id );
106
+
107
+ $charge = $intent->charges->data[0];
108
+
109
+ if ( $intent->status === 'succeeded' || $intent->status === 'requires_capture' ) {
110
+
111
+ return (object) array(
112
+ 'complete_payment' => true,
113
+ 'charge' => $charge,
114
+ );
115
+ } else {
116
+ return (object) array(
117
+ 'complete_payment' => false,
118
+ 'charge' => $charge,
119
+ );
120
+ }
121
+ }
122
+ }
123
+
124
+ /**
125
+ *
126
+ * {@inheritDoc}
127
+ *
128
+ * @see WC_Stripe_Payment::process_pre_order_payment()
129
+ */
130
+ public function process_pre_order_payment( $order ) {
131
+ $args = $this->get_payment_intent_args( $order );
132
+
133
+ $args['confirm'] = true;
134
+ $args['off_session'] = true;
135
+ $args['payment_method'] = $this->payment_method->get_order_meta_data( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN, $order );
136
+
137
+ if ( ( $customer = $this->payment_method->get_order_meta_data( WC_Stripe_Constants::CUSTOMER_ID, $order ) ) ) {
138
+ $args['customer'] = $customer;
139
+ }
140
+
141
+ $intent = $this->gateway->paymentIntents->mode( wc_stripe_order_mode( $order ) )->create( $args );
142
+
143
+ if ( is_wp_error( $intent ) ) {
144
+ return $intent;
145
+ } else {
146
+ $order->update_meta_data( WC_Stripe_Constants::PAYMENT_INTENT_ID, $intent->id );
147
+
148
+ $charge = $intent->charges->data[0];
149
+
150
+ if ( $intent->status === 'succeeded' || $intent->status === 'requires_capture' ) {
151
+ return (object) array(
152
+ 'complete_payment' => true,
153
+ 'charge' => $charge,
154
+ );
155
+ } else {
156
+ return (object) array(
157
+ 'complete_payment' => false,
158
+ 'charge' => $charge,
159
+ );
160
+ }
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Compares the order's saved intent to the order's attributes.
166
+ * If there is a delta, then the payment intent can be updated. The intent should
167
+ * only be updated if this is the checkout page.
168
+ *
169
+ * @param WC_Order $order
170
+ */
171
+ public function can_update_payment_intent( $order ) {
172
+ if ( ! is_checkout() || defined( WC_Stripe_Constants::REDIRECT_HANDLER ) ) {
173
+ return false;
174
+ }
175
+ $intent = $order->get_meta( WC_Stripe_Constants::PAYMENT_INTENT );
176
+ if ( $intent ) {
177
+ $order_hash = implode(
178
+ '_',
179
+ array(
180
+ wc_stripe_add_number_precision( $order->get_total(), $order->get_currency() ),
181
+ wc_stripe_get_customer_id( $order->get_user_id() ),
182
+ $this->payment_method->get_payment_method_from_request(),
183
+ $this->payment_method->get_payment_method_type(),
184
+ )
185
+ );
186
+ $intent_hash = implode(
187
+ '_',
188
+ array(
189
+ $intent['amount'],
190
+ $intent['customer'],
191
+ $intent['payment_method'],
192
+ isset( $intent['payment_method_types'] ) ? $intent['payment_method_types'][0] : '',
193
+ )
194
+ );
195
+
196
+ return $order_hash !== $intent_hash;
197
+ }
198
+
199
+ return false;
200
+ }
201
+
202
+ /**
203
+ *
204
+ * @param WC_Order $order
205
+ */
206
+ public function get_payment_intent_args( $order, $new = true ) {
207
+ $this->add_general_order_args( $args, $order );
208
+
209
+ if ( $new ) {
210
+ $args['confirmation_method'] = $this->payment_method->get_confirmation_method( $order );
211
+ $args['capture_method'] = $this->payment_method->get_option( 'charge_type' ) === 'capture' ? 'automatic' : 'manual';
212
+ $args['confirm'] = false;
213
+ }
214
+
215
+ if ( get_option( 'woocommerce_stripe_email_receipt', 'no' ) === 'yes' && ( $email = $order->get_billing_email() ) ) {
216
+ $args['receipt_email'] = $email;
217
+ }
218
+
219
+ if ( ( $customer_id = wc_stripe_get_customer_id( $order->get_customer_id() ) ) ) {
220
+ $args['customer'] = $customer_id;
221
+ }
222
+
223
+ if ( $this->payment_method->should_save_payment_method( $order ) ) {
224
+ $args['setup_future_usage'] = 'off_session';
225
+ }
226
+
227
+ $args['payment_method_types'][] = $this->payment_method->get_payment_method_type();
228
+
229
+ $this->payment_method->add_stripe_order_args( $args, $order );
230
+
231
+ return apply_filters( 'wc_stripe_payment_intent_args', $args, $order, $this );
232
+ }
233
+
234
+ /**
235
+ *
236
+ * {@inheritDoc}
237
+ *
238
+ * @see WC_Stripe_Payment::capture_charge()
239
+ */
240
+ public function capture_charge( $amount, $order ) {
241
+ $payment_intent = $this->payment_method->get_order_meta_data( WC_Stripe_Constants::PAYMENT_INTENT_ID, $order );
242
+ if ( empty( $payment_intent ) ) {
243
+ $charge = $this->gateway->charges->mode( wc_stripe_order_mode( $order ) )->retrieve( $order->get_transaction_id() );
244
+ $payment_intent = $charge->payment_intent;
245
+ $order->update_meta_data( WC_Stripe_Constants::PAYMENT_INTENT_ID, $payment_intent );
246
+ $order->save();
247
+ }
248
+
249
+ return $this->gateway->paymentIntents->mode( wc_stripe_order_mode( $order ) )->capture(
250
+ $payment_intent,
251
+ array(
252
+ 'amount_to_capture' => wc_stripe_add_number_precision(
253
+ $amount,
254
+ $order->get_currency()
255
+ ),
256
+ )
257
+ );
258
+ }
259
+
260
+ /**
261
+ *
262
+ * {@inheritDoc}
263
+ *
264
+ * @see WC_Stripe_Payment::void_charge()
265
+ */
266
+ public function void_charge( $order ) {
267
+ // fetch the intent and check its status
268
+ $payment_intent = $this->gateway->paymentIntents->mode( wc_stripe_order_mode( $order ) )->retrieve( $order->get_meta( WC_Stripe_Constants::PAYMENT_INTENT_ID ) );
269
+ if ( is_wp_error( $payment_intent ) ) {
270
+ return $payment_intent;
271
+ }
272
+ $statuses = array( 'requires_payment_method', 'requires_capture', 'requires_confirmation', 'requires_action' );
273
+ if ( 'canceled' !== $payment_intent->status ) {
274
+ if ( in_array( $payment_intent->status, $statuses ) ) {
275
+ return $this->gateway->paymentIntents->mode( wc_stripe_order_mode( $order ) )->cancel( $payment_intent->id );
276
+ } elseif ( 'succeeded' === $payment_intent->status ) {
277
+ return $this->process_refund( $order, $order->get_total() );
278
+ }
279
+ }
280
+ }
281
+
282
+ /**
283
+ *
284
+ * {@inheritDoc}
285
+ *
286
+ * @see WC_Stripe_Payment::get_payment_method_from_charge()
287
+ */
288
+ public function get_payment_method_from_charge( $charge ) {
289
+ return $charge->payment_method;
290
+ }
291
+
292
+ /**
293
+ *
294
+ * {@inheritDoc}
295
+ *
296
+ * @see WC_Stripe_Payment::add_order_payment_method()
297
+ */
298
+ public function add_order_payment_method( &$args, $order ) {
299
+ $args['payment_method'] = $this->payment_method->get_payment_method_from_request();
300
+ if ( empty( $args['payment_method'] ) ) {
301
+ unset( $args['payment_method'] );
302
+ }
303
+ }
304
+
305
+ /**
306
+ *
307
+ * @param WC_Order $order
308
+ */
309
+ public function can_use_payment_intent( $order ) {
310
+ $intent = $order->get_meta( WC_Stripe_Constants::PAYMENT_INTENT );
311
+
312
+ if ( $intent ) {
313
+ if ( $intent['confirmation_method'] != $this->payment_method->get_confirmation_method( $order ) ) {
314
+ return false;
315
+ }
316
+
317
+ // compare the active environment to the order's environment
318
+ if ( wc_stripe_order_mode( $order ) != wc_stripe_mode() ) {
319
+ return false;
320
+ }
321
+
322
+ return $intent;
323
+ }
324
+
325
+ return false;
326
+ }
327
+
328
+ /**
329
+ *
330
+ * {@inheritDoc}
331
+ *
332
+ * @see WC_Stripe_Payment::can_void_charge()
333
+ */
334
+ public function can_void_order( $order ) {
335
+ return $order->get_meta( WC_Stripe_Constants::PAYMENT_INTENT_ID );
336
+ }
337
+ }
includes/class-wc-stripe-product-gateway-option.php CHANGED
@@ -1,102 +1,109 @@
1
- <?php
2
- /**
3
- * @since 3.1.2
4
- * @package Stripe/Classes
5
- * @author PaymentPlugins
6
- *
7
- */
8
- class WC_Stripe_Product_Gateway_Option {
9
-
10
- /**
11
- *
12
- * @var string
13
- */
14
- private $id;
15
-
16
- /**
17
- *
18
- * @var array
19
- */
20
- private $settings = [];
21
-
22
- /**
23
- *
24
- * @var WC_Product
25
- */
26
- private $product;
27
-
28
- /**
29
- *
30
- * @var WC_Payment_Gateway_Stripe
31
- */
32
- private $payment_method;
33
-
34
- /**
35
- *
36
- * @param int|WC_Product $product
37
- * @param WC_Payment_Gateway_Stripe $payment_method
38
- */
39
- public function __construct($product, $payment_method) {
40
- if (! is_object ( $product )) {
41
- $this->product = wc_get_product ( $product );
42
- } else {
43
- $this->product = $product;
44
- }
45
- $this->payment_method = $payment_method;
46
-
47
- $this->init_settings ();
48
- }
49
-
50
- /**
51
- * Return the ID of this product option.
52
- */
53
- public function get_id() {
54
- return '_' . $this->payment_method->id . '_options';
55
- }
56
-
57
- /**
58
- * Save the settings
59
- */
60
- public function save() {
61
- $this->product->update_meta_data ( $this->get_id (), $this->settings );
62
- $this->product->save ();
63
- }
64
-
65
- /**
66
- * Initialzie the settings.
67
- */
68
- public function init_settings() {
69
- if (! $this->settings) {
70
- $this->settings = $this->product->get_meta ( $this->get_id () );
71
- $this->settings = is_array ( $this->settings ) ? $this->settings : [];
72
- $this->settings = wp_parse_args ( $this->settings, $this->get_default_values () );
73
- }
74
- }
75
-
76
- public function get_default_values() {
77
- return [
78
- 'enabled' => $this->payment_method->product_checkout_enabled (),
79
- 'charge_type' => $this->payment_method->get_option ( 'charge_type' )
80
- ];
81
- }
82
-
83
- /**
84
- *
85
- * @param string $key
86
- * @param mixed $default
87
- */
88
- public function get_option($key, $default = null) {
89
- if (! isset ( $this->settings[ $key ] ) && null != $default) {
90
- $this->settings[ $key ] = $default;
91
- }
92
- return $this->settings[ $key ];
93
- }
94
-
95
- public function set_option($key, $value) {
96
- $this->settings[ $key ] = $value;
97
- }
98
-
99
- public function enabled() {
100
- return $this->get_option ( 'enabled', false );
101
- }
102
- }
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * @since 3.1.2
6
+ * @package Stripe/Classes
7
+ * @author PaymentPlugins
8
+ *
9
+ */
10
+ class WC_Stripe_Product_Gateway_Option {
11
+
12
+ /**
13
+ *
14
+ * @var string
15
+ */
16
+ private $id;
17
+
18
+ /**
19
+ *
20
+ * @var array
21
+ */
22
+ private $settings = array();
23
+
24
+ /**
25
+ *
26
+ * @var WC_Product
27
+ */
28
+ private $product;
29
+
30
+ /**
31
+ *
32
+ * @var WC_Payment_Gateway_Stripe
33
+ */
34
+ private $payment_method;
35
+
36
+ /**
37
+ *
38
+ * @param int|WC_Product $product
39
+ * @param WC_Payment_Gateway_Stripe $payment_method
40
+ */
41
+ public function __construct( $product, $payment_method ) {
42
+ if ( ! is_object( $product ) ) {
43
+ $this->product = wc_get_product( $product );
44
+ } else {
45
+ $this->product = $product;
46
+ }
47
+ $this->payment_method = $payment_method;
48
+
49
+ $this->init_settings();
50
+ }
51
+
52
+ /**
53
+ * Return the ID of this product option.
54
+ */
55
+ public function get_id() {
56
+ return '_' . $this->payment_method->id . '_options';
57
+ }
58
+
59
+ /**
60
+ * Save the settings
61
+ */
62
+ public function save() {
63
+ $this->product->update_meta_data( $this->get_id(), $this->settings );
64
+ $this->product->save();
65
+ }
66
+
67
+ /**
68
+ * Initialzie the settings.
69
+ */
70
+ public function init_settings() {
71
+ if ( ! $this->settings ) {
72
+ $this->settings = $this->product->get_meta( $this->get_id() );
73
+ $this->settings = is_array( $this->settings ) ? $this->settings : array();
74
+ $this->settings = wp_parse_args( $this->settings, $this->get_default_values() );
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Return default options build from the payment gateway's options.
80
+ * @return array
81
+ */
82
+ public function get_default_values() {
83
+ return array(
84
+ 'enabled' => $this->payment_method->product_checkout_enabled(),
85
+ 'charge_type' => $this->payment_method->get_option( 'charge_type' ),
86
+ );
87
+ }
88
+
89
+ /**
90
+ *
91
+ * @param string $key
92
+ * @param mixed $default
93
+ */
94
+ public function get_option( $key, $default = null ) {
95
+ if ( ! isset( $this->settings[ $key ] ) && null != $default ) {
96
+ $this->settings[ $key ] = $default;
97
+ }
98
+
99
+ return $this->settings[ $key ];
100
+ }
101
+
102
+ public function set_option( $key, $value ) {
103
+ $this->settings[ $key ] = $value;
104
+ }
105
+
106
+ public function enabled() {
107
+ return $this->get_option( 'enabled', false );
108
+ }
109
+ }
includes/class-wc-stripe-product-option.php CHANGED
@@ -1,102 +1,103 @@
1
- <?php
2
- /**
3
- * @since 3.1.2
4
- * @package Stripe/Classes
5
- * @author PaymentPlugins
6
- *
7
- */
8
- class WC_Stripe_Product_Option {
9
-
10
- /**
11
- *
12
- * @var string
13
- */
14
- private $id;
15
-
16
- /**
17
- *
18
- * @var array
19
- */
20
- private $settings = [];
21
-
22
- /**
23
- *
24
- * @var WC_Product
25
- */
26
- private $product;
27
-
28
- /**
29
- *
30
- * @var WC_Payment_Gateway_Stripe
31
- */
32
- private $payment_method;
33
-
34
- /**
35
- *
36
- * @param int|WC_Product $product
37
- * @param WC_Payment_Gateway_Stripe $payment_method
38
- */
39
- public function __construct($product, $payment_method) {
40
- if (! is_object ( $product )) {
41
- $this->product = wc_get_product ( $product );
42
- } else {
43
- $this->product = $product;
44
- }
45
- $this->payment_method = $payment_method;
46
-
47
- $this->init_settings ();
48
- }
49
-
50
- /**
51
- * Return the ID of this product option.
52
- */
53
- public function get_id() {
54
- return '_' . $this->payment_method->id . '_options';
55
- }
56
-
57
- /**
58
- * Save the settings
59
- */
60
- public function save() {
61
- $this->product->update_meta_data ( $this->get_id (), $this->settings );
62
- $this->product->save ();
63
- }
64
-
65
- /**
66
- * Initialzie the settings.
67
- */
68
- public function init_settings() {
69
- if (! $this->settings) {
70
- $this->settings = $this->product->get_meta ( $this->get_id () );
71
- $this->settings = is_array ( $this->settings ) ? $this->settings : [];
72
- $this->settings = wp_parse_args ( $this->settings, $this->get_default_values () );
73
- }
74
- }
75
-
76
- public function get_default_values() {
77
- return [
78
- 'enabled' => $this->payment_method->product_checkout_enabled (),
79
- 'charge_type' => $this->payment_method->get_option ( 'charge_type' )
80
- ];
81
- }
82
-
83
- /**
84
- *
85
- * @param string $key
86
- * @param mixed $default
87
- */
88
- public function get_option($key, $default = null) {
89
- if (! isset ( $this->settings[ $key ] ) && null != $default) {
90
- $this->settings[ $key ] = $default;
91
- }
92
- return $this->settings[ $key ];
93
- }
94
-
95
- public function set_option($key, $value) {
96
- $this->settings[ $key ] = $value;
97
- }
98
-
99
- public function enabled() {
100
- return $this->get_option ( 'enabled', false );
101
- }
102
- }
 
1
+ <?php
2
+
3
+ /**
4
+ * @since 3.1.2
5
+ * @package Stripe/Classes
6
+ * @author PaymentPlugins
7
+ *
8
+ */
9
+ class WC_Stripe_Product_Option {
10
+
11
+ /**
12
+ *
13
+ * @var string
14
+ */
15
+ private $id;
16
+
17
+ /**
18
+ *
19
+ * @var array
20
+ */
21
+ private $settings = array();
22
+
23
+ /**
24
+ *
25
+ * @var WC_Product
26
+ */
27
+ private $product;
28
+
29
+ /**
30
+ *
31
+ * @var WC_Payment_Gateway_Stripe
32
+ */
33
+ private $payment_method;
34
+
35
+ /**
36
+ *
37
+ * @param int|WC_Product $product
38
+ * @param WC_Payment_Gateway_Stripe $payment_method
39
+ */
40
+ public function __construct( $product, $payment_method ) {
41
+ if ( ! is_object( $product ) ) {
42
+ $this->product = wc_get_product( $product );
43
+ } else {
44
+ $this->product = $product;
45
+ }
46
+ $this->payment_method = $payment_method;
47
+
48
+ $this->init_settings();
49
+ }
50
+
51
+ /**
52
+ * Return the ID of this product option.
53
+ */
54
+ public function get_id() {
55
+ return '_' . $this->payment_method->id . '_options';
56
+ }
57
+
58
+ /**
59
+ * Save the settings
60
+ */
61
+ public function save() {
62
+ $this->product->update_meta_data( $this->get_id(), $this->settings );
63
+ $this->product->save();
64
+ }
65
+
66
+ /**
67
+ * Initialzie the settings.
68
+ */
69
+ public function init_settings() {
70
+ if ( ! $this->settings ) {
71
+ $this->settings = $this->product->get_meta( $this->get_id() );
72
+ $this->settings = is_array( $this->settings ) ? $this->settings : array();
73
+ $this->settings = wp_parse_args( $this->settings, $this->get_default_values() );
74
+ }
75
+ }
76
+
77
+ public function get_default_values() {
78
+ return array(
79
+ 'enabled' => $this->payment_method->product_checkout_enabled(),
80
+ 'charge_type' => $this->payment_method->get_option( 'charge_type' ),
81
+ );
82
+ }
83
+
84
+ /**
85
+ *
86
+ * @param string $key
87
+ * @param mixed $default
88
+ */
89
+ public function get_option( $key, $default = null ) {
90
+ if ( ! isset( $this->settings[ $key ] ) && null != $default ) {
91
+ $this->settings[ $key ] = $default;
92
+ }
93
+ return $this->settings[ $key ];
94
+ }
95
+
96
+ public function set_option( $key, $value ) {
97
+ $this->settings[ $key ] = $value;
98
+ }
99
+
100
+ public function enabled() {
101
+ return $this->get_option( 'enabled', false );
102
+ }
103
+ }
includes/class-wc-stripe-redirect-handler.php CHANGED
@@ -1,92 +1,91 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @package Stripe/Classes
8
- *
9
- */
10
- class WC_Stripe_Redirect_Handler {
11
-
12
- public static function init() {
13
- add_action ( 'template_redirect', [ __CLASS__,
14
- 'local_payment_redirect'
15
- ] );
16
- add_action ( 'get_header', [ __CLASS__,
17
- 'maybe_restore_cart'
18
- ], 100 );
19
- }
20
-
21
- /**
22
- * Check if this request is for a local payment redirect.
23
- */
24
- public static function local_payment_redirect() {
25
- if (isset ( $_GET[ 'wc-stripe-local-gateway' ], $_GET[ '_payment_nonce' ] ) && wp_verify_nonce ( $_GET[ '_payment_nonce' ], 'local-payment' )) {
26
- self::process_redirect ();
27
- }
28
- }
29
-
30
- /**
31
- */
32
- public static function process_redirect() {
33
- if (isset ( $_GET[ 'source' ] )) {
34
- $result = WC_Stripe_Gateway::load ()->fetch_payment_source ( wc_clean ( $_GET[ 'source' ] ) );
35
- } else {
36
- $result = WC_Stripe_Gateway::load ()->fetch_payment_intent ( wc_clean ( $_GET[ 'payment_intent' ] ) );
37
- }
38
- if (is_wp_error ( $result )) {
39
- wc_add_notice ( sprintf ( __ ( 'Error retrieving payment source. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message () ), 'error' );
40
- return;
41
- } else {
42
- define ( WC_Stripe_Constants::REDIRECT_HANDLER, true );
43
- $order_id = $result->metadata[ 'order_id' ];
44
- $order = wc_get_order ( wc_stripe_filter_order_id ( $order_id, $result ) );
45
-
46
- /**
47
- *
48
- * @var WC_Payment_Gateway_Stripe_Local_Payment $payment_method
49
- */
50
- $payment_method = WC ()->payment_gateways ()->payment_gateways ()[ $order->get_payment_method () ];
51
- $redirect = $order->get_checkout_order_received_url ();
52
-
53
- if ('failed' === $result->status || 'requires_payment_method' === $result->status) {
54
- wc_add_notice ( __ ( 'Payment authorization failed. Please select another payment method.', 'woo-stripe-payment' ), 'error' );
55
- $order->update_status ( 'failed', __ ( 'Payment authorization failed.', 'woo-stripe-payment' ) );
56
- if ($result instanceof \Stripe\PaymentIntent) {
57
- $order->update_meta_data ( WC_Stripe_Constants::PAYMENT_INTENT, $result->jsonSerialize () );
58
- }
59
- return;
60
- } elseif ('chargeable' === $result->status) {
61
- if (! $payment_method->has_order_lock ( $order ) && ! $order->get_transaction_id ()) {
62
- $payment_method->set_order_lock ( $order );
63
- $payment_method->set_new_source_token ( $result->id );
64
- wc_stripe_log_info ( 'processing from redirect handler.' );
65
- $result = $payment_method->process_payment ( $order_id );
66
- // we don't release the order lock so there aren't conflicts with the source.chargeable webhook
67
- if ($result[ 'result' ] === 'success') {
68
- $redirect = $result[ 'redirect' ];
69
- }
70
- }
71
- } elseif ('succeeded' == $result->status) {
72
- if (! $payment_method->has_order_lock ( $order )) {
73
- $payment_method->set_order_lock ( $order );
74
- $result = $payment_method->process_payment ( $order_id );
75
- if ($result[ 'result' ] === 'success') {
76
- $redirect = $result[ 'redirect' ];
77
- }
78
- }
79
- }
80
- wp_safe_redirect ( $redirect );
81
- exit ();
82
- }
83
- }
84
-
85
- public static function maybe_restore_cart() {
86
- global $wp;
87
- if (isset ( $wp->query_vars[ 'order-received' ] ) && isset ( $_GET[ 'wc_stripe_product_checkout' ] )) {
88
- add_action ( 'woocommerce_cart_emptied', 'wc_stripe_restore_cart_after_product_checkout' );
89
- }
90
- }
91
- }
92
- WC_Stripe_Redirect_Handler::init ();
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @package Stripe/Classes
8
+ *
9
+ */
10
+ class WC_Stripe_Redirect_Handler {
11
+
12
+ public static function init() {
13
+ add_action( 'template_redirect', array( __CLASS__, 'local_payment_redirect' ) );
14
+ add_action( 'get_header', array( __CLASS__, 'maybe_restore_cart' ), 100 );
15
+ }
16
+
17
+ /**
18
+ * Check if this request is for a local payment redirect.
19
+ */
20
+ public static function local_payment_redirect() {
21
+ if ( isset( $_GET['wc-stripe-local-gateway'], $_GET['_payment_nonce'] ) && wp_verify_nonce( $_GET['_payment_nonce'], 'local-payment' ) ) {
22
+ self::process_redirect();
23
+ }
24
+ }
25
+
26
+ /**
27
+ */
28
+ public static function process_redirect() {
29
+ if ( isset( $_GET['source'] ) ) {
30
+ $result = WC_Stripe_Gateway::load()->sources->retrieve( wc_clean( $_GET['source'] ) );
31
+ } else {
32
+ $result = WC_Stripe_Gateway::load()->paymentIntents->retrieve( wc_clean( $_GET['payment_intent'] ) );
33
+ }
34
+ if ( is_wp_error( $result ) ) {
35
+ wc_add_notice( sprintf( __( 'Error retrieving payment source. Reason: %s', 'woo-stripe-payment' ), $result->get_error_message() ), 'error' );
36
+
37
+ return;
38
+ } else {
39
+ define( WC_Stripe_Constants::REDIRECT_HANDLER, true );
40
+ $order_id = $result->metadata['order_id'];
41
+ $order = wc_get_order( wc_stripe_filter_order_id( $order_id, $result ) );
42
+
43
+ /**
44
+ *
45
+ * @var WC_Payment_Gateway_Stripe_Local_Payment $payment_method
46
+ */
47
+ $payment_method = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
48
+ $redirect = $order->get_checkout_order_received_url();
49
+
50
+ if ( 'failed' === $result->status || 'requires_payment_method' === $result->status ) {
51
+ wc_add_notice( __( 'Payment authorization failed. Please select another payment method.', 'woo-stripe-payment' ), 'error' );
52
+ $order->update_status( 'failed', __( 'Payment authorization failed.', 'woo-stripe-payment' ) );
53
+ if ( $result instanceof \Stripe\PaymentIntent ) {
54
+ $order->update_meta_data( WC_Stripe_Constants::PAYMENT_INTENT, $result->jsonSerialize() );
55
+ }
56
+
57
+ return;
58
+ } elseif ( 'chargeable' === $result->status ) {
59
+ if ( ! $payment_method->has_order_lock( $order ) && ! $order->get_transaction_id() ) {
60
+ $payment_method->set_order_lock( $order );
61
+ $payment_method->set_new_source_token( $result->id );
62
+ wc_stripe_log_info( 'processing from redirect handler.' );
63
+ $result = $payment_method->process_payment( $order_id );
64
+ // we don't release the order lock so there aren't conflicts with the source.chargeable webhook
65
+ if ( $result['result'] === 'success' ) {
66
+ $redirect = $result['redirect'];
67
+ }
68
+ }
69
+ } elseif ( 'succeeded' == $result->status ) {
70
+ if ( ! $payment_method->has_order_lock( $order ) ) {
71
+ $payment_method->set_order_lock( $order );
72
+ $result = $payment_method->process_payment( $order_id );
73
+ if ( $result['result'] === 'success' ) {
74
+ $redirect = $result['redirect'];
75
+ }
76
+ }
77
+ }
78
+ wp_safe_redirect( $redirect );
79
+ exit();
80
+ }
81
+ }
82
+
83
+ public static function maybe_restore_cart() {
84
+ global $wp;
85
+ if ( isset( $wp->query_vars['order-received'] ) && isset( $_GET['wc_stripe_product_checkout'] ) ) {
86
+ add_action( 'woocommerce_cart_emptied', 'wc_stripe_restore_cart_after_product_checkout' );
87
+ }
88
+ }
89
+ }
90
+
91
+ WC_Stripe_Redirect_Handler::init();
 
includes/class-wc-stripe-rest-api.php CHANGED
@@ -1,119 +1,113 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @package Stripe/Classes
8
- * @property WC_Stripe_Rest_Controller $order_actions
9
- * @property WC_Stripe_Rest_Controller $cart
10
- * @property WC_Stripe_Rest_Controller $checkout
11
- * @property WC_Stripe_Rest_Controller $payment_intent
12
- * @property WC_Stripe_Rest_Controller $googlepay
13
- * @property WC_Stripe_Rest_Controller $settings
14
- * @property WC_Stripe_Rest_Controller $webhook
15
- * @property WC_Stripe_Rest_Controller $product_data
16
- */
17
- class WC_Stripe_Rest_API {
18
-
19
- /**
20
- *
21
- * @var array
22
- */
23
- private $controllers = array();
24
-
25
- public function __construct() {
26
- $this->include_classes ();
27
- add_action ( 'rest_api_init', array( $this,
28
- 'register_routes'
29
- ) );
30
- }
31
-
32
- public static function init() {
33
- add_filter ( 'woocommerce_is_rest_api_request', array(
34
- __CLASS__, 'is_rest_api_request'
35
- ) );
36
- }
37
-
38
- /**
39
- *
40
- * @param WC_Stripe_Rest_Controller $key
41
- */
42
- public function __get($key) {
43
- $controller = isset ( $this->controllers[ $key ] ) ? $this->controllers[ $key ] : '';
44
- if (empty ( $controller )) {
45
- wc_doing_it_wrong ( __FUNCTION__, sprintf ( __ ( '%1$s is an invalid controller name.', 'woo-stripe-payment' ), $key ), wc_stripe ()->version );
46
- }
47
- return $controller;
48
- }
49
-
50
- public function __set($key, $value) {
51
- $this->controllers[ $key ] = $value;
52
- }
53
-
54
- private function include_classes() {
55
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-stripe-rest-controller.php';
56
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-order-actions.php';
57
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-payment-intent.php';
58
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-cart.php';
59
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-checkout.php';
60
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-googlepay.php';
61
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-payment-method.php';
62
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-gateway-settings.php';
63
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-webhook.php';
64
- include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-product-data.php';
65
-
66
- foreach ( $this->get_controllers () as $key => $class_name ) {
67
- if (class_exists ( $class_name )) {
68
- $this->{$key} = new $class_name ();
69
- }
70
- }
71
- }
72
-
73
- public function register_routes() {
74
- WC ()->payment_gateways ();
75
- foreach ( $this->controllers as $key => $controller ) {
76
- if (is_callable ( array( $controller,
77
- 'register_routes'
78
- ) )) {
79
- $controller->{ 'register_routes' } ();
80
- }
81
- }
82
- }
83
-
84
- public function get_controllers() {
85
- $controllers = array(
86
- 'order_actions' => 'WC_Stripe_Controller_Order_Actions',
87
- 'checkout' => 'WC_Stripe_Controller_Checkout',
88
- 'cart' => 'WC_Stripe_Controller_Cart',
89
- 'payment_intent' => 'WC_Stripe_Controller_Payment_Intent',
90
- 'googlepay' => 'WC_Stripe_Controller_GooglePay',
91
- 'payment_method' => 'WC_Stripe_Controller_Payment_Method',
92
- 'settings' => 'WC_Stripe_Controller_Gateway_Settings',
93
- 'webhook' => 'WC_Stripe_Controller_Webhook',
94
- 'product_data' => 'WC_Stripe_Controller_Product_Data'
95
- );
96
- return apply_filters ( 'wc_stripe_api_controllers', $controllers );
97
- }
98
-
99
- public function rest_url() {
100
- return wc_stripe ()->rest_url ();
101
- }
102
-
103
- public function rest_uri() {
104
- return wc_stripe ()->rest_uri ();
105
- }
106
-
107
- /**
108
- * Added after WC 3.6 so WC_STRIPE_PLUGIN_FILE_PATH, and Session are loaded for Stripe rest requests.
109
- *
110
- * @param bool $bool
111
- */
112
- public static function is_rest_api_request($bool) {
113
- if (! empty ( $_SERVER[ 'REQUEST_URI' ] ) && strpos ( $_SERVER[ 'REQUEST_URI' ], wc_stripe ()->rest_uri () ) !== false) {
114
- $bool = false;
115
- }
116
- return $bool;
117
- }
118
- }
119
- WC_Stripe_Rest_API::init ();
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @package Stripe/Classes
8
+ * @property WC_Stripe_Rest_Controller $order_actions
9
+ * @property WC_Stripe_Rest_Controller $cart
10
+ * @property WC_Stripe_Rest_Controller $checkout
11
+ * @property WC_Stripe_Rest_Controller $payment_intent
12
+ * @property WC_Stripe_Rest_Controller $googlepay
13
+ * @property WC_Stripe_Rest_Controller $settings
14
+ * @property WC_Stripe_Rest_Controller $webhook
15
+ * @property WC_Stripe_Rest_Controller $product_data
16
+ */
17
+ class WC_Stripe_Rest_API {
18
+
19
+ /**
20
+ *
21
+ * @var array
22
+ */
23
+ private $controllers = array();
24
+
25
+ public function __construct() {
26
+ $this->include_classes();
27
+ add_action( 'rest_api_init', array( $this, 'register_routes' ) );
28
+ }
29
+
30
+ public static function init() {
31
+ add_filter( 'woocommerce_is_rest_api_request', array( __CLASS__, 'is_rest_api_request' ) );
32
+ }
33
+
34
+ /**
35
+ *
36
+ * @param WC_Stripe_Rest_Controller $key
37
+ */
38
+ public function __get( $key ) {
39
+ $controller = isset( $this->controllers[ $key ] ) ? $this->controllers[ $key ] : '';
40
+ if ( empty( $controller ) ) {
41
+ wc_doing_it_wrong( __FUNCTION__, sprintf( __( '%1$s is an invalid controller name.', 'woo-stripe-payment' ), $key ), wc_stripe()->version );
42
+ }
43
+ return $controller;
44
+ }
45
+
46
+ public function __set( $key, $value ) {
47
+ $this->controllers[ $key ] = $value;
48
+ }
49
+
50
+ private function include_classes() {
51
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/abstract/abstract-wc-stripe-rest-controller.php';
52
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-order-actions.php';
53
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-payment-intent.php';
54
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-cart.php';
55
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-checkout.php';
56
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-googlepay.php';
57
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-payment-method.php';
58
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-gateway-settings.php';
59
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-webhook.php';
60
+ include_once WC_STRIPE_PLUGIN_FILE_PATH . 'includes/controllers/class-wc-stripe-controller-product-data.php';
61
+
62
+ foreach ( $this->get_controllers() as $key => $class_name ) {
63
+ if ( class_exists( $class_name ) ) {
64
+ $this->{$key} = new $class_name();
65
+ }
66
+ }
67
+ }
68
+
69
+ public function register_routes() {
70
+ WC()->payment_gateways();
71
+ foreach ( $this->controllers as $key => $controller ) {
72
+ if ( is_callable( array( $controller, 'register_routes' ) ) ) {
73
+ $controller->{ 'register_routes' }();
74
+ }
75
+ }
76
+ }
77
+
78
+ public function get_controllers() {
79
+ $controllers = array(
80
+ 'order_actions' => 'WC_Stripe_Controller_Order_Actions',
81
+ 'checkout' => 'WC_Stripe_Controller_Checkout',
82
+ 'cart' => 'WC_Stripe_Controller_Cart',
83
+ 'payment_intent' => 'WC_Stripe_Controller_Payment_Intent',
84
+ 'googlepay' => 'WC_Stripe_Controller_GooglePay',
85
+ 'payment_method' => 'WC_Stripe_Controller_Payment_Method',
86
+ 'settings' => 'WC_Stripe_Controller_Gateway_Settings',
87
+ 'webhook' => 'WC_Stripe_Controller_Webhook',
88
+ 'product_data' => 'WC_Stripe_Controller_Product_Data',
89
+ );
90
+ return apply_filters( 'wc_stripe_api_controllers', $controllers );
91
+ }
92
+
93
+ public function rest_url() {
94
+ return wc_stripe()->rest_url();
95
+ }
96
+
97
+ public function rest_uri() {
98
+ return wc_stripe()->rest_uri();
99
+ }
100
+
101
+ /**
102
+ * Added after WC 3.6 so WC_STRIPE_PLUGIN_FILE_PATH, and Session are loaded for Stripe rest requests.
103
+ *
104
+ * @param bool $bool
105
+ */
106
+ public static function is_rest_api_request( $bool ) {
107
+ if ( ! empty( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], wc_stripe()->rest_uri() ) !== false ) {
108
+ $bool = false;
109
+ }
110
+ return $bool;
111
+ }
112
+ }
113
+ WC_Stripe_Rest_API::init();
 
 
 
 
 
 
includes/class-wc-stripe-update.php CHANGED
@@ -1,62 +1,67 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @package Stripe/Classes
8
- *
9
- */
10
- class WC_Stripe_Update {
11
-
12
- private static $updates = [
13
- '3.0.7' => 'update-3.0.7.php',
14
- '3.1.0' => 'update-3.1.0.php',
15
- '3.1.1' => 'update-3.1.1.php'
16
- ];
17
-
18
- public static function init() {
19
- add_action ( 'init', [ __CLASS__, 'update'
20
- ] );
21
- }
22
-
23
- /**
24
- * Performs an update on the plugin if required.
25
- */
26
- public static function update() {
27
- // if option is not set, make the default version 3.0.6.
28
- $current_version = get_option ( 'stripe_wc_version', '3.0.6' );
29
-
30
- // if database version is less than plugin version, an update might be required.
31
- if (version_compare ( $current_version, wc_stripe ()->version (), '<' )) {
32
- foreach ( self::$updates as $version => $path ) {
33
- /*
34
- * If the current version is less than the version in the loop, then perform upgrade.
35
- */
36
- if (version_compare ( $current_version, $version, '<' )) {
37
- $file = wc_stripe ()->plugin_path () . 'includes/updates/' . $path;
38
- if (file_exists ( $file )) {
39
- include $file;
40
- }
41
- $current_version = $version;
42
- update_option ( 'stripe_wc_version', $current_version );
43
- add_action ( 'admin_notices', function () use ($current_version) {
44
- $message = sprintf ( __ ( 'Thank you for updating Stripe for WooCommerce to version %1$s.', 'woo-stripe-payment' ), $current_version );
45
- if (( $text = self::get_messages ( $current_version ) )) {
46
- $message .= ' ' . $text;
47
- }
48
- printf ( '<div class="notice notice-success is-dismissible"><p>%1$s</p></div>', $message );
49
- } );
50
- }
51
- }
52
- // save latest version.
53
- update_option ( 'stripe_wc_version', wc_stripe ()->version () );
54
- }
55
- }
56
-
57
- public static function get_messages($version) {
58
- $messages = [];
59
- return isset ( $messages[ $version ] ) ? $messages[ $version ] : false;
60
- }
61
- }
62
- WC_Stripe_Update::init ();
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @package Stripe/Classes
8
+ *
9
+ */
10
+ class WC_Stripe_Update {
11
+
12
+ private static $updates = array(
13
+ '3.0.7' => 'update-3.0.7.php',
14
+ '3.1.0' => 'update-3.1.0.php',
15
+ '3.1.1' => 'update-3.1.1.php',
16
+ '3.1.6' => 'update-3.1.6.php'
17
+ );
18
+
19
+ public static function init() {
20
+ add_action( 'init', array( __CLASS__, 'update' ) );
21
+ }
22
+
23
+ /**
24
+ * Performs an update on the plugin if required.
25
+ */
26
+ public static function update() {
27
+ // if option is not set, make the default version 3.0.6.
28
+ $current_version = get_option( 'stripe_wc_version', '3.0.6' );
29
+
30
+ // if database version is less than plugin version, an update might be required.
31
+ if ( version_compare( $current_version, wc_stripe()->version(), '<' ) ) {
32
+ foreach ( self::$updates as $version => $path ) {
33
+ /*
34
+ * If the current version is less than the version in the loop, then perform upgrade.
35
+ */
36
+ if ( version_compare( $current_version, $version, '<' ) ) {
37
+ $file = wc_stripe()->plugin_path() . 'includes/updates/' . $path;
38
+ if ( file_exists( $file ) ) {
39
+ include $file;
40
+ }
41
+ $current_version = $version;
42
+ update_option( 'stripe_wc_version', $current_version );
43
+ add_action(
44
+ 'admin_notices',
45
+ function () use ( $current_version ) {
46
+ $message = sprintf( __( 'Thank you for updating Stripe for WooCommerce to version %1$s.', 'woo-stripe-payment' ), $current_version );
47
+ if ( ( $text = self::get_messages( $current_version ) ) ) {
48
+ $message .= ' ' . $text;
49
+ }
50
+ printf( '<div class="notice notice-success is-dismissible"><p>%1$s</p></div>', $message );
51
+ }
52
+ );
53
+ }
54
+ }
55
+ // save latest version.
56
+ update_option( 'stripe_wc_version', wc_stripe()->version() );
57
+ }
58
+ }
59
+
60
+ public static function get_messages( $version ) {
61
+ $messages = array();
62
+
63
+ return isset( $messages[ $version ] ) ? $messages[ $version ] : false;
64
+ }
65
+ }
66
+
67
+ WC_Stripe_Update::init();
includes/controllers/class-wc-stripe-controller-cart.php CHANGED
@@ -1,335 +1,358 @@
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
-
15
- protected $namespace = 'cart';
16
-
17
- public function register_routes() {
18
- register_rest_route ( $this->rest_uri (), 'shipping-method', [
19
- 'methods' => WP_REST_Server::CREATABLE,
20
- 'callback' => [ $this,
21
- 'update_shipping_method'
22
- ],
23
- 'args' => [
24
- 'shipping_methods' => [
25
- 'required' => true
26
- ],
27
- 'payment_method' => [
28
- 'required' => true
29
- ]
30
- ]
31
- ] );
32
- register_rest_route ( $this->rest_uri (), 'shipping-address', [
33
- 'methods' => WP_REST_Server::CREATABLE,
34
- 'callback' => [ $this,
35
- 'update_shipping_address'
36
- ],
37
- 'args' => [
38
- 'address' => [
39
- 'required' => true
40
- ],
41
- 'payment_method' => [
42
- 'required' => true
43
- ]
44
- ]
45
- ] );
46
- register_rest_route ( $this->rest_uri (), 'add-to-cart', [
47
- 'methods' => WP_REST_Server::CREATABLE,
48
- 'callback' => [ $this, 'add_to_cart'
49
- ],
50
- 'args' => [
51
- 'product_id' => [
52
- 'required' => true
53
- ],
54
- 'qty' => [ 'required' => true,
55
- 'validate_callback' => [
56
- $this,
57
- 'validate_quantity'
58
- ]
59
- ],
60
- 'payment_method' => [
61
- 'required' => true
62
- ]
63
- ]
64
- ] );
65
- /**
66
- *
67
- * @since 3.0.6
68
- */
69
- register_rest_route ( $this->rest_uri (), 'cart-calculation', [
70
- 'methods' => WP_REST_Server::CREATABLE,
71
- 'callback' => [ $this,
72
- 'cart_calculation'
73
- ],
74
- 'args' => [
75
- 'product_id' => [
76
- 'required' => true
77
- ],
78
- 'qty' => [ 'required' => true,
79
- 'validate_callback' => [
80
- $this,
81
- 'validate_quantity'
82
- ]
83
- ],
84
- 'payment_method' => [
85
- 'required' => true
86
- ]
87
- ]
88
- ] );
89
- }
90
-
91
- /**
92
- *
93
- * @param int $qty
94
- * @param WP_REST_Request $request
95
- */
96
- public function validate_quantity($qty, $request) {
97
- if ($qty == 0) {
98
- return $this->add_validation_error ( new WP_Error ( 'cart-error', __ ( 'Quantity must be greater than zero.', 'woo-stripe-payment' ) ) );
99
- }
100
- return true;
101
- }
102
-
103
- /**
104
- * Update the shipping method chosen by the customer.
105
- *
106
- * @param WP_REST_Request $request
107
- */
108
- public function update_shipping_method($request) {
109
- wc_maybe_define_constant ( 'WOOCOMMERCE_CART', true );
110
- $shipping_methods = $request->get_param ( 'shipping_methods' );
111
- $payment_method = $request->get_param ( 'payment_method' );
112
- /**
113
- *
114
- * @var WC_Payment_Gateway_Stripe $gateway
115
- */
116
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $payment_method ];
117
-
118
- wc_stripe_update_shipping_methods ( $shipping_methods );
119
-
120
- $this->add_ready_to_calc_shipping ();
121
-
122
- // if this request is coming from product page, stash cart and use product cart
123
- if ('product' == $request->get_param ( 'page_id' )) {
124
- wc_stripe_stash_cart ( WC ()->cart );
125
- } else {
126
- WC ()->cart->calculate_totals ();
127
- }
128
-
129
- $response = rest_ensure_response ( apply_filters ( 'wc_stripe_update_shipping_method_response', [
130
- 'data' => $gateway->get_update_shipping_method_response ( [
131
- 'newData' => [
132
- 'status' => 'success',
133
- 'total' => [
134
- 'amount' => wc_stripe_add_number_precision ( WC ()->cart->total ),
135
- 'label' => __ ( 'Total', 'woo-stripe-payment' ),
136
- 'pending' => false
137
- ],
138
- 'displayItems' => wc_stripe_get_display_items (),
139
- 'shippingOptions' => wc_stripe_get_shipping_options ()
140
- ],
141
- 'shipping_methods' => WC ()->session->get ( 'chosen_shipping_methods', [] )
142
- ] )
143
- ] ) );
144
- if ('product' == $request->get_param ( 'page_id' )) {
145
- wc_stripe_restore_cart ( WC ()->cart );
146
- }
147
- return $response;
148
- }
149
-
150
- /**
151
- *
152
- * @param WP_REST_Request $request
153
- */
154
- public function update_shipping_address($request) {
155
- wc_maybe_define_constant ( 'WOOCOMMERCE_CART', true );
156
- $address = $request->get_param ( 'address' );
157
- $payment_method = $request->get_param ( 'payment_method' );
158
- /**
159
- *
160
- * @var WC_Payment_Gateway_Stripe $gateway
161
- */
162
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $payment_method ];
163
- try {
164
- wc_stripe_update_customer_location ( $address );
165
-
166
- $this->add_ready_to_calc_shipping ();
167
-
168
- if ('product' == $request->get_param ( 'page_id' )) {
169
- wc_stripe_stash_cart ( WC ()->cart );
170
- } else {
171
- WC ()->cart->calculate_totals ();
172
- }
173
-
174
- if (! $this->has_shipping_methods ( WC ()->shipping ()->get_packages () )) {
175
- throw new Exception ( 'No valid shipping methods.' );
176
- }
177
-
178
- $response = rest_ensure_response ( apply_filters ( 'wc_stripe_update_shipping_method_response', [
179
- 'data' => $gateway->get_update_shipping_address_response ( [
180
- 'newData' => [
181
- 'status' => 'success',
182
- 'total' => [
183
- 'amount' => wc_stripe_add_number_precision ( WC ()->cart->total ),
184
- 'label' => __ ( 'Total', 'woo-stripe-payment' ),
185
- 'pending' => false
186
- ],
187
- 'displayItems' => wc_stripe_get_display_items (),
188
- 'shippingOptions' => wc_stripe_get_shipping_options ()
189
- ]
190
- ] )
191
- ] ) );
192
- } catch ( Exception $e ) {
193
- $response = new WP_Error ( 'address-error', $e->getMessage (), [
194
- 'status' => 200,
195
- 'newData' => [
196
- 'status' => 'invalid_shipping_address'
197
- ]
198
- ] );
199
- }
200
- if ('product' == $request->get_param ( 'page_id' )) {
201
- wc_stripe_restore_cart ( WC ()->cart );
202
- }
203
- return $response;
204
- }
205
-
206
- /**
207
- *
208
- * @param WP_REST_Request $request
209
- */
210
- public function add_to_cart($request) {
211
- // WC 3.0.0 requires WOOCOMMERCE_CART to be defined.
212
- wc_maybe_define_constant ( 'WOOCOMMERCE_CART', true );
213
- $payment_method = $request->get_param ( 'payment_method' );
214
- /**
215
- *
216
- * @var WC_Payment_Gateway_Stripe $gateway
217
- */
218
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $payment_method ];
219
-
220
- $product_id = $request->get_param ( 'product_id' );
221
- $qty = $request->get_param ( 'qty' );
222
- $variation_id = $request->get_param ( 'variation_id' );
223
-
224
- // stash cart so clean calculation can be performed.
225
- wc_stripe_stash_cart ( WC ()->cart, false );
226
-
227
- if (WC ()->cart->add_to_cart ( $product_id, $qty, $variation_id ) == false) {
228
- return new WP_Error ( 'cart-error', $this->get_error_messages (), [
229
- 'status' => 200
230
- ] );
231
- } else {
232
- // add to cart was successful. Send a new X-WP-Nonce since it will be different now that a WC session exists.
233
- rest_get_server ()->send_header ( 'X-WP-Nonce', wp_create_nonce ( 'wp_rest' ) );
234
- $response = rest_ensure_response ( apply_filters ( 'wc_stripe_add_to_cart_response', [
235
- 'data' => $gateway->add_to_cart_response ( [
236
- 'total' => WC ()->cart->total,
237
- 'subtotal' => WC ()->cart->subtotal,
238
- 'totalCents' => wc_stripe_add_number_precision ( WC ()->cart->total ),
239
- 'displayItems' => wc_stripe_get_display_items (),
240
- 'shippingOptions' => wc_stripe_get_shipping_options ()
241
- ] )
242
- ], $gateway, $request ) );
243
- // save the product cart so it can be used for shipping calculations etc.
244
- wc_stripe_stash_product_cart ( WC ()->cart );
245
- // put cart contents back to how they were before.
246
- wc_stripe_restore_cart ( WC ()->cart );
247
- return $response;
248
- }
249
- }
250
-
251
- /**
252
- * Performs a cart calculation
253
- *
254
- * @param WP_REST_Request $request
255
- */
256
- public function cart_calculation($request) {
257
- // WC 3.0.0 requires WOOCOMMERCE_CART to be defined.
258
- wc_maybe_define_constant ( 'WOOCOMMERCE_CART', true );
259
- $product_id = $request->get_param ( 'product_id' );
260
- $qty = $request->get_param ( 'qty' );
261
- $variation_id = $request->get_param ( 'variation_id' ) == null ? 0 : $request->get_param ( 'variation_id' );
262
-
263
- wc_stripe_stash_cart ( WC ()->cart, false );
264
-
265
- if (WC ()->cart->add_to_cart ( $product_id, $qty, $variation_id )) {
266
- $payment_method = $request->get_param ( 'payment_method' );
267
- /**
268
- *
269
- * @var WC_Payment_Gateway_Stripe $gateway
270
- */
271
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $payment_method ];
272
- $response = rest_ensure_response ( apply_filters ( 'wc_stripe_add_to_cart_response', [
273
- 'data' => $gateway->add_to_cart_response ( [
274
- 'total' => WC ()->cart->total,
275
- 'subtotal' => WC ()->cart->subtotal,
276
- 'totalCents' => wc_stripe_add_number_precision ( WC ()->cart->total ),
277
- 'displayItems' => wc_stripe_get_display_items (),
278
- 'shippingOptions' => wc_stripe_get_shipping_options ()
279
- ] )
280
- ], $gateway, $request ) );
281
- } else {
282
- $response = new WP_Error ( 'cart-error', $this->get_error_messages (), [
283
- 'status' => 200
284
- ] );
285
- }
286
- wc_stripe_stash_product_cart ( WC ()->cart );
287
- wc_stripe_restore_cart ( WC ()->cart );
288
- wc_clear_notices ();
289
- // add to cart was successful. Send a new X-WP-Nonce since it will be different now that a WC session exists.
290
- rest_get_server ()->send_header ( 'X-WP-Nonce', wp_create_nonce ( 'wp_rest' ) );
291
- return $response;
292
- }
293
-
294
- protected function get_error_messages() {
295
- return $this->get_messages ( 'error' );
296
- }
297
-
298
- /**
299
- *
300
- * {@inheritDoc}
301
- *
302
- * @see WC_Stripe_Rest_Controller::get_messages()
303
- */
304
- protected function get_messages($types = 'all') {
305
- $notices = wc_get_notices ();
306
- $message = '';
307
- if ($types !== 'all') {
308
- $types = ( array ) $types;
309
- foreach ( $notices as $type => $notice ) {
310
- if (! in_array ( $type, $types )) {
311
- unset ( $notices[ $type ] );
312
- }
313
- }
314
- }
315
- foreach ( $notices as $notice ) {
316
- $message .= sprintf ( ' %s', $notice );
317
- }
318
-
319
- return trim ( $message );
320
- }
321
-
322
- /**
323
- * Return true if the provided packages have shipping methods.
324
- *
325
- * @param array $packages
326
- */
327
- private function has_shipping_methods($packages) {
328
- foreach ( $packages as $i => $package ) {
329
- if (! empty ( $package[ 'rates' ] )) {
330
- return true;
331
- }
332
- }
333
- return false;
334
- }
335
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
15
+ protected $namespace = 'cart';
16
+
17
+ public function register_routes() {
18
+ register_rest_route(
19
+ $this->rest_uri(),
20
+ 'shipping-method',
21
+ array(
22
+ 'methods' => WP_REST_Server::CREATABLE,
23
+ 'callback' => array( $this, 'update_shipping_method' ),
24
+ 'args' => array(
25
+ 'shipping_methods' => array( 'required' => true ),
26
+ 'payment_method' => array( 'required' => true ),
27
+ ),
28
+ )
29
+ );
30
+ register_rest_route(
31
+ $this->rest_uri(),
32
+ 'shipping-address',
33
+ array(
34
+ 'methods' => WP_REST_Server::CREATABLE,
35
+ 'callback' => array( $this, 'update_shipping_address' ),
36
+ 'args' => array(
37
+ 'address' => array( 'required' => true ),
38
+ 'payment_method' => array( 'required' => true ),
39
+ ),
40
+ )
41
+ );
42
+ register_rest_route(
43
+ $this->rest_uri(),
44
+ 'add-to-cart',
45
+ array(
46
+ 'methods' => WP_REST_Server::CREATABLE,
47
+ 'callback' => array( $this, 'add_to_cart' ),
48
+ 'args' => array(
49
+ 'product_id' => array( 'required' => true ),
50
+ 'qty' => array(
51
+ 'required' => true,
52
+ 'validate_callback' => array( $this, 'validate_quantity' ),
53
+ ),
54
+ 'payment_method' => array( 'required' => true ),
55
+ ),
56
+ )
57
+ );
58
+ /**
59
+ *
60
+ * @since 3.0.6
61
+ */
62
+ register_rest_route(
63
+ $this->rest_uri(),
64
+ 'cart-calculation',
65
+ array(
66
+ 'methods' => WP_REST_Server::CREATABLE,
67
+ 'callback' => array( $this, 'cart_calculation' ),
68
+ 'args' => array(
69
+ 'product_id' => array( 'required' => true ),
70
+ 'qty' => array(
71
+ 'required' => true,
72
+ 'validate_callback' => array( $this, 'validate_quantity' ),
73
+ ),
74
+ 'payment_method' => array( 'required' => true ),
75
+ ),
76
+ )
77
+ );
78
+ }
79
+
80
+ /**
81
+ *
82
+ * @param int $qty
83
+ * @param WP_REST_Request $request
84
+ */
85
+ public function validate_quantity( $qty, $request ) {
86
+ if ( $qty == 0 ) {
87
+ return $this->add_validation_error( new WP_Error( 'cart-error', __( 'Quantity must be greater than zero.', 'woo-stripe-payment' ) ) );
88
+ }
89
+ return true;
90
+ }
91
+
92
+ /**
93
+ * Update the shipping method chosen by the customer.
94
+ *
95
+ * @param WP_REST_Request $request
96
+ */
97
+ public function update_shipping_method( $request ) {
98
+ wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
99
+ $shipping_methods = $request->get_param( 'shipping_methods' );
100
+ $payment_method = $request->get_param( 'payment_method' );
101
+ /**
102
+ *
103
+ * @var WC_Payment_Gateway_Stripe $gateway
104
+ */
105
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
106
+
107
+ wc_stripe_update_shipping_methods( $shipping_methods );
108
+
109
+ $this->add_ready_to_calc_shipping();
110
+
111
+ // if this request is coming from product page, stash cart and use product cart
112
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
113
+ wc_stripe_stash_cart( WC()->cart );
114
+ } else {
115
+ WC()->cart->calculate_totals();
116
+ }
117
+
118
+ $response = rest_ensure_response(
119
+ apply_filters(
120
+ 'wc_stripe_update_shipping_method_response',
121
+ array(
122
+ 'data' => $gateway->get_update_shipping_method_response(
123
+ array(
124
+ 'newData' => array(
125
+ 'status' => 'success',
126
+ 'total' => array(
127
+ 'amount' => wc_stripe_add_number_precision( WC()->cart->total ),
128
+ 'label' => __( 'Total', 'woo-stripe-payment' ),
129
+ 'pending' => false,
130
+ ),
131
+ 'displayItems' => wc_stripe_get_display_items(),
132
+ 'shippingOptions' => wc_stripe_get_shipping_options(),
133
+ ),
134
+ 'shipping_methods' => WC()->session->get(
135
+ 'chosen_shipping_methods',
136
+ array()
137
+ ),
138
+ )
139
+ ),
140
+ )
141
+ )
142
+ );
143
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
144
+ wc_stripe_restore_cart( WC()->cart );
145
+ }
146
+ return $response;
147
+ }
148
+
149
+ /**
150
+ *
151
+ * @param WP_REST_Request $request
152
+ */
153
+ public function update_shipping_address( $request ) {
154
+ wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
155
+ $address = $request->get_param( 'address' );
156
+ $payment_method = $request->get_param( 'payment_method' );
157
+ /**
158
+ *
159
+ * @var WC_Payment_Gateway_Stripe $gateway
160
+ */
161
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
162
+ try {
163
+ wc_stripe_update_customer_location( $address );
164
+
165
+ $this->add_ready_to_calc_shipping();
166
+
167
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
168
+ wc_stripe_stash_cart( WC()->cart );
169
+ } else {
170
+ WC()->cart->calculate_totals();
171
+ }
172
+
173
+ if ( ! $this->has_shipping_methods( WC()->shipping()->get_packages() ) ) {
174
+ throw new Exception( 'No valid shipping methods.' );
175
+ }
176
+
177
+ $response = rest_ensure_response(
178
+ apply_filters(
179
+ 'wc_stripe_update_shipping_method_response',
180
+ array(
181
+ 'data' => $gateway->get_update_shipping_address_response(
182
+ array(
183
+ 'newData' => array(
184
+ 'status' => 'success',
185
+ 'total' => array(
186
+ 'amount' => wc_stripe_add_number_precision( WC()->cart->total ),
187
+ 'label' => __( 'Total', 'woo-stripe-payment' ),
188
+ 'pending' => false,
189
+ ),
190
+ 'displayItems' => wc_stripe_get_display_items(),
191
+ 'shippingOptions' => wc_stripe_get_shipping_options(),
192
+ ),
193
+ )
194
+ ),
195
+ )
196
+ )
197
+ );
198
+ } catch ( Exception $e ) {
199
+ $response = new WP_Error(
200
+ 'address-error',
201
+ $e->getMessage(),
202
+ array(
203
+ 'status' => 200,
204
+ 'newData' => array( 'status' => 'invalid_shipping_address' ),
205
+ )
206
+ );
207
+ }
208
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
209
+ wc_stripe_restore_cart( WC()->cart );
210
+ }
211
+ return $response;
212
+ }
213
+
214
+ /**
215
+ *
216
+ * @param WP_REST_Request $request
217
+ */
218
+ public function add_to_cart( $request ) {
219
+ // WC 3.0.0 requires WOOCOMMERCE_CART to be defined.
220
+ wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
221
+ $payment_method = $request->get_param( 'payment_method' );
222
+ /**
223
+ *
224
+ * @var WC_Payment_Gateway_Stripe $gateway
225
+ */
226
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
227
+
228
+ $product_id = $request->get_param( 'product_id' );
229
+ $qty = $request->get_param( 'qty' );
230
+ $variation_id = $request->get_param( 'variation_id' );
231
+
232
+ // stash cart so clean calculation can be performed.
233
+ wc_stripe_stash_cart( WC()->cart, false );
234
+
235
+ if ( WC()->cart->add_to_cart( $product_id, $qty, $variation_id ) == false ) {
236
+ return new WP_Error( 'cart-error', $this->get_error_messages(), array( 'status' => 200 ) );
237
+ } else {
238
+ // add to cart was successful. Send a new X-WP-Nonce since it will be different now that a WC session
239
+ // exists.
240
+ rest_get_server()->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) );
241
+ $response = rest_ensure_response(
242
+ apply_filters(
243
+ 'wc_stripe_add_to_cart_response',
244
+ array(
245
+ 'data' => $gateway->add_to_cart_response(
246
+ array(
247
+ 'total' => WC()->cart->total,
248
+ 'subtotal' => WC()->cart->subtotal,
249
+ 'totalCents' => wc_stripe_add_number_precision( WC()->cart->total ),
250
+ 'displayItems' => wc_stripe_get_display_items(),
251
+ 'shippingOptions' => wc_stripe_get_shipping_options(),
252
+ )
253
+ ),
254
+ ),
255
+ $gateway,
256
+ $request
257
+ )
258
+ );
259
+ // save the product cart so it can be used for shipping calculations etc.
260
+ wc_stripe_stash_product_cart( WC()->cart );
261
+ // put cart contents back to how they were before.
262
+ wc_stripe_restore_cart( WC()->cart );
263
+ return $response;
264
+ }
265
+ }
266
+
267
+ /**
268
+ * Performs a cart calculation
269
+ *
270
+ * @param WP_REST_Request $request
271
+ */
272
+ public function cart_calculation( $request ) {
273
+ // WC 3.0.0 requires WOOCOMMERCE_CART to be defined.
274
+ wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
275
+ $product_id = $request->get_param( 'product_id' );
276
+ $qty = $request->get_param( 'qty' );
277
+ $variation_id = $request->get_param( 'variation_id' ) == null ? 0 : $request->get_param( 'variation_id' );
278
+
279
+ wc_stripe_stash_cart( WC()->cart, false );
280
+
281
+ if ( WC()->cart->add_to_cart( $product_id, $qty, $variation_id ) ) {
282
+ $payment_method = $request->get_param( 'payment_method' );
283
+ /**
284
+ *
285
+ * @var WC_Payment_Gateway_Stripe $gateway
286
+ */
287
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
288
+ $response = rest_ensure_response(
289
+ apply_filters(
290
+ 'wc_stripe_add_to_cart_response',
291
+ array(
292
+ 'data' => $gateway->add_to_cart_response(
293
+ array(
294
+ 'total' => WC()->cart->total,
295
+ 'subtotal' => WC()->cart->subtotal,
296
+ 'totalCents' => wc_stripe_add_number_precision( WC()->cart->total ),
297
+ 'displayItems' => wc_stripe_get_display_items(),
298
+ 'shippingOptions' => wc_stripe_get_shipping_options(),
299
+ )
300
+ ),
301
+ ),
302
+ $gateway,
303
+ $request
304
+ )
305
+ );
306
+ } else {
307
+ $response = new WP_Error( 'cart-error', $this->get_error_messages(), array( 'status' => 200 ) );
308
+ }
309
+ wc_stripe_stash_product_cart( WC()->cart );
310
+ wc_stripe_restore_cart( WC()->cart );
311
+ wc_clear_notices();
312
+ // add to cart was successful. Send a new X-WP-Nonce since it will be different now that a WC session exists.
313
+ rest_get_server()->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) );
314
+ return $response;
315
+ }
316
+
317
+ protected function get_error_messages() {
318
+ return $this->get_messages( 'error' );
319
+ }
320
+
321
+ /**
322
+ *
323
+ * {@inheritDoc}
324
+ *
325
+ * @see WC_Stripe_Rest_Controller::get_messages()
326
+ */
327
+ protected function get_messages( $types = 'all' ) {
328
+ $notices = wc_get_notices();
329
+ $message = '';
330
+ if ( $types !== 'all' ) {
331
+ $types = (array) $types;
332
+ foreach ( $notices as $type => $notice ) {
333
+ if ( ! in_array( $type, $types ) ) {
334
+ unset( $notices[ $type ] );
335
+ }
336
+ }
337
+ }
338
+ foreach ( $notices as $notice ) {
339
+ $message .= sprintf( ' %s', $notice );
340
+ }
341
+
342
+ return trim( $message );
343
+ }
344
+
345
+ /**
346
+ * Return true if the provided packages have shipping methods.
347
+ *
348
+ * @param array $packages
349
+ */
350
+ private function has_shipping_methods( $packages ) {
351
+ foreach ( $packages as $i => $package ) {
352
+ if ( ! empty( $package['rates'] ) ) {
353
+ return true;
354
+ }
355
+ }
356
+ return false;
357
+ }
358
+ }
includes/controllers/class-wc-stripe-controller-checkout.php CHANGED
@@ -1,229 +1,265 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Stripe_Rest_Controller' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @author PaymentPlugins
10
- * @since 3.0.0
11
- * @package Stripe/Controllers
12
- *
13
- */
14
- class WC_Stripe_Controller_Checkout extends WC_Stripe_Rest_Controller {
15
-
16
- protected $namespace = '';
17
-
18
- private $order_review = false;
19
-
20
- /**
21
- *
22
- * @var WC_Payment_Gateway_Stripe
23
- */
24
- private $gateway = null;
25
-
26
- public function register_routes() {
27
- register_rest_route ( $this->rest_uri (), 'checkout', [
28
- 'methods' => WP_REST_Server::CREATABLE,
29
- 'callback' => [ $this,
30
- 'process_checkout'
31
- ]
32
- ] );
33
- register_rest_route ( $this->rest_uri (), 'order-pay', [
34
- 'methods' => WP_REST_Server::CREATABLE,
35
- 'callback' => [ $this,
36
- 'process_order_pay'
37
- ]
38
- ] );
39
- }
40
-
41
- /**
42
- * Process the WC Order
43
- *
44
- * @param WP_REST_Request $request
45
- */
46
- public function process_checkout($request) {
47
- wc_maybe_define_constant ( 'DOING_AJAX', true );
48
- $this->actions ();
49
- $checkout = WC ()->checkout ();
50
- $payment_method = $request->get_param ( 'payment_method' );
51
- /**
52
- *
53
- * @var WC_Payment_Gateway_Stripe $gateway
54
- */
55
- $this->gateway = $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $payment_method ];
56
-
57
- $this->required_post_data ();
58
-
59
- $this->order_review = ! is_null ( $request->get_param ( 'order_review' ) ) && 'true' === $request->get_param ( 'order_review' );
60
-
61
- try {
62
- do_action ( 'wc_stripe_rest_process_checkout', $request, $gateway );
63
- if (! is_user_logged_in ()) {
64
- $this->create_customer ( $request );
65
- }
66
- // set the checkout nonce so no exceptions are thrown.
67
- $_REQUEST[ '_wpnonce' ] = $_POST[ '_wpnonce' ] = wp_create_nonce ( 'woocommerce-process_checkout' );
68
-
69
- if ('product' == $request->get_param ( 'page_id' )) {
70
- wc_stripe_stash_cart ( WC ()->cart );
71
- $gateway->set_post_payment_process ( [
72
- $this, 'post_payment_processes'
73
- ] );
74
- add_filter ( 'woocommerce_get_checkout_order_received_url', function ($url, $order) {
75
- return add_query_arg ( 'wc_stripe_product_checkout', $order->get_payment_method (), $url );
76
- }, 10, 2 );
77
-
78
- $option = new WC_Stripe_Product_Gateway_Option ( current ( WC ()->cart->get_cart () )[ 'data' ], $gateway );
79
- $gateway->settings[ 'charge_type' ] = $option->get_option ( 'charge_type' );
80
- }
81
- $checkout->process_checkout ();
82
- } catch ( Exception $e ) {
83
- wc_add_notice ( $e->getMessage (), 'error' );
84
- }
85
- if (wc_notice_count ( 'error' ) > 0) {
86
- return $this->send_response ( false );
87
- }
88
- return $this->send_response ( true );
89
- }
90
-
91
- /**
92
- *
93
- * @since 3.1.8
94
- * @param WP_REST_Request $request
95
- */
96
- public function process_order_pay($request) {
97
- global $wp;
98
-
99
- $wp->query_vars[ 'order-pay' ] = $request->get_param ( 'order_id' );
100
-
101
- wc_maybe_define_constant ( WC_Stripe_Constants::WOOCOMMERCE_STRIPE_ORDER_PAY, true );
102
-
103
- WC_Form_Handler::pay_action ();
104
-
105
- if (wc_notice_count ( 'error' ) > 0) {
106
- return rest_ensure_response ( [
107
- 'success' => false,
108
- 'message' => $this->get_messages ( 'error' )
109
- ] );
110
- }
111
- }
112
-
113
- /**
114
- *
115
- * @param WP_REST_Request $request
116
- */
117
- private function create_customer($request) {
118
- $create = WC ()->checkout ()->is_registration_required ();
119
- // create an account for the user if it's required for things like subscriptions.
120
- if (wcs_stripe_active () && WC_Subscriptions_Cart::cart_contains_subscription ()) {
121
- $create = true;
122
- }
123
- if ($create) {
124
- $password = wp_generate_password ();
125
- $username = $email = $request->get_param ( 'billing_email' );
126
- $result = wc_create_new_customer ( $email, $username, $password );
127
- if ($result instanceof WP_Error) {
128
- // for email exists errors you want customer to either login or use a different email address.
129
- throw new Exception ( $result->get_error_message () );
130
- }
131
- $this->customer_id = $result;
132
-
133
- // log the customer in
134
- wp_set_current_user ( $this->customer_id );
135
- wc_set_customer_auth_cookie ( $this->customer_id );
136
-
137
- // As we are now logged in, cart will need to refresh to receive updated nonces
138
- WC ()->session->set ( 'reload_checkout', true );
139
- }
140
- }
141
-
142
- private function send_response($success) {
143
- $reload = WC ()->session->get ( 'reload_checkout', false );
144
- $data = array(
145
- 'result' => $success ? 'success' : 'failure',
146
- 'messages' => $reload ? null : $this->get_error_messages (),
147
- 'reload' => $reload
148
- );
149
- unset ( WC ()->session->reload_checkout );
150
- return rest_ensure_response ( $data );
151
- }
152
-
153
- public function validate_payment_method($payment_method) {
154
- $gateways = WC ()->payment_gateways ()->payment_gateways ();
155
- return isset ( $gateways[ $payment_method ] ) ? true : new WP_Error ( 'validation-error', 'Please choose a valid payment method.' );
156
- }
157
-
158
- private function actions() {
159
- add_action ( 'woocommerce_after_checkout_validation', array(
160
- $this, 'after_checkout_validation'
161
- ), 10, 2 );
162
- add_action ( 'woocommerce_checkout_order_processed', array(
163
- $this, 'checkout_order_processed'
164
- ), 10, 3 );
165
- }
166
-
167
- /**
168
- *
169
- * @param WC_Order $order
170
- * @param WC_Payment_Gateway_Stripe $gateway
171
- */
172
- public function set_stashed_cart($order, $gateway) {
173
- wc_stripe_restore_cart ( WC ()->cart );
174
- }
175
-
176
- /**
177
- *
178
- * @param array $data
179
- * @param WP_Error $errors
180
- */
181
- public function after_checkout_validation($data, $errors) {
182
- if ($errors->get_error_message ( 'required-field' )) {
183
- wc_add_notice ( apply_filters ( 'wc_stripe_after_checkout_validation_notice', sprintf ( __ ( 'Some required fields were missing. Please click %shere%s to complete your payment.', 'woo-stripe-payment' ), '<a href="' . $this->get_order_review_url () . '">', '</a>' ), $data, $errors ), 'notice' );
184
- wp_send_json ( array( 'result' => 'failure',
185
- 'messages' => $this->get_messages ( 'notice' ),
186
- 'reload' => false
187
- ), 200 );
188
- }
189
- }
190
-
191
- private function required_post_data() {
192
- if (WC ()->cart->needs_shipping ()) {
193
- $_POST[ 'ship_to_different_address' ] = true;
194
- }
195
- if (wc_get_page_id ( 'terms' ) > 0) {
196
- $_POST[ 'terms' ] = 1;
197
- }
198
- }
199
-
200
- private function get_order_review_url() {
201
- return add_query_arg ( array(
202
- 'order_review' => 'true',
203
- 'payment_method' => $this->gateway->id,
204
- 'payment_nonce' => $this->gateway->get_payment_source ()
205
- ), wc_get_checkout_url () );
206
- }
207
-
208
- /**
209
- *
210
- * @param int $order_id
211
- * @param array $posted_data
212
- * @param WC_Order $order
213
- */
214
- public function checkout_order_processed($order_id, $posted_data, $order) {
215
- if ($this->order_review) {
216
- wc_add_notice ( __ ( 'Please review your order details then click Place Order.', 'woo-stripe-payment' ), 'notice' );
217
- wp_send_json ( array( 'result' => 'success',
218
- 'redirect' => $this->get_order_review_url ()
219
- ), 200 );
220
- }
221
- }
222
-
223
- public function post_payment_processes($order, $gateway) {
224
- wc_stripe_restore_cart ( WC ()->cart );
225
- $data = WC ()->session->get ( 'wc_stripe_cart', [] );
226
- unset ( $data[ 'product_cart' ] );
227
- WC ()->session->set ( 'wc_stripe_cart', $data );
228
- }
229
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @since 3.0.0
12
+ * @package Stripe/Controllers
13
+ *
14
+ */
15
+ class WC_Stripe_Controller_Checkout extends WC_Stripe_Rest_Controller {
16
+
17
+ protected $namespace = '';
18
+
19
+ private $order_review = false;
20
+
21
+ /**
22
+ *
23
+ * @var WC_Payment_Gateway_Stripe
24
+ */
25
+ private $gateway = null;
26
+
27
+ public function register_routes() {
28
+ register_rest_route(
29
+ $this->rest_uri(),
30
+ 'checkout',
31
+ array(
32
+ 'methods' => WP_REST_Server::CREATABLE,
33
+ 'callback' => array(
34
+ $this,
35
+ 'process_checkout',
36
+ ),
37
+ )
38
+ );
39
+ register_rest_route(
40
+ $this->rest_uri(),
41
+ 'order-pay',
42
+ array(
43
+ 'methods' => WP_REST_Server::CREATABLE,
44
+ 'callback' => array(
45
+ $this,
46
+ 'process_order_pay',
47
+ ),
48
+ )
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Process the WC Order
54
+ *
55
+ * @param WP_REST_Request $request
56
+ */
57
+ public function process_checkout( $request ) {
58
+ wc_maybe_define_constant( 'DOING_AJAX', true );
59
+ $this->actions();
60
+ $checkout = WC()->checkout();
61
+ $payment_method = $request->get_param( 'payment_method' );
62
+ /**
63
+ *
64
+ * @var WC_Payment_Gateway_Stripe $gateway
65
+ */
66
+ $this->gateway = $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
67
+
68
+ $this->required_post_data();
69
+
70
+ $this->order_review = ! is_null( $request->get_param( 'order_review' ) ) && 'true' === $request->get_param( 'order_review' );
71
+
72
+ try {
73
+ do_action( 'wc_stripe_rest_process_checkout', $request, $gateway );
74
+ if ( ! is_user_logged_in() ) {
75
+ $this->create_customer( $request );
76
+ }
77
+ // set the checkout nonce so no exceptions are thrown.
78
+ $_REQUEST['_wpnonce'] = $_POST['_wpnonce'] = wp_create_nonce( 'woocommerce-process_checkout' );
79
+
80
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
81
+ wc_stripe_stash_cart( WC()->cart );
82
+ $gateway->set_post_payment_process( array( $this, 'post_payment_processes' ) );
83
+ add_filter(
84
+ 'woocommerce_get_checkout_order_received_url',
85
+ function ( $url, $order ) {
86
+ return add_query_arg( 'wc_stripe_product_checkout', $order->get_payment_method(), $url );
87
+ },
88
+ 10,
89
+ 2
90
+ );
91
+
92
+ $option = new WC_Stripe_Product_Gateway_Option( current( WC()->cart->get_cart() )['data'], $gateway );
93
+ $gateway->settings['charge_type'] = $option->get_option( 'charge_type' );
94
+ }
95
+ $checkout->process_checkout();
96
+ } catch ( Exception $e ) {
97
+ wc_add_notice( $e->getMessage(), 'error' );
98
+ }
99
+ if ( wc_notice_count( 'error' ) > 0 ) {
100
+ return $this->send_response( false );
101
+ }
102
+ return $this->send_response( true );
103
+ }
104
+
105
+ /**
106
+ *
107
+ * @since 3.1.8
108
+ * @param WP_REST_Request $request
109
+ */
110
+ public function process_order_pay( $request ) {
111
+ global $wp;
112
+
113
+ $wp->query_vars['order-pay'] = $request->get_param( 'order_id' );
114
+
115
+ wc_maybe_define_constant( WC_Stripe_Constants::WOOCOMMERCE_STRIPE_ORDER_PAY, true );
116
+
117
+ WC_Form_Handler::pay_action();
118
+
119
+ if ( wc_notice_count( 'error' ) > 0 ) {
120
+ return rest_ensure_response(
121
+ array(
122
+ 'success' => false,
123
+ 'message' => $this->get_messages( 'error' ),
124
+ )
125
+ );
126
+ }
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @param WP_REST_Request $request
132
+ */
133
+ private function create_customer( $request ) {
134
+ $create = WC()->checkout()->is_registration_required();
135
+ // create an account for the user if it's required for things like subscriptions.
136
+ if ( wcs_stripe_active() && WC_Subscriptions_Cart::cart_contains_subscription() ) {
137
+ $create = true;
138
+ }
139
+ if ( $create ) {
140
+ $password = wp_generate_password();
141
+ $username = $email = $request->get_param( 'billing_email' );
142
+ $result = wc_create_new_customer( $email, $username, $password );
143
+ if ( $result instanceof WP_Error ) {
144
+ // for email exists errors you want customer to either login or use a different email address.
145
+ throw new Exception( $result->get_error_message() );
146
+ }
147
+ $this->customer_id = $result;
148
+
149
+ // log the customer in
150
+ wp_set_current_user( $this->customer_id );
151
+ wc_set_customer_auth_cookie( $this->customer_id );
152
+
153
+ // As we are now logged in, cart will need to refresh to receive updated nonces
154
+ WC()->session->set( 'reload_checkout', true );
155
+ }
156
+ }
157
+
158
+ private function send_response( $success ) {
159
+ $reload = WC()->session->get( 'reload_checkout', false );
160
+ $data = array(
161
+ 'result' => $success ? 'success' : 'failure',
162
+ 'messages' => $reload ? null : $this->get_error_messages(),
163
+ 'reload' => $reload,
164
+ );
165
+ unset( WC()->session->reload_checkout );
166
+ return rest_ensure_response( $data );
167
+ }
168
+
169
+ public function validate_payment_method( $payment_method ) {
170
+ $gateways = WC()->payment_gateways()->payment_gateways();
171
+ return isset( $gateways[ $payment_method ] ) ? true : new WP_Error( 'validation-error', 'Please choose a valid payment method.' );
172
+ }
173
+
174
+ private function actions() {
175
+ add_action( 'woocommerce_after_checkout_validation', array( $this, 'after_checkout_validation' ), 10, 2 );
176
+ add_action( 'woocommerce_checkout_order_processed', array( $this, 'checkout_order_processed' ), 10, 3 );
177
+ }
178
+
179
+ /**
180
+ *
181
+ * @param WC_Order $order
182
+ * @param WC_Payment_Gateway_Stripe $gateway
183
+ */
184
+ public function set_stashed_cart( $order, $gateway ) {
185
+ wc_stripe_restore_cart( WC()->cart );
186
+ }
187
+
188
+ /**
189
+ *
190
+ * @param array $data
191
+ * @param WP_Error $errors
192
+ */
193
+ public function after_checkout_validation( $data, $errors ) {
194
+ if ( $errors->get_error_message( 'required-field' ) ) {
195
+ wc_add_notice(
196
+ apply_filters(
197
+ 'wc_stripe_after_checkout_validation_notice',
198
+ sprintf(
199
+ __( 'Some required fields were missing. Please click %1$shere%2$s to complete your payment.', 'woo-stripe-payment' ),
200
+ '<a href="' .
201
+ $this->get_order_review_url() . '">',
202
+ '</a>'
203
+ ),
204
+ $data,
205
+ $errors
206
+ ),
207
+ 'notice'
208
+ );
209
+ wp_send_json(
210
+ array(
211
+ 'result' => 'failure',
212
+ 'messages' => $this->get_messages( 'notice' ),
213
+ 'reload' => false,
214
+ ),
215
+ 200
216
+ );
217
+ }
218
+ }
219
+
220
+ private function required_post_data() {
221
+ if ( WC()->cart->needs_shipping() ) {
222
+ $_POST['ship_to_different_address'] = true;
223
+ }
224
+ if ( wc_get_page_id( 'terms' ) > 0 ) {
225
+ $_POST['terms'] = 1;
226
+ }
227
+ }
228
+
229
+ private function get_order_review_url() {
230
+ return add_query_arg(
231
+ array(
232
+ 'order_review' => 'true',
233
+ 'payment_method' => $this->gateway->id,
234
+ 'payment_nonce' => $this->gateway->get_payment_source(),
235
+ ),
236
+ wc_get_checkout_url()
237
+ );
238
+ }
239
+
240
+ /**
241
+ *
242
+ * @param int $order_id
243
+ * @param array $posted_data
244
+ * @param WC_Order $order
245
+ */
246
+ public function checkout_order_processed( $order_id, $posted_data, $order ) {
247
+ if ( $this->order_review ) {
248
+ wc_add_notice( __( 'Please review your order details then click Place Order.', 'woo-stripe-payment' ), 'notice' );
249
+ wp_send_json(
250
+ array(
251
+ 'result' => 'success',
252
+ 'redirect' => $this->get_order_review_url(),
253
+ ),
254
+ 200
255
+ );
256
+ }
257
+ }
258
+
259
+ public function post_payment_processes( $order, $gateway ) {
260
+ wc_stripe_restore_cart( WC()->cart );
261
+ $data = WC()->session->get( 'wc_stripe_cart', array() );
262
+ unset( $data['product_cart'] );
263
+ WC()->session->set( 'wc_stripe_cart', $data );
264
+ }
265
+ }
includes/controllers/class-wc-stripe-controller-gateway-settings.php CHANGED
@@ -1,194 +1,237 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @package Stripe/Controllers
7
- * @author PaymentPlugins
8
- *
9
- */
10
- class WC_Stripe_Controller_Gateway_Settings extends WC_Stripe_Rest_Controller {
11
-
12
- protected $namespace = 'gateway-settings';
13
-
14
- public function register_routes() {
15
- register_rest_route ( $this->rest_uri (), 'apple-domain', [
16
- 'methods' => WP_REST_Server::CREATABLE,
17
- 'callback' => [ $this,
18
- 'register_apple_domain'
19
- ],
20
- 'permission_callback' => array( $this,
21
- 'admin_permission_check'
22
- )
23
- ] );
24
- register_rest_route ( $this->rest_uri (), 'create-webook', [
25
- 'methods' => WP_REST_Server::CREATABLE,
26
- 'callback' => [ $this, 'create_webhook'
27
- ],
28
- 'permission_callback' => array( $this,
29
- 'admin_permission_check'
30
- )
31
- ] );
32
- register_rest_route ( $this->rest_uri (), 'connection-test', [
33
- 'methods' => WP_REST_Server::CREATABLE,
34
- 'callback' => [ $this,
35
- 'connection_test'
36
- ],
37
- 'permission_callback' => array( $this,
38
- 'admin_permission_check'
39
- )
40
- ] );
41
- }
42
-
43
- /**
44
- * Register the site domain with Stripe for Apple Pay.
45
- *
46
- * @param WP_REST_Request $request
47
- */
48
- public function register_apple_domain($request) {
49
- $gateway = WC_Stripe_Gateway::load ();
50
- // try to add domain association file.
51
- if (isset ( $_SERVER[ 'DOCUMENT_ROOT' ] )) {
52
- $path = $_SERVER[ 'DOCUMENT_ROOT' ] . DIRECTORY_SEPARATOR . '.well-known';
53
- $file = $path . DIRECTORY_SEPARATOR . 'apple-developer-merchantid-domain-association';
54
- if (! file_exists ( $file )) {
55
- require_once ( ABSPATH . '/wp-admin/includes/file.php' );
56
- if (function_exists ( 'WP_Filesystem' ) && ( WP_Filesystem () )) {
57
- /**
58
- *
59
- * @var WP_Filesystem_Base $wp_filesystem
60
- */
61
- global $wp_filesystem;
62
- if (! $wp_filesystem->is_dir ( $path )) {
63
- $wp_filesystem->mkdir ( $path );
64
- }
65
- $contents = $wp_filesystem->get_contents ( WC_STRIPE_PLUGIN_FILE_PATH . 'apple-developer-merchantid-domain-association' );
66
- $wp_filesystem->put_contents ( $file, $contents, 0755 );
67
- }
68
- }
69
- }
70
- $server_name = $_SERVER[ 'SERVER_NAME' ];
71
- if (strstr ( $server_name, 'www.' )) {
72
- $server_name_2 = str_replace ( 'www.', '', $server_name );
73
- } else {
74
- $server_name_2 = 'www.' . $server_name;
75
- }
76
- $domains = [ $server_name, $server_name_2
77
- ];
78
- try {
79
- $failures = 0;
80
- foreach ( $domains as $domain ) {
81
- $api_key = wc_stripe_get_secret_key ( 'live' );
82
- if (empty ( $api_key )) {
83
- throw new Exception ( __ ( 'You cannot register your domain until you have configured your Live API keys.', 'woo-stripe-payment' ) );
84
- }
85
- $result = $gateway->register_domain ( $domain, 'live' );
86
- if (is_wp_error ( $result )) {
87
- $failures ++;
88
- if ($failures > 1) {
89
- throw new Exception ( $result->get_error_message () );
90
- }
91
- }
92
- }
93
- } catch ( Exception $e ) {
94
- return new WP_Error ( 'domain-error', $e->getMessage (), [
95
- 'status' => 200
96
- ] );
97
- }
98
- return rest_ensure_response ( [
99
- 'message' => sprintf ( __ ( 'Domain registered successfully. You can confirm in your Stripe Dashboard at https://dashboard.stripe.com/account/apple_pay.', 'woo-stripe-payment' ) )
100
- ] );
101
- }
102
-
103
- /**
104
- * Create a Stripe webhook for the site.
105
- *
106
- * @param WP_REST_Request $request
107
- */
108
- public function create_webhook($request) {
109
- $url = wc_stripe ()->rest_api->webhook->rest_url ( 'webhook' );
110
- $api_settings = wc_stripe ()->api_settings;
111
- $env = $request->get_param ( 'environment' );
112
- $gateway = new WC_Stripe_Gateway ( $env );
113
- // first fetch all webhooks
114
- $private_key = wc_stripe_get_secret_key ( $env );
115
- if (empty ( $private_key )) {
116
- return new WP_Error ( 'webhook-error', __ ( 'You must configure your secret key before creating webhooks.', 'woo-stripe-payment' ), [
117
- 'status' => 200
118
- ] );
119
- }
120
- $webhooks = $gateway->webhooks ();
121
- if (! is_wp_error ( $webhooks )) {
122
- // validate that the webhook hasn't already been created.
123
- foreach ( $webhooks->data as $webhook ) {
124
- if ($webhook[ 'url' ] === $url) {
125
- return new WP_Error ( 'webhook-error', __ ( 'There is already a webhook configured for this site. If you want to delete the webhook, login to your Stripe Dashboard.', 'woo-stripe-payment' ), [
126
- 'status' => 200
127
- ] );
128
- }
129
- }
130
- }
131
-
132
- // create the webhooks and save it to the api settings.
133
- $webhook = $gateway->create_webhook ( $url, apply_filters ( 'wc_stripe_webhook_events', [
134
- 'charge.failed', 'charge.succeeded',
135
- 'source.chargeable',
136
- 'payment_intent.succeeded'
137
- ] ) );
138
- if (is_wp_error ( $webhook )) {
139
- return new WP_Error ( $webhook->get_error_code (), $webhook->get_error_message (), [
140
- 'status' => 200
141
- ] );
142
- } else {
143
- $api_settings->update_option ( "webhook_url_{$env}", $webhook[ 'url' ] );
144
- $api_settings->update_option ( "webhook_secret_{$env}", $webhook[ 'secret' ] );
145
- $api_settings->update_option ( "webhook_id_{$env}", $webhook[ 'id' ] );
146
- return rest_ensure_response ( [
147
- 'message' => sprintf ( __ ( 'Webhook created in Stripe for %s environment. You can test your webhook by logging in to the Stripe dashboard', 'woo-stripe-payment' ), 'live' == $env ? __ ( 'Live', 'woo-stripe-payment' ) : __ ( 'Test', 'woo-stripe-payment' ) ),
148
- 'secret' => $webhook[ 'secret' ]
149
- ] );
150
- }
151
- }
152
-
153
- /**
154
- * Perform a connection test
155
- *
156
- * @param WP_REST_Request $request
157
- */
158
- public function connection_test($request) {
159
- $mode = $request->get_param ( 'mode' );
160
- $gateway = new WC_Stripe_Gateway ( $mode );
161
-
162
- try {
163
- // test the secret key
164
- $response = $gateway->fetch_customers ();
165
-
166
- if (is_wp_error ( $response )) {
167
- throw new Exception ( sprintf ( __ ( 'Mode: %s. Invalid secret key. Please check your entry.', 'woo-stripe-payment' ), $mode ) );
168
- }
169
-
170
- // test the publishable key
171
- $response = wp_remote_post ( 'https://api.stripe.com/v1/payment_methods', [
172
- 'headers' => [
173
- 'Content-Type' => 'application/x-www-form-urlencoded'
174
- ],
175
- 'body' => [
176
- 'key' => wc_stripe_get_publishable_key ( $mode )
177
- ]
178
- ] );
179
- if (is_wp_error ( $response )) {
180
- throw new Exception ( sprintf ( __ ( 'Mode: %s. Invalid publishable key. Please check your entry.', 'woo-stripe-payment' ), $mode ) );
181
- }
182
- if ($response[ 'response' ][ 'code' ] == 401) {
183
- throw new Exception ( sprintf ( __ ( 'Mode: %s. Invalid publishable key. Please check your entry.', 'woo-stripe-payment' ), $mode ) );
184
- }
185
- } catch ( Exception $e ) {
186
- return new WP_Error ( 'connection-failure', $e->getMessage (), [
187
- 'status' => 200
188
- ] );
189
- }
190
- return rest_ensure_response ( [
191
- 'message' => sprintf ( __ ( 'Connection test to Stripe was successful. Mode: %s.', 'woo-stripe-payment' ), $mode )
192
- ] );
193
- }
194
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @package Stripe/Controllers
7
+ * @author PaymentPlugins
8
+ *
9
+ */
10
+ class WC_Stripe_Controller_Gateway_Settings extends WC_Stripe_Rest_Controller {
11
+
12
+ protected $namespace = 'gateway-settings';
13
+
14
+ public function register_routes() {
15
+ register_rest_route(
16
+ $this->rest_uri(),
17
+ 'apple-domain',
18
+ array(
19
+ 'methods' => WP_REST_Server::CREATABLE,
20
+ 'callback' => array( $this, 'register_apple_domain' ),
21
+ 'permission_callback' => array(
22
+ $this,
23
+ 'admin_permission_check',
24
+ ),
25
+ )
26
+ );
27
+ register_rest_route(
28
+ $this->rest_uri(),
29
+ 'create-webook',
30
+ array(
31
+ 'methods' => WP_REST_Server::CREATABLE,
32
+ 'callback' => array( $this, 'create_webhook' ),
33
+ 'permission_callback' => array(
34
+ $this,
35
+ 'admin_permission_check',
36
+ ),
37
+ )
38
+ );
39
+ register_rest_route(
40
+ $this->rest_uri(),
41
+ 'connection-test',
42
+ array(
43
+ 'methods' => WP_REST_Server::CREATABLE,
44
+ 'callback' => array( $this, 'connection_test' ),
45
+ 'permission_callback' => array(
46
+ $this,
47
+ 'admin_permission_check',
48
+ ),
49
+ )
50
+ );
51
+ }
52
+
53
+ /**
54
+ * Register the site domain with Stripe for Apple Pay.
55
+ *
56
+ * @param WP_REST_Request $request
57
+ */
58
+ public function register_apple_domain( $request ) {
59
+ $gateway = WC_Stripe_Gateway::load();
60
+
61
+ // try to add domain association file.
62
+ if ( isset( $_SERVER['DOCUMENT_ROOT'] ) ) {
63
+ $path = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.well-known';
64
+ $file = $path . DIRECTORY_SEPARATOR . 'apple-developer-merchantid-domain-association';
65
+ if ( ! file_exists( $file ) ) {
66
+ require_once( ABSPATH . '/wp-admin/includes/file.php' );
67
+ if ( function_exists( 'WP_Filesystem' ) && ( WP_Filesystem() ) ) {
68
+ /**
69
+ *
70
+ * @var WP_Filesystem_Base $wp_filesystem
71
+ */
72
+ global $wp_filesystem;
73
+ if ( ! $wp_filesystem->is_dir( $path ) ) {
74
+ $wp_filesystem->mkdir( $path );
75
+ }
76
+ $contents = $wp_filesystem->get_contents( WC_STRIPE_PLUGIN_FILE_PATH . 'apple-developer-merchantid-domain-association' );
77
+ $wp_filesystem->put_contents( $file, $contents, 0755 );
78
+ }
79
+ }
80
+ }
81
+ $server_name = $_SERVER['SERVER_NAME'];
82
+ if ( strstr( $server_name, 'www.' ) ) {
83
+ $server_name_2 = str_replace( 'www.', '', $server_name );
84
+ } else {
85
+ $server_name_2 = 'www.' . $server_name;
86
+ }
87
+ $domains = array( $server_name, $server_name_2 );
88
+ try {
89
+ $api_key = wc_stripe_get_secret_key( 'live' );
90
+ if ( empty( $api_key ) ) {
91
+ throw new Exception( __( 'You cannot register your domain until you have configured your Live API keys.', 'woo-stripe-payment' ) );
92
+ }
93
+ // fetch the Apple domains
94
+ $registered_domains = $gateway->applePayDomains->mode( 'live' )->all( array( 'limit' => 50 ) );
95
+ if ( ! is_wp_error( $registered_domains ) && $registered_domains ) {
96
+ // loop through domains and delete if they match domain of site.
97
+ foreach ( $registered_domains->data as $domain ) {
98
+ if ( in_array( $domain->domain_name, $domains ) ) {
99
+ $gateway->applePayDomains->mode( 'live' )->delete( $domain->id );
100
+ }
101
+ }
102
+ }
103
+ $failures = 0;
104
+ foreach ( $domains as $domain ) {
105
+ $result = $gateway->applePayDomains->mode( 'live' )->create( array( 'domain_name' => $domain ) );
106
+ if ( is_wp_error( $result ) ) {
107
+ $failures ++;
108
+ if ( $failures > 1 ) {
109
+ throw new Exception( $result->get_error_message() );
110
+ }
111
+ }
112
+ }
113
+ } catch ( Exception $e ) {
114
+ return new WP_Error( 'domain-error', $e->getMessage(), array( 'status' => 200 ) );
115
+ }
116
+
117
+ return rest_ensure_response(
118
+ array(
119
+ 'message' => sprintf(
120
+ __(
121
+ 'Domain registered successfully. You can confirm in your Stripe Dashboard at https://dashboard.stripe.com/account/apple_pay.',
122
+ 'woo-stripe-payment'
123
+ )
124
+ ),
125
+ )
126
+ );
127
+ }
128
+
129
+ /**
130
+ * Create a Stripe webhook for the site.
131
+ *
132
+ * @param WP_REST_Request $request
133
+ */
134
+ public function create_webhook( $request ) {
135
+ $url = wc_stripe()->rest_api->webhook->rest_url( 'webhook' );
136
+ $api_settings = wc_stripe()->api_settings;
137
+ $env = $request->get_param( 'environment' );
138
+ $gateway = new WC_Stripe_Gateway( $env );
139
+ // first fetch all webhooks
140
+ $private_key = wc_stripe_get_secret_key( $env );
141
+ if ( empty( $private_key ) ) {
142
+ return new WP_Error(
143
+ 'webhook-error',
144
+ __( 'You must configure your secret key before creating webhooks.', 'woo-stripe-payment' ),
145
+ array(
146
+ 'status' => 200,
147
+ )
148
+ );
149
+ }
150
+ $webhooks = $gateway->webhookEndpoints->all( array( 'limit' => 100 ) );
151
+ if ( ! is_wp_error( $webhooks ) ) {
152
+ // validate that the webhook hasn't already been created.
153
+ foreach ( $webhooks->data as $webhook ) {
154
+ if ( $webhook['url'] === $url ) {
155
+ return new WP_Error(
156
+ 'webhook-error',
157
+ __( 'There is already a webhook configured for this site. If you want to delete the webhook, login to your Stripe Dashboard.', 'woo-stripe-payment' ),
158
+ array(
159
+ 'status' => 200,
160
+ )
161
+ );
162
+ }
163
+ }
164
+ }
165
+
166
+ // create the webhooks and save it to the api settings.
167
+ $webhook = $gateway->webhookEndpoints->create(
168
+ array(
169
+ 'url' => $url,
170
+ 'enabled_events' => apply_filters(
171
+ 'wc_stripe_webhook_events',
172
+ array(
173
+ 'charge.failed',
174
+ 'charge.succeeded',
175
+ 'source.chargeable',
176
+ 'payment_intent.succeeded',
177
+ )
178
+ ),
179
+ )
180
+ );
181
+ if ( is_wp_error( $webhook ) ) {
182
+ return new WP_Error( $webhook->get_error_code(), $webhook->get_error_message(), array( 'status' => 200 ) );
183
+ } else {
184
+ $api_settings->update_option( "webhook_url_{$env}", $webhook['url'] );
185
+ $api_settings->update_option( "webhook_secret_{$env}", $webhook['secret'] );
186
+ $api_settings->update_option( "webhook_id_{$env}", $webhook['id'] );
187
+
188
+ return rest_ensure_response(
189
+ array(
190
+ 'message' => sprintf(
191
+ __( 'Webhook created in Stripe for %s environment. You can test your webhook by logging in to the Stripe dashboard', 'woo-stripe-payment' ),
192
+ 'live' ==
193
+ $env ? __( 'Live', 'woo-stripe-payment' ) : __( 'Test', 'woo-stripe-payment' )
194
+ ),
195
+ 'secret' => $webhook['secret'],
196
+ )
197
+ );
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Perform a connection test
203
+ *
204
+ * @param WP_REST_Request $request
205
+ */
206
+ public function connection_test( $request ) {
207
+ $mode = $request->get_param( 'mode' );
208
+
209
+ try {
210
+ // test the secret key
211
+ $response = WC_Stripe_Gateway::load()->customers->mode( $mode )->all( array( 'limit' => 1 ) );
212
+
213
+ if ( is_wp_error( $response ) ) {
214
+ throw new Exception( sprintf( __( 'Mode: %s. Invalid secret key. Please check your entry.', 'woo-stripe-payment' ), $mode ) );
215
+ }
216
+
217
+ // test the publishable key
218
+ $response = wp_remote_post(
219
+ 'https://api.stripe.com/v1/payment_methods',
220
+ array(
221
+ 'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded' ),
222
+ 'body' => array( 'key' => wc_stripe_get_publishable_key( $mode ) ),
223
+ )
224
+ );
225
+ if ( is_wp_error( $response ) ) {
226
+ throw new Exception( sprintf( __( 'Mode: %s. Invalid publishable key. Please check your entry.', 'woo-stripe-payment' ), $mode ) );
227
+ }
228
+ if ( $response['response']['code'] == 401 ) {
229
+ throw new Exception( sprintf( __( 'Mode: %s. Invalid publishable key. Please check your entry.', 'woo-stripe-payment' ), $mode ) );
230
+ }
231
+ } catch ( Exception $e ) {
232
+ return new WP_Error( 'connection-failure', $e->getMessage(), array( 'status' => 200 ) );
233
+ }
234
+
235
+ return rest_ensure_response( array( 'message' => sprintf( __( 'Connection test to Stripe was successful. Mode: %s.', 'woo-stripe-payment' ), $mode ) ) );
236
+ }
237
+ }
includes/controllers/class-wc-stripe-controller-googlepay.php CHANGED
@@ -1,154 +1,160 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Stripe_Rest_Controller' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @author PaymentPlugins
10
- * @package Stripe/Controllers
11
- */
12
- class WC_Stripe_Controller_GooglePay extends WC_Stripe_Rest_Controller {
13
-
14
- use WC_Stripe_Controller_Cart_Trait;
15
-
16
- protected $namespace = 'googlepay';
17
-
18
- /**
19
- *
20
- * @var WC_Payment_Gateway_Stripe
21
- */
22
- private $gateway;
23
-
24
- /**
25
- *
26
- * @var string
27
- */
28
- private $shipping_method_id;
29
-
30
- /**
31
- *
32
- * @var array
33
- */
34
- private $shipping_methods = [];
35
-
36
- /**
37
- *
38
- * @var string
39
- */
40
- private $reason_code;
41
-
42
- public function register_routes() {
43
- register_rest_route ( $this->rest_uri (), 'shipping-data', [
44
- 'methods' => WP_REST_Server::CREATABLE,
45
- 'callback' => [ $this,
46
- 'update_shipping_data'
47
- ],
48
- 'args' => [
49
- 'shipping_address' => [
50
- 'required' => true
51
- ],
52
- 'shipping_methods' => [
53
- 'required' => false
54
- ],
55
- 'shipping_method_id' => [
56
- 'required' => true
57
- ]
58
- ]
59
- ] );
60
- }
61
-
62
- /**
63
- * Update the WC shipping data from the Google payment sheet.
64
- *
65
- * @param WP_REST_Request $request
66
- */
67
- public function update_shipping_data($request) {
68
- wc_maybe_define_constant ( 'WOOCOMMERCE_CART', true );
69
- $address = $request->get_param ( 'shipping_address' );
70
- $this->shipping_methods = $request->get_param ( 'shipping_methods' );
71
- $this->shipping_methods = null == $this->shipping_methods ? [] : $this->shipping_methods;
72
- $this->shipping_method_id = $request->get_param ( 'shipping_method_id' );
73
-
74
- $this->gateway = WC ()->payment_gateways ()->payment_gateways ()[ 'stripe_googlepay' ];
75
-
76
- $this->add_ready_to_calc_shipping ();
77
-
78
- try {
79
- if ('product' == $request->get_param ( 'page_id' )) {
80
- wc_stripe_stash_cart ( WC ()->cart );
81
- }
82
- wc_stripe_update_customer_location ( $address );
83
-
84
- wc_stripe_update_shipping_methods ( $this->shipping_methods );
85
-
86
- // update the WC cart with the new shipping options
87
- WC ()->cart->calculate_totals ();
88
-
89
- // if shipping address is not serviceable, throw an error.
90
- if (! wc_stripe_shipping_address_serviceable ()) {
91
- $this->reason_code = 'SHIPPING_ADDRESS_UNSERVICEABLE';
92
- throw new Exception ( __ ( 'Your shipping address is not serviceable.', 'woo-stripe-payment' ) );
93
- }
94
-
95
- $response = rest_ensure_response ( apply_filters ( 'wc_stripe_googlepay_paymentdata_response', [
96
- 'data' => [
97
- 'shipping_methods' => $this->get_shipping_methods (),
98
- 'paymentRequestUpdate' => $this->get_payment_response_data ()
99
- ]
100
- ] ) );
101
- if ('product' == $request->get_param ( 'page_id' )) {
102
- wc_stripe_restore_cart ( WC ()->cart );
103
- }
104
- return $response;
105
- } catch ( Exception $e ) {
106
- return new WP_Error ( 'payment-data-error', $e->getMessage (), [
107
- 'status' => 200,
108
- 'data' => [
109
- 'error' => [
110
- 'reason' => $this->reason_code,
111
- 'message' => $e->getMessage (),
112
- 'intent' => 'SHIPPING_ADDRESS'
113
- ]
114
- ]
115
- ] );
116
- }
117
- }
118
-
119
- /**
120
- * Return a formatted array of response data required by the Google payment sheet.
121
- */
122
- public function get_payment_response_data() {
123
- return [
124
- 'newTransactionInfo' => [
125
- 'currencyCode' => get_woocommerce_currency (),
126
- 'totalPriceStatus' => 'FINAL',
127
- 'totalPrice' => strval ( WC ()->cart->total ),
128
- 'displayItems' => $this->gateway->get_display_items (),
129
- 'totalPriceLabel' => __ ( 'Total', 'woo-stripe-payment' )
130
- ],
131
- 'newShippingOptionParameters' => [
132
- 'shippingOptions' => $this->gateway->get_shipping_methods (),
133
- 'defaultSelectedOptionId' => $this->get_default_shipping_method ()
134
- ]
135
- ];
136
- }
137
-
138
- private function get_shipping_methods() {
139
- return WC ()->session->get ( 'chosen_shipping_methods', [] );
140
- }
141
-
142
- /**
143
- * Returns a default shipping method based on the chosen shipping methods.
144
- *
145
- * @return string
146
- */
147
- private function get_default_shipping_method() {
148
- $chosen_shipping_methods = WC ()->session->get ( 'chosen_shipping_methods', [] );
149
- if (! empty ( $chosen_shipping_methods )) {
150
- return sprintf ( '%s:%s', 0, current ( $chosen_shipping_methods ) );
151
- }
152
- return $this->shipping_method_id;
153
- }
154
- }
 
 
 
 
 
 
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
+
17
+ protected $namespace = 'googlepay';
18
+
19
+ /**
20
+ *
21
+ * @var WC_Payment_Gateway_Stripe
22
+ */
23
+ private $gateway;
24
+
25
+ /**
26
+ *
27
+ * @var string
28
+ */
29
+ private $shipping_method_id;
30
+
31
+ /**
32
+ *
33
+ * @var array
34
+ */
35
+ private $shipping_methods = array();
36
+
37
+ /**
38
+ *
39
+ * @var string
40
+ */
41
+ private $reason_code;
42
+
43
+ public function register_routes() {
44
+ register_rest_route(
45
+ $this->rest_uri(),
46
+ 'shipping-data',
47
+ array(
48
+ 'methods' => WP_REST_Server::CREATABLE,
49
+ 'callback' => array( $this, 'update_shipping_data' ),
50
+ 'args' => array(
51
+ 'shipping_address' => array( 'required' => true ),
52
+ 'shipping_methods' => array( 'required' => false ),
53
+ 'shipping_method_id' => array( 'required' => true ),
54
+ ),
55
+ )
56
+ );
57
+ }
58
+
59
+ /**
60
+ * Update the WC shipping data from the Google payment sheet.
61
+ *
62
+ * @param WP_REST_Request $request
63
+ */
64
+ public function update_shipping_data( $request ) {
65
+ wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
66
+ $address = $request->get_param( 'shipping_address' );
67
+ $this->shipping_methods = $request->get_param( 'shipping_methods' );
68
+ $this->shipping_methods = null == $this->shipping_methods ? array() : $this->shipping_methods;
69
+ $this->shipping_method_id = $request->get_param( 'shipping_method_id' );
70
+
71
+ $this->gateway = WC()->payment_gateways()->payment_gateways()['stripe_googlepay'];
72
+
73
+ $this->add_ready_to_calc_shipping();
74
+
75
+ try {
76
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
77
+ wc_stripe_stash_cart( WC()->cart );
78
+ }
79
+ wc_stripe_update_customer_location( $address );
80
+
81
+ wc_stripe_update_shipping_methods( $this->shipping_methods );
82
+
83
+ // update the WC cart with the new shipping options
84
+ WC()->cart->calculate_totals();
85
+
86
+ // if shipping address is not serviceable, throw an error.
87
+ if ( ! wc_stripe_shipping_address_serviceable() ) {
88
+ $this->reason_code = 'SHIPPING_ADDRESS_UNSERVICEABLE';
89
+ throw new Exception( __( 'Your shipping address is not serviceable.', 'woo-stripe-payment' ) );
90
+ }
91
+
92
+ $response = rest_ensure_response(
93
+ apply_filters(
94
+ 'wc_stripe_googlepay_paymentdata_response',
95
+ array(
96
+ 'data' => array(
97
+ 'shipping_methods' => $this->get_shipping_methods(),
98
+ 'paymentRequestUpdate' => $this->get_payment_response_data(),
99
+ ),
100
+ )
101
+ )
102
+ );
103
+ if ( 'product' == $request->get_param( 'page_id' ) ) {
104
+ wc_stripe_restore_cart( WC()->cart );
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
+ return array(
130
+ 'newTransactionInfo' => array(
131
+ 'currencyCode' => get_woocommerce_currency(),
132
+ 'totalPriceStatus' => 'FINAL',
133
+ 'totalPrice' => strval( WC()->cart->total ),
134
+ 'displayItems' => $this->gateway->get_display_items(),
135
+ 'totalPriceLabel' => __( 'Total', 'woo-stripe-payment' ),
136
+ ),
137
+ 'newShippingOptionParameters' => array(
138
+ 'shippingOptions' => $this->gateway->get_shipping_methods(),
139
+ 'defaultSelectedOptionId' => $this->get_default_shipping_method(),
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
+ * @return string
152
+ */
153
+ private function get_default_shipping_method() {
154
+ $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods', array() );
155
+ if ( ! empty( $chosen_shipping_methods ) ) {
156
+ return sprintf( '%s:%s', 0, current( $chosen_shipping_methods ) );
157
+ }
158
+ return $this->shipping_method_id;
159
+ }
160
+ }
includes/controllers/class-wc-stripe-controller-order-actions.php CHANGED
@@ -1,300 +1,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
- protected $namespace = 'order~action';
13
-
14
- public function register_routes() {
15
- register_rest_route ( $this->rest_uri (), 'capture', array(
16
- 'methods' => WP_REST_Server::CREATABLE,
17
- 'callback' => array( $this, 'capture'
18
- ),
19
- 'permission_callback' => array( $this,
20
- 'admin_permission_check'
21
- ),
22
- 'args' => array(
23
- 'order_id' => array(
24
- 'required' => true,
25
- 'type' => 'int',
26
- 'validate_callback' => array(
27
- $this,
28
- 'validate_order_id'
29
- )
30
- ),
31
- 'amount' => array(
32
- 'required' => true,
33
- 'type' => 'float'
34
- )
35
- )
36
- ) );
37
- register_rest_route ( $this->rest_uri (), 'void', array(
38
- 'methods' => WP_REST_Server::CREATABLE,
39
- 'callback' => array( $this, 'void'
40
- ),
41
- 'permission_callback' => array( $this,
42
- 'admin_permission_check'
43
- ),
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
- register_rest_route ( $this->rest_uri (), 'pay', array(
56
- 'methods' => WP_REST_Server::CREATABLE,
57
- 'callback' => array( $this,
58
- 'process_payment'
59
- ),
60
- 'permission_callback' => array( $this,
61
- 'admin_permission_check'
62
- ),
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
- register_rest_route ( $this->rest_uri (), 'customer-payment-methods', array(
75
- 'methods' => WP_REST_Server::READABLE,
76
- 'callback' => array( $this,
77
- 'customer_payment_methods'
78
- ),
79
- 'permission_callback' => array( $this,
80
- 'admin_permission_check'
81
- ),
82
- 'args' => array(
83
- 'customer_id' => array(
84
- 'required' => true,
85
- 'type' => 'number'
86
- )
87
- )
88
- ) );
89
- register_rest_route ( $this->rest_uri (), 'charge-view', array(
90
- 'methods' => WP_REST_Server::READABLE,
91
- 'callback' => array( $this, 'charge_view'
92
- ),
93
- 'permission_callback' => array( $this,
94
- 'admin_permission_check'
95
- ),
96
- 'args' => array(
97
- 'order_id' => array(
98
- 'required' => true,
99
- 'type' => 'number'
100
- )
101
- )
102
- ) );
103
- }
104
-
105
- /**
106
- * Return true if the order_id is a valid post.
107
- *
108
- * @param int $order_id
109
- */
110
- public function validate_order_id($order_id) {
111
- return null !== get_post ( $order_id );
112
- }
113
-
114
- /**
115
- *
116
- * @param WP_REST_Request $request
117
- */
118
- public function capture($request) {
119
- $order_id = $request->get_param ( 'order_id' );
120
- $order = wc_get_order ( $order_id );
121
- $amount = $request->get_param ( 'amount' );
122
- if (! is_numeric ( $amount )) {
123
- return new WP_Error ( 'invalid_data', __ ( 'Invalid amount entered.', 'woo-stripe-payment' ), array(
124
- 'success' => false, 'status' => 200
125
- ) );
126
- }
127
- try {
128
- /**
129
- *
130
- * @var WC_Payment_Gateway_Stripe $gateway
131
- */
132
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $order->get_payment_method () ];
133
- $result = $gateway->capture_charge ( $amount, $order );
134
- if (is_wp_error ( $result )) {
135
- throw new Exception ( $result->get_error_message () );
136
- }
137
- return rest_ensure_response ( array() );
138
- } catch ( Exception $e ) {
139
- return new WP_Error ( 'capture-error', $e->getMessage (), array(
140
- 'status' => 200
141
- ) );
142
- }
143
- }
144
-
145
- /**
146
- *
147
- * @param WP_REST_Request $request
148
- */
149
- public function void($request) {
150
- $order_id = $request->get_param ( 'order_id' );
151
- $order = wc_get_order ( $order_id );
152
- /**
153
- * When the order's status is set to cancelled, the wc_stripe_order_cancelled
154
- * function is called, which voids the charge.
155
- */
156
- $order->update_status ( 'cancelled' );
157
- return rest_ensure_response ( array() );
158
- }
159
-
160
- /**
161
- * Process a payment as an admin.
162
- *
163
- * @param WP_REST_Request $request
164
- */
165
- public function process_payment($request) {
166
- $order_id = $request->get_param ( 'order_id' );
167
- $payment_type = $request->get_param ( 'payment_type' );
168
- $order = wc_get_order ( $order_id );
169
- $use_token = $payment_type === 'token';
170
- try {
171
- // perform some validations
172
- if ($order->get_total () == 0) {
173
- if (! wcs_stripe_active ()) {
174
- throw new Exception ( __ ( 'Order total must be greater than zero.', 'woo-stripe-payment' ) );
175
- } else {
176
- if (! wcs_order_contains_subscription ( $order )) {
177
- throw new Exception ( __ ( 'Order total must be greater than zero.', 'woo-stripe-payment' ) );
178
- }
179
- }
180
- }
181
- // update the order's customer ID if it has changed.
182
- if ($order->get_customer_id () != $request->get_param ( 'customer_id' )) {
183
- $order->set_customer_id ( $request->get_param ( 'customer_id' ) );
184
- }
185
-
186
- if ($order->get_transaction_id ()) {
187
- throw new Exception ( sprintf ( __ ( 'This order has already been processed. Transaction ID: %s. Payment method: %s', 'woo-stripe-payment' ), $order->get_transaction_id (), $order->get_payment_method_title () ) );
188
- }
189
- if (! $use_token) {
190
- // only credit card payments are allowed for one off payments as an admin.
191
- $payment_method = 'stripe_cc';
192
- } else if ($payment_type === 'token') {
193
- $token_id = intval ( $request->get_param ( 'payment_token_id' ) );
194
- $token = WC_Payment_Tokens::get ( $token_id );
195
- if ($token->get_user_id () !== $order->get_customer_id ()) {
196
- throw new Exception ( __ ( 'Order customer Id and payment method customer Id do not match.', 'woo-stripe-payment' ) );
197
- }
198
- $payment_method = $token->get_gateway_id ();
199
- }
200
- /**
201
- *
202
- * @var WC_Payment_Gateway_Stripe $gateway
203
- */
204
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $payment_method ];
205
- // temporarily set the charge type of the gateway to whatever the admin has selected.
206
- $gateway->settings[ 'charge_type' ] = $request->get_param ( 'wc_stripe_charge_type' );
207
- // set the payment gateway to the order.
208
- $order->set_payment_method ( $gateway->id );
209
- $order->save ();
210
- if (! $use_token) {
211
- $_POST[ $gateway->token_key ] = $request->get_param ( 'payment_nonce' );
212
- } else {
213
- $gateway->set_payment_method_token ( $token->get_token () );
214
- }
215
-
216
- // set intent attribute off_session. Stripe requires confirm to be true to use off session.
217
- add_filter ( 'wc_stripe_payment_intent_args', function ($args) {
218
- $args[ 'confirm' ] = true;
219
- $args[ 'off_session' ] = true;
220
- return $args;
221
- } );
222
-
223
- $result = $gateway->process_payment ( $order_id );
224
-
225
- if (isset ( $result[ 'result' ] ) && $result[ 'result' ] === 'success') {
226
- return rest_ensure_response ( array(
227
- 'success' => true
228
- ) );
229
- } else {
230
- // create a new order since updates to the order were made during the process_payment call.
231
- $order = wc_get_order ( $order_id );
232
- $order->update_status ( 'pending' );
233
- return new WP_Error ( 'order-error', $this->get_error_messages (), [
234
- 'status' => 200, 'success' => false
235
- ] );
236
- }
237
- } catch ( Exception $e ) {
238
- return new WP_Error ( 'order-error', '<div class="woocommerce-error">' . $e->getMessage () . '</div>', [
239
- 'status' => 200
240
- ] );
241
- }
242
- }
243
-
244
- /**
245
- *
246
- * @param WP_REST_Request $request
247
- */
248
- public function customer_payment_methods($request) {
249
- $customer_id = $request->get_param ( 'customer_id' );
250
- $tokens = array();
251
- foreach ( WC ()->payment_gateways ()->payment_gateways () as $gateway ) {
252
- if ($gateway instanceof WC_Payment_Gateway_Stripe) {
253
- $tokens = array_merge ( $tokens, WC_Payment_Tokens::get_customer_tokens ( $customer_id, $gateway->id ) );
254
- }
255
- }
256
- return rest_ensure_response ( array(
257
- 'payment_methods' => array_map ( function ($payment_method) {
258
- return $payment_method->to_json ();
259
- }, $tokens )
260
- ) );
261
- }
262
-
263
- /**
264
- *
265
- * @param WP_REST_Request $request
266
- */
267
- public function charge_view($request) {
268
- $order = wc_get_order ( absint ( $request->get_param ( 'order_id' ) ) );
269
- /**
270
- *
271
- * @var WC_Payment_Gateway_Stripe $gateway
272
- */
273
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $order->get_payment_method () ];
274
- try {
275
- // fetch the charge so data is up to date.
276
- $charge = $gateway->retrieve_charge ( $order->get_transaction_id (), wc_stripe_order_mode ( $order ) );
277
-
278
- if (is_wp_error ( $charge )) {
279
- throw new Exception ( $charge->get_error_message () );
280
- }
281
- $order->update_meta_data ( WC_Stripe_Constants::CHARGE_STATUS, $charge->status );
282
- $order->save ();
283
- ob_start ();
284
- include wc_stripe ()->plugin_path () . 'includes/admin/meta-boxes/views/html-charge-data-subview.php';
285
- $html = ob_get_clean ();
286
- return rest_ensure_response ( array(
287
- 'data' => array(
288
- 'order_id' => $order->get_id (),
289
- 'order_number' => $order->get_order_number (),
290
- 'charge' => $charge->jsonSerialize (),
291
- 'html' => $html
292
- )
293
- ) );
294
- } catch ( Exception $e ) {
295
- return new WP_Error ( 'charge-error', $e->getMessage (), array(
296
- 'status' => 200
297
- ) );
298
- }
299
- }
300
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ protected $namespace = 'order~action';
13
+
14
+ public function register_routes() {
15
+ register_rest_route(
16
+ $this->rest_uri(),
17
+ 'capture',
18
+ array(
19
+ 'methods' => WP_REST_Server::CREATABLE,
20
+ 'callback' => array( $this, 'capture' ),
21
+ 'permission_callback' => array( $this, 'admin_permission_check' ),
22
+ 'args' => array(
23
+ 'order_id' => array(
24
+ 'required' => true,
25
+ 'type' => 'int',
26
+ 'validate_callback' => array( $this, 'validate_order_id' ),
27
+ ),
28
+ 'amount' => array(
29
+ 'required' => true,
30
+ 'type' => 'float',
31
+ ),
32
+ ),
33
+ )
34
+ );
35
+ register_rest_route(
36
+ $this->rest_uri(),
37
+ 'void',
38
+ array(
39
+ 'methods' => WP_REST_Server::CREATABLE,
40
+ 'callback' => array( $this, 'void' ),
41
+ 'permission_callback' => array( $this, 'admin_permission_check' ),
42
+ 'args' => array(
43
+ 'order_id' => array(
44
+ 'required' => true,
45
+ 'type' => 'number',
46
+ 'validate_callback' => array(
47
+ $this,
48
+ 'validate_order_id',
49
+ ),
50
+ ),
51
+ ),
52
+ )
53
+ );
54
+ register_rest_route(
55
+ $this->rest_uri(),
56
+ 'pay',
57
+ array(
58
+ 'methods' => WP_REST_Server::CREATABLE,
59
+ 'callback' => array( $this, 'process_payment' ),
60
+ 'permission_callback' => array( $this, 'admin_permission_check' ),
61
+ 'args' => array(
62
+ 'order_id' => array(
63
+ 'required' => true,
64
+ 'type' => 'number',
65
+ 'validate_callback' => array(
66
+ $this,
67
+ 'validate_order_id',
68
+ ),
69
+ ),
70
+ ),
71
+ )
72
+ );
73
+ register_rest_route(
74
+ $this->rest_uri(),
75
+ 'customer-payment-methods',
76
+ array(
77
+ 'methods' => WP_REST_Server::READABLE,
78
+ 'callback' => array( $this, 'customer_payment_methods' ),
79
+ 'permission_callback' => array( $this, 'admin_permission_check' ),
80
+ 'args' => array(
81
+ 'customer_id' => array(
82
+ 'required' => true,
83
+ 'type' => 'number',
84
+ ),
85
+ ),
86
+ )
87
+ );
88
+ register_rest_route(
89
+ $this->rest_uri(),
90
+ 'charge-view',
91
+ array(
92
+ 'methods' => WP_REST_Server::READABLE,
93
+ 'callback' => array( $this, 'charge_view' ),
94
+ 'permission_callback' => array( $this, 'admin_permission_check' ),
95
+ 'args' => array(
96
+ 'order_id' => array(
97
+ 'required' => true,
98
+ 'type' => 'number',
99
+ ),
100
+ ),
101
+ )
102
+ );
103
+ }
104
+
105
+ /**
106
+ * Return true if the order_id is a valid post.
107
+ *
108
+ * @param int $order_id
109
+ */
110
+ public function validate_order_id( $order_id ) {
111
+ return null !== get_post( $order_id );
112
+ }
113
+
114
+ /**
115
+ *
116
+ * @param WP_REST_Request $request
117
+ */
118
+ public function capture( $request ) {
119
+ $order_id = $request->get_param( 'order_id' );
120
+ $order = wc_get_order( $order_id );
121
+ $amount = $request->get_param( 'amount' );
122
+ if ( ! is_numeric( $amount ) ) {
123
+ return new WP_Error(
124
+ 'invalid_data',
125
+ __( 'Invalid amount entered.', 'woo-stripe-payment' ),
126
+ array(
127
+ 'success' => false,
128
+ 'status' => 200,
129
+ )
130
+ );
131
+ }
132
+ try {
133
+ /**
134
+ *
135
+ * @var WC_Payment_Gateway_Stripe $gateway
136
+ */
137
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
138
+ $result = $gateway->capture_charge( $amount, $order );
139
+ if ( is_wp_error( $result ) ) {
140
+ throw new Exception( $result->get_error_message() );
141
+ }
142
+
143
+ return rest_ensure_response( array() );
144
+ } catch ( Exception $e ) {
145
+ return new WP_Error( 'capture-error', $e->getMessage(), array( 'status' => 200 ) );
146
+ }
147
+ }
148
+
149
+ /**
150
+ *
151
+ * @param WP_REST_Request $request
152
+ */
153
+ public function void( $request ) {
154
+ $order_id = $request->get_param( 'order_id' );
155
+ $order = wc_get_order( $order_id );
156
+ /**
157
+ * When the order's status is set to cancelled, the wc_stripe_order_cancelled
158
+ * function is called, which voids the charge.
159
+ */
160
+ $order->update_status( 'cancelled' );
161
+
162
+ return rest_ensure_response( array() );
163
+ }
164
+
165
+ /**
166
+ * Process a payment as an admin.
167
+ *
168
+ * @param WP_REST_Request $request
169
+ */
170
+ public function process_payment( $request ) {
171
+ $order_id = $request->get_param( 'order_id' );
172
+ $payment_type = $request->get_param( 'payment_type' );
173
+ $order = wc_get_order( $order_id );
174
+ $use_token = $payment_type === 'token';
175
+ try {
176
+ // perform some validations
177
+ if ( $order->get_total() == 0 ) {
178
+ if ( ! wcs_stripe_active() ) {
179
+ throw new Exception( __( 'Order total must be greater than zero.', 'woo-stripe-payment' ) );
180
+ } else {
181
+ if ( ! wcs_order_contains_subscription( $order ) ) {
182
+ throw new Exception( __( 'Order total must be greater than zero.', 'woo-stripe-payment' ) );
183
+ }
184
+ }
185
+ }
186
+ // update the order's customer ID if it has changed.
187
+ if ( $order->get_customer_id() != $request->get_param( 'customer_id' ) ) {
188
+ $order->set_customer_id( $request->get_param( 'customer_id' ) );
189
+ }
190
+
191
+ if ( $order->get_transaction_id() ) {
192
+ 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() ) );
193
+ }
194
+ if ( ! $use_token ) {
195
+ // only credit card payments are allowed for one off payments as an admin.
196
+ $payment_method = 'stripe_cc';
197
+ } elseif ( $payment_type === 'token' ) {
198
+ $token_id = intval( $request->get_param( 'payment_token_id' ) );
199
+ $token = WC_Payment_Tokens::get( $token_id );
200
+ if ( $token->get_user_id() !== $order->get_customer_id() ) {
201
+ throw new Exception( __( 'Order customer Id and payment method customer Id do not match.', 'woo-stripe-payment' ) );
202
+ }
203
+ $payment_method = $token->get_gateway_id();
204
+ }
205
+ /**
206
+ *
207
+ * @var WC_Payment_Gateway_Stripe $gateway
208
+ */
209
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $payment_method ];
210
+ // temporarily set the charge type of the gateway to whatever the admin has selected.
211
+ $gateway->settings['charge_type'] = $request->get_param( 'wc_stripe_charge_type' );
212
+ // set the payment gateway to the order.
213
+ $order->set_payment_method( $gateway->id );
214
+ $order->save();
215
+ if ( ! $use_token ) {
216
+ $_POST[ $gateway->token_key ] = $request->get_param( 'payment_nonce' );
217
+ } else {
218
+ $gateway->set_payment_method_token( $token->get_token() );
219
+ }
220
+
221
+ // set intent attribute off_session. Stripe requires confirm to be true to use off session.
222
+ add_filter(
223
+ 'wc_stripe_payment_intent_args',
224
+ function ( $args ) {
225
+ $args['confirm'] = true;
226
+ $args['off_session'] = true;
227
+
228
+ return $args;
229
+ }
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
+ }
includes/controllers/class-wc-stripe-controller-payment-intent.php CHANGED
@@ -1,88 +1,89 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- * Controller which handles Payment Intent related actions such as creation.
6
- *
7
- * @author PaymentPlugins
8
- * @package Stripe/Controllers
9
- *
10
- */
11
- class WC_Stripe_Controller_Payment_Intent extends WC_Stripe_Rest_Controller {
12
-
13
- protected $namespace = '';
14
-
15
- public function register_routes() {
16
- register_rest_route ( $this->rest_uri (), 'setup-intent', array(
17
- 'methods' => WP_REST_Server::READABLE,
18
- 'callback' => array( $this,
19
- 'create_setup_intent'
20
- )
21
- ) );
22
- register_rest_route ( $this->rest_uri (), 'sync-payment-intent', [
23
- 'methods' => WP_REST_Server::CREATABLE,
24
- 'callback' => array( $this,
25
- 'sync_payment_intent'
26
- ),
27
- 'args' => [
28
- 'order_id' => [
29
- 'required' => true
30
- ],
31
- 'client_secret' => [
32
- 'required' => true
33
- ]
34
- ]
35
- ] );
36
- }
37
-
38
- /**
39
- *
40
- * @param WP_REST_Request $request
41
- */
42
- public function create_setup_intent($request) {
43
- $intent = WC_Stripe_Gateway::load ()->create_setup_intent ( array(
44
- 'usage' => 'off_session'
45
- ) );
46
- try {
47
- if (is_wp_error ( $intent )) {
48
- throw new Exception ( $result->get_error_message () );
49
- }
50
- return rest_ensure_response ( array(
51
- 'intent' => array(
52
- 'client_secret' => $intent->client_secret
53
- )
54
- ) );
55
- } catch ( Exception $e ) {
56
- return new WP_Error ( 'payment-intent-error', sprintf ( __ ( 'Error creating payment intent. Reason: %s', 'woo-stripe-payment' ), $e->getMessage () ), array(
57
- 'status' => 200
58
- ) );
59
- }
60
- }
61
-
62
- /**
63
- *
64
- * @param WP_REST_Request $request
65
- */
66
- public function sync_payment_intent($request) {
67
- try {
68
- $order = wc_get_order ( absint ( $request->get_param ( 'order_id' ) ) );
69
- if (! $order) {
70
- throw new Exception ( __ ( 'Invalid order id provided', 'woo-stripe-payment' ) );
71
- }
72
-
73
- $intent = WC_Stripe_Gateway::load ()->fetch_payment_intent ( $order->get_meta ( WC_Stripe_Constants::PAYMENT_INTENT_ID ) );
74
-
75
- if ($intent->client_secret != $request->get_param ( 'client_secret' )) {
76
- throw new Exception ( __ ( 'You are not authorized to update this order.', 'woo-stripe-payment' ) );
77
- }
78
-
79
- $order->update_meta_data ( WC_Stripe_Constants::PAYMENT_INTENT, $intent->jsonSerialize () );
80
- $order->save ();
81
- return rest_ensure_response ( [] );
82
- } catch ( Exception $e ) {
83
- return new WP_Error ( 'payment-intent-error', $e->getMessage (), [
84
- 'status' => 200
85
- ] );
86
- }
87
- }
88
- }
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * Controller which handles Payment Intent related actions such as creation.
6
+ *
7
+ * @author PaymentPlugins
8
+ * @package Stripe/Controllers
9
+ *
10
+ */
11
+ class WC_Stripe_Controller_Payment_Intent extends WC_Stripe_Rest_Controller {
12
+
13
+ protected $namespace = '';
14
+
15
+ public function register_routes() {
16
+ register_rest_route(
17
+ $this->rest_uri(),
18
+ 'setup-intent',
19
+ array(
20
+ 'methods' => WP_REST_Server::READABLE,
21
+ 'callback' => array(
22
+ $this,
23
+ 'create_setup_intent',
24
+ ),
25
+ )
26
+ );
27
+ register_rest_route(
28
+ $this->rest_uri(),
29
+ 'sync-payment-intent',
30
+ array(
31
+ 'methods' => WP_REST_Server::CREATABLE,
32
+ 'callback' => array( $this, 'sync_payment_intent' ),
33
+ 'args' => array(
34
+ 'order_id' => array( 'required' => true ),
35
+ 'client_secret' => array( 'required' => true ),
36
+ ),
37
+ )
38
+ );
39
+ }
40
+
41
+ /**
42
+ *
43
+ * @param WP_REST_Request $request
44
+ */
45
+ public function create_setup_intent( $request ) {
46
+ $intent = WC_Stripe_Gateway::load()->setupIntents->create( array( 'usage' => 'off_session' ) );
47
+ try {
48
+ if ( is_wp_error( $intent ) ) {
49
+ throw new Exception( $result->get_error_message() );
50
+ }
51
+
52
+ return rest_ensure_response( array( 'intent' => array( 'client_secret' => $intent->client_secret ) ) );
53
+ } catch ( Exception $e ) {
54
+ return new WP_Error(
55
+ 'payment-intent-error',
56
+ sprintf( __( 'Error creating payment intent. Reason: %s', 'woo-stripe-payment' ), $e->getMessage() ),
57
+ array(
58
+ 'status' => 200,
59
+ )
60
+ );
61
+ }
62
+ }
63
+
64
+ /**
65
+ *
66
+ * @param WP_REST_Request $request
67
+ */
68
+ public function sync_payment_intent( $request ) {
69
+ try {
70
+ $order = wc_get_order( absint( $request->get_param( 'order_id' ) ) );
71
+ if ( ! $order ) {
72
+ throw new Exception( __( 'Invalid order id provided', 'woo-stripe-payment' ) );
73
+ }
74
+
75
+ $intent = WC_Stripe_Gateway::load()->paymentIntents->retrieve( $order->get_meta( WC_Stripe_Constants::PAYMENT_INTENT_ID ) );
76
+
77
+ if ( ! hash_equals( $intent->client_secret, $request->get_param( 'client_secret' ) ) ) {
78
+ throw new Exception( __( 'You are not authorized to update this order.', 'woo-stripe-payment' ) );
79
+ }
80
+
81
+ $order->update_meta_data( WC_Stripe_Constants::PAYMENT_INTENT, $intent->jsonSerialize() );
82
+ $order->save();
83
+
84
+ return rest_ensure_response( array() );
85
+ } catch ( Exception $e ) {
86
+ return new WP_Error( 'payment-intent-error', $e->getMessage(), array( 'status' => 200 ) );
87
+ }
88
+ }
89
+ }
includes/controllers/class-wc-stripe-controller-payment-method.php CHANGED
@@ -1,49 +1,52 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @package Stripe/Controllers
7
- * @author PaymentPlugins
8
- * @since 3.0.0
9
- *
10
- */
11
- class WC_Stripe_Controller_Payment_Method extends WC_Stripe_Rest_Controller {
12
-
13
- protected $namespace = 'payment-method';
14
-
15
- public function register_routes() {
16
- register_rest_route ( $this->rest_uri (), 'token', [
17
- 'methods' => WP_REST_Server::CREATABLE,
18
- 'callback' => [ $this,
19
- 'payment_method_from_token'
20
- ]
21
- ] );
22
- }
23
-
24
- /**
25
- * Creates a PaymentMethod from a Token.
26
- * Use case for this controller would be if a token
27
- * is provided on the client side, but PaymentIntent is desired instead of a Charge. The token must be converted to
28
- * a PaymentMethod for use in a PaymentIntent.
29
- *
30
- * @param WP_REST_Request $request
31
- * @return WP_Error|WP_REST_Response|mixed
32
- */
33
- public function payment_method_from_token($request) {
34
- $result = WC_Stripe_Gateway::load ()->create_payment_method ( [
35
- 'type' => 'card',
36
- 'card' => [
37
- 'token' => $request->get_param ( 'token' )
38
- ]
39
- ] );
40
- if (is_wp_error ( $result )) {
41
- return new WP_Error ( 'payment-method', $result->get_error_message (), [
42
- 'status' => 200
43
- ] );
44
- }
45
- return rest_ensure_response ( [
46
- 'payment_method' => $result->jsonSerialize ()
47
- ] );
48
- }
49
- }
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @package Stripe/Controllers
7
+ * @author PaymentPlugins
8
+ * @since 3.0.0
9
+ *
10
+ */
11
+ class WC_Stripe_Controller_Payment_Method extends WC_Stripe_Rest_Controller {
12
+
13
+ protected $namespace = 'payment-method';
14
+
15
+ public function register_routes() {
16
+ register_rest_route(
17
+ $this->rest_uri(),
18
+ 'token',
19
+ array(
20
+ 'methods' => WP_REST_Server::CREATABLE,
21
+ 'callback' => array(
22
+ $this,
23
+ 'payment_method_from_token',
24
+ ),
25
+ )
26
+ );
27
+ }
28
+
29
+ /**
30
+ * Creates a PaymentMethod from a Token.
31
+ * Use case for this controller would be if a token
32
+ * is provided on the client side, but PaymentIntent is desired instead of a Charge. The token must be converted to
33
+ * a PaymentMethod for use in a PaymentIntent.
34
+ *
35
+ * @param WP_REST_Request $request
36
+ *
37
+ * @return WP_Error|WP_REST_Response|mixed
38
+ */
39
+ public function payment_method_from_token( $request ) {
40
+ $result = WC_Stripe_Gateway::load()->paymentMethods->create(
41
+ array(
42
+ 'type' => 'card',
43
+ 'card' => array( 'token' => $request->get_param( 'token' ) ),
44
+ )
45
+ );
46
+ if ( is_wp_error( $result ) ) {
47
+ return new WP_Error( 'payment-method', $result->get_error_message(), array( 'status' => 200 ) );
48
+ }
49
+
50
+ return rest_ensure_response( array( 'payment_method' => $result->jsonSerialize() ) );
51
+ }
52
+ }
includes/controllers/class-wc-stripe-controller-product-data.php CHANGED
@@ -1,79 +1,83 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.1.2
7
- * @author PaymentPlugins
8
- * @package Stripe/Controllers
9
- *
10
- */
11
- class WC_Stripe_Controller_Product_Data extends WC_Stripe_Rest_Controller {
12
-
13
- protected $namespace = 'product';
14
-
15
- public function register_routes() {
16
- register_rest_route ( $this->rest_uri (), 'gateway', [
17
- 'methods' => WP_REST_Server::CREATABLE,
18
- 'callback' => [ $this, 'toggle_gateway'
19
- ],
20
- 'permission_callback' => [ $this,
21
- 'admin_permission_check'
22
- ]
23
- ] );
24
- register_rest_route ( $this->rest_uri (), 'save', [
25
- 'methods' => WP_REST_Server::CREATABLE,
26
- 'callback' => [ $this, 'save'
27
- ],
28
- 'permission_callback' => [ $this,
29
- 'admin_permission_check'
30
- ]
31
- ] );
32
- }
33
-
34
- /**
35
- *
36
- * @param WP_REST_Request $request
37
- */
38
- public function toggle_gateway($request) {
39
- $product = wc_get_product ( $request->get_param ( 'product_id' ) );
40
- $payment_method = WC ()->payment_gateways ()->payment_gateways ()[ $request->get_param ( 'gateway_id' ) ];
41
-
42
- $option = new WC_Stripe_Product_Gateway_Option ( $product, $payment_method );
43
- $option->set_option ( 'enabled', ! $option->enabled () );
44
- $option->save ();
45
- return rest_ensure_response ( [
46
- 'enabled' => $option->enabled ()
47
- ] );
48
- }
49
-
50
- /**
51
- *
52
- * @param WP_REST_Request $request
53
- */
54
- public function save($request) {
55
- $gateways = $request->get_param ( 'gateways' );
56
- $charge_types = $request->get_param ( 'charge_types' );
57
- $payment_gateways = WC ()->payment_gateways ()->payment_gateways ();
58
- $product = wc_get_product ( $request->get_param ( 'product_id' ) );
59
- $order = [];
60
- $loop = 0;
61
- foreach ( $gateways as $gateway ) {
62
- $order[ $gateway ] = $loop;
63
- $loop ++;
64
- }
65
- $product->update_meta_data ( WC_Stripe_Constants::PRODUCT_GATEWAY_ORDER, $order );
66
-
67
- foreach ( $charge_types as $type ) {
68
- $option = new WC_Stripe_Product_Gateway_Option ( $product, $payment_gateways[ $type[ 'gateway' ] ] );
69
- $option->set_option ( 'charge_type', $type[ 'value' ] );
70
- $option->save ();
71
- }
72
- $product->update_meta_data ( '_stripe_button_position', $request->get_param ( 'position' ) );
73
-
74
- $product->save ();
75
- return rest_ensure_response ( [
76
- 'order' => $order
77
- ] );
78
- }
79
- }
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @since 3.1.2
7
+ * @author PaymentPlugins
8
+ * @package Stripe/Controllers
9
+ *
10
+ */
11
+ class WC_Stripe_Controller_Product_Data extends WC_Stripe_Rest_Controller {
12
+
13
+ protected $namespace = 'product';
14
+
15
+ public function register_routes() {
16
+ register_rest_route(
17
+ $this->rest_uri(),
18
+ 'gateway',
19
+ array(
20
+ 'methods' => WP_REST_Server::CREATABLE,
21
+ 'callback' => array( $this, 'toggle_gateway' ),
22
+ 'permission_callback' => array(
23
+ $this,
24
+ 'admin_permission_check',
25
+ ),
26
+ )
27
+ );
28
+ register_rest_route(
29
+ $this->rest_uri(),
30
+ 'save',
31
+ array(
32
+ 'methods' => WP_REST_Server::CREATABLE,
33
+ 'callback' => array( $this, 'save' ),
34
+ 'permission_callback' => array(
35
+ $this,
36
+ 'admin_permission_check',
37
+ ),
38
+ )
39
+ );
40
+ }
41
+
42
+ /**
43
+ *
44
+ * @param WP_REST_Request $request
45
+ */
46
+ public function toggle_gateway( $request ) {
47
+ $product = wc_get_product( $request->get_param( 'product_id' ) );
48
+ $payment_method = WC()->payment_gateways()->payment_gateways()[ $request->get_param( 'gateway_id' ) ];
49
+
50
+ $option = new WC_Stripe_Product_Gateway_Option( $product, $payment_method );
51
+ $option->set_option( 'enabled', ! $option->enabled() );
52
+ $option->save();
53
+ return rest_ensure_response( array( 'enabled' => $option->enabled() ) );
54
+ }
55
+
56
+ /**
57
+ *
58
+ * @param WP_REST_Request $request
59
+ */
60
+ public function save( $request ) {
61
+ $gateways = $request->get_param( 'gateways' );
62
+ $charge_types = $request->get_param( 'charge_types' );
63
+ $payment_gateways = WC()->payment_gateways()->payment_gateways();
64
+ $product = wc_get_product( $request->get_param( 'product_id' ) );
65
+ $order = array();
66
+ $loop = 0;
67
+ foreach ( $gateways as $gateway ) {
68
+ $order[ $gateway ] = $loop;
69
+ $loop++;
70
+ }
71
+ $product->update_meta_data( WC_Stripe_Constants::PRODUCT_GATEWAY_ORDER, $order );
72
+
73
+ foreach ( $charge_types as $type ) {
74
+ $option = new WC_Stripe_Product_Gateway_Option( $product, $payment_gateways[ $type['gateway'] ] );
75
+ $option->set_option( 'charge_type', $type['value'] );
76
+ $option->save();
77
+ }
78
+ $product->update_meta_data( '_stripe_button_position', $request->get_param( 'position' ) );
79
+
80
+ $product->save();
81
+ return rest_ensure_response( array( 'order' => $order ) );
82
+ }
83
+ }
includes/controllers/class-wc-stripe-controller-webhook.php CHANGED
@@ -1,58 +1,62 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @package Stripe/Controllers
8
- *
9
- */
10
- class WC_Stripe_Controller_Webhook extends WC_Stripe_Rest_Controller {
11
-
12
- protected $namespace = '';
13
-
14
- private $secret;
15
-
16
- public function register_routes() {
17
- register_rest_route ( $this->rest_uri (), 'webhook', [
18
- 'methods' => WP_REST_Server::CREATABLE,
19
- 'callback' => [ $this, 'webhook'
20
- ]
21
- ] );
22
- }
23
-
24
- /**
25
- *
26
- * @param WP_REST_Request $request
27
- */
28
- public function webhook($request) {
29
- $payload = $request->get_body ();
30
- $json_payload = json_decode ( $payload, true );
31
- $mode = $json_payload[ 'livemode' ] == true ? 'live' : 'test';
32
- $this->secret = wc_stripe ()->api_settings->get_option ( 'webhook_secret_' . $mode );
33
- $header = isset ( $_SERVER[ 'HTTP_STRIPE_SIGNATURE' ] ) ? $_SERVER[ 'HTTP_STRIPE_SIGNATURE' ] : '';
34
- try {
35
- $event = \Stripe\Webhook::constructEvent ( $payload, $header, $this->secret );
36
- // $event = \Stripe\StripeObject::constructFrom(json_decode($payload, true));
37
- wc_stripe_log_info ( sprintf ( 'Webhook notficiation received: Event: %s. Payload: %s', $event->type, print_r ( $payload, true ) ) );
38
- $type = $event->type;
39
- $type = str_replace ( '.', '_', $type );
40
-
41
- // allow functionality to hook in to the event action
42
- do_action ( 'wc_stripe_webhook_' . $type, $event->data->object, $request, $event );
43
-
44
- return rest_ensure_response ( apply_filters ( 'wc_stripe_webhook_response', [], $event, $request ) );
45
- } catch ( \Stripe\Error\SignatureVerification $e ) {
46
- wc_stripe_log_info ( __ ( 'Invalid signature received. Verify that your webhook secret is correct.', 'woo-stripe-payment' ) );
47
- return $this->send_error_response ( __ ( 'Invalid signature received. Verify that your webhook secret is correct.', 'woo-stripe-payment' ), 401 );
48
- } catch ( Exception $e ) {
49
- return $this->send_error_response ( $e->getMessage () );
50
- }
51
- }
52
-
53
- private function send_error_response($message, $code = 400) {
54
- return new WP_Error ( 'webhook-error', $message, [
55
- 'status' => $code
56
- ] );
57
- }
58
- }
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @package Stripe/Controllers
8
+ *
9
+ */
10
+ class WC_Stripe_Controller_Webhook extends WC_Stripe_Rest_Controller {
11
+
12
+ protected $namespace = '';
13
+
14
+ private $secret;
15
+
16
+ public function register_routes() {
17
+ register_rest_route(
18
+ $this->rest_uri(),
19
+ 'webhook',
20
+ array(
21
+ 'methods' => WP_REST_Server::CREATABLE,
22
+ 'callback' => array(
23
+ $this,
24
+ 'webhook',
25
+ ),
26
+ )
27
+ );
28
+ }
29
+
30
+ /**
31
+ *
32
+ * @param WP_REST_Request $request
33
+ */
34
+ public function webhook( $request ) {
35
+ $payload = $request->get_body();
36
+ $json_payload = json_decode( $payload, true );
37
+ $mode = $json_payload['livemode'] == true ? 'live' : 'test';
38
+ $this->secret = wc_stripe()->api_settings->get_option( 'webhook_secret_' . $mode );
39
+ $header = isset( $_SERVER['HTTP_STRIPE_SIGNATURE'] ) ? $_SERVER['HTTP_STRIPE_SIGNATURE'] : '';
40
+ try {
41
+ $event = \Stripe\Webhook::constructEvent( $payload, $header, $this->secret );
42
+ // $event = \Stripe\StripeObject::constructFrom(json_decode($payload, true));
43
+ wc_stripe_log_info( sprintf( 'Webhook notification received: Event: %s. Payload: %s', $event->type, print_r( $payload, true ) ) );
44
+ $type = $event->type;
45
+ $type = str_replace( '.', '_', $type );
46
+
47
+ // allow functionality to hook in to the event action
48
+ do_action( 'wc_stripe_webhook_' . $type, $event->data->object, $request, $event );
49
+
50
+ return rest_ensure_response( apply_filters( 'wc_stripe_webhook_response', array(), $event, $request ) );
51
+ } catch ( \Stripe\Error\SignatureVerification $e ) {
52
+ wc_stripe_log_info( __( 'Invalid signature received. Verify that your webhook secret is correct.', 'woo-stripe-payment' ) );
53
+ return $this->send_error_response( __( 'Invalid signature received. Verify that your webhook secret is correct.', 'woo-stripe-payment' ), 401 );
54
+ } catch ( Exception $e ) {
55
+ return $this->send_error_response( $e->getMessage() );
56
+ }
57
+ }
58
+
59
+ private function send_error_response( $message, $code = 400 ) {
60
+ return new WP_Error( 'webhook-error', $message, array( 'status' => $code ) );
61
+ }
62
+ }
includes/gateways/class-wc-payment-gateway-stripe-ach-v2.php DELETED
@@ -1,233 +0,0 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- * Gateway that processes ACH payments.
6
- * Only available for U.S. based merchants at this time.
7
- *
8
- * @since 3.0.5
9
- * @author Payment Plugins
10
- * @package Stripe/Gateways
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_ACH_V2 extends WC_Payment_Gateway_Stripe {
14
-
15
- use WC_Stripe_Payment_Charge_Trait;
16
-
17
- /**
18
- *
19
- * @var object
20
- */
21
- public $metadata_key = '';
22
-
23
- public function __construct() {
24
- $this->synchronous = false;
25
- $this->id = 'stripe_ach';
26
- $this->tab_title = __ ( 'ACH', 'woo-stripe-payment' );
27
- $this->template_name = 'ach.php';
28
- $this->token_type = 'Stripe_ACH';
29
- $this->method_title = __ ( 'Stripe ACH', 'woo-stripe-payment' );
30
- $this->method_description = __ ( 'ACH gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
31
- $this->icon = wc_stripe ()->assets_url ( 'img/ach.svg' );
32
- $this->order_button_text = __ ( 'Bank Payment', 'woo-stripe-payment' );
33
- $this->metadata_key = $this->id . '_metadata';
34
- parent::__construct ();
35
- $this->settings[ 'charge_type' ] = 'capture';
36
- }
37
-
38
- public function get_payment_object() {
39
- return new WC_Stripe_Payment_Charge ( $this, new WC_Stripe_Gateway_ACH () );
40
- }
41
-
42
- public static function init() {
43
- add_action ( 'woocommerce_checkout_update_order_review', [
44
- __CLASS__, 'update_order_review'
45
- ] );
46
- }
47
-
48
- /**
49
- *
50
- * {@inheritDoc}
51
- *
52
- * @see WC_Payment_Gateway::is_available()
53
- */
54
- public function is_available() {
55
- $is_available = parent::is_available ();
56
- return $is_available && get_woocommerce_currency () == 'USD';
57
- }
58
-
59
- /**
60
- *
61
- * {@inheritDoc}
62
- *
63
- * @see WC_Payment_Gateway_Stripe::init_supports()
64
- */
65
- public function init_supports() {
66
- /*
67
- * $this->supports = [ 'tokenization', 'products',
68
- * 'refunds'
69
- * ];
70
- */
71
- parent::init_supports ();
72
- unset ( $this->supports[ 'add_payment_method' ] );
73
- }
74
-
75
- /**
76
- *
77
- * {@inheritDoc}
78
- *
79
- * @see WC_Payment_Gateway_Stripe::enqueue_checkout_scripts()
80
- */
81
- public function enqueue_checkout_scripts($scripts) {
82
- $scripts->enqueue_script ( 'ach', $scripts->assets_url ( 'js/frontend/ach-payments.js' ), array(
83
- $scripts->get_handle ( 'external' ),
84
- $scripts->get_handle ( 'plaid' )
85
- ) );
86
- $scripts->localize_script ( 'ach', $this->get_localized_params () );
87
- }
88
-
89
- public function get_localized_params() {
90
- return array_merge_recursive ( parent::get_localized_params (), array(
91
- 'env' => $this->get_plaid_environment (),
92
- 'client_name' => $this->get_option ( 'client_name' ),
93
- 'public_key' => '3a5433ed5ff7229aef78bb4d87a63a',
94
- 'metadata_key' => '[name="' . $this->metadata_key . '"]',
95
- 'fees_enabled' => $this->fees_enabled ()
96
- ) );
97
- }
98
-
99
- /**
100
- *
101
- * {@inheritDoc}
102
- *
103
- * @see WC_Payment_Gateway_Stripe_Charge::process_payment()
104
- */
105
- public function process_payment($order_id) {
106
- $this->payment_object->get_gateway ()->set_plaid_environment ( $this->get_option ( 'environment' ) );
107
- $this->payment_object->get_gateway ()->set_public_token ( $this->get_public_token () );
108
- $this->payment_object->get_gateway ()->set_account_id ( $this->get_metadata ()[ 'account_id' ] );
109
-
110
- return parent::process_payment ( $order_id );
111
- }
112
-
113
- public function get_plaid_environment() {
114
- return $this->get_option ( 'environment' );
115
- }
116
-
117
- private function get_metadata() {
118
- return isset ( $_POST[ $this->metadata_key ] ) ? json_decode ( stripslashes ( $_POST[ $this->metadata_key ] ), true ) : null;
119
- }
120
-
121
- private function get_public_token() {
122
- return $this->get_new_source_token ();
123
- }
124
-
125
- public function get_saved_methods_label() {
126
- return __ ( 'Saved Banks', 'woo-stripe-payment' );
127
- }
128
-
129
- public function get_new_method_label() {
130
- return __ ( 'New Bank', 'woo-stripe-payment' );
131
- }
132
-
133
- public function generate_ach_fee_html($key, $data) {
134
- $field_key = $this->get_field_key ( $key );
135
- $defaults = array( 'title' => '',
136
- 'disabled' => false, 'class' => '',
137
- 'css' => 'max-width: 150px; min-width: 150px;',
138
- 'placeholder' => '', 'type' => 'text',
139
- 'desc_tip' => false, 'description' => '',
140
- 'custom_attributes' => array(),
141
- 'options' => array()
142
- );
143
- $data = wp_parse_args ( $data, $defaults );
144
- ob_start ();
145
- include wc_stripe ()->plugin_path () . 'includes/admin/views/html-ach-fee.php';
146
- return ob_get_clean ();
147
- }
148
-
149
- /**
150
- *
151
- * @param string $key
152
- * @param array $value
153
- */
154
- public function validate_ach_fee_field($key, $value) {
155
- $value = empty ( $value ) ? [ 'type' => 'none',
156
- 'taxable' => 'no', 'value' => '0'
157
- ] : $value;
158
- if (! isset ( $value[ 'taxable' ] )) {
159
- $value[ 'taxable' ] = 'no';
160
- }
161
- return $value;
162
- }
163
-
164
- /**
165
- *
166
- * @param string $key
167
- * @param string $value
168
- */
169
- public function validate_environment_field($key, $value) {
170
- if ('test' == wc_stripe_mode () && 'development' == $value) {
171
- WC_Admin_Settings::add_error ( __ ( 'You must set the API mode to live in order to enable the Plaid development environment.', 'woo-stripe-payment' ) );
172
- }
173
- return $value;
174
- }
175
-
176
- public function fees_enabled() {
177
- $fee = $this->get_option ( 'fee', [
178
- 'type' => 'none', 'value' => '0'
179
- ] );
180
- return ! empty ( $fee ) && $fee[ 'type' ] != 'none';
181
- }
182
-
183
- /**
184
- *
185
- * @param WC_Cart $cart
186
- */
187
- public function after_calculate_totals($cart) {
188
- remove_action ( 'woocommerce_after_calculate_totals', [
189
- $this, 'after_calculate_totals'
190
- ] );
191
-
192
- add_action ( 'woocommerce_cart_calculate_fees', array(
193
- $this, 'calculate_fees'
194
- ) );
195
-
196
- WC ()->session->set ( 'wc_stripe_cart_total', $cart->total );
197
- $cart->calculate_totals ();
198
- }
199
-
200
- /**
201
- *
202
- * @param WC_Cart $cart
203
- */
204
- public function calculate_fees($cart) {
205
- remove_action ( 'woocommerce_cart_calculate_fees', array(
206
- $this, 'calculate_fees'
207
- ) );
208
- $fee = $this->get_option ( 'fee' );
209
- $taxable = $fee[ 'taxable' ] == 'yes';
210
- switch ($fee[ 'type' ]) {
211
- case 'amount' :
212
- $cart->add_fee ( __ ( 'ACH Fee' ), $fee[ 'value' ], $taxable );
213
- break;
214
- case 'percent' :
215
- $cart->add_fee ( __ ( 'ACH Fee' ), $fee[ 'value' ] * WC ()->session->get ( 'wc_stripe_cart_total', 0 ), $taxable );
216
- break;
217
- }
218
- unset ( WC ()->session->wc_stripe_cart_total );
219
- }
220
-
221
- public static function update_order_review() {
222
- if (! empty ( $_POST[ 'payment_method' ] ) && $_POST[ 'payment_method' ] == 'stripe_ach') {
223
- $payment_method = new WC_Payment_Gateway_Stripe_ACH ();
224
- if ($payment_method->fees_enabled ()) {
225
- add_action ( 'woocommerce_after_calculate_totals', [
226
- $payment_method,
227
- 'after_calculate_totals'
228
- ] );
229
- }
230
- }
231
- }
232
- }
233
- WC_Payment_Gateway_Stripe_ACH::init ();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/gateways/class-wc-payment-gateway-stripe-ach.php CHANGED
@@ -1,331 +1,352 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- * Gateway that processes ACH payments.
6
- * Only available for U.S. based merchants at this time.
7
- *
8
- * @since 3.0.5
9
- * @author Payment Plugins
10
- * @package Stripe/Gateways
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_ACH extends WC_Payment_Gateway_Stripe {
14
-
15
- use WC_Stripe_Payment_Charge_Trait;
16
-
17
- /**
18
- *
19
- * @var object
20
- */
21
- public $metadata_key = '';
22
-
23
- public function __construct() {
24
- $this->synchronous = false;
25
- $this->id = 'stripe_ach';
26
- $this->tab_title = __ ( 'ACH', 'woo-stripe-payment' );
27
- $this->template_name = 'ach.php';
28
- $this->token_type = 'Stripe_ACH';
29
- $this->method_title = __ ( 'Stripe ACH', 'woo-stripe-payment' );
30
- $this->method_description = __ ( 'ACH gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
31
- $this->icon = wc_stripe ()->assets_url ( 'img/ach.svg' );
32
- $this->order_button_text = __ ( 'Bank Payment', 'woo-stripe-payment' );
33
- $this->metadata_key = $this->id . '_metadata';
34
- parent::__construct ();
35
- $this->settings[ 'charge_type' ] = 'capture';
36
- }
37
-
38
- public static function init() {
39
- add_action ( 'woocommerce_checkout_update_order_review', [
40
- __CLASS__, 'update_order_review'
41
- ] );
42
- }
43
-
44
- /**
45
- *
46
- * {@inheritDoc}
47
- *
48
- * @see WC_Payment_Gateway::is_available()
49
- */
50
- public function is_available() {
51
- $is_available = parent::is_available ();
52
- return $is_available && get_woocommerce_currency () == 'USD';
53
- }
54
-
55
- /**
56
- *
57
- * {@inheritDoc}
58
- *
59
- * @see WC_Payment_Gateway_Stripe::init_supports()
60
- */
61
- public function init_supports() {
62
- /*
63
- * $this->supports = [ 'tokenization', 'products',
64
- * 'refunds'
65
- * ];
66
- */
67
- parent::init_supports ();
68
- unset ( $this->supports[ 'add_payment_method' ] );
69
- }
70
-
71
- /**
72
- *
73
- * {@inheritDoc}
74
- *
75
- * @see WC_Payment_Gateway_Stripe::enqueue_checkout_scripts()
76
- */
77
- public function enqueue_checkout_scripts($scripts) {
78
- $scripts->enqueue_script ( 'ach', $scripts->assets_url ( 'js/frontend/ach-payments.js' ), array(
79
- $scripts->get_handle ( 'external' ),
80
- $scripts->get_handle ( 'wc-stripe' ),
81
- $scripts->get_handle ( 'plaid' )
82
- ) );
83
- $scripts->localize_script ( 'ach', $this->get_localized_params () );
84
- }
85
-
86
- public function get_localized_params() {
87
- return array_merge_recursive ( parent::get_localized_params (), array(
88
- 'env' => $this->get_plaid_environment (),
89
- 'client_name' => $this->get_option ( 'client_name' ),
90
- 'public_key' => $this->get_option ( 'public_key' ),
91
- 'metadata_key' => '[name="' . $this->metadata_key . '"]',
92
- 'fees_enabled' => $this->fees_enabled ()
93
- ) );
94
- }
95
-
96
- /**
97
- *
98
- * {@inheritDoc}
99
- *
100
- * @see WC_Payment_Gateway_Stripe_Charge::process_payment()
101
- */
102
- public function process_payment($order_id) {
103
- $order = wc_get_order ( $order_id );
104
-
105
- // generate the access token first.
106
- if (! $this->use_saved_source ()) {
107
- try {
108
- $result = $this->fetch_access_token ( $this->get_public_token () );
109
-
110
- $result = $this->fetch_bank_token ( $result->access_token );
111
-
112
- $this->set_new_source_token ( $result->stripe_bank_account_token );
113
- } catch ( Exception $e ) {
114
- wc_add_notice ( sprintf ( __ ( 'Error processing payment. Reason: %s', 'woo-stripe-payment' ), $e->getMessage () ), 'error' );
115
- }
116
- }
117
- if (wc_stripe ()->api_settings->get_option ( 'account_id' ) && ! $this->get_option ( 'record_ach', false )) {
118
- add_filter ( 'wc_stripe_order_meta_data', function ($metadata) {
119
- $metadata[ 'plaid_id' ] = $this->get_option ( 'client_id' );
120
- return $metadata;
121
- } );
122
- $this->update_option ( 'record_ach', true );
123
- }
124
- return parent::process_payment ( $order_id );
125
- }
126
-
127
- private function do_api_request($uri, $body, $method = 'POST') {
128
- $response = wp_safe_remote_post ( $this->get_plaid_url ( $uri ), [
129
- 'headers' => [
130
- 'Content-Type' => 'application/json'
131
- ], 'body' => wp_json_encode ( $body ),
132
- 'data_format' => 'body'
133
- ] );
134
- if (is_wp_error ( $response )) {
135
- throw new Exception ( $response->get_error_message () );
136
- } else {
137
- $body = json_decode ( $response[ 'body' ] );
138
- if ($response[ 'response' ][ 'code' ] > 299) {
139
- throw new Exception ( $body->error_message );
140
- } else {
141
- return $body;
142
- }
143
- }
144
- }
145
-
146
- private function fetch_access_token($public_token) {
147
- $env = $this->get_plaid_environment ();
148
- return $this->do_api_request ( 'item/public_token/exchange', [
149
- 'client_id' => $this->get_option ( 'client_id' ),
150
- 'secret' => $this->get_option ( "{$env}_secret" ),
151
- 'public_token' => $public_token
152
- ] );
153
- }
154
-
155
- private function fetch_bank_token($access_token) {
156
- $env = $this->get_plaid_environment ();
157
- return $this->do_api_request ( 'processor/stripe/bank_account_token/create', [
158
- 'client_id' => $this->get_option ( 'client_id' ),
159
- 'secret' => $this->get_option ( "{$env}_secret" ),
160
- 'access_token' => $access_token,
161
- 'account_id' => $this->get_metadata ()[ 'account_id' ]
162
- ] );
163
- }
164
-
165
- /**
166
- * Return the base plaid api url.
167
- *
168
- * @return string
169
- */
170
- private function get_base_url() {
171
- $url = '';
172
- switch ($this->get_plaid_environment ()) {
173
- case 'production' :
174
- $url = 'https://production.plaid.com/';
175
- break;
176
- case 'sandbox' :
177
- $url = 'https://sandbox.plaid.com/';
178
- break;
179
- case 'development' :
180
- $url = 'https://development.plaid.com/';
181
- break;
182
- }
183
- return $url;
184
- }
185
-
186
- private function get_plaid_url($uri) {
187
- return sprintf ( '%s%s', $this->get_base_url (), $uri );
188
- }
189
-
190
- public function get_plaid_environment() {
191
- return $this->get_option ( 'environment' );
192
- }
193
-
194
- private function get_metadata() {
195
- return isset ( $_POST[ $this->metadata_key ] ) ? json_decode ( stripslashes ( $_POST[ $this->metadata_key ] ), true ) : null;
196
- }
197
-
198
- private function get_public_token() {
199
- return $this->get_new_source_token ();
200
- }
201
-
202
- public function get_saved_methods_label() {
203
- return __ ( 'Saved Banks', 'woo-stripe-payment' );
204
- }
205
-
206
- public function get_new_method_label() {
207
- return __ ( 'New Bank', 'woo-stripe-payment' );
208
- }
209
-
210
- public function generate_ach_fee_html($key, $data) {
211
- $field_key = $this->get_field_key ( $key );
212
- $defaults = array( 'title' => '',
213
- 'disabled' => false, 'class' => '',
214
- 'css' => 'max-width: 150px; min-width: 150px;',
215
- 'placeholder' => '', 'type' => 'text',
216
- 'desc_tip' => false, 'description' => '',
217
- 'custom_attributes' => array(),
218
- 'options' => array()
219
- );
220
- $data = wp_parse_args ( $data, $defaults );
221
- ob_start ();
222
- include wc_stripe ()->plugin_path () . 'includes/admin/views/html-ach-fee.php';
223
- return ob_get_clean ();
224
- }
225
-
226
- public function validate_ach_fee_field($key, $value) {
227
- $value = empty ( $value ) ? [ 'type' => 'none',
228
- 'taxable' => 'no', 'value' => '0'
229
- ] : $value;
230
- if (! isset ( $value[ 'taxable' ] )) {
231
- $value[ 'taxable' ] = 'no';
232
- }
233
- return $value;
234
- }
235
-
236
- /**
237
- *
238
- * @param string $key
239
- * @param string $value
240
- */
241
- public function validate_environment_field($key, $value) {
242
- if ('test' == wc_stripe_mode () && 'development' == $value) {
243
- WC_Admin_Settings::add_error ( __ ( 'You must set the API mode to live in order to enable the Plaid development environment.', 'woo-stripe-payment' ) );
244
- }
245
- return $value;
246
- }
247
-
248
- public function fees_enabled() {
249
- $fee = $this->get_option ( 'fee', [
250
- 'type' => 'none', 'value' => '0'
251
- ] );
252
- return ! empty ( $fee ) && $fee[ 'type' ] != 'none';
253
- }
254
-
255
- /**
256
- *
257
- * @param WC_Cart $cart
258
- */
259
- public function after_calculate_totals($cart) {
260
- remove_action ( 'woocommerce_after_calculate_totals', [
261
- $this, 'after_calculate_totals'
262
- ] );
263
-
264
- add_action ( 'woocommerce_cart_calculate_fees', array(
265
- $this, 'calculate_fees'
266
- ) );
267
-
268
- WC ()->session->set ( 'wc_stripe_cart_total', $cart->total );
269
- $cart->calculate_totals ();
270
- }
271
-
272
- /**
273
- *
274
- * @param WC_Cart $cart
275
- */
276
- public function calculate_fees($cart) {
277
- remove_action ( 'woocommerce_cart_calculate_fees', array(
278
- $this, 'calculate_fees'
279
- ) );
280
- $fee = $this->get_option ( 'fee' );
281
- $taxable = $fee[ 'taxable' ] == 'yes';
282
- switch ($fee[ 'type' ]) {
283
- case 'amount' :
284
- $cart->add_fee ( __ ( 'ACH Fee' ), $fee[ 'value' ], $taxable );
285
- break;
286
- case 'percent' :
287
- $cart->add_fee ( __ ( 'ACH Fee' ), $fee[ 'value' ] * WC ()->session->get ( 'wc_stripe_cart_total', 0 ), $taxable );
288
- break;
289
- }
290
- unset ( WC ()->session->wc_stripe_cart_total );
291
- }
292
-
293
- public static function update_order_review() {
294
- if (! empty ( $_POST[ 'payment_method' ] ) && $_POST[ 'payment_method' ] == 'stripe_ach') {
295
- $payment_method = new WC_Payment_Gateway_Stripe_ACH ();
296
- if ($payment_method->fees_enabled ()) {
297
- add_action ( 'woocommerce_after_calculate_totals', [
298
- $payment_method,
299
- 'after_calculate_totals'
300
- ] );
301
- }
302
- }
303
- }
304
-
305
- /**
306
- * Override so Plaid token can be converted to a Stripe bank token.
307
- *
308
- * {@inheritDoc}
309
- *
310
- * @see WC_Payment_Gateway_Stripe::create_payment_method()
311
- */
312
- public function create_payment_method($id, $customer_id) {
313
- if ($this->is_change_payment_method_request ()) {
314
- $result = $this->fetch_access_token ( $this->get_public_token () );
315
-
316
- if (is_wp_error ( $result )) {
317
- return $result;
318
- }
319
-
320
- $result = $this->fetch_bank_token ( $result->access_token );
321
-
322
- if (is_wp_error ( $result )) {
323
- return $result;
324
- }
325
-
326
- $id = $result->stripe_bank_account_token;
327
- }
328
- return parent::create_payment_method ( $id, $customer_id );
329
- }
330
- }
331
- WC_Payment_Gateway_Stripe_ACH::init ();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * Gateway that processes ACH payments.
6
+ * Only available for U.S. based merchants at this time.
7
+ *
8
+ * @since 3.0.5
9
+ * @author Payment Plugins
10
+ * @package Stripe/Gateways
11
+ *
12
+ */
13
+ class WC_Payment_Gateway_Stripe_ACH extends WC_Payment_Gateway_Stripe {
14
+
15
+ use WC_Stripe_Payment_Charge_Trait;
16
+
17
+ /**
18
+ *
19
+ * @var object
20
+ */
21
+ public $metadata_key = '';
22
+
23
+ public function __construct() {
24
+ $this->synchronous = false;
25
+ $this->id = 'stripe_ach';
26
+ $this->tab_title = __( 'ACH', 'woo-stripe-payment' );
27
+ $this->template_name = 'ach.php';
28
+ $this->token_type = 'Stripe_ACH';
29
+ $this->method_title = __( 'Stripe ACH', 'woo-stripe-payment' );
30
+ $this->method_description = __( 'ACH gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
31
+ $this->icon = wc_stripe()->assets_url( 'img/ach.svg' );
32
+ $this->order_button_text = __( 'Bank Payment', 'woo-stripe-payment' );
33
+ $this->metadata_key = $this->id . '_metadata';
34
+ parent::__construct();
35
+ $this->settings['charge_type'] = 'capture';
36
+ }
37
+
38
+ public static function init() {
39
+ add_action( 'woocommerce_checkout_update_order_review', array( __CLASS__, 'update_order_review' ) );
40
+ }
41
+
42
+ /**
43
+ *
44
+ * {@inheritDoc}
45
+ *
46
+ * @see WC_Payment_Gateway::is_available()
47
+ */
48
+ public function is_available() {
49
+ $is_available = parent::is_available();
50
+
51
+ return $is_available && get_woocommerce_currency() == 'USD';
52
+ }
53
+
54
+ /**
55
+ *
56
+ * {@inheritDoc}
57
+ *
58
+ * @see WC_Payment_Gateway_Stripe::init_supports()
59
+ */
60
+ public function init_supports() {
61
+ parent::init_supports();
62
+ unset( $this->supports['add_payment_method'] );
63
+ }
64
+
65
+ /**
66
+ *
67
+ * {@inheritDoc}
68
+ *
69
+ * @see WC_Payment_Gateway_Stripe::enqueue_checkout_scripts()
70
+ */
71
+ public function enqueue_checkout_scripts( $scripts ) {
72
+ $scripts->enqueue_script(
73
+ 'ach',
74
+ $scripts->assets_url( 'js/frontend/ach-payments.js' ),
75
+ array(
76
+ $scripts->get_handle( 'external' ),
77
+ $scripts->get_handle( 'wc-stripe' ),
78
+ $scripts->get_handle( 'plaid' ),
79
+ )
80
+ );
81
+ $scripts->localize_script( 'ach', $this->get_localized_params() );
82
+ }
83
+
84
+ public function get_localized_params() {
85
+ return array_merge_recursive(
86
+ parent::get_localized_params(),
87
+ array(
88
+ 'env' => $this->get_plaid_environment(),
89
+ 'client_name' => $this->get_option( 'client_name' ),
90
+ 'public_key' => $this->get_option( 'public_key' ),
91
+ 'metadata_key' => '[name="' . $this->metadata_key . '"]',
92
+ 'fees_enabled' => $this->fees_enabled(),
93
+ )
94
+ );
95
+ }
96
+
97
+ /**
98
+ *
99
+ * {@inheritDoc}
100
+ *
101
+ * @see WC_Payment_Gateway_Stripe_Charge::process_payment()
102
+ */
103
+ public function process_payment( $order_id ) {
104
+ $order = wc_get_order( $order_id );
105
+
106
+ // generate the access token first.
107
+ if ( ! $this->use_saved_source() ) {
108
+ try {
109
+ $result = $this->fetch_access_token( $this->get_public_token() );
110
+
111
+ $result = $this->fetch_bank_token( $result->access_token );
112
+
113
+ $this->set_new_source_token( $result->stripe_bank_account_token );
114
+ } catch ( Exception $e ) {
115
+ wc_add_notice( sprintf( __( 'Error processing payment. Reason: %s', 'woo-stripe-payment' ), $e->getMessage() ), 'error' );
116
+ }
117
+ }
118
+ add_filter(
119
+ 'wc_stripe_order_meta_data',
120
+ function ( $metadata ) {
121
+ $metadata['plaid_id'] = $this->get_option( 'client_id' );
122
+
123
+ return $metadata;
124
+ }
125
+ );
126
+
127
+ return parent::process_payment( $order_id );
128
+ }
129
+
130
+ private function do_api_request( $uri, $body, $method = 'POST' ) {
131
+ $response = wp_safe_remote_post(
132
+ $this->get_plaid_url( $uri ),
133
+ array(
134
+ 'headers' => array( 'Content-Type' => 'application/json' ),
135
+ 'body' => wp_json_encode( $body ),
136
+ 'data_format' => 'body',
137
+ )
138
+ );
139
+ if ( is_wp_error( $response ) ) {
140
+ throw new Exception( $response->get_error_message() );
141
+ } else {
142
+ $body = json_decode( $response['body'] );
143
+ if ( $response['response']['code'] > 299 ) {
144
+ throw new Exception( $body->error_message );
145
+ } else {
146
+ return $body;
147
+ }
148
+ }
149
+ }
150
+
151
+ private function fetch_access_token( $public_token ) {
152
+ $env = $this->get_plaid_environment();
153
+
154
+ return $this->do_api_request(
155
+ 'item/public_token/exchange',
156
+ array(
157
+ 'client_id' => $this->get_option( 'client_id' ),
158
+ 'secret' => $this->get_option( "{$env}_secret" ),
159
+ 'public_token' => $public_token,
160
+ )
161
+ );
162
+ }
163
+
164
+ private function fetch_bank_token( $access_token ) {
165
+ $env = $this->get_plaid_environment();
166
+
167
+ return $this->do_api_request(
168
+ 'processor/stripe/bank_account_token/create',
169
+ array(
170
+ 'client_id' => $this->get_option( 'client_id' ),
171
+ 'secret' => $this->get_option( "{$env}_secret" ),
172
+ 'access_token' => $access_token,
173
+ 'account_id' => $this->get_metadata()['account_id'],
174
+ )
175
+ );
176
+ }
177
+
178
+ /**
179
+ * Return the base plaid api url.
180
+ *
181
+ * @return string
182
+ */
183
+ private function get_base_url() {
184
+ $url = '';
185
+ switch ( $this->get_plaid_environment() ) {
186
+ case 'production':
187
+ $url = 'https://production.plaid.com/';
188
+ break;
189
+ case 'sandbox':
190
+ $url = 'https://sandbox.plaid.com/';
191
+ break;
192
+ case 'development':
193
+ $url = 'https://development.plaid.com/';
194
+ break;
195
+ }
196
+
197
+ return $url;
198
+ }
199
+
200
+ private function get_plaid_url( $uri ) {
201
+ return sprintf( '%s%s', $this->get_base_url(), $uri );
202
+ }
203
+
204
+ public function get_plaid_environment() {
205
+ return $this->get_option( 'environment' );
206
+ }
207
+
208
+ private function get_metadata() {
209
+ return isset( $_POST[ $this->metadata_key ] ) ? json_decode( stripslashes( $_POST[ $this->metadata_key ] ), true ) : null;
210
+ }
211
+
212
+ private function get_public_token() {
213
+ return $this->get_new_source_token();
214
+ }
215
+
216
+ public function get_saved_methods_label() {
217
+ return __( 'Saved Banks', 'woo-stripe-payment' );
218
+ }
219
+
220
+ public function get_new_method_label() {
221
+ return __( 'New Bank', 'woo-stripe-payment' );
222
+ }
223
+
224
+ public function generate_ach_fee_html( $key, $data ) {
225
+ $field_key = $this->get_field_key( $key );
226
+ $defaults = array(
227
+ 'title' => '',
228
+ 'disabled' => false,
229
+ 'class' => '',
230
+ 'css' => 'max-width: 150px; min-width: 150px;',
231
+ 'placeholder' => '',
232
+ 'type' => 'text',
233
+ 'desc_tip' => false,
234
+ 'description' => '',
235
+ 'custom_attributes' => array(),
236
+ 'options' => array(),
237
+ );
238
+ $data = wp_parse_args( $data, $defaults );
239
+ ob_start();
240
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-ach-fee.php';
241
+
242
+ return ob_get_clean();
243
+ }
244
+
245
+ public function validate_ach_fee_field( $key, $value ) {
246
+ $value = empty( $value ) ? array(
247
+ 'type' => 'none',
248
+ 'taxable' => 'no',
249
+ 'value' => '0',
250
+ ) : $value;
251
+ if ( ! isset( $value['taxable'] ) ) {
252
+ $value['taxable'] = 'no';
253
+ }
254
+
255
+ return $value;
256
+ }
257
+
258
+ /**
259
+ *
260
+ * @param string $key
261
+ * @param string $value
262
+ */
263
+ public function validate_environment_field( $key, $value ) {
264
+ if ( 'test' == wc_stripe_mode() && 'development' == $value ) {
265
+ WC_Admin_Settings::add_error( __( 'You must set the API mode to live in order to enable the Plaid development environment.', 'woo-stripe-payment' ) );
266
+ }
267
+
268
+ return $value;
269
+ }
270
+
271
+ public function fees_enabled() {
272
+ $fee = $this->get_option(
273
+ 'fee',
274
+ array(
275
+ 'type' => 'none',
276
+ 'value' => '0',
277
+ )
278
+ );
279
+
280
+ return ! empty( $fee ) && $fee['type'] != 'none';
281
+ }
282
+
283
+ /**
284
+ *
285
+ * @param WC_Cart $cart
286
+ */
287
+ public function after_calculate_totals( $cart ) {
288
+ remove_action( 'woocommerce_after_calculate_totals', array( $this, 'after_calculate_totals' ) );
289
+
290
+ add_action( 'woocommerce_cart_calculate_fees', array( $this, 'calculate_fees' ) );
291
+
292
+ WC()->session->set( 'wc_stripe_cart_total', $cart->total );
293
+ $cart->calculate_totals();
294
+ }
295
+
296
+ /**
297
+ *
298
+ * @param WC_Cart $cart
299
+ */
300
+ public function calculate_fees( $cart ) {
301
+ remove_action( 'woocommerce_cart_calculate_fees', array( $this, 'calculate_fees' ) );
302
+ $fee = $this->get_option( 'fee' );
303
+ $taxable = $fee['taxable'] == 'yes';
304
+ switch ( $fee['type'] ) {
305
+ case 'amount':
306
+ $cart->add_fee( __( 'ACH Fee' ), $fee['value'], $taxable );
307
+ break;
308
+ case 'percent':
309
+ $cart->add_fee( __( 'ACH Fee' ), $fee['value'] * WC()->session->get( 'wc_stripe_cart_total', 0 ), $taxable );
310
+ break;
311
+ }
312
+ unset( WC()->session->wc_stripe_cart_total );
313
+ }
314
+
315
+ public static function update_order_review() {
316
+ if ( ! empty( $_POST['payment_method'] ) && $_POST['payment_method'] == 'stripe_ach' ) {
317
+ $payment_method = new WC_Payment_Gateway_Stripe_ACH();
318
+ if ( $payment_method->fees_enabled() ) {
319
+ add_action( 'woocommerce_after_calculate_totals', array( $payment_method, 'after_calculate_totals' ) );
320
+ }
321
+ }
322
+ }
323
+
324
+ /**
325
+ * Override so Plaid token can be converted to a Stripe bank token.
326
+ *
327
+ * {@inheritDoc}
328
+ *
329
+ * @see WC_Payment_Gateway_Stripe::create_payment_method()
330
+ */
331
+ public function create_payment_method( $id, $customer_id ) {
332
+ if ( $this->is_change_payment_method_request() ) {
333
+ $result = $this->fetch_access_token( $this->get_public_token() );
334
+
335
+ if ( is_wp_error( $result ) ) {
336
+ return $result;
337
+ }
338
+
339
+ $result = $this->fetch_bank_token( $result->access_token );
340
+
341
+ if ( is_wp_error( $result ) ) {
342
+ return $result;
343
+ }
344
+
345
+ $id = $result->stripe_bank_account_token;
346
+ }
347
+
348
+ return parent::create_payment_method( $id, $customer_id );
349
+ }
350
+ }
351
+
352
+ WC_Payment_Gateway_Stripe_ACH::init();
includes/gateways/class-wc-payment-gateway-stripe-alipay.php CHANGED
@@ -1,34 +1,33 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_Alipay extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Charge_Trait;
16
-
17
- public function __construct() {
18
- $this->local_payment_type = 'alipay';
19
- $this->currencies = [ 'AUD', 'CAD', 'EUR',
20
- 'GBP', 'HKD', 'JPY', 'SGD', 'USD'
21
- ];
22
- // $this->countries = [ 'CN'
23
- // ];
24
- $this->id = 'stripe_alipay';
25
- $this->tab_title = __ ( 'Alipay', 'woo-stripe-payment' );
26
- $this->template_name = 'local-payment.php';
27
- $this->token_type = 'Stripe_Local';
28
- $this->method_title = __ ( 'Alipay', 'woo-stripe-payment' );
29
- $this->method_description = __ ( 'Alipay gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
30
- $this->icon = wc_stripe ()->assets_url ( 'img/alipay.svg' );
31
- $this->order_button_text = $this->get_order_button_text ( __ ( 'Alipay', 'woo-stripe-payment' ) );
32
- parent::__construct ();
33
- }
34
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_Alipay extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->local_payment_type = 'alipay';
20
+ $this->currencies = array( 'AUD', 'CAD', 'EUR', 'GBP', 'HKD', 'JPY', 'SGD', 'USD' );
21
+ // $this->countries = [ 'CN'
22
+ // ];
23
+ $this->id = 'stripe_alipay';
24
+ $this->tab_title = __( 'Alipay', 'woo-stripe-payment' );
25
+ $this->template_name = 'local-payment.php';
26
+ $this->token_type = 'Stripe_Local';
27
+ $this->method_title = __( 'Alipay', 'woo-stripe-payment' );
28
+ $this->method_description = __( 'Alipay gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
29
+ $this->icon = wc_stripe()->assets_url( 'img/alipay.svg' );
30
+ $this->order_button_text = $this->get_order_button_text( __( 'Alipay', 'woo-stripe-payment' ) );
31
+ parent::__construct();
32
+ }
33
+ }
 
includes/gateways/class-wc-payment-gateway-stripe-applepay.php CHANGED
@@ -1,90 +1,115 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_ApplePay extends WC_Payment_Gateway_Stripe {
14
-
15
- use WC_Stripe_Payment_Intent_Trait;
16
-
17
- protected $payment_method_type = 'card';
18
-
19
- public function __construct() {
20
- $this->id = 'stripe_applepay';
21
- $this->tab_title = __ ( 'Apple Pay', 'woo-stripe-payment' );
22
- $this->template_name = 'applepay.php';
23
- $this->token_type = 'Stripe_ApplePay';
24
- $this->method_title = __ ( 'Stripe Apple Pay', 'woo-stripe-payment' );
25
- $this->method_description = __ ( 'Apple Pay gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
26
- parent::__construct ();
27
- $this->icon = wc_stripe ()->assets_url ( 'img/applepay.svg' );
28
- }
29
-
30
- public function init_supports() {
31
- parent::init_supports ();
32
- $this->supports[] = 'wc_stripe_cart_checkout';
33
- $this->supports[] = 'wc_stripe_product_checkout';
34
- $this->supports[] = 'wc_stripe_banner_checkout';
35
- }
36
-
37
- public function enqueue_product_scripts($scripts) {
38
- $scripts->enqueue_script ( 'applepay-product', $scripts->assets_url ( 'js/frontend/applepay-product.js' ), [
39
- $scripts->get_handle ( 'wc-stripe' ),
40
- $scripts->get_handle ( 'external' )
41
- ], wc_stripe ()->version (), true );
42
- $scripts->localize_script ( 'applepay-product', $this->get_localized_params () );
43
- }
44
-
45
- public function enqueue_cart_scripts($scripts) {
46
- $scripts->enqueue_script ( 'applepay-cart', $scripts->assets_url ( 'js/frontend/applepay-cart.js' ), [
47
- $scripts->get_handle ( 'wc-stripe' ),
48
- $scripts->get_handle ( 'external' )
49
- ], wc_stripe ()->version (), true );
50
- $scripts->localize_script ( 'applepay-cart', $this->get_localized_params () );
51
- }
52
-
53
- public function enqueue_checkout_scripts($scripts) {
54
- $scripts->enqueue_script ( 'applepay-checkout', $scripts->assets_url ( 'js/frontend/applepay-checkout.js' ), [
55
- $scripts->get_handle ( 'wc-stripe' ),
56
- $scripts->get_handle ( 'external' )
57
- ], wc_stripe ()->version (), true );
58
- $scripts->localize_script ( 'applepay-checkout', $this->get_localized_params () );
59
- }
60
-
61
- public function get_localized_params() {
62
- return array_merge_recursive ( parent::get_localized_params (), [
63
- 'messages' => [
64
- 'invalid_amount' => __ ( 'Please update you product quantity before using Apple Pay.', 'woo-stripe-payment' ),
65
- 'choose_product' => __ ( 'Please select a product option before updating quantity.', 'woo-stripe-payment' )
66
- ],
67
- 'button' => wc_stripe_get_template_html ( 'applepay-button.php', [
68
- 'style' => $this->get_option ( 'button_style' ),
69
- 'type' => $this->get_button_type ()
70
- ] )
71
- ] );
72
- }
73
-
74
- /**
75
- * Returns the Apple Pay button type based on the current page.
76
- *
77
- * @return string
78
- */
79
- protected function get_button_type() {
80
- if (is_checkout ()) {
81
- return $this->get_option ( 'button_type_checkout' );
82
- }
83
- if (is_cart ()) {
84
- return $this->get_option ( 'button_type_cart' );
85
- }
86
- if (is_product ()) {
87
- return $this->get_option ( 'button_type_product' );
88
- }
89
- }
90
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_ApplePay extends WC_Payment_Gateway_Stripe {
15
+
16
+ use WC_Stripe_Payment_Intent_Trait;
17
+
18
+ protected $payment_method_type = 'card';
19
+
20
+ public function __construct() {
21
+ $this->id = 'stripe_applepay';
22
+ $this->tab_title = __( 'Apple Pay', 'woo-stripe-payment' );
23
+ $this->template_name = 'applepay.php';
24
+ $this->token_type = 'Stripe_ApplePay';
25
+ $this->method_title = __( 'Stripe Apple Pay', 'woo-stripe-payment' );
26
+ $this->method_description = __( 'Apple Pay gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
27
+ parent::__construct();
28
+ $this->icon = wc_stripe()->assets_url( 'img/applepay.svg' );
29
+ }
30
+
31
+ public function init_supports() {
32
+ parent::init_supports();
33
+ $this->supports[] = 'wc_stripe_cart_checkout';
34
+ $this->supports[] = 'wc_stripe_product_checkout';
35
+ $this->supports[] = 'wc_stripe_banner_checkout';
36
+ }
37
+
38
+ public function enqueue_product_scripts( $scripts ) {
39
+ $scripts->enqueue_script(
40
+ 'applepay-product',
41
+ $scripts->assets_url( 'js/frontend/applepay-product.js' ),
42
+ array(
43
+ $scripts->get_handle( 'wc-stripe' ),
44
+ $scripts->get_handle( 'external' ),
45
+ ),
46
+ wc_stripe()->version(),
47
+ true
48
+ );
49
+ $scripts->localize_script( 'applepay-product', $this->get_localized_params() );
50
+ }
51
+
52
+ public function enqueue_cart_scripts( $scripts ) {
53
+ $scripts->enqueue_script(
54
+ 'applepay-cart',
55
+ $scripts->assets_url( 'js/frontend/applepay-cart.js' ),
56
+ array(
57
+ $scripts->get_handle( 'wc-stripe' ),
58
+ $scripts->get_handle( 'external' ),
59
+ ),
60
+ wc_stripe()->version(),
61
+ true
62
+ );
63
+ $scripts->localize_script( 'applepay-cart', $this->get_localized_params() );
64
+ }
65
+
66
+ public function enqueue_checkout_scripts( $scripts ) {
67
+ $scripts->enqueue_script(
68
+ 'applepay-checkout',
69
+ $scripts->assets_url( 'js/frontend/applepay-checkout.js' ),
70
+ array(
71
+ $scripts->get_handle( 'wc-stripe' ),
72
+ $scripts->get_handle( 'external' ),
73
+ ),
74
+ wc_stripe()->version(),
75
+ true
76
+ );
77
+ $scripts->localize_script( 'applepay-checkout', $this->get_localized_params() );
78
+ }
79
+
80
+ public function get_localized_params() {
81
+ return array_merge_recursive(
82
+ parent::get_localized_params(),
83
+ array(
84
+ 'messages' => array(
85
+ 'invalid_amount' => __( 'Please update you product quantity before using Apple Pay.', 'woo-stripe-payment' ),
86
+ 'choose_product' => __( 'Please select a product option before updating quantity.', 'woo-stripe-payment' ),
87
+ ),
88
+ 'button' => wc_stripe_get_template_html(
89
+ 'applepay-button.php',
90
+ array(
91
+ 'style' => $this->get_option( 'button_style' ),
92
+ 'type' => $this->get_button_type(),
93
+ )
94
+ ),
95
+ )
96
+ );
97
+ }
98
+
99
+ /**
100
+ * Returns the Apple Pay button type based on the current page.
101
+ *
102
+ * @return string
103
+ */
104
+ protected function get_button_type() {
105
+ if ( is_checkout() ) {
106
+ return $this->get_option( 'button_type_checkout' );
107
+ }
108
+ if ( is_cart() ) {
109
+ return $this->get_option( 'button_type_cart' );
110
+ }
111
+ if ( is_product() ) {
112
+ return $this->get_option( 'button_type_product' );
113
+ }
114
+ }
115
+ }
includes/gateways/class-wc-payment-gateway-stripe-bancontact.php CHANGED
@@ -1,34 +1,33 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_Bancontact extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Charge_Trait;
16
-
17
- public function __construct() {
18
- $this->synchronous = false;
19
- $this->local_payment_type = 'bancontact';
20
- $this->currencies = [ 'EUR'
21
- ];
22
- $this->countries = [ 'BE'
23
- ];
24
- $this->id = 'stripe_bancontact';
25
- $this->tab_title = __ ( 'Bancontact', 'woo-stripe-payment' );
26
- $this->template_name = 'local-payment.php';
27
- $this->token_type = 'Stripe_Local';
28
- $this->method_title = __ ( 'Bancontact', 'woo-stripe-payment' );
29
- $this->method_description = __ ( 'Bancontact gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
30
- $this->icon = wc_stripe ()->assets_url ( 'img/bancontact.svg' );
31
- $this->order_button_text = $this->get_order_button_text ( __ ( 'Bancontact', 'woo-stripe-payment' ) );
32
- parent::__construct ();
33
- }
34
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_Bancontact extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->synchronous = false;
20
+ $this->local_payment_type = 'bancontact';
21
+ $this->currencies = array( 'EUR' );
22
+ $this->countries = array( 'BE' );
23
+ $this->id = 'stripe_bancontact';
24
+ $this->tab_title = __( 'Bancontact', 'woo-stripe-payment' );
25
+ $this->template_name = 'local-payment.php';
26
+ $this->token_type = 'Stripe_Local';
27
+ $this->method_title = __( 'Bancontact', 'woo-stripe-payment' );
28
+ $this->method_description = __( 'Bancontact gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
29
+ $this->icon = wc_stripe()->assets_url( 'img/bancontact.svg' );
30
+ $this->order_button_text = $this->get_order_button_text( __( 'Bancontact', 'woo-stripe-payment' ) );
31
+ parent::__construct();
32
+ }
33
+ }
 
includes/gateways/class-wc-payment-gateway-stripe-cc.php CHANGED
@@ -1,164 +1,173 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.0.0
7
- * @package Stripe/Gateways
8
- * @author User
9
- *
10
- */
11
- class WC_Payment_Gateway_Stripe_CC extends WC_Payment_Gateway_Stripe {
12
-
13
- use WC_Stripe_Payment_Intent_Trait;
14
-
15
- protected $payment_method_type = 'card';
16
-
17
- public function __construct() {
18
- $this->id = 'stripe_cc';
19
- $this->tab_title = __ ( 'Credit Cards', 'woo-stripe-payment' );
20
- $this->template_name = 'credit-card.php';
21
- $this->token_type = 'Stripe_CC';
22
- $this->method_title = __ ( 'Stripe Credit Cards', 'woo-stripe-payment' );
23
- $this->method_description = __ ( 'Credit card gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
24
- parent::__construct ();
25
- }
26
-
27
- public function get_icon() {
28
- return wc_stripe_get_template ( 'card-icons.php', array(
29
- 'cards' => $this->get_option ( 'cards' ),
30
- 'style' => $this->get_option ( 'icon_style' )
31
- ) );
32
- }
33
-
34
- public function enqueue_checkout_scripts($scripts) {
35
- $scripts->enqueue_script ( 'credit-card', $scripts->assets_url ( 'js/frontend/credit-card.js' ), array(
36
- $scripts->prefix . 'external',
37
- $scripts->prefix . 'wc-stripe'
38
- ) );
39
- $scripts->localize_script ( 'credit-card', $this->get_localized_params () );
40
- }
41
-
42
- public function get_localized_params() {
43
- $data = parent::get_localized_params ();
44
- return array_merge ( $data, array(
45
- 'style' => $this->get_form_style (),
46
- 'elementOptions' => $this->get_element_options (),
47
- 'custom_form' => $this->is_custom_form_active (),
48
- 'html' => [
49
- 'card_brand' => sprintf ( '<img id="wc-stripe-card" src="%s" />', $this->get_custom_form ()[ 'cardBrand' ] )
50
- ],
51
- 'cards' => [
52
- 'visa' => wc_stripe ()->assets_url ( 'img/cards/visa.svg' ),
53
- 'amex' => wc_stripe ()->assets_url ( 'img/cards/amex.svg' ),
54
- 'mastercard' => wc_stripe ()->assets_url ( 'img/cards/mastercard.svg' ),
55
- 'discover' => wc_stripe ()->assets_url ( 'img/cards/discover.svg' ),
56
- 'diners' => wc_stripe ()->assets_url ( 'img/cards/diners.svg' ),
57
- 'jcb' => wc_stripe ()->assets_url ( 'img/cards/jcb.svg' ),
58
- 'unionpay' => wc_stripe ()->assets_url ( 'img/cards/china_union_pay.svg' ),
59
- 'unknown' => $this->get_custom_form ()[ 'cardBrand' ]
60
- ],
61
- 'postal_regex' => $this->get_postal_code_regex ()
62
- ) );
63
- }
64
-
65
- private function get_form_style() {
66
- if ($this->is_custom_form_active ()) {
67
- $style = $this->get_custom_form ()[ 'elementStyles' ];
68
- } else {
69
- $style = array(
70
- 'base' => array( 'color' => '#32325d',
71
- 'fontFamily' => '"Helvetica Neue", Helvetica, sans-serif',
72
- 'fontSmoothing' => 'antialiased',
73
- 'fontSize' => '18px',
74
- '::placeholder' => array(
75
- 'color' => '#aab7c4'
76
- ), ':focus' => []
77
- ),
78
- 'invalid' => array(
79
- 'color' => '#fa755a',
80
- 'iconColor' => '#fa755a'
81
- )
82
- );
83
- }
84
- return apply_filters ( 'wc_stripe_cc_element_style', $style );
85
- }
86
-
87
- private function get_custom_form() {
88
- return wc_stripe_get_custom_forms ()[ $this->get_option ( 'custom_form' ) ];
89
- }
90
-
91
- private function get_element_options() {
92
- return $this->get_custom_form ()[ 'elementOptions' ];
93
- }
94
-
95
- /**
96
- * Returns true if custom forms are enabled.
97
- *
98
- * @return bool
99
- */
100
- public function is_custom_form_active() {
101
- return $this->get_option ( 'form_type' ) === 'custom';
102
- }
103
-
104
- public function get_custom_form_template() {
105
- $form = $this->get_option ( 'custom_form' );
106
- return wc_stripe_get_custom_forms ()[ $form ][ 'template' ];
107
- }
108
-
109
- /**
110
- * Returns true if the postal code field is enabled.
111
- *
112
- * @return bool
113
- */
114
- public function postal_enabled() {
115
- if (is_checkout ()) {
116
- return $this->is_active ( 'postal_enabled' );
117
- }
118
- if (is_add_payment_method_page ()) {
119
- return true;
120
- }
121
- }
122
-
123
- /**
124
- * Returns true if the cvv field is enabled.
125
- *
126
- * @return bool
127
- */
128
- public function cvv_enabled() {
129
- return $this->is_active ( 'cvv_enabled' );
130
- }
131
-
132
- public function get_postal_code_regex() {
133
- return [ 'AT' => '^([0-9]{4})$',
134
- 'BR' => '^([0-9]{5})([-])?([0-9]{3})$',
135
- 'CH' => '^([0-9]{4})$',
136
- 'DE' => '^([0]{1}[1-9]{1}|[1-9]{1}[0-9]{1})[0-9]{3}$',
137
- 'ES' => '^([0-9]{5})$',
138
- 'FR' => '^([0-9]{5})$',
139
- 'IT' => '^([0-9]{5})$/i',
140
- 'IE' => '([AC-FHKNPRTV-Y]\d{2}|D6W)[0-9AC-FHKNPRTV-Y]{4}',
141
- 'JP' => '^([0-9]{3})([-])([0-9]{4})$',
142
- 'PT' => '^([0-9]{4})([-])([0-9]{3})$',
143
- 'US' => '^([0-9]{5})(-[0-9]{4})?$',
144
- 'CA' => '^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])([\ ])?(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$',
145
- 'PL' => '^([0-9]{2})([-])([0-9]{3})',
146
- 'CZ' => '^([0-9]{3})(\s?)([0-9]{2})$',
147
- 'SK' => '^([0-9]{3})(\s?)([0-9]{2})$',
148
- 'NL' => '^([1-9][0-9]{3})(\s?)(?!SA|SD|SS)[A-Z]{2}$'
149
- ];
150
- }
151
-
152
- /**
153
- *
154
- * {@inheritDoc}
155
- *
156
- * @see WC_Payment_Gateway_Stripe::add_stripe_order_args()
157
- */
158
- public function add_stripe_order_args(&$args, $order) {
159
- // if the merchant is forcing 3D secure for all intents then add the required args.
160
- if ($this->is_active ( 'force_3d_secure' ) && is_checkout () && ! doing_action ( 'woocommerce_scheduled_subscription_payment_' . $this->id )) {
161
- $args[ 'payment_method_options' ][ 'card' ][ 'request_three_d_secure' ] = 'any';
162
- }
163
- }
164
- }
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @since 3.0.0
7
+ * @package Stripe/Gateways
8
+ * @author User
9
+ *
10
+ */
11
+ class WC_Payment_Gateway_Stripe_CC extends WC_Payment_Gateway_Stripe {
12
+
13
+ use WC_Stripe_Payment_Intent_Trait;
14
+
15
+ protected $payment_method_type = 'card';
16
+
17
+ public function __construct() {
18
+ $this->id = 'stripe_cc';
19
+ $this->tab_title = __( 'Credit Cards', 'woo-stripe-payment' );
20
+ $this->template_name = 'credit-card.php';
21
+ $this->token_type = 'Stripe_CC';
22
+ $this->method_title = __( 'Stripe Credit Cards', 'woo-stripe-payment' );
23
+ $this->method_description = __( 'Credit card gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
24
+ parent::__construct();
25
+ }
26
+
27
+ public function get_icon() {
28
+ return wc_stripe_get_template(
29
+ 'card-icons.php',
30
+ array(
31
+ 'cards' => $this->get_option( 'cards' ),
32
+ 'style' => $this->get_option( 'icon_style' ),
33
+ )
34
+ );
35
+ }
36
+
37
+ public function enqueue_checkout_scripts( $scripts ) {
38
+ $scripts->enqueue_script(
39
+ 'credit-card',
40
+ $scripts->assets_url( 'js/frontend/credit-card.js' ),
41
+ array(
42
+ $scripts->prefix . 'external',
43
+ $scripts->prefix . 'wc-stripe',
44
+ )
45
+ );
46
+ $scripts->localize_script( 'credit-card', $this->get_localized_params() );
47
+ }
48
+
49
+ public function get_localized_params() {
50
+ $data = parent::get_localized_params();
51
+ return array_merge(
52
+ $data,
53
+ array(
54
+ 'style' => $this->get_form_style(),
55
+ 'elementOptions' => $this->get_element_options(),
56
+ 'custom_form' => $this->is_custom_form_active(),
57
+ 'html' => array( 'card_brand' => sprintf( '<img id="wc-stripe-card" src="%s" />', $this->get_custom_form()['cardBrand'] ) ),
58
+ 'cards' => array(
59
+ 'visa' => wc_stripe()->assets_url( 'img/cards/visa.svg' ),
60
+ 'amex' => wc_stripe()->assets_url( 'img/cards/amex.svg' ),
61
+ 'mastercard' => wc_stripe()->assets_url( 'img/cards/mastercard.svg' ),
62
+ 'discover' => wc_stripe()->assets_url( 'img/cards/discover.svg' ),
63
+ 'diners' => wc_stripe()->assets_url( 'img/cards/diners.svg' ),
64
+ 'jcb' => wc_stripe()->assets_url( 'img/cards/jcb.svg' ),
65
+ 'unionpay' => wc_stripe()->assets_url( 'img/cards/china_union_pay.svg' ),
66
+ 'unknown' => $this->get_custom_form()['cardBrand'],
67
+ ),
68
+ 'postal_regex' => $this->get_postal_code_regex(),
69
+ )
70
+ );
71
+ }
72
+
73
+ private function get_form_style() {
74
+ if ( $this->is_custom_form_active() ) {
75
+ $style = $this->get_custom_form()['elementStyles'];
76
+ } else {
77
+ $style = array(
78
+ 'base' => array(
79
+ 'color' => '#32325d',
80
+ 'fontFamily' => '"Helvetica Neue", Helvetica, sans-serif',
81
+ 'fontSmoothing' => 'antialiased',
82
+ 'fontSize' => '18px',
83
+ '::placeholder' => array( 'color' => '#aab7c4' ),
84
+ ':focus' => array(),
85
+ ),
86
+ 'invalid' => array(
87
+ 'color' => '#fa755a',
88
+ 'iconColor' => '#fa755a',
89
+ ),
90
+ );
91
+ }
92
+ return apply_filters( 'wc_stripe_cc_element_style', $style );
93
+ }
94
+
95
+ private function get_custom_form() {
96
+ return wc_stripe_get_custom_forms()[ $this->get_option( 'custom_form' ) ];
97
+ }
98
+
99
+ private function get_element_options() {
100
+ return $this->get_custom_form()['elementOptions'];
101
+ }
102
+
103
+ /**
104
+ * Returns true if custom forms are enabled.
105
+ *
106
+ * @return bool
107
+ */
108
+ public function is_custom_form_active() {
109
+ return $this->get_option( 'form_type' ) === 'custom';
110
+ }
111
+
112
+ public function get_custom_form_template() {
113
+ $form = $this->get_option( 'custom_form' );
114
+ return wc_stripe_get_custom_forms()[ $form ]['template'];
115
+ }
116
+
117
+ /**
118
+ * Returns true if the postal code field is enabled.
119
+ *
120
+ * @return bool
121
+ */
122
+ public function postal_enabled() {
123
+ if ( is_checkout() ) {
124
+ return $this->is_active( 'postal_enabled' );
125
+ }
126
+ if ( is_add_payment_method_page() ) {
127
+ return true;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Returns true if the cvv field is enabled.
133
+ *
134
+ * @return bool
135
+ */
136
+ public function cvv_enabled() {
137
+ return $this->is_active( 'cvv_enabled' );
138
+ }
139
+
140
+ public function get_postal_code_regex() {
141
+ return array(
142
+ 'AT' => '^([0-9]{4})$',
143
+ 'BR' => '^([0-9]{5})([-])?([0-9]{3})$',
144
+ 'CH' => '^([0-9]{4})$',
145
+ 'DE' => '^([0]{1}[1-9]{1}|[1-9]{1}[0-9]{1})[0-9]{3}$',
146
+ 'ES' => '^([0-9]{5})$',
147
+ 'FR' => '^([0-9]{5})$',
148
+ 'IT' => '^([0-9]{5})$/i',
149
+ 'IE' => '([AC-FHKNPRTV-Y]\d{2}|D6W)[0-9AC-FHKNPRTV-Y]{4}',
150
+ 'JP' => '^([0-9]{3})([-])([0-9]{4})$',
151
+ 'PT' => '^([0-9]{4})([-])([0-9]{3})$',
152
+ 'US' => '^([0-9]{5})(-[0-9]{4})?$',
153
+ 'CA' => '^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])([\ ])?(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$',
154
+ 'PL' => '^([0-9]{2})([-])([0-9]{3})',
155
+ 'CZ' => '^([0-9]{3})(\s?)([0-9]{2})$',
156
+ 'SK' => '^([0-9]{3})(\s?)([0-9]{2})$',
157
+ 'NL' => '^([1-9][0-9]{3})(\s?)(?!SA|SD|SS)[A-Z]{2}$',
158
+ );
159
+ }
160
+
161
+ /**
162
+ *
163
+ * {@inheritDoc}
164
+ *
165
+ * @see WC_Payment_Gateway_Stripe::add_stripe_order_args()
166
+ */
167
+ public function add_stripe_order_args( &$args, $order ) {
168
+ // if the merchant is forcing 3D secure for all intents then add the required args.
169
+ if ( $this->is_active( 'force_3d_secure' ) && is_checkout() && ! doing_action( 'woocommerce_scheduled_subscription_payment_' . $this->id ) ) {
170
+ $args['payment_method_options']['card']['request_three_d_secure'] = 'any';
171
+ }
172
+ }
173
+ }
includes/gateways/class-wc-payment-gateway-stripe-eps.php CHANGED
@@ -1,33 +1,32 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_EPS extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Charge_Trait;
16
-
17
- public function __construct() {
18
- $this->local_payment_type = 'eps';
19
- $this->currencies = [ 'EUR'
20
- ];
21
- $this->countries = [ 'AT'
22
- ];
23
- $this->id = 'stripe_eps';
24
- $this->tab_title = __ ( 'EPS', 'woo-stripe-payment' );
25
- $this->template_name = 'local-payment.php';
26
- $this->token_type = 'Stripe_Local';
27
- $this->method_title = __ ( 'EPS', 'woo-stripe-payment' );
28
- $this->method_description = __ ( 'EPS gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
29
- $this->icon = wc_stripe ()->assets_url ( 'img/eps.svg' );
30
- $this->order_button_text = $this->get_order_button_text ( __ ( 'EPS', 'woo-stripe-payment' ) );
31
- parent::__construct ();
32
- }
33
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_EPS extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->local_payment_type = 'eps';
20
+ $this->currencies = array( 'EUR' );
21
+ $this->countries = array( 'AT' );
22
+ $this->id = 'stripe_eps';
23
+ $this->tab_title = __( 'EPS', 'woo-stripe-payment' );
24
+ $this->template_name = 'local-payment.php';
25
+ $this->token_type = 'Stripe_Local';
26
+ $this->method_title = __( 'EPS', 'woo-stripe-payment' );
27
+ $this->method_description = __( 'EPS gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
28
+ $this->icon = wc_stripe()->assets_url( 'img/eps.svg' );
29
+ $this->order_button_text = $this->get_order_button_text( __( 'EPS', 'woo-stripe-payment' ) );
30
+ parent::__construct();
31
+ }
32
+ }
 
includes/gateways/class-wc-payment-gateway-stripe-fpx.php CHANGED
@@ -1,39 +1,38 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_FPX extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Intent_Trait;
16
-
17
- protected $payment_method_type = 'fpx';
18
-
19
- public function __construct() {
20
- $this->local_payment_type = 'fpx';
21
- $this->currencies = [ 'MYR'
22
- ];
23
- $this->countries = [ 'MY'
24
- ];
25
- $this->id = 'stripe_fpx';
26
- $this->tab_title = __ ( 'FPX', 'woo-stripe-payment' );
27
- $this->method_title = __ ( 'FPX', 'woo-stripe-payment' );
28
- $this->method_description = __ ( 'FPX gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
29
- $this->icon = wc_stripe ()->assets_url ( 'img/fpx.svg' );
30
- $this->order_button_text = $this->get_order_button_text ( __ ( 'FPX', 'woo-stripe-payment' ) );
31
- parent::__construct ();
32
- }
33
-
34
- public function get_element_params() {
35
- $params = parent::get_element_params ();
36
- $params[ 'accountHolderType' ] = 'individual';
37
- return $params;
38
- }
39
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_FPX extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Intent_Trait;
17
+
18
+ protected $payment_method_type = 'fpx';
19
+
20
+ public function __construct() {
21
+ $this->local_payment_type = 'fpx';
22
+ $this->currencies = array( 'MYR' );
23
+ $this->countries = array( 'MY' );
24
+ $this->id = 'stripe_fpx';
25
+ $this->tab_title = __( 'FPX', 'woo-stripe-payment' );
26
+ $this->method_title = __( 'FPX', 'woo-stripe-payment' );
27
+ $this->method_description = __( 'FPX gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
28
+ $this->icon = wc_stripe()->assets_url( 'img/fpx.svg' );
29
+ $this->order_button_text = $this->get_order_button_text( __( 'FPX', 'woo-stripe-payment' ) );
30
+ parent::__construct();
31
+ }
32
+
33
+ public function get_element_params() {
34
+ $params = parent::get_element_params();
35
+ $params['accountHolderType'] = 'individual';
36
+ return $params;
37
+ }
38
+ }
 
includes/gateways/class-wc-payment-gateway-stripe-giropay.php CHANGED
@@ -1,33 +1,32 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_Giropay extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Charge_Trait;
16
-
17
- public function __construct() {
18
- $this->local_payment_type = 'giropay';
19
- $this->currencies = [ 'EUR'
20
- ];
21
- $this->countries = [ 'DE'
22
- ];
23
- $this->id = 'stripe_giropay';
24
- $this->tab_title = __ ( 'Giropay', 'woo-stripe-payment' );
25
- $this->template_name = 'local-payment.php';
26
- $this->token_type = 'Stripe_Local';
27
- $this->method_title = __ ( 'Giropay', 'woo-stripe-payment' );
28
- $this->method_description = __ ( 'Giropay gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
29
- $this->icon = wc_stripe ()->assets_url ( 'img/giropay.svg' );
30
- $this->order_button_text = $this->get_order_button_text ( __ ( 'Giropay', 'woo-stripe-payment' ) );
31
- parent::__construct ();
32
- }
33
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_Giropay extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->local_payment_type = 'giropay';
20
+ $this->currencies = array( 'EUR' );
21
+ $this->countries = array( 'DE' );
22
+ $this->id = 'stripe_giropay';
23
+ $this->tab_title = __( 'Giropay', 'woo-stripe-payment' );
24
+ $this->template_name = 'local-payment.php';
25
+ $this->token_type = 'Stripe_Local';
26
+ $this->method_title = __( 'Giropay', 'woo-stripe-payment' );
27
+ $this->method_description = __( 'Giropay gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
28
+ $this->icon = wc_stripe()->assets_url( 'img/giropay.svg' );
29
+ $this->order_button_text = $this->get_order_button_text( __( 'Giropay', 'woo-stripe-payment' ) );
30
+ parent::__construct();
31
+ }
32
+ }
 
includes/gateways/class-wc-payment-gateway-stripe-googlepay.php CHANGED
@@ -1,278 +1,329 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @author PaymentPlugins
10
- * @since 3.0.0
11
- * @package Stripe/Gateways
12
- *
13
- */
14
- class WC_Payment_Gateway_Stripe_GooglePay extends WC_Payment_Gateway_Stripe {
15
-
16
- use WC_Stripe_Payment_Charge_Trait;
17
-
18
- public function __construct() {
19
- $this->id = 'stripe_googlepay';
20
- $this->tab_title = __ ( 'Google Pay', 'woo-stripe-payment' );
21
- $this->template_name = 'googlepay.php';
22
- $this->token_type = 'Stripe_GooglePay';
23
- $this->method_title = __ ( 'Stripe Google Pay', 'woo-stripe-payment' );
24
- $this->method_description = __ ( 'Google Pay gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
25
- parent::__construct ();
26
- $this->icon = wc_stripe ()->assets_url ( 'img/' . $this->get_option ( 'icon' ) . '.svg' );
27
- }
28
-
29
- public function init_supports() {
30
- parent::init_supports ();
31
- $this->supports[] = 'wc_stripe_cart_checkout';
32
- $this->supports[] = 'wc_stripe_product_checkout';
33
- $this->supports[] = 'wc_stripe_banner_checkout';
34
- }
35
-
36
- public function enqueue_checkout_scripts($scripts) {
37
- $scripts->enqueue_script ( 'googlepay-checkout', $scripts->assets_url ( 'js/frontend/googlepay-checkout.js' ), array(
38
- $scripts->get_handle ( 'wc-stripe' ),
39
- $scripts->get_handle ( 'gpay' )
40
- ), wc_stripe ()->version (), true );
41
- $scripts->localize_script ( 'googlepay-checkout', $this->get_localized_params () );
42
- }
43
-
44
- public function enqueue_product_scripts($scripts) {
45
- $scripts->enqueue_script ( 'googlepay-product', $scripts->assets_url ( 'js/frontend/googlepay-product.js' ), array(
46
- $scripts->get_handle ( 'wc-stripe' ),
47
- $scripts->get_handle ( 'gpay' )
48
- ), wc_stripe ()->version (), true );
49
- $scripts->localize_script ( 'googlepay-product', $this->get_localized_params () );
50
- }
51
-
52
- public function enqueue_cart_scripts($scripts) {
53
- $scripts->enqueue_script ( 'googlepay-cart', $scripts->assets_url ( 'js/frontend/googlepay-cart.js' ), array(
54
- $scripts->get_handle ( 'wc-stripe' ),
55
- $scripts->get_handle ( 'gpay' )
56
- ), wc_stripe ()->version (), true );
57
- $scripts->localize_script ( 'googlepay-cart', $this->get_localized_params () );
58
- }
59
-
60
- public function enqueue_admin_scripts() {
61
- wp_register_script ( 'gpay-external', wc_stripe ()->scripts ()->global_scripts[ 'gpay' ], [], wc_stripe ()->version (), true );
62
- wp_enqueue_script ( 'wc-stripe-gpay-admin', wc_stripe ()->assets_url ( 'js/admin/googlepay.js' ), [
63
- 'gpay-external', 'wc-stripe-admin-settings'
64
- ], wc_stripe ()->version (), true );
65
- }
66
-
67
- public function get_localized_params() {
68
- $data = array_merge_recursive ( parent::get_localized_params (), [
69
- 'environment' => wc_stripe_mode () === 'test' ? 'TEST' : 'PRODUCTION',
70
- 'merchant_id' => wc_stripe_mode () === 'test' ? '' : $this->get_option ( 'merchant_id' ),
71
- 'merchant_name' => $this->get_option ( 'merchant_name' ),
72
- 'button_color' => $this->get_option ( 'button_color' ),
73
- 'button_style' => $this->get_option ( 'button_style' ),
74
- 'total_price_label' => __ ( 'Total', 'woo-stripe-payment' ),
75
- 'routes' => [
76
- 'payment_data' => wc_stripe ()->rest_api->googlepay->rest_url ( 'shipping-data' )
77
- ],
78
- 'messages' => [
79
- 'invalid_amount' => __ ( 'Please update you product quantity before using Google Pay.', 'woo-stripe-payment' )
80
- ],
81
- 'dynamic_price' => $this->is_active ( 'dynamic_price' )
82
- ] );
83
- return $data;
84
- }
85
-
86
- public function get_display_items($encode = false) {
87
- $items = [];
88
- global $wp;
89
- if (wcs_stripe_active () && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment) {
90
- $subscription = wcs_get_subscription ( absint ( $_GET[ 'change_payment_method' ] ) );
91
- $items[] = [
92
- 'label' => __ ( 'Subscription', 'woo-stripe-payment' ),
93
- 'type' => 'SUBTOTAL',
94
- 'price' => strval ( $subscription->get_total () )
95
- ];
96
- } elseif (is_product ()) {
97
- global $product;
98
- $items[] = [
99
- 'label' => esc_attr ( $product->get_name () ),
100
- 'type' => 'LINE_ITEM',
101
- 'price' => strval ( $product->get_price () )
102
- ];
103
- } elseif (is_checkout () && isset ( $wp->query_vars[ 'order-pay' ] )) {
104
- $order = wc_get_order ( absint ( $wp->query_vars[ 'order-pay' ] ) );
105
- // add all order items
106
- foreach ( $order->get_items () as $item ) {
107
- /**
108
- *
109
- * @var WC_Order_Item_Product $item
110
- */
111
- $qty = $item->get_quantity ();
112
-
113
- $items[] = [
114
- 'label' => $qty > 1 ? sprintf ( '%s X %s', $item->get_name (), $qty ) : $item->get_name (),
115
- 'type' => 'LINE_ITEM',
116
- 'price' => strval ( $item->get_subtotal () )
117
- ];
118
- }
119
- // shipping total
120
- if ($order->get_shipping_total ()) {
121
- $items[] = [
122
- 'label' => __ ( 'Shipping', 'woo-stripe-payment' ),
123
- 'type' => 'LINE_ITEM',
124
- 'price' => strval ( $order->get_shipping_total () )
125
- ];
126
- }
127
- // discount total
128
- if ($order->get_total_discount ()) {
129
- $items[] = [
130
- 'label' => __ ( 'Discount', 'woo-stripe-payment' ),
131
- 'type' => 'LINE_ITEM',
132
- 'price' => strval ( $order->get_total_discount () )
133
- ];
134
- }
135
- if ($order->get_fees ()) {
136
- $fee_total = 0;
137
- foreach ( $order->get_fees () as $fee ) {
138
- $fee_total += $fee->get_total ();
139
- }
140
- $items[] = [
141
- 'label' => __ ( 'Fees', 'woo-stripe-payment' ),
142
- 'type' => 'LINE_ITEM',
143
- 'price' => strval ( $fee_total )
144
- ];
145
- }
146
- // tax total
147
- if ($order->get_total_tax ()) {
148
- $items[] = [
149
- 'label' => __ ( 'Tax', 'woocommerce' ),
150
- 'type' => 'TAX',
151
- 'price' => strval ( $order->get_total_tax () )
152
- ];
153
- }
154
- } else {
155
- $incl_tax = wc_stripe_display_prices_including_tax ();
156
- $decimals = ( ( $decimals = wc_get_price_decimals () ) < 2 ? $decimals : 2 );
157
- foreach ( WC ()->cart->get_cart () as $cart_item ) {
158
- /**
159
- *
160
- * @var WC_Product $product
161
- */
162
- $product = $cart_item[ 'data' ];
163
- $qty = $cart_item[ 'quantity' ];
164
- $args = [ 'qty' => $qty
165
- ];
166
- $items[] = [
167
- 'label' => $qty > 1 ? sprintf ( '%s X %s', $product->get_name (), $qty ) : $product->get_name (),
168
- 'type' => 'LINE_ITEM',
169
- 'price' => strval ( round ( $incl_tax ? wc_get_price_including_tax ( $product, $args ) : wc_get_price_excluding_tax ( $product, $args ), $decimals ) )
170
- ];
171
- }
172
- if (WC ()->cart->needs_shipping ()) {
173
- $items[] = [
174
- 'label' => __ ( 'Shipping', 'woo-stripe-payment' ),
175
- 'type' => 'LINE_ITEM',
176
- 'price' => strval ( round ( $incl_tax ? WC ()->cart->shipping_total + WC ()->cart->shipping_tax_total : WC ()->cart->shipping_total, wc_get_price_decimals () ) )
177
- ];
178
- }
179
-
180
- // fees
181
- foreach ( WC ()->cart->get_fees () as $fee_item ) {
182
- /**
183
- *
184
- * @var WC_Order_I
185
- */
186
- $items[] = [ 'label' => $fee_item->name,
187
- 'type' => 'LINE_ITEM',
188
- 'price' => strval ( round ( $incl_tax ? $fee_item->total + $fee_item->tax : $fee_item->total ), $decimals )
189
- ];
190
- }
191
-
192
- // coupons
193
- if (WC ()->cart->discount_cart != 0) {
194
- $items[] = [
195
- 'label' => __ ( 'Discount', 'woo-stripe-payment' ),
196
- 'type' => 'LINE_ITEM',
197
- 'price' => strval ( round ( - 1 * abs ( $incl_tax ? WC ()->cart->discount_cart + WC ()->cart->discount_cart_tax : WC ()->cart->discount_cart ), $decimals ) )
198
- ];
199
- }
200
-
201
- if (! $incl_tax && wc_tax_enabled ()) {
202
- $items[] = [
203
- 'label' => __ ( 'Tax', 'woo-stripe-payment' ),
204
- 'type' => 'TAX',
205
- 'price' => strval ( round ( WC ()->cart->get_taxes_total (), $decimals ) )
206
- ];
207
- }
208
- }
209
- return $encode ? htmlspecialchars ( json_encode ( $items ) ) : $items;
210
- }
211
-
212
- public function get_shipping_methods($encode = false) {
213
- if (wcs_stripe_active () && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment) {
214
- $methods = [];
215
- } else {
216
- $methods = [];
217
- $packages = WC ()->shipping ()->get_packages ();
218
- foreach ( $packages as $i => $package ) {
219
- foreach ( $package[ 'rates' ] as $rate ) {
220
- /**
221
- *
222
- * @var WC_Shipping_Rate $rate
223
- */
224
- $methods[] = [
225
- 'id' => sprintf ( '%s:%s', $i, $rate->id ),
226
- 'label' => $this->get_shipping_method_label ( $rate ),
227
- 'description' => ''
228
- ];
229
- }
230
- }
231
- if (empty ( $methods )) {
232
- // GPay does not like empty shipping methods. Make a temporary one;
233
- $methods[] = [ 'id' => 'default',
234
- 'label' => __ ( 'Waiting...', 'woo-stripe-payment' ),
235
- 'description' => __ ( 'loading shipping methods...', 'woo-stripe-payment' )
236
- ];
237
- }
238
- }
239
- return $encode ? htmlspecialchars ( json_encode ( $methods ) ) : $methods;
240
- }
241
-
242
- /**
243
- * Return a formatted shipping method label.
244
- * <strong>Example</strong>&nbsp;5 Day shipping: 5 USD
245
- *
246
- * @param WC_Shipping_Rate $rate
247
- * @return
248
- *
249
- */
250
- public function get_shipping_method_label($rate) {
251
- $incl_tax = wc_stripe_display_prices_including_tax ();
252
-
253
- if ($incl_tax) {
254
- $total = $rate->cost + $rate->get_shipping_tax ();
255
- } else {
256
- $total = $rate->cost;
257
- }
258
- $decimals = ( ( $decimals = wc_get_price_decimals () ) < 2 ? $decimals : 2 );
259
- $total = number_format ( $total, $decimals );
260
- $label = sprintf ( '%s: %s %s', $rate->get_label (), $total, get_woocommerce_currency () );
261
-
262
- if ($incl_tax) {
263
- if ($rate->get_shipping_tax () > 0 && ! wc_prices_include_tax ()) {
264
- $label .= ' ' . WC ()->countries->inc_tax_or_vat ();
265
- }
266
- } else {
267
- if ($rate->get_shipping_tax () > 0 && wc_prices_include_tax ()) {
268
- $label .= ' ' . WC ()->countries->ex_tax_or_vat ();
269
- }
270
- }
271
- return $label;
272
- }
273
-
274
- public function add_to_cart_response($data) {
275
- $data[ 'googlepay' ][ 'displayItems' ] = $this->get_display_items ();
276
- return $data;
277
- }
278
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @author PaymentPlugins
11
+ * @since 3.0.0
12
+ * @package Stripe/Gateways
13
+ */
14
+ class WC_Payment_Gateway_Stripe_GooglePay extends WC_Payment_Gateway_Stripe {
15
+
16
+ use WC_Stripe_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->id = 'stripe_googlepay';
20
+ $this->tab_title = __( 'Google Pay', 'woo-stripe-payment' );
21
+ $this->template_name = 'googlepay.php';
22
+ $this->token_type = 'Stripe_GooglePay';
23
+ $this->method_title = __( 'Stripe Google Pay', 'woo-stripe-payment' );
24
+ $this->method_description = __( 'Google Pay gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
25
+ parent::__construct();
26
+ $this->icon = wc_stripe()->assets_url( 'img/' . $this->get_option( 'icon' ) . '.svg' );
27
+ }
28
+
29
+ public function init_supports() {
30
+ parent::init_supports();
31
+ $this->supports[] = 'wc_stripe_cart_checkout';
32
+ $this->supports[] = 'wc_stripe_product_checkout';
33
+ $this->supports[] = 'wc_stripe_banner_checkout';
34
+ }
35
+
36
+ public function enqueue_checkout_scripts( $scripts ) {
37
+ $scripts->enqueue_script(
38
+ 'googlepay-checkout',
39
+ $scripts->assets_url( 'js/frontend/googlepay-checkout.js' ),
40
+ array(
41
+ $scripts->get_handle( 'wc-stripe' ),
42
+ $scripts->get_handle( 'gpay' ),
43
+ ),
44
+ wc_stripe()->version(),
45
+ true
46
+ );
47
+ $scripts->localize_script( 'googlepay-checkout', $this->get_localized_params() );
48
+ }
49
+
50
+ public function enqueue_product_scripts( $scripts ) {
51
+ $scripts->enqueue_script(
52
+ 'googlepay-product',
53
+ $scripts->assets_url( 'js/frontend/googlepay-product.js' ),
54
+ array(
55
+ $scripts->get_handle( 'wc-stripe' ),
56
+ $scripts->get_handle( 'gpay' ),
57
+ ),
58
+ wc_stripe()->version(),
59
+ true
60
+ );
61
+ $scripts->localize_script( 'googlepay-product', $this->get_localized_params() );
62
+ }
63
+
64
+ public function enqueue_cart_scripts( $scripts ) {
65
+ $scripts->enqueue_script(
66
+ 'googlepay-cart',
67
+ $scripts->assets_url( 'js/frontend/googlepay-cart.js' ),
68
+ array(
69
+ $scripts->get_handle( 'wc-stripe' ),
70
+ $scripts->get_handle( 'gpay' ),
71
+ ),
72
+ wc_stripe()->version(),
73
+ true
74
+ );
75
+ $scripts->localize_script( 'googlepay-cart', $this->get_localized_params() );
76
+ }
77
+
78
+ public function enqueue_admin_scripts() {
79
+ wp_register_script( 'gpay-external', wc_stripe()->scripts()->global_scripts['gpay'], array(), wc_stripe()->version(), true );
80
+ wp_enqueue_script(
81
+ 'wc-stripe-gpay-admin',
82
+ wc_stripe()->assets_url( 'js/admin/googlepay.js' ),
83
+ array(
84
+ 'gpay-external',
85
+ 'wc-stripe-admin-settings',
86
+ ),
87
+ wc_stripe()->version(),
88
+ true
89
+ );
90
+ }
91
+
92
+ public function get_localized_params() {
93
+ $data = array_merge_recursive(
94
+ parent::get_localized_params(),
95
+ array(
96
+ 'environment' => wc_stripe_mode() === 'test' ? 'TEST' : 'PRODUCTION',
97
+ 'merchant_id' => wc_stripe_mode() === 'test' ? '' : $this->get_option( 'merchant_id' ),
98
+ 'merchant_name' => $this->get_option( 'merchant_name' ),
99
+ 'button_color' => $this->get_option( 'button_color' ),
100
+ 'button_style' => $this->get_option( 'button_style' ),
101
+ 'total_price_label' => __( 'Total', 'woo-stripe-payment' ),
102
+ 'routes' => array( 'payment_data' => wc_stripe()->rest_api->googlepay->rest_url( 'shipping-data' ) ),
103
+ 'messages' => array( 'invalid_amount' => __( 'Please update you product quantity before using Google Pay.', 'woo-stripe-payment' ) ),
104
+ 'dynamic_price' => $this->is_active( 'dynamic_price' ),
105
+ )
106
+ );
107
+
108
+ return $data;
109
+ }
110
+
111
+ public function get_display_items( $encode = false ) {
112
+ $items = array();
113
+ global $wp;
114
+ if ( wcs_stripe_active() && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment ) {
115
+ $subscription = wcs_get_subscription( absint( $_GET['change_payment_method'] ) );
116
+ $items[] = array(
117
+ 'label' => __( 'Subscription', 'woo-stripe-payment' ),
118
+ 'type' => 'SUBTOTAL',
119
+ 'price' => strval( $subscription->get_total() ),
120
+ );
121
+ } elseif ( is_product() ) {
122
+ global $product;
123
+ $items[] = array(
124
+ 'label' => esc_attr( $product->get_name() ),
125
+ 'type' => 'LINE_ITEM',
126
+ 'price' => strval( $product->get_price() ),
127
+ );
128
+ } elseif ( is_checkout() && isset( $wp->query_vars['order-pay'] ) ) {
129
+ $order = wc_get_order( absint( $wp->query_vars['order-pay'] ) );
130
+ // add all order items
131
+ foreach ( $order->get_items() as $item ) {
132
+ /**
133
+ *
134
+ * @var WC_Order_Item_Product $item
135
+ */
136
+ $qty = $item->get_quantity();
137
+
138
+ $items[] = array(
139
+ 'label' => $qty > 1 ? sprintf( '%s X %s', $item->get_name(), $qty ) : $item->get_name(),
140
+ 'type' => 'LINE_ITEM',
141
+ 'price' => strval( $item->get_subtotal() ),
142
+ );
143
+ }
144
+ // shipping total
145
+ if ( $order->get_shipping_total() ) {
146
+ $items[] = array(
147
+ 'label' => __( 'Shipping', 'woo-stripe-payment' ),
148
+ 'type' => 'LINE_ITEM',
149
+ 'price' => strval( $order->get_shipping_total() ),
150
+ );
151
+ }
152
+ // discount total
153
+ if ( $order->get_total_discount() ) {
154
+ $items[] = array(
155
+ 'label' => __( 'Discount', 'woo-stripe-payment' ),
156
+ 'type' => 'LINE_ITEM',
157
+ 'price' => strval( $order->get_total_discount() ),
158
+ );
159
+ }
160
+ if ( $order->get_fees() ) {
161
+ $fee_total = 0;
162
+ foreach ( $order->get_fees() as $fee ) {
163
+ $fee_total += $fee->get_total();
164
+ }
165
+ $items[] = array(
166
+ 'label' => __( 'Fees', 'woo-stripe-payment' ),
167
+ 'type' => 'LINE_ITEM',
168
+ 'price' => strval( $fee_total ),
169
+ );
170
+ }
171
+ // tax total
172
+ if ( $order->get_total_tax() ) {
173
+ $items[] = array(
174
+ 'label' => __( 'Tax', 'woocommerce' ),
175
+ 'type' => 'TAX',
176
+ 'price' => strval( $order->get_total_tax() ),
177
+ );
178
+ }
179
+ } else {
180
+ $incl_tax = wc_stripe_display_prices_including_tax();
181
+ $decimals = ( ( $decimals = wc_get_price_decimals() ) < 2 ? $decimals : 2 );
182
+ foreach ( WC()->cart->get_cart() as $cart_item ) {
183
+ /**
184
+ *
185
+ * @var WC_Product $product
186
+ */
187
+ $product = $cart_item['data'];
188
+ $qty = $cart_item['quantity'];
189
+ $args = array( 'qty' => $qty );
190
+ $items[] = array(
191
+ 'label' => $qty > 1 ? sprintf( '%s X %s', $product->get_name(), $qty ) : $product->get_name(),
192
+ 'type' => 'LINE_ITEM',
193
+ 'price' => strval( round( $incl_tax ? wc_get_price_including_tax( $product, $args ) : wc_get_price_excluding_tax( $product, $args ), $decimals ) ),
194
+ );
195
+ }
196
+ if ( WC()->cart->needs_shipping() ) {
197
+ $items[] = array(
198
+ 'label' => __( 'Shipping', 'woo-stripe-payment' ),
199
+ 'type' => 'LINE_ITEM',
200
+ 'price' => strval( round( $incl_tax ? WC()->cart->shipping_total + WC()->cart->shipping_tax_total : WC()->cart->shipping_total, $decimals ) ),
201
+ );
202
+ }
203
+
204
+ // fees
205
+ foreach ( WC()->cart->get_fees() as $fee_item ) {
206
+ /**
207
+ *
208
+ * @var WC_Order_I
209
+ */
210
+ $items[] = array(
211
+ 'label' => $fee_item->name,
212
+ 'type' => 'LINE_ITEM',
213
+ 'price' => strval( round( $incl_tax ? $fee_item->total + $fee_item->tax : $fee_item->total, $decimals ) ),
214
+ );
215
+ }
216
+
217
+ // coupons
218
+ if ( WC()->cart->discount_cart != 0 ) {
219
+ $items[] = array(
220
+ 'label' => __( 'Discount', 'woo-stripe-payment' ),
221
+ 'type' => 'LINE_ITEM',
222
+ 'price' => strval(
223
+ round(
224
+ - 1 *
225
+ abs( $incl_tax ? WC()->cart->discount_cart + WC()->cart->discount_cart_tax : WC()->cart->discount_cart ),
226
+ $decimals
227
+ )
228
+ ),
229
+ );
230
+ }
231
+
232
+ if ( ! $incl_tax && wc_tax_enabled() ) {
233
+ $item = array(
234
+ 'label' => __( 'Tax', 'woo-stripe-payment' ),
235
+ 'type' => 'TAX',
236
+ 'price' => strval( round( WC()->cart->get_taxes_total(), $decimals ) ),
237
+ );
238
+ if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) {
239
+ if ( 0 < WC()->cart->get_taxes_total() ) {
240
+ $items[] = $item;
241
+ }
242
+ } else {
243
+ $items[] = $item;
244
+ }
245
+ }
246
+ }
247
+
248
+ return $encode ? htmlspecialchars( json_encode( $items ) ) : $items;
249
+ }
250
+
251
+ public function get_shipping_methods( $encode = false ) {
252
+ if ( wcs_stripe_active() && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment ) {
253
+ $methods = array();
254
+ } else {
255
+ $methods = array();
256
+ $packages = WC()->shipping()->get_packages();
257
+ foreach ( $packages as $i => $package ) {
258
+ foreach ( $package['rates'] as $rate ) {
259
+ /**
260
+ *
261
+ * @var WC_Shipping_Rate $rate
262
+ */
263
+ $methods[] = array(
264
+ 'id' => sprintf( '%s:%s', $i, $rate->id ),
265
+ 'label' => $this->get_shipping_method_label( $rate ),
266
+ 'description' => '',
267
+ );
268
+ }
269
+ }
270
+ if ( empty( $methods ) ) {
271
+ // GPay does not like empty shipping methods. Make a temporary one;
272
+ $methods[] = array(
273
+ 'id' => 'default',
274
+ 'label' => __( 'Waiting...', 'woo-stripe-payment' ),
275
+ 'description' => __( 'loading shipping methods...', 'woo-stripe-payment' ),
276
+ );
277
+ }
278
+ }
279
+
280
+ return $encode ? htmlspecialchars( json_encode( $methods ) ) : $methods;
281
+ }
282
+
283
+ /**
284
+ * Return a formatted shipping method label.
285
+ * <strong>Example</strong>&nbsp;5 Day shipping: 5 USD
286
+ *
287
+ * @param WC_Shipping_Rate $rate
288
+ *
289
+ * @return
290
+ */
291
+ public function get_shipping_method_label( $rate ) {
292
+ $incl_tax = wc_stripe_display_prices_including_tax();
293
+
294
+ if ( $incl_tax ) {
295
+ $total = $rate->cost + $rate->get_shipping_tax();
296
+ } else {
297
+ $total = $rate->cost;
298
+ }
299
+ $decimals = ( ( $decimals = wc_get_price_decimals() ) < 2 ? $decimals : 2 );
300
+ $total = number_format( $total, $decimals );
301
+ $label = sprintf( '%s: %s %s', $rate->get_label(), $total, get_woocommerce_currency() );
302
+
303
+ if ( $incl_tax ) {
304
+ if ( $rate->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) {
305
+ $label .= ' ' . WC()->countries->inc_tax_or_vat();
306
+ }
307
+ } else {
308
+ if ( $rate->get_shipping_tax() > 0 && wc_prices_include_tax() ) {
309
+ $label .= ' ' . WC()->countries->ex_tax_or_vat();
310
+ }
311
+ }
312
+
313
+ return $label;
314
+ }
315
+
316
+ public function add_to_cart_response( $data ) {
317
+ $data['googlepay']['displayItems'] = $this->get_display_items();
318
+
319
+ return $data;
320
+ }
321
+
322
+ /**
323
+ * Outputs fields required by Google Pay to render the payment wallet.
324
+ */
325
+ public function output_display_items() {
326
+ printf( '<input type="hidden" id="%1$s" data-items="%2$s"/>', 'googlepay_display_items', $this->get_display_items( true ) );
327
+ printf( '<input type="hidden" id="%1$s" data-items="%2$s"/>', 'googlepay_shipping_options', $this->get_shipping_methods( true ) );
328
+ }
329
+ }
includes/gateways/class-wc-payment-gateway-stripe-ideal.php CHANGED
@@ -1,35 +1,34 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_Ideal extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- protected $payment_method_type = 'ideal';
16
-
17
- // use WC_Stripe_Local_Payment_Charge_Trait;
18
-
19
- use WC_Stripe_Local_Payment_Intent_Trait;
20
-
21
- public function __construct() {
22
- $this->local_payment_type = 'ideal';
23
- $this->currencies = [ 'EUR'
24
- ];
25
- $this->countries = [ 'NL'
26
- ];
27
- $this->id = 'stripe_ideal';
28
- $this->tab_title = __ ( 'iDEAL', 'woo-stripe-payment' );
29
- $this->method_title = __ ( 'iDEAL', 'woo-stripe-payment' );
30
- $this->method_description = __ ( 'Ideal gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
31
- $this->icon = wc_stripe ()->assets_url ( 'img/ideal.svg' );
32
- $this->order_button_text = $this->get_order_button_text ( __ ( 'iDEAL', 'woo-stripe-payment' ) );
33
- parent::__construct ();
34
- }
35
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_Ideal extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ protected $payment_method_type = 'ideal';
17
+
18
+ // use WC_Stripe_Local_Payment_Charge_Trait;
19
+
20
+ use WC_Stripe_Local_Payment_Intent_Trait;
21
+
22
+ public function __construct() {
23
+ $this->local_payment_type = 'ideal';
24
+ $this->currencies = array( 'EUR' );
25
+ $this->countries = array( 'NL' );
26
+ $this->id = 'stripe_ideal';
27
+ $this->tab_title = __( 'iDEAL', 'woo-stripe-payment' );
28
+ $this->method_title = __( 'iDEAL', 'woo-stripe-payment' );
29
+ $this->method_description = __( 'Ideal gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
30
+ $this->icon = wc_stripe()->assets_url( 'img/ideal.svg' );
31
+ $this->order_button_text = $this->get_order_button_text( __( 'iDEAL', 'woo-stripe-payment' ) );
32
+ parent::__construct();
33
+ }
34
+ }
 
includes/gateways/class-wc-payment-gateway-stripe-klarna.php CHANGED
@@ -1,277 +1,298 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_Klarna extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Charge_Trait;
16
-
17
- public function __construct() {
18
- $this->local_payment_type = 'klarna';
19
- $this->currencies = [ 'EUR', 'SEK', 'NOK',
20
- 'DKK', 'GBP', 'USD'
21
- ];
22
- $this->id = 'stripe_klarna';
23
- $this->tab_title = __ ( 'Klarna', 'woo-stripe-payment' );
24
- $this->template_name = 'local-payment.php';
25
- $this->token_type = 'Stripe_Local';
26
- $this->method_title = __ ( 'Klarna', 'woo-stripe-payment' );
27
- $this->method_description = __ ( 'Klarna gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
28
- $this->icon = wc_stripe ()->assets_url ( 'img/klarna.svg' );
29
- $this->order_button_text = $this->get_order_button_text ( __ ( 'Klarna', 'woo-stripe-payment' ) );
30
- parent::__construct ();
31
- $this->template_name = 'klarna.php';
32
- }
33
-
34
- public function hooks() {
35
- parent::hooks ();
36
- add_action ( 'woocommerce_review_order_before_payment', array(
37
- $this, 'enqueue_klarna'
38
- ) );
39
- add_action ( 'woocommerce_pay_order_after_submit', array(
40
- $this, 'enqueue_klarna'
41
- ) );
42
- }
43
-
44
- /**
45
- * Enqueue Klarna based on whether it's available or not.
46
- */
47
- public function enqueue_klarna() {
48
- if ($this->is_available ()) {
49
- wc_stripe ()->scripts ()->enqueue_script ( 'klarna', 'https://x.klarnacdn.net/kp/lib/v1/api.js', [], wc_stripe ()->version (), true );
50
- }
51
- }
52
-
53
- public function get_required_parameters() {
54
- return [ 'USD' => [ 'US'
55
- ], 'EUR' => [ 'AT', 'FI', 'DE', 'NL'
56
- ], 'DKK' => [ 'DK'
57
- ], 'NOK' => [ 'NO'
58
- ], 'SEK' => [ 'SE'
59
- ], 'GBP' => [ 'GB'
60
- ]
61
- ];
62
- }
63
-
64
- public function is_local_payment_available() {
65
- global $wp;
66
- if (isset ( $wp->query_vars[ 'order-pay' ] )) {
67
- $order = wc_get_order ( absint ( $wp->query_vars[ 'order-pay' ] ) );
68
- $currency = $order->get_currency ();
69
- $country = $order->get_billing_country ();
70
- } else {
71
- $currency = get_woocommerce_currency ();
72
- $country = WC ()->customer ? WC ()->customer->get_billing_country () : null;
73
- if (! $country) {
74
- $country = WC ()->countries->get_base_country ();
75
- }
76
- }
77
- if ($country) {
78
- $params = $this->get_required_parameters ();
79
- return isset ( $params[ $currency ] ) && array_search ( $country, $params[ $currency ] ) !== false;
80
- }
81
- return false;
82
- }
83
-
84
- /**
85
- *
86
- * {@inheritDoc}
87
- *
88
- * @see WC_Payment_Gateway_Stripe::payment_fields()
89
- */
90
- public function payment_fields() {
91
- // this might be an update checkout request. If so, update the source if it exists
92
- if (is_ajax () && ( $order_id = absint ( WC ()->session->get ( 'order_awaiting_payment' ) ) )) {
93
- $order = wc_get_order ( $order_id );
94
- if (( $source_id = $order->get_meta ( WC_Stripe_Constants::SOURCE_ID, true ) )) {
95
- $this->payment_object->get_gateway ()->update_source ( $source_id, $this->get_update_source_args ( $order ) );
96
- }
97
- }
98
- parent::payment_fields ();
99
- }
100
-
101
- public function get_local_payment_settings() {
102
- return wp_parse_args ( [
103
- 'payment_categories' => [
104
- 'title' => __ ( 'Payment Categories', 'woo-stripe-payment' ),
105
- 'type' => 'multiselect',
106
- 'class' => 'wc-enhanced-select',
107
- 'options' => $this->get_payment_categories (),
108
- 'default' => array_keys ( $this->get_payment_categories () ),
109
- 'desc_tip' => true,
110
- 'description' => __ ( 'Thes are the payment categories that will be displayed on the checkout page if they are supported. Note, depending on the customer\'s billing country, not all enabled options may show.', 'woo-stripe-payment' )
111
- ]
112
- ], parent::get_local_payment_settings () );
113
- }
114
-
115
- private function get_update_source_args($order) {
116
- $args = $this->get_source_args ( $order, true );
117
- unset ( $args[ 'type' ], $args[ 'currency' ], $args[ 'statement_descriptor' ], $args[ 'redirect' ], $args[ 'klarna' ][ 'product' ], $args[ 'klarna' ][ 'locale' ] );
118
- return $args;
119
- }
120
-
121
- /**
122
- *
123
- * {@inheritDoc}
124
- *
125
- * @see WC_Payment_Gateway_Stripe_Local_Payment::get_source_args()
126
- */
127
- public function get_source_args($order, $update = false) {
128
- if ($update) {
129
- /*
130
- * Use customer if this is an update since customer object has been updated
131
- * with all checkout form data in the update_order_review process.
132
- */
133
- $object = WC ()->customer;
134
- } else {
135
- $object = $order;
136
- }
137
-
138
- $args = array_merge_recursive ( parent::get_source_args ( $order ), [
139
- 'klarna' => [ 'product' => 'payment',
140
- 'purchase_country' => $object->get_billing_country (),
141
- 'first_name' => $object->get_billing_first_name (),
142
- 'last_name' => $object->get_billing_last_name ()
143
- ],
144
- 'owner' => [
145
- 'address' => [
146
- 'city' => $object->get_billing_city (),
147
- 'country' => $object->get_billing_country (),
148
- 'line1' => $object->get_billing_address_1 (),
149
- 'line2' => $object->get_billing_address_2 (),
150
- 'postal_code' => $object->get_billing_postcode (),
151
- 'state' => $object->get_billing_state ()
152
- ]
153
- ]
154
- ] );
155
- $args[ 'source_order' ] = [];
156
-
157
- if (( $locale = get_locale () )) {
158
- $args[ 'klarna' ][ 'locale' ] = str_replace ( '_', '-', $locale );
159
- }
160
-
161
- if ($order->get_shipping_address_1 ()) {
162
- $args[ 'klarna' ][ 'shipping_first_name' ] = $object->get_shipping_first_name ();
163
- $args[ 'klarna' ][ 'shipping_last_name' ] = $object->get_shipping_last_name ();
164
- $args[ 'source_order' ][ 'shipping' ][ 'address' ] = [
165
- 'city' => $object->get_billing_city (),
166
- 'country' => $object->get_shipping_country (),
167
- 'line1' => $object->get_shipping_address_1 (),
168
- 'line2' => $object->get_shipping_address_2 (),
169
- 'postal_code' => $object->get_shipping_postcode (),
170
- 'state' => $object->get_shipping_state ()
171
- ];
172
- }
173
-
174
- foreach ( $order->get_items ( 'line_item' ) as $item ) {
175
- /**
176
- *
177
- * @var WC_Order_Item_Product $item
178
- */
179
- $args[ 'source_order' ][ 'items' ][] = [
180
- 'type' => 'sku',
181
- 'amount' => wc_stripe_add_number_precision ( $item->get_subtotal (), $order->get_currency () ),
182
- 'currency' => $order->get_currency (),
183
- 'quantity' => $item->get_quantity (),
184
- 'description' => $item->get_name ()
185
- ];
186
- }
187
- // shipping
188
- if ($order->get_shipping_total ()) {
189
- $args[ 'source_order' ][ 'items' ][] = [
190
- 'type' => 'shipping',
191
- 'amount' => wc_stripe_add_number_precision ( $order->get_shipping_total (), $order->get_currency () ),
192
- 'currency' => $order->get_currency (),
193
- 'quantity' => 1,
194
- 'description' => __ ( 'Shipping', 'woo-stripe-payment' )
195
- ];
196
- }
197
- // discount
198
- if ($order->get_discount_total ()) {
199
- $args[ 'source_order' ][ 'items' ][] = [
200
- 'type' => 'discount',
201
- 'amount' => - 1 * wc_stripe_add_number_precision ( $order->get_discount_total (), $order->get_currency () ),
202
- 'currency' => $order->get_currency (),
203
- 'quantity' => 1,
204
- 'description' => __ ( 'Discount', 'woo-stripe-payment' )
205
- ];
206
- }
207
- // fees
208
- if ($order->get_fees ()) {
209
- $fee_total = 0;
210
- foreach ( $order->get_fees () as $fee ) {
211
- $fee_total += wc_stripe_add_number_precision ( $fee->get_total (), $order->get_currency () );
212
- }
213
- $args[ 'source_order' ][ 'items' ][] = [
214
- 'type' => 'sku', 'amount' => $fee_total,
215
- 'currency' => $order->get_currency (),
216
- 'quantity' => 1,
217
- 'description' => __ ( 'Fee', 'woo-stripe-payment' )
218
- ];
219
- }
220
- // tax
221
- if ($order->get_total_tax ()) {
222
- $args[ 'source_order' ][ 'items' ][] = [
223
- 'type' => 'tax',
224
- 'amount' => wc_stripe_add_number_precision ( $order->get_total_tax () ),
225
- 'description' => __ ( 'Tax', 'woo-stripe-payment' ),
226
- 'quantity' => 1,
227
- 'currency' => $order->get_currency ()
228
- ];
229
- }
230
- return $args;
231
- }
232
-
233
- /**
234
- *
235
- * {@inheritDoc}
236
- *
237
- * @see WC_Payment_Gateway_Stripe_Local_Payment::get_source_redirect_url()
238
- */
239
- public function get_source_redirect_url($source, $order) {
240
- $klarna_categories = explode ( ',', $source[ 'klarna' ][ 'payment_method_categories' ] );
241
- $klarna_categories = array_intersect ( $klarna_categories, $this->get_option ( 'payment_categories' ) );
242
- $source[ 'klarna' ][ 'payment_method_categories' ] = implode ( $klarna_categories, ',' );
243
- return '#local_payment=klarna&redirect=' . $this->get_local_payment_return_url ( $order ) . '&encoded_source=' . base64_encode ( wp_json_encode ( $source ) );
244
- }
245
-
246
- protected function get_local_payment_return_url($order) {
247
- return add_query_arg ( 'source', $order->get_meta ( '_stripe_source_id', true ), parent::get_local_payment_return_url ( $order ) );
248
- }
249
-
250
- /**
251
- *
252
- * @return mixed
253
- */
254
- public function get_payment_categories() {
255
- return apply_filters ( 'wc_stripe_klarna_payment_categries', [
256
- 'pay_now' => __ ( 'Pay Now', 'woo-stripe-payment' ),
257
- 'pay_later' => __ ( 'Pay Later', 'woo-stripe-payment' ),
258
- 'pay_over_time' => __ ( 'Pay Over Time', 'woo-stripe-payment' )
259
- ] );
260
- }
261
-
262
- /**
263
- *
264
- * {@inheritDoc}
265
- *
266
- * @see WC_Payment_Gateway_Stripe_Local_Payment::get_payment_description()
267
- */
268
- public function get_payment_description() {
269
- return '<p>' . sprintf ( __ ( 'Click %shere%s for Klarna test payment methods.', 'woo-stripe-payment' ), '<a target="_blank" href="https://stripe.com/docs/sources/klarna#testing-klarna-payments">', '</a>' ) . '</p>' . parent::get_payment_description ();
270
- }
271
-
272
- public function get_localized_params() {
273
- $params = parent::get_localized_params ();
274
- $params[ 'messages' ][ 'klarna_error' ] = __ ( 'Your purchase is not approved.', 'woo-stripe-payment' );
275
- return $params;
276
- }
277
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_Klarna extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->local_payment_type = 'klarna';
20
+ $this->currencies = array( 'EUR', 'SEK', 'NOK', 'DKK', 'GBP', 'USD' );
21
+ $this->id = 'stripe_klarna';
22
+ $this->tab_title = __( 'Klarna', 'woo-stripe-payment' );
23
+ $this->template_name = 'local-payment.php';
24
+ $this->token_type = 'Stripe_Local';
25
+ $this->method_title = __( 'Klarna', 'woo-stripe-payment' );
26
+ $this->method_description = __( 'Klarna gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
27
+ $this->icon = wc_stripe()->assets_url( 'img/klarna.svg' );
28
+ $this->order_button_text = $this->get_order_button_text( __( 'Klarna', 'woo-stripe-payment' ) );
29
+ parent::__construct();
30
+ $this->template_name = 'klarna.php';
31
+ }
32
+
33
+ public function hooks() {
34
+ parent::hooks();
35
+ add_action( 'woocommerce_review_order_before_payment', array( $this, 'enqueue_klarna' ) );
36
+ add_action( 'woocommerce_pay_order_after_submit', array( $this, 'enqueue_klarna' ) );
37
+ }
38
+
39
+ /**
40
+ * Enqueue Klarna based on whether it's available or not.
41
+ */
42
+ public function enqueue_klarna() {
43
+ if ( $this->is_available() ) {
44
+ wc_stripe()->scripts()->enqueue_script( 'klarna', 'https://x.klarnacdn.net/kp/lib/v1/api.js', array(), wc_stripe()->version(), true );
45
+ }
46
+ }
47
+
48
+ public function get_required_parameters() {
49
+ return array(
50
+ 'USD' => array( 'US' ),
51
+ 'EUR' => array( 'AT', 'FI', 'DE', 'NL' ),
52
+ 'DKK' => array( 'DK' ),
53
+ 'NOK' => array( 'NO' ),
54
+ 'SEK' => array( 'SE' ),
55
+ 'GBP' => array( 'GB' ),
56
+ );
57
+ }
58
+
59
+ public function is_local_payment_available() {
60
+ global $wp;
61
+ if ( isset( $wp->query_vars['order-pay'] ) ) {
62
+ $order = wc_get_order( absint( $wp->query_vars['order-pay'] ) );
63
+ $currency = $order->get_currency();
64
+ $country = $order->get_billing_country();
65
+ } else {
66
+ $currency = get_woocommerce_currency();
67
+ $country = WC()->customer ? WC()->customer->get_billing_country() : null;
68
+ if ( ! $country ) {
69
+ $country = WC()->countries->get_base_country();
70
+ }
71
+ }
72
+ if ( $country ) {
73
+ $params = $this->get_required_parameters();
74
+
75
+ return isset( $params[ $currency ] ) && array_search( $country, $params[ $currency ] ) !== false;
76
+ }
77
+
78
+ return false;
79
+ }
80
+
81
+ /**
82
+ *
83
+ * {@inheritDoc}
84
+ *
85
+ * @see WC_Payment_Gateway_Stripe::payment_fields()
86
+ */
87
+ public function payment_fields() {
88
+ // this might be an update checkout request. If so, update the source if it exists
89
+ if ( is_ajax() && ( $order_id = absint( WC()->session->get( 'order_awaiting_payment' ) ) ) ) {
90
+ $order = wc_get_order( $order_id );
91
+ if ( $order->get_payment_method() === $this->id && ( $source_id = $order->get_meta( WC_Stripe_Constants::SOURCE_ID, true ) ) ) {
92
+ $this->payment_object->get_gateway()->sources->mode( wc_stripe_order_mode( $order ) )->update( $source_id, $this->get_update_source_args( $order ) );
93
+ }
94
+ }
95
+ parent::payment_fields();
96
+ }
97
+
98
+ public function get_local_payment_settings() {
99
+ return wp_parse_args(
100
+ array(
101
+ 'payment_categories' => array(
102
+ 'title' => __( 'Payment Categories', 'woo-stripe-payment' ),
103
+ 'type' => 'multiselect',
104
+ 'class' => 'wc-enhanced-select',
105
+ 'options' => $this->get_payment_categories(),
106
+ 'default' => array_keys( $this->get_payment_categories() ),
107
+ 'desc_tip' => true,
108
+ 'description' => __(
109
+ 'These are the payment categories that will be displayed on the checkout page if they are supported. Note, depending on the customer\'s billing country, not all enabled options may show.',
110
+ 'woo-stripe-payment'
111
+ ),
112
+ ),
113
+ ),
114
+ parent::get_local_payment_settings()
115
+ );
116
+ }
117
+
118
+ private function get_update_source_args( $order ) {
119
+ $args = $this->get_source_args( $order, true );
120
+ unset( $args['type'], $args['currency'], $args['statement_descriptor'], $args['redirect'], $args['klarna']['product'], $args['klarna']['locale'] );
121
+
122
+ return $args;
123
+ }
124
+
125
+ /**
126
+ *
127
+ * {@inheritDoc}
128
+ *
129
+ * @see WC_Payment_Gateway_Stripe_Local_Payment::get_source_args()
130
+ */
131
+ public function get_source_args( $order, $update = false ) {
132
+ if ( $update ) {
133
+ /*
134
+ * Use customer if this is an update since customer object has been updated
135
+ * with all checkout form data in the update_order_review process.
136
+ */
137
+ $object = WC()->customer;
138
+ } else {
139
+ $object = $order;
140
+ }
141
+
142
+ $args = array_merge_recursive(
143
+ parent::get_source_args( $order ),
144
+ array(
145
+ 'klarna' => array(
146
+ 'product' => 'payment',
147
+ 'purchase_country' => $object->get_billing_country(),
148
+ 'first_name' => $object->get_billing_first_name(),
149
+ 'last_name' => $object->get_billing_last_name(),
150
+ ),
151
+ 'owner' => array(
152
+ 'address' => array(
153
+ 'city' => $object->get_billing_city(),
154
+ 'country' => $object->get_billing_country(),
155
+ 'line1' => $object->get_billing_address_1(),
156
+ 'line2' => $object->get_billing_address_2(),
157
+ 'postal_code' => $object->get_billing_postcode(),
158
+ 'state' => $object->get_billing_state(),
159
+ ),
160
+ ),
161
+ )
162
+ );
163
+ $args['source_order'] = array();
164
+
165
+ if ( ( $locale = get_locale() ) ) {
166
+ $args['klarna']['locale'] = str_replace( '_', '-', $locale );
167
+ }
168
+
169
+ if ( $order->get_shipping_address_1() ) {
170
+ $args['klarna']['shipping_first_name'] = $object->get_shipping_first_name();
171
+ $args['klarna']['shipping_last_name'] = $object->get_shipping_last_name();
172
+ $args['source_order']['shipping']['address'] = array(
173
+ 'city' => $object->get_billing_city(),
174
+ 'country' => $object->get_shipping_country(),
175
+ 'line1' => $object->get_shipping_address_1(),
176
+ 'line2' => $object->get_shipping_address_2(),
177
+ 'postal_code' => $object->get_shipping_postcode(),
178
+ 'state' => $object->get_shipping_state(),
179
+ );
180
+ }
181
+
182
+ foreach ( $order->get_items( 'line_item' ) as $item ) {
183
+ /**
184
+ *
185
+ * @var WC_Order_Item_Product $item
186
+ */
187
+ $args['source_order']['items'][] = array(
188
+ 'type' => 'sku',
189
+ 'amount' => wc_stripe_add_number_precision( $item->get_subtotal(), $order->get_currency() ),
190
+ 'currency' => $order->get_currency(),
191
+ 'quantity' => $item->get_quantity(),
192
+ 'description' => $item->get_name(),
193
+ );
194
+ }
195
+ // shipping
196
+ if ( $order->get_shipping_total() ) {
197
+ $args['source_order']['items'][] = array(
198
+ 'type' => 'shipping',
199
+ 'amount' => wc_stripe_add_number_precision( $order->get_shipping_total(), $order->get_currency() ),
200
+ 'currency' => $order->get_currency(),
201
+ 'quantity' => 1,
202
+ 'description' => __( 'Shipping', 'woo-stripe-payment' ),
203
+ );
204
+ }
205
+ // discount
206
+ if ( $order->get_discount_total() ) {
207
+ $args['source_order']['items'][] = array(
208
+ 'type' => 'discount',
209
+ 'amount' => - 1 * wc_stripe_add_number_precision( $order->get_discount_total(), $order->get_currency() ),
210
+ 'currency' => $order->get_currency(),
211
+ 'quantity' => 1,
212
+ 'description' => __( 'Discount', 'woo-stripe-payment' ),
213
+ );
214
+ }
215
+ // fees
216
+ if ( $order->get_fees() ) {
217
+ $fee_total = 0;
218
+ foreach ( $order->get_fees() as $fee ) {
219
+ $fee_total += wc_stripe_add_number_precision( $fee->get_total(), $order->get_currency() );
220
+ }
221
+ $args['source_order']['items'][] = array(
222
+ 'type' => 'sku',
223
+ 'amount' => $fee_total,
224
+ 'currency' => $order->get_currency(),
225
+ 'quantity' => 1,
226
+ 'description' => __( 'Fee', 'woo-stripe-payment' ),
227
+ );
228
+ }
229
+ // tax
230
+ if ( $order->get_total_tax() ) {
231
+ $args['source_order']['items'][] = array(
232
+ 'type' => 'tax',
233
+ 'amount' => wc_stripe_add_number_precision( $order->get_total_tax() ),
234
+ 'description' => __( 'Tax', 'woo-stripe-payment' ),
235
+ 'quantity' => 1,
236
+ 'currency' => $order->get_currency(),
237
+ );
238
+ }
239
+
240
+ return $args;
241
+ }
242
+
243
+ /**
244
+ *
245
+ * {@inheritDoc}
246
+ *
247
+ * @see WC_Payment_Gateway_Stripe_Local_Payment::get_source_redirect_url()
248
+ */
249
+ public function get_source_redirect_url( $source, $order ) {
250
+ $klarna_categories = explode( ',', $source['klarna']['payment_method_categories'] );
251
+ $klarna_categories = array_intersect( $klarna_categories, $this->get_option( 'payment_categories' ) );
252
+ $source['klarna']['payment_method_categories'] = implode( $klarna_categories, ',' );
253
+
254
+ return '#local_payment=klarna&redirect=' . $this->get_local_payment_return_url( $order ) . '&encoded_source=' .
255
+ base64_encode( wp_json_encode( $source ) );
256
+ }
257
+
258
+ protected function get_local_payment_return_url( $order ) {
259
+ return add_query_arg( 'source', $order->get_meta( '_stripe_source_id', true ), parent::get_local_payment_return_url( $order ) );
260
+ }
261
+
262
+ /**
263
+ *
264
+ * @return mixed
265
+ */
266
+ public function get_payment_categories() {
267
+ return apply_filters(
268
+ 'wc_stripe_klarna_payment_categries',
269
+ array(
270
+ 'pay_now' => __( 'Pay Now', 'woo-stripe-payment' ),
271
+ 'pay_later' => __( 'Pay Later', 'woo-stripe-payment' ),
272
+ 'pay_over_time' => __(
273
+ 'Pay Over Time',
274
+ 'woo-stripe-payment'
275
+ ),
276
+ )
277
+ );
278
+ }
279
+
280
+ /**
281
+ *
282
+ * {@inheritDoc}
283
+ *
284
+ * @see WC_Payment_Gateway_Stripe_Local_Payment::get_payment_description()
285
+ */
286
+ public function get_payment_description() {
287
+ return '<p>' .
288
+ sprintf( __( 'Click %1$shere%2$s for Klarna test payment methods.', 'woo-stripe-payment' ), '<a target="_blank" href="https://stripe.com/docs/sources/klarna#testing-klarna-payments">', '</a>' ) .
289
+ '</p>' . parent::get_payment_description();
290
+ }
291
+
292
+ public function get_localized_params() {
293
+ $params = parent::get_localized_params();
294
+ $params['messages']['klarna_error'] = __( 'Your purchase is not approved.', 'woo-stripe-payment' );
295
+
296
+ return $params;
297
+ }
298
+ }
includes/gateways/class-wc-payment-gateway-stripe-multibanco.php CHANGED
@@ -1,33 +1,32 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_Multibanco extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Charge_Trait;
16
-
17
- public function __construct() {
18
- $this->local_payment_type = 'multibanco';
19
- $this->currencies = [ 'EUR'
20
- ];
21
- $this->countries = [ 'PT'
22
- ];
23
- $this->id = 'stripe_multibanco';
24
- $this->tab_title = __ ( 'Multibanco', 'woo-stripe-payment' );
25
- $this->template_name = 'local-payment.php';
26
- $this->token_type = 'Stripe_Local';
27
- $this->method_title = __ ( 'Multibanco', 'woo-stripe-payment' );
28
- $this->method_description = __ ( 'Multibanco gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
29
- $this->icon = wc_stripe ()->assets_url ( 'img/multibanco.svg' );
30
- $this->order_button_text = $this->get_order_button_text ( __ ( 'Multibanco', 'woo-stripe-payment' ) );
31
- parent::__construct ();
32
- }
33
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_Multibanco extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->local_payment_type = 'multibanco';
20
+ $this->currencies = array( 'EUR' );
21
+ $this->countries = array( 'PT' );
22
+ $this->id = 'stripe_multibanco';
23
+ $this->tab_title = __( 'Multibanco', 'woo-stripe-payment' );
24
+ $this->template_name = 'local-payment.php';
25
+ $this->token_type = 'Stripe_Local';
26
+ $this->method_title = __( 'Multibanco', 'woo-stripe-payment' );
27
+ $this->method_description = __( 'Multibanco gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
28
+ $this->icon = wc_stripe()->assets_url( 'img/multibanco.svg' );
29
+ $this->order_button_text = $this->get_order_button_text( __( 'Multibanco', 'woo-stripe-payment' ) );
30
+ parent::__construct();
31
+ }
32
+ }
 
includes/gateways/class-wc-payment-gateway-stripe-p24.php CHANGED
@@ -1,33 +1,32 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_P24 extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Charge_Trait;
16
-
17
- public function __construct() {
18
- $this->local_payment_type = 'p24';
19
- $this->currencies = [ 'EUR', 'PLN'
20
- ];
21
- $this->countries = [ 'PL'
22
- ];
23
- $this->id = 'stripe_p24';
24
- $this->tab_title = __ ( 'Przelewy24', 'woo-stripe-payment' );
25
- $this->template_name = 'local-payment.php';
26
- $this->token_type = 'Stripe_Local';
27
- $this->method_title = __ ( 'Przelewy24', 'woo-stripe-payment' );
28
- $this->method_description = __ ( 'P24 gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
29
- $this->icon = wc_stripe ()->assets_url ( 'img/p24.svg' );
30
- $this->order_button_text = $this->get_order_button_text ( __ ( 'P24', 'woo-stripe-payment' ) );
31
- parent::__construct ();
32
- }
33
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_P24 extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->local_payment_type = 'p24';
20
+ $this->currencies = array( 'EUR', 'PLN' );
21
+ $this->countries = array( 'PL' );
22
+ $this->id = 'stripe_p24';
23
+ $this->tab_title = __( 'Przelewy24', 'woo-stripe-payment' );
24
+ $this->template_name = 'local-payment.php';
25
+ $this->token_type = 'Stripe_Local';
26
+ $this->method_title = __( 'Przelewy24', 'woo-stripe-payment' );
27
+ $this->method_description = __( 'P24 gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
28
+ $this->icon = wc_stripe()->assets_url( 'img/p24.svg' );
29
+ $this->order_button_text = $this->get_order_button_text( __( 'P24', 'woo-stripe-payment' ) );
30
+ parent::__construct();
31
+ }
32
+ }
 
includes/gateways/class-wc-payment-gateway-stripe-payment-request.php CHANGED
@@ -1,87 +1,98 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe' )) {
5
- return;
6
- }
7
- /**
8
- * This gateway is provided so merchants can accept Chrome Payments, Microsoft Pay, etc.
9
- *
10
- * @author PaymentPlugins
11
- * @package Stripe/Gateways
12
- *
13
- */
14
- class WC_Payment_Gateway_Stripe_Payment_Request extends WC_Payment_Gateway_Stripe {
15
-
16
- use WC_Stripe_Payment_Intent_Trait;
17
-
18
- protected $payment_method_type = 'card';
19
-
20
- public function __construct() {
21
- $this->id = 'stripe_payment_request';
22
- $this->tab_title = __ ( 'PaymentRequest Gateway', 'woo-stripe-payment' );
23
- $this->template_name = 'payment-request.php';
24
- $this->token_type = 'Stripe_CC';
25
- $this->method_title = __ ( 'Stripe Payment Request', 'woo-stripe-payment' );
26
- $this->method_description = __ ( 'Gateway that renders based on the user\'s browser. Chrome payment methods, Microsoft pay, etc.', 'woo-stripe-payment' );
27
- parent::__construct ();
28
- }
29
-
30
- public function init_supports() {
31
- parent::init_supports ();
32
- $this->supports[] = 'wc_stripe_cart_checkout';
33
- $this->supports[] = 'wc_stripe_product_checkout';
34
- $this->supports[] = 'wc_stripe_banner_checkout';
35
- }
36
-
37
- public function get_icon() {
38
- return wc_stripe_get_template ( 'payment-request-icons.php' );
39
- }
40
-
41
- public function enqueue_product_scripts($scripts) {
42
- $this->enqueue_checkout_scripts ( $scripts );
43
- }
44
-
45
- public function enqueue_cart_scripts($scripts) {
46
- $this->enqueue_checkout_scripts ( $scripts );
47
- }
48
-
49
- public function enqueue_checkout_scripts($scripts) {
50
- $scripts->enqueue_script ( 'payment-request', $scripts->assets_url ( 'js/frontend/payment-request.js' ), [
51
- $scripts->get_handle ( 'wc-stripe' ),
52
- $scripts->get_handle ( 'external' )
53
- ], wc_stripe ()->version (), true );
54
-
55
- $scripts->localize_script ( 'payment-request', $this->get_localized_params () );
56
- }
57
-
58
- public function get_localized_params() {
59
- return array_merge_recursive ( parent::get_localized_params (), [
60
- 'button' => [
61
- 'type' => $this->get_option ( 'button_type' ),
62
- 'theme' => $this->get_option ( 'button_theme' ),
63
- 'height' => $this->get_button_height ()
64
- ],
65
- 'icons' => [
66
- 'chrome' => wc_stripe ()->assets_url ( 'img/chrome.svg' )
67
- ],
68
- 'messages' => [
69
- 'invalid_amount' => __ ( 'Please update you product quantity before paying.', 'woo-stripe-payment' ),
70
- 'add_to_cart' => __ ( 'Adding to cart...', 'woo-stripe-payment' ),
71
- 'choose_product' => __ ( 'Please select a product option before updating quantity.', 'woo-stripe-payment' )
72
- ]
73
- ] );
74
- }
75
-
76
- private function get_button_height() {
77
- $value = $this->get_option ( 'button_height' );
78
- $value .= strpos ( $value, 'px' ) === false ? 'px' : '';
79
- return $value;
80
- }
81
-
82
- private function get_icon_for_payment_request() {
83
- $user_agent = isset ( $_SERVER[ 'HTTP_USER_AGENT' ] ) ? $_SERVER[ 'HTTP_USER_AGENT' ] : '';
84
- if (! empty ( $user_agent )) {
85
- }
86
- }
87
- }
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ * This gateway is provided so merchants can accept Chrome Payments, Microsoft Pay, etc.
10
+ *
11
+ * @author PaymentPlugins
12
+ * @package Stripe/Gateways
13
+ *
14
+ */
15
+ class WC_Payment_Gateway_Stripe_Payment_Request extends WC_Payment_Gateway_Stripe {
16
+
17
+ use WC_Stripe_Payment_Intent_Trait;
18
+
19
+ protected $payment_method_type = 'card';
20
+
21
+ public function __construct() {
22
+ $this->id = 'stripe_payment_request';
23
+ $this->tab_title = __( 'PaymentRequest Gateway', 'woo-stripe-payment' );
24
+ $this->template_name = 'payment-request.php';
25
+ $this->token_type = 'Stripe_CC';
26
+ $this->method_title = __( 'Stripe Payment Request', 'woo-stripe-payment' );
27
+ $this->method_description = __( 'Gateway that renders based on the user\'s browser. Chrome payment methods, Microsoft pay, etc.', 'woo-stripe-payment' );
28
+ parent::__construct();
29
+ }
30
+
31
+ public function init_supports() {
32
+ parent::init_supports();
33
+ $this->supports[] = 'wc_stripe_cart_checkout';
34
+ $this->supports[] = 'wc_stripe_product_checkout';
35
+ $this->supports[] = 'wc_stripe_banner_checkout';
36
+ }
37
+
38
+ public function get_icon() {
39
+ return wc_stripe_get_template( 'payment-request-icons.php' );
40
+ }
41
+
42
+ public function enqueue_product_scripts( $scripts ) {
43
+ $this->enqueue_checkout_scripts( $scripts );
44
+ }
45
+
46
+ public function enqueue_cart_scripts( $scripts ) {
47
+ $this->enqueue_checkout_scripts( $scripts );
48
+ }
49
+
50
+ public function enqueue_checkout_scripts( $scripts ) {
51
+ $scripts->enqueue_script(
52
+ 'payment-request',
53
+ $scripts->assets_url( 'js/frontend/payment-request.js' ),
54
+ array(
55
+ $scripts->get_handle( 'wc-stripe' ),
56
+ $scripts->get_handle( 'external' ),
57
+ ),
58
+ wc_stripe()->version(),
59
+ true
60
+ );
61
+
62
+ $scripts->localize_script( 'payment-request', $this->get_localized_params() );
63
+ }
64
+
65
+ public function get_localized_params() {
66
+ return array_merge_recursive(
67
+ parent::get_localized_params(),
68
+ array(
69
+ 'button' => array(
70
+ 'type' => $this->get_option( 'button_type' ),
71
+ 'theme' => $this->get_option( 'button_theme' ),
72
+ 'height' => $this->get_button_height(),
73
+ ),
74
+ 'icons' => array( 'chrome' => wc_stripe()->assets_url( 'img/chrome.svg' ) ),
75
+ 'messages' => array(
76
+ 'invalid_amount' => __( 'Please update you product quantity before paying.', 'woo-stripe-payment' ),
77
+ 'add_to_cart' => __( 'Adding to cart...', 'woo-stripe-payment' ),
78
+ 'choose_product' => __(
79
+ 'Please select a product option before updating quantity.',
80
+ 'woo-stripe-payment'
81
+ ),
82
+ ),
83
+ )
84
+ );
85
+ }
86
+
87
+ private function get_button_height() {
88
+ $value = $this->get_option( 'button_height' );
89
+ $value .= strpos( $value, 'px' ) === false ? 'px' : '';
90
+ return $value;
91
+ }
92
+
93
+ private function get_icon_for_payment_request() {
94
+ $user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
95
+ if ( ! empty( $user_agent ) ) {
96
+ }
97
+ }
98
+ }
includes/gateways/class-wc-payment-gateway-stripe-sepa.php CHANGED
@@ -1,60 +1,64 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_Sepa extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Charge_Trait;
16
-
17
- public function __construct() {
18
- $this->synchronous = false;
19
- $this->local_payment_type = 'sepa_debit';
20
- $this->currencies = [ 'EUR'
21
- ];
22
- $this->id = 'stripe_sepa';
23
- $this->tab_title = __ ( 'SEPA', 'woo-stripe-payment' );
24
- $this->template_name = 'local-payment.php';
25
- $this->token_type = 'Stripe_Local';
26
- $this->method_title = __ ( 'Sepa', 'woo-stripe-payment' );
27
- $this->method_description = __ ( 'Sepa gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
28
- $this->icon = wc_stripe ()->assets_url ( 'img/sepa.svg' );
29
- $this->order_button_text = $this->get_order_button_text ( __ ( 'SEPA', 'woo-stripe-payment' ) );
30
- parent::__construct ();
31
-
32
- $this->local_payment_description = sprintf ( __ ( 'By providing your IBAN and confirming this payment, you are
33
- authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account
34
- and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the
35
- terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woo-stripe-payment' ), $this->get_option ( 'company_name' ) );
36
- }
37
-
38
- public function get_element_params() {
39
- return array_merge ( parent::get_element_params (), [
40
- 'supportedCountries' => [ 'SEPA'
41
- ]
42
- ] );
43
- }
44
-
45
- public function get_local_payment_settings() {
46
- return parent::get_local_payment_settings () + [
47
- 'company_name' => array(
48
- 'title' => __ ( 'Company Name', 'woo-stripe-payment' ),
49
- 'type' => 'text',
50
- 'default' => get_bloginfo ( 'name' ),
51
- 'desc_tip' => true,
52
- 'description' => __ ( 'The name of your company that will appear in the SEPA mandate.', 'woo-stripe-payment' )
53
- )
54
- ];
55
- }
56
-
57
- public function get_payment_description() {
58
- return parent::get_payment_description () . sprintf ( '<p><a target="_blank" href="https://stripe.com/docs/sources/sepa-debit#testing">%s</a></p>', __ ( 'SEPA Test Accounts', 'woo-stripe-payment' ) );
59
- }
60
- }
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_Sepa extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->synchronous = false;
20
+ $this->local_payment_type = 'sepa_debit';
21
+ $this->currencies = array( 'EUR' );
22
+ $this->id = 'stripe_sepa';
23
+ $this->tab_title = __( 'SEPA', 'woo-stripe-payment' );
24
+ $this->template_name = 'local-payment.php';
25
+ $this->token_type = 'Stripe_Local';
26
+ $this->method_title = __( 'Sepa', 'woo-stripe-payment' );
27
+ $this->method_description = __( 'Sepa gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
28
+ $this->icon = wc_stripe()->assets_url( 'img/sepa.svg' );
29
+ $this->order_button_text = $this->get_order_button_text( __( 'SEPA', 'woo-stripe-payment' ) );
30
+ parent::__construct();
31
+
32
+ $this->local_payment_description = sprintf(
33
+ __(
34
+ 'By providing your IBAN and confirming this payment, you are
35
+ authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account
36
+ and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the
37
+ terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.',
38
+ 'woo-stripe-payment'
39
+ ),
40
+ $this->get_option( 'company_name' )
41
+ );
42
+ }
43
+
44
+ public function get_element_params() {
45
+ return array_merge( parent::get_element_params(), array( 'supportedCountries' => array( 'SEPA' ) ) );
46
+ }
47
+
48
+ public function get_local_payment_settings() {
49
+ return parent::get_local_payment_settings() + array(
50
+ 'company_name' => array(
51
+ 'title' => __( 'Company Name', 'woo-stripe-payment' ),
52
+ 'type' => 'text',
53
+ 'default' => get_bloginfo( 'name' ),
54
+ 'desc_tip' => true,
55
+ 'description' => __( 'The name of your company that will appear in the SEPA mandate.', 'woo-stripe-payment' ),
56
+ ),
57
+ );
58
+ }
59
+
60
+ public function get_payment_description() {
61
+ return parent::get_payment_description() .
62
+ sprintf( '<p><a target="_blank" href="https://stripe.com/docs/sources/sepa-debit#testing">%s</a></p>', __( 'SEPA Test Accounts', 'woo-stripe-payment' ) );
63
+ }
64
+ }
includes/gateways/class-wc-payment-gateway-stripe-sofort.php CHANGED
@@ -1,43 +1,37 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_Sofort extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Charge_Trait;
16
-
17
- public function __construct() {
18
- $this->synchronous = false;
19
- $this->local_payment_type = 'sofort';
20
- $this->currencies = [ 'EUR'
21
- ];
22
- $this->countries = [ 'AT', 'BE', 'DE', 'ES',
23
- 'IT', 'NL'
24
- ];
25
- $this->id = 'stripe_sofort';
26
- $this->tab_title = __ ( 'Sofort', 'woo-stripe-payment' );
27
- $this->template_name = 'local-payment.php';
28
- $this->token_type = 'Stripe_Local';
29
- $this->method_title = __ ( 'Sofort', 'woo-stripe-payment' );
30
- $this->method_description = __ ( 'Sofort gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
31
- $this->icon = wc_stripe ()->assets_url ( 'img/sofort.svg' );
32
- $this->order_button_text = $this->get_order_button_text ( __ ( 'SOFORT', 'woo-stripe-payment' ) );
33
- parent::__construct ();
34
- }
35
-
36
- public function get_source_args($order) {
37
- return array_merge ( parent::get_source_args ( $order ), [
38
- 'sofort' => [
39
- 'country' => $order->get_billing_country ()
40
- ]
41
- ] );
42
- }
43
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_Sofort extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->synchronous = false;
20
+ $this->local_payment_type = 'sofort';
21
+ $this->currencies = array( 'EUR' );
22
+ $this->countries = array( 'AT', 'BE', 'DE', 'ES', 'IT', 'NL' );
23
+ $this->id = 'stripe_sofort';
24
+ $this->tab_title = __( 'Sofort', 'woo-stripe-payment' );
25
+ $this->template_name = 'local-payment.php';
26
+ $this->token_type = 'Stripe_Local';
27
+ $this->method_title = __( 'Sofort', 'woo-stripe-payment' );
28
+ $this->method_description = __( 'Sofort gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
29
+ $this->icon = wc_stripe()->assets_url( 'img/sofort.svg' );
30
+ $this->order_button_text = $this->get_order_button_text( __( 'SOFORT', 'woo-stripe-payment' ) );
31
+ parent::__construct();
32
+ }
33
+
34
+ public function get_source_args( $order ) {
35
+ return array_merge( parent::get_source_args( $order ), array( 'sofort' => array( 'country' => $order->get_billing_country() ) ) );
36
+ }
37
+ }
 
 
 
 
 
 
includes/gateways/class-wc-payment-gateway-stripe-wechat.php CHANGED
@@ -1,67 +1,73 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Gateway_Stripe_Local_Payment' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @package Stripe/Gateways
10
- * @author PaymentPlugins
11
- *
12
- */
13
- class WC_Payment_Gateway_Stripe_WeChat extends WC_Payment_Gateway_Stripe_Local_Payment {
14
-
15
- use WC_Stripe_Local_Payment_Charge_Trait;
16
-
17
- public function __construct() {
18
- $this->local_payment_type = 'wechat';
19
- $this->currencies = [ 'AUD', 'CAD', 'EUR',
20
- 'GBP', 'HKD', 'JPY', 'SGD', 'USD'
21
- ];
22
- // $this->countries = [ 'CN'
23
- // ];
24
- $this->id = 'stripe_wechat';
25
- $this->tab_title = __ ( 'WeChat', 'woo-stripe-payment' );
26
- $this->template_name = 'local-payment.php';
27
- $this->token_type = 'Stripe_Local';
28
- $this->method_title = __ ( 'WeChat', 'woo-stripe-payment' );
29
- $this->method_description = __ ( 'WeChat gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
30
- $this->icon = wc_stripe ()->assets_url ( 'img/wechat.svg' );
31
- $this->order_button_text = $this->get_order_button_text ( __ ( 'WeChat', 'woo-stripe-payment' ) );
32
- parent::__construct ();
33
- }
34
-
35
- /**
36
- *
37
- * {@inheritDoc}
38
- *
39
- * @see WC_Payment_Gateway_Stripe_Local_Payment::get_source_redirect_url()
40
- */
41
- public function get_source_redirect_url($source, $order) {
42
- if (wc_stripe_mode () == 'live') {
43
- return sprintf ( '#qrcode=%s', base64_encode ( wp_json_encode ( [
44
- 'code' => $source->wechat->qr_code_url,
45
- 'redirect' => $order->get_checkout_order_received_url ()
46
- ] ) ) );
47
- }
48
- // test code
49
- // 'code' => 'weixin:\/\/wxpay\/bizpayurl?pr=tMih4Jo'
50
-
51
- // in test mode just return the redirect url
52
- return $source->wechat->qr_code_url;
53
- }
54
-
55
- /**
56
- *
57
- * {@inheritDoc}
58
- *
59
- * @see WC_Payment_Gateway_Stripe_Local_Payment::get_localized_params()
60
- */
61
- public function get_localized_params() {
62
- $data = parent::get_localized_params ();
63
- $data[ 'qr_script' ] = sprintf ( wc_stripe ()->scripts ()->assets_url ( 'js/frontend/qrcode.js?ver=%s' ), wc_stripe ()->version );
64
- $data[ 'qr_message' ] = __ ( 'Scan the QR code using your WeChat app. Once scanned click the Place Order button.', 'woo-stripe-payment' );
65
- return $data;
66
- }
67
- }
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @package Stripe/Gateways
11
+ * @author PaymentPlugins
12
+ *
13
+ */
14
+ class WC_Payment_Gateway_Stripe_WeChat extends WC_Payment_Gateway_Stripe_Local_Payment {
15
+
16
+ use WC_Stripe_Local_Payment_Charge_Trait;
17
+
18
+ public function __construct() {
19
+ $this->local_payment_type = 'wechat';
20
+ $this->currencies = array( 'AUD', 'CAD', 'EUR', 'GBP', 'HKD', 'JPY', 'SGD', 'USD' );
21
+ // $this->countries = [ 'CN'
22
+ // ];
23
+ $this->id = 'stripe_wechat';
24
+ $this->tab_title = __( 'WeChat', 'woo-stripe-payment' );
25
+ $this->template_name = 'local-payment.php';
26
+ $this->token_type = 'Stripe_Local';
27
+ $this->method_title = __( 'WeChat', 'woo-stripe-payment' );
28
+ $this->method_description = __( 'WeChat gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
29
+ $this->icon = wc_stripe()->assets_url( 'img/wechat.svg' );
30
+ $this->order_button_text = $this->get_order_button_text( __( 'WeChat', 'woo-stripe-payment' ) );
31
+ parent::__construct();
32
+ }
33
+
34
+ /**
35
+ *
36
+ * {@inheritDoc}
37
+ *
38
+ * @see WC_Payment_Gateway_Stripe_Local_Payment::get_source_redirect_url()
39
+ */
40
+ public function get_source_redirect_url( $source, $order ) {
41
+ if ( wc_stripe_mode() == 'live' ) {
42
+ return sprintf(
43
+ '#qrcode=%s',
44
+ base64_encode(
45
+ wp_json_encode(
46
+ array(
47
+ 'code' => $source->wechat->qr_code_url,
48
+ 'redirect' => $order->get_checkout_order_received_url(),
49
+ )
50
+ )
51
+ )
52
+ );
53
+ }
54
+ // test code
55
+ // 'code' => 'weixin:\/\/wxpay\/bizpayurl?pr=tMih4Jo'
56
+
57
+ // in test mode just return the redirect url
58
+ return $source->wechat->qr_code_url;
59
+ }
60
+
61
+ /**
62
+ *
63
+ * {@inheritDoc}
64
+ *
65
+ * @see WC_Payment_Gateway_Stripe_Local_Payment::get_localized_params()
66
+ */
67
+ public function get_localized_params() {
68
+ $data = parent::get_localized_params();
69
+ $data['qr_script'] = sprintf( wc_stripe()->scripts()->assets_url( 'js/frontend/qrcode.js?ver=%s' ), wc_stripe()->version );
70
+ $data['qr_message'] = __( 'Scan the QR code using your WeChat app. Once scanned click the Place Order button.', 'woo-stripe-payment' );
71
+ return $data;
72
+ }
73
+ }
includes/gateways/settings/ach-settings-v2.php CHANGED
@@ -1,101 +1,115 @@
1
- <?php
2
- return array(
3
- 'desc' => array( 'type' => 'description',
4
- 'description' => sprintf ( '<div>%s</div>', __ ( 'For US customers only.', 'woo-stripe-payment' ) ) . sprintf ( '<p>%s</p>', sprintf ( __ ( 'Read through our %sdocumentation%s to configure ACH payments', 'woo-stripe-payment' ), '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config/#/stripe_ach">', '</a>' ) )
5
- ),
6
- 'enabled' => array(
7
- 'title' => __ ( 'Enabled', 'woo-stripe-payment' ),
8
- 'type' => 'checkbox', 'default' => 'no',
9
- 'value' => 'yes', 'desc_tip' => true,
10
- 'description' => __ ( 'If enabled, your site can accept ACH payments through Stripe.', 'woo-stripe-payment' )
11
- ),
12
- 'environment' => array( 'type' => 'select',
13
- 'title' => __ ( 'Plaid Environment', 'woo-stripe-payment' ),
14
- 'options' => array(
15
- 'sandbox' => __ ( 'Sandbox', 'woo-stripe-payment' ),
16
- 'development' => __ ( 'Development', 'woo-stripe-payment' ),
17
- 'production' => __ ( 'Production', 'woo-stripe-payment' )
18
- ),
19
- 'description' => __ ( 'This setting determines the Plaid environment you are connecting with. When you are ready to accept live transactions, switch this option to Production.<br><strong>Production</strong> - accept live ACH payments <br><strong>Development</strong> - use real bank login details with test transactions <br><strong>Sandbox</strong> - test integration using test credentials', 'woo-stripe-payment' )
20
- ),
21
- /* 'plaid_keys' => array( 'type' => 'title',
22
- 'title' => __ ( 'Plaid Keys', 'wo-stripe-paymento' )
23
- ),
24
- 'client_id' => array( 'type' => 'text',
25
- 'title' => __ ( 'Client ID' ),
26
- 'default' => '',
27
- 'description' => __ ( 'ID that identifies your Plaid account.', 'woo-stripe-payment' ),
28
- 'desc_tip' => true
29
- ),
30
- 'public_key' => array( 'type' => 'text',
31
- 'title' => __ ( 'Public Key' ),
32
- 'default' => '',
33
- 'description' => __ ( 'Used to identify ACH payments initiated from your site.', 'woo-stripe-payment' ),
34
- 'desc_tip' => true
35
- ),
36
- 'plaid_secrets' => array( 'type' => 'title',
37
- 'title' => __ ( 'Plaid Secrets', 'wo-stripe-paymento' )
38
- ),
39
- 'sandbox_secret' => array(
40
- 'title' => __ ( 'Sandbox Secret', 'woo-stripe-payment' ),
41
- 'type' => 'password', 'default' => '',
42
- 'description' => __ ( 'Key that acts as a password when connecting to Plaid\'s sandbox environment.', 'woo-stripe-payment' ),
43
- 'desc_tip' => true
44
- ),
45
- 'development_secret' => array(
46
- 'title' => __ ( 'Development Secret', 'woo-stripe-payment' ),
47
- 'type' => 'password', 'default' => '',
48
- 'description' => __ ( '', 'woo-stripe-payment' ),
49
- 'desc_tip' => true
50
- ),
51
- 'production_secret' => array(
52
- 'title' => __ ( 'Production Secret', 'woo-stripe-payment' ),
53
- 'type' => 'password', 'default' => '',
54
- 'description' => __ ( 'Key that acts as a password when connecting to Plaid\'s production environment.', 'woo-stripe-payment' ),
55
- 'desc_tip' => true
56
- ), */
57
- 'general_settings' => array( 'type' => 'title',
58
- 'title' => __ ( 'General Settings', 'woo-stripe-payment' )
59
- ),
60
- 'title_text' => array( 'type' => 'text',
61
- 'title' => __ ( 'Title', 'woo-stripe-payment' ),
62
- 'default' => __ ( 'ACH Payment', 'woo-stripe-payment' ),
63
- 'desc_tip' => true,
64
- 'description' => __ ( 'Title of the ACH gateway' )
65
- ),
66
- 'description' => array(
67
- 'title' => __ ( 'Description', 'woo-stripe-payment' ),
68
- 'type' => 'text', 'default' => '',
69
- 'description' => __ ( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
70
- 'desc_tip' => true
71
- ),
72
- 'client_name' => array( 'type' => 'text',
73
- 'title' => __ ( 'Client Name', 'woo-stripe-payment' ),
74
- 'default' => get_bloginfo ( 'name' ),
75
- 'description' => __ ( 'The name that appears on the ACH payment screen.', 'woo-stripe-payment' ),
76
- 'desc_tip' => true
77
- ),
78
- 'method_format' => array(
79
- 'title' => __ ( 'ACH Display', 'woo-stripe-payment' ),
80
- 'type' => 'select',
81
- 'class' => 'wc-enhanced-select',
82
- 'options' => wp_list_pluck ( $this->get_method_formats (), 'example' ),
83
- 'value' => '', 'default' => 'type_ending_in',
84
- 'desc_tip' => true,
85
- 'description' => __ ( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' )
86
- ),
87
- 'fee' => array(
88
- 'title' => __ ( 'ACH Fee', 'woo-stripe-payment' ),
89
- 'type' => 'ach_fee', 'class' => '',
90
- 'value' => '',
91
- 'default' => [ 'type' => 'none',
92
- 'taxable' => 'no', 'value' => '0'
93
- ],
94
- 'options' => [
95
- 'none' => __ ( 'None', 'woo-stripe-payment' ),
96
- 'amount' => __ ( 'Amount', 'woo-stripe-payment' ),
97
- 'percent' => __ ( 'Percentage', 'woo-stripe-payment' )
98
- ], 'desc_tip' => true,
99
- 'description' => __ ( 'You can assign a fee to the order for ACH payments. Amount is a static amount and percentage is a percentage of the cart amount.', 'woo-stripe-payment' )
100
- )
101
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ return array(
3
+ 'desc' => array(
4
+ 'type' => 'description',
5
+ 'description' => sprintf( '<div>%s</div>', __( 'For US customers only.', 'woo-stripe-payment' ) ) .
6
+ sprintf( '<p>%s</p>', sprintf( __( 'Read through our %1$sdocumentation%2$s to configure ACH payments', 'woo-stripe-payment' ), '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config/#/stripe_ach">', '</a>' ) ),
7
+ ),
8
+ 'enabled' => array(
9
+ 'title' => __( 'Enabled', 'woo-stripe-payment' ),
10
+ 'type' => 'checkbox',
11
+ 'default' => 'no',
12
+ 'value' => 'yes',
13
+ 'desc_tip' => true,
14
+ 'description' => __( 'If enabled, your site can accept ACH payments through Stripe.', 'woo-stripe-payment' ),
15
+ ),
16
+ 'environment' => array(
17
+ 'type' => 'select',
18
+ 'title' => __( 'Plaid Environment', 'woo-stripe-payment' ),
19
+ 'options' => array(
20
+ 'sandbox' => __( 'Sandbox', 'woo-stripe-payment' ),
21
+ 'development' => __( 'Development', 'woo-stripe-payment' ),
22
+ 'production' => __( 'Production', 'woo-stripe-payment' ),
23
+ ),
24
+ 'description' => __( 'This setting determines the Plaid environment you are connecting with. When you are ready to accept live transactions, switch this option to Production.<br><strong>Production</strong> - accept live ACH payments <br><strong>Development</strong> - use real bank login details with test transactions <br><strong>Sandbox</strong> - test integration using test credentials', 'woo-stripe-payment' ),
25
+ ),
26
+ /* 'plaid_keys' => array( 'type' => 'title',
27
+ 'title' => __ ( 'Plaid Keys', 'wo-stripe-paymento' )
28
+ ),
29
+ 'client_id' => array( 'type' => 'text',
30
+ 'title' => __ ( 'Client ID' ),
31
+ 'default' => '',
32
+ 'description' => __ ( 'ID that identifies your Plaid account.', 'woo-stripe-payment' ),
33
+ 'desc_tip' => true
34
+ ),
35
+ 'public_key' => array( 'type' => 'text',
36
+ 'title' => __ ( 'Public Key' ),
37
+ 'default' => '',
38
+ 'description' => __ ( 'Used to identify ACH payments initiated from your site.', 'woo-stripe-payment' ),
39
+ 'desc_tip' => true
40
+ ),
41
+ 'plaid_secrets' => array( 'type' => 'title',
42
+ 'title' => __ ( 'Plaid Secrets', 'wo-stripe-paymento' )
43
+ ),
44
+ 'sandbox_secret' => array(
45
+ 'title' => __ ( 'Sandbox Secret', 'woo-stripe-payment' ),
46
+ 'type' => 'password', 'default' => '',
47
+ 'description' => __ ( 'Key that acts as a password when connecting to Plaid\'s sandbox environment.', 'woo-stripe-payment' ),
48
+ 'desc_tip' => true
49
+ ),
50
+ 'development_secret' => array(
51
+ 'title' => __ ( 'Development Secret', 'woo-stripe-payment' ),
52
+ 'type' => 'password', 'default' => '',
53
+ 'description' => __ ( '', 'woo-stripe-payment' ),
54
+ 'desc_tip' => true
55
+ ),
56
+ 'production_secret' => array(
57
+ 'title' => __ ( 'Production Secret', 'woo-stripe-payment' ),
58
+ 'type' => 'password', 'default' => '',
59
+ 'description' => __ ( 'Key that acts as a password when connecting to Plaid\'s production environment.', 'woo-stripe-payment' ),
60
+ 'desc_tip' => true
61
+ ), */
62
+ 'general_settings' => array(
63
+ 'type' => 'title',
64
+ 'title' => __( 'General Settings', 'woo-stripe-payment' ),
65
+ ),
66
+ 'title_text' => array(
67
+ 'type' => 'text',
68
+ 'title' => __( 'Title', 'woo-stripe-payment' ),
69
+ 'default' => __( 'ACH Payment', 'woo-stripe-payment' ),
70
+ 'desc_tip' => true,
71
+ 'description' => __( 'Title of the ACH gateway' ),
72
+ ),
73
+ 'description' => array(
74
+ 'title' => __( 'Description', 'woo-stripe-payment' ),
75
+ 'type' => 'text',
76
+ 'default' => '',
77
+ 'description' => __( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
78
+ 'desc_tip' => true,
79
+ ),
80
+ 'client_name' => array(
81
+ 'type' => 'text',
82
+ 'title' => __( 'Client Name', 'woo-stripe-payment' ),
83
+ 'default' => get_bloginfo( 'name' ),
84
+ 'description' => __( 'The name that appears on the ACH payment screen.', 'woo-stripe-payment' ),
85
+ 'desc_tip' => true,
86
+ ),
87
+ 'method_format' => array(
88
+ 'title' => __( 'ACH Display', 'woo-stripe-payment' ),
89
+ 'type' => 'select',
90
+ 'class' => 'wc-enhanced-select',
91
+ 'options' => wp_list_pluck( $this->get_method_formats(), 'example' ),
92
+ 'value' => '',
93
+ 'default' => 'type_ending_in',
94
+ 'desc_tip' => true,
95
+ 'description' => __( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' ),
96
+ ),
97
+ 'fee' => array(
98
+ 'title' => __( 'ACH Fee', 'woo-stripe-payment' ),
99
+ 'type' => 'ach_fee',
100
+ 'class' => '',
101
+ 'value' => '',
102
+ 'default' => array(
103
+ 'type' => 'none',
104
+ 'taxable' => 'no',
105
+ 'value' => '0',
106
+ ),
107
+ 'options' => array(
108
+ 'none' => __( 'None', 'woo-stripe-payment' ),
109
+ 'amount' => __( 'Amount', 'woo-stripe-payment' ),
110
+ 'percent' => __( 'Percentage', 'woo-stripe-payment' ),
111
+ ),
112
+ 'desc_tip' => true,
113
+ 'description' => __( 'You can assign a fee to the order for ACH payments. Amount is a static amount and percentage is a percentage of the cart amount.', 'woo-stripe-payment' ),
114
+ ),
115
+ );
includes/gateways/settings/ach-settings.php CHANGED
@@ -1,102 +1,124 @@
1
- <?php
2
- return array(
3
- 'desc' => array( 'type' => 'description',
4
- 'description' => sprintf ( '<div>%s</div>', __ ( 'For US customers only.', 'woo-stripe-payment' ) ) . sprintf ( '<p>%s</p>', sprintf ( __ ( 'Read through our %sdocumentation%s to configure ACH payments', 'woo-stripe-payment' ), '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config/#/stripe_ach">', '</a>' ) )
5
- ),
6
- 'enabled' => array(
7
- 'title' => __ ( 'Enabled', 'woo-stripe-payment' ),
8
- 'type' => 'checkbox', 'default' => 'no',
9
- 'value' => 'yes', 'desc_tip' => true,
10
- 'description' => __ ( 'If enabled, your site can accept ACH payments through Stripe.', 'woo-stripe-payment' )
11
- ),
12
- 'environment' => array( 'type' => 'select',
13
- 'title' => __ ( 'Plaid Environment', 'woo-stripe-payment' ),
14
- 'default' => 'production',
15
- 'options' => array(
16
- 'sandbox' => __ ( 'Sandbox', 'woo-stripe-payment' ),
17
- 'development' => __ ( 'Development', 'woo-stripe-payment' ),
18
- 'production' => __ ( 'Production', 'woo-stripe-payment' )
19
- ), 'desc_tip' => true,
20
- 'description' => __ ( 'The active Plaid environment. You must set API mode to live to use Plaid\'s development environment.', 'woo-stripe-payment' )
21
- ),
22
- 'plaid_keys' => array( 'type' => 'title',
23
- 'title' => __ ( 'Plaid Keys', 'wo-stripe-paymento' )
24
- ),
25
- 'client_id' => array( 'type' => 'text',
26
- 'title' => __ ( 'Client ID' ),
27
- 'default' => '',
28
- 'description' => __ ( 'ID that identifies your Plaid account.', 'woo-stripe-payment' ),
29
- 'desc_tip' => true
30
- ),
31
- 'public_key' => array( 'type' => 'text',
32
- 'title' => __ ( 'Public Key' ),
33
- 'default' => '',
34
- 'description' => __ ( 'Used to identify ACH payments initiated from your site.', 'woo-stripe-payment' ),
35
- 'desc_tip' => true
36
- ),
37
- 'plaid_secrets' => array( 'type' => 'title',
38
- 'title' => __ ( 'Plaid Secrets', 'wo-stripe-paymento' )
39
- ),
40
- 'sandbox_secret' => array(
41
- 'title' => __ ( 'Sandbox Secret', 'woo-stripe-payment' ),
42
- 'type' => 'password', 'default' => '',
43
- 'description' => __ ( 'Key that acts as a password when connecting to Plaid\'s sandbox environment.', 'woo-stripe-payment' ),
44
- 'desc_tip' => true
45
- ),
46
- 'development_secret' => array(
47
- 'title' => __ ( 'Development Secret', 'woo-stripe-payment' ),
48
- 'type' => 'password', 'default' => '',
49
- 'description' => __ ( 'Development allows you to test real bank credentials with test transactions.', 'woo-stripe-payment' ),
50
- 'desc_tip' => true
51
- ),
52
- 'production_secret' => array(
53
- 'title' => __ ( 'Production Secret', 'woo-stripe-payment' ),
54
- 'type' => 'password', 'default' => '',
55
- 'description' => __ ( 'Key that acts as a password when connecting to Plaid\'s production environment.', 'woo-stripe-payment' ),
56
- 'desc_tip' => true
57
- ),
58
- 'general_settings' => array( 'type' => 'title',
59
- 'title' => __ ( 'General Settings', 'woo-stripe-payment' )
60
- ),
61
- 'title_text' => array( 'type' => 'text',
62
- 'title' => __ ( 'Title', 'woo-stripe-payment' ),
63
- 'default' => __ ( 'ACH Payment', 'woo-stripe-payment' ),
64
- 'desc_tip' => true,
65
- 'description' => __ ( 'Title of the ACH gateway' )
66
- ),
67
- 'description' => array(
68
- 'title' => __ ( 'Description', 'woo-stripe-payment' ),
69
- 'type' => 'text', 'default' => '',
70
- 'description' => __ ( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
71
- 'desc_tip' => true
72
- ),
73
- 'client_name' => array( 'type' => 'text',
74
- 'title' => __ ( 'Client Name', 'woo-stripe-payment' ),
75
- 'default' => get_bloginfo ( 'name' ),
76
- 'description' => __ ( 'The name that appears on the ACH payment screen.', 'woo-stripe-payment' ),
77
- 'desc_tip' => true
78
- ),
79
- 'method_format' => array(
80
- 'title' => __ ( 'ACH Display', 'woo-stripe-payment' ),
81
- 'type' => 'select',
82
- 'class' => 'wc-enhanced-select',
83
- 'options' => wp_list_pluck ( $this->get_method_formats (), 'example' ),
84
- 'value' => '', 'default' => 'type_ending_in',
85
- 'desc_tip' => true,
86
- 'description' => __ ( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' )
87
- ),
88
- 'fee' => array(
89
- 'title' => __ ( 'ACH Fee', 'woo-stripe-payment' ),
90
- 'type' => 'ach_fee', 'class' => '',
91
- 'value' => '',
92
- 'default' => [ 'type' => 'none',
93
- 'taxable' => 'no', 'value' => '0'
94
- ],
95
- 'options' => [
96
- 'none' => __ ( 'None', 'woo-stripe-payment' ),
97
- 'amount' => __ ( 'Amount', 'woo-stripe-payment' ),
98
- 'percent' => __ ( 'Percentage', 'woo-stripe-payment' )
99
- ], 'desc_tip' => true,
100
- 'description' => __ ( 'You can assign a fee to the order for ACH payments. Amount is a static amount and percentage is a percentage of the cart amount.', 'woo-stripe-payment' )
101
- )
102
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ return array(
3
+ 'desc' => array(
4
+ 'type' => 'description',
5
+ 'description' => sprintf( '<div>%s</div>', __( 'For US customers only.', 'woo-stripe-payment' ) ) .
6
+ sprintf( '<p>%s</p>', sprintf( __( 'Read through our %1$sdocumentation%2$s to configure ACH payments', 'woo-stripe-payment' ), '<a target="_blank" href="https://docs.paymentplugins.com/wc-stripe/config/#/stripe_ach">', '</a>' ) ),
7
+ ),
8
+ 'enabled' => array(
9
+ 'title' => __( 'Enabled', 'woo-stripe-payment' ),
10
+ 'type' => 'checkbox',
11
+ 'default' => 'no',
12
+ 'value' => 'yes',
13
+ 'desc_tip' => true,
14
+ 'description' => __( 'If enabled, your site can accept ACH payments through Stripe.', 'woo-stripe-payment' ),
15
+ ),
16
+ 'environment' => array(
17
+ 'type' => 'select',
18
+ 'title' => __( 'Plaid Environment', 'woo-stripe-payment' ),
19
+ 'default' => 'production',
20
+ 'options' => array(
21
+ 'sandbox' => __( 'Sandbox', 'woo-stripe-payment' ),
22
+ 'development' => __( 'Development', 'woo-stripe-payment' ),
23
+ 'production' => __( 'Production', 'woo-stripe-payment' ),
24
+ ),
25
+ 'desc_tip' => true,
26
+ 'description' => __( 'The active Plaid environment. You must set API mode to live to use Plaid\'s development environment.', 'woo-stripe-payment' ),
27
+ ),
28
+ 'plaid_keys' => array(
29
+ 'type' => 'title',
30
+ 'title' => __( 'Plaid Keys', 'wo-stripe-paymento' ),
31
+ ),
32
+ 'client_id' => array(
33
+ 'type' => 'text',
34
+ 'title' => __( 'Client ID' ),
35
+ 'default' => '',
36
+ 'description' => __( 'ID that identifies your Plaid account.', 'woo-stripe-payment' ),
37
+ 'desc_tip' => true,
38
+ ),
39
+ 'public_key' => array(
40
+ 'type' => 'text',
41
+ 'title' => __( 'Public Key' ),
42
+ 'default' => '',
43
+ 'description' => __( 'Used to identify ACH payments initiated from your site.', 'woo-stripe-payment' ),
44
+ 'desc_tip' => true,
45
+ ),
46
+ 'plaid_secrets' => array(
47
+ 'type' => 'title',
48
+ 'title' => __( 'Plaid Secrets', 'wo-stripe-paymento' ),
49
+ ),
50
+ 'sandbox_secret' => array(
51
+ 'title' => __( 'Sandbox Secret', 'woo-stripe-payment' ),
52
+ 'type' => 'password',
53
+ 'default' => '',
54
+ 'description' => __( 'Key that acts as a password when connecting to Plaid\'s sandbox environment.', 'woo-stripe-payment' ),
55
+ 'desc_tip' => true,
56
+ ),
57
+ 'development_secret' => array(
58
+ 'title' => __( 'Development Secret', 'woo-stripe-payment' ),
59
+ 'type' => 'password',
60
+ 'default' => '',
61
+ 'description' => __( 'Development allows you to test real bank credentials with test transactions.', 'woo-stripe-payment' ),
62
+ 'desc_tip' => true,
63
+ ),
64
+ 'production_secret' => array(
65
+ 'title' => __( 'Production Secret', 'woo-stripe-payment' ),
66
+ 'type' => 'password',
67
+ 'default' => '',
68
+ 'description' => __( 'Key that acts as a password when connecting to Plaid\'s production environment.', 'woo-stripe-payment' ),
69
+ 'desc_tip' => true,
70
+ ),
71
+ 'general_settings' => array(
72
+ 'type' => 'title',
73
+ 'title' => __( 'General Settings', 'woo-stripe-payment' ),
74
+ ),
75
+ 'title_text' => array(
76
+ 'type' => 'text',
77
+ 'title' => __( 'Title', 'woo-stripe-payment' ),
78
+ 'default' => __( 'ACH Payment', 'woo-stripe-payment' ),
79
+ 'desc_tip' => true,
80
+ 'description' => __( 'Title of the ACH gateway' ),
81
+ ),
82
+ 'description' => array(
83
+ 'title' => __( 'Description', 'woo-stripe-payment' ),
84
+ 'type' => 'text',
85
+ 'default' => '',
86
+ 'description' => __( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
87
+ 'desc_tip' => true,
88
+ ),
89
+ 'client_name' => array(
90
+ 'type' => 'text',
91
+ 'title' => __( 'Client Name', 'woo-stripe-payment' ),
92
+ 'default' => get_bloginfo( 'name' ),
93
+ 'description' => __( 'The name that appears on the ACH payment screen.', 'woo-stripe-payment' ),
94
+ 'desc_tip' => true,
95
+ ),
96
+ 'method_format' => array(
97
+ 'title' => __( 'ACH Display', 'woo-stripe-payment' ),
98
+ 'type' => 'select',
99
+ 'class' => 'wc-enhanced-select',
100
+ 'options' => wp_list_pluck( $this->get_method_formats(), 'example' ),
101
+ 'value' => '',
102
+ 'default' => 'type_ending_in',
103
+ 'desc_tip' => true,
104
+ 'description' => __( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' ),
105
+ ),
106
+ 'fee' => array(
107
+ 'title' => __( 'ACH Fee', 'woo-stripe-payment' ),
108
+ 'type' => 'ach_fee',
109
+ 'class' => '',
110
+ 'value' => '',
111
+ 'default' => array(
112
+ 'type' => 'none',
113
+ 'taxable' => 'no',
114
+ 'value' => '0',
115
+ ),
116
+ 'options' => array(
117
+ 'none' => __( 'None', 'woo-stripe-payment' ),
118
+ 'amount' => __( 'Amount', 'woo-stripe-payment' ),
119
+ 'percent' => __( 'Percentage', 'woo-stripe-payment' ),
120
+ ),
121
+ 'desc_tip' => true,
122
+ 'description' => __( 'You can assign a fee to the order for ACH payments. Amount is a static amount and percentage is a percentage of the cart amount.', 'woo-stripe-payment' ),
123
+ ),
124
+ );
includes/gateways/settings/applepay-settings.php CHANGED
@@ -1,112 +1,125 @@
1
- <?php
2
- return array(
3
- 'desc' => array( 'type' => 'description',
4
- 'description' => sprintf ( '<div class="wc-stripe-register-domain"><button class="button button-secondary api-register-domain">%s</button></div><p>%s</p>', __ ( 'Register Domain', 'woo-stripe-payment' ), sprintf ( __ ( 'This plugin attemps to add the domain association file to your server automatically when you click the Register Domain button. If that fails due to file permssions, you must add the <strong>%s.well-known/apple-developer-merchantid-domain-association%s</strong> file to your domain and register your domain within the Stripe Dashboard.', 'woo-stripe-payment' ), '<a href="https://stripe.com/files/apple-pay/apple-developer-merchantid-domain-association">', '</a>' ) ) . '<p>' . __ ( 'In order for Apple Pay to display, you must test with an iOS device and have a payment method saved in the Apple Wallet.', 'woo-stripe-payment' ) . '</p>'
5
- ),
6
- 'enabled' => array(
7
- 'title' => __ ( 'Enabled', 'woo-stripe-payment' ),
8
- 'type' => 'checkbox', 'default' => 'no',
9
- 'value' => 'yes', 'desc_tip' => true,
10
- 'description' => __ ( 'If enabled, your site can accept Apple Pay payments through Stripe.', 'woo-stripe-payment' )
11
- ),
12
- 'general_settings' => array( 'type' => 'title',
13
- 'title' => __ ( 'General Settings', 'woo-stripe-payment' )
14
- ),
15
- 'title_text' => array( 'type' => 'text',
16
- 'title' => __ ( 'Title', 'woo-stripe-payment' ),
17
- 'default' => __ ( 'Apple Pay', 'woo-stripe-payment' ),
18
- 'desc_tip' => true,
19
- 'description' => __ ( 'Title of the Apple Pay gateway' )
20
- ),
21
- 'description' => array(
22
- 'title' => __ ( 'Description', 'woo-stripe-payment' ),
23
- 'type' => 'text', 'default' => '',
24
- 'description' => __ ( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
25
- 'desc_tip' => true
26
- ),
27
- 'method_format' => array(
28
- 'title' => __ ( 'Credit Card Display', 'woo-stripe-payment' ),
29
- 'type' => 'select',
30
- 'class' => 'wc-enhanced-select',
31
- 'options' => wp_list_pluck ( $this->get_method_formats (), 'example' ),
32
- 'value' => '', 'default' => 'type_ending_in',
33
- 'desc_tip' => true,
34
- 'description' => __ ( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' )
35
- ),
36
- 'charge_type' => array( 'type' => 'select',
37
- 'title' => __ ( 'Charge Type', 'woo-stripe-payment' ),
38
- 'default' => 'capture',
39
- 'class' => 'wc-enhanced-select',
40
- 'options' => array(
41
- 'capture' => __ ( 'Capture', 'woo-stripe-payment' ),
42
- 'authorize' => __ ( 'Authorize', 'woo-stripe-payment' )
43
- ), 'desc_tip' => true,
44
- 'description' => __ ( 'This option determines whether the customer\'s funds are captured immediately or authorized and can be captured at a later date.', 'woo-stripe-payment' )
45
- ),
46
- 'payment_sections' => array(
47
- 'type' => 'multiselect',
48
- 'title' => __ ( 'Payment Sections', 'woo-stripe-payment' ),
49
- 'class' => 'wc-enhanced-select',
50
- 'options' => [
51
- 'product' => __ ( 'Product Page', 'woo-stripe-payment' ),
52
- 'cart' => __ ( 'Cart Page', 'woo-stripe-payment' ),
53
- 'checkout_banner' => __ ( 'Top of Checkout', 'woo-stripe-payment' )
54
- ], 'default' => [ 'product', 'cart'
55
- ],
56
- 'description' => $this->get_payment_section_description ()
57
- ),
58
- 'order_status' => array( 'type' => 'select',
59
- 'title' => __ ( 'Order Status', 'woo-stripe-payment' ),
60
- 'default' => 'default',
61
- 'class' => 'wc-enhanced-select',
62
- 'options' => array_merge ( array(
63
- 'default' => __ ( 'Default', 'woo-stripe-payment' )
64
- ), wc_get_order_statuses () ),
65
- 'tool_tip' => true,
66
- 'description' => __ ( 'This is the status of the order once payment is complete. If <b>Default</b> is selected, then WooCommerce will set the order status automatically based on internal logic which states if a product is virtual and downloadable then status is set to complete. Products that require shipping are set to Processing. Default is the recommended setting as it allows standard WooCommerce code to process the order status.', 'woo-stripe-payment' )
67
- ),
68
- 'button_section' => [ 'type' => 'title',
69
- 'title' => __ ( 'Button Settings', 'woo-stripe-payment' )
70
- ],
71
- 'button_style' => [ 'type' => 'select',
72
- 'title' => __ ( 'Button Design', 'woo-stripe-payment' ),
73
- 'class' => 'wc-enhanced-select',
74
- 'default' => 'apple-pay-button-black',
75
- 'options' => array(
76
- 'apple-pay-button-black' => __ ( 'Black Button', 'woo-stripe-payment' ),
77
- 'apple-pay-button-white-with-line' => __ ( 'White With Black Line', 'woo-stripe-payment' ),
78
- 'apple-pay-button-white' => __ ( 'White Button', 'woo-stripe-payment' )
79
- ),
80
- 'description' => __ ( 'This is the style for all Apple Pay buttons presented on your store.', 'woo-stripe-payment' )
81
- ],
82
- 'button_type_checkout' => array(
83
- 'title' => __ ( 'Checkout button type', 'woo-stripe-payment' ),
84
- 'type' => 'select',
85
- 'options' => array(
86
- 'plain' => __ ( 'Standard Button', 'woo-stripe-payment' ),
87
- 'buy' => __ ( 'Buy with Apple Pay', 'woo-stripe-payment' )
88
- ),
89
- // 'check-out' => __ ( 'Checkout with Apple Pay', 'woo-stripe-payment' )
90
- 'default' => 'plain'
91
- ),
92
- 'button_type_cart' => array(
93
- 'title' => __ ( 'Cart button type', 'woo-stripe-payment' ),
94
- 'type' => 'select',
95
- 'options' => array(
96
- 'plain' => __ ( 'Standard Button', 'woo-stripe-payment' ),
97
- 'buy' => __ ( 'Buy with Apple Pay', 'woo-stripe-payment' )
98
- ),
99
- // 'check-out' => __ ( 'Checkout with Apple Pay', 'woo-stripe-payment' )
100
- 'default' => 'plain'
101
- ),
102
- 'button_type_product' => array(
103
- 'title' => __ ( 'Product button type', 'woo-stripe-payment' ),
104
- 'type' => 'select',
105
- 'options' => array(
106
- 'plain' => __ ( 'Standard Button', 'woo-stripe-payment' ),
107
- 'buy' => __ ( 'Buy with Apple Pay', 'woo-stripe-payment' )
108
- ),
109
- // 'check-out' => __ ( 'Checkout with Apple Pay', 'woo-stripe-payment' )
110
- 'default' => 'buy'
111
- )
112
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ return array(
3
+ 'desc' => array(
4
+ 'type' => 'description',
5
+ 'description' => sprintf( '<div class="wc-stripe-register-domain"><button class="button button-secondary api-register-domain">%s</button></div><p>%s</p>', __( 'Register Domain', 'woo-stripe-payment' ), sprintf( __( 'This plugin attemps to add the domain association file to your server automatically when you click the Register Domain button. If that fails due to file permssions, you must add the <strong>%1$s.well-known/apple-developer-merchantid-domain-association%2$s</strong> file to your domain and register your domain within the Stripe Dashboard.', 'woo-stripe-payment' ), '<a href="https://stripe.com/files/apple-pay/apple-developer-merchantid-domain-association">', '</a>' ) ) .
6
+ '<p>' .
7
+ __( 'In order for Apple Pay to display, you must test with an iOS device and have a payment method saved in the Apple Wallet.', 'woo-stripe-payment' ) .
8
+ '</p>',
9
+ ),
10
+ 'enabled' => array(
11
+ 'title' => __( 'Enabled', 'woo-stripe-payment' ),
12
+ 'type' => 'checkbox',
13
+ 'default' => 'no',
14
+ 'value' => 'yes',
15
+ 'desc_tip' => true,
16
+ 'description' => __( 'If enabled, your site can accept Apple Pay payments through Stripe.', 'woo-stripe-payment' ),
17
+ ),
18
+ 'general_settings' => array(
19
+ 'type' => 'title',
20
+ 'title' => __( 'General Settings', 'woo-stripe-payment' ),
21
+ ),
22
+ 'title_text' => array(
23
+ 'type' => 'text',
24
+ 'title' => __( 'Title', 'woo-stripe-payment' ),
25
+ 'default' => __( 'Apple Pay', 'woo-stripe-payment' ),
26
+ 'desc_tip' => true,
27
+ 'description' => __( 'Title of the Apple Pay gateway' ),
28
+ ),
29
+ 'description' => array(
30
+ 'title' => __( 'Description', 'woo-stripe-payment' ),
31
+ 'type' => 'text',
32
+ 'default' => '',
33
+ 'description' => __( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
34
+ 'desc_tip' => true,
35
+ ),
36
+ 'method_format' => array(
37
+ 'title' => __( 'Credit Card Display', 'woo-stripe-payment' ),
38
+ 'type' => 'select',
39
+ 'class' => 'wc-enhanced-select',
40
+ 'options' => wp_list_pluck( $this->get_method_formats(), 'example' ),
41
+ 'value' => '',
42
+ 'default' => 'type_ending_in',
43
+ 'desc_tip' => true,
44
+ 'description' => __( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' ),
45
+ ),
46
+ 'charge_type' => array(
47
+ 'type' => 'select',
48
+ 'title' => __( 'Charge Type', 'woo-stripe-payment' ),
49
+ 'default' => 'capture',
50
+ 'class' => 'wc-enhanced-select',
51
+ 'options' => array(
52
+ 'capture' => __( 'Capture', 'woo-stripe-payment' ),
53
+ 'authorize' => __( 'Authorize', 'woo-stripe-payment' ),
54
+ ),
55
+ 'desc_tip' => true,
56
+ 'description' => __( 'This option determines whether the customer\'s funds are captured immediately or authorized and can be captured at a later date.', 'woo-stripe-payment' ),
57
+ ),
58
+ 'payment_sections' => array(
59
+ 'type' => 'multiselect',
60
+ 'title' => __( 'Payment Sections', 'woo-stripe-payment' ),
61
+ 'class' => 'wc-enhanced-select',
62
+ 'options' => array(
63
+ 'product' => __( 'Product Page', 'woo-stripe-payment' ),
64
+ 'cart' => __( 'Cart Page', 'woo-stripe-payment' ),
65
+ 'checkout_banner' => __( 'Top of Checkout', 'woo-stripe-payment' ),
66
+ ),
67
+ 'default' => array( 'product', 'cart' ),
68
+ 'description' => $this->get_payment_section_description(),
69
+ ),
70
+ 'order_status' => array(
71
+ 'type' => 'select',
72
+ 'title' => __( 'Order Status', 'woo-stripe-payment' ),
73
+ 'default' => 'default',
74
+ 'class' => 'wc-enhanced-select',
75
+ 'options' => array_merge( array( 'default' => __( 'Default', 'woo-stripe-payment' ) ), wc_get_order_statuses() ),
76
+ 'tool_tip' => true,
77
+ 'description' => __( 'This is the status of the order once payment is complete. If <b>Default</b> is selected, then WooCommerce will set the order status automatically based on internal logic which states if a product is virtual and downloadable then status is set to complete. Products that require shipping are set to Processing. Default is the recommended setting as it allows standard WooCommerce code to process the order status.', 'woo-stripe-payment' ),
78
+ ),
79
+ 'button_section' => array(
80
+ 'type' => 'title',
81
+ 'title' => __( 'Button Settings', 'woo-stripe-payment' ),
82
+ ),
83
+ 'button_style' => array(
84
+ 'type' => 'select',
85
+ 'title' => __( 'Button Design', 'woo-stripe-payment' ),
86
+ 'class' => 'wc-enhanced-select',
87
+ 'default' => 'apple-pay-button-black',
88
+ 'options' => array(
89
+ 'apple-pay-button-black' => __( 'Black Button', 'woo-stripe-payment' ),
90
+ 'apple-pay-button-white-with-line' => __( 'White With Black Line', 'woo-stripe-payment' ),
91
+ 'apple-pay-button-white' => __( 'White Button', 'woo-stripe-payment' ),
92
+ ),
93
+ 'description' => __( 'This is the style for all Apple Pay buttons presented on your store.', 'woo-stripe-payment' ),
94
+ ),
95
+ 'button_type_checkout' => array(
96
+ 'title' => __( 'Checkout button type', 'woo-stripe-payment' ),
97
+ 'type' => 'select',
98
+ 'options' => array(
99
+ 'plain' => __( 'Standard Button', 'woo-stripe-payment' ),
100
+ 'buy' => __( 'Buy with Apple Pay', 'woo-stripe-payment' ),
101
+ ),
102
+ // 'check-out' => __ ( 'Checkout with Apple Pay', 'woo-stripe-payment' )
103
+ 'default' => 'plain',
104
+ ),
105
+ 'button_type_cart' => array(
106
+ 'title' => __( 'Cart button type', 'woo-stripe-payment' ),
107
+ 'type' => 'select',
108
+ 'options' => array(
109
+ 'plain' => __( 'Standard Button', 'woo-stripe-payment' ),
110
+ 'buy' => __( 'Buy with Apple Pay', 'woo-stripe-payment' ),
111
+ ),
112
+ // 'check-out' => __ ( 'Checkout with Apple Pay', 'woo-stripe-payment' )
113
+ 'default' => 'plain',
114
+ ),
115
+ 'button_type_product' => array(
116
+ 'title' => __( 'Product button type', 'woo-stripe-payment' ),
117
+ 'type' => 'select',
118
+ 'options' => array(
119
+ 'plain' => __( 'Standard Button', 'woo-stripe-payment' ),
120
+ 'buy' => __( 'Buy with Apple Pay', 'woo-stripe-payment' ),
121
+ ),
122
+ // 'check-out' => __ ( 'Checkout with Apple Pay', 'woo-stripe-payment' )
123
+ 'default' => 'buy',
124
+ ),
125
+ );
includes/gateways/settings/cc-settings.php CHANGED
@@ -1,139 +1,148 @@
1
- <?php
2
- return array(
3
- 'enabled' => array(
4
- 'title' => __ ( 'Enabled', 'woo-stripe-payment' ),
5
- 'type' => 'checkbox', 'default' => 'yes',
6
- 'value' => 'yes', 'desc_tip' => true,
7
- 'description' => __ ( 'If enabled, your site can accept credit card payments through Stripe.', 'woo-stripe-payment' )
8
- ),
9
- 'desc1' => array( 'type' => 'description',
10
- 'description' => sprintf ( __ ( '%sTest cards%s', 'woo-stripe-payment' ), '<a target="_blank" href="https://stripe.com/docs/testing#cards">', '</a>' )
11
- ),
12
- 'general_settings' => array( 'type' => 'title',
13
- 'title' => __ ( 'General Settings', 'woo-stripe-payment' )
14
- ),
15
- 'title_text' => array( 'type' => 'text',
16
- 'title' => __ ( 'Title', 'woo-stripe-payment' ),
17
- 'default' => __ ( 'Credit Cards', 'woo-stripe-payment' ),
18
- 'desc_tip' => true,
19
- 'description' => __ ( 'Title of the credit card gateway' )
20
- ),
21
- 'description' => array(
22
- 'title' => __ ( 'Description', 'woo-stripe-payment' ),
23
- 'type' => 'text', 'default' => '',
24
- 'description' => __ ( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
25
- 'desc_tip' => true
26
- ),
27
- 'method_format' => array(
28
- 'title' => __ ( 'Credit Card Display', 'woo-stripe-payment' ),
29
- 'type' => 'select',
30
- 'class' => 'wc-enhanced-select',
31
- 'options' => wp_list_pluck ( $this->get_method_formats (), 'example' ),
32
- 'value' => '', 'default' => 'type_ending_in',
33
- 'desc_tip' => true,
34
- 'description' => __ ( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' )
35
- ),
36
- 'charge_type' => array( 'type' => 'select',
37
- 'title' => __ ( 'Charge Type', 'woo-stripe-payment' ),
38
- 'default' => 'capture',
39
- 'class' => 'wc-enhanced-select',
40
- 'options' => array(
41
- 'capture' => __ ( 'Capture', 'woo-stripe-payment' ),
42
- 'authorize' => __ ( 'Authorize', 'woo-stripe-payment' )
43
- ), 'desc_tip' => true,
44
- 'description' => __ ( 'This option determines whether the customer\'s funds are captured immediately or authorized and can be captured at a later date.', 'woo-stripe-payment' )
45
- ),
46
- 'order_status' => array( 'type' => 'select',
47
- 'title' => __ ( 'Order Status', 'woo-stripe-payment' ),
48
- 'default' => 'default',
49
- 'class' => 'wc-enhanced-select',
50
- 'options' => array_merge ( array(
51
- 'default' => __ ( 'Default', 'woo-stripe-payment' )
52
- ), wc_get_order_statuses () ),
53
- 'tool_tip' => true,
54
- 'description' => __ ( 'This is the status of the order once payment is complete. If <b>Default</b> is selected, then WooCommerce will set the order status automatically based on internal logic which states if a product is virtual and downloadable then status is set to complete. Products that require shipping are set to Processing. Default is the recommended setting as it allows standard WooCommerce code to process the order status.', 'woo-stripe-payment' )
55
- ),
56
- 'save_card_enabled' => array( 'type' => 'checkbox',
57
- 'value' => 'yes', 'default' => 'yes',
58
- 'title' => __ ( 'Allow Credit Card Save', 'woo-stripe-payment' ),
59
- 'desc_tip' => false,
60
- 'description' => __ ( 'If enabled, a checkbox will be available on the checkout page allowing your customers to save their credit card. The payment methods are stored securely in Stripe\'s vault and never touch your server. Note: if the cart contains a subscription, there will be no checkbox because the payment method will be saved automatically. There will also be no checkbox for guest checkout as a user must be logged in to save a payment method.', 'woo-stripe-payment' )
61
- ),
62
- 'force_3d_secure' => array(
63
- 'title' => __ ( 'Force 3D Secure', 'woo-stripe-payment' ),
64
- 'type' => 'checkbox', 'value' => 'yes',
65
- 'default' => 'no', 'desc_tip' => false,
66
- 'description' => sprintf ( __ ( 'Stripe internally determines when 3D secure should be presented based on their SCA engine. If <strong>Force 3D Secure</strong> is enabled, 3D Secure will be forced for ALL credit card transactions. In test mode 3D secure only shows for %s3DS Test Cards%s regardless of this setting.', 'woo-stripe-payment' ), '<a target="_blank" href="https://stripe.com/docs/testing#regulatory-cards">', '</a>' )
67
- ),
68
- 'generic_error' => array(
69
- 'title' => __ ( 'Generic Errors', 'woo-stripe-payment' ),
70
- 'type' => 'checkbox', 'default' => 'no',
71
- 'value' => 'yes', 'desc_tip' => true,
72
- 'description' => __ ( 'If enabled, credit card errors will be generic when presented to the customer. Merchants may prefer to not provide details on why a card was not accepted for security purposes.', 'woo-stripe-payment' )
73
- ),
74
- 'cards' => array( 'type' => 'multiselect',
75
- 'title' => __ ( 'Accepted Payment Methods', 'wwoo-stripe' ),
76
- 'class' => 'wc-enhanced-select stripe-accepted-cards',
77
- 'default' => array( 'amex', 'discover',
78
- 'visa', 'mastercard'
79
- ),
80
- 'options' => array(
81
- 'visa' => __ ( 'Visa', 'wwoo-stripe' ),
82
- 'amex' => __ ( 'Amex', 'wwoo-stripe' ),
83
- 'discover' => __ ( 'Discover', 'wwoo-stripe' ),
84
- 'mastercard' => __ ( 'MasterCard', 'wwoo-stripe' ),
85
- 'jcb' => __ ( 'JCB', 'wwoo-stripe' ),
86
- 'maestro' => __ ( 'Maestro', 'wwoo-stripe' ),
87
- 'diners' => __ ( 'Diners Club', 'wwoo-stripe' ),
88
- 'china_union_pay' => __ ( 'Union Pay', 'wwoo-stripe' )
89
- ), 'desc_tip' => true,
90
- 'description' => __ ( 'The selected icons will show customers which credit card brands you accept.', 'wwoo-stripe' )
91
- ),
92
- 'form_title' => array( 'type' => 'title',
93
- 'title' => __ ( 'Credit Card Form', 'woo-stripe-payment' )
94
- ),
95
- 'form_type' => array(
96
- 'title' => __ ( 'Card Form', 'woo-stripe-payment' ),
97
- 'type' => 'select',
98
- 'options' => array(
99
- 'inline' => __ ( 'Stripe form', 'woo-stripe-payment' ),
100
- 'custom' => __ ( 'Custom form', 'woo-stripe-payment' )
101
- ), 'default' => 'inline',
102
- 'description' => __ ( 'The Stripe form option displays a CC form rendered by Stripe. It works well with most themes. The custom card forms are offered if you want more options on the CC form design.', 'woo-stripe-payment' )
103
- ),
104
- 'custom_form' => array(
105
- 'title' => __ ( 'Custom Form', 'woo-stripe-payment' ),
106
- 'type' => 'select',
107
- 'options' => wp_list_pluck ( wc_stripe_get_custom_forms (), 'label' ),
108
- 'default' => 'bootstrap',
109
- 'description' => __ ( 'The design of the credit card form.', 'woo-stripe-payment' ),
110
- 'desc_tip' => true,
111
- 'custom_attributes' => array(
112
- 'data-show-if' => array(
113
- 'form_type' => 'custom'
114
- )
115
- )
116
- ),
117
- 'postal_enabled' => array(
118
- 'title' => __ ( 'Postal Code', 'woo-stripe-payment' ),
119
- 'type' => 'checkbox', 'default' => 'no',
120
- 'description' => __ ( 'If enabled, the CC form will show the postal code on the checkout page. If disabled, the billing field\'s postal code will be used. The postal code will show on the Add Payment Method page for security reasons.', 'woo-stripe-payment' ),
121
- 'desc_tip' => true,
122
- 'custom_attributes' => array(
123
- 'data-show-if' => array(
124
- 'form_type' => 'custom'
125
- )
126
- )
127
- ),
128
- /* 'cvv_enabled' => array(
129
- 'title' => __ ( 'CVV Code', 'woo-stripe-payment' ),
130
- 'type' => 'checkbox', 'default' => 'yes',
131
- 'description' => __ ( 'If enabled, the CC form will show the cvv field.', 'woo-stripe-payment' ),
132
- 'desc_tip' => true,
133
- 'custom_attributes' => array(
134
- 'data-show-if' => array(
135
- 'form_type' => 'custom'
136
- )
137
- )
138
- ) */
139
- );
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ return array(
3
+ 'enabled' => array(
4
+ 'title' => __( 'Enabled', 'woo-stripe-payment' ),
5
+ 'type' => 'checkbox',
6
+ 'default' => 'yes',
7
+ 'value' => 'yes',
8
+ 'desc_tip' => true,
9
+ 'description' => __( 'If enabled, your site can accept credit card payments through Stripe.', 'woo-stripe-payment' ),
10
+ ),
11
+ 'desc1' => array(
12
+ 'type' => 'description',
13
+ 'description' => sprintf( __( '%1$sTest cards%2$s', 'woo-stripe-payment' ), '<a target="_blank" href="https://stripe.com/docs/testing#cards">', '</a>' ),
14
+ ),
15
+ 'general_settings' => array(
16
+ 'type' => 'title',
17
+ 'title' => __( 'General Settings', 'woo-stripe-payment' ),
18
+ ),
19
+ 'title_text' => array(
20
+ 'type' => 'text',
21
+ 'title' => __( 'Title', 'woo-stripe-payment' ),
22
+ 'default' => __( 'Credit Cards', 'woo-stripe-payment' ),
23
+ 'desc_tip' => true,
24
+ 'description' => __( 'Title of the credit card gateway' ),
25
+ ),
26
+ 'description' => array(
27
+ 'title' => __( 'Description', 'woo-stripe-payment' ),
28
+ 'type' => 'text',
29
+ 'default' => '',
30
+ 'description' => __( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
31
+ 'desc_tip' => true,
32
+ ),
33
+ 'method_format' => array(
34
+ 'title' => __( 'Credit Card Display', 'woo-stripe-payment' ),
35
+ 'type' => 'select',
36
+ 'class' => 'wc-enhanced-select',
37
+ 'options' => wp_list_pluck( $this->get_method_formats(), 'example' ),
38
+ 'value' => '',
39
+ 'default' => 'type_ending_in',
40
+ 'desc_tip' => true,
41
+ 'description' => __( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' ),
42
+ ),
43
+ 'charge_type' => array(
44
+ 'type' => 'select',
45
+ 'title' => __( 'Charge Type', 'woo-stripe-payment' ),
46
+ 'default' => 'capture',
47
+ 'class' => 'wc-enhanced-select',
48
+ 'options' => array(
49
+ 'capture' => __( 'Capture', 'woo-stripe-payment' ),
50
+ 'authorize' => __( 'Authorize', 'woo-stripe-payment' ),
51
+ ),
52
+ 'desc_tip' => true,
53
+ 'description' => __( 'This option determines whether the customer\'s funds are captured immediately or authorized and can be captured at a later date.', 'woo-stripe-payment' ),
54
+ ),
55
+ 'order_status' => array(
56
+ 'type' => 'select',
57
+ 'title' => __( 'Order Status', 'woo-stripe-payment' ),
58
+ 'default' => 'default',
59
+ 'class' => 'wc-enhanced-select',
60
+ 'options' => array_merge( array( 'default' => __( 'Default', 'woo-stripe-payment' ) ), wc_get_order_statuses() ),
61
+ 'tool_tip' => true,
62
+ 'description' => __( 'This is the status of the order once payment is complete. If <b>Default</b> is selected, then WooCommerce will set the order status automatically based on internal logic which states if a product is virtual and downloadable then status is set to complete. Products that require shipping are set to Processing. Default is the recommended setting as it allows standard WooCommerce code to process the order status.', 'woo-stripe-payment' ),
63
+ ),
64
+ 'save_card_enabled' => array(
65
+ 'type' => 'checkbox',
66
+ 'value' => 'yes',
67
+ 'default' => 'yes',
68
+ 'title' => __( 'Allow Credit Card Save', 'woo-stripe-payment' ),
69
+ 'desc_tip' => false,
70
+ 'description' => __( 'If enabled, a checkbox will be available on the checkout page allowing your customers to save their credit card. The payment methods are stored securely in Stripe\'s vault and never touch your server. Note: if the cart contains a subscription, there will be no checkbox because the payment method will be saved automatically. There will also be no checkbox for guest checkout as a user must be logged in to save a payment method.', 'woo-stripe-payment' ),
71
+ ),
72
+ 'force_3d_secure' => array(
73
+ 'title' => __( 'Force 3D Secure', 'woo-stripe-payment' ),
74
+ 'type' => 'checkbox',
75
+ 'value' => 'yes',
76
+ 'default' => 'no',
77
+ 'desc_tip' => false,
78
+ 'description' => sprintf( __( 'Stripe internally determines when 3D secure should be presented based on their SCA engine. If <strong>Force 3D Secure</strong> is enabled, 3D Secure will be forced for ALL credit card transactions. In test mode 3D secure only shows for %1$s3DS Test Cards%2$s regardless of this setting.', 'woo-stripe-payment' ), '<a target="_blank" href="https://stripe.com/docs/testing#regulatory-cards">', '</a>' ),
79
+ ),
80
+ 'generic_error' => array(
81
+ 'title' => __( 'Generic Errors', 'woo-stripe-payment' ),
82
+ 'type' => 'checkbox',
83
+ 'default' => 'no',
84
+ 'value' => 'yes',
85
+ 'desc_tip' => true,
86
+ 'description' => __( 'If enabled, credit card errors will be generic when presented to the customer. Merchants may prefer to not provide details on why a card was not accepted for security purposes.', 'woo-stripe-payment' ),
87
+ ),
88
+ 'cards' => array(
89
+ 'type' => 'multiselect',
90
+ 'title' => __( 'Accepted Payment Methods', 'wwoo-stripe' ),
91
+ 'class' => 'wc-enhanced-select stripe-accepted-cards',
92
+ 'default' => array( 'amex', 'discover', 'visa', 'mastercard' ),
93
+ 'options' => array(
94
+ 'visa' => __( 'Visa', 'wwoo-stripe' ),
95
+ 'amex' => __( 'Amex', 'wwoo-stripe' ),
96
+ 'discover' => __( 'Discover', 'wwoo-stripe' ),
97
+ 'mastercard' => __( 'MasterCard', 'wwoo-stripe' ),
98
+ 'jcb' => __( 'JCB', 'wwoo-stripe' ),
99
+ 'maestro' => __( 'Maestro', 'wwoo-stripe' ),
100
+ 'diners' => __( 'Diners Club', 'wwoo-stripe' ),
101
+ 'china_union_pay' => __( 'Union Pay', 'wwoo-stripe' ),
102
+ ),
103
+ 'desc_tip' => true,
104
+ 'description' => __( 'The selected icons will show customers which credit card brands you accept.', 'wwoo-stripe' ),
105
+ ),
106
+ 'form_title' => array(
107
+ 'type' => 'title',
108
+ 'title' => __( 'Credit Card Form', 'woo-stripe-payment' ),
109
+ ),
110
+ 'form_type' => array(
111
+ 'title' => __( 'Card Form', 'woo-stripe-payment' ),
112
+ 'type' => 'select',
113
+ 'options' => array(
114
+ 'inline' => __( 'Stripe form', 'woo-stripe-payment' ),
115
+ 'custom' => __( 'Custom form', 'woo-stripe-payment' ),
116
+ ),
117
+ 'default' => 'inline',
118
+ 'description' => __( 'The Stripe form option displays a CC form rendered by Stripe. It works well with most themes. The custom card forms are offered if you want more options on the CC form design.', 'woo-stripe-payment' ),
119
+ ),
120
+ 'custom_form' => array(
121
+ 'title' => __( 'Custom Form', 'woo-stripe-payment' ),
122
+ 'type' => 'select',
123
+ 'options' => wp_list_pluck( wc_stripe_get_custom_forms(), 'label' ),
124
+ 'default' => 'bootstrap',
125
+ 'description' => __( 'The design of the credit card form.', 'woo-stripe-payment' ),
126
+ 'desc_tip' => true,
127
+ 'custom_attributes' => array( 'data-show-if' => array( 'form_type' => 'custom' ) ),
128
+ ),
129
+ 'postal_enabled' => array(
130
+ 'title' => __( 'Postal Code', 'woo-stripe-payment' ),
131
+ 'type' => 'checkbox',
132
+ 'default' => 'no',
133
+ 'description' => __( 'If enabled, the CC form will show the postal code on the checkout page. If disabled, the billing field\'s postal code will be used. The postal code will show on the Add Payment Method page for security reasons.', 'woo-stripe-payment' ),
134
+ 'desc_tip' => true,
135
+ 'custom_attributes' => array( 'data-show-if' => array( 'form_type' => 'custom' ) ),
136
+ ),
137
+ /* 'cvv_enabled' => array(
138
+ 'title' => __ ( 'CVV Code', 'woo-stripe-payment' ),
139
+ 'type' => 'checkbox', 'default' => 'yes',
140
+ 'description' => __ ( 'If enabled, the CC form will show the cvv field.', 'woo-stripe-payment' ),
141
+ 'desc_tip' => true,
142
+ 'custom_attributes' => array(
143
+ 'data-show-if' => array(
144
+ 'form_type' => 'custom'
145
+ )
146
+ )
147
+ ) */
148
+ );
includes/gateways/settings/googlepay-settings.php CHANGED
@@ -1,126 +1,153 @@
1
- <?php
2
- return array(
3
- 'desc1' => array( 'type' => 'description',
4
- 'description' => '<p><a target="_blank" href="https://pay.google.com/business/console">' . __ ( 'GPay Business Console', 'woo-stripe-payment' ) . '</a></p>' . __ ( 'When test mode is enabled, Google Pay will work without a merchant ID, allowing you to capture the necessary screenshots the Google API team needs to approve your integration request.', 'woo-stripe-payment' )
5
- ),
6
- 'desc2' => array( 'type' => 'description',
7
- 'description' => sprintf ( '<p>%s</p>', sprintf ( __ ( 'If you don\'t want to request a Google Merchant ID, you can use the %sPayment Request Gateway%s which has a Google Pay integration through Stripe via the Chrome browser.', 'woo-stripe-payment' ), '<a target="_blank" href="' . admin_url ( 'admin.php?page=wc-settings&tab=checkout&section=stripe_payment_request' ) . '">', '</a>' ) )
8
- ),
9
- 'enabled' => array(
10
- 'title' => __ ( 'Enabled', 'woo-stripe-payment' ),
11
- 'type' => 'checkbox', 'default' => 'no',
12
- 'value' => 'yes', 'desc_tip' => true,
13
- 'description' => __ ( 'If enabled, your site can accept Google Pay payments through Stripe.', 'woo-stripe-payment' )
14
- ),
15
- 'general_settings' => array( 'type' => 'title',
16
- 'title' => __ ( 'General Settings', 'woo-stripe-payment' )
17
- ),
18
- 'dynamic_price' => array(
19
- 'title' => __ ( 'Dynamic Price', 'woo-stripe-payment' ),
20
- 'type' => 'checkbox', 'default' => 'yes',
21
- 'desc_tip' => true,
22
- 'description' => __ ( 'If enabled, the Google Payment sheet will show the order line items. You must have Google whitelist you for callback intents.', 'woo-stripe-payment' )
23
- ),
24
- 'merchant_id' => array( 'type' => 'text',
25
- 'title' => __ ( 'Merchant ID', 'woo-stripe-payment' ),
26
- 'default' => '',
27
- 'description' => __ ( 'Your Google Merchant ID is given to you by the Google API team once you register for Google Pay. While testing in TEST mode you can leave this value blank and Google Pay will work.', 'woo-stripe-payment' )
28
- ),
29
- 'title_text' => array( 'type' => 'text',
30
- 'title' => __ ( 'Title', 'woo-stripe-payment' ),
31
- 'default' => __ ( 'Google Pay', 'woo-stripe-payment' ),
32
- 'desc_tip' => true,
33
- 'description' => __ ( 'Title of the credit card gateway' )
34
- ),
35
- 'description' => array(
36
- 'title' => __ ( 'Description', 'woo-stripe-payment' ),
37
- 'type' => 'text', 'default' => '',
38
- 'description' => __ ( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
39
- 'desc_tip' => true
40
- ),
41
- 'method_format' => array(
42
- 'title' => __ ( 'Credit Card Display', 'woo-stripe-payment' ),
43
- 'type' => 'select',
44
- 'class' => 'wc-enhanced-select',
45
- 'options' => wp_list_pluck ( $this->get_method_formats (), 'example' ),
46
- 'value' => '', 'default' => 'type_ending_in',
47
- 'desc_tip' => true,
48
- 'description' => __ ( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' )
49
- ),
50
- 'charge_type' => array( 'type' => 'select',
51
- 'title' => __ ( 'Charge Type', 'woo-stripe-payment' ),
52
- 'default' => 'capture',
53
- 'class' => 'wc-enhanced-select',
54
- 'options' => array(
55
- 'capture' => __ ( 'Capture', 'woo-stripe-payment' ),
56
- 'authorize' => __ ( 'Authorize', 'woo-stripe-payment' )
57
- ), 'desc_tip' => true,
58
- 'description' => __ ( 'This option determines whether the customer\'s funds are capture immediately or authorized and can be captured at a later date.', 'woo-stripe-payment' )
59
- ),
60
- 'payment_sections' => array(
61
- 'type' => 'multiselect',
62
- 'title' => __ ( 'Payment Sections', 'woo-stripe-payment' ),
63
- 'class' => 'wc-enhanced-select',
64
- 'options' => [
65
- 'product' => __ ( 'Product Page', 'woo-stripe-payment' ),
66
- 'cart' => __ ( 'Cart Page', 'woo-stripe-payment' ),
67
- 'checkout_banner' => __ ( 'Top of Checkout', 'woo-stripe-payment' )
68
- ], 'default' => [ 'product', 'cart'
69
- ],
70
- 'description' => $this->get_payment_section_description ()
71
- ),
72
- 'order_status' => array( 'type' => 'select',
73
- 'title' => __ ( 'Order Status', 'woo-stripe-payment' ),
74
- 'default' => 'default',
75
- 'class' => 'wc-enhanced-select',
76
- 'options' => array_merge ( array(
77
- 'default' => __ ( 'Default', 'woo-stripe-payment' )
78
- ), wc_get_order_statuses () ),
79
- 'tool_tip' => true,
80
- 'description' => __ ( 'This is the status of the order once payment is complete. If <b>Default</b> is selected, then WooCommerce will set the order status automatically based on internal logic which states if a product is virtual and downloadable then status is set to complete. Products that require shipping are set to Processing. Default is the recommended setting as it allows standard WooCommerce code to process the order status.', 'woo-stripe-payment' )
81
- ),
82
- 'merchant_name' => [ 'type' => 'text',
83
- 'title' => __ ( 'Merchant Name', 'woo-stripe-payment' ),
84
- 'default' => get_bloginfo ( 'name' ),
85
- 'description' => __ ( 'The name of your business as it appears on the Google Pay payment sheet.', 'woo-stripe-payment' ),
86
- 'desc_tip' => true
87
- ],
88
- 'icon' => array(
89
- 'title' => __ ( 'Icon', 'woo-stripe-payment' ),
90
- 'type' => 'select',
91
- 'options' => array(
92
- 'googlepay_outline' => __ ( 'With Outline', 'woo-stripe-payment' ),
93
- 'googlepay_standard' => __ ( 'Standard', 'woo-stripe-payment' )
94
- ), 'default' => 'googlepay_outline',
95
- 'desc_tip' => true,
96
- 'description' => __ ( 'This is the icon style that appears next to the gateway on the checkout page. Google\'s API team typically requires the With Outline option on the checkout page for branding purposes.', 'woo-stripe-payment' )
97
- ),
98
- 'button_section' => array( 'type' => 'title',
99
- 'title' => __ ( 'Button Options', 'woo-stripe-payment' )
100
- ),
101
- 'button_color' => array(
102
- 'title' => __ ( 'Button Color', 'woo-stripe-payment' ),
103
- 'type' => 'select',
104
- 'class' => 'gpay-button-option button-color',
105
- 'options' => array(
106
- 'black' => __ ( 'Black', 'woo-stripe-payment' ),
107
- 'white' => __ ( 'White', 'woo-stripe-payment' )
108
- ), 'default' => 'black',
109
- 'description' => __ ( 'The button color of the GPay button.', 'woo-stripe-payment' )
110
- ),
111
- 'button_style' => array(
112
- 'title' => __ ( 'Button Style', 'woo-stripe-payment' ),
113
- 'type' => 'select',
114
- 'class' => 'gpay-button-option button-style',
115
- 'options' => array(
116
- 'long' => __ ( 'Long', 'woo-stripe-payment' ),
117
- 'short' => __ ( 'Short', 'woo-stripe-payment' )
118
- ), 'default' => 'long',
119
- 'description' => __ ( 'The button style of the GPay button.', 'woo-stripe-payment' )
120
- ),
121
- 'button_render' => [ 'type' => 'button_demo',
122
- 'title' => __ ( 'Button Design', 'woo-stripe-payment' ),
123
- 'id' => 'gpay-button',
124
- 'description' => __ ( 'If you can\'t see the Google Pay button, try switching to a Chrome browser.', 'woo-stripe-payment' )
125
- ]
126
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ return array(
3
+ 'desc1' => array(
4
+ 'type' => 'description',
5
+ 'description' => '<p><a target="_blank" href="https://pay.google.com/business/console">' . __( 'GPay Business Console', 'woo-stripe-payment' ) .
6
+ '</a></p>' .
7
+ __( 'When test mode is enabled, Google Pay will work without a merchant ID, allowing you to capture the necessary screenshots the Google API team needs to approve your integration request.', 'woo-stripe-payment' ),
8
+ ),
9
+ 'desc2' => array(
10
+ 'type' => 'description',
11
+ 'description' => sprintf(
12
+ '<p>%s</p>',
13
+ sprintf(
14
+ __( 'If you don\'t want to request a Google Merchant ID, you can use the %1$sPayment Request Gateway%2$s which has a Google Pay integration through Stripe via the Chrome browser.', 'woo-stripe-payment' ),
15
+ '<a target="_blank" href="' .
16
+ admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe_payment_request' ) . '">',
17
+ '</a>'
18
+ )
19
+ ),
20
+ ),
21
+ 'enabled' => array(
22
+ 'title' => __( 'Enabled', 'woo-stripe-payment' ),
23
+ 'type' => 'checkbox',
24
+ 'default' => 'no',
25
+ 'value' => 'yes',
26
+ 'desc_tip' => true,
27
+ 'description' => __( 'If enabled, your site can accept Google Pay payments through Stripe.', 'woo-stripe-payment' ),
28
+ ),
29
+ 'general_settings' => array(
30
+ 'type' => 'title',
31
+ 'title' => __( 'General Settings', 'woo-stripe-payment' ),
32
+ ),
33
+ 'dynamic_price' => array(
34
+ 'title' => __( 'Dynamic Price', 'woo-stripe-payment' ),
35
+ 'type' => 'checkbox',
36
+ 'default' => 'yes',
37
+ 'desc_tip' => true,
38
+ 'description' => __( 'If enabled, the Google Payment sheet will show the order line items. You must have Google whitelist you for callback intents.', 'woo-stripe-payment' ),
39
+ ),
40
+ 'merchant_id' => array(
41
+ 'type' => 'text',
42
+ 'title' => __( 'Merchant ID', 'woo-stripe-payment' ),
43
+ 'default' => '',
44
+ 'description' => __( 'Your Google Merchant ID is given to you by the Google API team once you register for Google Pay. While testing in TEST mode you can leave this value blank and Google Pay will work.', 'woo-stripe-payment' ),
45
+ ),
46
+ 'title_text' => array(
47
+ 'type' => 'text',
48
+ 'title' => __( 'Title', 'woo-stripe-payment' ),
49
+ 'default' => __( 'Google Pay', 'woo-stripe-payment' ),
50
+ 'desc_tip' => true,
51
+ 'description' => __( 'Title of the credit card gateway' ),
52
+ ),
53
+ 'description' => array(
54
+ 'title' => __( 'Description', 'woo-stripe-payment' ),
55
+ 'type' => 'text',
56
+ 'default' => '',
57
+ 'description' => __( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
58
+ 'desc_tip' => true,
59
+ ),
60
+ 'method_format' => array(
61
+ 'title' => __( 'Credit Card Display', 'woo-stripe-payment' ),
62
+ 'type' => 'select',
63
+ 'class' => 'wc-enhanced-select',
64
+ 'options' => wp_list_pluck( $this->get_method_formats(), 'example' ),
65
+ 'value' => '',
66
+ 'default' => 'type_ending_in',
67
+ 'desc_tip' => true,
68
+ 'description' => __( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' ),
69
+ ),
70
+ 'charge_type' => array(
71
+ 'type' => 'select',
72
+ 'title' => __( 'Charge Type', 'woo-stripe-payment' ),
73
+ 'default' => 'capture',
74
+ 'class' => 'wc-enhanced-select',
75
+ 'options' => array(
76
+ 'capture' => __( 'Capture', 'woo-stripe-payment' ),
77
+ 'authorize' => __( 'Authorize', 'woo-stripe-payment' ),
78
+ ),
79
+ 'desc_tip' => true,
80
+ 'description' => __( 'This option determines whether the customer\'s funds are capture immediately or authorized and can be captured at a later date.', 'woo-stripe-payment' ),
81
+ ),
82
+ 'payment_sections' => array(
83
+ 'type' => 'multiselect',
84
+ 'title' => __( 'Payment Sections', 'woo-stripe-payment' ),
85
+ 'class' => 'wc-enhanced-select',
86
+ 'options' => array(
87
+ 'product' => __( 'Product Page', 'woo-stripe-payment' ),
88
+ 'cart' => __( 'Cart Page', 'woo-stripe-payment' ),
89
+ 'checkout_banner' => __( 'Top of Checkout', 'woo-stripe-payment' ),
90
+ ),
91
+ 'default' => array( 'product', 'cart' ),
92
+ 'description' => $this->get_payment_section_description(),
93
+ ),
94
+ 'order_status' => array(
95
+ 'type' => 'select',
96
+ 'title' => __( 'Order Status', 'woo-stripe-payment' ),
97
+ 'default' => 'default',
98
+ 'class' => 'wc-enhanced-select',
99
+ 'options' => array_merge( array( 'default' => __( 'Default', 'woo-stripe-payment' ) ), wc_get_order_statuses() ),
100
+ 'tool_tip' => true,
101
+ 'description' => __( 'This is the status of the order once payment is complete. If <b>Default</b> is selected, then WooCommerce will set the order status automatically based on internal logic which states if a product is virtual and downloadable then status is set to complete. Products that require shipping are set to Processing. Default is the recommended setting as it allows standard WooCommerce code to process the order status.', 'woo-stripe-payment' ),
102
+ ),
103
+ 'merchant_name' => array(
104
+ 'type' => 'text',
105
+ 'title' => __( 'Merchant Name', 'woo-stripe-payment' ),
106
+ 'default' => get_bloginfo( 'name' ),
107
+ 'description' => __( 'The name of your business as it appears on the Google Pay payment sheet.', 'woo-stripe-payment' ),
108
+ 'desc_tip' => true,
109
+ ),
110
+ 'icon' => array(
111
+ 'title' => __( 'Icon', 'woo-stripe-payment' ),
112
+ 'type' => 'select',
113
+ 'options' => array(
114
+ 'googlepay_outline' => __( 'With Outline', 'woo-stripe-payment' ),
115
+ 'googlepay_standard' => __( 'Standard', 'woo-stripe-payment' ),
116
+ ),
117
+ 'default' => 'googlepay_outline',
118
+ 'desc_tip' => true,
119
+ 'description' => __( 'This is the icon style that appears next to the gateway on the checkout page. Google\'s API team typically requires the With Outline option on the checkout page for branding purposes.', 'woo-stripe-payment' ),
120
+ ),
121
+ 'button_section' => array(
122
+ 'type' => 'title',
123
+ 'title' => __( 'Button Options', 'woo-stripe-payment' ),
124
+ ),
125
+ 'button_color' => array(
126
+ 'title' => __( 'Button Color', 'woo-stripe-payment' ),
127
+ 'type' => 'select',
128
+ 'class' => 'gpay-button-option button-color',
129
+ 'options' => array(
130
+ 'black' => __( 'Black', 'woo-stripe-payment' ),
131
+ 'white' => __( 'White', 'woo-stripe-payment' ),
132
+ ),
133
+ 'default' => 'black',
134
+ 'description' => __( 'The button color of the GPay button.', 'woo-stripe-payment' ),
135
+ ),
136
+ 'button_style' => array(
137
+ 'title' => __( 'Button Style', 'woo-stripe-payment' ),
138
+ 'type' => 'select',
139
+ 'class' => 'gpay-button-option button-style',
140
+ 'options' => array(
141
+ 'long' => __( 'Long', 'woo-stripe-payment' ),
142
+ 'short' => __( 'Short', 'woo-stripe-payment' ),
143
+ ),
144
+ 'default' => 'long',
145
+ 'description' => __( 'The button style of the GPay button.', 'woo-stripe-payment' ),
146
+ ),
147
+ 'button_render' => array(
148
+ 'type' => 'button_demo',
149
+ 'title' => __( 'Button Design', 'woo-stripe-payment' ),
150
+ 'id' => 'gpay-button',
151
+ 'description' => __( 'If you can\'t see the Google Pay button, try switching to a Chrome browser.', 'woo-stripe-payment' ),
152
+ ),
153
+ );
includes/gateways/settings/payment-request-settings.php CHANGED
@@ -1,95 +1,115 @@
1
- <?php
2
- return array(
3
- 'desc' => array( 'type' => 'description',
4
- 'description' => __ ( 'The PaymentRequest gateway uses your customer\'s browser to render payment options like Google Pay and Microsoft Pay. You can either use the Google Pay gateway for example, or this gateway.
5
- The difference is this gateway uses Stripe\'s PaymentRequest Button rather than render a Google Pay specific button.', 'woo-stripe-payment' )
6
- ),
7
- 'enabled' => array(
8
- 'title' => __ ( 'Enabled', 'woo-stripe-payment' ),
9
- 'type' => 'checkbox', 'default' => 'no',
10
- 'value' => 'yes', 'desc_tip' => true,
11
- 'description' => __ ( 'If enabled, your site can accept Apple Pay payments through Stripe.', 'woo-stripe-payment' )
12
- ),
13
- 'general_settings' => array( 'type' => 'title',
14
- 'title' => __ ( 'General Settings', 'woo-stripe-payment' )
15
- ),
16
- 'title_text' => array( 'type' => 'text',
17
- 'title' => __ ( 'Title', 'woo-stripe-payment' ),
18
- 'default' => __ ( 'Browser Payments', 'woo-stripe-payment' ),
19
- 'desc_tip' => true,
20
- 'description' => __ ( 'Title of the credit card gateway' )
21
- ),
22
- 'description' => array(
23
- 'title' => __ ( 'Description', 'woo-stripe-payment' ),
24
- 'type' => 'text', 'default' => '',
25
- 'description' => __ ( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
26
- 'desc_tip' => true
27
- ),
28
- 'method_format' => array(
29
- 'title' => __ ( 'Credit Card Display', 'woo-stripe-payment' ),
30
- 'type' => 'select',
31
- 'class' => 'wc-enhanced-select',
32
- 'options' => wp_list_pluck ( $this->get_method_formats (), 'example' ),
33
- 'value' => '', 'default' => 'type_ending_in',
34
- 'desc_tip' => true,
35
- 'description' => __ ( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' )
36
- ),
37
- 'charge_type' => array( 'type' => 'select',
38
- 'title' => __ ( 'Charge Type', 'woo-stripe-payment' ),
39
- 'default' => 'capture',
40
- 'class' => 'wc-enhanced-select',
41
- 'options' => array(
42
- 'capture' => __ ( 'Capture', 'woo-stripe-payment' ),
43
- 'authorize' => __ ( 'Authorize', 'woo-stripe-payment' )
44
- ), 'desc_tip' => true,
45
- 'description' => __ ( 'This option determines whether the customer\'s funds are captured immediately or authorized and can be captured at a later date.', 'woo-stripe-payment' )
46
- ),
47
- 'payment_sections' => array(
48
- 'type' => 'multiselect',
49
- 'title' => __ ( 'Payment Sections', 'woo-stripe-payment' ),
50
- 'class' => 'wc-enhanced-select',
51
- 'options' => [
52
- 'product' => __ ( 'Product Page', 'woo-stripe-payment' ),
53
- 'cart' => __ ( 'Cart Page', 'woo-stripe-payment' ),
54
- 'checkout_banner' => __ ( 'Top of Checkout', 'woo-stripe-payment' )
55
- ], 'default' => [ 'product', 'cart'
56
- ],
57
- 'description' => $this->get_payment_section_description ()
58
- ),
59
- 'order_status' => array( 'type' => 'select',
60
- 'title' => __ ( 'Order Status', 'woo-stripe-payment' ),
61
- 'default' => 'default',
62
- 'class' => 'wc-enhanced-select',
63
- 'options' => array_merge ( array(
64
- 'default' => __ ( 'Default', 'woo-stripe-payment' )
65
- ), wc_get_order_statuses () ),
66
- 'tool_tip' => true,
67
- 'description' => __ ( 'This is the status of the order once payment is complete. If <b>Default</b> is selected, then WooCommerce will set the order status automatically based on internal logic which states if a product is virtual and downloadable then status is set to complete. Products that require shipping are set to Processing. Default is the recommended setting as it allows standard WooCommerce code to process the order status.', 'woo-stripe-payment' )
68
- ),
69
- 'button_section' => [ 'type' => 'title',
70
- 'title' => __ ( 'Button Settings', 'woo-stripe-payment' )
71
- ],
72
- 'button_type' => [ 'type' => 'select',
73
- 'title' => __ ( 'Type', 'woo-stripe-payment' ),
74
- 'options' => [
75
- 'default' => __ ( 'default', 'woo-stripe-payment' ),
76
- // 'donate' => __ ( 'donate', 'woo-stripe-payment' ),
77
- 'buy' => __ ( 'buy', 'woo-stripe-payment' )
78
- ], 'default' => 'buy', 'desc_tip' => true,
79
- 'description' => __ ( 'This defines the type of button that will display.', 'woo-stripe-payment' )
80
- ],
81
- 'button_theme' => [ 'type' => 'select',
82
- 'title' => __ ( 'Theme', 'woo-stripe-payment' ),
83
- 'options' => [
84
- 'dark' => __ ( 'dark', 'woo-stripe-payment' ),
85
- 'light' => __ ( 'light', 'woo-stripe-payment' ),
86
- 'light-outline' => __ ( 'light-outline', 'woo-stripe-payment' )
87
- ], 'default' => 'dark', 'desc_tip' => true,
88
- 'description' => __ ( 'This defines the color scheme for the button.', 'woo-stripe-payment' )
89
- ],
90
- 'button_height' => [ 'type' => 'text',
91
- 'title' => __ ( 'Height', 'woo-stripe-payment' ),
92
- 'default' => '40', 'desc_tip' => true,
93
- 'description' => __ ( 'The height of the button. Max height is 64', 'woo-stripe-payment' )
94
- ]
95
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ return array(
3
+ 'desc' => array(
4
+ 'type' => 'description',
5
+ 'description' => __(
6
+ 'The PaymentRequest gateway uses your customer\'s browser to render payment options like Google Pay and Microsoft Pay. You can either use the Google Pay gateway for example, or this gateway.
7
+ The difference is this gateway uses Stripe\'s PaymentRequest Button rather than render a Google Pay specific button.',
8
+ 'woo-stripe-payment'
9
+ ),
10
+ ),
11
+ 'enabled' => array(
12
+ 'title' => __( 'Enabled', 'woo-stripe-payment' ),
13
+ 'type' => 'checkbox',
14
+ 'default' => 'no',
15
+ 'value' => 'yes',
16
+ 'desc_tip' => true,
17
+ 'description' => __( 'If enabled, your site can accept Apple Pay payments through Stripe.', 'woo-stripe-payment' ),
18
+ ),
19
+ 'general_settings' => array(
20
+ 'type' => 'title',
21
+ 'title' => __( 'General Settings', 'woo-stripe-payment' ),
22
+ ),
23
+ 'title_text' => array(
24
+ 'type' => 'text',
25
+ 'title' => __( 'Title', 'woo-stripe-payment' ),
26
+ 'default' => __( 'Browser Payments', 'woo-stripe-payment' ),
27
+ 'desc_tip' => true,
28
+ 'description' => __( 'Title of the credit card gateway' ),
29
+ ),
30
+ 'description' => array(
31
+ 'title' => __( 'Description', 'woo-stripe-payment' ),
32
+ 'type' => 'text',
33
+ 'default' => '',
34
+ 'description' => __( 'Leave blank if you don\'t want a description to show for the gateway.', 'woo-stripe-payment' ),
35
+ 'desc_tip' => true,
36
+ ),
37
+ 'method_format' => array(
38
+ 'title' => __( 'Credit Card Display', 'woo-stripe-payment' ),
39
+ 'type' => 'select',
40
+ 'class' => 'wc-enhanced-select',
41
+ 'options' => wp_list_pluck( $this->get_method_formats(), 'example' ),
42
+ 'value' => '',
43
+ 'default' => 'type_ending_in',
44
+ 'desc_tip' => true,
45
+ 'description' => __( 'This option allows you to customize how the credit card will display for your customers on orders, subscriptions, etc.' ),
46
+ ),
47
+ 'charge_type' => array(
48
+ 'type' => 'select',
49
+ 'title' => __( 'Charge Type', 'woo-stripe-payment' ),
50
+ 'default' => 'capture',
51
+ 'class' => 'wc-enhanced-select',
52
+ 'options' => array(
53
+ 'capture' => __( 'Capture', 'woo-stripe-payment' ),
54
+ 'authorize' => __( 'Authorize', 'woo-stripe-payment' ),
55
+ ),
56
+ 'desc_tip' => true,
57
+ 'description' => __( 'This option determines whether the customer\'s funds are captured immediately or authorized and can be captured at a later date.', 'woo-stripe-payment' ),
58
+ ),
59
+ 'payment_sections' => array(
60
+ 'type' => 'multiselect',
61
+ 'title' => __( 'Payment Sections', 'woo-stripe-payment' ),
62
+ 'class' => 'wc-enhanced-select',
63
+ 'options' => array(
64
+ 'product' => __( 'Product Page', 'woo-stripe-payment' ),
65
+ 'cart' => __( 'Cart Page', 'woo-stripe-payment' ),
66
+ 'checkout_banner' => __( 'Top of Checkout', 'woo-stripe-payment' ),
67
+ ),
68
+ 'default' => array( 'product', 'cart' ),
69
+ 'description' => $this->get_payment_section_description(),
70
+ ),
71
+ 'order_status' => array(
72
+ 'type' => 'select',
73
+ 'title' => __( 'Order Status', 'woo-stripe-payment' ),
74
+ 'default' => 'default',
75
+ 'class' => 'wc-enhanced-select',
76
+ 'options' => array_merge( array( 'default' => __( 'Default', 'woo-stripe-payment' ) ), wc_get_order_statuses() ),
77
+ 'tool_tip' => true,
78
+ 'description' => __( 'This is the status of the order once payment is complete. If <b>Default</b> is selected, then WooCommerce will set the order status automatically based on internal logic which states if a product is virtual and downloadable then status is set to complete. Products that require shipping are set to Processing. Default is the recommended setting as it allows standard WooCommerce code to process the order status.', 'woo-stripe-payment' ),
79
+ ),
80
+ 'button_section' => array(
81
+ 'type' => 'title',
82
+ 'title' => __( 'Button Settings', 'woo-stripe-payment' ),
83
+ ),
84
+ 'button_type' => array(
85
+ 'type' => 'select',
86
+ 'title' => __( 'Type', 'woo-stripe-payment' ),
87
+ 'options' => array(
88
+ 'default' => __( 'default', 'woo-stripe-payment' ),
89
+ // 'donate' => __ ( 'donate', 'woo-stripe-payment' ),
90
+ 'buy' => __( 'buy', 'woo-stripe-payment' ),
91
+ ),
92
+ 'default' => 'buy',
93
+ 'desc_tip' => true,
94
+ 'description' => __( 'This defines the type of button that will display.', 'woo-stripe-payment' ),
95
+ ),
96
+ 'button_theme' => array(
97
+ 'type' => 'select',
98
+ 'title' => __( 'Theme', 'woo-stripe-payment' ),
99
+ 'options' => array(
100
+ 'dark' => __( 'dark', 'woo-stripe-payment' ),
101
+ 'light' => __( 'light', 'woo-stripe-payment' ),
102
+ 'light-outline' => __( 'light-outline', 'woo-stripe-payment' ),
103
+ ),
104
+ 'default' => 'dark',
105
+ 'desc_tip' => true,
106
+ 'description' => __( 'This defines the color scheme for the button.', 'woo-stripe-payment' ),
107
+ ),
108
+ 'button_height' => array(
109
+ 'type' => 'text',
110
+ 'title' => __( 'Height', 'woo-stripe-payment' ),
111
+ 'default' => '40',
112
+ 'desc_tip' => true,
113
+ 'description' => __( 'The height of the button. Max height is 64', 'woo-stripe-payment' ),
114
+ ),
115
+ );
includes/tokens/class-wc-payment-token-stripe-ach.php CHANGED
@@ -1,83 +1,85 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.0.5
7
- * @package Stripe/Tokens
8
- * @author Payment Plugins
9
- *
10
- */
11
- class WC_Payment_Token_Stripe_ACH extends WC_Payment_Token_Stripe {
12
-
13
- use WC_Payment_Token_Source_Trait;
14
-
15
- protected $type = 'Stripe_ACH';
16
-
17
- protected $stripe_payment_type = 'source';
18
-
19
- protected $stripe_data = array( 'bank_name' => '',
20
- 'routing_number' => '', 'last4' => ''
21
- );
22
-
23
- /**
24
- *
25
- * {@inheritDoc}
26
- *
27
- * @see WC_Payment_Token_Stripe::details_to_props()
28
- */
29
- public function details_to_props($details) {
30
- if (isset ( $details[ 'ach_debit' ] )) {
31
- $bank = $details[ 'ach_debit' ];
32
- } elseif ($details instanceof \Stripe\BankAccount) {
33
- $bank = $details;
34
- }
35
- $this->set_brand ( $bank[ 'bank_name' ] );
36
- $this->set_bank_name ( $bank[ 'bank_name' ] );
37
- $this->set_last4 ( $bank[ 'last4' ] );
38
- $this->set_routing_number ( $bank[ 'routing_number' ] );
39
- }
40
-
41
- public function get_bank_name($context = 'view') {
42
- return $this->get_prop ( 'bank_name', $context );
43
- }
44
-
45
- public function get_routing_number($context = 'view') {
46
- return $this->get_prop ( 'routing_number', $context );
47
- }
48
-
49
- public function get_last4($context = 'view') {
50
- return $this->get_prop ( 'last4', $context );
51
- }
52
-
53
- public function set_bank_name($value) {
54
- $this->set_prop ( 'bank_name', $value );
55
- }
56
-
57
- public function set_routing_number($value) {
58
- $this->set_prop ( 'routing_number', $value );
59
- }
60
-
61
- public function set_last4($value) {
62
- $this->set_prop ( 'last4', $value );
63
- }
64
-
65
- public function get_formats() {
66
- return array(
67
- 'type_ending_in' => array(
68
- 'label' => __ ( 'Type Ending In', 'woo-stripe-payment' ),
69
- 'example' => 'Chase ending in 3434',
70
- 'format' => __ ( '{bank_name} ending in {last4}', 'woo-stripe-payment' )
71
- ),
72
- 'name_masked_last4' => array(
73
- 'label' => __ ( 'Type Ending In', 'woo-stripe-payment' ),
74
- 'example' => 'Chase **** 3434',
75
- 'format' => __ ( '{bank_name} **** {last4}', 'woo-stripe-payment' )
76
- )
77
- );
78
- }
79
-
80
- public function get_html_classes() {
81
- return 'wc-stripe-ach';
82
- }
83
- }
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @since 3.0.5
7
+ * @package Stripe/Tokens
8
+ * @author Payment Plugins
9
+ *
10
+ */
11
+ class WC_Payment_Token_Stripe_ACH extends WC_Payment_Token_Stripe {
12
+
13
+ use WC_Payment_Token_Source_Trait;
14
+
15
+ protected $type = 'Stripe_ACH';
16
+
17
+ protected $stripe_payment_type = 'source';
18
+
19
+ protected $stripe_data = array(
20
+ 'bank_name' => '',
21
+ 'routing_number' => '',
22
+ 'last4' => '',
23
+ );
24
+
25
+ /**
26
+ *
27
+ * {@inheritDoc}
28
+ *
29
+ * @see WC_Payment_Token_Stripe::details_to_props()
30
+ */
31
+ public function details_to_props( $details ) {
32
+ if ( isset( $details['ach_debit'] ) ) {
33
+ $bank = $details['ach_debit'];
34
+ } elseif ( $details instanceof \Stripe\BankAccount ) {
35
+ $bank = $details;
36
+ }
37
+ $this->set_brand( $bank['bank_name'] );
38
+ $this->set_bank_name( $bank['bank_name'] );
39
+ $this->set_last4( $bank['last4'] );
40
+ $this->set_routing_number( $bank['routing_number'] );
41
+ }
42
+
43
+ public function get_bank_name( $context = 'view' ) {
44
+ return $this->get_prop( 'bank_name', $context );
45
+ }
46
+
47
+ public function get_routing_number( $context = 'view' ) {
48
+ return $this->get_prop( 'routing_number', $context );
49
+ }
50
+
51
+ public function get_last4( $context = 'view' ) {
52
+ return $this->get_prop( 'last4', $context );
53
+ }
54
+
55
+ public function set_bank_name( $value ) {
56
+ $this->set_prop( 'bank_name', $value );
57
+ }
58
+
59
+ public function set_routing_number( $value ) {
60
+ $this->set_prop( 'routing_number', $value );
61
+ }
62
+
63
+ public function set_last4( $value ) {
64
+ $this->set_prop( 'last4', $value );
65
+ }
66
+
67
+ public function get_formats() {
68
+ return array(
69
+ 'type_ending_in' => array(
70
+ 'label' => __( 'Type Ending In', 'woo-stripe-payment' ),
71
+ 'example' => 'Chase ending in 3434',
72
+ 'format' => __( '{bank_name} ending in {last4}', 'woo-stripe-payment' ),
73
+ ),
74
+ 'name_masked_last4' => array(
75
+ 'label' => __( 'Type Ending In', 'woo-stripe-payment' ),
76
+ 'example' => 'Chase **** 3434',
77
+ 'format' => __( '{bank_name} **** {last4}', 'woo-stripe-payment' ),
78
+ ),
79
+ );
80
+ }
81
+
82
+ public function get_html_classes() {
83
+ return 'wc-stripe-ach';
84
+ }
85
+ }
includes/tokens/class-wc-payment-token-stripe-applepay.php CHANGED
@@ -1,16 +1,17 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Token_Stripe_CC' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @author PaymentPlugins
10
- * @package Stripe/Tokens
11
- *
12
- */
13
- class WC_Payment_Token_Stripe_ApplePay extends WC_Payment_Token_Stripe_CC {
14
-
15
- protected $type = 'Stripe_ApplePay';
16
- }
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Token_Stripe_CC' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @author PaymentPlugins
11
+ * @package Stripe/Tokens
12
+ *
13
+ */
14
+ class WC_Payment_Token_Stripe_ApplePay extends WC_Payment_Token_Stripe_CC {
15
+
16
+ protected $type = 'Stripe_ApplePay';
17
+ }
includes/tokens/class-wc-payment-token-stripe-cc.php CHANGED
@@ -1,122 +1,126 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Token_Stripe' )) {
5
- return;
6
- }
7
- /**
8
- * @sin 3.0.0
9
- *
10
- * @author PaymentPlugins
11
- * @package Stripe/Tokens
12
- *
13
- */
14
- class WC_Payment_Token_Stripe_CC extends WC_Payment_Token_Stripe {
15
-
16
- use WC_Payment_Token_Payment_Method_Trait;
17
-
18
- protected $has_expiration = true;
19
-
20
- protected $type = 'Stripe_CC';
21
-
22
- protected $stripe_payment_type = 'payment_method';
23
-
24
- protected $stripe_data = array( 'brand' => '',
25
- 'exp_month' => '', 'exp_year' => '',
26
- 'last4' => '', 'masked_number' => ''
27
- );
28
-
29
- public function details_to_props($details) {
30
- if (isset ( $details[ 'card' ] )) {
31
- $card = $details[ 'card' ];
32
- }
33
- if ($details instanceof \Stripe\Card) {
34
- $card = $details;
35
- }
36
- $this->set_brand ( $card[ 'brand' ] );
37
- $this->set_last4 ( $card[ 'last4' ] );
38
- $this->set_exp_month ( $card[ 'exp_month' ] );
39
- $this->set_exp_year ( $card[ 'exp_year' ] );
40
- $this->set_masked_number ( sprintf ( '********%s', $card[ 'last4' ] ) );
41
- }
42
-
43
- public function get_last4($context = 'view') {
44
- return $this->get_prop ( 'last4', $context );
45
- }
46
-
47
- public function get_masked_number($context = 'view') {
48
- return $this->get_prop ( 'masked_number', $context );
49
- }
50
-
51
- public function set_last4($last4) {
52
- $this->set_prop ( 'last4', $last4 );
53
- }
54
-
55
- public function set_masked_number($value) {
56
- $this->set_prop ( 'masked_number', $value );
57
- }
58
-
59
- public function get_exp_year($context = 'view') {
60
- return $this->get_prop ( 'exp_year', $context );
61
- }
62
-
63
- public function set_exp_year($year) {
64
- $this->set_prop ( 'exp_year', $year );
65
- }
66
-
67
- public function get_exp_month($context = 'view') {
68
- return $this->get_prop ( 'exp_month', $context );
69
- }
70
-
71
- public function set_exp_month($month) {
72
- $this->set_prop ( 'exp_month', str_pad ( $month, 2, '0', STR_PAD_LEFT ) );
73
- }
74
-
75
- public function get_html_classes() {
76
- return sprintf ( '%s', str_replace ( ' ', '', strtolower ( $this->get_prop ( 'brand' ) ) ) );
77
- }
78
-
79
- public function get_card_type($context = 'view') {
80
- return $this->get_brand ( $context );
81
- }
82
-
83
- public function get_formats() {
84
- return array(
85
- 'type_ending_in' => array(
86
- 'label' => __ ( 'Type Ending In', 'woo-stripe-payment' ),
87
- 'example' => 'Visa ending in 1111',
88
- 'format' => __ ( '{brand} ending in {last4}', 'woo-stripe-payment' )
89
- ),
90
- 'type_masked_number' => array(
91
- 'label' => __ ( 'Type Masked Number', 'woo-stripe-payment' ),
92
- 'example' => 'Visa ********1111',
93
- 'format' => '{brand} {masked_number}'
94
- ),
95
- 'type_dash_masked_number' => array(
96
- 'label' => __ ( 'Type Dash Masked Number', 'woo-stripe-payment' ),
97
- 'example' => 'Visa - ********1111',
98
- 'format' => '{brand} - {masked_number}'
99
- ),
100
- 'type_last4' => array(
101
- 'label' => __ ( 'Type Last 4', 'woo-stripe-payment' ),
102
- 'example' => 'Visa 1111',
103
- 'format' => '{brand} {last4}'
104
- ),
105
- 'type_dash_last4' => array(
106
- 'label' => __ ( 'Type Dash & Last 4', 'woo-stripe-payment' ),
107
- 'example' => 'Visa - 1111',
108
- 'format' => '{brand} - {last4}'
109
- ),
110
- 'last4' => array(
111
- 'label' => __ ( 'Last Four', 'woo-stripe-payment' ),
112
- 'example' => '1111',
113
- 'format' => '{last4}'
114
- ),
115
- 'card_type' => array(
116
- 'label' => __ ( 'Card Type', 'woo-stripe-payment' ),
117
- 'example' => 'Visa',
118
- 'format' => '{brand}'
119
- )
120
- );
121
- }
122
- }
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Token_Stripe' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ * @sin 3.0.0
10
+ *
11
+ * @author PaymentPlugins
12
+ * @package Stripe/Tokens
13
+ *
14
+ */
15
+ class WC_Payment_Token_Stripe_CC extends WC_Payment_Token_Stripe {
16
+
17
+ use WC_Payment_Token_Payment_Method_Trait;
18
+
19
+ protected $has_expiration = true;
20
+
21
+ protected $type = 'Stripe_CC';
22
+
23
+ protected $stripe_payment_type = 'payment_method';
24
+
25
+ protected $stripe_data = array(
26
+ 'brand' => '',
27
+ 'exp_month' => '',
28
+ 'exp_year' => '',
29
+ 'last4' => '',
30
+ 'masked_number' => '',
31
+ );
32
+
33
+ public function details_to_props( $details ) {
34
+ if ( isset( $details['card'] ) ) {
35
+ $card = $details['card'];
36
+ }
37
+ if ( $details instanceof \Stripe\Card ) {
38
+ $card = $details;
39
+ }
40
+ $this->set_brand( $card['brand'] );
41
+ $this->set_last4( $card['last4'] );
42
+ $this->set_exp_month( $card['exp_month'] );
43
+ $this->set_exp_year( $card['exp_year'] );
44
+ $this->set_masked_number( sprintf( '********%s', $card['last4'] ) );
45
+ }
46
+
47
+ public function get_last4( $context = 'view' ) {
48
+ return $this->get_prop( 'last4', $context );
49
+ }
50
+
51
+ public function get_masked_number( $context = 'view' ) {
52
+ return $this->get_prop( 'masked_number', $context );
53
+ }
54
+
55
+ public function set_last4( $last4 ) {
56
+ $this->set_prop( 'last4', $last4 );
57
+ }
58
+
59
+ public function set_masked_number( $value ) {
60
+ $this->set_prop( 'masked_number', $value );
61
+ }
62
+
63
+ public function get_exp_year( $context = 'view' ) {
64
+ return $this->get_prop( 'exp_year', $context );
65
+ }
66
+
67
+ public function set_exp_year( $year ) {
68
+ $this->set_prop( 'exp_year', $year );
69
+ }
70
+
71
+ public function get_exp_month( $context = 'view' ) {
72
+ return $this->get_prop( 'exp_month', $context );
73
+ }
74
+
75
+ public function set_exp_month( $month ) {
76
+ $this->set_prop( 'exp_month', str_pad( $month, 2, '0', STR_PAD_LEFT ) );
77
+ }
78
+
79
+ public function get_html_classes() {
80
+ return sprintf( '%s', str_replace( ' ', '', strtolower( $this->get_prop( 'brand' ) ) ) );
81
+ }
82
+
83
+ public function get_card_type( $context = 'view' ) {
84
+ return $this->get_brand( $context );
85
+ }
86
+
87
+ public function get_formats() {
88
+ return array(
89
+ 'type_ending_in' => array(
90
+ 'label' => __( 'Type Ending In', 'woo-stripe-payment' ),
91
+ 'example' => 'Visa ending in 1111',
92
+ 'format' => __( '{brand} ending in {last4}', 'woo-stripe-payment' ),
93
+ ),
94
+ 'type_masked_number' => array(
95
+ 'label' => __( 'Type Masked Number', 'woo-stripe-payment' ),
96
+ 'example' => 'Visa ********1111',
97
+ 'format' => '{brand} {masked_number}',
98
+ ),
99
+ 'type_dash_masked_number' => array(
100
+ 'label' => __( 'Type Dash Masked Number', 'woo-stripe-payment' ),
101
+ 'example' => 'Visa - ********1111',
102
+ 'format' => '{brand} - {masked_number}',
103
+ ),
104
+ 'type_last4' => array(
105
+ 'label' => __( 'Type Last 4', 'woo-stripe-payment' ),
106
+ 'example' => 'Visa 1111',
107
+ 'format' => '{brand} {last4}',
108
+ ),
109
+ 'type_dash_last4' => array(
110
+ 'label' => __( 'Type Dash & Last 4', 'woo-stripe-payment' ),
111
+ 'example' => 'Visa - 1111',
112
+ 'format' => '{brand} - {last4}',
113
+ ),
114
+ 'last4' => array(
115
+ 'label' => __( 'Last Four', 'woo-stripe-payment' ),
116
+ 'example' => '1111',
117
+ 'format' => '{last4}',
118
+ ),
119
+ 'card_type' => array(
120
+ 'label' => __( 'Card Type', 'woo-stripe-payment' ),
121
+ 'example' => 'Visa',
122
+ 'format' => '{brand}',
123
+ ),
124
+ );
125
+ }
126
+ }
includes/tokens/class-wc-payment-token-stripe-googlepay.php CHANGED
@@ -1,21 +1,21 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- if (! class_exists ( 'WC_Payment_Token_Stripe_CC' )) {
5
- return;
6
- }
7
- /**
8
- *
9
- * @author PaymentPlugins
10
- * @package Stripe/Tokens
11
- *
12
- */
13
- class WC_Payment_Token_Stripe_GooglePay extends WC_Payment_Token_Stripe_CC {
14
-
15
- use WC_Payment_Token_Source_Trait;
16
-
17
- protected $type = 'Stripe_GooglePay';
18
-
19
- protected $stripe_payment_type = 'source';
20
-
21
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ if ( ! class_exists( 'WC_Payment_Token_Stripe_CC' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ *
10
+ * @author PaymentPlugins
11
+ * @package Stripe/Tokens
12
+ *
13
+ */
14
+ class WC_Payment_Token_Stripe_GooglePay extends WC_Payment_Token_Stripe_CC {
15
+
16
+ use WC_Payment_Token_Source_Trait;
17
+
18
+ protected $type = 'Stripe_GooglePay';
19
+
20
+ protected $stripe_payment_type = 'source';
21
+ }
includes/tokens/class-wc-payment-token-stripe-local-payment.php CHANGED
@@ -1,41 +1,40 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.0.0
7
- * @package Stripe/Tokens
8
- * @author PaymentPlugins
9
- *
10
- */
11
- class WC_Payment_Token_Stripe_Local extends WC_Payment_Token_Stripe {
12
-
13
- protected $type = 'Stripe_Local';
14
-
15
- protected $stripe_data = [ 'gateway_title' => ''
16
- ];
17
-
18
- public function details_to_props($details) {}
19
-
20
- public function set_gateway_title($value) {
21
- $this->set_prop ( 'gateway_title', $value );
22
- }
23
-
24
- public function get_gateway_title($context = 'view') {
25
- return $this->get_prop ( 'gateway_title', $context );
26
- }
27
-
28
- public function get_formats() {
29
- return [
30
- 'gateway_title' => [
31
- 'label' => __ ( 'Gateway Title', 'woo-stripe-payment' ),
32
- 'example' => 'P24',
33
- 'format' => '{gateway_title}'
34
- ]
35
- ];
36
- }
37
-
38
- public function save_payment_method() {}
39
-
40
- public function delete_from_stripe() {}
41
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @since 3.0.0
7
+ * @package Stripe/Tokens
8
+ * @author PaymentPlugins
9
+ *
10
+ */
11
+ class WC_Payment_Token_Stripe_Local extends WC_Payment_Token_Stripe {
12
+
13
+ protected $type = 'Stripe_Local';
14
+
15
+ protected $stripe_data = array( 'gateway_title' => '' );
16
+
17
+ public function details_to_props( $details ) {}
18
+
19
+ public function set_gateway_title( $value ) {
20
+ $this->set_prop( 'gateway_title', $value );
21
+ }
22
+
23
+ public function get_gateway_title( $context = 'view' ) {
24
+ return $this->get_prop( 'gateway_title', $context );
25
+ }
26
+
27
+ public function get_formats() {
28
+ return array(
29
+ 'gateway_title' => array(
30
+ 'label' => __( 'Gateway Title', 'woo-stripe-payment' ),
31
+ 'example' => 'P24',
32
+ 'format' => '{gateway_title}',
33
+ ),
34
+ );
35
+ }
36
+
37
+ public function save_payment_method() {}
38
+
39
+ public function delete_from_stripe() {}
40
+ }
 
includes/traits/wc-stripe-controller-cart-trait.php CHANGED
@@ -1,25 +1,28 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.1.0
7
- * @author Payment Plugins
8
- *
9
- */
10
- trait WC_Stripe_Controller_Cart_Trait{
11
-
12
- /**
13
- * Method that hooks in to the woocommerce_cart_ready_to_calc_shipping filter.
14
- * Purpose is to ensure
15
- * true is returned so shipping packages are calculated. Some 3rd party plugins and themes return false
16
- * if the current page is the cart because they don't want to display the shipping calculator.
17
- *
18
- * @since 3.1.0
19
- */
20
- public function add_ready_to_calc_shipping() {
21
- add_filter ( 'woocommerce_cart_ready_to_calc_shipping', function ($show_shipping) {
22
- return true;
23
- }, 1000 );
24
- }
25
- }
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @since 3.1.0
7
+ * @author Payment Plugins
8
+ */
9
+ trait WC_Stripe_Controller_Cart_Trait {
10
+
11
+ /**
12
+ * Method that hooks in to the woocommerce_cart_ready_to_calc_shipping filter.
13
+ * Purpose is to ensure
14
+ * true is returned so shipping packages are calculated. Some 3rd party plugins and themes return false
15
+ * if the current page is the cart because they don't want to display the shipping calculator.
16
+ *
17
+ * @since 3.1.0
18
+ */
19
+ public function add_ready_to_calc_shipping() {
20
+ add_filter(
21
+ 'woocommerce_cart_ready_to_calc_shipping',
22
+ function ( $show_shipping ) {
23
+ return true;
24
+ },
25
+ 1000
26
+ );
27
+ }
28
+ }
includes/traits/wc-stripe-payment-token-traits.php CHANGED
@@ -1,65 +1,38 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author PaymentPlugins
7
- * @since 3.1.5
8
- * @package Stripe/Trait
9
- *
10
- */
11
- trait WC_Payment_Token_Source_Trait{
12
-
13
- public function save_payment_method() {
14
- $gateway = WC_Stripe_Gateway::load ();
15
-
16
- return $gateway->create_customer_source ( $this->get_customer_id (), $this->get_token () );
17
- }
18
-
19
- public function delete_from_stripe() {
20
- $customer_id = wc_stripe_get_customer_id ( $this->get_user_id (), $this->get_environment () );
21
-
22
- try {
23
- WC_Stripe_Gateway::load ()->delete_card ( $this->get_token (), $customer_id, $this->get_environment () );
24
- } catch ( \Stripe\Error\Base $e ) {
25
- wc_stripe_log_error ( sprintf ( __ ( 'Error deleting Stripe card. Token Id: %s', 'woo-stripe-payment' ), $this->get_token () ) );
26
- }
27
- }
28
- }
29
-
30
- /**
31
- *
32
- * @author PaymentPlugins
33
- * @since 3.1.5
34
- * @package Stripe/Trait
35
- *
36
- */
37
- trait WC_Payment_Token_Payment_Method_Trait{
38
-
39
- public function save_payment_method() {
40
- $gateway = WC_Stripe_Gateway::load ();
41
-
42
- $payment_method = $gateway->fetch_payment_method ( $this->get_token () );
43
-
44
- if (is_wp_error ( $payment_method )) {
45
- return $payment_method;
46
- }
47
-
48
- return $gateway->attach_payment_method ( $payment_method, [
49
- 'customer' => $this->get_customer_id ()
50
- ] );
51
- }
52
-
53
- public function delete_from_stripe() {
54
- $customer_id = wc_stripe_get_customer_id ( $this->get_user_id (), $this->get_environment () );
55
- $gateway = WC_Stripe_Gateway::load ();
56
-
57
- $payment_method = $gateway->fetch_payment_method ( $this->get_token () );
58
-
59
- if (is_wp_error ( $payment_method )) {
60
- return $payment_method;
61
- }
62
-
63
- return $gateway->delete_payment_method ( $payment_method );
64
- }
65
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author PaymentPlugins
7
+ * @since 3.1.5
8
+ * @package Stripe/Trait
9
+ *
10
+ */
11
+ trait WC_Payment_Token_Source_Trait {
12
+
13
+ public function save_payment_method() {
14
+ return WC_Stripe_Gateway::load()->customers->createSource( $this->get_customer_id(), array( 'source' => $this->get_token() ) );
15
+ }
16
+
17
+ public function delete_from_stripe() {
18
+ return WC_Stripe_Gateway::load()->sources->mode( $this->get_environment() )->detach( $this->get_customer_id(), $this->get_token() );
19
+ }
20
+ }
21
+
22
+ /**
23
+ *
24
+ * @author PaymentPlugins
25
+ * @since 3.1.5
26
+ * @package Stripe/Trait
27
+ *
28
+ */
29
+ trait WC_Payment_Token_Payment_Method_Trait {
30
+
31
+ public function save_payment_method() {
32
+ return WC_Stripe_Gateway::load()->paymentMethods->attach( $this->get_token(), array( 'customer' => $this->get_customer_id() ) );
33
+ }
34
+
35
+ public function delete_from_stripe() {
36
+ return WC_Stripe_Gateway::load()->paymentMethods->mode( $this->get_environment() )->detach( $this->get_token() );
37
+ }
38
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/traits/wc-stripe-payment-traits.php CHANGED
@@ -1,101 +1,122 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @author Payment Plugins
7
- * @since 3.1.0
8
- * @package Stripe/Trait
9
- */
10
- trait WC_Stripe_Payment_Intent_Trait{
11
-
12
- public function get_payment_object() {
13
- return WC_Stripe_Payment_Factory::load ( 'payment_intent', $this, WC_Stripe_Gateway::load () );
14
- }
15
-
16
- public function get_payment_method_type() {
17
- return $this->payment_method_type;
18
- }
19
-
20
- /**
21
- *
22
- * @param WC_Order $order
23
- */
24
- public function get_confirmation_method($order) {
25
- return 'manual';
26
- }
27
-
28
- /**
29
- *
30
- * @param \Stripe\PaymentIntent $secret
31
- * @param WC_Order $order
32
- */
33
- public function get_payment_intent_checkout_url($intent, $order) {
34
- // rand is used to generate some random entropy so that window hash events are triggered.
35
- return sprintf ( '#response=%s', base64_encode ( wp_json_encode ( [
36
- 'client_secret' => $intent->client_secret,
37
- 'order_id' => $order->get_id (),
38
- 'time' => rand ( 0, 999999 )
39
- ] ) ) );
40
- }
41
- }
42
- /**
43
- *
44
- * @author Payment Plugins
45
- * @since 3.1.0
46
- * @package Stripe/Trait
47
- */
48
- trait WC_Stripe_Payment_Charge_Trait{
49
-
50
- public function get_payment_object() {
51
- return WC_Stripe_Payment_Factory::load ( 'charge', $this, WC_Stripe_Gateway::load () );
52
- }
53
- }
54
-
55
- /**
56
- *
57
- * @author Payment Plugins
58
- * @since 3.1.0
59
- * @package Stripe/Trait
60
- */
61
- trait WC_Stripe_Local_Payment_Charge_Trait{
62
-
63
- public function get_payment_object() {
64
- return WC_Stripe_Payment_Factory::load ( 'local_charge', $this, WC_Stripe_Gateway::load () );
65
- }
66
- }
67
-
68
- /**
69
- *
70
- * @author Payment Plugins
71
- * @since 3.1.0
72
- * @package Stripe/Trait
73
- *
74
- */
75
- trait WC_Stripe_Local_Payment_Intent_Trait {
76
-
77
- use WC_Stripe_Payment_Intent_Trait;
78
-
79
- /**
80
- *
81
- * @param \Stripe\PaymentIntent $secret
82
- * @param WC_Order $order
83
- */
84
- public function get_payment_intent_checkout_url($intent, $order) {
85
- // rand is used to generate some random entropy so that window hash events are triggered.
86
- return sprintf ( '#response=%s', base64_encode ( wp_json_encode ( [
87
- 'client_secret' => $intent->client_secret,
88
- 'gateway_id' => $this->id,
89
- 'return_url' => $this->get_local_payment_return_url ( $order ),
90
- 'time' => rand ( 0, 999999 )
91
- ] ) ) );
92
- }
93
-
94
- /**
95
- *
96
- * @param WC_Order $order
97
- */
98
- public function get_confirmation_method($order) {
99
- return 'automatic';
100
- }
101
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @author Payment Plugins
7
+ * @since 3.1.0
8
+ * @package Stripe/Trait
9
+ */
10
+ trait WC_Stripe_Payment_Intent_Trait {
11
+
12
+ public function get_payment_object() {
13
+ return WC_Stripe_Payment_Factory::load( 'payment_intent', $this, WC_Stripe_Gateway::load() );
14
+ }
15
+
16
+ public function get_payment_method_type() {
17
+ return $this->payment_method_type;
18
+ }
19
+
20
+ /**
21
+ *
22
+ * @param WC_Order $order
23
+ */
24
+ public function get_confirmation_method( $order ) {
25
+ return 'manual';
26
+ }
27
+
28
+ /**
29
+ *
30
+ * @param \Stripe\PaymentIntent $secret
31
+ * @param WC_Order $order
32
+ */
33
+ public function get_payment_intent_checkout_url( $intent, $order ) {
34
+ // rand is used to generate some random entropy so that window hash events are triggered.
35
+ return sprintf(
36
+ '#response=%s',
37
+ base64_encode(
38
+ wp_json_encode(
39
+ array(
40
+ 'client_secret' => $intent->client_secret,
41
+ 'order_id' => $order->get_id(),
42
+ 'time' => rand(
43
+ 0,
44
+ 999999
45
+ ),
46
+ )
47
+ )
48
+ )
49
+ );
50
+ }
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @author Payment Plugins
56
+ * @since 3.1.0
57
+ * @package Stripe/Trait
58
+ */
59
+ trait WC_Stripe_Payment_Charge_Trait {
60
+
61
+ public function get_payment_object() {
62
+ return WC_Stripe_Payment_Factory::load( 'charge', $this, WC_Stripe_Gateway::load() );
63
+ }
64
+ }
65
+
66
+ /**
67
+ *
68
+ * @author Payment Plugins
69
+ * @since 3.1.0
70
+ * @package Stripe/Trait
71
+ */
72
+ trait WC_Stripe_Local_Payment_Charge_Trait {
73
+
74
+ public function get_payment_object() {
75
+ return WC_Stripe_Payment_Factory::load( 'local_charge', $this, WC_Stripe_Gateway::load() );
76
+ }
77
+ }
78
+
79
+ /**
80
+ *
81
+ * @author Payment Plugins
82
+ * @since 3.1.0
83
+ * @package Stripe/Trait
84
+ *
85
+ */
86
+ trait WC_Stripe_Local_Payment_Intent_Trait {
87
+
88
+ use WC_Stripe_Payment_Intent_Trait;
89
+
90
+ /**
91
+ *
92
+ * @param \Stripe\PaymentIntent $secret
93
+ * @param WC_Order $order
94
+ */
95
+ public function get_payment_intent_checkout_url( $intent, $order ) {
96
+ // rand is used to generate some random entropy so that window hash events are triggered.
97
+ return sprintf(
98
+ '#response=%s',
99
+ base64_encode(
100
+ wp_json_encode(
101
+ array(
102
+ 'client_secret' => $intent->client_secret,
103
+ 'gateway_id' => $this->id,
104
+ 'return_url' => $this->get_local_payment_return_url( $order ),
105
+ 'time' => rand(
106
+ 0,
107
+ 999999
108
+ ),
109
+ )
110
+ )
111
+ )
112
+ );
113
+ }
114
+
115
+ /**
116
+ *
117
+ * @param WC_Order $order
118
+ */
119
+ public function get_confirmation_method( $order ) {
120
+ return 'automatic';
121
+ }
122
+ }
includes/traits/wc-stripe-settings-trait.php CHANGED
@@ -1,160 +1,178 @@
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
- return $tabs;
19
- }
20
-
21
- public function is_active($key) {
22
- return $this->get_option ( $key ) === 'yes';
23
- }
24
-
25
- public function admin_options() {
26
- if ($this->admin_output) {
27
- return;
28
- }
29
- $this->display_errors ();
30
- $this->output_settings_nav ();
31
- printf ( '<input type="hidden" id="wc_stripe_prefix" name="wc_stripe_prefix" value="%1$s"/>', $this->get_prefix () );
32
- echo '<div class="wc-stripe-settings-container ' . $this->id . '">';
33
- parent::admin_options ();
34
- echo '</div>';
35
- $this->admin_output = true;
36
- }
37
-
38
- public function output_settings_nav() {
39
- include wc_stripe ()->plugin_path () . 'includes/admin/views/html-settings-nav.php';
40
- }
41
-
42
- /**
43
- * Display admin error messages.
44
- */
45
- public function display_errors() {
46
- if ($this->get_errors ()) {
47
- echo '<div id="woocommerce_errors" class="error notice inline is-dismissible">';
48
- foreach ( $this->get_errors () as $error ) {
49
- echo '<p>' . wp_kses_post ( $error ) . '</p>';
50
- }
51
- echo '</div>';
52
- }
53
- }
54
-
55
- public function get_prefix() {
56
- return $this->plugin_id . $this->id . '_';
57
- }
58
-
59
- public function generate_multiselect_html($key, $data) {
60
- $value = ( array ) $this->get_option ( $key, array() );
61
- $data[ 'options' ] = array_merge ( array_flip ( $value ), $data[ 'options' ] );
62
- return parent::generate_multiselect_html ( $key, $data );
63
- }
64
-
65
- public function get_custom_attribute_html($attribs) {
66
- if (! empty ( $attribs[ 'custom_attributes' ] ) && is_array ( $attribs[ 'custom_attributes' ] )) {
67
- foreach ( $attribs[ 'custom_attributes' ] as $k => $v ) {
68
- if (is_array ( $v )) {
69
- $attribs[ 'custom_attributes' ][ $k ] = htmlspecialchars ( wp_json_encode ( $v ) );
70
- }
71
- }
72
- }
73
- return parent::get_custom_attribute_html ( $attribs );
74
- }
75
-
76
- public function generate_description_html($key, $data) {
77
- $field_key = $this->get_field_key ( $key );
78
- $data = wp_parse_args ( $data, array(
79
- 'class' => '', 'style' => '',
80
- 'description' => ''
81
- ) );
82
- ob_start ();
83
- include wc_stripe ()->plugin_path () . 'includes/admin/views/html-description.php';
84
- return ob_get_clean ();
85
- }
86
-
87
- public function generate_paragraph_html($key, $data) {
88
- $field_key = $this->get_field_key ( $key );
89
- $defaults = array( 'title' => '', 'label' => '',
90
- 'class' => '', 'css' => '',
91
- 'desc_tip' => false, 'description' => '',
92
- 'custom_attributes' => array()
93
- );
94
- $data = wp_parse_args ( $data, $defaults );
95
- if (! $data[ 'label' ]) {
96
- $data[ 'label' ] = $data[ 'title' ];
97
- }
98
- ob_start ();
99
- include wc_stripe ()->plugin_path () . 'includes/admin/views/html-paragraph.php';
100
- return ob_get_clean ();
101
- }
102
-
103
- public function generate_stripe_button_html($key, $data) {
104
- $field_key = $this->get_field_key ( $key );
105
- $data = wp_parse_args ( $data, array(
106
- 'title' => '', 'class' => '', 'style' => '',
107
- 'description' => '', 'desc_tip' => false,
108
- 'id' => 'wc-stripe-button_' . $key,
109
- 'disabled' => false, 'css' => ''
110
- ) );
111
- ob_start ();
112
- include wc_stripe ()->plugin_path () . 'includes/admin/views/html-button.php';
113
- return ob_get_clean ();
114
- }
115
-
116
- public function generate_button_demo_html($key, $data) {
117
- $field_key = $this->get_field_key ( $key );
118
- $data = wp_parse_args ( $data, array(
119
- 'title' => '', 'class' => '', 'style' => '',
120
- 'description' => '', 'desc_tip' => false,
121
- 'id' => 'wc-stripe-button-demo'
122
- ) );
123
- ob_start ();
124
- include wc_stripe ()->plugin_path () . 'includes/admin/views/html-button-demo.php';
125
- return ob_get_clean ();
126
- }
127
-
128
- /**
129
- * Added override to provide more control on which fields are saved and which are skipped.
130
- * This plugin
131
- * has custom setting fields like "paragraph" that are for info display only and not for saving.
132
- *
133
- * {@inheritDoc}
134
- *
135
- * @see WC_Settings_API::process_admin_options()
136
- */
137
- public function process_admin_options() {
138
- $this->init_settings ();
139
-
140
- $post_data = $this->get_post_data ();
141
-
142
- $skip_types = [ 'title', 'paragraph', 'button',
143
- 'description', 'button_demo',
144
- 'stripe_button'
145
- ];
146
-
147
- foreach ( $this->get_form_fields () as $key => $field ) {
148
- $skip = isset ( $field[ 'skip' ] ) && $field[ 'skip' ] == true;
149
- if (! in_array ( $this->get_field_type ( $field ), $skip_types ) && ! $skip) {
150
- try {
151
- $this->settings[ $key ] = $this->get_field_value ( $key, $field, $post_data );
152
- } catch ( Exception $e ) {
153
- $this->add_error ( $e->getMessage () );
154
- }
155
- }
156
- }
157
-
158
- return update_option ( $this->get_option_key (), apply_filters ( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' );
159
- }
160
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ return $tabs;
19
+ }
20
+
21
+ public function is_active( $key ) {
22
+ return $this->get_option( $key ) === 'yes';
23
+ }
24
+
25
+ public function admin_options() {
26
+ if ( $this->admin_output ) {
27
+ return;
28
+ }
29
+ $this->display_errors();
30
+ $this->output_settings_nav();
31
+ printf( '<input type="hidden" id="wc_stripe_prefix" name="wc_stripe_prefix" value="%1$s"/>', $this->get_prefix() );
32
+ echo '<div class="wc-stripe-settings-container ' . $this->id . '">';
33
+ parent::admin_options();
34
+ echo '</div>';
35
+ $this->admin_output = true;
36
+ }
37
+
38
+ public function output_settings_nav() {
39
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-settings-nav.php';
40
+ }
41
+
42
+ /**
43
+ * Display admin error messages.
44
+ */
45
+ public function display_errors() {
46
+ if ( $this->get_errors() ) {
47
+ echo '<div id="woocommerce_errors" class="error notice inline is-dismissible">';
48
+ foreach ( $this->get_errors() as $error ) {
49
+ echo '<p>' . wp_kses_post( $error ) . '</p>';
50
+ }
51
+ echo '</div>';
52
+ }
53
+ }
54
+
55
+ public function get_prefix() {
56
+ return $this->plugin_id . $this->id . '_';
57
+ }
58
+
59
+ public function generate_multiselect_html( $key, $data ) {
60
+ $value = (array) $this->get_option( $key, array() );
61
+ $data['options'] = array_merge( array_flip( $value ), $data['options'] );
62
+ return parent::generate_multiselect_html( $key, $data );
63
+ }
64
+
65
+ public function get_custom_attribute_html( $attribs ) {
66
+ if ( ! empty( $attribs['custom_attributes'] ) && is_array( $attribs['custom_attributes'] ) ) {
67
+ foreach ( $attribs['custom_attributes'] as $k => $v ) {
68
+ if ( is_array( $v ) ) {
69
+ $attribs['custom_attributes'][ $k ] = htmlspecialchars( wp_json_encode( $v ) );
70
+ }
71
+ }
72
+ }
73
+ return parent::get_custom_attribute_html( $attribs );
74
+ }
75
+
76
+ public function generate_description_html( $key, $data ) {
77
+ $field_key = $this->get_field_key( $key );
78
+ $data = wp_parse_args(
79
+ $data,
80
+ array(
81
+ 'class' => '',
82
+ 'style' => '',
83
+ 'description' => '',
84
+ )
85
+ );
86
+ ob_start();
87
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-description.php';
88
+ return ob_get_clean();
89
+ }
90
+
91
+ public function generate_paragraph_html( $key, $data ) {
92
+ $field_key = $this->get_field_key( $key );
93
+ $defaults = array(
94
+ 'title' => '',
95
+ 'label' => '',
96
+ 'class' => '',
97
+ 'css' => '',
98
+ 'desc_tip' => false,
99
+ 'description' => '',
100
+ 'custom_attributes' => array(),
101
+ );
102
+ $data = wp_parse_args( $data, $defaults );
103
+ if ( ! $data['label'] ) {
104
+ $data['label'] = $data['title'];
105
+ }
106
+ ob_start();
107
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-paragraph.php';
108
+ return ob_get_clean();
109
+ }
110
+
111
+ public function generate_stripe_button_html( $key, $data ) {
112
+ $field_key = $this->get_field_key( $key );
113
+ $data = wp_parse_args(
114
+ $data,
115
+ array(
116
+ 'title' => '',
117
+ 'class' => '',
118
+ 'style' => '',
119
+ 'description' => '',
120
+ 'desc_tip' => false,
121
+ 'id' => 'wc-stripe-button_' . $key,
122
+ 'disabled' => false,
123
+ 'css' => '',
124
+ )
125
+ );
126
+ ob_start();
127
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-button.php';
128
+ return ob_get_clean();
129
+ }
130
+
131
+ public function generate_button_demo_html( $key, $data ) {
132
+ $field_key = $this->get_field_key( $key );
133
+ $data = wp_parse_args(
134
+ $data,
135
+ array(
136
+ 'title' => '',
137
+ 'class' => '',
138
+ 'style' => '',
139
+ 'description' => '',
140
+ 'desc_tip' => false,
141
+ 'id' => 'wc-stripe-button-demo',
142
+ )
143
+ );
144
+ ob_start();
145
+ include wc_stripe()->plugin_path() . 'includes/admin/views/html-button-demo.php';
146
+ return ob_get_clean();
147
+ }
148
+
149
+ /**
150
+ * Added override to provide more control on which fields are saved and which are skipped.
151
+ * This plugin
152
+ * has custom setting fields like "paragraph" that are for info display only and not for saving.
153
+ *
154
+ * {@inheritDoc}
155
+ *
156
+ * @see WC_Settings_API::process_admin_options()
157
+ */
158
+ public function process_admin_options() {
159
+ $this->init_settings();
160
+
161
+ $post_data = $this->get_post_data();
162
+
163
+ $skip_types = array( 'title', 'paragraph', 'button', 'description', 'button_demo', 'stripe_button' );
164
+
165
+ foreach ( $this->get_form_fields() as $key => $field ) {
166
+ $skip = isset( $field['skip'] ) && $field['skip'] == true;
167
+ if ( ! in_array( $this->get_field_type( $field ), $skip_types ) && ! $skip ) {
168
+ try {
169
+ $this->settings[ $key ] = $this->get_field_value( $key, $field, $post_data );
170
+ } catch ( Exception $e ) {
171
+ $this->add_error( $e->getMessage() );
172
+ }
173
+ }
174
+ }
175
+
176
+ return update_option( $this->get_option_key(), apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' );
177
+ }
178
+ }
includes/updates/update-3.0.7.php CHANGED
@@ -1,42 +1,38 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- use Stripe\Webhook;
5
- use Stripe\WebhookEndpoint;
6
- use Stripe\ApiOperations\Delete;
7
-
8
- /**
9
- * This update reconfigured the webhooks for each environment.
10
- */
11
- $environments = [ 'live', 'test'
12
- ];
13
- $api_settings = wc_stripe ()->api_settings;
14
- $url = wc_stripe ()->rest_api->webhook->rest_url ( 'webhook' );
15
-
16
- foreach ( $environments as $env ) {
17
- $gateway = new WC_Stripe_Gateway ();
18
- $webhooks = $gateway->webhooks ( $env );
19
-
20
- if (! is_wp_error ( $webhooks )) {
21
- // first delete the webhook if it matches the wp-json webhook. Then re-create it.
22
- foreach ( $webhooks->data as $webhook ) {
23
- /**
24
- *
25
- * @var Stripe\WebhookEndpoint $webhook
26
- */
27
- if ($webhook[ 'url' ] == $url) {
28
- $webhook->delete ();
29
- }
30
- }
31
- }
32
- // now that endpoint is deleted, re-create it and store details.
33
- $webhook = $gateway->create_webhook ( $url, [
34
- 'charge.failed', 'charge.succeeded',
35
- 'source.chargeable'
36
- ], $env );
37
- if (! is_wp_error ( $webhook )) {
38
- $api_settings->update_option ( "webhook_url_{$env}", $webhook[ 'url' ] );
39
- $api_settings->update_option ( "webhook_secret_{$env}", $webhook[ 'secret' ] );
40
- $api_settings->update_option ( "webhook_id_{$env}", $webhook[ 'id' ] );
41
- }
42
- }
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ use Stripe\Webhook;
5
+ use Stripe\WebhookEndpoint;
6
+ use Stripe\ApiOperations\Delete;
7
+
8
+ /**
9
+ * This update reconfigured the webhooks for each environment.
10
+ */
11
+ $environments = array( 'live', 'test' );
12
+ $api_settings = wc_stripe()->api_settings;
13
+ $url = wc_stripe()->rest_api->webhook->rest_url( 'webhook' );
14
+
15
+ foreach ( $environments as $env ) {
16
+ $gateway = new WC_Stripe_Gateway();
17
+ $webhooks = $gateway->webhooks( $env );
18
+
19
+ if ( ! is_wp_error( $webhooks ) ) {
20
+ // first delete the webhook if it matches the wp-json webhook. Then re-create it.
21
+ foreach ( $webhooks->data as $webhook ) {
22
+ /**
23
+ *
24
+ * @var Stripe\WebhookEndpoint $webhook
25
+ */
26
+ if ( $webhook['url'] == $url ) {
27
+ $webhook->delete();
28
+ }
29
+ }
30
+ }
31
+ // now that endpoint is deleted, re-create it and store details.
32
+ $webhook = $gateway->create_webhook( $url, array( 'charge.failed', 'charge.succeeded', 'source.chargeable' ), $env );
33
+ if ( ! is_wp_error( $webhook ) ) {
34
+ $api_settings->update_option( "webhook_url_{$env}", $webhook['url'] );
35
+ $api_settings->update_option( "webhook_secret_{$env}", $webhook['secret'] );
36
+ $api_settings->update_option( "webhook_id_{$env}", $webhook['id'] );
37
+ }
38
+ }
 
 
 
 
includes/updates/update-3.1.0.php CHANGED
@@ -1,60 +1,55 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- // update webhooks to include payment_intent.succeeded
5
- $environments = [ 'live', 'test'
6
- ];
7
-
8
- foreach ( $environments as $env ) {
9
- $webhook_id = wc_stripe ()->api_settings->get_option ( "webhook_id_{$env}" );
10
- if ($webhook_id) {
11
- $gateway = WC_Stripe_Gateway::load ( $env );
12
-
13
- // fetch webhook so we can merge existing events with the new payment_intent.succeeded event
14
- $webhook = $gateway->fetch_webhook ( $webhook_id );
15
- if (! is_wp_error ( $webhook )) {
16
- $events = $webhook[ 'enabled_events' ];
17
- $events[] = 'payment_intent.succeeded';
18
-
19
- $result = $gateway->update_webhook ( $webhook_id, [
20
- 'enabled_events' => $events
21
- ] );
22
- wc_stripe_log_info ( "Webhook {$webhook_id} updated." );
23
- }
24
- }
25
- }
26
-
27
- update_option ( 'wc_stripe_connect_notice', 'yes' );
28
-
29
- // send email
30
- ob_start ();
31
- WC_Emails::instance ()->email_header ( __ ( 'Stripe For WooCommerce Update', 'woo-stripe-payment' ) );
32
- ?>
33
- <p><?php _e('Greetings from Payment Plugins,', 'woo-stripe-payment')?></p>
34
- <p><?php _e('At Stripe\'s request, we have updated Stripe for WooCommerce to use the new Stripe Connect integration. This new integration offers even more security. Stripe is requesting that all merchants switch.', 'woo-stripe-payment')?></p>
35
- <p><?php printf(__('Click %shere%s to be redirected to your Stripe API settings page then click the <strong>Click to Connect</strong> button.', 'woo-stripe-payment'), '<a href="' . admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe_api') . '" target="_blank">', '</a>')?>
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
- <p><?php _e('Kind Regards,', 'woo-stripe-payment')?></p>
45
- <p><?php _e('Payment Plugins')?></p>
46
- <?php
47
- WC_Emails::instance ()->email_footer ();
48
- $content = ob_get_clean ();
49
- $settings = get_option ( 'woocommerce_new_order_settings', [
50
- 'recipient' => get_option ( 'admin_email', '' )
51
- ] );
52
- $email = new WC_Email ();
53
- $email->email_type = 'html';
54
- add_filter('woocommerce_email_from_address', function($from){
55
- return 'support@paymentplugins.com';
56
- });
57
- add_filter('woocommerce_email_from_name', function($name){
58
- return 'Payment Plugins';
59
- });
60
- $email->send ( $settings[ 'recipient' ], __ ( 'Stripe For WooCommerce Update', 'woo-stripe-payment' ), $content, $email->get_headers (), []);
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ // update webhooks to include payment_intent.succeeded
5
+ $environments = array( 'live', 'test' );
6
+
7
+ foreach ( $environments as $env ) {
8
+ $webhook_id = wc_stripe()->api_settings->get_option( "webhook_id_{$env}" );
9
+ if ( $webhook_id ) {
10
+ $gateway = WC_Stripe_Gateway::load( $env );
11
+
12
+ // fetch webhook so we can merge existing events with the new payment_intent.succeeded event
13
+ $webhook = $gateway->webhookEndpoints->retrieve( $webhook_id );
14
+ if ( ! is_wp_error( $webhook ) ) {
15
+ $events = $webhook['enabled_events'];
16
+ $events[] = 'payment_intent.succeeded';
17
+
18
+ $result = $gateway->webhookEndpoints->update( $webhook_id, array( 'enabled_events' => $events ) );
19
+ wc_stripe_log_info( "Webhook {$webhook_id} updated." );
20
+ }
21
+ }
22
+ }
23
+
24
+ update_option( 'wc_stripe_connect_notice', 'yes' );
25
+
26
+ // send email
27
+ ob_start();
28
+ WC_Emails::instance()->email_header( __( 'Stripe For WooCommerce Update', 'woo-stripe-payment' ) );
29
+ ?>
30
+ <p><?php _e( 'Greetings from Payment Plugins,', 'woo-stripe-payment' ); ?></p>
31
+ <p><?php _e( 'At Stripe\'s request, we have updated Stripe for WooCommerce to use the new Stripe Connect integration. This new integration offers even more security. Stripe is requesting that all merchants switch.', 'woo-stripe-payment' ); ?></p>
32
+ <p><?php printf( __( 'Click %1$shere%2$s to be redirected to your Stripe API settings page then click the <strong>Click to Connect</strong> button.', 'woo-stripe-payment' ), '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe_api' ) . '" target="_blank">', '</a>' ); ?>
33
+
34
+
35
+ <p><?php _e( 'Kind Regards,', 'woo-stripe-payment' ); ?></p>
36
+ <p><?php _e( 'Payment Plugins' ); ?></p>
37
+ <?php
38
+ WC_Emails::instance()->email_footer();
39
+ $content = ob_get_clean();
40
+ $settings = get_option( 'woocommerce_new_order_settings', array( 'recipient' => get_option( 'admin_email', '' ) ) );
41
+ $email = new WC_Email();
42
+ $email->email_type = 'html';
43
+ add_filter(
44
+ 'woocommerce_email_from_address',
45
+ function ( $from ) {
46
+ return 'support@paymentplugins.com';
47
+ }
48
+ );
49
+ add_filter(
50
+ 'woocommerce_email_from_name',
51
+ function ( $name ) {
52
+ return 'Payment Plugins';
53
+ }
54
+ );
55
+ $email->send( $settings['recipient'], __( 'Stripe For WooCommerce Update', 'woo-stripe-payment' ), $content, $email->get_headers(), array() );
 
 
 
 
 
includes/updates/update-3.1.1.php CHANGED
@@ -1,7 +1,7 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- global $wpdb;
5
-
6
- // delete transients that have incorrect timeouts
7
- $wpdb->query ( $wpdb->prepare ( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", '%_transient_timeout__stripe_lock_order_%', '%_transient__stripe_lock_order_%' ) );
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ global $wpdb;
5
+
6
+ // delete transients that have incorrect timeouts
7
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", '%_transient_timeout__stripe_lock_order_%', '%_transient__stripe_lock_order_%' ) );
includes/updates/update-3.1.6.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Schedule actions required by the plugin.
4
+ */
5
+ wc_stripe()->scheduled_actions();
includes/wc-stripe-functions.php CHANGED
@@ -1,1175 +1,1243 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- *
6
- * @since 3.0.0
7
- * @package Stripe/Functions
8
- * Wrapper for wc_get_template that returns Stripe specfic templates.
9
- * @param string $template_name
10
- * @param array $args
11
- */
12
- function wc_stripe_get_template($template_name, $args = array()) {
13
- wc_get_template ( $template_name, $args, wc_stripe ()->template_path (), wc_stripe ()->default_template_path () );
14
- }
15
-
16
- /**
17
- *
18
- *
19
- * Wrapper for wc_get_template_html that returns Stripe specififc templates in an html string.
20
- *
21
- * @package Stripe/Functions
22
- * @since 3.0.0
23
- * @param string $template_name
24
- * @param array $args
25
- * @return string
26
- */
27
- function wc_stripe_get_template_html($template_name, $args = array()) {
28
- return wc_get_template_html ( $template_name, $args, wc_stripe ()->template_path (), wc_stripe ()->default_template_path () );
29
- }
30
-
31
- /**
32
- * Return true if WCS is active.
33
- *
34
- * @package Stripe/Functions
35
- * @return boolean
36
- */
37
- function wcs_stripe_active() {
38
- return function_exists ( 'wcs_is_subscription' );
39
- }
40
-
41
- /**
42
- *
43
- * @package Stripe/Functions
44
- * @param WC_Payment_Gateway_Stripe $gateway
45
- */
46
- function wc_stripe_token_field($gateway) {
47
- wc_stripe_hidden_field ( $gateway->token_key, 'wc-stripe-token-field' );
48
- }
49
-
50
- /**
51
- *
52
- * @package Stripe/Functions
53
- * @param WC_Payment_Gateway_Stripe $gateway
54
- */
55
- function wc_stripe_payment_intent_field($gateway) {
56
- wc_stripe_hidden_field ( $gateway->payment_intent_key, 'wc-stripe-payment-intent-field' );
57
- }
58
-
59
- /**
60
- *
61
- * @package Stripe/Functions
62
- * @param string $id
63
- * @param string $class
64
- * @param string $value
65
- */
66
- function wc_stripe_hidden_field($id, $class = '', $value = '') {
67
- printf ( '<input type="hidden" class="%1$s" id="%2$s" name="%2$s" value="%3$s"/>', $class, $id, $value );
68
- }
69
-
70
- /**
71
- * Return the mode for the plugin.
72
- *
73
- * @package Stripe/Functions
74
- * @return string
75
- */
76
- function wc_stripe_mode() {
77
- return wc_stripe ()->api_settings->get_option ( 'mode' );
78
- }
79
-
80
- /**
81
- * Return the secret key for the provided mode.
82
- * If no mode given, the key for the active mode is returned.
83
- *
84
- * @package Stripe/Functions
85
- * @since 3.0.0
86
- * @param string $mode
87
- */
88
- function wc_stripe_get_secret_key($mode = '') {
89
- $mode = empty ( $mode ) ? wc_stripe_mode () : $mode;
90
- return wc_stripe ()->api_settings->get_option ( "secret_key_{$mode}" );
91
- }
92
-
93
- /**
94
- * Return the publishable key for the provided mode.
95
- * If no mode given, the key for the active mode is returned.
96
- *
97
- * @package Stripe/Functions
98
- * @since 3.0.0
99
- * @param string $mode
100
- */
101
- function wc_stripe_get_publishable_key($mode = '') {
102
- $mode = empty ( $mode ) ? wc_stripe_mode () : $mode;
103
- return wc_stripe ()->api_settings->get_option ( "publishable_key_{$mode}" );
104
- }
105
-
106
- /**
107
- * Return the merchant's Stripe account.
108
- *
109
- * @package Stripe/Functions
110
- * @since 3.1.4
111
- * @return string
112
- */
113
- function wc_stripe_get_account_id() {
114
- return wc_stripe ()->api_settings->get_option ( 'account_id' );
115
- }
116
-
117
- /**
118
- * Return the stripe customer ID
119
- *
120
- * @package Stripe/Functions
121
- * @since 3.0.0
122
- * @param int $user_id
123
- * @param string $mode
124
- */
125
- function wc_stripe_get_customer_id($user_id = '', $mode = '') {
126
- $mode = empty ( $mode ) ? wc_stripe_mode () : $mode;
127
- if ($user_id === 0) {
128
- return '';
129
- }
130
- if (empty ( $user_id )) {
131
- $user_id = get_current_user_id ();
132
- }
133
- return get_user_meta ( $user_id, "wc_stripe_customer_{$mode}", true );
134
- }
135
-
136
- /**
137
- *
138
- * @package Stripe/Functions
139
- * @param string $customer_id
140
- * @param int $user_id
141
- * @param string $mode
142
- */
143
- function wc_stripe_save_customer($customer_id, $user_id, $mode = '') {
144
- $mode = empty ( $mode ) ? wc_stripe_mode () : $mode;
145
- $key = "wc_stripe_customer_{$mode}";
146
- update_user_meta ( $user_id, $key, $customer_id );
147
- }
148
-
149
- /**
150
- *
151
- * @since 3.0.0
152
- * @package Stripe/Functions
153
- * @param int $token_id
154
- * @param WC_Payment_Token $token
155
- */
156
- function wc_stripe_woocommerce_payment_token_deleted($token_id, $token) {
157
- if (! did_action ( 'woocommerce_payment_gateways' )) {
158
- WC_Payment_Gateways::instance ();
159
- }
160
- do_action ( 'wc_stripe_payment_token_deleted_' . $token->get_gateway_id (), $token_id, $token );
161
- }
162
-
163
- /**
164
- * Log the provided message in the WC logs directory.
165
- *
166
- * @since 3.0.0
167
- * @package Stripe/Functions
168
- * @param int $level
169
- * @param string $message
170
- */
171
- function wc_stripe_log($level, $message) {
172
- if (wc_stripe ()->api_settings->is_active ( 'debug_log' )) {
173
- $log = wc_get_logger ();
174
- $log->log ( $level, $message, array(
175
- 'source' => 'wc-stripe'
176
- ) );
177
- }
178
- }
179
-
180
- /**
181
- *
182
- * @since 3.0.0
183
- * @package Stripe/Functions
184
- * @param string $message
185
- */
186
- function wc_stripe_log_error($message) {
187
- wc_stripe_log ( WC_Log_Levels::ERROR, $message );
188
- }
189
-
190
- /**
191
- *
192
- * @since 3.0.0
193
- * @package Stripe/Functions
194
- * @param string $message
195
- */
196
- function wc_stripe_log_info($message) {
197
- wc_stripe_log ( WC_Log_Levels::INFO, $message );
198
- }
199
-
200
- /**
201
- * Return the mode that the order was created in.
202
- * Values can be <strong>live</strong> or <strong>test</strong>
203
- *
204
- * @since 3.0.0
205
- * @package Stripe/Functions
206
- * @param WC_Order|int $order
207
- */
208
- function wc_stripe_order_mode($order) {
209
- if (is_object ( $order )) {
210
- return $order->get_meta ( WC_Stripe_Constants::MODE, true );
211
- }
212
- return get_post_meta ( $order, WC_Stripe_Constants::MODE, true );
213
- }
214
-
215
- /**
216
- *
217
- * @since 3.0.0
218
- * @package Stripe\Functions
219
- * @param array $gateways
220
- */
221
- function wc_stripe_payment_gateways($gateways) {
222
- return array_merge ( $gateways, wc_stripe ()->payment_gateways () );
223
- }
224
-
225
- /**
226
- * Cancel the Stripe charge
227
- *
228
- * @package Stripe/Functions
229
- * @param int $order_id
230
- * @param WC_Order $order
231
- */
232
- function wc_stripe_order_cancelled($order_id, $order) {
233
- $gateways = WC ()->payment_gateways ()->payment_gateways ();
234
- /**
235
- *
236
- * @var WC_Payment_Gateway_Stripe $gateway
237
- */
238
- $gateway = isset ( $gateways[ $order->get_payment_method () ] ) ? $gateways[ $order->get_payment_method () ] : null;
239
-
240
- if ($gateway && $gateway instanceof WC_Payment_Gateway_Stripe) {
241
- $gateway->void_charge ( $order );
242
- }
243
- }
244
-
245
- /**
246
- *
247
- * @since 3.0.0
248
- * @package Stripe/Functions
249
- * @param int $order_id
250
- * @param WC_Order $order
251
- */
252
- function wc_stripe_order_status_completed($order_id, $order) {
253
- $gateways = WC ()->payment_gateways ()->payment_gateways ();
254
- /**
255
- *
256
- * @var WC_Payment_Gateway_Stripe $gateway
257
- */
258
- $gateway = isset ( $gateways[ $order->get_payment_method () ] ) ? $gateways[ $order->get_payment_method () ] : null;
259
- // @since 3.0.3 check added to ensure this is a Stripe gateway.
260
- if ($gateway && $gateway instanceof WC_Payment_Gateway_Stripe && ! $gateway->processing_payment) {
261
- $gateway->capture_charge ( $order->get_total (), $order );
262
- }
263
- }
264
-
265
- /**
266
- *
267
- * @since 3.0.0
268
- * @package Stripe/Functions
269
- * @param [] $address
270
- * @throws Exception
271
- */
272
- function wc_stripe_update_customer_location($address) {
273
- // address validation for countries other than US is problematic when using responses from payment sources like Apple Pay.
274
- if ($address[ 'postcode' ] && $address[ 'country' ] === 'US' && ! WC_Validation::is_postcode ( $address[ 'postcode' ], $address[ 'country' ] )) {
275
- throw new Exception ( __ ( 'Please enter a valid postcode / ZIP.', 'woocommerce' ) );
276
- } elseif ($address[ 'postcode' ]) {
277
- $address[ 'postcode' ] = wc_format_postcode ( $address[ 'postcode' ], $address[ 'country' ] );
278
- }
279
-
280
- if ($address[ 'country' ]) {
281
- WC ()->customer->set_billing_location ( $address[ 'country' ], $address[ 'state' ], $address[ 'postcode' ], $address[ 'city' ] );
282
- WC ()->customer->set_shipping_location ( $address[ 'country' ], $address[ 'state' ], $address[ 'postcode' ], $address[ 'city' ] );
283
- // set the customer's address if it's in the $address array
284
- if (! empty ( $address[ 'address_1' ] )) {
285
- WC ()->customer->set_shipping_address_1 ( wc_clean ( $address[ 'address_1' ] ) );
286
- }
287
- if (! empty ( $address[ 'address_2' ] )) {
288
- WC ()->customer->set_shipping_address_2 ( wc_clean ( $address[ 'address_2' ] ) );
289
- }
290
- if (! empty ( $address[ 'first_name' ] )) {
291
- WC ()->customer->set_shipping_first_name ( $address[ 'first_name' ] );
292
- }
293
- if (! empty ( $address[ 'last_name' ] )) {
294
- WC ()->customer->set_shipping_last_name ( $address[ 'last_name' ] );
295
- }
296
- } else {
297
- WC ()->customer->set_billing_address_to_base ();
298
- WC ()->customer->set_shipping_address_to_base ();
299
- }
300
-
301
- WC ()->customer->set_calculated_shipping ( true );
302
- WC ()->customer->save ();
303
-
304
- do_action ( 'woocommerce_calculated_shipping' );
305
- }
306
-
307
- /**
308
- *
309
- * @since 3.0.0
310
- * @package Stripe/Functions
311
- * @param [] $methods
312
- */
313
- function wc_stripe_update_shipping_methods($methods) {
314
- $chosen_shipping_methods = WC ()->session->get ( 'chosen_shipping_methods', [] );
315
-
316
- foreach ( $methods as $i => $method ) {
317
- $chosen_shipping_methods[ $i ] = $method;
318
- }
319
-
320
- WC ()->session->set ( 'chosen_shipping_methods', $chosen_shipping_methods );
321
- }
322
-
323
- /**
324
- * Return true if there are shipping packages that contain rates.
325
- *
326
- * @since 3.0.0
327
- * @package Stripe/Functions
328
- * @return boolean
329
- */
330
- function wc_stripe_shipping_address_serviceable() {
331
- $packages = WC ()->shipping ()->get_packages ();
332
- if ($packages) {
333
- foreach ( $packages as $package ) {
334
- if (count ( $package[ 'rates' ] ) > 0) {
335
- return true;
336
- }
337
- }
338
- }
339
- return false;
340
- }
341
-
342
- /**
343
- *
344
- * @package Stripe/Functions
345
- * @param bool $encode
346
- * @param WC_Order $order
347
- * @since 3.0.0
348
- */
349
- function wc_stripe_get_display_items($encode = false, $order = null) {
350
- $items = [];
351
- if (! $order) {
352
- $cart = WC ()->cart;
353
- $incl_tax = wc_stripe_display_prices_including_tax ();
354
-
355
- foreach ( $cart->get_cart () as $cart_item ) {
356
- /**
357
- *
358
- * @var WC_Product $product
359
- */
360
- $product = $cart_item[ 'data' ];
361
- $qty = $cart_item[ 'quantity' ];
362
- $items[] = [
363
- 'label' => $qty > 1 ? sprintf ( '%s X %s', $product->get_name (), $qty ) : $product->get_name (),
364
- 'pending' => false,
365
- 'amount' => wc_stripe_add_number_precision ( $incl_tax ? wc_get_price_including_tax ( $product, [
366
- 'qty' => $qty
367
- ] ) : wc_get_price_excluding_tax ( $product, [
368
- 'qty' => $qty
369
- ] ) )
370
- ];
371
- }
372
- if ($cart->needs_shipping ()) {
373
- $items[] = [
374
- 'label' => __ ( 'Shipping', 'woo-stripe-payment' ),
375
- 'pending' => false,
376
- 'amount' => wc_stripe_add_number_precision ( $incl_tax ? $cart->shipping_total + $cart->shipping_tax_total : $cart->shipping_total )
377
- ];
378
- }
379
-
380
- // fees
381
- foreach ( $cart->get_fees () as $fee ) {
382
- $items[] = [ 'label' => $fee->name,
383
- 'pending' => false,
384
- 'amount' => wc_stripe_add_number_precision ( $incl_tax ? $fee->total + $fee->tax : $fee->total )
385
- ];
386
- }
387
- // coupons
388
- if ($cart->discount_cart != 0) {
389
- $items[] = [
390
- 'label' => __ ( 'Discount', 'woo-stripe-payment' ),
391
- 'pending' => false,
392
- 'amount' => wc_stripe_add_number_precision ( - 1 * abs ( $incl_tax ? $cart->discount_cart + $cart->discount_cart_tax : $cart->discount_cart ) )
393
- ];
394
- }
395
-
396
- if (! $incl_tax && wc_tax_enabled ()) {
397
- $items[] = [
398
- 'label' => __ ( 'Tax', 'woo-stripe-payment' ),
399
- 'pending' => false,
400
- 'amount' => wc_stripe_add_number_precision ( $cart->get_taxes_total () )
401
- ];
402
- }
403
- } else {
404
- $currency = $order->get_currency ();
405
- // add all order items
406
- foreach ( $order->get_items () as $item ) {
407
- /**
408
- *
409
- * @var WC_Order_Item_Product $item
410
- */
411
- $qty = $item->get_quantity ();
412
-
413
- $items[] = [
414
- 'label' => $qty > 1 ? sprintf ( '%s X %s', $item->get_name (), $qty ) : $item->get_name (),
415
- 'pending' => false,
416
- 'amount' => wc_stripe_add_number_precision ( $item->get_subtotal (), $currency )
417
- ];
418
- }
419
- // shipping total
420
- if ($order->get_shipping_total ()) {
421
- $items[] = [
422
- 'label' => __ ( 'Shipping', 'woo-stripe-payment' ),
423
- 'pending' => false,
424
- 'amount' => wc_stripe_add_number_precision ( $order->get_shipping_total (), $currency )
425
- ];
426
- }
427
- // discount total
428
- if ($order->get_total_discount ()) {
429
- $items[] = [
430
- 'label' => __ ( 'Discount', 'woo-stripe-payment' ),
431
- 'pending' => false,
432
- 'amount' => wc_stripe_add_number_precision ( $order->get_total_discount (), $currency )
433
- ];
434
- }
435
- if ($order->get_fees ()) {
436
- $fee_total = 0;
437
- foreach ( $order->get_fees () as $fee ) {
438
- $fee_total += $fee->get_total ();
439
- }
440
- $items[] = [
441
- 'label' => __ ( 'Fees', 'woo-stripe-payment' ),
442
- 'pending' => false,
443
- 'amount' => wc_stripe_add_number_precision ( $fee_total, $currency )
444
- ];
445
- }
446
- // tax total
447
- if ($order->get_total_tax ()) {
448
- $items[] = [
449
- 'label' => __ ( 'Tax', 'woocommerce' ),
450
- 'pending' => false,
451
- 'amount' => wc_stripe_add_number_precision ( $order->get_total_tax (), $currency )
452
- ];
453
- }
454
- }
455
- $items = apply_filters ( 'wc_stripe_get_display_items', $items, $order );
456
- return $encode ? htmlspecialchars ( wp_json_encode ( $items ) ) : $items;
457
- }
458
-
459
- /**
460
- *
461
- * @since 3.0.0
462
- * @package Stripe/Functions
463
- * @param bool $encode
464
- * @param WC_Order $order
465
- * @return mixed
466
- */
467
- function wc_stripe_get_shipping_options($encode = false, $order = null) {
468
- $methods = [];
469
- $incl_tax = wc_stripe_display_prices_including_tax ();
470
- if (! $order) {
471
- $ids = [];
472
- $chosen_shipping_methods = WC ()->session->get ( 'chosen_shipping_methods', [] );
473
- $packages = WC ()->shipping ()->get_packages ();
474
- foreach ( $packages as $i => $package ) {
475
- foreach ( $package[ 'rates' ] as $rate ) {
476
- /**
477
- *
478
- * @var WC_Shipping_Rate $rate
479
- */
480
- $method = [
481
- 'id' => sprintf ( '%s:%s', $i, $rate->id ),
482
- 'label' => sprintf ( '%s', esc_attr ( $rate->get_label () ) ),
483
- 'detail' => '',
484
- 'amount' => wc_stripe_add_number_precision ( $incl_tax ? $rate->cost + $rate->get_shipping_tax () : $rate->cost )
485
- ];
486
- if ($incl_tax) {
487
- if ($rate->get_shipping_tax () > 0 && ! wc_prices_include_tax ()) {
488
- $method[ 'detail' ] = WC ()->countries->inc_tax_or_vat ();
489
- }
490
- } else {
491
- if ($rate->get_shipping_tax () > 0 && wc_prices_include_tax ()) {
492
- $method[ 'detail' ] = WC ()->countries->ex_tax_or_vat ();
493
- }
494
- }
495
- $methods[] = $method;
496
- $ids[] = $rate->id;
497
- }
498
- // Stripe always shows the first shipping option as selected. Make sure the chosen method
499
- // is first in the array.
500
- if (isset ( $chosen_shipping_methods[ $i ] )) {
501
- $index = array_search ( $chosen_shipping_methods[ $i ], $ids );
502
- if ($index != 0) {
503
- $temp = $methods[ 0 ];
504
- $methods[ 0 ] = $methods[ $index ];
505
- $methods[ $index ] = $temp;
506
- }
507
- }
508
- }
509
- if (empty ( $methods )) {
510
- // GPay does not like empty shipping methods. Make a temporary one;
511
- $methods[] = [ 'id' => 'default',
512
- 'label' => __ ( 'Waiting...', 'woo-stripe-payment' ),
513
- 'detail' => __ ( 'loading shipping methods...', 'woo-stripe-payment' ),
514
- 'amount' => 0
515
- ];
516
- }
517
- }
518
- /**
519
- *
520
- * @param array $methods
521
- * @param WC_Order $orer
522
- */
523
- $methods = apply_filters ( 'wc_stripe_get_shipping_options', $methods, $order );
524
- return $encode ? htmlspecialchars ( wp_json_encode ( $methods ) ) : $methods;
525
- }
526
-
527
- /**
528
- *
529
- * @since 3.0.0
530
- * @package Stripe/Functions
531
- */
532
- function wc_stripe_set_checkout_error() {
533
- add_action ( 'woocommerce_after_template_part', 'wc_stripe_output_checkout_error' );
534
- }
535
-
536
- /**
537
- *
538
- * @since 3.0.0
539
- * @package Stripe/Functions
540
- * @param string $template_name
541
- */
542
- function wc_stripe_output_checkout_error($template_name) {
543
- if ($template_name === 'notices/error.php' && is_ajax ()) {
544
- echo '<input type="hidden" id="wc_stripe_checkout_error" value="true"/>';
545
- remove_action ( 'woocommerce_after_template_part', 'wc_stripe_output_checkout_error' );
546
- add_filter ( 'wp_kses_allowed_html', 'wc_stripe_add_allowed_html', 10, 2 );
547
- }
548
- }
549
-
550
- /**
551
- *
552
- * @since 3.0.0
553
- * @package Stripe/Functions
554
- */
555
- function wc_stripe_add_allowed_html($tags, $context) {
556
- if ($context === 'post') {
557
- $tags[ 'input' ] = array( 'id' => true,
558
- 'type' => true, 'value' => true
559
- );
560
- }
561
- return $tags;
562
- }
563
-
564
- /**
565
- * Save WCS meta data when it's changed in the admin section.
566
- * By default WCS saves the
567
- * payment method title as the gateway title. This method saves the payment method title in
568
- * a human readable format suitable for the frontend.
569
- *
570
- * @package Stripe/Functions
571
- * @param int $post_id
572
- * @param WP_Post $post
573
- */
574
- function wc_stripe_process_shop_subscription_meta($post_id, $post) {
575
- $subscription = wcs_get_subscription ( $post_id );
576
- $gateway_id = $subscription->get_payment_method ();
577
- $gateways = WC ()->payment_gateways ()->payment_gateways ();
578
- if (isset ( $gateways[ $gateway_id ] )) {
579
- $gateway = $gateways[ $gateway_id ];
580
- if ($gateway instanceof WC_Payment_Gateway_Stripe) {
581
- $token = $gateway->get_token ( $subscription->get_meta ( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN ), $subscription->get_customer_id () );
582
- if ($token) {
583
- $subscription->set_payment_method_title ( $token->get_payment_method_title () );
584
- $subscription->save ();
585
- }
586
- }
587
- }
588
- }
589
-
590
- /**
591
- * Filter the WC payment gateways based on criteria specific to Stripe functionality.
592
- *
593
- * <strong>Example:</strong> on add payment method page, only show the CC gateway for Stripe.
594
- *
595
- * @since 3.0.0
596
- * @package Stripe/Functions
597
- * @param WC_Payment_Gateway[] $gateways
598
- */
599
- function wc_stripe_available_payment_gateways($gateways) {
600
- global $wp;
601
- if (is_add_payment_method_page () && ! isset ( $wp->query_vars[ 'payment-methods' ] )) {
602
- foreach ( $gateways as $gateway ) {
603
- if ($gateway instanceof WC_Payment_Gateway_Stripe) {
604
- if ('stripe_cc' !== $gateway->id) {
605
- unset ( $gateways[ $gateway->id ] );
606
- }
607
- }
608
- }
609
- }
610
- return $gateways;
611
- }
612
-
613
- /**
614
- *
615
- * @since 3.0.0
616
- * @package Stripe/Functions
617
- * @return array
618
- */
619
- function wc_stripe_get_local_payment_params() {
620
- global $wp;
621
- $data = [];
622
- $gateways = WC ()->payment_gateways ()->payment_gateways ();
623
- foreach ( $gateways as $gateway ) {
624
- if ($gateway instanceof WC_Payment_Gateway_Stripe_Local_Payment && $gateway->is_available ()) {
625
- $data[ 'gateways' ][ $gateway->id ] = $gateway->get_localized_params ();
626
- if (isset ( $wp->query_vars[ 'order-pay' ] )) {
627
- $data[ 'gateways' ][ $gateway->id ][ 'order_id' ] = $wp->query_vars[ 'order-pay' ];
628
- }
629
- }
630
- }
631
- $data[ 'api_key' ] = wc_stripe_get_publishable_key ();
632
- return $data;
633
- }
634
-
635
- /**
636
- *
637
- * @package Stripe/Functions
638
- * @since 3.0.0
639
- * @param array $gateways
640
- * @return WC_Payment_Gateway[]
641
- */
642
- function wc_stripe_get_available_local_gateways($gateways) {
643
- foreach ( $gateways as $gateway ) {
644
- if ($gateway instanceof WC_Payment_Gateway_Stripe_Local_Payment) {
645
- if (! $gateway->is_local_payment_available ()) {
646
- unset ( $gateways[ $gateway->id ] );
647
- }
648
- }
649
- }
650
- return $gateways;
651
- }
652
-
653
- /**
654
- *
655
- * @since 3.0.0
656
- * @package Stripe/Functions
657
- * @param string|int $key
658
- */
659
- function wc_stripe_set_idempotency_key($key) {
660
- global $wc_stripe_idempotency_key;
661
- $wc_stripe_idempotency_key = $key;
662
- }
663
-
664
- /**
665
- *
666
- * @since 3.0.0
667
- * @package Stripe/Functions
668
- * @return mixed
669
- */
670
- function wc_stripe_get_idempotency_key() {
671
- global $wc_stripe_idempotency_key;
672
- return $wc_stripe_idempotency_key;
673
- }
674
-
675
- /**
676
- *
677
- * @since 3.0.0
678
- * @package Stripe/Functions
679
- * @param array $options
680
- * @return array
681
- */
682
- function wc_stripe_api_options($options) {
683
- $key = wc_stripe_get_idempotency_key ();
684
- if ($key) {
685
- $options[ 'idempotency_key' ] = $key;
686
- }
687
- return $options;
688
- }
689
-
690
- /**
691
- *
692
- * @since 3.0.0
693
- * @package Stripe/Functions
694
- * @param string $order_status
695
- * @param int $order_id
696
- * @param WC_Order $order
697
- */
698
- function wc_stripe_payment_complete_order_status($order_status, $order_id, $order) {
699
- if (is_checkout () && $order->get_payment_method ()) {
700
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $order->get_payment_method () ];
701
- if ($gateway instanceof WC_Payment_Gateway_Stripe && 'default' !== $gateway->get_option ( 'order_status' )) {
702
- $order_status = $gateway->get_option ( 'order_status' );
703
- }
704
- }
705
- return $order_status;
706
- }
707
-
708
- /**
709
- * Converts the amount to cents.
710
- * Stripe processes all requests in cents.
711
- *
712
- * @since 3.0.0
713
- * @package Stripe/Functions
714
- * @param float $value
715
- * @param string $round
716
- * @return number
717
- */
718
- function wc_stripe_add_number_precision($value, $currency = '', $round = true) {
719
- if (! is_numeric ( $value )) {
720
- $value = 0;
721
- }
722
- $currency = empty ( $currency ) ? get_woocommerce_currency () : $currency;
723
- $currencies = wc_stripe_get_currencies ();
724
- $exp = isset ( $currencies[ $currency ] ) ? $currencies[ $currency ] : 2;
725
- $cent_precision = pow ( 10, $exp );
726
- $value = $value * $cent_precision;
727
- $value = $round ? round ( $value, wc_get_rounding_precision () - wc_get_price_decimals () ) : $value;
728
-
729
- if (is_numeric ( $value ) && floor ( $value ) != $value) {
730
- // there are some decimal points that need to be removed.
731
- $value = round ( $value );
732
- }
733
- return $value;
734
- }
735
-
736
- /**
737
- * Return an array of credit card forms.
738
- *
739
- * @since 3.0.0
740
- * @package Stripe/Functions
741
- * @return mixed
742
- */
743
- function wc_stripe_get_custom_forms() {
744
- return apply_filters ( 'wc_stripe_get_custom_forms', [
745
- 'bootstrap' => [
746
- 'template' => 'cc-forms/bootstrap.php',
747
- 'label' => __ ( 'Bootstrap form', 'woo-stripe-payment' ),
748
- 'cardBrand' => wc_stripe ()->assets_url ( 'img/card_brand2.svg' ),
749
- 'elementStyles' => [
750
- 'base' => [
751
- 'color' => '#495057',
752
- 'fontWeight' => 300,
753
- 'fontFamily' => 'Roboto, sans-serif, Source Code Pro, Consolas, Menlo, monospace',
754
- 'fontSize' => '16px',
755
- 'fontSmoothing' => 'antialiased',
756
- '::placeholder' => [
757
- 'color' => '#fff',
758
- 'fontSize' => '0px'
759
- ],
760
- ':-webkit-autofill' => [
761
- 'color' => '#495057'
762
- ]
763
- ],
764
- 'invalid' => [
765
- 'color' => '#E25950',
766
- '::placeholder' => [
767
- 'color' => '#757575'
768
- ]
769
- ]
770
- ],
771
- 'elementOptions' => [
772
- 'fonts' => [
773
- [
774
- 'cssSrc' => 'https://fonts.googleapis.com/css?family=Source+Code+Pro'
775
- ]
776
- ]
777
- ]
778
- ],
779
- 'simple' => [
780
- 'template' => 'cc-forms/simple.php',
781
- 'label' => __ ( 'Simple form', 'woo-stripe-payment' ),
782
- 'cardBrand' => wc_stripe ()->assets_url ( 'img/card_brand2.svg' ),
783
- 'elementStyles' => [
784
- 'base' => [
785
- 'color' => '#32325D',
786
- 'fontWeight' => 500,
787
- 'fontFamily' => 'Source Code Pro, Consolas, Menlo, monospace',
788
- 'fontSize' => '16px',
789
- 'fontSmoothing' => 'antialiased',
790
- '::placeholder' => [
791
- 'color' => '#CFD7DF'
792
- ],
793
- ':-webkit-autofill' => [
794
- 'color' => '#32325D'
795
- ]
796
- ],
797
- 'invalid' => [
798
- 'color' => '#E25950',
799
- '::placeholder' => [
800
- 'color' => '#FFCCA5'
801
- ]
802
- ]
803
- ],
804
- 'elementOptions' => [
805
- 'fonts' => [
806
- [
807
- 'cssSrc' => 'https://fonts.googleapis.com/css?family=Source+Code+Pro'
808
- ]
809
- ]
810
- ]
811
- ],
812
- 'minimalist' => [
813
- 'template' => 'cc-forms/minimalist.php',
814
- 'label' => __ ( 'Minimalist form', 'woo-stripe-payment' ),
815
- 'cardBrand' => wc_stripe ()->assets_url ( 'img/card_brand2.svg' ),
816
- 'elementStyles' => [
817
- 'base' => [
818
- 'color' => '#495057',
819
- 'fontWeight' => 300,
820
- 'fontFamily' => 'Roboto, sans-serif, Source Code Pro, Consolas, Menlo, monospace',
821
- 'fontSize' => '30px',
822
- 'fontSmoothing' => 'antialiased',
823
- '::placeholder' => [
824
- 'color' => '#fff',
825
- 'fontSize' => '0px'
826
- ],
827
- ':-webkit-autofill' => [
828
- 'color' => '#495057'
829
- ]
830
- ],
831
- 'invalid' => [
832
- 'color' => '#495057',
833
- '::placeholder' => [
834
- 'color' => '#495057'
835
- ]
836
- ]
837
- ],
838
- 'elementOptions' => [
839
- 'fonts' => [
840
- [
841
- 'cssSrc' => 'https://fonts.googleapis.com/css?family=Source+Code+Pro'
842
- ]
843
- ]
844
- ]
845
- ],
846
- 'inline' => [
847
- 'template' => 'cc-forms/inline.php',
848
- 'label' => __ ( 'Inline Form', 'woo-stripe-payment' ),
849
- 'cardBrand' => wc_stripe ()->assets_url ( 'img/card_brand.svg' ),
850
- 'elementStyles' => [
851
- 'base' => [
852
- 'color' => '#819efc',
853
- 'fontWeight' => 600,
854
- 'fontFamily' => 'Roboto, Open Sans, Segoe UI, sans-serif',
855
- 'fontSize' => '16px',
856
- 'fontSmoothing' => 'antialiased',
857
- ':focus' => [
858
- 'color' => '#819efc'
859
- ],
860
- '::placeholder' => [
861
- 'color' => '#87BBFD'
862
- ],
863
- ':focus::placeholder' => [
864
- 'color' => '#CFD7DF'
865
- ],
866
- ':-webkit-autofill' => [
867
- 'color' => '#819efc'
868
- ]
869
- ],
870
- 'invalid' => [
871
- 'color' => '#f99393'
872
- ]
873
- ],
874
- 'elementOptions' => [
875
- 'fonts' => [
876
- [
877
- 'cssSrc' => 'https://fonts.googleapis.com/css?family=Roboto'
878
- ]
879
- ]
880
- ]
881
- ],
882
- 'rounded' => [
883
- 'template' => 'cc-forms/round.php',
884
- 'label' => __ ( 'Rounded Form', 'woo-stripe-payment' ),
885
- 'cardBrand' => wc_stripe ()->assets_url ( 'img/card_brand.svg' ),
886
- 'elementStyles' => [
887
- 'base' => [
888
- 'color' => '#fff',
889
- 'fontWeight' => 600,
890
- 'fontFamily' => 'Quicksand, Open Sans, Segoe UI, sans-serif',
891
- 'fontSize' => '16px',
892
- 'fontSmoothing' => 'antialiased',
893
- ':focus' => [
894
- 'color' => '#424770'
895
- ],
896
- '::placeholder' => [
897
- 'color' => '#9BACC8'
898
- ],
899
- ':focus::placeholder' => [
900
- 'color' => '#CFD7DF'
901
- ],
902
- ':-webkit-autofill' => [
903
- 'color' => '#fff'
904
- ]
905
- ],
906
- 'invalid' => [
907
- 'color' => '#fff',
908
- ':focus' => [
909
- 'color' => '#FA755A'
910
- ],
911
- '::placeholder' => [
912
- 'color' => '#FFCCA5'
913
- ]
914
- ]
915
- ],
916
- 'elementOptions' => [
917
- 'fonts' => [
918
- [
919
- 'cssSrc' => 'https://fonts.googleapis.com/css?family=Quicksand'
920
- ]
921
- ]
922
- ]
923
- ]
924
- ] );
925
- }
926
-
927
- /**
928
- *
929
- * @package Stripe/Functions
930
- * @since 3.0.0
931
- * @param WC_Order $order
932
- */
933
- function wc_stripe_order_has_shipping_address($order) {
934
- if (method_exists ( $order, 'has_shipping_address' )) {
935
- return $order->has_shipping_address ();
936
- } else {
937
- return $order->get_shipping_address_1 () || $order->get_shipping_address_2 ();
938
- }
939
- }
940
-
941
- /**
942
- *
943
- * @since 3.0.0
944
- * @package Stripe/Functions
945
- */
946
- function wc_stripe_display_prices_including_tax() {
947
- $cart = WC ()->cart;
948
- if (method_exists ( $cart, 'display_prices_including_tax' )) {
949
- return $cart->display_prices_including_tax ();
950
- }
951
- return 'incl' == $cart->tax_display_cart && ( WC ()->customer && ! WC ()->customer->is_vat_exempt () );
952
- }
953
-
954
- /**
955
- * Return true if the WC pre-orders plugin is active
956
- *
957
- * @since 3.0.1
958
- * @package Stripe/Functions
959
- */
960
- function wc_stripe_pre_orders_active() {
961
- return class_exists ( 'WC_Pre_Orders' );
962
- }
963
-
964
- /**
965
- *
966
- * @since 3.0.5
967
- * @param string $source_id
968
- */
969
- function wc_stripe_get_order_from_source_id($source_id) {
970
- global $wpdb;
971
- $order_id = $wpdb->get_var ( $wpdb->prepare ( "SELECT ID FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id WHERE meta.meta_key = %s AND meta.meta_value = %s LIMIT 1", '_stripe_source_id', $source_id ) );
972
- return wc_get_order ( $order_id );
973
- }
974
-
975
- /**
976
- *
977
- * @since 3.0.5
978
- * @param string $transaction_id
979
- * @return WC_Order|WC_Refund|boolean|WC_Order_Refund
980
- */
981
- function wc_stripe_get_order_from_transaction($transaction_id) {
982
- global $wpdb;
983
- $order_id = $wpdb->get_var ( $wpdb->prepare ( "SELECT ID FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id WHERE meta.meta_key = %s AND meta.meta_value = %s LIMIT 1", '_transaction_id', $transaction_id ) );
984
- return wc_get_order ( $order_id );
985
- }
986
-
987
- /**
988
- * Stash the WC cart contents in the session and empty it's contents.
989
- * If $product_cart is true, add the stashed product(s)
990
- * to the cart.
991
- *
992
- * @since 3.0.6
993
- * @todo Maybe empty cart silently so actions are not triggered that cause session data to be removed
994
- * from 3rd party plugins.
995
- *
996
- * @param WC_Cart $cart
997
- */
998
- function wc_stripe_stash_cart($cart, $product_cart = true) {
999
- $data = WC ()->session->get ( 'wc_stripe_cart', [] );
1000
- $data[ 'cart' ] = $cart->get_cart_for_session ();
1001
- WC ()->session->set ( 'wc_stripe_cart', $data );
1002
- $cart->empty_cart ( false );
1003
- if ($product_cart && isset ( $data[ 'product_cart' ] )) {
1004
- foreach ( $data[ 'product_cart' ] as $cart_item ) {
1005
- $cart->add_to_cart ( $cart_item[ 'product_id' ], $cart_item[ 'quantity' ], $cart_item[ 'variation_id' ] );
1006
- }
1007
- }
1008
- }
1009
-
1010
- /**
1011
- *
1012
- * @since 3.0.6
1013
- * @param number $product_id
1014
- * @param number $qty
1015
- * @param number $variation_id
1016
- */
1017
- function wc_stripe_stash_product_cart($cart) {
1018
- $data = WC ()->session->get ( 'wc_stripe_cart', [] );
1019
- $data[ 'product_cart' ] = $cart->get_cart_for_session ();
1020
- WC ()->session->set ( 'wc_stripe_cart', $data );
1021
- WC ()->cart->set_session ();
1022
- }
1023
-
1024
- /**
1025
- *
1026
- * @since 3.0.6
1027
- * @param WC_Cart $cart
1028
- */
1029
- function wc_stripe_restore_cart($cart) {
1030
- $data = WC ()->session->get ( 'wc_stripe_cart', [
1031
- 'cart' => []
1032
- ] );
1033
- $cart->cart_contents = $data[ 'cart' ];
1034
- $cart->set_session ();
1035
- }
1036
-
1037
- /**
1038
- *
1039
- * @since 3.0.6
1040
- */
1041
- function wc_stripe_restore_cart_after_product_checkout() {
1042
- wc_stripe_restore_cart ( WC ()->cart );
1043
- $cart_contents = [];
1044
- foreach ( WC ()->cart->get_cart () as $key => $cart_item ) {
1045
- $cart_item[ 'data' ] = wc_get_product ( $cart_item[ 'variation_id' ] ? $cart_item[ 'variation_id' ] : $cart_item[ 'product_id' ] );
1046
- $cart_contents[ $key ] = $cart_item;
1047
- }
1048
- WC ()->cart->cart_contents = $cart_contents;
1049
- WC ()->cart->calculate_totals ();
1050
- }
1051
-
1052
- /**
1053
- *
1054
- * @since 3.1.0
1055
- * @param WC_Payment_Token[] $tokens
1056
- * @param int $user_id
1057
- * @param string $gateway_id
1058
- * @return WC_Payment_Token[]
1059
- */
1060
- function wc_stripe_get_customer_payment_tokens($tokens, $user_id, $gateway_id) {
1061
- foreach ( $tokens as $idx => $token ) {
1062
- if ($token instanceof WC_Payment_Token_Stripe) {
1063
- $mode = wc_stripe_mode ();
1064
- if ($token->get_environment () != $mode) {
1065
- unset ( $tokens[ $idx ] );
1066
- }
1067
- }
1068
- }
1069
- return $tokens;
1070
- }
1071
-
1072
- /**
1073
- *
1074
- * @since 3.1.0
1075
- * @param array $labels
1076
- * @return string
1077
- */
1078
- function wc_stripe_credit_card_labels($labels) {
1079
- if (! isset ( $labels[ 'amex' ] )) {
1080
- $labels[ 'amex' ] = __ ( 'Amex', 'woocommerce' );
1081
- }
1082
- return $labels;
1083
- }
1084
-
1085
- /**
1086
- * Return an array of Stripe error messages.
1087
- *
1088
- * @since 3.1.1
1089
- */
1090
- function wc_stripe_get_error_messages() {
1091
- return apply_filters ( 'wc_stripe_get_error_messages', [
1092
- 'stripe_cc_generic' => __ ( 'There was an error processing your credit card.', 'woo-stripe-payment' ),
1093
- 'incomplete_number' => __ ( 'Your card number is incomplete.', 'woo-stripe-payment' ),
1094
- 'incorrect_number' => __ ( 'The card number is incorrect. Check the card\'s number or use a different card.', 'woo-stripe-payment' ),
1095
- 'incorrect_cvc' => __ ( 'The card\'s security code is incorrect. Check the card\'s security code or use a different card.', 'woo-stripe-payment' ),
1096
- 'incorrect_zip' => __ ( 'The card\'s ZIP code is incorrect. Check the card\'s ZIP code or use a different card.', 'woo-stripe-payment' ),
1097
- 'invalid_number' => __ ( 'The card number is invalid. Check the card details or use a different card.', 'woo-stripe-payment' ),
1098
- 'invalid_characters' => __ ( 'This value provided to the field contains characters that are unsupported by the field.', 'woo-stripe-payment' ),
1099
- 'invalid_cvc' => __ ( 'The card\'s security code is invalid. Check the card\'s security code or use a different card.', 'woo-stripe-payment' ),
1100
- 'invalid_expiry_month' => __ ( 'The card\'s expiration month is incorrect. Check the expiration date or use a different card.', 'woo-stripe-payment' ),
1101
- 'invalid_expiry_year' => __ ( 'The card\'s expiration year is incorrect. Check the expiration date or use a different card.', 'woo-stripe-payment' ),
1102
- 'invalid_number' => __ ( 'The card number is invalid. Check the card details or use a different card.', 'woo-stripe-payment' ),
1103
- 'incorrect_address' => __ ( 'The card\'s address is incorrect. Check the card\'s address or use a different card.', 'woo-stripe-payment' ),
1104
- 'expired_card' => __ ( 'The card has expired. Check the expiration date or use a different card.', 'woo-stripe-payment' ),
1105
- 'card_declined' => __ ( 'The card has been declined.', 'woo-stripe-payment' ),
1106
- 'invalid_expiry_year_past' => __ ( 'Your card\'s expiration year is in the past.', 'woo-stripe-payment' ),
1107
- 'account_number_invalid' => __ ( 'The bank account number provided is invalid (e.g., missing digits). Bank account information varies from country to country. We recommend creating validations in your entry forms based on the bank account formats we provide.', 'woo-stripe-payment' ),
1108
- 'amount_too_large' => __ ( 'The specified amount is greater than the maximum amount allowed. Use a lower amount and try again.', 'woo-stripe-payment' ),
1109
- 'amount_too_small' => __ ( 'The specified amount is less than the minimum amount allowed. Use a higher amount and try again.', 'woo-stripe-payment' ),
1110
- 'authentication_required' => __ ( 'The payment requires authentication to proceed. If your customer is off session, notify your customer to return to your application and complete the payment. If you provided the error_on_requires_action parameter, then your customer should try another card that does not require authentication.', 'woo-stripe-payment' ),
1111
- 'balance_insufficient' => __ ( 'The transfer or payout could not be completed because the associated account does not have a sufficient balance available. Create a new transfer or payout using an amount less than or equal to the account\'s available balance.', 'woo-stripe-payment' ),
1112
- 'bank_account_declined' => __ ( 'The bank account provided can not be used to charge, either because it is not verified yet or it is not supported.', 'woo-stripe-payment' ),
1113
- 'bank_account_exists' => __ ( 'The bank account provided already exists on the specified Customer object. If the bank account should also be attached to a different customer, include the correct customer ID when making the request again.', 'woo-stripe-payment' ),
1114
- 'bank_account_unusable' => __ ( 'The bank account provided cannot be used for payouts. A different bank account must be used.', 'woo-stripe-payment' ),
1115
- 'bank_account_unverified' => __ ( 'Your Connect platform is attempting to share an unverified bank account with a connected account.', 'woo-stripe-payment' ),
1116
- 'bank_account_verification_failed' => __ ( 'The bank account cannot be verified, either because the microdeposit amounts provided do not match the actual amounts, or because verification has failed too many times.', 'woo-stripe-payment' ),
1117
- 'card_decline_rate_limit_exceeded' => __ ( 'This card has been declined too many times. You can try to charge this card again after 24 hours. We suggest reaching out to your customer to make sure they have entered all of their information correctly and that there are no issues with their card.', 'woo-stripe-payment' ),
1118
- 'charge_already_captured' => __ ( 'The charge you\'re attempting to capture has already been captured. Update the request with an uncaptured charge ID.', 'woo-stripe-payment' ),
1119
- 'charge_already_refunded' => __ ( 'The charge you\'re attempting to refund has already been refunded. Update the request to use the ID of a charge that has not been refunded.', 'woo-stripe-payment' ),
1120
- 'charge_disputed' => __ ( 'The charge you\'re attempting to refund has been charged back. Check the disputes documentation to learn how to respond to the dispute.', 'woo-stripe-payment' ),
1121
- 'charge_exceeds_source_limit' => __ ( 'This charge would cause you to exceed your rolling-window processing limit for this source type. Please retry the charge later, or contact us to request a higher processing limit.', 'woo-stripe-payment' ),
1122
- 'charge_expired_for_capture' => __ ( 'The charge cannot be captured as the authorization has expired. Auth and capture charges must be captured within seven days.', 'woo-stripe-payment' ),
1123
- 'charge_invalid_parameter' => __ ( 'One or more provided parameters was not allowed for the given operation on the Charge. Check our API reference or the returned error message to see which values were not correct for that Charge.', 'woo-stripe-payment' ),
1124
- 'email_invalid' => __ ( 'The email address is invalid (e.g., not properly formatted). Check that the email address is properly formatted and only includes allowed characters.', 'woo-stripe-payment' ),
1125
- 'idempotency_key_in_use' => __ ( 'The idempotency key provided is currently being used in another request. This occurs if your integration is making duplicate requests simultaneously.', 'woo-stripe-payment' ),
1126
- 'invalid_charge_amount' => __ ( 'The specified amount is invalid. The charge amount must be a positive integer in the smallest currency unit, and not exceed the minimum or maximum amount.', 'woo-stripe-payment' ),
1127
- 'invalid_source_usage' => __ ( 'The source cannot be used because it is not in the correct state (e.g., a charge request is trying to use a source with a pending, failed, or consumed source). Check the status of the source you are attempting to use.', 'woo-stripe-payment' ),
1128
- 'missing' => __ ( 'Both a customer and source ID have been provided, but the source has not been saved to the customer. To create a charge for a customer with a specified source, you must first save the card details.', 'woo-stripe-payment' ),
1129
- 'postal_code_invalid' => __ ( 'The ZIP code provided was incorrect.', 'woo-stripe-payment' ),
1130
- 'processing_error' => __ ( 'An error occurred while processing the card. Try again later or with a different payment method.', 'woo-stripe-payment' ),
1131
- 'card_not_supported' => __ ( 'The card does not support this type of purchase.', 'woo-stripe-payment' ),
1132
- 'call_issuer' => __ ( 'The card has been declined for an unknown reason.', 'woo-stripe-payment' ),
1133
- 'card_velocity_exceeded' => __ ( 'The customer has exceeded the balance or credit limit available on their card.', 'woo-stripe-payment' ),
1134
- 'currency_not_supported' => __ ( 'The card does not support the specified currency.', 'woo-stripe-payment' ),
1135
- 'do_not_honor' => __ ( 'The card has been declined for an unknown reason.', 'woo-stripe-payment' ),
1136
- 'fraudulent' => __ ( 'The payment has been declined as Stripe suspects it is fraudulent.', 'woo-stripe-payment' ),
1137
- 'generic_decline' => __ ( 'The card has been declined for an unknown reason.', 'woo-stripe-payment' ),
1138
- 'incorrect_pin' => __ ( 'The PIN entered is incorrect. ', 'woo-stripe-payment' ),
1139
- 'insufficient_funds' => __ ( 'The card has insufficient funds to complete the purchase.', 'woo-stripe-payment' ),
1140
- 'empty_element' => __ ( 'Please select a payment method before proceeding.', 'woo-stripe-payment' ),
1141
- 'empty_element_sepa_debit' => __ ( 'Please enter your IBAN before proceeding.', 'woo-stripe-payment' ),
1142
- 'empty_element_ideal' => __ ( 'Please select a bank before proceeding', 'woo-stripe-payment' )
1143
- ] );
1144
- }
1145
-
1146
- /**
1147
- * Return an array of Stripe currencies where the value of each
1148
- * currency is the curency multiplier.
1149
- *
1150
- * @since 3.1.2
1151
- * @package Stripe/Functions
1152
- * @return mixed
1153
- */
1154
- function wc_stripe_get_currencies() {
1155
- return apply_filters ( 'wc_stripe_get_currencies', [
1156
- 'BIF' => 0, 'CLP' => 0, 'DJF' => 0, 'GNF' => 0,
1157
- 'JPY' => 0, 'KMF' => 0, 'KRW' => 0, 'MGA' => 0,
1158
- 'PYG' => 0, 'RWF' => 0, 'UGX' => 0, 'VND' => 0,
1159
- 'VUV' => 0, 'XAF' => 0, 'XOF' => 0, 'XPF' => 0
1160
- ] );
1161
- }
1162
-
1163
- /**
1164
- * Function that triggers a filter on the order id.
1165
- * Allows 3rd parties to
1166
- * convert the order_id from the metadata of the Stripe object.
1167
- *
1168
- * @since 3.1.3
1169
- * @package Stripe/Functions
1170
- * @param int $order_id
1171
- * @param \Stripe\ApiResource $object
1172
- */
1173
- function wc_stripe_filter_order_id($order_id, $object) {
1174
- return apply_filters ( 'wc_stripe_filter_order_id', $order_id, $object );
1175
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ *
6
+ * @param string $template_name
7
+ * @param array $args
8
+ *
9
+ * @since 3.0.0
10
+ * @package Stripe/Functions
11
+ * Wrapper for wc_get_template that returns Stripe specfic templates.
12
+ */
13
+ function wc_stripe_get_template( $template_name, $args = array() ) {
14
+ wc_get_template( $template_name, $args, wc_stripe()->template_path(), wc_stripe()->default_template_path() );
15
+ }
16
+
17
+ /**
18
+ *
19
+ *
20
+ * Wrapper for wc_get_template_html that returns Stripe specififc templates in an html string.
21
+ *
22
+ * @param string $template_name
23
+ * @param array $args
24
+ *
25
+ * @return string
26
+ * @since 3.0.0
27
+ * @package Stripe/Functions
28
+ */
29
+ function wc_stripe_get_template_html( $template_name, $args = array() ) {
30
+ return wc_get_template_html( $template_name, $args, wc_stripe()->template_path(), wc_stripe()->default_template_path() );
31
+ }
32
+
33
+ /**
34
+ * Return true if WCS is active.
35
+ *
36
+ * @return boolean
37
+ * @package Stripe/Functions
38
+ */
39
+ function wcs_stripe_active() {
40
+ return function_exists( 'wcs_is_subscription' );
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @param WC_Payment_Gateway_Stripe $gateway
46
+ *
47
+ * @package Stripe/Functions
48
+ */
49
+ function wc_stripe_token_field( $gateway ) {
50
+ wc_stripe_hidden_field( $gateway->token_key, 'wc-stripe-token-field' );
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @param WC_Payment_Gateway_Stripe $gateway
56
+ *
57
+ * @package Stripe/Functions
58
+ */
59
+ function wc_stripe_payment_intent_field( $gateway ) {
60
+ wc_stripe_hidden_field( $gateway->payment_intent_key, 'wc-stripe-payment-intent-field' );
61
+ }
62
+
63
+ /**
64
+ *
65
+ * @param string $id
66
+ * @param string $class
67
+ * @param string $value
68
+ *
69
+ * @package Stripe/Functions
70
+ */
71
+ function wc_stripe_hidden_field( $id, $class = '', $value = '' ) {
72
+ printf( '<input type="hidden" class="%1$s" id="%2$s" name="%2$s" value="%3$s"/>', $class, $id, $value );
73
+ }
74
+
75
+ /**
76
+ * Return the mode for the plugin.
77
+ *
78
+ * @return string
79
+ * @package Stripe/Functions
80
+ */
81
+ function wc_stripe_mode() {
82
+ return apply_filters( 'wc_stripe_mode', wc_stripe()->api_settings->get_option( 'mode' ) );
83
+ }
84
+
85
+ /**
86
+ * Return the secret key for the provided mode.
87
+ * If no mode given, the key for the active mode is returned.
88
+ *
89
+ * @param string $mode
90
+ *
91
+ * @since 3.0.0
92
+ * @package Stripe/Functions
93
+ */
94
+ function wc_stripe_get_secret_key( $mode = '' ) {
95
+ $mode = empty( $mode ) ? wc_stripe_mode() : $mode;
96
+
97
+ return apply_filters( 'wc_stripe_get_secret_key', wc_stripe()->api_settings->get_option( "secret_key_{$mode}" ), $mode );
98
+ }
99
+
100
+ /**
101
+ * Return the publishable key for the provided mode.
102
+ * If no mode given, the key for the active mode is returned.
103
+ *
104
+ * @param string $mode
105
+ *
106
+ * @since 3.0.0
107
+ * @package Stripe/Functions
108
+ */
109
+ function wc_stripe_get_publishable_key( $mode = '' ) {
110
+ $mode = empty( $mode ) ? wc_stripe_mode() : $mode;
111
+
112
+ return apply_filters( 'wc_stripe_get_publishable_key', wc_stripe()->api_settings->get_option( "publishable_key_{$mode}" ), $mode );
113
+ }
114
+
115
+ /**
116
+ * Return the merchant's Stripe account.
117
+ *
118
+ * @return string
119
+ * @since 3.1.4
120
+ * @package Stripe/Functions
121
+ */
122
+ function wc_stripe_get_account_id() {
123
+ return apply_filters( 'wc_stripe_get_account_id', wc_stripe()->api_settings->get_option( 'account_id' ) );
124
+ }
125
+
126
+ /**
127
+ * Return the stripe customer ID
128
+ *
129
+ * @param int $user_id
130
+ * @param string $mode
131
+ *
132
+ * @package Stripe/Functions
133
+ * @since 3.0.0
134
+ */
135
+ function wc_stripe_get_customer_id( $user_id = '', $mode = '' ) {
136
+ $mode = empty( $mode ) ? wc_stripe_mode() : $mode;
137
+ if ( $user_id === 0 ) {
138
+ return '';
139
+ }
140
+ if ( empty( $user_id ) ) {
141
+ $user_id = get_current_user_id();
142
+ }
143
+
144
+ return get_user_meta( $user_id, "wc_stripe_customer_{$mode}", true );
145
+ }
146
+
147
+ /**
148
+ *
149
+ * @param string $customer_id
150
+ * @param int $user_id
151
+ * @param string $mode
152
+ *
153
+ * @package Stripe/Functions
154
+ */
155
+ function wc_stripe_save_customer( $customer_id, $user_id, $mode = '' ) {
156
+ $mode = empty( $mode ) ? wc_stripe_mode() : $mode;
157
+ $key = "wc_stripe_customer_{$mode}";
158
+ update_user_meta( $user_id, $key, $customer_id );
159
+ }
160
+
161
+ /**
162
+ *
163
+ * @param int $token_id
164
+ * @param WC_Payment_Token $token
165
+ *
166
+ * @since 3.0.0
167
+ * @package Stripe/Functions
168
+ */
169
+ function wc_stripe_woocommerce_payment_token_deleted( $token_id, $token ) {
170
+ if ( ! did_action( 'woocommerce_payment_gateways' ) ) {
171
+ WC_Payment_Gateways::instance();
172
+ }
173
+ do_action( 'wc_stripe_payment_token_deleted_' . $token->get_gateway_id(), $token_id, $token );
174
+ }
175
+
176
+ /**
177
+ * Log the provided message in the WC logs directory.
178
+ *
179
+ * @param int $level
180
+ * @param string $message
181
+ *
182
+ * @since 3.0.0
183
+ * @package Stripe/Functions
184
+ */
185
+ function wc_stripe_log( $level, $message ) {
186
+ if ( wc_stripe()->api_settings->is_active( 'debug_log' ) ) {
187
+ $log = wc_get_logger();
188
+ $log->log( $level, $message, array( 'source' => 'wc-stripe' ) );
189
+ }
190
+ }
191
+
192
+ /**
193
+ *
194
+ * @param string $message
195
+ *
196
+ * @package Stripe/Functions
197
+ * @since 3.0.0
198
+ */
199
+ function wc_stripe_log_error( $message ) {
200
+ wc_stripe_log( WC_Log_Levels::ERROR, $message );
201
+ }
202
+
203
+ /**
204
+ *
205
+ * @param string $message
206
+ *
207
+ * @package Stripe/Functions
208
+ * @since 3.0.0
209
+ */
210
+ function wc_stripe_log_info( $message ) {
211
+ wc_stripe_log( WC_Log_Levels::INFO, $message );
212
+ }
213
+
214
+ /**
215
+ * Return the mode that the order was created in.
216
+ * Values can be <strong>live</strong> or <strong>test</strong>
217
+ *
218
+ * @param WC_Order|int $order
219
+ *
220
+ * @package Stripe/Functions
221
+ * @since 3.0.0
222
+ */
223
+ function wc_stripe_order_mode( $order ) {
224
+ if ( is_object( $order ) ) {
225
+ return $order->get_meta( WC_Stripe_Constants::MODE, true );
226
+ }
227
+
228
+ return get_post_meta( $order, WC_Stripe_Constants::MODE, true );
229
+ }
230
+
231
+ /**
232
+ *
233
+ * @param array $gateways
234
+ *
235
+ * @package Stripe\Functions
236
+ * @since 3.0.0
237
+ */
238
+ function wc_stripe_payment_gateways( $gateways ) {
239
+ return array_merge( $gateways, wc_stripe()->payment_gateways() );
240
+ }
241
+
242
+ /**
243
+ * Cancel the Stripe charge
244
+ *
245
+ * @param int $order_id
246
+ * @param WC_Order $order
247
+ *
248
+ * @package Stripe/Functions
249
+ */
250
+ function wc_stripe_order_cancelled( $order_id, $order ) {
251
+ $gateways = WC()->payment_gateways()->payment_gateways();
252
+ /**
253
+ *
254
+ * @var WC_Payment_Gateway_Stripe $gateway
255
+ */
256
+ $gateway = isset( $gateways[ $order->get_payment_method() ] ) ? $gateways[ $order->get_payment_method() ] : null;
257
+
258
+ if ( $gateway && $gateway instanceof WC_Payment_Gateway_Stripe ) {
259
+ $gateway->void_charge( $order );
260
+ }
261
+ }
262
+
263
+ /**
264
+ *
265
+ * @param int $order_id
266
+ * @param WC_Order $order
267
+ *
268
+ * @since 3.0.0
269
+ * @package Stripe/Functions
270
+ */
271
+ function wc_stripe_order_status_completed( $order_id, $order ) {
272
+ $gateways = WC()->payment_gateways()->payment_gateways();
273
+ /**
274
+ *
275
+ * @var WC_Payment_Gateway_Stripe $gateway
276
+ */
277
+ $gateway = isset( $gateways[ $order->get_payment_method() ] ) ? $gateways[ $order->get_payment_method() ] : null;
278
+ // @since 3.0.3 check added to ensure this is a Stripe gateway.
279
+ if ( $gateway && $gateway instanceof WC_Payment_Gateway_Stripe && ! $gateway->processing_payment ) {
280
+ $gateway->capture_charge( $order->get_total(), $order );
281
+ }
282
+ }
283
+
284
+ /**
285
+ *
286
+ * @param [] $address
287
+ *
288
+ * @throws Exception
289
+ * @since 3.0.0
290
+ * @package Stripe/Functions
291
+ */
292
+ function wc_stripe_update_customer_location( $address ) {
293
+ // address validation for countries other than US is problematic when using responses from payment sources like
294
+ // Apple Pay.
295
+ if ( $address['postcode'] && $address['country'] === 'US' && ! WC_Validation::is_postcode( $address['postcode'], $address['country'] ) ) {
296
+ throw new Exception( __( 'Please enter a valid postcode / ZIP.', 'woocommerce' ) );
297
+ } elseif ( $address['postcode'] ) {
298
+ $address['postcode'] = wc_format_postcode( $address['postcode'], $address['country'] );
299
+ }
300
+
301
+ if ( $address['country'] ) {
302
+ WC()->customer->set_billing_location( $address['country'], $address['state'], $address['postcode'], $address['city'] );
303
+ WC()->customer->set_shipping_location( $address['country'], $address['state'], $address['postcode'], $address['city'] );
304
+ // set the customer's address if it's in the $address array
305
+ if ( ! empty( $address['address_1'] ) ) {
306
+ WC()->customer->set_shipping_address_1( wc_clean( $address['address_1'] ) );
307
+ }
308
+ if ( ! empty( $address['address_2'] ) ) {
309
+ WC()->customer->set_shipping_address_2( wc_clean( $address['address_2'] ) );
310
+ }
311
+ if ( ! empty( $address['first_name'] ) ) {
312
+ WC()->customer->set_shipping_first_name( $address['first_name'] );
313
+ }
314
+ if ( ! empty( $address['last_name'] ) ) {
315
+ WC()->customer->set_shipping_last_name( $address['last_name'] );
316
+ }
317
+ } else {
318
+ WC()->customer->set_billing_address_to_base();
319
+ WC()->customer->set_shipping_address_to_base();
320
+ }
321
+
322
+ WC()->customer->set_calculated_shipping( true );
323
+ WC()->customer->save();
324
+
325
+ do_action( 'woocommerce_calculated_shipping' );
326
+ }
327
+
328
+ /**
329
+ *
330
+ * @param [] $methods
331
+ *
332
+ * @package Stripe/Functions
333
+ * @since 3.0.0
334
+ */
335
+ function wc_stripe_update_shipping_methods( $methods ) {
336
+ $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods', array() );
337
+
338
+ foreach ( $methods as $i => $method ) {
339
+ $chosen_shipping_methods[ $i ] = $method;
340
+ }
341
+
342
+ WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
343
+ }
344
+
345
+ /**
346
+ * Return true if there are shipping packages that contain rates.
347
+ *
348
+ * @return boolean
349
+ * @package Stripe/Functions
350
+ * @since 3.0.0
351
+ */
352
+ function wc_stripe_shipping_address_serviceable() {
353
+ $packages = WC()->shipping()->get_packages();
354
+ if ( $packages ) {
355
+ foreach ( $packages as $package ) {
356
+ if ( count( $package['rates'] ) > 0 ) {
357
+ return true;
358
+ }
359
+ }
360
+ }
361
+
362
+ return false;
363
+ }
364
+
365
+ /**
366
+ *
367
+ * @param bool $encode
368
+ * @param WC_Order $order
369
+ *
370
+ * @package Stripe/Functions
371
+ * @since 3.0.0
372
+ */
373
+ function wc_stripe_get_display_items( $encode = false, $order = null ) {
374
+ $items = array();
375
+ if ( ! $order ) {
376
+ $cart = WC()->cart;
377
+ $incl_tax = wc_stripe_display_prices_including_tax();
378
+
379
+ foreach ( $cart->get_cart() as $cart_item ) {
380
+ /**
381
+ *
382
+ * @var WC_Product $product
383
+ */
384
+ $product = $cart_item['data'];
385
+ $qty = $cart_item['quantity'];
386
+ $items[] = array(
387
+ 'label' => $qty > 1 ? sprintf( '%s X %s', $product->get_name(), $qty ) : $product->get_name(),
388
+ 'pending' => false,
389
+ 'amount' => wc_stripe_add_number_precision(
390
+ $incl_tax ? wc_get_price_including_tax( $product, array( 'qty' => $qty ) ) : wc_get_price_excluding_tax(
391
+ $product,
392
+ array(
393
+ 'qty' => $qty,
394
+ )
395
+ )
396
+ ),
397
+ );
398
+ }
399
+ if ( $cart->needs_shipping() ) {
400
+ $items[] = array(
401
+ 'label' => __( 'Shipping', 'woo-stripe-payment' ),
402
+ 'pending' => false,
403
+ 'amount' => wc_stripe_add_number_precision( $incl_tax ? $cart->shipping_total + $cart->shipping_tax_total : $cart->shipping_total ),
404
+ );
405
+ }
406
+
407
+ // fees
408
+ foreach ( $cart->get_fees() as $fee ) {
409
+ $items[] = array(
410
+ 'label' => $fee->name,
411
+ 'pending' => false,
412
+ 'amount' => wc_stripe_add_number_precision( $incl_tax ? $fee->total + $fee->tax : $fee->total ),
413
+ );
414
+ }
415
+ // coupons
416
+ if ( $cart->discount_cart != 0 ) {
417
+ $items[] = array(
418
+ 'label' => __( 'Discount', 'woo-stripe-payment' ),
419
+ 'pending' => false,
420
+ 'amount' => wc_stripe_add_number_precision( - 1 * abs( $incl_tax ? $cart->discount_cart + $cart->discount_cart_tax : $cart->discount_cart ) ),
421
+ );
422
+ }
423
+
424
+ if ( ! $incl_tax && wc_tax_enabled() ) {
425
+ $item = array(
426
+ 'label' => __( 'Tax', 'woo-stripe-payment' ),
427
+ 'pending' => false,
428
+ 'amount' => wc_stripe_add_number_precision( $cart->get_taxes_total() ),
429
+ );
430
+ if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) {
431
+ if ( 0 < WC()->cart->get_taxes_total() ) {
432
+ $items[] = $item;
433
+ }
434
+ } else {
435
+ $items[] = $item;
436
+ }
437
+ }
438
+ } else {
439
+ $currency = $order->get_currency();
440
+ // add all order items
441
+ foreach ( $order->get_items() as $item ) {
442
+ /**
443
+ *
444
+ * @var WC_Order_Item_Product $item
445
+ */
446
+ $qty = $item->get_quantity();
447
+
448
+ $items[] = array(
449
+ 'label' => $qty > 1 ? sprintf( '%s X %s', $item->get_name(), $qty ) : $item->get_name(),
450
+ 'pending' => false,
451
+ 'amount' => wc_stripe_add_number_precision( $item->get_subtotal(), $currency ),
452
+ );
453
+ }
454
+ // shipping total
455
+ if ( $order->get_shipping_total() ) {
456
+ $items[] = array(
457
+ 'label' => __( 'Shipping', 'woo-stripe-payment' ),
458
+ 'pending' => false,
459
+ 'amount' => wc_stripe_add_number_precision( $order->get_shipping_total(), $currency ),
460
+ );
461
+ }
462
+ // discount total
463
+ if ( $order->get_total_discount() ) {
464
+ $items[] = array(
465
+ 'label' => __( 'Discount', 'woo-stripe-payment' ),
466
+ 'pending' => false,
467
+ 'amount' => wc_stripe_add_number_precision( $order->get_total_discount(), $currency ),
468
+ );
469
+ }
470
+ if ( $order->get_fees() ) {
471
+ $fee_total = 0;
472
+ foreach ( $order->get_fees() as $fee ) {
473
+ $fee_total += $fee->get_total();
474
+ }
475
+ $items[] = array(
476
+ 'label' => __( 'Fees', 'woo-stripe-payment' ),
477
+ 'pending' => false,
478
+ 'amount' => wc_stripe_add_number_precision( $fee_total, $currency ),
479
+ );
480
+ }
481
+ // tax total
482
+ if ( $order->get_total_tax() ) {
483
+ $items[] = array(
484
+ 'label' => __( 'Tax', 'woocommerce' ),
485
+ 'pending' => false,
486
+ 'amount' => wc_stripe_add_number_precision( $order->get_total_tax(), $currency ),
487
+ );
488
+ }
489
+ }
490
+ $items = apply_filters( 'wc_stripe_get_display_items', $items, $order );
491
+
492
+ return $encode ? htmlspecialchars( wp_json_encode( $items ) ) : $items;
493
+ }
494
+
495
+ /**
496
+ *
497
+ * @param bool $encode
498
+ * @param WC_Order $order
499
+ *
500
+ * @return mixed
501
+ * @package Stripe/Functions
502
+ * @since 3.0.0
503
+ */
504
+ function wc_stripe_get_shipping_options( $encode = false, $order = null ) {
505
+ $methods = array();
506
+ $incl_tax = wc_stripe_display_prices_including_tax();
507
+ if ( ! $order ) {
508
+ $ids = array();
509
+ $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods', array() );
510
+ $packages = WC()->shipping()->get_packages();
511
+ foreach ( $packages as $i => $package ) {
512
+ foreach ( $package['rates'] as $rate ) {
513
+ /**
514
+ *
515
+ * @var WC_Shipping_Rate $rate
516
+ */
517
+ $method = array(
518
+ 'id' => sprintf( '%s:%s', $i, $rate->id ),
519
+ 'label' => sprintf( '%s', esc_attr( $rate->get_label() ) ),
520
+ 'detail' => '',
521
+ 'amount' => wc_stripe_add_number_precision( $incl_tax ? $rate->cost + $rate->get_shipping_tax() : $rate->cost ),
522
+ );
523
+ if ( $incl_tax ) {
524
+ if ( $rate->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) {
525
+ $method['detail'] = WC()->countries->inc_tax_or_vat();
526
+ }
527
+ } else {
528
+ if ( $rate->get_shipping_tax() > 0 && wc_prices_include_tax() ) {
529
+ $method['detail'] = WC()->countries->ex_tax_or_vat();
530
+ }
531
+ }
532
+ $methods[] = $method;
533
+ $ids[] = $rate->id;
534
+ }
535
+ // Stripe always shows the first shipping option as selected. Make sure the chosen method
536
+ // is first in the array.
537
+ if ( isset( $chosen_shipping_methods[ $i ] ) ) {
538
+ $index = array_search( $chosen_shipping_methods[ $i ], $ids );
539
+ if ( $index != 0 ) {
540
+ $temp = $methods[0];
541
+ $methods[0] = $methods[ $index ];
542
+ $methods[ $index ] = $temp;
543
+ }
544
+ }
545
+ }
546
+ /*
547
+ * if (empty ( $methods )) {
548
+ * // GPay does not like empty shipping methods. Make a temporary one;
549
+ * $methods[] = [ 'id' => 'default',
550
+ * 'label' => __ ( 'Waiting...', 'woo-stripe-payment' ),
551
+ * 'detail' => __ ( 'loading shipping methods...', 'woo-stripe-payment' ),
552
+ * 'amount' => 0
553
+ * ];
554
+ * }
555
+ */
556
+ }
557
+ /**
558
+ *
559
+ * @param array $methods
560
+ * @param WC_Order $orer
561
+ */
562
+ $methods = apply_filters( 'wc_stripe_get_shipping_options', $methods, $order );
563
+
564
+ return $encode ? htmlspecialchars( wp_json_encode( $methods ) ) : $methods;
565
+ }
566
+
567
+ /**
568
+ *
569
+ * @since 3.0.0
570
+ * @package Stripe/Functions
571
+ */
572
+ function wc_stripe_set_checkout_error() {
573
+ add_action( 'woocommerce_after_template_part', 'wc_stripe_output_checkout_error' );
574
+ }
575
+
576
+ /**
577
+ *
578
+ * @param string $template_name
579
+ *
580
+ * @package Stripe/Functions
581
+ * @since 3.0.0
582
+ */
583
+ function wc_stripe_output_checkout_error( $template_name ) {
584
+ if ( $template_name === 'notices/error.php' && is_ajax() ) {
585
+ echo '<input type="hidden" id="wc_stripe_checkout_error" value="true"/>';
586
+ remove_action( 'woocommerce_after_template_part', 'wc_stripe_output_checkout_error' );
587
+ add_filter( 'wp_kses_allowed_html', 'wc_stripe_add_allowed_html', 10, 2 );
588
+ }
589
+ }
590
+
591
+ /**
592
+ *
593
+ * @since 3.0.0
594
+ * @package Stripe/Functions
595
+ */
596
+ function wc_stripe_add_allowed_html( $tags, $context ) {
597
+ if ( $context === 'post' ) {
598
+ $tags['input'] = array(
599
+ 'id' => true,
600
+ 'type' => true,
601
+ 'value' => true,
602
+ );
603
+ }
604
+
605
+ return $tags;
606
+ }
607
+
608
+ /**
609
+ * Save WCS meta data when it's changed in the admin section.
610
+ * By default WCS saves the
611
+ * payment method title as the gateway title. This method saves the payment method title in
612
+ * a human readable format suitable for the frontend.
613
+ *
614
+ * @param int $post_id
615
+ * @param WP_Post $post
616
+ *
617
+ * @package Stripe/Functions
618
+ */
619
+ function wc_stripe_process_shop_subscription_meta( $post_id, $post ) {
620
+ $subscription = wcs_get_subscription( $post_id );
621
+ $gateway_id = $subscription->get_payment_method();
622
+ $gateways = WC()->payment_gateways()->payment_gateways();
623
+ if ( isset( $gateways[ $gateway_id ] ) ) {
624
+ $gateway = $gateways[ $gateway_id ];
625
+ if ( $gateway instanceof WC_Payment_Gateway_Stripe ) {
626
+ $token = $gateway->get_token( $subscription->get_meta( WC_Stripe_Constants::PAYMENT_METHOD_TOKEN ), $subscription->get_customer_id() );
627
+ if ( $token ) {
628
+ $subscription->set_payment_method_title( $token->get_payment_method_title() );
629
+ $subscription->save();
630
+ }
631
+ }
632
+ }
633
+ }
634
+
635
+ /**
636
+ * Filter the WC payment gateways based on criteria specific to Stripe functionality.
637
+ *
638
+ * <strong>Example:</strong> on add payment method page, only show the CC gateway for Stripe.
639
+ *
640
+ * @param WC_Payment_Gateway[] $gateways
641
+ *
642
+ * @package Stripe/Functions
643
+ * @since 3.0.0
644
+ */
645
+ function wc_stripe_available_payment_gateways( $gateways ) {
646
+ global $wp;
647
+ if ( is_add_payment_method_page() && ! isset( $wp->query_vars['payment-methods'] ) ) {
648
+ foreach ( $gateways as $gateway ) {
649
+ if ( $gateway instanceof WC_Payment_Gateway_Stripe ) {
650
+ if ( 'stripe_cc' !== $gateway->id ) {
651
+ unset( $gateways[ $gateway->id ] );
652
+ }
653
+ }
654
+ }
655
+ }
656
+
657
+ return $gateways;
658
+ }
659
+
660
+ /**
661
+ *
662
+ * @return array
663
+ * @package Stripe/Functions
664
+ * @since 3.0.0
665
+ */
666
+ function wc_stripe_get_local_payment_params() {
667
+ global $wp;
668
+ $data = array();
669
+ $gateways = WC()->payment_gateways()->payment_gateways();
670
+ foreach ( $gateways as $gateway ) {
671
+ if ( $gateway instanceof WC_Payment_Gateway_Stripe_Local_Payment && $gateway->is_available() ) {
672
+ $data['gateways'][ $gateway->id ] = $gateway->get_localized_params();
673
+ if ( isset( $wp->query_vars['order-pay'] ) ) {
674
+ $data['gateways'][ $gateway->id ]['order_id'] = $wp->query_vars['order-pay'];
675
+ }
676
+ }
677
+ }
678
+ $data['api_key'] = wc_stripe_get_publishable_key();
679
+
680
+ return $data;
681
+ }
682
+
683
+ /**
684
+ *
685
+ * @param array $gateways
686
+ *
687
+ * @return WC_Payment_Gateway[]
688
+ * @package Stripe/Functions
689
+ * @since 3.0.0
690
+ */
691
+ function wc_stripe_get_available_local_gateways( $gateways ) {
692
+ foreach ( $gateways as $gateway ) {
693
+ if ( $gateway instanceof WC_Payment_Gateway_Stripe_Local_Payment ) {
694
+ if ( ! $gateway->is_local_payment_available() ) {
695
+ unset( $gateways[ $gateway->id ] );
696
+ }
697
+ }
698
+ }
699
+
700
+ return $gateways;
701
+ }
702
+
703
+ /**
704
+ *
705
+ * @param string|int $key
706
+ *
707
+ * @package Stripe/Functions
708
+ * @since 3.0.0
709
+ */
710
+ function wc_stripe_set_idempotency_key( $key ) {
711
+ global $wc_stripe_idempotency_key;
712
+ $wc_stripe_idempotency_key = $key;
713
+ }
714
+
715
+ /**
716
+ *
717
+ * @return mixed
718
+ * @package Stripe/Functions
719
+ * @since 3.0.0
720
+ */
721
+ function wc_stripe_get_idempotency_key() {
722
+ global $wc_stripe_idempotency_key;
723
+
724
+ return $wc_stripe_idempotency_key;
725
+ }
726
+
727
+ /**
728
+ *
729
+ * @param array $options
730
+ *
731
+ * @return array
732
+ * @since 3.0.0
733
+ * @package Stripe/Functions
734
+ */
735
+ function wc_stripe_api_options( $options ) {
736
+ $key = wc_stripe_get_idempotency_key();
737
+ if ( $key ) {
738
+ $options['idempotency_key'] = $key;
739
+ }
740
+
741
+ return $options;
742
+ }
743
+
744
+ /**
745
+ *
746
+ * @param string $order_status
747
+ * @param int $order_id
748
+ * @param WC_Order $order
749
+ *
750
+ * @package Stripe/Functions
751
+ * @since 3.0.0
752
+ */
753
+ function wc_stripe_payment_complete_order_status( $order_status, $order_id, $order ) {
754
+ if ( is_checkout() && $order->get_payment_method() ) {
755
+ $gateway = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
756
+ if ( $gateway instanceof WC_Payment_Gateway_Stripe && 'default' !== $gateway->get_option( 'order_status' ) ) {
757
+ $order_status = $gateway->get_option( 'order_status' );
758
+ }
759
+ }
760
+
761
+ return $order_status;
762
+ }
763
+
764
+ /**
765
+ * Converts the amount to cents.
766
+ * Stripe processes all requests in cents.
767
+ *
768
+ * @param float $value
769
+ * @param string $currency
770
+ * @param string $round
771
+ *
772
+ * @return number
773
+ * @package Stripe/Functions
774
+ * @since 3.0.0
775
+ */
776
+ function wc_stripe_add_number_precision( $value, $currency = '', $round = true ) {
777
+ if ( ! is_numeric( $value ) ) {
778
+ $value = 0;
779
+ }
780
+ $currency = empty( $currency ) ? get_woocommerce_currency() : $currency;
781
+ $currencies = wc_stripe_get_currencies();
782
+ $exp = isset( $currencies[ $currency ] ) ? $currencies[ $currency ] : 2;
783
+ $cent_precision = pow( 10, $exp );
784
+ $value = $value * $cent_precision;
785
+ $value = $round ? round( $value, wc_get_rounding_precision() - wc_get_price_decimals() ) : $value;
786
+
787
+ if ( is_numeric( $value ) && floor( $value ) != $value ) {
788
+ // there are some decimal points that need to be removed.
789
+ $value = round( $value );
790
+ }
791
+
792
+ return $value;
793
+ }
794
+
795
+ /**
796
+ * Return an array of credit card forms.
797
+ *
798
+ * @return mixed
799
+ * @package Stripe/Functions
800
+ * @since 3.0.0
801
+ */
802
+ function wc_stripe_get_custom_forms() {
803
+ return apply_filters(
804
+ 'wc_stripe_get_custom_forms',
805
+ array(
806
+ 'bootstrap' => array(
807
+ 'template' => 'cc-forms/bootstrap.php',
808
+ 'label' => __( 'Bootstrap form', 'woo-stripe-payment' ),
809
+ 'cardBrand' => wc_stripe()->assets_url( 'img/card_brand2.svg' ),
810
+ 'elementStyles' => array(
811
+ 'base' => array(
812
+ 'color' => '#495057',
813
+ 'fontWeight' => 300,
814
+ 'fontFamily' => 'Roboto, sans-serif, Source Code Pro, Consolas, Menlo, monospace',
815
+ 'fontSize' => '16px',
816
+ 'fontSmoothing' => 'antialiased',
817
+ '::placeholder' => array(
818
+ 'color' => '#fff',
819
+ 'fontSize' => '0px',
820
+ ),
821
+ ':-webkit-autofill' => array( 'color' => '#495057' ),
822
+ ),
823
+ 'invalid' => array(
824
+ 'color' => '#E25950',
825
+ '::placeholder' => array( 'color' => '#757575' ),
826
+ ),
827
+ ),
828
+ 'elementOptions' => array(
829
+ 'fonts' => array( array( 'cssSrc' => 'https://fonts.googleapis.com/css?family=Source+Code+Pro' ) ),
830
+ ),
831
+ ),
832
+ 'simple' => array(
833
+ 'template' => 'cc-forms/simple.php',
834
+ 'label' => __( 'Simple form', 'woo-stripe-payment' ),
835
+ 'cardBrand' => wc_stripe()->assets_url( 'img/card_brand2.svg' ),
836
+ 'elementStyles' => array(
837
+ 'base' => array(
838
+ 'color' => '#32325D',
839
+ 'fontWeight' => 500,
840
+ 'fontFamily' => 'Source Code Pro, Consolas, Menlo, monospace',
841
+ 'fontSize' => '16px',
842
+ 'fontSmoothing' => 'antialiased',
843
+ '::placeholder' => array( 'color' => '#CFD7DF' ),
844
+ ':-webkit-autofill' => array( 'color' => '#32325D' ),
845
+ ),
846
+ 'invalid' => array(
847
+ 'color' => '#E25950',
848
+ '::placeholder' => array( 'color' => '#FFCCA5' ),
849
+ ),
850
+ ),
851
+ 'elementOptions' => array(
852
+ 'fonts' => array( array( 'cssSrc' => 'https://fonts.googleapis.com/css?family=Source+Code+Pro' ) ),
853
+ ),
854
+ ),
855
+ 'minimalist' => array(
856
+ 'template' => 'cc-forms/minimalist.php',
857
+ 'label' => __( 'Minimalist form', 'woo-stripe-payment' ),
858
+ 'cardBrand' => wc_stripe()->assets_url( 'img/card_brand2.svg' ),
859
+ 'elementStyles' => array(
860
+ 'base' => array(
861
+ 'color' => '#495057',
862
+ 'fontWeight' => 300,
863
+ 'fontFamily' => 'Roboto, sans-serif, Source Code Pro, Consolas, Menlo, monospace',
864
+ 'fontSize' => '30px',
865
+ 'fontSmoothing' => 'antialiased',
866
+ '::placeholder' => array(
867
+ 'color' => '#fff',
868
+ 'fontSize' => '0px',
869
+ ),
870
+ ':-webkit-autofill' => array( 'color' => '#495057' ),
871
+ ),
872
+ 'invalid' => array(
873
+ 'color' => '#495057',
874
+ '::placeholder' => array( 'color' => '#495057' ),
875
+ ),
876
+ ),
877
+ 'elementOptions' => array(
878
+ 'fonts' => array( array( 'cssSrc' => 'https://fonts.googleapis.com/css?family=Source+Code+Pro' ) ),
879
+ ),
880
+ ),
881
+ 'inline' => array(
882
+ 'template' => 'cc-forms/inline.php',
883
+ 'label' => __( 'Inline Form', 'woo-stripe-payment' ),
884
+ 'cardBrand' => wc_stripe()->assets_url( 'img/card_brand.svg' ),
885
+ 'elementStyles' => array(
886
+ 'base' => array(
887
+ 'color' => '#819efc',
888
+ 'fontWeight' => 600,
889
+ 'fontFamily' => 'Roboto, Open Sans, Segoe UI, sans-serif',
890
+ 'fontSize' => '16px',
891
+ 'fontSmoothing' => 'antialiased',
892
+ ':focus' => array( 'color' => '#819efc' ),
893
+ '::placeholder' => array( 'color' => '#87BBFD' ),
894
+ ':focus::placeholder' => array( 'color' => '#CFD7DF' ),
895
+ ':-webkit-autofill' => array( 'color' => '#819efc' ),
896
+ ),
897
+ 'invalid' => array( 'color' => '#f99393' ),
898
+ ),
899
+ 'elementOptions' => array(
900
+ 'fonts' => array( array( 'cssSrc' => 'https://fonts.googleapis.com/css?family=Roboto' ) ),
901
+ ),
902
+ ),
903
+ 'rounded' => array(
904
+ 'template' => 'cc-forms/round.php',
905
+ 'label' => __( 'Rounded Form', 'woo-stripe-payment' ),
906
+ 'cardBrand' => wc_stripe()->assets_url( 'img/card_brand.svg' ),
907
+ 'elementStyles' => array(
908
+ 'base' => array(
909
+ 'color' => '#fff',
910
+ 'fontWeight' => 600,
911
+ 'fontFamily' => 'Quicksand, Open Sans, Segoe UI, sans-serif',
912
+ 'fontSize' => '16px',
913
+ 'fontSmoothing' => 'antialiased',
914
+ ':focus' => array( 'color' => '#424770' ),
915
+ '::placeholder' => array( 'color' => '#9BACC8' ),
916
+ ':focus::placeholder' => array( 'color' => '#CFD7DF' ),
917
+ ':-webkit-autofill' => array( 'color' => '#fff' ),
918
+ ),
919
+ 'invalid' => array(
920
+ 'color' => '#fff',
921
+ ':focus' => array( 'color' => '#FA755A' ),
922
+ '::placeholder' => array( 'color' => '#FFCCA5' ),
923
+ ),
924
+ ),
925
+ 'elementOptions' => array(
926
+ 'fonts' => array( array( 'cssSrc' => 'https://fonts.googleapis.com/css?family=Quicksand' ) ),
927
+ ),
928
+ ),
929
+ )
930
+ );
931
+ }
932
+
933
+ /**
934
+ *
935
+ * @param WC_Order $order
936
+ *
937
+ * @since 3.0.0
938
+ * @package Stripe/Functions
939
+ */
940
+ function wc_stripe_order_has_shipping_address( $order ) {
941
+ if ( method_exists( $order, 'has_shipping_address' ) ) {
942
+ return $order->has_shipping_address();
943
+ } else {
944
+ return $order->get_shipping_address_1() || $order->get_shipping_address_2();
945
+ }
946
+ }
947
+
948
+ /**
949
+ *
950
+ * @since 3.0.0
951
+ * @package Stripe/Functions
952
+ */
953
+ function wc_stripe_display_prices_including_tax() {
954
+ $cart = WC()->cart;
955
+ if ( method_exists( $cart, 'display_prices_including_tax' ) ) {
956
+ return $cart->display_prices_including_tax();
957
+ }
958
+
959
+ return 'incl' == $cart->tax_display_cart && ( WC()->customer && ! WC()->customer->is_vat_exempt() );
960
+ }
961
+
962
+ /**
963
+ * Return true if the WC pre-orders plugin is active
964
+ *
965
+ * @since 3.0.1
966
+ * @package Stripe/Functions
967
+ */
968
+ function wc_stripe_pre_orders_active() {
969
+ return class_exists( 'WC_Pre_Orders' );
970
+ }
971
+
972
+ /**
973
+ *
974
+ * @param string $source_id
975
+ *
976
+ * @package Stripe/Functions
977
+ * @since 3.0.5
978
+ */
979
+ function wc_stripe_get_order_from_source_id( $source_id ) {
980
+ global $wpdb;
981
+ $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id WHERE meta.meta_key = %s AND meta.meta_value = %s LIMIT 1", '_stripe_source_id', $source_id ) );
982
+
983
+ return wc_get_order( $order_id );
984
+ }
985
+
986
+ /**
987
+ *
988
+ * @param string $transaction_id
989
+ *
990
+ * @return WC_Order|WC_Refund|boolean|WC_Order_Refund
991
+ * @since 3.0.5
992
+ * @package Stripe/Functions
993
+ */
994
+ function wc_stripe_get_order_from_transaction( $transaction_id ) {
995
+ global $wpdb;
996
+ $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id WHERE meta.meta_key = %s AND meta.meta_value = %s LIMIT 1", '_transaction_id', $transaction_id ) );
997
+
998
+ return wc_get_order( $order_id );
999
+ }
1000
+
1001
+ /**
1002
+ * Stash the WC cart contents in the session and empty it's contents.
1003
+ * If $product_cart is true, add the stashed product(s)
1004
+ * to the cart.
1005
+ *
1006
+ * @param WC_Cart $cart
1007
+ *
1008
+ * @package Stripe/Functions
1009
+ * @todo Maybe empty cart silently so actions are not triggered that cause session data to be removed
1010
+ * from 3rd party plugins.
1011
+ *
1012
+ * @since 3.0.6
1013
+ */
1014
+ function wc_stripe_stash_cart( $cart, $product_cart = true ) {
1015
+ $data = WC()->session->get( 'wc_stripe_cart', array() );
1016
+ $data['cart'] = $cart->get_cart_for_session();
1017
+ WC()->session->set( 'wc_stripe_cart', $data );
1018
+ $cart->empty_cart( false );
1019
+ if ( $product_cart && isset( $data['product_cart'] ) ) {
1020
+ foreach ( $data['product_cart'] as $cart_item ) {
1021
+ $cart->add_to_cart( $cart_item['product_id'], $cart_item['quantity'], $cart_item['variation_id'] );
1022
+ }
1023
+ }
1024
+ }
1025
+
1026
+ /**
1027
+ *
1028
+ * @param number $product_id
1029
+ * @param number $qty
1030
+ * @param number $variation_id
1031
+ *
1032
+ * @package Stripe/Functions
1033
+ * @since 3.0.6
1034
+ */
1035
+ function wc_stripe_stash_product_cart( $cart ) {
1036
+ $data = WC()->session->get( 'wc_stripe_cart', array() );
1037
+ $data['product_cart'] = $cart->get_cart_for_session();
1038
+ WC()->session->set( 'wc_stripe_cart', $data );
1039
+ WC()->cart->set_session();
1040
+ }
1041
+
1042
+ /**
1043
+ *
1044
+ * @param WC_Cart $cart
1045
+ *
1046
+ * @package Stripe/Functions
1047
+ * @since 3.0.6
1048
+ */
1049
+ function wc_stripe_restore_cart( $cart ) {
1050
+ $data = WC()->session->get( 'wc_stripe_cart', array( 'cart' => array() ) );
1051
+ $cart->cart_contents = $data['cart'];
1052
+ $cart->set_session();
1053
+ }
1054
+
1055
+ /**
1056
+ *
1057
+ * @since 3.0.6
1058
+ * @package Stripe/Functions
1059
+ */
1060
+ function wc_stripe_restore_cart_after_product_checkout() {
1061
+ wc_stripe_restore_cart( WC()->cart );
1062
+ $cart_contents = array();
1063
+ foreach ( WC()->cart->get_cart() as $key => $cart_item ) {
1064
+ $cart_item['data'] = wc_get_product( $cart_item['variation_id'] ? $cart_item['variation_id'] : $cart_item['product_id'] );
1065
+ $cart_contents[ $key ] = $cart_item;
1066
+ }
1067
+ WC()->cart->cart_contents = $cart_contents;
1068
+ WC()->cart->calculate_totals();
1069
+ }
1070
+
1071
+ /**
1072
+ *
1073
+ * @param WC_Payment_Token[] $tokens
1074
+ * @param int $user_id
1075
+ * @param string $gateway_id
1076
+ *
1077
+ * @return WC_Payment_Token[]
1078
+ * @since 3.1.0
1079
+ * @package Stripe/Functions
1080
+ */
1081
+ function wc_stripe_get_customer_payment_tokens( $tokens, $user_id, $gateway_id ) {
1082
+ foreach ( $tokens as $idx => $token ) {
1083
+ if ( $token instanceof WC_Payment_Token_Stripe ) {
1084
+ $mode = wc_stripe_mode();
1085
+ if ( $token->get_environment() != $mode ) {
1086
+ unset( $tokens[ $idx ] );
1087
+ }
1088
+ }
1089
+ }
1090
+
1091
+ return $tokens;
1092
+ }
1093
+
1094
+ /**
1095
+ *
1096
+ * @param array $labels
1097
+ *
1098
+ * @return string
1099
+ * @since 3.1.0
1100
+ * @package Stripe/Functions
1101
+ */
1102
+ function wc_stripe_credit_card_labels( $labels ) {
1103
+ if ( ! isset( $labels['amex'] ) ) {
1104
+ $labels['amex'] = __( 'Amex', 'woocommerce' );
1105
+ }
1106
+
1107
+ return $labels;
1108
+ }
1109
+
1110
+ /**
1111
+ * Return an array of Stripe error messages.
1112
+ *
1113
+ * @since 3.1.1
1114
+ * @package Stripe/Functions
1115
+ */
1116
+ function wc_stripe_get_error_messages() {
1117
+ return apply_filters(
1118
+ 'wc_stripe_get_error_messages',
1119
+ array(
1120
+ 'stripe_cc_generic' => __( 'There was an error processing your credit card.', 'woo-stripe-payment' ),
1121
+ 'incomplete_number' => __( 'Your card number is incomplete.', 'woo-stripe-payment' ),
1122
+ 'incorrect_number' => __( 'The card number is incorrect. Check the card\'s number or use a different card.', 'woo-stripe-payment' ),
1123
+ 'incorrect_cvc' => __( 'The card\'s security code is incorrect. Check the card\'s security code or use a different card.', 'woo-stripe-payment' ),
1124
+ 'incorrect_zip' => __( 'The card\'s ZIP code is incorrect. Check the card\'s ZIP code or use a different card.', 'woo-stripe-payment' ),
1125
+ 'invalid_number' => __( 'The card number is invalid. Check the card details or use a different card.', 'woo-stripe-payment' ),
1126
+ 'invalid_characters' => __( 'This value provided to the field contains characters that are unsupported by the field.', 'woo-stripe-payment' ),
1127
+ 'invalid_cvc' => __( 'The card\'s security code is invalid. Check the card\'s security code or use a different card.', 'woo-stripe-payment' ),
1128
+ 'invalid_expiry_month' => __( 'The card\'s expiration month is incorrect. Check the expiration date or use a different card.', 'woo-stripe-payment' ),
1129
+ 'invalid_expiry_year' => __( 'The card\'s expiration year is incorrect. Check the expiration date or use a different card.', 'woo-stripe-payment' ),
1130
+ 'invalid_number' => __( 'The card number is invalid. Check the card details or use a different card.', 'woo-stripe-payment' ),
1131
+ 'incorrect_address' => __( 'The card\'s address is incorrect. Check the card\'s address or use a different card.', 'woo-stripe-payment' ),
1132
+ 'expired_card' => __( 'The card has expired. Check the expiration date or use a different card.', 'woo-stripe-payment' ),
1133
+ 'card_declined' => __( 'The card has been declined.', 'woo-stripe-payment' ),
1134
+ 'invalid_expiry_year_past' => __( 'Your card\'s expiration year is in the past.', 'woo-stripe-payment' ),
1135
+ 'account_number_invalid' => __( 'The bank account number provided is invalid (e.g., missing digits). Bank account information varies from country to country. We recommend creating validations in your entry forms based on the bank account formats we provide.', 'woo-stripe-payment' ),
1136
+ 'amount_too_large' => __( 'The specified amount is greater than the maximum amount allowed. Use a lower amount and try again.', 'woo-stripe-payment' ),
1137
+ 'amount_too_small' => __( 'The specified amount is less than the minimum amount allowed. Use a higher amount and try again.', 'woo-stripe-payment' ),
1138
+ 'authentication_required' => __( 'The payment requires authentication to proceed. If your customer is off session, notify your customer to return to your application and complete the payment. If you provided the error_on_requires_action parameter, then your customer should try another card that does not require authentication.', 'woo-stripe-payment' ),
1139
+ 'balance_insufficient' => __( 'The transfer or payout could not be completed because the associated account does not have a sufficient balance available. Create a new transfer or payout using an amount less than or equal to the account\'s available balance.', 'woo-stripe-payment' ),
1140
+ 'bank_account_declined' => __( 'The bank account provided can not be used to charge, either because it is not verified yet or it is not supported.', 'woo-stripe-payment' ),
1141
+ 'bank_account_exists' => __( 'The bank account provided already exists on the specified Customer object. If the bank account should also be attached to a different customer, include the correct customer ID when making the request again.', 'woo-stripe-payment' ),
1142
+ 'bank_account_unusable' => __( 'The bank account provided cannot be used for payouts. A different bank account must be used.', 'woo-stripe-payment' ),
1143
+ 'bank_account_unverified' => __( 'Your Connect platform is attempting to share an unverified bank account with a connected account.', 'woo-stripe-payment' ),
1144
+ 'bank_account_verification_failed' => __( 'The bank account cannot be verified, either because the microdeposit amounts provided do not match the actual amounts, or because verification has failed too many times.', 'woo-stripe-payment' ),
1145
+ 'card_decline_rate_limit_exceeded' => __( 'This card has been declined too many times. You can try to charge this card again after 24 hours. We suggest reaching out to your customer to make sure they have entered all of their information correctly and that there are no issues with their card.', 'woo-stripe-payment' ),
1146
+ 'charge_already_captured' => __( 'The charge you\'re attempting to capture has already been captured. Update the request with an uncaptured charge ID.', 'woo-stripe-payment' ),
1147
+ 'charge_already_refunded' => __( 'The charge you\'re attempting to refund has already been refunded. Update the request to use the ID of a charge that has not been refunded.', 'woo-stripe-payment' ),
1148
+ 'charge_disputed' => __( 'The charge you\'re attempting to refund has been charged back. Check the disputes documentation to learn how to respond to the dispute.', 'woo-stripe-payment' ),
1149
+ 'charge_exceeds_source_limit' => __( 'This charge would cause you to exceed your rolling-window processing limit for this source type. Please retry the charge later, or contact us to request a higher processing limit.', 'woo-stripe-payment' ),
1150
+ 'charge_expired_for_capture' => __( 'The charge cannot be captured as the authorization has expired. Auth and capture charges must be captured within seven days.', 'woo-stripe-payment' ),
1151
+ 'charge_invalid_parameter' => __( 'One or more provided parameters was not allowed for the given operation on the Charge. Check our API reference or the returned error message to see which values were not correct for that Charge.', 'woo-stripe-payment' ),
1152
+ 'email_invalid' => __( 'The email address is invalid (e.g., not properly formatted). Check that the email address is properly formatted and only includes allowed characters.', 'woo-stripe-payment' ),
1153
+ 'idempotency_key_in_use' => __( 'The idempotency key provided is currently being used in another request. This occurs if your integration is making duplicate requests simultaneously.', 'woo-stripe-payment' ),
1154
+ 'invalid_charge_amount' => __( 'The specified amount is invalid. The charge amount must be a positive integer in the smallest currency unit, and not exceed the minimum or maximum amount.', 'woo-stripe-payment' ),
1155
+ 'invalid_source_usage' => __( 'The source cannot be used because it is not in the correct state (e.g., a charge request is trying to use a source with a pending, failed, or consumed source). Check the status of the source you are attempting to use.', 'woo-stripe-payment' ),
1156
+ 'missing' => __( 'Both a customer and source ID have been provided, but the source has not been saved to the customer. To create a charge for a customer with a specified source, you must first save the card details.', 'woo-stripe-payment' ),
1157
+ 'postal_code_invalid' => __( 'The ZIP code provided was incorrect.', 'woo-stripe-payment' ),
1158
+ 'processing_error' => __( 'An error occurred while processing the card. Try again later or with a different payment method.', 'woo-stripe-payment' ),
1159
+ 'card_not_supported' => __( 'The card does not support this type of purchase.', 'woo-stripe-payment' ),
1160
+ 'call_issuer' => __( 'The card has been declined for an unknown reason.', 'woo-stripe-payment' ),
1161
+ 'card_velocity_exceeded' => __( 'The customer has exceeded the balance or credit limit available on their card.', 'woo-stripe-payment' ),
1162
+ 'currency_not_supported' => __( 'The card does not support the specified currency.', 'woo-stripe-payment' ),
1163
+ 'do_not_honor' => __( 'The card has been declined for an unknown reason.', 'woo-stripe-payment' ),
1164
+ 'fraudulent' => __( 'The payment has been declined as Stripe suspects it is fraudulent.', 'woo-stripe-payment' ),
1165
+ 'generic_decline' => __( 'The card has been declined for an unknown reason.', 'woo-stripe-payment' ),
1166
+ 'incorrect_pin' => __( 'The PIN entered is incorrect. ', 'woo-stripe-payment' ),
1167
+ 'insufficient_funds' => __( 'The card has insufficient funds to complete the purchase.', 'woo-stripe-payment' ),
1168
+ 'empty_element' => __( 'Please select a payment method before proceeding.', 'woo-stripe-payment' ),
1169
+ 'empty_element_sepa_debit' => __( 'Please enter your IBAN before proceeding.', 'woo-stripe-payment' ),
1170
+ 'empty_element_ideal' => __(
1171
+ 'Please select a bank before proceeding',
1172
+ 'woo-stripe-payment'
1173
+ ),
1174
+ )
1175
+ );
1176
+ }
1177
+
1178
+ /**
1179
+ * Return an array of Stripe currencies where the value of each
1180
+ * currency is the curency multiplier.
1181
+ *
1182
+ * @return mixed
1183
+ * @package Stripe/Functions
1184
+ * @since 3.1.2
1185
+ */
1186
+ function wc_stripe_get_currencies() {
1187
+ return apply_filters(
1188
+ 'wc_stripe_get_currencies',
1189
+ array(
1190
+ 'BIF' => 0,
1191
+ 'CLP' => 0,
1192
+ 'DJF' => 0,
1193
+ 'GNF' => 0,
1194
+ 'JPY' => 0,
1195
+ 'KMF' => 0,
1196
+ 'KRW' => 0,
1197
+ 'MGA' => 0,
1198
+ 'PYG' => 0,
1199
+ 'RWF' => 0,
1200
+ 'UGX' => 0,
1201
+ 'VND' => 0,
1202
+ 'VUV' => 0,
1203
+ 'XAF' => 0,
1204
+ 'XOF' => 0,
1205
+ 'XPF' => 0,
1206
+ )
1207
+ );
1208
+ }
1209
+
1210
+ /**
1211
+ * Function that triggers a filter on the order id.
1212
+ * Allows 3rd parties to
1213
+ * convert the order_id from the metadata of the Stripe object.
1214
+ *
1215
+ * @param int $order_id
1216
+ * @param \Stripe\ApiResource $object
1217
+ *
1218
+ * @since 3.1.3
1219
+ * @package Stripe/Functions
1220
+ */
1221
+ function wc_stripe_filter_order_id( $order_id, $object ) {
1222
+ return apply_filters( 'wc_stripe_filter_order_id', $order_id, $object );
1223
+ }
1224
+
1225
+ /**
1226
+ * Removes order locks that have expired so the options table does not get cluttered with transients.
1227
+ * @since 3.1.6
1228
+ * @package Stripe/Functions
1229
+ */
1230
+ function wc_stripe_remove_order_locks() {
1231
+ global $wpdb;
1232
+
1233
+ // this operation could take some time, ensure it completes.
1234
+ wc_set_time_limit();
1235
+
1236
+ $results = $wpdb->get_results( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s AND option_value < %d", '_transient_timeout_stripe_lock_order_%', time() ) );
1237
+ if ( $results ) {
1238
+ foreach ( $results as $result ) {
1239
+ // call delete_transient so Wordpress can fire all it's transient actions.
1240
+ delete_transient( substr( $result->option_name, strlen( '_transient_timeout_' ) ) );
1241
+ }
1242
+ }
1243
+ }
includes/wc-stripe-hooks.php CHANGED
@@ -1,28 +1,29 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- * Actions
6
- */
7
- add_action ( 'woocommerce_payment_token_deleted', 'wc_stripe_woocommerce_payment_token_deleted', 10, 2 );
8
- add_action ( 'woocommerce_order_status_cancelled', 'wc_stripe_order_cancelled', 10, 2 );
9
- add_action ( 'woocommerce_order_status_completed', 'wc_stripe_order_status_completed', 10, 2 );
10
- /**
11
- * * Webhook Actions ***
12
- */
13
- add_action ( 'wc_stripe_webhook_source_chargeable', 'wc_stripe_process_source_chargeable', 10, 2 );
14
- add_action ( 'wc_stripe_webhook_charge_succeeded', 'wc_stripe_process_charge_succeeded', 10, 2 );
15
- add_action ( 'wc_stripe_webhook_charge_failed', 'wc_stripe_process_charge_failed', 10, 2 );
16
- add_action ( 'wc_stripe_webhook_payment_intent_succeeded', 'wc_stripe_process_payment_intent_succeeded', 10, 2 );
17
-
18
- /**
19
- * Filters
20
- */
21
- add_filter ( 'wc_stripe_api_options', 'wc_stripe_api_options' );
22
- add_filter ( 'woocommerce_payment_gateways', 'wc_stripe_payment_gateways' );
23
- add_filter ( 'woocommerce_available_payment_gateways', 'wc_stripe_available_payment_gateways' );
24
- add_action ( 'woocommerce_process_shop_subscription_meta', 'wc_stripe_process_shop_subscription_meta', 10, 2 );
25
- add_filter ( 'woocommerce_available_payment_gateways', 'wc_stripe_get_available_local_gateways' );
26
- add_filter ( 'woocommerce_payment_complete_order_status', 'wc_stripe_payment_complete_order_status', 10, 3 );
27
- add_filter ( 'woocommerce_get_customer_payment_tokens', 'wc_stripe_get_customer_payment_tokens', 10, 3 );
28
- add_filter ( 'woocommerce_credit_card_type_labels', 'wc_stripe_credit_card_labels' );
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * Actions
6
+ */
7
+ add_action( 'woocommerce_payment_token_deleted', 'wc_stripe_woocommerce_payment_token_deleted', 10, 2 );
8
+ add_action( 'woocommerce_order_status_cancelled', 'wc_stripe_order_cancelled', 10, 2 );
9
+ add_action( 'woocommerce_order_status_completed', 'wc_stripe_order_status_completed', 10, 2 );
10
+ add_action( 'wc_stripe_remove_order_locks', 'wc_stripe_remove_order_locks' );
11
+ /**
12
+ * * Webhook Actions ***
13
+ */
14
+ add_action( 'wc_stripe_webhook_source_chargeable', 'wc_stripe_process_source_chargeable', 10, 2 );
15
+ add_action( 'wc_stripe_webhook_charge_succeeded', 'wc_stripe_process_charge_succeeded', 10, 2 );
16
+ add_action( 'wc_stripe_webhook_charge_failed', 'wc_stripe_process_charge_failed', 10, 2 );
17
+ add_action( 'wc_stripe_webhook_payment_intent_succeeded', 'wc_stripe_process_payment_intent_succeeded', 10, 2 );
18
+
19
+ /**
20
+ * Filters
21
+ */
22
+ add_filter( 'wc_stripe_api_options', 'wc_stripe_api_options' );
23
+ add_filter( 'woocommerce_payment_gateways', 'wc_stripe_payment_gateways' );
24
+ add_filter( 'woocommerce_available_payment_gateways', 'wc_stripe_available_payment_gateways' );
25
+ add_action( 'woocommerce_process_shop_subscription_meta', 'wc_stripe_process_shop_subscription_meta', 10, 2 );
26
+ add_filter( 'woocommerce_available_payment_gateways', 'wc_stripe_get_available_local_gateways' );
27
+ add_filter( 'woocommerce_payment_complete_order_status', 'wc_stripe_payment_complete_order_status', 10, 3 );
28
+ add_filter( 'woocommerce_get_customer_payment_tokens', 'wc_stripe_get_customer_payment_tokens', 10, 3 );
29
+ add_filter( 'woocommerce_credit_card_type_labels', 'wc_stripe_credit_card_labels' );
includes/wc-stripe-webhook-functions.php CHANGED
@@ -1,149 +1,150 @@
1
- <?php
2
- defined ( 'ABSPATH' ) || exit ();
3
-
4
- /**
5
- * Processes the charge via webhooks for local payment methods like iDEAL, EPS, etc.
6
- *
7
- * @since 3.0.0
8
- * @package Stripe/Functions
9
- *
10
- * @param \Stripe\Source $source
11
- * @param WP_REST_Request $request
12
- */
13
- function wc_stripe_process_source_chargeable($source, $request) {
14
- $order = wc_get_order ( wc_stripe_filter_order_id ( $source->metadata[ 'order_id' ], $source ) );
15
- if (! $order) {
16
- wc_stripe_log_error ( sprintf ( 'Could not create a charge for source %s. No order ID was found in your Wordpress database.', $source->id ) );
17
- return;
18
- }
19
-
20
- $payment_method = $order->get_payment_method ();
21
-
22
- /**
23
- *
24
- * @var WC_Payment_Gateway_Stripe $gateway
25
- */
26
- $gateway = WC ()->payment_gateways ()->payment_gateways ()[ $payment_method ];
27
-
28
- // if the order has a transaction ID, then a charge has already been created.
29
- if ($gateway->has_order_lock ( $order ) || ( $transaction_id = $order->get_transaction_id () )) {
30
- wc_stripe_log_info ( sprintf ( 'source.chargeable event received. Charge has already been created for order %s. Event exited.', $order->get_id () ) );
31
- return;
32
- }
33
- $gateway->set_order_lock ( $order );
34
- $gateway->set_new_source_token ( $source->id );
35
- $gateway->process_payment ( $order->get_id () );
36
-
37
- // we don't release the order lock so there aren't conflicts with the redirect handler
38
- }
39
-
40
- /**
41
- * When the charge has succeeded, the order should be completed.
42
- *
43
- * @since 3.0.5
44
- * @package Stripe/Functions
45
- *
46
- * @param \Stripe\Charge $charge
47
- * @param WP_REST_Request $request
48
- */
49
- function wc_stripe_process_charge_succeeded($charge, $request) {
50
- $order = wc_get_order ( $charge->metadata[ 'order_id' ] );
51
- if (! $order) {
52
- wc_stripe_log_error ( sprintf ( 'Could not complete payment for charge %s. No order ID was found in your Wordpress database.', $charge->id ) );
53
- return;
54
- }
55
-
56
- /**
57
- *
58
- * @var WC_Payment_Gateway_Stripe $payment_method
59
- */
60
- $payment_method = WC ()->payment_gateways ()->payment_gateways ()[ $order->get_payment_method () ];
61
- // Only process for asynchronous payment methods.
62
- if (! $payment_method->synchronous) {
63
- // the order has a lock which means code could still be running for the checkout process.
64
- // sleep for 1 second to allow other code to finish running.
65
- // @todo in future version, action scheduler will be used to trigger the event after it is received.
66
- if ($payment_method->has_order_lock ( $order )) {
67
- sleep ( 1 );
68
- // for the order to read it's metadata from the db as it may have changed
69
- // during the sleep operation.
70
- $order->read_meta_data ( true );
71
- }
72
- // If the order's charge status is not equal to charge status from Stripe, then complete_payment.
73
- if ($order->get_meta ( WC_Stripe_Constants::CHARGE_STATUS ) != $charge->status) {
74
- // want to prevent plugin from processing capture_charge since charge has already been captured.
75
- remove_action ( 'woocommerce_order_status_completed', 'wc_stripe_order_status_completed' );
76
-
77
- // call payment complete so shipping, emails, etc are triggered.
78
- $payment_method->save_order_meta ( $order, $charge );
79
- $order->payment_complete ();
80
- $order->add_order_note ( __ ( 'Charge.succeeded webhook received. Payment has been completed.', 'woo-stripe-payment' ) );
81
- }
82
- }
83
- // release any existing locks on the order so the db is cleared of the transient.
84
- $payment_method->release_order_lock ( $order );
85
- }
86
-
87
- /**
88
- *
89
- * @since 3.1.0
90
- * @package Stripe/Functions
91
- *
92
- * @param \Stripe\PaymentIntent $intent
93
- * @param WP_REST_Request $request
94
- */
95
- function wc_stripe_process_payment_intent_succeeded($intent, $request) {
96
- $order = wc_get_order ( $intent->metadata[ 'order_id' ] );
97
- if (! $order) {
98
- wc_stripe_log_error ( sprintf ( 'Could not complete payment for payment_intent %s. No order ID was found in your Wordpress database.', $intent->id ) );
99
- return;
100
- }
101
- $payment_method = WC ()->payment_gateways ()->payment_gateways ()[ $order->get_payment_method () ];
102
-
103
- if ($payment_method instanceof WC_Payment_Gateway_Stripe_Local_Payment) {
104
- // this webhook is executed immediately by Stripe so add some delay so the redirect
105
- // can potentially be used first.
106
- sleep ( 1 );
107
-
108
- if ($payment_method->has_order_lock ( $order ) || ( $transaction_id = $order->get_transaction_id () )) {
109
- wc_stripe_log_info ( sprintf ( 'payment_intent.succeeded event received. Intent has been completed and been created for order %s. Event exited.', $order->get_id () ) );
110
- return;
111
- }
112
-
113
- $payment_method->set_order_lock ( $order );
114
-
115
- $payment_method->process_payment ( $order->get_id () );
116
-
117
- $order->add_order_note ( __ ( 'payment_intent.succeeded webhook recieved. Payment has been completed.', 'woo-stripe-payment' ) );
118
-
119
- $payment_method->release_order_lock ( $order );
120
- }
121
- }
122
-
123
- /**
124
- *
125
- * @since 3.1.1
126
- * @package Stripe/Functions
127
- * @param \Stripe\Charge $charge
128
- * @param WP_REST_Request $request
129
- */
130
- function wc_stripe_process_charge_failed($charge, $request) {
131
- $order = wc_get_order ( $charge->metadata[ 'order_id' ] );
132
-
133
- if ($order) {
134
- $payment_methods = WC ()->payment_gateways ()->payment_gateways ();
135
- if (isset ( $payment_methods[ $order->get_payment_method () ] )) {
136
- /**
137
- *
138
- * @var WC_Payment_Gateway_Stripe $payment_method
139
- */
140
- $payment_method = $payment_methods[ $order->get_payment_method () ];
141
- // only update order status if this is an asynchronous payment method, doesn't have a lock,
142
- // and there is no completed date on the order. If there is a complete date it means payment_complete
143
- // was called on the order at some point
144
- if (! $payment_method->synchronous && ! $payment_method->has_order_lock ( $order ) && ! $order->get_date_completed ()) {
145
- $order->update_status ( 'failed', $charge->failure_message );
146
- }
147
- }
148
- }
149
- }
 
1
+ <?php
2
+ defined( 'ABSPATH' ) || exit();
3
+
4
+ /**
5
+ * Processes the charge via webhooks for local payment methods like P24, EPS, etc.
6
+ *
7
+ * @param \Stripe\Source $source
8
+ * @param WP_REST_Request $request
9
+ *
10
+ * @since 3.0.0
11
+ * @package Stripe/Functions
12
+ */
13
+ function wc_stripe_process_source_chargeable( $source, $request ) {
14
+ $order = wc_get_order( wc_stripe_filter_order_id( $source->metadata['order_id'], $source ) );
15
+ if ( ! $order ) {
16
+ wc_stripe_log_error( sprintf( 'Could not create a charge for source %s. No order ID was found in your WordPress database.', $source->id ) );
17
+
18
+ return;
19
+ }
20
+
21
+ /**
22
+ *
23
+ * @var WC_Payment_Gateway_Stripe $payment_method
24
+ */
25
+ $payment_method = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
26
+
27
+ // if the order has a transaction ID, then a charge has already been created.
28
+ if ( $payment_method->has_order_lock( $order ) || ( $transaction_id = $order->get_transaction_id() ) ) {
29
+ wc_stripe_log_info( sprintf( 'source.chargeable event received. Charge has already been created for order %s. Event exited.', $order->get_id() ) );
30
+
31
+ return;
32
+ }
33
+ $payment_method->set_order_lock( $order );
34
+ $payment_method->set_new_source_token( $source->id );
35
+ $payment_method->process_payment( $order->get_id() );
36
+ }
37
+
38
+ /**
39
+ * When the charge has succeeded, the order should be completed.
40
+ *
41
+ * @param \Stripe\Charge $charge
42
+ * @param WP_REST_Request $request
43
+ *
44
+ * @since 3.0.5
45
+ * @package Stripe/Functions
46
+ */
47
+ function wc_stripe_process_charge_succeeded( $charge, $request ) {
48
+ // charges that belong to a payment intent can be skipped
49
+ // because the payment_intent.succeeded event will be called.
50
+ if ( $charge->payment_intent ) {
51
+ return;
52
+ }
53
+ $order = wc_get_order( wc_stripe_filter_order_id( $charge->metadata['order_id'], $charge ) );
54
+ if ( ! $order ) {
55
+ wc_stripe_log_error( sprintf( 'Could not complete payment for charge %s. No order ID %s was found in your WordPress database.', $charge->id, $charge->metadata['order_id'] ) );
56
+
57
+ return;
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @var WC_Payment_Gateway_Stripe $payment_method
63
+ */
64
+ $payment_method = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
65
+ /**
66
+ * Only process for local payment methods. We make sure the payment method is asynchronous
67
+ * because synchronous payments are handled via the source.chargeable event which processes the payment.
68
+ * This event is relevant for payment methods that receive a charge.succeeded event at some arbitrary amount of time
69
+ * after the source is chargeable.
70
+ */
71
+ if ( $payment_method instanceof WC_Payment_Gateway_Stripe_Local_Payment && ! $payment_method->synchronous ) {
72
+
73
+ // If the order's charge status is not equal to charge status from Stripe, then complete_payment.
74
+ if ( $order->get_meta( WC_Stripe_Constants::CHARGE_STATUS ) != $charge->status ) {
75
+ // want to prevent plugin from processing capture_charge since charge has already been captured.
76
+ remove_action( 'woocommerce_order_status_completed', 'wc_stripe_order_status_completed' );
77
+
78
+ // call payment complete so shipping, emails, etc are triggered.
79
+ $payment_method->save_order_meta( $order, $charge );
80
+ $order->payment_complete();
81
+ $order->add_order_note( __( 'Charge.succeeded webhook received. Payment has been completed.', 'woo-stripe-payment' ) );
82
+ $payment_method->release_order_lock( $order );
83
+ }
84
+ }
85
+ }
86
+
87
+ /**
88
+ *
89
+ * @param \Stripe\PaymentIntent $intent
90
+ * @param WP_REST_Request $request
91
+ *
92
+ * @since 3.1.0
93
+ * @package Stripe/Functions
94
+ */
95
+ function wc_stripe_process_payment_intent_succeeded( $intent, $request ) {
96
+ $order = wc_get_order( wc_stripe_filter_order_id( $intent->metadata['order_id'], $intent ) );
97
+ if ( ! $order ) {
98
+ wc_stripe_log_error( sprintf( 'Could not complete payment for payment_intent %s. No order ID was found in your WordPress database.', $intent->id ) );
99
+
100
+ return;
101
+ }
102
+ $payment_method = WC()->payment_gateways()->payment_gateways()[ $order->get_payment_method() ];
103
+
104
+ if ( $payment_method instanceof WC_Payment_Gateway_Stripe_Local_Payment ) {
105
+ /**
106
+ * Delay the event by one second to allow the redirect handler to process
107
+ * the payment.
108
+ */
109
+ sleep( 1 );
110
+
111
+ if ( $payment_method->has_order_lock( $order ) || ( $transaction_id = $order->get_transaction_id() ) ) {
112
+ wc_stripe_log_info( sprintf( 'payment_intent.succeeded event received. Intent has been completed and been created for order %s. Event exited.', $order->get_id() ) );
113
+
114
+ return;
115
+ }
116
+
117
+ $payment_method->set_order_lock( $order );
118
+ $payment_method->process_payment( $order->get_id() );
119
+ $order->add_order_note( __( 'payment_intent.succeeded webhook received. Payment has been completed.', 'woo-stripe-payment' ) );
120
+ }
121
+ }
122
+
123
+ /**
124
+ *
125
+ * @param \Stripe\Charge $charge
126
+ * @param WP_REST_Request $request
127
+ *
128
+ * @since 3.1.1
129
+ * @package Stripe/Functions
130
+ */
131
+ function wc_stripe_process_charge_failed( $charge, $request ) {
132
+ $order = wc_get_order( wc_stripe_filter_order_id( $charge->metadata['order_id'], $charge ) );
133
+
134
+ if ( $order ) {
135
+ $payment_methods = WC()->payment_gateways()->payment_gateways();
136
+ if ( isset( $payment_methods[ $order->get_payment_method() ] ) ) {
137
+ /**
138
+ *
139
+ * @var WC_Payment_Gateway_Stripe $payment_method
140
+ */
141
+ $payment_method = $payment_methods[ $order->get_payment_method() ];
142
+ // only update order status if this is an asynchronous payment method,
143
+ // and there is no completed date on the order. If there is a complete date it
144
+ // means payment_complete was called on the order at some point
145
+ if ( ! $payment_method->synchronous && ! $order->get_date_completed() ) {
146
+ $order->update_status( 'failed', $charge->failure_message );
147
+ }
148
+ }
149
+ }
150
+ }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: mr.clayton
3
  Tags: stripe, ach, klarna, credit card, apple pay, google pay, ideal, sepa, sofort
4
  Requires at least: 3.0.1
5
  Tested up to: 5.4
6
- Requires PHP: 5.4
7
- Stable tag: 3.1.5
8
  Copyright: Payment Plugins
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -57,6 +57,14 @@ If you're site is not loading over https, then Stripe won't render the Payment R
57
  8. Edit payment gateways on the product page
58
 
59
  == Changelog ==
 
 
 
 
 
 
 
 
60
  = 3.1.5 =
61
  * Fixed - Capture type on product page checkout
62
  * Fixed - WP 5.4.2 deprecation message for namespaces
3
  Tags: stripe, ach, klarna, credit card, apple pay, google pay, ideal, sepa, sofort
4
  Requires at least: 3.0.1
5
  Tested up to: 5.4
6
+ Requires PHP: 5.6
7
+ Stable tag: 3.1.6
8
  Copyright: Payment Plugins
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
57
  8. Edit payment gateways on the product page
58
 
59
  == Changelog ==
60
+ = 3.1.6 =
61
+ * Updated - WC tested to 4.3.0
62
+ * Updated - Bumped PHP min version to 5.6
63
+ * Updated - Stripe php lib version 7.39.0
64
+ * Updated - Apple domain registration check for existing domain
65
+ * Fixed - Notice on cart page when payment request button active and cart emptied
66
+ * Fixed - Google Pay fee line item in wallet
67
+ * Added - New filters for API requests
68
  = 3.1.5 =
69
  * Fixed - Capture type on product page checkout
70
  * Fixed - WP 5.4.2 deprecation message for namespaces
stripe-payments.php CHANGED
@@ -3,22 +3,22 @@
3
  * Plugin Name: Stripe For WooCommerce
4
  * Plugin URI: https://docs.paymentplugins.com/wc-stripe/config/
5
  * Description: Accept credit cards, Google Pay, Apple Pay, ACH, Klarna and more using Stripe.
6
- * Version: 3.1.5
7
  * Author: Payment Plugins, support@paymentplugins.com
8
  * Text Domain: woo-stripe-payment
9
  * Domain Path: /i18n/languages/
10
  * Tested up to: 5.4
11
  * WC requires at least: 3.0.0
12
- * WC tested up to: 4.2.0
13
  */
14
  defined ( 'ABSPATH' ) || exit ();
15
 
16
  function wc_stripe_php_version_notice() {
17
- $message = sprintf ( __ ( 'Your PHP version is %s but Stripe requires version 5.4+.', 'woo-stripe-payment' ), PHP_VERSION );
18
  echo '<div class="notice notice-error"><p style="font-size: 16px">' . $message . '</p></div>';
19
  }
20
 
21
- if (version_compare ( PHP_VERSION, '5.4', '<' )) {
22
  add_action ( 'admin_init', 'wc_stripe_php_version_notice' );
23
  return;
24
  }
@@ -29,5 +29,4 @@ define ( 'WC_STRIPE_PLUGIN_NAME', plugin_basename ( __FILE__ ) );
29
  define ( 'WC_STRIPE_CLASS_VERSION', '6.40.0' );
30
  // include main plugin file.
31
  require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-stripe.php' );
32
- // load Stripe classes
33
- require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'stripe-php-' . WC_STRIPE_CLASS_VERSION . '/init.php' );
3
  * Plugin Name: Stripe For WooCommerce
4
  * Plugin URI: https://docs.paymentplugins.com/wc-stripe/config/
5
  * Description: Accept credit cards, Google Pay, Apple Pay, ACH, Klarna and more using Stripe.
6
+ * Version: 3.1.6
7
  * Author: Payment Plugins, support@paymentplugins.com
8
  * Text Domain: woo-stripe-payment
9
  * Domain Path: /i18n/languages/
10
  * Tested up to: 5.4
11
  * WC requires at least: 3.0.0
12
+ * WC tested up to: 4.3.0
13
  */
14
  defined ( 'ABSPATH' ) || exit ();
15
 
16
  function wc_stripe_php_version_notice() {
17
+ $message = sprintf ( __ ( 'Your PHP version is %s but Stripe requires version 5.6+.', 'woo-stripe-payment' ), PHP_VERSION );
18
  echo '<div class="notice notice-error"><p style="font-size: 16px">' . $message . '</p></div>';
19
  }
20
 
21
+ if (version_compare ( PHP_VERSION, '5.6', '<' )) {
22
  add_action ( 'admin_init', 'wc_stripe_php_version_notice' );
23
  return;
24
  }
29
  define ( 'WC_STRIPE_CLASS_VERSION', '6.40.0' );
30
  // include main plugin file.
31
  require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'includes/class-stripe.php' );
32
+ require_once ( WC_STRIPE_PLUGIN_FILE_PATH . 'vendor/autoload.php' );
 
stripe-php-6.40.0/CHANGELOG.md DELETED
@@ -1,715 +0,0 @@
1
- # Changelog
2
-
3
- ## 6.40.0 - 2019-06-27
4
- * [#675](https://github.com/stripe/stripe-php/pull/675) Add support for `SetupIntent` resource and APIs
5
-
6
- ## 6.39.2 - 2019-06-26
7
- * [#676](https://github.com/stripe/stripe-php/pull/676) Fix exception message in `CustomerBalanceTransaction::update()`
8
-
9
- ## 6.39.1 - 2019-06-25
10
- * [#674](https://github.com/stripe/stripe-php/pull/674) Add new constants for `collection_method` on `Invoice`
11
-
12
- ## 6.39.0 - 2019-06-24
13
- * [#673](https://github.com/stripe/stripe-php/pull/673) Enable request latency telemetry by default
14
-
15
- ## 6.38.0 - 2019-06-17
16
- * [#649](https://github.com/stripe/stripe-php/pull/649) Add support for `CustomerBalanceTransaction` resource and APIs
17
-
18
- ## 6.37.2 - 2019-06-17
19
- * [#671](https://github.com/stripe/stripe-php/pull/671) Add new PHPDoc
20
- * [#672](https://github.com/stripe/stripe-php/pull/672) Add constants for `submit_type` on Checkout `Session`
21
-
22
- ## 6.37.1 - 2019-06-14
23
- * [#670](https://github.com/stripe/stripe-php/pull/670) Add new PHPDoc
24
-
25
- ## 6.37.0 - 2019-05-23
26
- * [#663](https://github.com/stripe/stripe-php/pull/663) Add support for `radar.early_fraud_warning` resource
27
-
28
- ## 6.36.0 - 2019-05-22
29
- * [#661](https://github.com/stripe/stripe-php/pull/661) Add constants for new TaxId types
30
- * [#662](https://github.com/stripe/stripe-php/pull/662) Add constants for BalanceTransaction types
31
-
32
- ## 6.35.2 - 2019-05-20
33
- * [#655](https://github.com/stripe/stripe-php/pull/655) Add constants for payment intent statuses
34
- * [#659](https://github.com/stripe/stripe-php/pull/659) Fix PHPDoc for various nested Account actions
35
- * [#660](https://github.com/stripe/stripe-php/pull/660) Fix various PHPDoc
36
-
37
- ## 6.35.1 - 2019-05-20
38
- * [#658](https://github.com/stripe/stripe-php/pull/658) Use absolute value when checking timestamp tolerance
39
-
40
- ## 6.35.0 - 2019-05-14
41
- * [#651](https://github.com/stripe/stripe-php/pull/651) Add support for the Capability resource and APIs
42
-
43
- ## 6.34.6 - 2019-05-13
44
- * [#654](https://github.com/stripe/stripe-php/pull/654) Fix typo in definition of `Event::PAYMENT_METHOD_ATTACHED` constant
45
-
46
- ## 6.34.5 - 2019-05-06
47
- * [#647](https://github.com/stripe/stripe-php/pull/647) Set the return type to static for more operations
48
-
49
- ## 6.34.4 - 2019-05-06
50
- * [#650](https://github.com/stripe/stripe-php/pull/650) Add missing constants for Event types
51
-
52
- ## 6.34.3 - 2019-05-01
53
- * [#644](https://github.com/stripe/stripe-php/pull/644) Update return type to `static` to improve static analysis
54
- * [#645](https://github.com/stripe/stripe-php/pull/645) Fix constant for `payment_intent.payment_failed`
55
-
56
- ## 6.34.2 - 2019-04-26
57
- * [#642](https://github.com/stripe/stripe-php/pull/642) Fix an issue where existing idempotency keys would be overwritten when using automatic retries
58
-
59
- ## 6.34.1 - 2019-04-25
60
- * [#640](https://github.com/stripe/stripe-php/pull/640) Add missing phpdocs
61
-
62
- ## 6.34.0 - 2019-04-24
63
- * [#626](https://github.com/stripe/stripe-php/pull/626) Add support for the `TaxRate` resource and APIs
64
- * [#639](https://github.com/stripe/stripe-php/pull/639) Fix multiple phpdoc issues
65
-
66
- ## 6.33.0 - 2019-04-22
67
- * [#630](https://github.com/stripe/stripe-php/pull/630) Add support for the `TaxId` resource and APIs
68
-
69
- ## 6.32.1 - 2019-04-19
70
- * [#636](https://github.com/stripe/stripe-php/pull/636) Correct type of `$personId` in PHPDoc
71
-
72
- ## 6.32.0 - 2019-04-18
73
- * [#621](https://github.com/stripe/stripe-php/pull/621) Add support for `CreditNote`
74
-
75
- ## 6.31.5 - 2019-04-12
76
- * [#628](https://github.com/stripe/stripe-php/pull/628) Add constants for `person.*` event types
77
- * [#628](https://github.com/stripe/stripe-php/pull/628) Add missing constants for `Account` and `Person`
78
-
79
- ## 6.31.4 - 2019-04-05
80
- * [#624](https://github.com/stripe/stripe-php/pull/624) Fix encoding of nested parameters in multipart requests
81
-
82
- ## 6.31.3 - 2019-04-02
83
- * [#623](https://github.com/stripe/stripe-php/pull/623) Only use HTTP/2 with curl >= 7.60.0
84
-
85
- ## 6.31.2 - 2019-03-25
86
- * [#619](https://github.com/stripe/stripe-php/pull/619) Fix PHPDoc return types for list methods for nested resources
87
-
88
- ## 6.31.1 - 2019-03-22
89
- * [#612](https://github.com/stripe/stripe-php/pull/612) Add a lot of constants
90
- * [#614](https://github.com/stripe/stripe-php/pull/614) Add missing subscription status constants
91
-
92
- ## 6.31.0 - 2019-03-18
93
- * [#600](https://github.com/stripe/stripe-php/pull/600) Add support for the `PaymentMethod` resource and APIs
94
- * [#606](https://github.com/stripe/stripe-php/pull/606) Add support for retrieving a Checkout `Session`
95
- * [#611](https://github.com/stripe/stripe-php/pull/611) Add support for deleting a Terminal `Location` and `Reader`
96
-
97
- ## 6.30.5 - 2019-03-11
98
- * [#607](https://github.com/stripe/stripe-php/pull/607) Correctly handle case where a metadata key is called `metadata`
99
-
100
- ## 6.30.4 - 2019-02-27
101
- * [#602](https://github.com/stripe/stripe-php/pull/602) Add `subscription_schedule` to `Subscription` for PHPDoc.
102
-
103
- ## 6.30.3 - 2019-02-26
104
- * [#603](https://github.com/stripe/stripe-php/pull/603) Improve PHPDoc on the `Source` object to cover all types of Sources currently supported.
105
-
106
- ## 6.30.2 - 2019-02-25
107
- * [#601](https://github.com/stripe/stripe-php/pull/601) Fix PHPDoc across multiple resources and add support for new events.
108
-
109
- ## 6.30.1 - 2019-02-16
110
- * [#599](https://github.com/stripe/stripe-php/pull/599) Fix PHPDoc for `SubscriptionSchedule` and `SubscriptionScheduleRevision`
111
-
112
- ## 6.30.0 - 2019-02-12
113
- * [#590](https://github.com/stripe/stripe-php/pull/590) Add support for `SubscriptionSchedule` and `SubscriptionScheduleRevision`
114
-
115
- ## 6.29.3 - 2019-01-31
116
- * [#592](https://github.com/stripe/stripe-php/pull/592) Some more PHPDoc fixes
117
-
118
- ## 6.29.2 - 2019-01-31
119
- * [#591](https://github.com/stripe/stripe-php/pull/591) Fix PHPDoc for nested resources
120
-
121
- ## 6.29.1 - 2019-01-25
122
- * [#566](https://github.com/stripe/stripe-php/pull/566) Fix dangling message contents
123
- * [#586](https://github.com/stripe/stripe-php/pull/586) Don't overwrite `CURLOPT_HTTP_VERSION` option
124
-
125
- ## 6.29.0 - 2019-01-23
126
- * [#579](https://github.com/stripe/stripe-php/pull/579) Rename `CheckoutSession` to `Session` and move it under the `Checkout` namespace. This is a breaking change, but we've reached out to affected merchants and all new merchants would use the new approach.
127
-
128
- ## 6.28.1 - 2019-01-21
129
- * [#580](https://github.com/stripe/stripe-php/pull/580) Properly serialize `individual` on `Account` objects
130
-
131
- ## 6.28.0 - 2019-01-03
132
- * [#576](https://github.com/stripe/stripe-php/pull/576) Add support for iterating directly over `Collection` instances
133
-
134
- ## 6.27.0 - 2018-12-21
135
- * [#571](https://github.com/stripe/stripe-php/pull/571) Add support for the `CheckoutSession` resource
136
-
137
- ## 6.26.0 - 2018-12-11
138
- * [#568](https://github.com/stripe/stripe-php/pull/568) Enable persistent connections
139
-
140
- ## 6.25.0 - 2018-12-10
141
- * [#567](https://github.com/stripe/stripe-php/pull/567) Add support for account links
142
-
143
- ## 6.24.0 - 2018-11-28
144
- * [#562](https://github.com/stripe/stripe-php/pull/562) Add support for the Review resource
145
- * [#564](https://github.com/stripe/stripe-php/pull/564) Add event name constants for subscription schedule aborted/expiring
146
-
147
- ## 6.23.0 - 2018-11-27
148
- * [#542](https://github.com/stripe/stripe-php/pull/542) Add support for `ValueList` and `ValueListItem` for Radar
149
-
150
- ## 6.22.1 - 2018-11-20
151
- * [#561](https://github.com/stripe/stripe-php/pull/561) Add cast and some docs to telemetry introduced in 6.22.0/#549
152
-
153
- ## 6.22.0 - 2018-11-15
154
- * [#549](https://github.com/stripe/stripe-php/pull/549) Add support for client telemetry
155
-
156
- ## 6.21.1 - 2018-11-12
157
- * [#548](https://github.com/stripe/stripe-php/pull/548) Don't mutate `Exception` class properties from `OAuthBase` error
158
-
159
- ## 6.21.0 - 2018-11-08
160
- * [#537](https://github.com/stripe/stripe-php/pull/537) Add new API endpoints for the `Invoice` resource.
161
-
162
- ## 6.20.1 - 2018-11-07
163
- * [#546](https://github.com/stripe/stripe-php/pull/546) Drop files from the Composer package that aren't needed in the release
164
-
165
- ## 6.20.0 - 2018-10-30
166
- * [#536](https://github.com/stripe/stripe-php/pull/536) Add support for the `Person` resource
167
- * [#541](https://github.com/stripe/stripe-php/pull/541) Add support for the `WebhookEndpoint` resource
168
-
169
- ## 6.19.5 - 2018-10-17
170
- * [#539](https://github.com/stripe/stripe-php/pull/539) Fix methods on `\Stripe\PaymentIntent` to properly pass arguments to the API.
171
-
172
- ## 6.19.4 - 2018-10-11
173
- * [#534](https://github.com/stripe/stripe-php/pull/534) Fix PSR-4 autoloading for `\Stripe\FileUpload` class alias
174
-
175
- ## 6.19.3 - 2018-10-09
176
- * [#530](https://github.com/stripe/stripe-php/pull/530) Add constants for `flow` (`FLOW_*`), `status` (`STATUS_*`) and `usage` (`USAGE_*`) on `\Stripe\Source`
177
-
178
- ## 6.19.2 - 2018-10-08
179
- * [#531](https://github.com/stripe/stripe-php/pull/531) Store HTTP response headers in case-insensitive array
180
-
181
- ## 6.19.1 - 2018-09-25
182
- * [#526](https://github.com/stripe/stripe-php/pull/526) Ignore null values in request parameters
183
-
184
- ## 6.19.0 - 2018-09-24
185
- * [#523](https://github.com/stripe/stripe-php/pull/523) Add support for Stripe Terminal
186
-
187
- ## 6.18.0 - 2018-09-24
188
- * [#520](https://github.com/stripe/stripe-php/pull/520) Rename `\Stripe\FileUpload` to `\Stripe\File`
189
-
190
- ## 6.17.2 - 2018-09-18
191
- * [#522](https://github.com/stripe/stripe-php/pull/522) Fix warning when adding a new additional owner to an existing array
192
-
193
- ## 6.17.1 - 2018-09-14
194
- * [#517](https://github.com/stripe/stripe-php/pull/517) Integer-index encode all sequential arrays
195
-
196
- ## 6.17.0 - 2018-09-05
197
- * [#514](https://github.com/stripe/stripe-php/pull/514) Add support for reporting resources
198
-
199
- ## 6.16.0 - 2018-08-23
200
- * [#509](https://github.com/stripe/stripe-php/pull/509) Add support for usage record summaries
201
-
202
- ## 6.15.0 - 2018-08-03
203
- * [#504](https://github.com/stripe/stripe-php/pull/504) Add cancel support for topups
204
-
205
- ## 6.14.0 - 2018-08-02
206
- * [#505](https://github.com/stripe/stripe-php/pull/505) Add support for file links
207
-
208
- ## 6.13.0 - 2018-07-31
209
- * [#502](https://github.com/stripe/stripe-php/pull/502) Add `isDeleted()` method to `\Stripe\StripeObject`
210
-
211
- ## 6.12.0 - 2018-07-28
212
- * [#501](https://github.com/stripe/stripe-php/pull/501) Add support for scheduled query runs (`\Stripe\Sigma\ScheduledQueryRun`) for Sigma
213
-
214
- ## 6.11.0 - 2018-07-26
215
- * [#500](https://github.com/stripe/stripe-php/pull/500) Add support for Stripe Issuing
216
-
217
- ## 6.10.4 - 2018-07-19
218
- * [#498](https://github.com/stripe/stripe-php/pull/498) Internal improvements to the `\Stripe\ApiResource.classUrl()` method
219
-
220
- ## 6.10.3 - 2018-07-16
221
- * [#497](https://github.com/stripe/stripe-php/pull/497) Use HTTP/2 only for HTTPS requests
222
-
223
- ## 6.10.2 - 2018-07-11
224
- * [#494](https://github.com/stripe/stripe-php/pull/494) Enable HTTP/2 support
225
-
226
- ## 6.10.1 - 2018-07-10
227
- * [#493](https://github.com/stripe/stripe-php/pull/493) Add PHPDoc for `auto_advance` on `\Stripe\Invoice`
228
-
229
- ## 6.10.0 - 2018-06-28
230
- * [#488](https://github.com/stripe/stripe-php/pull/488) Add support for `$appPartnerId` to `Stripe::setAppInfo()`
231
-
232
- ## 6.9.0 - 2018-06-28
233
- * [#487](https://github.com/stripe/stripe-php/pull/487) Add support for payment intents
234
-
235
- ## 6.8.2 - 2018-06-24
236
- * [#486](https://github.com/stripe/stripe-php/pull/486) Make `Account.deauthorize()` return the `StripeObject` from the API
237
-
238
- ## 6.8.1 - 2018-06-13
239
- * [#472](https://github.com/stripe/stripe-php/pull/472) Added phpDoc for `ApiRequestor` and others, especially regarding thrown errors
240
-
241
- ## 6.8.0 - 2018-06-13
242
- * [#481](https://github.com/stripe/stripe-php/pull/481) Add new `\Stripe\Discount` and `\Stripe\OrderItem` classes, add more PHPDoc describing object attributes
243
-
244
- ## 6.7.4 - 2018-05-29
245
- * [#480](https://github.com/stripe/stripe-php/pull/480) PHPDoc changes for API version 2018-05-21 and the addition of the new `CHARGE_EXPIRED` event type
246
-
247
- ## 6.7.3 - 2018-05-28
248
- * [#479](https://github.com/stripe/stripe-php/pull/479) Fix unnecessary traits on `\Stripe\InvoiceLineItem`
249
-
250
- ## 6.7.2 - 2018-05-28
251
- * [#471](https://github.com/stripe/stripe-php/pull/471) Add `OBJECT_NAME` constant to all API resource classes, add `\Stripe\InvoiceLineItem` class
252
-
253
- ## 6.7.1 - 2018-05-13
254
- * [#468](https://github.com/stripe/stripe-php/pull/468) Update fields in PHP docs for accuracy
255
-
256
- ## 6.7.0 - 2018-05-09
257
- * [#466](https://github.com/stripe/stripe-php/pull/466) Add support for issuer fraud records
258
-
259
- ## 6.6.0 - 2018-04-11
260
- * [#460](https://github.com/stripe/stripe-php/pull/460) Add support for flexible billing primitives
261
-
262
- ## 6.5.0 - 2018-04-05
263
- * [#461](https://github.com/stripe/stripe-php/pull/461) Don't zero keys on non-`metadata` subobjects
264
-
265
- ## 6.4.2 - 2018-03-17
266
- * [#458](https://github.com/stripe/stripe-php/pull/458) Add PHPDoc for `account` on `\Stripe\Event`
267
-
268
- ## 6.4.1 - 2018-03-02
269
- * [#455](https://github.com/stripe/stripe-php/pull/455) Fix namespaces in PHPDoc
270
- * [#456](https://github.com/stripe/stripe-php/pull/456) Fix namespaces for some exceptions
271
-
272
- ## 6.4.0 - 2018-02-28
273
- * [#453](https://github.com/stripe/stripe-php/pull/453) Add constants for `reason` (`REASON_*`) and `status` (`STATUS_*`) on `\Stripe\Dispute`
274
-
275
- ## 6.3.2 - 2018-02-27
276
- * [#452](https://github.com/stripe/stripe-php/pull/452) Add PHPDoc for `amount_paid` and `amount_remaining` on `\Stripe\Invoice`
277
-
278
- ## 6.3.1 - 2018-02-26
279
- * [#443](https://github.com/stripe/stripe-php/pull/443) Add event types as constants to `\Stripe\Event` class
280
-
281
- ## 6.3.0 - 2018-02-23
282
- * [#450](https://github.com/stripe/stripe-php/pull/450) Add support for `code` attribute on all Stripe exceptions
283
-
284
- ## 6.2.0 - 2018-02-21
285
- * [#440](https://github.com/stripe/stripe-php/pull/440) Add support for topups
286
- * [#442](https://github.com/stripe/stripe-php/pull/442) Fix PHPDoc for `\Stripe\Error\SignatureVerification`
287
-
288
- ## 6.1.0 - 2018-02-12
289
- * [#435](https://github.com/stripe/stripe-php/pull/435) Fix header persistence on `Collection` objects
290
- * [#436](https://github.com/stripe/stripe-php/pull/436) Introduce new `Idempotency` error class
291
-
292
- ## 6.0.0 - 2018-02-07
293
- Major version release. List of backwards incompatible changes to watch out for:
294
- + The minimum PHP version is now 5.4.0. If you're using PHP 5.3 or older, consider upgrading to a more recent version.
295
- * `\Stripe\AttachedObject` no longer exists. Attributes that used to be instances of `\Stripe\AttachedObject` (such as `metadata`) are now instances of `\Stripe\StripeObject`.
296
- + Attributes that used to be PHP arrays (such as `legal_entity->additional_owners` on `\Stripe\Account` instances) are now instances of `\Stripe\StripeObject`, except when they are empty. `\Stripe\StripeObject` has array semantics so this should not be an issue unless you are actively checking types.
297
- * `\Stripe\Collection` now derives from `\Stripe\StripeObject` rather than from `\Stripe\ApiResource`.
298
-
299
- Pull requests included in this release:
300
- * [#410](https://github.com/stripe/stripe-php/pull/410) Drop support for PHP 5.3
301
- * [#411](https://github.com/stripe/stripe-php/pull/411) Use traits for common API operations
302
- * [#414](https://github.com/stripe/stripe-php/pull/414) Use short array syntax
303
- * [#404](https://github.com/stripe/stripe-php/pull/404) Fix serialization logic
304
- * [#417](https://github.com/stripe/stripe-php/pull/417) Remove `ExternalAccount` class
305
- * [#418](https://github.com/stripe/stripe-php/pull/418) Increase test coverage
306
- * [#421](https://github.com/stripe/stripe-php/pull/421) Update CA bundle and add script for future updates
307
- * [#422](https://github.com/stripe/stripe-php/pull/422) Use vendored CA bundle for all requests
308
- * [#428](https://github.com/stripe/stripe-php/pull/428) Support for automatic request retries
309
-
310
- ## 5.9.2 - 2018-02-07
311
- * [#431](https://github.com/stripe/stripe-php/pull/431) Update PHPDoc @property tags for latest API version
312
-
313
- ## 5.9.1 - 2018-02-06
314
- * [#427](https://github.com/stripe/stripe-php/pull/427) Add and update PHPDoc @property tags on all API resources
315
-
316
- ## 5.9.0 - 2018-01-17
317
- * [#421](https://github.com/stripe/stripe-php/pull/421) Updated bundled CA certificates
318
- * [#423](https://github.com/stripe/stripe-php/pull/423) Escape unsanitized input in OAuth example
319
-
320
- ## 5.8.0 - 2017-12-20
321
- * [#403](https://github.com/stripe/stripe-php/pull/403) Add `__debugInfo()` magic method to `StripeObject`
322
-
323
- ## 5.7.0 - 2017-11-28
324
- * [#390](https://github.com/stripe/stripe-php/pull/390) Remove some unsupported API methods
325
- * [#391](https://github.com/stripe/stripe-php/pull/391) Alphabetize the list of API resources in `Util::convertToStripeObject()` and add missing resources
326
- * [#393](https://github.com/stripe/stripe-php/pull/393) Fix expiry date update for card sources
327
-
328
- ## 5.6.0 - 2017-10-31
329
- * [#386](https://github.com/stripe/stripe-php/pull/386) Support for exchange rates APIs
330
-
331
- ## 5.5.1 - 2017-10-30
332
- * [#387](https://github.com/stripe/stripe-php/pull/387) Allow `personal_address_kana` and `personal_address_kanji` to be updated on an account
333
-
334
- ## 5.5.0 - 2017-10-27
335
- * [#385](https://github.com/stripe/stripe-php/pull/385) Support for listing source transactions
336
-
337
- ## 5.4.0 - 2017-10-24
338
- * [#383](https://github.com/stripe/stripe-php/pull/383) Add static methods to manipulate resources from parent
339
- * `Account` gains methods for external accounts and login links (e.g. `createExternalAccount`, `createLoginLink`)
340
- * `ApplicationFee` gains methods for refunds
341
- * `Customer` gains methods for sources
342
- * `Transfer` gains methods for reversals
343
-
344
- ## 5.3.0 - 2017-10-11
345
- * [#378](https://github.com/stripe/stripe-php/pull/378) Rename source `delete` to `detach` (and deprecate the former)
346
-
347
- ## 5.2.3 - 2017-09-27
348
- * Add PHPDoc for `Card`
349
-
350
- ## 5.2.2 - 2017-09-20
351
- * Fix deserialization mapping of `FileUpload` objects
352
-
353
- ## 5.2.1 - 2017-09-14
354
- * Serialized `shipping` nested attribute
355
-
356
- ## 5.2.0 - 2017-08-29
357
- * Add support for `InvalidClient` OAuth error
358
-
359
- ## 5.1.3 - 2017-08-14
360
- * Allow `address_kana` and `address_kanji` to be updated for custom accounts
361
-
362
- ## 5.1.2 - 2017-08-01
363
- * Fix documented return type of `autoPagingIterator()` (was missing namespace)
364
-
365
- ## 5.1.1 - 2017-07-03
366
- * Fix order returns to use the right URL `/v1/order_returns`
367
-
368
- ## 5.1.0 - 2017-06-30
369
- * Add support for OAuth
370
-
371
- ## 5.0.0 - 2017-06-27
372
- * `pay` on invoice now takes params as well as opts
373
-
374
- ## 4.13.0 - 2017-06-19
375
- * Add support for ephemeral keys
376
-
377
- ## 4.12.0 - 2017-06-05
378
- * Clients can implement `getUserAgentInfo()` to add additional user agent information
379
-
380
- ## 4.11.0 - 2017-06-05
381
- * Implement `Countable` for `AttachedObject` (`metadata` and `additional_owners`)
382
-
383
- ## 4.10.0 - 2017-05-25
384
- * Add support for login links
385
-
386
- ## 4.9.1 - 2017-05-10
387
- * Fix docs to include arrays on `$id` parameter for retrieve methods
388
-
389
- ## 4.9.0 - 2017-04-28
390
- * Support for checking webhook signatures
391
-
392
- ## 4.8.1 - 2017-04-24
393
- * Allow nested field `payout_schedule` to be updated
394
-
395
- ## 4.8.0 - 2017-04-20
396
- * Add `\Stripe\Stripe::setLogger()` to support an external PSR-3 compatible logger
397
-
398
- ## 4.7.0 - 2017-04-10
399
- * Add support for payouts and recipient transfers
400
-
401
- ## 4.6.0 - 2017-04-06
402
- * Please see 4.7.0 instead (no-op release)
403
-
404
- ## 4.5.1 - 2017-03-22
405
- * Remove hard dependency on cURL
406
-
407
- ## 4.5.0 - 2017-03-20
408
- * Support for detaching sources from customers
409
-
410
- ## 4.4.2 - 2017-02-27
411
- * Correct handling of `owner` parameter when updating sources
412
-
413
- ## 4.4.1 - 2017-02-24
414
- * Correct the error check on a bad JSON decoding
415
-
416
- ## 4.4.0 - 2017-01-18
417
- * Add support for updating sources
418
-
419
- ## 4.3.0 - 2016-11-30
420
- * Add support for verifying sources
421
-
422
- ## 4.2.0 - 2016-11-21
423
- * Add retrieve method for 3-D Secure resources
424
-
425
- ## 4.1.1 - 2016-10-21
426
- * Add docblock with model properties for `Plan`
427
-
428
- ## 4.1.0 - 2016-10-18
429
- * Support for 403 status codes (permission denied)
430
-
431
- ## 4.0.1 - 2016-10-17
432
- * Fix transfer reversal materialization
433
- * Fixes for some property definitions in docblocks
434
-
435
- ## 4.0.0 - 2016-09-28
436
- * Support for subscription items
437
- * Drop attempt to force TLS 1.2: please note that this could be breaking if you're using old OS distributions or packages and upgraded recently (so please make sure to test your integration!)
438
-
439
- ## 3.23.0 - 2016-09-15
440
- * Add support for Apple Pay domains
441
-
442
- ## 3.22.0 - 2016-09-13
443
- * Add `Stripe::setAppInfo` to allow plugins to register user agent information
444
-
445
- ## 3.21.0 - 2016-08-25
446
- * Add `Source` model for generic payment sources
447
-
448
- ## 3.20.0 - 2016-08-08
449
- * Add `getDeclineCode` to card errors
450
-
451
- ## 3.19.0 - 2016-07-29
452
- * Opt requests directly into TLS 1.2 where OpenSSL >= 1.0.1 (see #277 for context)
453
-
454
- ## 3.18.0 - 2016-07-28
455
- * Add new `STATUS_` constants for subscriptions
456
-
457
- ## 3.17.1 - 2016-07-28
458
- * Fix auto-paging iterator so that it plays nicely with `iterator_to_array`
459
-
460
- ## 3.17.0 - 2016-07-14
461
- * Add field annotations to model classes for better editor hinting
462
-
463
- ## 3.16.0 - 2016-07-12
464
- * Add `ThreeDSecure` model for 3-D secure payments
465
-
466
- ## 3.15.0 - 2016-06-29
467
- * Add static `update` method to all resources that can be changed.
468
-
469
- ## 3.14.3 - 2016-06-20
470
- * Make sure that cURL never sends `Expects: 100-continue`, even on large request bodies
471
-
472
- ## 3.14.2 - 2016-06-03
473
- * Add `inventory` under `SKU` to list of keys that have nested data and can be updated
474
-
475
- ## 3.14.1 - 2016-05-27
476
- * Fix some inconsistencies in PHPDoc
477
-
478
- ## 3.14.0 - 2016-05-25
479
- * Add support for returning Relay orders
480
-
481
- ## 3.13.0 - 2016-05-04
482
- * Add `list`, `create`, `update`, `retrieve`, and `delete` methods to the Subscription class
483
-
484
- ## 3.12.1 - 2016-04-07
485
- * Additional check on value arrays for some extra safety
486
-
487
- ## 3.12.0 - 2016-03-31
488
- * Fix bug `refreshFrom` on `StripeObject` would not take an `$opts` array
489
- * Fix bug where `$opts` not passed to parent `save` method in `Account`
490
- * Fix bug where non-existent variable was referenced in `reverse` in `Transfer`
491
- * Update CA cert bundle for compatibility with OpenSSL versions below 1.0.1
492
-
493
- ## 3.11.0 - 2016-03-22
494
- * Allow `CurlClient` to be initialized with default `CURLOPT_*` options
495
-
496
- ## 3.10.1 - 2016-03-22
497
- * Fix bug where request params and options were ignored in `ApplicationFee`'s `refund.`
498
-
499
- ## 3.10.0 - 2016-03-15
500
- * Add `reject` on `Account` to support the new API feature
501
-
502
- ## 3.9.2 - 2016-03-04
503
- * Fix error when an object's metadata is set more than once
504
-
505
- ## 3.9.1 - 2016-02-24
506
- * Fix encoding behavior of nested arrays for requests (see #227)
507
-
508
- ## 3.9.0 - 2016-02-09
509
- * Add automatic pagination mechanism with `autoPagingIterator()`
510
- * Allow global account ID to be set with `Stripe::setAccountId()`
511
-
512
- ## 3.8.0 - 2016-02-08
513
- * Add `CountrySpec` model for looking up country payment information
514
-
515
- ## 3.7.1 - 2016-02-01
516
- * Update bundled CA certs
517
-
518
- ## 3.7.0 - 2016-01-27
519
- * Support deleting Relay products and SKUs
520
-
521
- ## 3.6.0 - 2016-01-05
522
- * Allow configuration of HTTP client timeouts
523
-
524
- ## 3.5.0 - 2015-12-01
525
- * Add a verification routine for external accounts
526
-
527
- ## 3.4.0 - 2015-09-14
528
- * Products, SKUs, and Orders -- https://stripe.com/relay
529
-
530
- ## 3.3.0 - 2015-09-11
531
- * Add support for 429 Rate Limit response
532
-
533
- ## 3.2.0 - 2015-08-17
534
- * Add refund listing and retrieval without an associated charge
535
-
536
- ## 3.1.0 - 2015-08-03
537
- * Add dispute listing and retrieval
538
- * Add support for manage account deletion
539
-
540
- ## 3.0.0 - 2015-07-28
541
- * Rename `\Stripe\Object` to `\Stripe\StripeObject` (PHP 7 compatibility)
542
- * Rename `getCode` and `getParam` in exceptions to `getStripeCode` and `getStripeParam`
543
- * Add support for calling `json_encode` on Stripe objects in PHP 5.4+
544
- * Start supporting/testing PHP 7
545
-
546
- ## 2.3.0 - 2015-07-06
547
- * Add request ID to all Stripe exceptions
548
-
549
- ## 2.2.0 - 2015-06-01
550
- * Add support for Alipay accounts as sources
551
- * Add support for bank accounts as sources (private beta)
552
- * Add support for bank accounts and cards as external_accounts on Account objects
553
-
554
- ## 2.1.4 - 2015-05-13
555
- * Fix CA certificate file path (thanks @lphilps & @matthewarkin)
556
-
557
- ## 2.1.3 - 2015-05-12
558
- * Fix to account updating to permit `tos_acceptance` and `personal_address` to be set properly
559
- * Fix to Transfer reversal creation (thanks @neatness!)
560
- * Network requests are now done through a swappable class for easier mocking
561
-
562
- ## 2.1.2 - 2015-04-10
563
- * Remove SSL cert revokation checking (all pre-Heartbleed certs have expired)
564
- * Bug fixes to account updating
565
-
566
- ## 2.1.1 - 2015-02-27
567
- * Support transfer reversals
568
-
569
- ## 2.1.0 - 2015-02-19
570
- * Support new API version (2015-02-18)
571
- * Added Bitcoin Receiever update and delete actions
572
- * Edited tests to prefer "source" over "card" as per new API version
573
-
574
- ## 2.0.1 - 2015-02-16
575
- * Fix to fetching endpoints that use a non-default baseUrl (`FileUpload`)
576
-
577
- ## 2.0.0 - 2015-02-14
578
- * Bumped minimum version to 5.3.3