|
@@ -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
|
|
|
@@ -85,8 +85,8 @@ discard block |
|
|
block discarded – undo |
|
85
|
85
|
*/ |
|
86
|
86
|
public function __construct() { |
|
87
|
87
|
$this->id = 'stripe'; |
|
88
|
|
- $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
89
|
|
- $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' ); |
|
|
88
|
+ $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
|
89
|
+ $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'); |
|
90
|
90
|
$this->has_fields = true; |
|
91
|
91
|
$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
|
92
|
92
|
$this->supports = array( |
|
@@ -114,35 +114,35 @@ discard block |
|
|
block discarded – undo |
|
114
|
114
|
$this->init_settings(); |
|
115
|
115
|
|
|
116
|
116
|
// Get setting values. |
|
117
|
|
- $this->title = $this->get_option( 'title' ); |
|
118
|
|
- $this->description = $this->get_option( 'description' ); |
|
119
|
|
- $this->enabled = $this->get_option( 'enabled' ); |
|
120
|
|
- $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
121
|
|
- $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
122
|
|
- $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
123
|
|
- $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
124
|
|
- $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
125
|
|
- $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
126
|
|
- $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
127
|
|
- $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
128
|
|
- $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
129
|
|
- $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
|
117
|
+ $this->title = $this->get_option('title'); |
|
|
118
|
+ $this->description = $this->get_option('description'); |
|
|
119
|
+ $this->enabled = $this->get_option('enabled'); |
|
|
120
|
+ $this->testmode = 'yes' === $this->get_option('testmode'); |
|
|
121
|
+ $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
|
122
|
+ $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
|
123
|
+ $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
|
124
|
+ $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
|
125
|
+ $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
|
126
|
+ $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
|
127
|
+ $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
|
128
|
+ $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
|
129
|
+ $this->logging = 'yes' === $this->get_option('logging'); |
|
130
|
130
|
|
|
131
|
|
- if ( $this->stripe_checkout ) { |
|
132
|
|
- $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
|
131
|
+ if ($this->stripe_checkout) { |
|
|
132
|
+ $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
133
|
133
|
} |
|
134
|
134
|
|
|
135
|
|
- if ( $this->testmode ) { |
|
136
|
|
- $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' ); |
|
137
|
|
- $this->description = trim( $this->description ); |
|
|
135
|
+ if ($this->testmode) { |
|
|
136
|
+ $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'); |
|
|
137
|
+ $this->description = trim($this->description); |
|
138
|
138
|
} |
|
139
|
139
|
|
|
140
|
|
- WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
|
140
|
+ WC_Stripe_API::set_secret_key($this->secret_key); |
|
141
|
141
|
|
|
142
|
142
|
// Hooks. |
|
143
|
|
- add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
144
|
|
- add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
145
|
|
- add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
|
143
|
+ add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
|
144
|
+ add_action('admin_notices', array($this, 'admin_notices')); |
|
|
145
|
+ add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
146
|
146
|
} |
|
147
|
147
|
|
|
148
|
148
|
/** |
|
@@ -152,24 +152,24 @@ discard block |
|
|
block discarded – undo |
|
152
|
152
|
* @return string |
|
153
|
153
|
*/ |
|
154
|
154
|
public function get_icon() { |
|
155
|
|
- $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
156
|
|
- $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
|
155
|
+ $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
|
156
|
+ $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
157
|
157
|
|
|
158
|
|
- $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
159
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
160
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
|
158
|
+ $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
|
159
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
|
160
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
161
|
161
|
|
|
162
|
|
- if ( 'USD' === get_woocommerce_currency() ) { |
|
163
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
164
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
165
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
|
162
|
+ if ('USD' === get_woocommerce_currency()) { |
|
|
163
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
|
164
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
|
165
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
166
|
166
|
} |
|
167
|
167
|
|
|
168
|
|
- if ( 'yes' === $this->bitcoin && 'yes' === $this->stripe_checkout ) { |
|
169
|
|
- $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
|
168
|
+ if ('yes' === $this->bitcoin && 'yes' === $this->stripe_checkout) { |
|
|
169
|
+ $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
170
|
170
|
} |
|
171
|
171
|
|
|
172
|
|
- return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
|
172
|
+ return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
173
|
173
|
} |
|
174
|
174
|
|
|
175
|
175
|
/** |
|
@@ -180,11 +180,11 @@ discard block |
|
|
block discarded – undo |
|
180
|
180
|
* |
|
181
|
181
|
* @return float|int |
|
182
|
182
|
*/ |
|
183
|
|
- public function get_stripe_amount( $total, $currency = '' ) { |
|
184
|
|
- if ( ! $currency ) { |
|
|
183
|
+ public function get_stripe_amount($total, $currency = '') { |
|
|
184
|
+ if ( ! $currency) { |
|
185
|
185
|
$currency = get_woocommerce_currency(); |
|
186
|
186
|
} |
|
187
|
|
- switch ( strtoupper( $currency ) ) { |
|
|
187
|
+ switch (strtoupper($currency)) { |
|
188
|
188
|
// Zero decimal currencies. |
|
189
|
189
|
case 'BIF' : |
|
190
|
190
|
case 'CLP' : |
|
@@ -201,10 +201,10 @@ discard block |
|
|
block discarded – undo |
|
201
|
201
|
case 'XAF' : |
|
202
|
202
|
case 'XOF' : |
|
203
|
203
|
case 'XPF' : |
|
204
|
|
- $total = absint( $total ); |
|
|
204
|
+ $total = absint($total); |
|
205
|
205
|
break; |
|
206
|
206
|
default : |
|
207
|
|
- $total = round( $total, 2 ) * 100; // In cents. |
|
|
207
|
+ $total = round($total, 2) * 100; // In cents. |
|
208
|
208
|
break; |
|
209
|
209
|
} |
|
210
|
210
|
return $total; |
|
@@ -214,13 +214,13 @@ discard block |
|
|
block discarded – undo |
|
214
|
214
|
* Check if SSL is enabled and notify the user |
|
215
|
215
|
*/ |
|
216
|
216
|
public function admin_notices() { |
|
217
|
|
- if ( 'no' === $this->enabled ) { |
|
|
217
|
+ if ('no' === $this->enabled) { |
|
218
|
218
|
return; |
|
219
|
219
|
} |
|
220
|
220
|
|
|
221
|
221
|
// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
|
222
|
|
- if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
223
|
|
- 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>'; |
|
|
222
|
+ if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
|
223
|
+ 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>'; |
|
224
|
224
|
} |
|
225
|
225
|
} |
|
226
|
226
|
|
|
@@ -228,11 +228,11 @@ discard block |
|
|
block discarded – undo |
|
228
|
228
|
* Check if this gateway is enabled |
|
229
|
229
|
*/ |
|
230
|
230
|
public function is_available() { |
|
231
|
|
- if ( 'yes' === $this->enabled ) { |
|
232
|
|
- if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
|
231
|
+ if ('yes' === $this->enabled) { |
|
|
232
|
+ if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
233
|
233
|
return false; |
|
234
|
234
|
} |
|
235
|
|
- if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
|
235
|
+ if ( ! $this->secret_key || ! $this->publishable_key) { |
|
236
|
236
|
return false; |
|
237
|
237
|
} |
|
238
|
238
|
return true; |
|
@@ -244,9 +244,9 @@ discard block |
|
|
block discarded – undo |
|
244
|
244
|
* Initialise Gateway Settings Form Fields |
|
245
|
245
|
*/ |
|
246
|
246
|
public function init_form_fields() { |
|
247
|
|
- $this->form_fields = include( 'settings-stripe.php' ); |
|
|
247
|
+ $this->form_fields = include('settings-stripe.php'); |
|
248
|
248
|
|
|
249
|
|
- wc_enqueue_js( " |
|
|
249
|
+ wc_enqueue_js(" |
|
250
|
250
|
jQuery( function( $ ) { |
|
251
|
251
|
$( '#woocommerce_stripe_stripe_checkout' ).change(function(){ |
|
252
|
252
|
if ( $( this ).is( ':checked' ) ) { |
|
@@ -260,7 +260,7 @@ discard block |
|
|
block discarded – undo |
|
260
|
260
|
var value = $( this ).val(); |
|
261
|
261
|
|
|
262
|
262
|
if ( value.indexOf( '_test_' ) >= 0 ) { |
|
263
|
|
- $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ) . "</span>' ); |
|
|
263
|
+ $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe') . "</span>' ); |
|
264
|
264
|
} else { |
|
265
|
265
|
$( this ).css( 'border-color', '' ); |
|
266
|
266
|
$( '.stripe-error-description', $( this ).parent() ).remove(); |
|
@@ -271,7 +271,7 @@ discard block |
|
|
block discarded – undo |
|
271
|
271
|
var value = $( this ).val(); |
|
272
|
272
|
|
|
273
|
273
|
if ( value.indexOf( '_live_' ) >= 0 ) { |
|
274
|
|
- $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ) . "</span>' ); |
|
|
274
|
+ $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe') . "</span>' ); |
|
275
|
275
|
} else { |
|
276
|
276
|
$( this ).css( 'border-color', '' ); |
|
277
|
277
|
$( '.stripe-error-description', $( this ).parent() ).remove(); |
|
@@ -286,46 +286,46 @@ discard block |
|
|
block discarded – undo |
|
286
|
286
|
*/ |
|
287
|
287
|
public function payment_fields() { |
|
288
|
288
|
$user = wp_get_current_user(); |
|
289
|
|
- $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
|
289
|
+ $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
290
|
290
|
|
|
291
|
|
- if ( $user->ID ) { |
|
292
|
|
- $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
|
291
|
+ if ($user->ID) { |
|
|
292
|
+ $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
293
|
293
|
$user_email = $user_email ? $user_email : $user->user_email; |
|
294
|
294
|
} else { |
|
295
|
295
|
$user_email = ''; |
|
296
|
296
|
} |
|
297
|
297
|
|
|
298
|
|
- if ( is_add_payment_method_page() ) { |
|
299
|
|
- $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
|
298
|
+ if (is_add_payment_method_page()) { |
|
|
299
|
+ $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
300
|
300
|
} else { |
|
301
|
301
|
$pay_button_text = ''; |
|
302
|
302
|
} |
|
303
|
303
|
|
|
304
|
304
|
echo '<div |
|
305
|
305
|
id="stripe-payment-data" |
|
306
|
|
- data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
|
306
|
+ data-panel-label="' . esc_attr($pay_button_text) . '" |
|
307
|
307
|
data-description="" |
|
308
|
|
- data-email="' . esc_attr( $user_email ) . '" |
|
309
|
|
- data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '" |
|
310
|
|
- data-name="' . esc_attr( sprintf( __( '%s', 'woocommerce-gateway-stripe' ), get_bloginfo( 'name', 'display' ) ) ) . '" |
|
311
|
|
- data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
312
|
|
- data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
313
|
|
- data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
314
|
|
- data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">'; |
|
|
308
|
+ data-email="' . esc_attr($user_email) . '" |
|
|
309
|
+ data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '" |
|
|
310
|
+ data-name="' . esc_attr(sprintf(__('%s', 'woocommerce-gateway-stripe'), get_bloginfo('name', 'display'))) . '" |
|
|
311
|
+ data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
|
312
|
+ data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
|
313
|
+ data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
|
314
|
+ data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">'; |
|
315
|
315
|
|
|
316
|
|
- if ( $this->description ) { |
|
317
|
|
- echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
|
316
|
+ if ($this->description) { |
|
|
317
|
+ echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
318
|
318
|
} |
|
319
|
319
|
|
|
320
|
|
- if ( $display_tokenization ) { |
|
|
320
|
+ if ($display_tokenization) { |
|
321
|
321
|
$this->tokenization_script(); |
|
322
|
322
|
$this->saved_payment_methods(); |
|
323
|
323
|
} |
|
324
|
324
|
|
|
325
|
|
- if ( ! $this->stripe_checkout ) { |
|
|
325
|
+ if ( ! $this->stripe_checkout) { |
|
326
|
326
|
$this->form(); |
|
327
|
327
|
|
|
328
|
|
- if ( $display_tokenization ) { |
|
|
328
|
+ if ($display_tokenization) { |
|
329
|
329
|
$this->save_payment_method_checkbox(); |
|
330
|
330
|
} |
|
331
|
331
|
} |
|
@@ -341,20 +341,20 @@ discard block |
|
|
block discarded – undo |
|
341
|
341
|
* @return array |
|
342
|
342
|
*/ |
|
343
|
343
|
public function get_localized_messages() { |
|
344
|
|
- return apply_filters( 'wc_stripe_localized_messages', array( |
|
345
|
|
- 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
346
|
|
- 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
347
|
|
- 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
348
|
|
- 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
349
|
|
- 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
350
|
|
- 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
351
|
|
- 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
352
|
|
- 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
353
|
|
- 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
354
|
|
- 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
355
|
|
- 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
356
|
|
- 'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ), |
|
357
|
|
- ) ); |
|
|
344
|
+ return apply_filters('wc_stripe_localized_messages', array( |
|
|
345
|
+ 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
|
346
|
+ 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
|
347
|
+ 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
|
348
|
+ 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
|
349
|
+ 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
|
350
|
+ 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
|
351
|
+ 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
|
352
|
+ 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
|
353
|
+ 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
|
354
|
+ 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
|
355
|
+ 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
|
356
|
+ 'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'), |
|
|
357
|
+ )); |
|
358
|
358
|
} |
|
359
|
359
|
|
|
360
|
360
|
/** |
|
@@ -365,29 +365,29 @@ discard block |
|
|
block discarded – undo |
|
365
|
365
|
* @access public |
|
366
|
366
|
*/ |
|
367
|
367
|
public function payment_scripts() { |
|
368
|
|
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
|
368
|
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
369
|
369
|
|
|
370
|
|
- if ( $this->stripe_checkout ) { |
|
371
|
|
- wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
372
|
|
- wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
|
370
|
+ if ($this->stripe_checkout) { |
|
|
371
|
+ wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
|
372
|
+ wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
373
|
373
|
} else { |
|
374
|
|
- wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
375
|
|
- wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
|
374
|
+ wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
|
375
|
+ wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
376
|
376
|
} |
|
377
|
377
|
|
|
378
|
378
|
$stripe_params = array( |
|
379
|
379
|
'key' => $this->publishable_key, |
|
380
|
|
- 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
381
|
|
- 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
|
380
|
+ 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
|
381
|
+ 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
382
|
382
|
); |
|
383
|
383
|
|
|
384
|
384
|
// If we're on the pay page we need to pass stripe.js the address of the order. |
|
385
|
|
- if ( is_checkout_pay_page() && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) { |
|
386
|
|
- $order_key = urldecode( $_GET['order'] ); |
|
387
|
|
- $order_id = absint( $_GET['order_id'] ); |
|
388
|
|
- $order = wc_get_order( $order_id ); |
|
|
385
|
+ if (is_checkout_pay_page() && isset($_GET['order']) && isset($_GET['order_id'])) { |
|
|
386
|
+ $order_key = urldecode($_GET['order']); |
|
|
387
|
+ $order_id = absint($_GET['order_id']); |
|
|
388
|
+ $order = wc_get_order($order_id); |
|
389
|
389
|
|
|
390
|
|
- if ( $order->id === $order_id && $order->order_key === $order_key ) { |
|
|
390
|
+ if ($order->id === $order_id && $order->order_key === $order_key) { |
|
391
|
391
|
$stripe_params['billing_first_name'] = $order->billing_first_name; |
|
392
|
392
|
$stripe_params['billing_last_name'] = $order->billing_last_name; |
|
393
|
393
|
$stripe_params['billing_address_1'] = $order->billing_address_1; |
|
@@ -399,14 +399,14 @@ discard block |
|
|
block discarded – undo |
|
399
|
399
|
} |
|
400
|
400
|
} |
|
401
|
401
|
|
|
402
|
|
- $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ); |
|
403
|
|
- $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
404
|
|
- $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
|
402
|
+ $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'); |
|
|
403
|
+ $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
|
404
|
+ $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
405
|
405
|
|
|
406
|
406
|
// merge localized messages to be use in JS |
|
407
|
|
- $stripe_params = array_merge( $stripe_params, $this->get_localized_messages() ); |
|
|
407
|
+ $stripe_params = array_merge($stripe_params, $this->get_localized_messages()); |
|
408
|
408
|
|
|
409
|
|
- wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
|
409
|
+ wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
410
|
410
|
} |
|
411
|
411
|
|
|
412
|
412
|
/** |
|
@@ -415,24 +415,24 @@ discard block |
|
|
block discarded – undo |
|
415
|
415
|
* @param object $source |
|
416
|
416
|
* @return array() |
|
417
|
417
|
*/ |
|
418
|
|
- protected function generate_payment_request( $order, $source ) { |
|
|
418
|
+ protected function generate_payment_request($order, $source) { |
|
419
|
419
|
$post_data = array(); |
|
420
|
|
- $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
421
|
|
- $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
422
|
|
- $post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
|
420
|
+ $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
|
421
|
+ $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
|
422
|
+ $post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
423
|
423
|
$post_data['capture'] = $this->capture ? 'true' : 'false'; |
|
424
|
424
|
|
|
425
|
|
- if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
|
425
|
+ if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
426
|
426
|
$post_data['receipt_email'] = $order->billing_email; |
|
427
|
427
|
} |
|
428
|
428
|
|
|
429
|
|
- $post_data['expand[]'] = 'balance_transaction'; |
|
|
429
|
+ $post_data['expand[]'] = 'balance_transaction'; |
|
430
|
430
|
|
|
431
|
|
- if ( $source->customer ) { |
|
|
431
|
+ if ($source->customer) { |
|
432
|
432
|
$post_data['customer'] = $source->customer; |
|
433
|
433
|
} |
|
434
|
434
|
|
|
435
|
|
- if ( $source->source ) { |
|
|
435
|
+ if ($source->source) { |
|
436
|
436
|
$post_data['source'] = $source->source; |
|
437
|
437
|
} |
|
438
|
438
|
|
|
@@ -444,7 +444,7 @@ discard block |
|
|
block discarded – undo |
|
444
|
444
|
* @param WC_Order $order |
|
445
|
445
|
* @param object $source |
|
446
|
446
|
*/ |
|
447
|
|
- return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
|
447
|
+ return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
448
|
448
|
} |
|
449
|
449
|
|
|
450
|
450
|
/** |
|
@@ -456,22 +456,22 @@ discard block |
|
|
block discarded – undo |
|
456
|
456
|
* @throws Exception When card was not added or for and invalid card. |
|
457
|
457
|
* @return object |
|
458
|
458
|
*/ |
|
459
|
|
- protected function get_source( $user_id, $force_customer = false ) { |
|
460
|
|
- $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
|
459
|
+ protected function get_source($user_id, $force_customer = false) { |
|
|
460
|
+ $stripe_customer = new WC_Stripe_Customer($user_id); |
|
461
|
461
|
$stripe_source = false; |
|
462
|
462
|
$token_id = false; |
|
463
|
463
|
|
|
464
|
464
|
// New CC info was entered and we have a new token to process |
|
465
|
|
- if ( isset( $_POST['stripe_token'] ) ) { |
|
466
|
|
- $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
467
|
|
- $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
|
465
|
+ if (isset($_POST['stripe_token'])) { |
|
|
466
|
+ $stripe_token = wc_clean($_POST['stripe_token']); |
|
|
467
|
+ $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
468
|
468
|
|
|
469
|
469
|
// This is true if the user wants to store the card to their account. |
|
470
|
|
- if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
471
|
|
- $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
|
470
|
+ if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
|
471
|
+ $stripe_source = $stripe_customer->add_card($stripe_token); |
|
472
|
472
|
|
|
473
|
|
- if ( is_wp_error( $stripe_source ) ) { |
|
474
|
|
- throw new Exception( $stripe_source->get_error_message() ); |
|
|
473
|
+ if (is_wp_error($stripe_source)) { |
|
|
474
|
+ throw new Exception($stripe_source->get_error_message()); |
|
475
|
475
|
} |
|
476
|
476
|
|
|
477
|
477
|
} else { |
|
@@ -482,13 +482,13 @@ discard block |
|
|
block discarded – undo |
|
482
|
482
|
} |
|
483
|
483
|
|
|
484
|
484
|
// Use an existing token, and then process the payment |
|
485
|
|
- elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
486
|
|
- $token_id = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
487
|
|
- $token = WC_Payment_Tokens::get( $token_id ); |
|
|
485
|
+ elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
|
486
|
+ $token_id = wc_clean($_POST['wc-stripe-payment-token']); |
|
|
487
|
+ $token = WC_Payment_Tokens::get($token_id); |
|
488
|
488
|
|
|
489
|
|
- if ( ! $token || $token->get_user_id() !== get_current_user_id() ) { |
|
490
|
|
- WC()->session->set( 'refresh_totals', true ); |
|
491
|
|
- throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
|
489
|
+ if ( ! $token || $token->get_user_id() !== get_current_user_id()) { |
|
|
490
|
+ WC()->session->set('refresh_totals', true); |
|
|
491
|
+ throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
492
|
492
|
} |
|
493
|
493
|
|
|
494
|
494
|
$stripe_source = $token->get_token(); |
|
@@ -512,16 +512,16 @@ discard block |
|
|
block discarded – undo |
|
512
|
512
|
* @param object $order |
|
513
|
513
|
* @return object |
|
514
|
514
|
*/ |
|
515
|
|
- protected function get_order_source( $order = null ) { |
|
|
515
|
+ protected function get_order_source($order = null) { |
|
516
|
516
|
$stripe_customer = new WC_Stripe_Customer(); |
|
517
|
517
|
$stripe_source = false; |
|
518
|
518
|
$token_id = false; |
|
519
|
519
|
|
|
520
|
|
- if ( $order ) { |
|
521
|
|
- if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) { |
|
522
|
|
- $stripe_customer->set_id( $meta_value ); |
|
|
520
|
+ if ($order) { |
|
|
521
|
+ if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) { |
|
|
522
|
+ $stripe_customer->set_id($meta_value); |
|
523
|
523
|
} |
|
524
|
|
- if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) { |
|
|
524
|
+ if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) { |
|
525
|
525
|
$stripe_source = $meta_value; |
|
526
|
526
|
} |
|
527
|
527
|
} |
|
@@ -544,50 +544,50 @@ discard block |
|
|
block discarded – undo |
|
544
|
544
|
* |
|
545
|
545
|
* @return array|void |
|
546
|
546
|
*/ |
|
547
|
|
- public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
|
547
|
+ public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
548
|
548
|
try { |
|
549
|
|
- $order = wc_get_order( $order_id ); |
|
550
|
|
- $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
|
549
|
+ $order = wc_get_order($order_id); |
|
|
550
|
+ $source = $this->get_source(get_current_user_id(), $force_customer); |
|
551
|
551
|
|
|
552
|
|
- if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
553
|
|
- $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
554
|
|
- $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
555
|
|
- throw new Exception( $error_msg ); |
|
|
552
|
+ if (empty($source->source) && empty($source->customer)) { |
|
|
553
|
+ $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
|
554
|
+ $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
|
555
|
+ throw new Exception($error_msg); |
|
556
|
556
|
} |
|
557
|
557
|
|
|
558
|
558
|
// Store source to order meta. |
|
559
|
|
- $this->save_source( $order, $source ); |
|
|
559
|
+ $this->save_source($order, $source); |
|
560
|
560
|
|
|
561
|
561
|
// Handle payment. |
|
562
|
|
- if ( $order->get_total() > 0 ) { |
|
|
562
|
+ if ($order->get_total() > 0) { |
|
563
|
563
|
|
|
564
|
|
- if ( $order->get_total() * 100 < 50 ) { |
|
565
|
|
- throw new Exception( __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe' ) ); |
|
|
564
|
+ if ($order->get_total() * 100 < 50) { |
|
|
565
|
+ throw new Exception(__('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe')); |
|
566
|
566
|
} |
|
567
|
567
|
|
|
568
|
|
- WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
|
568
|
+ WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
569
|
569
|
|
|
570
|
570
|
// Make the request. |
|
571
|
|
- $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
|
571
|
+ $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
572
|
572
|
|
|
573
|
|
- if ( is_wp_error( $response ) ) { |
|
|
573
|
+ if (is_wp_error($response)) { |
|
574
|
574
|
// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
575
|
|
- if ( 'customer' === $response->get_error_code() && $retry ) { |
|
576
|
|
- delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
577
|
|
- return $this->process_payment( $order_id, false, $force_customer ); |
|
|
575
|
+ if ('customer' === $response->get_error_code() && $retry) { |
|
|
576
|
+ delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
|
577
|
+ return $this->process_payment($order_id, false, $force_customer); |
|
578
|
578
|
// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
579
|
|
- } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
580
|
|
- $token = WC_Payment_Tokens::get( $source->token_id ); |
|
|
579
|
+ } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
|
580
|
+ $token = WC_Payment_Tokens::get($source->token_id); |
|
581
|
581
|
$token->delete(); |
|
582
|
|
- throw new Exception( __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ) ); |
|
|
582
|
+ throw new Exception(__('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe')); |
|
583
|
583
|
} |
|
584
|
584
|
$localized_messages = $this->get_localized_messages(); |
|
585
|
585
|
|
|
586
|
|
- throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
|
586
|
+ throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
587
|
587
|
} |
|
588
|
588
|
|
|
589
|
589
|
// Process valid response. |
|
590
|
|
- $this->process_response( $response, $order ); |
|
|
590
|
+ $this->process_response($response, $order); |
|
591
|
591
|
} else { |
|
592
|
592
|
$order->payment_complete(); |
|
593
|
593
|
} |
|
@@ -598,16 +598,16 @@ discard block |
|
|
block discarded – undo |
|
598
|
598
|
// Return thank you page redirect. |
|
599
|
599
|
return array( |
|
600
|
600
|
'result' => 'success', |
|
601
|
|
- 'redirect' => $this->get_return_url( $order ) |
|
|
601
|
+ 'redirect' => $this->get_return_url($order) |
|
602
|
602
|
); |
|
603
|
603
|
|
|
604
|
|
- } catch ( Exception $e ) { |
|
605
|
|
- wc_add_notice( $e->getMessage(), 'error' ); |
|
606
|
|
- WC()->session->set( 'refresh_totals', true ); |
|
607
|
|
- WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
|
604
|
+ } catch (Exception $e) { |
|
|
605
|
+ wc_add_notice($e->getMessage(), 'error'); |
|
|
606
|
+ WC()->session->set('refresh_totals', true); |
|
|
607
|
+ WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
608
|
608
|
|
|
609
|
|
- if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
610
|
|
- $this->send_failed_order_email( $order_id ); |
|
|
609
|
+ if ($order->has_status(array('pending', 'failed'))) { |
|
|
610
|
+ $this->send_failed_order_email($order_id); |
|
611
|
611
|
} |
|
612
|
612
|
|
|
613
|
613
|
return; |
|
@@ -620,49 +620,49 @@ discard block |
|
|
block discarded – undo |
|
620
|
620
|
* @param WC_Order $order For to which the source applies. |
|
621
|
621
|
* @param stdClass $source Source information. |
|
622
|
622
|
*/ |
|
623
|
|
- protected function save_source( $order, $source ) { |
|
|
623
|
+ protected function save_source($order, $source) { |
|
624
|
624
|
// Store source in the order. |
|
625
|
|
- if ( $source->customer ) { |
|
626
|
|
- update_post_meta( $order->id, '_stripe_customer_id', $source->customer ); |
|
|
625
|
+ if ($source->customer) { |
|
|
626
|
+ update_post_meta($order->id, '_stripe_customer_id', $source->customer); |
|
627
|
627
|
} |
|
628
|
|
- if ( $source->source ) { |
|
629
|
|
- update_post_meta( $order->id, '_stripe_card_id', $source->source ); |
|
|
628
|
+ if ($source->source) { |
|
|
629
|
+ update_post_meta($order->id, '_stripe_card_id', $source->source); |
|
630
|
630
|
} |
|
631
|
631
|
} |
|
632
|
632
|
|
|
633
|
633
|
/** |
|
634
|
634
|
* Store extra meta data for an order from a Stripe Response. |
|
635
|
635
|
*/ |
|
636
|
|
- public function process_response( $response, $order ) { |
|
637
|
|
- WC_Stripe::log( "Processing response: " . print_r( $response, true ) ); |
|
|
636
|
+ public function process_response($response, $order) { |
|
|
637
|
+ WC_Stripe::log("Processing response: " . print_r($response, true)); |
|
638
|
638
|
|
|
639
|
639
|
// Store charge data |
|
640
|
|
- update_post_meta( $order->id, '_stripe_charge_id', $response->id ); |
|
641
|
|
- update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
|
640
|
+ update_post_meta($order->id, '_stripe_charge_id', $response->id); |
|
|
641
|
+ update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
642
|
642
|
|
|
643
|
643
|
// Store other data such as fees |
|
644
|
|
- if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
645
|
|
- $fee = number_format( $response->balance_transaction->fee / 100, 2, '.', '' ); |
|
646
|
|
- update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
647
|
|
- update_post_meta( $order->id, 'Net Revenue From Stripe', $order->get_total() - $fee ); |
|
|
644
|
+ if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
|
645
|
+ $fee = number_format($response->balance_transaction->fee / 100, 2, '.', ''); |
|
|
646
|
+ update_post_meta($order->id, 'Stripe Fee', $fee); |
|
|
647
|
+ update_post_meta($order->id, 'Net Revenue From Stripe', $order->get_total() - $fee); |
|
648
|
648
|
} |
|
649
|
649
|
|
|
650
|
|
- if ( $response->captured ) { |
|
651
|
|
- $order->payment_complete( $response->id ); |
|
|
650
|
+ if ($response->captured) { |
|
|
651
|
+ $order->payment_complete($response->id); |
|
652
|
652
|
|
|
653
|
|
- $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
654
|
|
- $order->add_order_note( $message ); |
|
655
|
|
- WC_Stripe::log( 'Success: ' . $message ); |
|
|
653
|
+ $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
|
654
|
+ $order->add_order_note($message); |
|
|
655
|
+ WC_Stripe::log('Success: ' . $message); |
|
656
|
656
|
|
|
657
|
657
|
} else { |
|
658
|
|
- add_post_meta( $order->id, '_transaction_id', $response->id, true ); |
|
|
658
|
+ add_post_meta($order->id, '_transaction_id', $response->id, true); |
|
659
|
659
|
|
|
660
|
|
- if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
|
660
|
+ if ($order->has_status(array('pending', 'failed'))) { |
|
661
|
661
|
$order->reduce_order_stock(); |
|
662
|
662
|
} |
|
663
|
663
|
|
|
664
|
|
- $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 ) ); |
|
665
|
|
- WC_Stripe::log( "Successful auth: $response->id" ); |
|
|
664
|
+ $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)); |
|
|
665
|
+ WC_Stripe::log("Successful auth: $response->id"); |
|
666
|
666
|
} |
|
667
|
667
|
|
|
668
|
668
|
return $response; |
|
@@ -674,32 +674,32 @@ discard block |
|
|
block discarded – undo |
|
674
|
674
|
* @since 3.0.0 |
|
675
|
675
|
*/ |
|
676
|
676
|
public function add_payment_method() { |
|
677
|
|
- if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
678
|
|
- wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
|
677
|
+ if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
|
678
|
+ wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
679
|
679
|
return; |
|
680
|
680
|
} |
|
681
|
681
|
|
|
682
|
|
- $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
683
|
|
- $card = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
|
682
|
+ $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
|
683
|
+ $card = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
684
|
684
|
|
|
685
|
|
- if ( is_wp_error( $card ) ) { |
|
|
685
|
+ if (is_wp_error($card)) { |
|
686
|
686
|
$localized_messages = $this->get_localized_messages(); |
|
687
|
|
- $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
|
687
|
+ $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
688
|
688
|
|
|
689
|
689
|
// loop through the errors to find matching localized message |
|
690
|
|
- foreach ( $card->errors as $error => $msg ) { |
|
691
|
|
- if ( isset( $localized_messages[ $error ] ) ) { |
|
692
|
|
- $error_msg = $localized_messages[ $error ]; |
|
|
690
|
+ foreach ($card->errors as $error => $msg) { |
|
|
691
|
+ if (isset($localized_messages[$error])) { |
|
|
692
|
+ $error_msg = $localized_messages[$error]; |
|
693
|
693
|
} |
|
694
|
694
|
} |
|
695
|
695
|
|
|
696
|
|
- wc_add_notice( $error_msg, 'error' ); |
|
|
696
|
+ wc_add_notice($error_msg, 'error'); |
|
697
|
697
|
return; |
|
698
|
698
|
} |
|
699
|
699
|
|
|
700
|
700
|
return array( |
|
701
|
701
|
'result' => 'success', |
|
702
|
|
- 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
|
702
|
+ 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
703
|
703
|
); |
|
704
|
704
|
} |
|
705
|
705
|
|
|
@@ -709,36 +709,36 @@ discard block |
|
|
block discarded – undo |
|
709
|
709
|
* @param float $amount |
|
710
|
710
|
* @return bool |
|
711
|
711
|
*/ |
|
712
|
|
- public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
713
|
|
- $order = wc_get_order( $order_id ); |
|
|
712
|
+ public function process_refund($order_id, $amount = null, $reason = '') { |
|
|
713
|
+ $order = wc_get_order($order_id); |
|
714
|
714
|
|
|
715
|
|
- if ( ! $order || ! $order->get_transaction_id() ) { |
|
|
715
|
+ if ( ! $order || ! $order->get_transaction_id()) { |
|
716
|
716
|
return false; |
|
717
|
717
|
} |
|
718
|
718
|
|
|
719
|
719
|
$body = array(); |
|
720
|
720
|
|
|
721
|
|
- if ( ! is_null( $amount ) ) { |
|
722
|
|
- $body['amount'] = $this->get_stripe_amount( $amount ); |
|
|
721
|
+ if ( ! is_null($amount)) { |
|
|
722
|
+ $body['amount'] = $this->get_stripe_amount($amount); |
|
723
|
723
|
} |
|
724
|
724
|
|
|
725
|
|
- if ( $reason ) { |
|
|
725
|
+ if ($reason) { |
|
726
|
726
|
$body['metadata'] = array( |
|
727
|
727
|
'reason' => $reason, |
|
728
|
728
|
); |
|
729
|
729
|
} |
|
730
|
730
|
|
|
731
|
|
- WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
|
731
|
+ WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
732
|
732
|
|
|
733
|
|
- $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
|
733
|
+ $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
734
|
734
|
|
|
735
|
|
- if ( is_wp_error( $response ) ) { |
|
736
|
|
- WC_Stripe::log( "Error: " . $response->get_error_message() ); |
|
|
735
|
+ if (is_wp_error($response)) { |
|
|
736
|
+ WC_Stripe::log("Error: " . $response->get_error_message()); |
|
737
|
737
|
return $response; |
|
738
|
|
- } elseif ( ! empty( $response->id ) ) { |
|
739
|
|
- $refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
740
|
|
- $order->add_order_note( $refund_message ); |
|
741
|
|
- WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
|
738
|
+ } elseif ( ! empty($response->id)) { |
|
|
739
|
+ $refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
|
740
|
+ $order->add_order_note($refund_message); |
|
|
741
|
+ WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message))); |
|
742
|
742
|
return true; |
|
743
|
743
|
} |
|
744
|
744
|
} |
|
@@ -751,10 +751,10 @@ discard block |
|
|
block discarded – undo |
|
751
|
751
|
* @param int $order_id |
|
752
|
752
|
* @return null |
|
753
|
753
|
*/ |
|
754
|
|
- public function send_failed_order_email( $order_id ) { |
|
|
754
|
+ public function send_failed_order_email($order_id) { |
|
755
|
755
|
$emails = WC()->mailer()->get_emails(); |
|
756
|
|
- if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
757
|
|
- $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
|
756
|
+ if ( ! empty($emails) && ! empty($order_id)) { |
|
|
757
|
+ $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
758
|
758
|
} |
|
759
|
759
|
} |
|
760
|
760
|
} |