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