|
@@ -6,7 +6,7 @@ discard block |
|
|
block discarded – undo |
|
6
|
6
|
* @since 4.0.0 |
|
7
|
7
|
*/ |
|
8
|
8
|
|
|
9
|
|
-if ( ! defined( 'ABSPATH' ) ) { |
|
|
9
|
+if ( ! defined('ABSPATH')) { |
|
10
|
10
|
exit; |
|
11
|
11
|
} |
|
12
|
12
|
|
|
@@ -64,41 +64,41 @@ discard block |
|
|
block discarded – undo |
|
64
|
64
|
*/ |
|
65
|
65
|
public function __construct() { |
|
66
|
66
|
self::$_this = $this; |
|
67
|
|
- $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
68
|
|
- $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
69
|
|
- $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
70
|
|
- $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
71
|
|
- $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
|
67
|
+ $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
|
68
|
+ $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
|
69
|
+ $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
|
70
|
+ $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
|
71
|
+ $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
72
|
72
|
|
|
73
|
|
- if ( $this->testmode ) { |
|
74
|
|
- $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
75
|
|
- $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
|
73
|
+ if ($this->testmode) { |
|
|
74
|
+ $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
|
75
|
+ $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
76
|
76
|
} |
|
77
|
77
|
|
|
78
|
|
- $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
|
78
|
+ $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
79
|
79
|
|
|
80
|
80
|
// Checks if Stripe Gateway is enabled. |
|
81
|
|
- if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
|
81
|
+ if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
82
|
82
|
return; |
|
83
|
83
|
} |
|
84
|
84
|
|
|
85
|
85
|
// Checks if Payment Request is enabled. |
|
86
|
|
- if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
|
86
|
+ if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
87
|
87
|
return; |
|
88
|
88
|
} |
|
89
|
89
|
|
|
90
|
90
|
// Don't load for change payment method page. |
|
91
|
|
- if ( isset( $_GET['change_payment_method'] ) ) { |
|
|
91
|
+ if (isset($_GET['change_payment_method'])) { |
|
92
|
92
|
return; |
|
93
|
93
|
} |
|
94
|
94
|
|
|
95
|
|
- $wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
|
95
|
+ $wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2); |
|
96
|
96
|
|
|
97
|
|
- if ( ! in_array( $wc_default_country, $this->get_stripe_supported_countries() ) ) { |
|
|
97
|
+ if ( ! in_array($wc_default_country, $this->get_stripe_supported_countries())) { |
|
98
|
98
|
return; |
|
99
|
99
|
} |
|
100
|
100
|
|
|
101
|
|
- add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
|
101
|
+ add_action('template_redirect', array($this, 'set_session')); |
|
102
|
102
|
$this->init(); |
|
103
|
103
|
} |
|
104
|
104
|
|
|
@@ -109,7 +109,7 @@ discard block |
|
|
block discarded – undo |
|
109
|
109
|
* @return array The list of countries. |
|
110
|
110
|
*/ |
|
111
|
111
|
public function get_stripe_supported_countries() { |
|
112
|
|
- return apply_filters( 'wc_stripe_supported_countries', array( 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US' ) ); |
|
|
112
|
+ return apply_filters('wc_stripe_supported_countries', array('AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US')); |
|
113
|
113
|
} |
|
114
|
114
|
|
|
115
|
115
|
/** |
|
@@ -119,7 +119,7 @@ discard block |
|
|
block discarded – undo |
|
119
|
119
|
* @return bool |
|
120
|
120
|
*/ |
|
121
|
121
|
public function are_keys_set() { |
|
122
|
|
- if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
|
122
|
+ if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
123
|
123
|
return false; |
|
124
|
124
|
} |
|
125
|
125
|
|
|
@@ -143,11 +143,11 @@ discard block |
|
|
block discarded – undo |
|
143
|
143
|
* @since 4.0.0 |
|
144
|
144
|
*/ |
|
145
|
145
|
public function set_session() { |
|
146
|
|
- if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) { |
|
|
146
|
+ if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) { |
|
147
|
147
|
return; |
|
148
|
148
|
} |
|
149
|
149
|
|
|
150
|
|
- WC()->session->set_customer_session_cookie( true ); |
|
|
150
|
+ WC()->session->set_customer_session_cookie(true); |
|
151
|
151
|
} |
|
152
|
152
|
|
|
153
|
153
|
/** |
|
@@ -157,40 +157,40 @@ discard block |
|
|
block discarded – undo |
|
157
|
157
|
* @version 4.0.0 |
|
158
|
158
|
*/ |
|
159
|
159
|
public function init() { |
|
160
|
|
- add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
|
160
|
+ add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
161
|
161
|
|
|
162
|
162
|
/* |
|
163
|
163
|
* In order to display the Payment Request button in the correct position, |
|
164
|
164
|
* a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
|
165
|
165
|
* CSS is used to position the button. |
|
166
|
166
|
*/ |
|
167
|
|
- if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
168
|
|
- add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
169
|
|
- add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
|
167
|
+ if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
|
168
|
+ add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
|
169
|
+ add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
170
|
170
|
} else { |
|
171
|
|
- add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
172
|
|
- add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
|
171
|
+ add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
|
172
|
+ add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
173
|
173
|
} |
|
174
|
174
|
|
|
175
|
|
- add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
176
|
|
- add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
|
175
|
+ add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
|
176
|
+ add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
177
|
177
|
|
|
178
|
|
- add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
179
|
|
- add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
|
178
|
+ add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
|
179
|
+ add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
180
|
180
|
|
|
181
|
|
- add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
182
|
|
- add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
183
|
|
- add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
184
|
|
- add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
185
|
|
- add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
186
|
|
- add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
187
|
|
- add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
188
|
|
- add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
|
181
|
+ add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
|
182
|
+ add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
|
183
|
+ add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
|
184
|
+ add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
|
185
|
+ add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
|
186
|
+ add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
|
187
|
+ add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
|
188
|
+ add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
189
|
189
|
|
|
190
|
|
- add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
191
|
|
- add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
|
190
|
+ add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
|
191
|
+ add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
192
|
192
|
|
|
193
|
|
- add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
|
193
|
+ add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
194
|
194
|
} |
|
195
|
195
|
|
|
196
|
196
|
/** |
|
@@ -201,7 +201,7 @@ discard block |
|
|
block discarded – undo |
|
201
|
201
|
* @return string |
|
202
|
202
|
*/ |
|
203
|
203
|
public function get_button_type() { |
|
204
|
|
- return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
|
204
|
+ return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
205
|
205
|
} |
|
206
|
206
|
|
|
207
|
207
|
/** |
|
@@ -212,7 +212,7 @@ discard block |
|
|
block discarded – undo |
|
212
|
212
|
* @return string |
|
213
|
213
|
*/ |
|
214
|
214
|
public function get_button_theme() { |
|
215
|
|
- return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
|
215
|
+ return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
216
|
216
|
} |
|
217
|
217
|
|
|
218
|
218
|
/** |
|
@@ -223,7 +223,7 @@ discard block |
|
|
block discarded – undo |
|
223
|
223
|
* @return string |
|
224
|
224
|
*/ |
|
225
|
225
|
public function get_button_height() { |
|
226
|
|
- return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
|
226
|
+ return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
227
|
227
|
} |
|
228
|
228
|
|
|
229
|
229
|
/** |
|
@@ -233,26 +233,26 @@ discard block |
|
|
block discarded – undo |
|
233
|
233
|
* @version 4.0.0 |
|
234
|
234
|
*/ |
|
235
|
235
|
public function get_product_data() { |
|
236
|
|
- if ( ! is_product() ) { |
|
|
236
|
+ if ( ! is_product()) { |
|
237
|
237
|
return false; |
|
238
|
238
|
} |
|
239
|
239
|
|
|
240
|
240
|
global $post; |
|
241
|
241
|
|
|
242
|
|
- $product = wc_get_product( $post->ID ); |
|
|
242
|
+ $product = wc_get_product($post->ID); |
|
243
|
243
|
|
|
244
|
|
- if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) { |
|
245
|
|
- $attributes = wc_clean( wp_unslash( $_GET ) ); |
|
|
244
|
+ if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) { |
|
|
245
|
+ $attributes = wc_clean(wp_unslash($_GET)); |
|
246
|
246
|
|
|
247
|
|
- if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
248
|
|
- $variation_id = $product->get_matching_variation( $attributes ); |
|
|
247
|
+ if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
|
248
|
+ $variation_id = $product->get_matching_variation($attributes); |
|
249
|
249
|
} else { |
|
250
|
|
- $data_store = WC_Data_Store::load( 'product' ); |
|
251
|
|
- $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
|
250
|
+ $data_store = WC_Data_Store::load('product'); |
|
|
251
|
+ $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
252
|
252
|
} |
|
253
|
253
|
|
|
254
|
|
- if ( ! empty( $variation_id ) ) { |
|
255
|
|
- $product = wc_get_product( $variation_id ); |
|
|
254
|
+ if ( ! empty($variation_id)) { |
|
|
255
|
+ $product = wc_get_product($variation_id); |
|
256
|
256
|
} |
|
257
|
257
|
} |
|
258
|
258
|
|
|
@@ -260,28 +260,28 @@ discard block |
|
|
block discarded – undo |
|
260
|
260
|
$items = array(); |
|
261
|
261
|
|
|
262
|
262
|
$items[] = array( |
|
263
|
|
- 'label' => WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name(), |
|
264
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ), |
|
|
263
|
+ 'label' => WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name(), |
|
|
264
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()), |
|
265
|
265
|
); |
|
266
|
266
|
|
|
267
|
|
- if ( wc_tax_enabled() ) { |
|
|
267
|
+ if (wc_tax_enabled()) { |
|
268
|
268
|
$items[] = array( |
|
269
|
|
- 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
|
269
|
+ 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
270
|
270
|
'amount' => 0, |
|
271
|
271
|
'pending' => true, |
|
272
|
272
|
); |
|
273
|
273
|
} |
|
274
|
274
|
|
|
275
|
|
- if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
|
275
|
+ if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
276
|
276
|
$items[] = array( |
|
277
|
|
- 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
|
277
|
+ 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
278
|
278
|
'amount' => 0, |
|
279
|
279
|
'pending' => true, |
|
280
|
280
|
); |
|
281
|
281
|
|
|
282
|
282
|
$data['shippingOptions'] = array( |
|
283
|
283
|
'id' => 'pending', |
|
284
|
|
- 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
|
284
|
+ 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
285
|
285
|
'detail' => '', |
|
286
|
286
|
'amount' => 0, |
|
287
|
287
|
); |
|
@@ -289,41 +289,41 @@ discard block |
|
|
block discarded – undo |
|
289
|
289
|
|
|
290
|
290
|
$data['displayItems'] = $items; |
|
291
|
291
|
$data['total'] = array( |
|
292
|
|
- 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
293
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ), |
|
|
292
|
+ 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
|
293
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()), |
|
294
|
294
|
'pending' => true, |
|
295
|
295
|
); |
|
296
|
296
|
|
|
297
|
|
- $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
298
|
|
- $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
299
|
|
- $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
|
297
|
+ $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
|
298
|
+ $data['currency'] = strtolower(get_woocommerce_currency()); |
|
|
299
|
+ $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
300
|
300
|
|
|
301
|
|
- return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
|
301
|
+ return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
302
|
302
|
} |
|
303
|
303
|
|
|
304
|
304
|
/** |
|
305
|
305
|
* Filters the gateway title to reflect Payment Request type |
|
306
|
306
|
* |
|
307
|
307
|
*/ |
|
308
|
|
- public function filter_gateway_title( $title, $id ) { |
|
|
308
|
+ public function filter_gateway_title($title, $id) { |
|
309
|
309
|
global $post; |
|
310
|
310
|
|
|
311
|
|
- if ( ! is_object( $post ) ) { |
|
|
311
|
+ if ( ! is_object($post)) { |
|
312
|
312
|
return $title; |
|
313
|
313
|
} |
|
314
|
314
|
|
|
315
|
|
- if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
316
|
|
- $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
|
315
|
+ if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
|
316
|
+ $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
317
|
317
|
} else { |
|
318
|
|
- $order = wc_get_order( $post->ID ); |
|
319
|
|
- $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
|
318
|
+ $order = wc_get_order($post->ID); |
|
|
319
|
+ $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
320
|
320
|
} |
|
321
|
321
|
|
|
322
|
|
- if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
|
322
|
+ if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
323
|
323
|
return $method_title; |
|
324
|
324
|
} |
|
325
|
325
|
|
|
326
|
|
- if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
|
326
|
+ if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
327
|
327
|
return $method_title; |
|
328
|
328
|
} |
|
329
|
329
|
|
|
@@ -336,16 +336,16 @@ discard block |
|
|
block discarded – undo |
|
336
|
336
|
* @since 3.1.4 |
|
337
|
337
|
* @version 4.0.0 |
|
338
|
338
|
*/ |
|
339
|
|
- public function postal_code_validation( $valid, $postcode, $country ) { |
|
|
339
|
+ public function postal_code_validation($valid, $postcode, $country) { |
|
340
|
340
|
$gateways = WC()->payment_gateways->get_available_payment_gateways(); |
|
341
|
341
|
|
|
342
|
|
- if ( ! isset( $gateways['stripe'] ) ) { |
|
|
342
|
+ if ( ! isset($gateways['stripe'])) { |
|
343
|
343
|
return $valid; |
|
344
|
344
|
} |
|
345
|
345
|
|
|
346
|
|
- $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
|
346
|
+ $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
347
|
347
|
|
|
348
|
|
- if ( 'apple_pay' !== $payment_request_type ) { |
|
|
348
|
+ if ('apple_pay' !== $payment_request_type) { |
|
349
|
349
|
return $valid; |
|
350
|
350
|
} |
|
351
|
351
|
|
|
@@ -355,7 +355,7 @@ discard block |
|
|
block discarded – undo |
|
355
|
355
|
* the order and not let it go through. The remedy for now is just to remove this validation. |
|
356
|
356
|
* Note that this only works with shipping providers that don't validate full postal codes. |
|
357
|
357
|
*/ |
|
358
|
|
- if ( 'GB' === $country || 'CA' === $country ) { |
|
|
358
|
+ if ('GB' === $country || 'CA' === $country) { |
|
359
|
359
|
return true; |
|
360
|
360
|
} |
|
361
|
361
|
|
|
@@ -370,29 +370,29 @@ discard block |
|
|
block discarded – undo |
|
370
|
370
|
* @param int $order_id |
|
371
|
371
|
* @param array $posted_data The posted data from checkout form. |
|
372
|
372
|
*/ |
|
373
|
|
- public function add_order_meta( $order_id, $posted_data ) { |
|
374
|
|
- if ( empty( $_POST['payment_request_type'] ) ) { |
|
|
373
|
+ public function add_order_meta($order_id, $posted_data) { |
|
|
374
|
+ if (empty($_POST['payment_request_type'])) { |
|
375
|
375
|
return; |
|
376
|
376
|
} |
|
377
|
377
|
|
|
378
|
|
- $order = wc_get_order( $order_id ); |
|
|
378
|
+ $order = wc_get_order($order_id); |
|
379
|
379
|
|
|
380
|
|
- $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
|
380
|
+ $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
381
|
381
|
|
|
382
|
|
- if ( 'apple_pay' === $payment_request_type ) { |
|
383
|
|
- if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
384
|
|
- update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
|
382
|
+ if ('apple_pay' === $payment_request_type) { |
|
|
383
|
+ if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
|
384
|
+ update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
385
|
385
|
} else { |
|
386
|
|
- $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
|
386
|
+ $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
387
|
387
|
$order->save(); |
|
388
|
388
|
} |
|
389
|
389
|
} |
|
390
|
390
|
|
|
391
|
|
- if ( 'payment_request_api' === $payment_request_type ) { |
|
392
|
|
- if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
393
|
|
- update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
|
391
|
+ if ('payment_request_api' === $payment_request_type) { |
|
|
392
|
+ if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
|
393
|
+ update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
394
|
394
|
} else { |
|
395
|
|
- $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
|
395
|
+ $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
396
|
396
|
$order->save(); |
|
397
|
397
|
} |
|
398
|
398
|
} |
|
@@ -431,20 +431,20 @@ discard block |
|
|
block discarded – undo |
|
431
|
431
|
* @return bool |
|
432
|
432
|
*/ |
|
433
|
433
|
public function allowed_items_in_cart() { |
|
434
|
|
- foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
435
|
|
- $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
|
434
|
+ foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
|
435
|
+ $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
436
|
436
|
|
|
437
|
|
- if ( ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
|
437
|
+ if ( ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
438
|
438
|
return false; |
|
439
|
439
|
} |
|
440
|
440
|
|
|
441
|
441
|
// Trial subscriptions with shipping are not supported |
|
442
|
|
- if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) { |
|
|
442
|
+ if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) { |
|
443
|
443
|
return false; |
|
444
|
444
|
} |
|
445
|
445
|
|
|
446
|
446
|
// Pre Orders compatbility where we don't support charge upon release. |
|
447
|
|
- if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
|
447
|
+ if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
448
|
448
|
return false; |
|
449
|
449
|
} |
|
450
|
450
|
} |
|
@@ -460,73 +460,73 @@ discard block |
|
|
block discarded – undo |
|
460
|
460
|
*/ |
|
461
|
461
|
public function scripts() { |
|
462
|
462
|
// If keys are not set bail. |
|
463
|
|
- if ( ! $this->are_keys_set() ) { |
|
464
|
|
- WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
|
463
|
+ if ( ! $this->are_keys_set()) { |
|
|
464
|
+ WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
465
|
465
|
return; |
|
466
|
466
|
} |
|
467
|
467
|
|
|
468
|
468
|
// If no SSL bail. |
|
469
|
|
- if ( ! $this->testmode && ! is_ssl() ) { |
|
470
|
|
- WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' ); |
|
|
469
|
+ if ( ! $this->testmode && ! is_ssl()) { |
|
|
470
|
+ WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.'); |
|
471
|
471
|
return; |
|
472
|
472
|
} |
|
473
|
473
|
|
|
474
|
|
- if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
|
474
|
+ if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
475
|
475
|
return; |
|
476
|
476
|
} |
|
477
|
477
|
|
|
478
|
|
- if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
|
478
|
+ if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
479
|
479
|
return; |
|
480
|
480
|
} |
|
481
|
481
|
|
|
482
|
|
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
|
482
|
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
483
|
483
|
|
|
484
|
484
|
$stripe_params = array( |
|
485
|
|
- 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
|
485
|
+ 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
486
|
486
|
'stripe' => array( |
|
487
|
487
|
'key' => $this->publishable_key, |
|
488
|
|
- 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
|
488
|
+ 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
489
|
489
|
), |
|
490
|
490
|
'nonce' => array( |
|
491
|
|
- 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
492
|
|
- 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
493
|
|
- 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
494
|
|
- 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
495
|
|
- 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
496
|
|
- 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
497
|
|
- 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
498
|
|
- 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
|
491
|
+ 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
|
492
|
+ 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
|
493
|
+ 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
|
494
|
+ 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
|
495
|
+ 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
|
496
|
+ 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
|
497
|
+ 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
|
498
|
+ 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
499
|
499
|
), |
|
500
|
500
|
'i18n' => array( |
|
501
|
|
- 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
|
501
|
+ 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
502
|
502
|
/* translators: Do not translate the [option] placeholder */ |
|
503
|
|
- 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
|
503
|
+ 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
504
|
504
|
), |
|
505
|
505
|
'checkout' => array( |
|
506
|
506
|
'url' => wc_get_checkout_url(), |
|
507
|
|
- 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
508
|
|
- 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
|
507
|
+ 'currency_code' => strtolower(get_woocommerce_currency()), |
|
|
508
|
+ 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
509
|
509
|
'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
|
510
|
510
|
), |
|
511
|
511
|
'button' => array( |
|
512
|
512
|
'type' => $this->get_button_type(), |
|
513
|
513
|
'theme' => $this->get_button_theme(), |
|
514
|
514
|
'height' => $this->get_button_height(), |
|
515
|
|
- 'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US. |
|
|
515
|
+ 'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US. |
|
516
|
516
|
), |
|
517
|
517
|
'is_product_page' => is_product(), |
|
518
|
518
|
'product' => $this->get_product_data(), |
|
519
|
519
|
); |
|
520
|
520
|
|
|
521
|
|
- wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
522
|
|
- wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
|
521
|
+ wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
|
522
|
+ wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
523
|
523
|
|
|
524
|
|
- wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) ); |
|
|
524
|
+ wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params)); |
|
525
|
525
|
|
|
526
|
|
- wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
|
526
|
+ wp_enqueue_script('wc_stripe_payment_request'); |
|
527
|
527
|
|
|
528
|
528
|
$gateways = WC()->payment_gateways->get_available_payment_gateways(); |
|
529
|
|
- if ( isset( $gateways['stripe'] ) ) { |
|
|
529
|
+ if (isset($gateways['stripe'])) { |
|
530
|
530
|
$gateways['stripe']->payment_scripts(); |
|
531
|
531
|
} |
|
532
|
532
|
} |
|
@@ -542,23 +542,23 @@ discard block |
|
|
block discarded – undo |
|
542
|
542
|
|
|
543
|
543
|
$gateways = WC()->payment_gateways->get_available_payment_gateways(); |
|
544
|
544
|
|
|
545
|
|
- if ( ! isset( $gateways['stripe'] ) ) { |
|
|
545
|
+ if ( ! isset($gateways['stripe'])) { |
|
546
|
546
|
return; |
|
547
|
547
|
} |
|
548
|
548
|
|
|
549
|
|
- if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
|
549
|
+ if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
550
|
550
|
return; |
|
551
|
551
|
} |
|
552
|
552
|
|
|
553
|
|
- if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
|
553
|
+ if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
554
|
554
|
return; |
|
555
|
555
|
} |
|
556
|
556
|
|
|
557
|
|
- if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
|
557
|
+ if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
558
|
558
|
return; |
|
559
|
559
|
} else { |
|
560
|
|
- if ( ! $this->allowed_items_in_cart() ) { |
|
561
|
|
- WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
|
560
|
+ if ( ! $this->allowed_items_in_cart()) { |
|
|
561
|
+ WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
562
|
562
|
return; |
|
563
|
563
|
} |
|
564
|
564
|
} |
|
@@ -582,28 +582,28 @@ discard block |
|
|
block discarded – undo |
|
582
|
582
|
|
|
583
|
583
|
$gateways = WC()->payment_gateways->get_available_payment_gateways(); |
|
584
|
584
|
|
|
585
|
|
- if ( ! isset( $gateways['stripe'] ) ) { |
|
|
585
|
+ if ( ! isset($gateways['stripe'])) { |
|
586
|
586
|
return; |
|
587
|
587
|
} |
|
588
|
588
|
|
|
589
|
|
- if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
|
589
|
+ if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
590
|
590
|
return; |
|
591
|
591
|
} |
|
592
|
592
|
|
|
593
|
|
- if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
|
593
|
+ if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
594
|
594
|
return; |
|
595
|
595
|
} |
|
596
|
596
|
|
|
597
|
|
- if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
|
597
|
+ if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
598
|
598
|
return; |
|
599
|
599
|
} else { |
|
600
|
|
- if ( ! $this->allowed_items_in_cart() ) { |
|
601
|
|
- WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
|
600
|
+ if ( ! $this->allowed_items_in_cart()) { |
|
|
601
|
+ WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
602
|
602
|
return; |
|
603
|
603
|
} |
|
604
|
604
|
} |
|
605
|
605
|
?> |
|
606
|
|
- <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> —</p> |
|
|
606
|
+ <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> —</p> |
|
607
|
607
|
<?php |
|
608
|
608
|
} |
|
609
|
609
|
|
|
@@ -619,32 +619,32 @@ discard block |
|
|
block discarded – undo |
|
619
|
619
|
private function should_show_payment_button_on_product_page() { |
|
620
|
620
|
global $post; |
|
621
|
621
|
|
|
622
|
|
- $product = wc_get_product( $post->ID ); |
|
|
622
|
+ $product = wc_get_product($post->ID); |
|
623
|
623
|
|
|
624
|
|
- if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
|
624
|
+ if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
625
|
625
|
return false; |
|
626
|
626
|
} |
|
627
|
627
|
|
|
628
|
|
- if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
|
628
|
+ if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
629
|
629
|
return false; |
|
630
|
630
|
} |
|
631
|
631
|
|
|
632
|
632
|
// Trial subscriptions with shipping are not supported |
|
633
|
|
- if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) { |
|
|
633
|
+ if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) { |
|
634
|
634
|
return false; |
|
635
|
635
|
} |
|
636
|
636
|
|
|
637
|
637
|
// Pre Orders charge upon release not supported. |
|
638
|
|
- if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
639
|
|
- WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
|
638
|
+ if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
|
639
|
+ WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
640
|
640
|
return false; |
|
641
|
641
|
} |
|
642
|
642
|
|
|
643
|
643
|
// File upload addon not supported |
|
644
|
|
- if ( class_exists( 'WC_Product_Addons_Helper' ) ) { |
|
645
|
|
- $product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() ); |
|
646
|
|
- foreach ( $product_addons as $addon ) { |
|
647
|
|
- if ( 'file_upload' === $addon['type'] ) { |
|
|
644
|
+ if (class_exists('WC_Product_Addons_Helper')) { |
|
|
645
|
+ $product_addons = WC_Product_Addons_Helper::get_product_addons($product->get_id()); |
|
|
646
|
+ foreach ($product_addons as $addon) { |
|
|
647
|
+ if ('file_upload' === $addon['type']) { |
|
648
|
648
|
return false; |
|
649
|
649
|
} |
|
650
|
650
|
} |
|
@@ -660,11 +660,11 @@ discard block |
|
|
block discarded – undo |
|
660
|
660
|
* @version 4.0.0 |
|
661
|
661
|
*/ |
|
662
|
662
|
public function ajax_log_errors() { |
|
663
|
|
- check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
|
663
|
+ check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
664
|
664
|
|
|
665
|
|
- $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
|
665
|
+ $errors = wc_clean(stripslashes($_POST['errors'])); |
|
666
|
666
|
|
|
667
|
|
- WC_Stripe_Logger::log( $errors ); |
|
|
667
|
+ WC_Stripe_Logger::log($errors); |
|
668
|
668
|
|
|
669
|
669
|
exit; |
|
670
|
670
|
} |
|
@@ -676,7 +676,7 @@ discard block |
|
|
block discarded – undo |
|
676
|
676
|
* @version 4.0.0 |
|
677
|
677
|
*/ |
|
678
|
678
|
public function ajax_clear_cart() { |
|
679
|
|
- check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
|
679
|
+ check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
680
|
680
|
|
|
681
|
681
|
WC()->cart->empty_cart(); |
|
682
|
682
|
exit; |
|
@@ -686,10 +686,10 @@ discard block |
|
|
block discarded – undo |
|
686
|
686
|
* Get cart details. |
|
687
|
687
|
*/ |
|
688
|
688
|
public function ajax_get_cart_details() { |
|
689
|
|
- check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
|
689
|
+ check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
690
|
690
|
|
|
691
|
|
- if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
692
|
|
- define( 'WOOCOMMERCE_CART', true ); |
|
|
691
|
+ if ( ! defined('WOOCOMMERCE_CART')) { |
|
|
692
|
+ define('WOOCOMMERCE_CART', true); |
|
693
|
693
|
} |
|
694
|
694
|
|
|
695
|
695
|
WC()->cart->calculate_totals(); |
|
@@ -700,14 +700,14 @@ discard block |
|
|
block discarded – undo |
|
700
|
700
|
$data = array( |
|
701
|
701
|
'shipping_required' => WC()->cart->needs_shipping(), |
|
702
|
702
|
'order_data' => array( |
|
703
|
|
- 'currency' => strtolower( $currency ), |
|
704
|
|
- 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
|
703
|
+ 'currency' => strtolower($currency), |
|
|
704
|
+ 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
705
|
705
|
), |
|
706
|
706
|
); |
|
707
|
707
|
|
|
708
|
708
|
$data['order_data'] += $this->build_display_items(); |
|
709
|
709
|
|
|
710
|
|
- wp_send_json( $data ); |
|
|
710
|
+ wp_send_json($data); |
|
711
|
711
|
} |
|
712
|
712
|
|
|
713
|
713
|
/** |
|
@@ -718,7 +718,7 @@ discard block |
|
|
block discarded – undo |
|
718
|
718
|
* @see WC_Shipping::get_packages(). |
|
719
|
719
|
*/ |
|
720
|
720
|
public function ajax_get_shipping_options() { |
|
721
|
|
- check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
|
721
|
+ check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
722
|
722
|
|
|
723
|
723
|
try { |
|
724
|
724
|
// Set the shipping package. |
|
@@ -734,34 +734,34 @@ discard block |
|
|
block discarded – undo |
|
734
|
734
|
) |
|
735
|
735
|
); |
|
736
|
736
|
|
|
737
|
|
- $this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) ); |
|
|
737
|
+ $this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted)); |
|
738
|
738
|
|
|
739
|
739
|
// Set the shipping options. |
|
740
|
740
|
$data = array(); |
|
741
|
741
|
$packages = WC()->shipping->get_packages(); |
|
742
|
742
|
|
|
743
|
|
- if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
744
|
|
- foreach ( $packages as $package_key => $package ) { |
|
745
|
|
- if ( empty( $package['rates'] ) ) { |
|
746
|
|
- throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
|
743
|
+ if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
|
744
|
+ foreach ($packages as $package_key => $package) { |
|
|
745
|
+ if (empty($package['rates'])) { |
|
|
746
|
+ throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
747
|
747
|
} |
|
748
|
748
|
|
|
749
|
|
- foreach ( $package['rates'] as $key => $rate ) { |
|
|
749
|
+ foreach ($package['rates'] as $key => $rate) { |
|
750
|
750
|
$data['shipping_options'][] = array( |
|
751
|
751
|
'id' => $rate->id, |
|
752
|
752
|
'label' => $rate->label, |
|
753
|
753
|
'detail' => '', |
|
754
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
|
754
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
755
|
755
|
); |
|
756
|
756
|
} |
|
757
|
757
|
} |
|
758
|
758
|
} else { |
|
759
|
|
- throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
|
759
|
+ throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
760
|
760
|
} |
|
761
|
761
|
|
|
762
|
|
- if ( isset( $data[0] ) ) { |
|
|
762
|
+ if (isset($data[0])) { |
|
763
|
763
|
// Auto select the first shipping method. |
|
764
|
|
- WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
|
764
|
+ WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
765
|
765
|
} |
|
766
|
766
|
|
|
767
|
767
|
WC()->cart->calculate_totals(); |
|
@@ -769,12 +769,12 @@ discard block |
|
|
block discarded – undo |
|
769
|
769
|
$data += $this->build_display_items(); |
|
770
|
770
|
$data['result'] = 'success'; |
|
771
|
771
|
|
|
772
|
|
- wp_send_json( $data ); |
|
773
|
|
- } catch ( Exception $e ) { |
|
|
772
|
+ wp_send_json($data); |
|
|
773
|
+ } catch (Exception $e) { |
|
774
|
774
|
$data += $this->build_display_items(); |
|
775
|
775
|
$data['result'] = 'invalid_shipping_address'; |
|
776
|
776
|
|
|
777
|
|
- wp_send_json( $data ); |
|
|
777
|
+ wp_send_json($data); |
|
778
|
778
|
} |
|
779
|
779
|
} |
|
780
|
780
|
|
|
@@ -782,22 +782,22 @@ discard block |
|
|
block discarded – undo |
|
782
|
782
|
* Update shipping method. |
|
783
|
783
|
*/ |
|
784
|
784
|
public function ajax_update_shipping_method() { |
|
785
|
|
- check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
|
785
|
+ check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
786
|
786
|
|
|
787
|
|
- if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
788
|
|
- define( 'WOOCOMMERCE_CART', true ); |
|
|
787
|
+ if ( ! defined('WOOCOMMERCE_CART')) { |
|
|
788
|
+ define('WOOCOMMERCE_CART', true); |
|
789
|
789
|
} |
|
790
|
790
|
|
|
791
|
|
- $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
792
|
|
- $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
|
791
|
+ $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
|
792
|
+ $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
793
|
793
|
|
|
794
|
|
- if ( is_array( $shipping_method ) ) { |
|
795
|
|
- foreach ( $shipping_method as $i => $value ) { |
|
796
|
|
- $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
|
794
|
+ if (is_array($shipping_method)) { |
|
|
795
|
+ foreach ($shipping_method as $i => $value) { |
|
|
796
|
+ $chosen_shipping_methods[$i] = wc_clean($value); |
|
797
|
797
|
} |
|
798
|
798
|
} |
|
799
|
799
|
|
|
800
|
|
- WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
|
800
|
+ WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
801
|
801
|
|
|
802
|
802
|
WC()->cart->calculate_totals(); |
|
803
|
803
|
|
|
@@ -805,7 +805,7 @@ discard block |
|
|
block discarded – undo |
|
805
|
805
|
$data += $this->build_display_items(); |
|
806
|
806
|
$data['result'] = 'success'; |
|
807
|
807
|
|
|
808
|
|
- wp_send_json( $data ); |
|
|
808
|
+ wp_send_json($data); |
|
809
|
809
|
} |
|
810
|
810
|
|
|
811
|
811
|
/** |
|
@@ -816,45 +816,45 @@ discard block |
|
|
block discarded – undo |
|
816
|
816
|
* @return array $data |
|
817
|
817
|
*/ |
|
818
|
818
|
public function ajax_get_selected_product_data() { |
|
819
|
|
- check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
|
819
|
+ check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
820
|
820
|
|
|
821
|
821
|
try { |
|
822
|
|
- $product_id = absint( $_POST['product_id'] ); |
|
823
|
|
- $qty = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id ); |
|
824
|
|
- $addon_value = isset( $_POST['addon_value'] ) ? max( floatval( $_POST['addon_value'] ), 0 ) : 0; |
|
825
|
|
- $product = wc_get_product( $product_id ); |
|
|
822
|
+ $product_id = absint($_POST['product_id']); |
|
|
823
|
+ $qty = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id); |
|
|
824
|
+ $addon_value = isset($_POST['addon_value']) ? max(floatval($_POST['addon_value']), 0) : 0; |
|
|
825
|
+ $product = wc_get_product($product_id); |
|
826
|
826
|
$variation_id = null; |
|
827
|
827
|
|
|
828
|
|
- if ( ! is_a( $product, 'WC_Product' ) ) { |
|
829
|
|
- throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) ); |
|
|
828
|
+ if ( ! is_a($product, 'WC_Product')) { |
|
|
829
|
+ throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id)); |
|
830
|
830
|
} |
|
831
|
831
|
|
|
832
|
|
- if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
833
|
|
- $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); |
|
|
832
|
+ if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
|
833
|
+ $attributes = wc_clean(wp_unslash($_POST['attributes'])); |
|
834
|
834
|
|
|
835
|
|
- if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
836
|
|
- $variation_id = $product->get_matching_variation( $attributes ); |
|
|
835
|
+ if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
|
836
|
+ $variation_id = $product->get_matching_variation($attributes); |
|
837
|
837
|
} else { |
|
838
|
|
- $data_store = WC_Data_Store::load( 'product' ); |
|
839
|
|
- $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
|
838
|
+ $data_store = WC_Data_Store::load('product'); |
|
|
839
|
+ $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
840
|
840
|
} |
|
841
|
841
|
|
|
842
|
|
- if ( ! empty( $variation_id ) ) { |
|
843
|
|
- $product = wc_get_product( $variation_id ); |
|
|
842
|
+ if ( ! empty($variation_id)) { |
|
|
843
|
+ $product = wc_get_product($variation_id); |
|
844
|
844
|
} |
|
845
|
845
|
} |
|
846
|
846
|
|
|
847
|
847
|
// Force quantity to 1 if sold individually and check for existing item in cart. |
|
848
|
|
- if ( $product->is_sold_individually() ) { |
|
849
|
|
- $qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id ); |
|
|
848
|
+ if ($product->is_sold_individually()) { |
|
|
849
|
+ $qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id); |
|
850
|
850
|
} |
|
851
|
851
|
|
|
852
|
|
- if ( ! $product->has_enough_stock( $qty ) ) { |
|
|
852
|
+ if ( ! $product->has_enough_stock($qty)) { |
|
853
|
853
|
/* translators: 1: product name 2: quantity in stock */ |
|
854
|
|
- throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) ); |
|
|
854
|
+ throw new Exception(sprintf(__('You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe'), $product->get_name(), wc_format_stock_quantity_for_display($product->get_stock_quantity(), $product))); |
|
855
|
855
|
} |
|
856
|
856
|
|
|
857
|
|
- $total = $qty * ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ) + $addon_value; |
|
|
857
|
+ $total = $qty * (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()) + $addon_value; |
|
858
|
858
|
|
|
859
|
859
|
$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
|
860
|
860
|
|
|
@@ -862,28 +862,28 @@ discard block |
|
|
block discarded – undo |
|
862
|
862
|
$items = array(); |
|
863
|
863
|
|
|
864
|
864
|
$items[] = array( |
|
865
|
|
- 'label' => ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name() ) . $quantity_label, |
|
866
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
|
865
|
+ 'label' => (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name()) . $quantity_label, |
|
|
866
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
867
|
867
|
); |
|
868
|
868
|
|
|
869
|
|
- if ( wc_tax_enabled() ) { |
|
|
869
|
+ if (wc_tax_enabled()) { |
|
870
|
870
|
$items[] = array( |
|
871
|
|
- 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
|
871
|
+ 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
872
|
872
|
'amount' => 0, |
|
873
|
873
|
'pending' => true, |
|
874
|
874
|
); |
|
875
|
875
|
} |
|
876
|
876
|
|
|
877
|
|
- if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
|
877
|
+ if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
878
|
878
|
$items[] = array( |
|
879
|
|
- 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
|
879
|
+ 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
880
|
880
|
'amount' => 0, |
|
881
|
881
|
'pending' => true, |
|
882
|
882
|
); |
|
883
|
883
|
|
|
884
|
884
|
$data['shippingOptions'] = array( |
|
885
|
885
|
'id' => 'pending', |
|
886
|
|
- 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
|
886
|
+ 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
887
|
887
|
'detail' => '', |
|
888
|
888
|
'amount' => 0, |
|
889
|
889
|
); |
|
@@ -892,17 +892,17 @@ discard block |
|
|
block discarded – undo |
|
892
|
892
|
$data['displayItems'] = $items; |
|
893
|
893
|
$data['total'] = array( |
|
894
|
894
|
'label' => $this->total_label, |
|
895
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
|
895
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
896
|
896
|
'pending' => true, |
|
897
|
897
|
); |
|
898
|
898
|
|
|
899
|
|
- $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
900
|
|
- $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
901
|
|
- $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
|
899
|
+ $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
|
900
|
+ $data['currency'] = strtolower(get_woocommerce_currency()); |
|
|
901
|
+ $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
902
|
902
|
|
|
903
|
|
- wp_send_json( $data ); |
|
904
|
|
- } catch ( Exception $e ) { |
|
905
|
|
- wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) ); |
|
|
903
|
+ wp_send_json($data); |
|
|
904
|
+ } catch (Exception $e) { |
|
|
905
|
+ wp_send_json(array('error' => wp_strip_all_tags($e->getMessage()))); |
|
906
|
906
|
} |
|
907
|
907
|
} |
|
908
|
908
|
|
|
@@ -914,37 +914,37 @@ discard block |
|
|
block discarded – undo |
|
914
|
914
|
* @return array $data |
|
915
|
915
|
*/ |
|
916
|
916
|
public function ajax_add_to_cart() { |
|
917
|
|
- check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
|
917
|
+ check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
918
|
918
|
|
|
919
|
|
- if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
920
|
|
- define( 'WOOCOMMERCE_CART', true ); |
|
|
919
|
+ if ( ! defined('WOOCOMMERCE_CART')) { |
|
|
920
|
+ define('WOOCOMMERCE_CART', true); |
|
921
|
921
|
} |
|
922
|
922
|
|
|
923
|
923
|
WC()->shipping->reset_shipping(); |
|
924
|
924
|
|
|
925
|
|
- $product_id = absint( $_POST['product_id'] ); |
|
926
|
|
- $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
927
|
|
- $product = wc_get_product( $product_id ); |
|
928
|
|
- $product_type = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type(); |
|
|
925
|
+ $product_id = absint($_POST['product_id']); |
|
|
926
|
+ $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
|
927
|
+ $product = wc_get_product($product_id); |
|
|
928
|
+ $product_type = WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type(); |
|
929
|
929
|
|
|
930
|
930
|
// First empty the cart to prevent wrong calculation. |
|
931
|
931
|
WC()->cart->empty_cart(); |
|
932
|
932
|
|
|
933
|
|
- if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { |
|
934
|
|
- $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); |
|
|
933
|
+ if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) { |
|
|
934
|
+ $attributes = wc_clean(wp_unslash($_POST['attributes'])); |
|
935
|
935
|
|
|
936
|
|
- if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
937
|
|
- $variation_id = $product->get_matching_variation( $attributes ); |
|
|
936
|
+ if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
|
937
|
+ $variation_id = $product->get_matching_variation($attributes); |
|
938
|
938
|
} else { |
|
939
|
|
- $data_store = WC_Data_Store::load( 'product' ); |
|
940
|
|
- $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
|
939
|
+ $data_store = WC_Data_Store::load('product'); |
|
|
940
|
+ $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
941
|
941
|
} |
|
942
|
942
|
|
|
943
|
|
- WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
|
943
|
+ WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
944
|
944
|
} |
|
945
|
945
|
|
|
946
|
|
- if ( 'simple' === $product_type || 'subscription' === $product_type ) { |
|
947
|
|
- WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
|
946
|
+ if ('simple' === $product_type || 'subscription' === $product_type) { |
|
|
947
|
+ WC()->cart->add_to_cart($product->get_id(), $qty); |
|
948
|
948
|
} |
|
949
|
949
|
|
|
950
|
950
|
WC()->cart->calculate_totals(); |
|
@@ -953,7 +953,7 @@ discard block |
|
|
block discarded – undo |
|
953
|
953
|
$data += $this->build_display_items(); |
|
954
|
954
|
$data['result'] = 'success'; |
|
955
|
955
|
|
|
956
|
|
- wp_send_json( $data ); |
|
|
956
|
+ wp_send_json($data); |
|
957
|
957
|
} |
|
958
|
958
|
|
|
959
|
959
|
/** |
|
@@ -966,31 +966,31 @@ discard block |
|
|
block discarded – undo |
|
966
|
966
|
* @version 4.0.0 |
|
967
|
967
|
*/ |
|
968
|
968
|
public function normalize_state() { |
|
969
|
|
- $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
970
|
|
- $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
971
|
|
- $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
972
|
|
- $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
|
969
|
+ $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
|
970
|
+ $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
|
971
|
+ $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
|
972
|
+ $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
973
|
973
|
|
|
974
|
|
- if ( $billing_state && $billing_country ) { |
|
975
|
|
- $valid_states = WC()->countries->get_states( $billing_country ); |
|
|
974
|
+ if ($billing_state && $billing_country) { |
|
|
975
|
+ $valid_states = WC()->countries->get_states($billing_country); |
|
976
|
976
|
|
|
977
|
977
|
// Valid states found for country. |
|
978
|
|
- if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
979
|
|
- foreach ( $valid_states as $state_abbr => $state ) { |
|
980
|
|
- if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
|
978
|
+ if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
|
979
|
+ foreach ($valid_states as $state_abbr => $state) { |
|
|
980
|
+ if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
981
|
981
|
$_POST['billing_state'] = $state_abbr; |
|
982
|
982
|
} |
|
983
|
983
|
} |
|
984
|
984
|
} |
|
985
|
985
|
} |
|
986
|
986
|
|
|
987
|
|
- if ( $shipping_state && $shipping_country ) { |
|
988
|
|
- $valid_states = WC()->countries->get_states( $shipping_country ); |
|
|
987
|
+ if ($shipping_state && $shipping_country) { |
|
|
988
|
+ $valid_states = WC()->countries->get_states($shipping_country); |
|
989
|
989
|
|
|
990
|
990
|
// Valid states found for country. |
|
991
|
|
- if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
992
|
|
- foreach ( $valid_states as $state_abbr => $state ) { |
|
993
|
|
- if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
|
991
|
+ if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
|
992
|
+ foreach ($valid_states as $state_abbr => $state) { |
|
|
993
|
+ if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
994
|
994
|
$_POST['shipping_state'] = $state_abbr; |
|
995
|
995
|
} |
|
996
|
996
|
} |
|
@@ -1005,19 +1005,19 @@ discard block |
|
|
block discarded – undo |
|
1005
|
1005
|
* @version 4.0.0 |
|
1006
|
1006
|
*/ |
|
1007
|
1007
|
public function ajax_create_order() { |
|
1008
|
|
- if ( WC()->cart->is_empty() ) { |
|
1009
|
|
- wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
|
1008
|
+ if (WC()->cart->is_empty()) { |
|
|
1009
|
+ wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
1010
|
1010
|
} |
|
1011
|
1011
|
|
|
1012
|
|
- if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
1013
|
|
- define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
|
1012
|
+ if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
|
1013
|
+ define('WOOCOMMERCE_CHECKOUT', true); |
|
1014
|
1014
|
} |
|
1015
|
1015
|
|
|
1016
|
1016
|
$this->normalize_state(); |
|
1017
|
1017
|
|
|
1018
|
1018
|
WC()->checkout()->process_checkout(); |
|
1019
|
1019
|
|
|
1020
|
|
- die( 0 ); |
|
|
1020
|
+ die(0); |
|
1021
|
1021
|
} |
|
1022
|
1022
|
|
|
1023
|
1023
|
/** |
|
@@ -1027,41 +1027,41 @@ discard block |
|
|
block discarded – undo |
|
1027
|
1027
|
* @version 4.0.0 |
|
1028
|
1028
|
* @param array $address |
|
1029
|
1029
|
*/ |
|
1030
|
|
- protected function calculate_shipping( $address = array() ) { |
|
|
1030
|
+ protected function calculate_shipping($address = array()) { |
|
1031
|
1031
|
$country = $address['country']; |
|
1032
|
1032
|
$state = $address['state']; |
|
1033
|
1033
|
$postcode = $address['postcode']; |
|
1034
|
1034
|
$city = $address['city']; |
|
1035
|
1035
|
$address_1 = $address['address']; |
|
1036
|
1036
|
$address_2 = $address['address_2']; |
|
1037
|
|
- $wc_states = WC()->countries->get_states( $country ); |
|
|
1037
|
+ $wc_states = WC()->countries->get_states($country); |
|
1038
|
1038
|
|
|
1039
|
1039
|
/** |
|
1040
|
1040
|
* In some versions of Chrome, state can be a full name. So we need |
|
1041
|
1041
|
* to convert that to abbreviation as WC is expecting that. |
|
1042
|
1042
|
*/ |
|
1043
|
|
- if ( 2 < strlen( $state ) && ! empty( $wc_states ) ) { |
|
1044
|
|
- $state = array_search( ucwords( strtolower( $state ) ), $wc_states, true ); |
|
|
1043
|
+ if (2 < strlen($state) && ! empty($wc_states)) { |
|
|
1044
|
+ $state = array_search(ucwords(strtolower($state)), $wc_states, true); |
|
1045
|
1045
|
} |
|
1046
|
1046
|
|
|
1047
|
1047
|
WC()->shipping->reset_shipping(); |
|
1048
|
1048
|
|
|
1049
|
|
- if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
1050
|
|
- $postcode = wc_format_postcode( $postcode, $country ); |
|
|
1049
|
+ if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
|
1050
|
+ $postcode = wc_format_postcode($postcode, $country); |
|
1051
|
1051
|
} |
|
1052
|
1052
|
|
|
1053
|
|
- if ( $country ) { |
|
1054
|
|
- WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
1055
|
|
- WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
|
1053
|
+ if ($country) { |
|
|
1054
|
+ WC()->customer->set_location($country, $state, $postcode, $city); |
|
|
1055
|
+ WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
1056
|
1056
|
} else { |
|
1057
|
|
- WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
|
1058
|
|
- WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
|
|
1057
|
+ WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
|
|
1058
|
+ WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
|
1059
|
1059
|
} |
|
1060
|
1060
|
|
|
1061
|
|
- if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
1062
|
|
- WC()->customer->calculated_shipping( true ); |
|
|
1061
|
+ if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
|
1062
|
+ WC()->customer->calculated_shipping(true); |
|
1063
|
1063
|
} else { |
|
1064
|
|
- WC()->customer->set_calculated_shipping( true ); |
|
|
1064
|
+ WC()->customer->set_calculated_shipping(true); |
|
1065
|
1065
|
WC()->customer->save(); |
|
1066
|
1066
|
} |
|
1067
|
1067
|
|
|
@@ -1078,17 +1078,17 @@ discard block |
|
|
block discarded – undo |
|
1078
|
1078
|
$packages[0]['destination']['address'] = $address_1; |
|
1079
|
1079
|
$packages[0]['destination']['address_2'] = $address_2; |
|
1080
|
1080
|
|
|
1081
|
|
- foreach ( WC()->cart->get_cart() as $item ) { |
|
1082
|
|
- if ( $item['data']->needs_shipping() ) { |
|
1083
|
|
- if ( isset( $item['line_total'] ) ) { |
|
|
1081
|
+ foreach (WC()->cart->get_cart() as $item) { |
|
|
1082
|
+ if ($item['data']->needs_shipping()) { |
|
|
1083
|
+ if (isset($item['line_total'])) { |
|
1084
|
1084
|
$packages[0]['contents_cost'] += $item['line_total']; |
|
1085
|
1085
|
} |
|
1086
|
1086
|
} |
|
1087
|
1087
|
} |
|
1088
|
1088
|
|
|
1089
|
|
- $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
|
1089
|
+ $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1090
|
1090
|
|
|
1091
|
|
- WC()->shipping->calculate_shipping( $packages ); |
|
|
1091
|
+ WC()->shipping->calculate_shipping($packages); |
|
1092
|
1092
|
} |
|
1093
|
1093
|
|
|
1094
|
1094
|
/** |
|
@@ -1097,19 +1097,19 @@ discard block |
|
|
block discarded – undo |
|
1097
|
1097
|
* @since 3.1.0 |
|
1098
|
1098
|
* @version 4.0.0 |
|
1099
|
1099
|
*/ |
|
1100
|
|
- protected function build_shipping_methods( $shipping_methods ) { |
|
1101
|
|
- if ( empty( $shipping_methods ) ) { |
|
|
1100
|
+ protected function build_shipping_methods($shipping_methods) { |
|
|
1101
|
+ if (empty($shipping_methods)) { |
|
1102
|
1102
|
return array(); |
|
1103
|
1103
|
} |
|
1104
|
1104
|
|
|
1105
|
1105
|
$shipping = array(); |
|
1106
|
1106
|
|
|
1107
|
|
- foreach ( $shipping_methods as $method ) { |
|
|
1107
|
+ foreach ($shipping_methods as $method) { |
|
1108
|
1108
|
$shipping[] = array( |
|
1109
|
1109
|
'id' => $method['id'], |
|
1110
|
1110
|
'label' => $method['label'], |
|
1111
|
1111
|
'detail' => '', |
|
1112
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
|
1112
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1113
|
1113
|
); |
|
1114
|
1114
|
} |
|
1115
|
1115
|
|
|
@@ -1123,8 +1123,8 @@ discard block |
|
|
block discarded – undo |
|
1123
|
1123
|
* @version 4.0.0 |
|
1124
|
1124
|
*/ |
|
1125
|
1125
|
protected function build_display_items() { |
|
1126
|
|
- if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1127
|
|
- define( 'WOOCOMMERCE_CART', true ); |
|
|
1126
|
+ if ( ! defined('WOOCOMMERCE_CART')) { |
|
|
1127
|
+ define('WOOCOMMERCE_CART', true); |
|
1128
|
1128
|
} |
|
1129
|
1129
|
|
|
1130
|
1130
|
$items = array(); |
|
@@ -1132,71 +1132,71 @@ discard block |
|
|
block discarded – undo |
|
1132
|
1132
|
$discounts = 0; |
|
1133
|
1133
|
|
|
1134
|
1134
|
// Default show only subtotal instead of itemization. |
|
1135
|
|
- if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1136
|
|
- foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
|
1135
|
+ if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
|
1136
|
+ foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1137
|
1137
|
$amount = $cart_item['line_subtotal']; |
|
1138
|
1138
|
$subtotal += $cart_item['line_subtotal']; |
|
1139
|
1139
|
$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
|
1140
|
1140
|
|
|
1141
|
|
- $product_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
|
1141
|
+ $product_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
1142
|
1142
|
|
|
1143
|
1143
|
$item = array( |
|
1144
|
1144
|
'label' => $product_name . $quantity_label, |
|
1145
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
|
1145
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1146
|
1146
|
); |
|
1147
|
1147
|
|
|
1148
|
1148
|
$items[] = $item; |
|
1149
|
1149
|
} |
|
1150
|
1150
|
} |
|
1151
|
1151
|
|
|
1152
|
|
- if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1153
|
|
- $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
|
1152
|
+ if (version_compare(WC_VERSION, '3.2', '<')) { |
|
|
1153
|
+ $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1154
|
1154
|
} else { |
|
1155
|
|
- $applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() ); |
|
|
1155
|
+ $applied_coupons = array_values(WC()->cart->get_coupon_discount_totals()); |
|
1156
|
1156
|
|
|
1157
|
|
- foreach ( $applied_coupons as $amount ) { |
|
|
1157
|
+ foreach ($applied_coupons as $amount) { |
|
1158
|
1158
|
$discounts += (float) $amount; |
|
1159
|
1159
|
} |
|
1160
|
1160
|
} |
|
1161
|
1161
|
|
|
1162
|
|
- $discounts = wc_format_decimal( $discounts, WC()->cart->dp ); |
|
1163
|
|
- $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1164
|
|
- $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1165
|
|
- $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1166
|
|
- $order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false ); |
|
|
1162
|
+ $discounts = wc_format_decimal($discounts, WC()->cart->dp); |
|
|
1163
|
+ $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
|
1164
|
+ $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
|
1165
|
+ $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
|
1166
|
+ $order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false); |
|
1167
|
1167
|
|
|
1168
|
|
- if ( wc_tax_enabled() ) { |
|
|
1168
|
+ if (wc_tax_enabled()) { |
|
1169
|
1169
|
$items[] = array( |
|
1170
|
|
- 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1171
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
|
1170
|
+ 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
|
1171
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1172
|
1172
|
); |
|
1173
|
1173
|
} |
|
1174
|
1174
|
|
|
1175
|
|
- if ( WC()->cart->needs_shipping() ) { |
|
|
1175
|
+ if (WC()->cart->needs_shipping()) { |
|
1176
|
1176
|
$items[] = array( |
|
1177
|
|
- 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1178
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
|
1177
|
+ 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
|
1178
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1179
|
1179
|
); |
|
1180
|
1180
|
} |
|
1181
|
1181
|
|
|
1182
|
|
- if ( WC()->cart->has_discount() ) { |
|
|
1182
|
+ if (WC()->cart->has_discount()) { |
|
1183
|
1183
|
$items[] = array( |
|
1184
|
|
- 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1185
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
|
1184
|
+ 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
|
1185
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1186
|
1186
|
); |
|
1187
|
1187
|
} |
|
1188
|
1188
|
|
|
1189
|
|
- if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
|
1189
|
+ if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1190
|
1190
|
$cart_fees = WC()->cart->fees; |
|
1191
|
1191
|
} else { |
|
1192
|
1192
|
$cart_fees = WC()->cart->get_fees(); |
|
1193
|
1193
|
} |
|
1194
|
1194
|
|
|
1195
|
1195
|
// Include fees and taxes as display items. |
|
1196
|
|
- foreach ( $cart_fees as $key => $fee ) { |
|
|
1196
|
+ foreach ($cart_fees as $key => $fee) { |
|
1197
|
1197
|
$items[] = array( |
|
1198
|
1198
|
'label' => $fee->name, |
|
1199
|
|
- 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
|
1199
|
+ 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1200
|
1200
|
); |
|
1201
|
1201
|
} |
|
1202
|
1202
|
|
|
@@ -1204,7 +1204,7 @@ discard block |
|
|
block discarded – undo |
|
1204
|
1204
|
'displayItems' => $items, |
|
1205
|
1205
|
'total' => array( |
|
1206
|
1206
|
'label' => $this->total_label, |
|
1207
|
|
- 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
|
1207
|
+ 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1208
|
1208
|
'pending' => false, |
|
1209
|
1209
|
), |
|
1210
|
1210
|
); |