@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | * Check if this gateway is enabled |
19 | 19 | */ |
20 | 20 | public function is_available() { |
21 | - if ( 'yes' === $this->enabled ) { |
|
22 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
21 | + if ('yes' === $this->enabled) { |
|
22 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
23 | 23 | return false; |
24 | 24 | } |
25 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
25 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | return true; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * @since 4.0.0 |
38 | 38 | * @version 4.0.0 |
39 | 39 | */ |
40 | - public function add_admin_notice( $slug, $class, $message ) { |
|
41 | - $this->notices[ $slug ] = array( |
|
40 | + public function add_admin_notice($slug, $class, $message) { |
|
41 | + $this->notices[$slug] = array( |
|
42 | 42 | 'class' => $class, |
43 | 43 | 'message' => $message, |
44 | 44 | ); |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @version 4.0.0 |
52 | 52 | */ |
53 | 53 | public function remove_admin_notice() { |
54 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
55 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
54 | + if (did_action('woocommerce_update_options')) { |
|
55 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | * @version 4.0.0 |
65 | 65 | * @param object $order |
66 | 66 | */ |
67 | - public function validate_minimum_order_amount( $order ) { |
|
68 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
67 | + public function validate_minimum_order_amount($order) { |
|
68 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
69 | 69 | /* translators: 1) dollar amount */ |
70 | - 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 ) ) ); |
|
70 | + 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))); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
@@ -77,14 +77,14 @@ discard block |
||
77 | 77 | * @since 4.0.0 |
78 | 78 | * @version 4.0.0 |
79 | 79 | */ |
80 | - public function get_transaction_url( $order ) { |
|
81 | - if ( $this->testmode ) { |
|
80 | + public function get_transaction_url($order) { |
|
81 | + if ($this->testmode) { |
|
82 | 82 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
83 | 83 | } else { |
84 | 84 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
85 | 85 | } |
86 | 86 | |
87 | - return parent::get_transaction_url( $order ); |
|
87 | + return parent::get_transaction_url($order); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | * @since 4.0.0 |
94 | 94 | * @version 4.0.0 |
95 | 95 | */ |
96 | - public function get_stripe_customer_id( $order ) { |
|
97 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
96 | + public function get_stripe_customer_id($order) { |
|
97 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
98 | 98 | |
99 | - if ( empty( $customer ) ) { |
|
99 | + if (empty($customer)) { |
|
100 | 100 | // Try to get it via the order. |
101 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
102 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
101 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
102 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
103 | 103 | } else { |
104 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
104 | + return $order->get_meta('_stripe_customer_id', true); |
|
105 | 105 | } |
106 | 106 | } else { |
107 | 107 | return $customer; |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | * @param object $order |
119 | 119 | * @param int $id Stripe session id. |
120 | 120 | */ |
121 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
122 | - if ( is_object( $order ) ) { |
|
123 | - if ( empty( $id ) ) { |
|
121 | + public function get_stripe_return_url($order = null, $id = null) { |
|
122 | + if (is_object($order)) { |
|
123 | + if (empty($id)) { |
|
124 | 124 | $id = uniqid(); |
125 | 125 | } |
126 | 126 | |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | 'order_id' => $order_id, |
132 | 132 | ); |
133 | 133 | |
134 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
134 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
135 | 135 | } |
136 | 136 | |
137 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
137 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -146,48 +146,47 @@ discard block |
||
146 | 146 | * @param object $source |
147 | 147 | * @return array() |
148 | 148 | */ |
149 | - public function generate_payment_request( $order, $source ) { |
|
150 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
151 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
152 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
149 | + public function generate_payment_request($order, $source) { |
|
150 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
151 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
152 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
153 | 153 | $post_data = array(); |
154 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
155 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
154 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
155 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
156 | 156 | /* translators: 1) blog name 2) order number */ |
157 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
157 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
158 | 158 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
159 | 159 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
160 | 160 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
161 | 161 | |
162 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
162 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
163 | 163 | $post_data['receipt_email'] = $billing_email; |
164 | 164 | } |
165 | 165 | |
166 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
167 | - case 'stripe': |
|
168 | - if ( ! empty( $statement_descriptor ) ) { |
|
169 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
166 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
167 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
168 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
170 | 169 | } |
171 | 170 | |
172 | - $post_data['capture'] = $capture ? 'true' : 'false'; |
|
171 | + $post_data['capture'] = $capture ? 'true' : 'false'; |
|
173 | 172 | break; |
174 | 173 | } |
175 | 174 | |
176 | 175 | $post_data['expand[]'] = 'balance_transaction'; |
177 | 176 | |
178 | 177 | $metadata = array( |
179 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
180 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
178 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
179 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
181 | 180 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
182 | 181 | ); |
183 | 182 | |
184 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
183 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
185 | 184 | |
186 | - if ( $source->customer ) { |
|
185 | + if ($source->customer) { |
|
187 | 186 | $post_data['customer'] = $source->customer; |
188 | 187 | } |
189 | 188 | |
190 | - if ( $source->source ) { |
|
189 | + if ($source->source) { |
|
191 | 190 | $post_data['source'] = $source->source; |
192 | 191 | } |
193 | 192 | |
@@ -199,75 +198,75 @@ discard block |
||
199 | 198 | * @param WC_Order $order |
200 | 199 | * @param object $source |
201 | 200 | */ |
202 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
201 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
203 | 202 | } |
204 | 203 | |
205 | 204 | /** |
206 | 205 | * Store extra meta data for an order from a Stripe Response. |
207 | 206 | */ |
208 | - public function process_response( $response, $order ) { |
|
209 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
207 | + public function process_response($response, $order) { |
|
208 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
210 | 209 | |
211 | 210 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
212 | 211 | |
213 | 212 | // Store charge data |
214 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ) : $order->update_meta_data( '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
213 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no') : $order->update_meta_data('_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
215 | 214 | |
216 | 215 | // Store other data such as fees |
217 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
216 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
218 | 217 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
219 | 218 | // values are in the local currency of the Stripe account, not from WC. |
220 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
221 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
222 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
223 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
219 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
220 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
221 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
222 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
224 | 223 | } |
225 | 224 | |
226 | - if ( $response->captured ) { |
|
225 | + if ($response->captured) { |
|
227 | 226 | /** |
228 | 227 | * Charge can be captured but in a pending state. Payment methods |
229 | 228 | * that are asynchronous may take couple days to clear. Webhook will |
230 | 229 | * take care of the status changes. |
231 | 230 | */ |
232 | - if ( 'pending' === $response->status ) { |
|
233 | - if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) { |
|
234 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
231 | + if ('pending' === $response->status) { |
|
232 | + if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) { |
|
233 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
235 | 234 | } |
236 | 235 | |
237 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id ); |
|
236 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id); |
|
238 | 237 | /* translators: transaction id */ |
239 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
238 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
240 | 239 | } |
241 | 240 | |
242 | - if ( 'succeeded' === $response->status ) { |
|
243 | - $order->payment_complete( $response->id ); |
|
241 | + if ('succeeded' === $response->status) { |
|
242 | + $order->payment_complete($response->id); |
|
244 | 243 | |
245 | 244 | /* translators: transaction id */ |
246 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
247 | - $order->add_order_note( $message ); |
|
245 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
246 | + $order->add_order_note($message); |
|
248 | 247 | } |
249 | 248 | |
250 | - if ( 'failed' === $response->status ) { |
|
251 | - $error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
252 | - $order->add_order_note( $error_msg ); |
|
253 | - throw new Exception( $error_msg ); |
|
249 | + if ('failed' === $response->status) { |
|
250 | + $error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
251 | + $order->add_order_note($error_msg); |
|
252 | + throw new Exception($error_msg); |
|
254 | 253 | } |
255 | 254 | } else { |
256 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id ); |
|
255 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id); |
|
257 | 256 | |
258 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
259 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
257 | + if ($order->has_status(array('pending', 'failed'))) { |
|
258 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
260 | 259 | } |
261 | 260 | |
262 | 261 | /* translators: transaction id */ |
263 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
262 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
264 | 263 | } |
265 | 264 | |
266 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
265 | + if (is_callable(array($order, 'save'))) { |
|
267 | 266 | $order->save(); |
268 | 267 | } |
269 | 268 | |
270 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
269 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
271 | 270 | |
272 | 271 | return $response; |
273 | 272 | } |
@@ -280,10 +279,10 @@ discard block |
||
280 | 279 | * @param int $order_id |
281 | 280 | * @return null |
282 | 281 | */ |
283 | - public function send_failed_order_email( $order_id ) { |
|
282 | + public function send_failed_order_email($order_id) { |
|
284 | 283 | $emails = WC()->mailer()->get_emails(); |
285 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
286 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
284 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
285 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
287 | 286 | } |
288 | 287 | } |
289 | 288 | |
@@ -295,7 +294,7 @@ discard block |
||
295 | 294 | * @param object $order |
296 | 295 | * @return object $details |
297 | 296 | */ |
298 | - public function get_owner_details( $order ) { |
|
297 | + public function get_owner_details($order) { |
|
299 | 298 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
300 | 299 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
301 | 300 | |
@@ -306,8 +305,8 @@ discard block |
||
306 | 305 | |
307 | 306 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
308 | 307 | |
309 | - if ( ! empty( $phone ) ) { |
|
310 | - $details['phone'] = $phone; |
|
308 | + if ( ! empty($phone)) { |
|
309 | + $details['phone'] = $phone; |
|
311 | 310 | } |
312 | 311 | |
313 | 312 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -317,7 +316,7 @@ discard block |
||
317 | 316 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
318 | 317 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
319 | 318 | |
320 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
319 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
321 | 320 | } |
322 | 321 | |
323 | 322 | /** |
@@ -333,58 +332,58 @@ discard block |
||
333 | 332 | * @throws Exception When card was not added or for and invalid card. |
334 | 333 | * @return object |
335 | 334 | */ |
336 | - public function prepare_source( $user_id, $force_save_source = false ) { |
|
337 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
335 | + public function prepare_source($user_id, $force_save_source = false) { |
|
336 | + $customer = new WC_Stripe_Customer($user_id); |
|
338 | 337 | $set_customer = true; |
339 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
338 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
340 | 339 | $source = ''; |
341 | 340 | $wc_token_id = false; |
342 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
341 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
343 | 342 | |
344 | 343 | // New CC info was entered and we have a new source to process. |
345 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
344 | + if ( ! empty($_POST['stripe_source'])) { |
|
346 | 345 | // This gets the source object from Stripe. |
347 | - $source = json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ); |
|
346 | + $source = json_decode(wc_clean(stripslashes($_POST['stripe_source']))); |
|
348 | 347 | |
349 | 348 | // This checks to see if customer opted to save the payment method to file. |
350 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
349 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
351 | 350 | |
352 | 351 | /** |
353 | 352 | * This is true if the user wants to store the card to their account. |
354 | 353 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
355 | 354 | * actually reusable. Either that or force_save_source is true. |
356 | 355 | */ |
357 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage ) || $force_save_source ) { |
|
358 | - $source = $customer->add_source( $source->id ); |
|
356 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage) || $force_save_source) { |
|
357 | + $source = $customer->add_source($source->id); |
|
359 | 358 | |
360 | - if ( ! empty( $source->error ) ) { |
|
361 | - throw new Exception( $source->error->message ); |
|
359 | + if ( ! empty($source->error)) { |
|
360 | + throw new Exception($source->error->message); |
|
362 | 361 | } |
363 | 362 | } else { |
364 | 363 | $source = $source->id; |
365 | 364 | } |
366 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
365 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
367 | 366 | // Use an existing token, and then process the payment |
368 | 367 | |
369 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
370 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
368 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
369 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
371 | 370 | |
372 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
373 | - WC()->session->set( 'refresh_totals', true ); |
|
374 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
371 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
372 | + WC()->session->set('refresh_totals', true); |
|
373 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
375 | 374 | } |
376 | 375 | |
377 | 376 | $source = $wc_token->get_token(); |
378 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
379 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
380 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
377 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
378 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
379 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
381 | 380 | |
382 | 381 | // This is true if the user wants to store the card to their account. |
383 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
384 | - $source = $customer->add_source( $stripe_token ); |
|
382 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
383 | + $source = $customer->add_source($stripe_token); |
|
385 | 384 | |
386 | - if ( ! empty( $source->error ) ) { |
|
387 | - throw new Exception( $source->error->message ); |
|
385 | + if ( ! empty($source->error)) { |
|
386 | + throw new Exception($source->error->message); |
|
388 | 387 | } |
389 | 388 | } else { |
390 | 389 | $set_customer = false; |
@@ -392,7 +391,7 @@ discard block |
||
392 | 391 | } |
393 | 392 | } |
394 | 393 | |
395 | - if ( ! $set_customer ) { |
|
394 | + if ( ! $set_customer) { |
|
396 | 395 | $customer_id = false; |
397 | 396 | } else { |
398 | 397 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
@@ -413,27 +412,27 @@ discard block |
||
413 | 412 | * @param WC_Order $order For to which the source applies. |
414 | 413 | * @param stdClass $source Source information. |
415 | 414 | */ |
416 | - public function save_source( $order, $source ) { |
|
415 | + public function save_source($order, $source) { |
|
417 | 416 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
418 | 417 | |
419 | 418 | // Store source in the order. |
420 | - if ( $source->customer ) { |
|
421 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
422 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
419 | + if ($source->customer) { |
|
420 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
421 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
423 | 422 | } else { |
424 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
423 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
425 | 424 | } |
426 | 425 | } |
427 | 426 | |
428 | - if ( $source->source ) { |
|
429 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
430 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
427 | + if ($source->source) { |
|
428 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
429 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
431 | 430 | } else { |
432 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
431 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
433 | 432 | } |
434 | 433 | } |
435 | 434 | |
436 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
435 | + if (is_callable(array($order, 'save'))) { |
|
437 | 436 | $order->save(); |
438 | 437 | } |
439 | 438 | } |
@@ -451,35 +450,35 @@ discard block |
||
451 | 450 | * @param object $order |
452 | 451 | * @return object |
453 | 452 | */ |
454 | - public function prepare_order_source( $order = null ) { |
|
453 | + public function prepare_order_source($order = null) { |
|
455 | 454 | $stripe_customer = new WC_Stripe_Customer(); |
456 | 455 | $stripe_source = false; |
457 | 456 | $token_id = false; |
458 | 457 | |
459 | - if ( $order ) { |
|
458 | + if ($order) { |
|
460 | 459 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
461 | 460 | |
462 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
461 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
463 | 462 | |
464 | - if ( $stripe_customer_id ) { |
|
465 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
463 | + if ($stripe_customer_id) { |
|
464 | + $stripe_customer->set_id($stripe_customer_id); |
|
466 | 465 | } |
467 | 466 | |
468 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
467 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
469 | 468 | |
470 | 469 | // Since 4.0.0, we changed card to source so we need to account for that. |
471 | - if ( empty( $source_id ) ) { |
|
472 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
470 | + if (empty($source_id)) { |
|
471 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
473 | 472 | |
474 | 473 | // Take this opportunity to update the key name. |
475 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
474 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
476 | 475 | |
477 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
476 | + if (is_callable(array($order, 'save'))) { |
|
478 | 477 | $order->save(); |
479 | 478 | } |
480 | 479 | } |
481 | 480 | |
482 | - if ( $source_id ) { |
|
481 | + if ($source_id) { |
|
483 | 482 | $stripe_source = $source_id; |
484 | 483 | } |
485 | 484 | } |
@@ -500,27 +499,27 @@ discard block |
||
500 | 499 | * @param object $order The order object |
501 | 500 | * @param int $balance_transaction_id |
502 | 501 | */ |
503 | - public function update_fees( $order, $balance_transaction_id ) { |
|
502 | + public function update_fees($order, $balance_transaction_id) { |
|
504 | 503 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
505 | 504 | |
506 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
505 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
507 | 506 | |
508 | - if ( empty( $balance_transaction->error ) ) { |
|
509 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
507 | + if (empty($balance_transaction->error)) { |
|
508 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
510 | 509 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
511 | 510 | // values are in the local currency of the Stripe account, not from WC. |
512 | - $fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
513 | - $net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
511 | + $fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
512 | + $net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
514 | 513 | |
515 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
516 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
514 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
515 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
517 | 516 | |
518 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
517 | + if (is_callable(array($order, 'save'))) { |
|
519 | 518 | $order->save(); |
520 | 519 | } |
521 | 520 | } |
522 | 521 | } else { |
523 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
522 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
524 | 523 | } |
525 | 524 | } |
526 | 525 | |
@@ -533,53 +532,53 @@ discard block |
||
533 | 532 | * @param float $amount |
534 | 533 | * @return bool |
535 | 534 | */ |
536 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
537 | - $order = wc_get_order( $order_id ); |
|
535 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
536 | + $order = wc_get_order($order_id); |
|
538 | 537 | |
539 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
538 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
540 | 539 | return false; |
541 | 540 | } |
542 | 541 | |
543 | 542 | $body = array(); |
544 | 543 | |
545 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
546 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
544 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
545 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
547 | 546 | } else { |
548 | 547 | $order_currency = $order->get_currency(); |
549 | 548 | } |
550 | 549 | |
551 | - if ( ! is_null( $amount ) ) { |
|
552 | - $body['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
550 | + if ( ! is_null($amount)) { |
|
551 | + $body['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
553 | 552 | } |
554 | 553 | |
555 | - if ( $reason ) { |
|
554 | + if ($reason) { |
|
556 | 555 | $body['metadata'] = array( |
557 | 556 | 'reason' => $reason, |
558 | 557 | ); |
559 | 558 | } |
560 | 559 | |
561 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
560 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
562 | 561 | |
563 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
562 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
564 | 563 | |
565 | - if ( ! empty( $response->error ) ) { |
|
566 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
564 | + if ( ! empty($response->error)) { |
|
565 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
567 | 566 | return $response; |
568 | - } elseif ( ! empty( $response->id ) ) { |
|
569 | - $amount = wc_price( $response->amount / 100 ); |
|
567 | + } elseif ( ! empty($response->id)) { |
|
568 | + $amount = wc_price($response->amount / 100); |
|
570 | 569 | |
571 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
572 | - $amount = wc_price( $response->amount ); |
|
570 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
571 | + $amount = wc_price($response->amount); |
|
573 | 572 | } |
574 | 573 | |
575 | - if ( isset( $response->balance_transaction ) ) { |
|
576 | - $this->update_fees( $order, $response->balance_transaction ); |
|
574 | + if (isset($response->balance_transaction)) { |
|
575 | + $this->update_fees($order, $response->balance_transaction); |
|
577 | 576 | } |
578 | 577 | |
579 | 578 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
580 | - $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ); |
|
581 | - $order->add_order_note( $refund_message ); |
|
582 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
579 | + $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason); |
|
580 | + $order->add_order_note($refund_message); |
|
581 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
583 | 582 | |
584 | 583 | return true; |
585 | 584 | } |
@@ -594,41 +593,41 @@ discard block |
||
594 | 593 | */ |
595 | 594 | public function add_payment_method() { |
596 | 595 | $error = false; |
597 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
596 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
598 | 597 | $source_id = ''; |
599 | 598 | |
600 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
599 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
601 | 600 | $error = true; |
602 | 601 | } |
603 | 602 | |
604 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
603 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
605 | 604 | |
606 | - if ( isset( $_POST['stripe_source'] ) ) { |
|
607 | - $source = json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ); |
|
605 | + if (isset($_POST['stripe_source'])) { |
|
606 | + $source = json_decode(wc_clean(stripslashes($_POST['stripe_source']))); |
|
608 | 607 | |
609 | - if ( ! empty( $source->error ) ) { |
|
608 | + if ( ! empty($source->error)) { |
|
610 | 609 | $error = true; |
611 | 610 | } |
612 | 611 | |
613 | 612 | $source_id = $source->id; |
614 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
615 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
613 | + } elseif (isset($_POST['stripe_token'])) { |
|
614 | + $source_id = wc_clean($_POST['stripe_token']); |
|
616 | 615 | } |
617 | 616 | |
618 | - $response = $stripe_customer->add_source( $source_id ); |
|
617 | + $response = $stripe_customer->add_source($source_id); |
|
619 | 618 | |
620 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
619 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
621 | 620 | $error = true; |
622 | 621 | } |
623 | 622 | |
624 | - if ( $error ) { |
|
625 | - wc_add_notice( $error_msg, 'error' ); |
|
623 | + if ($error) { |
|
624 | + wc_add_notice($error_msg, 'error'); |
|
626 | 625 | return; |
627 | 626 | } |
628 | 627 | |
629 | 628 | return array( |
630 | 629 | 'result' => 'success', |
631 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
630 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
632 | 631 | ); |
633 | 632 | } |
634 | 633 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | public function __construct() { |
22 | 22 | self::$_this = $this; |
23 | 23 | |
24 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
25 | - add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'get_account_saved_payment_methods_list_item_sepa' ), 10, 2 ); |
|
26 | - add_filter( 'woocommerce_get_credit_card_type_label', array( $this, 'normalize_sepa_label' ) ); |
|
27 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
28 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
24 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
25 | + add_filter('woocommerce_payment_methods_list_item', array($this, 'get_account_saved_payment_methods_list_item_sepa'), 10, 2); |
|
26 | + add_filter('woocommerce_get_credit_card_type_label', array($this, 'normalize_sepa_label')); |
|
27 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
28 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | * @param string $label |
47 | 47 | * @return string $label |
48 | 48 | */ |
49 | - public function normalize_sepa_label( $label ) { |
|
50 | - if ( 'sepa iban' === strtolower( $label ) ) { |
|
49 | + public function normalize_sepa_label($label) { |
|
50 | + if ('sepa iban' === strtolower($label)) { |
|
51 | 51 | return 'SEPA IBAN'; |
52 | 52 | } |
53 | 53 | |
@@ -62,67 +62,67 @@ discard block |
||
62 | 62 | * @param array $tokens |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) { |
|
66 | - if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
65 | + public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) { |
|
66 | + if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) { |
|
67 | 67 | $stored_tokens = array(); |
68 | 68 | |
69 | - foreach ( $tokens as $token ) { |
|
69 | + foreach ($tokens as $token) { |
|
70 | 70 | $stored_tokens[] = $token->get_token(); |
71 | 71 | } |
72 | 72 | |
73 | - if ( 'stripe' === $gateway_id ) { |
|
74 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
73 | + if ('stripe' === $gateway_id) { |
|
74 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
75 | 75 | $stripe_sources = $stripe_customer->get_sources(); |
76 | 76 | |
77 | - foreach ( $stripe_sources as $source ) { |
|
78 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
79 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
77 | + foreach ($stripe_sources as $source) { |
|
78 | + if (isset($source->type) && 'card' === $source->type) { |
|
79 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
80 | 80 | $token = new WC_Payment_Token_CC(); |
81 | - $token->set_token( $source->id ); |
|
82 | - $token->set_gateway_id( 'stripe' ); |
|
83 | - |
|
84 | - if ( 'source' === $source->object && 'card' === $source->type ) { |
|
85 | - $token->set_card_type( strtolower( $source->card->brand ) ); |
|
86 | - $token->set_last4( $source->card->last4 ); |
|
87 | - $token->set_expiry_month( $source->card->exp_month ); |
|
88 | - $token->set_expiry_year( $source->card->exp_year ); |
|
81 | + $token->set_token($source->id); |
|
82 | + $token->set_gateway_id('stripe'); |
|
83 | + |
|
84 | + if ('source' === $source->object && 'card' === $source->type) { |
|
85 | + $token->set_card_type(strtolower($source->card->brand)); |
|
86 | + $token->set_last4($source->card->last4); |
|
87 | + $token->set_expiry_month($source->card->exp_month); |
|
88 | + $token->set_expiry_year($source->card->exp_year); |
|
89 | 89 | } |
90 | 90 | |
91 | - $token->set_user_id( $customer_id ); |
|
91 | + $token->set_user_id($customer_id); |
|
92 | 92 | $token->save(); |
93 | - $tokens[ $token->get_id() ] = $token; |
|
93 | + $tokens[$token->get_id()] = $token; |
|
94 | 94 | } |
95 | 95 | } else { |
96 | - if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) { |
|
96 | + if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) { |
|
97 | 97 | $token = new WC_Payment_Token_CC(); |
98 | - $token->set_token( $source->id ); |
|
99 | - $token->set_gateway_id( 'stripe' ); |
|
100 | - $token->set_card_type( strtolower( $source->brand ) ); |
|
101 | - $token->set_last4( $source->last4 ); |
|
102 | - $token->set_expiry_month( $source->exp_month ); |
|
103 | - $token->set_expiry_year( $source->exp_year ); |
|
104 | - $token->set_user_id( $customer_id ); |
|
98 | + $token->set_token($source->id); |
|
99 | + $token->set_gateway_id('stripe'); |
|
100 | + $token->set_card_type(strtolower($source->brand)); |
|
101 | + $token->set_last4($source->last4); |
|
102 | + $token->set_expiry_month($source->exp_month); |
|
103 | + $token->set_expiry_year($source->exp_year); |
|
104 | + $token->set_user_id($customer_id); |
|
105 | 105 | $token->save(); |
106 | - $tokens[ $token->get_id() ] = $token; |
|
106 | + $tokens[$token->get_id()] = $token; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - if ( 'stripe_sepa' === $gateway_id ) { |
|
113 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
112 | + if ('stripe_sepa' === $gateway_id) { |
|
113 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
114 | 114 | $stripe_sources = $stripe_customer->get_sources(); |
115 | 115 | |
116 | - foreach ( $stripe_sources as $source ) { |
|
117 | - if ( isset( $source->type ) && 'sepa_debit' === $source->type ) { |
|
118 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
116 | + foreach ($stripe_sources as $source) { |
|
117 | + if (isset($source->type) && 'sepa_debit' === $source->type) { |
|
118 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
119 | 119 | $token = new WC_Payment_Token_SEPA(); |
120 | - $token->set_token( $source->id ); |
|
121 | - $token->set_gateway_id( 'stripe_sepa' ); |
|
122 | - $token->set_last4( $source->sepa_debit->last4 ); |
|
123 | - $token->set_user_id( $customer_id ); |
|
120 | + $token->set_token($source->id); |
|
121 | + $token->set_gateway_id('stripe_sepa'); |
|
122 | + $token->set_last4($source->sepa_debit->last4); |
|
123 | + $token->set_user_id($customer_id); |
|
124 | 124 | $token->save(); |
125 | - $tokens[ $token->get_id() ] = $token; |
|
125 | + $tokens[$token->get_id()] = $token; |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @param WC_Payment_Token $payment_token The payment token associated with this method entry |
142 | 142 | * @return array Filtered item |
143 | 143 | */ |
144 | - public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) { |
|
145 | - if ( 'sepa' !== strtolower( $payment_token->get_type() ) ) { |
|
144 | + public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) { |
|
145 | + if ('sepa' !== strtolower($payment_token->get_type())) { |
|
146 | 146 | return $item; |
147 | 147 | } |
148 | 148 | |
149 | 149 | $item['method']['last4'] = $payment_token->get_last4(); |
150 | - $item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' ); |
|
150 | + $item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe'); |
|
151 | 151 | |
152 | 152 | return $item; |
153 | 153 | } |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | * @since 3.1.0 |
159 | 159 | * @version 4.0.0 |
160 | 160 | */ |
161 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
162 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
163 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
164 | - $stripe_customer->delete_source( $token->get_token() ); |
|
161 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
162 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
163 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
164 | + $stripe_customer->delete_source($token->get_token()); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | * @since 3.1.0 |
172 | 172 | * @version 4.0.0 |
173 | 173 | */ |
174 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
175 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
174 | + public function woocommerce_payment_token_set_default($token_id) { |
|
175 | + $token = WC_Payment_Tokens::get($token_id); |
|
176 | 176 | |
177 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
178 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
179 | - $stripe_customer->set_default_source( $token->get_token() ); |
|
177 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
178 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
179 | + $stripe_customer->set_default_source($token->get_token()); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * Set secret API Key. |
27 | 27 | * @param string $key |
28 | 28 | */ |
29 | - public static function set_secret_key( $secret_key ) { |
|
29 | + public static function set_secret_key($secret_key) { |
|
30 | 30 | self::$secret_key = $secret_key; |
31 | 31 | } |
32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | * @return string |
36 | 36 | */ |
37 | 37 | public static function get_secret_key() { |
38 | - if ( ! self::$secret_key ) { |
|
39 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
38 | + if ( ! self::$secret_key) { |
|
39 | + $options = get_option('woocommerce_stripe_settings'); |
|
40 | 40 | |
41 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
42 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
41 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
42 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | return self::$secret_key; |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | $user_agent = self::get_user_agent(); |
79 | 79 | $app_info = $user_agent['application']; |
80 | 80 | |
81 | - return apply_filters( 'woocommerce_stripe_request_headers', array( |
|
82 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
81 | + return apply_filters('woocommerce_stripe_request_headers', array( |
|
82 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
83 | 83 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
84 | 84 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
85 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
86 | - ) ); |
|
85 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
86 | + )); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | * @param string $api |
96 | 96 | * @return array|WP_Error |
97 | 97 | */ |
98 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
99 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
98 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
99 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
100 | 100 | |
101 | 101 | $headers = self::get_headers(); |
102 | 102 | |
103 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
104 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
103 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
104 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
105 | 105 | |
106 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
106 | + if ('charges' === $api && 'POST' === $method) { |
|
107 | 107 | $headers['Idempotency-Key'] = $request['metadata']['order_id'] . '-' . $source; |
108 | 108 | } |
109 | 109 | |
@@ -112,17 +112,17 @@ discard block |
||
112 | 112 | array( |
113 | 113 | 'method' => $method, |
114 | 114 | 'headers' => $headers, |
115 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
115 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
116 | 116 | 'timeout' => 70, |
117 | 117 | ) |
118 | 118 | ); |
119 | 119 | |
120 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
121 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
122 | - throw new Exception( __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
120 | + if (is_wp_error($response) || empty($response['body'])) { |
|
121 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
122 | + throw new Exception(__('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
123 | 123 | } |
124 | 124 | |
125 | - return json_decode( $response['body'] ); |
|
125 | + return json_decode($response['body']); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @version 4.0.0 |
133 | 133 | * @param string $api |
134 | 134 | */ |
135 | - public static function retrieve( $api ) { |
|
136 | - WC_Stripe_Logger::log( "{$api}" ); |
|
135 | + public static function retrieve($api) { |
|
136 | + WC_Stripe_Logger::log("{$api}"); |
|
137 | 137 | |
138 | 138 | $ua = self::get_user_agent(); |
139 | 139 | |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | ) |
147 | 147 | ); |
148 | 148 | |
149 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
150 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
151 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
149 | + if (is_wp_error($response) || empty($response['body'])) { |
|
150 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
151 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
152 | 152 | } |
153 | 153 | |
154 | - return json_decode( $response['body'] ); |
|
154 | + return json_decode($response['body']); |
|
155 | 155 | } |
156 | 156 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @version 4.0.0 |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
20 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -27,24 +27,24 @@ discard block |
||
27 | 27 | * @version 4.0.0 |
28 | 28 | */ |
29 | 29 | public function check_for_webhook() { |
30 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
31 | - || ! isset( $_GET['wc-api'] ) |
|
32 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
30 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
31 | + || ! isset($_GET['wc-api']) |
|
32 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
33 | 33 | ) { |
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - $request_body = file_get_contents( 'php://input' ); |
|
38 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
37 | + $request_body = file_get_contents('php://input'); |
|
38 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
39 | 39 | |
40 | 40 | // Validate it to make sure it is legit. |
41 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
42 | - $this->process_webhook( $request_body ); |
|
43 | - status_header( 200 ); |
|
41 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
42 | + $this->process_webhook($request_body); |
|
43 | + status_header(200); |
|
44 | 44 | exit; |
45 | 45 | } else { |
46 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
47 | - status_header( 400 ); |
|
46 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
47 | + status_header(400); |
|
48 | 48 | exit; |
49 | 49 | } |
50 | 50 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | * @param string $request_body The request body from Stripe. |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
63 | - if ( null === $request_headers || null === $request_body ) { |
|
62 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
63 | + if (null === $request_headers || null === $request_body) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
67 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | * @version 4.0.0 |
81 | 81 | */ |
82 | 82 | public function get_request_headers() { |
83 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
83 | + if ( ! function_exists('getallheaders')) { |
|
84 | 84 | $headers = []; |
85 | - foreach ( $_SERVER as $name => $value ) { |
|
86 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
87 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
85 | + foreach ($_SERVER as $name => $value) { |
|
86 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
87 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -103,30 +103,30 @@ discard block |
||
103 | 103 | * @param object $notification |
104 | 104 | * @param bool $retry |
105 | 105 | */ |
106 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
106 | + public function process_webhook_payment($notification, $retry = true) { |
|
107 | 107 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
108 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
108 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
112 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
112 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
113 | 113 | |
114 | - if ( ! $order ) { |
|
115 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
114 | + if ( ! $order) { |
|
115 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
120 | 120 | $source_id = $notification->data->object->id; |
121 | 121 | |
122 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
122 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
123 | 123 | |
124 | 124 | try { |
125 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
125 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
129 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
@@ -134,69 +134,69 @@ discard block |
||
134 | 134 | $response = null; |
135 | 135 | |
136 | 136 | // This will throw exception if not valid. |
137 | - $this->validate_minimum_order_amount( $order ); |
|
137 | + $this->validate_minimum_order_amount($order); |
|
138 | 138 | |
139 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
139 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
140 | 140 | |
141 | 141 | // Prep source object. |
142 | 142 | $source_object = new stdClass(); |
143 | 143 | $source_object->token_id = ''; |
144 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
144 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
145 | 145 | $source_object->source = $source_id; |
146 | 146 | |
147 | 147 | // Make the request. |
148 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
148 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
149 | 149 | |
150 | - if ( ! empty( $response->error ) ) { |
|
150 | + if ( ! empty($response->error)) { |
|
151 | 151 | // If it is an API error such connection or server, let's retry. |
152 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
153 | - if ( $retry ) { |
|
154 | - sleep( 5 ); |
|
155 | - return $this->process_payment( $order_id, false ); |
|
152 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
153 | + if ($retry) { |
|
154 | + sleep(5); |
|
155 | + return $this->process_payment($order_id, false); |
|
156 | 156 | } else { |
157 | 157 | $message = 'API connection error and retries exhausted.'; |
158 | - $order->add_order_note( $message ); |
|
159 | - throw new Exception( $message ); |
|
158 | + $order->add_order_note($message); |
|
159 | + throw new Exception($message); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
164 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
165 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
164 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
165 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
166 | 166 | |
167 | - return $this->process_payment( $order_id, false ); |
|
167 | + return $this->process_payment($order_id, false); |
|
168 | 168 | |
169 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
169 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
170 | 170 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
171 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
171 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
172 | 172 | $wc_token->delete(); |
173 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
174 | - $order->add_order_note( $message ); |
|
175 | - throw new Exception( $message ); |
|
173 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
174 | + $order->add_order_note($message); |
|
175 | + throw new Exception($message); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
179 | 179 | |
180 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
180 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
181 | 181 | |
182 | - $order->add_order_note( $message ); |
|
182 | + $order->add_order_note($message); |
|
183 | 183 | |
184 | - throw new Exception( $message ); |
|
184 | + throw new Exception($message); |
|
185 | 185 | } |
186 | 186 | |
187 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
187 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
188 | 188 | |
189 | - $this->process_response( $response, $order ); |
|
189 | + $this->process_response($response, $order); |
|
190 | 190 | |
191 | - } catch ( Exception $e ) { |
|
192 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
191 | + } catch (Exception $e) { |
|
192 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
193 | 193 | |
194 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order ); |
|
194 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
195 | 195 | |
196 | - $statuses = array( 'pending', 'failed' ); |
|
196 | + $statuses = array('pending', 'failed'); |
|
197 | 197 | |
198 | - if ( $order->has_status( $statuses ) ) { |
|
199 | - $this->send_failed_order_email( $order_id ); |
|
198 | + if ($order->has_status($statuses)) { |
|
199 | + $this->send_failed_order_email($order_id); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | } |
@@ -210,18 +210,18 @@ discard block |
||
210 | 210 | * @version 4.0.0 |
211 | 211 | * @param object $notification |
212 | 212 | */ |
213 | - public function process_webhook_dispute( $notification ) { |
|
214 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
213 | + public function process_webhook_dispute($notification) { |
|
214 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
215 | 215 | |
216 | - if ( ! $order ) { |
|
217 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
216 | + if ( ! $order) { |
|
217 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
221 | - $order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) ); |
|
221 | + $order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe')); |
|
222 | 222 | |
223 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
224 | - $this->send_failed_order_email( $order_id ); |
|
223 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
224 | + $this->send_failed_order_email($order_id); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -232,41 +232,41 @@ discard block |
||
232 | 232 | * @version 4.0.0 |
233 | 233 | * @param object $notification |
234 | 234 | */ |
235 | - public function process_webhook_capture( $notification ) { |
|
236 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
235 | + public function process_webhook_capture($notification) { |
|
236 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
237 | 237 | |
238 | - if ( ! $order ) { |
|
239 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
238 | + if ( ! $order) { |
|
239 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
240 | 240 | return; |
241 | 241 | } |
242 | 242 | |
243 | 243 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
244 | 244 | |
245 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
246 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
247 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
245 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
246 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
247 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
248 | 248 | |
249 | - if ( $charge && 'no' === $captured ) { |
|
250 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
249 | + if ($charge && 'no' === $captured) { |
|
250 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
251 | 251 | |
252 | 252 | // Store other data such as fees |
253 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
253 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
254 | 254 | |
255 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
256 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
255 | + if (isset($notification->data->object->balance_transaction)) { |
|
256 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
257 | 257 | } |
258 | 258 | |
259 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
259 | + if (is_callable(array($order, 'save'))) { |
|
260 | 260 | $order->save(); |
261 | 261 | } |
262 | 262 | |
263 | 263 | /* translators: transaction id */ |
264 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
264 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
265 | 265 | |
266 | 266 | // Check and see if capture is partial. |
267 | - if ( $this->is_partial_capture( $notification ) ) { |
|
268 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
269 | - $order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
267 | + if ($this->is_partial_capture($notification)) { |
|
268 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
269 | + $order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
270 | 270 | $order->save(); |
271 | 271 | } |
272 | 272 | } |
@@ -281,38 +281,38 @@ discard block |
||
281 | 281 | * @version 4.0.0 |
282 | 282 | * @param object $notification |
283 | 283 | */ |
284 | - public function process_webhook_charge_succeeded( $notification ) { |
|
284 | + public function process_webhook_charge_succeeded($notification) { |
|
285 | 285 | // The following payment methods are synchronous so does not need to be handle via webhook. |
286 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
286 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
287 | 287 | return; |
288 | 288 | } |
289 | 289 | |
290 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
290 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
291 | 291 | |
292 | - if ( ! $order ) { |
|
293 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
292 | + if ( ! $order) { |
|
293 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
294 | 294 | return; |
295 | 295 | } |
296 | 296 | |
297 | 297 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
298 | 298 | |
299 | - if ( 'on-hold' !== $order->get_status() ) { |
|
299 | + if ('on-hold' !== $order->get_status()) { |
|
300 | 300 | return; |
301 | 301 | } |
302 | 302 | |
303 | 303 | // Store other data such as fees |
304 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
304 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
305 | 305 | |
306 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
307 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
306 | + if (isset($notification->data->object->balance_transaction)) { |
|
307 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
308 | 308 | } |
309 | 309 | |
310 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
310 | + if (is_callable(array($order, 'save'))) { |
|
311 | 311 | $order->save(); |
312 | 312 | } |
313 | 313 | |
314 | 314 | /* translators: transaction id */ |
315 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
315 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -323,23 +323,23 @@ discard block |
||
323 | 323 | * @version 4.0.0 |
324 | 324 | * @param object $notification |
325 | 325 | */ |
326 | - public function process_webhook_charge_failed( $notification ) { |
|
327 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
326 | + public function process_webhook_charge_failed($notification) { |
|
327 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
328 | 328 | |
329 | - if ( ! $order ) { |
|
330 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
329 | + if ( ! $order) { |
|
330 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
331 | 331 | return; |
332 | 332 | } |
333 | 333 | |
334 | 334 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
335 | 335 | |
336 | - if ( 'on-hold' !== $order->get_status() ) { |
|
336 | + if ('on-hold' !== $order->get_status()) { |
|
337 | 337 | return; |
338 | 338 | } |
339 | 339 | |
340 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
340 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
341 | 341 | |
342 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
342 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -350,23 +350,23 @@ discard block |
||
350 | 350 | * @version 4.0.0 |
351 | 351 | * @param object $notification |
352 | 352 | */ |
353 | - public function process_webhook_source_canceled( $notification ) { |
|
354 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
353 | + public function process_webhook_source_canceled($notification) { |
|
354 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
355 | 355 | |
356 | - if ( ! $order ) { |
|
357 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
356 | + if ( ! $order) { |
|
357 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | 361 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
362 | 362 | |
363 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
363 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
364 | 364 | return; |
365 | 365 | } |
366 | 366 | |
367 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
367 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
368 | 368 | |
369 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
369 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -377,31 +377,31 @@ discard block |
||
377 | 377 | * @version 4.0.0 |
378 | 378 | * @param object $notification |
379 | 379 | */ |
380 | - public function process_webhook_refund( $notification ) { |
|
381 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
380 | + public function process_webhook_refund($notification) { |
|
381 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
382 | 382 | |
383 | - if ( ! $order ) { |
|
384 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
383 | + if ( ! $order) { |
|
384 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
385 | 385 | return; |
386 | 386 | } |
387 | 387 | |
388 | 388 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
389 | 389 | |
390 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
391 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
392 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
390 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
391 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
392 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
393 | 393 | |
394 | 394 | // Only refund captured charge. |
395 | - if ( $charge && 'yes' === $captured ) { |
|
395 | + if ($charge && 'yes' === $captured) { |
|
396 | 396 | // Create the refund. |
397 | - $refund = wc_create_refund( array( |
|
397 | + $refund = wc_create_refund(array( |
|
398 | 398 | 'order_id' => $order_id, |
399 | - 'amount' => $this->get_refund_amount( $notification ), |
|
400 | - 'reason' => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ), |
|
401 | - ) ); |
|
399 | + 'amount' => $this->get_refund_amount($notification), |
|
400 | + 'reason' => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'), |
|
401 | + )); |
|
402 | 402 | |
403 | - if ( is_wp_error( $refund ) ) { |
|
404 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
403 | + if (is_wp_error($refund)) { |
|
404 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | } |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | * @version 4.0.0 |
415 | 415 | * @param object $notification |
416 | 416 | */ |
417 | - public function is_partial_capture( $notification ) { |
|
417 | + public function is_partial_capture($notification) { |
|
418 | 418 | return 0 < $notification->data->object->amount_refunded; |
419 | 419 | } |
420 | 420 | |
@@ -425,11 +425,11 @@ discard block |
||
425 | 425 | * @version 4.0.0 |
426 | 426 | * @param object $notification |
427 | 427 | */ |
428 | - public function get_refund_amount( $notification ) { |
|
429 | - if ( $this->is_partial_capture( $notification ) ) { |
|
428 | + public function get_refund_amount($notification) { |
|
429 | + if ($this->is_partial_capture($notification)) { |
|
430 | 430 | $amount = $notification->data->object->amount_refunded / 100; |
431 | 431 | |
432 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
432 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
433 | 433 | $amount = $notification->data->object->amount_refunded; |
434 | 434 | } |
435 | 435 | |
@@ -446,12 +446,12 @@ discard block |
||
446 | 446 | * @version 4.0.0 |
447 | 447 | * @param object $notification |
448 | 448 | */ |
449 | - public function get_partial_amount_to_charge( $notification ) { |
|
450 | - if ( $this->is_partial_capture( $notification ) ) { |
|
451 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
449 | + public function get_partial_amount_to_charge($notification) { |
|
450 | + if ($this->is_partial_capture($notification)) { |
|
451 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
452 | 452 | |
453 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
454 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
453 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
454 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | return $amount; |
@@ -467,36 +467,36 @@ discard block |
||
467 | 467 | * @version 4.0.0 |
468 | 468 | * @param string $request_body |
469 | 469 | */ |
470 | - public function process_webhook( $request_body ) { |
|
471 | - $notification = json_decode( $request_body ); |
|
470 | + public function process_webhook($request_body) { |
|
471 | + $notification = json_decode($request_body); |
|
472 | 472 | |
473 | - switch ( $notification->type ) { |
|
473 | + switch ($notification->type) { |
|
474 | 474 | case 'source.chargeable': |
475 | - $this->process_webhook_payment( $notification ); |
|
475 | + $this->process_webhook_payment($notification); |
|
476 | 476 | break; |
477 | 477 | |
478 | 478 | case 'source.canceled': |
479 | - $this->process_webhook_source_canceled( $notification ); |
|
479 | + $this->process_webhook_source_canceled($notification); |
|
480 | 480 | break; |
481 | 481 | |
482 | 482 | case 'charge.succeeded': |
483 | - $this->process_webhook_charge_succeeded( $notification ); |
|
483 | + $this->process_webhook_charge_succeeded($notification); |
|
484 | 484 | break; |
485 | 485 | |
486 | 486 | case 'charge.failed': |
487 | - $this->process_webhook_charge_failed( $notification ); |
|
487 | + $this->process_webhook_charge_failed($notification); |
|
488 | 488 | break; |
489 | 489 | |
490 | 490 | case 'charge.captured': |
491 | - $this->process_webhook_capture( $notification ); |
|
491 | + $this->process_webhook_capture($notification); |
|
492 | 492 | break; |
493 | 493 | |
494 | 494 | case 'charge.dispute.created': |
495 | - $this->process_webhook_dispute( $notification ); |
|
495 | + $this->process_webhook_dispute($notification); |
|
496 | 496 | break; |
497 | 497 | |
498 | 498 | case 'charge.refunded': |
499 | - $this->process_webhook_refund( $notification ); |
|
499 | + $this->process_webhook_refund($notification); |
|
500 | 500 | break; |
501 | 501 | |
502 | 502 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -20,23 +20,23 @@ discard block |
||
20 | 20 | * @since 4.0.0 |
21 | 21 | * @version 4.0.0 |
22 | 22 | */ |
23 | - public static function log( $message, $start_time = null, $end_time = null ) { |
|
24 | - if ( empty( self::$logger ) ) { |
|
23 | + public static function log($message, $start_time = null, $end_time = null) { |
|
24 | + if (empty(self::$logger)) { |
|
25 | 25 | self::$logger = new WC_Logger(); |
26 | 26 | } |
27 | 27 | |
28 | - $settings = get_option( 'woocommerce_stripe_settings' ); |
|
28 | + $settings = get_option('woocommerce_stripe_settings'); |
|
29 | 29 | |
30 | - if ( empty( $settings ) || isset( $settings['logging'] ) && 'yes' !== $settings['logging'] ) { |
|
30 | + if (empty($settings) || isset($settings['logging']) && 'yes' !== $settings['logging']) { |
|
31 | 31 | return; |
32 | 32 | } |
33 | 33 | |
34 | - if ( ! is_null( $start_time ) ) { |
|
34 | + if ( ! is_null($start_time)) { |
|
35 | 35 | |
36 | - $formatted_start_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $start_time ); |
|
37 | - $end_time = is_null( $end_time ) ? current_time( 'timestamp' ) : $end_time; |
|
38 | - $formatted_end_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $end_time ); |
|
39 | - $elapsed_time = round( abs( $end_time - $start_time ) / 60, 2 ); |
|
36 | + $formatted_start_time = date_i18n(get_option('date_format') . ' g:ia', $start_time); |
|
37 | + $end_time = is_null($end_time) ? current_time('timestamp') : $end_time; |
|
38 | + $formatted_end_time = date_i18n(get_option('date_format') . ' g:ia', $end_time); |
|
39 | + $elapsed_time = round(abs($end_time - $start_time) / 60, 2); |
|
40 | 40 | |
41 | 41 | $log_entry = '====Start Log ' . $formatted_start_time . '====' . "\n" . $message . "\n"; |
42 | 42 | $log_entry .= '====End Log ' . $formatted_end_time . ' (' . $elapsed_time . ')====' . "\n\n"; |
@@ -47,6 +47,6 @@ discard block |
||
47 | 47 | |
48 | 48 | } |
49 | 49 | |
50 | - self::$logger->add( self::WC_LOG_FILENAME, $log_entry ); |
|
50 | + self::$logger->add(self::WC_LOG_FILENAME, $log_entry); |
|
51 | 51 | } |
52 | 52 | } |
@@ -1,50 +1,50 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | $webhook_url = WC_Stripe_Helper::get_webhook_url(); |
7 | 7 | |
8 | -return apply_filters( 'wc_stripe_bitcoin_settings', |
|
8 | +return apply_filters('wc_stripe_bitcoin_settings', |
|
9 | 9 | array( |
10 | 10 | 'geo_target' => array( |
11 | - 'description' => __( 'Relevant Payer Geography: Global', 'woocommerce-gateway-stripe' ), |
|
11 | + 'description' => __('Relevant Payer Geography: Global', 'woocommerce-gateway-stripe'), |
|
12 | 12 | 'type' => 'title', |
13 | 13 | ), |
14 | 14 | 'guide' => array( |
15 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#bitcoin" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
15 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#bitcoin" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
16 | 16 | 'type' => 'title', |
17 | 17 | ), |
18 | 18 | 'activation' => array( |
19 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
19 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'type' => 'title', |
21 | 21 | ), |
22 | 22 | 'enabled' => array( |
23 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
24 | - 'label' => __( 'Enable Stripe Bitcoin', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
24 | + 'label' => __('Enable Stripe Bitcoin', 'woocommerce-gateway-stripe'), |
|
25 | 25 | 'type' => 'checkbox', |
26 | 26 | 'description' => '', |
27 | 27 | 'default' => 'no', |
28 | 28 | ), |
29 | 29 | 'title' => array( |
30 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
31 | 31 | 'type' => 'text', |
32 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
33 | - 'default' => __( 'Bitcoin', 'woocommerce-gateway-stripe' ), |
|
32 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
33 | + 'default' => __('Bitcoin', 'woocommerce-gateway-stripe'), |
|
34 | 34 | 'desc_tip' => true, |
35 | 35 | ), |
36 | 36 | 'description' => array( |
37 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
37 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
38 | 38 | 'type' => 'text', |
39 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
40 | - 'default' => __( 'Bitcoin payment information will be provided when you place the order.', 'woocommerce-gateway-stripe' ), |
|
39 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
40 | + 'default' => __('Bitcoin payment information will be provided when you place the order.', 'woocommerce-gateway-stripe'), |
|
41 | 41 | 'desc_tip' => true, |
42 | 42 | ), |
43 | 43 | 'webhook' => array( |
44 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
44 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
45 | 45 | 'type' => 'title', |
46 | 46 | /* translators: webhook URL */ |
47 | - 'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ), |
|
47 | + 'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url), |
|
48 | 48 | ), |
49 | 49 | ) |
50 | 50 | ); |
@@ -1,50 +1,50 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | $webhook_url = WC_Stripe_Helper::get_webhook_url(); |
7 | 7 | |
8 | -return apply_filters( 'wc_stripe_ideal_settings', |
|
8 | +return apply_filters('wc_stripe_ideal_settings', |
|
9 | 9 | array( |
10 | 10 | 'geo_target' => array( |
11 | - 'description' => __( 'Relevant Payer Geography: The Netherlands', 'woocommerce-gateway-stripe' ), |
|
11 | + 'description' => __('Relevant Payer Geography: The Netherlands', 'woocommerce-gateway-stripe'), |
|
12 | 12 | 'type' => 'title', |
13 | 13 | ), |
14 | 14 | 'guide' => array( |
15 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#ideal" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
15 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#ideal" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
16 | 16 | 'type' => 'title', |
17 | 17 | ), |
18 | 18 | 'activation' => array( |
19 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
19 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'type' => 'title', |
21 | 21 | ), |
22 | 22 | 'enabled' => array( |
23 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
24 | - 'label' => __( 'Enable Stripe iDeal', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
24 | + 'label' => __('Enable Stripe iDeal', 'woocommerce-gateway-stripe'), |
|
25 | 25 | 'type' => 'checkbox', |
26 | 26 | 'description' => '', |
27 | 27 | 'default' => 'no', |
28 | 28 | ), |
29 | 29 | 'title' => array( |
30 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
31 | 31 | 'type' => 'text', |
32 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
33 | - 'default' => __( 'iDeal', 'woocommerce-gateway-stripe' ), |
|
32 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
33 | + 'default' => __('iDeal', 'woocommerce-gateway-stripe'), |
|
34 | 34 | 'desc_tip' => true, |
35 | 35 | ), |
36 | 36 | 'description' => array( |
37 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
37 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
38 | 38 | 'type' => 'text', |
39 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
40 | - 'default' => __( 'You will be redirected to iDeal.', 'woocommerce-gateway-stripe' ), |
|
39 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
40 | + 'default' => __('You will be redirected to iDeal.', 'woocommerce-gateway-stripe'), |
|
41 | 41 | 'desc_tip' => true, |
42 | 42 | ), |
43 | 43 | 'webhook' => array( |
44 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
44 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
45 | 45 | 'type' => 'title', |
46 | 46 | /* translators: webhook URL */ |
47 | - 'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ), |
|
47 | + 'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url), |
|
48 | 48 | ), |
49 | 49 | ) |
50 | 50 | ); |
@@ -1,50 +1,50 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | $webhook_url = WC_Stripe_Helper::get_webhook_url(); |
7 | 7 | |
8 | -return apply_filters( 'wc_stripe_sofort_settings', |
|
8 | +return apply_filters('wc_stripe_sofort_settings', |
|
9 | 9 | array( |
10 | 10 | 'geo_target' => array( |
11 | - 'description' => __( 'Relevant Payer Geography: Germany, Austria', 'woocommerce-gateway-stripe' ), |
|
11 | + 'description' => __('Relevant Payer Geography: Germany, Austria', 'woocommerce-gateway-stripe'), |
|
12 | 12 | 'type' => 'title', |
13 | 13 | ), |
14 | 14 | 'guide' => array( |
15 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#sofort" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
15 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#sofort" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
16 | 16 | 'type' => 'title', |
17 | 17 | ), |
18 | 18 | 'activation' => array( |
19 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
19 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'type' => 'title', |
21 | 21 | ), |
22 | 22 | 'enabled' => array( |
23 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
24 | - 'label' => __( 'Enable Stripe SOFORT', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
24 | + 'label' => __('Enable Stripe SOFORT', 'woocommerce-gateway-stripe'), |
|
25 | 25 | 'type' => 'checkbox', |
26 | 26 | 'description' => '', |
27 | 27 | 'default' => 'no', |
28 | 28 | ), |
29 | 29 | 'title' => array( |
30 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
31 | 31 | 'type' => 'text', |
32 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
33 | - 'default' => __( 'SOFORT', 'woocommerce-gateway-stripe' ), |
|
32 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
33 | + 'default' => __('SOFORT', 'woocommerce-gateway-stripe'), |
|
34 | 34 | 'desc_tip' => true, |
35 | 35 | ), |
36 | 36 | 'description' => array( |
37 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
37 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
38 | 38 | 'type' => 'text', |
39 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
40 | - 'default' => __( 'You will be redirected to SOFORT.', 'woocommerce-gateway-stripe' ), |
|
39 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
40 | + 'default' => __('You will be redirected to SOFORT.', 'woocommerce-gateway-stripe'), |
|
41 | 41 | 'desc_tip' => true, |
42 | 42 | ), |
43 | 43 | 'webhook' => array( |
44 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
44 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
45 | 45 | 'type' => 'title', |
46 | 46 | /* translators: webhook URL */ |
47 | - 'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ), |
|
47 | + 'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url), |
|
48 | 48 | ), |
49 | 49 | ) |
50 | 50 | ); |
@@ -1,50 +1,50 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | $webhook_url = WC_Stripe_Helper::get_webhook_url(); |
7 | 7 | |
8 | -return apply_filters( 'wc_stripe_giropay_settings', |
|
8 | +return apply_filters('wc_stripe_giropay_settings', |
|
9 | 9 | array( |
10 | 10 | 'geo_target' => array( |
11 | - 'description' => __( 'Relevant Payer Geography: Germany', 'woocommerce-gateway-stripe' ), |
|
11 | + 'description' => __('Relevant Payer Geography: Germany', 'woocommerce-gateway-stripe'), |
|
12 | 12 | 'type' => 'title', |
13 | 13 | ), |
14 | 14 | 'guide' => array( |
15 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#giropay" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
15 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#giropay" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
16 | 16 | 'type' => 'title', |
17 | 17 | ), |
18 | 18 | 'activation' => array( |
19 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
19 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'type' => 'title', |
21 | 21 | ), |
22 | 22 | 'enabled' => array( |
23 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
24 | - 'label' => __( 'Enable Stripe Giropay', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
24 | + 'label' => __('Enable Stripe Giropay', 'woocommerce-gateway-stripe'), |
|
25 | 25 | 'type' => 'checkbox', |
26 | 26 | 'description' => '', |
27 | 27 | 'default' => 'no', |
28 | 28 | ), |
29 | 29 | 'title' => array( |
30 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
31 | 31 | 'type' => 'text', |
32 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
33 | - 'default' => __( 'Giropay', 'woocommerce-gateway-stripe' ), |
|
32 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
33 | + 'default' => __('Giropay', 'woocommerce-gateway-stripe'), |
|
34 | 34 | 'desc_tip' => true, |
35 | 35 | ), |
36 | 36 | 'description' => array( |
37 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
37 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
38 | 38 | 'type' => 'text', |
39 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
40 | - 'default' => __( 'You will be redirected to Giropay.', 'woocommerce-gateway-stripe' ), |
|
39 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
40 | + 'default' => __('You will be redirected to Giropay.', 'woocommerce-gateway-stripe'), |
|
41 | 41 | 'desc_tip' => true, |
42 | 42 | ), |
43 | 43 | 'webhook' => array( |
44 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
44 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
45 | 45 | 'type' => 'title', |
46 | 46 | /* translators: webhook URL */ |
47 | - 'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ), |
|
47 | + 'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url), |
|
48 | 48 | ), |
49 | 49 | ) |
50 | 50 | ); |