@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,24 +15,24 @@ discard block |
||
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 |
||
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 |
||
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 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @param int $order_id |
66 | 66 | * @return boolean |
67 | 67 | */ |
68 | - protected function is_pre_order( $order_id ) { |
|
69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
68 | + protected function is_pre_order($order_id) { |
|
69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * @param int $order_id |
75 | 75 | * @return array |
76 | 76 | */ |
77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
78 | - if ( $this->has_subscription( $order_id ) ) { |
|
77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
78 | + if ($this->has_subscription($order_id)) { |
|
79 | 79 | // Regular payment with force customer enabled. |
80 | - return parent::process_payment( $order_id, true, true ); |
|
81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
80 | + return parent::process_payment($order_id, true, true); |
|
81 | + } elseif ($this->is_pre_order($order_id)) { |
|
82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
83 | 83 | } else { |
84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | * @param array $metadata |
93 | 93 | * @param object $order |
94 | 94 | */ |
95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
96 | - if ( ! $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
95 | + public function add_subscription_meta_data($metadata, $order) { |
|
96 | + if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
97 | 97 | return $metadata; |
98 | 98 | } |
99 | 99 | |
100 | 100 | return $metadata += array( |
101 | 101 | 'payment_type' => 'recurring', |
102 | - 'site_url' => esc_url( get_site_url() ), |
|
102 | + 'site_url' => esc_url(get_site_url()), |
|
103 | 103 | ); |
104 | 104 | } |
105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
109 | 109 | * @since 3.1.0 |
110 | 110 | * @version 4.0.0 |
111 | 111 | */ |
112 | - public function save_source_to_order( $order, $source ) { |
|
113 | - parent::save_source_to_order( $order, $source ); |
|
112 | + public function save_source_to_order($order, $source) { |
|
113 | + parent::save_source_to_order($order, $source); |
|
114 | 114 | |
115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
116 | 116 | |
117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order. |
118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
122 | 122 | } else { |
123 | 123 | $subscriptions = array(); |
124 | 124 | } |
125 | 125 | |
126 | - foreach ( $subscriptions as $subscription ) { |
|
126 | + foreach ($subscriptions as $subscription) { |
|
127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -139,45 +139,45 @@ discard block |
||
139 | 139 | * @param mixed $renewal_order |
140 | 140 | * @param bool $is_retry Is this a retry process. |
141 | 141 | */ |
142 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
143 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
142 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) { |
|
143 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
144 | 144 | /* translators: minimum amount */ |
145 | - 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 ) ) ); |
|
145 | + 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))); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
149 | 149 | |
150 | 150 | // Get source from order. |
151 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
151 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
152 | 152 | |
153 | - if ( ! $prepared_source->customer ) { |
|
154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
153 | + if ( ! $prepared_source->customer) { |
|
154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
155 | 155 | } |
156 | 156 | |
157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
158 | 158 | |
159 | - if ( $is_retry ) { |
|
159 | + if ($is_retry) { |
|
160 | 160 | // Passing empty source with charge customer default. |
161 | 161 | $prepared_source->source = ''; |
162 | 162 | } |
163 | 163 | |
164 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
164 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
165 | 165 | $request['capture'] = 'true'; |
166 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
167 | - $response = WC_Stripe_API::request( $request ); |
|
166 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
167 | + $response = WC_Stripe_API::request($request); |
|
168 | 168 | |
169 | - if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
170 | - if ( $is_retry ) { |
|
169 | + if ( ! empty($response->error) || is_wp_error($response)) { |
|
170 | + if ($is_retry) { |
|
171 | 171 | /* translators: error message */ |
172 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
172 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | return $response; // Default catch all errors. |
176 | 176 | } |
177 | 177 | |
178 | - $this->process_response( $response, $renewal_order ); |
|
178 | + $this->process_response($response, $renewal_order); |
|
179 | 179 | |
180 | - if ( ! $is_retry ) { |
|
180 | + if ( ! $is_retry) { |
|
181 | 181 | return $response; |
182 | 182 | } |
183 | 183 | } |
@@ -186,21 +186,21 @@ discard block |
||
186 | 186 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
187 | 187 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
188 | 188 | */ |
189 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
190 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
191 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
189 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
190 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
191 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
192 | 192 | // For BW compat will remove in future |
193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
194 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
194 | + $this->delete_renewal_meta($resubscribe_order); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Don't transfer Stripe fee/ID meta to renewal orders. |
199 | 199 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
200 | 200 | */ |
201 | - public function delete_renewal_meta( $renewal_order ) { |
|
202 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
203 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
201 | + public function delete_renewal_meta($renewal_order) { |
|
202 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
203 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
204 | 204 | return $renewal_order; |
205 | 205 | } |
206 | 206 | |
@@ -210,21 +210,21 @@ discard block |
||
210 | 210 | * @param $amount_to_charge float The amount to charge. |
211 | 211 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
212 | 212 | */ |
213 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
214 | - $response = $this->process_subscription_payment( $amount_to_charge, $renewal_order ); |
|
213 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
214 | + $response = $this->process_subscription_payment($amount_to_charge, $renewal_order); |
|
215 | 215 | |
216 | - if ( is_wp_error( $response ) ) { |
|
216 | + if (is_wp_error($response)) { |
|
217 | 217 | /* translators: error message */ |
218 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
218 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
219 | 219 | } |
220 | 220 | |
221 | - if ( ! empty( $response->error ) ) { |
|
221 | + if ( ! empty($response->error)) { |
|
222 | 222 | // This is a very generic error to listen for but worth a retry before total fail. |
223 | - if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
224 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true ); |
|
223 | + if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
224 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true); |
|
225 | 225 | } else { |
226 | 226 | /* translators: error message */ |
227 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
227 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | } |
@@ -233,20 +233,20 @@ discard block |
||
233 | 233 | * Remove order meta |
234 | 234 | * @param object $order |
235 | 235 | */ |
236 | - public function remove_order_source_before_retry( $order ) { |
|
236 | + public function remove_order_source_before_retry($order) { |
|
237 | 237 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
238 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
238 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
239 | 239 | // For BW compat will remove in the future. |
240 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
240 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
244 | 244 | * Remove order meta |
245 | 245 | * @param object $order |
246 | 246 | */ |
247 | - public function remove_order_customer_before_retry( $order ) { |
|
247 | + public function remove_order_customer_before_retry($order) { |
|
248 | 248 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
249 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
249 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
259 | 259 | * @return void |
260 | 260 | */ |
261 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
262 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
263 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
264 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
261 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
262 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
263 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
264 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
265 | 265 | |
266 | 266 | } else { |
267 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
268 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
267 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
268 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
@@ -278,21 +278,21 @@ discard block |
||
278 | 278 | * @param WC_Subscription $subscription An instance of a subscription object |
279 | 279 | * @return array |
280 | 280 | */ |
281 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
282 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
281 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
282 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
283 | 283 | |
284 | 284 | // For BW compat will remove in future. |
285 | - if ( empty( $source_id ) ) { |
|
286 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
285 | + if (empty($source_id)) { |
|
286 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
287 | 287 | |
288 | 288 | // Take this opportunity to update the key name. |
289 | - 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 ); |
|
289 | + 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); |
|
290 | 290 | } |
291 | 291 | |
292 | - $payment_meta[ $this->id ] = array( |
|
292 | + $payment_meta[$this->id] = array( |
|
293 | 293 | 'post_meta' => array( |
294 | 294 | '_stripe_customer_id' => array( |
295 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
295 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
296 | 296 | 'label' => 'Stripe Customer ID', |
297 | 297 | ), |
298 | 298 | '_stripe_source_id' => array( |
@@ -313,22 +313,22 @@ discard block |
||
313 | 313 | * @param array $payment_meta associative array of meta data required for automatic payments |
314 | 314 | * @return array |
315 | 315 | */ |
316 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
317 | - if ( $this->id === $payment_method_id ) { |
|
316 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
317 | + if ($this->id === $payment_method_id) { |
|
318 | 318 | |
319 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
320 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
321 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
322 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
319 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
320 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
321 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
322 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | if ( |
326 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
327 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
328 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
329 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
326 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
327 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
328 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
329 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
330 | 330 | |
331 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
331 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | } |
@@ -341,67 +341,67 @@ discard block |
||
341 | 341 | * @param WC_Subscription $subscription the subscription details |
342 | 342 | * @return string the subscription payment method |
343 | 343 | */ |
344 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
344 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
345 | 345 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
346 | 346 | |
347 | 347 | // bail for other payment methods |
348 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
348 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
349 | 349 | return $payment_method_to_display; |
350 | 350 | } |
351 | 351 | |
352 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
352 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
353 | 353 | |
354 | 354 | // For BW compat will remove in future. |
355 | - if ( empty( $stripe_source_id ) ) { |
|
356 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
355 | + if (empty($stripe_source_id)) { |
|
356 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
357 | 357 | |
358 | 358 | // Take this opportunity to update the key name. |
359 | - 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 ); |
|
359 | + 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); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | $stripe_customer = new WC_Stripe_Customer(); |
363 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
363 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
364 | 364 | |
365 | 365 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
366 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
366 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
367 | 367 | $user_id = $customer_user; |
368 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
369 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
368 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
369 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
370 | 370 | |
371 | 371 | // For BW compat will remove in future. |
372 | - if ( empty( $stripe_source_id ) ) { |
|
373 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
372 | + if (empty($stripe_source_id)) { |
|
373 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
374 | 374 | |
375 | 375 | // Take this opportunity to update the key name. |
376 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
376 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | |
380 | 380 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
381 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
382 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
383 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
381 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
382 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
383 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
384 | 384 | |
385 | 385 | // For BW compat will remove in future. |
386 | - if ( empty( $stripe_source_id ) ) { |
|
387 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
386 | + if (empty($stripe_source_id)) { |
|
387 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
388 | 388 | |
389 | 389 | // Take this opportunity to update the key name. |
390 | - 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 ); |
|
390 | + 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); |
|
391 | 391 | } |
392 | 392 | } |
393 | 393 | |
394 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
394 | + $stripe_customer->set_id($stripe_customer_id); |
|
395 | 395 | $sources = $stripe_customer->get_sources(); |
396 | 396 | |
397 | - if ( $sources ) { |
|
398 | - foreach ( $sources as $source ) { |
|
399 | - if ( $source->id === $stripe_source_id ) { |
|
400 | - if ( $source->sepa_debit ) { |
|
397 | + if ($sources) { |
|
398 | + foreach ($sources as $source) { |
|
399 | + if ($source->id === $stripe_source_id) { |
|
400 | + if ($source->sepa_debit) { |
|
401 | 401 | /* translators: 1) last 4 digits of SEPA Direct Debit */ |
402 | - $payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 ); |
|
402 | + $payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4); |
|
403 | 403 | } else { |
404 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
404 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
405 | 405 | } |
406 | 406 | break; |
407 | 407 | } |
@@ -416,42 +416,42 @@ discard block |
||
416 | 416 | * @param int $order_id |
417 | 417 | * @return array |
418 | 418 | */ |
419 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
420 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
419 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
420 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
421 | 421 | try { |
422 | - $order = wc_get_order( $order_id ); |
|
422 | + $order = wc_get_order($order_id); |
|
423 | 423 | |
424 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
424 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
425 | 425 | /* translators: minimum amount */ |
426 | - 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 ) ) ); |
|
426 | + 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))); |
|
427 | 427 | } |
428 | 428 | |
429 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
429 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
430 | 430 | |
431 | 431 | // We need a source on file to continue. |
432 | - if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) { |
|
433 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
432 | + if (empty($prepared_source->customer) || empty($prepared_source->source)) { |
|
433 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
434 | 434 | } |
435 | 435 | |
436 | - $this->save_source_to_order( $order, $prepared_source ); |
|
436 | + $this->save_source_to_order($order, $prepared_source); |
|
437 | 437 | |
438 | 438 | // Remove cart |
439 | 439 | WC()->cart->empty_cart(); |
440 | 440 | |
441 | 441 | // Is pre ordered! |
442 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
442 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
443 | 443 | |
444 | 444 | // Return thank you page redirect |
445 | 445 | return array( |
446 | 446 | 'result' => 'success', |
447 | - 'redirect' => $this->get_return_url( $order ), |
|
447 | + 'redirect' => $this->get_return_url($order), |
|
448 | 448 | ); |
449 | - } catch ( Exception $e ) { |
|
450 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
449 | + } catch (Exception $e) { |
|
450 | + wc_add_notice($e->getMessage(), 'error'); |
|
451 | 451 | return; |
452 | 452 | } |
453 | 453 | } else { |
454 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
454 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
455 | 455 | } |
456 | 456 | } |
457 | 457 | |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * @param WC_Order $order |
461 | 461 | * @return void |
462 | 462 | */ |
463 | - public function process_pre_order_release_payment( $order ) { |
|
463 | + public function process_pre_order_release_payment($order) { |
|
464 | 464 | try { |
465 | 465 | // Define some callbacks if the first attempt fails. |
466 | 466 | $retry_callbacks = array( |
@@ -468,33 +468,33 @@ discard block |
||
468 | 468 | 'remove_order_customer_before_retry', |
469 | 469 | ); |
470 | 470 | |
471 | - while ( 1 ) { |
|
472 | - $source = $this->prepare_order_source( $order ); |
|
473 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
471 | + while (1) { |
|
472 | + $source = $this->prepare_order_source($order); |
|
473 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
474 | 474 | |
475 | - if ( ! empty( $response->error ) ) { |
|
476 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
477 | - throw new Exception( $response->error->message ); |
|
475 | + if ( ! empty($response->error)) { |
|
476 | + if (0 === sizeof($retry_callbacks)) { |
|
477 | + throw new Exception($response->error->message); |
|
478 | 478 | } else { |
479 | - $retry_callback = array_shift( $retry_callbacks ); |
|
480 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
479 | + $retry_callback = array_shift($retry_callbacks); |
|
480 | + call_user_func(array($this, $retry_callback), $order); |
|
481 | 481 | } |
482 | 482 | } else { |
483 | 483 | // Successful |
484 | - $this->process_response( $response, $order ); |
|
484 | + $this->process_response($response, $order); |
|
485 | 485 | break; |
486 | 486 | } |
487 | 487 | } |
488 | - } catch ( Exception $e ) { |
|
488 | + } catch (Exception $e) { |
|
489 | 489 | /* translators: error message */ |
490 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
490 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
491 | 491 | |
492 | 492 | // Mark order as failed if not already set, |
493 | 493 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
494 | - if ( ! $order->has_status( 'failed' ) ) { |
|
495 | - $order->update_status( 'failed', $order_note ); |
|
494 | + if ( ! $order->has_status('failed')) { |
|
495 | + $order->update_status('failed', $order_note); |
|
496 | 496 | } else { |
497 | - $order->add_order_note( $order_note ); |
|
497 | + $order->add_order_note($order_note); |
|
498 | 498 | } |
499 | 499 | } |
500 | 500 | } |