WooCommerce Stripe Payment Gateway - Version 5.2.0

Version Description

  • 2021-05-19 =

  • Fix - Use get_parent method to avoid accessing order subscription property directly.

  • Fix - Orders won't transition to 'Refunded' state if refund can't be created.

  • Fix - Normalize United Kingdom and Canada postal codes for Apple Pay.

  • Fix - Subscription sign-up fees not included in total for Payment Request Button.

  • Fix - Reduce requests sent to server from stripe settings page.

  • Fix - Choose the appropriate version of the WooCommerce Admin Notes API based on which API is available.

  • Fix - Customer information is now correctly displayed in the Stripe Payments Dashboard when a new customer checks out through the WooCommerce Checkout Block.

  • Fix - Pass customer language/locale to Stripe upon creation or modification.

  • Fix - Initial price for Variable Products is now correctly shown when a Payment Request is started.

  • Add - Support for Credit Card payments (incl. 3DS payments) via WooCommerce Blocks; limited to WooCommerce Core product types.

  • Add - Support for payments (incl. 3DS payments) paid via Payment Request Buttons in WooCommerce Blocks; limited to WooCommerce Core product types.

  • Add - Support for custom and branded Payment Request Buttons when using the Cart and Checkout blocks.

  • Tweak - Should customer opt to save their card, the card is now saved after a payment has been confirmed.

See changelog for all versions.

Download this release

Release Info

Developer woothemes
Plugin Icon 128x128 WooCommerce Stripe Payment Gateway
Version 5.2.0
Comparing to
See all releases

Code changes from version 5.1.0 to 5.2.0

assets/css/stripe-styles.css CHANGED
@@ -1 +1 @@
1
- .wc-stripe-elements-field,.wc-stripe-iban-element-field{border:1px solid #ddd;margin:5px 0;padding:5px;background-color:#fff;outline:0}#payment .methods li.woocommerce-SavedPaymentMethods-token label{display:inline}#payment .methods li.woocommerce-SavedPaymentMethods-new label{display:inline}#add_payment_method #payment ul.payment_methods li img.stripe-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-icon{max-width:40px;padding-left:3px;margin:0}#add_payment_method #payment ul.payment_methods li img.stripe-bancontact-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-bancontact-icon{max-height:65px;max-width:45px}#add_payment_method #payment ul.payment_methods li img.stripe-ideal-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-ideal-icon{max-height:35px}#add_payment_method #payment ul.payment_methods li img.stripe-p24-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-p24-icon{max-width:65px}#add_payment_method #payment ul.payment_methods li img.stripe-alipay-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-alipay-icon{max-width:50px}#add_payment_method #payment ul.payment_methods li img.stripe-sofort-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-sofort-icon{max-width:55px}#add_payment_method #payment ul.payment_methods li img.stripe-sepa-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-sepa-icon{max-width:50px}#add_payment_method #payment ul.payment_methods li img.stripe-multibanco-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-multibanco-icon{max-height:30px}#add_payment_method #payment ul.payment_methods li img.stripe-eps-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-eps-icon{max-height:30px}#add_payment_method #payment ul.payment_methods li img.stripe-giropay-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-giropay-icon{max-width:50px}#add_payment_method #payment ul.payment_methods li .stripe-credit-card-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-credit-card-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/credit-card.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-visa-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-visa-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/visa.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-amex-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-amex-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/amex.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-diners-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-diners-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/diners.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-discover-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-discover-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/discover.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-jcb-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-jcb-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/jcb.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-maestro-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-maestro-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/maestro.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-mastercard-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-mastercard-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/mastercard.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods .stripe-card-group,.woocommerce-checkout #payment ul.payment_methods .stripe-card-group{position:relative}.woocommerce-SavedPaymentMethods-token .stripe-source-errors .woocommerce-error{margin-top:1em;margin-bottom:2em}#wc-stripe-custom-button{display:block;width:100%}.gpay-button{background-origin:content-box;background-position:center center;background-repeat:no-repeat;background-size:contain;border:0;border-radius:4px;box-shadow:rgba(60,64,67,.3) 0 1px 1px 0,rgba(60,64,67,.15) 0 1px 3px 1px;cursor:pointer;height:40px;min-height:40px;padding:11px 24px;width:100%}.gpay-button.light{width:calc(100% - 3px);background-color:#fff}.gpay-button.light:active{background-color:#fff}.gpay-button.light:hover{background-color:#f8f8f8}.gpay-button.light:focus{box-shadow:#e8e8e8 0 1px 1px 0,#e8e8e8 0 1px 3px;outline:0}.gpay-button.dark{background-color:#000;box-shadow:none;padding:12px 24px 10px}.gpay-button.dark:active{background-color:#5f6368}.gpay-button.dark:hover{background-color:#3c4043}.gpay-button.dark:focus{box-shadow:#5f6368 0 1px 1px 0,#5f6368 0 1px 3px;outline:0}.gpay-button.short.light{background-image:url(https://www.gstatic.com/instantbuy/svg/light_gpay.svg)}.gpay-button.short.dark{background-image:url(https://www.gstatic.com/instantbuy/svg/dark_gpay.svg)}
1
+ .wc-stripe-elements-field,.wc-stripe-iban-element-field{border:1px solid #ddd;margin:5px 0;padding:5px;background-color:#fff;outline:0}#payment .methods li.woocommerce-SavedPaymentMethods-token label{display:inline}#payment .methods li.woocommerce-SavedPaymentMethods-new label{display:inline}#add_payment_method #payment ul.payment_methods li img.stripe-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-icon{max-width:40px;padding-left:3px;margin:0}#add_payment_method #payment ul.payment_methods li img.stripe-bancontact-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-bancontact-icon{max-height:65px;max-width:45px}#add_payment_method #payment ul.payment_methods li img.stripe-ideal-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-ideal-icon{max-height:35px}#add_payment_method #payment ul.payment_methods li img.stripe-p24-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-p24-icon{max-width:65px}#add_payment_method #payment ul.payment_methods li img.stripe-alipay-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-alipay-icon{max-width:50px}#add_payment_method #payment ul.payment_methods li img.stripe-sofort-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-sofort-icon{max-width:55px}#add_payment_method #payment ul.payment_methods li img.stripe-sepa-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-sepa-icon{max-width:50px}#add_payment_method #payment ul.payment_methods li img.stripe-multibanco-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-multibanco-icon{max-height:30px}#add_payment_method #payment ul.payment_methods li img.stripe-eps-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-eps-icon{max-height:30px}#add_payment_method #payment ul.payment_methods li img.stripe-giropay-icon,.woocommerce-checkout #payment ul.payment_methods li img.stripe-giropay-icon{max-width:50px}#add_payment_method #payment ul.payment_methods li .stripe-credit-card-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-credit-card-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/credit-card.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-visa-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-visa-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/visa.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-amex-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-amex-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/amex.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-diners-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-diners-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/diners.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-discover-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-discover-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/discover.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-jcb-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-jcb-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/jcb.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-maestro-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-maestro-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/maestro.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods li .stripe-mastercard-brand,.woocommerce-checkout #payment ul.payment_methods li .stripe-mastercard-brand{position:absolute;top:50%;margin-top:-10px;right:10px;background:no-repeat url(../images/mastercard.svg);display:block;width:30px;height:24px}#add_payment_method #payment ul.payment_methods .stripe-card-group,.woocommerce-checkout #payment ul.payment_methods .stripe-card-group{position:relative}.woocommerce-SavedPaymentMethods-token .stripe-source-errors .woocommerce-error{margin-top:1em;margin-bottom:2em}#wc-stripe-custom-button{display:block;width:100%}.gpay-button{background-origin:content-box;background-position:center center;background-repeat:no-repeat;background-size:contain;border:0;border-radius:4px;cursor:pointer;height:40px;min-height:40px;padding:11px 24px;width:100%}.gpay-button.light{width:calc(100% - 3px);background-color:#fff;margin:2px 0 3px 0}.gpay-button.light:active{background-color:#fff}.gpay-button.light:hover{background-color:#f8f8f8}.gpay-button.light:focus{box-shadow:#e8e8e8 0 1px 1px 0,#e8e8e8 0 1px 3px;outline:0}.gpay-button.light-outline{width:calc(100% - 3px);background-color:#fff;box-shadow:rgba(60,64,67,.3) 0 1px 1px 0,rgba(60,64,67,.15) 0 1px 3px 1px;margin:2px 0 3px 0}.gpay-button.light-outline:active{background-color:#fff}.gpay-button.light-outline:hover{background-color:#f8f8f8}.gpay-button.light-outline:focus{box-shadow:#e8e8e8 0 1px 1px 0,#e8e8e8 0 1px 3px;outline:0}.gpay-button.dark{background-color:#000;padding:12px 24px 10px}.gpay-button.dark:active{background-color:#5f6368}.gpay-button.dark:hover{background-color:#3c4043}.gpay-button.dark:focus{box-shadow:#5f6368 0 1px 1px 0,#5f6368 0 1px 3px;outline:0}.gpay-button.short.light,.gpay-button.short.light-outline{background-image:url(https://www.gstatic.com/instantbuy/svg/light_gpay.svg)}.gpay-button.short.dark{background-image:url(https://www.gstatic.com/instantbuy/svg/dark_gpay.svg)}
assets/css/stripe-styles.scss CHANGED
@@ -1,76 +1,191 @@
1
- .wc-stripe-elements-field, .wc-stripe-iban-element-field { border:1px solid #ddd; margin:5px 0; padding:5px; background-color:#fff; outline:0; }
2
- #payment .methods li.woocommerce-SavedPaymentMethods-token label { display: inline; }
3
- #payment .methods li.woocommerce-SavedPaymentMethods-new label { display: inline; }
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-icon,
6
- #add_payment_method #payment ul.payment_methods li img.stripe-icon { max-width: 40px; padding-left: 3px; margin: 0; }
 
 
 
 
7
 
8
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-bancontact-icon,
9
- #add_payment_method #payment ul.payment_methods li img.stripe-bancontact-icon { max-height: 65px; max-width: 45px; }
 
 
 
10
 
11
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-ideal-icon,
12
- #add_payment_method #payment ul.payment_methods li img.stripe-ideal-icon { max-height: 35px; }
 
 
13
 
14
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-p24-icon,
15
- #add_payment_method #payment ul.payment_methods li img.stripe-p24-icon { max-width: 65px; }
 
 
16
 
17
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-alipay-icon,
18
- #add_payment_method #payment ul.payment_methods li img.stripe-alipay-icon { max-width: 50px; }
 
 
19
 
20
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-sofort-icon,
21
- #add_payment_method #payment ul.payment_methods li img.stripe-sofort-icon { max-width: 55px; }
 
 
22
 
23
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-sepa-icon,
24
- #add_payment_method #payment ul.payment_methods li img.stripe-sepa-icon { max-width: 50px; }
 
 
25
 
26
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-multibanco-icon,
27
- #add_payment_method #payment ul.payment_methods li img.stripe-multibanco-icon { max-height: 30px; }
 
 
28
 
29
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-eps-icon,
30
- #add_payment_method #payment ul.payment_methods li img.stripe-eps-icon { max-height: 30px; }
 
 
31
 
32
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-giropay-icon,
33
- #add_payment_method #payment ul.payment_methods li img.stripe-giropay-icon { max-width: 50px; }
 
 
34
 
35
  .woocommerce-checkout #payment ul.payment_methods li .stripe-credit-card-brand,
36
- #add_payment_method #payment ul.payment_methods li .stripe-credit-card-brand { position: absolute; top: 50%; margin-top: -10px; right: 10px; background: no-repeat url( '../images/credit-card.svg' ); display: block; width: 30px; height: 24px; }
 
 
 
 
 
 
 
 
 
37
 
38
  .woocommerce-checkout #payment ul.payment_methods li .stripe-visa-brand,
39
- #add_payment_method #payment ul.payment_methods li .stripe-visa-brand { position: absolute; top: 50%; margin-top: -10px; right: 10px; background: no-repeat url( '../images/visa.svg' ); display: block; width: 30px; height: 24px; }
 
 
 
 
 
 
 
 
 
40
 
41
  .woocommerce-checkout #payment ul.payment_methods li .stripe-amex-brand,
42
- #add_payment_method #payment ul.payment_methods li .stripe-amex-brand { position: absolute; top: 50%; margin-top: -10px; right: 10px; background: no-repeat url( '../images/amex.svg' ); display: block; width: 30px; height: 24px; }
 
 
 
 
 
 
 
 
 
43
 
44
  .woocommerce-checkout #payment ul.payment_methods li .stripe-diners-brand,
45
- #add_payment_method #payment ul.payment_methods li .stripe-diners-brand { position: absolute; top: 50%; margin-top: -10px; right: 10px; background: no-repeat url( '../images/diners.svg' ); display: block; width: 30px; height: 24px; }
 
 
 
 
 
 
 
 
 
46
 
47
  .woocommerce-checkout #payment ul.payment_methods li .stripe-discover-brand,
48
- #add_payment_method #payment ul.payment_methods li .stripe-discover-brand { position: absolute; top: 50%; margin-top: -10px; right: 10px; background: no-repeat url( '../images/discover.svg' ); display: block; width: 30px; height: 24px; }
 
 
 
 
 
 
 
 
 
49
 
50
  .woocommerce-checkout #payment ul.payment_methods li .stripe-jcb-brand,
51
- #add_payment_method #payment ul.payment_methods li .stripe-jcb-brand { position: absolute; top: 50%; margin-top: -10px; right: 10px; background: no-repeat url( '../images/jcb.svg' ); display: block; width: 30px; height: 24px; }
 
 
 
 
 
 
 
 
 
52
 
53
  .woocommerce-checkout #payment ul.payment_methods li .stripe-maestro-brand,
54
- #add_payment_method #payment ul.payment_methods li .stripe-maestro-brand { position: absolute; top: 50%; margin-top: -10px; right: 10px; background: no-repeat url( '../images/maestro.svg' ); display: block; width: 30px; height: 24px; }
 
 
 
 
 
 
 
 
 
55
 
56
  .woocommerce-checkout #payment ul.payment_methods li .stripe-mastercard-brand,
57
- #add_payment_method #payment ul.payment_methods li .stripe-mastercard-brand { position: absolute; top: 50%; margin-top: -10px; right: 10px; background: no-repeat url( '../images/mastercard.svg' ); display: block; width: 30px; height: 24px; }
 
 
 
 
 
 
 
 
 
58
 
59
  .woocommerce-checkout #payment ul.payment_methods .stripe-card-group,
60
- #add_payment_method #payment ul.payment_methods .stripe-card-group { position: relative; }
 
 
61
 
62
- .woocommerce-SavedPaymentMethods-token .stripe-source-errors .woocommerce-error { margin-top: 1em; margin-bottom: 2em; }
 
 
 
 
 
63
 
64
- #wc-stripe-custom-button { display: block; width: 100%; }
 
 
 
65
 
66
  .gpay-button {
67
  background-origin: content-box;
68
  background-position: center center;
69
  background-repeat: no-repeat;
70
  background-size: contain;
71
- border: 0px;
72
  border-radius: 4px;
73
- box-shadow: rgba(60, 64, 67, 0.3) 0px 1px 1px 0px, rgba(60, 64, 67, 0.15) 0px 1px 3px 1px;
74
  cursor: pointer;
75
  height: 40px;
76
  min-height: 40px;
@@ -81,6 +196,34 @@
81
  // account for button box-shadow when setting width
82
  width: calc( 100% - 3px );
83
  background-color: #fff;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  &:active {
85
  background-color: #fff;
86
  }
@@ -95,12 +238,11 @@
95
 
96
  &.dark {
97
  background-color: #000;
98
- box-shadow: none;
99
  padding: 12px 24px 10px;
100
  &:active {
101
  background-color: #5f6368;
102
  }
103
- &:hover{
104
  background-color: #3c4043;
105
  }
106
  &:focus {
@@ -110,11 +252,12 @@
110
  }
111
 
112
  &.short {
113
- &.light {
114
- background-image: url(https://www.gstatic.com/instantbuy/svg/light_gpay.svg);
 
115
  }
116
  &.dark {
117
- background-image: url(https://www.gstatic.com/instantbuy/svg/dark_gpay.svg);
118
  }
119
  }
120
  }
1
+ .wc-stripe-elements-field,
2
+ .wc-stripe-iban-element-field {
3
+ border: 1px solid #ddd;
4
+ margin: 5px 0;
5
+ padding: 5px;
6
+ background-color: #fff;
7
+ outline: 0;
8
+ }
9
+ #payment .methods li.woocommerce-SavedPaymentMethods-token label {
10
+ display: inline;
11
+ }
12
+ #payment .methods li.woocommerce-SavedPaymentMethods-new label {
13
+ display: inline;
14
+ }
15
 
16
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-icon,
17
+ #add_payment_method #payment ul.payment_methods li img.stripe-icon {
18
+ max-width: 40px;
19
+ padding-left: 3px;
20
+ margin: 0;
21
+ }
22
 
23
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-bancontact-icon,
24
+ #add_payment_method #payment ul.payment_methods li img.stripe-bancontact-icon {
25
+ max-height: 65px;
26
+ max-width: 45px;
27
+ }
28
 
29
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-ideal-icon,
30
+ #add_payment_method #payment ul.payment_methods li img.stripe-ideal-icon {
31
+ max-height: 35px;
32
+ }
33
 
34
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-p24-icon,
35
+ #add_payment_method #payment ul.payment_methods li img.stripe-p24-icon {
36
+ max-width: 65px;
37
+ }
38
 
39
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-alipay-icon,
40
+ #add_payment_method #payment ul.payment_methods li img.stripe-alipay-icon {
41
+ max-width: 50px;
42
+ }
43
 
44
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-sofort-icon,
45
+ #add_payment_method #payment ul.payment_methods li img.stripe-sofort-icon {
46
+ max-width: 55px;
47
+ }
48
 
49
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-sepa-icon,
50
+ #add_payment_method #payment ul.payment_methods li img.stripe-sepa-icon {
51
+ max-width: 50px;
52
+ }
53
 
54
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-multibanco-icon,
55
+ #add_payment_method #payment ul.payment_methods li img.stripe-multibanco-icon {
56
+ max-height: 30px;
57
+ }
58
 
59
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-eps-icon,
60
+ #add_payment_method #payment ul.payment_methods li img.stripe-eps-icon {
61
+ max-height: 30px;
62
+ }
63
 
64
  .woocommerce-checkout #payment ul.payment_methods li img.stripe-giropay-icon,
65
+ #add_payment_method #payment ul.payment_methods li img.stripe-giropay-icon {
66
+ max-width: 50px;
67
+ }
68
 
69
  .woocommerce-checkout #payment ul.payment_methods li .stripe-credit-card-brand,
70
+ #add_payment_method #payment ul.payment_methods li .stripe-credit-card-brand {
71
+ position: absolute;
72
+ top: 50%;
73
+ margin-top: -10px;
74
+ right: 10px;
75
+ background: no-repeat url( '../images/credit-card.svg' );
76
+ display: block;
77
+ width: 30px;
78
+ height: 24px;
79
+ }
80
 
81
  .woocommerce-checkout #payment ul.payment_methods li .stripe-visa-brand,
82
+ #add_payment_method #payment ul.payment_methods li .stripe-visa-brand {
83
+ position: absolute;
84
+ top: 50%;
85
+ margin-top: -10px;
86
+ right: 10px;
87
+ background: no-repeat url( '../images/visa.svg' );
88
+ display: block;
89
+ width: 30px;
90
+ height: 24px;
91
+ }
92
 
93
  .woocommerce-checkout #payment ul.payment_methods li .stripe-amex-brand,
94
+ #add_payment_method #payment ul.payment_methods li .stripe-amex-brand {
95
+ position: absolute;
96
+ top: 50%;
97
+ margin-top: -10px;
98
+ right: 10px;
99
+ background: no-repeat url( '../images/amex.svg' );
100
+ display: block;
101
+ width: 30px;
102
+ height: 24px;
103
+ }
104
 
105
  .woocommerce-checkout #payment ul.payment_methods li .stripe-diners-brand,
106
+ #add_payment_method #payment ul.payment_methods li .stripe-diners-brand {
107
+ position: absolute;
108
+ top: 50%;
109
+ margin-top: -10px;
110
+ right: 10px;
111
+ background: no-repeat url( '../images/diners.svg' );
112
+ display: block;
113
+ width: 30px;
114
+ height: 24px;
115
+ }
116
 
117
  .woocommerce-checkout #payment ul.payment_methods li .stripe-discover-brand,
118
+ #add_payment_method #payment ul.payment_methods li .stripe-discover-brand {
119
+ position: absolute;
120
+ top: 50%;
121
+ margin-top: -10px;
122
+ right: 10px;
123
+ background: no-repeat url( '../images/discover.svg' );
124
+ display: block;
125
+ width: 30px;
126
+ height: 24px;
127
+ }
128
 
129
  .woocommerce-checkout #payment ul.payment_methods li .stripe-jcb-brand,
130
+ #add_payment_method #payment ul.payment_methods li .stripe-jcb-brand {
131
+ position: absolute;
132
+ top: 50%;
133
+ margin-top: -10px;
134
+ right: 10px;
135
+ background: no-repeat url( '../images/jcb.svg' );
136
+ display: block;
137
+ width: 30px;
138
+ height: 24px;
139
+ }
140
 
141
  .woocommerce-checkout #payment ul.payment_methods li .stripe-maestro-brand,
142
+ #add_payment_method #payment ul.payment_methods li .stripe-maestro-brand {
143
+ position: absolute;
144
+ top: 50%;
145
+ margin-top: -10px;
146
+ right: 10px;
147
+ background: no-repeat url( '../images/maestro.svg' );
148
+ display: block;
149
+ width: 30px;
150
+ height: 24px;
151
+ }
152
 
153
  .woocommerce-checkout #payment ul.payment_methods li .stripe-mastercard-brand,
154
+ #add_payment_method #payment ul.payment_methods li .stripe-mastercard-brand {
155
+ position: absolute;
156
+ top: 50%;
157
+ margin-top: -10px;
158
+ right: 10px;
159
+ background: no-repeat url( '../images/mastercard.svg' );
160
+ display: block;
161
+ width: 30px;
162
+ height: 24px;
163
+ }
164
 
165
  .woocommerce-checkout #payment ul.payment_methods .stripe-card-group,
166
+ #add_payment_method #payment ul.payment_methods .stripe-card-group {
167
+ position: relative;
168
+ }
169
 
170
+ .woocommerce-SavedPaymentMethods-token
171
+ .stripe-source-errors
172
+ .woocommerce-error {
173
+ margin-top: 1em;
174
+ margin-bottom: 2em;
175
+ }
176
 
177
+ #wc-stripe-custom-button {
178
+ display: block;
179
+ width: 100%;
180
+ }
181
 
