@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | |
315 | 315 | /** |
316 | 316 | * Don't transfer Stripe fee/ID meta to renewal orders. |
317 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
317 | + * @param integer $renewal_order |
|
318 | 318 | */ |
319 | 319 | public function delete_renewal_meta( $renewal_order ) { |
320 | 320 | delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
@@ -556,6 +556,8 @@ discard block |
||
556 | 556 | /** |
557 | 557 | * Process the pre-order |
558 | 558 | * @param int $order_id |
559 | + * @param boolean $retry |
|
560 | + * @param boolean $force_save_source |
|
559 | 561 | * @return array |
560 | 562 | */ |
561 | 563 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
@@ -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,23 +15,23 @@ 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' ) ); |
|
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 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
34 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
33 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
34 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * @since 4.0.0 |
43 | 43 | * @version 4.0.0 |
44 | 44 | */ |
45 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
46 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
45 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
46 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | * @param int $order_id |
56 | 56 | * @return boolean |
57 | 57 | */ |
58 | - public function has_subscription( $order_id ) { |
|
59 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
58 | + public function has_subscription($order_id) { |
|
59 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return bool |
67 | 67 | */ |
68 | 68 | public function is_subs_change_payment() { |
69 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
69 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @param int $order_id |
75 | 75 | * @return boolean |
76 | 76 | */ |
77 | - public function is_pre_order( $order_id ) { |
|
78 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
77 | + public function is_pre_order($order_id) { |
|
78 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,24 +84,24 @@ discard block |
||
84 | 84 | * @since 4.0.4 |
85 | 85 | * @param int $order_id |
86 | 86 | */ |
87 | - public function change_subs_payment_method( $order_id ) { |
|
87 | + public function change_subs_payment_method($order_id) { |
|
88 | 88 | try { |
89 | - $subscription = wc_get_order( $order_id ); |
|
90 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
89 | + $subscription = wc_get_order($order_id); |
|
90 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
91 | 91 | $source_object = $prepared_source->source_object; |
92 | 92 | |
93 | 93 | // Check if we don't allow prepaid credit cards. |
94 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) { |
|
95 | - $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' ); |
|
96 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
94 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) { |
|
95 | + $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'); |
|
96 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( empty( $prepared_source->source ) ) { |
|
100 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
101 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
99 | + if (empty($prepared_source->source)) { |
|
100 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
101 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
102 | 102 | } |
103 | 103 | |
104 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
104 | + $this->save_source_to_order($subscription, $prepared_source); |
|
105 | 105 | |
106 | 106 | /* |
107 | 107 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -110,41 +110,41 @@ discard block |
||
110 | 110 | * Note that if we need to save source, the original source must be first |
111 | 111 | * attached to a customer in Stripe before it can be charged. |
112 | 112 | */ |
113 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
113 | + if ($this->is_3ds_required($source_object)) { |
|
114 | 114 | $order = $subscription->get_parent(); |
115 | - $response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() ); |
|
115 | + $response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url()); |
|
116 | 116 | |
117 | - if ( ! empty( $response->error ) ) { |
|
117 | + if ( ! empty($response->error)) { |
|
118 | 118 | $localized_message = $response->error->message; |
119 | 119 | |
120 | - $order->add_order_note( $localized_message ); |
|
120 | + $order->add_order_note($localized_message); |
|
121 | 121 | |
122 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
122 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // Update order meta with 3DS source. |
126 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
127 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
126 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
127 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
128 | 128 | } else { |
129 | - $subscription->update_meta_data( '_stripe_source_id', $response->id ); |
|
129 | + $subscription->update_meta_data('_stripe_source_id', $response->id); |
|
130 | 130 | $subscription->save(); |
131 | 131 | } |
132 | 132 | |
133 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
133 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
134 | 134 | |
135 | 135 | return array( |
136 | 136 | 'result' => 'success', |
137 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
137 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
138 | 138 | ); |
139 | 139 | } |
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 | |
@@ -153,18 +153,18 @@ discard block |
||
153 | 153 | * @param int $order_id |
154 | 154 | * @return array |
155 | 155 | */ |
156 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
157 | - if ( $this->has_subscription( $order_id ) ) { |
|
158 | - if ( $this->is_subs_change_payment() ) { |
|
159 | - return $this->change_subs_payment_method( $order_id ); |
|
156 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
157 | + if ($this->has_subscription($order_id)) { |
|
158 | + if ($this->is_subs_change_payment()) { |
|
159 | + return $this->change_subs_payment_method($order_id); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | // Regular payment with force customer enabled |
163 | - return parent::process_payment( $order_id, true, true ); |
|
164 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
165 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
163 | + return parent::process_payment($order_id, true, true); |
|
164 | + } elseif ($this->is_pre_order($order_id)) { |
|
165 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
166 | 166 | } else { |
167 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
167 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
@@ -174,24 +174,24 @@ discard block |
||
174 | 174 | * @since 3.1.0 |
175 | 175 | * @version 4.0.0 |
176 | 176 | */ |
177 | - public function save_source_to_order( $order, $source ) { |
|
178 | - parent::save_source_to_order( $order, $source ); |
|
177 | + public function save_source_to_order($order, $source) { |
|
178 | + parent::save_source_to_order($order, $source); |
|
179 | 179 | |
180 | 180 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
181 | 181 | |
182 | 182 | // Also store it on the subscriptions being purchased or paid for in the order |
183 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
184 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
185 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
186 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
183 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
184 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
185 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
186 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
187 | 187 | } else { |
188 | 188 | $subscriptions = array(); |
189 | 189 | } |
190 | 190 | |
191 | - foreach ( $subscriptions as $subscription ) { |
|
191 | + foreach ($subscriptions as $subscription) { |
|
192 | 192 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
193 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
194 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
193 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
194 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
@@ -204,45 +204,45 @@ discard block |
||
204 | 204 | * @param mixed $renewal_order |
205 | 205 | * @param bool $is_retry Is this a retry process. |
206 | 206 | */ |
207 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
208 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
207 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) { |
|
208 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
209 | 209 | /* translators: minimum amount */ |
210 | - 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 ) ) ); |
|
210 | + 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))); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
214 | 214 | |
215 | 215 | // Get source from order |
216 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
216 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
217 | 217 | |
218 | - if ( ! $prepared_source->customer ) { |
|
219 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
218 | + if ( ! $prepared_source->customer) { |
|
219 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
220 | 220 | } |
221 | 221 | |
222 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
222 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
223 | 223 | |
224 | - if ( $is_retry ) { |
|
224 | + if ($is_retry) { |
|
225 | 225 | // Passing empty source with charge customer default. |
226 | 226 | $prepared_source->source = ''; |
227 | 227 | } |
228 | 228 | |
229 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
229 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
230 | 230 | $request['capture'] = 'true'; |
231 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
232 | - $response = WC_Stripe_API::request( $request ); |
|
231 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
232 | + $response = WC_Stripe_API::request($request); |
|
233 | 233 | |
234 | - if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
235 | - if ( $is_retry ) { |
|
234 | + if ( ! empty($response->error) || is_wp_error($response)) { |
|
235 | + if ($is_retry) { |
|
236 | 236 | /* translators: error message */ |
237 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
237 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | return $response; // Default catch all errors. |
241 | 241 | } |
242 | 242 | |
243 | - $this->process_response( $response, $renewal_order ); |
|
243 | + $this->process_response($response, $renewal_order); |
|
244 | 244 | |
245 | - if ( ! $is_retry ) { |
|
245 | + if ( ! $is_retry) { |
|
246 | 246 | return $response; |
247 | 247 | } |
248 | 248 | } |
@@ -251,21 +251,21 @@ discard block |
||
251 | 251 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
252 | 252 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
253 | 253 | */ |
254 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
255 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
256 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
254 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
255 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
256 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
257 | 257 | // For BW compat will remove in future |
258 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
259 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
258 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
259 | + $this->delete_renewal_meta($resubscribe_order); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Don't transfer Stripe fee/ID meta to renewal orders. |
264 | 264 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
265 | 265 | */ |
266 | - public function delete_renewal_meta( $renewal_order ) { |
|
267 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
268 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
266 | + public function delete_renewal_meta($renewal_order) { |
|
267 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
268 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
269 | 269 | return $renewal_order; |
270 | 270 | } |
271 | 271 | |
@@ -275,21 +275,21 @@ discard block |
||
275 | 275 | * @param $amount_to_charge float The amount to charge. |
276 | 276 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
277 | 277 | */ |
278 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
279 | - $response = $this->process_subscription_payment( $amount_to_charge, $renewal_order ); |
|
278 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
279 | + $response = $this->process_subscription_payment($amount_to_charge, $renewal_order); |
|
280 | 280 | |
281 | - if ( is_wp_error( $response ) ) { |
|
281 | + if (is_wp_error($response)) { |
|
282 | 282 | /* translators: error message */ |
283 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
283 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
284 | 284 | } |
285 | 285 | |
286 | - if ( ! empty( $response->error ) ) { |
|
286 | + if ( ! empty($response->error)) { |
|
287 | 287 | // This is a very generic error to listen for but worth a retry before total fail. |
288 | - if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
289 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true ); |
|
288 | + if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
289 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true); |
|
290 | 290 | } else { |
291 | 291 | /* translators: error message */ |
292 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
292 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | } |
@@ -298,20 +298,20 @@ discard block |
||
298 | 298 | * Remove order meta |
299 | 299 | * @param object $order |
300 | 300 | */ |
301 | - public function remove_order_source_before_retry( $order ) { |
|
301 | + public function remove_order_source_before_retry($order) { |
|
302 | 302 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
303 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
303 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
304 | 304 | // For BW compat will remove in the future. |
305 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
305 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | 309 | * Remove order meta |
310 | 310 | * @param object $order |
311 | 311 | */ |
312 | - public function remove_order_customer_before_retry( $order ) { |
|
312 | + public function remove_order_customer_before_retry($order) { |
|
313 | 313 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
314 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
314 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -323,14 +323,14 @@ discard block |
||
323 | 323 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
324 | 324 | * @return void |
325 | 325 | */ |
326 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
327 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
328 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
329 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
326 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
327 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
328 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
329 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
330 | 330 | |
331 | 331 | } else { |
332 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
333 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
332 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
333 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
@@ -343,21 +343,21 @@ discard block |
||
343 | 343 | * @param WC_Subscription $subscription An instance of a subscription object |
344 | 344 | * @return array |
345 | 345 | */ |
346 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
347 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
346 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
347 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
348 | 348 | |
349 | 349 | // For BW compat will remove in future. |
350 | - if ( empty( $source_id ) ) { |
|
351 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
350 | + if (empty($source_id)) { |
|
351 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
352 | 352 | |
353 | 353 | // Take this opportunity to update the key name. |
354 | - 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 ); |
|
354 | + 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); |
|
355 | 355 | } |
356 | 356 | |
357 | - $payment_meta[ $this->id ] = array( |
|
357 | + $payment_meta[$this->id] = array( |
|
358 | 358 | 'post_meta' => array( |
359 | 359 | '_stripe_customer_id' => array( |
360 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
360 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
361 | 361 | 'label' => 'Stripe Customer ID', |
362 | 362 | ), |
363 | 363 | '_stripe_source_id' => array( |
@@ -380,22 +380,22 @@ discard block |
||
380 | 380 | * @param array $payment_meta associative array of meta data required for automatic payments |
381 | 381 | * @return array |
382 | 382 | */ |
383 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
384 | - if ( $this->id === $payment_method_id ) { |
|
383 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
384 | + if ($this->id === $payment_method_id) { |
|
385 | 385 | |
386 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
387 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
388 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
389 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
386 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
387 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
388 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
389 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | if ( |
393 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
394 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
395 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
396 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
393 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
394 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
395 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
396 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
397 | 397 | |
398 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
398 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | } |
@@ -408,91 +408,91 @@ discard block |
||
408 | 408 | * @param WC_Subscription $subscription the subscription details |
409 | 409 | * @return string the subscription payment method |
410 | 410 | */ |
411 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
411 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
412 | 412 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
413 | 413 | |
414 | 414 | // bail for other payment methods |
415 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
415 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
416 | 416 | return $payment_method_to_display; |
417 | 417 | } |
418 | 418 | |
419 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
419 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
420 | 420 | |
421 | 421 | // For BW compat will remove in future. |
422 | - if ( empty( $stripe_source_id ) ) { |
|
423 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
422 | + if (empty($stripe_source_id)) { |
|
423 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
424 | 424 | |
425 | 425 | // Take this opportunity to update the key name. |
426 | - 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 ); |
|
426 | + 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); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | $stripe_customer = new WC_Stripe_Customer(); |
430 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
430 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
431 | 431 | |
432 | 432 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
433 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
433 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
434 | 434 | $user_id = $customer_user; |
435 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
436 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
435 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
436 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
437 | 437 | |
438 | 438 | // For BW compat will remove in future. |
439 | - if ( empty( $stripe_source_id ) ) { |
|
440 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
439 | + if (empty($stripe_source_id)) { |
|
440 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
441 | 441 | |
442 | 442 | // Take this opportunity to update the key name. |
443 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
443 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
447 | 447 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
448 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
449 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
450 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
448 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
449 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
450 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
451 | 451 | |
452 | 452 | // For BW compat will remove in future. |
453 | - if ( empty( $stripe_source_id ) ) { |
|
454 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
453 | + if (empty($stripe_source_id)) { |
|
454 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
455 | 455 | |
456 | 456 | // Take this opportunity to update the key name. |
457 | - 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 ); |
|
457 | + 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); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
461 | + $stripe_customer->set_id($stripe_customer_id); |
|
462 | 462 | $sources = $stripe_customer->get_sources(); |
463 | 463 | |
464 | - if ( $sources ) { |
|
464 | + if ($sources) { |
|
465 | 465 | $found_source = false; |
466 | - foreach ( $sources as $source ) { |
|
467 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
466 | + foreach ($sources as $source) { |
|
467 | + if (isset($source->type) && 'card' === $source->type) { |
|
468 | 468 | $card = $source->card; |
469 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
469 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
470 | 470 | $card = $source; |
471 | 471 | } |
472 | 472 | |
473 | - if ( $source->id === $stripe_source_id ) { |
|
473 | + if ($source->id === $stripe_source_id) { |
|
474 | 474 | $found_source = true; |
475 | 475 | |
476 | - if ( $card ) { |
|
476 | + if ($card) { |
|
477 | 477 | /* translators: 1) card brand 2) last 4 digits */ |
478 | - $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 ); |
|
478 | + $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); |
|
479 | 479 | } else { |
480 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
480 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
481 | 481 | } |
482 | 482 | break; |
483 | 483 | } |
484 | 484 | } |
485 | 485 | |
486 | - if ( ! $found_source ) { |
|
487 | - if ( 'card' === $sources[0]->type ) { |
|
486 | + if ( ! $found_source) { |
|
487 | + if ('card' === $sources[0]->type) { |
|
488 | 488 | $card = $sources[0]->card; |
489 | 489 | } |
490 | 490 | |
491 | - if ( $card ) { |
|
491 | + if ($card) { |
|
492 | 492 | /* translators: 1) card brand 2) last 4 digits */ |
493 | - $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 ); |
|
493 | + $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); |
|
494 | 494 | } else { |
495 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
495 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
496 | 496 | } |
497 | 497 | } |
498 | 498 | } |
@@ -505,42 +505,42 @@ discard block |
||
505 | 505 | * @param int $order_id |
506 | 506 | * @return array |
507 | 507 | */ |
508 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
509 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
508 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
509 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
510 | 510 | try { |
511 | - $order = wc_get_order( $order_id ); |
|
511 | + $order = wc_get_order($order_id); |
|
512 | 512 | |
513 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
513 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
514 | 514 | /* translators: minimum amount */ |
515 | - 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 ) ) ); |
|
515 | + 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))); |
|
516 | 516 | } |
517 | 517 | |
518 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
518 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
519 | 519 | |
520 | 520 | // We need a source on file to continue. |
521 | - if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) { |
|
522 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
521 | + if (empty($prepared_source->customer) || empty($prepared_source->source)) { |
|
522 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
523 | 523 | } |
524 | 524 | |
525 | - $this->save_source_to_order( $order, $prepared_source ); |
|
525 | + $this->save_source_to_order($order, $prepared_source); |
|
526 | 526 | |
527 | 527 | // Remove cart |
528 | 528 | WC()->cart->empty_cart(); |
529 | 529 | |
530 | 530 | // Is pre ordered! |
531 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
531 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
532 | 532 | |
533 | 533 | // Return thank you page redirect |
534 | 534 | return array( |
535 | 535 | 'result' => 'success', |
536 | - 'redirect' => $this->get_return_url( $order ), |
|
536 | + 'redirect' => $this->get_return_url($order), |
|
537 | 537 | ); |
538 | - } catch ( Exception $e ) { |
|
539 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
538 | + } catch (Exception $e) { |
|
539 | + wc_add_notice($e->getMessage(), 'error'); |
|
540 | 540 | return; |
541 | 541 | } |
542 | 542 | } else { |
543 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
543 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
544 | 544 | } |
545 | 545 | } |
546 | 546 | |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * @param WC_Order $order |
550 | 550 | * @return void |
551 | 551 | */ |
552 | - public function process_pre_order_release_payment( $order ) { |
|
552 | + public function process_pre_order_release_payment($order) { |
|
553 | 553 | try { |
554 | 554 | // Define some callbacks if the first attempt fails. |
555 | 555 | $retry_callbacks = array( |
@@ -557,33 +557,33 @@ discard block |
||
557 | 557 | 'remove_order_customer_before_retry', |
558 | 558 | ); |
559 | 559 | |
560 | - while ( 1 ) { |
|
561 | - $source = $this->prepare_order_source( $order ); |
|
562 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
560 | + while (1) { |
|
561 | + $source = $this->prepare_order_source($order); |
|
562 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
563 | 563 | |
564 | - if ( ! empty( $response->error ) ) { |
|
565 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
566 | - throw new Exception( $response->error->message ); |
|
564 | + if ( ! empty($response->error)) { |
|
565 | + if (0 === sizeof($retry_callbacks)) { |
|
566 | + throw new Exception($response->error->message); |
|
567 | 567 | } else { |
568 | - $retry_callback = array_shift( $retry_callbacks ); |
|
569 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
568 | + $retry_callback = array_shift($retry_callbacks); |
|
569 | + call_user_func(array($this, $retry_callback), $order); |
|
570 | 570 | } |
571 | 571 | } else { |
572 | 572 | // Successful |
573 | - $this->process_response( $response, $order ); |
|
573 | + $this->process_response($response, $order); |
|
574 | 574 | break; |
575 | 575 | } |
576 | 576 | } |
577 | - } catch ( Exception $e ) { |
|
577 | + } catch (Exception $e) { |
|
578 | 578 | /* translators: error message */ |
579 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
579 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
580 | 580 | |
581 | 581 | // Mark order as failed if not already set, |
582 | 582 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
583 | - if ( ! $order->has_status( 'failed' ) ) { |
|
584 | - $order->update_status( 'failed', $order_note ); |
|
583 | + if ( ! $order->has_status('failed')) { |
|
584 | + $order->update_status('failed', $order_note); |
|
585 | 585 | } else { |
586 | - $order->add_order_note( $order_note ); |
|
586 | + $order->add_order_note($order_note); |
|
587 | 587 | } |
588 | 588 | } |
589 | 589 | } |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | |
315 | 315 | /** |
316 | 316 | * Don't transfer Stripe fee/ID meta to renewal orders. |
317 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
317 | + * @param integer $renewal_order |
|
318 | 318 | */ |
319 | 319 | public function delete_renewal_meta( $renewal_order ) { |
320 | 320 | delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
@@ -556,6 +556,8 @@ discard block |
||
556 | 556 | /** |
557 | 557 | * Process the pre-order |
558 | 558 | * @param int $order_id |
559 | + * @param boolean $retry |
|
560 | + * @param boolean $force_save_source |
|
559 | 561 | * @return array |
560 | 562 | */ |
561 | 563 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
@@ -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,89 +341,89 @@ 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 ) { |
|
397 | + if ($sources) { |
|
398 | 398 | $found_source = false; |
399 | - foreach ( $sources as $source ) { |
|
400 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
399 | + foreach ($sources as $source) { |
|
400 | + if (isset($source->type) && 'card' === $source->type) { |
|
401 | 401 | $card = $source->card; |
402 | 402 | } |
403 | 403 | |
404 | - if ( $source->id === $stripe_source_id ) { |
|
404 | + if ($source->id === $stripe_source_id) { |
|
405 | 405 | $found_source = true; |
406 | 406 | |
407 | - if ( $card ) { |
|
407 | + if ($card) { |
|
408 | 408 | /* translators: 1) card brand 2) last 4 digits */ |
409 | - $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 ); |
|
409 | + $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); |
|
410 | 410 | } else { |
411 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
411 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
412 | 412 | } |
413 | 413 | break; |
414 | 414 | } |
415 | 415 | } |
416 | 416 | |
417 | - if ( ! $found_source ) { |
|
418 | - if ( 'card' === $sources[0]->type ) { |
|
417 | + if ( ! $found_source) { |
|
418 | + if ('card' === $sources[0]->type) { |
|
419 | 419 | $card = $sources[0]->card; |
420 | 420 | } |
421 | 421 | |
422 | - if ( $card ) { |
|
422 | + if ($card) { |
|
423 | 423 | /* translators: 1) card brand 2) last 4 digits */ |
424 | - $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 ); |
|
424 | + $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); |
|
425 | 425 | } else { |
426 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
426 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
427 | 427 | } |
428 | 428 | } |
429 | 429 | } |
@@ -436,42 +436,42 @@ discard block |
||
436 | 436 | * @param int $order_id |
437 | 437 | * @return array |
438 | 438 | */ |
439 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
440 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
439 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
440 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
441 | 441 | try { |
442 | - $order = wc_get_order( $order_id ); |
|
442 | + $order = wc_get_order($order_id); |
|
443 | 443 | |
444 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
444 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
445 | 445 | /* translators: minimum amount */ |
446 | - 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 ) ) ); |
|
446 | + 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))); |
|
447 | 447 | } |
448 | 448 | |
449 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
449 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
450 | 450 | |
451 | 451 | // We need a source on file to continue. |
452 | - if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) { |
|
453 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
452 | + if (empty($prepared_source->customer) || empty($prepared_source->source)) { |
|
453 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
454 | 454 | } |
455 | 455 | |
456 | - $this->save_source_to_order( $order, $prepared_source ); |
|
456 | + $this->save_source_to_order($order, $prepared_source); |
|
457 | 457 | |
458 | 458 | // Remove cart |
459 | 459 | WC()->cart->empty_cart(); |
460 | 460 | |
461 | 461 | // Is pre ordered! |
462 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
462 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
463 | 463 | |
464 | 464 | // Return thank you page redirect |
465 | 465 | return array( |
466 | 466 | 'result' => 'success', |
467 | - 'redirect' => $this->get_return_url( $order ), |
|
467 | + 'redirect' => $this->get_return_url($order), |
|
468 | 468 | ); |
469 | - } catch ( Exception $e ) { |
|
470 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
469 | + } catch (Exception $e) { |
|
470 | + wc_add_notice($e->getMessage(), 'error'); |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | } else { |
474 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
474 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
475 | 475 | } |
476 | 476 | } |
477 | 477 | |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @param WC_Order $order |
481 | 481 | * @return void |
482 | 482 | */ |
483 | - public function process_pre_order_release_payment( $order ) { |
|
483 | + public function process_pre_order_release_payment($order) { |
|
484 | 484 | try { |
485 | 485 | // Define some callbacks if the first attempt fails. |
486 | 486 | $retry_callbacks = array( |
@@ -488,33 +488,33 @@ discard block |
||
488 | 488 | 'remove_order_customer_before_retry', |
489 | 489 | ); |
490 | 490 | |
491 | - while ( 1 ) { |
|
492 | - $source = $this->prepare_order_source( $order ); |
|
493 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
491 | + while (1) { |
|
492 | + $source = $this->prepare_order_source($order); |
|
493 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
494 | 494 | |
495 | - if ( ! empty( $response->error ) ) { |
|
496 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
497 | - throw new Exception( $response->error->message ); |
|
495 | + if ( ! empty($response->error)) { |
|
496 | + if (0 === sizeof($retry_callbacks)) { |
|
497 | + throw new Exception($response->error->message); |
|
498 | 498 | } else { |
499 | - $retry_callback = array_shift( $retry_callbacks ); |
|
500 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
499 | + $retry_callback = array_shift($retry_callbacks); |
|
500 | + call_user_func(array($this, $retry_callback), $order); |
|
501 | 501 | } |
502 | 502 | } else { |
503 | 503 | // Successful |
504 | - $this->process_response( $response, $order ); |
|
504 | + $this->process_response($response, $order); |
|
505 | 505 | break; |
506 | 506 | } |
507 | 507 | } |
508 | - } catch ( Exception $e ) { |
|
508 | + } catch (Exception $e) { |
|
509 | 509 | /* translators: error message */ |
510 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
510 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
511 | 511 | |
512 | 512 | // Mark order as failed if not already set, |
513 | 513 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
514 | - if ( ! $order->has_status( 'failed' ) ) { |
|
515 | - $order->update_status( 'failed', $order_note ); |
|
514 | + if ( ! $order->has_status('failed')) { |
|
515 | + $order->update_status('failed', $order_note); |
|
516 | 516 | } else { |
517 | - $order->add_order_note( $order_note ); |
|
517 | + $order->add_order_note($order_note); |
|
518 | 518 | } |
519 | 519 | } |
520 | 520 | } |
@@ -213,7 +213,6 @@ |
||
213 | 213 | /** |
214 | 214 | * Get a customers saved sources using their Stripe ID. |
215 | 215 | * |
216 | - * @param string $customer_id |
|
217 | 216 | * @return array |
218 | 217 | */ |
219 | 218 | public function get_sources() { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * Constructor |
33 | 33 | * @param int $user_id The WP user ID |
34 | 34 | */ |
35 | - public function __construct( $user_id = 0 ) { |
|
36 | - if ( $user_id ) { |
|
37 | - $this->set_user_id( $user_id ); |
|
38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
35 | + public function __construct($user_id = 0) { |
|
36 | + if ($user_id) { |
|
37 | + $this->set_user_id($user_id); |
|
38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * Set Stripe customer ID. |
52 | 52 | * @param [type] $id [description] |
53 | 53 | */ |
54 | - public function set_id( $id ) { |
|
55 | - $this->id = wc_clean( $id ); |
|
54 | + public function set_id($id) { |
|
55 | + $this->id = wc_clean($id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | * @return int |
61 | 61 | */ |
62 | 62 | public function get_user_id() { |
63 | - return absint( $this->user_id ); |
|
63 | + return absint($this->user_id); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Set User ID used by WordPress. |
68 | 68 | * @param int $user_id |
69 | 69 | */ |
70 | - public function set_user_id( $user_id ) { |
|
71 | - $this->user_id = absint( $user_id ); |
|
70 | + public function set_user_id($user_id) { |
|
71 | + $this->user_id = absint($user_id); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | * @return WP_User |
77 | 77 | */ |
78 | 78 | protected function get_user() { |
79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Store data from the Stripe API about this customer |
84 | 84 | */ |
85 | - public function set_customer_data( $data ) { |
|
85 | + public function set_customer_data($data) { |
|
86 | 86 | $this->customer_data = $data; |
87 | 87 | } |
88 | 88 | |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | * @param array $args |
92 | 92 | * @return WP_Error|int |
93 | 93 | */ |
94 | - public function create_customer( $args = array() ) { |
|
95 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
94 | + public function create_customer($args = array()) { |
|
95 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
96 | 96 | $user = $this->get_user(); |
97 | 97 | |
98 | - if ( $user ) { |
|
99 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
100 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
98 | + if ($user) { |
|
99 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
100 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
101 | 101 | |
102 | 102 | $defaults = array( |
103 | 103 | 'email' => $user->user_email, |
@@ -112,24 +112,24 @@ discard block |
||
112 | 112 | |
113 | 113 | $metadata = array(); |
114 | 114 | |
115 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
115 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
116 | 116 | |
117 | - $args = wp_parse_args( $args, $defaults ); |
|
118 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
117 | + $args = wp_parse_args($args, $defaults); |
|
118 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
119 | 119 | |
120 | - if ( ! empty( $response->error ) ) { |
|
121 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
120 | + if ( ! empty($response->error)) { |
|
121 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->set_id( $response->id ); |
|
124 | + $this->set_id($response->id); |
|
125 | 125 | $this->clear_cache(); |
126 | - $this->set_customer_data( $response ); |
|
126 | + $this->set_customer_data($response); |
|
127 | 127 | |
128 | - if ( $this->get_user_id() ) { |
|
129 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
128 | + if ($this->get_user_id()) { |
|
129 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
130 | 130 | } |
131 | 131 | |
132 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
132 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
133 | 133 | |
134 | 134 | return $response->id; |
135 | 135 | } |
@@ -140,72 +140,72 @@ discard block |
||
140 | 140 | * @param bool $retry |
141 | 141 | * @return WP_Error|int |
142 | 142 | */ |
143 | - public function add_source( $source_id, $retry = true ) { |
|
144 | - if ( ! $this->get_id() ) { |
|
145 | - $this->set_id( $this->create_customer() ); |
|
143 | + public function add_source($source_id, $retry = true) { |
|
144 | + if ( ! $this->get_id()) { |
|
145 | + $this->set_id($this->create_customer()); |
|
146 | 146 | } |
147 | 147 | |
148 | - $response = WC_Stripe_API::request( array( |
|
148 | + $response = WC_Stripe_API::request(array( |
|
149 | 149 | 'source' => $source_id, |
150 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
150 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
151 | 151 | |
152 | - if ( ! empty( $response->error ) ) { |
|
152 | + if ( ! empty($response->error)) { |
|
153 | 153 | // It is possible the WC user once was linked to a customer on Stripe |
154 | 154 | // but no longer exists. Instead of failing, lets try to create a |
155 | 155 | // new customer. |
156 | - if ( preg_match( '/No such customer/i', $response->error->message ) ) { |
|
157 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
156 | + if (preg_match('/No such customer/i', $response->error->message)) { |
|
157 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
158 | 158 | $this->create_customer(); |
159 | - return $this->add_source( $source_id, false ); |
|
159 | + return $this->add_source($source_id, false); |
|
160 | 160 | } else { |
161 | 161 | return $response; |
162 | 162 | } |
163 | - } elseif ( empty( $response->id ) ) { |
|
164 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
163 | + } elseif (empty($response->id)) { |
|
164 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // Add token to WooCommerce. |
168 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
169 | - if ( ! empty( $response->type ) ) { |
|
170 | - switch ( $response->type ) { |
|
168 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
169 | + if ( ! empty($response->type)) { |
|
170 | + switch ($response->type) { |
|
171 | 171 | case 'alipay': |
172 | 172 | break; |
173 | 173 | case 'sepa_debit': |
174 | 174 | $wc_token = new WC_Payment_Token_SEPA(); |
175 | - $wc_token->set_token( $response->id ); |
|
176 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
177 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
175 | + $wc_token->set_token($response->id); |
|
176 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
177 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
178 | 178 | break; |
179 | 179 | default: |
180 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
180 | + if ('source' === $response->object && 'card' === $response->type) { |
|
181 | 181 | $wc_token = new WC_Payment_Token_CC(); |
182 | - $wc_token->set_token( $response->id ); |
|
183 | - $wc_token->set_gateway_id( 'stripe' ); |
|
184 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
185 | - $wc_token->set_last4( $response->card->last4 ); |
|
186 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
187 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
182 | + $wc_token->set_token($response->id); |
|
183 | + $wc_token->set_gateway_id('stripe'); |
|
184 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
185 | + $wc_token->set_last4($response->card->last4); |
|
186 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
187 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
188 | 188 | } |
189 | 189 | break; |
190 | 190 | } |
191 | 191 | } else { |
192 | 192 | // Legacy. |
193 | 193 | $wc_token = new WC_Payment_Token_CC(); |
194 | - $wc_token->set_token( $response->id ); |
|
195 | - $wc_token->set_gateway_id( 'stripe' ); |
|
196 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
197 | - $wc_token->set_last4( $response->last4 ); |
|
198 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
199 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
194 | + $wc_token->set_token($response->id); |
|
195 | + $wc_token->set_gateway_id('stripe'); |
|
196 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
197 | + $wc_token->set_last4($response->last4); |
|
198 | + $wc_token->set_expiry_month($response->exp_month); |
|
199 | + $wc_token->set_expiry_year($response->exp_year); |
|
200 | 200 | } |
201 | 201 | |
202 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
202 | + $wc_token->set_user_id($this->get_user_id()); |
|
203 | 203 | $wc_token->save(); |
204 | 204 | } |
205 | 205 | |
206 | 206 | $this->clear_cache(); |
207 | 207 | |
208 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
208 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
209 | 209 | |
210 | 210 | return $response->id; |
211 | 211 | } |
@@ -217,42 +217,42 @@ discard block |
||
217 | 217 | * @return array |
218 | 218 | */ |
219 | 219 | public function get_sources() { |
220 | - if ( ! $this->get_id() ) { |
|
220 | + if ( ! $this->get_id()) { |
|
221 | 221 | return array(); |
222 | 222 | } |
223 | 223 | |
224 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
224 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
225 | 225 | |
226 | - $response = WC_Stripe_API::request( array( |
|
226 | + $response = WC_Stripe_API::request(array( |
|
227 | 227 | 'limit' => 100, |
228 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
228 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
229 | 229 | |
230 | - if ( ! empty( $response->error ) ) { |
|
230 | + if ( ! empty($response->error)) { |
|
231 | 231 | return array(); |
232 | 232 | } |
233 | 233 | |
234 | - if ( is_array( $response->data ) ) { |
|
234 | + if (is_array($response->data)) { |
|
235 | 235 | $sources = $response->data; |
236 | 236 | } |
237 | 237 | |
238 | - return empty( $sources ) ? array() : $sources; |
|
238 | + return empty($sources) ? array() : $sources; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
242 | 242 | * Delete a source from stripe. |
243 | 243 | * @param string $source_id |
244 | 244 | */ |
245 | - public function delete_source( $source_id ) { |
|
246 | - if ( ! $this->get_id() ) { |
|
245 | + public function delete_source($source_id) { |
|
246 | + if ( ! $this->get_id()) { |
|
247 | 247 | return false; |
248 | 248 | } |
249 | 249 | |
250 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
250 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
251 | 251 | |
252 | 252 | $this->clear_cache(); |
253 | 253 | |
254 | - if ( empty( $response->error ) ) { |
|
255 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
254 | + if (empty($response->error)) { |
|
255 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
256 | 256 | |
257 | 257 | return true; |
258 | 258 | } |
@@ -264,15 +264,15 @@ discard block |
||
264 | 264 | * Set default source in Stripe |
265 | 265 | * @param string $source_id |
266 | 266 | */ |
267 | - public function set_default_source( $source_id ) { |
|
268 | - $response = WC_Stripe_API::request( array( |
|
269 | - 'default_source' => sanitize_text_field( $source_id ), |
|
270 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
267 | + public function set_default_source($source_id) { |
|
268 | + $response = WC_Stripe_API::request(array( |
|
269 | + 'default_source' => sanitize_text_field($source_id), |
|
270 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
271 | 271 | |
272 | 272 | $this->clear_cache(); |
273 | 273 | |
274 | - if ( empty( $response->error ) ) { |
|
275 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
274 | + if (empty($response->error)) { |
|
275 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
276 | 276 | |
277 | 277 | return true; |
278 | 278 | } |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * Deletes caches for this users cards. |
285 | 285 | */ |
286 | 286 | public function clear_cache() { |
287 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
288 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
287 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
288 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
289 | 289 | $this->customer_data = array(); |
290 | 290 | } |
291 | 291 | } |
@@ -2,12 +2,12 @@ discard block |
||
2 | 2 | |
3 | 3 | class WC_Stripe_Test extends WP_UnitTestCase { |
4 | 4 | public function test_constants_defined() { |
5 | - $this->assertTrue( defined( 'WC_STRIPE_VERSION' ) ); |
|
6 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) ); |
|
7 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) ); |
|
8 | - $this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) ); |
|
9 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) ); |
|
10 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) ); |
|
5 | + $this->assertTrue(defined('WC_STRIPE_VERSION')); |
|
6 | + $this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER')); |
|
7 | + $this->assertTrue(defined('WC_STRIPE_MIN_WC_VER')); |
|
8 | + $this->assertTrue(defined('WC_STRIPE_MAIN_FILE')); |
|
9 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_URL')); |
|
10 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH')); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * This test will see if we're indeed converting the price correctly. |
16 | 16 | */ |
17 | 17 | public function test_price_conversion_before_send_to_stripe() { |
18 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
19 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) ); |
|
20 | - $this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) ); |
|
21 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) ); |
|
22 | - $this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
18 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
19 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY')); |
|
20 | + $this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY')); |
|
21 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50)); |
|
22 | + $this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -33,37 +33,37 @@ discard block |
||
33 | 33 | $balance_fee1->net = 10000; |
34 | 34 | $balance_fee1->currency = 'USD'; |
35 | 35 | |
36 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) ); |
|
36 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee')); |
|
37 | 37 | |
38 | 38 | $balance_fee2 = new stdClass(); |
39 | 39 | $balance_fee2->fee = 10500; |
40 | 40 | $balance_fee2->net = 10000; |
41 | 41 | $balance_fee2->currency = 'JPY'; |
42 | 42 | |
43 | - $this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) ); |
|
43 | + $this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee')); |
|
44 | 44 | |
45 | 45 | $balance_fee3 = new stdClass(); |
46 | 46 | $balance_fee3->fee = 10500; |
47 | 47 | $balance_fee3->net = 10000; |
48 | 48 | $balance_fee3->currency = 'USD'; |
49 | 49 | |
50 | - $this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) ); |
|
50 | + $this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net')); |
|
51 | 51 | |
52 | 52 | $balance_fee4 = new stdClass(); |
53 | 53 | $balance_fee4->fee = 10500; |
54 | 54 | $balance_fee4->net = 10000; |
55 | 55 | $balance_fee4->currency = 'JPY'; |
56 | 56 | |
57 | - $this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) ); |
|
57 | + $this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net')); |
|
58 | 58 | |
59 | 59 | $balance_fee5 = new stdClass(); |
60 | 60 | $balance_fee5->fee = 10500; |
61 | 61 | $balance_fee5->net = 10000; |
62 | 62 | $balance_fee5->currency = 'USD'; |
63 | 63 | |
64 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
64 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
65 | 65 | |
66 | - $this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
66 | + $this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -76,28 +76,28 @@ discard block |
||
76 | 76 | 'expected' => 'Tests Store', |
77 | 77 | ); |
78 | 78 | |
79 | - $this->assertEquals( $statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor1['actual'] ) ); |
|
79 | + $this->assertEquals($statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor1['actual'])); |
|
80 | 80 | |
81 | 81 | $statement_descriptor2 = array( |
82 | 82 | 'actual' => 'Test\'s Store > Driving Course Range', |
83 | 83 | 'expected' => 'Tests Store Driving C', |
84 | 84 | ); |
85 | 85 | |
86 | - $this->assertEquals( $statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor2['actual'] ) ); |
|
86 | + $this->assertEquals($statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor2['actual'])); |
|
87 | 87 | |
88 | 88 | $statement_descriptor3 = array( |
89 | 89 | 'actual' => 'Test\'s Store < Driving Course Range', |
90 | 90 | 'expected' => 'Tests Store Driving C', |
91 | 91 | ); |
92 | 92 | |
93 | - $this->assertEquals( $statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor3['actual'] ) ); |
|
93 | + $this->assertEquals($statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor3['actual'])); |
|
94 | 94 | |
95 | 95 | $statement_descriptor4 = array( |
96 | 96 | 'actual' => 'Test\'s Store " Driving Course Range', |
97 | 97 | 'expected' => 'Tests Store Driving C', |
98 | 98 | ); |
99 | 99 | |
100 | - $this->assertEquals( $statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor4['actual'] ) ); |
|
100 | + $this->assertEquals($statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor4['actual'])); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | $source = new stdClass(); |
110 | 110 | $source->type = 'three_d_secure'; |
111 | 111 | |
112 | - $this->assertEquals( true, $stripe->is_3ds_card( $source ) ); |
|
112 | + $this->assertEquals(true, $stripe->is_3ds_card($source)); |
|
113 | 113 | |
114 | 114 | $source = new stdClass(); |
115 | 115 | $source->type = 'card'; |
116 | 116 | |
117 | - $this->assertEquals( false, $stripe->is_3ds_card( $source ) ); |
|
117 | + $this->assertEquals(false, $stripe->is_3ds_card($source)); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | $source->card = new stdClass(); |
129 | 129 | $source->card->three_d_secure = 'required'; |
130 | 130 | |
131 | - $this->assertEquals( true, $stripe->is_3ds_required( $source ) ); |
|
131 | + $this->assertEquals(true, $stripe->is_3ds_required($source)); |
|
132 | 132 | |
133 | 133 | $source = new stdClass(); |
134 | 134 | $source->type = 'card'; |
135 | 135 | $source->card = new stdClass(); |
136 | 136 | $source->card->three_d_secure = 'optional'; |
137 | 137 | |
138 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
138 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
139 | 139 | |
140 | 140 | $source = new stdClass(); |
141 | 141 | $source->type = 'card'; |
142 | 142 | $source->card = new stdClass(); |
143 | 143 | $source->card->three_d_secure = 'not_supported'; |
144 | 144 | |
145 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
145 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
146 | 146 | } |
147 | 147 | } |
@@ -1,28 +1,28 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$_tests_dir = getenv( 'WP_TESTS_DIR' ); |
|
4 | -if ( ! $_tests_dir ) { |
|
3 | +$_tests_dir = getenv('WP_TESTS_DIR'); |
|
4 | +if ( ! $_tests_dir) { |
|
5 | 5 | $_tests_dir = '/tmp/wordpress-tests-lib'; |
6 | 6 | } |
7 | 7 | |
8 | 8 | require_once $_tests_dir . '/includes/functions.php'; |
9 | 9 | |
10 | 10 | function _manually_load_plugin() { |
11 | - $plugin_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/'; |
|
11 | + $plugin_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/'; |
|
12 | 12 | require $plugin_dir . 'woocommerce-gateway-stripe/woocommerce-gateway-stripe.php'; |
13 | 13 | require $plugin_dir . 'woocommerce/woocommerce.php'; |
14 | 14 | } |
15 | 15 | |
16 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); |
|
16 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); |
|
17 | 17 | |
18 | 18 | require $_tests_dir . '/includes/bootstrap.php'; |
19 | 19 | |
20 | -$wc_tests_framework_base_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/tests/framework/'; |
|
21 | -require_once( $wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php' ); |
|
22 | -require_once( $wc_tests_framework_base_dir . 'class-wc-unit-test-case.php' ); |
|
23 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php' ); |
|
24 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php' ); |
|
25 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php' ); |
|
26 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php' ); |
|
27 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php' ); |
|
28 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php' ); |
|
20 | +$wc_tests_framework_base_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/woocommerce/tests/framework/'; |
|
21 | +require_once($wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php'); |
|
22 | +require_once($wc_tests_framework_base_dir . 'class-wc-unit-test-case.php'); |
|
23 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php'); |
|
24 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php'); |
|
25 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php'); |
|
26 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php'); |
|
27 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php'); |
|
28 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php'); |
@@ -104,7 +104,7 @@ |
||
104 | 104 | * Get this instance. |
105 | 105 | * |
106 | 106 | * @since 4.0.6 |
107 | - * @return class |
|
107 | + * @return WC_Stripe_Payment_Request |
|
108 | 108 | */ |
109 | 109 | public static function instance() { |
110 | 110 | return self::$_this; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 4.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -71,36 +71,36 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function __construct() { |
73 | 73 | self::$_this = $this; |
74 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
75 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
76 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
74 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
75 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
76 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
80 | 80 | |
81 | - if ( $this->testmode ) { |
|
82 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
81 | + if ($this->testmode) { |
|
82 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
84 | 84 | } |
85 | 85 | |
86 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
86 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
87 | 87 | |
88 | 88 | // Checks if Stripe Gateway is enabled. |
89 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
89 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | 93 | // Checks if Payment Request is enabled. |
94 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
94 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Don't load for change payment method page. |
99 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
99 | + if (isset($_GET['change_payment_method'])) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | - add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
103 | + add_action('template_redirect', array($this, 'set_session')); |
|
104 | 104 | $this->init(); |
105 | 105 | } |
106 | 106 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function are_keys_set() { |
114 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
114 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -135,19 +135,19 @@ discard block |
||
135 | 135 | * @since 4.0.0 |
136 | 136 | */ |
137 | 137 | public function set_session() { |
138 | - if ( ! is_product() ) { |
|
138 | + if ( ! is_product()) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | - if ( ! is_user_logged_in() ) { |
|
142 | + if ( ! is_user_logged_in()) { |
|
143 | 143 | $wc_session = new WC_Session_Handler(); |
144 | 144 | |
145 | - if ( version_compare( WC_VERSION, '3.3', '>=' ) ) { |
|
145 | + if (version_compare(WC_VERSION, '3.3', '>=')) { |
|
146 | 146 | $wc_session->init(); |
147 | 147 | } |
148 | 148 | |
149 | - if ( ! $wc_session->has_session() ) { |
|
150 | - $wc_session->set_customer_session_cookie( true ); |
|
149 | + if ( ! $wc_session->has_session()) { |
|
150 | + $wc_session->set_customer_session_cookie(true); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
@@ -159,40 +159,40 @@ discard block |
||
159 | 159 | * @version 4.0.0 |
160 | 160 | */ |
161 | 161 | public function init() { |
162 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
162 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
163 | 163 | |
164 | 164 | /* |
165 | 165 | * In order to display the Payment Request button in the correct position, |
166 | 166 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
167 | 167 | * CSS is used to position the button. |
168 | 168 | */ |
169 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
170 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
171 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
169 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
170 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
171 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
172 | 172 | } else { |
173 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
174 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
173 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
174 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
175 | 175 | } |
176 | 176 | |
177 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
178 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
177 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
178 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
179 | 179 | |
180 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
181 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
180 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
181 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
182 | 182 | |
183 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
184 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
185 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
186 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
187 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
188 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
189 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
190 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
183 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
184 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
185 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
186 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
187 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
188 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
189 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
190 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
191 | 191 | |
192 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
193 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
192 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
193 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
194 | 194 | |
195 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
195 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function get_button_type() { |
206 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
206 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @return string |
215 | 215 | */ |
216 | 216 | public function get_button_theme() { |
217 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
217 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @return string |
226 | 226 | */ |
227 | 227 | public function get_button_height() { |
228 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
228 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -235,40 +235,40 @@ discard block |
||
235 | 235 | * @version 4.0.0 |
236 | 236 | */ |
237 | 237 | public function get_product_data() { |
238 | - if ( ! is_product() ) { |
|
238 | + if ( ! is_product()) { |
|
239 | 239 | return false; |
240 | 240 | } |
241 | 241 | |
242 | 242 | global $post; |
243 | 243 | |
244 | - $product = wc_get_product( $post->ID ); |
|
244 | + $product = wc_get_product($post->ID); |
|
245 | 245 | |
246 | 246 | $data = array(); |
247 | 247 | $items = array(); |
248 | 248 | |
249 | 249 | $items[] = array( |
250 | 250 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
251 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
251 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
252 | 252 | ); |
253 | 253 | |
254 | - if ( wc_tax_enabled() ) { |
|
254 | + if (wc_tax_enabled()) { |
|
255 | 255 | $items[] = array( |
256 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
256 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
257 | 257 | 'amount' => 0, |
258 | 258 | 'pending' => true, |
259 | 259 | ); |
260 | 260 | } |
261 | 261 | |
262 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
262 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
263 | 263 | $items[] = array( |
264 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
264 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
265 | 265 | 'amount' => 0, |
266 | 266 | 'pending' => true, |
267 | 267 | ); |
268 | 268 | |
269 | - $data['shippingOptions'] = array( |
|
269 | + $data['shippingOptions'] = array( |
|
270 | 270 | 'id' => 'pending', |
271 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
271 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
272 | 272 | 'detail' => '', |
273 | 273 | 'amount' => 0, |
274 | 274 | ); |
@@ -276,41 +276,41 @@ discard block |
||
276 | 276 | |
277 | 277 | $data['displayItems'] = $items; |
278 | 278 | $data['total'] = array( |
279 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
280 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
279 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
280 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
281 | 281 | 'pending' => true, |
282 | 282 | ); |
283 | 283 | |
284 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
285 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
286 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
284 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
285 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
286 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
287 | 287 | |
288 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
288 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
292 | 292 | * Filters the gateway title to reflect Payment Request type |
293 | 293 | * |
294 | 294 | */ |
295 | - public function filter_gateway_title( $title, $id ) { |
|
295 | + public function filter_gateway_title($title, $id) { |
|
296 | 296 | global $post; |
297 | 297 | |
298 | - if ( ! is_object( $post ) ) { |
|
298 | + if ( ! is_object($post)) { |
|
299 | 299 | return $title; |
300 | 300 | } |
301 | 301 | |
302 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
303 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
302 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
303 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
304 | 304 | } else { |
305 | - $order = wc_get_order( $post->ID ); |
|
306 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
305 | + $order = wc_get_order($post->ID); |
|
306 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
309 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
310 | 310 | return $method_title; |
311 | 311 | } |
312 | 312 | |
313 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
313 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
314 | 314 | return $method_title; |
315 | 315 | } |
316 | 316 | |
@@ -323,16 +323,16 @@ discard block |
||
323 | 323 | * @since 3.1.4 |
324 | 324 | * @version 4.0.0 |
325 | 325 | */ |
326 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
326 | + public function postal_code_validation($valid, $postcode, $country) { |
|
327 | 327 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
328 | 328 | |
329 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
329 | + if ( ! isset($gateways['stripe'])) { |
|
330 | 330 | return $valid; |
331 | 331 | } |
332 | 332 | |
333 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
333 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
334 | 334 | |
335 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
335 | + if ('apple_pay' !== $payment_request_type) { |
|
336 | 336 | return $valid; |
337 | 337 | } |
338 | 338 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | * the order and not let it go through. The remedy for now is just to remove this validation. |
343 | 343 | * Note that this only works with shipping providers that don't validate full postal codes. |
344 | 344 | */ |
345 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
345 | + if ('GB' === $country || 'CA' === $country) { |
|
346 | 346 | return true; |
347 | 347 | } |
348 | 348 | |
@@ -357,29 +357,29 @@ discard block |
||
357 | 357 | * @param int $order_id |
358 | 358 | * @param array $posted_data The posted data from checkout form. |
359 | 359 | */ |
360 | - public function add_order_meta( $order_id, $posted_data ) { |
|
361 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
360 | + public function add_order_meta($order_id, $posted_data) { |
|
361 | + if (empty($_POST['payment_request_type'])) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | - $order = wc_get_order( $order_id ); |
|
365 | + $order = wc_get_order($order_id); |
|
366 | 366 | |
367 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
367 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
368 | 368 | |
369 | - if ( 'apple_pay' === $payment_request_type ) { |
|
370 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
371 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
369 | + if ('apple_pay' === $payment_request_type) { |
|
370 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
371 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
372 | 372 | } else { |
373 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
373 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
374 | 374 | $order->save(); |
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
378 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
379 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
380 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
378 | + if ('payment_request_api' === $payment_request_type) { |
|
379 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
380 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
381 | 381 | } else { |
382 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
382 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
383 | 383 | $order->save(); |
384 | 384 | } |
385 | 385 | } |
@@ -393,11 +393,11 @@ discard block |
||
393 | 393 | * @return array |
394 | 394 | */ |
395 | 395 | public function supported_product_types() { |
396 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
396 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
397 | 397 | 'simple', |
398 | 398 | 'variable', |
399 | 399 | 'variation', |
400 | - ) ); |
|
400 | + )); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -408,15 +408,15 @@ discard block |
||
408 | 408 | * @return bool |
409 | 409 | */ |
410 | 410 | public function allowed_items_in_cart() { |
411 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
412 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
411 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
412 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
413 | 413 | |
414 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
414 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
415 | 415 | return false; |
416 | 416 | } |
417 | 417 | |
418 | 418 | // Pre Orders compatbility where we don't support charge upon release. |
419 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
419 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
420 | 420 | return false; |
421 | 421 | } |
422 | 422 | } |
@@ -432,82 +432,82 @@ discard block |
||
432 | 432 | */ |
433 | 433 | public function scripts() { |
434 | 434 | // If keys are not set bail. |
435 | - if ( ! $this->are_keys_set() ) { |
|
436 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
435 | + if ( ! $this->are_keys_set()) { |
|
436 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
437 | 437 | return; |
438 | 438 | } |
439 | 439 | |
440 | 440 | // If no SSL bail. |
441 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
442 | - WC_Stripe_Logger::log( 'Stripe requires SSL.' ); |
|
441 | + if ( ! $this->testmode && ! is_ssl()) { |
|
442 | + WC_Stripe_Logger::log('Stripe requires SSL.'); |
|
443 | 443 | return; |
444 | 444 | } |
445 | 445 | |
446 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
446 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
447 | 447 | return; |
448 | 448 | } |
449 | 449 | |
450 | - if ( is_product() ) { |
|
450 | + if (is_product()) { |
|
451 | 451 | global $post; |
452 | 452 | |
453 | - $product = wc_get_product( $post->ID ); |
|
453 | + $product = wc_get_product($post->ID); |
|
454 | 454 | |
455 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
455 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
456 | 456 | return; |
457 | 457 | } |
458 | 458 | |
459 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
459 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
460 | 460 | return; |
461 | 461 | } |
462 | 462 | } |
463 | 463 | |
464 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
464 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
465 | 465 | |
466 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
467 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
466 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
467 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
468 | 468 | |
469 | 469 | wp_localize_script( |
470 | 470 | 'wc_stripe_payment_request', |
471 | 471 | 'wc_stripe_payment_request_params', |
472 | 472 | array( |
473 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
473 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
474 | 474 | 'stripe' => array( |
475 | 475 | 'key' => $this->publishable_key, |
476 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
476 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
477 | 477 | ), |
478 | 478 | 'nonce' => array( |
479 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
480 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
481 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
482 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
483 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
484 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
485 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
486 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
479 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
480 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
481 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
482 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
483 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
484 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
485 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
486 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
487 | 487 | ), |
488 | 488 | 'i18n' => array( |
489 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
489 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
490 | 490 | /* translators: Do not translate the [option] placeholder */ |
491 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
491 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
492 | 492 | ), |
493 | 493 | 'checkout' => array( |
494 | 494 | 'url' => wc_get_checkout_url(), |
495 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
496 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
495 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
496 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
497 | 497 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
498 | 498 | ), |
499 | 499 | 'button' => array( |
500 | 500 | 'type' => $this->get_button_type(), |
501 | 501 | 'theme' => $this->get_button_theme(), |
502 | 502 | 'height' => $this->get_button_height(), |
503 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
503 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
504 | 504 | ), |
505 | 505 | 'is_product_page' => is_product(), |
506 | 506 | 'product' => $this->get_product_data(), |
507 | 507 | ) |
508 | 508 | ); |
509 | 509 | |
510 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
510 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -519,39 +519,39 @@ discard block |
||
519 | 519 | public function display_payment_request_button_html() { |
520 | 520 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
521 | 521 | |
522 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
522 | + if ( ! isset($gateways['stripe'])) { |
|
523 | 523 | return; |
524 | 524 | } |
525 | 525 | |
526 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
526 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
527 | 527 | return; |
528 | 528 | } |
529 | 529 | |
530 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
530 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
531 | 531 | return; |
532 | 532 | } |
533 | 533 | |
534 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
534 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
535 | 535 | return; |
536 | 536 | } |
537 | 537 | |
538 | - if ( is_product() ) { |
|
538 | + if (is_product()) { |
|
539 | 539 | global $post; |
540 | 540 | |
541 | - $product = wc_get_product( $post->ID ); |
|
541 | + $product = wc_get_product($post->ID); |
|
542 | 542 | |
543 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
543 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
544 | 544 | return; |
545 | 545 | } |
546 | 546 | |
547 | 547 | // Pre Orders charge upon release not supported. |
548 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
549 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
548 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
549 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
550 | 550 | return; |
551 | 551 | } |
552 | 552 | } else { |
553 | - if ( ! $this->allowed_items_in_cart() ) { |
|
554 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
553 | + if ( ! $this->allowed_items_in_cart()) { |
|
554 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
555 | 555 | return; |
556 | 556 | } |
557 | 557 | } |
@@ -573,44 +573,44 @@ discard block |
||
573 | 573 | public function display_payment_request_button_separator_html() { |
574 | 574 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
575 | 575 | |
576 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
576 | + if ( ! isset($gateways['stripe'])) { |
|
577 | 577 | return; |
578 | 578 | } |
579 | 579 | |
580 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
580 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
581 | 581 | return; |
582 | 582 | } |
583 | 583 | |
584 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
584 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
585 | 585 | return; |
586 | 586 | } |
587 | 587 | |
588 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
588 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
589 | 589 | return; |
590 | 590 | } |
591 | 591 | |
592 | - if ( is_product() ) { |
|
592 | + if (is_product()) { |
|
593 | 593 | global $post; |
594 | 594 | |
595 | - $product = wc_get_product( $post->ID ); |
|
595 | + $product = wc_get_product($post->ID); |
|
596 | 596 | |
597 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
597 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
598 | 598 | return; |
599 | 599 | } |
600 | 600 | |
601 | 601 | // Pre Orders charge upon release not supported. |
602 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
603 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
602 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
603 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
604 | 604 | return; |
605 | 605 | } |
606 | 606 | } else { |
607 | - if ( ! $this->allowed_items_in_cart() ) { |
|
608 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
607 | + if ( ! $this->allowed_items_in_cart()) { |
|
608 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
609 | 609 | return; |
610 | 610 | } |
611 | 611 | } |
612 | 612 | ?> |
613 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
613 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p> |
|
614 | 614 | <?php |
615 | 615 | } |
616 | 616 | |
@@ -621,11 +621,11 @@ discard block |
||
621 | 621 | * @version 4.0.0 |
622 | 622 | */ |
623 | 623 | public function ajax_log_errors() { |
624 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
624 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
625 | 625 | |
626 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
626 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
627 | 627 | |
628 | - WC_Stripe_Logger::log( $errors ); |
|
628 | + WC_Stripe_Logger::log($errors); |
|
629 | 629 | |
630 | 630 | exit; |
631 | 631 | } |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | * @version 4.0.0 |
638 | 638 | */ |
639 | 639 | public function ajax_clear_cart() { |
640 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
640 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
641 | 641 | |
642 | 642 | WC()->cart->empty_cart(); |
643 | 643 | exit; |
@@ -647,10 +647,10 @@ discard block |
||
647 | 647 | * Get cart details. |
648 | 648 | */ |
649 | 649 | public function ajax_get_cart_details() { |
650 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
650 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
651 | 651 | |
652 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
653 | - define( 'WOOCOMMERCE_CART', true ); |
|
652 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
653 | + define('WOOCOMMERCE_CART', true); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | WC()->cart->calculate_totals(); |
@@ -661,14 +661,14 @@ discard block |
||
661 | 661 | $data = array( |
662 | 662 | 'shipping_required' => WC()->cart->needs_shipping(), |
663 | 663 | 'order_data' => array( |
664 | - 'currency' => strtolower( $currency ), |
|
665 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
664 | + 'currency' => strtolower($currency), |
|
665 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
666 | 666 | ), |
667 | 667 | ); |
668 | 668 | |
669 | 669 | $data['order_data'] += $this->build_display_items(); |
670 | 670 | |
671 | - wp_send_json( $data ); |
|
671 | + wp_send_json($data); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | /** |
@@ -679,47 +679,47 @@ discard block |
||
679 | 679 | * @see WC_Shipping::get_packages(). |
680 | 680 | */ |
681 | 681 | public function ajax_get_shipping_options() { |
682 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
682 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
683 | 683 | |
684 | 684 | try { |
685 | 685 | // Set the shipping package. |
686 | - $posted = filter_input_array( INPUT_POST, array( |
|
686 | + $posted = filter_input_array(INPUT_POST, array( |
|
687 | 687 | 'country' => FILTER_SANITIZE_STRING, |
688 | 688 | 'state' => FILTER_SANITIZE_STRING, |
689 | 689 | 'postcode' => FILTER_SANITIZE_STRING, |
690 | 690 | 'city' => FILTER_SANITIZE_STRING, |
691 | 691 | 'address' => FILTER_SANITIZE_STRING, |
692 | 692 | 'address_2' => FILTER_SANITIZE_STRING, |
693 | - ) ); |
|
693 | + )); |
|
694 | 694 | |
695 | - $this->calculate_shipping( $posted ); |
|
695 | + $this->calculate_shipping($posted); |
|
696 | 696 | |
697 | 697 | // Set the shipping options. |
698 | 698 | $data = array(); |
699 | 699 | $packages = WC()->shipping->get_packages(); |
700 | 700 | |
701 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
702 | - foreach ( $packages as $package_key => $package ) { |
|
703 | - if ( empty( $package['rates'] ) ) { |
|
704 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
701 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
702 | + foreach ($packages as $package_key => $package) { |
|
703 | + if (empty($package['rates'])) { |
|
704 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
705 | 705 | } |
706 | 706 | |
707 | - foreach ( $package['rates'] as $key => $rate ) { |
|
707 | + foreach ($package['rates'] as $key => $rate) { |
|
708 | 708 | $data['shipping_options'][] = array( |
709 | 709 | 'id' => $rate->id, |
710 | 710 | 'label' => $rate->label, |
711 | 711 | 'detail' => '', |
712 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
712 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
713 | 713 | ); |
714 | 714 | } |
715 | 715 | } |
716 | 716 | } else { |
717 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
717 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
718 | 718 | } |
719 | 719 | |
720 | - if ( isset( $data[0] ) ) { |
|
720 | + if (isset($data[0])) { |
|
721 | 721 | // Auto select the first shipping method. |
722 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
722 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | WC()->cart->calculate_totals(); |
@@ -727,12 +727,12 @@ discard block |
||
727 | 727 | $data += $this->build_display_items(); |
728 | 728 | $data['result'] = 'success'; |
729 | 729 | |
730 | - wp_send_json( $data ); |
|
731 | - } catch ( Exception $e ) { |
|
730 | + wp_send_json($data); |
|
731 | + } catch (Exception $e) { |
|
732 | 732 | $data += $this->build_display_items(); |
733 | 733 | $data['result'] = 'invalid_shipping_address'; |
734 | 734 | |
735 | - wp_send_json( $data ); |
|
735 | + wp_send_json($data); |
|
736 | 736 | } |
737 | 737 | } |
738 | 738 | |
@@ -740,22 +740,22 @@ discard block |
||
740 | 740 | * Update shipping method. |
741 | 741 | */ |
742 | 742 | public function ajax_update_shipping_method() { |
743 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
743 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
744 | 744 | |
745 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
746 | - define( 'WOOCOMMERCE_CART', true ); |
|
745 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
746 | + define('WOOCOMMERCE_CART', true); |
|
747 | 747 | } |
748 | 748 | |
749 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
750 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
749 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
750 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
751 | 751 | |
752 | - if ( is_array( $shipping_method ) ) { |
|
753 | - foreach ( $shipping_method as $i => $value ) { |
|
754 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
752 | + if (is_array($shipping_method)) { |
|
753 | + foreach ($shipping_method as $i => $value) { |
|
754 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
755 | 755 | } |
756 | 756 | } |
757 | 757 | |
758 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
758 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
759 | 759 | |
760 | 760 | WC()->cart->calculate_totals(); |
761 | 761 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | $data += $this->build_display_items(); |
764 | 764 | $data['result'] = 'success'; |
765 | 765 | |
766 | - wp_send_json( $data ); |
|
766 | + wp_send_json($data); |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | /** |
@@ -774,31 +774,31 @@ discard block |
||
774 | 774 | * @return array $data |
775 | 775 | */ |
776 | 776 | public function ajax_get_selected_product_data() { |
777 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
777 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
778 | 778 | |
779 | - $product_id = absint( $_POST['product_id'] ); |
|
780 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
779 | + $product_id = absint($_POST['product_id']); |
|
780 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
781 | 781 | |
782 | - $product = wc_get_product( $product_id ); |
|
782 | + $product = wc_get_product($product_id); |
|
783 | 783 | |
784 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
785 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
784 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
785 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
786 | 786 | |
787 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
788 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
787 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
788 | + $variation_id = $product->get_matching_variation($attributes); |
|
789 | 789 | } else { |
790 | - $data_store = WC_Data_Store::load( 'product' ); |
|
791 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
790 | + $data_store = WC_Data_Store::load('product'); |
|
791 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
792 | 792 | } |
793 | 793 | |
794 | - if ( ! empty( $variation_id ) ) { |
|
795 | - $product = wc_get_product( $variation_id ); |
|
794 | + if ( ! empty($variation_id)) { |
|
795 | + $product = wc_get_product($variation_id); |
|
796 | 796 | } |
797 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
798 | - $product = wc_get_product( $product_id ); |
|
797 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
798 | + $product = wc_get_product($product_id); |
|
799 | 799 | } |
800 | 800 | |
801 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
801 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
802 | 802 | |
803 | 803 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
804 | 804 | |
@@ -806,28 +806,28 @@ discard block |
||
806 | 806 | $items = array(); |
807 | 807 | |
808 | 808 | $items[] = array( |
809 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
810 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
809 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
810 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
811 | 811 | ); |
812 | 812 | |
813 | - if ( wc_tax_enabled() ) { |
|
813 | + if (wc_tax_enabled()) { |
|
814 | 814 | $items[] = array( |
815 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
815 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
816 | 816 | 'amount' => 0, |
817 | 817 | 'pending' => true, |
818 | 818 | ); |
819 | 819 | } |
820 | 820 | |
821 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
821 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
822 | 822 | $items[] = array( |
823 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
823 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
824 | 824 | 'amount' => 0, |
825 | 825 | 'pending' => true, |
826 | 826 | ); |
827 | 827 | |
828 | - $data['shippingOptions'] = array( |
|
828 | + $data['shippingOptions'] = array( |
|
829 | 829 | 'id' => 'pending', |
830 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
830 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
831 | 831 | 'detail' => '', |
832 | 832 | 'amount' => 0, |
833 | 833 | ); |
@@ -836,15 +836,15 @@ discard block |
||
836 | 836 | $data['displayItems'] = $items; |
837 | 837 | $data['total'] = array( |
838 | 838 | 'label' => $this->total_label, |
839 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
839 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
840 | 840 | 'pending' => true, |
841 | 841 | ); |
842 | 842 | |
843 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
844 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
845 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
843 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
844 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
845 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
846 | 846 | |
847 | - wp_send_json( $data ); |
|
847 | + wp_send_json($data); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | /** |
@@ -855,37 +855,37 @@ discard block |
||
855 | 855 | * @return array $data |
856 | 856 | */ |
857 | 857 | public function ajax_add_to_cart() { |
858 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
858 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
859 | 859 | |
860 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
861 | - define( 'WOOCOMMERCE_CART', true ); |
|
860 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
861 | + define('WOOCOMMERCE_CART', true); |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | WC()->shipping->reset_shipping(); |
865 | 865 | |
866 | - $product_id = absint( $_POST['product_id'] ); |
|
867 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
866 | + $product_id = absint($_POST['product_id']); |
|
867 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
868 | 868 | |
869 | - $product = wc_get_product( $product_id ); |
|
869 | + $product = wc_get_product($product_id); |
|
870 | 870 | |
871 | 871 | // First empty the cart to prevent wrong calculation. |
872 | 872 | WC()->cart->empty_cart(); |
873 | 873 | |
874 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
875 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
874 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
875 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
876 | 876 | |
877 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
878 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
877 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
878 | + $variation_id = $product->get_matching_variation($attributes); |
|
879 | 879 | } else { |
880 | - $data_store = WC_Data_Store::load( 'product' ); |
|
881 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
880 | + $data_store = WC_Data_Store::load('product'); |
|
881 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
882 | 882 | } |
883 | 883 | |
884 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
884 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
885 | 885 | } |
886 | 886 | |
887 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
888 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
887 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
888 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | WC()->cart->calculate_totals(); |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | $data += $this->build_display_items(); |
895 | 895 | $data['result'] = 'success'; |
896 | 896 | |
897 | - wp_send_json( $data ); |
|
897 | + wp_send_json($data); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -907,31 +907,31 @@ discard block |
||
907 | 907 | * @version 4.0.0 |
908 | 908 | */ |
909 | 909 | public function normalize_state() { |
910 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
911 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
912 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
913 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
910 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
911 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
912 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
913 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
914 | 914 | |
915 | - if ( $billing_state && $billing_country ) { |
|
916 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
915 | + if ($billing_state && $billing_country) { |
|
916 | + $valid_states = WC()->countries->get_states($billing_country); |
|
917 | 917 | |
918 | 918 | // Valid states found for country. |
919 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
920 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
921 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
919 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
920 | + foreach ($valid_states as $state_abbr => $state) { |
|
921 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
922 | 922 | $_POST['billing_state'] = $state_abbr; |
923 | 923 | } |
924 | 924 | } |
925 | 925 | } |
926 | 926 | } |
927 | 927 | |
928 | - if ( $shipping_state && $shipping_country ) { |
|
929 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
928 | + if ($shipping_state && $shipping_country) { |
|
929 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
930 | 930 | |
931 | 931 | // Valid states found for country. |
932 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
933 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
934 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
932 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
933 | + foreach ($valid_states as $state_abbr => $state) { |
|
934 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
935 | 935 | $_POST['shipping_state'] = $state_abbr; |
936 | 936 | } |
937 | 937 | } |
@@ -946,19 +946,19 @@ discard block |
||
946 | 946 | * @version 4.0.0 |
947 | 947 | */ |
948 | 948 | public function ajax_create_order() { |
949 | - if ( WC()->cart->is_empty() ) { |
|
950 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
949 | + if (WC()->cart->is_empty()) { |
|
950 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
951 | 951 | } |
952 | 952 | |
953 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
954 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
953 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
954 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | $this->normalize_state(); |
958 | 958 | |
959 | 959 | WC()->checkout()->process_checkout(); |
960 | 960 | |
961 | - die( 0 ); |
|
961 | + die(0); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | /** |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | * @version 4.0.0 |
969 | 969 | * @param array $address |
970 | 970 | */ |
971 | - protected function calculate_shipping( $address = array() ) { |
|
971 | + protected function calculate_shipping($address = array()) { |
|
972 | 972 | global $states; |
973 | 973 | |
974 | 974 | $country = $address['country']; |
@@ -985,28 +985,28 @@ discard block |
||
985 | 985 | * In some versions of Chrome, state can be a full name. So we need |
986 | 986 | * to convert that to abbreviation as WC is expecting that. |
987 | 987 | */ |
988 | - if ( 2 < strlen( $state ) ) { |
|
989 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
988 | + if (2 < strlen($state)) { |
|
989 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | WC()->shipping->reset_shipping(); |
993 | 993 | |
994 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
995 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
994 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
995 | + $postcode = wc_format_postcode($postcode, $country); |
|
996 | 996 | } |
997 | 997 | |
998 | - if ( $country ) { |
|
999 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
1000 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
998 | + if ($country) { |
|
999 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
1000 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
1001 | 1001 | } else { |
1002 | 1002 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
1003 | 1003 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
1004 | 1004 | } |
1005 | 1005 | |
1006 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
1007 | - WC()->customer->calculated_shipping( true ); |
|
1006 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
1007 | + WC()->customer->calculated_shipping(true); |
|
1008 | 1008 | } else { |
1009 | - WC()->customer->set_calculated_shipping( true ); |
|
1009 | + WC()->customer->set_calculated_shipping(true); |
|
1010 | 1010 | WC()->customer->save(); |
1011 | 1011 | } |
1012 | 1012 | |
@@ -1023,17 +1023,17 @@ discard block |
||
1023 | 1023 | $packages[0]['destination']['address'] = $address_1; |
1024 | 1024 | $packages[0]['destination']['address_2'] = $address_2; |
1025 | 1025 | |
1026 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
1027 | - if ( $item['data']->needs_shipping() ) { |
|
1028 | - if ( isset( $item['line_total'] ) ) { |
|
1026 | + foreach (WC()->cart->get_cart() as $item) { |
|
1027 | + if ($item['data']->needs_shipping()) { |
|
1028 | + if (isset($item['line_total'])) { |
|
1029 | 1029 | $packages[0]['contents_cost'] += $item['line_total']; |
1030 | 1030 | } |
1031 | 1031 | } |
1032 | 1032 | } |
1033 | 1033 | |
1034 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
1034 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1035 | 1035 | |
1036 | - WC()->shipping->calculate_shipping( $packages ); |
|
1036 | + WC()->shipping->calculate_shipping($packages); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | /** |
@@ -1042,19 +1042,19 @@ discard block |
||
1042 | 1042 | * @since 3.1.0 |
1043 | 1043 | * @version 4.0.0 |
1044 | 1044 | */ |
1045 | - protected function build_shipping_methods( $shipping_methods ) { |
|
1046 | - if ( empty( $shipping_methods ) ) { |
|
1045 | + protected function build_shipping_methods($shipping_methods) { |
|
1046 | + if (empty($shipping_methods)) { |
|
1047 | 1047 | return array(); |
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | $shipping = array(); |
1051 | 1051 | |
1052 | - foreach ( $shipping_methods as $method ) { |
|
1052 | + foreach ($shipping_methods as $method) { |
|
1053 | 1053 | $shipping[] = array( |
1054 | 1054 | 'id' => $method['id'], |
1055 | 1055 | 'label' => $method['label'], |
1056 | 1056 | 'detail' => '', |
1057 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1057 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1058 | 1058 | ); |
1059 | 1059 | } |
1060 | 1060 | |
@@ -1068,69 +1068,69 @@ discard block |
||
1068 | 1068 | * @version 4.0.0 |
1069 | 1069 | */ |
1070 | 1070 | protected function build_display_items() { |
1071 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1072 | - define( 'WOOCOMMERCE_CART', true ); |
|
1071 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1072 | + define('WOOCOMMERCE_CART', true); |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | $items = array(); |
1076 | 1076 | $subtotal = 0; |
1077 | 1077 | |
1078 | 1078 | // Default show only subtotal instead of itemization. |
1079 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1080 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1079 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1080 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1081 | 1081 | $amount = $cart_item['line_subtotal']; |
1082 | - $subtotal += $cart_item['line_subtotal']; |
|
1082 | + $subtotal += $cart_item['line_subtotal']; |
|
1083 | 1083 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1084 | 1084 | |
1085 | 1085 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1086 | 1086 | |
1087 | 1087 | $item = array( |
1088 | 1088 | 'label' => $product_name . $quantity_label, |
1089 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1089 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1090 | 1090 | ); |
1091 | 1091 | |
1092 | 1092 | $items[] = $item; |
1093 | 1093 | } |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1097 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1098 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1099 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1100 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1096 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1097 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1098 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1099 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1100 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1101 | 1101 | |
1102 | - if ( wc_tax_enabled() ) { |
|
1102 | + if (wc_tax_enabled()) { |
|
1103 | 1103 | $items[] = array( |
1104 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1105 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1104 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1105 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1106 | 1106 | ); |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - if ( WC()->cart->needs_shipping() ) { |
|
1109 | + if (WC()->cart->needs_shipping()) { |
|
1110 | 1110 | $items[] = array( |
1111 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1112 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1111 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1112 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1113 | 1113 | ); |
1114 | 1114 | } |
1115 | 1115 | |
1116 | - if ( WC()->cart->has_discount() ) { |
|
1116 | + if (WC()->cart->has_discount()) { |
|
1117 | 1117 | $items[] = array( |
1118 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1119 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1118 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1119 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1120 | 1120 | ); |
1121 | 1121 | } |
1122 | 1122 | |
1123 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1123 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1124 | 1124 | $cart_fees = WC()->cart->fees; |
1125 | 1125 | } else { |
1126 | 1126 | $cart_fees = WC()->cart->get_fees(); |
1127 | 1127 | } |
1128 | 1128 | |
1129 | 1129 | // Include fees and taxes as display items. |
1130 | - foreach ( $cart_fees as $key => $fee ) { |
|
1130 | + foreach ($cart_fees as $key => $fee) { |
|
1131 | 1131 | $items[] = array( |
1132 | 1132 | 'label' => $fee->name, |
1133 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1133 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1134 | 1134 | ); |
1135 | 1135 | } |
1136 | 1136 | |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | 'displayItems' => $items, |
1139 | 1139 | 'total' => array( |
1140 | 1140 | 'label' => $this->total_label, |
1141 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1141 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1142 | 1142 | 'pending' => false, |
1143 | 1143 | ), |
1144 | 1144 | ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_sofort'; |
60 | - $this->method_title = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_sofort_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_sofort_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['sofort']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-sofort-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,28 +241,28 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $bank_country = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'sofort'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | 254 | $post_data['sofort'] = array( |
255 | 255 | 'country' => $bank_country, |
256 | 256 | 'preferred_language' => $this->get_locale(), |
257 | 257 | ); |
258 | 258 | |
259 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
260 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
259 | + if ( ! empty($this->statement_descriptor)) { |
|
260 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
261 | 261 | } |
262 | 262 | |
263 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
263 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
264 | 264 | |
265 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_sofort_source', $post_data, $order ), 'sources' ); |
|
265 | + return WC_Stripe_API::request(apply_filters('wc_stripe_sofort_source', $post_data, $order), 'sources'); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -276,59 +276,59 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return array|void |
278 | 278 | */ |
279 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
279 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
280 | 280 | try { |
281 | - $order = wc_get_order( $order_id ); |
|
281 | + $order = wc_get_order($order_id); |
|
282 | 282 | |
283 | 283 | // This will throw exception if not valid. |
284 | - $this->validate_minimum_order_amount( $order ); |
|
284 | + $this->validate_minimum_order_amount($order); |
|
285 | 285 | |
286 | 286 | // This comes from the create account checkbox in the checkout page. |
287 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
287 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
288 | 288 | |
289 | - if ( $create_account ) { |
|
289 | + if ($create_account) { |
|
290 | 290 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
291 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
291 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
292 | 292 | $new_stripe_customer->create_customer(); |
293 | 293 | } |
294 | 294 | |
295 | - $response = $this->create_source( $order ); |
|
295 | + $response = $this->create_source($order); |
|
296 | 296 | |
297 | - if ( ! empty( $response->error ) ) { |
|
298 | - $order->add_order_note( $response->error->message ); |
|
297 | + if ( ! empty($response->error)) { |
|
298 | + $order->add_order_note($response->error->message); |
|
299 | 299 | |
300 | 300 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
301 | 301 | |
302 | - if ( 'invalid_sofort_country' === $response->error->code ) { |
|
303 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
302 | + if ('invalid_sofort_country' === $response->error->code) { |
|
303 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
304 | 304 | } else { |
305 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
305 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
306 | 306 | } |
307 | 307 | |
308 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
308 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
309 | 309 | } |
310 | 310 | |
311 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
312 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
311 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
312 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
313 | 313 | } else { |
314 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
314 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
315 | 315 | $order->save(); |
316 | 316 | } |
317 | 317 | |
318 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
318 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
319 | 319 | |
320 | 320 | return array( |
321 | 321 | 'result' => 'success', |
322 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
322 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
323 | 323 | ); |
324 | - } catch ( WC_Stripe_Exception $e ) { |
|
325 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
326 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
324 | + } catch (WC_Stripe_Exception $e) { |
|
325 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
326 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
327 | 327 | |
328 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
328 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
329 | 329 | |
330 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
331 | - $this->send_failed_order_email( $order_id ); |
|
330 | + if ($order->has_status(array('pending', 'failed'))) { |
|
331 | + $this->send_failed_order_email($order_id); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_bancontact'; |
60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_bancontact_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_bancontact_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['bancontact']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-bancontact-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,25 +241,25 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'bancontact'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
254 | - $post_data['bancontact'] = array( 'preferred_language' => $this->get_locale() ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | + $post_data['bancontact'] = array('preferred_language' => $this->get_locale()); |
|
255 | 255 | |
256 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
257 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
256 | + if ( ! empty($this->statement_descriptor)) { |
|
257 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
258 | 258 | } |
259 | 259 | |
260 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
260 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
261 | 261 | |
262 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' ); |
|
262 | + return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -273,51 +273,51 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return array|void |
275 | 275 | */ |
276 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
276 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
277 | 277 | try { |
278 | - $order = wc_get_order( $order_id ); |
|
278 | + $order = wc_get_order($order_id); |
|
279 | 279 | |
280 | 280 | // This will throw exception if not valid. |
281 | - $this->validate_minimum_order_amount( $order ); |
|
281 | + $this->validate_minimum_order_amount($order); |
|
282 | 282 | |
283 | 283 | // This comes from the create account checkbox in the checkout page. |
284 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
284 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
285 | 285 | |
286 | - if ( $create_account ) { |
|
286 | + if ($create_account) { |
|
287 | 287 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
288 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
288 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
289 | 289 | $new_stripe_customer->create_customer(); |
290 | 290 | } |
291 | 291 | |
292 | - $response = $this->create_source( $order ); |
|
292 | + $response = $this->create_source($order); |
|
293 | 293 | |
294 | - if ( ! empty( $response->error ) ) { |
|
295 | - $order->add_order_note( $response->error->message ); |
|
294 | + if ( ! empty($response->error)) { |
|
295 | + $order->add_order_note($response->error->message); |
|
296 | 296 | |
297 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
297 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
298 | 298 | } |
299 | 299 | |
300 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
301 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
300 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
301 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
302 | 302 | } else { |
303 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
303 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
304 | 304 | $order->save(); |
305 | 305 | } |
306 | 306 | |
307 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
307 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
308 | 308 | |
309 | 309 | return array( |
310 | 310 | 'result' => 'success', |
311 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
311 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
312 | 312 | ); |
313 | - } catch ( WC_Stripe_Exception $e ) { |
|
314 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
315 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
313 | + } catch (WC_Stripe_Exception $e) { |
|
314 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
315 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
316 | 316 | |
317 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
317 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
318 | 318 | |
319 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
320 | - $this->send_failed_order_email( $order_id ); |
|
319 | + if ($order->has_status(array('pending', 'failed'))) { |
|
320 | + $this->send_failed_order_email($order_id); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | return array( |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
7 | 7 | * DEPRECATED DO NOT USE!! |
8 | 8 | */ |
9 | -if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) { |
|
9 | +if ( ! class_exists('WC_Stripe_Apple_Pay')) { |
|
10 | 10 | class WC_Stripe_Apple_Pay { |
11 | 11 | /** |
12 | 12 | * This Instance. |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function instance() { |
23 | - WC_Stripe_Logger::log( 'DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0' ); |
|
23 | + WC_Stripe_Logger::log('DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0'); |
|
24 | 24 | return self::$_this; |
25 | 25 | } |
26 | 26 | |
27 | - public function __get( $var ) { |
|
27 | + public function __get($var) { |
|
28 | 28 | return null; |
29 | 29 | } |
30 | 30 | |
31 | - public function __call( $name, $arguments ) { |
|
31 | + public function __call($name, $arguments) { |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 | } |