@@ -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,7 +21,7 @@ discard block |
||
21 | 21 | * @since 4.0.5 |
22 | 22 | * @param array $error |
23 | 23 | */ |
24 | - public function is_retryable_error( $error ) { |
|
24 | + public function is_retryable_error($error) { |
|
25 | 25 | return ( |
26 | 26 | 'invalid_request_error' === $error->type || |
27 | 27 | 'idempotency_error' === $error->type || |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | * Check if this gateway is enabled |
34 | 34 | */ |
35 | 35 | public function is_available() { |
36 | - if ( 'yes' === $this->enabled ) { |
|
37 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
36 | + if ('yes' === $this->enabled) { |
|
37 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
38 | 38 | return false; |
39 | 39 | } |
40 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
40 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
41 | 41 | return false; |
42 | 42 | } |
43 | 43 | return true; |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | * @since 4.0.0 |
53 | 53 | * @version 4.0.0 |
54 | 54 | */ |
55 | - public function add_admin_notice( $slug, $class, $message ) { |
|
56 | - $this->notices[ $slug ] = array( |
|
55 | + public function add_admin_notice($slug, $class, $message) { |
|
56 | + $this->notices[$slug] = array( |
|
57 | 57 | 'class' => $class, |
58 | 58 | 'message' => $message, |
59 | 59 | ); |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * @version 4.0.0 |
67 | 67 | */ |
68 | 68 | public function remove_admin_notice() { |
69 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
70 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
69 | + if (did_action('woocommerce_update_options')) { |
|
70 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @return array |
80 | 80 | */ |
81 | 81 | public function payment_icons() { |
82 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
82 | + return apply_filters('wc_stripe_payment_icons', array( |
|
83 | 83 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
84 | 84 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
85 | 85 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
97 | 97 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
98 | 98 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
99 | - ) ); |
|
99 | + )); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | * @version 4.0.0 |
108 | 108 | * @param object $order |
109 | 109 | */ |
110 | - public function validate_minimum_order_amount( $order ) { |
|
111 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
110 | + public function validate_minimum_order_amount($order) { |
|
111 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
112 | 112 | /* translators: 1) dollar amount */ |
113 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', 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 ) ) ); |
|
113 | + throw new WC_Stripe_Exception('Did not meet minimum amount', 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))); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | * @since 4.0.0 |
121 | 121 | * @version 4.0.0 |
122 | 122 | */ |
123 | - public function get_transaction_url( $order ) { |
|
124 | - if ( $this->testmode ) { |
|
123 | + public function get_transaction_url($order) { |
|
124 | + if ($this->testmode) { |
|
125 | 125 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
126 | 126 | } else { |
127 | 127 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
128 | 128 | } |
129 | 129 | |
130 | - return parent::get_transaction_url( $order ); |
|
130 | + return parent::get_transaction_url($order); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | * @since 4.0.0 |
137 | 137 | * @version 4.0.0 |
138 | 138 | */ |
139 | - public function get_stripe_customer_id( $order ) { |
|
140 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
139 | + public function get_stripe_customer_id($order) { |
|
140 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
141 | 141 | |
142 | - if ( empty( $customer ) ) { |
|
142 | + if (empty($customer)) { |
|
143 | 143 | // Try to get it via the order. |
144 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
145 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
144 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
145 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
146 | 146 | } else { |
147 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
147 | + return $order->get_meta('_stripe_customer_id', true); |
|
148 | 148 | } |
149 | 149 | } else { |
150 | 150 | return $customer; |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | * @param object $order |
162 | 162 | * @param int $id Stripe session id. |
163 | 163 | */ |
164 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
165 | - if ( is_object( $order ) ) { |
|
166 | - if ( empty( $id ) ) { |
|
164 | + public function get_stripe_return_url($order = null, $id = null) { |
|
165 | + if (is_object($order)) { |
|
166 | + if (empty($id)) { |
|
167 | 167 | $id = uniqid(); |
168 | 168 | } |
169 | 169 | |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | 'order_id' => $order_id, |
175 | 175 | ); |
176 | 176 | |
177 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
177 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
178 | 178 | } |
179 | 179 | |
180 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
180 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -189,34 +189,33 @@ discard block |
||
189 | 189 | * @param object $source |
190 | 190 | * @return array() |
191 | 191 | */ |
192 | - public function generate_payment_request( $order, $source ) { |
|
193 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
194 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
195 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
192 | + public function generate_payment_request($order, $source) { |
|
193 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
194 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
195 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
196 | 196 | $post_data = array(); |
197 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
198 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
197 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
198 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
199 | 199 | /* translators: 1) blog name 2) order number */ |
200 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
200 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
201 | 201 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
202 | 202 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
203 | 203 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
204 | 204 | |
205 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
205 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
206 | 206 | $post_data['receipt_email'] = $billing_email; |
207 | 207 | } |
208 | 208 | |
209 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
210 | - case 'stripe': |
|
211 | - if ( ! empty( $statement_descriptor ) ) { |
|
212 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
209 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
210 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
211 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
213 | 212 | } |
214 | 213 | |
215 | 214 | $post_data['capture'] = $capture ? 'true' : 'false'; |
216 | 215 | break; |
217 | 216 | case 'stripe_sepa': |
218 | - if ( ! empty( $statement_descriptor ) ) { |
|
219 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
217 | + if ( ! empty($statement_descriptor)) { |
|
218 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
220 | 219 | } |
221 | 220 | break; |
222 | 221 | } |
@@ -224,18 +223,18 @@ discard block |
||
224 | 223 | $post_data['expand[]'] = 'balance_transaction'; |
225 | 224 | |
226 | 225 | $metadata = array( |
227 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
228 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
226 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
227 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
229 | 228 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
230 | 229 | ); |
231 | 230 | |
232 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
231 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
233 | 232 | |
234 | - if ( $source->customer ) { |
|
233 | + if ($source->customer) { |
|
235 | 234 | $post_data['customer'] = $source->customer; |
236 | 235 | } |
237 | 236 | |
238 | - if ( $source->source ) { |
|
237 | + if ($source->source) { |
|
239 | 238 | $post_data['source'] = $source->source; |
240 | 239 | } |
241 | 240 | |
@@ -247,77 +246,77 @@ discard block |
||
247 | 246 | * @param WC_Order $order |
248 | 247 | * @param object $source |
249 | 248 | */ |
250 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
249 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
251 | 250 | } |
252 | 251 | |
253 | 252 | /** |
254 | 253 | * Store extra meta data for an order from a Stripe Response. |
255 | 254 | */ |
256 | - public function process_response( $response, $order ) { |
|
257 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
255 | + public function process_response($response, $order) { |
|
256 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
258 | 257 | |
259 | 258 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
260 | 259 | |
261 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
260 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
262 | 261 | |
263 | 262 | // Store charge data |
264 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
263 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
265 | 264 | |
266 | 265 | // Store other data such as fees |
267 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
266 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
268 | 267 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
269 | 268 | // values are in the local currency of the Stripe account, not from WC. |
270 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
271 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
272 | - 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 ); |
|
273 | - 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 ); |
|
269 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
270 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
271 | + 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); |
|
272 | + 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); |
|
274 | 273 | } |
275 | 274 | |
276 | - if ( 'yes' === $captured ) { |
|
275 | + if ('yes' === $captured) { |
|
277 | 276 | /** |
278 | 277 | * Charge can be captured but in a pending state. Payment methods |
279 | 278 | * that are asynchronous may take couple days to clear. Webhook will |
280 | 279 | * take care of the status changes. |
281 | 280 | */ |
282 | - if ( 'pending' === $response->status ) { |
|
283 | - if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) { |
|
284 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
281 | + if ('pending' === $response->status) { |
|
282 | + if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) { |
|
283 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
285 | 284 | } |
286 | 285 | |
287 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
286 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
288 | 287 | /* translators: transaction id */ |
289 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
288 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
290 | 289 | } |
291 | 290 | |
292 | - if ( 'succeeded' === $response->status ) { |
|
293 | - $order->payment_complete( $response->id ); |
|
291 | + if ('succeeded' === $response->status) { |
|
292 | + $order->payment_complete($response->id); |
|
294 | 293 | |
295 | 294 | /* translators: transaction id */ |
296 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
297 | - $order->add_order_note( $message ); |
|
295 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
296 | + $order->add_order_note($message); |
|
298 | 297 | } |
299 | 298 | |
300 | - if ( 'failed' === $response->status ) { |
|
301 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
302 | - $order->add_order_note( $localized_message ); |
|
303 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
299 | + if ('failed' === $response->status) { |
|
300 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
301 | + $order->add_order_note($localized_message); |
|
302 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
304 | 303 | } |
305 | 304 | } else { |
306 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
305 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
307 | 306 | |
308 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
309 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
307 | + if ($order->has_status(array('pending', 'failed'))) { |
|
308 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
310 | 309 | } |
311 | 310 | |
312 | 311 | /* translators: transaction id */ |
313 | - $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 ) ); |
|
312 | + $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)); |
|
314 | 313 | } |
315 | 314 | |
316 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
315 | + if (is_callable(array($order, 'save'))) { |
|
317 | 316 | $order->save(); |
318 | 317 | } |
319 | 318 | |
320 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
319 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
321 | 320 | |
322 | 321 | return $response; |
323 | 322 | } |
@@ -330,10 +329,10 @@ discard block |
||
330 | 329 | * @param int $order_id |
331 | 330 | * @return null |
332 | 331 | */ |
333 | - public function send_failed_order_email( $order_id ) { |
|
332 | + public function send_failed_order_email($order_id) { |
|
334 | 333 | $emails = WC()->mailer()->get_emails(); |
335 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
336 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
334 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
335 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
337 | 336 | } |
338 | 337 | } |
339 | 338 | |
@@ -345,7 +344,7 @@ discard block |
||
345 | 344 | * @param object $order |
346 | 345 | * @return object $details |
347 | 346 | */ |
348 | - public function get_owner_details( $order ) { |
|
347 | + public function get_owner_details($order) { |
|
349 | 348 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
350 | 349 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
351 | 350 | |
@@ -356,8 +355,8 @@ discard block |
||
356 | 355 | |
357 | 356 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
358 | 357 | |
359 | - if ( ! empty( $phone ) ) { |
|
360 | - $details['phone'] = $phone; |
|
358 | + if ( ! empty($phone)) { |
|
359 | + $details['phone'] = $phone; |
|
361 | 360 | } |
362 | 361 | |
363 | 362 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -367,7 +366,7 @@ discard block |
||
367 | 366 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
368 | 367 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
369 | 368 | |
370 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
369 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
371 | 370 | } |
372 | 371 | |
373 | 372 | /** |
@@ -376,16 +375,16 @@ discard block |
||
376 | 375 | * @since 4.0.3 |
377 | 376 | */ |
378 | 377 | public function get_source_object() { |
379 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
378 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
380 | 379 | |
381 | - if ( empty( $source ) ) { |
|
380 | + if (empty($source)) { |
|
382 | 381 | return ''; |
383 | 382 | } |
384 | 383 | |
385 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
384 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
386 | 385 | |
387 | - if ( ! empty( $source_object->error ) ) { |
|
388 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
386 | + if ( ! empty($source_object->error)) { |
|
387 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
389 | 388 | } |
390 | 389 | |
391 | 390 | return $source_object; |
@@ -398,11 +397,11 @@ discard block |
||
398 | 397 | * @param object $source_object |
399 | 398 | * @return bool |
400 | 399 | */ |
401 | - public function is_3ds_required( $source_object ) { |
|
400 | + public function is_3ds_required($source_object) { |
|
402 | 401 | return ( |
403 | - $source_object && ! empty( $source_object->card ) ) && |
|
404 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
405 | - ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) |
|
402 | + $source_object && ! empty($source_object->card) ) && |
|
403 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
404 | + ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure) |
|
406 | 405 | ); |
407 | 406 | } |
408 | 407 | |
@@ -413,8 +412,8 @@ discard block |
||
413 | 412 | * @param object $source_object |
414 | 413 | * @return bool |
415 | 414 | */ |
416 | - public function is_3ds_card( $source_object ) { |
|
417 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
415 | + public function is_3ds_card($source_object) { |
|
416 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
418 | 417 | } |
419 | 418 | |
420 | 419 | /** |
@@ -427,22 +426,22 @@ discard block |
||
427 | 426 | * @param string $return_url |
428 | 427 | * @return mixed |
429 | 428 | */ |
430 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
429 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
431 | 430 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
432 | 431 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
433 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
432 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
434 | 433 | |
435 | 434 | $post_data = array(); |
436 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
437 | - $post_data['currency'] = strtolower( $currency ); |
|
435 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
436 | + $post_data['currency'] = strtolower($currency); |
|
438 | 437 | $post_data['type'] = 'three_d_secure'; |
439 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
440 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
441 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
438 | + $post_data['owner'] = $this->get_owner_details($order); |
|
439 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
440 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
442 | 441 | |
443 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
442 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
444 | 443 | |
445 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
444 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
446 | 445 | } |
447 | 446 | |
448 | 447 | /** |
@@ -459,54 +458,54 @@ discard block |
||
459 | 458 | * @throws Exception When card was not added or for and invalid card. |
460 | 459 | * @return object |
461 | 460 | */ |
462 | - public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) { |
|
463 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
461 | + public function prepare_source($source_object = '', $user_id, $force_save_source = false) { |
|
462 | + $customer = new WC_Stripe_Customer($user_id); |
|
464 | 463 | $set_customer = true; |
465 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
464 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
466 | 465 | $source_id = ''; |
467 | 466 | $wc_token_id = false; |
468 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
467 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
469 | 468 | |
470 | 469 | // New CC info was entered and we have a new source to process. |
471 | - if ( ! empty( $source_object ) ) { |
|
470 | + if ( ! empty($source_object)) { |
|
472 | 471 | $source_id = $source_object->id; |
473 | 472 | |
474 | 473 | // This checks to see if customer opted to save the payment method to file. |
475 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
474 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
476 | 475 | |
477 | 476 | /** |
478 | 477 | * This is true if the user wants to store the card to their account. |
479 | 478 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
480 | 479 | * actually reusable. Either that or force_save_source is true. |
481 | 480 | */ |
482 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
483 | - $response = $customer->add_source( $source_object->id ); |
|
481 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
482 | + $response = $customer->add_source($source_object->id); |
|
484 | 483 | |
485 | - if ( ! empty( $response->error ) ) { |
|
486 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
484 | + if ( ! empty($response->error)) { |
|
485 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
487 | 486 | } |
488 | 487 | } |
489 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
488 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
490 | 489 | // Use an existing token, and then process the payment |
491 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
492 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
490 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
491 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
493 | 492 | |
494 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
495 | - WC()->session->set( 'refresh_totals', true ); |
|
496 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
493 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
494 | + WC()->session->set('refresh_totals', true); |
|
495 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
497 | 496 | } |
498 | 497 | |
499 | 498 | $source_id = $wc_token->get_token(); |
500 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
501 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
502 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
499 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
500 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
501 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
503 | 502 | |
504 | 503 | // This is true if the user wants to store the card to their account. |
505 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
506 | - $response = $customer->add_source( $stripe_token ); |
|
504 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
505 | + $response = $customer->add_source($stripe_token); |
|
507 | 506 | |
508 | - if ( ! empty( $response->error ) ) { |
|
509 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
507 | + if ( ! empty($response->error)) { |
|
508 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
510 | 509 | } |
511 | 510 | } else { |
512 | 511 | $set_customer = false; |
@@ -514,7 +513,7 @@ discard block |
||
514 | 513 | } |
515 | 514 | } |
516 | 515 | |
517 | - if ( ! $set_customer ) { |
|
516 | + if ( ! $set_customer) { |
|
518 | 517 | $customer_id = false; |
519 | 518 | } else { |
520 | 519 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
@@ -540,37 +539,37 @@ discard block |
||
540 | 539 | * @param object $order |
541 | 540 | * @return object |
542 | 541 | */ |
543 | - public function prepare_order_source( $order = null ) { |
|
542 | + public function prepare_order_source($order = null) { |
|
544 | 543 | $stripe_customer = new WC_Stripe_Customer(); |
545 | 544 | $stripe_source = false; |
546 | 545 | $token_id = false; |
547 | 546 | |
548 | - if ( $order ) { |
|
547 | + if ($order) { |
|
549 | 548 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
550 | 549 | |
551 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
550 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
552 | 551 | |
553 | - if ( $stripe_customer_id ) { |
|
554 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
552 | + if ($stripe_customer_id) { |
|
553 | + $stripe_customer->set_id($stripe_customer_id); |
|
555 | 554 | } |
556 | 555 | |
557 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
556 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
558 | 557 | |
559 | 558 | // Since 4.0.0, we changed card to source so we need to account for that. |
560 | - if ( empty( $source_id ) ) { |
|
561 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
559 | + if (empty($source_id)) { |
|
560 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
562 | 561 | |
563 | 562 | // Take this opportunity to update the key name. |
564 | - 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 ); |
|
563 | + 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); |
|
565 | 564 | |
566 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
565 | + if (is_callable(array($order, 'save'))) { |
|
567 | 566 | $order->save(); |
568 | 567 | } |
569 | 568 | } |
570 | 569 | |
571 | - if ( $source_id ) { |
|
570 | + if ($source_id) { |
|
572 | 571 | $stripe_source = $source_id; |
573 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
572 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
574 | 573 | /* |
575 | 574 | * We can attempt to charge the customer's default source |
576 | 575 | * by sending empty source id. |
@@ -594,27 +593,27 @@ discard block |
||
594 | 593 | * @param WC_Order $order For to which the source applies. |
595 | 594 | * @param stdClass $source Source information. |
596 | 595 | */ |
597 | - public function save_source_to_order( $order, $source ) { |
|
596 | + public function save_source_to_order($order, $source) { |
|
598 | 597 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
599 | 598 | |
600 | 599 | // Store source in the order. |
601 | - if ( $source->customer ) { |
|
602 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
603 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
600 | + if ($source->customer) { |
|
601 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
602 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
604 | 603 | } else { |
605 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
604 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
606 | 605 | } |
607 | 606 | } |
608 | 607 | |
609 | - if ( $source->source ) { |
|
610 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
611 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
608 | + if ($source->source) { |
|
609 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
610 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
612 | 611 | } else { |
613 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
612 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
614 | 613 | } |
615 | 614 | } |
616 | 615 | |
617 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
616 | + if (is_callable(array($order, 'save'))) { |
|
618 | 617 | $order->save(); |
619 | 618 | } |
620 | 619 | } |
@@ -628,27 +627,27 @@ discard block |
||
628 | 627 | * @param object $order The order object |
629 | 628 | * @param int $balance_transaction_id |
630 | 629 | */ |
631 | - public function update_fees( $order, $balance_transaction_id ) { |
|
630 | + public function update_fees($order, $balance_transaction_id) { |
|
632 | 631 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
633 | 632 | |
634 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
633 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
635 | 634 | |
636 | - if ( empty( $balance_transaction->error ) ) { |
|
637 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
635 | + if (empty($balance_transaction->error)) { |
|
636 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
638 | 637 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
639 | 638 | // values are in the local currency of the Stripe account, not from WC. |
640 | - $fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
641 | - $net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
639 | + $fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
640 | + $net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
642 | 641 | |
643 | - 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 ); |
|
644 | - 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 ); |
|
642 | + 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); |
|
643 | + 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); |
|
645 | 644 | |
646 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
645 | + if (is_callable(array($order, 'save'))) { |
|
647 | 646 | $order->save(); |
648 | 647 | } |
649 | 648 | } |
650 | 649 | } else { |
651 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
650 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
652 | 651 | } |
653 | 652 | } |
654 | 653 | |
@@ -661,33 +660,33 @@ discard block |
||
661 | 660 | * @param float $amount |
662 | 661 | * @return bool |
663 | 662 | */ |
664 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
665 | - $order = wc_get_order( $order_id ); |
|
663 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
664 | + $order = wc_get_order($order_id); |
|
666 | 665 | |
667 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
666 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
668 | 667 | return false; |
669 | 668 | } |
670 | 669 | |
671 | 670 | $request = array(); |
672 | 671 | |
673 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
674 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
675 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
672 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
673 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
674 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
676 | 675 | } else { |
677 | 676 | $order_currency = $order->get_currency(); |
678 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
677 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
679 | 678 | } |
680 | 679 | |
681 | - if ( ! is_null( $amount ) ) { |
|
682 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
680 | + if ( ! is_null($amount)) { |
|
681 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
683 | 682 | } |
684 | 683 | |
685 | 684 | // If order is only authorized, don't pass amount. |
686 | - if ( 'yes' !== $captured ) { |
|
687 | - unset( $request['amount'] ); |
|
685 | + if ('yes' !== $captured) { |
|
686 | + unset($request['amount']); |
|
688 | 687 | } |
689 | 688 | |
690 | - if ( $reason ) { |
|
689 | + if ($reason) { |
|
691 | 690 | $request['metadata'] = array( |
692 | 691 | 'reason' => $reason, |
693 | 692 | ); |
@@ -695,33 +694,33 @@ discard block |
||
695 | 694 | |
696 | 695 | $request['charge'] = $order->get_transaction_id(); |
697 | 696 | |
698 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
697 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
699 | 698 | |
700 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
699 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
701 | 700 | |
702 | - if ( ! empty( $response->error ) ) { |
|
703 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
701 | + if ( ! empty($response->error)) { |
|
702 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
704 | 703 | |
705 | 704 | return $response; |
706 | 705 | |
707 | - } elseif ( ! empty( $response->id ) ) { |
|
708 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
706 | + } elseif ( ! empty($response->id)) { |
|
707 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
709 | 708 | |
710 | - $amount = wc_price( $response->amount / 100 ); |
|
709 | + $amount = wc_price($response->amount / 100); |
|
711 | 710 | |
712 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
713 | - $amount = wc_price( $response->amount ); |
|
711 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
712 | + $amount = wc_price($response->amount); |
|
714 | 713 | } |
715 | 714 | |
716 | - if ( isset( $response->balance_transaction ) ) { |
|
717 | - $this->update_fees( $order, $response->balance_transaction ); |
|
715 | + if (isset($response->balance_transaction)) { |
|
716 | + $this->update_fees($order, $response->balance_transaction); |
|
718 | 717 | } |
719 | 718 | |
720 | 719 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
721 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
720 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe'); |
|
722 | 721 | |
723 | - $order->add_order_note( $refund_message ); |
|
724 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
722 | + $order->add_order_note($refund_message); |
|
723 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
725 | 724 | |
726 | 725 | return true; |
727 | 726 | } |
@@ -736,44 +735,44 @@ discard block |
||
736 | 735 | */ |
737 | 736 | public function add_payment_method() { |
738 | 737 | $error = false; |
739 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
738 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
740 | 739 | $source_id = ''; |
741 | 740 | |
742 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
741 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
743 | 742 | $error = true; |
744 | 743 | } |
745 | 744 | |
746 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
745 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
747 | 746 | |
748 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
747 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
749 | 748 | |
750 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
749 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
751 | 750 | |
752 | - if ( isset( $source_object ) ) { |
|
753 | - if ( ! empty( $source_object->error ) ) { |
|
751 | + if (isset($source_object)) { |
|
752 | + if ( ! empty($source_object->error)) { |
|
754 | 753 | $error = true; |
755 | 754 | } |
756 | 755 | |
757 | 756 | $source_id = $source_object->id; |
758 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
759 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
757 | + } elseif (isset($_POST['stripe_token'])) { |
|
758 | + $source_id = wc_clean($_POST['stripe_token']); |
|
760 | 759 | } |
761 | 760 | |
762 | - $response = $stripe_customer->add_source( $source_id ); |
|
761 | + $response = $stripe_customer->add_source($source_id); |
|
763 | 762 | |
764 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
763 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
765 | 764 | $error = true; |
766 | 765 | } |
767 | 766 | |
768 | - if ( $error ) { |
|
769 | - wc_add_notice( $error_msg, 'error' ); |
|
770 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
767 | + if ($error) { |
|
768 | + wc_add_notice($error_msg, 'error'); |
|
769 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
771 | 770 | return; |
772 | 771 | } |
773 | 772 | |
774 | 773 | return array( |
775 | 774 | 'result' => 'success', |
776 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
775 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
777 | 776 | ); |
778 | 777 | } |
779 | 778 | } |
@@ -51,6 +51,8 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @since 4.0.0 |
53 | 53 | * @version 4.0.0 |
54 | + * @param string $slug |
|
55 | + * @param string $class |
|
54 | 56 | */ |
55 | 57 | public function add_admin_notice( $slug, $class, $message ) { |
56 | 58 | $this->notices[ $slug ] = array( |
@@ -410,7 +412,7 @@ discard block |
||
410 | 412 | * Checks if card is 3DS. |
411 | 413 | * |
412 | 414 | * @since 4.0.4 |
413 | - * @param object $source_object |
|
415 | + * @param stdClass $source_object |
|
414 | 416 | * @return bool |
415 | 417 | */ |
416 | 418 | public function is_3ds_card( $source_object ) { |
@@ -213,7 +213,6 @@ |
||
213 | 213 | /** |
214 | 214 | * Get a customers saved sources using their Stripe ID. |
215 | 215 | * |
216 | - * @param string $customer_id |
|
217 | 216 | * @return array |
218 | 217 | */ |
219 | 218 | public function get_sources() { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * Constructor |
33 | 33 | * @param int $user_id The WP user ID |
34 | 34 | */ |
35 | - public function __construct( $user_id = 0 ) { |
|
36 | - if ( $user_id ) { |
|
37 | - $this->set_user_id( $user_id ); |
|
38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
35 | + public function __construct($user_id = 0) { |
|
36 | + if ($user_id) { |
|
37 | + $this->set_user_id($user_id); |
|
38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * Set Stripe customer ID. |
52 | 52 | * @param [type] $id [description] |
53 | 53 | */ |
54 | - public function set_id( $id ) { |
|
55 | - $this->id = wc_clean( $id ); |
|
54 | + public function set_id($id) { |
|
55 | + $this->id = wc_clean($id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | * @return int |
61 | 61 | */ |
62 | 62 | public function get_user_id() { |
63 | - return absint( $this->user_id ); |
|
63 | + return absint($this->user_id); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Set User ID used by WordPress. |
68 | 68 | * @param int $user_id |
69 | 69 | */ |
70 | - public function set_user_id( $user_id ) { |
|
71 | - $this->user_id = absint( $user_id ); |
|
70 | + public function set_user_id($user_id) { |
|
71 | + $this->user_id = absint($user_id); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | * @return WP_User |
77 | 77 | */ |
78 | 78 | protected function get_user() { |
79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Store data from the Stripe API about this customer |
84 | 84 | */ |
85 | - public function set_customer_data( $data ) { |
|
85 | + public function set_customer_data($data) { |
|
86 | 86 | $this->customer_data = $data; |
87 | 87 | } |
88 | 88 | |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | * @param array $args |
92 | 92 | * @return WP_Error|int |
93 | 93 | */ |
94 | - public function create_customer( $args = array() ) { |
|
95 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
94 | + public function create_customer($args = array()) { |
|
95 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
96 | 96 | $user = $this->get_user(); |
97 | 97 | |
98 | - if ( $user ) { |
|
99 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
100 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
98 | + if ($user) { |
|
99 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
100 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
101 | 101 | |
102 | 102 | $defaults = array( |
103 | 103 | 'email' => $user->user_email, |
@@ -112,24 +112,24 @@ discard block |
||
112 | 112 | |
113 | 113 | $metadata = array(); |
114 | 114 | |
115 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
115 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
116 | 116 | |
117 | - $args = wp_parse_args( $args, $defaults ); |
|
118 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
117 | + $args = wp_parse_args($args, $defaults); |
|
118 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
119 | 119 | |
120 | - if ( ! empty( $response->error ) ) { |
|
121 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
120 | + if ( ! empty($response->error)) { |
|
121 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->set_id( $response->id ); |
|
124 | + $this->set_id($response->id); |
|
125 | 125 | $this->clear_cache(); |
126 | - $this->set_customer_data( $response ); |
|
126 | + $this->set_customer_data($response); |
|
127 | 127 | |
128 | - if ( $this->get_user_id() ) { |
|
129 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
128 | + if ($this->get_user_id()) { |
|
129 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
130 | 130 | } |
131 | 131 | |
132 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
132 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
133 | 133 | |
134 | 134 | return $response->id; |
135 | 135 | } |
@@ -140,72 +140,72 @@ discard block |
||
140 | 140 | * @param bool $retry |
141 | 141 | * @return WP_Error|int |
142 | 142 | */ |
143 | - public function add_source( $source_id, $retry = true ) { |
|
144 | - if ( ! $this->get_id() ) { |
|
145 | - $this->set_id( $this->create_customer() ); |
|
143 | + public function add_source($source_id, $retry = true) { |
|
144 | + if ( ! $this->get_id()) { |
|
145 | + $this->set_id($this->create_customer()); |
|
146 | 146 | } |
147 | 147 | |
148 | - $response = WC_Stripe_API::request( array( |
|
148 | + $response = WC_Stripe_API::request(array( |
|
149 | 149 | 'source' => $source_id, |
150 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
150 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
151 | 151 | |
152 | - if ( ! empty( $response->error ) ) { |
|
152 | + if ( ! empty($response->error)) { |
|
153 | 153 | // It is possible the WC user once was linked to a customer on Stripe |
154 | 154 | // but no longer exists. Instead of failing, lets try to create a |
155 | 155 | // new customer. |
156 | - if ( preg_match( '/No such customer/i', $response->error->message ) ) { |
|
157 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
156 | + if (preg_match('/No such customer/i', $response->error->message)) { |
|
157 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
158 | 158 | $this->create_customer(); |
159 | - return $this->add_source( $source_id, false ); |
|
159 | + return $this->add_source($source_id, false); |
|
160 | 160 | } else { |
161 | 161 | return $response; |
162 | 162 | } |
163 | - } elseif ( empty( $response->id ) ) { |
|
164 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
163 | + } elseif (empty($response->id)) { |
|
164 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // Add token to WooCommerce. |
168 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
169 | - if ( ! empty( $response->type ) ) { |
|
170 | - switch ( $response->type ) { |
|
168 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
169 | + if ( ! empty($response->type)) { |
|
170 | + switch ($response->type) { |
|
171 | 171 | case 'alipay': |
172 | 172 | break; |
173 | 173 | case 'sepa_debit': |
174 | 174 | $wc_token = new WC_Payment_Token_SEPA(); |
175 | - $wc_token->set_token( $response->id ); |
|
176 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
177 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
175 | + $wc_token->set_token($response->id); |
|
176 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
177 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
178 | 178 | break; |
179 | 179 | default: |
180 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
180 | + if ('source' === $response->object && 'card' === $response->type) { |
|
181 | 181 | $wc_token = new WC_Payment_Token_CC(); |
182 | - $wc_token->set_token( $response->id ); |
|
183 | - $wc_token->set_gateway_id( 'stripe' ); |
|
184 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
185 | - $wc_token->set_last4( $response->card->last4 ); |
|
186 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
187 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
182 | + $wc_token->set_token($response->id); |
|
183 | + $wc_token->set_gateway_id('stripe'); |
|
184 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
185 | + $wc_token->set_last4($response->card->last4); |
|
186 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
187 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
188 | 188 | } |
189 | 189 | break; |
190 | 190 | } |
191 | 191 | } else { |
192 | 192 | // Legacy. |
193 | 193 | $wc_token = new WC_Payment_Token_CC(); |
194 | - $wc_token->set_token( $response->id ); |
|
195 | - $wc_token->set_gateway_id( 'stripe' ); |
|
196 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
197 | - $wc_token->set_last4( $response->last4 ); |
|
198 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
199 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
194 | + $wc_token->set_token($response->id); |
|
195 | + $wc_token->set_gateway_id('stripe'); |
|
196 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
197 | + $wc_token->set_last4($response->last4); |
|
198 | + $wc_token->set_expiry_month($response->exp_month); |
|
199 | + $wc_token->set_expiry_year($response->exp_year); |
|
200 | 200 | } |
201 | 201 | |
202 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
202 | + $wc_token->set_user_id($this->get_user_id()); |
|
203 | 203 | $wc_token->save(); |
204 | 204 | } |
205 | 205 | |
206 | 206 | $this->clear_cache(); |
207 | 207 | |
208 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
208 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
209 | 209 | |
210 | 210 | return $response->id; |
211 | 211 | } |
@@ -217,42 +217,42 @@ discard block |
||
217 | 217 | * @return array |
218 | 218 | */ |
219 | 219 | public function get_sources() { |
220 | - if ( ! $this->get_id() ) { |
|
220 | + if ( ! $this->get_id()) { |
|
221 | 221 | return array(); |
222 | 222 | } |
223 | 223 | |
224 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
224 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
225 | 225 | |
226 | - $response = WC_Stripe_API::request( array( |
|
226 | + $response = WC_Stripe_API::request(array( |
|
227 | 227 | 'limit' => 100, |
228 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
228 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
229 | 229 | |
230 | - if ( ! empty( $response->error ) ) { |
|
230 | + if ( ! empty($response->error)) { |
|
231 | 231 | return array(); |
232 | 232 | } |
233 | 233 | |
234 | - if ( is_array( $response->data ) ) { |
|
234 | + if (is_array($response->data)) { |
|
235 | 235 | $sources = $response->data; |
236 | 236 | } |
237 | 237 | |
238 | - return empty( $sources ) ? array() : $sources; |
|
238 | + return empty($sources) ? array() : $sources; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
242 | 242 | * Delete a source from stripe. |
243 | 243 | * @param string $source_id |
244 | 244 | */ |
245 | - public function delete_source( $source_id ) { |
|
246 | - if ( ! $this->get_id() ) { |
|
245 | + public function delete_source($source_id) { |
|
246 | + if ( ! $this->get_id()) { |
|
247 | 247 | return false; |
248 | 248 | } |
249 | 249 | |
250 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
250 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
251 | 251 | |
252 | 252 | $this->clear_cache(); |
253 | 253 | |
254 | - if ( empty( $response->error ) ) { |
|
255 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
254 | + if (empty($response->error)) { |
|
255 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
256 | 256 | |
257 | 257 | return true; |
258 | 258 | } |
@@ -264,15 +264,15 @@ discard block |
||
264 | 264 | * Set default source in Stripe |
265 | 265 | * @param string $source_id |
266 | 266 | */ |
267 | - public function set_default_source( $source_id ) { |
|
268 | - $response = WC_Stripe_API::request( array( |
|
269 | - 'default_source' => sanitize_text_field( $source_id ), |
|
270 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
267 | + public function set_default_source($source_id) { |
|
268 | + $response = WC_Stripe_API::request(array( |
|
269 | + 'default_source' => sanitize_text_field($source_id), |
|
270 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
271 | 271 | |
272 | 272 | $this->clear_cache(); |
273 | 273 | |
274 | - if ( empty( $response->error ) ) { |
|
275 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
274 | + if (empty($response->error)) { |
|
275 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
276 | 276 | |
277 | 277 | return true; |
278 | 278 | } |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * Deletes caches for this users cards. |
285 | 285 | */ |
286 | 286 | public function clear_cache() { |
287 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
288 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
287 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
288 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
289 | 289 | $this->customer_data = array(); |
290 | 290 | } |
291 | 291 | } |
@@ -1,184 +1,184 @@ |
||
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_settings', |
|
8 | +return apply_filters('wc_stripe_settings', |
|
9 | 9 | array( |
10 | 10 | 'enabled' => array( |
11 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
12 | - 'label' => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ), |
|
11 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
12 | + 'label' => __('Enable Stripe', 'woocommerce-gateway-stripe'), |
|
13 | 13 | 'type' => 'checkbox', |
14 | 14 | 'description' => '', |
15 | 15 | 'default' => 'no', |
16 | 16 | ), |
17 | 17 | 'title' => array( |
18 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
18 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
19 | 19 | 'type' => 'text', |
20 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
21 | - 'default' => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ), |
|
20 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
21 | + 'default' => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'), |
|
22 | 22 | 'desc_tip' => true, |
23 | 23 | ), |
24 | 24 | 'description' => array( |
25 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
25 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
26 | 26 | 'type' => 'text', |
27 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
28 | - 'default' => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ), |
|
27 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
28 | + 'default' => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
29 | 29 | 'desc_tip' => true, |
30 | 30 | ), |
31 | 31 | 'webhook' => array( |
32 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
32 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
33 | 33 | 'type' => 'title', |
34 | 34 | /* translators: webhook URL */ |
35 | - '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 ), |
|
35 | + '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), |
|
36 | 36 | ), |
37 | 37 | 'testmode' => array( |
38 | - 'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ), |
|
39 | - 'label' => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ), |
|
38 | + 'title' => __('Test mode', 'woocommerce-gateway-stripe'), |
|
39 | + 'label' => __('Enable Test Mode', 'woocommerce-gateway-stripe'), |
|
40 | 40 | 'type' => 'checkbox', |
41 | - 'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ), |
|
41 | + 'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'), |
|
42 | 42 | 'default' => 'yes', |
43 | 43 | 'desc_tip' => true, |
44 | 44 | ), |
45 | 45 | 'test_publishable_key' => array( |
46 | - 'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ), |
|
46 | + 'title' => __('Test Publishable Key', 'woocommerce-gateway-stripe'), |
|
47 | 47 | 'type' => 'password', |
48 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
48 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
49 | 49 | 'default' => '', |
50 | 50 | 'desc_tip' => true, |
51 | 51 | ), |
52 | 52 | 'test_secret_key' => array( |
53 | - 'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ), |
|
53 | + 'title' => __('Test Secret Key', 'woocommerce-gateway-stripe'), |
|
54 | 54 | 'type' => 'password', |
55 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
55 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
56 | 56 | 'default' => '', |
57 | 57 | 'desc_tip' => true, |
58 | 58 | ), |
59 | 59 | 'publishable_key' => array( |
60 | - 'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ), |
|
60 | + 'title' => __('Live Publishable Key', 'woocommerce-gateway-stripe'), |
|
61 | 61 | 'type' => 'password', |
62 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
62 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
63 | 63 | 'default' => '', |
64 | 64 | 'desc_tip' => true, |
65 | 65 | ), |
66 | 66 | 'secret_key' => array( |
67 | - 'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ), |
|
67 | + 'title' => __('Live Secret Key', 'woocommerce-gateway-stripe'), |
|
68 | 68 | 'type' => 'password', |
69 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
69 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
70 | 70 | 'default' => '', |
71 | 71 | 'desc_tip' => true, |
72 | 72 | ), |
73 | 73 | 'inline_cc_form' => array( |
74 | - 'title' => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ), |
|
74 | + 'title' => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'), |
|
75 | 75 | 'type' => 'checkbox', |
76 | - 'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ), |
|
76 | + 'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'), |
|
77 | 77 | 'default' => 'no', |
78 | 78 | 'desc_tip' => true, |
79 | 79 | ), |
80 | 80 | 'statement_descriptor' => array( |
81 | - 'title' => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ), |
|
81 | + 'title' => __('Statement Descriptor', 'woocommerce-gateway-stripe'), |
|
82 | 82 | 'type' => 'text', |
83 | - 'description' => __( 'This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe' ), |
|
83 | + 'description' => __('This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe'), |
|
84 | 84 | 'default' => '', |
85 | 85 | 'desc_tip' => true, |
86 | 86 | ), |
87 | 87 | 'capture' => array( |
88 | - 'title' => __( 'Capture', 'woocommerce-gateway-stripe' ), |
|
89 | - 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ), |
|
88 | + 'title' => __('Capture', 'woocommerce-gateway-stripe'), |
|
89 | + 'label' => __('Capture charge immediately', 'woocommerce-gateway-stripe'), |
|
90 | 90 | 'type' => 'checkbox', |
91 | - 'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ), |
|
91 | + 'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'), |
|
92 | 92 | 'default' => 'yes', |
93 | 93 | 'desc_tip' => true, |
94 | 94 | ), |
95 | 95 | 'three_d_secure' => array( |
96 | - 'title' => __( '3D Secure', 'woocommerce-gateway-stripe' ), |
|
97 | - 'label' => __( 'Require 3D Secure when applicable', 'woocommerce-gateway-stripe' ), |
|
96 | + 'title' => __('3D Secure', 'woocommerce-gateway-stripe'), |
|
97 | + 'label' => __('Require 3D Secure when applicable', 'woocommerce-gateway-stripe'), |
|
98 | 98 | 'type' => 'checkbox', |
99 | - 'description' => __( 'Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe' ), |
|
99 | + 'description' => __('Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe'), |
|
100 | 100 | 'default' => 'no', |
101 | 101 | 'desc_tip' => true, |
102 | 102 | ), |
103 | 103 | 'stripe_checkout' => array( |
104 | - 'title' => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
105 | - 'label' => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
104 | + 'title' => __('Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
105 | + 'label' => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
106 | 106 | 'type' => 'checkbox', |
107 | - 'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ), |
|
107 | + 'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'), |
|
108 | 108 | 'default' => 'no', |
109 | 109 | 'desc_tip' => true, |
110 | 110 | ), |
111 | 111 | 'stripe_bitcoin' => array( |
112 | - 'title' => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
113 | - 'label' => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
112 | + 'title' => __('Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
113 | + 'label' => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
114 | 114 | 'type' => 'checkbox', |
115 | - 'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ), |
|
115 | + 'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'), |
|
116 | 116 | 'default' => 'no', |
117 | 117 | 'desc_tip' => true, |
118 | 118 | ), |
119 | 119 | 'stripe_checkout_image' => array( |
120 | - 'title' => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ), |
|
121 | - 'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ), |
|
120 | + 'title' => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'), |
|
121 | + 'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'), |
|
122 | 122 | 'type' => 'text', |
123 | 123 | 'default' => '', |
124 | 124 | 'desc_tip' => true, |
125 | 125 | ), |
126 | 126 | 'payment_request' => array( |
127 | - 'title' => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ), |
|
127 | + 'title' => __('Payment Request Buttons', 'woocommerce-gateway-stripe'), |
|
128 | 128 | /* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */ |
129 | - 'label' => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ), |
|
129 | + 'label' => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'), |
|
130 | 130 | 'type' => 'checkbox', |
131 | - 'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ), |
|
131 | + 'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'), |
|
132 | 132 | 'default' => 'yes', |
133 | 133 | 'desc_tip' => true, |
134 | 134 | ), |
135 | 135 | 'payment_request_button_type' => array( |
136 | - 'title' => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ), |
|
137 | - 'label' => __( 'Button Type', 'woocommerce-gateway-stripe' ), |
|
136 | + 'title' => __('Payment Request Button Type', 'woocommerce-gateway-stripe'), |
|
137 | + 'label' => __('Button Type', 'woocommerce-gateway-stripe'), |
|
138 | 138 | 'type' => 'select', |
139 | - 'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ), |
|
139 | + 'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'), |
|
140 | 140 | 'default' => 'buy', |
141 | 141 | 'desc_tip' => true, |
142 | 142 | 'options' => array( |
143 | - 'default' => __( 'Default', 'woocommerce-gateway-stripe' ), |
|
144 | - 'buy' => __( 'Buy', 'woocommerce-gateway-stripe' ), |
|
145 | - 'donate' => __( 'Donate', 'woocommerce-gateway-stripe' ), |
|
143 | + 'default' => __('Default', 'woocommerce-gateway-stripe'), |
|
144 | + 'buy' => __('Buy', 'woocommerce-gateway-stripe'), |
|
145 | + 'donate' => __('Donate', 'woocommerce-gateway-stripe'), |
|
146 | 146 | ), |
147 | 147 | ), |
148 | 148 | 'payment_request_button_theme' => array( |
149 | - 'title' => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ), |
|
150 | - 'label' => __( 'Button Theme', 'woocommerce-gateway-stripe' ), |
|
149 | + 'title' => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'), |
|
150 | + 'label' => __('Button Theme', 'woocommerce-gateway-stripe'), |
|
151 | 151 | 'type' => 'select', |
152 | - 'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ), |
|
152 | + 'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'), |
|
153 | 153 | 'default' => 'dark', |
154 | 154 | 'desc_tip' => true, |
155 | 155 | 'options' => array( |
156 | - 'dark' => __( 'Dark', 'woocommerce-gateway-stripe' ), |
|
157 | - 'light' => __( 'Light', 'woocommerce-gateway-stripe' ), |
|
158 | - 'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ), |
|
156 | + 'dark' => __('Dark', 'woocommerce-gateway-stripe'), |
|
157 | + 'light' => __('Light', 'woocommerce-gateway-stripe'), |
|
158 | + 'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'), |
|
159 | 159 | ), |
160 | 160 | ), |
161 | 161 | 'payment_request_button_height' => array( |
162 | - 'title' => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ), |
|
163 | - 'label' => __( 'Button Height', 'woocommerce-gateway-stripe' ), |
|
162 | + 'title' => __('Payment Request Button Height', 'woocommerce-gateway-stripe'), |
|
163 | + 'label' => __('Button Height', 'woocommerce-gateway-stripe'), |
|
164 | 164 | 'type' => 'text', |
165 | - 'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ), |
|
165 | + 'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'), |
|
166 | 166 | 'default' => '44', |
167 | 167 | 'desc_tip' => true, |
168 | 168 | ), |
169 | 169 | 'saved_cards' => array( |
170 | - 'title' => __( 'Saved Cards', 'woocommerce-gateway-stripe' ), |
|
171 | - 'label' => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ), |
|
170 | + 'title' => __('Saved Cards', 'woocommerce-gateway-stripe'), |
|
171 | + 'label' => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'), |
|
172 | 172 | 'type' => 'checkbox', |
173 | - 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ), |
|
173 | + 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'), |
|
174 | 174 | 'default' => 'no', |
175 | 175 | 'desc_tip' => true, |
176 | 176 | ), |
177 | 177 | 'logging' => array( |
178 | - 'title' => __( 'Logging', 'woocommerce-gateway-stripe' ), |
|
179 | - 'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ), |
|
178 | + 'title' => __('Logging', 'woocommerce-gateway-stripe'), |
|
179 | + 'label' => __('Log debug messages', 'woocommerce-gateway-stripe'), |
|
180 | 180 | 'type' => 'checkbox', |
181 | - 'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ), |
|
181 | + 'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'), |
|
182 | 182 | 'default' => 'no', |
183 | 183 | 'desc_tip' => true, |
184 | 184 | ), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | public function __construct() { |
116 | 116 | $this->retry_interval = 2; |
117 | 117 | $this->id = 'stripe'; |
118 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
118 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
119 | 119 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
120 | - $this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
120 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
121 | 121 | $this->has_fields = true; |
122 | 122 | $this->supports = array( |
123 | 123 | 'products', |
@@ -144,37 +144,37 @@ discard block |
||
144 | 144 | $this->init_settings(); |
145 | 145 | |
146 | 146 | // Get setting values. |
147 | - $this->title = $this->get_option( 'title' ); |
|
148 | - $this->description = $this->get_option( 'description' ); |
|
149 | - $this->enabled = $this->get_option( 'enabled' ); |
|
150 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
151 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
152 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
153 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
154 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
155 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
156 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
157 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
158 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
159 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
160 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
161 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
162 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
147 | + $this->title = $this->get_option('title'); |
|
148 | + $this->description = $this->get_option('description'); |
|
149 | + $this->enabled = $this->get_option('enabled'); |
|
150 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
151 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
152 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
153 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
154 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
155 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
156 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
157 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
158 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
159 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
160 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
161 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
162 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
163 | 163 | $this->apple_pay_verify_notice = ''; |
164 | 164 | |
165 | - if ( $this->stripe_checkout ) { |
|
166 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
165 | + if ($this->stripe_checkout) { |
|
166 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
167 | 167 | } |
168 | 168 | |
169 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
169 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
170 | 170 | |
171 | 171 | $this->init_apple_pay(); |
172 | 172 | |
173 | 173 | // Hooks. |
174 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
175 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
176 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
177 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
174 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
175 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
176 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
177 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @since 4.0.2 |
184 | 184 | */ |
185 | 185 | public function is_available() { |
186 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
186 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
187 | 187 | return false; |
188 | 188 | } |
189 | 189 | |
@@ -206,17 +206,17 @@ discard block |
||
206 | 206 | $icons_str .= $icons['amex']; |
207 | 207 | $icons_str .= $icons['mastercard']; |
208 | 208 | |
209 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
209 | + if ('USD' === get_woocommerce_currency()) { |
|
210 | 210 | $icons_str .= $icons['discover']; |
211 | 211 | $icons_str .= $icons['jcb']; |
212 | 212 | $icons_str .= $icons['diners']; |
213 | 213 | } |
214 | 214 | |
215 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
215 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
216 | 216 | $icons_str .= $icons['bitcoin']; |
217 | 217 | } |
218 | 218 | |
219 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
219 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | public function init_apple_pay() { |
229 | 229 | if ( |
230 | 230 | is_admin() && |
231 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
232 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
233 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
231 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
232 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
233 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
234 | 234 | $this->payment_request |
235 | 235 | ) { |
236 | 236 | $this->process_apple_pay_verification(); |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | * @version 3.1.0 |
245 | 245 | * @param string $secret_key |
246 | 246 | */ |
247 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
248 | - if ( empty( $secret_key ) ) { |
|
249 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
247 | + private function register_apple_pay_domain($secret_key = '') { |
|
248 | + if (empty($secret_key)) { |
|
249 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -260,23 +260,23 @@ discard block |
||
260 | 260 | 'Authorization' => 'Bearer ' . $secret_key, |
261 | 261 | ); |
262 | 262 | |
263 | - $response = wp_remote_post( $endpoint, array( |
|
263 | + $response = wp_remote_post($endpoint, array( |
|
264 | 264 | 'headers' => $headers, |
265 | - 'body' => http_build_query( $data ), |
|
266 | - ) ); |
|
265 | + 'body' => http_build_query($data), |
|
266 | + )); |
|
267 | 267 | |
268 | - if ( is_wp_error( $response ) ) { |
|
268 | + if (is_wp_error($response)) { |
|
269 | 269 | /* translators: error message */ |
270 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
270 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
271 | 271 | } |
272 | 272 | |
273 | - if ( 200 !== $response['response']['code'] ) { |
|
274 | - $parsed_response = json_decode( $response['body'] ); |
|
273 | + if (200 !== $response['response']['code']) { |
|
274 | + $parsed_response = json_decode($response['body']); |
|
275 | 275 | |
276 | 276 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
277 | 277 | |
278 | 278 | /* translators: error message */ |
279 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
279 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
@@ -287,48 +287,48 @@ discard block |
||
287 | 287 | * @version 3.1.0 |
288 | 288 | */ |
289 | 289 | public function process_apple_pay_verification() { |
290 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
290 | + $gateway_settings = get_option('woocommerce_stripe_settings', array()); |
|
291 | 291 | |
292 | 292 | try { |
293 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
293 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
294 | 294 | $dir = '.well-known'; |
295 | 295 | $file = 'apple-developer-merchantid-domain-association'; |
296 | 296 | $fullpath = $path . '/' . $dir . '/' . $file; |
297 | 297 | |
298 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
298 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
299 | 299 | return; |
300 | 300 | } |
301 | 301 | |
302 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
303 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
304 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
302 | + if ( ! file_exists($path . '/' . $dir)) { |
|
303 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
304 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
305 | 305 | } |
306 | 306 | } |
307 | 307 | |
308 | - if ( ! file_exists( $fullpath ) ) { |
|
309 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
310 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
308 | + if ( ! file_exists($fullpath)) { |
|
309 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
310 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
311 | 311 | } |
312 | 312 | } |
313 | 313 | |
314 | 314 | // At this point then the domain association folder and file should be available. |
315 | 315 | // Proceed to verify/and or verify again. |
316 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
316 | + $this->register_apple_pay_domain($this->secret_key); |
|
317 | 317 | |
318 | 318 | // No errors to this point, verification success! |
319 | 319 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
320 | 320 | $this->apple_pay_domain_set = true; |
321 | 321 | |
322 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
322 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
323 | 323 | |
324 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
324 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
325 | 325 | |
326 | - } catch ( Exception $e ) { |
|
326 | + } catch (Exception $e) { |
|
327 | 327 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
328 | 328 | |
329 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
329 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
330 | 330 | |
331 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
331 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
@@ -336,11 +336,11 @@ discard block |
||
336 | 336 | * Check if SSL is enabled and notify the user |
337 | 337 | */ |
338 | 338 | public function admin_notices() { |
339 | - if ( 'no' === $this->enabled ) { |
|
339 | + if ('no' === $this->enabled) { |
|
340 | 340 | return; |
341 | 341 | } |
342 | 342 | |
343 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
343 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
344 | 344 | $allowed_html = array( |
345 | 345 | 'a' => array( |
346 | 346 | 'href' => array(), |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | ), |
349 | 349 | ); |
350 | 350 | |
351 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
351 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -356,9 +356,9 @@ discard block |
||
356 | 356 | * when setting screen is displayed. So if domain verification is not set, |
357 | 357 | * something went wrong so lets notify user. |
358 | 358 | */ |
359 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
359 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
360 | 360 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
361 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
361 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * Initialise Gateway Settings Form Fields |
367 | 367 | */ |
368 | 368 | public function init_form_fields() { |
369 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
369 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -374,59 +374,59 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public function payment_fields() { |
376 | 376 | $user = wp_get_current_user(); |
377 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
377 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
378 | 378 | $total = WC()->cart->total; |
379 | 379 | $user_email = ''; |
380 | 380 | |
381 | 381 | // If paying from order, we need to get total from order not cart. |
382 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
383 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
382 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
383 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
384 | 384 | $total = $order->get_total(); |
385 | 385 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
386 | 386 | } else { |
387 | - if ( $user->ID ) { |
|
388 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
387 | + if ($user->ID) { |
|
388 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
389 | 389 | $user_email = $user_email ? $user_email : $user->user_email; |
390 | 390 | } |
391 | 391 | } |
392 | 392 | |
393 | - if ( is_add_payment_method_page() ) { |
|
394 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
395 | - $total = ''; |
|
393 | + if (is_add_payment_method_page()) { |
|
394 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
395 | + $total = ''; |
|
396 | 396 | } else { |
397 | 397 | $pay_button_text = ''; |
398 | 398 | } |
399 | 399 | |
400 | 400 | echo '<div |
401 | 401 | id="stripe-payment-data" |
402 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
402 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
403 | 403 | data-description="" |
404 | - data-email="' . esc_attr( $user_email ) . '" |
|
405 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
406 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
407 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
408 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
409 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
410 | - data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', substr( get_locale(), 0, 2 ) ) ) . '" |
|
411 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
412 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
413 | - |
|
414 | - if ( $this->description ) { |
|
415 | - if ( $this->testmode ) { |
|
404 | + data-email="' . esc_attr($user_email) . '" |
|
405 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
406 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
407 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
408 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
409 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
410 | + data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', substr(get_locale(), 0, 2))) . '" |
|
411 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
412 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
413 | + |
|
414 | + if ($this->description) { |
|
415 | + if ($this->testmode) { |
|
416 | 416 | /* translators: link to Stripe testing page */ |
417 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
418 | - $this->description = trim( $this->description ); |
|
417 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
418 | + $this->description = trim($this->description); |
|
419 | 419 | } |
420 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
420 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
421 | 421 | } |
422 | 422 | |
423 | - if ( $display_tokenization ) { |
|
423 | + if ($display_tokenization) { |
|
424 | 424 | $this->tokenization_script(); |
425 | 425 | $this->saved_payment_methods(); |
426 | 426 | } |
427 | 427 | |
428 | - if ( ! $this->stripe_checkout ) { |
|
429 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
428 | + if ( ! $this->stripe_checkout) { |
|
429 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
430 | 430 | $this->elements_form(); |
431 | 431 | } else { |
432 | 432 | $this->form(); |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
437 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
437 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
438 | 438 | $this->save_payment_method_checkbox(); |
439 | 439 | } |
440 | 440 | |
@@ -449,12 +449,12 @@ discard block |
||
449 | 449 | */ |
450 | 450 | public function elements_form() { |
451 | 451 | ?> |
452 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
453 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
452 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
453 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
454 | 454 | |
455 | - <?php if ( $this->inline_cc_form ) { ?> |
|
455 | + <?php if ($this->inline_cc_form) { ?> |
|
456 | 456 | <label for="card-element"> |
457 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
457 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
458 | 458 | </label> |
459 | 459 | |
460 | 460 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | </div> |
463 | 463 | <?php } else { ?> |
464 | 464 | <div class="form-row form-row-wide"> |
465 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
465 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
466 | 466 | |
467 | 467 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
468 | 468 | <!-- a Stripe Element will be inserted here. --> |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | </div> |
471 | 471 | |
472 | 472 | <div class="form-row form-row-first"> |
473 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
473 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
474 | 474 | |
475 | 475 | <div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
476 | 476 | <!-- a Stripe Element will be inserted here. --> |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | </div> |
479 | 479 | |
480 | 480 | <div class="form-row form-row-last"> |
481 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
481 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
482 | 482 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
483 | 483 | <!-- a Stripe Element will be inserted here. --> |
484 | 484 | </div> |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | |
489 | 489 | <!-- Used to display form errors --> |
490 | 490 | <div class="stripe-source-errors" role="alert"></div> |
491 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
491 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
492 | 492 | <div class="clear"></div> |
493 | 493 | </fieldset> |
494 | 494 | <?php |
@@ -501,13 +501,13 @@ discard block |
||
501 | 501 | * @version 3.1.0 |
502 | 502 | */ |
503 | 503 | public function admin_scripts() { |
504 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
504 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
505 | 505 | return; |
506 | 506 | } |
507 | 507 | |
508 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
508 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
509 | 509 | |
510 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
510 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -519,29 +519,29 @@ discard block |
||
519 | 519 | * @version 4.0.0 |
520 | 520 | */ |
521 | 521 | public function payment_scripts() { |
522 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
522 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
523 | 523 | return; |
524 | 524 | } |
525 | 525 | |
526 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
526 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
527 | 527 | |
528 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
529 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
530 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
531 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
532 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
533 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
528 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
529 | + wp_enqueue_style('stripe_paymentfonts'); |
|
530 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
531 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
532 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
533 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true); |
|
534 | 534 | |
535 | 535 | $stripe_params = array( |
536 | 536 | 'key' => $this->publishable_key, |
537 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
538 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
537 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
538 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
539 | 539 | ); |
540 | 540 | |
541 | 541 | // If we're on the pay page we need to pass stripe.js the address of the order. |
542 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
543 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
544 | - $order = wc_get_order( $order_id ); |
|
542 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
543 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
544 | + $order = wc_get_order($order_id); |
|
545 | 545 | |
546 | 546 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
547 | 547 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -553,38 +553,38 @@ discard block |
||
553 | 553 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
554 | 554 | } |
555 | 555 | |
556 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
557 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
558 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
559 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
560 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
556 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
557 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
558 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
559 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
560 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
561 | 561 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
562 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
563 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
562 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
563 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
564 | 564 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
565 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
566 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
565 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
566 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
567 | 567 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
568 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
569 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
568 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
569 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
570 | 570 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
571 | - $stripe_params['is_change_payment_page'] = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no'; |
|
571 | + $stripe_params['is_change_payment_page'] = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no'; |
|
572 | 572 | $stripe_params['is_add_payment_method_page'] = is_add_payment_method_page() ? 'yes' : 'no'; |
573 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
574 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
573 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
574 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
575 | 575 | |
576 | 576 | // merge localized messages to be use in JS |
577 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
577 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
578 | 578 | |
579 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
580 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
579 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
580 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
581 | 581 | |
582 | - if ( $this->stripe_checkout ) { |
|
583 | - wp_enqueue_script( 'stripe_checkout' ); |
|
582 | + if ($this->stripe_checkout) { |
|
583 | + wp_enqueue_script('stripe_checkout'); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | $this->tokenization_script(); |
587 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
587 | + wp_enqueue_script('woocommerce_stripe'); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -600,43 +600,43 @@ discard block |
||
600 | 600 | * |
601 | 601 | * @return array|void |
602 | 602 | */ |
603 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
603 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
604 | 604 | try { |
605 | - $order = wc_get_order( $order_id ); |
|
605 | + $order = wc_get_order($order_id); |
|
606 | 606 | |
607 | 607 | // This comes from the create account checkbox in the checkout page. |
608 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
608 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
609 | 609 | |
610 | - if ( $create_account ) { |
|
610 | + if ($create_account) { |
|
611 | 611 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
612 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
612 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
613 | 613 | $new_stripe_customer->create_customer(); |
614 | 614 | } |
615 | 615 | |
616 | 616 | $source_object = $this->get_source_object(); |
617 | - $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source ); |
|
617 | + $prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source); |
|
618 | 618 | |
619 | 619 | // Check if we don't allow prepaid credit cards. |
620 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
621 | - if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
622 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
623 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
620 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
621 | + if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
622 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
623 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
624 | 624 | } |
625 | 625 | } |
626 | 626 | |
627 | - if ( empty( $prepared_source->source ) ) { |
|
628 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
629 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
627 | + if (empty($prepared_source->source)) { |
|
628 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
629 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
630 | 630 | } |
631 | 631 | |
632 | - $this->save_source_to_order( $order, $prepared_source ); |
|
632 | + $this->save_source_to_order($order, $prepared_source); |
|
633 | 633 | |
634 | 634 | // Result from Stripe API request. |
635 | 635 | $response = null; |
636 | 636 | |
637 | - if ( $order->get_total() > 0 ) { |
|
637 | + if ($order->get_total() > 0) { |
|
638 | 638 | // This will throw exception if not valid. |
639 | - $this->validate_minimum_order_amount( $order ); |
|
639 | + $this->validate_minimum_order_amount($order); |
|
640 | 640 | |
641 | 641 | /* |
642 | 642 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -645,109 +645,109 @@ discard block |
||
645 | 645 | * Note that if we need to save source, the original source must be first |
646 | 646 | * attached to a customer in Stripe before it can be charged. |
647 | 647 | */ |
648 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
649 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
648 | + if ($this->is_3ds_required($source_object)) { |
|
649 | + $response = $this->create_3ds_source($order, $source_object); |
|
650 | 650 | |
651 | - if ( ! empty( $response->error ) ) { |
|
651 | + if ( ! empty($response->error)) { |
|
652 | 652 | $localized_message = $response->error->message; |
653 | 653 | |
654 | - $order->add_order_note( $localized_message ); |
|
654 | + $order->add_order_note($localized_message); |
|
655 | 655 | |
656 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
656 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | // Update order meta with 3DS source. |
660 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
661 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
660 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
661 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
662 | 662 | } else { |
663 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
663 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
664 | 664 | $order->save(); |
665 | 665 | } |
666 | 666 | |
667 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
667 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
668 | 668 | |
669 | 669 | return array( |
670 | 670 | 'result' => 'success', |
671 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
671 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
672 | 672 | ); |
673 | 673 | } |
674 | 674 | |
675 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
675 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
676 | 676 | |
677 | 677 | // Make the request. |
678 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
678 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
679 | 679 | |
680 | - if ( ! empty( $response->error ) ) { |
|
680 | + if ( ! empty($response->error)) { |
|
681 | 681 | // If it is an API error such connection or server, let's retry. |
682 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
683 | - if ( $retry ) { |
|
684 | - sleep( 5 ); |
|
685 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
682 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
683 | + if ($retry) { |
|
684 | + sleep(5); |
|
685 | + return $this->process_payment($order_id, false, $force_save_source); |
|
686 | 686 | } else { |
687 | 687 | $localized_message = 'API connection error and retries exhausted.'; |
688 | - $order->add_order_note( $localized_message ); |
|
689 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
688 | + $order->add_order_note($localized_message); |
|
689 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
693 | 693 | // We want to retry. |
694 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
695 | - if ( $retry ) { |
|
694 | + if ($this->is_retryable_error($response->error)) { |
|
695 | + if ($retry) { |
|
696 | 696 | // Don't do anymore retries after this. |
697 | - if ( 5 <= $this->retry_interval ) { |
|
697 | + if (5 <= $this->retry_interval) { |
|
698 | 698 | |
699 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
699 | + return $this->process_payment($order_id, false, $force_save_source); |
|
700 | 700 | } |
701 | 701 | |
702 | - sleep( $this->retry_interval ); |
|
702 | + sleep($this->retry_interval); |
|
703 | 703 | |
704 | 704 | $this->retry_interval++; |
705 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
705 | + return $this->process_payment($order_id, true, $force_save_source); |
|
706 | 706 | } else { |
707 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
708 | - $order->add_order_note( $localized_message ); |
|
709 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
707 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
708 | + $order->add_order_note($localized_message); |
|
709 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
713 | 713 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
714 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
715 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
716 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
717 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
714 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
715 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
716 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
717 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
718 | 718 | } else { |
719 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
720 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
719 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
720 | + $order->delete_meta_data('_stripe_customer_id'); |
|
721 | 721 | $order->save(); |
722 | 722 | } |
723 | 723 | |
724 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
725 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
724 | + return $this->process_payment($order_id, false, $force_save_source); |
|
725 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
726 | 726 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
727 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
727 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
728 | 728 | $wc_token->delete(); |
729 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
730 | - $order->add_order_note( $localized_message ); |
|
731 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
729 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
730 | + $order->add_order_note($localized_message); |
|
731 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
735 | 735 | |
736 | - if ( 'card_error' === $response->error->type ) { |
|
737 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
736 | + if ('card_error' === $response->error->type) { |
|
737 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
738 | 738 | } else { |
739 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
739 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
740 | 740 | } |
741 | 741 | |
742 | - $order->add_order_note( $localized_message ); |
|
742 | + $order->add_order_note($localized_message); |
|
743 | 743 | |
744 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
744 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
745 | 745 | } |
746 | 746 | |
747 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
747 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
748 | 748 | |
749 | 749 | // Process valid response. |
750 | - $this->process_response( $response, $order ); |
|
750 | + $this->process_response($response, $order); |
|
751 | 751 | } else { |
752 | 752 | $order->payment_complete(); |
753 | 753 | } |
@@ -758,17 +758,17 @@ discard block |
||
758 | 758 | // Return thank you page redirect. |
759 | 759 | return array( |
760 | 760 | 'result' => 'success', |
761 | - 'redirect' => $this->get_return_url( $order ), |
|
761 | + 'redirect' => $this->get_return_url($order), |
|
762 | 762 | ); |
763 | 763 | |
764 | - } catch ( WC_Stripe_Exception $e ) { |
|
765 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
766 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
764 | + } catch (WC_Stripe_Exception $e) { |
|
765 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
766 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
767 | 767 | |
768 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
768 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
769 | 769 | |
770 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
771 | - $this->send_failed_order_email( $order_id ); |
|
770 | + if ($order->has_status(array('pending', 'failed'))) { |
|
771 | + $this->send_failed_order_email($order_id); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | return array( |
@@ -2,12 +2,12 @@ discard block |
||
2 | 2 | |
3 | 3 | class WC_Stripe_Test extends WP_UnitTestCase { |
4 | 4 | public function test_constants_defined() { |
5 | - $this->assertTrue( defined( 'WC_STRIPE_VERSION' ) ); |
|
6 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) ); |
|
7 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) ); |
|
8 | - $this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) ); |
|
9 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) ); |
|
10 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) ); |
|
5 | + $this->assertTrue(defined('WC_STRIPE_VERSION')); |
|
6 | + $this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER')); |
|
7 | + $this->assertTrue(defined('WC_STRIPE_MIN_WC_VER')); |
|
8 | + $this->assertTrue(defined('WC_STRIPE_MAIN_FILE')); |
|
9 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_URL')); |
|
10 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH')); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * This test will see if we're indeed converting the price correctly. |
16 | 16 | */ |
17 | 17 | public function test_price_conversion_before_send_to_stripe() { |
18 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
19 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) ); |
|
20 | - $this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) ); |
|
21 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) ); |
|
22 | - $this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
18 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
19 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY')); |
|
20 | + $this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY')); |
|
21 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50)); |
|
22 | + $this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -33,37 +33,37 @@ discard block |
||
33 | 33 | $balance_fee1->net = 10000; |
34 | 34 | $balance_fee1->currency = 'USD'; |
35 | 35 | |
36 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) ); |
|
36 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee')); |
|
37 | 37 | |
38 | 38 | $balance_fee2 = new stdClass(); |
39 | 39 | $balance_fee2->fee = 10500; |
40 | 40 | $balance_fee2->net = 10000; |
41 | 41 | $balance_fee2->currency = 'JPY'; |
42 | 42 | |
43 | - $this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) ); |
|
43 | + $this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee')); |
|
44 | 44 | |
45 | 45 | $balance_fee3 = new stdClass(); |
46 | 46 | $balance_fee3->fee = 10500; |
47 | 47 | $balance_fee3->net = 10000; |
48 | 48 | $balance_fee3->currency = 'USD'; |
49 | 49 | |
50 | - $this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) ); |
|
50 | + $this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net')); |
|
51 | 51 | |
52 | 52 | $balance_fee4 = new stdClass(); |
53 | 53 | $balance_fee4->fee = 10500; |
54 | 54 | $balance_fee4->net = 10000; |
55 | 55 | $balance_fee4->currency = 'JPY'; |
56 | 56 | |
57 | - $this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) ); |
|
57 | + $this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net')); |
|
58 | 58 | |
59 | 59 | $balance_fee5 = new stdClass(); |
60 | 60 | $balance_fee5->fee = 10500; |
61 | 61 | $balance_fee5->net = 10000; |
62 | 62 | $balance_fee5->currency = 'USD'; |
63 | 63 | |
64 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
64 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
65 | 65 | |
66 | - $this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
66 | + $this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -76,28 +76,28 @@ discard block |
||
76 | 76 | 'expected' => 'Tests Store', |
77 | 77 | ); |
78 | 78 | |
79 | - $this->assertEquals( $statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor1['actual'] ) ); |
|
79 | + $this->assertEquals($statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor1['actual'])); |
|
80 | 80 | |
81 | 81 | $statement_descriptor2 = array( |
82 | 82 | 'actual' => 'Test\'s Store > Driving Course Range', |
83 | 83 | 'expected' => 'Tests Store Driving C', |
84 | 84 | ); |
85 | 85 | |
86 | - $this->assertEquals( $statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor2['actual'] ) ); |
|
86 | + $this->assertEquals($statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor2['actual'])); |
|
87 | 87 | |
88 | 88 | $statement_descriptor3 = array( |
89 | 89 | 'actual' => 'Test\'s Store < Driving Course Range', |
90 | 90 | 'expected' => 'Tests Store Driving C', |
91 | 91 | ); |
92 | 92 | |
93 | - $this->assertEquals( $statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor3['actual'] ) ); |
|
93 | + $this->assertEquals($statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor3['actual'])); |
|
94 | 94 | |
95 | 95 | $statement_descriptor4 = array( |
96 | 96 | 'actual' => 'Test\'s Store " Driving Course Range', |
97 | 97 | 'expected' => 'Tests Store Driving C', |
98 | 98 | ); |
99 | 99 | |
100 | - $this->assertEquals( $statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor4['actual'] ) ); |
|
100 | + $this->assertEquals($statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor4['actual'])); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | $source = new stdClass(); |
110 | 110 | $source->type = 'three_d_secure'; |
111 | 111 | |
112 | - $this->assertEquals( true, $stripe->is_3ds_card( $source ) ); |
|
112 | + $this->assertEquals(true, $stripe->is_3ds_card($source)); |
|
113 | 113 | |
114 | 114 | $source = new stdClass(); |
115 | 115 | $source->type = 'card'; |
116 | 116 | |
117 | - $this->assertEquals( false, $stripe->is_3ds_card( $source ) ); |
|
117 | + $this->assertEquals(false, $stripe->is_3ds_card($source)); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | $source->card = new stdClass(); |
129 | 129 | $source->card->three_d_secure = 'required'; |
130 | 130 | |
131 | - $this->assertEquals( true, $stripe->is_3ds_required( $source ) ); |
|
131 | + $this->assertEquals(true, $stripe->is_3ds_required($source)); |
|
132 | 132 | |
133 | 133 | $source = new stdClass(); |
134 | 134 | $source->type = 'card'; |
135 | 135 | $source->card = new stdClass(); |
136 | 136 | $source->card->three_d_secure = 'optional'; |
137 | 137 | |
138 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
138 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
139 | 139 | |
140 | 140 | $source = new stdClass(); |
141 | 141 | $source->type = 'card'; |
142 | 142 | $source->card = new stdClass(); |
143 | 143 | $source->card->three_d_secure = 'not_supported'; |
144 | 144 | |
145 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
145 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
146 | 146 | } |
147 | 147 | } |
@@ -1,28 +1,28 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$_tests_dir = getenv( 'WP_TESTS_DIR' ); |
|
4 | -if ( ! $_tests_dir ) { |
|
3 | +$_tests_dir = getenv('WP_TESTS_DIR'); |
|
4 | +if ( ! $_tests_dir) { |
|
5 | 5 | $_tests_dir = '/tmp/wordpress-tests-lib'; |
6 | 6 | } |
7 | 7 | |
8 | 8 | require_once $_tests_dir . '/includes/functions.php'; |
9 | 9 | |
10 | 10 | function _manually_load_plugin() { |
11 | - $plugin_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/'; |
|
11 | + $plugin_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/'; |
|
12 | 12 | require $plugin_dir . 'woocommerce-gateway-stripe/woocommerce-gateway-stripe.php'; |
13 | 13 | require $plugin_dir . 'woocommerce/woocommerce.php'; |
14 | 14 | } |
15 | 15 | |
16 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); |
|
16 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); |
|
17 | 17 | |
18 | 18 | require $_tests_dir . '/includes/bootstrap.php'; |
19 | 19 | |
20 | -$wc_tests_framework_base_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/tests/framework/'; |
|
21 | -require_once( $wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php' ); |
|
22 | -require_once( $wc_tests_framework_base_dir . 'class-wc-unit-test-case.php' ); |
|
23 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php' ); |
|
24 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php' ); |
|
25 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php' ); |
|
26 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php' ); |
|
27 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php' ); |
|
28 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php' ); |
|
20 | +$wc_tests_framework_base_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/woocommerce/tests/framework/'; |
|
21 | +require_once($wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php'); |
|
22 | +require_once($wc_tests_framework_base_dir . 'class-wc-unit-test-case.php'); |
|
23 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php'); |
|
24 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php'); |
|
25 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php'); |
|
26 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php'); |
|
27 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php'); |
|
28 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php'); |