182
  .gpay-button {
183
  background-origin: content-box;
184
  background-position: center center;
185
  background-repeat: no-repeat;
186
  background-size: contain;
187
+ border: 0;
188
  border-radius: 4px;
 
189
  cursor: pointer;
190
  height: 40px;
191
  min-height: 40px;
196
  // account for button box-shadow when setting width
197
  width: calc( 100% - 3px );
198
  background-color: #fff;
199
+
200
+ // Add vertical margin to make box-shadow visible in blocks.
201
+ margin: 2px 0 3px 0;
202
+
203
+ &:active {
204
+ background-color: #fff;
205
+ }
206
+ &:hover {
207
+ background-color: #f8f8f8;
208
+ }
209
+ &:focus {
210
+ box-shadow: #e8e8e8 0 1px 1px 0, #e8e8e8 0 1px 3px;
211
+ outline: 0;
212
+ }
213
+ }
214
+
215
+ &.light-outline {
216
+ // account for button box-shadow when setting width
217
+ width: calc( 100% - 3px );
218
+ background-color: #fff;
219
+
220
+ // The box-shadow forms the outline and as such is always on.
221
+ box-shadow: rgba( 60, 64, 67, 0.3 ) 0px 1px 1px 0,
222
+ rgba( 60, 64, 67, 0.15 ) 0 1px 3px 1px;
223
+
224
+ // Add vertical margin to make box-shadow visible in blocks.
225
+ margin: 2px 0 3px 0;
226
+
227
  &:active {
228
  background-color: #fff;
229
  }
238
 
239
  &.dark {
240
  background-color: #000;
 
241
  padding: 12px 24px 10px;
242
  &:active {
243
  background-color: #5f6368;
244
  }
245
+ &:hover {
246
  background-color: #3c4043;
247
  }
248
  &:focus {
252
  }
253
 
254
  &.short {
255
+ &.light,
256
+ &.light-outline {
257
+ background-image: url( https://www.gstatic.com/instantbuy/svg/light_gpay.svg );
258
  }
259
  &.dark {
260
+ background-image: url( https://www.gstatic.com/instantbuy/svg/dark_gpay.svg );
261
  }
262
  }
263
  }
assets/js/stripe-admin.js CHANGED
@@ -129,22 +129,10 @@ jQuery( function( $ ) {
129
  // server time is off from browser time by > 4 minutes.
130
  var timeDifference = Date.now() / 1000 - wc_stripe_settings_params.time;
131
  var isTimeOutOfSync = Math.abs( timeDifference ) > 4 * 60;
132
- $( '#woocommerce_stripe_test_webhook_secret, #woocommerce_stripe_webhook_secret' )
133
- .on( 'change input', function() {
134
- var $td = $( this ).closest( 'td' );
135
- var $warning = $td.find( '.webhook_secret_time_sync_warning' );
136
- var hasWebhookSecretValue = $( this ).val().length > 0;
137
-
138
- if ( hasWebhookSecretValue ){
139
- var isWarningShown = $warning.length > 0;
140
- if ( isTimeOutOfSync && ! isWarningShown ) {
141
- $td.append( '<p class="webhook_secret_time_sync_warning">' + wc_stripe_settings_params.i18n_out_of_sync + '</p>' );
142
- }
143
- } else {
144
- $warning.remove();
145
- }
146
- } )
147
- .change();
148
  }
149
  };
150
 
129
  // server time is off from browser time by > 4 minutes.
130
  var timeDifference = Date.now() / 1000 - wc_stripe_settings_params.time;
131
  var isTimeOutOfSync = Math.abs( timeDifference ) > 4 * 60;
132
+ if ( isTimeOutOfSync ) {
133
+ var $td = $( '#woocommerce_stripe_test_webhook_secret, #woocommerce_stripe_webhook_secret' ).closest( 'td' );
134
+ $td.append( '<p>' + wc_stripe_settings_params.i18n_out_of_sync + '</p>' );
135
+ }
 
 
 
 
 
 
 
 
 
 
 
 
136
  }
137
  };
138
 
assets/js/stripe-admin.min.js CHANGED
@@ -1 +1 @@
1
- jQuery(function(i){"use strict";var e={isTestMode:function(){return i("#woocommerce_stripe_testmode").is(":checked")},getSecretKey:function(){return e.isTestMode()?i("#woocommerce_stripe_test_secret_key").val():i("#woocommerce_stripe_secret_key").val()},init:function(){i(document.body).on("change","#woocommerce_stripe_testmode",function(){var e=i("#woocommerce_stripe_test_secret_key").parents("tr").eq(0),t=i("#woocommerce_stripe_test_publishable_key").parents("tr").eq(0),o=i("#woocommerce_stripe_test_webhook_secret").parents("tr").eq(0),s=i("#woocommerce_stripe_secret_key").parents("tr").eq(0),r=i("#woocommerce_stripe_publishable_key").parents("tr").eq(0),c=i("#woocommerce_stripe_webhook_secret").parents("tr").eq(0);i(this).is(":checked")?(e.show(),t.show(),o.show(),s.hide(),r.hide(),c.hide()):(e.hide(),t.hide(),o.hide(),s.show(),r.show(),c.show())}),i("#woocommerce_stripe_testmode").trigger("change"),i("#woocommerce_stripe_payment_request").on("change",function(){i(this).is(":checked")?i("#woocommerce_stripe_payment_request_button_theme, #woocommerce_stripe_payment_request_button_type, #woocommerce_stripe_payment_request_button_height").closest("tr").show():i("#woocommerce_stripe_payment_request_button_theme, #woocommerce_stripe_payment_request_button_type, #woocommerce_stripe_payment_request_button_height").closest("tr").hide()}).trigger("change"),i("#woocommerce_stripe_payment_request_button_type").on("change",function(){"custom"===i(this).val()?i("#woocommerce_stripe_payment_request_button_label").closest("tr").show():i("#woocommerce_stripe_payment_request_button_label").closest("tr").hide()}).trigger("change"),i("#woocommerce_stripe_payment_request_button_type").on("change",function(){"branded"===i(this).val()?i("#woocommerce_stripe_payment_request_button_branded_type").closest("tr").show():i("#woocommerce_stripe_payment_request_button_branded_type").closest("tr").hide()}).trigger("change"),i(".wc-stripe-3ds-missing").each(function(){var e=i(this);e.find(".notice-dismiss").on("click.wc-stripe-dismiss-notice",function(){i.ajax({type:"head",url:window.location.href+"&stripe_dismiss_3ds="+e.data("nonce")})})}),i("#woocommerce_stripe_test_secret_key, #woocommerce_stripe_secret_key, #woocommerce_stripe_test_webhook_secret, #woocommerce_stripe_webhook_secret").after('<button class="wc-stripe-toggle-secret" style="height: 30px; margin-left: 2px; cursor: pointer"><span class="dashicons dashicons-visibility"></span></button>'),i(".wc-stripe-toggle-secret").on("click",function(e){e.preventDefault();var t=i(this).closest("button").find(".dashicons"),o=i(this).closest("tr").find(".input-text");"text"==o.attr("type")?(o.attr("type","password"),t.removeClass("dashicons-hidden"),t.addClass("dashicons-visibility")):(o.attr("type","text"),t.removeClass("dashicons-visibility"),t.addClass("dashicons-hidden"))}),i("form").find("input, select").on("change input",function e(){i("#wc_stripe_connect_button").addClass("disabled"),i("#wc_stripe_connect_button").on("click",function(){return!1}),i("#woocommerce_stripe_api_credentials").next("p").append(" (Please save changes before selecting this button.)"),i("form").find("input, select").off("change input",e)});var e=Date.now()/1e3-wc_stripe_settings_params.time,s=240<Math.abs(e);i("#woocommerce_stripe_test_webhook_secret, #woocommerce_stripe_webhook_secret").on("change input",function(){var e=i(this).closest("td"),t=e.find(".webhook_secret_time_sync_warning");if(0<i(this).val().length){var o=0<t.length;s&&!o&&e.append('<p class="webhook_secret_time_sync_warning">'+wc_stripe_settings_params.i18n_out_of_sync+"</p>")}else t.remove()}).change()}};e.init()});
1
+ jQuery(function(i){"use strict";var e={isTestMode:function(){return i("#woocommerce_stripe_testmode").is(":checked")},getSecretKey:function(){return(e.isTestMode()?i("#woocommerce_stripe_test_secret_key"):i("#woocommerce_stripe_secret_key")).val()},init:function(){i(document.body).on("change","#woocommerce_stripe_testmode",function(){var e=i("#woocommerce_stripe_test_secret_key").parents("tr").eq(0),t=i("#woocommerce_stripe_test_publishable_key").parents("tr").eq(0),o=i("#woocommerce_stripe_test_webhook_secret").parents("tr").eq(0),s=i("#woocommerce_stripe_secret_key").parents("tr").eq(0),r=i("#woocommerce_stripe_publishable_key").parents("tr").eq(0),c=i("#woocommerce_stripe_webhook_secret").parents("tr").eq(0);i(this).is(":checked")?(e.show(),t.show(),o.show(),s.hide(),r.hide(),c.hide()):(e.hide(),t.hide(),o.hide(),s.show(),r.show(),c.show())}),i("#woocommerce_stripe_testmode").trigger("change"),i("#woocommerce_stripe_payment_request").on("change",function(){i(this).is(":checked")?i("#woocommerce_stripe_payment_request_button_theme, #woocommerce_stripe_payment_request_button_type, #woocommerce_stripe_payment_request_button_height").closest("tr").show():i("#woocommerce_stripe_payment_request_button_theme, #woocommerce_stripe_payment_request_button_type, #woocommerce_stripe_payment_request_button_height").closest("tr").hide()}).trigger("change"),i("#woocommerce_stripe_payment_request_button_type").on("change",function(){"custom"===i(this).val()?i("#woocommerce_stripe_payment_request_button_label").closest("tr").show():i("#woocommerce_stripe_payment_request_button_label").closest("tr").hide()}).trigger("change"),i("#woocommerce_stripe_payment_request_button_type").on("change",function(){"branded"===i(this).val()?i("#woocommerce_stripe_payment_request_button_branded_type").closest("tr").show():i("#woocommerce_stripe_payment_request_button_branded_type").closest("tr").hide()}).trigger("change"),i(".wc-stripe-3ds-missing").each(function(){var e=i(this);e.find(".notice-dismiss").on("click.wc-stripe-dismiss-notice",function(){i.ajax({type:"head",url:window.location.href+"&stripe_dismiss_3ds="+e.data("nonce")})})}),i("#woocommerce_stripe_test_secret_key, #woocommerce_stripe_secret_key, #woocommerce_stripe_test_webhook_secret, #woocommerce_stripe_webhook_secret").after('<button class="wc-stripe-toggle-secret" style="height: 30px; margin-left: 2px; cursor: pointer"><span class="dashicons dashicons-visibility"></span></button>'),i(".wc-stripe-toggle-secret").on("click",function(e){e.preventDefault();var t=i(this).closest("button").find(".dashicons"),e=i(this).closest("tr").find(".input-text");"text"==e.attr("type")?(e.attr("type","password"),t.removeClass("dashicons-hidden"),t.addClass("dashicons-visibility")):(e.attr("type","text"),t.removeClass("dashicons-visibility"),t.addClass("dashicons-hidden"))}),i("form").find("input, select").on("change input",function e(){i("#wc_stripe_connect_button").addClass("disabled"),i("#wc_stripe_connect_button").on("click",function(){return!1}),i("#woocommerce_stripe_api_credentials").next("p").append(" (Please save changes before selecting this button.)"),i("form").find("input, select").off("change input",e)});var e=Date.now()/1e3-wc_stripe_settings_params.time;240<Math.abs(e)&&i("#woocommerce_stripe_test_webhook_secret, #woocommerce_stripe_webhook_secret").closest("td").append("<p>"+wc_stripe_settings_params.i18n_out_of_sync+"</p>")}};e.init()});
assets/js/stripe-payment-request.js CHANGED
@@ -2,7 +2,9 @@
2
  jQuery( function( $ ) {
3
  'use strict';
4
 
5
- var stripe = Stripe( wc_stripe_payment_request_params.stripe.key ),
 
 
6
  paymentRequestType;
7
 
8
  /**
@@ -542,7 +544,7 @@ jQuery( function( $ ) {
542
  },
543
 
544
  createGooglePayButton: function () {
545
- var allowedThemes = [ 'dark', 'light' ];
546
  var allowedTypes = [ 'short', 'long' ];
547
 
548
  var theme = wc_stripe_payment_request_params.button.theme;
@@ -550,14 +552,15 @@ jQuery( function( $ ) {
550
  var locale = wc_stripe_payment_request_params.button.locale;
551
  var height = wc_stripe_payment_request_params.button.height;
552
  theme = allowedThemes.includes( theme ) ? theme : 'light';
 
553
  type = allowedTypes.includes( type ) ? type : 'long';
554
 
555
  var button = $( '<button type="button" id="wc-stripe-branded-button" aria-label="Google Pay" class="gpay-button"></button>' );
556
  button.css( 'height', height + 'px' );
557
  button.addClass( theme + ' ' + type );
558
  if ( 'long' === type ) {
559
- var url = 'https://www.gstatic.com/instantbuy/svg/' + theme + '/' + locale + '.svg';
560
- var fallbackUrl = 'https://www.gstatic.com/instantbuy/svg/' + theme + '/en.svg';
561
  // Check if locale GPay button exists, default to en if not
562
  setBackgroundImageWithFallback( button, url, fallbackUrl );
563
  }
@@ -610,8 +613,20 @@ jQuery( function( $ ) {
610
  }
611
  });
612
 
 
 
 
 
 
 
 
 
 
 
 
 
613
  $( document.body ).on( 'woocommerce_variation_has_changed', function () {
614
- wc_stripe_payment_request.blockPaymentRequestButton( prButton );
615
 
616
  $.when( wc_stripe_payment_request.getSelectedProductData() ).then( function ( response ) {
617
  $.when(
@@ -620,7 +635,7 @@ jQuery( function( $ ) {
620
  displayItems: response.displayItems,
621
  } )
622
  ).then( function () {
623
- wc_stripe_payment_request.unblockPaymentRequestButton( prButton );
624
  } );
625
  });
626
  } );
@@ -628,17 +643,17 @@ jQuery( function( $ ) {
628
  // Block the payment request button as soon as an "input" event is fired, to avoid sync issues
629
  // when the customer clicks on the button before the debounced event is processed.
630
  $( '.quantity' ).on( 'input', '.qty', function() {
631
- wc_stripe_payment_request.blockPaymentRequestButton( prButton );
632
  } );
633
 
634
  $( '.quantity' ).on( 'input', '.qty', wc_stripe_payment_request.debounce( 250, function() {
635
- wc_stripe_payment_request.blockPaymentRequestButton( prButton );
636
  paymentRequestError = [];
637
 
638
  $.when( wc_stripe_payment_request.getSelectedProductData() ).then( function ( response ) {
639
  if ( response.error ) {
640
  paymentRequestError = [ response.error ];
641
- wc_stripe_payment_request.unblockPaymentRequestButton( prButton );
642
  } else {
643
  $.when(
644
  paymentRequest.update( {
@@ -646,7 +661,7 @@ jQuery( function( $ ) {
646
  displayItems: response.displayItems,
647
  } )
648
  ).then( function () {
649
- wc_stripe_payment_request.unblockPaymentRequestButton( prButton );
650
  });
651
  }
652
  } );
@@ -678,24 +693,22 @@ jQuery( function( $ ) {
678
  }
679
  },
680
 
681
- blockPaymentRequestButton: function( prButton ) {
682
  // check if element isn't already blocked before calling block() to avoid blinking overlay issues
683
  // blockUI.isBlocked is either undefined or 0 when element is not blocked
684
  if ( $( '#wc-stripe-payment-request-button' ).data( 'blockUI.isBlocked' ) ) {
685
  return;
686
  }
687
 
688
- $( '#wc-stripe-payment-request-button' ).block( { message: null } );
689
- if ( wc_stripe_payment_request.isCustomPaymentRequestButton( prButton ) ) {
690
- prButton.addClass( 'is-blocked' );
691
- }
692
  },
693
 
694
- unblockPaymentRequestButton: function( prButton ) {
695
- $( '#wc-stripe-payment-request-button' ).unblock();
696
- if ( wc_stripe_payment_request.isCustomPaymentRequestButton( prButton ) ) {
697
- prButton.removeClass( 'is-blocked' );
698
- }
699
  },
700
 
701
  /**
2
  jQuery( function( $ ) {
3
  'use strict';
4
 
5
+ var stripe = Stripe( wc_stripe_payment_request_params.stripe.key, {
6
+ locale: typeof wc_stripe_params !== 'undefined' ? wc_stripe_params.stripe_locale : 'auto',
7
+ } ),
8
  paymentRequestType;
9
 
10
  /**
544
  },
545
 
546
  createGooglePayButton: function () {
547
+ var allowedThemes = [ 'dark', 'light', 'light-outline' ];
548
  var allowedTypes = [ 'short', 'long' ];
549
 
550
  var theme = wc_stripe_payment_request_params.button.theme;
552
  var locale = wc_stripe_payment_request_params.button.locale;
553
  var height = wc_stripe_payment_request_params.button.height;
554
  theme = allowedThemes.includes( theme ) ? theme : 'light';
555
+ var gpaySvgTheme = 'dark' === theme ? 'dark' : 'light';
556
  type = allowedTypes.includes( type ) ? type : 'long';
557
 
558
  var button = $( '<button type="button" id="wc-stripe-branded-button" aria-label="Google Pay" class="gpay-button"></button>' );
559
  button.css( 'height', height + 'px' );
560
  button.addClass( theme + ' ' + type );
561
  if ( 'long' === type ) {
562
+ var url = 'https://www.gstatic.com/instantbuy/svg/' + gpaySvgTheme + '/' + locale + '.svg';
563
+ var fallbackUrl = 'https://www.gstatic.com/instantbuy/svg/' + gpaySvgTheme + '/en.svg';
564
  // Check if locale GPay button exists, default to en if not
565
  setBackgroundImageWithFallback( button, url, fallbackUrl );
566
  }
613
  }
614
  });
615
 
616
+ $( document.body ).on( 'wc_stripe_unblock_payment_request_button wc_stripe_enable_payment_request_button', function () {
617
+ wc_stripe_payment_request.unblockPaymentRequestButton();
618
+ } );
619
+
620
+ $( document.body ).on( 'wc_stripe_block_payment_request_button', function () {
621
+ wc_stripe_payment_request.blockPaymentRequestButton( 'wc_request_button_is_blocked' );
622
+ } );
623
+
624
+ $( document.body ).on( 'wc_stripe_disable_payment_request_button', function () {
625
+ wc_stripe_payment_request.blockPaymentRequestButton( 'wc_request_button_is_disabled' );
626
+ } );
627
+
628
  $( document.body ).on( 'woocommerce_variation_has_changed', function () {
629
+ $( document.body ).trigger( 'wc_stripe_block_payment_request_button' );
630
 
631
  $.when( wc_stripe_payment_request.getSelectedProductData() ).then( function ( response ) {
632
  $.when(
635
  displayItems: response.displayItems,
636
  } )
637
  ).then( function () {
638
+ $( document.body ).trigger( 'wc_stripe_unblock_payment_request_button' );
639
  } );
640
  });
641
  } );
643
  // Block the payment request button as soon as an "input" event is fired, to avoid sync issues
644
  // when the customer clicks on the button before the debounced event is processed.
645
  $( '.quantity' ).on( 'input', '.qty', function() {
646
+ $( document.body ).trigger( 'wc_stripe_block_payment_request_button' );
647
  } );
648
 
649
  $( '.quantity' ).on( 'input', '.qty', wc_stripe_payment_request.debounce( 250, function() {
650
+ $( document.body ).trigger( 'wc_stripe_block_payment_request_button' );
651
  paymentRequestError = [];
652
 
653
  $.when( wc_stripe_payment_request.getSelectedProductData() ).then( function ( response ) {
654
  if ( response.error ) {
655
  paymentRequestError = [ response.error ];
656
+ $( document.body ).trigger( 'wc_stripe_unblock_payment_request_button' );
657
  } else {
658
  $.when(
659
  paymentRequest.update( {
661
  displayItems: response.displayItems,
662
  } )
663
  ).then( function () {
664
+ $( document.body ).trigger( 'wc_stripe_unblock_payment_request_button' );
665
  });
666
  }
667
  } );
693
  }
694
  },
695
 
696
+ blockPaymentRequestButton: function( cssClassname ) {
697
  // check if element isn't already blocked before calling block() to avoid blinking overlay issues
698
  // blockUI.isBlocked is either undefined or 0 when element is not blocked
699
  if ( $( '#wc-stripe-payment-request-button' ).data( 'blockUI.isBlocked' ) ) {
700
  return;
701
  }
702
 
703
+ $( '#wc-stripe-payment-request-button' )
704
+ .addClass( cssClassname )
705
+ .block( { message: null } );
 
706
  },
707
 
708
+ unblockPaymentRequestButton: function() {
709
+ $( '#wc-stripe-payment-request-button' )
710
+ .removeClass( ['wc_request_button_is_blocked', 'wc_request_button_is_disabled'] )
711
+ .unblock();
 
712
  },
713
 
714
  /**
assets/js/stripe-payment-request.min.js CHANGED
@@ -1 +1 @@
1
- jQuery(function(i){"use strict";var o,u=Stripe(wc_stripe_payment_request_params.stripe.key),p={getAjaxURL:function(t){return wc_stripe_payment_request_params.ajax_url.toString().replace("%%endpoint%%","wc_stripe_"+t)},getCartDetails:function(){var t={security:wc_stripe_payment_request_params.nonce.payment};i.ajax({type:"POST",data:t,url:p.getAjaxURL("get_cart_details"),success:function(t){p.startPaymentRequest(t)}})},getAttributes:function(){var t=i(".variations_form").find(".variations select"),a={},n=0,r=0;return t.each(function(){var t=i(this).data("attribute_name")||i(this).attr("name"),e=i(this).val()||"";0<e.length&&r++,n++,a[t]=e}),{count:n,chosenCount:r,data:a}},processSource:function(t,e){var a=p.getOrderData(t,e);return i.ajax({type:"POST",data:a,dataType:"json",url:p.getAjaxURL("create_order")})},getOrderData:function(t,e){var a=t.source,n=a.owner.email,r=a.owner.phone,s=a.owner.address,i=a.owner.name,o=t.shippingAddress,u={_wpnonce:wc_stripe_payment_request_params.nonce.checkout,billing_first_name:null!==i?i.split(" ").slice(0,1).join(" "):"",billing_last_name:null!==i?i.split(" ").slice(1).join(" "):"",billing_company:"",billing_email:null!==n?n:t.payerEmail,billing_phone:null!==r?r:t.payerPhone&&t.payerPhone.replace("/[() -]/g",""),billing_country:null!==s?s.country:"",billing_address_1:null!==s?s.line1:"",billing_address_2:null!==s?s.line2:"",billing_city:null!==s?s.city:"",billing_state:null!==s?s.state:"",billing_postcode:null!==s?s.postal_code:"",shipping_first_name:"",shipping_last_name:"",shipping_company:"",shipping_country:"",shipping_address_1:"",shipping_address_2:"",shipping_city:"",shipping_state:"",shipping_postcode:"",shipping_method:[null===t.shippingOption?null:t.shippingOption.id],order_comments:"",payment_method:"stripe",ship_to_different_address:1,terms:1,stripe_source:a.id,payment_request_type:e};return o&&(u.shipping_first_name=o.recipient.split(" ").slice(0,1).join(" "),u.shipping_last_name=o.recipient.split(" ").slice(1).join(" "),u.shipping_company=o.organization,u.shipping_country=o.country,u.shipping_address_1=void 0===o.addressLine[0]?"":o.addressLine[0],u.shipping_address_2=void 0===o.addressLine[1]?"":o.addressLine[1],u.shipping_city=o.city,u.shipping_state=o.region,u.shipping_postcode=o.postalCode),u},getErrorMessageHTML:function(t){return i('<div class="woocommerce-error" />').text(t)},displayErrorMessage:function(t){if(i(".woocommerce-error").remove(),wc_stripe_payment_request_params.is_product_page){var e=i(".product").first();e.before(t),i("html, body").animate({scrollTop:e.prev(".woocommerce-error").offset().top},600)}else{var a=i(".shop_table.cart").closest("form");a.before(t),i("html, body").animate({scrollTop:a.prev(".woocommerce-error").offset().top},600)}},abortPayment:function(t,e){t.complete("fail"),p.displayErrorMessage(e)},completePayment:function(t,e){p.block(),t.complete("success"),window.location=e},block:function(){i.blockUI({message:null,overlayCSS:{background:"#fff",opacity:.6}})},updateShippingOptions:function(t,e){var a={security:wc_stripe_payment_request_params.nonce.shipping,country:e.country,state:e.region,postcode:e.postalCode,city:e.city,address:void 0===e.addressLine[0]?"":e.addressLine[0],address_2:void 0===e.addressLine[1]?"":e.addressLine[1],payment_request_type:o,is_product_page:wc_stripe_payment_request_params.is_product_page};return i.ajax({type:"POST",data:a,url:p.getAjaxURL("get_shipping_options")})},updateShippingDetails:function(t,e){var a={security:wc_stripe_payment_request_params.nonce.update_shipping,shipping_method:[e.id],payment_request_type:o,is_product_page:wc_stripe_payment_request_params.is_product_page};return i.ajax({type:"POST",data:a,url:p.getAjaxURL("update_shipping_method")})},addToCart:function(){var t=i(".single_add_to_cart_button").val();i(".single_variation_wrap").length&&(t=i(".single_variation_wrap").find('input[name="product_id"]').val());var n={security:wc_stripe_payment_request_params.nonce.add_to_cart,product_id:t,qty:i(".quantity .qty").val(),attributes:i(".variations_form").length?p.getAttributes().data:[]},e=i("form.cart").serializeArray();return i.each(e,function(t,e){if(/^addon-/.test(e.name))if(/\[\]$/.test(e.name)){var a=e.name.substring(0,e.name.length-2);n[a]?n[a].push(e.value):n[a]=[e.value]}else n[e.name]=e.value}),i.ajax({type:"POST",data:n,url:p.getAjaxURL("add_to_cart")})},clearCart:function(){var t={security:wc_stripe_payment_request_params.nonce.clear_cart};return i.ajax({type:"POST",data:t,url:p.getAjaxURL("clear_cart"),success:function(t){}})},getRequestOptionsFromLocal:function(){return{total:wc_stripe_payment_request_params.product.total,currency:wc_stripe_payment_request_params.checkout.currency_code,country:wc_stripe_payment_request_params.checkout.country_code,requestPayerName:!0,requestPayerEmail:!0,requestPayerPhone:wc_stripe_payment_request_params.checkout.needs_payer_phone,requestShipping:wc_stripe_payment_request_params.product.requestShipping,displayItems:wc_stripe_payment_request_params.product.displayItems}},startPaymentRequest:function(t){var a,e;a=wc_stripe_payment_request_params.is_product_page?e=p.getRequestOptionsFromLocal():(e={total:t.order_data.total,currency:t.order_data.currency,country:t.order_data.country_code,requestPayerName:!0,requestPayerEmail:!0,requestPayerPhone:wc_stripe_payment_request_params.checkout.needs_payer_phone,requestShipping:!!t.shipping_required,displayItems:t.order_data.displayItems},t.order_data),"PR"===e.country&&(e.country="US");try{var n=u.paymentRequest(e),r=u.elements({locale:wc_stripe_payment_request_params.button.locale}),s=p.createPaymentRequestButton(r,n);n.canMakePayment().then(function(t){t&&(o=t.applePay?"apple_pay":"payment_request_api",p.attachPaymentRequestButtonEventListeners(s,n),p.showPaymentRequestButton(s))}),n.on("shippingaddresschange",function(e){i.when(p.updateShippingOptions(a,e.shippingAddress)).then(function(t){e.updateWith({status:t.result,shippingOptions:t.shipping_options,total:t.total,displayItems:t.displayItems})})}),n.on("shippingoptionchange",function(e){i.when(p.updateShippingDetails(a,e.shippingOption)).then(function(t){"success"===t.result&&e.updateWith({status:"success",total:t.total,displayItems:t.displayItems}),"fail"===t.result&&e.updateWith({status:"fail"})})}),n.on("source",function(e){"no"===wc_stripe_payment_request_params.stripe.allow_prepaid_card&&"prepaid"===e.source.card.funding?p.abortPayment(e,p.getErrorMessageHTML(wc_stripe_payment_request_params.i18n.no_prepaid_card)):i.when(p.processSource(e,o)).then(function(t){"success"===t.result?p.completePayment(e,t.redirect):p.abortPayment(e,t.messages)})})}catch(t){console.error(t)}},getSelectedProductData:function(){var t=i(".single_add_to_cart_button").val();i(".single_variation_wrap").length&&(t=i(".single_variation_wrap").find('input[name="product_id"]').val());var e=(i("#product-addons-total").data("price_data")||[]).reduce(function(t,e){return t+e.cost},0),a={security:wc_stripe_payment_request_params.nonce.get_selected_product_data,product_id:t,qty:i(".quantity .qty").val(),attributes:i(".variations_form").length?p.getAttributes().data:[],addon_value:e};return i.ajax({type:"POST",data:a,url:p.getAjaxURL("get_selected_product_data")})},debounce:function(n,r,s){var i;return function(){var t=this,e=arguments,a=s&&!i;clearTimeout(i),i=setTimeout(function(){i=null,s||r.apply(t,e)},n),a&&r.apply(t,e)}},createPaymentRequestButton:function(t,e){var a;if(wc_stripe_payment_request_params.button.is_custom&&(a=i(wc_stripe_payment_request_params.button.css_selector)).length)return a.data("isCustom",!0),a;if(wc_stripe_payment_request_params.button.is_branded){if(p.shouldUseGooglePayBrand())return(a=p.createGooglePayButton()).data("isBranded",!0),a;wc_stripe_payment_request_params.button.type="long"===wc_stripe_payment_request_params.button.branded_type?"buy":"default"}return t.create("paymentRequestButton",{paymentRequest:e,style:{paymentRequestButton:{type:wc_stripe_payment_request_params.button.type,theme:wc_stripe_payment_request_params.button.theme,height:wc_stripe_payment_request_params.button.height+"px"}}})},isCustomPaymentRequestButton:function(t){return t&&"function"==typeof t.data&&t.data("isCustom")},isBrandedPaymentRequestButton:function(t){return t&&"function"==typeof t.data&&t.data("isBranded")},shouldUseGooglePayBrand:function(){var t=window.navigator.userAgent.toLowerCase(),e=/chrome/.test(t)&&!/edge|edg|opr|brave\//.test(t)&&"Google Inc."===window.navigator.vendor,a=e&&window.navigator.brave;return e&&!a},createGooglePayButton:function(){var t=wc_stripe_payment_request_params.button.theme,e=wc_stripe_payment_request_params.button.branded_type,a=wc_stripe_payment_request_params.button.locale,n=wc_stripe_payment_request_params.button.height;t=["dark","light"].includes(t)?t:"light",e=["short","long"].includes(e)?e:"long";var r=i('<button type="button" id="wc-stripe-branded-button" aria-label="Google Pay" class="gpay-button"></button>');r.css("height",n+"px"),r.addClass(t+" "+e),"long"===e&&function(t,e,a){t.css("background-image","url("+e+")");var n=document.createElement("img");n.onerror=function(){t.css("background-image","url("+a+")")},n.src=e}(r,"https://www.gstatic.com/instantbuy/svg/"+t+"/"+a+".svg","https://www.gstatic.com/instantbuy/svg/"+t+"/en.svg");return r},attachPaymentRequestButtonEventListeners:function(t,e){t.on("click",function(t){i("body").addClass("woocommerce-stripe-prb-clicked")}),wc_stripe_payment_request_params.is_product_page?p.attachProductPageEventListeners(t,e):p.attachCartPageEventListeners(t,e)},attachProductPageEventListeners:function(e,a){var n=[],r=i(".single_add_to_cart_button");e.on("click",function(t){return r.is(".disabled")?(t.preventDefault(),void(r.is(".wc-variation-is-unavailable")?window.alert(wc_add_to_cart_variation_params.i18n_unavailable_text):r.is(".wc-variation-selection-needed")&&window.alert(wc_add_to_cart_variation_params.i18n_make_a_selection_text))):0<n.length?(t.preventDefault(),void window.alert(n)):(p.addToCart(),void((p.isCustomPaymentRequestButton(e)||p.isBrandedPaymentRequestButton(e))&&(t.preventDefault(),a.show())))}),i(document.body).on("woocommerce_variation_has_changed",function(){p.blockPaymentRequestButton(e),i.when(p.getSelectedProductData()).then(function(t){i.when(a.update({total:t.total,displayItems:t.displayItems})).then(function(){p.unblockPaymentRequestButton(e)})})}),i(".quantity").on("input",".qty",function(){p.blockPaymentRequestButton(e)}),i(".quantity").on("input",".qty",p.debounce(250,function(){p.blockPaymentRequestButton(e),n=[],i.when(p.getSelectedProductData()).then(function(t){t.error?(n=[t.error],p.unblockPaymentRequestButton(e)):i.when(a.update({total:t.total,displayItems:t.displayItems})).then(function(){p.unblockPaymentRequestButton(e)})})}))},attachCartPageEventListeners:function(t,e){(wc_stripe_payment_request_params.button.is_custom&&p.isCustomPaymentRequestButton(t)||wc_stripe_payment_request_params.button.is_branded&&p.isBrandedPaymentRequestButton(t))&&t.on("click",function(t){t.preventDefault(),e.show()})},showPaymentRequestButton:function(t){p.isCustomPaymentRequestButton(t)?(t.addClass("is-active"),i("#wc-stripe-payment-request-wrapper, #wc-stripe-payment-request-button-separator").show()):p.isBrandedPaymentRequestButton(t)?(i("#wc-stripe-payment-request-wrapper, #wc-stripe-payment-request-button-separator").show(),i("#wc-stripe-payment-request-button").html(t)):i("#wc-stripe-payment-request-button").length&&(i("#wc-stripe-payment-request-wrapper, #wc-stripe-payment-request-button-separator").show(),t.mount("#wc-stripe-payment-request-button"))},blockPaymentRequestButton:function(t){i("#wc-stripe-payment-request-button").data("blockUI.isBlocked")||(i("#wc-stripe-payment-request-button").block({message:null}),p.isCustomPaymentRequestButton(t)&&t.addClass("is-blocked"))},unblockPaymentRequestButton:function(t){i("#wc-stripe-payment-request-button").unblock(),p.isCustomPaymentRequestButton(t)&&t.removeClass("is-blocked")},init:function(){wc_stripe_payment_request_params.is_product_page?p.startPaymentRequest(""):p.getCartDetails()}};p.init(),i(document.body).on("updated_cart_totals",function(){p.init()}),i(document.body).on("updated_checkout",function(){p.init()})});
1
+ jQuery(function(i){"use strict";var o,u=Stripe(wc_stripe_payment_request_params.stripe.key,{locale:"undefined"!=typeof wc_stripe_params?wc_stripe_params.stripe_locale:"auto"}),p={getAjaxURL:function(t){return wc_stripe_payment_request_params.ajax_url.toString().replace("%%endpoint%%","wc_stripe_"+t)},getCartDetails:function(){var t={security:wc_stripe_payment_request_params.nonce.payment};i.ajax({type:"POST",data:t,url:p.getAjaxURL("get_cart_details"),success:function(t){p.startPaymentRequest(t)}})},getAttributes:function(){var t=i(".variations_form").find(".variations select"),a={},n=0,r=0;return t.each(function(){var t=i(this).data("attribute_name")||i(this).attr("name"),e=i(this).val()||"";0<e.length&&r++,n++,a[t]=e}),{count:n,chosenCount:r,data:a}},processSource:function(t,e){e=p.getOrderData(t,e);return i.ajax({type:"POST",data:e,dataType:"json",url:p.getAjaxURL("create_order")})},getOrderData:function(t,e){var a=t.source,n=a.owner.email,r=a.owner.phone,s=a.owner.address,i=a.owner.name,o=t.shippingAddress,e={_wpnonce:wc_stripe_payment_request_params.nonce.checkout,billing_first_name:null!==i?i.split(" ").slice(0,1).join(" "):"",billing_last_name:null!==i?i.split(" ").slice(1).join(" "):"",billing_company:"",billing_email:null!==n?n:t.payerEmail,billing_phone:null!==r?r:t.payerPhone&&t.payerPhone.replace("/[() -]/g",""),billing_country:null!==s?s.country:"",billing_address_1:null!==s?s.line1:"",billing_address_2:null!==s?s.line2:"",billing_city:null!==s?s.city:"",billing_state:null!==s?s.state:"",billing_postcode:null!==s?s.postal_code:"",shipping_first_name:"",shipping_last_name:"",shipping_company:"",shipping_country:"",shipping_address_1:"",shipping_address_2:"",shipping_city:"",shipping_state:"",shipping_postcode:"",shipping_method:[null===t.shippingOption?null:t.shippingOption.id],order_comments:"",payment_method:"stripe",ship_to_different_address:1,terms:1,stripe_source:a.id,payment_request_type:e};return o&&(e.shipping_first_name=o.recipient.split(" ").slice(0,1).join(" "),e.shipping_last_name=o.recipient.split(" ").slice(1).join(" "),e.shipping_company=o.organization,e.shipping_country=o.country,e.shipping_address_1=void 0===o.addressLine[0]?"":o.addressLine[0],e.shipping_address_2=void 0===o.addressLine[1]?"":o.addressLine[1],e.shipping_city=o.city,e.shipping_state=o.region,e.shipping_postcode=o.postalCode),e},getErrorMessageHTML:function(t){return i('<div class="woocommerce-error" />').text(t)},displayErrorMessage:function(t){var e;i(".woocommerce-error").remove(),wc_stripe_payment_request_params.is_product_page?((e=i(".product").first()).before(t),i("html, body").animate({scrollTop:e.prev(".woocommerce-error").offset().top},600)):((e=i(".shop_table.cart").closest("form")).before(t),i("html, body").animate({scrollTop:e.prev(".woocommerce-error").offset().top},600))},abortPayment:function(t,e){t.complete("fail"),p.displayErrorMessage(e)},completePayment:function(t,e){p.block(),t.complete("success"),window.location=e},block:function(){i.blockUI({message:null,overlayCSS:{background:"#fff",opacity:.6}})},updateShippingOptions:function(t,e){e={security:wc_stripe_payment_request_params.nonce.shipping,country:e.country,state:e.region,postcode:e.postalCode,city:e.city,address:void 0===e.addressLine[0]?"":e.addressLine[0],address_2:void 0===e.addressLine[1]?"":e.addressLine[1],payment_request_type:o,is_product_page:wc_stripe_payment_request_params.is_product_page};return i.ajax({type:"POST",data:e,url:p.getAjaxURL("get_shipping_options")})},updateShippingDetails:function(t,e){e={security:wc_stripe_payment_request_params.nonce.update_shipping,shipping_method:[e.id],payment_request_type:o,is_product_page:wc_stripe_payment_request_params.is_product_page};return i.ajax({type:"POST",data:e,url:p.getAjaxURL("update_shipping_method")})},addToCart:function(){var t=i(".single_add_to_cart_button").val();i(".single_variation_wrap").length&&(t=i(".single_variation_wrap").find('input[name="product_id"]').val());var n={security:wc_stripe_payment_request_params.nonce.add_to_cart,product_id:t,qty:i(".quantity .qty").val(),attributes:i(".variations_form").length?p.getAttributes().data:[]},t=i("form.cart").serializeArray();return i.each(t,function(t,e){var a;/^addon-/.test(e.name)&&(/\[\]$/.test(e.name)?(a=e.name.substring(0,e.name.length-2),n[a]?n[a].push(e.value):n[a]=[e.value]):n[e.name]=e.value)}),i.ajax({type:"POST",data:n,url:p.getAjaxURL("add_to_cart")})},clearCart:function(){var t={security:wc_stripe_payment_request_params.nonce.clear_cart};return i.ajax({type:"POST",data:t,url:p.getAjaxURL("clear_cart"),success:function(t){}})},getRequestOptionsFromLocal:function(){return{total:wc_stripe_payment_request_params.product.total,currency:wc_stripe_payment_request_params.checkout.currency_code,country:wc_stripe_payment_request_params.checkout.country_code,requestPayerName:!0,requestPayerEmail:!0,requestPayerPhone:wc_stripe_payment_request_params.checkout.needs_payer_phone,requestShipping:wc_stripe_payment_request_params.product.requestShipping,displayItems:wc_stripe_payment_request_params.product.displayItems}},startPaymentRequest:function(t){var e,a=wc_stripe_payment_request_params.is_product_page?e=p.getRequestOptionsFromLocal():(e={total:t.order_data.total,currency:t.order_data.currency,country:t.order_data.country_code,requestPayerName:!0,requestPayerEmail:!0,requestPayerPhone:wc_stripe_payment_request_params.checkout.needs_payer_phone,requestShipping:!!t.shipping_required,displayItems:t.order_data.displayItems},t.order_data);"PR"===e.country&&(e.country="US");try{var n=u.paymentRequest(e),r=u.elements({locale:wc_stripe_payment_request_params.button.locale}),s=p.createPaymentRequestButton(r,n);n.canMakePayment().then(function(t){t&&(o=t.applePay?"apple_pay":"payment_request_api",p.attachPaymentRequestButtonEventListeners(s,n),p.showPaymentRequestButton(s))}),n.on("shippingaddresschange",function(e){i.when(p.updateShippingOptions(a,e.shippingAddress)).then(function(t){e.updateWith({status:t.result,shippingOptions:t.shipping_options,total:t.total,displayItems:t.displayItems})})}),n.on("shippingoptionchange",function(e){i.when(p.updateShippingDetails(a,e.shippingOption)).then(function(t){"success"===t.result&&e.updateWith({status:"success",total:t.total,displayItems:t.displayItems}),"fail"===t.result&&e.updateWith({status:"fail"})})}),n.on("source",function(e){"no"===wc_stripe_payment_request_params.stripe.allow_prepaid_card&&"prepaid"===e.source.card.funding?p.abortPayment(e,p.getErrorMessageHTML(wc_stripe_payment_request_params.i18n.no_prepaid_card)):i.when(p.processSource(e,o)).then(function(t){"success"===t.result?p.completePayment(e,t.redirect):p.abortPayment(e,t.messages)})})}catch(t){console.error(t)}},getSelectedProductData:function(){var t=i(".single_add_to_cart_button").val();i(".single_variation_wrap").length&&(t=i(".single_variation_wrap").find('input[name="product_id"]').val());var e=(i("#product-addons-total").data("price_data")||[]).reduce(function(t,e){return t+e.cost},0),e={security:wc_stripe_payment_request_params.nonce.get_selected_product_data,product_id:t,qty:i(".quantity .qty").val(),attributes:i(".variations_form").length?p.getAttributes().data:[],addon_value:e};return i.ajax({type:"POST",data:e,url:p.getAjaxURL("get_selected_product_data")})},debounce:function(n,r,s){var i;return function(){var t=this,e=arguments,a=s&&!i;clearTimeout(i),i=setTimeout(function(){i=null,s||r.apply(t,e)},n),a&&r.apply(t,e)}},createPaymentRequestButton:function(t,e){var a;if(wc_stripe_payment_request_params.button.is_custom&&(a=i(wc_stripe_payment_request_params.button.css_selector)).length)return a.data("isCustom",!0),a;if(wc_stripe_payment_request_params.button.is_branded){if(p.shouldUseGooglePayBrand())return(a=p.createGooglePayButton()).data("isBranded",!0),a;wc_stripe_payment_request_params.button.type="long"===wc_stripe_payment_request_params.button.branded_type?"buy":"default"}return t.create("paymentRequestButton",{paymentRequest:e,style:{paymentRequestButton:{type:wc_stripe_payment_request_params.button.type,theme:wc_stripe_payment_request_params.button.theme,height:wc_stripe_payment_request_params.button.height+"px"}}})},isCustomPaymentRequestButton:function(t){return t&&"function"==typeof t.data&&t.data("isCustom")},isBrandedPaymentRequestButton:function(t){return t&&"function"==typeof t.data&&t.data("isBranded")},shouldUseGooglePayBrand:function(){var t=window.navigator.userAgent.toLowerCase(),e=/chrome/.test(t)&&!/edge|edg|opr|brave\//.test(t)&&"Google Inc."===window.navigator.vendor,t=e&&window.navigator.brave;return e&&!t},createGooglePayButton:function(){var t=wc_stripe_payment_request_params.button.theme,e=wc_stripe_payment_request_params.button.branded_type,a=wc_stripe_payment_request_params.button.locale,n=wc_stripe_payment_request_params.button.height,r="dark"===(t=["dark","light","light-outline"].includes(t)?t:"light")?"dark":"light",e=["short","long"].includes(e)?e:"long",s=i('<button type="button" id="wc-stripe-branded-button" aria-label="Google Pay" class="gpay-button"></button>');return s.css("height",n+"px"),s.addClass(t+" "+e),"long"===e&&function(t,e,a){t.css("background-image","url("+e+")");var n=document.createElement("img");n.onerror=function(){t.css("background-image","url("+a+")")},n.src=e}(s,"https://www.gstatic.com/instantbuy/svg/"+r+"/"+a+".svg","https://www.gstatic.com/instantbuy/svg/"+r+"/en.svg"),s},attachPaymentRequestButtonEventListeners:function(t,e){t.on("click",function(t){i("body").addClass("woocommerce-stripe-prb-clicked")}),wc_stripe_payment_request_params.is_product_page?p.attachProductPageEventListeners(t,e):p.attachCartPageEventListeners(t,e)},attachProductPageEventListeners:function(e,a){var n=[],r=i(".single_add_to_cart_button");e.on("click",function(t){return r.is(".disabled")?(t.preventDefault(),void(r.is(".wc-variation-is-unavailable")?window.alert(wc_add_to_cart_variation_params.i18n_unavailable_text):r.is(".wc-variation-selection-needed")&&window.alert(wc_add_to_cart_variation_params.i18n_make_a_selection_text))):0<n.length?(t.preventDefault(),void window.alert(n)):(p.addToCart(),void((p.isCustomPaymentRequestButton(e)||p.isBrandedPaymentRequestButton(e))&&(t.preventDefault(),a.show())))}),i(document.body).on("wc_stripe_unblock_payment_request_button wc_stripe_enable_payment_request_button",function(){p.unblockPaymentRequestButton()}),i(document.body).on("wc_stripe_block_payment_request_button",function(){p.blockPaymentRequestButton("wc_request_button_is_blocked")}),i(document.body).on("wc_stripe_disable_payment_request_button",function(){p.blockPaymentRequestButton("wc_request_button_is_disabled")}),i(document.body).on("woocommerce_variation_has_changed",function(){i(document.body).trigger("wc_stripe_block_payment_request_button"),i.when(p.getSelectedProductData()).then(function(t){i.when(a.update({total:t.total,displayItems:t.displayItems})).then(function(){i(document.body).trigger("wc_stripe_unblock_payment_request_button")})})}),i(".quantity").on("input",".qty",function(){i(document.body).trigger("wc_stripe_block_payment_request_button")}),i(".quantity").on("input",".qty",p.debounce(250,function(){i(document.body).trigger("wc_stripe_block_payment_request_button"),n=[],i.when(p.getSelectedProductData()).then(function(t){t.error?(n=[t.error],i(document.body).trigger("wc_stripe_unblock_payment_request_button")):i.when(a.update({total:t.total,displayItems:t.displayItems})).then(function(){i(document.body).trigger("wc_stripe_unblock_payment_request_button")})})}))},attachCartPageEventListeners:function(t,e){(wc_stripe_payment_request_params.button.is_custom&&p.isCustomPaymentRequestButton(t)||wc_stripe_payment_request_params.button.is_branded&&p.isBrandedPaymentRequestButton(t))&&t.on("click",function(t){t.preventDefault(),e.show()})},showPaymentRequestButton:function(t){p.isCustomPaymentRequestButton(t)?(t.addClass("is-active"),i("#wc-stripe-payment-request-wrapper, #wc-stripe-payment-request-button-separator").show()):p.isBrandedPaymentRequestButton(t)?(i("#wc-stripe-payment-request-wrapper, #wc-stripe-payment-request-button-separator").show(),i("#wc-stripe-payment-request-button").html(t)):i("#wc-stripe-payment-request-button").length&&(i("#wc-stripe-payment-request-wrapper, #wc-stripe-payment-request-button-separator").show(),t.mount("#wc-stripe-payment-request-button"))},blockPaymentRequestButton:function(t){i("#wc-stripe-payment-request-button").data("blockUI.isBlocked")||i("#wc-stripe-payment-request-button").addClass(t).block({message:null})},unblockPaymentRequestButton:function(){i("#wc-stripe-payment-request-button").removeClass(["wc_request_button_is_blocked","wc_request_button_is_disabled"]).unblock()},init:function(){wc_stripe_payment_request_params.is_product_page?p.startPaymentRequest(""):p.getCartDetails()}};p.init(),i(document.body).on("updated_cart_totals",function(){p.init()}),i(document.body).on("updated_checkout",function(){p.init()})});
assets/js/stripe.js CHANGED
@@ -4,7 +4,9 @@ jQuery( function( $ ) {
4
  'use strict';
5
 
6
  try {
7
- var stripe = Stripe( wc_stripe_params.key );
 
 
8
  } catch( error ) {
9
  console.log( error );
10
  return;
4
  'use strict';
5
 
6
  try {
7
+ var stripe = Stripe( wc_stripe_params.key, {
8
+ locale: wc_stripe_params.stripe_locale || 'auto',
9
+ } );
10
  } catch( error ) {
11
  console.log( error );
12
  return;
assets/js/stripe.min.js CHANGED
@@ -1 +1 @@
1
- jQuery(function(c){"use strict";try{var n=Stripe(wc_stripe_params.key)}catch(e){return void console.log(e)}var t,o,i,e=Object.keys(wc_stripe_params.elements_options).length?wc_stripe_params.elements_options:{},r=Object.keys(wc_stripe_params.sepa_elements_options).length?wc_stripe_params.sepa_elements_options:{},s=n.elements(e),a=s.create("iban",r),m={getAjaxURL:function(e){return wc_stripe_params.ajaxurl.toString().replace("%%endpoint%%","wc_stripe_"+e)},unmountElements:function(){"yes"===wc_stripe_params.inline_cc_form?t.unmount("#stripe-card-element"):(t.unmount("#stripe-card-element"),o.unmount("#stripe-exp-element"),i.unmount("#stripe-cvc-element"))},mountElements:function(){c("#stripe-card-element").length&&("yes"!==wc_stripe_params.inline_cc_form?(t.mount("#stripe-card-element"),o.mount("#stripe-exp-element"),i.mount("#stripe-cvc-element")):t.mount("#stripe-card-element"))},createElements:function(){var e={base:{iconColor:"#666EE8",color:"#31325F",fontSize:"15px","::placeholder":{color:"#CFD7E0"}}},r={focus:"focused",empty:"empty",invalid:"invalid"};e=wc_stripe_params.elements_styling?wc_stripe_params.elements_styling:e,r=wc_stripe_params.elements_classes?wc_stripe_params.elements_classes:r,"yes"===wc_stripe_params.inline_cc_form?(t=s.create("card",{style:e,hidePostalCode:!0})).addEventListener("change",function(e){m.onCCFormChange(),e.error&&c(document.body).trigger("stripeError",e)}):(t=s.create("cardNumber",{style:e,classes:r}),o=s.create("cardExpiry",{style:e,classes:r}),i=s.create("cardCvc",{style:e,classes:r}),t.addEventListener("change",function(e){m.onCCFormChange(),m.updateCardBrand(e.brand),e.error&&c(document.body).trigger("stripeError",e)}),o.addEventListener("change",function(e){m.onCCFormChange(),e.error&&c(document.body).trigger("stripeError",e)}),i.addEventListener("change",function(e){m.onCCFormChange(),e.error&&c(document.body).trigger("stripeError",e)})),"yes"===wc_stripe_params.is_checkout?c(document.body).on("updated_checkout",function(){c("#stripe-card-element").children().length||(t&&m.unmountElements(),m.mountElements(),c("#stripe-iban-element").length&&a.mount("#stripe-iban-element"))}):(c("form#add_payment_method").length||c("form#order_review").length)&&(m.mountElements(),c("#stripe-iban-element").length&&a.mount("#stripe-iban-element"))},updateCardBrand:function(e){var r={visa:"stripe-visa-brand",mastercard:"stripe-mastercard-brand",amex:"stripe-amex-brand",discover:"stripe-discover-brand",diners:"stripe-diners-brand",jcb:"stripe-jcb-brand",unknown:"stripe-credit-card-brand"},t=c(".stripe-card-brand"),o="stripe-credit-card-brand";e in r&&(o=r[e]),c.each(r,function(e,r){t.removeClass(r)}),t.addClass(o)},init:function(){"yes"!==wc_stripe_params.is_change_payment_page&&"yes"!==wc_stripe_params.is_pay_for_order_page||c(document.body).trigger("wc-credit-card-form-init"),c("form.woocommerce-checkout").length&&(this.form=c("form.woocommerce-checkout")),c("form.woocommerce-checkout").on("checkout_place_order_stripe checkout_place_order_stripe_bancontact checkout_place_order_stripe_sofort checkout_place_order_stripe_giropay checkout_place_order_stripe_ideal checkout_place_order_stripe_alipay checkout_place_order_stripe_sepa",this.onSubmit),c("form#order_review").length&&(this.form=c("form#order_review")),c("form#order_review, form#add_payment_method").on("submit",this.onSubmit),c("form#add_payment_method").length&&(this.form=c("form#add_payment_method")),c("form.woocommerce-checkout").on("change",this.reset),c(document).on("stripeError",this.onError).on("checkout_error",this.reset),a.on("change",this.onSepaError),c("#early_renewal_modal_submit").on("click",this.onEarlyRenewalSubmit),m.createElements(),window.addEventListener("hashchange",m.onHashChange),m.maybeConfirmIntent()},isStripeChosen:function(){return c("#payment_method_stripe, #payment_method_stripe_bancontact, #payment_method_stripe_sofort, #payment_method_stripe_giropay, #payment_method_stripe_ideal, #payment_method_stripe_alipay, #payment_method_stripe_sepa, #payment_method_stripe_eps, #payment_method_stripe_multibanco").is(":checked")||c("#payment_method_stripe").is(":checked")&&"new"===c('input[name="wc-stripe-payment-token"]:checked').val()||c("#payment_method_stripe_sepa").is(":checked")&&"new"===c('input[name="wc-stripe-payment-token"]:checked').val()},isStripeSaveCardChosen:function(){return c("#payment_method_stripe").is(":checked")&&c('input[name="wc-stripe-payment-token"]').is(":checked")&&"new"!==c('input[name="wc-stripe-payment-token"]:checked').val()||c("#payment_method_stripe_sepa").is(":checked")&&c('input[name="wc-stripe_sepa-payment-token"]').is(":checked")&&"new"!==c('input[name="wc-stripe_sepa-payment-token"]:checked').val()},isStripeCardChosen:function(){return c("#payment_method_stripe").is(":checked")},isBancontactChosen:function(){return c("#payment_method_stripe_bancontact").is(":checked")},isGiropayChosen:function(){return c("#payment_method_stripe_giropay").is(":checked")},isIdealChosen:function(){return c("#payment_method_stripe_ideal").is(":checked")},isSofortChosen:function(){return c("#payment_method_stripe_sofort").is(":checked")},isAlipayChosen:function(){return c("#payment_method_stripe_alipay").is(":checked")},isSepaChosen:function(){return c("#payment_method_stripe_sepa").is(":checked")},isP24Chosen:function(){return c("#payment_method_stripe_p24").is(":checked")},isEpsChosen:function(){return c("#payment_method_stripe_eps").is(":checked")},isMultibancoChosen:function(){return c("#payment_method_stripe_multibanco").is(":checked")},hasSource:function(){return 0<c("input.stripe-source").length},isMobile:function(){return!!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)},block:function(){m.isMobile()||m.form.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){m.form&&m.form.unblock()},getSelectedPaymentElement:function(){return c('.payment_methods input[name="payment_method"]:checked')},getOwnerDetails:function(){var e=c("#billing_first_name").length?c("#billing_first_name").val():wc_stripe_params.billing_first_name,r=c("#billing_last_name").length?c("#billing_last_name").val():wc_stripe_params.billing_last_name,t={name:"",address:{},email:"",phone:""};return t.name=e,t.name=e&&r?e+" "+r:c("#stripe-payment-data").data("full-name"),t.email=c("#billing_email").val(),t.phone=c("#billing_phone").val(),(void 0===t.phone||t.phone.length<=0)&&delete t.phone,(void 0===t.email||t.email.length<=0)&&(c("#stripe-payment-data").data("email").length?t.email=c("#stripe-payment-data").data("email"):delete t.email),(void 0===t.name||t.name.length<=0)&&delete t.name,t.address.line1=c("#billing_address_1").val()||wc_stripe_params.billing_address_1,t.address.line2=c("#billing_address_2").val()||wc_stripe_params.billing_address_2,t.address.state=c("#billing_state").val()||wc_stripe_params.billing_state,t.address.city=c("#billing_city").val()||wc_stripe_params.billing_city,t.address.postal_code=c("#billing_postcode").val()||wc_stripe_params.billing_postcode,t.address.country=c("#billing_country").val()||wc_stripe_params.billing_country,{owner:t}},createSource:function(){var e=m.getOwnerDetails();return m.isSepaChosen()?(e.currency=c("#stripe-sepa_debit-payment-data").data("currency"),e.mandate={notification_method:wc_stripe_params.sepa_mandate_notification},e.type="sepa_debit",n.createSource(a,e).then(m.sourceResponse)):n.createSource(t,e).then(m.sourceResponse)},sourceResponse:function(e){e.error?c(document.body).trigger("stripeError",e):(m.reset(),m.form.append(c('<input type="hidden" />').addClass("stripe-source").attr("name","stripe_source").val(e.source.id)),c("form#add_payment_method").length||c("#wc-stripe-change-payment-method").length?m.sourceSetup(e):m.form.trigger("submit"))},sourceSetup:function(r){var e={error:{type:"api_connection_error"}};c.post({url:m.getAjaxURL("create_setup_intent"),dataType:"json",data:{stripe_source_id:r.source.id,nonce:wc_stripe_params.add_card_nonce},error:function(){c(document.body).trigger("stripeError",e)}}).done(function(e){if("success"===e.status)return c("form#add_payment_method").length&&c(m.form).off("submit",m.form.onSubmit),void m.form.trigger("submit");"requires_action"===e.status?n.confirmCardSetup(e.client_secret,{payment_method:r.source.id}).then(function(e){e.error?c(document.body).trigger("stripeError",e):(c("form#add_payment_method").length&&c(m.form).off("submit",m.form.onSubmit),m.form.trigger("submit"))}).catch(function(e){console.log(e),c(document.body).trigger("stripeError",{error:e})}):c(document.body).trigger("stripeError",e)})},onSubmit:function(){return!m.isStripeChosen()||(!(!m.isStripeSaveCardChosen()&&!m.hasSource())||(!!(m.isBancontactChosen()||m.isGiropayChosen()||m.isIdealChosen()||m.isAlipayChosen()||m.isSofortChosen()||m.isP24Chosen()||m.isEpsChosen()||m.isMultibancoChosen())||(m.block(),m.createSource(),!1)))},onCCFormChange:function(){m.reset()},reset:function(){c(".wc-stripe-error, .stripe-source").remove()},onSepaError:function(e){var r=m.getSelectedPaymentElement().parents("li").eq(0).find(".stripe-source-errors");e.error?(console.log(e.error.message),c(r).html('<ul class="woocommerce_error woocommerce-error wc-stripe-error"><li /></ul>'),c(r).find("li").text(e.error.message)):c(r).html("")},onError:function(e,r){var t,o=r.error.message,n=m.getSelectedPaymentElement().closest("li"),i=n.find(".woocommerce-SavedPaymentMethods-tokenInput");if(c("body").hasClass("woocommerce-stripe-prb-clicked"))c("body").removeClass("woocommerce-stripe-prb-clicked"),t=c("div.woocommerce-notices-wrapper").first();else if(i.length){var s=i.filter(":checked");t=s.closest(".woocommerce-SavedPaymentMethods-new").length?c("#wc-stripe-cc-form .stripe-source-errors"):s.closest("li").find(".stripe-source-errors")}else t=n.find(".stripe-source-errors");if(m.isSepaChosen()&&"invalid_owner_name"===r.error.code&&wc_stripe_params.hasOwnProperty(r.error.code)){var a=c('<div><ul class="woocommerce-error"><li /></ul></div>');return a.find("li").text(wc_stripe_params[r.error.code]),void m.submitError(a.html())}"email_invalid"===r.error.code?o=wc_stripe_params.email_invalid:"invalid_request_error"!==r.error.type&&"api_connection_error"!==r.error.type&&"api_error"!==r.error.type&&"authentication_error"!==r.error.type&&"rate_limit_error"!==r.error.type||(o=wc_stripe_params.invalid_request_error),"card_error"===r.error.type&&wc_stripe_params.hasOwnProperty(r.error.code)&&(o=wc_stripe_params[r.error.code]),"validation_error"===r.error.type&&wc_stripe_params.hasOwnProperty(r.error.code)&&(o=wc_stripe_params[r.error.code]),m.reset(),c(".woocommerce-NoticeGroup-checkout").remove(),console.log(r.error.message),c(t).html('<ul class="woocommerce_error woocommerce-error wc-stripe-error"><li /></ul>'),c(t).find("li").text(o),c(".wc-stripe-error").length&&c("html, body").animate({scrollTop:c(".wc-stripe-error").offset().top-200},200),m.unblock(),c.unblockUI()},submitError:function(e){c(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),m.form.prepend('<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">'+e+"</div>"),m.form.removeClass("processing").unblock(),m.form.find(".input-text, select, input:checkbox").trigger("blur");var r="";c("#add_payment_method").length&&(r=c("#add_payment_method")),c("#order_review").length&&(r=c("#order_review")),c("form.checkout").length&&(r=c("form.checkout")),r.length&&c("html, body").animate({scrollTop:r.offset().top-100},500),c(document.body).trigger("checkout_error"),m.unblock()},onHashChange:function(){var e=window.location.hash.match(/^#?confirm-(pi|si)-([^:]+):(.+)$/);if(e&&!(e.length<4)){var r=e[1],t=e[2],o=decodeURIComponent(e[3]);window.location.hash="",m.openIntentModal(t,o,!1,"si"===r)}},maybeConfirmIntent:function(){if(c("#stripe-intent-id").length&&c("#stripe-intent-return").length){var e=c("#stripe-intent-id").val(),r=c("#stripe-intent-return").val();m.openIntentModal(e,r,!0,!1)}},openIntentModal:function(e,t,r,o){n[o?"handleCardSetup":"handleCardPayment"](e).then(function(e){if(e.error)throw e.error;var r=e[o?"setupIntent":"paymentIntent"];"requires_capture"!==r.status&&"succeeded"!==r.status||(window.location=t)}).catch(function(e){r?window.location=t:(c(document.body).trigger("stripeError",{error:e}),m.form&&m.form.removeClass("processing"),c.get(t+"&is_ajax"))})},onEarlyRenewalSubmit:function(e){return e.preventDefault(),c.ajax({url:c("#early_renewal_modal_submit").attr("href"),method:"get",success:function(e){var r=JSON.parse(e);r.stripe_sca_required?m.openIntentModal(r.intent_secret,r.redirect_url,!0,!1):window.location=r.redirect_url}}),!1}};m.init()});
1
+ jQuery(function(a){"use strict";try{var n=Stripe(wc_stripe_params.key,{locale:wc_stripe_params.stripe_locale||"auto"})}catch(e){return void console.log(e)}var t,o,i,e=Object.keys(wc_stripe_params.elements_options).length?wc_stripe_params.elements_options:{},r=Object.keys(wc_stripe_params.sepa_elements_options).length?wc_stripe_params.sepa_elements_options:{},s=n.elements(e),c=s.create("iban",r),m={getAjaxURL:function(e){return wc_stripe_params.ajaxurl.toString().replace("%%endpoint%%","wc_stripe_"+e)},unmountElements:function(){"yes"===wc_stripe_params.inline_cc_form?t.unmount("#stripe-card-element"):(t.unmount("#stripe-card-element"),o.unmount("#stripe-exp-element"),i.unmount("#stripe-cvc-element"))},mountElements:function(){a("#stripe-card-element").length&&("yes"!==wc_stripe_params.inline_cc_form?(t.mount("#stripe-card-element"),o.mount("#stripe-exp-element"),i.mount("#stripe-cvc-element")):t.mount("#stripe-card-element"))},createElements:function(){var e={base:{iconColor:"#666EE8",color:"#31325F",fontSize:"15px","::placeholder":{color:"#CFD7E0"}}},r={focus:"focused",empty:"empty",invalid:"invalid"},e=wc_stripe_params.elements_styling||e,r=wc_stripe_params.elements_classes||r;"yes"===wc_stripe_params.inline_cc_form?(t=s.create("card",{style:e,hidePostalCode:!0})).addEventListener("change",function(e){m.onCCFormChange(),e.error&&a(document.body).trigger("stripeError",e)}):(t=s.create("cardNumber",{style:e,classes:r}),o=s.create("cardExpiry",{style:e,classes:r}),i=s.create("cardCvc",{style:e,classes:r}),t.addEventListener("change",function(e){m.onCCFormChange(),m.updateCardBrand(e.brand),e.error&&a(document.body).trigger("stripeError",e)}),o.addEventListener("change",function(e){m.onCCFormChange(),e.error&&a(document.body).trigger("stripeError",e)}),i.addEventListener("change",function(e){m.onCCFormChange(),e.error&&a(document.body).trigger("stripeError",e)})),"yes"===wc_stripe_params.is_checkout?a(document.body).on("updated_checkout",function(){a("#stripe-card-element").children().length||(t&&m.unmountElements(),m.mountElements(),a("#stripe-iban-element").length&&c.mount("#stripe-iban-element"))}):(a("form#add_payment_method").length||a("form#order_review").length)&&(m.mountElements(),a("#stripe-iban-element").length&&c.mount("#stripe-iban-element"))},updateCardBrand:function(e){var r={visa:"stripe-visa-brand",mastercard:"stripe-mastercard-brand",amex:"stripe-amex-brand",discover:"stripe-discover-brand",diners:"stripe-diners-brand",jcb:"stripe-jcb-brand",unknown:"stripe-credit-card-brand"},t=a(".stripe-card-brand"),e=e in r?r[e]:"stripe-credit-card-brand";a.each(r,function(e,r){t.removeClass(r)}),t.addClass(e)},init:function(){"yes"!==wc_stripe_params.is_change_payment_page&&"yes"!==wc_stripe_params.is_pay_for_order_page||a(document.body).trigger("wc-credit-card-form-init"),a("form.woocommerce-checkout").length&&(this.form=a("form.woocommerce-checkout")),a("form.woocommerce-checkout").on("checkout_place_order_stripe checkout_place_order_stripe_bancontact checkout_place_order_stripe_sofort checkout_place_order_stripe_giropay checkout_place_order_stripe_ideal checkout_place_order_stripe_alipay checkout_place_order_stripe_sepa",this.onSubmit),a("form#order_review").length&&(this.form=a("form#order_review")),a("form#order_review, form#add_payment_method").on("submit",this.onSubmit),a("form#add_payment_method").length&&(this.form=a("form#add_payment_method")),a("form.woocommerce-checkout").on("change",this.reset),a(document).on("stripeError",this.onError).on("checkout_error",this.reset),c.on("change",this.onSepaError),a("#early_renewal_modal_submit").on("click",this.onEarlyRenewalSubmit),m.createElements(),window.addEventListener("hashchange",m.onHashChange),m.maybeConfirmIntent()},isStripeChosen:function(){return a("#payment_method_stripe, #payment_method_stripe_bancontact, #payment_method_stripe_sofort, #payment_method_stripe_giropay, #payment_method_stripe_ideal, #payment_method_stripe_alipay, #payment_method_stripe_sepa, #payment_method_stripe_eps, #payment_method_stripe_multibanco").is(":checked")||a("#payment_method_stripe").is(":checked")&&"new"===a('input[name="wc-stripe-payment-token"]:checked').val()||a("#payment_method_stripe_sepa").is(":checked")&&"new"===a('input[name="wc-stripe-payment-token"]:checked').val()},isStripeSaveCardChosen:function(){return a("#payment_method_stripe").is(":checked")&&a('input[name="wc-stripe-payment-token"]').is(":checked")&&"new"!==a('input[name="wc-stripe-payment-token"]:checked').val()||a("#payment_method_stripe_sepa").is(":checked")&&a('input[name="wc-stripe_sepa-payment-token"]').is(":checked")&&"new"!==a('input[name="wc-stripe_sepa-payment-token"]:checked').val()},isStripeCardChosen:function(){return a("#payment_method_stripe").is(":checked")},isBancontactChosen:function(){return a("#payment_method_stripe_bancontact").is(":checked")},isGiropayChosen:function(){return a("#payment_method_stripe_giropay").is(":checked")},isIdealChosen:function(){return a("#payment_method_stripe_ideal").is(":checked")},isSofortChosen:function(){return a("#payment_method_stripe_sofort").is(":checked")},isAlipayChosen:function(){return a("#payment_method_stripe_alipay").is(":checked")},isSepaChosen:function(){return a("#payment_method_stripe_sepa").is(":checked")},isP24Chosen:function(){return a("#payment_method_stripe_p24").is(":checked")},isEpsChosen:function(){return a("#payment_method_stripe_eps").is(":checked")},isMultibancoChosen:function(){return a("#payment_method_stripe_multibanco").is(":checked")},hasSource:function(){return 0<a("input.stripe-source").length},isMobile:function(){return!!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)},block:function(){m.isMobile()||m.form.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){m.form&&m.form.unblock()},getSelectedPaymentElement:function(){return a('.payment_methods input[name="payment_method"]:checked')},getOwnerDetails:function(){var e=a("#billing_first_name").length?a("#billing_first_name").val():wc_stripe_params.billing_first_name,r=a("#billing_last_name").length?a("#billing_last_name").val():wc_stripe_params.billing_last_name,t={name:"",address:{},email:"",phone:""};return t.name=e,t.name=e&&r?e+" "+r:a("#stripe-payment-data").data("full-name"),t.email=a("#billing_email").val(),t.phone=a("#billing_phone").val(),(void 0===t.phone||t.phone.length<=0)&&delete t.phone,(void 0===t.email||t.email.length<=0)&&(a("#stripe-payment-data").data("email").length?t.email=a("#stripe-payment-data").data("email"):delete t.email),(void 0===t.name||t.name.length<=0)&&delete t.name,t.address.line1=a("#billing_address_1").val()||wc_stripe_params.billing_address_1,t.address.line2=a("#billing_address_2").val()||wc_stripe_params.billing_address_2,t.address.state=a("#billing_state").val()||wc_stripe_params.billing_state,t.address.city=a("#billing_city").val()||wc_stripe_params.billing_city,t.address.postal_code=a("#billing_postcode").val()||wc_stripe_params.billing_postcode,t.address.country=a("#billing_country").val()||wc_stripe_params.billing_country,{owner:t}},createSource:function(){var e=m.getOwnerDetails();return m.isSepaChosen()?(e.currency=a("#stripe-sepa_debit-payment-data").data("currency"),e.mandate={notification_method:wc_stripe_params.sepa_mandate_notification},e.type="sepa_debit",n.createSource(c,e).then(m.sourceResponse)):n.createSource(t,e).then(m.sourceResponse)},sourceResponse:function(e){e.error?a(document.body).trigger("stripeError",e):(m.reset(),m.form.append(a('<input type="hidden" />').addClass("stripe-source").attr("name","stripe_source").val(e.source.id)),a("form#add_payment_method").length||a("#wc-stripe-change-payment-method").length?m.sourceSetup(e):m.form.trigger("submit"))},sourceSetup:function(r){var e={error:{type:"api_connection_error"}};a.post({url:m.getAjaxURL("create_setup_intent"),dataType:"json",data:{stripe_source_id:r.source.id,nonce:wc_stripe_params.add_card_nonce},error:function(){a(document.body).trigger("stripeError",e)}}).done(function(e){return"success"===e.status?(a("form#add_payment_method").length&&a(m.form).off("submit",m.form.onSubmit),void m.form.trigger("submit")):void("requires_action"===e.status?n.confirmCardSetup(e.client_secret,{payment_method:r.source.id}).then(function(e){e.error?a(document.body).trigger("stripeError",e):(a("form#add_payment_method").length&&a(m.form).off("submit",m.form.onSubmit),m.form.trigger("submit"))}).catch(function(e){console.log(e),a(document.body).trigger("stripeError",{error:e})}):a(document.body).trigger("stripeError",e))})},onSubmit:function(){return!m.isStripeChosen()||(!(!m.isStripeSaveCardChosen()&&!m.hasSource())||(!!(m.isBancontactChosen()||m.isGiropayChosen()||m.isIdealChosen()||m.isAlipayChosen()||m.isSofortChosen()||m.isP24Chosen()||m.isEpsChosen()||m.isMultibancoChosen())||(m.block(),m.createSource(),!1)))},onCCFormChange:function(){m.reset()},reset:function(){a(".wc-stripe-error, .stripe-source").remove()},onSepaError:function(e){var r=m.getSelectedPaymentElement().parents("li").eq(0).find(".stripe-source-errors");e.error?(console.log(e.error.message),a(r).html('<ul class="woocommerce_error woocommerce-error wc-stripe-error"><li /></ul>'),a(r).find("li").text(e.error.message)):a(r).html("")},onError:function(e,r){var t,o=r.error.message,n=m.getSelectedPaymentElement().closest("li"),i=n.find(".woocommerce-SavedPaymentMethods-tokenInput"),s=a("body").hasClass("woocommerce-stripe-prb-clicked");if(t=s?(a("body").removeClass("woocommerce-stripe-prb-clicked"),a("div.woocommerce-notices-wrapper").first()):i.length?(t=i.filter(":checked")).closest(".woocommerce-SavedPaymentMethods-new").length?a("#wc-stripe-cc-form .stripe-source-errors"):t.closest("li").find(".stripe-source-errors"):n.find(".stripe-source-errors"),m.isSepaChosen()&&"invalid_owner_name"===r.error.code&&wc_stripe_params.hasOwnProperty(r.error.code)){n=a('<div><ul class="woocommerce-error"><li /></ul></div>');return n.find("li").text(wc_stripe_params[r.error.code]),void m.submitError(n.html())}"email_invalid"===r.error.code?o=wc_stripe_params.email_invalid:"invalid_request_error"!==r.error.type&&"api_connection_error"!==r.error.type&&"api_error"!==r.error.type&&"authentication_error"!==r.error.type&&"rate_limit_error"!==r.error.type||(o=wc_stripe_params.invalid_request_error),"card_error"===r.error.type&&wc_stripe_params.hasOwnProperty(r.error.code)&&(o=wc_stripe_params[r.error.code]),"validation_error"===r.error.type&&wc_stripe_params.hasOwnProperty(r.error.code)&&(o=wc_stripe_params[r.error.code]),m.reset(),a(".woocommerce-NoticeGroup-checkout").remove(),console.log(r.error.message),a(t).html('<ul class="woocommerce_error woocommerce-error wc-stripe-error"><li /></ul>'),a(t).find("li").text(o),a(".wc-stripe-error").length&&a("html, body").animate({scrollTop:a(".wc-stripe-error").offset().top-200},200),m.unblock(),a.unblockUI()},submitError:function(e){a(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),m.form.prepend('<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">'+e+"</div>"),m.form.removeClass("processing").unblock(),m.form.find(".input-text, select, input:checkbox").trigger("blur");e="";a("#add_payment_method").length&&(e=a("#add_payment_method")),a("#order_review").length&&(e=a("#order_review")),(e=a("form.checkout").length?a("form.checkout"):e).length&&a("html, body").animate({scrollTop:e.offset().top-100},500),a(document.body).trigger("checkout_error"),m.unblock()},onHashChange:function(){var e,r,t=window.location.hash.match(/^#?confirm-(pi|si)-([^:]+):(.+)$/);!t||t.length<4||(e=t[1],r=t[2],t=decodeURIComponent(t[3]),window.location.hash="",m.openIntentModal(r,t,!1,"si"===e))},maybeConfirmIntent:function(){var e,r;a("#stripe-intent-id").length&&a("#stripe-intent-return").length&&(e=a("#stripe-intent-id").val(),r=a("#stripe-intent-return").val(),m.openIntentModal(e,r,!0,!1))},openIntentModal:function(e,r,t,o){n[o?"handleCardSetup":"handleCardPayment"](e).then(function(e){if(e.error)throw e.error;e=e[o?"setupIntent":"paymentIntent"];"requires_capture"!==e.status&&"succeeded"!==e.status||(window.location=r)}).catch(function(e){t?window.location=r:(a(document.body).trigger("stripeError",{error:e}),m.form&&m.form.removeClass("processing"),a.get(r+"&is_ajax"))})},onEarlyRenewalSubmit:function(e){return e.preventDefault(),a.ajax({url:a("#early_renewal_modal_submit").attr("href"),method:"get",success:function(e){e=JSON.parse(e);e.stripe_sca_required?m.openIntentModal(e.intent_secret,e.redirect_url,!0,!1):window.location=e.redirect_url}}),!1}};m.init()});
build/index.asset.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php return array('dependencies' => array('jquery', 'react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '70bf8f00a445ed6d4cd6dfa3cc471382');
build/index.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=20)}([function(e,t){e.exports=window.wp.element},function(e,t){e.exports=window.wp.i18n},function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,n){var r=n(13),o=n(14),i=n(15),c=n(17);e.exports=function(e,t){return r(e)||o(e,t)||i(e,t)||c()},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,n){!function(e,t){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(){}function i(){}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,i.resetWarningCache=o;var c=function(e,t){return function(e){e.exports=function(){function e(e,t,n,r,o,i){if("SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==i){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:o};return n.PropTypes=n,n}()}(t={exports:{}}),t.exports}(),a=function(e){return null!==e&&"object"===n(e)},s=function e(t,n){if(!a(t)||!a(n))return t===n;var r=Array.isArray(t);if(r!==Array.isArray(n))return!1;var o="[object Object]"===Object.prototype.toString.call(t);if(o!==("[object Object]"===Object.prototype.toString.call(n)))return!1;if(!o&&!r)return!1;var i=Object.keys(t),c=Object.keys(n);if(i.length!==c.length)return!1;for(var s={},u=0;u<i.length;u+=1)s[i[u]]=!0;for(var l=0;l<c.length;l+=1)s[c[l]]=!0;var p=Object.keys(s);if(p.length!==i.length)return!1;var d=t,f=n;return p.every((function(t){return e(d[t],f[t])}))},u=function(e){var n=t.useRef(e);return t.useEffect((function(){n.current=e}),[e]),n.current},l=function(e){if(null===e||a(t=e)&&"function"==typeof t.elements&&"function"==typeof t.createToken&&"function"==typeof t.createPaymentMethod&&"function"==typeof t.confirmCardPayment)return e;var t;throw new Error("Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.")},p=t.createContext(null);p.displayName="ElementsContext";var d=function(e){var n,o,i=e.stripe,c=e.options,d=e.children,f=t.useRef(!1),m=t.useRef(!0),y=t.useMemo((function(){return function(e){if(function(e){return a(e)&&"function"==typeof e.then}(e))return{tag:"async",stripePromise:Promise.resolve(e).then(l)};var t=l(e);return null===t?{tag:"empty"}:{tag:"sync",stripe:t}}(i)}),[i]),v=(n=t.useState((function(){return{stripe:null,elements:null}})),o=2,function(e){if(Array.isArray(e))return e}(n)||function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var n=[],_n=!0,r=!1,o=void 0;try{for(var i,c=e[Symbol.iterator]();!(_n=(i=c.next()).done)&&(n.push(i.value),!t||n.length!==t);_n=!0);}catch(e){r=!0,o=e}finally{try{_n||null==c.return||c.return()}finally{if(r)throw o}}return n}}(n,o)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(n,o)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),b=v[0],_=v[1],g=u(i),h=u(c);return null!==g&&(g!==i&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it."),s(c,h)||console.warn("Unsupported prop change on Elements: You cannot change the `options` prop after setting the `stripe` prop.")),f.current||("sync"===y.tag&&(f.current=!0,_({stripe:y.stripe,elements:y.stripe.elements(c)})),"async"===y.tag&&(f.current=!0,y.stripePromise.then((function(e){e&&m.current&&_({stripe:e,elements:e.elements(c)})})))),t.useEffect((function(){return function(){m.current=!1}}),[]),t.useEffect((function(){var e=b.stripe;e&&e._registerWrapper&&e._registerWrapper({name:"react-stripe-js",version:"1.2.2"})}),[b.stripe]),t.createElement(p.Provider,{value:b},d)};d.propTypes={stripe:c.any,options:c.object};var f=function(e){return function(e,t){if(!e)throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(t," in an <Elements> provider."));return e}(t.useContext(p),e)},m=function(e){return(0,e.children)(f("mounts <ElementsConsumer>"))};m.propTypes={children:c.func.isRequired};var y=function(e){var n=t.useRef(e);return t.useEffect((function(){n.current=e}),[e]),function(){n.current&&n.current.apply(n,arguments)}},v=function(e){return a(e)?(e.paymentRequest,function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(e,["paymentRequest"])):{}},b=function(){},_=function(e,n){var r,o="".concat((r=e).charAt(0).toUpperCase()+r.slice(1),"Element"),i=n?function(e){f("mounts <".concat(o,">"));var n=e.id,r=e.className;return t.createElement("div",{id:n,className:r})}:function(n){var r=n.id,i=n.className,c=n.options,a=void 0===c?{}:c,u=n.onBlur,l=void 0===u?b:u,p=n.onFocus,d=void 0===p?b:p,m=n.onReady,_=void 0===m?b:m,g=n.onChange,h=void 0===g?b:g,w=n.onEscape,O=void 0===w?b:w,E=n.onClick,j=void 0===E?b:E,C=f("mounts <".concat(o,">")).elements,x=t.useRef(null),S=t.useRef(null),R=y(_),P=y(l),T=y(d),k=y(j),A=y(h),I=y(O);t.useLayoutEffect((function(){if(null==x.current&&C&&null!=S.current){var t=C.create(e,a);x.current=t,t.mount(S.current),t.on("ready",(function(){return R(t)})),t.on("change",A),t.on("blur",P),t.on("focus",T),t.on("escape",I),t.on("click",k)}}));var M=t.useRef(a);return t.useEffect((function(){M.current&&M.current.paymentRequest!==a.paymentRequest&&console.warn("Unsupported prop change: options.paymentRequest is not a customizable property.");var e=v(a);0===Object.keys(e).length||s(e,v(M.current))||x.current&&(x.current.update(e),M.current=a)}),[a]),t.useLayoutEffect((function(){return function(){x.current&&x.current.destroy()}}),[]),t.createElement("div",{id:r,className:i,ref:S})};return i.propTypes={id:c.string,className:c.string,onChange:c.func,onBlur:c.func,onFocus:c.func,onReady:c.func,onClick:c.func,options:c.object},i.displayName=o,i.__elementType=e,i},g="undefined"==typeof window,h=_("auBankAccount",g),w=_("card",g),O=_("cardNumber",g),E=_("cardExpiry",g),j=_("cardCvc",g),C=_("fpxBank",g),x=_("iban",g),S=_("idealBank",g),R=_("paymentRequestButton",g);e.AuBankAccountElement=h,e.CardCvcElement=j,e.CardElement=w,e.CardExpiryElement=E,e.CardNumberElement=O,e.Elements=d,e.ElementsConsumer=m,e.FpxBankElement=C,e.IbanElement=x,e.IdealBankElement=S,e.PaymentRequestButtonElement=R,e.useElements=function(){return f("calls useElements()").elements},e.useStripe=function(){return f("calls useStripe()").stripe},Object.defineProperty(e,"__esModule",{value:!0})}(t,n(19))},function(e,t){e.exports=window.regeneratorRuntime},function(e,t){e.exports=window.jQuery},function(e,t){function n(e,t,n,r,o,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(r,o)}e.exports=function(e){return function(){var t=this,r=arguments;return new Promise((function(o,i){var c=e.apply(t,r);function a(e){n(c,o,i,a,s,"next",e)}function s(e){n(c,o,i,a,s,"throw",e)}a(void 0)}))}},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,n){var r=n(18);e.exports=function(e,t){if(null==e)return{};var n,o,i=r(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(o=0;o<c.length;o++)n=c[o],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=window.wc.wcSettings},function(e,t){e.exports=window.wc.wcBlocksRegistry},function(e,t){function n(){return e.exports=n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},e.exports.default=e.exports,e.exports.__esModule=!0,n.apply(this,arguments)}e.exports=n,e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){function n(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(e.exports=n=function(e){return typeof e},e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=n=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.default=e.exports,e.exports.__esModule=!0),n(t)}e.exports=n,e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e){if(Array.isArray(e))return e},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var n=[],_n=!0,r=!1,o=void 0;try{for(var i,c=e[Symbol.iterator]();!(_n=(i=c.next()).done)&&(n.push(i.value),!t||n.length!==t);_n=!0);}catch(e){r=!0,o=e}finally{try{_n||null==c.return||c.return()}finally{if(r)throw o}}return n}},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,n){var r=n(16);e.exports=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=window.React},function(e,t,n){"use strict";n.r(t);var r=n(10),o=n(11),i=n.n(o),c=n(3),a=n.n(c),s=n(8),u=n.n(s),l=n(0),p=n(1),d=n(2),f=n.n(d),m=n(9),y={INVALID_EMAIL:"email_invalid",INVALID_REQUEST:"invalid_request_error",API_CONNECTION:"api_connection_error",API_ERROR:"api_error",AUTHENTICATION_ERROR:"authentication_error",RATE_LIMIT_ERROR:"rate_limit_error",CARD_ERROR:"card_error",VALIDATION_ERROR:"validation_error"},v=function(){var e=Object(m.getSetting)("stripe_data",null);if(!e)throw new Error("Stripe initialization data is not available");return e},b=function(e){return[y.INVALID_REQUEST,y.API_CONNECTION,y.API_ERROR,y.AUTHENTICATION_ERROR,y.RATE_LIMIT_ERROR].includes(e)},_=function(e){var t;return(t={},f()(t,"invalid_number",Object(p.__)("The card number is not a valid credit card number.","woocommerce-gateway-stripe")),f()(t,"invalid_expiry_month",Object(p.__)("The card expiration month is invalid.","woocommerce-gateway-stripe")),f()(t,"invalid_expiry_year",Object(p.__)("The card expiration year is invalid.","woocommerce-gateway-stripe")),f()(t,"invalid_cvc",Object(p.__)("The card security code is invalid.","woocommerce-gateway-stripe")),f()(t,"incorrect_number",Object(p.__)("The card number is incorrect.","woocommerce-gateway-stripe")),f()(t,"incomplete_number",Object(p.__)("The card number is incomplete.","woocommerce-gateway-stripe")),f()(t,"incomplete_cvc",Object(p.__)("The card security code is incomplete.","woocommerce-gateway-stripe")),f()(t,"incomplete_expiry",Object(p.__)("The card expiration date is incomplete.","woocommerce-gateway-stripe")),f()(t,"expired_card",Object(p.__)("The card has expired.","woocommerce-gateway-stripe")),f()(t,"incorrect_cvc",Object(p.__)("The card security code is incorrect.","woocommerce-gateway-stripe")),f()(t,"incorrect_zip",Object(p.__)("The card zip code failed validation.","woocommerce-gateway-stripe")),f()(t,"invalid_expiry_year_past",Object(p.__)("The card expiration year is in the past","woocommerce-gateway-stripe")),f()(t,"card_declined",Object(p.__)("The card was declined.","woocommerce-gateway-stripe")),f()(t,"missing",Object(p.__)("There is no card on a customer that is being charged.","woocommerce-gateway-stripe")),f()(t,"processing_error",Object(p.__)("An error occurred while processing the card.","woocommerce-gateway-stripe")),t)[e]||null},g=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";switch(e){case y.INVALID_EMAIL:return Object(p.__)("Invalid email address, please correct and try again.","woocommerce-gateway-stripe");case b(e):return Object(p.__)("Unable to process this payment, please try again or use alternative method.","woocommerce-gateway-stripe");case y.CARD_ERROR:return _(t);case y.VALIDATION_ERROR:return""}return null},h="https://js.stripe.com/v3",w=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,O="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used",E=null,j=function(e,t,n){if(null===e)return null;var r=e.apply(void 0,t);return function(e,t){e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",version:"1.11.0",startTime:t})}(r,n),r},C=Promise.resolve().then((function(){return e=null,null!==E?E:E=new Promise((function(t,n){if("undefined"!=typeof window)if(window.Stripe&&e&&console.warn(O),window.Stripe)t(window.Stripe);else try{var r=function(){for(var e=document.querySelectorAll('script[src^="'.concat(h,'"]')),t=0;t<e.length;t++){var n=e[t];if(w.test(n.src))return n}return null}();r&&e?console.warn(O):r||(r=function(e){var t=e&&!e.advancedFraudSignals?"?advancedFraudSignals=false":"",n=document.createElement("script");n.src="".concat(h).concat(t);var r=document.head||document.body;if(!r)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return r.appendChild(n),n}(e)),r.addEventListener("load",(function(){window.Stripe?t(window.Stripe):n(new Error("Stripe.js not available"))})),r.addEventListener("error",(function(){n(new Error("Failed to load Stripe.js"))}))}catch(e){return void n(e)}else t(null)}));var e})),x=!1;C.catch((function(e){x||console.warn(e)}));var S=function(){return new Promise((function(e){try{var t,n,r=null!==(t=null===(n=v())||void 0===n?void 0:n.stripeLocale)&&void 0!==t?t:"auto";e(function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];x=!0;var r=Date.now();return C.then((function(e){return j(e,t,r)}))}(function(){var e=v().publicKey;if(!e)throw new Error("There is no api key available for stripe. Make sure it is available on the wc.stripe_data.stripe.key property.");return e}(),{locale:r}))}catch(t){e({error:t})}}))},R=n(4),P=n(7),T=n.n(P),k=n(5),A=n.n(k),I=function(e){var t=e.stripe,n=e.paymentDetails,r=e.errorContext,o=e.errorType,i={type:e.successType};if(!n.setup_intent&&!n.payment_intent_secret)return!0;var c=!!n.setupIntent,a=n.verification_endpoint,s=c?n.setup_intent:n.payment_intent_secret;return t[c?"confirmCardSetup":"confirmCardPayment"](s).then((function(e){if(e.error)throw e.error;var t=e[c?"setupIntent":"paymentIntent"];return"requires_capture"!==t.status&&"succeeded"!==t.status||(i.redirectUrl=a),i})).catch((function(e){return i.type=o,i.message=e.message,i.retry=!0,i.messageContext=r,window.fetch(a+"&is_ajax"),i}))},M=function(e,t,n,r){Object(l.useEffect)((function(){var o=t(function(){var t=T()(A.a.mark((function t(o){var i,c,a;return A.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=o.processingResponse,c=i.paymentDetails||{},t.next=4,I({stripe:e,paymentDetails:c,errorContext:r.noticeContexts.PAYMENTS,errorType:r.responseTypes.ERROR,successType:r.responseTypes.SUCCESS});case 4:return(a=t.sent).type===r.responseTypes.ERROR&&a.retry&&n(""),t.abrupt("return",a);case 7:case"end":return t.stop()}}),t)})));return function(_x){return t.apply(this,arguments)}}());return function(){return o()}}),[t,r.noticeContexts.PAYMENTS,r.responseTypes.ERROR,r.responseTypes.SUCCESS,n,e])},N=function(){},q=function(e){var t=e.eventRegistration,n=e.emitResponse,r=Object(R.useStripe)(),o=t.onCheckoutAfterProcessingWithSuccess;return M(r,o,N,n),null},L=n(12),D=n.n(L);function B(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function U(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?B(Object(n),!0).forEach((function(t){f()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):B(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var F={style:{base:{iconColor:"#666EE8",color:"#31325F",fontSize:function(e,t,n){var r={};if("object"===("undefined"==typeof document?"undefined":D()(document))&&"function"==typeof document.querySelector&&"function"==typeof window.getComputedStyle){var o=document.querySelector(".wc-block-checkout");o&&(r=window.getComputedStyle(o))}return r.fontSize||"16px"}(),lineHeight:1.375,"::placeholder":{color:"#fff"}}},classes:{focus:"focused",empty:"empty",invalid:"has-error"}},V=function(e){var t=Object(l.useState)(!1),n=a()(t,2),r=n[0],o=n[1],i=Object(l.useState)(U(U({},F),e)),c=a()(i,2),s=c[0],u=c[1],p=Object(l.useState)(""),d=a()(p,2),f=d[0],m=d[1];return Object(l.useEffect)((function(){var e=r?"#CFD7E0":"#fff";u((function(t){var n=void 0!==t.showIcon?{showIcon:r}:{};return U(U({},t),{},{style:U(U({},t.style),{},{base:U(U({},t.style.base),{},{"::placeholder":{color:e}})})},n)}))}),[r]),{options:s,onActive:Object(l.useCallback)((function(e){o(!e||function(e){return!e})}),[o]),error:f,setError:m}};function H(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function W(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?H(Object(n),!0).forEach((function(t){f()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):H(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var Y,z,Z,$,Q=function(e){var t=e.inputErrorComponent,n=e.onChange,r=Object(l.useState)(!0),o=a()(r,2),i=o[0],c=o[1],s=V({hidePostalCode:!0}),u=s.options,d=s.onActive,f=s.error,m=s.setError;return Object(l.createElement)(l.Fragment,null,Object(l.createElement)("div",{className:"wc-block-gateway-container wc-inline-card-element"},Object(l.createElement)(R.CardElement,{id:"wc-stripe-inline-card-element",className:"wc-block-gateway-input",options:u,onBlur:function(){return d(i)},onFocus:function(){return d(i)},onChange:function(e){e.error?m(e.error.message):m(""),c(e.empty),n(e)}}),Object(l.createElement)("label",{htmlFor:"wc-stripe-inline-card-element"},Object(p.__)("Credit Card Information","woocommerce-gateway-stripe"))),Object(l.createElement)(t,{errorMessage:f}))},G=function(e){var t=e.onChange,n=e.inputErrorComponent,r=Object(l.useState)({cardNumber:!0,cardExpiry:!0,cardCvc:!0}),o=a()(r,2),i=o[0],c=o[1],s=V({showIcon:!1}),u=s.options,d=s.onActive,m=s.error,y=s.setError,v=V(),b=v.options,_=v.onActive,g=v.error,h=v.setError,w=V(),O=w.options,E=w.onActive,j=w.error,C=w.setError,x=function(e,n){return function(r){r.error?e(r.error.message):e(""),c(W(W({},i),{},f()({},n,r.empty))),t(r)}};return Object(l.createElement)("div",{className:"wc-block-card-elements"},Object(l.createElement)("div",{className:"wc-block-gateway-container wc-card-number-element"},Object(l.createElement)(R.CardNumberElement,{onChange:x(y,"cardNumber"),options:u,className:"wc-block-gateway-input",id:"wc-stripe-card-number-element",onFocus:function(){return d(i.cardNumber)},onBlur:function(){return d(i.cardNumber)}}),Object(l.createElement)("label",{htmlFor:"wc-stripe-card-number-element"},Object(p.__)("Card Number","woocommerce-gateway-stripe")),Object(l.createElement)(n,{errorMessage:m})),Object(l.createElement)("div",{className:"wc-block-gateway-container wc-card-expiry-element"},Object(l.createElement)(R.CardExpiryElement,{onChange:x(h,"cardExpiry"),options:b,className:"wc-block-gateway-input",onFocus:function(){return _(i.cardExpiry)},onBlur:function(){return _(i.cardExpiry)},id:"wc-stripe-card-expiry-element"}),Object(l.createElement)("label",{htmlFor:"wc-stripe-card-expiry-element"},Object(p.__)("Expiry Date","woocommerce-gateway-stripe")),Object(l.createElement)(n,{errorMessage:g})),Object(l.createElement)("div",{className:"wc-block-gateway-container wc-card-cvc-element"},Object(l.createElement)(R.CardCvcElement,{onChange:x(C,"cardCvc"),options:O,className:"wc-block-gateway-input",onFocus:function(){return E(i.cardCvc)},onBlur:function(){return E(i.cardCvc)},id:"wc-stripe-card-code-element"}),Object(l.createElement)("label",{htmlFor:"wc-stripe-card-code-element"},Object(p.__)("CVV/CVC","woocommerce-gateway-stripe")),Object(l.createElement)(n,{errorMessage:j})))},K=function(){return Object.entries(v().icons).map((function(e){var t=a()(e,2),n=t[0],r=t[1];return{id:n,src:r.src,alt:r.alt}}))},J=function(e){var t=e.billing,n=e.eventRegistration,r=e.emitResponse,o=e.components,i=o.ValidationInputError,c=o.PaymentMethodIcons,s=Object(l.useState)(""),u=a()(s,2),p=u[0],d=u[1],f=Object(R.useStripe)(),m=function(e,t,n,r,o,i){var c=Object(l.useState)(""),s=a()(c,2),u=s[0],p=s[1],d=Object(l.useCallback)((function(e){var t,n=e.error.type,r=e.error.code||"",o=null!==(t=g(n,r))&&void 0!==t?t:e.error.message;return p(o),o}),[]),f=e.onCheckoutAfterProcessingWithSuccess,m=e.onPaymentProcessing,b=e.onCheckoutAfterProcessingWithError;return M(i,f,r,o),function(e,t,n,r,o,i,c,a){var s=Object(R.useElements)();Object(l.useEffect)((function(){var u=function(){var e=T()(A.a.mark((function e(t){var r;return A.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=v().inline_cc_form?R.CardElement:R.CardNumberElement,e.next=3,n.createSource(null==s?void 0:s.getElement(r),{type:"card",owner:t});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})));return function(_x){return e.apply(this,arguments)}}(),l=a(function(){var n=T()(A.a.mark((function n(){var a,s,l,p,d;return A.a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(n.prev=0,l=r.billingData,!t){n.next=4;break}return n.abrupt("return",{type:o.responseTypes.ERROR,message:t});case 4:if(""===i){n.next=6;break}return n.abrupt("return",{type:o.responseTypes.SUCCESS,meta:{paymentMethodData:{paymentMethod:"stripe",paymentRequestType:"cc",stripe_source:i},billingData:l}});case 6:return p={address:{line1:l.address_1,line2:l.address_2,city:l.city,state:l.state,postal_code:l.postcode,country:l.country}},l.phone&&(p.phone=l.phone),l.email&&(p.email=l.email),(l.first_name||l.last_name)&&(p.name="".concat(l.first_name," ").concat(l.last_name)),n.next=12,u(p);case 12:if(!(d=n.sent).error){n.next=15;break}return n.abrupt("return",{type:o.responseTypes.ERROR,message:e(d)});case 15:if(d.source&&d.source.id){n.next=17;break}throw new Error(g(y.API_ERROR));case 17:return c(d.source.id),n.abrupt("return",{type:o.responseTypes.SUCCESS,meta:{paymentMethodData:{stripe_source:d.source.id,billing_email:p.email,billing_first_name:null!==(a=null==l?void 0:l.first_name)&&void 0!==a?a:"",billing_last_name:null!==(s=null==l?void 0:l.last_name)&&void 0!==s?s:"",paymentMethod:"stripe",paymentRequestType:"cc"},billingData:l}});case 21:return n.prev=21,n.t0=n.catch(0),n.abrupt("return",{type:o.responseTypes.ERROR,message:n.t0});case 24:case"end":return n.stop()}}),n,null,[[0,21]])})));return function(){return n.apply(this,arguments)}}());return function(){l()}}),[a,r.billingData,n,i,c,e,t,o.noticeContexts.PAYMENTS,o.responseTypes.ERROR,o.responseTypes.SUCCESS,s])}(d,u,i,t,o,n,r,m),Object(l.useEffect)((function(){var e=b((function(e){var t,n=e.processingResponse;return null==n||null===(t=n.paymentDetails)||void 0===t||!t.errorMessage||{type:o.responseTypes.ERROR,message:n.paymentDetails.errorMessage,messageContext:o.noticeContexts.PAYMENTS}}));return function(){e()}}),[b,o.noticeContexts.PAYMENTS,o.responseTypes.ERROR]),d}(n,t,p,d,r,f),b=function(e){e.error&&m(e),d("")},_=K(),h=v().inline_cc_form?Object(l.createElement)(Q,{onChange:b,inputErrorComponent:i}):Object(l.createElement)(G,{onChange:b,inputErrorComponent:i});return Object(l.createElement)(l.Fragment,null,h,c&&_.length&&Object(l.createElement)(c,{icons:_,align:"left"}))},X=function(e){var t=e.stripe;return Object(l.createElement)(R.Elements,{stripe:t},Object(l.createElement)(J,e))},ee=S(),te=function(e){var t=e.RenderedComponent,n=u()(e,["RenderedComponent"]),r=Object(l.useState)(""),o=a()(r,2),c=o[0],s=o[1];return Object(l.useEffect)((function(){Promise.resolve(ee).then((function(e){var t=e.error;t&&s(t.message)}))}),[s]),Object(l.useEffect)((function(){if(c)throw new Error(c)}),[c]),Object(l.createElement)(t,i()({stripe:ee},n))},ne=K(),re={name:"stripe",label:Object(l.createElement)((function(e){var t=e.components.PaymentMethodLabel,n=v().title?v().title:Object(p.__)("Credit / Debit Card","woocommerce-gateway-stripe");return Object(l.createElement)(t,{text:n})}),null),content:Object(l.createElement)(te,{RenderedComponent:X}),edit:Object(l.createElement)(te,{RenderedComponent:X}),savedTokenComponent:Object(l.createElement)(te,{RenderedComponent:function(e){var t=e.stripe,n=u()(e,["stripe"]);return Object(l.createElement)(R.Elements,{stripe:t},Object(l.createElement)(q,n))}}),icons:ne,canMakePayment:function(){return ee},ariaLabel:Object(p.__)("Stripe Credit Card payment method","woocommerce-gateway-stripe"),supports:{showSavedCards:null!==(Y=v().showSavedCards)&&void 0!==Y&&Y,showSaveOption:null!==(z=v().showSaveOption)&&void 0!==z&&z,features:null!==(Z=null===($=v())||void 0===$?void 0:$.supports)&&void 0!==Z?Z:[]}},oe=function(e){var t,n=e.onButtonClicked,r=null===(t=v())||void 0===t?void 0:t.button,o=r.theme,i=void 0===o?"dark":o,c=r.locale,s=void 0===c?"en":c,u=r.height,p=void 0===u?"44":u,d=wc_stripe_payment_request_params.button.branded_type,f=["short","long"].includes(d)?d:"long",m=function(e,t,n){var r="long"===e?"https://www.gstatic.com/instantbuy/svg/".concat(t,"/").concat(n,".svg"):"https://www.gstatic.com/instantbuy/svg/".concat(t,"_gpay.svg"),o=Object(l.useState)(r),i=a()(o,2),c=i[0],s=i[1];return Object(l.useEffect)((function(){var e=document.createElement("img");e.addEventListener("error",(function(){s("https://www.gstatic.com/instantbuy/svg/".concat(t,"/en.svg"))})),e.src=c}),[c,t]),c}(f,"dark"===i?"dark":"light",s);return Object(l.createElement)("button",{type:"button",id:"wc-stripe-branded-button","aria-label":"Google Pay",className:"gpay-button ".concat(i," ").concat(f),style:{backgroundImage:"url(".concat(m,")"),height:p+"px"},onClick:n})},ie=function(e){var t=e.onButtonClicked,n=v().button,r=n.theme,o=void 0===r?"dark":r,i=n.height,c=void 0===i?"44":i,a=n.customLabel,s=void 0===a?Object(p.__)("Buy now","woocommerce-gateway-stripe"):a;return Object(l.createElement)("button",{type:"button",id:"wc-stripe-custom-button",className:"button ".concat(o," is-active"),style:{height:c+"px"},onClick:t},s)},ce=n(6),ae=n.n(ce);function se(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}var ue,le,pe=function(e){return wc_stripe_payment_request_params.ajax_url.toString().replace("%%endpoint%%","wc_stripe_"+e)},de=function(e){var t,n;(t=e.shippingOption,n={security:wc_stripe_payment_request_params.nonce.update_shipping,shipping_method:[t.id],is_product_page:wc_stripe_payment_request_params.is_product_page},ae.a.ajax({type:"POST",data:n,url:pe("update_shipping_method")})).then((function(t){"success"===t.result&&e.updateWith({status:"success",total:t.total,displayItems:t.displayItems}),"fail"===t.result&&e.updateWith({status:"fail"})}))},fe=function(e,t){Object(l.useEffect)((function(){var n=null==e?void 0:e.on("shippingaddresschange",function(e){return function(t){(function(e,t){var n=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?se(Object(n),!0).forEach((function(t){f()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):se(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({security:wc_stripe_payment_request_params.nonce.shipping,payment_request_type:t,is_product_page:wc_stripe_payment_request_params.is_product_page},function(e){return{country:e.country,state:e.region,postcode:e.postalCode,city:e.city,address:void 0===e.addressLine[0]?"":e.addressLine[0],address_2:void 0===e.addressLine[1]?"":e.addressLine[1]}}(e));return ae.a.ajax({type:"POST",data:n,url:pe("get_shipping_options")})})(t.shippingAddress,e).then((function(e){t.updateWith({status:e.result,shippingOptions:e.shipping_options,total:e.total,displayItems:e.displayItems})}))}}(t));return function(){null==n||n.removeAllListeners()}}),[e,t])},me=function(e,t,n,r){Object(l.useEffect)((function(){var o=null==t?void 0:t.on("source",function(e,t,n){return function(r){var o,i,c,a,s,u;"yes"===(null===(o=wc_stripe_payment_request_params)||void 0===o||null===(i=o.stripe)||void 0===i?void 0:i.allow_prepaid_card)||"prepaid"!==(null==r||null===(c=r.source)||void 0===c||null===(a=c.card)||void 0===a?void 0:a.funding)?function(e,t){var n=function(e,t){var n,r,o,i,c,a,s,u,l,p,d,f,m,y,v,b,_,g,h,w,O,E,j,C,x,S,R,P,T=e.source,k=null==T||null===(n=T.owner)||void 0===n?void 0:n.email,A=null==T||null===(r=T.owner)||void 0===r?void 0:r.phone,I=null==T||null===(o=T.owner)||void 0===o?void 0:o.address,M=null==T||null===(i=T.owner)||void 0===i?void 0:i.name,N=null==e?void 0:e.shippingAddress,q={_wpnonce:wc_stripe_payment_request_params.nonce.checkout,billing_first_name:null!==(c=null==M||null===(a=M.split(" "))||void 0===a||null===(s=a.slice(0,1))||void 0===s?void 0:s.join(" "))&&void 0!==c?c:"",billing_last_name:null!==(u=null==M||null===(l=M.split(" "))||void 0===l||null===(p=l.slice(1))||void 0===p?void 0:p.join(" "))&&void 0!==u?u:"",billing_company:"",billing_email:null!=k?k:null==e?void 0:e.payerEmail,billing_phone:null!=A?A:null==e||null===(d=e.payerPhone)||void 0===d?void 0:d.replace("/[() -]/g",""),billing_country:null!==(f=null==I?void 0:I.country)&&void 0!==f?f:"",billing_address_1:null!==(m=null==I?void 0:I.line1)&&void 0!==m?m:"",billing_address_2:null!==(y=null==I?void 0:I.line2)&&void 0!==y?y:"",billing_city:null!==(v=null==I?void 0:I.city)&&void 0!==v?v:"",billing_state:null!==(b=null==I?void 0:I.state)&&void 0!==b?b:"",billing_postcode:null!==(_=null==I?void 0:I.postal_code)&&void 0!==_?_:"",shipping_first_name:"",shipping_last_name:"",shipping_company:"",shipping_country:"",shipping_address_1:"",shipping_address_2:"",shipping_city:"",shipping_state:"",shipping_postcode:"",shipping_method:[null==e||null===(g=e.shippingOption)||void 0===g?void 0:g.id],order_comments:"",payment_method:"stripe",ship_to_different_address:1,terms:1,stripe_source:T.id,payment_request_type:t};return N&&(q.shipping_first_name=null==N||null===(h=N.recipient)||void 0===h||null===(w=h.split(" "))||void 0===w||null===(O=w.slice(0,1))||void 0===O?void 0:O.join(" "),q.shipping_last_name=null==N||null===(E=N.recipient)||void 0===E||null===(j=E.split(" "))||void 0===j||null===(C=j.slice(1))||void 0===C?void 0:C.join(" "),q.shipping_company=null==N?void 0:N.organization,q.shipping_country=null==N?void 0:N.country,q.shipping_address_1=null!==(x=null==N||null===(S=N.addressLine)||void 0===S?void 0:S[0])&&void 0!==x?x:"",q.shipping_address_2=null!==(R=null==N||null===(P=N.addressLine)||void 0===P?void 0:P[1])&&void 0!==R?R:"",q.shipping_city=null==N?void 0:N.city,q.shipping_state=null==N?void 0:N.region,q.shipping_postcode=null==N?void 0:N.postalCode),q}(e,t);return ae.a.ajax({type:"POST",data:n,dataType:"json",url:pe("create_order")})}(r,t).then(function(e,t,n){return function(r){if("success"===r.result){t.complete("success");var o=function(e){var t=e.match(/^#?confirm-(pi|si)-([^:]+):(.+)$/);if(t&&!(t.length<4))return{type:t[1],clientSecret:t[2],redirectUrl:decodeURIComponent(t[3])}}(r.redirect);if(!o||o.length<4)return void(window.location=r.redirect);var i=o.type,c=o.clientSecret,a=o.redirectUrl;(function(e,t,n){return"si"===t?e.handleCardSetup(n):e.handleCardPayment(n)})(e,i,c).then(function(e,t){return function(n){if(n.error)throw n.error;var r=function(e,t){return"si"===t?e.setupIntent:e.paymentIntent}(n,t);(function(e){return"requires_capture"===e.status}(r)||function(e){return"succeeded"===e.status}(r))&&(window.location=e)}}(a,i)).catch((function(e){n(e.message),ae.a.get(a+"&is_ajax")}))}else{var s,u;t.complete("fail");var l=document.createElement("div");l.innerHTML=r.messages;var p=null!==(s=null==l||null===(u=l.firstChild)||void 0===u?void 0:u.textContent)&&void 0!==s?s:"";n(p)}}}(e,r,n)):n(null===(s=wc_stripe_payment_request_params)||void 0===s||null===(u=s.i18n)||void 0===u?void 0:u.no_prepaid_card)}}(e,n,r));return function(){null==o||o.removeAllListeners()}}),[e,t,n,r])},ye=function(e){var t=e.billing,n=e.shippingData,r=e.onClick,o=e.onClose,i=e.setExpressPaymentError,c=Object(R.useStripe)(),s=function(e,t,n){var r=Object(l.useState)(null),o=a()(r,2),i=o[0],c=o[1],s=Object(l.useState)(null),u=a()(s,2),p=u[0],d=u[1];return Object(l.useEffect)((function(){var t;e&&!i&&(t={security:wc_stripe_payment_request_params.nonce.payment},ae.a.ajax({type:"POST",data:t,url:pe("get_cart_details")})).then((function(t){var n=function(e,t){var n={total:t.order_data.total,currency:t.order_data.currency,country:t.order_data.country_code,requestPayerName:!0,requestPayerEmail:!0,requestPayerPhone:wc_stripe_payment_request_params.checkout.needs_payer_phone,requestShipping:!!t.shipping_required,displayItems:t.order_data.displayItems};return"PR"===n.country&&(n.country="US"),e.paymentRequest(n)}(e,t);n.canMakePayment().then((function(e){e&&(c(n),e.applePay?d("apple_pay"):e.googlePay?d("google_pay"):d("payment_request_api"))}))}))}),[i,e]),Object(l.useEffect)((function(){c(null)}),[t,n.cartTotal,n.cartTotalItems,n.currency.code]),[i,p]}(c,n.needsShipping,t),u=a()(s,2),p=u[0],d=u[1];fe(p,d),function(e,t){Object(l.useEffect)((function(){var t=null==e?void 0:e.on("shippingoptionchange",de);return function(){null==t||t.removeAllListeners()}}),[e,t])}(p,d),me(c,p,d,i);var f=function(e,t){return Object(l.useCallback)((function(){e(""),t()}),[e,t])}(i,r);!function(e,t){Object(l.useEffect)((function(){null==e||e.on("cancel",(function(){t()}))}),[e,t])}(p,o);var m=v().button,y=m.type,b=void 0===y?"default":y,_=m.theme,g=void 0===_?"dark":_,h=m.height,w={paymentRequestButton:{type:b,theme:g,height:"".concat(void 0===h?"48":h,"px")}},O=wc_stripe_payment_request_params.button.is_branded,E=wc_stripe_payment_request_params.button.branded_type,j=wc_stripe_payment_request_params.button.is_custom;if(!p)return null;var C,x,S,P=function(){f(),p.show()};return j?Object(l.createElement)(ie,{onButtonClicked:P}):O&&(C=window.navigator.userAgent.toLowerCase(),S=(x=/chrome/.test(C)&&!/edge|edg|opr|brave\//.test(C)&&"Google Inc."===window.navigator.vendor)&&window.navigator.brave,x&&!S)?Object(l.createElement)(oe,{onButtonClicked:P}):(O&&(w.paymentRequestButton.type="long"===E?"buy":"default"),Object(l.createElement)(R.PaymentRequestButtonElement,{onClick:f,options:{style:w,paymentRequest:p}}))},ve=S(),be={name:"payment_request",content:Object(l.createElement)((function(e){var t=e.stripe;return Object(l.createElement)(R.Elements,{stripe:t},Object(l.createElement)(ye,e))}),{stripe:ve}),edit:Object(l.createElement)((function(){return Object(l.createElement)("img",{src:"data:image/svg+xml,%3Csvg width='264' height='48' viewBox='0 0 264 48' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='264' height='48' rx='3' fill='black'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M125.114 16.6407C125.682 15.93 126.067 14.9756 125.966 14C125.135 14.0415 124.121 14.549 123.533 15.2602C123.006 15.8693 122.539 16.8641 122.661 17.7983C123.594 17.8797 124.526 17.3317 125.114 16.6407Z' fill='white'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M125.955 17.982C124.601 17.9011 123.448 18.7518 122.801 18.7518C122.154 18.7518 121.163 18.0224 120.092 18.0421C118.696 18.0629 117.402 18.8524 116.694 20.1079C115.238 22.6196 116.31 26.3453 117.726 28.3909C118.414 29.4028 119.242 30.5174 120.334 30.4769C121.366 30.4365 121.77 29.8087 123.024 29.8087C124.277 29.8087 124.641 30.4769 125.733 30.4567C126.865 30.4365 127.573 29.4443 128.261 28.4313C129.049 27.2779 129.373 26.1639 129.393 26.1027C129.373 26.0825 127.209 25.2515 127.189 22.7606C127.169 20.6751 128.888 19.6834 128.969 19.6217C127.998 18.1847 126.481 18.0224 125.955 17.982Z' fill='white'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M136.131 23.1804H138.834C140.886 23.1804 142.053 22.0752 142.053 20.1592C142.053 18.2432 140.886 17.1478 138.845 17.1478H136.131V23.1804ZM139.466 15.1582C142.411 15.1582 144.461 17.1903 144.461 20.1483C144.461 23.1172 142.369 25.1596 139.392 25.1596H136.131V30.3498H133.775V15.1582H139.466Z' fill='white'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M152.198 26.224V25.3712L149.579 25.5397C148.106 25.6341 147.339 26.182 147.339 27.14C147.339 28.0664 148.138 28.6667 149.39 28.6667C150.988 28.6667 152.198 27.6449 152.198 26.224ZM145.046 27.2032C145.046 25.2551 146.529 24.1395 149.263 23.971L152.198 23.7922V22.9498C152.198 21.7181 151.388 21.0442 149.947 21.0442C148.758 21.0442 147.896 21.6548 147.717 22.5916H145.592C145.656 20.6232 147.507 19.1914 150.01 19.1914C152.703 19.1914 154.459 20.602 154.459 22.7917V30.351H152.282V28.5298H152.229C151.609 29.719 150.241 30.4666 148.758 30.4666C146.571 30.4666 145.046 29.1612 145.046 27.2032Z' fill='white'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M156.461 34.4145V32.5934C156.608 32.6141 156.965 32.6354 157.155 32.6354C158.196 32.6354 158.785 32.1932 159.142 31.0564L159.353 30.3824L155.366 19.3281H157.827L160.604 28.298H160.657L163.434 19.3281H165.832L161.698 30.9402C160.752 33.6038 159.668 34.4778 157.376 34.4778C157.197 34.4778 156.618 34.4565 156.461 34.4145Z' fill='white'/%3E%3C/svg%3E%0A",alt:""})}),null),canMakePayment:function(e){var t,n;return!(null===(t=null===(n=v())||void 0===n?void 0:n.isAdmin)||void 0===t||!t)||"undefined"!=typeof wc_stripe_payment_request_params&&S().then((function(t){var n,r,o,i,c;return t.paymentRequest({total:{label:"Total",amount:parseInt(null!==(n=null==e||null===(r=e.cartTotals)||void 0===r?void 0:r.total_price)&&void 0!==n?n:0,10),pending:!0},country:null===(o=Object(m.getSetting)("baseLocation",{}))||void 0===o?void 0:o.country,currency:null==e||null===(i=e.cartTotals)||void 0===i||null===(c=i.currency_code)||void 0===c?void 0:c.toLowerCase()}).canMakePayment()}))},paymentMethodId:"stripe",supports:{features:null!==(ue=null===(le=v())||void 0===le?void 0:le.supports)&&void 0!==ue?ue:[]}};Object(r.registerPaymentMethod)(re),Object(r.registerExpressPaymentMethod)(be)}]);
changelog.txt CHANGED
@@ -1,4 +1,20 @@
1
  *** Changelog ***
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  = 5.1.0 - 2021-04-07 =
3
  * Fix - Don't attempt to submit level 3 data for non-US merchants.
4
  * Fix - Hide Payment Request Buttons when guest checkout is disabled.
1
  *** Changelog ***
2
+
3
+ = 5.2.0 - 2021-05-19 =
4
+ * Fix - Use `get_parent` method to avoid accessing `order` subscription property directly.
5
+ * Fix - Orders won't transition to 'Refunded' state if refund can't be created.
6
+ * Fix - Normalize United Kingdom and Canada postal codes for Apple Pay.
7
+ * Fix - Subscription sign-up fees not included in total for Payment Request Button.
8
+ * Fix - Reduce requests sent to server from stripe settings page.
9
+ * Fix - Choose the appropriate version of the WooCommerce Admin Notes API based on which API is available.
10
+ * Fix - Customer information is now correctly displayed in the Stripe Payments Dashboard when a new customer checks out through the WooCommerce Checkout Block.
11
+ * Fix - Pass customer language/locale to Stripe upon creation or modification.
12
+ * Fix - Initial price for Variable Products is now correctly shown when a Payment Request is started.
13
+ * Add - Support for Credit Card payments (incl. 3DS payments) via WooCommerce Blocks; limited to WooCommerce Core product types.
14
+ * Add - Support for payments (incl. 3DS payments) paid via Payment Request Buttons in WooCommerce Blocks; limited to WooCommerce Core product types.
15
+ * Add - Support for custom and branded Payment Request Buttons when using the Cart and Checkout blocks.
16
+ * Tweak - Should customer opt to save their card, the card is now saved after a payment has been confirmed.
17
+
18
  = 5.1.0 - 2021-04-07 =
19
  * Fix - Don't attempt to submit level 3 data for non-US merchants.
20
  * Fix - Hide Payment Request Buttons when guest checkout is disabled.
includes/abstracts/abstract-wc-stripe-payment-gateway.php CHANGED
@@ -118,7 +118,7 @@ abstract class WC_Stripe_Payment_Gateway extends WC_Payment_Gateway_CC {
118
  return (
119
  $error &&
120
  'invalid_request_error' === $error->type &&
121
- preg_match( '/No such source/i', $error->message )
122
  );
123
  }
124
 
@@ -188,6 +188,12 @@ abstract class WC_Stripe_Payment_Gateway extends WC_Payment_Gateway_CC {
188
  return parent::is_available();
189
  }
190
 
 
 
 
 
 
 
191
  /**
192
  * Checks if we need to process pre orders when
193
  * pre orders is in the cart.
@@ -635,7 +641,7 @@ abstract class WC_Stripe_Payment_Gateway extends WC_Payment_Gateway_CC {
635
  * actually reusable. Either that or force_save_source is true.
636
  */
637
  if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
638
- $response = $customer->add_source( $source_object->id );
639
 
640
  if ( ! empty( $response->error ) ) {
641
  throw new WC_Stripe_Exception( print_r( $response, true ), $this->get_localized_error_message_from_response( $response ) );
@@ -665,7 +671,7 @@ abstract class WC_Stripe_Payment_Gateway extends WC_Payment_Gateway_CC {
665
 
666
  // This is true if the user wants to store the card to their account.
667
  if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
668
- $response = $customer->add_source( $stripe_token );
669
 
670
  if ( ! empty( $response->error ) ) {
671
  throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
@@ -673,7 +679,7 @@ abstract class WC_Stripe_Payment_Gateway extends WC_Payment_Gateway_CC {
673
  if ( is_wp_error( $response ) ) {
674
  throw new WC_Stripe_Exception( $response->get_error_message(), $response->get_error_message() );
675
  }
676
- $source_id = $response;
677
  } else {
678
  $source_id = $stripe_token;
679
  $is_token = true;
@@ -912,7 +918,14 @@ abstract class WC_Stripe_Payment_Gateway extends WC_Payment_Gateway_CC {
912
  if ( ! empty( $response->error ) ) {
913
  WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
914
 
915
- return $response;
 
 
 
 
 
 
 
916
 
917
  } elseif ( ! empty( $response->id ) ) {
918
  $formatted_amount = wc_price( $response->amount / 100 );
@@ -1080,6 +1093,13 @@ abstract class WC_Stripe_Payment_Gateway extends WC_Payment_Gateway_CC {
1080
  ],
1081
  ];
1082
 
 
 
 
 
 
 
 
1083
  if ( $prepared_source->customer ) {
1084
  $request['customer'] = $prepared_source->customer;
1085
  }
118
  return (
119
  $error &&
120
  'invalid_request_error' === $error->type &&
121
+ preg_match( '/No such (source|PaymentMethod)/i', $error->message )
122
  );
123
  }
124
 
188
  return parent::is_available();
189
  }
190
 
191
+ public function save_payment_method_requested() {
192
+ $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( wp_unslash( $_POST['payment_method'] ) ) : 'stripe';
193
+
194
+ return isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
195
+ }
196
+
197
  /**
198
  * Checks if we need to process pre orders when
199
  * pre orders is in the cart.
641
  * actually reusable. Either that or force_save_source is true.
642
  */
643
  if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
644
+ $response = $customer->attach_source( $source_object->id );
645
 
646
  if ( ! empty( $response->error ) ) {
647
  throw new WC_Stripe_Exception( print_r( $response, true ), $this->get_localized_error_message_from_response( $response ) );
671
 
672
  // This is true if the user wants to store the card to their account.
673
  if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
674
+ $response = $customer->attach_source( $stripe_token );
675
 
676
  if ( ! empty( $response->error ) ) {
677
  throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
679
  if ( is_wp_error( $response ) ) {
680
  throw new WC_Stripe_Exception( $response->get_error_message(), $response->get_error_message() );
681
  }
682
+ $source_id = $response->id;
683
  } else {
684
  $source_id = $stripe_token;
685
  $is_token = true;
918
  if ( ! empty( $response->error ) ) {
919
  WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
920
 
921
+ return new WP_Error(
922
+ 'stripe_error',
923
+ sprintf(
924
+ /* translators: %1$s is a stripe error message */
925
+ __( 'There was a problem initiating a refund: %1$s', 'woocommerce-gateway-stripe' ),
926
+ $response->error->message
927
+ )
928
+ );
929
 
930
  } elseif ( ! empty( $response->id ) ) {
931
  $formatted_amount = wc_price( $response->amount / 100 );
1093
  ],
1094
  ];
1095
 
1096
+ $force_save_source = apply_filters( 'wc_stripe_force_save_source', false, $prepared_source->source );
1097
+
1098
+ if ( $this->save_payment_method_requested() || $force_save_source ) {
1099
+ $request['setup_future_usage'] = 'off_session';
1100
+ $request['metadata']['save_payment_method'] = 'true';
1101
+ }
1102
+
1103
  if ( $prepared_source->customer ) {
1104
  $request['customer'] = $prepared_source->customer;
1105
  }
includes/admin/class-wc-stripe-inbox-notes.php CHANGED
@@ -1,11 +1,9 @@
1
  <?php
 
2
  if ( ! defined( 'ABSPATH' ) ) {
3
  exit;
4
  }
5
 
6
- use Automattic\WooCommerce\Admin\Notes\WC_Admin_Note;
7
- use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes;
8
-
9
  /**
10
  * Class that adds Inbox notifications.
11
  *
@@ -49,11 +47,8 @@ class WC_Stripe_Inbox_Notes {
49
  * Manage notes to show after Apple Pay domain verification.
50
  */
51
  public static function notify_on_apple_pay_domain_verification( $verification_complete ) {
52
- if ( ! class_exists( 'Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes' ) ) {
53
- return;
54
- }
55
-
56
- if ( ! class_exists( 'WC_Data_Store' ) ) {
57
  return;
58
  }
59
 
@@ -63,7 +58,7 @@ class WC_Stripe_Inbox_Notes {
63
  // Delete all previously created, soft deleted and unactioned failure notes (Legacy).
64
  while ( ! empty( $failure_note_ids ) ) {
65
  $note_id = array_pop( $failure_note_ids );
66
- $note = WC_Admin_Notes::get_note( $note_id );
67
  $note->delete();
68
  }
69
  } catch ( Exception $e ) {} // @codingStandardsIgnoreLine
@@ -121,10 +116,11 @@ class WC_Stripe_Inbox_Notes {
121
  }
122
 
123
  try {
124
- $note = new WC_Admin_Note();
 
125
  $note->set_title( self::get_success_title() );
126
  $note->set_content( __( 'Now that you accept Apple Pay® with Stripe, you can increase conversion rates by letting your customers know that Apple Pay is available. Here’s a marketing guide to help you get started.', 'woocommerce-gateway-stripe' ) );
127
- $note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_MARKETING );
128
  $note->set_name( self::SUCCESS_NOTE_NAME );
129
  $note->set_source( 'woocommerce-gateway-stripe' );
130
  $note->add_action(
@@ -141,10 +137,11 @@ class WC_Stripe_Inbox_Notes {
141
  */
142
  public static function create_failure_note() {
143
  try {
144
- $note = new WC_Admin_Note();
 
145
  $note->set_title( __( 'Apple Pay domain verification needed', 'woocommerce-gateway-stripe' ) );
146
  $note->set_content( __( 'The WooCommerce Stripe Gateway extension attempted to perform domain verification on behalf of your store, but was unable to do so. This must be resolved before Apple Pay can be offered to your customers.', 'woocommerce-gateway-stripe' ) );
147
- $note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
148
  $note->set_name( self::FAILURE_NOTE_NAME );
149
  $note->set_source( 'woocommerce-gateway-stripe' );
150
  $note->add_action(
@@ -162,11 +159,8 @@ class WC_Stripe_Inbox_Notes {
162
  * on/about 2020 Dec 22.
163
  */
164
  public static function cleanup_campaign_2020() {
165
- if ( ! class_exists( 'Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes' ) ) {
166
- return;
167
- }
168
-
169
- if ( ! class_exists( 'WC_Data_Store' ) ) {
170
  return;
171
  }
172
 
@@ -184,10 +178,11 @@ class WC_Stripe_Inbox_Notes {
184
 
185
  $deleted_an_unactioned_note = false;
186
 
 
187
  foreach ( (array) $note_ids as $note_id ) {
188
  try {
189
- $note = new WC_Admin_Note( $note_id );
190
- if ( WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED == $note->get_status() ) {
191
  $note->delete();
192
  $deleted_an_unactioned_note = true;
193
  }
1
  <?php
2
+
3
  if ( ! defined( 'ABSPATH' ) ) {
4
  exit;
5
  }
6
 
 
 
 
7
  /**
8
  * Class that adds Inbox notifications.
9
  *
47
  * Manage notes to show after Apple Pay domain verification.
48
  */
49
  public static function notify_on_apple_pay_domain_verification( $verification_complete ) {
50
+ $admin_notes_class = WC_Stripe_Woo_Compat_Utils::get_notes_class();
51
+ if ( ! class_exists( $admin_notes_class ) || ! class_exists( 'WC_Data_Store' ) ) {
 
 
 
52
  return;
53
  }
54
 
58
  // Delete all previously created, soft deleted and unactioned failure notes (Legacy).
59
  while ( ! empty( $failure_note_ids ) ) {
60
  $note_id = array_pop( $failure_note_ids );
61
+ $note = $admin_notes_class::get_note( $note_id );
62
  $note->delete();
63
  }
64
  } catch ( Exception $e ) {} // @codingStandardsIgnoreLine
116
  }
117
 
118
  try {
119
+ $admin_note_class = WC_Stripe_Woo_Compat_Utils::get_note_class();
120
+ $note = new $admin_note_class();
121
  $note->set_title( self::get_success_title() );
122
  $note->set_content( __( 'Now that you accept Apple Pay® with Stripe, you can increase conversion rates by letting your customers know that Apple Pay is available. Here’s a marketing guide to help you get started.', 'woocommerce-gateway-stripe' ) );
123
+ $note->set_type( $admin_note_class::E_WC_ADMIN_NOTE_MARKETING );
124
  $note->set_name( self::SUCCESS_NOTE_NAME );
125
  $note->set_source( 'woocommerce-gateway-stripe' );
126
  $note->add_action(
137
  */
138
  public static function create_failure_note() {
139
  try {
140
+ $admin_note_class = WC_Stripe_Woo_Compat_Utils::get_note_class();
141
+ $note = new $admin_note_class();
142
  $note->set_title( __( 'Apple Pay domain verification needed', 'woocommerce-gateway-stripe' ) );
143
  $note->set_content( __( 'The WooCommerce Stripe Gateway extension attempted to perform domain verification on behalf of your store, but was unable to do so. This must be resolved before Apple Pay can be offered to your customers.', 'woocommerce-gateway-stripe' ) );
144
+ $note->set_type( $admin_note_class::E_WC_ADMIN_NOTE_INFORMATIONAL );
145
  $note->set_name( self::FAILURE_NOTE_NAME );
146
  $note->set_source( 'woocommerce-gateway-stripe' );
147
  $note->add_action(
159
  * on/about 2020 Dec 22.
160
  */
161
  public static function cleanup_campaign_2020() {
162
+ $admin_notes_class = WC_Stripe_Woo_Compat_Utils::get_notes_class();
163
+ if ( ! class_exists( $admin_notes_class ) || ! class_exists( 'WC_Data_Store' ) ) {
 
 
 
164
  return;
165
  }
166
 
178
 
179
  $deleted_an_unactioned_note = false;
180
 
181
+ $admin_note_class = WC_Stripe_Woo_Compat_Utils::get_note_class();
182
  foreach ( (array) $note_ids as $note_id ) {
183
  try {
184
+ $note = new $admin_note_class( $note_id );
185
+ if ( $admin_note_class::E_WC_ADMIN_NOTE_UNACTIONED == $note->get_status() ) {
186
  $note->delete();
187
  $deleted_an_unactioned_note = true;
188
  }
includes/admin/stripe-settings.php CHANGED
@@ -3,39 +3,6 @@ if ( ! defined( 'ABSPATH' ) ) {
3
  exit;
4
  }
5
 
6
- if ( woocommerce_gateway_stripe()->connect->is_connected() ) {
7
- $reset_link = add_query_arg(
8
- [
9
- '_wpnonce' => wp_create_nonce( 'reset_stripe_api_credentials' ),
10
- 'reset_stripe_api_credentials' => true,
11
- ],
12
- admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' )
13
- );
14
-
15
- $api_credentials_text = sprintf(
16
- /* translators: %1, %2, %3, and %4 are all HTML markup tags */
17
- __( '%1$sClear all Stripe account keys.%2$s %3$sThis will disable any connection to Stripe.%4$s', 'woocommerce-gateway-stripe' ),
18
- '<a id="wc_stripe_connect_button" href="' . $reset_link . '" class="button button-secondary">',
19
- '</a>',
20
- '<span style="color:red;">',
21
- '</span>'
22
- );
23
- } else {
24
- $oauth_url = woocommerce_gateway_stripe()->connect->get_oauth_url();
25
-
26
- if ( ! is_wp_error( $oauth_url ) ) {
27
- $api_credentials_text = sprintf(
28
- /* translators: %1, %2 and %3 are all HTML markup tags */
29
- __( '%1$sSetup or link an existing Stripe account.%2$s By clicking this button you agree to the %3$sTerms of Service%2$s. Or, manually enter Stripe account keys below.', 'woocommerce-gateway-stripe' ),
30
- '<a id="wc_stripe_connect_button" href="' . $oauth_url . '" class="button button-primary">',
31
- '</a>',
32
- '<a href="https://wordpress.com/tos">'
33
- );
34
- } else {
35
- $api_credentials_text = __( 'Manually enter Stripe keys below.', 'woocommerce-gateway-stripe' );
36
- }
37
- }
38
-
39
  return apply_filters(
40
  'wc_stripe_settings',
41
  [
@@ -62,8 +29,7 @@ return apply_filters(
62
  ],
63
  'api_credentials' => [
64
  'title' => __( 'Stripe Account Keys', 'woocommerce-gateway-stripe' ),
65
- 'type' => 'title',
66
- 'description' => $api_credentials_text,
67
  ],
68
  'testmode' => [
69
  'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ),
3
  exit;
4
  }
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  return apply_filters(
7
  'wc_stripe_settings',
8
  [
29
  ],
30
  'api_credentials' => [
31
  'title' => __( 'Stripe Account Keys', 'woocommerce-gateway-stripe' ),
32
+ 'type' => 'stripe_account_keys',
 
33
  ],
34
  'testmode' => [
35
  'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ),
includes/class-wc-gateway-stripe.php CHANGED
@@ -442,6 +442,7 @@ class WC_Gateway_Stripe extends WC_Stripe_Payment_Gateway {
442
  ]
443
  );
444
 
 
445
  $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
446
  $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
447
  $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
@@ -627,6 +628,12 @@ class WC_Gateway_Stripe extends WC_Stripe_Payment_Gateway {
627
  $intent = $this->confirm_intent( $intent, $order, $prepared_source );
628
  }
629
 
 
 
 
 
 
 
630
  if ( ! empty( $intent->error ) ) {
631
  $this->maybe_remove_non_existent_customer( $intent->error, $order );
632
 
@@ -703,6 +710,28 @@ class WC_Gateway_Stripe extends WC_Stripe_Payment_Gateway {
703
  }
704
  }
705
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
706
  /**
707
  * Displays the Stripe fee
708
  *
@@ -1013,14 +1042,19 @@ class WC_Gateway_Stripe extends WC_Stripe_Payment_Gateway {
1013
  }
1014
 
1015
  // Put the final thank you page redirect into the verification URL.
1016
- $verification_url = add_query_arg(
1017
- [
1018
- 'order' => $order_id,
1019
- 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ),
1020
- 'redirect_to' => rawurlencode( $result['redirect'] ),
1021
- ],
1022
- WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' )
1023
- );
 
 
 
 
 
1024
 
1025
  if ( isset( $result['payment_intent_secret'] ) ) {
1026
  $redirect = sprintf( '#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode( $verification_url ) );
@@ -1232,4 +1266,48 @@ class WC_Gateway_Stripe extends WC_Stripe_Payment_Gateway {
1232
  }
1233
  return $settings;
1234
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1235
  }
442
  ]
443
  );
444
 
445
+ $stripe_params['stripe_locale'] = WC_Stripe_Helper::convert_wc_locale_to_stripe_locale( get_locale() );
446
  $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
447
  $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
448
  $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
628
  $intent = $this->confirm_intent( $intent, $order, $prepared_source );
629
  }
630
 
631
+ $force_save_source_value = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $prepared_source->source );
632
+
633
+ if ( 'succeeded' === $intent->status && ! $this->is_using_saved_payment_method() && ( $this->save_payment_method_requested() || $force_save_source_value ) ) {
634
+ $this->save_payment_method( $prepared_source->source_object );
635
+ }
636
+
637
  if ( ! empty( $intent->error ) ) {
638
  $this->maybe_remove_non_existent_customer( $intent->error, $order );
639
 
710
  }
711
  }
712
 
713
+ /**
714
+ * Saves payment method
715
+ *
716
+ * @param object $source_object
717
+ * @throws WC_Stripe_Exception
718
+ */
719
+ public function save_payment_method( $source_object ) {
720
+ $user_id = get_current_user_id();
721
+ $customer = new WC_Stripe_Customer( $user_id );
722
+
723
+ if ( ( $user_id && 'reusable' === $source_object->usage ) ) {
724
+ $response = $customer->add_source( $source_object->id );
725
+
726
+ if ( ! empty( $response->error ) ) {
727
+ throw new WC_Stripe_Exception( print_r( $response, true ), $this->get_localized_error_message_from_response( $response ) );
728
+ }
729
+ if ( is_wp_error( $response ) ) {
730
+ throw new WC_Stripe_Exception( $response->get_error_message(), $response->get_error_message() );
731
+ }
732
+ }
733
+ }
734
+
735
  /**
736
  * Displays the Stripe fee
737
  *
1042
  }
1043
 
1044
  // Put the final thank you page redirect into the verification URL.
1045
+ $query_params = [
1046
+ 'order' => $order_id,
1047
+ 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ),
1048
+ 'redirect_to' => rawurlencode( $result['redirect'] ),
1049
+ ];
1050
+
1051
+ $force_save_source_value = apply_filters( 'wc_stripe_force_save_source', false );
1052
+
1053
+ if ( $this->save_payment_method_requested() || $force_save_source_value ) {
1054
+ $query_params['save_payment_method'] = true;
1055
+ }
1056
+
1057
+ $verification_url = add_query_arg( $query_params, WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) );
1058
 
1059
  if ( isset( $result['payment_intent_secret'] ) ) {
1060
  $redirect = sprintf( '#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode( $verification_url ) );
1266
  }
1267
  return $settings;
1268
  }
1269
+
1270
+ /**
1271
+ * This is overloading the title type so the oauth url is only fetched if we are on the settings page.
1272
+ *
1273
+ * @param string $key Field key.
1274
+ * @param array $data Field data.
1275
+ * @return string
1276
+ */
1277
+ public function generate_stripe_account_keys_html( $key, $data ) {
1278
+ if ( woocommerce_gateway_stripe()->connect->is_connected() ) {
1279
+ $reset_link = add_query_arg(
1280
+ [
1281
+ '_wpnonce' => wp_create_nonce( 'reset_stripe_api_credentials' ),
1282
+ 'reset_stripe_api_credentials' => true,
1283
+ ],
1284
+ admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' )
1285
+ );
1286
+
1287
+ $api_credentials_text = sprintf(
1288
+ /* translators: %1, %2, %3, and %4 are all HTML markup tags */
1289
+ __( '%1$sClear all Stripe account keys.%2$s %3$sThis will disable any connection to Stripe.%4$s', 'woocommerce-gateway-stripe' ),
1290
+ '<a id="wc_stripe_connect_button" href="' . $reset_link . '" class="button button-secondary">',
1291
+ '</a>',
1292
+ '<span style="color:red;">',
1293
+ '</span>'
1294
+ );
1295
+ } else {
1296
+ $oauth_url = woocommerce_gateway_stripe()->connect->get_oauth_url();
1297
+
1298
+ if ( ! is_wp_error( $oauth_url ) ) {
1299
+ $api_credentials_text = sprintf(
1300
+ /* translators: %1, %2 and %3 are all HTML markup tags */
1301
+ __( '%1$sSetup or link an existing Stripe account.%2$s By clicking this button you agree to the %3$sTerms of Service%2$s. Or, manually enter Stripe account keys below.', 'woocommerce-gateway-stripe' ),
1302
+ '<a id="wc_stripe_connect_button" href="' . $oauth_url . '" class="button button-primary">',
1303
+ '</a>',
1304
+ '<a href="https://wordpress.com/tos">'
1305
+ );
1306
+ } else {
1307
+ $api_credentials_text = __( 'Manually enter Stripe keys below.', 'woocommerce-gateway-stripe' );
1308
+ }
1309
+ }
1310
+ $data['description'] = $api_credentials_text;
1311
+ return $this->generate_title_html( $key, $data );
1312
+ }
1313
  }
includes/class-wc-stripe-api.php CHANGED
@@ -57,9 +57,10 @@ class WC_Stripe_API {
57
  */
58
  public static function get_user_agent() {
59
  $app_info = [
60
- 'name' => 'WooCommerce Stripe Gateway',
61
- 'version' => WC_STRIPE_VERSION,
62
- 'url' => 'https://woocommerce.com/products/stripe/',
 
63
  ];
64
 
65
  return [
@@ -81,15 +82,19 @@ class WC_Stripe_API {
81
  $user_agent = self::get_user_agent();
82
  $app_info = $user_agent['application'];
83
 
84
- return apply_filters(
85
  'woocommerce_stripe_request_headers',
86
  [
87
- 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
88
- 'Stripe-Version' => self::STRIPE_API_VERSION,
89
- 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')',
90
- 'X-Stripe-Client-User-Agent' => wp_json_encode( $user_agent ),
91
  ]
92
  );
 
 
 
 
 
 
93
  }
94
 
95
  /**
57
  */
58
  public static function get_user_agent() {
59
  $app_info = [
60
+ 'name' => 'WooCommerce Stripe Gateway',
61
+ 'version' => WC_STRIPE_VERSION,
62
+ 'url' => 'https://woocommerce.com/products/stripe/',
63
+ 'partner_id' => 'pp_partner_EYuSt9peR0WTMg',
64
  ];
65
 
66
  return [
82
  $user_agent = self::get_user_agent();
83
  $app_info = $user_agent['application'];
84
 
85
+ $headers = apply_filters(
86
  'woocommerce_stripe_request_headers',
87
  [
88
+ 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ),
89
+ 'Stripe-Version' => self::STRIPE_API_VERSION,
 
 
90
  ]
91
  );
92
+
93
+ // These headers should not be overridden for this gateway.
94
+ $headers['User-Agent'] = $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')';
95
+ $headers['X-Stripe-Client-User-Agent'] = wp_json_encode( $user_agent );
96
+
97
+ return $headers;
98
  }
99
 
100
  /**
includes/class-wc-stripe-blocks-support.php ADDED
@@ -0,0 +1,337 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
3
+ use Automattic\WooCommerce\Blocks\Payments\PaymentResult;
4
+ use Automattic\WooCommerce\Blocks\Payments\PaymentContext;
5
+
6
+ defined( 'ABSPATH' ) || exit;
7
+
8
+ /**
9
+ * WC_Stripe_Blocks_Support class.
10
+ *
11
+ * @extends AbstractPaymentMethodType
12
+ */
13
+ final class WC_Stripe_Blocks_Support extends AbstractPaymentMethodType {
14
+ /**
15
+ * Payment method name defined by payment methods extending this class.
16
+ *
17
+ * @var string
18
+ */
19
+ protected $name = 'stripe';
20
+
21
+ /**
22
+ * Constructor
23
+ */
24
+ public function __construct() {
25
+ add_action( 'woocommerce_rest_checkout_process_payment_with_context', [ $this, 'add_payment_request_order_meta' ], 8, 2 );
26
+ add_action( 'woocommerce_rest_checkout_process_payment_with_context', [ $this, 'add_stripe_intents' ], 9999, 2 );
27
+ }
28
+
29
+ /**
30
+ * Initializes the payment method type.
31
+ */
32
+ public function initialize() {
33
+ $this->settings = get_option( 'woocommerce_stripe_settings', [] );
34
+ }
35
+
36
+ /**
37
+ * Returns if this payment method should be active. If false, the scripts will not be enqueued.
38
+ *
39
+ * @return boolean
40
+ */
41
+ public function is_active() {
42
+ return ! empty( $this->settings['enabled'] ) && 'yes' === $this->settings['enabled'];
43
+ }
44
+
45
+ /**
46
+ * Returns an array of scripts/handles to be registered for this payment method.
47
+ *
48
+ * @return array
49
+ */
50
+ public function get_payment_method_script_handles() {
51
+ $asset_path = WC_STRIPE_PLUGIN_PATH . '/build/index.asset.php';
52
+ $version = WC_STRIPE_VERSION;
53
+ $dependencies = [];
54
+ if ( file_exists( $asset_path ) ) {
55
+ $asset = require $asset_path;
56
+ $version = is_array( $asset ) && isset( $asset['version'] )
57
+ ? $asset['version']
58
+ : $version;
59
+ $dependencies = is_array( $asset ) && isset( $asset['dependencies'] )
60
+ ? $asset['dependencies']
61
+ : $dependencies;
62
+ }
63
+ wp_register_script(
64
+ 'wc-stripe-blocks-integration',
65
+ WC_STRIPE_PLUGIN_URL . '/build/index.js',
66
+ $dependencies,
67
+ $version,
68
+ true
69
+ );
70
+ wp_set_script_translations(
71
+ 'wc-stripe-blocks-integration',
72
+ 'woocommerce-gateway-stripe'
73
+ );
74
+
75
+ return [ 'wc-stripe-blocks-integration' ];
76
+ }
77
+
78
+ /**
79
+ * Returns an array of key=>value pairs of data made available to the payment methods script.
80
+ *
81
+ * @return array
82
+ */
83
+ public function get_payment_method_data() {
84
+ return [
85
+ 'stripeTotalLabel' => $this->get_total_label(),
86
+ 'publicKey' => $this->get_publishable_key(),
87
+ 'allowPrepaidCard' => $this->get_allow_prepaid_card(),
88
+ 'title' => $this->get_title(),
89
+ 'button' => [
90
+ 'type' => $this->get_button_type(),
91
+ 'theme' => $this->get_button_theme(),
92
+ 'height' => $this->get_button_height(),
93
+ 'locale' => $this->get_button_locale(),
94
+ 'customLabel' => isset( $this->settings['payment_request_button_label'] ) ? $this->settings['payment_request_button_label'] : 'Buy now',
95
+ ],
96
+ 'inline_cc_form' => $this->get_inline_cc_form(),
97
+ 'icons' => $this->get_icons(),
98
+ 'showSavedCards' => $this->get_show_saved_cards(),
99
+ 'showSaveOption' => $this->get_show_save_option(),
100
+ 'supports' => $this->get_supported_features(),
101
+ 'stripeLocale' => WC_Stripe_Helper::convert_wc_locale_to_stripe_locale( get_locale() ),
102
+ 'isAdmin' => is_admin(),
103
+ ];
104
+ }
105
+
106
+ /**
107
+ * Determine if store allows cards to be saved during checkout.
108
+ *
109
+ * @return bool True if merchant allows shopper to save card (payment method) during checkout.
110
+ */
111
+ private function get_show_saved_cards() {
112
+ return isset( $this->settings['saved_cards'] ) ? 'yes' === $this->settings['saved_cards'] : false;
113
+ }
114
+
115
+ /**
116
+ * Determine if the checkbox to enable the user to save their payment method should be shown.
117
+ *
118
+ * @return bool True if the save payment checkbox should be displayed to the user.
119
+ */
120
+ private function get_show_save_option() {
121
+ $saved_cards = $this->get_show_saved_cards();
122
+ // This assumes that Stripe supports `tokenization` - currently this is true, based on
123
+ // https://github.com/woocommerce/woocommerce-gateway-stripe/blob/master/includes/class-wc-gateway-stripe.php#L95 .
124
+ // See https://github.com/woocommerce/woocommerce-gateway-stripe/blob/ad19168b63df86176cbe35c3e95203a245687640/includes/class-wc-gateway-stripe.php#L271 and
125
+ // https://github.com/woocommerce/woocommerce/wiki/Payment-Token-API .
126
+ return apply_filters( 'wc_stripe_display_save_payment_method_checkbox', filter_var( $saved_cards, FILTER_VALIDATE_BOOLEAN ) );
127
+ }
128
+
129
+ /**
130
+ * Returns the label to use accompanying the total in the stripe statement.
131
+ *
132
+ * @return string Statement descriptor.
133
+ */
134
+ private function get_total_label() {
135
+ return ! empty( $this->settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->settings['statement_descriptor'] ) : '';
136
+ }
137
+
138
+ /**
139
+ * Returns the publishable api key for the Stripe service.
140
+ *
141
+ * @return string Public api key.
142
+ */
143
+ private function get_publishable_key() {
144
+ $test_mode = ( ! empty( $this->settings['testmode'] ) && 'yes' === $this->settings['testmode'] );
145
+ $setting_key = $test_mode ? 'test_publishable_key' : 'publishable_key';
146
+ return ! empty( $this->settings[ $setting_key ] ) ? $this->settings[ $setting_key ] : '';
147
+ }
148
+
149
+ /**
150
+ * Returns whether to allow prepaid cards for payments.
151
+ *
152
+ * @return bool True means to allow prepaid card (default).
153
+ */
154
+ private function get_allow_prepaid_card() {
155
+ return apply_filters( 'wc_stripe_allow_prepaid_card', true );
156
+ }
157
+
158
+ /**
159
+ * Returns the title string to use in the UI (customisable via admin settings screen).
160
+ *
161
+ * @return string Title / label string
162
+ */
163
+ private function get_title() {
164
+ return isset( $this->settings['title'] ) ? $this->settings['title'] : __( 'Credit / Debit Card', 'woocommerce-gateway-stripe' );
165
+ }
166
+
167
+ /**
168
+ * Return the button type for the payment button.
169
+ *
170
+ * @return string Defaults to 'default'.
171
+ */
172
+ private function get_button_type() {
173
+ return isset( $this->settings['payment_request_button_type'] ) ? $this->settings['payment_request_button_type'] : 'default';
174
+ }
175
+
176
+ /**
177
+ * Return the theme to use for the payment button.
178
+ *
179
+ * @return string Defaults to 'dark'.
180
+ */
181
+ private function get_button_theme() {
182
+ return isset( $this->settings['payment_request_button_theme'] ) ? $this->settings['payment_request_button_theme'] : 'dark';
183
+ }
184
+
185
+ /**
186
+ * Return the height for the payment button.
187
+ *
188
+ * @return string A pixel value for the height (defaults to '64').
189
+ */
190
+ private function get_button_height() {
191
+ return isset( $this->settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->settings['payment_request_button_height'] ) : '64';
192
+ }
193
+
194
+ /**
195
+ * Return the inline cc option.
196
+ *
197
+ * @return boolean True if the inline CC form option is enabled.
198
+ */
199
+ private function get_inline_cc_form() {
200
+ return isset( $this->settings['inline_cc_form'] ) && 'yes' === $this->settings['inline_cc_form'];
201
+ }
202
+
203
+ /**
204
+ * Return the locale for the payment button.
205
+ *
206
+ * @return string Defaults to en_US.
207
+ */
208
+ private function get_button_locale() {
209
+ return apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) );
210
+ }
211
+
212
+ /**
213
+ * Return the icons urls.
214
+ *
215
+ * @return array Arrays of icons metadata.
216
+ */
217
+ private function get_icons() {
218
+ $icons_src = [
219
+ 'visa' => [
220
+ 'src' => WC_STRIPE_PLUGIN_URL . '/assets/images/visa.svg',
221
+ 'alt' => __( 'Visa', 'woocommerce-gateway-stripe' ),
222
+ ],
223
+ 'amex' => [
224
+ 'src' => WC_STRIPE_PLUGIN_URL . '/assets/images/amex.svg',
225
+ 'alt' => __( 'American Express', 'woocommerce-gateway-stripe' ),
226
+ ],
227
+ 'mastercard' => [
228
+ 'src' => WC_STRIPE_PLUGIN_URL . '/assets/images/mastercard.svg',
229
+ 'alt' => __( 'Mastercard', 'woocommerce-gateway-stripe' ),
230
+ ],
231
+ ];
232
+
233
+ if ( 'USD' === get_woocommerce_currency() ) {
234
+ $icons_src['discover'] = [
235
+ 'src' => WC_STRIPE_PLUGIN_URL . '/assets/images/discover.svg',
236
+ 'alt' => __( 'Discover', 'woocommerce-gateway-stripe' ),
237
+ ];
238
+ $icons_src['jcb'] = [
239
+ 'src' => WC_STRIPE_PLUGIN_URL . '/assets/images/jcb.svg',
240
+ 'alt' => __( 'JCB', 'woocommerce-gateway-stripe' ),
241
+ ];
242
+ $icons_src['diners'] = [
243
+ 'src' => WC_STRIPE_PLUGIN_URL . '/assets/images/diners.svg',
244
+ 'alt' => __( 'Diners', 'woocommerce-gateway-stripe' ),
245
+ ];
246
+ }
247
+ return $icons_src;
248
+ }
249
+
250
+ /**
251
+ * Add payment request data to the order meta as hooked on the
252
+ * woocommerce_rest_checkout_process_payment_with_context action.
253
+ *
254
+ * @param PaymentContext $context Holds context for the payment.
255
+ * @param PaymentResult $result Result object for the payment.
256
+ */
257
+ public function add_payment_request_order_meta( PaymentContext $context, PaymentResult &$result ) {
258
+ $data = $context->payment_data;
259
+ if ( ! empty( $data['payment_request_type'] ) && 'stripe' === $context->payment_method ) {
260
+ $this->add_order_meta( $context->order, $data['payment_request_type'] );
261
+ }
262
+
263
+ // hook into stripe error processing so that we can capture the error to
264
+ // payment details (which is added to notices and thus not helpful for
265
+ // this context).
266
+ if ( 'stripe' === $context->payment_method ) {
267
+ add_action(
268
+ 'wc_gateway_stripe_process_payment_error',
269
+ function( $error ) use ( &$result ) {
270
+ $payment_details = $result->payment_details;
271
+ $payment_details['errorMessage'] = wp_strip_all_tags( $error->getLocalizedMessage() );
272
+ $result->set_payment_details( $payment_details );
273
+ }
274
+ );
275
+ }
276
+ }
277
+
278
+ /**
279
+ * Handles any potential stripe intents on the order that need handled.
280
+ *
281
+ * This is configured to execute after legacy payment processing has
282
+ * happened on the woocommerce_rest_checkout_process_payment_with_context
283
+ * action hook.
284
+ *
285
+ * @param PaymentContext $context Holds context for the payment.
286
+ * @param PaymentResult $result Result object for the payment.
287
+ */
288
+ public function add_stripe_intents( PaymentContext $context, PaymentResult &$result ) {
289
+ if ( 'stripe' === $context->payment_method
290
+ && (
291
+ ! empty( $result->payment_details['payment_intent_secret'] )
292
+ || ! empty( $result->payment_details['setup_intent_secret'] )
293
+ )
294
+ ) {
295
+ $payment_details = $result->payment_details;
296
+ $payment_details['verification_endpoint'] = add_query_arg(
297
+ [
298
+ 'order' => $context->order->get_id(),
299
+ 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ),
300
+ 'redirect_to' => rawurlencode( $result->redirect_url ),
301
+ ],
302
+ home_url() . \WC_Ajax::get_endpoint( 'wc_stripe_verify_intent' )
303
+ );
304
+ $result->set_payment_details( $payment_details );
305
+ $result->set_status( 'success' );
306
+ }
307
+ }
308
+
309
+ /**
310
+ * Handles adding information about the payment request type used to the order meta.
311
+ *
312
+ * @param \WC_Order $order The order being processed.
313
+ * @param string $payment_request_type The payment request type used for payment.
314
+ */
315
+ private function add_order_meta( \WC_Order $order, $payment_request_type ) {
316
+ if ( 'apple_pay' === $payment_request_type ) {
317
+ $order->set_payment_method_title( 'Apple Pay (Stripe)' );
318
+ $order->save();
319
+ } elseif ( 'google_pay' === $payment_request_type ) {
320
+ $order->set_payment_method_title( 'Google Pay (Stripe)' );
321
+ $order->save();
322
+ } elseif ( 'payment_request_api' === $payment_request_type ) {
323
+ $order->set_payment_method_title( 'Payment Request (Stripe)' );
324
+ $order->save();
325
+ }
326
+ }
327
+
328
+ /**
329
+ * Returns an array of supported features.
330
+ *
331
+ * @return string[]
332
+ */
333
+ public function get_supported_features() {
334
+ $gateway = new WC_Gateway_Stripe();
335
+ return array_filter( $gateway->supports, [ $gateway, 'supports' ] );
336
+ }
337
+ }
includes/class-wc-stripe-customer.php CHANGED
@@ -156,8 +156,9 @@ class WC_Stripe_Customer {
156
  }
157
  }
158
 
159
- $metadata = [];
160
- $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user );
 
161
 
162
  return wp_parse_args( $args, $defaults );
163
  }
@@ -265,7 +266,7 @@ class WC_Stripe_Customer {
265
  * @return WP_Error|int
266
  */
267
  public function add_source( $source_id ) {
268
- $response = $this->attach_source( $source_id );
269
 
270
  if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
271
  return $response;
@@ -484,4 +485,58 @@ class WC_Stripe_Customer {
484
  $this->delete_id_from_meta();
485
  return $this->create_customer();
486
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
487
  }
156
  }
157
  }
158
 
159
+ $metadata = [];
160
+ $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user );
161
+ $defaults['preferred_locales'] = $this->get_customer_preferred_locale( $user );
162
 
163
  return wp_parse_args( $args, $defaults );
164
  }
266
  * @return WP_Error|int
267
  */
268
  public function add_source( $source_id ) {
269
+ $response = WC_Stripe_API::retrieve( 'sources/' . $source_id );
270
 
271
  if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
272
  return $response;
485
  $this->delete_id_from_meta();
486
  return $this->create_customer();
487
  }
488
+
489
+ /**
490
+ * Get the customer's preferred locale based on the user or site setting.
491
+ *
492
+ * @param object $user The user being created/modified.
493
+ * @return array The matched locale string wrapped in an array, or empty default.
494
+ */
495
+ public function get_customer_preferred_locale( $user ) {
496
+ $locale = $this->get_customer_locale( $user );
497
+
498
+ // Options based on Stripe locales.
499
+ // https://support.stripe.com/questions/language-options-for-customer-emails
500
+ $stripe_locales = [
501
+ 'ar' => 'ar-AR',
502
+ 'da_DK' => 'da-DK',
503
+ 'de_DE' => 'de-DE',
504
+ 'en' => 'en-US',
505
+ 'es_ES' => 'es-ES',
506
+ 'es_CL' => 'es-419',
507
+ 'es_AR' => 'es-419',
508
+ 'es_CO' => 'es-419',
509
+ 'es_PE' => 'es-419',
510
+ 'es_UY' => 'es-419',
511
+ 'es_PR' => 'es-419',
512
+ 'es_GT' => 'es-419',
513
+ 'es_EC' => 'es-419',
514
+ 'es_MX' => 'es-419',
515
+ 'es_VE' => 'es-419',
516
+ 'es_CR' => 'es-419',
517
+ 'fi' => 'fi-FI',
518
+ 'fr_FR' => 'fr-FR',
519
+ 'he_IL' => 'he-IL',
520
+ 'it_IT' => 'it-IT',
521
+ 'ja' => 'ja-JP',
522
+ 'nl_NL' => 'nl-NL',
523
+ 'nn_NO' => 'no-NO',
524
+ 'pt_BR' => 'pt-BR',
525
+ 'sv_SE' => 'sv-SE',
526
+ ];
527
+
528
+ $preferred = isset( $stripe_locales[ $locale ] ) ? $stripe_locales[ $locale ] : 'en-US';
529
+ return [ $preferred ];
530
+ }
531
+
532
+ /**
533
+ * Gets the customer's locale/language based on their setting or the site settings.
534
+ *
535
+ * @param object $user The user we're wanting to get the locale for.
536
+ * @return string The locale/language set in the user profile or the site itself.
537
+ */
538
+ public function get_customer_locale( $user ) {
539
+ // If we have a user, get their locale with a site fallback.
540
+ return ( $user ) ? get_user_locale( $user->ID ) : get_locale();
541
+ }
542
  }
includes/class-wc-stripe-helper.php CHANGED
@@ -510,4 +510,91 @@ class WC_Stripe_Helper {
510
 
511
  return $statement_descriptor;
512
  }