@@ -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 | |
@@ -56,35 +56,35 @@ discard block |
||
56 | 56 | * @version 4.0.0 |
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
60 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
61 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
62 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
63 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
64 | - |
|
65 | - if ( $this->testmode ) { |
|
66 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
59 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
60 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
61 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
62 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
63 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
64 | + |
|
65 | + if ($this->testmode) { |
|
66 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | // If both site title and statement descriptor is not set. Fallback. |
70 | - if ( empty( $this->total_label ) ) { |
|
70 | + if (empty($this->total_label)) { |
|
71 | 71 | $this->total_label = $_SERVER['SERVER_NAME']; |
72 | 72 | } |
73 | 73 | |
74 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
74 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
75 | 75 | |
76 | 76 | // Checks if Stripe Gateway is enabled. |
77 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
77 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Checks if Payment Request is enabled. |
82 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
82 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Don't load for change payment method page. |
87 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
87 | + if (isset($_GET['change_payment_method'])) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
@@ -98,42 +98,42 @@ discard block |
||
98 | 98 | * @version 4.0.0 |
99 | 99 | */ |
100 | 100 | protected function init() { |
101 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
102 | - add_action( 'wp', array( $this, 'set_session' ) ); |
|
101 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
102 | + add_action('wp', array($this, 'set_session')); |
|
103 | 103 | |
104 | 104 | /* |
105 | 105 | * In order to display the Payment Request button in the correct position, |
106 | 106 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
107 | 107 | * CSS is used to position the button. |
108 | 108 | */ |
109 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
110 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
111 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
109 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
110 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
111 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
112 | 112 | } else { |
113 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
114 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
113 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
114 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
115 | 115 | } |
116 | 116 | |
117 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
118 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
117 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
118 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
119 | 119 | |
120 | - if ( apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
121 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
122 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
120 | + if (apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
121 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
122 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
123 | 123 | } |
124 | 124 | |
125 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
126 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
127 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
128 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
129 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
130 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
131 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
132 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
125 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
126 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
127 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
128 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
129 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
130 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
131 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
132 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
133 | 133 | |
134 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
134 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
135 | 135 | |
136 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 ); |
|
136 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | * @since 4.0.0 |
144 | 144 | */ |
145 | 145 | public function set_session() { |
146 | - if ( ! is_user_logged_in() ) { |
|
146 | + if ( ! is_user_logged_in()) { |
|
147 | 147 | $wc_session = new WC_Session_Handler(); |
148 | 148 | |
149 | - if ( ! $wc_session->has_session() ) { |
|
150 | - $wc_session->set_customer_session_cookie( true ); |
|
149 | + if ( ! $wc_session->has_session()) { |
|
150 | + $wc_session->set_customer_session_cookie(true); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @return string |
161 | 161 | */ |
162 | 162 | public function get_button_type() { |
163 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
163 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @return string |
172 | 172 | */ |
173 | 173 | public function get_button_theme() { |
174 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
174 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return string |
183 | 183 | */ |
184 | 184 | public function get_button_height() { |
185 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
185 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -192,40 +192,40 @@ discard block |
||
192 | 192 | * @version 4.0.0 |
193 | 193 | */ |
194 | 194 | public function get_product_data() { |
195 | - if ( ! is_product() ) { |
|
195 | + if ( ! is_product()) { |
|
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | 199 | global $post; |
200 | 200 | |
201 | - $product = wc_get_product( $post->ID ); |
|
201 | + $product = wc_get_product($post->ID); |
|
202 | 202 | |
203 | 203 | $data = array(); |
204 | 204 | $items = array(); |
205 | 205 | |
206 | 206 | $items[] = array( |
207 | 207 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
208 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
208 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
209 | 209 | ); |
210 | 210 | |
211 | - if ( wc_tax_enabled() ) { |
|
211 | + if (wc_tax_enabled()) { |
|
212 | 212 | $items[] = array( |
213 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
213 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
214 | 214 | 'amount' => 0, |
215 | 215 | 'pending' => true, |
216 | 216 | ); |
217 | 217 | } |
218 | 218 | |
219 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
219 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
220 | 220 | $items[] = array( |
221 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
221 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
222 | 222 | 'amount' => 0, |
223 | 223 | 'pending' => true, |
224 | 224 | ); |
225 | 225 | |
226 | - $data['shippingOptions'] = array( |
|
226 | + $data['shippingOptions'] = array( |
|
227 | 227 | 'id' => 'pending', |
228 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
228 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
229 | 229 | 'detail' => '', |
230 | 230 | 'amount' => 0, |
231 | 231 | ); |
@@ -234,13 +234,13 @@ discard block |
||
234 | 234 | $data['displayItems'] = $items; |
235 | 235 | $data['total'] = array( |
236 | 236 | 'label' => $this->total_label, |
237 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
237 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
238 | 238 | 'pending' => true, |
239 | 239 | ); |
240 | 240 | |
241 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
242 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
243 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
241 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
242 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
243 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
244 | 244 | |
245 | 245 | return $data; |
246 | 246 | } |
@@ -249,25 +249,25 @@ discard block |
||
249 | 249 | * Filters the gateway title to reflect Payment Request type |
250 | 250 | * |
251 | 251 | */ |
252 | - public function filter_gateway_title( $title, $id ) { |
|
252 | + public function filter_gateway_title($title, $id) { |
|
253 | 253 | global $post; |
254 | 254 | |
255 | - if ( ! is_object( $post ) ) { |
|
255 | + if ( ! is_object($post)) { |
|
256 | 256 | return $title; |
257 | 257 | } |
258 | 258 | |
259 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
260 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
259 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
260 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
261 | 261 | } else { |
262 | - $order = wc_get_order( $post->ID ); |
|
263 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
262 | + $order = wc_get_order($post->ID); |
|
263 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
264 | 264 | } |
265 | 265 | |
266 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
266 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
267 | 267 | return $method_title; |
268 | 268 | } |
269 | 269 | |
270 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
270 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
271 | 271 | return $method_title; |
272 | 272 | } |
273 | 273 | |
@@ -283,27 +283,27 @@ discard block |
||
283 | 283 | * @param array $posted_data The posted data from checkout form. |
284 | 284 | * @param object $order |
285 | 285 | */ |
286 | - public function add_order_meta( $order_id, $posted_data, $order ) { |
|
287 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
286 | + public function add_order_meta($order_id, $posted_data, $order) { |
|
287 | + if (empty($_POST['payment_request_type'])) { |
|
288 | 288 | return; |
289 | 289 | } |
290 | 290 | |
291 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
291 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
292 | 292 | |
293 | - if ( 'apple_pay' === $payment_request_type ) { |
|
294 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
295 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
293 | + if ('apple_pay' === $payment_request_type) { |
|
294 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
295 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
296 | 296 | } else { |
297 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
297 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
298 | 298 | $order->save(); |
299 | 299 | } |
300 | 300 | } |
301 | 301 | |
302 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
303 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
304 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
302 | + if ('payment_request_api' === $payment_request_type) { |
|
303 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
304 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
305 | 305 | } else { |
306 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
306 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
307 | 307 | $order->save(); |
308 | 308 | } |
309 | 309 | } |
@@ -317,11 +317,11 @@ discard block |
||
317 | 317 | * @return array |
318 | 318 | */ |
319 | 319 | public function supported_product_types() { |
320 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
320 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
321 | 321 | 'simple', |
322 | 322 | 'variable', |
323 | 323 | 'variation', |
324 | - ) ); |
|
324 | + )); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -332,15 +332,15 @@ discard block |
||
332 | 332 | * @return bool |
333 | 333 | */ |
334 | 334 | public function allowed_items_in_cart() { |
335 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
336 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
335 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
336 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
337 | 337 | |
338 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
338 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
339 | 339 | return false; |
340 | 340 | } |
341 | 341 | |
342 | 342 | // Pre Orders compatbility where we don't support charge upon release. |
343 | - 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() ) ) { |
|
343 | + 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())) { |
|
344 | 344 | return false; |
345 | 345 | } |
346 | 346 | } |
@@ -355,71 +355,71 @@ discard block |
||
355 | 355 | * @version 4.0.0 |
356 | 356 | */ |
357 | 357 | public function scripts() { |
358 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
358 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
359 | 359 | return; |
360 | 360 | } |
361 | 361 | |
362 | - if ( is_product() ) { |
|
362 | + if (is_product()) { |
|
363 | 363 | global $post; |
364 | 364 | |
365 | - $product = wc_get_product( $post->ID ); |
|
365 | + $product = wc_get_product($post->ID); |
|
366 | 366 | |
367 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
367 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
371 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
372 | 372 | return; |
373 | 373 | } |
374 | 374 | } |
375 | 375 | |
376 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
376 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
377 | 377 | |
378 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
379 | - 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 ); |
|
378 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
379 | + 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); |
|
380 | 380 | |
381 | 381 | wp_localize_script( |
382 | 382 | 'wc_stripe_payment_request', |
383 | 383 | 'wc_stripe_payment_request_params', |
384 | 384 | array( |
385 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
385 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
386 | 386 | 'stripe' => array( |
387 | 387 | 'key' => $this->publishable_key, |
388 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
388 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
389 | 389 | ), |
390 | 390 | 'nonce' => array( |
391 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
392 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
393 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
394 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
395 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
396 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
397 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
398 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
391 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
392 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
393 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
394 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
395 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
396 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
397 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
398 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
399 | 399 | ), |
400 | 400 | 'i18n' => array( |
401 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
401 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
402 | 402 | /* translators: Do not translate the [option] placeholder */ |
403 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
403 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
404 | 404 | ), |
405 | 405 | 'checkout' => array( |
406 | 406 | 'url' => wc_get_checkout_url(), |
407 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
408 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
407 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
408 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
409 | 409 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
410 | 410 | ), |
411 | 411 | 'button' => array( |
412 | 412 | 'type' => $this->get_button_type(), |
413 | 413 | 'theme' => $this->get_button_theme(), |
414 | 414 | 'height' => $this->get_button_height(), |
415 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
415 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
416 | 416 | ), |
417 | 417 | 'is_product_page' => is_product(), |
418 | 418 | 'product' => $this->get_product_data(), |
419 | 419 | ) |
420 | 420 | ); |
421 | 421 | |
422 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
422 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -431,35 +431,35 @@ discard block |
||
431 | 431 | public function display_payment_request_button_html() { |
432 | 432 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
433 | 433 | |
434 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
434 | + if ( ! isset($gateways['stripe'])) { |
|
435 | 435 | return; |
436 | 436 | } |
437 | 437 | |
438 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
438 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
439 | 439 | return; |
440 | 440 | } |
441 | 441 | |
442 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
442 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
443 | 443 | return; |
444 | 444 | } |
445 | 445 | |
446 | - if ( is_product() ) { |
|
446 | + if (is_product()) { |
|
447 | 447 | global $post; |
448 | 448 | |
449 | - $product = wc_get_product( $post->ID ); |
|
449 | + $product = wc_get_product($post->ID); |
|
450 | 450 | |
451 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
451 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
452 | 452 | return; |
453 | 453 | } |
454 | 454 | |
455 | 455 | // Pre Orders charge upon release not supported. |
456 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
457 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
456 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
457 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
458 | 458 | return; |
459 | 459 | } |
460 | 460 | } else { |
461 | - if ( ! $this->allowed_items_in_cart() ) { |
|
462 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
461 | + if ( ! $this->allowed_items_in_cart()) { |
|
462 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
463 | 463 | return; |
464 | 464 | } |
465 | 465 | } |
@@ -481,40 +481,40 @@ discard block |
||
481 | 481 | public function display_payment_request_button_separator_html() { |
482 | 482 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
483 | 483 | |
484 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
484 | + if ( ! isset($gateways['stripe'])) { |
|
485 | 485 | return; |
486 | 486 | } |
487 | 487 | |
488 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
488 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
489 | 489 | return; |
490 | 490 | } |
491 | 491 | |
492 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
492 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
493 | 493 | return; |
494 | 494 | } |
495 | 495 | |
496 | - if ( is_product() ) { |
|
496 | + if (is_product()) { |
|
497 | 497 | global $post; |
498 | 498 | |
499 | - $product = wc_get_product( $post->ID ); |
|
499 | + $product = wc_get_product($post->ID); |
|
500 | 500 | |
501 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
501 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
502 | 502 | return; |
503 | 503 | } |
504 | 504 | |
505 | 505 | // Pre Orders charge upon release not supported. |
506 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
507 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
506 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
507 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
508 | 508 | return; |
509 | 509 | } |
510 | 510 | } else { |
511 | - if ( ! $this->allowed_items_in_cart() ) { |
|
512 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
511 | + if ( ! $this->allowed_items_in_cart()) { |
|
512 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | } |
516 | 516 | ?> |
517 | - <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> |
|
517 | + <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> |
|
518 | 518 | <?php |
519 | 519 | } |
520 | 520 | |
@@ -525,11 +525,11 @@ discard block |
||
525 | 525 | * @version 4.0.0 |
526 | 526 | */ |
527 | 527 | public function ajax_log_errors() { |
528 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
528 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
529 | 529 | |
530 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
530 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
531 | 531 | |
532 | - WC_Stripe_Logger::log( $errors ); |
|
532 | + WC_Stripe_Logger::log($errors); |
|
533 | 533 | |
534 | 534 | exit; |
535 | 535 | } |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | * @version 4.0.0 |
542 | 542 | */ |
543 | 543 | public function ajax_clear_cart() { |
544 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
544 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
545 | 545 | |
546 | 546 | WC()->cart->empty_cart(); |
547 | 547 | exit; |
@@ -551,10 +551,10 @@ discard block |
||
551 | 551 | * Get cart details. |
552 | 552 | */ |
553 | 553 | public function ajax_get_cart_details() { |
554 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
554 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
555 | 555 | |
556 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
557 | - define( 'WOOCOMMERCE_CART', true ); |
|
556 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
557 | + define('WOOCOMMERCE_CART', true); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | WC()->cart->calculate_totals(); |
@@ -565,14 +565,14 @@ discard block |
||
565 | 565 | $data = array( |
566 | 566 | 'shipping_required' => WC()->cart->needs_shipping(), |
567 | 567 | 'order_data' => array( |
568 | - 'currency' => strtolower( $currency ), |
|
569 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
568 | + 'currency' => strtolower($currency), |
|
569 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
570 | 570 | ), |
571 | 571 | ); |
572 | 572 | |
573 | 573 | $data['order_data'] += $this->build_display_items(); |
574 | 574 | |
575 | - wp_send_json( $data ); |
|
575 | + wp_send_json($data); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | /** |
@@ -583,47 +583,47 @@ discard block |
||
583 | 583 | * @see WC_Shipping::get_packages(). |
584 | 584 | */ |
585 | 585 | public function ajax_get_shipping_options() { |
586 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
586 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
587 | 587 | |
588 | 588 | try { |
589 | 589 | // Set the shipping package. |
590 | - $posted = filter_input_array( INPUT_POST, array( |
|
590 | + $posted = filter_input_array(INPUT_POST, array( |
|
591 | 591 | 'country' => FILTER_SANITIZE_STRING, |
592 | 592 | 'state' => FILTER_SANITIZE_STRING, |
593 | 593 | 'postcode' => FILTER_SANITIZE_STRING, |
594 | 594 | 'city' => FILTER_SANITIZE_STRING, |
595 | 595 | 'address' => FILTER_SANITIZE_STRING, |
596 | 596 | 'address_2' => FILTER_SANITIZE_STRING, |
597 | - ) ); |
|
597 | + )); |
|
598 | 598 | |
599 | - $this->calculate_shipping( $posted ); |
|
599 | + $this->calculate_shipping($posted); |
|
600 | 600 | |
601 | 601 | // Set the shipping options. |
602 | 602 | $data = array(); |
603 | 603 | $packages = WC()->shipping->get_packages(); |
604 | 604 | |
605 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
606 | - foreach ( $packages as $package_key => $package ) { |
|
607 | - if ( empty( $package['rates'] ) ) { |
|
608 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
605 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
606 | + foreach ($packages as $package_key => $package) { |
|
607 | + if (empty($package['rates'])) { |
|
608 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
609 | 609 | } |
610 | 610 | |
611 | - foreach ( $package['rates'] as $key => $rate ) { |
|
611 | + foreach ($package['rates'] as $key => $rate) { |
|
612 | 612 | $data['shipping_options'][] = array( |
613 | 613 | 'id' => $rate->id, |
614 | 614 | 'label' => $rate->label, |
615 | 615 | 'detail' => '', |
616 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
616 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
617 | 617 | ); |
618 | 618 | } |
619 | 619 | } |
620 | 620 | } else { |
621 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
621 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
622 | 622 | } |
623 | 623 | |
624 | - if ( isset( $data[0] ) ) { |
|
624 | + if (isset($data[0])) { |
|
625 | 625 | // Auto select the first shipping method. |
626 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
626 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | WC()->cart->calculate_totals(); |
@@ -631,12 +631,12 @@ discard block |
||
631 | 631 | $data += $this->build_display_items(); |
632 | 632 | $data['result'] = 'success'; |
633 | 633 | |
634 | - wp_send_json( $data ); |
|
635 | - } catch ( Exception $e ) { |
|
634 | + wp_send_json($data); |
|
635 | + } catch (Exception $e) { |
|
636 | 636 | $data += $this->build_display_items(); |
637 | 637 | $data['result'] = 'invalid_shipping_address'; |
638 | 638 | |
639 | - wp_send_json( $data ); |
|
639 | + wp_send_json($data); |
|
640 | 640 | } |
641 | 641 | } |
642 | 642 | |
@@ -644,22 +644,22 @@ discard block |
||
644 | 644 | * Update shipping method. |
645 | 645 | */ |
646 | 646 | public function ajax_update_shipping_method() { |
647 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
647 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
648 | 648 | |
649 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
650 | - define( 'WOOCOMMERCE_CART', true ); |
|
649 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
650 | + define('WOOCOMMERCE_CART', true); |
|
651 | 651 | } |
652 | 652 | |
653 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
654 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
653 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
654 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
655 | 655 | |
656 | - if ( is_array( $shipping_method ) ) { |
|
657 | - foreach ( $shipping_method as $i => $value ) { |
|
658 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
656 | + if (is_array($shipping_method)) { |
|
657 | + foreach ($shipping_method as $i => $value) { |
|
658 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
659 | 659 | } |
660 | 660 | } |
661 | 661 | |
662 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
662 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
663 | 663 | |
664 | 664 | WC()->cart->calculate_totals(); |
665 | 665 | |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | $data += $this->build_display_items(); |
668 | 668 | $data['result'] = 'success'; |
669 | 669 | |
670 | - wp_send_json( $data ); |
|
670 | + wp_send_json($data); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
@@ -678,31 +678,31 @@ discard block |
||
678 | 678 | * @return array $data |
679 | 679 | */ |
680 | 680 | public function ajax_get_selected_product_data() { |
681 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
681 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
682 | 682 | |
683 | - $product_id = absint( $_POST['product_id'] ); |
|
684 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
683 | + $product_id = absint($_POST['product_id']); |
|
684 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
685 | 685 | |
686 | - $product = wc_get_product( $product_id ); |
|
686 | + $product = wc_get_product($product_id); |
|
687 | 687 | |
688 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
689 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
688 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
689 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
690 | 690 | |
691 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
692 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
691 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
692 | + $variation_id = $product->get_matching_variation($attributes); |
|
693 | 693 | } else { |
694 | - $data_store = WC_Data_Store::load( 'product' ); |
|
695 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
694 | + $data_store = WC_Data_Store::load('product'); |
|
695 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
696 | 696 | } |
697 | 697 | |
698 | - if ( ! empty( $variation_id ) ) { |
|
699 | - $product = wc_get_product( $variation_id ); |
|
698 | + if ( ! empty($variation_id)) { |
|
699 | + $product = wc_get_product($variation_id); |
|
700 | 700 | } |
701 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
702 | - $product = wc_get_product( $product_id ); |
|
701 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
702 | + $product = wc_get_product($product_id); |
|
703 | 703 | } |
704 | 704 | |
705 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
705 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
706 | 706 | |
707 | 707 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
708 | 708 | |
@@ -710,28 +710,28 @@ discard block |
||
710 | 710 | $items = array(); |
711 | 711 | |
712 | 712 | $items[] = array( |
713 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
714 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
713 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
714 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
715 | 715 | ); |
716 | 716 | |
717 | - if ( wc_tax_enabled() ) { |
|
717 | + if (wc_tax_enabled()) { |
|
718 | 718 | $items[] = array( |
719 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
719 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
720 | 720 | 'amount' => 0, |
721 | 721 | 'pending' => true, |
722 | 722 | ); |
723 | 723 | } |
724 | 724 | |
725 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
725 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
726 | 726 | $items[] = array( |
727 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
727 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
728 | 728 | 'amount' => 0, |
729 | 729 | 'pending' => true, |
730 | 730 | ); |
731 | 731 | |
732 | - $data['shippingOptions'] = array( |
|
732 | + $data['shippingOptions'] = array( |
|
733 | 733 | 'id' => 'pending', |
734 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
734 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
735 | 735 | 'detail' => '', |
736 | 736 | 'amount' => 0, |
737 | 737 | ); |
@@ -740,15 +740,15 @@ discard block |
||
740 | 740 | $data['displayItems'] = $items; |
741 | 741 | $data['total'] = array( |
742 | 742 | 'label' => $this->total_label, |
743 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
743 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
744 | 744 | 'pending' => true, |
745 | 745 | ); |
746 | 746 | |
747 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
748 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
749 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
747 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
748 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
749 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
750 | 750 | |
751 | - wp_send_json( $data ); |
|
751 | + wp_send_json($data); |
|
752 | 752 | } |
753 | 753 | |
754 | 754 | /** |
@@ -759,37 +759,37 @@ discard block |
||
759 | 759 | * @return array $data |
760 | 760 | */ |
761 | 761 | public function ajax_add_to_cart() { |
762 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
762 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
763 | 763 | |
764 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
765 | - define( 'WOOCOMMERCE_CART', true ); |
|
764 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
765 | + define('WOOCOMMERCE_CART', true); |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | WC()->shipping->reset_shipping(); |
769 | 769 | |
770 | - $product_id = absint( $_POST['product_id'] ); |
|
771 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
770 | + $product_id = absint($_POST['product_id']); |
|
771 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
772 | 772 | |
773 | - $product = wc_get_product( $product_id ); |
|
773 | + $product = wc_get_product($product_id); |
|
774 | 774 | |
775 | 775 | // First empty the cart to prevent wrong calculation. |
776 | 776 | WC()->cart->empty_cart(); |
777 | 777 | |
778 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
779 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
778 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
779 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
780 | 780 | |
781 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
782 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
781 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
782 | + $variation_id = $product->get_matching_variation($attributes); |
|
783 | 783 | } else { |
784 | - $data_store = WC_Data_Store::load( 'product' ); |
|
785 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
784 | + $data_store = WC_Data_Store::load('product'); |
|
785 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
786 | 786 | } |
787 | 787 | |
788 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
788 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
789 | 789 | } |
790 | 790 | |
791 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
792 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
791 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
792 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | WC()->cart->calculate_totals(); |
@@ -798,7 +798,7 @@ discard block |
||
798 | 798 | $data += $this->build_display_items(); |
799 | 799 | $data['result'] = 'success'; |
800 | 800 | |
801 | - wp_send_json( $data ); |
|
801 | + wp_send_json($data); |
|
802 | 802 | } |
803 | 803 | |
804 | 804 | /** |
@@ -811,31 +811,31 @@ discard block |
||
811 | 811 | * @version 4.0.0 |
812 | 812 | */ |
813 | 813 | public function normalize_state() { |
814 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
815 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
816 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
817 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
814 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
815 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
816 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
817 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
818 | 818 | |
819 | - if ( $billing_state && $billing_country ) { |
|
820 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
819 | + if ($billing_state && $billing_country) { |
|
820 | + $valid_states = WC()->countries->get_states($billing_country); |
|
821 | 821 | |
822 | 822 | // Valid states found for country. |
823 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
824 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
825 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
823 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
824 | + foreach ($valid_states as $state_abbr => $state) { |
|
825 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
826 | 826 | $_POST['billing_state'] = $state_abbr; |
827 | 827 | } |
828 | 828 | } |
829 | 829 | } |
830 | 830 | } |
831 | 831 | |
832 | - if ( $shipping_state && $shipping_country ) { |
|
833 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
832 | + if ($shipping_state && $shipping_country) { |
|
833 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
834 | 834 | |
835 | 835 | // Valid states found for country. |
836 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
837 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
838 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
836 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
837 | + foreach ($valid_states as $state_abbr => $state) { |
|
838 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
839 | 839 | $_POST['shipping_state'] = $state_abbr; |
840 | 840 | } |
841 | 841 | } |
@@ -850,19 +850,19 @@ discard block |
||
850 | 850 | * @version 4.0.0 |
851 | 851 | */ |
852 | 852 | public function ajax_create_order() { |
853 | - if ( WC()->cart->is_empty() ) { |
|
854 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
853 | + if (WC()->cart->is_empty()) { |
|
854 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
855 | 855 | } |
856 | 856 | |
857 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
858 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
857 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
858 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | $this->normalize_state(); |
862 | 862 | |
863 | 863 | WC()->checkout()->process_checkout(); |
864 | 864 | |
865 | - die( 0 ); |
|
865 | + die(0); |
|
866 | 866 | } |
867 | 867 | |
868 | 868 | /** |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | * @version 4.0.0 |
873 | 873 | * @param array $address |
874 | 874 | */ |
875 | - protected function calculate_shipping( $address = array() ) { |
|
875 | + protected function calculate_shipping($address = array()) { |
|
876 | 876 | global $states; |
877 | 877 | |
878 | 878 | $country = $address['country']; |
@@ -889,28 +889,28 @@ discard block |
||
889 | 889 | * In some versions of Chrome, state can be a full name. So we need |
890 | 890 | * to convert that to abbreviation as WC is expecting that. |
891 | 891 | */ |
892 | - if ( 2 < strlen( $state ) ) { |
|
893 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
892 | + if (2 < strlen($state)) { |
|
893 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | WC()->shipping->reset_shipping(); |
897 | 897 | |
898 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
899 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
898 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
899 | + $postcode = wc_format_postcode($postcode, $country); |
|
900 | 900 | } |
901 | 901 | |
902 | - if ( $country ) { |
|
903 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
904 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
902 | + if ($country) { |
|
903 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
904 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
905 | 905 | } else { |
906 | 906 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
907 | 907 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
908 | 908 | } |
909 | 909 | |
910 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
911 | - WC()->customer->calculated_shipping( true ); |
|
910 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
911 | + WC()->customer->calculated_shipping(true); |
|
912 | 912 | } else { |
913 | - WC()->customer->set_calculated_shipping( true ); |
|
913 | + WC()->customer->set_calculated_shipping(true); |
|
914 | 914 | WC()->customer->save(); |
915 | 915 | } |
916 | 916 | |
@@ -927,17 +927,17 @@ discard block |
||
927 | 927 | $packages[0]['destination']['address'] = $address_1; |
928 | 928 | $packages[0]['destination']['address_2'] = $address_2; |
929 | 929 | |
930 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
931 | - if ( $item['data']->needs_shipping() ) { |
|
932 | - if ( isset( $item['line_total'] ) ) { |
|
930 | + foreach (WC()->cart->get_cart() as $item) { |
|
931 | + if ($item['data']->needs_shipping()) { |
|
932 | + if (isset($item['line_total'])) { |
|
933 | 933 | $packages[0]['contents_cost'] += $item['line_total']; |
934 | 934 | } |
935 | 935 | } |
936 | 936 | } |
937 | 937 | |
938 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
938 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
939 | 939 | |
940 | - WC()->shipping->calculate_shipping( $packages ); |
|
940 | + WC()->shipping->calculate_shipping($packages); |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | /** |
@@ -946,19 +946,19 @@ discard block |
||
946 | 946 | * @since 3.1.0 |
947 | 947 | * @version 4.0.0 |
948 | 948 | */ |
949 | - protected function build_shipping_methods( $shipping_methods ) { |
|
950 | - if ( empty( $shipping_methods ) ) { |
|
949 | + protected function build_shipping_methods($shipping_methods) { |
|
950 | + if (empty($shipping_methods)) { |
|
951 | 951 | return array(); |
952 | 952 | } |
953 | 953 | |
954 | 954 | $shipping = array(); |
955 | 955 | |
956 | - foreach ( $shipping_methods as $method ) { |
|
956 | + foreach ($shipping_methods as $method) { |
|
957 | 957 | $shipping[] = array( |
958 | 958 | 'id' => $method['id'], |
959 | 959 | 'label' => $method['label'], |
960 | 960 | 'detail' => '', |
961 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
961 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
962 | 962 | ); |
963 | 963 | } |
964 | 964 | |
@@ -972,69 +972,69 @@ discard block |
||
972 | 972 | * @version 4.0.0 |
973 | 973 | */ |
974 | 974 | protected function build_display_items() { |
975 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
976 | - define( 'WOOCOMMERCE_CART', true ); |
|
975 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
976 | + define('WOOCOMMERCE_CART', true); |
|
977 | 977 | } |
978 | 978 | |
979 | 979 | $items = array(); |
980 | 980 | $subtotal = 0; |
981 | 981 | |
982 | 982 | // Default show only subtotal instead of itemization. |
983 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
984 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
983 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
984 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
985 | 985 | $amount = $cart_item['line_subtotal']; |
986 | - $subtotal += $cart_item['line_subtotal']; |
|
986 | + $subtotal += $cart_item['line_subtotal']; |
|
987 | 987 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
988 | 988 | |
989 | 989 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
990 | 990 | |
991 | 991 | $item = array( |
992 | 992 | 'label' => $product_name . $quantity_label, |
993 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
993 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
994 | 994 | ); |
995 | 995 | |
996 | 996 | $items[] = $item; |
997 | 997 | } |
998 | 998 | } |
999 | 999 | |
1000 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1001 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1002 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1003 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1004 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1000 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1001 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1002 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1003 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1004 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1005 | 1005 | |
1006 | - if ( wc_tax_enabled() ) { |
|
1006 | + if (wc_tax_enabled()) { |
|
1007 | 1007 | $items[] = array( |
1008 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1009 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1008 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1009 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1010 | 1010 | ); |
1011 | 1011 | } |
1012 | 1012 | |
1013 | - if ( WC()->cart->needs_shipping() ) { |
|
1013 | + if (WC()->cart->needs_shipping()) { |
|
1014 | 1014 | $items[] = array( |
1015 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1016 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1015 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1016 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1017 | 1017 | ); |
1018 | 1018 | } |
1019 | 1019 | |
1020 | - if ( WC()->cart->has_discount() ) { |
|
1020 | + if (WC()->cart->has_discount()) { |
|
1021 | 1021 | $items[] = array( |
1022 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1023 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1022 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1023 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1024 | 1024 | ); |
1025 | 1025 | } |
1026 | 1026 | |
1027 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1027 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1028 | 1028 | $cart_fees = WC()->cart->fees; |
1029 | 1029 | } else { |
1030 | 1030 | $cart_fees = WC()->cart->get_fees(); |
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | // Include fees and taxes as display items. |
1034 | - foreach ( $cart_fees as $key => $fee ) { |
|
1034 | + foreach ($cart_fees as $key => $fee) { |
|
1035 | 1035 | $items[] = array( |
1036 | 1036 | 'label' => $fee->name, |
1037 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1037 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1038 | 1038 | ); |
1039 | 1039 | } |
1040 | 1040 | |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | 'displayItems' => $items, |
1043 | 1043 | 'total' => array( |
1044 | 1044 | 'label' => $this->total_label, |
1045 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1045 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1046 | 1046 | 'pending' => false, |
1047 | 1047 | ), |
1048 | 1048 | ); |