|
@@ -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,19 +15,19 @@ 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' ) ); |
|
|
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
|
31
|
} |
|
32
|
32
|
} |
|
33
|
33
|
|
|
@@ -47,8 +47,8 @@ discard block |
|
|
block discarded – undo |
|
47
|
47
|
* @since 4.0.0 |
|
48
|
48
|
* @version 4.0.0 |
|
49
|
49
|
*/ |
|
50
|
|
- public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
51
|
|
- if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
|
50
|
+ public function maybe_hide_save_checkbox($display_tokenization) { |
|
|
51
|
+ if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
52
|
52
|
return false; |
|
53
|
53
|
} |
|
54
|
54
|
|
|
@@ -60,8 +60,8 @@ discard block |
|
|
block discarded – undo |
|
60
|
60
|
* @param int $order_id |
|
61
|
61
|
* @return boolean |
|
62
|
62
|
*/ |
|
63
|
|
- public function has_subscription( $order_id ) { |
|
64
|
|
- return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
|
63
|
+ public function has_subscription($order_id) { |
|
|
64
|
+ return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
65
|
65
|
} |
|
66
|
66
|
|
|
67
|
67
|
/** |
|
@@ -71,7 +71,7 @@ discard block |
|
|
block discarded – undo |
|
71
|
71
|
* @return bool |
|
72
|
72
|
*/ |
|
73
|
73
|
public function is_subs_change_payment() { |
|
74
|
|
- return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
|
74
|
+ return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
75
|
75
|
} |
|
76
|
76
|
|
|
77
|
77
|
/** |
|
@@ -80,24 +80,24 @@ discard block |
|
|
block discarded – undo |
|
80
|
80
|
* @since 3.1.0 |
|
81
|
81
|
* @version 4.0.0 |
|
82
|
82
|
*/ |
|
83
|
|
- public function save_source_to_order( $order, $source ) { |
|
84
|
|
- parent::save_source_to_order( $order, $source ); |
|
|
83
|
+ public function save_source_to_order($order, $source) { |
|
|
84
|
+ parent::save_source_to_order($order, $source); |
|
85
|
85
|
|
|
86
|
|
- $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
|
86
|
+ $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
87
|
87
|
|
|
88
|
88
|
// Also store it on the subscriptions being purchased or paid for in the order. |
|
89
|
|
- if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
90
|
|
- $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
91
|
|
- } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
92
|
|
- $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
|
89
|
+ if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
|
90
|
+ $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
|
91
|
+ } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
|
92
|
+ $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
93
|
93
|
} else { |
|
94
|
94
|
$subscriptions = array(); |
|
95
|
95
|
} |
|
96
|
96
|
|
|
97
|
|
- foreach ( $subscriptions as $subscription ) { |
|
|
97
|
+ foreach ($subscriptions as $subscription) { |
|
98
|
98
|
$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
|
99
|
|
- update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
100
|
|
- update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
|
99
|
+ update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
|
100
|
+ update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
101
|
101
|
} |
|
102
|
102
|
} |
|
103
|
103
|
|
|
@@ -106,16 +106,16 @@ discard block |
|
|
block discarded – undo |
|
106
|
106
|
* @param int $order_id |
|
107
|
107
|
* @return array |
|
108
|
108
|
*/ |
|
109
|
|
- public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
110
|
|
- if ( $this->has_subscription( $order_id ) ) { |
|
111
|
|
- if ( $this->is_subs_change_payment() ) { |
|
112
|
|
- return $this->change_subs_payment_method( $order_id ); |
|
|
109
|
+ public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
|
110
|
+ if ($this->has_subscription($order_id)) { |
|
|
111
|
+ if ($this->is_subs_change_payment()) { |
|
|
112
|
+ return $this->change_subs_payment_method($order_id); |
|
113
|
113
|
} |
|
114
|
114
|
|
|
115
|
115
|
// Regular payment with force customer enabled |
|
116
|
|
- return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
|
116
|
+ return parent::process_payment($order_id, $retry, true, $previous_error); |
|
117
|
117
|
} else { |
|
118
|
|
- return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
|
118
|
+ return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
119
|
119
|
} |
|
120
|
120
|
} |
|
121
|
121
|
|
|
@@ -125,26 +125,26 @@ discard block |
|
|
block discarded – undo |
|
125
|
125
|
* @since 4.0.4 |
|
126
|
126
|
* @param int $order_id |
|
127
|
127
|
*/ |
|
128
|
|
- public function change_subs_payment_method( $order_id ) { |
|
|
128
|
+ public function change_subs_payment_method($order_id) { |
|
129
|
129
|
try { |
|
130
|
|
- $subscription = wc_get_order( $order_id ); |
|
131
|
|
- $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
|
130
|
+ $subscription = wc_get_order($order_id); |
|
|
131
|
+ $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
132
|
132
|
$source_object = $prepared_source->source_object; |
|
133
|
133
|
|
|
134
|
|
- if ( empty( $prepared_source->source ) ) { |
|
135
|
|
- $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
136
|
|
- throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
|
134
|
+ if (empty($prepared_source->source)) { |
|
|
135
|
+ $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
|
136
|
+ throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
137
|
137
|
} |
|
138
|
138
|
|
|
139
|
|
- $this->save_source_to_order( $subscription, $prepared_source ); |
|
|
139
|
+ $this->save_source_to_order($subscription, $prepared_source); |
|
140
|
140
|
|
|
141
|
141
|
return array( |
|
142
|
142
|
'result' => 'success', |
|
143
|
|
- 'redirect' => $this->get_return_url( $subscription ), |
|
|
143
|
+ 'redirect' => $this->get_return_url($subscription), |
|
144
|
144
|
); |
|
145
|
|
- } catch ( WC_Stripe_Exception $e ) { |
|
146
|
|
- wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
147
|
|
- WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
|
145
|
+ } catch (WC_Stripe_Exception $e) { |
|
|
146
|
+ wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
|
147
|
+ WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
148
|
148
|
} |
|
149
|
149
|
} |
|
150
|
150
|
|
|
@@ -154,8 +154,8 @@ discard block |
|
|
block discarded – undo |
|
154
|
154
|
* @param $amount_to_charge float The amount to charge. |
|
155
|
155
|
* @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
|
156
|
156
|
*/ |
|
157
|
|
- public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
158
|
|
- $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
|
157
|
+ public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
|
158
|
+ $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
159
|
159
|
} |
|
160
|
160
|
|
|
161
|
161
|
/** |
|
@@ -169,89 +169,89 @@ discard block |
|
|
block discarded – undo |
|
169
|
169
|
* @param bool $retry Should we retry the process? |
|
170
|
170
|
* @param object $previous_error |
|
171
|
171
|
*/ |
|
172
|
|
- public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
|
172
|
+ public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
173
|
173
|
try { |
|
174
|
|
- if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
|
174
|
+ if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
175
|
175
|
/* translators: minimum amount */ |
|
176
|
|
- 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 ) ) ); |
|
|
176
|
+ 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))); |
|
177
|
177
|
} |
|
178
|
178
|
|
|
179
|
179
|
$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
|
180
|
180
|
|
|
181
|
181
|
// Get source from order |
|
182
|
|
- $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
|
182
|
+ $prepared_source = $this->prepare_order_source($renewal_order); |
|
183
|
183
|
$source_object = $prepared_source->source_object; |
|
184
|
184
|
|
|
185
|
|
- if ( ! $prepared_source->customer ) { |
|
186
|
|
- return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
|
185
|
+ if ( ! $prepared_source->customer) { |
|
|
186
|
+ return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
187
|
187
|
} |
|
188
|
188
|
|
|
189
|
|
- WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
|
189
|
+ WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
190
|
190
|
|
|
191
|
191
|
/* If we're doing a retry and source is chargeable, we need to pass |
|
192
|
192
|
* a different idempotency key and retry for success. |
|
193
|
193
|
*/ |
|
194
|
|
- if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
195
|
|
- add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
|
194
|
+ if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
|
195
|
+ add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
196
|
196
|
} |
|
197
|
197
|
|
|
198
|
|
- if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
|
198
|
+ if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
199
|
199
|
// Passing empty source will charge customer default. |
|
200
|
200
|
$prepared_source->source = ''; |
|
201
|
201
|
} |
|
202
|
202
|
|
|
203
|
|
- $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
|
203
|
+ $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
204
|
204
|
$request['capture'] = 'true'; |
|
205
|
|
- $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
206
|
|
- $response = WC_Stripe_API::request( $request ); |
|
|
205
|
+ $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
|
206
|
+ $response = WC_Stripe_API::request($request); |
|
207
|
207
|
|
|
208
|
|
- if ( ! empty( $response->error ) ) { |
|
|
208
|
+ if ( ! empty($response->error)) { |
|
209
|
209
|
// We want to retry. |
|
210
|
|
- if ( $this->is_retryable_error( $response->error ) ) { |
|
211
|
|
- if ( $retry ) { |
|
|
210
|
+ if ($this->is_retryable_error($response->error)) { |
|
|
211
|
+ if ($retry) { |
|
212
|
212
|
// Don't do anymore retries after this. |
|
213
|
|
- if ( 5 <= $this->retry_interval ) { |
|
214
|
|
- return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
|
213
|
+ if (5 <= $this->retry_interval) { |
|
|
214
|
+ return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
215
|
215
|
} |
|
216
|
216
|
|
|
217
|
|
- sleep( $this->retry_interval ); |
|
|
217
|
+ sleep($this->retry_interval); |
|
218
|
218
|
|
|
219
|
219
|
$this->retry_interval++; |
|
220
|
220
|
|
|
221
|
|
- return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
|
221
|
+ return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
222
|
222
|
} else { |
|
223
|
|
- $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
224
|
|
- $renewal_order->add_order_note( $localized_message ); |
|
225
|
|
- throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
|
223
|
+ $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
|
224
|
+ $renewal_order->add_order_note($localized_message); |
|
|
225
|
+ throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
226
|
226
|
} |
|
227
|
227
|
} |
|
228
|
228
|
|
|
229
|
229
|
$localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
230
|
230
|
|
|
231
|
|
- if ( 'card_error' === $response->error->type ) { |
|
232
|
|
- $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
|
231
|
+ if ('card_error' === $response->error->type) { |
|
|
232
|
+ $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
233
|
233
|
} else { |
|
234
|
|
- $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
|
234
|
+ $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
235
|
235
|
} |
|
236
|
236
|
|
|
237
|
|
- $renewal_order->add_order_note( $localized_message ); |
|
|
237
|
+ $renewal_order->add_order_note($localized_message); |
|
238
|
238
|
|
|
239
|
|
- throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
|
239
|
+ throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
240
|
240
|
} |
|
241
|
241
|
|
|
242
|
|
- do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
|
242
|
+ do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
243
|
243
|
|
|
244
|
|
- $this->process_response( $response, $renewal_order ); |
|
245
|
|
- } catch ( WC_Stripe_Exception $e ) { |
|
246
|
|
- WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
|
244
|
+ $this->process_response($response, $renewal_order); |
|
|
245
|
+ } catch (WC_Stripe_Exception $e) { |
|
|
246
|
+ WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
247
|
247
|
|
|
248
|
|
- do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
|
248
|
+ do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
249
|
249
|
|
|
250
|
250
|
/* translators: error message */ |
|
251
|
|
- $renewal_order->update_status( 'failed' ); |
|
|
251
|
+ $renewal_order->update_status('failed'); |
|
252
|
252
|
|
|
253
|
|
- if ( $renewal_order->has_status( array( 'pending', 'failed' ) ) ) { |
|
254
|
|
- $this->send_failed_order_email( $order_id ); |
|
|
253
|
+ if ($renewal_order->has_status(array('pending', 'failed'))) { |
|
|
254
|
+ $this->send_failed_order_email($order_id); |
|
255
|
255
|
} |
|
256
|
256
|
} |
|
257
|
257
|
} |
|
@@ -260,21 +260,21 @@ discard block |
|
|
block discarded – undo |
|
260
|
260
|
* Don't transfer Stripe customer/token meta to resubscribe orders. |
|
261
|
261
|
* @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
262
|
262
|
*/ |
|
263
|
|
- public function delete_resubscribe_meta( $resubscribe_order ) { |
|
264
|
|
- delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
265
|
|
- delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
|
263
|
+ public function delete_resubscribe_meta($resubscribe_order) { |
|
|
264
|
+ delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
|
265
|
+ delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
266
|
266
|
// For BW compat will remove in future |
|
267
|
|
- delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
268
|
|
- $this->delete_renewal_meta( $resubscribe_order ); |
|
|
267
|
+ delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
|
268
|
+ $this->delete_renewal_meta($resubscribe_order); |
|
269
|
269
|
} |
|
270
|
270
|
|
|
271
|
271
|
/** |
|
272
|
272
|
* Don't transfer Stripe fee/ID meta to renewal 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_renewal_meta( $renewal_order ) { |
|
276
|
|
- WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
277
|
|
- WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
|
275
|
+ public function delete_renewal_meta($renewal_order) { |
|
|
276
|
+ WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
|
277
|
+ WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
278
|
278
|
|
|
279
|
279
|
return $renewal_order; |
|
280
|
280
|
} |
|
@@ -288,14 +288,14 @@ discard block |
|
|
block discarded – undo |
|
288
|
288
|
* @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
|
289
|
289
|
* @return void |
|
290
|
290
|
*/ |
|
291
|
|
- public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
292
|
|
- if ( WC_Stripe_Helper::is_pre_30() ) { |
|
293
|
|
- update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
294
|
|
- update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
|
291
|
+ public function update_failing_payment_method($subscription, $renewal_order) { |
|
|
292
|
+ if (WC_Stripe_Helper::is_pre_30()) { |
|
|
293
|
+ update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
|
294
|
+ update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
295
|
295
|
|
|
296
|
296
|
} else { |
|
297
|
|
- update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
298
|
|
- update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
|
297
|
+ update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
|
298
|
+ update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
299
|
299
|
} |
|
300
|
300
|
} |
|
301
|
301
|
|
|
@@ -308,21 +308,21 @@ discard block |
|
|
block discarded – undo |
|
308
|
308
|
* @param WC_Subscription $subscription An instance of a subscription object |
|
309
|
309
|
* @return array |
|
310
|
310
|
*/ |
|
311
|
|
- public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
312
|
|
- $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
|
311
|
+ public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
|
312
|
+ $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
313
|
313
|
|
|
314
|
314
|
// For BW compat will remove in future. |
|
315
|
|
- if ( empty( $source_id ) ) { |
|
316
|
|
- $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
|
315
|
+ if (empty($source_id)) { |
|
|
316
|
+ $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
317
|
317
|
|
|
318
|
318
|
// Take this opportunity to update the key name. |
|
319
|
|
- 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 ); |
|
|
319
|
+ 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); |
|
320
|
320
|
} |
|
321
|
321
|
|
|
322
|
|
- $payment_meta[ $this->id ] = array( |
|
|
322
|
+ $payment_meta[$this->id] = array( |
|
323
|
323
|
'post_meta' => array( |
|
324
|
324
|
'_stripe_customer_id' => array( |
|
325
|
|
- 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
|
325
|
+ 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
326
|
326
|
'label' => 'Stripe Customer ID', |
|
327
|
327
|
), |
|
328
|
328
|
'_stripe_source_id' => array( |
|
@@ -343,22 +343,22 @@ discard block |
|
|
block discarded – undo |
|
343
|
343
|
* @param array $payment_meta associative array of meta data required for automatic payments |
|
344
|
344
|
* @return array |
|
345
|
345
|
*/ |
|
346
|
|
- public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
347
|
|
- if ( $this->id === $payment_method_id ) { |
|
|
346
|
+ public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
|
347
|
+ if ($this->id === $payment_method_id) { |
|
348
|
348
|
|
|
349
|
|
- if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
350
|
|
- throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
351
|
|
- } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
352
|
|
- throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
|
349
|
+ if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
|
350
|
+ throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
|
351
|
+ } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
|
352
|
+ throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
353
|
353
|
} |
|
354
|
354
|
|
|
355
|
355
|
if ( |
|
356
|
|
- ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
357
|
|
- && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
358
|
|
- && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
359
|
|
- && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
|
356
|
+ ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
|
357
|
+ && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
|
358
|
+ && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
|
359
|
+ && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
360
|
360
|
|
|
361
|
|
- throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
|
361
|
+ throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
362
|
362
|
} |
|
363
|
363
|
} |
|
364
|
364
|
} |
|
@@ -371,67 +371,67 @@ discard block |
|
|
block discarded – undo |
|
371
|
371
|
* @param WC_Subscription $subscription the subscription details |
|
372
|
372
|
* @return string the subscription payment method |
|
373
|
373
|
*/ |
|
374
|
|
- public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
|
374
|
+ public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
375
|
375
|
$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
|
376
|
376
|
|
|
377
|
377
|
// bail for other payment methods |
|
378
|
|
- if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
|
378
|
+ if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
379
|
379
|
return $payment_method_to_display; |
|
380
|
380
|
} |
|
381
|
381
|
|
|
382
|
|
- $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
|
382
|
+ $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
383
|
383
|
|
|
384
|
384
|
// For BW compat will remove in future. |
|
385
|
|
- if ( empty( $stripe_source_id ) ) { |
|
386
|
|
- $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
|
385
|
+ if (empty($stripe_source_id)) { |
|
|
386
|
+ $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
387
|
387
|
|
|
388
|
388
|
// Take this opportunity to update the key name. |
|
389
|
|
- 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 ); |
|
|
389
|
+ 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); |
|
390
|
390
|
} |
|
391
|
391
|
|
|
392
|
392
|
$stripe_customer = new WC_Stripe_Customer(); |
|
393
|
|
- $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
|
393
|
+ $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
394
|
394
|
|
|
395
|
395
|
// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
|
396
|
|
- if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
|
396
|
+ if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
397
|
397
|
$user_id = $customer_user; |
|
398
|
|
- $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
399
|
|
- $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
|
398
|
+ $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
|
399
|
+ $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
400
|
400
|
|
|
401
|
401
|
// For BW compat will remove in future. |
|
402
|
|
- if ( empty( $stripe_source_id ) ) { |
|
403
|
|
- $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
|
402
|
+ if (empty($stripe_source_id)) { |
|
|
403
|
+ $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
404
|
404
|
|
|
405
|
405
|
// Take this opportunity to update the key name. |
|
406
|
|
- update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
|
406
|
+ update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
407
|
407
|
} |
|
408
|
408
|
} |
|
409
|
409
|
|
|
410
|
410
|
// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
|
411
|
|
- if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
412
|
|
- $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
413
|
|
- $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
|
411
|
+ if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
|
412
|
+ $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
|
413
|
+ $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
414
|
414
|
|
|
415
|
415
|
// For BW compat will remove in future. |
|
416
|
|
- if ( empty( $stripe_source_id ) ) { |
|
417
|
|
- $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
|
416
|
+ if (empty($stripe_source_id)) { |
|
|
417
|
+ $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
418
|
418
|
|
|
419
|
419
|
// Take this opportunity to update the key name. |
|
420
|
|
- 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 ); |
|
|
420
|
+ 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); |
|
421
|
421
|
} |
|
422
|
422
|
} |
|
423
|
423
|
|
|
424
|
|
- $stripe_customer->set_id( $stripe_customer_id ); |
|
|
424
|
+ $stripe_customer->set_id($stripe_customer_id); |
|
425
|
425
|
$sources = $stripe_customer->get_sources(); |
|
426
|
426
|
|
|
427
|
|
- if ( $sources ) { |
|
428
|
|
- foreach ( $sources as $source ) { |
|
429
|
|
- if ( $source->id === $stripe_source_id ) { |
|
430
|
|
- if ( $source->sepa_debit ) { |
|
|
427
|
+ if ($sources) { |
|
|
428
|
+ foreach ($sources as $source) { |
|
|
429
|
+ if ($source->id === $stripe_source_id) { |
|
|
430
|
+ if ($source->sepa_debit) { |
|
431
|
431
|
/* translators: 1) last 4 digits of SEPA Direct Debit */ |
|
432
|
|
- $payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 ); |
|
|
432
|
+ $payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4); |
|
433
|
433
|
} else { |
|
434
|
|
- $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
|
434
|
+ $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
435
|
435
|
} |
|
436
|
436
|
break; |
|
437
|
437
|
} |