@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @since 4.0.5 |
| 22 | 22 | * @param array $error |
| 23 | 23 | */ |
| 24 | - public function is_retryable_error( $error ) { |
|
| 24 | + public function is_retryable_error($error) { |
|
| 25 | 25 | return ( |
| 26 | 26 | 'invalid_request_error' === $error->type || |
| 27 | 27 | 'idempotency_error' === $error->type || |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | * Check if this gateway is enabled |
| 36 | 36 | */ |
| 37 | 37 | public function is_available() { |
| 38 | - if ( 'yes' === $this->enabled ) { |
|
| 39 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
| 38 | + if ('yes' === $this->enabled) { |
|
| 39 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
| 42 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
| 43 | 43 | return false; |
| 44 | 44 | } |
| 45 | 45 | return true; |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | * @since 4.0.0 |
| 55 | 55 | * @version 4.0.0 |
| 56 | 56 | */ |
| 57 | - public function add_admin_notice( $slug, $class, $message ) { |
|
| 58 | - $this->notices[ $slug ] = array( |
|
| 57 | + public function add_admin_notice($slug, $class, $message) { |
|
| 58 | + $this->notices[$slug] = array( |
|
| 59 | 59 | 'class' => $class, |
| 60 | 60 | 'message' => $message, |
| 61 | 61 | ); |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | * @version 4.0.0 |
| 69 | 69 | */ |
| 70 | 70 | public function remove_admin_notice() { |
| 71 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
| 72 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 71 | + if (did_action('woocommerce_update_options')) { |
|
| 72 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | 83 | public function payment_icons() { |
| 84 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 84 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 85 | 85 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
| 86 | 86 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
| 87 | 87 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
| 99 | 99 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
| 100 | 100 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
| 101 | - ) ); |
|
| 101 | + )); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -109,10 +109,10 @@ discard block |
||
| 109 | 109 | * @version 4.0.0 |
| 110 | 110 | * @param object $order |
| 111 | 111 | */ |
| 112 | - public function validate_minimum_order_amount( $order ) { |
|
| 113 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 112 | + public function validate_minimum_order_amount($order) { |
|
| 113 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 114 | 114 | /* translators: 1) dollar amount */ |
| 115 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 115 | + throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -122,14 +122,14 @@ discard block |
||
| 122 | 122 | * @since 4.0.0 |
| 123 | 123 | * @version 4.0.0 |
| 124 | 124 | */ |
| 125 | - public function get_transaction_url( $order ) { |
|
| 126 | - if ( $this->testmode ) { |
|
| 125 | + public function get_transaction_url($order) { |
|
| 126 | + if ($this->testmode) { |
|
| 127 | 127 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
| 128 | 128 | } else { |
| 129 | 129 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - return parent::get_transaction_url( $order ); |
|
| 132 | + return parent::get_transaction_url($order); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -138,15 +138,15 @@ discard block |
||
| 138 | 138 | * @since 4.0.0 |
| 139 | 139 | * @version 4.0.0 |
| 140 | 140 | */ |
| 141 | - public function get_stripe_customer_id( $order ) { |
|
| 142 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
| 141 | + public function get_stripe_customer_id($order) { |
|
| 142 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
| 143 | 143 | |
| 144 | - if ( empty( $customer ) ) { |
|
| 144 | + if (empty($customer)) { |
|
| 145 | 145 | // Try to get it via the order. |
| 146 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 147 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
| 146 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 147 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
| 148 | 148 | } else { |
| 149 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
| 149 | + return $order->get_meta('_stripe_customer_id', true); |
|
| 150 | 150 | } |
| 151 | 151 | } else { |
| 152 | 152 | return $customer; |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | * @param object $order |
| 164 | 164 | * @param int $id Stripe session id. |
| 165 | 165 | */ |
| 166 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
| 167 | - if ( is_object( $order ) ) { |
|
| 168 | - if ( empty( $id ) ) { |
|
| 166 | + public function get_stripe_return_url($order = null, $id = null) { |
|
| 167 | + if (is_object($order)) { |
|
| 168 | + if (empty($id)) { |
|
| 169 | 169 | $id = uniqid(); |
| 170 | 170 | } |
| 171 | 171 | |
@@ -176,10 +176,10 @@ discard block |
||
| 176 | 176 | 'order_id' => $order_id, |
| 177 | 177 | ); |
| 178 | 178 | |
| 179 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
| 179 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
| 182 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | * @param int $order_id |
| 188 | 188 | * @return boolean |
| 189 | 189 | */ |
| 190 | - public function has_subscription( $order_id ) { |
|
| 191 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 190 | + public function has_subscription($order_id) { |
|
| 191 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -200,34 +200,33 @@ discard block |
||
| 200 | 200 | * @param object $prepared_source |
| 201 | 201 | * @return array() |
| 202 | 202 | */ |
| 203 | - public function generate_payment_request( $order, $prepared_source ) { |
|
| 204 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 205 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
| 206 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
| 203 | + public function generate_payment_request($order, $prepared_source) { |
|
| 204 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
| 205 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
| 206 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
| 207 | 207 | $post_data = array(); |
| 208 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
| 209 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 208 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
| 209 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 210 | 210 | /* translators: 1) blog name 2) order number */ |
| 211 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
| 211 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
| 212 | 212 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
| 213 | 213 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 214 | 214 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
| 215 | 215 | |
| 216 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 216 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 217 | 217 | $post_data['receipt_email'] = $billing_email; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
| 221 | - case 'stripe': |
|
| 222 | - if ( ! empty( $statement_descriptor ) ) { |
|
| 223 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
| 220 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
| 221 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
| 222 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
| 224 | 223 | } |
| 225 | 224 | |
| 226 | 225 | $post_data['capture'] = $capture ? 'true' : 'false'; |
| 227 | 226 | break; |
| 228 | 227 | case 'stripe_sepa': |
| 229 | - if ( ! empty( $statement_descriptor ) ) { |
|
| 230 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
| 228 | + if ( ! empty($statement_descriptor)) { |
|
| 229 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
| 231 | 230 | } |
| 232 | 231 | break; |
| 233 | 232 | } |
@@ -235,25 +234,25 @@ discard block |
||
| 235 | 234 | $post_data['expand[]'] = 'balance_transaction'; |
| 236 | 235 | |
| 237 | 236 | $metadata = array( |
| 238 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
| 239 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
| 237 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
| 238 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
| 240 | 239 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
| 241 | 240 | ); |
| 242 | 241 | |
| 243 | - if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
| 242 | + if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
| 244 | 243 | $metadata += array( |
| 245 | 244 | 'payment_type' => 'recurring', |
| 246 | - 'site_url' => esc_url( get_site_url() ), |
|
| 245 | + 'site_url' => esc_url(get_site_url()), |
|
| 247 | 246 | ); |
| 248 | 247 | } |
| 249 | 248 | |
| 250 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source ); |
|
| 249 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source); |
|
| 251 | 250 | |
| 252 | - if ( $prepared_source->customer ) { |
|
| 251 | + if ($prepared_source->customer) { |
|
| 253 | 252 | $post_data['customer'] = $prepared_source->customer; |
| 254 | 253 | } |
| 255 | 254 | |
| 256 | - if ( $prepared_source->source ) { |
|
| 255 | + if ($prepared_source->source) { |
|
| 257 | 256 | $post_data['source'] = $prepared_source->source; |
| 258 | 257 | } |
| 259 | 258 | |
@@ -265,79 +264,79 @@ discard block |
||
| 265 | 264 | * @param WC_Order $order |
| 266 | 265 | * @param object $source |
| 267 | 266 | */ |
| 268 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source ); |
|
| 267 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source); |
|
| 269 | 268 | } |
| 270 | 269 | |
| 271 | 270 | /** |
| 272 | 271 | * Store extra meta data for an order from a Stripe Response. |
| 273 | 272 | */ |
| 274 | - public function process_response( $response, $order ) { |
|
| 275 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
| 273 | + public function process_response($response, $order) { |
|
| 274 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
| 276 | 275 | |
| 277 | 276 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 278 | 277 | |
| 279 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
| 278 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
| 280 | 279 | |
| 281 | 280 | // Store charge data. |
| 282 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
| 281 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
| 283 | 282 | |
| 284 | 283 | // Store other data such as fees. |
| 285 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
| 284 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
| 286 | 285 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 287 | 286 | // values are in the local currency of the Stripe account, not from WC. |
| 288 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
| 289 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
| 290 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
| 291 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
| 287 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
| 288 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
| 289 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
| 290 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
| 292 | 291 | } |
| 293 | 292 | |
| 294 | - if ( 'yes' === $captured ) { |
|
| 293 | + if ('yes' === $captured) { |
|
| 295 | 294 | /** |
| 296 | 295 | * Charge can be captured but in a pending state. Payment methods |
| 297 | 296 | * that are asynchronous may take couple days to clear. Webhook will |
| 298 | 297 | * take care of the status changes. |
| 299 | 298 | */ |
| 300 | - if ( 'pending' === $response->status ) { |
|
| 301 | - $order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true ); |
|
| 299 | + if ('pending' === $response->status) { |
|
| 300 | + $order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true); |
|
| 302 | 301 | |
| 303 | - if ( ! $order_stock_reduced ) { |
|
| 304 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
| 302 | + if ( ! $order_stock_reduced) { |
|
| 303 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
| 305 | 304 | } |
| 306 | 305 | |
| 307 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
| 306 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
| 308 | 307 | /* translators: transaction id */ |
| 309 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
| 308 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
| 310 | 309 | } |
| 311 | 310 | |
| 312 | - if ( 'succeeded' === $response->status ) { |
|
| 313 | - $order->payment_complete( $response->id ); |
|
| 311 | + if ('succeeded' === $response->status) { |
|
| 312 | + $order->payment_complete($response->id); |
|
| 314 | 313 | |
| 315 | 314 | /* translators: transaction id */ |
| 316 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
| 317 | - $order->add_order_note( $message ); |
|
| 315 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
| 316 | + $order->add_order_note($message); |
|
| 318 | 317 | } |
| 319 | 318 | |
| 320 | - if ( 'failed' === $response->status ) { |
|
| 321 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 322 | - $order->add_order_note( $localized_message ); |
|
| 323 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 319 | + if ('failed' === $response->status) { |
|
| 320 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 321 | + $order->add_order_note($localized_message); |
|
| 322 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 324 | 323 | } |
| 325 | 324 | } else { |
| 326 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
| 325 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
| 327 | 326 | |
| 328 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 329 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
| 327 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 328 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
| 330 | 329 | } |
| 331 | 330 | |
| 332 | 331 | /* translators: transaction id */ |
| 333 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
| 332 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
| 334 | 333 | } |
| 335 | 334 | |
| 336 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 335 | + if (is_callable(array($order, 'save'))) { |
|
| 337 | 336 | $order->save(); |
| 338 | 337 | } |
| 339 | 338 | |
| 340 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
| 339 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
| 341 | 340 | |
| 342 | 341 | return $response; |
| 343 | 342 | } |
@@ -350,10 +349,10 @@ discard block |
||
| 350 | 349 | * @param int $order_id |
| 351 | 350 | * @return null |
| 352 | 351 | */ |
| 353 | - public function send_failed_order_email( $order_id ) { |
|
| 352 | + public function send_failed_order_email($order_id) { |
|
| 354 | 353 | $emails = WC()->mailer()->get_emails(); |
| 355 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
| 356 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
| 354 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
| 355 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
| 357 | 356 | } |
| 358 | 357 | } |
| 359 | 358 | |
@@ -365,7 +364,7 @@ discard block |
||
| 365 | 364 | * @param object $order |
| 366 | 365 | * @return object $details |
| 367 | 366 | */ |
| 368 | - public function get_owner_details( $order ) { |
|
| 367 | + public function get_owner_details($order) { |
|
| 369 | 368 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 370 | 369 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
| 371 | 370 | |
@@ -375,15 +374,15 @@ discard block |
||
| 375 | 374 | $email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
| 376 | 375 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
| 377 | 376 | |
| 378 | - if ( ! empty( $phone ) ) { |
|
| 377 | + if ( ! empty($phone)) { |
|
| 379 | 378 | $details['phone'] = $phone; |
| 380 | 379 | } |
| 381 | 380 | |
| 382 | - if ( ! empty( $name ) ) { |
|
| 381 | + if ( ! empty($name)) { |
|
| 383 | 382 | $details['name'] = $name; |
| 384 | 383 | } |
| 385 | 384 | |
| 386 | - if ( ! empty( $email ) ) { |
|
| 385 | + if ( ! empty($email)) { |
|
| 387 | 386 | $details['email'] = $email; |
| 388 | 387 | } |
| 389 | 388 | |
@@ -394,7 +393,7 @@ discard block |
||
| 394 | 393 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
| 395 | 394 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
| 396 | 395 | |
| 397 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
| 396 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
| 398 | 397 | } |
| 399 | 398 | |
| 400 | 399 | /** |
@@ -403,15 +402,15 @@ discard block |
||
| 403 | 402 | * @since 4.0.3 |
| 404 | 403 | * @param string $source_id The source ID to get source object for. |
| 405 | 404 | */ |
| 406 | - public function get_source_object( $source_id = '' ) { |
|
| 407 | - if ( empty( $source_id ) ) { |
|
| 405 | + public function get_source_object($source_id = '') { |
|
| 406 | + if (empty($source_id)) { |
|
| 408 | 407 | return ''; |
| 409 | 408 | } |
| 410 | 409 | |
| 411 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
| 410 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
| 412 | 411 | |
| 413 | - if ( ! empty( $source_object->error ) ) { |
|
| 414 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
| 412 | + if ( ! empty($source_object->error)) { |
|
| 413 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
| 415 | 414 | } |
| 416 | 415 | |
| 417 | 416 | return $source_object; |
@@ -424,11 +423,11 @@ discard block |
||
| 424 | 423 | * @param object $source_object |
| 425 | 424 | * @return bool |
| 426 | 425 | */ |
| 427 | - public function is_3ds_required( $source_object ) { |
|
| 426 | + public function is_3ds_required($source_object) { |
|
| 428 | 427 | return ( |
| 429 | - $source_object && ! empty( $source_object->card ) ) && |
|
| 430 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
| 431 | - ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) |
|
| 428 | + $source_object && ! empty($source_object->card) ) && |
|
| 429 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
| 430 | + ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure) |
|
| 432 | 431 | ); |
| 433 | 432 | } |
| 434 | 433 | |
@@ -439,8 +438,8 @@ discard block |
||
| 439 | 438 | * @param object $source_object |
| 440 | 439 | * @return bool |
| 441 | 440 | */ |
| 442 | - public function is_3ds_card( $source_object ) { |
|
| 443 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
| 441 | + public function is_3ds_card($source_object) { |
|
| 442 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
| 444 | 443 | } |
| 445 | 444 | |
| 446 | 445 | /** |
@@ -450,8 +449,8 @@ discard block |
||
| 450 | 449 | * @param object $source_object |
| 451 | 450 | * @return bool |
| 452 | 451 | */ |
| 453 | - public function is_prepaid_card( $source_object ) { |
|
| 454 | - return ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ); |
|
| 452 | + public function is_prepaid_card($source_object) { |
|
| 453 | + return ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding); |
|
| 455 | 454 | } |
| 456 | 455 | |
| 457 | 456 | /** |
@@ -461,8 +460,8 @@ discard block |
||
| 461 | 460 | * @param string $source_id |
| 462 | 461 | * @return bool |
| 463 | 462 | */ |
| 464 | - public function is_type_legacy_card( $source_id ) { |
|
| 465 | - return ( preg_match( '/^card_/', $source_id ) ); |
|
| 463 | + public function is_type_legacy_card($source_id) { |
|
| 464 | + return (preg_match('/^card_/', $source_id)); |
|
| 466 | 465 | } |
| 467 | 466 | |
| 468 | 467 | /** |
@@ -475,22 +474,22 @@ discard block |
||
| 475 | 474 | * @param string $return_url |
| 476 | 475 | * @return mixed |
| 477 | 476 | */ |
| 478 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
| 477 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
| 479 | 478 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 480 | 479 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 481 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
| 480 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
| 482 | 481 | |
| 483 | 482 | $post_data = array(); |
| 484 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 485 | - $post_data['currency'] = strtolower( $currency ); |
|
| 483 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 484 | + $post_data['currency'] = strtolower($currency); |
|
| 486 | 485 | $post_data['type'] = 'three_d_secure'; |
| 487 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 488 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
| 489 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 486 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 487 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
| 488 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 490 | 489 | |
| 491 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
| 490 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
| 492 | 491 | |
| 493 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
| 492 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
| 494 | 493 | } |
| 495 | 494 | |
| 496 | 495 | /** |
@@ -506,61 +505,61 @@ discard block |
||
| 506 | 505 | * @throws Exception When card was not added or for and invalid card. |
| 507 | 506 | * @return object |
| 508 | 507 | */ |
| 509 | - public function prepare_source( $user_id, $force_save_source = false ) { |
|
| 510 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
| 508 | + public function prepare_source($user_id, $force_save_source = false) { |
|
| 509 | + $customer = new WC_Stripe_Customer($user_id); |
|
| 511 | 510 | $set_customer = true; |
| 512 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
| 511 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
| 513 | 512 | $source_object = ''; |
| 514 | 513 | $source_id = ''; |
| 515 | 514 | $wc_token_id = false; |
| 516 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
| 515 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
| 517 | 516 | $is_token = false; |
| 518 | 517 | |
| 519 | 518 | // New CC info was entered and we have a new source to process. |
| 520 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
| 521 | - $source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) ); |
|
| 519 | + if ( ! empty($_POST['stripe_source'])) { |
|
| 520 | + $source_object = self::get_source_object(wc_clean($_POST['stripe_source'])); |
|
| 522 | 521 | $source_id = $source_object->id; |
| 523 | 522 | |
| 524 | 523 | // This checks to see if customer opted to save the payment method to file. |
| 525 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
| 524 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
| 526 | 525 | |
| 527 | 526 | /** |
| 528 | 527 | * This is true if the user wants to store the card to their account. |
| 529 | 528 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
| 530 | 529 | * actually reusable. Either that or force_save_source is true. |
| 531 | 530 | */ |
| 532 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
| 533 | - $response = $customer->add_source( $source_object->id ); |
|
| 531 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
| 532 | + $response = $customer->add_source($source_object->id); |
|
| 534 | 533 | |
| 535 | - if ( ! empty( $response->error ) ) { |
|
| 536 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 534 | + if ( ! empty($response->error)) { |
|
| 535 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 537 | 536 | } |
| 538 | 537 | } |
| 539 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
| 538 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
| 540 | 539 | // Use an existing token, and then process the payment. |
| 541 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
| 542 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
| 540 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
| 541 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
| 543 | 542 | |
| 544 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
| 545 | - WC()->session->set( 'refresh_totals', true ); |
|
| 546 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
| 543 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
| 544 | + WC()->session->set('refresh_totals', true); |
|
| 545 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
| 547 | 546 | } |
| 548 | 547 | |
| 549 | 548 | $source_id = $wc_token->get_token(); |
| 550 | 549 | |
| 551 | - if ( $this->is_type_legacy_card( $source_id ) ) { |
|
| 550 | + if ($this->is_type_legacy_card($source_id)) { |
|
| 552 | 551 | $is_token = true; |
| 553 | 552 | } |
| 554 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
| 555 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 556 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
| 553 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
| 554 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 555 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
| 557 | 556 | |
| 558 | 557 | // This is true if the user wants to store the card to their account. |
| 559 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
| 560 | - $response = $customer->add_source( $stripe_token ); |
|
| 558 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
| 559 | + $response = $customer->add_source($stripe_token); |
|
| 561 | 560 | |
| 562 | - if ( ! empty( $response->error ) ) { |
|
| 563 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 561 | + if ( ! empty($response->error)) { |
|
| 562 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 564 | 563 | } |
| 565 | 564 | } else { |
| 566 | 565 | $set_customer = false; |
@@ -569,14 +568,14 @@ discard block |
||
| 569 | 568 | } |
| 570 | 569 | } |
| 571 | 570 | |
| 572 | - if ( ! $set_customer ) { |
|
| 571 | + if ( ! $set_customer) { |
|
| 573 | 572 | $customer_id = false; |
| 574 | 573 | } else { |
| 575 | 574 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
| 576 | 575 | } |
| 577 | 576 | |
| 578 | - if ( empty( $source_object ) && ! $is_token ) { |
|
| 579 | - $source_object = self::get_source_object( $source_id ); |
|
| 577 | + if (empty($source_object) && ! $is_token) { |
|
| 578 | + $source_object = self::get_source_object($source_id); |
|
| 580 | 579 | } |
| 581 | 580 | |
| 582 | 581 | return (object) array( |
@@ -600,37 +599,37 @@ discard block |
||
| 600 | 599 | * @param object $order |
| 601 | 600 | * @return object |
| 602 | 601 | */ |
| 603 | - public function prepare_order_source( $order = null ) { |
|
| 602 | + public function prepare_order_source($order = null) { |
|
| 604 | 603 | $stripe_customer = new WC_Stripe_Customer(); |
| 605 | 604 | $stripe_source = false; |
| 606 | 605 | $token_id = false; |
| 607 | 606 | |
| 608 | - if ( $order ) { |
|
| 607 | + if ($order) { |
|
| 609 | 608 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 610 | 609 | |
| 611 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
| 610 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
| 612 | 611 | |
| 613 | - if ( $stripe_customer_id ) { |
|
| 614 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 612 | + if ($stripe_customer_id) { |
|
| 613 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 615 | 614 | } |
| 616 | 615 | |
| 617 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
| 616 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
| 618 | 617 | |
| 619 | 618 | // Since 4.0.0, we changed card to source so we need to account for that. |
| 620 | - if ( empty( $source_id ) ) { |
|
| 621 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
| 619 | + if (empty($source_id)) { |
|
| 620 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
| 622 | 621 | |
| 623 | 622 | // Take this opportunity to update the key name. |
| 624 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
| 623 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
| 625 | 624 | |
| 626 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 625 | + if (is_callable(array($order, 'save'))) { |
|
| 627 | 626 | $order->save(); |
| 628 | 627 | } |
| 629 | 628 | } |
| 630 | 629 | |
| 631 | - if ( $source_id ) { |
|
| 630 | + if ($source_id) { |
|
| 632 | 631 | $stripe_source = $source_id; |
| 633 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 632 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 634 | 633 | /* |
| 635 | 634 | * We can attempt to charge the customer's default source |
| 636 | 635 | * by sending empty source id. |
@@ -654,27 +653,27 @@ discard block |
||
| 654 | 653 | * @param WC_Order $order For to which the source applies. |
| 655 | 654 | * @param stdClass $source Source information. |
| 656 | 655 | */ |
| 657 | - public function save_source_to_order( $order, $source ) { |
|
| 656 | + public function save_source_to_order($order, $source) { |
|
| 658 | 657 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 659 | 658 | |
| 660 | 659 | // Store source in the order. |
| 661 | - if ( $source->customer ) { |
|
| 662 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 663 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
| 660 | + if ($source->customer) { |
|
| 661 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 662 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
| 664 | 663 | } else { |
| 665 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
| 664 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
| 666 | 665 | } |
| 667 | 666 | } |
| 668 | 667 | |
| 669 | - if ( $source->source ) { |
|
| 670 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 671 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
| 668 | + if ($source->source) { |
|
| 669 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 670 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
| 672 | 671 | } else { |
| 673 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
| 672 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
| 674 | 673 | } |
| 675 | 674 | } |
| 676 | 675 | |
| 677 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 676 | + if (is_callable(array($order, 'save'))) { |
|
| 678 | 677 | $order->save(); |
| 679 | 678 | } |
| 680 | 679 | } |
@@ -688,35 +687,35 @@ discard block |
||
| 688 | 687 | * @param object $order The order object |
| 689 | 688 | * @param int $balance_transaction_id |
| 690 | 689 | */ |
| 691 | - public function update_fees( $order, $balance_transaction_id ) { |
|
| 690 | + public function update_fees($order, $balance_transaction_id) { |
|
| 692 | 691 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 693 | 692 | |
| 694 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
| 693 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
| 695 | 694 | |
| 696 | - if ( empty( $balance_transaction->error ) ) { |
|
| 697 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
| 695 | + if (empty($balance_transaction->error)) { |
|
| 696 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
| 698 | 697 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 699 | 698 | // values are in the local currency of the Stripe account, not from WC. |
| 700 | - $fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
| 701 | - $net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
| 699 | + $fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
| 700 | + $net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
| 702 | 701 | |
| 703 | 702 | // Current data fee & net. |
| 704 | - $fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_FEE, true ) : $order->get_meta( self::META_NAME_FEE, true ); |
|
| 705 | - $net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_NET, true ) : $order->get_meta( self::META_NAME_NET, true ); |
|
| 703 | + $fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_FEE, true) : $order->get_meta(self::META_NAME_FEE, true); |
|
| 704 | + $net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_NET, true) : $order->get_meta(self::META_NAME_NET, true); |
|
| 706 | 705 | |
| 707 | 706 | // Calculation. |
| 708 | 707 | $fee = (float) $fee_current + (float) $fee_refund; |
| 709 | 708 | $net = (float) $net_current + (float) $net_refund; |
| 710 | 709 | |
| 711 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
| 712 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
| 710 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
| 711 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
| 713 | 712 | |
| 714 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 713 | + if (is_callable(array($order, 'save'))) { |
|
| 715 | 714 | $order->save(); |
| 716 | 715 | } |
| 717 | 716 | } |
| 718 | 717 | } else { |
| 719 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
| 718 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
| 720 | 719 | } |
| 721 | 720 | } |
| 722 | 721 | |
@@ -729,33 +728,33 @@ discard block |
||
| 729 | 728 | * @param float $amount |
| 730 | 729 | * @return bool |
| 731 | 730 | */ |
| 732 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 733 | - $order = wc_get_order( $order_id ); |
|
| 731 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 732 | + $order = wc_get_order($order_id); |
|
| 734 | 733 | |
| 735 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 734 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
| 736 | 735 | return false; |
| 737 | 736 | } |
| 738 | 737 | |
| 739 | 738 | $request = array(); |
| 740 | 739 | |
| 741 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 742 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
| 743 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
| 740 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 741 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
| 742 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
| 744 | 743 | } else { |
| 745 | 744 | $order_currency = $order->get_currency(); |
| 746 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
| 745 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
| 747 | 746 | } |
| 748 | 747 | |
| 749 | - if ( ! is_null( $amount ) ) { |
|
| 750 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
| 748 | + if ( ! is_null($amount)) { |
|
| 749 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
| 751 | 750 | } |
| 752 | 751 | |
| 753 | 752 | // If order is only authorized, don't pass amount. |
| 754 | - if ( 'yes' !== $captured ) { |
|
| 755 | - unset( $request['amount'] ); |
|
| 753 | + if ('yes' !== $captured) { |
|
| 754 | + unset($request['amount']); |
|
| 756 | 755 | } |
| 757 | 756 | |
| 758 | - if ( $reason ) { |
|
| 757 | + if ($reason) { |
|
| 759 | 758 | $request['metadata'] = array( |
| 760 | 759 | 'reason' => $reason, |
| 761 | 760 | ); |
@@ -763,35 +762,35 @@ discard block |
||
| 763 | 762 | |
| 764 | 763 | $request['charge'] = $order->get_transaction_id(); |
| 765 | 764 | |
| 766 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
| 765 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
| 767 | 766 | |
| 768 | - $request = apply_filters( 'wc_stripe_refund_request', $request, $order ); |
|
| 767 | + $request = apply_filters('wc_stripe_refund_request', $request, $order); |
|
| 769 | 768 | |
| 770 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
| 769 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
| 771 | 770 | |
| 772 | - if ( ! empty( $response->error ) ) { |
|
| 773 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
| 771 | + if ( ! empty($response->error)) { |
|
| 772 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
| 774 | 773 | |
| 775 | 774 | return $response; |
| 776 | 775 | |
| 777 | - } elseif ( ! empty( $response->id ) ) { |
|
| 778 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
| 776 | + } elseif ( ! empty($response->id)) { |
|
| 777 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
| 779 | 778 | |
| 780 | - $amount = wc_price( $response->amount / 100 ); |
|
| 779 | + $amount = wc_price($response->amount / 100); |
|
| 781 | 780 | |
| 782 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
| 783 | - $amount = wc_price( $response->amount ); |
|
| 781 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
| 782 | + $amount = wc_price($response->amount); |
|
| 784 | 783 | } |
| 785 | 784 | |
| 786 | - if ( isset( $response->balance_transaction ) ) { |
|
| 787 | - $this->update_fees( $order, $response->balance_transaction ); |
|
| 785 | + if (isset($response->balance_transaction)) { |
|
| 786 | + $this->update_fees($order, $response->balance_transaction); |
|
| 788 | 787 | } |
| 789 | 788 | |
| 790 | 789 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
| 791 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
| 790 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe'); |
|
| 792 | 791 | |
| 793 | - $order->add_order_note( $refund_message ); |
|
| 794 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 792 | + $order->add_order_note($refund_message); |
|
| 793 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
| 795 | 794 | |
| 796 | 795 | return true; |
| 797 | 796 | } |
@@ -806,44 +805,44 @@ discard block |
||
| 806 | 805 | */ |
| 807 | 806 | public function add_payment_method() { |
| 808 | 807 | $error = false; |
| 809 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
| 808 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
| 810 | 809 | $source_id = ''; |
| 811 | 810 | |
| 812 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 811 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 813 | 812 | $error = true; |
| 814 | 813 | } |
| 815 | 814 | |
| 816 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 815 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 817 | 816 | |
| 818 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
| 817 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
| 819 | 818 | |
| 820 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
| 819 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
| 821 | 820 | |
| 822 | - if ( isset( $source_object ) ) { |
|
| 823 | - if ( ! empty( $source_object->error ) ) { |
|
| 821 | + if (isset($source_object)) { |
|
| 822 | + if ( ! empty($source_object->error)) { |
|
| 824 | 823 | $error = true; |
| 825 | 824 | } |
| 826 | 825 | |
| 827 | 826 | $source_id = $source_object->id; |
| 828 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
| 829 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
| 827 | + } elseif (isset($_POST['stripe_token'])) { |
|
| 828 | + $source_id = wc_clean($_POST['stripe_token']); |
|
| 830 | 829 | } |
| 831 | 830 | |
| 832 | - $response = $stripe_customer->add_source( $source_id ); |
|
| 831 | + $response = $stripe_customer->add_source($source_id); |
|
| 833 | 832 | |
| 834 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
| 833 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
| 835 | 834 | $error = true; |
| 836 | 835 | } |
| 837 | 836 | |
| 838 | - if ( $error ) { |
|
| 839 | - wc_add_notice( $error_msg, 'error' ); |
|
| 840 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
| 837 | + if ($error) { |
|
| 838 | + wc_add_notice($error_msg, 'error'); |
|
| 839 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
| 841 | 840 | return; |
| 842 | 841 | } |
| 843 | 842 | |
| 844 | 843 | return array( |
| 845 | 844 | 'result' => 'success', |
| 846 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 845 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 847 | 846 | ); |
| 848 | 847 | } |
| 849 | 848 | |
@@ -860,10 +859,10 @@ discard block |
||
| 860 | 859 | * Stripe expects Norwegian to only be passed NO. |
| 861 | 860 | * But WP has different dialects. |
| 862 | 861 | */ |
| 863 | - if ( 'NO' === substr( $locale, 3, 2 ) ) { |
|
| 862 | + if ('NO' === substr($locale, 3, 2)) { |
|
| 864 | 863 | $locale = 'no'; |
| 865 | 864 | } else { |
| 866 | - $locale = substr( get_locale(), 0, 2 ); |
|
| 865 | + $locale = substr(get_locale(), 0, 2); |
|
| 867 | 866 | } |
| 868 | 867 | |
| 869 | 868 | return $locale; |
@@ -877,9 +876,9 @@ discard block |
||
| 877 | 876 | * @param string $idempotency_key |
| 878 | 877 | * @param array $request |
| 879 | 878 | */ |
| 880 | - public function change_idempotency_key( $idempotency_key, $request ) { |
|
| 881 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
| 882 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
| 879 | + public function change_idempotency_key($idempotency_key, $request) { |
|
| 880 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
| 881 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
| 883 | 882 | $count = $this->retry_interval; |
| 884 | 883 | |
| 885 | 884 | return $request['metadata']['order_id'] . '-' . $count . '-' . $source; |
@@ -893,8 +892,8 @@ discard block |
||
| 893 | 892 | * @since 4.0.6 |
| 894 | 893 | * @param array $headers |
| 895 | 894 | */ |
| 896 | - public function is_original_request( $headers ) { |
|
| 897 | - if ( $headers['original-request'] === $headers['request-id'] ) { |
|
| 895 | + public function is_original_request($headers) { |
|
| 896 | + if ($headers['original-request'] === $headers['request-id']) { |
|
| 898 | 897 | return true; |
| 899 | 898 | } |
| 900 | 899 | |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 4.0.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -71,36 +71,36 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function __construct() { |
| 73 | 73 | self::$_this = $this; |
| 74 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 75 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
| 76 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
| 77 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
| 78 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
| 79 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
| 74 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 75 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
| 76 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
| 77 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
| 78 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
| 79 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
| 80 | 80 | |
| 81 | - if ( $this->testmode ) { |
|
| 82 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
| 83 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
| 81 | + if ($this->testmode) { |
|
| 82 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
| 83 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
| 86 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
| 87 | 87 | |
| 88 | 88 | // Checks if Stripe Gateway is enabled. |
| 89 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
| 89 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Checks if Payment Request is enabled. |
| 94 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
| 94 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
| 95 | 95 | return; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Don't load for change payment method page. |
| 99 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
| 99 | + if (isset($_GET['change_payment_method'])) { |
|
| 100 | 100 | return; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
| 103 | + add_action('template_redirect', array($this, 'set_session')); |
|
| 104 | 104 | $this->init(); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @return bool |
| 112 | 112 | */ |
| 113 | 113 | public function are_keys_set() { |
| 114 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
| 114 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
| 115 | 115 | return false; |
| 116 | 116 | } |
| 117 | 117 | |
@@ -135,18 +135,18 @@ discard block |
||
| 135 | 135 | * @since 4.0.0 |
| 136 | 136 | */ |
| 137 | 137 | public function set_session() { |
| 138 | - if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) { |
|
| 138 | + if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) { |
|
| 139 | 139 | return; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); |
|
| 142 | + $session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler'); |
|
| 143 | 143 | $wc_session = new $session_class(); |
| 144 | 144 | |
| 145 | - if ( version_compare( WC_VERSION, '3.3', '>=' ) ) { |
|
| 145 | + if (version_compare(WC_VERSION, '3.3', '>=')) { |
|
| 146 | 146 | $wc_session->init(); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $wc_session->set_customer_session_cookie( true ); |
|
| 149 | + $wc_session->set_customer_session_cookie(true); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -156,40 +156,40 @@ discard block |
||
| 156 | 156 | * @version 4.0.0 |
| 157 | 157 | */ |
| 158 | 158 | public function init() { |
| 159 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
| 159 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
| 160 | 160 | |
| 161 | 161 | /* |
| 162 | 162 | * In order to display the Payment Request button in the correct position, |
| 163 | 163 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
| 164 | 164 | * CSS is used to position the button. |
| 165 | 165 | */ |
| 166 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 167 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 168 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 166 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 167 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
| 168 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 169 | 169 | } else { |
| 170 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 171 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 170 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
| 171 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 175 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 174 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
| 175 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 176 | 176 | |
| 177 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 178 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 177 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
| 178 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 179 | 179 | |
| 180 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
| 181 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
| 182 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
| 183 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
| 184 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
| 185 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
| 186 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
| 187 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
| 180 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
| 181 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
| 182 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
| 183 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
| 184 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
| 185 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
| 186 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
| 187 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
| 188 | 188 | |
| 189 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 190 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
| 189 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 190 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
| 191 | 191 | |
| 192 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
| 192 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | 202 | public function get_button_type() { |
| 203 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 203 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * @return string |
| 212 | 212 | */ |
| 213 | 213 | public function get_button_theme() { |
| 214 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 214 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @return string |
| 223 | 223 | */ |
| 224 | 224 | public function get_button_height() { |
| 225 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
| 225 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -232,40 +232,40 @@ discard block |
||
| 232 | 232 | * @version 4.0.0 |
| 233 | 233 | */ |
| 234 | 234 | public function get_product_data() { |
| 235 | - if ( ! is_product() ) { |
|
| 235 | + if ( ! is_product()) { |
|
| 236 | 236 | return false; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | global $post; |
| 240 | 240 | |
| 241 | - $product = wc_get_product( $post->ID ); |
|
| 241 | + $product = wc_get_product($post->ID); |
|
| 242 | 242 | |
| 243 | 243 | $data = array(); |
| 244 | 244 | $items = array(); |
| 245 | 245 | |
| 246 | 246 | $items[] = array( |
| 247 | 247 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
| 248 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
| 248 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
| 249 | 249 | ); |
| 250 | 250 | |
| 251 | - if ( wc_tax_enabled() ) { |
|
| 251 | + if (wc_tax_enabled()) { |
|
| 252 | 252 | $items[] = array( |
| 253 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 253 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 254 | 254 | 'amount' => 0, |
| 255 | 255 | 'pending' => true, |
| 256 | 256 | ); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 259 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 260 | 260 | $items[] = array( |
| 261 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 261 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 262 | 262 | 'amount' => 0, |
| 263 | 263 | 'pending' => true, |
| 264 | 264 | ); |
| 265 | 265 | |
| 266 | - $data['shippingOptions'] = array( |
|
| 266 | + $data['shippingOptions'] = array( |
|
| 267 | 267 | 'id' => 'pending', |
| 268 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 268 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 269 | 269 | 'detail' => '', |
| 270 | 270 | 'amount' => 0, |
| 271 | 271 | ); |
@@ -273,41 +273,41 @@ discard block |
||
| 273 | 273 | |
| 274 | 274 | $data['displayItems'] = $items; |
| 275 | 275 | $data['total'] = array( |
| 276 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
| 277 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
| 276 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
| 277 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
| 278 | 278 | 'pending' => true, |
| 279 | 279 | ); |
| 280 | 280 | |
| 281 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 282 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 283 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 281 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 282 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 283 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 284 | 284 | |
| 285 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
| 285 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Filters the gateway title to reflect Payment Request type |
| 290 | 290 | * |
| 291 | 291 | */ |
| 292 | - public function filter_gateway_title( $title, $id ) { |
|
| 292 | + public function filter_gateway_title($title, $id) { |
|
| 293 | 293 | global $post; |
| 294 | 294 | |
| 295 | - if ( ! is_object( $post ) ) { |
|
| 295 | + if ( ! is_object($post)) { |
|
| 296 | 296 | return $title; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 300 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 300 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 301 | 301 | } else { |
| 302 | - $order = wc_get_order( $post->ID ); |
|
| 303 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
| 302 | + $order = wc_get_order($post->ID); |
|
| 303 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
| 306 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
| 307 | 307 | return $method_title; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
| 310 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
| 311 | 311 | return $method_title; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -320,16 +320,16 @@ discard block |
||
| 320 | 320 | * @since 3.1.4 |
| 321 | 321 | * @version 4.0.0 |
| 322 | 322 | */ |
| 323 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
| 323 | + public function postal_code_validation($valid, $postcode, $country) { |
|
| 324 | 324 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 325 | 325 | |
| 326 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 326 | + if ( ! isset($gateways['stripe'])) { |
|
| 327 | 327 | return $valid; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
| 330 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
| 331 | 331 | |
| 332 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
| 332 | + if ('apple_pay' !== $payment_request_type) { |
|
| 333 | 333 | return $valid; |
| 334 | 334 | } |
| 335 | 335 | |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | * the order and not let it go through. The remedy for now is just to remove this validation. |
| 340 | 340 | * Note that this only works with shipping providers that don't validate full postal codes. |
| 341 | 341 | */ |
| 342 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
| 342 | + if ('GB' === $country || 'CA' === $country) { |
|
| 343 | 343 | return true; |
| 344 | 344 | } |
| 345 | 345 | |
@@ -354,29 +354,29 @@ discard block |
||
| 354 | 354 | * @param int $order_id |
| 355 | 355 | * @param array $posted_data The posted data from checkout form. |
| 356 | 356 | */ |
| 357 | - public function add_order_meta( $order_id, $posted_data ) { |
|
| 358 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
| 357 | + public function add_order_meta($order_id, $posted_data) { |
|
| 358 | + if (empty($_POST['payment_request_type'])) { |
|
| 359 | 359 | return; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - $order = wc_get_order( $order_id ); |
|
| 362 | + $order = wc_get_order($order_id); |
|
| 363 | 363 | |
| 364 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
| 364 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
| 365 | 365 | |
| 366 | - if ( 'apple_pay' === $payment_request_type ) { |
|
| 367 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 368 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
| 366 | + if ('apple_pay' === $payment_request_type) { |
|
| 367 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 368 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
| 369 | 369 | } else { |
| 370 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
| 370 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
| 371 | 371 | $order->save(); |
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
| 376 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 377 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
| 375 | + if ('payment_request_api' === $payment_request_type) { |
|
| 376 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 377 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
| 378 | 378 | } else { |
| 379 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
| 379 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
| 380 | 380 | $order->save(); |
| 381 | 381 | } |
| 382 | 382 | } |
@@ -390,11 +390,11 @@ discard block |
||
| 390 | 390 | * @return array |
| 391 | 391 | */ |
| 392 | 392 | public function supported_product_types() { |
| 393 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
| 393 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
| 394 | 394 | 'simple', |
| 395 | 395 | 'variable', |
| 396 | 396 | 'variation', |
| 397 | - ) ); |
|
| 397 | + )); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | /** |
@@ -405,15 +405,15 @@ discard block |
||
| 405 | 405 | * @return bool |
| 406 | 406 | */ |
| 407 | 407 | public function allowed_items_in_cart() { |
| 408 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 409 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
| 408 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 409 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
| 410 | 410 | |
| 411 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
| 411 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
| 412 | 412 | return false; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | // Pre Orders compatbility where we don't support charge upon release. |
| 416 | - 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() ) ) { |
|
| 416 | + 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())) { |
|
| 417 | 417 | return false; |
| 418 | 418 | } |
| 419 | 419 | } |
@@ -429,82 +429,82 @@ discard block |
||
| 429 | 429 | */ |
| 430 | 430 | public function scripts() { |
| 431 | 431 | // If keys are not set bail. |
| 432 | - if ( ! $this->are_keys_set() ) { |
|
| 433 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
| 432 | + if ( ! $this->are_keys_set()) { |
|
| 433 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
| 434 | 434 | return; |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | // If no SSL bail. |
| 438 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
| 439 | - WC_Stripe_Logger::log( 'Stripe requires SSL.' ); |
|
| 438 | + if ( ! $this->testmode && ! is_ssl()) { |
|
| 439 | + WC_Stripe_Logger::log('Stripe requires SSL.'); |
|
| 440 | 440 | return; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 443 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 444 | 444 | return; |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - if ( is_product() ) { |
|
| 447 | + if (is_product()) { |
|
| 448 | 448 | global $post; |
| 449 | 449 | |
| 450 | - $product = wc_get_product( $post->ID ); |
|
| 450 | + $product = wc_get_product($post->ID); |
|
| 451 | 451 | |
| 452 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 452 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 453 | 453 | return; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 456 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 457 | 457 | return; |
| 458 | 458 | } |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 461 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 462 | 462 | |
| 463 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 464 | - 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 ); |
|
| 463 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 464 | + 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); |
|
| 465 | 465 | |
| 466 | 466 | wp_localize_script( |
| 467 | 467 | 'wc_stripe_payment_request', |
| 468 | 468 | 'wc_stripe_payment_request_params', |
| 469 | 469 | array( |
| 470 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 470 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 471 | 471 | 'stripe' => array( |
| 472 | 472 | 'key' => $this->publishable_key, |
| 473 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
| 473 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
| 474 | 474 | ), |
| 475 | 475 | 'nonce' => array( |
| 476 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
| 477 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
| 478 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
| 479 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
| 480 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
| 481 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
| 482 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
| 483 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
| 476 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
| 477 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
| 478 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
| 479 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
| 480 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
| 481 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
| 482 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
| 483 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
| 484 | 484 | ), |
| 485 | 485 | 'i18n' => array( |
| 486 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
| 486 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
| 487 | 487 | /* translators: Do not translate the [option] placeholder */ |
| 488 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
| 488 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
| 489 | 489 | ), |
| 490 | 490 | 'checkout' => array( |
| 491 | 491 | 'url' => wc_get_checkout_url(), |
| 492 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
| 493 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 492 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
| 493 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 494 | 494 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 495 | 495 | ), |
| 496 | 496 | 'button' => array( |
| 497 | 497 | 'type' => $this->get_button_type(), |
| 498 | 498 | 'theme' => $this->get_button_theme(), |
| 499 | 499 | 'height' => $this->get_button_height(), |
| 500 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
| 500 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
| 501 | 501 | ), |
| 502 | 502 | 'is_product_page' => is_product(), |
| 503 | 503 | 'product' => $this->get_product_data(), |
| 504 | 504 | ) |
| 505 | 505 | ); |
| 506 | 506 | |
| 507 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
| 507 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | /** |
@@ -516,39 +516,39 @@ discard block |
||
| 516 | 516 | public function display_payment_request_button_html() { |
| 517 | 517 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 518 | 518 | |
| 519 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 519 | + if ( ! isset($gateways['stripe'])) { |
|
| 520 | 520 | return; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 523 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 524 | 524 | return; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 527 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 528 | 528 | return; |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
| 531 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
| 532 | 532 | return; |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - if ( is_product() ) { |
|
| 535 | + if (is_product()) { |
|
| 536 | 536 | global $post; |
| 537 | 537 | |
| 538 | - $product = wc_get_product( $post->ID ); |
|
| 538 | + $product = wc_get_product($post->ID); |
|
| 539 | 539 | |
| 540 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 540 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 541 | 541 | return; |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | // Pre Orders charge upon release not supported. |
| 545 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 546 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 545 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 546 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 547 | 547 | return; |
| 548 | 548 | } |
| 549 | 549 | } else { |
| 550 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 551 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 550 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 551 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 552 | 552 | return; |
| 553 | 553 | } |
| 554 | 554 | } |
@@ -570,44 +570,44 @@ discard block |
||
| 570 | 570 | public function display_payment_request_button_separator_html() { |
| 571 | 571 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 572 | 572 | |
| 573 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 573 | + if ( ! isset($gateways['stripe'])) { |
|
| 574 | 574 | return; |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 577 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 578 | 578 | return; |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 581 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 582 | 582 | return; |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
| 585 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
| 586 | 586 | return; |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | - if ( is_product() ) { |
|
| 589 | + if (is_product()) { |
|
| 590 | 590 | global $post; |
| 591 | 591 | |
| 592 | - $product = wc_get_product( $post->ID ); |
|
| 592 | + $product = wc_get_product($post->ID); |
|
| 593 | 593 | |
| 594 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 594 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 595 | 595 | return; |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | // Pre Orders charge upon release not supported. |
| 599 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 600 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 599 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 600 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 601 | 601 | return; |
| 602 | 602 | } |
| 603 | 603 | } else { |
| 604 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 605 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 604 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 605 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 606 | 606 | return; |
| 607 | 607 | } |
| 608 | 608 | } |
| 609 | 609 | ?> |
| 610 | - <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> |
|
| 610 | + <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> |
|
| 611 | 611 | <?php |
| 612 | 612 | } |
| 613 | 613 | |
@@ -618,11 +618,11 @@ discard block |
||
| 618 | 618 | * @version 4.0.0 |
| 619 | 619 | */ |
| 620 | 620 | public function ajax_log_errors() { |
| 621 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
| 621 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
| 622 | 622 | |
| 623 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
| 623 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
| 624 | 624 | |
| 625 | - WC_Stripe_Logger::log( $errors ); |
|
| 625 | + WC_Stripe_Logger::log($errors); |
|
| 626 | 626 | |
| 627 | 627 | exit; |
| 628 | 628 | } |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | * @version 4.0.0 |
| 635 | 635 | */ |
| 636 | 636 | public function ajax_clear_cart() { |
| 637 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
| 637 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
| 638 | 638 | |
| 639 | 639 | WC()->cart->empty_cart(); |
| 640 | 640 | exit; |
@@ -644,10 +644,10 @@ discard block |
||
| 644 | 644 | * Get cart details. |
| 645 | 645 | */ |
| 646 | 646 | public function ajax_get_cart_details() { |
| 647 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
| 647 | + check_ajax_referer('wc-stripe-payment-request', '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 | 653 | WC()->cart->calculate_totals(); |
@@ -658,14 +658,14 @@ discard block |
||
| 658 | 658 | $data = array( |
| 659 | 659 | 'shipping_required' => WC()->cart->needs_shipping(), |
| 660 | 660 | 'order_data' => array( |
| 661 | - 'currency' => strtolower( $currency ), |
|
| 662 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 661 | + 'currency' => strtolower($currency), |
|
| 662 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 663 | 663 | ), |
| 664 | 664 | ); |
| 665 | 665 | |
| 666 | 666 | $data['order_data'] += $this->build_display_items(); |
| 667 | 667 | |
| 668 | - wp_send_json( $data ); |
|
| 668 | + wp_send_json($data); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -676,47 +676,47 @@ discard block |
||
| 676 | 676 | * @see WC_Shipping::get_packages(). |
| 677 | 677 | */ |
| 678 | 678 | public function ajax_get_shipping_options() { |
| 679 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
| 679 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
| 680 | 680 | |
| 681 | 681 | try { |
| 682 | 682 | // Set the shipping package. |
| 683 | - $posted = filter_input_array( INPUT_POST, array( |
|
| 683 | + $posted = filter_input_array(INPUT_POST, array( |
|
| 684 | 684 | 'country' => FILTER_SANITIZE_STRING, |
| 685 | 685 | 'state' => FILTER_SANITIZE_STRING, |
| 686 | 686 | 'postcode' => FILTER_SANITIZE_STRING, |
| 687 | 687 | 'city' => FILTER_SANITIZE_STRING, |
| 688 | 688 | 'address' => FILTER_SANITIZE_STRING, |
| 689 | 689 | 'address_2' => FILTER_SANITIZE_STRING, |
| 690 | - ) ); |
|
| 690 | + )); |
|
| 691 | 691 | |
| 692 | - $this->calculate_shipping( $posted ); |
|
| 692 | + $this->calculate_shipping($posted); |
|
| 693 | 693 | |
| 694 | 694 | // Set the shipping options. |
| 695 | 695 | $data = array(); |
| 696 | 696 | $packages = WC()->shipping->get_packages(); |
| 697 | 697 | |
| 698 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 699 | - foreach ( $packages as $package_key => $package ) { |
|
| 700 | - if ( empty( $package['rates'] ) ) { |
|
| 701 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 698 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 699 | + foreach ($packages as $package_key => $package) { |
|
| 700 | + if (empty($package['rates'])) { |
|
| 701 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 704 | + foreach ($package['rates'] as $key => $rate) { |
|
| 705 | 705 | $data['shipping_options'][] = array( |
| 706 | 706 | 'id' => $rate->id, |
| 707 | 707 | 'label' => $rate->label, |
| 708 | 708 | 'detail' => '', |
| 709 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
| 709 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
| 710 | 710 | ); |
| 711 | 711 | } |
| 712 | 712 | } |
| 713 | 713 | } else { |
| 714 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 714 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - if ( isset( $data[0] ) ) { |
|
| 717 | + if (isset($data[0])) { |
|
| 718 | 718 | // Auto select the first shipping method. |
| 719 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 719 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | WC()->cart->calculate_totals(); |
@@ -724,12 +724,12 @@ discard block |
||
| 724 | 724 | $data += $this->build_display_items(); |
| 725 | 725 | $data['result'] = 'success'; |
| 726 | 726 | |
| 727 | - wp_send_json( $data ); |
|
| 728 | - } catch ( Exception $e ) { |
|
| 727 | + wp_send_json($data); |
|
| 728 | + } catch (Exception $e) { |
|
| 729 | 729 | $data += $this->build_display_items(); |
| 730 | 730 | $data['result'] = 'invalid_shipping_address'; |
| 731 | 731 | |
| 732 | - wp_send_json( $data ); |
|
| 732 | + wp_send_json($data); |
|
| 733 | 733 | } |
| 734 | 734 | } |
| 735 | 735 | |
@@ -737,22 +737,22 @@ discard block |
||
| 737 | 737 | * Update shipping method. |
| 738 | 738 | */ |
| 739 | 739 | public function ajax_update_shipping_method() { |
| 740 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
| 740 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
| 741 | 741 | |
| 742 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 743 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 742 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 743 | + define('WOOCOMMERCE_CART', true); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
| 747 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 746 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
| 747 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 748 | 748 | |
| 749 | - if ( is_array( $shipping_method ) ) { |
|
| 750 | - foreach ( $shipping_method as $i => $value ) { |
|
| 751 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
| 749 | + if (is_array($shipping_method)) { |
|
| 750 | + foreach ($shipping_method as $i => $value) { |
|
| 751 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
| 752 | 752 | } |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
| 755 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
| 756 | 756 | |
| 757 | 757 | WC()->cart->calculate_totals(); |
| 758 | 758 | |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | $data += $this->build_display_items(); |
| 761 | 761 | $data['result'] = 'success'; |
| 762 | 762 | |
| 763 | - wp_send_json( $data ); |
|
| 763 | + wp_send_json($data); |
|
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | /** |
@@ -771,31 +771,31 @@ discard block |
||
| 771 | 771 | * @return array $data |
| 772 | 772 | */ |
| 773 | 773 | public function ajax_get_selected_product_data() { |
| 774 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
| 774 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
| 775 | 775 | |
| 776 | - $product_id = absint( $_POST['product_id'] ); |
|
| 777 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 776 | + $product_id = absint($_POST['product_id']); |
|
| 777 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 778 | 778 | |
| 779 | - $product = wc_get_product( $product_id ); |
|
| 779 | + $product = wc_get_product($product_id); |
|
| 780 | 780 | |
| 781 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 782 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 781 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 782 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 783 | 783 | |
| 784 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 785 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 784 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 785 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 786 | 786 | } else { |
| 787 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 788 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 787 | + $data_store = WC_Data_Store::load('product'); |
|
| 788 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | - if ( ! empty( $variation_id ) ) { |
|
| 792 | - $product = wc_get_product( $variation_id ); |
|
| 791 | + if ( ! empty($variation_id)) { |
|
| 792 | + $product = wc_get_product($variation_id); |
|
| 793 | 793 | } |
| 794 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
| 795 | - $product = wc_get_product( $product_id ); |
|
| 794 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
| 795 | + $product = wc_get_product($product_id); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
| 798 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
| 799 | 799 | |
| 800 | 800 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
| 801 | 801 | |
@@ -803,28 +803,28 @@ discard block |
||
| 803 | 803 | $items = array(); |
| 804 | 804 | |
| 805 | 805 | $items[] = array( |
| 806 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
| 807 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 806 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
| 807 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 808 | 808 | ); |
| 809 | 809 | |
| 810 | - if ( wc_tax_enabled() ) { |
|
| 810 | + if (wc_tax_enabled()) { |
|
| 811 | 811 | $items[] = array( |
| 812 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 812 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 813 | 813 | 'amount' => 0, |
| 814 | 814 | 'pending' => true, |
| 815 | 815 | ); |
| 816 | 816 | } |
| 817 | 817 | |
| 818 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 818 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 819 | 819 | $items[] = array( |
| 820 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 820 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 821 | 821 | 'amount' => 0, |
| 822 | 822 | 'pending' => true, |
| 823 | 823 | ); |
| 824 | 824 | |
| 825 | - $data['shippingOptions'] = array( |
|
| 825 | + $data['shippingOptions'] = array( |
|
| 826 | 826 | 'id' => 'pending', |
| 827 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 827 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 828 | 828 | 'detail' => '', |
| 829 | 829 | 'amount' => 0, |
| 830 | 830 | ); |
@@ -833,15 +833,15 @@ discard block |
||
| 833 | 833 | $data['displayItems'] = $items; |
| 834 | 834 | $data['total'] = array( |
| 835 | 835 | 'label' => $this->total_label, |
| 836 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 836 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 837 | 837 | 'pending' => true, |
| 838 | 838 | ); |
| 839 | 839 | |
| 840 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 841 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 842 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 840 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 841 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 842 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 843 | 843 | |
| 844 | - wp_send_json( $data ); |
|
| 844 | + wp_send_json($data); |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | /** |
@@ -852,37 +852,37 @@ discard block |
||
| 852 | 852 | * @return array $data |
| 853 | 853 | */ |
| 854 | 854 | public function ajax_add_to_cart() { |
| 855 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
| 855 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
| 856 | 856 | |
| 857 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 858 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 857 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 858 | + define('WOOCOMMERCE_CART', true); |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | WC()->shipping->reset_shipping(); |
| 862 | 862 | |
| 863 | - $product_id = absint( $_POST['product_id'] ); |
|
| 864 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 863 | + $product_id = absint($_POST['product_id']); |
|
| 864 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 865 | 865 | |
| 866 | - $product = wc_get_product( $product_id ); |
|
| 866 | + $product = wc_get_product($product_id); |
|
| 867 | 867 | |
| 868 | 868 | // First empty the cart to prevent wrong calculation. |
| 869 | 869 | WC()->cart->empty_cart(); |
| 870 | 870 | |
| 871 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 872 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 871 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 872 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 873 | 873 | |
| 874 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 875 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 874 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 875 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 876 | 876 | } else { |
| 877 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 878 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 877 | + $data_store = WC_Data_Store::load('product'); |
|
| 878 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 881 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
| 885 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 884 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
| 885 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | WC()->cart->calculate_totals(); |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | $data += $this->build_display_items(); |
| 892 | 892 | $data['result'] = 'success'; |
| 893 | 893 | |
| 894 | - wp_send_json( $data ); |
|
| 894 | + wp_send_json($data); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | /** |
@@ -904,31 +904,31 @@ discard block |
||
| 904 | 904 | * @version 4.0.0 |
| 905 | 905 | */ |
| 906 | 906 | public function normalize_state() { |
| 907 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
| 908 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
| 909 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
| 910 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
| 907 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
| 908 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
| 909 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
| 910 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
| 911 | 911 | |
| 912 | - if ( $billing_state && $billing_country ) { |
|
| 913 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
| 912 | + if ($billing_state && $billing_country) { |
|
| 913 | + $valid_states = WC()->countries->get_states($billing_country); |
|
| 914 | 914 | |
| 915 | 915 | // Valid states found for country. |
| 916 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 917 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 918 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
| 916 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 917 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 918 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
| 919 | 919 | $_POST['billing_state'] = $state_abbr; |
| 920 | 920 | } |
| 921 | 921 | } |
| 922 | 922 | } |
| 923 | 923 | } |
| 924 | 924 | |
| 925 | - if ( $shipping_state && $shipping_country ) { |
|
| 926 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
| 925 | + if ($shipping_state && $shipping_country) { |
|
| 926 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
| 927 | 927 | |
| 928 | 928 | // Valid states found for country. |
| 929 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 930 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 931 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
| 929 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 930 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 931 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
| 932 | 932 | $_POST['shipping_state'] = $state_abbr; |
| 933 | 933 | } |
| 934 | 934 | } |
@@ -943,19 +943,19 @@ discard block |
||
| 943 | 943 | * @version 4.0.0 |
| 944 | 944 | */ |
| 945 | 945 | public function ajax_create_order() { |
| 946 | - if ( WC()->cart->is_empty() ) { |
|
| 947 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
| 946 | + if (WC()->cart->is_empty()) { |
|
| 947 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
| 951 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 950 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
| 951 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
| 952 | 952 | } |
| 953 | 953 | |
| 954 | 954 | $this->normalize_state(); |
| 955 | 955 | |
| 956 | 956 | WC()->checkout()->process_checkout(); |
| 957 | 957 | |
| 958 | - die( 0 ); |
|
| 958 | + die(0); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | * @version 4.0.0 |
| 966 | 966 | * @param array $address |
| 967 | 967 | */ |
| 968 | - protected function calculate_shipping( $address = array() ) { |
|
| 968 | + protected function calculate_shipping($address = array()) { |
|
| 969 | 969 | global $states; |
| 970 | 970 | |
| 971 | 971 | $country = $address['country']; |
@@ -982,28 +982,28 @@ discard block |
||
| 982 | 982 | * In some versions of Chrome, state can be a full name. So we need |
| 983 | 983 | * to convert that to abbreviation as WC is expecting that. |
| 984 | 984 | */ |
| 985 | - if ( 2 < strlen( $state ) ) { |
|
| 986 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
| 985 | + if (2 < strlen($state)) { |
|
| 986 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | WC()->shipping->reset_shipping(); |
| 990 | 990 | |
| 991 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 992 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 991 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
| 992 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | - if ( $country ) { |
|
| 996 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 997 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 995 | + if ($country) { |
|
| 996 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 997 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 998 | 998 | } else { |
| 999 | 999 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
| 1000 | 1000 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 1004 | - WC()->customer->calculated_shipping( true ); |
|
| 1003 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 1004 | + WC()->customer->calculated_shipping(true); |
|
| 1005 | 1005 | } else { |
| 1006 | - WC()->customer->set_calculated_shipping( true ); |
|
| 1006 | + WC()->customer->set_calculated_shipping(true); |
|
| 1007 | 1007 | WC()->customer->save(); |
| 1008 | 1008 | } |
| 1009 | 1009 | |
@@ -1020,17 +1020,17 @@ discard block |
||
| 1020 | 1020 | $packages[0]['destination']['address'] = $address_1; |
| 1021 | 1021 | $packages[0]['destination']['address_2'] = $address_2; |
| 1022 | 1022 | |
| 1023 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 1024 | - if ( $item['data']->needs_shipping() ) { |
|
| 1025 | - if ( isset( $item['line_total'] ) ) { |
|
| 1023 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 1024 | + if ($item['data']->needs_shipping()) { |
|
| 1025 | + if (isset($item['line_total'])) { |
|
| 1026 | 1026 | $packages[0]['contents_cost'] += $item['line_total']; |
| 1027 | 1027 | } |
| 1028 | 1028 | } |
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 1031 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 1032 | 1032 | |
| 1033 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 1033 | + WC()->shipping->calculate_shipping($packages); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | /** |
@@ -1039,19 +1039,19 @@ discard block |
||
| 1039 | 1039 | * @since 3.1.0 |
| 1040 | 1040 | * @version 4.0.0 |
| 1041 | 1041 | */ |
| 1042 | - protected function build_shipping_methods( $shipping_methods ) { |
|
| 1043 | - if ( empty( $shipping_methods ) ) { |
|
| 1042 | + protected function build_shipping_methods($shipping_methods) { |
|
| 1043 | + if (empty($shipping_methods)) { |
|
| 1044 | 1044 | return array(); |
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | $shipping = array(); |
| 1048 | 1048 | |
| 1049 | - foreach ( $shipping_methods as $method ) { |
|
| 1049 | + foreach ($shipping_methods as $method) { |
|
| 1050 | 1050 | $shipping[] = array( |
| 1051 | 1051 | 'id' => $method['id'], |
| 1052 | 1052 | 'label' => $method['label'], |
| 1053 | 1053 | 'detail' => '', |
| 1054 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
| 1054 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
| 1055 | 1055 | ); |
| 1056 | 1056 | } |
| 1057 | 1057 | |
@@ -1065,69 +1065,69 @@ discard block |
||
| 1065 | 1065 | * @version 4.0.0 |
| 1066 | 1066 | */ |
| 1067 | 1067 | protected function build_display_items() { |
| 1068 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 1069 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 1068 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 1069 | + define('WOOCOMMERCE_CART', true); |
|
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | 1072 | $items = array(); |
| 1073 | 1073 | $subtotal = 0; |
| 1074 | 1074 | |
| 1075 | 1075 | // Default show only subtotal instead of itemization. |
| 1076 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
| 1077 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 1076 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
| 1077 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 1078 | 1078 | $amount = $cart_item['line_subtotal']; |
| 1079 | - $subtotal += $cart_item['line_subtotal']; |
|
| 1079 | + $subtotal += $cart_item['line_subtotal']; |
|
| 1080 | 1080 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
| 1081 | 1081 | |
| 1082 | 1082 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
| 1083 | 1083 | |
| 1084 | 1084 | $item = array( |
| 1085 | 1085 | 'label' => $product_name . $quantity_label, |
| 1086 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
| 1086 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
| 1087 | 1087 | ); |
| 1088 | 1088 | |
| 1089 | 1089 | $items[] = $item; |
| 1090 | 1090 | } |
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
| 1094 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
| 1095 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
| 1096 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
| 1097 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
| 1093 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
| 1094 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
| 1095 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
| 1096 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
| 1097 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
| 1098 | 1098 | |
| 1099 | - if ( wc_tax_enabled() ) { |
|
| 1099 | + if (wc_tax_enabled()) { |
|
| 1100 | 1100 | $items[] = array( |
| 1101 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
| 1102 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
| 1101 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
| 1102 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
| 1103 | 1103 | ); |
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | - if ( WC()->cart->needs_shipping() ) { |
|
| 1106 | + if (WC()->cart->needs_shipping()) { |
|
| 1107 | 1107 | $items[] = array( |
| 1108 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
| 1109 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
| 1108 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
| 1109 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
| 1110 | 1110 | ); |
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | - if ( WC()->cart->has_discount() ) { |
|
| 1113 | + if (WC()->cart->has_discount()) { |
|
| 1114 | 1114 | $items[] = array( |
| 1115 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
| 1116 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
| 1115 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
| 1116 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
| 1117 | 1117 | ); |
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
| 1120 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
| 1121 | 1121 | $cart_fees = WC()->cart->fees; |
| 1122 | 1122 | } else { |
| 1123 | 1123 | $cart_fees = WC()->cart->get_fees(); |
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | 1126 | // Include fees and taxes as display items. |
| 1127 | - foreach ( $cart_fees as $key => $fee ) { |
|
| 1127 | + foreach ($cart_fees as $key => $fee) { |
|
| 1128 | 1128 | $items[] = array( |
| 1129 | 1129 | 'label' => $fee->name, |
| 1130 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
| 1130 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
| 1131 | 1131 | ); |
| 1132 | 1132 | } |
| 1133 | 1133 | |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | 'displayItems' => $items, |
| 1136 | 1136 | 'total' => array( |
| 1137 | 1137 | 'label' => $this->total_label, |
| 1138 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
| 1138 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
| 1139 | 1139 | 'pending' => false, |
| 1140 | 1140 | ), |
| 1141 | 1141 | ); |