|
@@ -1,5 +1,5 @@ discard block |
|
|
block discarded – undo |
|
1
|
1
|
<?php |
|
2
|
|
-if ( ! defined( 'ABSPATH' ) ) { |
|
|
2
|
+if ( ! defined('ABSPATH')) { |
|
3
|
3
|
exit; |
|
4
|
4
|
} |
|
5
|
5
|
|
|
@@ -120,8 +120,8 @@ discard block |
|
|
block discarded – undo |
|
120
|
120
|
*/ |
|
121
|
121
|
public function __construct() { |
|
122
|
122
|
$this->id = 'stripe'; |
|
123
|
|
- $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
124
|
|
- $this->method_description = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
|
123
|
+ $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
|
124
|
+ $this->method_description = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
125
|
125
|
$this->has_fields = true; |
|
126
|
126
|
$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
|
127
|
127
|
$this->supports = array( |
|
@@ -149,41 +149,41 @@ discard block |
|
|
block discarded – undo |
|
149
|
149
|
$this->init_settings(); |
|
150
|
150
|
|
|
151
|
151
|
// Get setting values. |
|
152
|
|
- $this->title = $this->get_option( 'title' ); |
|
153
|
|
- $this->description = $this->get_option( 'description' ); |
|
154
|
|
- $this->enabled = $this->get_option( 'enabled' ); |
|
155
|
|
- $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
156
|
|
- $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
157
|
|
- $this->statement_descriptor = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
158
|
|
- $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
159
|
|
- $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
160
|
|
- $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
161
|
|
- $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
162
|
|
- $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
163
|
|
- $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
164
|
|
- $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
165
|
|
- $this->apple_pay = 'yes' === $this->get_option( 'apple_pay' ); |
|
166
|
|
- $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
167
|
|
- $this->apple_pay_button = $this->get_option( 'apple_pay_button', 'black' ); |
|
168
|
|
- $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
169
|
|
- $this->allow_remember_me = 'yes' === $this->get_option( 'allow_remember_me', 'no' ); |
|
170
|
|
- |
|
171
|
|
- if ( $this->stripe_checkout ) { |
|
172
|
|
- $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
173
|
|
- } |
|
174
|
|
- |
|
175
|
|
- if ( $this->testmode ) { |
|
176
|
|
- $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
177
|
|
- $this->description = trim( $this->description ); |
|
178
|
|
- } |
|
179
|
|
- |
|
180
|
|
- WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
|
152
|
+ $this->title = $this->get_option('title'); |
|
|
153
|
+ $this->description = $this->get_option('description'); |
|
|
154
|
+ $this->enabled = $this->get_option('enabled'); |
|
|
155
|
+ $this->testmode = 'yes' === $this->get_option('testmode'); |
|
|
156
|
+ $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
|
157
|
+ $this->statement_descriptor = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
|
158
|
+ $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
|
159
|
+ $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
|
160
|
+ $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
|
161
|
+ $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
|
162
|
+ $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
|
163
|
+ $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
|
164
|
+ $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
|
165
|
+ $this->apple_pay = 'yes' === $this->get_option('apple_pay'); |
|
|
166
|
+ $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
|
167
|
+ $this->apple_pay_button = $this->get_option('apple_pay_button', 'black'); |
|
|
168
|
+ $this->logging = 'yes' === $this->get_option('logging'); |
|
|
169
|
+ $this->allow_remember_me = 'yes' === $this->get_option('allow_remember_me', 'no'); |
|
|
170
|
+ |
|
|
171
|
+ if ($this->stripe_checkout) { |
|
|
172
|
+ $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
|
173
|
+ } |
|
|
174
|
+ |
|
|
175
|
+ if ($this->testmode) { |
|
|
176
|
+ $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
|
177
|
+ $this->description = trim($this->description); |
|
|
178
|
+ } |
|
|
179
|
+ |
|
|
180
|
+ WC_Stripe_API::set_secret_key($this->secret_key); |
|
181
|
181
|
|
|
182
|
182
|
// Hooks. |
|
183
|
|
- add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
184
|
|
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
185
|
|
- add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
186
|
|
- add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
|
183
|
+ add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
|
184
|
+ add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
|
185
|
+ add_action('admin_notices', array($this, 'admin_notices')); |
|
|
186
|
+ add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
187
|
187
|
} |
|
188
|
188
|
|
|
189
|
189
|
/** |
|
@@ -197,16 +197,16 @@ discard block |
|
|
block discarded – undo |
|
197
|
197
|
?> |
|
198
|
198
|
<tr valign="top"> |
|
199
|
199
|
<th scope="row" class="titledesc"> |
|
200
|
|
- <label for="wc-to-square"><?php esc_html_e( 'Apple Pay Domain Verification', 'woocommerce-gateway-stripe' ); ?></label> |
|
201
|
|
- <?php echo wc_help_tip( __( 'Click button to verify your domain with Apple Pay. This is required.', 'woocommerce-gateway-stripe' ) ); ?> |
|
|
200
|
+ <label for="wc-to-square"><?php esc_html_e('Apple Pay Domain Verification', 'woocommerce-gateway-stripe'); ?></label> |
|
|
201
|
+ <?php echo wc_help_tip(__('Click button to verify your domain with Apple Pay. This is required.', 'woocommerce-gateway-stripe')); ?> |
|
202
|
202
|
</th> |
|
203
|
203
|
<td class="forminp"> |
|
204
|
|
- <?php if ( ! empty( $this->secret_key ) && ! $this->apple_pay_domain_set ) { ?> |
|
205
|
|
- <a href="#" id="wc-gateway-stripe-apple-pay-domain" class="button button-secondary"><?php esc_html_e( 'Verify Domain', 'woocommerce-gateway-stripe' ); ?></a> |
|
|
204
|
+ <?php if ( ! empty($this->secret_key) && ! $this->apple_pay_domain_set) { ?> |
|
|
205
|
+ <a href="#" id="wc-gateway-stripe-apple-pay-domain" class="button button-secondary"><?php esc_html_e('Verify Domain', 'woocommerce-gateway-stripe'); ?></a> |
|
206
|
206
|
<p class="wc-stripe-apple-pay-domain-message" style="color:green;"></p> |
|
207
|
207
|
<?php } else { ?> |
|
208
|
|
- <a href="#" id="wc-gateway-stripe-apple-pay-domain" class="button button-secondary"><?php esc_html_e( 'Re-verify Domain', 'woocommerce-gateway-stripe' ); ?></a> |
|
209
|
|
- <p class="wc-stripe-apple-pay-domain-message" style="color:green;"><?php esc_html_e( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ); ?></p> |
|
|
208
|
+ <a href="#" id="wc-gateway-stripe-apple-pay-domain" class="button button-secondary"><?php esc_html_e('Re-verify Domain', 'woocommerce-gateway-stripe'); ?></a> |
|
|
209
|
+ <p class="wc-stripe-apple-pay-domain-message" style="color:green;"><?php esc_html_e('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe'); ?></p> |
|
210
|
210
|
<?php } ?> |
|
211
|
211
|
<input type="hidden" name="woocommerce_stripe_apple_pay_domain_set" class="wc-gateway-stripe-apple-pay-domain-set" /> |
|
212
|
212
|
</td> |
|
@@ -222,8 +222,8 @@ discard block |
|
|
block discarded – undo |
|
222
|
222
|
* @version 3.1.0 |
|
223
|
223
|
* @param string $key |
|
224
|
224
|
*/ |
|
225
|
|
- public function validate_apple_pay_domain_field( $key ) { |
|
226
|
|
- $value = isset( $_POST['woocommerce_stripe_apple_pay_domain_set'] ) ? 'yes' : 'no'; |
|
|
225
|
+ public function validate_apple_pay_domain_field($key) { |
|
|
226
|
+ $value = isset($_POST['woocommerce_stripe_apple_pay_domain_set']) ? 'yes' : 'no'; |
|
227
|
227
|
|
|
228
|
228
|
return $value; |
|
229
|
229
|
} |
|
@@ -235,24 +235,24 @@ discard block |
|
|
block discarded – undo |
|
235
|
235
|
* @return string |
|
236
|
236
|
*/ |
|
237
|
237
|
public function get_icon() { |
|
238
|
|
- $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
239
|
|
- $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
|
238
|
+ $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
|
239
|
+ $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
240
|
240
|
|
|
241
|
|
- $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
242
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
243
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
|
241
|
+ $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
|
242
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
|
243
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
244
|
244
|
|
|
245
|
|
- if ( 'USD' === get_woocommerce_currency() ) { |
|
246
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
247
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
248
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
|
245
|
+ if ('USD' === get_woocommerce_currency()) { |
|
|
246
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
|
247
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
|
248
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
249
|
249
|
} |
|
250
|
250
|
|
|
251
|
|
- if ( $this->bitcoin && $this->stripe_checkout ) { |
|
252
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
|
251
|
+ if ($this->bitcoin && $this->stripe_checkout) { |
|
|
252
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
253
|
253
|
} |
|
254
|
254
|
|
|
255
|
|
- return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
|
255
|
+ return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
256
|
256
|
} |
|
257
|
257
|
|
|
258
|
258
|
/** |
|
@@ -263,11 +263,11 @@ discard block |
|
|
block discarded – undo |
|
263
|
263
|
* |
|
264
|
264
|
* @return float|int |
|
265
|
265
|
*/ |
|
266
|
|
- public function get_stripe_amount( $total, $currency = '' ) { |
|
267
|
|
- if ( ! $currency ) { |
|
|
266
|
+ public function get_stripe_amount($total, $currency = '') { |
|
|
267
|
+ if ( ! $currency) { |
|
268
|
268
|
$currency = get_woocommerce_currency(); |
|
269
|
269
|
} |
|
270
|
|
- switch ( strtoupper( $currency ) ) { |
|
|
270
|
+ switch (strtoupper($currency)) { |
|
271
|
271
|
// Zero decimal currencies. |
|
272
|
272
|
case 'BIF' : |
|
273
|
273
|
case 'CLP' : |
|
@@ -284,10 +284,10 @@ discard block |
|
|
block discarded – undo |
|
284
|
284
|
case 'XAF' : |
|
285
|
285
|
case 'XOF' : |
|
286
|
286
|
case 'XPF' : |
|
287
|
|
- $total = absint( $total ); |
|
|
287
|
+ $total = absint($total); |
|
288
|
288
|
break; |
|
289
|
289
|
default : |
|
290
|
|
- $total = round( $total, 2 ) * 100; // In cents. |
|
|
290
|
+ $total = round($total, 2) * 100; // In cents. |
|
291
|
291
|
break; |
|
292
|
292
|
} |
|
293
|
293
|
return $total; |
|
@@ -297,13 +297,13 @@ discard block |
|
|
block discarded – undo |
|
297
|
297
|
* Check if SSL is enabled and notify the user |
|
298
|
298
|
*/ |
|
299
|
299
|
public function admin_notices() { |
|
300
|
|
- if ( 'no' === $this->enabled ) { |
|
|
300
|
+ if ('no' === $this->enabled) { |
|
301
|
301
|
return; |
|
302
|
302
|
} |
|
303
|
303
|
|
|
304
|
304
|
// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
|
305
|
|
- if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
306
|
|
- echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>'; |
|
|
305
|
+ if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
|
306
|
+ echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; |
|
307
|
307
|
} |
|
308
|
308
|
} |
|
309
|
309
|
|
|
@@ -311,11 +311,11 @@ discard block |
|
|
block discarded – undo |
|
311
|
311
|
* Check if this gateway is enabled |
|
312
|
312
|
*/ |
|
313
|
313
|
public function is_available() { |
|
314
|
|
- if ( 'yes' === $this->enabled ) { |
|
315
|
|
- if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
|
314
|
+ if ('yes' === $this->enabled) { |
|
|
315
|
+ if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
316
|
316
|
return false; |
|
317
|
317
|
} |
|
318
|
|
- if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
|
318
|
+ if ( ! $this->secret_key || ! $this->publishable_key) { |
|
319
|
319
|
return false; |
|
320
|
320
|
} |
|
321
|
321
|
return true; |
|
@@ -327,7 +327,7 @@ discard block |
|
|
block discarded – undo |
|
327
|
327
|
* Initialise Gateway Settings Form Fields |
|
328
|
328
|
*/ |
|
329
|
329
|
public function init_form_fields() { |
|
330
|
|
- $this->form_fields = include( 'settings-stripe.php' ); |
|
|
330
|
+ $this->form_fields = include('settings-stripe.php'); |
|
331
|
331
|
} |
|
332
|
332
|
|
|
333
|
333
|
/** |
|
@@ -335,54 +335,54 @@ discard block |
|
|
block discarded – undo |
|
335
|
335
|
*/ |
|
336
|
336
|
public function payment_fields() { |
|
337
|
337
|
$user = wp_get_current_user(); |
|
338
|
|
- $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
|
338
|
+ $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
339
|
339
|
$total = WC()->cart->total; |
|
340
|
340
|
|
|
341
|
341
|
// If paying from order, we need to get total from order not cart. |
|
342
|
|
- if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) { |
|
343
|
|
- $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
|
342
|
+ if (isset($_GET['pay_for_order']) && isset($_GET['key'])) { |
|
|
343
|
+ $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
344
|
344
|
$total = $order->get_total(); |
|
345
|
345
|
} |
|
346
|
346
|
|
|
347
|
|
- if ( $user->ID ) { |
|
348
|
|
- $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
|
347
|
+ if ($user->ID) { |
|
|
348
|
+ $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
349
|
349
|
$user_email = $user_email ? $user_email : $user->user_email; |
|
350
|
350
|
} else { |
|
351
|
351
|
$user_email = ''; |
|
352
|
352
|
} |
|
353
|
353
|
|
|
354
|
|
- if ( is_add_payment_method_page() ) { |
|
355
|
|
- $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
|
354
|
+ if (is_add_payment_method_page()) { |
|
|
355
|
+ $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
356
|
356
|
} else { |
|
357
|
357
|
$pay_button_text = ''; |
|
358
|
358
|
} |
|
359
|
359
|
|
|
360
|
360
|
echo '<div |
|
361
|
361
|
id="stripe-payment-data" |
|
362
|
|
- data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
|
362
|
+ data-panel-label="' . esc_attr($pay_button_text) . '" |
|
363
|
363
|
data-description="" |
|
364
|
|
- data-email="' . esc_attr( $user_email ) . '" |
|
365
|
|
- data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '" |
|
366
|
|
- data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
367
|
|
- data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
368
|
|
- data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
369
|
|
- data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
370
|
|
- data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
371
|
|
- data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">'; |
|
|
364
|
+ data-email="' . esc_attr($user_email) . '" |
|
|
365
|
+ data-amount="' . esc_attr($this->get_stripe_amount($total)) . '" |
|
|
366
|
+ data-name="' . esc_attr($this->statement_descriptor) . '" |
|
|
367
|
+ data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
|
368
|
+ data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
|
369
|
+ data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
|
370
|
+ data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
|
371
|
+ data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">'; |
|
372
|
372
|
|
|
373
|
|
- if ( $this->description ) { |
|
374
|
|
- echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
|
373
|
+ if ($this->description) { |
|
|
374
|
+ echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
375
|
375
|
} |
|
376
|
376
|
|
|
377
|
|
- if ( $display_tokenization ) { |
|
|
377
|
+ if ($display_tokenization) { |
|
378
|
378
|
$this->tokenization_script(); |
|
379
|
379
|
$this->saved_payment_methods(); |
|
380
|
380
|
} |
|
381
|
381
|
|
|
382
|
|
- if ( ! $this->stripe_checkout ) { |
|
|
382
|
+ if ( ! $this->stripe_checkout) { |
|
383
|
383
|
$this->form(); |
|
384
|
384
|
|
|
385
|
|
- if ( $display_tokenization ) { |
|
|
385
|
+ if ($display_tokenization) { |
|
386
|
386
|
$this->save_payment_method_checkbox(); |
|
387
|
387
|
} |
|
388
|
388
|
} |
|
@@ -398,20 +398,20 @@ discard block |
|
|
block discarded – undo |
|
398
|
398
|
* @return array |
|
399
|
399
|
*/ |
|
400
|
400
|
public function get_localized_messages() { |
|
401
|
|
- return apply_filters( 'wc_stripe_localized_messages', array( |
|
402
|
|
- 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
403
|
|
- 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
404
|
|
- 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
405
|
|
- 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
406
|
|
- 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
407
|
|
- 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
408
|
|
- 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
409
|
|
- 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
410
|
|
- 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
411
|
|
- 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
412
|
|
- 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
413
|
|
- 'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ), |
|
414
|
|
- ) ); |
|
|
401
|
+ return apply_filters('wc_stripe_localized_messages', array( |
|
|
402
|
+ 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
|
403
|
+ 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
|
404
|
+ 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
|
405
|
+ 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
|
406
|
+ 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
|
407
|
+ 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
|
408
|
+ 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
|
409
|
+ 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
|
410
|
+ 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
|
411
|
+ 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
|
412
|
+ 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
|
413
|
+ 'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'), |
|
|
414
|
+ )); |
|
415
|
415
|
} |
|
416
|
416
|
|
|
417
|
417
|
/** |
|
@@ -421,29 +421,29 @@ discard block |
|
|
block discarded – undo |
|
421
|
421
|
* @version 3.1.0 |
|
422
|
422
|
*/ |
|
423
|
423
|
public function admin_scripts() { |
|
424
|
|
- if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
|
424
|
+ if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
425
|
425
|
return; |
|
426
|
426
|
} |
|
427
|
427
|
|
|
428
|
|
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
|
428
|
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
429
|
429
|
|
|
430
|
|
- wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
|
430
|
+ wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
431
|
431
|
|
|
432
|
432
|
$stripe_admin_params = array( |
|
433
|
433
|
'localized_messages' => array( |
|
434
|
|
- 'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ), |
|
435
|
|
- 'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ), |
|
436
|
|
- 're_verify_button_text' => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ), |
|
437
|
|
- 'missing_secret_key' => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ), |
|
438
|
|
- 'verifying_button_text' => __( 'Verifying Domain...', 'woocommerce-gateway-stripe' ), |
|
|
434
|
+ 'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'), |
|
|
435
|
+ 'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'), |
|
|
436
|
+ 're_verify_button_text' => __('Re-verify Domain', 'woocommerce-gateway-stripe'), |
|
|
437
|
+ 'missing_secret_key' => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'), |
|
|
438
|
+ 'verifying_button_text' => __('Verifying Domain...', 'woocommerce-gateway-stripe'), |
|
439
|
439
|
), |
|
440
|
|
- 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
|
440
|
+ 'ajaxurl' => admin_url('admin-ajax.php'), |
|
441
|
441
|
'nonce' => array( |
|
442
|
|
- 'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ), |
|
|
442
|
+ 'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'), |
|
443
|
443
|
), |
|
444
|
444
|
); |
|
445
|
445
|
|
|
446
|
|
- wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) ); |
|
|
446
|
+ wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params)); |
|
447
|
447
|
} |
|
448
|
448
|
|
|
449
|
449
|
/** |
|
@@ -454,30 +454,30 @@ discard block |
|
|
block discarded – undo |
|
454
|
454
|
* @access public |
|
455
|
455
|
*/ |
|
456
|
456
|
public function payment_scripts() { |
|
457
|
|
- if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
|
457
|
+ if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
458
|
458
|
return; |
|
459
|
459
|
} |
|
460
|
460
|
|
|
461
|
|
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
|
461
|
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
462
|
462
|
|
|
463
|
|
- if ( $this->stripe_checkout ) { |
|
464
|
|
- wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
465
|
|
- wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
|
463
|
+ if ($this->stripe_checkout) { |
|
|
464
|
+ wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
|
465
|
+ wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
466
|
466
|
} else { |
|
467
|
|
- wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
468
|
|
- wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
|
467
|
+ wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
|
468
|
+ wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
469
|
469
|
} |
|
470
|
470
|
|
|
471
|
471
|
$stripe_params = array( |
|
472
|
472
|
'key' => $this->publishable_key, |
|
473
|
|
- 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
474
|
|
- 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
|
473
|
+ 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
|
474
|
+ 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
475
|
475
|
); |
|
476
|
476
|
|
|
477
|
477
|
// If we're on the pay page we need to pass stripe.js the address of the order. |
|
478
|
|
- if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
479
|
|
- $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
480
|
|
- $order = wc_get_order( $order_id ); |
|
|
478
|
+ if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
|
479
|
+ $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
|
480
|
+ $order = wc_get_order($order_id); |
|
481
|
481
|
|
|
482
|
482
|
$stripe_params['billing_first_name'] = $order->billing_first_name; |
|
483
|
483
|
$stripe_params['billing_last_name'] = $order->billing_last_name; |
|
@@ -489,14 +489,14 @@ discard block |
|
|
block discarded – undo |
|
489
|
489
|
$stripe_params['billing_country'] = $order->billing_country; |
|
490
|
490
|
} |
|
491
|
491
|
|
|
492
|
|
- $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ); |
|
493
|
|
- $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
494
|
|
- $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
|
492
|
+ $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'); |
|
|
493
|
+ $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
|
494
|
+ $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
495
|
495
|
|
|
496
|
496
|
// merge localized messages to be use in JS |
|
497
|
|
- $stripe_params = array_merge( $stripe_params, $this->get_localized_messages() ); |
|
|
497
|
+ $stripe_params = array_merge($stripe_params, $this->get_localized_messages()); |
|
498
|
498
|
|
|
499
|
|
- wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
|
499
|
+ wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
500
|
500
|
} |
|
501
|
501
|
|
|
502
|
502
|
/** |
|
@@ -505,31 +505,31 @@ discard block |
|
|
block discarded – undo |
|
505
|
505
|
* @param object $source |
|
506
|
506
|
* @return array() |
|
507
|
507
|
*/ |
|
508
|
|
- protected function generate_payment_request( $order, $source ) { |
|
|
508
|
+ protected function generate_payment_request($order, $source) { |
|
509
|
509
|
$post_data = array(); |
|
510
|
|
- $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
511
|
|
- $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
512
|
|
- $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
|
510
|
+ $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
|
511
|
+ $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
|
512
|
+ $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
513
|
513
|
$post_data['capture'] = $this->capture ? 'true' : 'false'; |
|
514
|
514
|
|
|
515
|
|
- if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
|
515
|
+ if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
516
|
516
|
$post_data['receipt_email'] = $order->billing_email; |
|
517
|
517
|
} |
|
518
|
518
|
|
|
519
|
|
- $post_data['expand[]'] = 'balance_transaction'; |
|
|
519
|
+ $post_data['expand[]'] = 'balance_transaction'; |
|
520
|
520
|
|
|
521
|
521
|
$metadata = array( |
|
522
|
|
- __( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $order->billing_first_name ) . ' ' . sanitize_text_field( $order->billing_last_name ), |
|
523
|
|
- __( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $order->billing_email ), |
|
|
522
|
+ __('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($order->billing_first_name) . ' ' . sanitize_text_field($order->billing_last_name), |
|
|
523
|
+ __('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($order->billing_email), |
|
524
|
524
|
); |
|
525
|
525
|
|
|
526
|
|
- $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
|
526
|
+ $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
527
|
527
|
|
|
528
|
|
- if ( $source->customer ) { |
|
|
528
|
+ if ($source->customer) { |
|
529
|
529
|
$post_data['customer'] = $source->customer; |
|
530
|
530
|
} |
|
531
|
531
|
|
|
532
|
|
- if ( $source->source ) { |
|
|
532
|
+ if ($source->source) { |
|
533
|
533
|
$post_data['source'] = $source->source; |
|
534
|
534
|
} |
|
535
|
535
|
|
|
@@ -541,7 +541,7 @@ discard block |
|
|
block discarded – undo |
|
541
|
541
|
* @param WC_Order $order |
|
542
|
542
|
* @param object $source |
|
543
|
543
|
*/ |
|
544
|
|
- return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
|
544
|
+ return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
545
|
545
|
} |
|
546
|
546
|
|
|
547
|
547
|
/** |
|
@@ -553,37 +553,37 @@ discard block |
|
|
block discarded – undo |
|
553
|
553
|
* @throws Exception When card was not added or for and invalid card. |
|
554
|
554
|
* @return object |
|
555
|
555
|
*/ |
|
556
|
|
- protected function get_source( $user_id, $force_customer = false ) { |
|
557
|
|
- $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
|
556
|
+ protected function get_source($user_id, $force_customer = false) { |
|
|
557
|
+ $stripe_customer = new WC_Stripe_Customer($user_id); |
|
558
|
558
|
$stripe_source = false; |
|
559
|
559
|
$token_id = false; |
|
560
|
560
|
|
|
561
|
561
|
// New CC info was entered and we have a new token to process |
|
562
|
|
- if ( isset( $_POST['stripe_token'] ) ) { |
|
563
|
|
- $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
564
|
|
- $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
|
562
|
+ if (isset($_POST['stripe_token'])) { |
|
|
563
|
+ $stripe_token = wc_clean($_POST['stripe_token']); |
|
|
564
|
+ $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
565
|
565
|
|
|
566
|
566
|
// This is true if the user wants to store the card to their account. |
|
567
|
|
- if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
568
|
|
- $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
|
567
|
+ if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
|
568
|
+ $stripe_source = $stripe_customer->add_card($stripe_token); |
|
569
|
569
|
|
|
570
|
|
- if ( is_wp_error( $stripe_source ) ) { |
|
571
|
|
- throw new Exception( $stripe_source->get_error_message() ); |
|
|
570
|
+ if (is_wp_error($stripe_source)) { |
|
|
571
|
+ throw new Exception($stripe_source->get_error_message()); |
|
572
|
572
|
} |
|
573
|
573
|
} else { |
|
574
|
574
|
// Not saving token, so don't define customer either. |
|
575
|
575
|
$stripe_source = $stripe_token; |
|
576
|
576
|
$stripe_customer = false; |
|
577
|
577
|
} |
|
578
|
|
- } elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
|
578
|
+ } elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
579
|
579
|
// Use an existing token, and then process the payment |
|
580
|
580
|
|
|
581
|
|
- $token_id = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
582
|
|
- $token = WC_Payment_Tokens::get( $token_id ); |
|
|
581
|
+ $token_id = wc_clean($_POST['wc-stripe-payment-token']); |
|
|
582
|
+ $token = WC_Payment_Tokens::get($token_id); |
|
583
|
583
|
|
|
584
|
|
- if ( ! $token || $token->get_user_id() !== get_current_user_id() ) { |
|
585
|
|
- WC()->session->set( 'refresh_totals', true ); |
|
586
|
|
- throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
|
584
|
+ if ( ! $token || $token->get_user_id() !== get_current_user_id()) { |
|
|
585
|
+ WC()->session->set('refresh_totals', true); |
|
|
586
|
+ throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
587
|
587
|
} |
|
588
|
588
|
|
|
589
|
589
|
$stripe_source = $token->get_token(); |
|
@@ -607,16 +607,16 @@ discard block |
|
|
block discarded – undo |
|
607
|
607
|
* @param object $order |
|
608
|
608
|
* @return object |
|
609
|
609
|
*/ |
|
610
|
|
- protected function get_order_source( $order = null ) { |
|
|
610
|
+ protected function get_order_source($order = null) { |
|
611
|
611
|
$stripe_customer = new WC_Stripe_Customer(); |
|
612
|
612
|
$stripe_source = false; |
|
613
|
613
|
$token_id = false; |
|
614
|
614
|
|
|
615
|
|
- if ( $order ) { |
|
616
|
|
- if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) { |
|
617
|
|
- $stripe_customer->set_id( $meta_value ); |
|
|
615
|
+ if ($order) { |
|
|
616
|
+ if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) { |
|
|
617
|
+ $stripe_customer->set_id($meta_value); |
|
618
|
618
|
} |
|
619
|
|
- if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) { |
|
|
619
|
+ if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) { |
|
620
|
620
|
$stripe_source = $meta_value; |
|
621
|
621
|
} |
|
622
|
622
|
} |
|
@@ -639,57 +639,57 @@ discard block |
|
|
block discarded – undo |
|
639
|
639
|
* |
|
640
|
640
|
* @return array|void |
|
641
|
641
|
*/ |
|
642
|
|
- public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
|
642
|
+ public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
643
|
643
|
try { |
|
644
|
|
- $order = wc_get_order( $order_id ); |
|
645
|
|
- $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
|
644
|
+ $order = wc_get_order($order_id); |
|
|
645
|
+ $source = $this->get_source(get_current_user_id(), $force_customer); |
|
646
|
646
|
|
|
647
|
|
- if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
648
|
|
- $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
649
|
|
- $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
650
|
|
- throw new Exception( $error_msg ); |
|
|
647
|
+ if (empty($source->source) && empty($source->customer)) { |
|
|
648
|
+ $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
|
649
|
+ $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
|
650
|
+ throw new Exception($error_msg); |
|
651
|
651
|
} |
|
652
|
652
|
|
|
653
|
653
|
// Store source to order meta. |
|
654
|
|
- $this->save_source( $order, $source ); |
|
|
654
|
+ $this->save_source($order, $source); |
|
655
|
655
|
|
|
656
|
656
|
// Handle payment. |
|
657
|
|
- if ( $order->get_total() > 0 ) { |
|
|
657
|
+ if ($order->get_total() > 0) { |
|
658
|
658
|
|
|
659
|
|
- if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
660
|
|
- throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
|
659
|
+ if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
|
660
|
+ throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
661
|
661
|
} |
|
662
|
662
|
|
|
663
|
|
- $this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
|
663
|
+ $this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
664
|
664
|
|
|
665
|
665
|
// Make the request. |
|
666
|
|
- $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
|
666
|
+ $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
667
|
667
|
|
|
668
|
|
- if ( is_wp_error( $response ) ) { |
|
|
668
|
+ if (is_wp_error($response)) { |
|
669
|
669
|
// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
670
|
|
- if ( 'customer' === $response->get_error_code() && $retry ) { |
|
671
|
|
- delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
672
|
|
- return $this->process_payment( $order_id, false, $force_customer ); |
|
|
670
|
+ if ('customer' === $response->get_error_code() && $retry) { |
|
|
671
|
+ delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
|
672
|
+ return $this->process_payment($order_id, false, $force_customer); |
|
673
|
673
|
// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
674
|
|
- } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
675
|
|
- $token = WC_Payment_Tokens::get( $source->token_id ); |
|
|
674
|
+ } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
|
675
|
+ $token = WC_Payment_Tokens::get($source->token_id); |
|
676
|
676
|
$token->delete(); |
|
677
|
|
- $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
678
|
|
- $order->add_order_note( $message ); |
|
679
|
|
- throw new Exception( $message ); |
|
|
677
|
+ $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
|
678
|
+ $order->add_order_note($message); |
|
|
679
|
+ throw new Exception($message); |
|
680
|
680
|
} |
|
681
|
681
|
|
|
682
|
682
|
$localized_messages = $this->get_localized_messages(); |
|
683
|
683
|
|
|
684
|
|
- $message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message(); |
|
|
684
|
+ $message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message(); |
|
685
|
685
|
|
|
686
|
|
- $order->add_order_note( $message ); |
|
|
686
|
+ $order->add_order_note($message); |
|
687
|
687
|
|
|
688
|
|
- throw new Exception( $message ); |
|
|
688
|
+ throw new Exception($message); |
|
689
|
689
|
} |
|
690
|
690
|
|
|
691
|
691
|
// Process valid response. |
|
692
|
|
- $this->process_response( $response, $order ); |
|
|
692
|
+ $this->process_response($response, $order); |
|
693
|
693
|
} else { |
|
694
|
694
|
$order->payment_complete(); |
|
695
|
695
|
} |
|
@@ -697,23 +697,23 @@ discard block |
|
|
block discarded – undo |
|
697
|
697
|
// Remove cart. |
|
698
|
698
|
WC()->cart->empty_cart(); |
|
699
|
699
|
|
|
700
|
|
- do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
|
700
|
+ do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
701
|
701
|
|
|
702
|
702
|
// Return thank you page redirect. |
|
703
|
703
|
return array( |
|
704
|
704
|
'result' => 'success', |
|
705
|
|
- 'redirect' => $this->get_return_url( $order ), |
|
|
705
|
+ 'redirect' => $this->get_return_url($order), |
|
706
|
706
|
); |
|
707
|
707
|
|
|
708
|
|
- } catch ( Exception $e ) { |
|
709
|
|
- wc_add_notice( $e->getMessage(), 'error' ); |
|
710
|
|
- $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
|
708
|
+ } catch (Exception $e) { |
|
|
709
|
+ wc_add_notice($e->getMessage(), 'error'); |
|
|
710
|
+ $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
711
|
711
|
|
|
712
|
|
- if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
713
|
|
- $this->send_failed_order_email( $order_id ); |
|
|
712
|
+ if ($order->has_status(array('pending', 'failed'))) { |
|
|
713
|
+ $this->send_failed_order_email($order_id); |
|
714
|
714
|
} |
|
715
|
715
|
|
|
716
|
|
- do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
|
716
|
+ do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
717
|
717
|
|
|
718
|
718
|
return array( |
|
719
|
719
|
'result' => 'fail', |
|
@@ -728,52 +728,52 @@ discard block |
|
|
block discarded – undo |
|
728
|
728
|
* @param WC_Order $order For to which the source applies. |
|
729
|
729
|
* @param stdClass $source Source information. |
|
730
|
730
|
*/ |
|
731
|
|
- protected function save_source( $order, $source ) { |
|
|
731
|
+ protected function save_source($order, $source) { |
|
732
|
732
|
// Store source in the order. |
|
733
|
|
- if ( $source->customer ) { |
|
734
|
|
- update_post_meta( $order->id, '_stripe_customer_id', $source->customer ); |
|
|
733
|
+ if ($source->customer) { |
|
|
734
|
+ update_post_meta($order->id, '_stripe_customer_id', $source->customer); |
|
735
|
735
|
} |
|
736
|
|
- if ( $source->source ) { |
|
737
|
|
- update_post_meta( $order->id, '_stripe_card_id', $source->source ); |
|
|
736
|
+ if ($source->source) { |
|
|
737
|
+ update_post_meta($order->id, '_stripe_card_id', $source->source); |
|
738
|
738
|
} |
|
739
|
739
|
} |
|
740
|
740
|
|
|
741
|
741
|
/** |
|
742
|
742
|
* Store extra meta data for an order from a Stripe Response. |
|
743
|
743
|
*/ |
|
744
|
|
- public function process_response( $response, $order ) { |
|
745
|
|
- $this->log( 'Processing response: ' . print_r( $response, true ) ); |
|
|
744
|
+ public function process_response($response, $order) { |
|
|
745
|
+ $this->log('Processing response: ' . print_r($response, true)); |
|
746
|
746
|
|
|
747
|
747
|
// Store charge data |
|
748
|
|
- update_post_meta( $order->id, '_stripe_charge_id', $response->id ); |
|
749
|
|
- update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
|
748
|
+ update_post_meta($order->id, '_stripe_charge_id', $response->id); |
|
|
749
|
+ update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
750
|
750
|
|
|
751
|
751
|
// Store other data such as fees |
|
752
|
|
- if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
|
752
|
+ if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
753
|
753
|
// Fees and Net needs to both come from Stripe to be accurate as the returned |
|
754
|
754
|
// values are in the local currency of the Stripe account, not from WC. |
|
755
|
|
- $fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0; |
|
756
|
|
- $net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0; |
|
757
|
|
- update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
758
|
|
- update_post_meta( $order->id, 'Net Revenue From Stripe', $net ); |
|
|
755
|
+ $fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0; |
|
|
756
|
+ $net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0; |
|
|
757
|
+ update_post_meta($order->id, 'Stripe Fee', $fee); |
|
|
758
|
+ update_post_meta($order->id, 'Net Revenue From Stripe', $net); |
|
759
|
759
|
} |
|
760
|
760
|
|
|
761
|
|
- if ( $response->captured ) { |
|
762
|
|
- $order->payment_complete( $response->id ); |
|
|
761
|
+ if ($response->captured) { |
|
|
762
|
+ $order->payment_complete($response->id); |
|
763
|
763
|
|
|
764
|
|
- $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
765
|
|
- $order->add_order_note( $message ); |
|
766
|
|
- $this->log( 'Success: ' . $message ); |
|
|
764
|
+ $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
|
765
|
+ $order->add_order_note($message); |
|
|
766
|
+ $this->log('Success: ' . $message); |
|
767
|
767
|
|
|
768
|
768
|
} else { |
|
769
|
|
- add_post_meta( $order->id, '_transaction_id', $response->id, true ); |
|
|
769
|
+ add_post_meta($order->id, '_transaction_id', $response->id, true); |
|
770
|
770
|
|
|
771
|
|
- if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
|
771
|
+ if ($order->has_status(array('pending', 'failed'))) { |
|
772
|
772
|
$order->reduce_order_stock(); |
|
773
|
773
|
} |
|
774
|
774
|
|
|
775
|
|
- $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
776
|
|
- $this->log( "Successful auth: $response->id" ); |
|
|
775
|
+ $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
|
776
|
+ $this->log("Successful auth: $response->id"); |
|
777
|
777
|
} |
|
778
|
778
|
|
|
779
|
779
|
return $response; |
|
@@ -785,32 +785,32 @@ discard block |
|
|
block discarded – undo |
|
785
|
785
|
* @since 3.0.0 |
|
786
|
786
|
*/ |
|
787
|
787
|
public function add_payment_method() { |
|
788
|
|
- if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
789
|
|
- wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
|
788
|
+ if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
|
789
|
+ wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
790
|
790
|
return; |
|
791
|
791
|
} |
|
792
|
792
|
|
|
793
|
|
- $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
794
|
|
- $card = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
|
793
|
+ $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
|
794
|
+ $card = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
795
|
795
|
|
|
796
|
|
- if ( is_wp_error( $card ) ) { |
|
|
796
|
+ if (is_wp_error($card)) { |
|
797
|
797
|
$localized_messages = $this->get_localized_messages(); |
|
798
|
|
- $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
|
798
|
+ $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
799
|
799
|
|
|
800
|
800
|
// loop through the errors to find matching localized message |
|
801
|
|
- foreach ( $card->errors as $error => $msg ) { |
|
802
|
|
- if ( isset( $localized_messages[ $error ] ) ) { |
|
803
|
|
- $error_msg = $localized_messages[ $error ]; |
|
|
801
|
+ foreach ($card->errors as $error => $msg) { |
|
|
802
|
+ if (isset($localized_messages[$error])) { |
|
|
803
|
+ $error_msg = $localized_messages[$error]; |
|
804
|
804
|
} |
|
805
|
805
|
} |
|
806
|
806
|
|
|
807
|
|
- wc_add_notice( $error_msg, 'error' ); |
|
|
807
|
+ wc_add_notice($error_msg, 'error'); |
|
808
|
808
|
return; |
|
809
|
809
|
} |
|
810
|
810
|
|
|
811
|
811
|
return array( |
|
812
|
812
|
'result' => 'success', |
|
813
|
|
- 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
|
813
|
+ 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
814
|
814
|
); |
|
815
|
815
|
} |
|
816
|
816
|
|
|
@@ -820,36 +820,36 @@ discard block |
|
|
block discarded – undo |
|
820
|
820
|
* @param float $amount |
|
821
|
821
|
* @return bool |
|
822
|
822
|
*/ |
|
823
|
|
- public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
824
|
|
- $order = wc_get_order( $order_id ); |
|
|
823
|
+ public function process_refund($order_id, $amount = null, $reason = '') { |
|
|
824
|
+ $order = wc_get_order($order_id); |
|
825
|
825
|
|
|
826
|
|
- if ( ! $order || ! $order->get_transaction_id() ) { |
|
|
826
|
+ if ( ! $order || ! $order->get_transaction_id()) { |
|
827
|
827
|
return false; |
|
828
|
828
|
} |
|
829
|
829
|
|
|
830
|
830
|
$body = array(); |
|
831
|
831
|
|
|
832
|
|
- if ( ! is_null( $amount ) ) { |
|
833
|
|
- $body['amount'] = $this->get_stripe_amount( $amount ); |
|
|
832
|
+ if ( ! is_null($amount)) { |
|
|
833
|
+ $body['amount'] = $this->get_stripe_amount($amount); |
|
834
|
834
|
} |
|
835
|
835
|
|
|
836
|
|
- if ( $reason ) { |
|
|
836
|
+ if ($reason) { |
|
837
|
837
|
$body['metadata'] = array( |
|
838
|
838
|
'reason' => $reason, |
|
839
|
839
|
); |
|
840
|
840
|
} |
|
841
|
841
|
|
|
842
|
|
- $this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
|
842
|
+ $this->log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
843
|
843
|
|
|
844
|
|
- $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
|
844
|
+ $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
845
|
845
|
|
|
846
|
|
- if ( is_wp_error( $response ) ) { |
|
847
|
|
- $this->log( 'Error: ' . $response->get_error_message() ); |
|
|
846
|
+ if (is_wp_error($response)) { |
|
|
847
|
+ $this->log('Error: ' . $response->get_error_message()); |
|
848
|
848
|
return $response; |
|
849
|
|
- } elseif ( ! empty( $response->id ) ) { |
|
850
|
|
- $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
851
|
|
- $order->add_order_note( $refund_message ); |
|
852
|
|
- $this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
|
849
|
+ } elseif ( ! empty($response->id)) { |
|
|
850
|
+ $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
|
851
|
+ $order->add_order_note($refund_message); |
|
|
852
|
+ $this->log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
853
|
853
|
return true; |
|
854
|
854
|
} |
|
855
|
855
|
} |
|
@@ -862,10 +862,10 @@ discard block |
|
|
block discarded – undo |
|
862
|
862
|
* @param int $order_id |
|
863
|
863
|
* @return null |
|
864
|
864
|
*/ |
|
865
|
|
- public function send_failed_order_email( $order_id ) { |
|
|
865
|
+ public function send_failed_order_email($order_id) { |
|
866
|
866
|
$emails = WC()->mailer()->get_emails(); |
|
867
|
|
- if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
868
|
|
- $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
|
867
|
+ if ( ! empty($emails) && ! empty($order_id)) { |
|
|
868
|
+ $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
869
|
869
|
} |
|
870
|
870
|
} |
|
871
|
871
|
|
|
@@ -877,9 +877,9 @@ discard block |
|
|
block discarded – undo |
|
877
|
877
|
* |
|
878
|
878
|
* @param string $message |
|
879
|
879
|
*/ |
|
880
|
|
- public function log( $message ) { |
|
881
|
|
- if ( $this->logging ) { |
|
882
|
|
- WC_Stripe::log( $message ); |
|
|
880
|
+ public function log($message) { |
|
|
881
|
+ if ($this->logging) { |
|
|
882
|
+ WC_Stripe::log($message); |
|
883
|
883
|
} |
|
884
|
884
|
} |
|
885
|
885
|
} |