|
@@ -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
|
|
|
@@ -15,24 +15,24 @@ discard block |
|
|
block discarded – undo |
|
15
|
15
|
public function __construct() { |
|
16
|
16
|
parent::__construct(); |
|
17
|
17
|
|
|
18
|
|
- if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19
|
|
- add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20
|
|
- add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21
|
|
- add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22
|
|
- add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
|
18
|
+ if (class_exists('WC_Subscriptions_Order')) { |
|
|
19
|
+ add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
|
20
|
+ add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
|
21
|
+ add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
|
22
|
+ add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23
|
23
|
|
|
24
|
24
|
// display the credit card used for a subscription in the "My Subscriptions" table |
|
25
|
|
- add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
|
25
|
+ add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
26
|
26
|
|
|
27
|
27
|
// allow store managers to manually set Stripe as the payment method on a subscription |
|
28
|
|
- add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
29
|
|
- add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
30
|
|
- add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
31
|
|
- add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
|
28
|
+ add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
|
29
|
+ add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
|
30
|
+ add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
|
31
|
+ add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
32
|
32
|
} |
|
33
|
33
|
|
|
34
|
|
- if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
35
|
|
- add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
|
34
|
+ if (class_exists('WC_Pre_Orders_Order')) { |
|
|
35
|
+ add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
36
|
36
|
} |
|
37
|
37
|
} |
|
38
|
38
|
|
|
@@ -43,8 +43,8 @@ discard block |
|
|
block discarded – undo |
|
43
|
43
|
* @since 4.0.0 |
|
44
|
44
|
* @version 4.0.0 |
|
45
|
45
|
*/ |
|
46
|
|
- public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
47
|
|
- if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
|
46
|
+ public function maybe_hide_save_checkbox($display_tokenization) { |
|
|
47
|
+ if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
48
|
48
|
return false; |
|
49
|
49
|
} |
|
50
|
50
|
|
|
@@ -56,8 +56,8 @@ discard block |
|
|
block discarded – undo |
|
56
|
56
|
* @param int $order_id |
|
57
|
57
|
* @return boolean |
|
58
|
58
|
*/ |
|
59
|
|
- public function has_subscription( $order_id ) { |
|
60
|
|
- return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
|
59
|
+ public function has_subscription($order_id) { |
|
|
60
|
+ return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
61
|
61
|
} |
|
62
|
62
|
|
|
63
|
63
|
/** |
|
@@ -67,7 +67,7 @@ discard block |
|
|
block discarded – undo |
|
67
|
67
|
* @return bool |
|
68
|
68
|
*/ |
|
69
|
69
|
public function is_subs_change_payment() { |
|
70
|
|
- return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
|
70
|
+ return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
71
|
71
|
} |
|
72
|
72
|
|
|
73
|
73
|
/** |
|
@@ -75,8 +75,8 @@ discard block |
|
|
block discarded – undo |
|
75
|
75
|
* @param int $order_id |
|
76
|
76
|
* @return boolean |
|
77
|
77
|
*/ |
|
78
|
|
- public function is_pre_order( $order_id ) { |
|
79
|
|
- return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
|
78
|
+ public function is_pre_order($order_id) { |
|
|
79
|
+ return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
80
|
80
|
} |
|
81
|
81
|
|
|
82
|
82
|
/** |
|
@@ -85,26 +85,26 @@ discard block |
|
|
block discarded – undo |
|
85
|
85
|
* @since 4.0.4 |
|
86
|
86
|
* @param int $order_id |
|
87
|
87
|
*/ |
|
88
|
|
- public function change_subs_payment_method( $order_id ) { |
|
|
88
|
+ public function change_subs_payment_method($order_id) { |
|
89
|
89
|
try { |
|
90
|
|
- $subscription = wc_get_order( $order_id ); |
|
|
90
|
+ $subscription = wc_get_order($order_id); |
|
91
|
91
|
$source_object = $this->get_source_object(); |
|
92
|
|
- $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), true ); |
|
|
92
|
+ $prepared_source = $this->prepare_source($source_object, get_current_user_id(), true); |
|
93
|
93
|
|
|
94
|
94
|
// Check if we don't allow prepaid credit cards. |
|
95
|
|
- if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
96
|
|
- if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
97
|
|
- $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
98
|
|
- throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
|
95
|
+ if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
|
96
|
+ if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
|
97
|
+ $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
|
98
|
+ throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
99
|
99
|
} |
|
100
|
100
|
} |
|
101
|
101
|
|
|
102
|
|
- if ( empty( $prepared_source->source ) ) { |
|
103
|
|
- $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
104
|
|
- throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
|
102
|
+ if (empty($prepared_source->source)) { |
|
|
103
|
+ $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
|
104
|
+ throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
105
|
105
|
} |
|
106
|
106
|
|
|
107
|
|
- $this->save_source_to_order( $subscription, $prepared_source ); |
|
|
107
|
+ $this->save_source_to_order($subscription, $prepared_source); |
|
108
|
108
|
|
|
109
|
109
|
/* |
|
110
|
110
|
* Check if card 3DS is required or optional with 3DS setting. |
|
@@ -113,41 +113,41 @@ discard block |
|
|
block discarded – undo |
|
113
|
113
|
* Note that if we need to save source, the original source must be first |
|
114
|
114
|
* attached to a customer in Stripe before it can be charged. |
|
115
|
115
|
*/ |
|
116
|
|
- if ( $this->is_3ds_required( $source_object ) ) { |
|
|
116
|
+ if ($this->is_3ds_required($source_object)) { |
|
117
|
117
|
$order = $subscription->get_parent(); |
|
118
|
|
- $response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() ); |
|
|
118
|
+ $response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url()); |
|
119
|
119
|
|
|
120
|
|
- if ( ! empty( $response->error ) ) { |
|
|
120
|
+ if ( ! empty($response->error)) { |
|
121
|
121
|
$localized_message = $response->error->message; |
|
122
|
122
|
|
|
123
|
|
- $order->add_order_note( $localized_message ); |
|
|
123
|
+ $order->add_order_note($localized_message); |
|
124
|
124
|
|
|
125
|
|
- throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
|
125
|
+ throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
126
|
126
|
} |
|
127
|
127
|
|
|
128
|
128
|
// Update order meta with 3DS source. |
|
129
|
|
- if ( WC_Stripe_Helper::is_pre_30() ) { |
|
130
|
|
- update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
|
129
|
+ if (WC_Stripe_Helper::is_pre_30()) { |
|
|
130
|
+ update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
131
|
131
|
} else { |
|
132
|
|
- $subscription->update_meta_data( '_stripe_source_id', $response->id ); |
|
|
132
|
+ $subscription->update_meta_data('_stripe_source_id', $response->id); |
|
133
|
133
|
$subscription->save(); |
|
134
|
134
|
} |
|
135
|
135
|
|
|
136
|
|
- WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
|
136
|
+ WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
137
|
137
|
|
|
138
|
138
|
return array( |
|
139
|
139
|
'result' => 'success', |
|
140
|
|
- 'redirect' => esc_url_raw( $response->redirect->url ), |
|
|
140
|
+ 'redirect' => esc_url_raw($response->redirect->url), |
|
141
|
141
|
); |
|
142
|
142
|
} |
|
143
|
143
|
|
|
144
|
144
|
return array( |
|
145
|
145
|
'result' => 'success', |
|
146
|
|
- 'redirect' => $this->get_return_url( $subscription ), |
|
|
146
|
+ 'redirect' => $this->get_return_url($subscription), |
|
147
|
147
|
); |
|
148
|
|
- } catch ( WC_Stripe_Exception $e ) { |
|
149
|
|
- wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
150
|
|
- WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
|
148
|
+ } catch (WC_Stripe_Exception $e) { |
|
|
149
|
+ wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
|
150
|
+ WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
151
|
151
|
} |
|
152
|
152
|
} |
|
153
|
153
|
|
|
@@ -156,18 +156,18 @@ discard block |
|
|
block discarded – undo |
|
156
|
156
|
* @param int $order_id |
|
157
|
157
|
* @return array |
|
158
|
158
|
*/ |
|
159
|
|
- public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
160
|
|
- if ( $this->has_subscription( $order_id ) ) { |
|
161
|
|
- if ( $this->is_subs_change_payment() ) { |
|
162
|
|
- return $this->change_subs_payment_method( $order_id ); |
|
|
159
|
+ public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
|
160
|
+ if ($this->has_subscription($order_id)) { |
|
|
161
|
+ if ($this->is_subs_change_payment()) { |
|
|
162
|
+ return $this->change_subs_payment_method($order_id); |
|
163
|
163
|
} |
|
164
|
164
|
|
|
165
|
165
|
// Regular payment with force customer enabled |
|
166
|
|
- return parent::process_payment( $order_id, true, true ); |
|
167
|
|
- } elseif ( $this->is_pre_order( $order_id ) ) { |
|
168
|
|
- return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
|
166
|
+ return parent::process_payment($order_id, true, true); |
|
|
167
|
+ } elseif ($this->is_pre_order($order_id)) { |
|
|
168
|
+ return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
169
|
169
|
} else { |
|
170
|
|
- return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
|
170
|
+ return parent::process_payment($order_id, $retry, $force_save_source); |
|
171
|
171
|
} |
|
172
|
172
|
} |
|
173
|
173
|
|
|
@@ -178,14 +178,14 @@ discard block |
|
|
block discarded – undo |
|
178
|
178
|
* @param array $metadata |
|
179
|
179
|
* @param object $order |
|
180
|
180
|
*/ |
|
181
|
|
- public function add_subscription_meta_data( $metadata, $order ) { |
|
182
|
|
- if ( ! $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
|
181
|
+ public function add_subscription_meta_data($metadata, $order) { |
|
|
182
|
+ if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
183
|
183
|
return $metadata; |
|
184
|
184
|
} |
|
185
|
185
|
|
|
186
|
186
|
return $metadata += array( |
|
187
|
187
|
'payment_type' => 'recurring', |
|
188
|
|
- 'site_url' => esc_url( get_site_url() ), |
|
|
188
|
+ 'site_url' => esc_url(get_site_url()), |
|
189
|
189
|
); |
|
190
|
190
|
} |
|
191
|
191
|
|
|
@@ -195,24 +195,24 @@ discard block |
|
|
block discarded – undo |
|
195
|
195
|
* @since 3.1.0 |
|
196
|
196
|
* @version 4.0.0 |
|
197
|
197
|
*/ |
|
198
|
|
- public function save_source_to_order( $order, $source ) { |
|
199
|
|
- parent::save_source_to_order( $order, $source ); |
|
|
198
|
+ public function save_source_to_order($order, $source) { |
|
|
199
|
+ parent::save_source_to_order($order, $source); |
|
200
|
200
|
|
|
201
|
201
|
$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
202
|
202
|
|
|
203
|
203
|
// Also store it on the subscriptions being purchased or paid for in the order |
|
204
|
|
- if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
205
|
|
- $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
206
|
|
- } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
207
|
|
- $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
|
204
|
+ if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
|
205
|
+ $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
|
206
|
+ } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
|
207
|
+ $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
208
|
208
|
} else { |
|
209
|
209
|
$subscriptions = array(); |
|
210
|
210
|
} |
|
211
|
211
|
|
|
212
|
|
- foreach ( $subscriptions as $subscription ) { |
|
|
212
|
+ foreach ($subscriptions as $subscription) { |
|
213
|
213
|
$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
|
214
|
|
- update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
215
|
|
- update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
|
214
|
+ update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
|
215
|
+ update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
216
|
216
|
} |
|
217
|
217
|
} |
|
218
|
218
|
|
|
@@ -225,45 +225,45 @@ discard block |
|
|
block discarded – undo |
|
225
|
225
|
* @param mixed $renewal_order |
|
226
|
226
|
* @param bool $is_retry Is this a retry process. |
|
227
|
227
|
*/ |
|
228
|
|
- public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
229
|
|
- if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
|
228
|
+ public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) { |
|
|
229
|
+ if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
230
|
230
|
/* translators: minimum amount */ |
|
231
|
|
- return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
|
231
|
+ return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
232
|
232
|
} |
|
233
|
233
|
|
|
234
|
234
|
$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
|
235
|
235
|
|
|
236
|
236
|
// Get source from order |
|
237
|
|
- $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
|
237
|
+ $prepared_source = $this->prepare_order_source($renewal_order); |
|
238
|
238
|
|
|
239
|
|
- if ( ! $prepared_source->customer ) { |
|
240
|
|
- return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
|
239
|
+ if ( ! $prepared_source->customer) { |
|
|
240
|
+ return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
241
|
241
|
} |
|
242
|
242
|
|
|
243
|
|
- WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
|
243
|
+ WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
244
|
244
|
|
|
245
|
|
- if ( $is_retry ) { |
|
|
245
|
+ if ($is_retry) { |
|
246
|
246
|
// Passing empty source with charge customer default. |
|
247
|
247
|
$prepared_source->source = ''; |
|
248
|
248
|
} |
|
249
|
249
|
|
|
250
|
|
- $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
|
250
|
+ $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
251
|
251
|
$request['capture'] = 'true'; |
|
252
|
|
- $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
253
|
|
- $response = WC_Stripe_API::request( $request ); |
|
|
252
|
+ $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
|
253
|
+ $response = WC_Stripe_API::request($request); |
|
254
|
254
|
|
|
255
|
|
- if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
256
|
|
- if ( $is_retry ) { |
|
|
255
|
+ if ( ! empty($response->error) || is_wp_error($response)) { |
|
|
256
|
+ if ($is_retry) { |
|
257
|
257
|
/* translators: error message */ |
|
258
|
|
- $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
|
258
|
+ $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
259
|
259
|
} |
|
260
|
260
|
|
|
261
|
261
|
return $response; // Default catch all errors. |
|
262
|
262
|
} |
|
263
|
263
|
|
|
264
|
|
- $this->process_response( $response, $renewal_order ); |
|
|
264
|
+ $this->process_response($response, $renewal_order); |
|
265
|
265
|
|
|
266
|
|
- if ( ! $is_retry ) { |
|
|
266
|
+ if ( ! $is_retry) { |
|
267
|
267
|
return $response; |
|
268
|
268
|
} |
|
269
|
269
|
} |
|
@@ -272,21 +272,21 @@ discard block |
|
|
block discarded – undo |
|
272
|
272
|
* Don't transfer Stripe customer/token meta to resubscribe orders. |
|
273
|
273
|
* @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
274
|
274
|
*/ |
|
275
|
|
- public function delete_resubscribe_meta( $resubscribe_order ) { |
|
276
|
|
- delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
277
|
|
- delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
|
275
|
+ public function delete_resubscribe_meta($resubscribe_order) { |
|
|
276
|
+ delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
|
277
|
+ delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
278
|
278
|
// For BW compat will remove in future |
|
279
|
|
- delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
280
|
|
- $this->delete_renewal_meta( $resubscribe_order ); |
|
|
279
|
+ delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
|
280
|
+ $this->delete_renewal_meta($resubscribe_order); |
|
281
|
281
|
} |
|
282
|
282
|
|
|
283
|
283
|
/** |
|
284
|
284
|
* Don't transfer Stripe fee/ID meta to renewal orders. |
|
285
|
285
|
* @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
286
|
286
|
*/ |
|
287
|
|
- public function delete_renewal_meta( $renewal_order ) { |
|
288
|
|
- delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
289
|
|
- delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
|
287
|
+ public function delete_renewal_meta($renewal_order) { |
|
|
288
|
+ delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
|
289
|
+ delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
290
|
290
|
return $renewal_order; |
|
291
|
291
|
} |
|
292
|
292
|
|
|
@@ -296,21 +296,21 @@ discard block |
|
|
block discarded – undo |
|
296
|
296
|
* @param $amount_to_charge float The amount to charge. |
|
297
|
297
|
* @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
|
298
|
298
|
*/ |
|
299
|
|
- public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
300
|
|
- $response = $this->process_subscription_payment( $amount_to_charge, $renewal_order ); |
|
|
299
|
+ public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
|
300
|
+ $response = $this->process_subscription_payment($amount_to_charge, $renewal_order); |
|
301
|
301
|
|
|
302
|
|
- if ( is_wp_error( $response ) ) { |
|
|
302
|
+ if (is_wp_error($response)) { |
|
303
|
303
|
/* translators: error message */ |
|
304
|
|
- $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
|
304
|
+ $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
305
|
305
|
} |
|
306
|
306
|
|
|
307
|
|
- if ( ! empty( $response->error ) ) { |
|
|
307
|
+ if ( ! empty($response->error)) { |
|
308
|
308
|
// This is a very generic error to listen for but worth a retry before total fail. |
|
309
|
|
- if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
310
|
|
- $this->process_subscription_payment( $amount_to_charge, $renewal_order, true ); |
|
|
309
|
+ if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
|
310
|
+ $this->process_subscription_payment($amount_to_charge, $renewal_order, true); |
|
311
|
311
|
} else { |
|
312
|
312
|
/* translators: error message */ |
|
313
|
|
- $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
|
313
|
+ $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
314
|
314
|
} |
|
315
|
315
|
} |
|
316
|
316
|
} |
|
@@ -319,20 +319,20 @@ discard block |
|
|
block discarded – undo |
|
319
|
319
|
* Remove order meta |
|
320
|
320
|
* @param object $order |
|
321
|
321
|
*/ |
|
322
|
|
- public function remove_order_source_before_retry( $order ) { |
|
|
322
|
+ public function remove_order_source_before_retry($order) { |
|
323
|
323
|
$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
324
|
|
- delete_post_meta( $order_id, '_stripe_source_id' ); |
|
|
324
|
+ delete_post_meta($order_id, '_stripe_source_id'); |
|
325
|
325
|
// For BW compat will remove in the future. |
|
326
|
|
- delete_post_meta( $order_id, '_stripe_card_id' ); |
|
|
326
|
+ delete_post_meta($order_id, '_stripe_card_id'); |
|
327
|
327
|
} |
|
328
|
328
|
|
|
329
|
329
|
/** |
|
330
|
330
|
* Remove order meta |
|
331
|
331
|
* @param object $order |
|
332
|
332
|
*/ |
|
333
|
|
- public function remove_order_customer_before_retry( $order ) { |
|
|
333
|
+ public function remove_order_customer_before_retry($order) { |
|
334
|
334
|
$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
335
|
|
- delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
|
335
|
+ delete_post_meta($order_id, '_stripe_customer_id'); |
|
336
|
336
|
} |
|
337
|
337
|
|
|
338
|
338
|
/** |
|
@@ -344,14 +344,14 @@ discard block |
|
|
block discarded – undo |
|
344
|
344
|
* @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
|
345
|
345
|
* @return void |
|
346
|
346
|
*/ |
|
347
|
|
- public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
348
|
|
- if ( WC_Stripe_Helper::is_pre_30() ) { |
|
349
|
|
- update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
350
|
|
- update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
|
347
|
+ public function update_failing_payment_method($subscription, $renewal_order) { |
|
|
348
|
+ if (WC_Stripe_Helper::is_pre_30()) { |
|
|
349
|
+ update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
|
350
|
+ update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
351
|
351
|
|
|
352
|
352
|
} else { |
|
353
|
|
- update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
354
|
|
- update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
|
353
|
+ update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
|
354
|
+ update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
355
|
355
|
} |
|
356
|
356
|
} |
|
357
|
357
|
|
|
@@ -364,21 +364,21 @@ discard block |
|
|
block discarded – undo |
|
364
|
364
|
* @param WC_Subscription $subscription An instance of a subscription object |
|
365
|
365
|
* @return array |
|
366
|
366
|
*/ |
|
367
|
|
- public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
368
|
|
- $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
|
367
|
+ public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
|
368
|
+ $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
369
|
369
|
|
|
370
|
370
|
// For BW compat will remove in future. |
|
371
|
|
- if ( empty( $source_id ) ) { |
|
372
|
|
- $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
|
371
|
+ if (empty($source_id)) { |
|
|
372
|
+ $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
373
|
373
|
|
|
374
|
374
|
// Take this opportunity to update the key name. |
|
375
|
|
- WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
|
375
|
+ WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
376
|
376
|
} |
|
377
|
377
|
|
|
378
|
|
- $payment_meta[ $this->id ] = array( |
|
|
378
|
+ $payment_meta[$this->id] = array( |
|
379
|
379
|
'post_meta' => array( |
|
380
|
380
|
'_stripe_customer_id' => array( |
|
381
|
|
- 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
|
381
|
+ 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
382
|
382
|
'label' => 'Stripe Customer ID', |
|
383
|
383
|
), |
|
384
|
384
|
'_stripe_source_id' => array( |
|
@@ -401,22 +401,22 @@ discard block |
|
|
block discarded – undo |
|
401
|
401
|
* @param array $payment_meta associative array of meta data required for automatic payments |
|
402
|
402
|
* @return array |
|
403
|
403
|
*/ |
|
404
|
|
- public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
405
|
|
- if ( $this->id === $payment_method_id ) { |
|
|
404
|
+ public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
|
405
|
+ if ($this->id === $payment_method_id) { |
|
406
|
406
|
|
|
407
|
|
- if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
408
|
|
- throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
409
|
|
- } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
410
|
|
- throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
|
407
|
+ if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
|
408
|
+ throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
|
409
|
+ } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
|
410
|
+ throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
411
|
411
|
} |
|
412
|
412
|
|
|
413
|
413
|
if ( |
|
414
|
|
- ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
415
|
|
- && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
416
|
|
- && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
417
|
|
- && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
|
414
|
+ ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
|
415
|
+ && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
|
416
|
+ && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
|
417
|
+ && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
418
|
418
|
|
|
419
|
|
- throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
|
419
|
+ throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
420
|
420
|
} |
|
421
|
421
|
} |
|
422
|
422
|
} |
|
@@ -429,91 +429,91 @@ discard block |
|
|
block discarded – undo |
|
429
|
429
|
* @param WC_Subscription $subscription the subscription details |
|
430
|
430
|
* @return string the subscription payment method |
|
431
|
431
|
*/ |
|
432
|
|
- public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
|
432
|
+ public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
433
|
433
|
$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
|
434
|
434
|
|
|
435
|
435
|
// bail for other payment methods |
|
436
|
|
- if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
|
436
|
+ if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
437
|
437
|
return $payment_method_to_display; |
|
438
|
438
|
} |
|
439
|
439
|
|
|
440
|
|
- $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
|
440
|
+ $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
441
|
441
|
|
|
442
|
442
|
// For BW compat will remove in future. |
|
443
|
|
- if ( empty( $stripe_source_id ) ) { |
|
444
|
|
- $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
|
443
|
+ if (empty($stripe_source_id)) { |
|
|
444
|
+ $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
445
|
445
|
|
|
446
|
446
|
// Take this opportunity to update the key name. |
|
447
|
|
- WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
|
447
|
+ WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
448
|
448
|
} |
|
449
|
449
|
|
|
450
|
450
|
$stripe_customer = new WC_Stripe_Customer(); |
|
451
|
|
- $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
|
451
|
+ $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
452
|
452
|
|
|
453
|
453
|
// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
|
454
|
|
- if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
|
454
|
+ if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
455
|
455
|
$user_id = $customer_user; |
|
456
|
|
- $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
457
|
|
- $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
|
456
|
+ $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
|
457
|
+ $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
458
|
458
|
|
|
459
|
459
|
// For BW compat will remove in future. |
|
460
|
|
- if ( empty( $stripe_source_id ) ) { |
|
461
|
|
- $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
|
460
|
+ if (empty($stripe_source_id)) { |
|
|
461
|
+ $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
462
|
462
|
|
|
463
|
463
|
// Take this opportunity to update the key name. |
|
464
|
|
- update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
|
464
|
+ update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
465
|
465
|
} |
|
466
|
466
|
} |
|
467
|
467
|
|
|
468
|
468
|
// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
|
469
|
|
- if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
470
|
|
- $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
471
|
|
- $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
|
469
|
+ if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
|
470
|
+ $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
|
471
|
+ $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
472
|
472
|
|
|
473
|
473
|
// For BW compat will remove in future. |
|
474
|
|
- if ( empty( $stripe_source_id ) ) { |
|
475
|
|
- $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
|
474
|
+ if (empty($stripe_source_id)) { |
|
|
475
|
+ $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
476
|
476
|
|
|
477
|
477
|
// Take this opportunity to update the key name. |
|
478
|
|
- WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
|
478
|
+ WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
479
|
479
|
} |
|
480
|
480
|
} |
|
481
|
481
|
|
|
482
|
|
- $stripe_customer->set_id( $stripe_customer_id ); |
|
|
482
|
+ $stripe_customer->set_id($stripe_customer_id); |
|
483
|
483
|
$sources = $stripe_customer->get_sources(); |
|
484
|
484
|
|
|
485
|
|
- if ( $sources ) { |
|
|
485
|
+ if ($sources) { |
|
486
|
486
|
$found_source = false; |
|
487
|
|
- foreach ( $sources as $source ) { |
|
488
|
|
- if ( isset( $source->type ) && 'card' === $source->type ) { |
|
|
487
|
+ foreach ($sources as $source) { |
|
|
488
|
+ if (isset($source->type) && 'card' === $source->type) { |
|
489
|
489
|
$card = $source->card; |
|
490
|
|
- } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
|
490
|
+ } elseif (isset($source->object) && 'card' === $source->object) { |
|
491
|
491
|
$card = $source; |
|
492
|
492
|
} |
|
493
|
493
|
|
|
494
|
|
- if ( $source->id === $stripe_source_id ) { |
|
|
494
|
+ if ($source->id === $stripe_source_id) { |
|
495
|
495
|
$found_source = true; |
|
496
|
496
|
|
|
497
|
|
- if ( $card ) { |
|
|
497
|
+ if ($card) { |
|
498
|
498
|
/* translators: 1) card brand 2) last 4 digits */ |
|
499
|
|
- $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
|
499
|
+ $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
500
|
500
|
} else { |
|
501
|
|
- $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
|
501
|
+ $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
502
|
502
|
} |
|
503
|
503
|
break; |
|
504
|
504
|
} |
|
505
|
505
|
} |
|
506
|
506
|
|
|
507
|
|
- if ( ! $found_source ) { |
|
508
|
|
- if ( 'card' === $sources[0]->type ) { |
|
|
507
|
+ if ( ! $found_source) { |
|
|
508
|
+ if ('card' === $sources[0]->type) { |
|
509
|
509
|
$card = $sources[0]->card; |
|
510
|
510
|
} |
|
511
|
511
|
|
|
512
|
|
- if ( $card ) { |
|
|
512
|
+ if ($card) { |
|
513
|
513
|
/* translators: 1) card brand 2) last 4 digits */ |
|
514
|
|
- $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
|
514
|
+ $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
515
|
515
|
} else { |
|
516
|
|
- $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
|
516
|
+ $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
517
|
517
|
} |
|
518
|
518
|
} |
|
519
|
519
|
} |
|
@@ -526,42 +526,42 @@ discard block |
|
|
block discarded – undo |
|
526
|
526
|
* @param int $order_id |
|
527
|
527
|
* @return array |
|
528
|
528
|
*/ |
|
529
|
|
- public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
530
|
|
- if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
|
529
|
+ public function process_pre_order($order_id, $retry, $force_save_source) { |
|
|
530
|
+ if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
531
|
531
|
try { |
|
532
|
|
- $order = wc_get_order( $order_id ); |
|
|
532
|
+ $order = wc_get_order($order_id); |
|
533
|
533
|
|
|
534
|
|
- if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
|
534
|
+ if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
535
|
535
|
/* translators: minimum amount */ |
|
536
|
|
- 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_Helper::get_minimum_amount() / 100 ) ) ); |
|
|
536
|
+ 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_Helper::get_minimum_amount() / 100))); |
|
537
|
537
|
} |
|
538
|
538
|
|
|
539
|
|
- $source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true ); |
|
|
539
|
+ $source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true); |
|
540
|
540
|
|
|
541
|
541
|
// We need a source on file to continue. |
|
542
|
|
- if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
543
|
|
- throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
|
542
|
+ if (empty($source->customer) || empty($source->source)) { |
|
|
543
|
+ throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
544
|
544
|
} |
|
545
|
545
|
|
|
546
|
|
- $this->save_source_to_order( $order, $source ); |
|
|
546
|
+ $this->save_source_to_order($order, $source); |
|
547
|
547
|
|
|
548
|
548
|
// Remove cart |
|
549
|
549
|
WC()->cart->empty_cart(); |
|
550
|
550
|
|
|
551
|
551
|
// Is pre ordered! |
|
552
|
|
- WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
|
552
|
+ WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
553
|
553
|
|
|
554
|
554
|
// Return thank you page redirect |
|
555
|
555
|
return array( |
|
556
|
556
|
'result' => 'success', |
|
557
|
|
- 'redirect' => $this->get_return_url( $order ), |
|
|
557
|
+ 'redirect' => $this->get_return_url($order), |
|
558
|
558
|
); |
|
559
|
|
- } catch ( Exception $e ) { |
|
560
|
|
- wc_add_notice( $e->getMessage(), 'error' ); |
|
|
559
|
+ } catch (Exception $e) { |
|
|
560
|
+ wc_add_notice($e->getMessage(), 'error'); |
|
561
|
561
|
return; |
|
562
|
562
|
} |
|
563
|
563
|
} else { |
|
564
|
|
- return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
|
564
|
+ return parent::process_payment($order_id, $retry, $force_save_source); |
|
565
|
565
|
} |
|
566
|
566
|
} |
|
567
|
567
|
|
|
@@ -570,7 +570,7 @@ discard block |
|
|
block discarded – undo |
|
570
|
570
|
* @param WC_Order $order |
|
571
|
571
|
* @return void |
|
572
|
572
|
*/ |
|
573
|
|
- public function process_pre_order_release_payment( $order ) { |
|
|
573
|
+ public function process_pre_order_release_payment($order) { |
|
574
|
574
|
try { |
|
575
|
575
|
// Define some callbacks if the first attempt fails. |
|
576
|
576
|
$retry_callbacks = array( |
|
@@ -578,33 +578,33 @@ discard block |
|
|
block discarded – undo |
|
578
|
578
|
'remove_order_customer_before_retry', |
|
579
|
579
|
); |
|
580
|
580
|
|
|
581
|
|
- while ( 1 ) { |
|
582
|
|
- $source = $this->prepare_order_source( $order ); |
|
583
|
|
- $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
|
581
|
+ while (1) { |
|
|
582
|
+ $source = $this->prepare_order_source($order); |
|
|
583
|
+ $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
584
|
584
|
|
|
585
|
|
- if ( ! empty( $response->error ) ) { |
|
586
|
|
- if ( 0 === sizeof( $retry_callbacks ) ) { |
|
587
|
|
- throw new Exception( $response->error->message ); |
|
|
585
|
+ if ( ! empty($response->error)) { |
|
|
586
|
+ if (0 === sizeof($retry_callbacks)) { |
|
|
587
|
+ throw new Exception($response->error->message); |
|
588
|
588
|
} else { |
|
589
|
|
- $retry_callback = array_shift( $retry_callbacks ); |
|
590
|
|
- call_user_func( array( $this, $retry_callback ), $order ); |
|
|
589
|
+ $retry_callback = array_shift($retry_callbacks); |
|
|
590
|
+ call_user_func(array($this, $retry_callback), $order); |
|
591
|
591
|
} |
|
592
|
592
|
} else { |
|
593
|
593
|
// Successful |
|
594
|
|
- $this->process_response( $response, $order ); |
|
|
594
|
+ $this->process_response($response, $order); |
|
595
|
595
|
break; |
|
596
|
596
|
} |
|
597
|
597
|
} |
|
598
|
|
- } catch ( Exception $e ) { |
|
|
598
|
+ } catch (Exception $e) { |
|
599
|
599
|
/* translators: error message */ |
|
600
|
|
- $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
|
600
|
+ $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
601
|
601
|
|
|
602
|
602
|
// Mark order as failed if not already set, |
|
603
|
603
|
// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
|
604
|
|
- if ( ! $order->has_status( 'failed' ) ) { |
|
605
|
|
- $order->update_status( 'failed', $order_note ); |
|
|
604
|
+ if ( ! $order->has_status('failed')) { |
|
|
605
|
+ $order->update_status('failed', $order_note); |
|
606
|
606
|
} else { |
|
607
|
|
- $order->add_order_note( $order_note ); |
|
|
607
|
+ $order->add_order_note($order_note); |
|
608
|
608
|
} |
|
609
|
609
|
} |
|
610
|
610
|
} |