@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 3.1.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -42,30 +42,30 @@ discard block |
||
42 | 42 | * @version 4.0.0 |
43 | 43 | */ |
44 | 44 | public function __construct() { |
45 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
45 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
46 | 46 | $this->publishable_key = $this->get_publishable_key(); |
47 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
48 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
47 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
48 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
49 | 49 | |
50 | 50 | // If both site title and statement descriptor is not set. Fallback. |
51 | - if ( empty( $this->total_label ) ) { |
|
51 | + if (empty($this->total_label)) { |
|
52 | 52 | $this->total_label = $_SERVER['SERVER_NAME']; |
53 | 53 | } |
54 | 54 | |
55 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
55 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
56 | 56 | |
57 | 57 | // Checks if Stripe Gateway is enabled. |
58 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
58 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
62 | 62 | // Checks if Payment Request is enabled. |
63 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
63 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // Don't load for change payment method page. |
68 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
68 | + if (isset($_GET['change_payment_method'])) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
@@ -79,38 +79,38 @@ discard block |
||
79 | 79 | * @version 4.0.0 |
80 | 80 | */ |
81 | 81 | protected function init() { |
82 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
83 | - add_action( 'wp', array( $this, 'set_session' ) ); |
|
82 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
83 | + add_action('wp', array($this, 'set_session')); |
|
84 | 84 | |
85 | 85 | /* |
86 | 86 | * In order to display the Payment Request button in the correct position, |
87 | 87 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
88 | 88 | * CSS is used to position the button. |
89 | 89 | */ |
90 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
91 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
92 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
90 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
91 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
92 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
93 | 93 | } else { |
94 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
95 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
94 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
95 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
96 | 96 | } |
97 | 97 | |
98 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
99 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
98 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
99 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
100 | 100 | |
101 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
102 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
103 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
104 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
105 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
106 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
107 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
108 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
101 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
102 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
103 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
104 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
105 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
106 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
107 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
108 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
109 | 109 | |
110 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
111 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
110 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
111 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
112 | 112 | |
113 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 ); |
|
113 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | * @since 4.0.0 |
121 | 121 | */ |
122 | 122 | public function set_session() { |
123 | - if ( ! is_user_logged_in() ) { |
|
123 | + if ( ! is_user_logged_in()) { |
|
124 | 124 | $wc_session = new WC_Session_Handler(); |
125 | 125 | |
126 | - if ( ! $wc_session->has_session() ) { |
|
127 | - $wc_session->set_customer_session_cookie( true ); |
|
126 | + if ( ! $wc_session->has_session()) { |
|
127 | + $wc_session->set_customer_session_cookie(true); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | } |
@@ -135,15 +135,15 @@ discard block |
||
135 | 135 | * @return string |
136 | 136 | */ |
137 | 137 | protected function get_publishable_key() { |
138 | - if ( empty( $this->stripe_settings ) ) { |
|
138 | + if (empty($this->stripe_settings)) { |
|
139 | 139 | return ''; |
140 | 140 | } |
141 | 141 | |
142 | - if ( empty( $this->stripe_settings['testmode'] ) ) { |
|
142 | + if (empty($this->stripe_settings['testmode'])) { |
|
143 | 143 | return ''; |
144 | 144 | } |
145 | 145 | |
146 | - if ( empty( $this->stripe_settings['test_publishable_key'] ) ) { |
|
146 | + if (empty($this->stripe_settings['test_publishable_key'])) { |
|
147 | 147 | return ''; |
148 | 148 | } |
149 | 149 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | public function get_button_type() { |
161 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
161 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * @return string |
170 | 170 | */ |
171 | 171 | public function get_button_theme() { |
172 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
172 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @return string |
181 | 181 | */ |
182 | 182 | public function get_button_height() { |
183 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
183 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -190,40 +190,40 @@ discard block |
||
190 | 190 | * @version 4.0.0 |
191 | 191 | */ |
192 | 192 | public function get_product_data() { |
193 | - if ( ! is_product() ) { |
|
193 | + if ( ! is_product()) { |
|
194 | 194 | return false; |
195 | 195 | } |
196 | 196 | |
197 | 197 | global $post; |
198 | 198 | |
199 | - $product = wc_get_product( $post->ID ); |
|
199 | + $product = wc_get_product($post->ID); |
|
200 | 200 | |
201 | 201 | $data = array(); |
202 | 202 | $items = array(); |
203 | 203 | |
204 | 204 | $items[] = array( |
205 | 205 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
206 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
206 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
207 | 207 | ); |
208 | 208 | |
209 | - if ( wc_tax_enabled() ) { |
|
209 | + if (wc_tax_enabled()) { |
|
210 | 210 | $items[] = array( |
211 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
211 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
212 | 212 | 'amount' => 0, |
213 | 213 | 'pending' => true, |
214 | 214 | ); |
215 | 215 | } |
216 | 216 | |
217 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
217 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
218 | 218 | $items[] = array( |
219 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
219 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
220 | 220 | 'amount' => 0, |
221 | 221 | 'pending' => true, |
222 | 222 | ); |
223 | 223 | |
224 | - $data['shippingOptions'] = array( |
|
224 | + $data['shippingOptions'] = array( |
|
225 | 225 | 'id' => 'pending', |
226 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
226 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
227 | 227 | 'detail' => '', |
228 | 228 | 'amount' => 0, |
229 | 229 | ); |
@@ -232,13 +232,13 @@ discard block |
||
232 | 232 | $data['displayItems'] = $items; |
233 | 233 | $data['total'] = array( |
234 | 234 | 'label' => $this->total_label, |
235 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
235 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
236 | 236 | 'pending' => true, |
237 | 237 | ); |
238 | 238 | |
239 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
240 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
241 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
239 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
240 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
241 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
242 | 242 | |
243 | 243 | return $data; |
244 | 244 | } |
@@ -247,25 +247,25 @@ discard block |
||
247 | 247 | * Filters the gateway title to reflect Payment Request type |
248 | 248 | * |
249 | 249 | */ |
250 | - public function filter_gateway_title( $title, $id ) { |
|
250 | + public function filter_gateway_title($title, $id) { |
|
251 | 251 | global $post; |
252 | 252 | |
253 | - if ( ! is_object( $post ) ) { |
|
253 | + if ( ! is_object($post)) { |
|
254 | 254 | return $title; |
255 | 255 | } |
256 | 256 | |
257 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
258 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
257 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
258 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
259 | 259 | } else { |
260 | - $order = wc_get_order( $post->ID ); |
|
261 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
260 | + $order = wc_get_order($post->ID); |
|
261 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
262 | 262 | } |
263 | 263 | |
264 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
264 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
265 | 265 | return $method_title; |
266 | 266 | } |
267 | 267 | |
268 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
268 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
269 | 269 | return $method_title; |
270 | 270 | } |
271 | 271 | |
@@ -278,10 +278,10 @@ discard block |
||
278 | 278 | * @since 3.1.4 |
279 | 279 | * @version 4.0.0 |
280 | 280 | */ |
281 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
281 | + public function postal_code_validation($valid, $postcode, $country) { |
|
282 | 282 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
283 | 283 | |
284 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
284 | + if ( ! isset($gateways['stripe'])) { |
|
285 | 285 | return $valid; |
286 | 286 | } |
287 | 287 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * the order and not let it go through. The remedy for now is just to remove this validation. |
292 | 292 | * Note that this only works with shipping providers that don't validate full postal codes. |
293 | 293 | */ |
294 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
294 | + if ('GB' === $country || 'CA' === $country) { |
|
295 | 295 | return true; |
296 | 296 | } |
297 | 297 | |
@@ -307,27 +307,27 @@ discard block |
||
307 | 307 | * @param array $posted_data The posted data from checkout form. |
308 | 308 | * @param object $order |
309 | 309 | */ |
310 | - public function add_order_meta( $order_id, $posted_data, $order ) { |
|
311 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
310 | + public function add_order_meta($order_id, $posted_data, $order) { |
|
311 | + if (empty($_POST['payment_request_type'])) { |
|
312 | 312 | return; |
313 | 313 | } |
314 | 314 | |
315 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
315 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
316 | 316 | |
317 | - if ( 'apple_pay' === $payment_request_type ) { |
|
318 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
319 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
317 | + if ('apple_pay' === $payment_request_type) { |
|
318 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
319 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
320 | 320 | } else { |
321 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
321 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
322 | 322 | $order->save(); |
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
326 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
327 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
328 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
326 | + if ('payment_request_api' === $payment_request_type) { |
|
327 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
328 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
329 | 329 | } else { |
330 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
330 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
331 | 331 | $order->save(); |
332 | 332 | } |
333 | 333 | } |
@@ -341,11 +341,11 @@ discard block |
||
341 | 341 | * @return array |
342 | 342 | */ |
343 | 343 | public function supported_product_types() { |
344 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
344 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
345 | 345 | 'simple', |
346 | 346 | 'variable', |
347 | 347 | 'variation', |
348 | - ) ); |
|
348 | + )); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -356,15 +356,15 @@ discard block |
||
356 | 356 | * @return bool |
357 | 357 | */ |
358 | 358 | public function allowed_items_in_cart() { |
359 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
360 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
359 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
360 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
361 | 361 | |
362 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
362 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
363 | 363 | return false; |
364 | 364 | } |
365 | 365 | |
366 | 366 | // Pre Orders compatbility where we don't support charge upon release. |
367 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
367 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
368 | 368 | return false; |
369 | 369 | } |
370 | 370 | } |
@@ -379,71 +379,71 @@ discard block |
||
379 | 379 | * @version 4.0.0 |
380 | 380 | */ |
381 | 381 | public function scripts() { |
382 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
382 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
383 | 383 | return; |
384 | 384 | } |
385 | 385 | |
386 | - if ( is_product() ) { |
|
386 | + if (is_product()) { |
|
387 | 387 | global $post; |
388 | 388 | |
389 | - $product = wc_get_product( $post->ID ); |
|
389 | + $product = wc_get_product($post->ID); |
|
390 | 390 | |
391 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
391 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | |
395 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
395 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
396 | 396 | return; |
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
400 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
400 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
401 | 401 | |
402 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
403 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
402 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
403 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
404 | 404 | |
405 | 405 | wp_localize_script( |
406 | 406 | 'wc_stripe_payment_request', |
407 | 407 | 'wc_stripe_payment_request_params', |
408 | 408 | array( |
409 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
409 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
410 | 410 | 'stripe' => array( |
411 | 411 | 'key' => $this->get_publishable_key(), |
412 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
412 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
413 | 413 | ), |
414 | 414 | 'nonce' => array( |
415 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
416 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
417 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
418 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
419 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
420 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
421 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
422 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
415 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
416 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
417 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
418 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
419 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
420 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
421 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
422 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
423 | 423 | ), |
424 | 424 | 'i18n' => array( |
425 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
425 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
426 | 426 | /* translators: Do not translate the [option] placeholder */ |
427 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
427 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
428 | 428 | ), |
429 | 429 | 'checkout' => array( |
430 | 430 | 'url' => wc_get_checkout_url(), |
431 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
432 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
431 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
432 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
433 | 433 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
434 | 434 | ), |
435 | 435 | 'button' => array( |
436 | 436 | 'type' => $this->get_button_type(), |
437 | 437 | 'theme' => $this->get_button_theme(), |
438 | 438 | 'height' => $this->get_button_height(), |
439 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
439 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
440 | 440 | ), |
441 | 441 | 'is_product_page' => is_product(), |
442 | 442 | 'product' => $this->get_product_data(), |
443 | 443 | ) |
444 | 444 | ); |
445 | 445 | |
446 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
446 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -455,35 +455,35 @@ discard block |
||
455 | 455 | public function display_payment_request_button_html() { |
456 | 456 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
457 | 457 | |
458 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
458 | + if ( ! isset($gateways['stripe'])) { |
|
459 | 459 | return; |
460 | 460 | } |
461 | 461 | |
462 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
462 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
463 | 463 | return; |
464 | 464 | } |
465 | 465 | |
466 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
466 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
467 | 467 | return; |
468 | 468 | } |
469 | 469 | |
470 | - if ( is_product() ) { |
|
470 | + if (is_product()) { |
|
471 | 471 | global $post; |
472 | 472 | |
473 | - $product = wc_get_product( $post->ID ); |
|
473 | + $product = wc_get_product($post->ID); |
|
474 | 474 | |
475 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
475 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
476 | 476 | return; |
477 | 477 | } |
478 | 478 | |
479 | 479 | // Pre Orders charge upon release not supported. |
480 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
481 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
480 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
481 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
482 | 482 | return; |
483 | 483 | } |
484 | 484 | } else { |
485 | - if ( ! $this->allowed_items_in_cart() ) { |
|
486 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
485 | + if ( ! $this->allowed_items_in_cart()) { |
|
486 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
487 | 487 | return; |
488 | 488 | } |
489 | 489 | } |
@@ -505,40 +505,40 @@ discard block |
||
505 | 505 | public function display_payment_request_button_separator_html() { |
506 | 506 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
507 | 507 | |
508 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
508 | + if ( ! isset($gateways['stripe'])) { |
|
509 | 509 | return; |
510 | 510 | } |
511 | 511 | |
512 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
512 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | |
516 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
516 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
517 | 517 | return; |
518 | 518 | } |
519 | 519 | |
520 | - if ( is_product() ) { |
|
520 | + if (is_product()) { |
|
521 | 521 | global $post; |
522 | 522 | |
523 | - $product = wc_get_product( $post->ID ); |
|
523 | + $product = wc_get_product($post->ID); |
|
524 | 524 | |
525 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
525 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
526 | 526 | return; |
527 | 527 | } |
528 | 528 | |
529 | 529 | // Pre Orders charge upon release not supported. |
530 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
531 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
530 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
531 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
532 | 532 | return; |
533 | 533 | } |
534 | 534 | } else { |
535 | - if ( ! $this->allowed_items_in_cart() ) { |
|
536 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
535 | + if ( ! $this->allowed_items_in_cart()) { |
|
536 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
537 | 537 | return; |
538 | 538 | } |
539 | 539 | } |
540 | 540 | ?> |
541 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
541 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p> |
|
542 | 542 | <?php |
543 | 543 | } |
544 | 544 | |
@@ -549,11 +549,11 @@ discard block |
||
549 | 549 | * @version 4.0.0 |
550 | 550 | */ |
551 | 551 | public function ajax_log_errors() { |
552 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
552 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
553 | 553 | |
554 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
554 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
555 | 555 | |
556 | - WC_Stripe_Logger::log( $errors ); |
|
556 | + WC_Stripe_Logger::log($errors); |
|
557 | 557 | |
558 | 558 | exit; |
559 | 559 | } |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | * @version 4.0.0 |
566 | 566 | */ |
567 | 567 | public function ajax_clear_cart() { |
568 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
568 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
569 | 569 | |
570 | 570 | WC()->cart->empty_cart(); |
571 | 571 | exit; |
@@ -575,10 +575,10 @@ discard block |
||
575 | 575 | * Get cart details. |
576 | 576 | */ |
577 | 577 | public function ajax_get_cart_details() { |
578 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
578 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
579 | 579 | |
580 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
581 | - define( 'WOOCOMMERCE_CART', true ); |
|
580 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
581 | + define('WOOCOMMERCE_CART', true); |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | WC()->cart->calculate_totals(); |
@@ -591,14 +591,14 @@ discard block |
||
591 | 591 | $data = array( |
592 | 592 | 'shipping_required' => WC()->cart->needs_shipping(), |
593 | 593 | 'order_data' => array( |
594 | - 'currency' => strtolower( $currency ), |
|
595 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
594 | + 'currency' => strtolower($currency), |
|
595 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
596 | 596 | ), |
597 | 597 | ); |
598 | 598 | |
599 | 599 | $data['order_data'] += $this->build_display_items(); |
600 | 600 | |
601 | - wp_send_json( $data ); |
|
601 | + wp_send_json($data); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | /** |
@@ -609,47 +609,47 @@ discard block |
||
609 | 609 | * @see WC_Shipping::get_packages(). |
610 | 610 | */ |
611 | 611 | public function ajax_get_shipping_options() { |
612 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
612 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
613 | 613 | |
614 | 614 | try { |
615 | 615 | // Set the shipping package. |
616 | - $posted = filter_input_array( INPUT_POST, array( |
|
616 | + $posted = filter_input_array(INPUT_POST, array( |
|
617 | 617 | 'country' => FILTER_SANITIZE_STRING, |
618 | 618 | 'state' => FILTER_SANITIZE_STRING, |
619 | 619 | 'postcode' => FILTER_SANITIZE_STRING, |
620 | 620 | 'city' => FILTER_SANITIZE_STRING, |
621 | 621 | 'address' => FILTER_SANITIZE_STRING, |
622 | 622 | 'address_2' => FILTER_SANITIZE_STRING, |
623 | - ) ); |
|
623 | + )); |
|
624 | 624 | |
625 | - $this->calculate_shipping( $posted ); |
|
625 | + $this->calculate_shipping($posted); |
|
626 | 626 | |
627 | 627 | // Set the shipping options. |
628 | 628 | $data = array(); |
629 | 629 | $packages = WC()->shipping->get_packages(); |
630 | 630 | |
631 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
632 | - foreach ( $packages as $package_key => $package ) { |
|
633 | - if ( empty( $package['rates'] ) ) { |
|
634 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
631 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
632 | + foreach ($packages as $package_key => $package) { |
|
633 | + if (empty($package['rates'])) { |
|
634 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
635 | 635 | } |
636 | 636 | |
637 | - foreach ( $package['rates'] as $key => $rate ) { |
|
637 | + foreach ($package['rates'] as $key => $rate) { |
|
638 | 638 | $data['shipping_options'][] = array( |
639 | 639 | 'id' => $rate->id, |
640 | 640 | 'label' => $rate->label, |
641 | 641 | 'detail' => '', |
642 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
642 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
643 | 643 | ); |
644 | 644 | } |
645 | 645 | } |
646 | 646 | } else { |
647 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
647 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
648 | 648 | } |
649 | 649 | |
650 | - if ( isset( $data[0] ) ) { |
|
650 | + if (isset($data[0])) { |
|
651 | 651 | // Auto select the first shipping method. |
652 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
652 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | WC()->cart->calculate_totals(); |
@@ -657,12 +657,12 @@ discard block |
||
657 | 657 | $data += $this->build_display_items(); |
658 | 658 | $data['result'] = 'success'; |
659 | 659 | |
660 | - wp_send_json( $data ); |
|
661 | - } catch ( Exception $e ) { |
|
660 | + wp_send_json($data); |
|
661 | + } catch (Exception $e) { |
|
662 | 662 | $data += $this->build_display_items(); |
663 | 663 | $data['result'] = 'invalid_shipping_address'; |
664 | 664 | |
665 | - wp_send_json( $data ); |
|
665 | + wp_send_json($data); |
|
666 | 666 | } |
667 | 667 | } |
668 | 668 | |
@@ -670,22 +670,22 @@ discard block |
||
670 | 670 | * Update shipping method. |
671 | 671 | */ |
672 | 672 | public function ajax_update_shipping_method() { |
673 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
673 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
674 | 674 | |
675 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
676 | - define( 'WOOCOMMERCE_CART', true ); |
|
675 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
676 | + define('WOOCOMMERCE_CART', true); |
|
677 | 677 | } |
678 | 678 | |
679 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
680 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
679 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
680 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
681 | 681 | |
682 | - if ( is_array( $shipping_method ) ) { |
|
683 | - foreach ( $shipping_method as $i => $value ) { |
|
684 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
682 | + if (is_array($shipping_method)) { |
|
683 | + foreach ($shipping_method as $i => $value) { |
|
684 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
685 | 685 | } |
686 | 686 | } |
687 | 687 | |
688 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
688 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
689 | 689 | |
690 | 690 | WC()->cart->calculate_totals(); |
691 | 691 | |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | $data += $this->build_display_items(); |
694 | 694 | $data['result'] = 'success'; |
695 | 695 | |
696 | - wp_send_json( $data ); |
|
696 | + wp_send_json($data); |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | /** |
@@ -704,31 +704,31 @@ discard block |
||
704 | 704 | * @return array $data |
705 | 705 | */ |
706 | 706 | public function ajax_get_selected_product_data() { |
707 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
707 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
708 | 708 | |
709 | - $product_id = absint( $_POST['product_id'] ); |
|
710 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
709 | + $product_id = absint($_POST['product_id']); |
|
710 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
711 | 711 | |
712 | - $product = wc_get_product( $product_id ); |
|
712 | + $product = wc_get_product($product_id); |
|
713 | 713 | |
714 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
715 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
714 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
715 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
716 | 716 | |
717 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
718 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
717 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
718 | + $variation_id = $product->get_matching_variation($attributes); |
|
719 | 719 | } else { |
720 | - $data_store = WC_Data_Store::load( 'product' ); |
|
721 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
720 | + $data_store = WC_Data_Store::load('product'); |
|
721 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
722 | 722 | } |
723 | 723 | |
724 | - if ( ! empty( $variation_id ) ) { |
|
725 | - $product = wc_get_product( $variation_id ); |
|
724 | + if ( ! empty($variation_id)) { |
|
725 | + $product = wc_get_product($variation_id); |
|
726 | 726 | } |
727 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
728 | - $product = wc_get_product( $product_id ); |
|
727 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
728 | + $product = wc_get_product($product_id); |
|
729 | 729 | } |
730 | 730 | |
731 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
731 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
732 | 732 | |
733 | 733 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
734 | 734 | |
@@ -736,28 +736,28 @@ discard block |
||
736 | 736 | $items = array(); |
737 | 737 | |
738 | 738 | $items[] = array( |
739 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
740 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
739 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
740 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
741 | 741 | ); |
742 | 742 | |
743 | - if ( wc_tax_enabled() ) { |
|
743 | + if (wc_tax_enabled()) { |
|
744 | 744 | $items[] = array( |
745 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
745 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
746 | 746 | 'amount' => 0, |
747 | 747 | 'pending' => true, |
748 | 748 | ); |
749 | 749 | } |
750 | 750 | |
751 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
751 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
752 | 752 | $items[] = array( |
753 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
753 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
754 | 754 | 'amount' => 0, |
755 | 755 | 'pending' => true, |
756 | 756 | ); |
757 | 757 | |
758 | - $data['shippingOptions'] = array( |
|
758 | + $data['shippingOptions'] = array( |
|
759 | 759 | 'id' => 'pending', |
760 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
760 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
761 | 761 | 'detail' => '', |
762 | 762 | 'amount' => 0, |
763 | 763 | ); |
@@ -766,15 +766,15 @@ discard block |
||
766 | 766 | $data['displayItems'] = $items; |
767 | 767 | $data['total'] = array( |
768 | 768 | 'label' => $this->total_label, |
769 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
769 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
770 | 770 | 'pending' => true, |
771 | 771 | ); |
772 | 772 | |
773 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
774 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
775 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
773 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
774 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
775 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
776 | 776 | |
777 | - wp_send_json( $data ); |
|
777 | + wp_send_json($data); |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | /** |
@@ -785,37 +785,37 @@ discard block |
||
785 | 785 | * @return array $data |
786 | 786 | */ |
787 | 787 | public function ajax_add_to_cart() { |
788 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
788 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
789 | 789 | |
790 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
791 | - define( 'WOOCOMMERCE_CART', true ); |
|
790 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
791 | + define('WOOCOMMERCE_CART', true); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | WC()->shipping->reset_shipping(); |
795 | 795 | |
796 | - $product_id = absint( $_POST['product_id'] ); |
|
797 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
796 | + $product_id = absint($_POST['product_id']); |
|
797 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
798 | 798 | |
799 | - $product = wc_get_product( $product_id ); |
|
799 | + $product = wc_get_product($product_id); |
|
800 | 800 | |
801 | 801 | // First empty the cart to prevent wrong calculation. |
802 | 802 | WC()->cart->empty_cart(); |
803 | 803 | |
804 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
805 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
804 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
805 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
806 | 806 | |
807 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
808 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
807 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
808 | + $variation_id = $product->get_matching_variation($attributes); |
|
809 | 809 | } else { |
810 | - $data_store = WC_Data_Store::load( 'product' ); |
|
811 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
810 | + $data_store = WC_Data_Store::load('product'); |
|
811 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
812 | 812 | } |
813 | 813 | |
814 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
814 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
815 | 815 | } |
816 | 816 | |
817 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
818 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
817 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
818 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | WC()->cart->calculate_totals(); |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | $data += $this->build_display_items(); |
825 | 825 | $data['result'] = 'success'; |
826 | 826 | |
827 | - wp_send_json( $data ); |
|
827 | + wp_send_json($data); |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | /** |
@@ -837,31 +837,31 @@ discard block |
||
837 | 837 | * @version 4.0.0 |
838 | 838 | */ |
839 | 839 | public function normalize_state() { |
840 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
841 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
842 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
843 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
840 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
841 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
842 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
843 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
844 | 844 | |
845 | - if ( $billing_state && $billing_country ) { |
|
846 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
845 | + if ($billing_state && $billing_country) { |
|
846 | + $valid_states = WC()->countries->get_states($billing_country); |
|
847 | 847 | |
848 | 848 | // Valid states found for country. |
849 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
850 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
851 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
849 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
850 | + foreach ($valid_states as $state_abbr => $state) { |
|
851 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
852 | 852 | $_POST['billing_state'] = $state_abbr; |
853 | 853 | } |
854 | 854 | } |
855 | 855 | } |
856 | 856 | } |
857 | 857 | |
858 | - if ( $shipping_state && $shipping_country ) { |
|
859 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
858 | + if ($shipping_state && $shipping_country) { |
|
859 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
860 | 860 | |
861 | 861 | // Valid states found for country. |
862 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
863 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
864 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
862 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
863 | + foreach ($valid_states as $state_abbr => $state) { |
|
864 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
865 | 865 | $_POST['shipping_state'] = $state_abbr; |
866 | 866 | } |
867 | 867 | } |
@@ -876,19 +876,19 @@ discard block |
||
876 | 876 | * @version 4.0.0 |
877 | 877 | */ |
878 | 878 | public function ajax_create_order() { |
879 | - if ( WC()->cart->is_empty() ) { |
|
880 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
879 | + if (WC()->cart->is_empty()) { |
|
880 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
881 | 881 | } |
882 | 882 | |
883 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
884 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
883 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
884 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | $this->normalize_state(); |
888 | 888 | |
889 | 889 | WC()->checkout()->process_checkout(); |
890 | 890 | |
891 | - die( 0 ); |
|
891 | + die(0); |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | /** |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | * @version 4.0.0 |
899 | 899 | * @param array $address |
900 | 900 | */ |
901 | - protected function calculate_shipping( $address = array() ) { |
|
901 | + protected function calculate_shipping($address = array()) { |
|
902 | 902 | global $states; |
903 | 903 | |
904 | 904 | $country = $address['country']; |
@@ -915,28 +915,28 @@ discard block |
||
915 | 915 | * In some versions of Chrome, state can be a full name. So we need |
916 | 916 | * to convert that to abbreviation as WC is expecting that. |
917 | 917 | */ |
918 | - if ( 2 < strlen( $state ) ) { |
|
919 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
918 | + if (2 < strlen($state)) { |
|
919 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
920 | 920 | } |
921 | 921 | |
922 | 922 | WC()->shipping->reset_shipping(); |
923 | 923 | |
924 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
925 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
924 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
925 | + $postcode = wc_format_postcode($postcode, $country); |
|
926 | 926 | } |
927 | 927 | |
928 | - if ( $country ) { |
|
929 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
930 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
928 | + if ($country) { |
|
929 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
930 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
931 | 931 | } else { |
932 | 932 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
933 | 933 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
934 | 934 | } |
935 | 935 | |
936 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
937 | - WC()->customer->calculated_shipping( true ); |
|
936 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
937 | + WC()->customer->calculated_shipping(true); |
|
938 | 938 | } else { |
939 | - WC()->customer->set_calculated_shipping( true ); |
|
939 | + WC()->customer->set_calculated_shipping(true); |
|
940 | 940 | WC()->customer->save(); |
941 | 941 | } |
942 | 942 | |
@@ -953,17 +953,17 @@ discard block |
||
953 | 953 | $packages[0]['destination']['address'] = $address_1; |
954 | 954 | $packages[0]['destination']['address_2'] = $address_2; |
955 | 955 | |
956 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
957 | - if ( $item['data']->needs_shipping() ) { |
|
958 | - if ( isset( $item['line_total'] ) ) { |
|
956 | + foreach (WC()->cart->get_cart() as $item) { |
|
957 | + if ($item['data']->needs_shipping()) { |
|
958 | + if (isset($item['line_total'])) { |
|
959 | 959 | $packages[0]['contents_cost'] += $item['line_total']; |
960 | 960 | } |
961 | 961 | } |
962 | 962 | } |
963 | 963 | |
964 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
964 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
965 | 965 | |
966 | - WC()->shipping->calculate_shipping( $packages ); |
|
966 | + WC()->shipping->calculate_shipping($packages); |
|
967 | 967 | } |
968 | 968 | |
969 | 969 | /** |
@@ -972,19 +972,19 @@ discard block |
||
972 | 972 | * @since 3.1.0 |
973 | 973 | * @version 4.0.0 |
974 | 974 | */ |
975 | - protected function build_shipping_methods( $shipping_methods ) { |
|
976 | - if ( empty( $shipping_methods ) ) { |
|
975 | + protected function build_shipping_methods($shipping_methods) { |
|
976 | + if (empty($shipping_methods)) { |
|
977 | 977 | return array(); |
978 | 978 | } |
979 | 979 | |
980 | 980 | $shipping = array(); |
981 | 981 | |
982 | - foreach ( $shipping_methods as $method ) { |
|
982 | + foreach ($shipping_methods as $method) { |
|
983 | 983 | $shipping[] = array( |
984 | 984 | 'id' => $method['id'], |
985 | 985 | 'label' => $method['label'], |
986 | 986 | 'detail' => '', |
987 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
987 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
988 | 988 | ); |
989 | 989 | } |
990 | 990 | |
@@ -998,69 +998,69 @@ discard block |
||
998 | 998 | * @version 4.0.0 |
999 | 999 | */ |
1000 | 1000 | protected function build_display_items() { |
1001 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1002 | - define( 'WOOCOMMERCE_CART', true ); |
|
1001 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1002 | + define('WOOCOMMERCE_CART', true); |
|
1003 | 1003 | } |
1004 | 1004 | |
1005 | 1005 | $items = array(); |
1006 | 1006 | $subtotal = 0; |
1007 | 1007 | |
1008 | 1008 | // Default show only subtotal instead of itemization. |
1009 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1010 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1009 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1010 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1011 | 1011 | $amount = $cart_item['line_subtotal']; |
1012 | - $subtotal += $cart_item['line_subtotal']; |
|
1012 | + $subtotal += $cart_item['line_subtotal']; |
|
1013 | 1013 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1014 | 1014 | |
1015 | 1015 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1016 | 1016 | |
1017 | 1017 | $item = array( |
1018 | 1018 | 'label' => $product_name . $quantity_label, |
1019 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1019 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1020 | 1020 | ); |
1021 | 1021 | |
1022 | 1022 | $items[] = $item; |
1023 | 1023 | } |
1024 | 1024 | } |
1025 | 1025 | |
1026 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1027 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1028 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1029 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1030 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1026 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1027 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1028 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1029 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1030 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1031 | 1031 | |
1032 | - if ( wc_tax_enabled() ) { |
|
1032 | + if (wc_tax_enabled()) { |
|
1033 | 1033 | $items[] = array( |
1034 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1035 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1034 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1035 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1036 | 1036 | ); |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - if ( WC()->cart->needs_shipping() ) { |
|
1039 | + if (WC()->cart->needs_shipping()) { |
|
1040 | 1040 | $items[] = array( |
1041 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1042 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1041 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1042 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1043 | 1043 | ); |
1044 | 1044 | } |
1045 | 1045 | |
1046 | - if ( WC()->cart->has_discount() ) { |
|
1046 | + if (WC()->cart->has_discount()) { |
|
1047 | 1047 | $items[] = array( |
1048 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1049 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1048 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1049 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1050 | 1050 | ); |
1051 | 1051 | } |
1052 | 1052 | |
1053 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1053 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1054 | 1054 | $cart_fees = WC()->cart->fees; |
1055 | 1055 | } else { |
1056 | 1056 | $cart_fees = WC()->cart->get_fees(); |
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | // Include fees and taxes as display items. |
1060 | - foreach ( $cart_fees as $key => $fee ) { |
|
1060 | + foreach ($cart_fees as $key => $fee) { |
|
1061 | 1061 | $items[] = array( |
1062 | 1062 | 'label' => $fee->name, |
1063 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1063 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1064 | 1064 | ); |
1065 | 1065 | } |
1066 | 1066 | |
@@ -1068,7 +1068,7 @@ discard block |
||
1068 | 1068 | 'displayItems' => $items, |
1069 | 1069 | 'total' => array( |
1070 | 1070 | 'label' => $this->total_label, |
1071 | - 'amount' => max( 0, apply_filters( 'woocommerce_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1071 | + 'amount' => max(0, apply_filters('woocommerce_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1072 | 1072 | 'pending' => false, |
1073 | 1073 | ), |
1074 | 1074 | ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_giropay'; |
60 | - $this->method_title = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_giropay_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_giropay_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | * @return array |
170 | 170 | */ |
171 | 171 | public function payment_icons() { |
172 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
172 | + return apply_filters('wc_stripe_payment_icons', array( |
|
173 | 173 | 'giropay' => '<i class="stripe-pf stripe-pf-giropay stripe-pf-right" alt="Giropay" aria-hidden="true"></i>', |
174 | - ) ); |
|
174 | + )); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | $icons_str .= $icons['giropay']; |
190 | 190 | |
191 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
191 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -199,19 +199,19 @@ discard block |
||
199 | 199 | * @access public |
200 | 200 | */ |
201 | 201 | public function payment_scripts() { |
202 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
202 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | 205 | |
206 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
207 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
206 | + wp_enqueue_style('stripe_paymentfonts'); |
|
207 | + wp_enqueue_script('woocommerce_stripe'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * Initialize Gateway Settings Form Fields. |
212 | 212 | */ |
213 | 213 | public function init_form_fields() { |
214 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' ); |
|
214 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php'); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -222,25 +222,25 @@ discard block |
||
222 | 222 | $total = WC()->cart->total; |
223 | 223 | |
224 | 224 | // If paying from order, we need to get total from order not cart. |
225 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
226 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
225 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
226 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
227 | 227 | $total = $order->get_total(); |
228 | 228 | } |
229 | 229 | |
230 | - if ( is_add_payment_method_page() ) { |
|
231 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
232 | - $total = ''; |
|
230 | + if (is_add_payment_method_page()) { |
|
231 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
232 | + $total = ''; |
|
233 | 233 | } else { |
234 | 234 | $pay_button_text = ''; |
235 | 235 | } |
236 | 236 | |
237 | 237 | echo '<div |
238 | 238 | id="stripe-giropay-payment-data" |
239 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
240 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
239 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
240 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
241 | 241 | |
242 | - if ( $this->description ) { |
|
243 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
242 | + if ($this->description) { |
|
243 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | echo '</div>'; |
@@ -254,24 +254,24 @@ discard block |
||
254 | 254 | * @param object $order |
255 | 255 | * @return mixed |
256 | 256 | */ |
257 | - public function create_source( $order ) { |
|
257 | + public function create_source($order) { |
|
258 | 258 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
259 | 259 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
260 | - $return_url = $this->get_stripe_return_url( $order ); |
|
260 | + $return_url = $this->get_stripe_return_url($order); |
|
261 | 261 | $post_data = array(); |
262 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
263 | - $post_data['currency'] = strtolower( $currency ); |
|
262 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
263 | + $post_data['currency'] = strtolower($currency); |
|
264 | 264 | $post_data['type'] = 'giropay'; |
265 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
266 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
265 | + $post_data['owner'] = $this->get_owner_details($order); |
|
266 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
267 | 267 | |
268 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
269 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
268 | + if ( ! empty($this->statement_descriptor)) { |
|
269 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
270 | 270 | } |
271 | 271 | |
272 | - WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' ); |
|
272 | + WC_Stripe_Logger::log('Info: Begin creating Giropay source'); |
|
273 | 273 | |
274 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
274 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -285,51 +285,51 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return array|void |
287 | 287 | */ |
288 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
288 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
289 | 289 | try { |
290 | - $order = wc_get_order( $order_id ); |
|
290 | + $order = wc_get_order($order_id); |
|
291 | 291 | |
292 | 292 | // This will throw exception if not valid. |
293 | - $this->validate_minimum_order_amount( $order ); |
|
293 | + $this->validate_minimum_order_amount($order); |
|
294 | 294 | |
295 | 295 | // This comes from the create account checkbox in the checkout page. |
296 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
296 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
297 | 297 | |
298 | - if ( $create_account ) { |
|
298 | + if ($create_account) { |
|
299 | 299 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
300 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
300 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
301 | 301 | $new_stripe_customer->create_customer(); |
302 | 302 | } |
303 | 303 | |
304 | - $response = $this->create_source( $order ); |
|
304 | + $response = $this->create_source($order); |
|
305 | 305 | |
306 | - if ( ! empty( $response->error ) ) { |
|
307 | - $order->add_order_note( $response->error->message ); |
|
306 | + if ( ! empty($response->error)) { |
|
307 | + $order->add_order_note($response->error->message); |
|
308 | 308 | |
309 | - throw new Exception( $response->error->message ); |
|
309 | + throw new Exception($response->error->message); |
|
310 | 310 | } |
311 | 311 | |
312 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
313 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
312 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
313 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
314 | 314 | } else { |
315 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
315 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
316 | 316 | $order->save(); |
317 | 317 | } |
318 | 318 | |
319 | - WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' ); |
|
319 | + WC_Stripe_Logger::log('Info: Redirecting to Giropay...'); |
|
320 | 320 | |
321 | 321 | return array( |
322 | 322 | 'result' => 'success', |
323 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
323 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
324 | 324 | ); |
325 | - } catch ( Exception $e ) { |
|
326 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
327 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
325 | + } catch (Exception $e) { |
|
326 | + wc_add_notice($e->getMessage(), 'error'); |
|
327 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
328 | 328 | |
329 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
329 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
330 | 330 | |
331 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
332 | - $this->send_failed_order_email( $order_id ); |
|
331 | + if ($order->has_status(array('pending', 'failed'))) { |
|
332 | + $this->send_failed_order_email($order_id); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_ideal'; |
60 | - $this->method_title = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_ideal_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_ideal_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | * @return array |
170 | 170 | */ |
171 | 171 | public function payment_icons() { |
172 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
172 | + return apply_filters('wc_stripe_payment_icons', array( |
|
173 | 173 | 'ideal' => '<i class="stripe-pf stripe-pf-ideal stripe-pf-right" alt="iDeal" aria-hidden="true"></i>', |
174 | - ) ); |
|
174 | + )); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | $icons_str .= $icons['ideal']; |
190 | 190 | |
191 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
191 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -199,19 +199,19 @@ discard block |
||
199 | 199 | * @access public |
200 | 200 | */ |
201 | 201 | public function payment_scripts() { |
202 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
202 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | 205 | |
206 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
207 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
206 | + wp_enqueue_style('stripe_paymentfonts'); |
|
207 | + wp_enqueue_script('woocommerce_stripe'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * Initialize Gateway Settings Form Fields. |
212 | 212 | */ |
213 | 213 | public function init_form_fields() { |
214 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' ); |
|
214 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php'); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -222,25 +222,25 @@ discard block |
||
222 | 222 | $total = WC()->cart->total; |
223 | 223 | |
224 | 224 | // If paying from order, we need to get total from order not cart. |
225 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
226 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
225 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
226 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
227 | 227 | $total = $order->get_total(); |
228 | 228 | } |
229 | 229 | |
230 | - if ( is_add_payment_method_page() ) { |
|
231 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
232 | - $total = ''; |
|
230 | + if (is_add_payment_method_page()) { |
|
231 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
232 | + $total = ''; |
|
233 | 233 | } else { |
234 | 234 | $pay_button_text = ''; |
235 | 235 | } |
236 | 236 | |
237 | 237 | echo '<div |
238 | 238 | id="stripe-ideal-payment-data" |
239 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
240 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
239 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
240 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
241 | 241 | |
242 | - if ( $this->description ) { |
|
243 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
242 | + if ($this->description) { |
|
243 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | echo '</div>'; |
@@ -254,24 +254,24 @@ discard block |
||
254 | 254 | * @param object $order |
255 | 255 | * @return mixed |
256 | 256 | */ |
257 | - public function create_source( $order ) { |
|
257 | + public function create_source($order) { |
|
258 | 258 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
259 | 259 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
260 | - $return_url = $this->get_stripe_return_url( $order ); |
|
260 | + $return_url = $this->get_stripe_return_url($order); |
|
261 | 261 | $post_data = array(); |
262 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
263 | - $post_data['currency'] = strtolower( $currency ); |
|
262 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
263 | + $post_data['currency'] = strtolower($currency); |
|
264 | 264 | $post_data['type'] = 'ideal'; |
265 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
266 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
265 | + $post_data['owner'] = $this->get_owner_details($order); |
|
266 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
267 | 267 | |
268 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
269 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
268 | + if ( ! empty($this->statement_descriptor)) { |
|
269 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
270 | 270 | } |
271 | 271 | |
272 | - WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' ); |
|
272 | + WC_Stripe_Logger::log('Info: Begin creating iDeal source'); |
|
273 | 273 | |
274 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
274 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -285,51 +285,51 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return array|void |
287 | 287 | */ |
288 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
288 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
289 | 289 | try { |
290 | - $order = wc_get_order( $order_id ); |
|
290 | + $order = wc_get_order($order_id); |
|
291 | 291 | |
292 | 292 | // This will throw exception if not valid. |
293 | - $this->validate_minimum_order_amount( $order ); |
|
293 | + $this->validate_minimum_order_amount($order); |
|
294 | 294 | |
295 | 295 | // This comes from the create account checkbox in the checkout page. |
296 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
296 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
297 | 297 | |
298 | - if ( $create_account ) { |
|
298 | + if ($create_account) { |
|
299 | 299 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
300 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
300 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
301 | 301 | $new_stripe_customer->create_customer(); |
302 | 302 | } |
303 | 303 | |
304 | - $response = $this->create_source( $order ); |
|
304 | + $response = $this->create_source($order); |
|
305 | 305 | |
306 | - if ( ! empty( $response->error ) ) { |
|
307 | - $order->add_order_note( $response->error->message ); |
|
306 | + if ( ! empty($response->error)) { |
|
307 | + $order->add_order_note($response->error->message); |
|
308 | 308 | |
309 | - throw new Exception( $response->error->message ); |
|
309 | + throw new Exception($response->error->message); |
|
310 | 310 | } |
311 | 311 | |
312 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
313 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
312 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
313 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
314 | 314 | } else { |
315 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
315 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
316 | 316 | $order->save(); |
317 | 317 | } |
318 | 318 | |
319 | - WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' ); |
|
319 | + WC_Stripe_Logger::log('Info: Redirecting to iDeal...'); |
|
320 | 320 | |
321 | 321 | return array( |
322 | 322 | 'result' => 'success', |
323 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
323 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
324 | 324 | ); |
325 | - } catch ( Exception $e ) { |
|
326 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
327 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
325 | + } catch (Exception $e) { |
|
326 | + wc_add_notice($e->getMessage(), 'error'); |
|
327 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
328 | 328 | |
329 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
329 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
330 | 330 | |
331 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
332 | - $this->send_failed_order_email( $order_id ); |
|
331 | + if ($order->has_status(array('pending', 'failed'))) { |
|
332 | + $this->send_failed_order_email($order_id); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_p24'; |
60 | - $this->method_title = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_p24_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_p24_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | 146 | 'PLN', |
147 | - ) ); |
|
147 | + )); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @return bool |
156 | 156 | */ |
157 | 157 | public function is_available() { |
158 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
158 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
159 | 159 | return false; |
160 | 160 | } |
161 | 161 | |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * @return array |
171 | 171 | */ |
172 | 172 | public function payment_icons() { |
173 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
173 | + return apply_filters('wc_stripe_payment_icons', array( |
|
174 | 174 | 'p24' => '<i class="stripe-pf stripe-pf-p24 stripe-pf-right" alt="P24" aria-hidden="true"></i>', |
175 | - ) ); |
|
175 | + )); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | $icons_str .= $icons['p24']; |
191 | 191 | |
192 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
192 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -200,19 +200,19 @@ discard block |
||
200 | 200 | * @access public |
201 | 201 | */ |
202 | 202 | public function payment_scripts() { |
203 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
203 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
204 | 204 | return; |
205 | 205 | } |
206 | 206 | |
207 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
208 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
207 | + wp_enqueue_style('stripe_paymentfonts'); |
|
208 | + wp_enqueue_script('woocommerce_stripe'); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | 212 | * Initialize Gateway Settings Form Fields. |
213 | 213 | */ |
214 | 214 | public function init_form_fields() { |
215 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' ); |
|
215 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php'); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -223,25 +223,25 @@ discard block |
||
223 | 223 | $total = WC()->cart->total; |
224 | 224 | |
225 | 225 | // If paying from order, we need to get total from order not cart. |
226 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
227 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
226 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
227 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
228 | 228 | $total = $order->get_total(); |
229 | 229 | } |
230 | 230 | |
231 | - if ( is_add_payment_method_page() ) { |
|
232 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
233 | - $total = ''; |
|
231 | + if (is_add_payment_method_page()) { |
|
232 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
233 | + $total = ''; |
|
234 | 234 | } else { |
235 | 235 | $pay_button_text = ''; |
236 | 236 | } |
237 | 237 | |
238 | 238 | echo '<div |
239 | 239 | id="stripe-p24-payment-data" |
240 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
241 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
240 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
241 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
242 | 242 | |
243 | - if ( $this->description ) { |
|
244 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
243 | + if ($this->description) { |
|
244 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | echo '</div>'; |
@@ -255,20 +255,20 @@ discard block |
||
255 | 255 | * @param object $order |
256 | 256 | * @return mixed |
257 | 257 | */ |
258 | - public function create_source( $order ) { |
|
258 | + public function create_source($order) { |
|
259 | 259 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
260 | 260 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
261 | - $return_url = $this->get_stripe_return_url( $order ); |
|
261 | + $return_url = $this->get_stripe_return_url($order); |
|
262 | 262 | $post_data = array(); |
263 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
264 | - $post_data['currency'] = strtolower( $currency ); |
|
263 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
264 | + $post_data['currency'] = strtolower($currency); |
|
265 | 265 | $post_data['type'] = 'p24'; |
266 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
267 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
266 | + $post_data['owner'] = $this->get_owner_details($order); |
|
267 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
268 | 268 | |
269 | - WC_Stripe_Logger::log( 'Info: Begin creating P24 source' ); |
|
269 | + WC_Stripe_Logger::log('Info: Begin creating P24 source'); |
|
270 | 270 | |
271 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
271 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -282,51 +282,51 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @return array|void |
284 | 284 | */ |
285 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
285 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
286 | 286 | try { |
287 | - $order = wc_get_order( $order_id ); |
|
287 | + $order = wc_get_order($order_id); |
|
288 | 288 | |
289 | 289 | // This will throw exception if not valid. |
290 | - $this->validate_minimum_order_amount( $order ); |
|
290 | + $this->validate_minimum_order_amount($order); |
|
291 | 291 | |
292 | 292 | // This comes from the create account checkbox in the checkout page. |
293 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
293 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
294 | 294 | |
295 | - if ( $create_account ) { |
|
295 | + if ($create_account) { |
|
296 | 296 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
297 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
297 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
298 | 298 | $new_stripe_customer->create_customer(); |
299 | 299 | } |
300 | 300 | |
301 | - $response = $this->create_source( $order ); |
|
301 | + $response = $this->create_source($order); |
|
302 | 302 | |
303 | - if ( ! empty( $response->error ) ) { |
|
304 | - $order->add_order_note( $response->error->message ); |
|
303 | + if ( ! empty($response->error)) { |
|
304 | + $order->add_order_note($response->error->message); |
|
305 | 305 | |
306 | - throw new Exception( $response->error->message ); |
|
306 | + throw new Exception($response->error->message); |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
310 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
309 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
310 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
311 | 311 | } else { |
312 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
312 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
313 | 313 | $order->save(); |
314 | 314 | } |
315 | 315 | |
316 | - WC_Stripe_Logger::log( 'Info: Redirecting to P24...' ); |
|
316 | + WC_Stripe_Logger::log('Info: Redirecting to P24...'); |
|
317 | 317 | |
318 | 318 | return array( |
319 | 319 | 'result' => 'success', |
320 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
320 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
321 | 321 | ); |
322 | - } catch ( Exception $e ) { |
|
323 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
324 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
322 | + } catch (Exception $e) { |
|
323 | + wc_add_notice($e->getMessage(), 'error'); |
|
324 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
325 | 325 | |
326 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
326 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
327 | 327 | |
328 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
329 | - $this->send_failed_order_email( $order_id ); |
|
328 | + if ($order->has_status(array('pending', 'failed'))) { |
|
329 | + $this->send_failed_order_email($order_id); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | public function __construct() { |
21 | 21 | self::$_this = $this; |
22 | 22 | |
23 | - add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) ); |
|
24 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
25 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
26 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
27 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
28 | - add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) ); |
|
23 | + add_action('wp', array($this, 'maybe_process_redirect_order')); |
|
24 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
25 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
26 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
27 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
28 | + add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -46,25 +46,25 @@ discard block |
||
46 | 46 | * @since 4.0.0 |
47 | 47 | * @version 4.0.0 |
48 | 48 | */ |
49 | - public function process_redirect_payment( $order_id, $retry = true ) { |
|
49 | + public function process_redirect_payment($order_id, $retry = true) { |
|
50 | 50 | try { |
51 | - $source = wc_clean( $_GET['source'] ); |
|
51 | + $source = wc_clean($_GET['source']); |
|
52 | 52 | |
53 | - if ( empty( $source ) ) { |
|
53 | + if (empty($source)) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | - if ( empty( $order_id ) ) { |
|
57 | + if (empty($order_id)) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | 60 | |
61 | - $order = wc_get_order( $order_id ); |
|
61 | + $order = wc_get_order($order_id); |
|
62 | 62 | |
63 | - if ( ! is_object( $order ) ) { |
|
63 | + if ( ! is_object($order)) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) { |
|
67 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
@@ -72,97 +72,97 @@ discard block |
||
72 | 72 | $response = null; |
73 | 73 | |
74 | 74 | // This will throw exception if not valid. |
75 | - $this->validate_minimum_order_amount( $order ); |
|
75 | + $this->validate_minimum_order_amount($order); |
|
76 | 76 | |
77 | - WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
77 | + WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
78 | 78 | |
79 | 79 | // Prep source object. |
80 | 80 | $source_object = new stdClass(); |
81 | 81 | $source_object->token_id = ''; |
82 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
82 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
83 | 83 | $source_object->source = $source; |
84 | 84 | |
85 | 85 | /** |
86 | 86 | * First check if the source is chargeable at this time. If not, |
87 | 87 | * webhook will take care of it later. |
88 | 88 | */ |
89 | - $source_info = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
89 | + $source_info = WC_Stripe_API::retrieve('sources/' . $source); |
|
90 | 90 | |
91 | - if ( ! empty( $source_info->error ) ) { |
|
92 | - throw new Exception( $source_info->error->message ); |
|
91 | + if ( ! empty($source_info->error)) { |
|
92 | + throw new Exception($source_info->error->message); |
|
93 | 93 | } |
94 | 94 | |
95 | - if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) { |
|
96 | - throw new Exception( __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) ); |
|
95 | + if ('failed' === $source_info->status || 'canceled' === $source_info->status) { |
|
96 | + throw new Exception(__('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe')); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // If already consumed, then ignore request. |
100 | - if ( 'consumed' === $source_info->status ) { |
|
100 | + if ('consumed' === $source_info->status) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // If not chargeable, then ignore request. |
105 | - if ( 'chargeable' !== $source_info->status ) { |
|
105 | + if ('chargeable' !== $source_info->status) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | 109 | // Make the request. |
110 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
110 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
111 | 111 | |
112 | - if ( ! empty( $response->error ) ) { |
|
112 | + if ( ! empty($response->error)) { |
|
113 | 113 | // If it is an API error such connection or server, let's retry. |
114 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
115 | - if ( $retry ) { |
|
116 | - sleep( 5 ); |
|
117 | - return $this->process_redirect_payment( $order_id, false ); |
|
114 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
115 | + if ($retry) { |
|
116 | + sleep(5); |
|
117 | + return $this->process_redirect_payment($order_id, false); |
|
118 | 118 | } else { |
119 | 119 | $message = 'API connection error and retries exhausted.'; |
120 | - $order->add_order_note( $message ); |
|
121 | - throw new Exception( $message ); |
|
120 | + $order->add_order_note($message); |
|
121 | + throw new Exception($message); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | 125 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
126 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
127 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
126 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
127 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
128 | 128 | |
129 | - return $this->process_redirect_payment( $order_id, false ); |
|
129 | + return $this->process_redirect_payment($order_id, false); |
|
130 | 130 | |
131 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
131 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
132 | 132 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
133 | 133 | |
134 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
134 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
135 | 135 | $wc_token->delete(); |
136 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
137 | - $order->add_order_note( $message ); |
|
138 | - throw new Exception( $message ); |
|
136 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
137 | + $order->add_order_note($message); |
|
138 | + throw new Exception($message); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
142 | 142 | |
143 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
143 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
144 | 144 | |
145 | - throw new Exception( $message ); |
|
145 | + throw new Exception($message); |
|
146 | 146 | } |
147 | 147 | |
148 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
148 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
149 | 149 | |
150 | - $this->process_response( $response, $order ); |
|
150 | + $this->process_response($response, $order); |
|
151 | 151 | |
152 | - } catch ( Exception $e ) { |
|
153 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
152 | + } catch (Exception $e) { |
|
153 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
154 | 154 | |
155 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
155 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
156 | 156 | |
157 | 157 | /* translators: error message */ |
158 | - $order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
158 | + $order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
159 | 159 | |
160 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
161 | - $this->send_failed_order_email( $order_id ); |
|
160 | + if ($order->has_status(array('pending', 'failed'))) { |
|
161 | + $this->send_failed_order_email($order_id); |
|
162 | 162 | } |
163 | 163 | |
164 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
165 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
164 | + wc_add_notice($e->getMessage(), 'error'); |
|
165 | + wp_safe_redirect(wc_get_checkout_url()); |
|
166 | 166 | exit; |
167 | 167 | } |
168 | 168 | } |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * @version 4.0.0 |
175 | 175 | */ |
176 | 176 | public function maybe_process_redirect_order() { |
177 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) { |
|
177 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | 180 | |
181 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
181 | + $order_id = wc_clean($_GET['order_id']); |
|
182 | 182 | |
183 | - $this->process_redirect_payment( $order_id ); |
|
183 | + $this->process_redirect_payment($order_id); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -190,52 +190,52 @@ discard block |
||
190 | 190 | * @version 4.0.0 |
191 | 191 | * @param int $order_id |
192 | 192 | */ |
193 | - public function capture_payment( $order_id ) { |
|
194 | - $order = wc_get_order( $order_id ); |
|
193 | + public function capture_payment($order_id) { |
|
194 | + $order = wc_get_order($order_id); |
|
195 | 195 | |
196 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
197 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
198 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
196 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
197 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
198 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
199 | 199 | |
200 | - if ( $charge && 'no' === $captured ) { |
|
200 | + if ($charge && 'no' === $captured) { |
|
201 | 201 | $order_total = $order->get_total(); |
202 | 202 | |
203 | - if ( 0 < $order->get_total_refunded() ) { |
|
203 | + if (0 < $order->get_total_refunded()) { |
|
204 | 204 | $order_total = $order_total - $order->get_total_refunded(); |
205 | 205 | } |
206 | 206 | |
207 | - $result = WC_Stripe_API::request( array( |
|
208 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
207 | + $result = WC_Stripe_API::request(array( |
|
208 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
209 | 209 | 'expand[]' => 'balance_transaction', |
210 | - ), 'charges/' . $charge . '/capture' ); |
|
210 | + ), 'charges/' . $charge . '/capture'); |
|
211 | 211 | |
212 | - if ( ! empty( $result->error ) ) { |
|
212 | + if ( ! empty($result->error)) { |
|
213 | 213 | /* translators: error message */ |
214 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
214 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
215 | 215 | } else { |
216 | 216 | /* translators: transaction id */ |
217 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
218 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
217 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
218 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
219 | 219 | |
220 | 220 | // Store other data such as fees |
221 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id ); |
|
221 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id); |
|
222 | 222 | |
223 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
223 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
224 | 224 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
225 | 225 | // values are in the local currency of the Stripe account, not from WC. |
226 | - $fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0; |
|
227 | - $net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0; |
|
228 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee ); |
|
229 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net ); |
|
226 | + $fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0; |
|
227 | + $net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0; |
|
228 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee); |
|
229 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
232 | + if (is_callable(array($order, 'save'))) { |
|
233 | 233 | $order->save(); |
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
237 | 237 | // This hook fires when admin manually changes order status to processing or completed. |
238 | - do_action( 'woocommerce_stripe_process_manual_capture', $order, $result ); |
|
238 | + do_action('woocommerce_stripe_process_manual_capture', $order, $result); |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | } |
@@ -247,32 +247,32 @@ discard block |
||
247 | 247 | * @version 4.0.0 |
248 | 248 | * @param int $order_id |
249 | 249 | */ |
250 | - public function cancel_payment( $order_id ) { |
|
251 | - $order = wc_get_order( $order_id ); |
|
250 | + public function cancel_payment($order_id) { |
|
251 | + $order = wc_get_order($order_id); |
|
252 | 252 | |
253 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
254 | - $charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
253 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
254 | + $charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
255 | 255 | |
256 | - if ( $charge_id ) { |
|
257 | - $result = WC_Stripe_API::request( array( |
|
258 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ), |
|
259 | - ), 'charges/' . $charge_id . '/refund' ); |
|
256 | + if ($charge_id) { |
|
257 | + $result = WC_Stripe_API::request(array( |
|
258 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()), |
|
259 | + ), 'charges/' . $charge_id . '/refund'); |
|
260 | 260 | |
261 | - if ( ! empty( $result->error ) ) { |
|
262 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->error->message ); |
|
261 | + if ( ! empty($result->error)) { |
|
262 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->error->message); |
|
263 | 263 | } else { |
264 | 264 | /* translators: transaction id */ |
265 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
266 | - WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_stripe_charge_captured' ) : $order->delete_meta_data( '_stripe_charge_captured' ); |
|
267 | - WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_transaction_id' ) : $order->delete_meta_data( '_stripe_transaction_id' ); |
|
265 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
266 | + WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_stripe_charge_captured') : $order->delete_meta_data('_stripe_charge_captured'); |
|
267 | + WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_transaction_id') : $order->delete_meta_data('_stripe_transaction_id'); |
|
268 | 268 | |
269 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
269 | + if (is_callable(array($order, 'save'))) { |
|
270 | 270 | $order->save(); |
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | 274 | // This hook fires when admin manually changes order status to cancel. |
275 | - do_action( 'woocommerce_stripe_process_manual_cancel', $order, $result ); |
|
275 | + do_action('woocommerce_stripe_process_manual_cancel', $order, $result); |
|
276 | 276 | } |
277 | 277 | } |
278 | 278 | } |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | * @param string $field |
286 | 286 | * @return string $error_field |
287 | 287 | */ |
288 | - public function normalize_field( $field ) { |
|
289 | - $error_field = ucfirst( str_replace( '_', ' ', $field ) ); |
|
288 | + public function normalize_field($field) { |
|
289 | + $error_field = ucfirst(str_replace('_', ' ', $field)); |
|
290 | 290 | |
291 | 291 | $org_str = array(); |
292 | 292 | $replace_str = array(); |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $org_str[] = 'sofort'; |
304 | 304 | $replace_str[] = 'SOFORT'; |
305 | 305 | |
306 | - return str_replace( $org_str, $replace_str, $error_field ); |
|
306 | + return str_replace($org_str, $replace_str, $error_field); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -313,151 +313,151 @@ discard block |
||
313 | 313 | * @version 4.0.0 |
314 | 314 | */ |
315 | 315 | public function validate_checkout() { |
316 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) { |
|
317 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
316 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) { |
|
317 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | $errors = new WP_Error(); |
321 | - parse_str( $_POST['required_fields'], $required_fields ); |
|
322 | - parse_str( $_POST['all_fields'], $all_fields ); |
|
323 | - $source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : ''; |
|
321 | + parse_str($_POST['required_fields'], $required_fields); |
|
322 | + parse_str($_POST['all_fields'], $all_fields); |
|
323 | + $source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : ''; |
|
324 | 324 | $validate_shipping_fields = false; |
325 | 325 | $create_account = false; |
326 | 326 | |
327 | - array_walk_recursive( $required_fields, 'wc_clean' ); |
|
328 | - array_walk_recursive( $all_fields, 'wc_clean' ); |
|
327 | + array_walk_recursive($required_fields, 'wc_clean'); |
|
328 | + array_walk_recursive($all_fields, 'wc_clean'); |
|
329 | 329 | |
330 | 330 | // Remove unneeded required fields depending on source type. |
331 | - if ( 'stripe_sepa' !== $source_type ) { |
|
332 | - unset( $required_fields['stripe_sepa_owner'] ); |
|
333 | - unset( $required_fields['stripe_sepa_iban'] ); |
|
331 | + if ('stripe_sepa' !== $source_type) { |
|
332 | + unset($required_fields['stripe_sepa_owner']); |
|
333 | + unset($required_fields['stripe_sepa_iban']); |
|
334 | 334 | } |
335 | 335 | |
336 | - if ( 'stripe_sofort' !== $source_type ) { |
|
337 | - unset( $required_fields['stripe_sofort_bank_country'] ); |
|
336 | + if ('stripe_sofort' !== $source_type) { |
|
337 | + unset($required_fields['stripe_sofort_bank_country']); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
341 | 341 | * If ship to different address checkbox is checked then we need |
342 | 342 | * to validate shipping fields too. |
343 | 343 | */ |
344 | - if ( isset( $all_fields['ship_to_different_address'] ) ) { |
|
344 | + if (isset($all_fields['ship_to_different_address'])) { |
|
345 | 345 | $validate_shipping_fields = true; |
346 | 346 | } |
347 | 347 | |
348 | 348 | // Check if createaccount is checked. |
349 | - if ( isset( $all_fields['createaccount'] ) ) { |
|
349 | + if (isset($all_fields['createaccount'])) { |
|
350 | 350 | $create_account = true; |
351 | 351 | } |
352 | 352 | |
353 | 353 | // Check if required fields are empty. |
354 | - foreach ( $required_fields as $field => $field_value ) { |
|
354 | + foreach ($required_fields as $field => $field_value) { |
|
355 | 355 | // Check for shipping field. |
356 | - if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) { |
|
356 | + if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) { |
|
357 | 357 | continue; |
358 | 358 | } |
359 | 359 | |
360 | 360 | // Check create account name. |
361 | - if ( 'account_username' === $field && ! $create_account ) { |
|
361 | + if ('account_username' === $field && ! $create_account) { |
|
362 | 362 | continue; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Check create account password. |
366 | - if ( 'account_password' === $field && ! $create_account ) { |
|
366 | + if ('account_password' === $field && ! $create_account) { |
|
367 | 367 | continue; |
368 | 368 | } |
369 | 369 | |
370 | 370 | // Check if is SEPA. |
371 | - if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field ) { |
|
371 | + if ('stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field) { |
|
372 | 372 | continue; |
373 | 373 | } |
374 | 374 | |
375 | - if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field ) { |
|
375 | + if ('stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field) { |
|
376 | 376 | $continue; |
377 | 377 | } |
378 | 378 | |
379 | - if ( empty( $field_value ) || '-1' === $field_value ) { |
|
380 | - $error_field = $this->normalize_field( $field ); |
|
379 | + if (empty($field_value) || '-1' === $field_value) { |
|
380 | + $error_field = $this->normalize_field($field); |
|
381 | 381 | /* translators: error field name */ |
382 | - $errors->add( 'validation', sprintf( __( '%s cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) ); |
|
382 | + $errors->add('validation', sprintf(__('%s cannot be empty', 'woocommerce-gateway-stripe'), $error_field)); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | |
386 | 386 | // Check if email is valid format. |
387 | - if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) { |
|
388 | - $errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) ); |
|
387 | + if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) { |
|
388 | + $errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe')); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | // Check if phone number is valid format. |
392 | - if ( ! empty( $required_fields['billing_phone'] ) ) { |
|
393 | - $phone = wc_format_phone_number( $required_fields['billing_phone'] ); |
|
392 | + if ( ! empty($required_fields['billing_phone'])) { |
|
393 | + $phone = wc_format_phone_number($required_fields['billing_phone']); |
|
394 | 394 | |
395 | - if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) { |
|
395 | + if ('' !== $phone && ! WC_Validation::is_phone($phone)) { |
|
396 | 396 | /* translators: %s: phone number */ |
397 | - $errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) ); |
|
397 | + $errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe')); |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
401 | 401 | // Check if postal code is valid format. |
402 | - if ( ! empty( $required_fields['billing_postcode'] ) ) { |
|
403 | - $country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
404 | - $postcode = wc_format_postcode( $required_fields['billing_postcode'], $country ); |
|
402 | + if ( ! empty($required_fields['billing_postcode'])) { |
|
403 | + $country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
404 | + $postcode = wc_format_postcode($required_fields['billing_postcode'], $country); |
|
405 | 405 | |
406 | - if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
407 | - $errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
406 | + if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
407 | + $errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
408 | 408 | } |
409 | 409 | } |
410 | 410 | |
411 | - if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) { |
|
412 | - $errors->add( 'terms', __( 'You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe' ) ); |
|
411 | + if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) { |
|
412 | + $errors->add('terms', __('You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe')); |
|
413 | 413 | } |
414 | 414 | |
415 | - if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) { |
|
415 | + if (WC()->cart->needs_shipping() && $validate_shipping_fields) { |
|
416 | 416 | // Check if postal code is valid format. |
417 | - if ( ! empty( $required_fields['shipping_postcode'] ) ) { |
|
418 | - $country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
419 | - $postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country ); |
|
417 | + if ( ! empty($required_fields['shipping_postcode'])) { |
|
418 | + $country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
419 | + $postcode = wc_format_postcode($required_fields['shipping_postcode'], $country); |
|
420 | 420 | |
421 | - if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
422 | - $errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
421 | + if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
422 | + $errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
423 | 423 | } |
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - if ( WC()->cart->needs_shipping() ) { |
|
427 | + if (WC()->cart->needs_shipping()) { |
|
428 | 428 | $shipping_country = WC()->customer->get_shipping_country(); |
429 | 429 | |
430 | - if ( empty( $shipping_country ) ) { |
|
431 | - $errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) ); |
|
432 | - } elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) { |
|
430 | + if (empty($shipping_country)) { |
|
431 | + $errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe')); |
|
432 | + } elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { |
|
433 | 433 | /* translators: country name */ |
434 | - $errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) ); |
|
434 | + $errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country())); |
|
435 | 435 | } else { |
436 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
436 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
437 | 437 | |
438 | - foreach ( WC()->shipping->get_packages() as $i => $package ) { |
|
439 | - if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) { |
|
440 | - $errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) ); |
|
438 | + foreach (WC()->shipping->get_packages() as $i => $package) { |
|
439 | + if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) { |
|
440 | + $errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe')); |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | } |
444 | 444 | } |
445 | 445 | |
446 | - if ( WC()->cart->needs_payment() ) { |
|
446 | + if (WC()->cart->needs_payment()) { |
|
447 | 447 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
448 | 448 | |
449 | - if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) { |
|
450 | - $errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) ); |
|
449 | + if ( ! isset($available_gateways[$all_fields['payment_method']])) { |
|
450 | + $errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe')); |
|
451 | 451 | } else { |
452 | - $available_gateways[ $all_fields['payment_method'] ]->validate_fields(); |
|
452 | + $available_gateways[$all_fields['payment_method']]->validate_fields(); |
|
453 | 453 | } |
454 | 454 | } |
455 | 455 | |
456 | - if ( 0 === count( $errors->errors ) ) { |
|
457 | - wp_send_json( 'success' ); |
|
456 | + if (0 === count($errors->errors)) { |
|
457 | + wp_send_json('success'); |
|
458 | 458 | } else { |
459 | - foreach ( $errors->get_error_messages() as $message ) { |
|
460 | - wc_add_notice( $message, 'error' ); |
|
459 | + foreach ($errors->get_error_messages() as $message) { |
|
460 | + wc_add_notice($message, 'error'); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | $this->send_ajax_failure_response(); |
@@ -471,9 +471,9 @@ discard block |
||
471 | 471 | * @version 4.0.0 |
472 | 472 | */ |
473 | 473 | public function send_ajax_failure_response() { |
474 | - if ( is_ajax() ) { |
|
474 | + if (is_ajax()) { |
|
475 | 475 | // only print notices if not reloading the checkout, otherwise they're lost in the page reload. |
476 | - if ( ! isset( WC()->session->reload_checkout ) ) { |
|
476 | + if ( ! isset(WC()->session->reload_checkout)) { |
|
477 | 477 | ob_start(); |
478 | 478 | wc_print_notices(); |
479 | 479 | $messages = ob_get_clean(); |
@@ -481,14 +481,14 @@ discard block |
||
481 | 481 | |
482 | 482 | $response = array( |
483 | 483 | 'result' => 'failure', |
484 | - 'messages' => isset( $messages ) ? $messages : '', |
|
485 | - 'refresh' => isset( WC()->session->refresh_totals ), |
|
486 | - 'reload' => isset( WC()->session->reload_checkout ), |
|
484 | + 'messages' => isset($messages) ? $messages : '', |
|
485 | + 'refresh' => isset(WC()->session->refresh_totals), |
|
486 | + 'reload' => isset(WC()->session->reload_checkout), |
|
487 | 487 | ); |
488 | 488 | |
489 | - unset( WC()->session->refresh_totals, WC()->session->reload_checkout ); |
|
489 | + unset(WC()->session->refresh_totals, WC()->session->reload_checkout); |
|
490 | 490 | |
491 | - wp_send_json( $response ); |
|
491 | + wp_send_json($response); |
|
492 | 492 | } |
493 | 493 | } |
494 | 494 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -17,15 +17,15 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @return float|int |
19 | 19 | */ |
20 | - public static function get_stripe_amount( $total, $currency = '' ) { |
|
21 | - if ( ! $currency ) { |
|
20 | + public static function get_stripe_amount($total, $currency = '') { |
|
21 | + if ( ! $currency) { |
|
22 | 22 | $currency = get_woocommerce_currency(); |
23 | 23 | } |
24 | 24 | |
25 | - if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) { |
|
26 | - return absint( $total ); |
|
25 | + if (in_array(strtolower($currency), self::no_decimal_currencies())) { |
|
26 | + return absint($total); |
|
27 | 27 | } else { |
28 | - return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents. |
|
28 | + return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents. |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
@@ -37,20 +37,20 @@ discard block |
||
37 | 37 | * @return array |
38 | 38 | */ |
39 | 39 | public static function get_localized_messages() { |
40 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
41 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
42 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
43 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
44 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
45 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
46 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
47 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
48 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
49 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
50 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
51 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
52 | - 'invalid_request_error' => __( 'Could not find payment information. Please try with another payment method.', 'woocommerce-gateway-stripe' ), |
|
53 | - ) ); |
|
40 | + return apply_filters('wc_stripe_localized_messages', array( |
|
41 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
42 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
43 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
44 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
45 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
46 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
47 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
48 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
49 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
50 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
51 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
52 | + 'invalid_request_error' => __('Could not find payment information. Please try with another payment method.', 'woocommerce-gateway-stripe'), |
|
53 | + )); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -87,24 +87,24 @@ discard block |
||
87 | 87 | * @param string $type Type of number to format |
88 | 88 | * @return string |
89 | 89 | */ |
90 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
91 | - if ( ! is_object( $balance_transaction ) ) { |
|
90 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
91 | + if ( ! is_object($balance_transaction)) { |
|
92 | 92 | return; |
93 | 93 | } |
94 | 94 | |
95 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
96 | - if ( 'fee' === $type ) { |
|
95 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
96 | + if ('fee' === $type) { |
|
97 | 97 | return $balance_transaction->fee; |
98 | 98 | } |
99 | 99 | |
100 | 100 | return $balance_transaction->net; |
101 | 101 | } |
102 | 102 | |
103 | - if ( 'fee' === $type ) { |
|
104 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
103 | + if ('fee' === $type) { |
|
104 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
105 | 105 | } |
106 | 106 | |
107 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
107 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public static function get_minimum_amount() { |
114 | 114 | // Check order amount |
115 | - switch ( get_woocommerce_currency() ) { |
|
115 | + switch (get_woocommerce_currency()) { |
|
116 | 116 | case 'USD': |
117 | 117 | case 'CAD': |
118 | 118 | case 'EUR': |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | * @param string $method The payment method to get the settings from. |
158 | 158 | * @param string $setting The name of the setting to get. |
159 | 159 | */ |
160 | - public static function get_settings( $method = null, $setting = null ) { |
|
161 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
160 | + public static function get_settings($method = null, $setting = null) { |
|
161 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
162 | 162 | |
163 | - if ( null === $setting ) { |
|
163 | + if (null === $setting) { |
|
164 | 164 | return $all_settings; |
165 | 165 | } |
166 | 166 | |
167 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
167 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @return bool |
176 | 176 | */ |
177 | 177 | public static function is_pre_30() { |
178 | - return version_compare( WC_VERSION, '3.0.0', '<' ); |
|
178 | + return version_compare(WC_VERSION, '3.0.0', '<'); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return string |
189 | 189 | */ |
190 | 190 | public static function get_webhook_url() { |
191 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
191 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | * @version 4.0.0 |
199 | 199 | * @param string $source_id |
200 | 200 | */ |
201 | - public static function get_order_by_source_id( $source_id ) { |
|
201 | + public static function get_order_by_source_id($source_id) { |
|
202 | 202 | global $wpdb; |
203 | 203 | |
204 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id ) ); |
|
204 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id)); |
|
205 | 205 | |
206 | - if ( ! empty( $order_id ) ) { |
|
207 | - return wc_get_order( $order_id ); |
|
206 | + if ( ! empty($order_id)) { |
|
207 | + return wc_get_order($order_id); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | return false; |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | * @version 4.0.0 |
218 | 218 | * @param string $charge_id |
219 | 219 | */ |
220 | - public static function get_order_by_charge_id( $charge_id ) { |
|
220 | + public static function get_order_by_charge_id($charge_id) { |
|
221 | 221 | global $wpdb; |
222 | 222 | |
223 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id ) ); |
|
223 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id)); |
|
224 | 224 | |
225 | - if ( ! empty( $order_id ) ) { |
|
226 | - return wc_get_order( $order_id ); |
|
225 | + if ( ! empty($order_id)) { |
|
226 | + return wc_get_order($order_id); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | return false; |
@@ -239,13 +239,13 @@ discard block |
||
239 | 239 | * @param string $statement_descriptor |
240 | 240 | * @return string $statement_descriptor Sanitized statement descriptor |
241 | 241 | */ |
242 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
243 | - $disallowed_characters = array( '<', '>', '"', "'" ); |
|
242 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
243 | + $disallowed_characters = array('<', '>', '"', "'"); |
|
244 | 244 | |
245 | 245 | // Remove special characters. |
246 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
246 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
247 | 247 | |
248 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
248 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
249 | 249 | |
250 | 250 | return $statement_descriptor; |
251 | 251 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if ( ! defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * @param string $deprecated Deprecated since WooCommerce 3.0 |
36 | 36 | * @return string |
37 | 37 | */ |
38 | - public function get_display_name( $deprecated = '' ) { |
|
38 | + public function get_display_name($deprecated = '') { |
|
39 | 39 | $display = sprintf( |
40 | 40 | /* translators: last 4 digits of IBAN account */ |
41 | - __( 'SEPA IBAN ending in %s', 'woocommerce-gateway-stripe' ), |
|
41 | + __('SEPA IBAN ending in %s', 'woocommerce-gateway-stripe'), |
|
42 | 42 | $this->get_last4() |
43 | 43 | ); |
44 | 44 | |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | * @return boolean True if the passed data is valid |
67 | 67 | */ |
68 | 68 | public function validate() { |
69 | - if ( false === parent::validate() ) { |
|
69 | + if (false === parent::validate()) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | - if ( ! $this->get_last4( 'edit' ) ) { |
|
73 | + if ( ! $this->get_last4('edit')) { |
|
74 | 74 | return false; |
75 | 75 | } |
76 | 76 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * @param string $context |
86 | 86 | * @return string Last 4 digits |
87 | 87 | */ |
88 | - public function get_last4( $context = 'view' ) { |
|
89 | - return $this->get_prop( 'last4', $context ); |
|
88 | + public function get_last4($context = 'view') { |
|
89 | + return $this->get_prop('last4', $context); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @version 4.0.0 |
96 | 96 | * @param string $last4 |
97 | 97 | */ |
98 | - public function set_last4( $last4 ) { |
|
99 | - $this->set_prop( 'last4', $last4 ); |
|
98 | + public function set_last4($last4) { |
|
99 | + $this->set_prop('last4', $last4); |
|
100 | 100 | } |
101 | 101 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | public function __construct() { |
22 | 22 | self::$_this = $this; |
23 | 23 | |
24 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
25 | - add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'get_account_saved_payment_methods_list_item_sepa' ), 10, 2 ); |
|
26 | - add_filter( 'woocommerce_get_credit_card_type_label', array( $this, 'normalize_sepa_label' ) ); |
|
27 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
28 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
24 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
25 | + add_filter('woocommerce_payment_methods_list_item', array($this, 'get_account_saved_payment_methods_list_item_sepa'), 10, 2); |
|
26 | + add_filter('woocommerce_get_credit_card_type_label', array($this, 'normalize_sepa_label')); |
|
27 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
28 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | * @param string $label |
47 | 47 | * @return string $label |
48 | 48 | */ |
49 | - public function normalize_sepa_label( $label ) { |
|
50 | - if ( 'sepa iban' === strtolower( $label ) ) { |
|
49 | + public function normalize_sepa_label($label) { |
|
50 | + if ('sepa iban' === strtolower($label)) { |
|
51 | 51 | return 'SEPA IBAN'; |
52 | 52 | } |
53 | 53 | |
@@ -62,67 +62,67 @@ discard block |
||
62 | 62 | * @param array $tokens |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) { |
|
66 | - if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
65 | + public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) { |
|
66 | + if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) { |
|
67 | 67 | $stored_tokens = array(); |
68 | 68 | |
69 | - foreach ( $tokens as $token ) { |
|
69 | + foreach ($tokens as $token) { |
|
70 | 70 | $stored_tokens[] = $token->get_token(); |
71 | 71 | } |
72 | 72 | |
73 | - if ( 'stripe' === $gateway_id ) { |
|
74 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
73 | + if ('stripe' === $gateway_id) { |
|
74 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
75 | 75 | $stripe_sources = $stripe_customer->get_sources(); |
76 | 76 | |
77 | - foreach ( $stripe_sources as $source ) { |
|
78 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
79 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
77 | + foreach ($stripe_sources as $source) { |
|
78 | + if (isset($source->type) && 'card' === $source->type) { |
|
79 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
80 | 80 | $token = new WC_Payment_Token_CC(); |
81 | - $token->set_token( $source->id ); |
|
82 | - $token->set_gateway_id( 'stripe' ); |
|
83 | - |
|
84 | - if ( 'source' === $source->object && 'card' === $source->type ) { |
|
85 | - $token->set_card_type( strtolower( $source->card->brand ) ); |
|
86 | - $token->set_last4( $source->card->last4 ); |
|
87 | - $token->set_expiry_month( $source->card->exp_month ); |
|
88 | - $token->set_expiry_year( $source->card->exp_year ); |
|
81 | + $token->set_token($source->id); |
|
82 | + $token->set_gateway_id('stripe'); |
|
83 | + |
|
84 | + if ('source' === $source->object && 'card' === $source->type) { |
|
85 | + $token->set_card_type(strtolower($source->card->brand)); |
|
86 | + $token->set_last4($source->card->last4); |
|
87 | + $token->set_expiry_month($source->card->exp_month); |
|
88 | + $token->set_expiry_year($source->card->exp_year); |
|
89 | 89 | } |
90 | 90 | |
91 | - $token->set_user_id( $customer_id ); |
|
91 | + $token->set_user_id($customer_id); |
|
92 | 92 | $token->save(); |
93 | - $tokens[ $token->get_id() ] = $token; |
|
93 | + $tokens[$token->get_id()] = $token; |
|
94 | 94 | } |
95 | 95 | } else { |
96 | - if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) { |
|
96 | + if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) { |
|
97 | 97 | $token = new WC_Payment_Token_CC(); |
98 | - $token->set_token( $source->id ); |
|
99 | - $token->set_gateway_id( 'stripe' ); |
|
100 | - $token->set_card_type( strtolower( $source->brand ) ); |
|
101 | - $token->set_last4( $source->last4 ); |
|
102 | - $token->set_expiry_month( $source->exp_month ); |
|
103 | - $token->set_expiry_year( $source->exp_year ); |
|
104 | - $token->set_user_id( $customer_id ); |
|
98 | + $token->set_token($source->id); |
|
99 | + $token->set_gateway_id('stripe'); |
|
100 | + $token->set_card_type(strtolower($source->brand)); |
|
101 | + $token->set_last4($source->last4); |
|
102 | + $token->set_expiry_month($source->exp_month); |
|
103 | + $token->set_expiry_year($source->exp_year); |
|
104 | + $token->set_user_id($customer_id); |
|
105 | 105 | $token->save(); |
106 | - $tokens[ $token->get_id() ] = $token; |
|
106 | + $tokens[$token->get_id()] = $token; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - if ( 'stripe_sepa' === $gateway_id ) { |
|
113 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
112 | + if ('stripe_sepa' === $gateway_id) { |
|
113 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
114 | 114 | $stripe_sources = $stripe_customer->get_sources(); |
115 | 115 | |
116 | - foreach ( $stripe_sources as $source ) { |
|
117 | - if ( isset( $source->type ) && 'sepa_debit' === $source->type ) { |
|
118 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
116 | + foreach ($stripe_sources as $source) { |
|
117 | + if (isset($source->type) && 'sepa_debit' === $source->type) { |
|
118 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
119 | 119 | $token = new WC_Payment_Token_SEPA(); |
120 | - $token->set_token( $source->id ); |
|
121 | - $token->set_gateway_id( 'stripe_sepa' ); |
|
122 | - $token->set_last4( $source->sepa_debit->last4 ); |
|
123 | - $token->set_user_id( $customer_id ); |
|
120 | + $token->set_token($source->id); |
|
121 | + $token->set_gateway_id('stripe_sepa'); |
|
122 | + $token->set_last4($source->sepa_debit->last4); |
|
123 | + $token->set_user_id($customer_id); |
|
124 | 124 | $token->save(); |
125 | - $tokens[ $token->get_id() ] = $token; |
|
125 | + $tokens[$token->get_id()] = $token; |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @param WC_Payment_Token $payment_token The payment token associated with this method entry |
142 | 142 | * @return array Filtered item |
143 | 143 | */ |
144 | - public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) { |
|
145 | - if ( 'sepa' !== strtolower( $payment_token->get_type() ) ) { |
|
144 | + public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) { |
|
145 | + if ('sepa' !== strtolower($payment_token->get_type())) { |
|
146 | 146 | return $item; |
147 | 147 | } |
148 | 148 | |
149 | 149 | $item['method']['last4'] = $payment_token->get_last4(); |
150 | - $item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' ); |
|
150 | + $item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe'); |
|
151 | 151 | |
152 | 152 | return $item; |
153 | 153 | } |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | * @since 3.1.0 |
159 | 159 | * @version 4.0.0 |
160 | 160 | */ |
161 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
162 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
163 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
164 | - $stripe_customer->delete_source( $token->get_token() ); |
|
161 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
162 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
163 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
164 | + $stripe_customer->delete_source($token->get_token()); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | * @since 3.1.0 |
172 | 172 | * @version 4.0.0 |
173 | 173 | */ |
174 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
175 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
174 | + public function woocommerce_payment_token_set_default($token_id) { |
|
175 | + $token = WC_Payment_Tokens::get($token_id); |
|
176 | 176 | |
177 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
178 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
179 | - $stripe_customer->set_default_source( $token->get_token() ); |
|
177 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
178 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
179 | + $stripe_customer->set_default_source($token->get_token()); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function __construct() { |
121 | 121 | $this->id = 'stripe'; |
122 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
122 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
123 | 123 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
124 | - $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' ); |
|
124 | + $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'); |
|
125 | 125 | $this->has_fields = true; |
126 | 126 | $this->supports = array( |
127 | 127 | 'products', |
@@ -148,38 +148,38 @@ discard block |
||
148 | 148 | $this->init_settings(); |
149 | 149 | |
150 | 150 | // Get setting values. |
151 | - $this->title = $this->get_option( 'title' ); |
|
152 | - $this->description = $this->get_option( 'description' ); |
|
153 | - $this->enabled = $this->get_option( 'enabled' ); |
|
154 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
155 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
156 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
157 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
158 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
159 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
160 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
161 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
162 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
163 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
164 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
165 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
166 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
167 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
151 | + $this->title = $this->get_option('title'); |
|
152 | + $this->description = $this->get_option('description'); |
|
153 | + $this->enabled = $this->get_option('enabled'); |
|
154 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
155 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
156 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
157 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
158 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
159 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
160 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
161 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
162 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
163 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
164 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
165 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
166 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
167 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
168 | 168 | $this->apple_pay_verify_notice = ''; |
169 | 169 | |
170 | - if ( $this->stripe_checkout ) { |
|
171 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
170 | + if ($this->stripe_checkout) { |
|
171 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
172 | 172 | } |
173 | 173 | |
174 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
174 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
175 | 175 | |
176 | 176 | $this->init_apple_pay(); |
177 | 177 | |
178 | 178 | // Hooks. |
179 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
180 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
181 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
182 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
179 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
180 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
181 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
182 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @return array |
191 | 191 | */ |
192 | 192 | public function payment_icons() { |
193 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
193 | + return apply_filters('wc_stripe_payment_icons', array( |
|
194 | 194 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
195 | 195 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
196 | 196 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
208 | 208 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
209 | 209 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
210 | - ) ); |
|
210 | + )); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -226,17 +226,17 @@ discard block |
||
226 | 226 | $icons_str .= $icons['amex']; |
227 | 227 | $icons_str .= $icons['mastercard']; |
228 | 228 | |
229 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
229 | + if ('USD' === get_woocommerce_currency()) { |
|
230 | 230 | $icons_str .= $icons['discover']; |
231 | 231 | $icons_str .= $icons['jcb']; |
232 | 232 | $icons_str .= $icons['diners']; |
233 | 233 | } |
234 | 234 | |
235 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
235 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
236 | 236 | $icons_str .= $icons['bitcoin']; |
237 | 237 | } |
238 | 238 | |
239 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
239 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | public function init_apple_pay() { |
249 | 249 | if ( |
250 | 250 | is_admin() && |
251 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
252 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
253 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
251 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
252 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
253 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
254 | 254 | $this->payment_request |
255 | 255 | ) { |
256 | 256 | $this->process_apple_pay_verification(); |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | * @version 3.1.0 |
265 | 265 | * @param string $secret_key |
266 | 266 | */ |
267 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
268 | - if ( empty( $secret_key ) ) { |
|
269 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
267 | + private function register_apple_pay_domain($secret_key = '') { |
|
268 | + if (empty($secret_key)) { |
|
269 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -280,23 +280,23 @@ discard block |
||
280 | 280 | 'Authorization' => 'Bearer ' . $secret_key, |
281 | 281 | ); |
282 | 282 | |
283 | - $response = wp_remote_post( $endpoint, array( |
|
283 | + $response = wp_remote_post($endpoint, array( |
|
284 | 284 | 'headers' => $headers, |
285 | - 'body' => http_build_query( $data ), |
|
286 | - ) ); |
|
285 | + 'body' => http_build_query($data), |
|
286 | + )); |
|
287 | 287 | |
288 | - if ( is_wp_error( $response ) ) { |
|
288 | + if (is_wp_error($response)) { |
|
289 | 289 | /* translators: error message */ |
290 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
290 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
291 | 291 | } |
292 | 292 | |
293 | - if ( 200 !== $response['response']['code'] ) { |
|
294 | - $parsed_response = json_decode( $response['body'] ); |
|
293 | + if (200 !== $response['response']['code']) { |
|
294 | + $parsed_response = json_decode($response['body']); |
|
295 | 295 | |
296 | 296 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
297 | 297 | |
298 | 298 | /* translators: error message */ |
299 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
299 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
@@ -307,48 +307,48 @@ discard block |
||
307 | 307 | * @version 3.1.0 |
308 | 308 | */ |
309 | 309 | public function process_apple_pay_verification() { |
310 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
310 | + $gateway_settings = get_option('woocommerce_stripe_settings', array()); |
|
311 | 311 | |
312 | 312 | try { |
313 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
313 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
314 | 314 | $dir = '.well-known'; |
315 | 315 | $file = 'apple-developer-merchantid-domain-association'; |
316 | 316 | $fullpath = $path . '/' . $dir . '/' . $file; |
317 | 317 | |
318 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
318 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
319 | 319 | return; |
320 | 320 | } |
321 | 321 | |
322 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
323 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
324 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
322 | + if ( ! file_exists($path . '/' . $dir)) { |
|
323 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
324 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
325 | 325 | } |
326 | 326 | } |
327 | 327 | |
328 | - if ( ! file_exists( $fullpath ) ) { |
|
329 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
330 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
328 | + if ( ! file_exists($fullpath)) { |
|
329 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
330 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
334 | 334 | // At this point then the domain association folder and file should be available. |
335 | 335 | // Proceed to verify/and or verify again. |
336 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
336 | + $this->register_apple_pay_domain($this->secret_key); |
|
337 | 337 | |
338 | 338 | // No errors to this point, verification success! |
339 | 339 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
340 | 340 | $this->apple_pay_domain_set = true; |
341 | 341 | |
342 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
342 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
343 | 343 | |
344 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
344 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
345 | 345 | |
346 | - } catch ( Exception $e ) { |
|
346 | + } catch (Exception $e) { |
|
347 | 347 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
348 | 348 | |
349 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
349 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
350 | 350 | |
351 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
351 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
@@ -356,11 +356,11 @@ discard block |
||
356 | 356 | * Check if SSL is enabled and notify the user |
357 | 357 | */ |
358 | 358 | public function admin_notices() { |
359 | - if ( 'no' === $this->enabled ) { |
|
359 | + if ('no' === $this->enabled) { |
|
360 | 360 | return; |
361 | 361 | } |
362 | 362 | |
363 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
363 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
364 | 364 | $allowed_html = array( |
365 | 365 | 'a' => array( |
366 | 366 | 'href' => array(), |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | ), |
369 | 369 | ); |
370 | 370 | |
371 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
371 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -376,9 +376,9 @@ discard block |
||
376 | 376 | * when setting screen is displayed. So if domain verification is not set, |
377 | 377 | * something went wrong so lets notify user. |
378 | 378 | */ |
379 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
379 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
380 | 380 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
381 | - 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>'; |
|
381 | + 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>'; |
|
382 | 382 | } |
383 | 383 | } |
384 | 384 | |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | * Initialise Gateway Settings Form Fields |
387 | 387 | */ |
388 | 388 | public function init_form_fields() { |
389 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
389 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | /** |
@@ -394,59 +394,59 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public function payment_fields() { |
396 | 396 | $user = wp_get_current_user(); |
397 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
397 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
398 | 398 | $total = WC()->cart->total; |
399 | 399 | $user_email = ''; |
400 | 400 | |
401 | 401 | // If paying from order, we need to get total from order not cart. |
402 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
403 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
402 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
403 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
404 | 404 | $total = $order->get_total(); |
405 | 405 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
406 | 406 | } else { |
407 | - if ( $user->ID ) { |
|
408 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
407 | + if ($user->ID) { |
|
408 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
409 | 409 | $user_email = $user_email ? $user_email : $user->user_email; |
410 | 410 | } |
411 | 411 | } |
412 | 412 | |
413 | - if ( is_add_payment_method_page() ) { |
|
414 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
415 | - $total = ''; |
|
413 | + if (is_add_payment_method_page()) { |
|
414 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
415 | + $total = ''; |
|
416 | 416 | } else { |
417 | 417 | $pay_button_text = ''; |
418 | 418 | } |
419 | 419 | |
420 | 420 | echo '<div |
421 | 421 | id="stripe-payment-data" |
422 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
422 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
423 | 423 | data-description="" |
424 | - data-email="' . esc_attr( $user_email ) . '" |
|
425 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
426 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
427 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
428 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
429 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
430 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
431 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
432 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
433 | - |
|
434 | - if ( $this->description ) { |
|
435 | - if ( $this->testmode ) { |
|
424 | + data-email="' . esc_attr($user_email) . '" |
|
425 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
426 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
427 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
428 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
429 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
430 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
431 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
432 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
433 | + |
|
434 | + if ($this->description) { |
|
435 | + if ($this->testmode) { |
|
436 | 436 | /* translators: link to Stripe testing page */ |
437 | - $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' ); |
|
438 | - $this->description = trim( $this->description ); |
|
437 | + $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'); |
|
438 | + $this->description = trim($this->description); |
|
439 | 439 | } |
440 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
440 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
441 | 441 | } |
442 | 442 | |
443 | - if ( $display_tokenization ) { |
|
443 | + if ($display_tokenization) { |
|
444 | 444 | $this->tokenization_script(); |
445 | 445 | $this->saved_payment_methods(); |
446 | 446 | } |
447 | 447 | |
448 | - if ( ! $this->stripe_checkout ) { |
|
449 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
448 | + if ( ! $this->stripe_checkout) { |
|
449 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
450 | 450 | $this->elements_form(); |
451 | 451 | } else { |
452 | 452 | $this->form(); |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | } |
455 | 455 | } |
456 | 456 | |
457 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
457 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
458 | 458 | $this->save_payment_method_checkbox(); |
459 | 459 | } |
460 | 460 | |
@@ -469,13 +469,13 @@ discard block |
||
469 | 469 | */ |
470 | 470 | public function elements_form() { |
471 | 471 | ?> |
472 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
473 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
472 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
473 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
474 | 474 | <label for="card-element"> |
475 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
475 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
476 | 476 | </label> |
477 | 477 | |
478 | - <?php if ( $this->inline_cc_form ) { ?> |
|
478 | + <?php if ($this->inline_cc_form) { ?> |
|
479 | 479 | <div id="stripe-card-element" style="background:#f2f2f2;padding:0 1em;box-shadow:inset 0 1px 1px rgba(0,0,0,.125);margin:5px 0;padding:10px 5px;"> |
480 | 480 | <!-- a Stripe Element will be inserted here. --> |
481 | 481 | </div> |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | |
495 | 495 | <!-- Used to display form errors --> |
496 | 496 | <div class="stripe-source-errors" role="alert"></div> |
497 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
497 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
498 | 498 | <div class="clear"></div> |
499 | 499 | </fieldset> |
500 | 500 | <?php |
@@ -507,13 +507,13 @@ discard block |
||
507 | 507 | * @version 3.1.0 |
508 | 508 | */ |
509 | 509 | public function admin_scripts() { |
510 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
510 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
511 | 511 | return; |
512 | 512 | } |
513 | 513 | |
514 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
514 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
515 | 515 | |
516 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
516 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
@@ -525,29 +525,29 @@ discard block |
||
525 | 525 | * @version 4.0.0 |
526 | 526 | */ |
527 | 527 | public function payment_scripts() { |
528 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
528 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
529 | 529 | return; |
530 | 530 | } |
531 | 531 | |
532 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
532 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
533 | 533 | |
534 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
535 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
536 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
537 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
538 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
539 | - 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 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
535 | + wp_enqueue_style('stripe_paymentfonts'); |
|
536 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
537 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
538 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
539 | + 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); |
|
540 | 540 | |
541 | 541 | $stripe_params = array( |
542 | 542 | 'key' => $this->publishable_key, |
543 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
544 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
543 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
544 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
545 | 545 | ); |
546 | 546 | |
547 | 547 | // If we're on the pay page we need to pass stripe.js the address of the order. |
548 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
549 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
550 | - $order = wc_get_order( $order_id ); |
|
548 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
549 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
550 | + $order = wc_get_order($order_id); |
|
551 | 551 | |
552 | 552 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
553 | 553 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -559,36 +559,36 @@ discard block |
||
559 | 559 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
560 | 560 | } |
561 | 561 | |
562 | - $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' ); |
|
563 | - $stripe_params['no_bank_country_msg'] = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' ); |
|
564 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
565 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
566 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
562 | + $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'); |
|
563 | + $stripe_params['no_bank_country_msg'] = __('Please select a country for your bank.', 'woocommerce-gateway-stripe'); |
|
564 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
565 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
566 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
567 | 567 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
568 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
569 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
568 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
569 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
570 | 570 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
571 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
572 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
571 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
572 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
573 | 573 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
574 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
574 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
575 | 575 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
576 | - $stripe_params['is_change_payment_page'] = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no'; |
|
577 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
578 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
576 | + $stripe_params['is_change_payment_page'] = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no'; |
|
577 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
578 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
579 | 579 | |
580 | 580 | // merge localized messages to be use in JS |
581 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
581 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
582 | 582 | |
583 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
584 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
583 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
584 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
585 | 585 | |
586 | - if ( $this->stripe_checkout ) { |
|
587 | - wp_enqueue_script( 'stripe_checkout' ); |
|
586 | + if ($this->stripe_checkout) { |
|
587 | + wp_enqueue_script('stripe_checkout'); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | $this->tokenization_script(); |
591 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
591 | + wp_enqueue_script('woocommerce_stripe'); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -600,22 +600,22 @@ discard block |
||
600 | 600 | * @param object $source_object |
601 | 601 | * @return mixed |
602 | 602 | */ |
603 | - public function create_3ds_source( $order, $source_object ) { |
|
603 | + public function create_3ds_source($order, $source_object) { |
|
604 | 604 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
605 | 605 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
606 | - $return_url = $this->get_stripe_return_url( $order ); |
|
606 | + $return_url = $this->get_stripe_return_url($order); |
|
607 | 607 | |
608 | 608 | $post_data = array(); |
609 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
610 | - $post_data['currency'] = strtolower( $currency ); |
|
609 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
610 | + $post_data['currency'] = strtolower($currency); |
|
611 | 611 | $post_data['type'] = 'three_d_secure'; |
612 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
613 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
614 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
612 | + $post_data['owner'] = $this->get_owner_details($order); |
|
613 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
614 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
615 | 615 | |
616 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' ); |
|
616 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source'); |
|
617 | 617 | |
618 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
618 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -631,46 +631,46 @@ discard block |
||
631 | 631 | * |
632 | 632 | * @return array|void |
633 | 633 | */ |
634 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
634 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
635 | 635 | try { |
636 | - $order = wc_get_order( $order_id ); |
|
637 | - $source_object = ! empty( $_POST['stripe_source'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ) : false; |
|
636 | + $order = wc_get_order($order_id); |
|
637 | + $source_object = ! empty($_POST['stripe_source']) ? json_decode(wc_clean(stripslashes($_POST['stripe_source']))) : false; |
|
638 | 638 | |
639 | 639 | // This comes from the create account checkbox in the checkout page. |
640 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
640 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
641 | 641 | |
642 | - if ( $create_account ) { |
|
642 | + if ($create_account) { |
|
643 | 643 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
644 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
644 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
645 | 645 | $new_stripe_customer->create_customer(); |
646 | 646 | } |
647 | 647 | |
648 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
648 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
649 | 649 | |
650 | 650 | // Check if we don't allow prepaid credit cards. |
651 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
652 | - $stripe_checkout_object = ! empty( $_POST['stripe_checkout_object'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_checkout_object'] ) ) ) : false; |
|
651 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
652 | + $stripe_checkout_object = ! empty($_POST['stripe_checkout_object']) ? json_decode(wc_clean(stripslashes($_POST['stripe_checkout_object']))) : false; |
|
653 | 653 | |
654 | - if ( $stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding ) { |
|
655 | - $error_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' ); |
|
656 | - throw new Exception( $error_msg ); |
|
654 | + if ($stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding) { |
|
655 | + $error_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'); |
|
656 | + throw new Exception($error_msg); |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | |
660 | - if ( empty( $prepared_source->source ) ) { |
|
661 | - $error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
662 | - throw new Exception( $error_msg ); |
|
660 | + if (empty($prepared_source->source)) { |
|
661 | + $error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
662 | + throw new Exception($error_msg); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | // Store source to order meta. |
666 | - $this->save_source( $order, $prepared_source ); |
|
666 | + $this->save_source($order, $prepared_source); |
|
667 | 667 | |
668 | 668 | // Result from Stripe API request. |
669 | 669 | $response = null; |
670 | 670 | |
671 | - if ( $order->get_total() > 0 ) { |
|
671 | + if ($order->get_total() > 0) { |
|
672 | 672 | // This will throw exception if not valid. |
673 | - $this->validate_minimum_order_amount( $order ); |
|
673 | + $this->validate_minimum_order_amount($order); |
|
674 | 674 | |
675 | 675 | /** |
676 | 676 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -679,79 +679,79 @@ discard block |
||
679 | 679 | * Note that if we need to save source, the original source must be first |
680 | 680 | * attached to a customer in Stripe before it can be charged. |
681 | 681 | */ |
682 | - if ( $source_object && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) { |
|
682 | + if ($source_object && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) { |
|
683 | 683 | |
684 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
684 | + $response = $this->create_3ds_source($order, $source_object); |
|
685 | 685 | |
686 | - if ( ! empty( $response->error ) ) { |
|
686 | + if ( ! empty($response->error)) { |
|
687 | 687 | $message = $response->error->message; |
688 | 688 | |
689 | - $order->add_order_note( $message ); |
|
689 | + $order->add_order_note($message); |
|
690 | 690 | |
691 | - throw new Exception( $message ); |
|
691 | + throw new Exception($message); |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | // Update order meta with 3DS source. |
695 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
696 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
695 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
696 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
697 | 697 | } else { |
698 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
698 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
699 | 699 | $order->save(); |
700 | 700 | } |
701 | 701 | |
702 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
702 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
703 | 703 | |
704 | 704 | return array( |
705 | 705 | 'result' => 'success', |
706 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
706 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
707 | 707 | ); |
708 | 708 | } |
709 | 709 | |
710 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
710 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
711 | 711 | |
712 | 712 | // Make the request. |
713 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
713 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
714 | 714 | |
715 | - if ( ! empty( $response->error ) ) { |
|
715 | + if ( ! empty($response->error)) { |
|
716 | 716 | // If it is an API error such connection or server, let's retry. |
717 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
718 | - if ( $retry ) { |
|
719 | - sleep( 5 ); |
|
720 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
717 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
718 | + if ($retry) { |
|
719 | + sleep(5); |
|
720 | + return $this->process_payment($order_id, false, $force_save_source); |
|
721 | 721 | } else { |
722 | 722 | $message = 'API connection error and retries exhausted.'; |
723 | - $order->add_order_note( $message ); |
|
724 | - throw new Exception( $message ); |
|
723 | + $order->add_order_note($message); |
|
724 | + throw new Exception($message); |
|
725 | 725 | } |
726 | 726 | } |
727 | 727 | |
728 | 728 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
729 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
730 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
729 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
730 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
731 | 731 | |
732 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
733 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
732 | + return $this->process_payment($order_id, false, $force_save_source); |
|
733 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
734 | 734 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
735 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
735 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
736 | 736 | $wc_token->delete(); |
737 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
738 | - $order->add_order_note( $message ); |
|
739 | - throw new Exception( $message ); |
|
737 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
738 | + $order->add_order_note($message); |
|
739 | + throw new Exception($message); |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
743 | 743 | |
744 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
744 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
745 | 745 | |
746 | - $order->add_order_note( $message ); |
|
746 | + $order->add_order_note($message); |
|
747 | 747 | |
748 | - throw new Exception( $message ); |
|
748 | + throw new Exception($message); |
|
749 | 749 | } |
750 | 750 | |
751 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
751 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
752 | 752 | |
753 | 753 | // Process valid response. |
754 | - $this->process_response( $response, $order ); |
|
754 | + $this->process_response($response, $order); |
|
755 | 755 | } else { |
756 | 756 | $order->payment_complete(); |
757 | 757 | } |
@@ -762,17 +762,17 @@ discard block |
||
762 | 762 | // Return thank you page redirect. |
763 | 763 | return array( |
764 | 764 | 'result' => 'success', |
765 | - 'redirect' => $this->get_return_url( $order ), |
|
765 | + 'redirect' => $this->get_return_url($order), |
|
766 | 766 | ); |
767 | 767 | |
768 | - } catch ( Exception $e ) { |
|
769 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
770 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
768 | + } catch (Exception $e) { |
|
769 | + wc_add_notice($e->getMessage(), 'error'); |
|
770 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
771 | 771 | |
772 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
772 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
773 | 773 | |
774 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
775 | - $this->send_failed_order_email( $order_id ); |
|
774 | + if ($order->has_status(array('pending', 'failed'))) { |
|
775 | + $this->send_failed_order_email($order_id); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | return array( |