@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @since 4.0.5 |
| 22 | 22 | * @param array $error |
| 23 | 23 | */ |
| 24 | - public function is_retryable_error( $error ) { |
|
| 24 | + public function is_retryable_error($error) { |
|
| 25 | 25 | return ( |
| 26 | 26 | 'invalid_request_error' === $error->type || |
| 27 | 27 | 'idempotency_error' === $error->type || |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * Check if this gateway is enabled |
| 34 | 34 | */ |
| 35 | 35 | public function is_available() { |
| 36 | - if ( 'yes' === $this->enabled ) { |
|
| 37 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
| 36 | + if ('yes' === $this->enabled) { |
|
| 37 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
| 38 | 38 | return false; |
| 39 | 39 | } |
| 40 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
| 40 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
| 41 | 41 | return false; |
| 42 | 42 | } |
| 43 | 43 | return true; |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | * @since 4.0.0 |
| 53 | 53 | * @version 4.0.0 |
| 54 | 54 | */ |
| 55 | - public function add_admin_notice( $slug, $class, $message ) { |
|
| 56 | - $this->notices[ $slug ] = array( |
|
| 55 | + public function add_admin_notice($slug, $class, $message) { |
|
| 56 | + $this->notices[$slug] = array( |
|
| 57 | 57 | 'class' => $class, |
| 58 | 58 | 'message' => $message, |
| 59 | 59 | ); |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | * @version 4.0.0 |
| 67 | 67 | */ |
| 68 | 68 | public function remove_admin_notice() { |
| 69 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
| 70 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 69 | + if (did_action('woocommerce_update_options')) { |
|
| 70 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | 81 | public function payment_icons() { |
| 82 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 82 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 83 | 83 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
| 84 | 84 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
| 85 | 85 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
| 97 | 97 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
| 98 | 98 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
| 99 | - ) ); |
|
| 99 | + )); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | * @version 4.0.0 |
| 108 | 108 | * @param object $order |
| 109 | 109 | */ |
| 110 | - public function validate_minimum_order_amount( $order ) { |
|
| 111 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 110 | + public function validate_minimum_order_amount($order) { |
|
| 111 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 112 | 112 | /* translators: 1) dollar amount */ |
| 113 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 113 | + throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
@@ -120,14 +120,14 @@ discard block |
||
| 120 | 120 | * @since 4.0.0 |
| 121 | 121 | * @version 4.0.0 |
| 122 | 122 | */ |
| 123 | - public function get_transaction_url( $order ) { |
|
| 124 | - if ( $this->testmode ) { |
|
| 123 | + public function get_transaction_url($order) { |
|
| 124 | + if ($this->testmode) { |
|
| 125 | 125 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
| 126 | 126 | } else { |
| 127 | 127 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - return parent::get_transaction_url( $order ); |
|
| 130 | + return parent::get_transaction_url($order); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -136,15 +136,15 @@ discard block |
||
| 136 | 136 | * @since 4.0.0 |
| 137 | 137 | * @version 4.0.0 |
| 138 | 138 | */ |
| 139 | - public function get_stripe_customer_id( $order ) { |
|
| 140 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
| 139 | + public function get_stripe_customer_id($order) { |
|
| 140 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
| 141 | 141 | |
| 142 | - if ( empty( $customer ) ) { |
|
| 142 | + if (empty($customer)) { |
|
| 143 | 143 | // Try to get it via the order. |
| 144 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 145 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
| 144 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 145 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
| 146 | 146 | } else { |
| 147 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
| 147 | + return $order->get_meta('_stripe_customer_id', true); |
|
| 148 | 148 | } |
| 149 | 149 | } else { |
| 150 | 150 | return $customer; |
@@ -161,9 +161,9 @@ discard block |
||
| 161 | 161 | * @param object $order |
| 162 | 162 | * @param int $id Stripe session id. |
| 163 | 163 | */ |
| 164 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
| 165 | - if ( is_object( $order ) ) { |
|
| 166 | - if ( empty( $id ) ) { |
|
| 164 | + public function get_stripe_return_url($order = null, $id = null) { |
|
| 165 | + if (is_object($order)) { |
|
| 166 | + if (empty($id)) { |
|
| 167 | 167 | $id = uniqid(); |
| 168 | 168 | } |
| 169 | 169 | |
@@ -174,10 +174,10 @@ discard block |
||
| 174 | 174 | 'order_id' => $order_id, |
| 175 | 175 | ); |
| 176 | 176 | |
| 177 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
| 177 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
| 180 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -189,34 +189,33 @@ discard block |
||
| 189 | 189 | * @param object $source |
| 190 | 190 | * @return array() |
| 191 | 191 | */ |
| 192 | - public function generate_payment_request( $order, $source ) { |
|
| 193 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 194 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
| 195 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
| 192 | + public function generate_payment_request($order, $source) { |
|
| 193 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
| 194 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
| 195 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
| 196 | 196 | $post_data = array(); |
| 197 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
| 198 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 197 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
| 198 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 199 | 199 | /* translators: 1) blog name 2) order number */ |
| 200 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
| 200 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
| 201 | 201 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
| 202 | 202 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 203 | 203 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
| 204 | 204 | |
| 205 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 205 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 206 | 206 | $post_data['receipt_email'] = $billing_email; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
| 210 | - case 'stripe': |
|
| 211 | - if ( ! empty( $statement_descriptor ) ) { |
|
| 212 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
| 209 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
| 210 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
| 211 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
| 213 | 212 | } |
| 214 | 213 | |
| 215 | 214 | $post_data['capture'] = $capture ? 'true' : 'false'; |
| 216 | 215 | break; |
| 217 | 216 | case 'stripe_sepa': |
| 218 | - if ( ! empty( $statement_descriptor ) ) { |
|
| 219 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
| 217 | + if ( ! empty($statement_descriptor)) { |
|
| 218 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
| 220 | 219 | } |
| 221 | 220 | break; |
| 222 | 221 | } |
@@ -224,18 +223,18 @@ discard block |
||
| 224 | 223 | $post_data['expand[]'] = 'balance_transaction'; |
| 225 | 224 | |
| 226 | 225 | $metadata = array( |
| 227 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
| 228 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
| 226 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
| 227 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
| 229 | 228 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
| 230 | 229 | ); |
| 231 | 230 | |
| 232 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
| 231 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
| 233 | 232 | |
| 234 | - if ( $source->customer ) { |
|
| 233 | + if ($source->customer) { |
|
| 235 | 234 | $post_data['customer'] = $source->customer; |
| 236 | 235 | } |
| 237 | 236 | |
| 238 | - if ( $source->source ) { |
|
| 237 | + if ($source->source) { |
|
| 239 | 238 | $post_data['source'] = $source->source; |
| 240 | 239 | } |
| 241 | 240 | |
@@ -247,79 +246,79 @@ discard block |
||
| 247 | 246 | * @param WC_Order $order |
| 248 | 247 | * @param object $source |
| 249 | 248 | */ |
| 250 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
| 249 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
| 251 | 250 | } |
| 252 | 251 | |
| 253 | 252 | /** |
| 254 | 253 | * Store extra meta data for an order from a Stripe Response. |
| 255 | 254 | */ |
| 256 | - public function process_response( $response, $order ) { |
|
| 257 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
| 255 | + public function process_response($response, $order) { |
|
| 256 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
| 258 | 257 | |
| 259 | 258 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 260 | 259 | |
| 261 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
| 260 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
| 262 | 261 | |
| 263 | 262 | // Store charge data |
| 264 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
| 263 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
| 265 | 264 | |
| 266 | 265 | // Store other data such as fees |
| 267 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
| 266 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
| 268 | 267 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 269 | 268 | // values are in the local currency of the Stripe account, not from WC. |
| 270 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
| 271 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
| 272 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
| 273 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
| 269 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
| 270 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
| 271 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
| 272 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
| 274 | 273 | } |
| 275 | 274 | |
| 276 | - if ( 'yes' === $captured ) { |
|
| 275 | + if ('yes' === $captured) { |
|
| 277 | 276 | /** |
| 278 | 277 | * Charge can be captured but in a pending state. Payment methods |
| 279 | 278 | * that are asynchronous may take couple days to clear. Webhook will |
| 280 | 279 | * take care of the status changes. |
| 281 | 280 | */ |
| 282 | - if ( 'pending' === $response->status ) { |
|
| 283 | - $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 ); |
|
| 281 | + if ('pending' === $response->status) { |
|
| 282 | + $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); |
|
| 284 | 283 | |
| 285 | - if ( ! $order_stock_reduced ) { |
|
| 286 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
| 284 | + if ( ! $order_stock_reduced) { |
|
| 285 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
| 287 | 286 | } |
| 288 | 287 | |
| 289 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
| 288 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
| 290 | 289 | /* translators: transaction id */ |
| 291 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
| 290 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
| 292 | 291 | } |
| 293 | 292 | |
| 294 | - if ( 'succeeded' === $response->status ) { |
|
| 295 | - $order->payment_complete( $response->id ); |
|
| 293 | + if ('succeeded' === $response->status) { |
|
| 294 | + $order->payment_complete($response->id); |
|
| 296 | 295 | |
| 297 | 296 | /* translators: transaction id */ |
| 298 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
| 299 | - $order->add_order_note( $message ); |
|
| 297 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
| 298 | + $order->add_order_note($message); |
|
| 300 | 299 | } |
| 301 | 300 | |
| 302 | - if ( 'failed' === $response->status ) { |
|
| 303 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 304 | - $order->add_order_note( $localized_message ); |
|
| 305 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 301 | + if ('failed' === $response->status) { |
|
| 302 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 303 | + $order->add_order_note($localized_message); |
|
| 304 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 306 | 305 | } |
| 307 | 306 | } else { |
| 308 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
| 307 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
| 309 | 308 | |
| 310 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 311 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
| 309 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 310 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
| 312 | 311 | } |
| 313 | 312 | |
| 314 | 313 | /* translators: transaction id */ |
| 315 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
| 314 | + $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)); |
|
| 316 | 315 | } |
| 317 | 316 | |
| 318 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 317 | + if (is_callable(array($order, 'save'))) { |
|
| 319 | 318 | $order->save(); |
| 320 | 319 | } |
| 321 | 320 | |
| 322 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
| 321 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
| 323 | 322 | |
| 324 | 323 | return $response; |
| 325 | 324 | } |
@@ -332,10 +331,10 @@ discard block |
||
| 332 | 331 | * @param int $order_id |
| 333 | 332 | * @return null |
| 334 | 333 | */ |
| 335 | - public function send_failed_order_email( $order_id ) { |
|
| 334 | + public function send_failed_order_email($order_id) { |
|
| 336 | 335 | $emails = WC()->mailer()->get_emails(); |
| 337 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
| 338 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
| 336 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
| 337 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
| 339 | 338 | } |
| 340 | 339 | } |
| 341 | 340 | |
@@ -347,7 +346,7 @@ discard block |
||
| 347 | 346 | * @param object $order |
| 348 | 347 | * @return object $details |
| 349 | 348 | */ |
| 350 | - public function get_owner_details( $order ) { |
|
| 349 | + public function get_owner_details($order) { |
|
| 351 | 350 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 352 | 351 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
| 353 | 352 | |
@@ -358,8 +357,8 @@ discard block |
||
| 358 | 357 | |
| 359 | 358 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
| 360 | 359 | |
| 361 | - if ( ! empty( $phone ) ) { |
|
| 362 | - $details['phone'] = $phone; |
|
| 360 | + if ( ! empty($phone)) { |
|
| 361 | + $details['phone'] = $phone; |
|
| 363 | 362 | } |
| 364 | 363 | |
| 365 | 364 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -369,7 +368,7 @@ discard block |
||
| 369 | 368 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
| 370 | 369 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
| 371 | 370 | |
| 372 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
| 371 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
| 373 | 372 | } |
| 374 | 373 | |
| 375 | 374 | /** |
@@ -378,16 +377,16 @@ discard block |
||
| 378 | 377 | * @since 4.0.3 |
| 379 | 378 | */ |
| 380 | 379 | public function get_source_object() { |
| 381 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
| 380 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
| 382 | 381 | |
| 383 | - if ( empty( $source ) ) { |
|
| 382 | + if (empty($source)) { |
|
| 384 | 383 | return ''; |
| 385 | 384 | } |
| 386 | 385 | |
| 387 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
| 386 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
| 388 | 387 | |
| 389 | - if ( ! empty( $source_object->error ) ) { |
|
| 390 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
| 388 | + if ( ! empty($source_object->error)) { |
|
| 389 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
| 391 | 390 | } |
| 392 | 391 | |
| 393 | 392 | return $source_object; |
@@ -400,11 +399,11 @@ discard block |
||
| 400 | 399 | * @param object $source_object |
| 401 | 400 | * @return bool |
| 402 | 401 | */ |
| 403 | - public function is_3ds_required( $source_object ) { |
|
| 402 | + public function is_3ds_required($source_object) { |
|
| 404 | 403 | return ( |
| 405 | - $source_object && ! empty( $source_object->card ) ) && |
|
| 406 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
| 407 | - ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) |
|
| 404 | + $source_object && ! empty($source_object->card) ) && |
|
| 405 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
| 406 | + ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure) |
|
| 408 | 407 | ); |
| 409 | 408 | } |
| 410 | 409 | |
@@ -415,8 +414,8 @@ discard block |
||
| 415 | 414 | * @param object $source_object |
| 416 | 415 | * @return bool |
| 417 | 416 | */ |
| 418 | - public function is_3ds_card( $source_object ) { |
|
| 419 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
| 417 | + public function is_3ds_card($source_object) { |
|
| 418 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
| 420 | 419 | } |
| 421 | 420 | |
| 422 | 421 | /** |
@@ -429,22 +428,22 @@ discard block |
||
| 429 | 428 | * @param string $return_url |
| 430 | 429 | * @return mixed |
| 431 | 430 | */ |
| 432 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
| 431 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
| 433 | 432 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 434 | 433 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 435 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
| 434 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
| 436 | 435 | |
| 437 | 436 | $post_data = array(); |
| 438 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 439 | - $post_data['currency'] = strtolower( $currency ); |
|
| 437 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 438 | + $post_data['currency'] = strtolower($currency); |
|
| 440 | 439 | $post_data['type'] = 'three_d_secure'; |
| 441 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 442 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
| 443 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 440 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 441 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
| 442 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 444 | 443 | |
| 445 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
| 444 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
| 446 | 445 | |
| 447 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
| 446 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
| 448 | 447 | } |
| 449 | 448 | |
| 450 | 449 | /** |
@@ -461,54 +460,54 @@ discard block |
||
| 461 | 460 | * @throws Exception When card was not added or for and invalid card. |
| 462 | 461 | * @return object |
| 463 | 462 | */ |
| 464 | - public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) { |
|
| 465 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
| 463 | + public function prepare_source($source_object = '', $user_id, $force_save_source = false) { |
|
| 464 | + $customer = new WC_Stripe_Customer($user_id); |
|
| 466 | 465 | $set_customer = true; |
| 467 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
| 466 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
| 468 | 467 | $source_id = ''; |
| 469 | 468 | $wc_token_id = false; |
| 470 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
| 469 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
| 471 | 470 | |
| 472 | 471 | // New CC info was entered and we have a new source to process. |
| 473 | - if ( ! empty( $source_object ) ) { |
|
| 472 | + if ( ! empty($source_object)) { |
|
| 474 | 473 | $source_id = $source_object->id; |
| 475 | 474 | |
| 476 | 475 | // This checks to see if customer opted to save the payment method to file. |
| 477 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
| 476 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
| 478 | 477 | |
| 479 | 478 | /** |
| 480 | 479 | * This is true if the user wants to store the card to their account. |
| 481 | 480 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
| 482 | 481 | * actually reusable. Either that or force_save_source is true. |
| 483 | 482 | */ |
| 484 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
| 485 | - $response = $customer->add_source( $source_object->id ); |
|
| 483 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
| 484 | + $response = $customer->add_source($source_object->id); |
|
| 486 | 485 | |
| 487 | - if ( ! empty( $response->error ) ) { |
|
| 488 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 486 | + if ( ! empty($response->error)) { |
|
| 487 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 489 | 488 | } |
| 490 | 489 | } |
| 491 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
| 490 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
| 492 | 491 | // Use an existing token, and then process the payment |
| 493 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
| 494 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
| 492 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
| 493 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
| 495 | 494 | |
| 496 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
| 497 | - WC()->session->set( 'refresh_totals', true ); |
|
| 498 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
| 495 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
| 496 | + WC()->session->set('refresh_totals', true); |
|
| 497 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
| 499 | 498 | } |
| 500 | 499 | |
| 501 | 500 | $source_id = $wc_token->get_token(); |
| 502 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
| 503 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 504 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
| 501 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
| 502 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 503 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
| 505 | 504 | |
| 506 | 505 | // This is true if the user wants to store the card to their account. |
| 507 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
| 508 | - $response = $customer->add_source( $stripe_token ); |
|
| 506 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
| 507 | + $response = $customer->add_source($stripe_token); |
|
| 509 | 508 | |
| 510 | - if ( ! empty( $response->error ) ) { |
|
| 511 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 509 | + if ( ! empty($response->error)) { |
|
| 510 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 512 | 511 | } |
| 513 | 512 | } else { |
| 514 | 513 | $set_customer = false; |
@@ -516,7 +515,7 @@ discard block |
||
| 516 | 515 | } |
| 517 | 516 | } |
| 518 | 517 | |
| 519 | - if ( ! $set_customer ) { |
|
| 518 | + if ( ! $set_customer) { |
|
| 520 | 519 | $customer_id = false; |
| 521 | 520 | } else { |
| 522 | 521 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
@@ -542,37 +541,37 @@ discard block |
||
| 542 | 541 | * @param object $order |
| 543 | 542 | * @return object |
| 544 | 543 | */ |
| 545 | - public function prepare_order_source( $order = null ) { |
|
| 544 | + public function prepare_order_source($order = null) { |
|
| 546 | 545 | $stripe_customer = new WC_Stripe_Customer(); |
| 547 | 546 | $stripe_source = false; |
| 548 | 547 | $token_id = false; |
| 549 | 548 | |
| 550 | - if ( $order ) { |
|
| 549 | + if ($order) { |
|
| 551 | 550 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 552 | 551 | |
| 553 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
| 552 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
| 554 | 553 | |
| 555 | - if ( $stripe_customer_id ) { |
|
| 556 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 554 | + if ($stripe_customer_id) { |
|
| 555 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 557 | 556 | } |
| 558 | 557 | |
| 559 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
| 558 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
| 560 | 559 | |
| 561 | 560 | // Since 4.0.0, we changed card to source so we need to account for that. |
| 562 | - if ( empty( $source_id ) ) { |
|
| 563 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
| 561 | + if (empty($source_id)) { |
|
| 562 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
| 564 | 563 | |
| 565 | 564 | // Take this opportunity to update the key name. |
| 566 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
| 565 | + 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); |
|
| 567 | 566 | |
| 568 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 567 | + if (is_callable(array($order, 'save'))) { |
|
| 569 | 568 | $order->save(); |
| 570 | 569 | } |
| 571 | 570 | } |
| 572 | 571 | |
| 573 | - if ( $source_id ) { |
|
| 572 | + if ($source_id) { |
|
| 574 | 573 | $stripe_source = $source_id; |
| 575 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 574 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 576 | 575 | /* |
| 577 | 576 | * We can attempt to charge the customer's default source |
| 578 | 577 | * by sending empty source id. |
@@ -596,27 +595,27 @@ discard block |
||
| 596 | 595 | * @param WC_Order $order For to which the source applies. |
| 597 | 596 | * @param stdClass $source Source information. |
| 598 | 597 | */ |
| 599 | - public function save_source_to_order( $order, $source ) { |
|
| 598 | + public function save_source_to_order($order, $source) { |
|
| 600 | 599 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 601 | 600 | |
| 602 | 601 | // Store source in the order. |
| 603 | - if ( $source->customer ) { |
|
| 604 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 605 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
| 602 | + if ($source->customer) { |
|
| 603 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 604 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
| 606 | 605 | } else { |
| 607 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
| 606 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
| 608 | 607 | } |
| 609 | 608 | } |
| 610 | 609 | |
| 611 | - if ( $source->source ) { |
|
| 612 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 613 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
| 610 | + if ($source->source) { |
|
| 611 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 612 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
| 614 | 613 | } else { |
| 615 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
| 614 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
| 616 | 615 | } |
| 617 | 616 | } |
| 618 | 617 | |
| 619 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 618 | + if (is_callable(array($order, 'save'))) { |
|
| 620 | 619 | $order->save(); |
| 621 | 620 | } |
| 622 | 621 | } |
@@ -630,27 +629,27 @@ discard block |
||
| 630 | 629 | * @param object $order The order object |
| 631 | 630 | * @param int $balance_transaction_id |
| 632 | 631 | */ |
| 633 | - public function update_fees( $order, $balance_transaction_id ) { |
|
| 632 | + public function update_fees($order, $balance_transaction_id) { |
|
| 634 | 633 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 635 | 634 | |
| 636 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
| 635 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
| 637 | 636 | |
| 638 | - if ( empty( $balance_transaction->error ) ) { |
|
| 639 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
| 637 | + if (empty($balance_transaction->error)) { |
|
| 638 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
| 640 | 639 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 641 | 640 | // values are in the local currency of the Stripe account, not from WC. |
| 642 | - $fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
| 643 | - $net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
| 641 | + $fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
| 642 | + $net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
| 644 | 643 | |
| 645 | - 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 ); |
|
| 646 | - 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 ); |
|
| 644 | + 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); |
|
| 645 | + 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); |
|
| 647 | 646 | |
| 648 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 647 | + if (is_callable(array($order, 'save'))) { |
|
| 649 | 648 | $order->save(); |
| 650 | 649 | } |
| 651 | 650 | } |
| 652 | 651 | } else { |
| 653 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
| 652 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
| 654 | 653 | } |
| 655 | 654 | } |
| 656 | 655 | |
@@ -663,33 +662,33 @@ discard block |
||
| 663 | 662 | * @param float $amount |
| 664 | 663 | * @return bool |
| 665 | 664 | */ |
| 666 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 667 | - $order = wc_get_order( $order_id ); |
|
| 665 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 666 | + $order = wc_get_order($order_id); |
|
| 668 | 667 | |
| 669 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 668 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
| 670 | 669 | return false; |
| 671 | 670 | } |
| 672 | 671 | |
| 673 | 672 | $request = array(); |
| 674 | 673 | |
| 675 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 676 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
| 677 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
| 674 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 675 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
| 676 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
| 678 | 677 | } else { |
| 679 | 678 | $order_currency = $order->get_currency(); |
| 680 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
| 679 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
| 681 | 680 | } |
| 682 | 681 | |
| 683 | - if ( ! is_null( $amount ) ) { |
|
| 684 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
| 682 | + if ( ! is_null($amount)) { |
|
| 683 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
| 685 | 684 | } |
| 686 | 685 | |
| 687 | 686 | // If order is only authorized, don't pass amount. |
| 688 | - if ( 'yes' !== $captured ) { |
|
| 689 | - unset( $request['amount'] ); |
|
| 687 | + if ('yes' !== $captured) { |
|
| 688 | + unset($request['amount']); |
|
| 690 | 689 | } |
| 691 | 690 | |
| 692 | - if ( $reason ) { |
|
| 691 | + if ($reason) { |
|
| 693 | 692 | $request['metadata'] = array( |
| 694 | 693 | 'reason' => $reason, |
| 695 | 694 | ); |
@@ -697,33 +696,33 @@ discard block |
||
| 697 | 696 | |
| 698 | 697 | $request['charge'] = $order->get_transaction_id(); |
| 699 | 698 | |
| 700 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
| 699 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
| 701 | 700 | |
| 702 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
| 701 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
| 703 | 702 | |
| 704 | - if ( ! empty( $response->error ) ) { |
|
| 705 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
| 703 | + if ( ! empty($response->error)) { |
|
| 704 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
| 706 | 705 | |
| 707 | 706 | return $response; |
| 708 | 707 | |
| 709 | - } elseif ( ! empty( $response->id ) ) { |
|
| 710 | - 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 ); |
|
| 708 | + } elseif ( ! empty($response->id)) { |
|
| 709 | + 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); |
|
| 711 | 710 | |
| 712 | - $amount = wc_price( $response->amount / 100 ); |
|
| 711 | + $amount = wc_price($response->amount / 100); |
|
| 713 | 712 | |
| 714 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
| 715 | - $amount = wc_price( $response->amount ); |
|
| 713 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
| 714 | + $amount = wc_price($response->amount); |
|
| 716 | 715 | } |
| 717 | 716 | |
| 718 | - if ( isset( $response->balance_transaction ) ) { |
|
| 719 | - $this->update_fees( $order, $response->balance_transaction ); |
|
| 717 | + if (isset($response->balance_transaction)) { |
|
| 718 | + $this->update_fees($order, $response->balance_transaction); |
|
| 720 | 719 | } |
| 721 | 720 | |
| 722 | 721 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
| 723 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
| 722 | + $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'); |
|
| 724 | 723 | |
| 725 | - $order->add_order_note( $refund_message ); |
|
| 726 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 724 | + $order->add_order_note($refund_message); |
|
| 725 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
| 727 | 726 | |
| 728 | 727 | return true; |
| 729 | 728 | } |
@@ -738,44 +737,44 @@ discard block |
||
| 738 | 737 | */ |
| 739 | 738 | public function add_payment_method() { |
| 740 | 739 | $error = false; |
| 741 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
| 740 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
| 742 | 741 | $source_id = ''; |
| 743 | 742 | |
| 744 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 743 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 745 | 744 | $error = true; |
| 746 | 745 | } |
| 747 | 746 | |
| 748 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 747 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 749 | 748 | |
| 750 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
| 749 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
| 751 | 750 | |
| 752 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
| 751 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
| 753 | 752 | |
| 754 | - if ( isset( $source_object ) ) { |
|
| 755 | - if ( ! empty( $source_object->error ) ) { |
|
| 753 | + if (isset($source_object)) { |
|
| 754 | + if ( ! empty($source_object->error)) { |
|
| 756 | 755 | $error = true; |
| 757 | 756 | } |
| 758 | 757 | |
| 759 | 758 | $source_id = $source_object->id; |
| 760 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
| 761 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
| 759 | + } elseif (isset($_POST['stripe_token'])) { |
|
| 760 | + $source_id = wc_clean($_POST['stripe_token']); |
|
| 762 | 761 | } |
| 763 | 762 | |
| 764 | - $response = $stripe_customer->add_source( $source_id ); |
|
| 763 | + $response = $stripe_customer->add_source($source_id); |
|
| 765 | 764 | |
| 766 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
| 765 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
| 767 | 766 | $error = true; |
| 768 | 767 | } |
| 769 | 768 | |
| 770 | - if ( $error ) { |
|
| 771 | - wc_add_notice( $error_msg, 'error' ); |
|
| 772 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
| 769 | + if ($error) { |
|
| 770 | + wc_add_notice($error_msg, 'error'); |
|
| 771 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
| 773 | 772 | return; |
| 774 | 773 | } |
| 775 | 774 | |
| 776 | 775 | return array( |
| 777 | 776 | 'result' => 'success', |
| 778 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 777 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 779 | 778 | ); |
| 780 | 779 | } |
| 781 | 780 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | public function __construct() { |
| 116 | 116 | $this->retry_interval = 2; |
| 117 | 117 | $this->id = 'stripe'; |
| 118 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 118 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 119 | 119 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
| 120 | - $this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
| 120 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
| 121 | 121 | $this->has_fields = true; |
| 122 | 122 | $this->supports = array( |
| 123 | 123 | 'products', |
@@ -144,37 +144,37 @@ discard block |
||
| 144 | 144 | $this->init_settings(); |
| 145 | 145 | |
| 146 | 146 | // Get setting values. |
| 147 | - $this->title = $this->get_option( 'title' ); |
|
| 148 | - $this->description = $this->get_option( 'description' ); |
|
| 149 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 150 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
| 151 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
| 152 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 153 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
| 154 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
| 155 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
| 156 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
| 157 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 158 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 159 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 160 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
| 161 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
| 162 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
| 147 | + $this->title = $this->get_option('title'); |
|
| 148 | + $this->description = $this->get_option('description'); |
|
| 149 | + $this->enabled = $this->get_option('enabled'); |
|
| 150 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
| 151 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
| 152 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 153 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
| 154 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
| 155 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
| 156 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
| 157 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 158 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 159 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 160 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
| 161 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
| 162 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
| 163 | 163 | $this->apple_pay_verify_notice = ''; |
| 164 | 164 | |
| 165 | - if ( $this->stripe_checkout ) { |
|
| 166 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
| 165 | + if ($this->stripe_checkout) { |
|
| 166 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
| 169 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 170 | 170 | |
| 171 | 171 | $this->init_apple_pay(); |
| 172 | 172 | |
| 173 | 173 | // Hooks. |
| 174 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 175 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
| 176 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 177 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 174 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 175 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
| 176 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 177 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @since 4.0.2 |
| 184 | 184 | */ |
| 185 | 185 | public function is_available() { |
| 186 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
| 186 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
| 187 | 187 | return false; |
| 188 | 188 | } |
| 189 | 189 | |
@@ -206,17 +206,17 @@ discard block |
||
| 206 | 206 | $icons_str .= $icons['amex']; |
| 207 | 207 | $icons_str .= $icons['mastercard']; |
| 208 | 208 | |
| 209 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 209 | + if ('USD' === get_woocommerce_currency()) { |
|
| 210 | 210 | $icons_str .= $icons['discover']; |
| 211 | 211 | $icons_str .= $icons['jcb']; |
| 212 | 212 | $icons_str .= $icons['diners']; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
| 215 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
| 216 | 216 | $icons_str .= $icons['bitcoin']; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 219 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -228,9 +228,9 @@ discard block |
||
| 228 | 228 | public function init_apple_pay() { |
| 229 | 229 | if ( |
| 230 | 230 | is_admin() && |
| 231 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
| 232 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
| 233 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
| 231 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
| 232 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
| 233 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
| 234 | 234 | $this->payment_request |
| 235 | 235 | ) { |
| 236 | 236 | $this->process_apple_pay_verification(); |
@@ -244,9 +244,9 @@ discard block |
||
| 244 | 244 | * @version 3.1.0 |
| 245 | 245 | * @param string $secret_key |
| 246 | 246 | */ |
| 247 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
| 248 | - if ( empty( $secret_key ) ) { |
|
| 249 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
| 247 | + private function register_apple_pay_domain($secret_key = '') { |
|
| 248 | + if (empty($secret_key)) { |
|
| 249 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -260,23 +260,23 @@ discard block |
||
| 260 | 260 | 'Authorization' => 'Bearer ' . $secret_key, |
| 261 | 261 | ); |
| 262 | 262 | |
| 263 | - $response = wp_remote_post( $endpoint, array( |
|
| 263 | + $response = wp_remote_post($endpoint, array( |
|
| 264 | 264 | 'headers' => $headers, |
| 265 | - 'body' => http_build_query( $data ), |
|
| 266 | - ) ); |
|
| 265 | + 'body' => http_build_query($data), |
|
| 266 | + )); |
|
| 267 | 267 | |
| 268 | - if ( is_wp_error( $response ) ) { |
|
| 268 | + if (is_wp_error($response)) { |
|
| 269 | 269 | /* translators: error message */ |
| 270 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 270 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if ( 200 !== $response['response']['code'] ) { |
|
| 274 | - $parsed_response = json_decode( $response['body'] ); |
|
| 273 | + if (200 !== $response['response']['code']) { |
|
| 274 | + $parsed_response = json_decode($response['body']); |
|
| 275 | 275 | |
| 276 | 276 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
| 277 | 277 | |
| 278 | 278 | /* translators: error message */ |
| 279 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
| 279 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | |
@@ -287,48 +287,48 @@ discard block |
||
| 287 | 287 | * @version 3.1.0 |
| 288 | 288 | */ |
| 289 | 289 | public function process_apple_pay_verification() { |
| 290 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 290 | + $gateway_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 291 | 291 | |
| 292 | 292 | try { |
| 293 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
| 293 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
| 294 | 294 | $dir = '.well-known'; |
| 295 | 295 | $file = 'apple-developer-merchantid-domain-association'; |
| 296 | 296 | $fullpath = $path . '/' . $dir . '/' . $file; |
| 297 | 297 | |
| 298 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
| 298 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
| 299 | 299 | return; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
| 303 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
| 304 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 302 | + if ( ! file_exists($path . '/' . $dir)) { |
|
| 303 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
| 304 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - if ( ! file_exists( $fullpath ) ) { |
|
| 309 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
| 310 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 308 | + if ( ! file_exists($fullpath)) { |
|
| 309 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
| 310 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | // At this point then the domain association folder and file should be available. |
| 315 | 315 | // Proceed to verify/and or verify again. |
| 316 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
| 316 | + $this->register_apple_pay_domain($this->secret_key); |
|
| 317 | 317 | |
| 318 | 318 | // No errors to this point, verification success! |
| 319 | 319 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
| 320 | 320 | $this->apple_pay_domain_set = true; |
| 321 | 321 | |
| 322 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 322 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 323 | 323 | |
| 324 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
| 324 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
| 325 | 325 | |
| 326 | - } catch ( Exception $e ) { |
|
| 326 | + } catch (Exception $e) { |
|
| 327 | 327 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
| 328 | 328 | |
| 329 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 329 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 330 | 330 | |
| 331 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 331 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
@@ -336,11 +336,11 @@ discard block |
||
| 336 | 336 | * Check if SSL is enabled and notify the user |
| 337 | 337 | */ |
| 338 | 338 | public function admin_notices() { |
| 339 | - if ( 'no' === $this->enabled ) { |
|
| 339 | + if ('no' === $this->enabled) { |
|
| 340 | 340 | return; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
| 343 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
| 344 | 344 | $allowed_html = array( |
| 345 | 345 | 'a' => array( |
| 346 | 346 | 'href' => array(), |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | ), |
| 349 | 349 | ); |
| 350 | 350 | |
| 351 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
| 351 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -356,9 +356,9 @@ discard block |
||
| 356 | 356 | * when setting screen is displayed. So if domain verification is not set, |
| 357 | 357 | * something went wrong so lets notify user. |
| 358 | 358 | */ |
| 359 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
| 359 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
| 360 | 360 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
| 361 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
| 361 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | * Initialise Gateway Settings Form Fields |
| 367 | 367 | */ |
| 368 | 368 | public function init_form_fields() { |
| 369 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
| 369 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -374,59 +374,59 @@ discard block |
||
| 374 | 374 | */ |
| 375 | 375 | public function payment_fields() { |
| 376 | 376 | $user = wp_get_current_user(); |
| 377 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 377 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 378 | 378 | $total = WC()->cart->total; |
| 379 | 379 | $user_email = ''; |
| 380 | 380 | |
| 381 | 381 | // If paying from order, we need to get total from order not cart. |
| 382 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 383 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 382 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 383 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 384 | 384 | $total = $order->get_total(); |
| 385 | 385 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
| 386 | 386 | } else { |
| 387 | - if ( $user->ID ) { |
|
| 388 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 387 | + if ($user->ID) { |
|
| 388 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 389 | 389 | $user_email = $user_email ? $user_email : $user->user_email; |
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - if ( is_add_payment_method_page() ) { |
|
| 394 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
| 395 | - $total = ''; |
|
| 393 | + if (is_add_payment_method_page()) { |
|
| 394 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
| 395 | + $total = ''; |
|
| 396 | 396 | } else { |
| 397 | 397 | $pay_button_text = ''; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | echo '<div |
| 401 | 401 | id="stripe-payment-data" |
| 402 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
| 402 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
| 403 | 403 | data-description="" |
| 404 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 405 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 406 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
| 407 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 408 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
| 409 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
| 410 | - data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', substr( get_locale(), 0, 2 ) ) ) . '" |
|
| 411 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
| 412 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
| 413 | - |
|
| 414 | - if ( $this->description ) { |
|
| 415 | - if ( $this->testmode ) { |
|
| 404 | + data-email="' . esc_attr($user_email) . '" |
|
| 405 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 406 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
| 407 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 408 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
| 409 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
| 410 | + data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', substr(get_locale(), 0, 2))) . '" |
|
| 411 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
| 412 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
| 413 | + |
|
| 414 | + if ($this->description) { |
|
| 415 | + if ($this->testmode) { |
|
| 416 | 416 | /* translators: link to Stripe testing page */ |
| 417 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
| 418 | - $this->description = trim( $this->description ); |
|
| 417 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
| 418 | + $this->description = trim($this->description); |
|
| 419 | 419 | } |
| 420 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 420 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - if ( $display_tokenization ) { |
|
| 423 | + if ($display_tokenization) { |
|
| 424 | 424 | $this->tokenization_script(); |
| 425 | 425 | $this->saved_payment_methods(); |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - if ( ! $this->stripe_checkout ) { |
|
| 429 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
| 428 | + if ( ! $this->stripe_checkout) { |
|
| 429 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
| 430 | 430 | $this->elements_form(); |
| 431 | 431 | } else { |
| 432 | 432 | $this->form(); |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
| 437 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
| 438 | 438 | $this->save_payment_method_checkbox(); |
| 439 | 439 | } |
| 440 | 440 | |
@@ -449,12 +449,12 @@ discard block |
||
| 449 | 449 | */ |
| 450 | 450 | public function elements_form() { |
| 451 | 451 | ?> |
| 452 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 453 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
| 452 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 453 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
| 454 | 454 | |
| 455 | - <?php if ( $this->inline_cc_form ) { ?> |
|
| 455 | + <?php if ($this->inline_cc_form) { ?> |
|
| 456 | 456 | <label for="card-element"> |
| 457 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
| 457 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
| 458 | 458 | </label> |
| 459 | 459 | |
| 460 | 460 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | </div> |
| 463 | 463 | <?php } else { ?> |
| 464 | 464 | <div class="form-row form-row-wide"> |
| 465 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 465 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 466 | 466 | |
| 467 | 467 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
| 468 | 468 | <!-- a Stripe Element will be inserted here. --> |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | </div> |
| 471 | 471 | |
| 472 | 472 | <div class="form-row form-row-first"> |
| 473 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 473 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 474 | 474 | |
| 475 | 475 | <div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
| 476 | 476 | <!-- a Stripe Element will be inserted here. --> |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | </div> |
| 479 | 479 | |
| 480 | 480 | <div class="form-row form-row-last"> |
| 481 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 481 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 482 | 482 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
| 483 | 483 | <!-- a Stripe Element will be inserted here. --> |
| 484 | 484 | </div> |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | |
| 489 | 489 | <!-- Used to display form errors --> |
| 490 | 490 | <div class="stripe-source-errors" role="alert"></div> |
| 491 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
| 491 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
| 492 | 492 | <div class="clear"></div> |
| 493 | 493 | </fieldset> |
| 494 | 494 | <?php |
@@ -501,13 +501,13 @@ discard block |
||
| 501 | 501 | * @version 3.1.0 |
| 502 | 502 | */ |
| 503 | 503 | public function admin_scripts() { |
| 504 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
| 504 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
| 505 | 505 | return; |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 508 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 509 | 509 | |
| 510 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
| 510 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -519,29 +519,29 @@ discard block |
||
| 519 | 519 | * @version 4.0.0 |
| 520 | 520 | */ |
| 521 | 521 | public function payment_scripts() { |
| 522 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
| 522 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
| 523 | 523 | return; |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 526 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 527 | 527 | |
| 528 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
| 529 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 530 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
| 531 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
| 532 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 533 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 528 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
| 529 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 530 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
| 531 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
| 532 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 533 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 534 | 534 | |
| 535 | 535 | $stripe_params = array( |
| 536 | 536 | 'key' => $this->publishable_key, |
| 537 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 538 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 537 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 538 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 539 | 539 | ); |
| 540 | 540 | |
| 541 | 541 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 542 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
| 543 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
| 544 | - $order = wc_get_order( $order_id ); |
|
| 542 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
| 543 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
| 544 | + $order = wc_get_order($order_id); |
|
| 545 | 545 | |
| 546 | 546 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 547 | 547 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -553,38 +553,38 @@ discard block |
||
| 553 | 553 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
| 557 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
| 558 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
| 559 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
| 560 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 556 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
| 557 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
| 558 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
| 559 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
| 560 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 561 | 561 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
| 562 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
| 563 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
| 562 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
| 563 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
| 564 | 564 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
| 565 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
| 566 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
| 565 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
| 566 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
| 567 | 567 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
| 568 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
| 569 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
| 568 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
| 569 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
| 570 | 570 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
| 571 | - $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; |
|
| 572 | - $stripe_params['validate_modal_checkout'] = apply_filters( 'wc_stripe_validate_model_checkout', true ) ? 'yes' : 'no'; |
|
| 573 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
| 574 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
| 571 | + $stripe_params['is_change_payment_page'] = isset($_GET['change_payment_method']) ? 'yes' : 'no'; |
|
| 572 | + $stripe_params['validate_modal_checkout'] = apply_filters('wc_stripe_validate_model_checkout', true) ? 'yes' : 'no'; |
|
| 573 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
| 574 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
| 575 | 575 | |
| 576 | 576 | // merge localized messages to be use in JS |
| 577 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
| 577 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
| 578 | 578 | |
| 579 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 580 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 579 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 580 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 581 | 581 | |
| 582 | - if ( $this->stripe_checkout ) { |
|
| 583 | - wp_enqueue_script( 'stripe_checkout' ); |
|
| 582 | + if ($this->stripe_checkout) { |
|
| 583 | + wp_enqueue_script('stripe_checkout'); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | $this->tokenization_script(); |
| 587 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 587 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -600,43 +600,43 @@ discard block |
||
| 600 | 600 | * |
| 601 | 601 | * @return array|void |
| 602 | 602 | */ |
| 603 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 603 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 604 | 604 | try { |
| 605 | - $order = wc_get_order( $order_id ); |
|
| 605 | + $order = wc_get_order($order_id); |
|
| 606 | 606 | |
| 607 | 607 | // This comes from the create account checkbox in the checkout page. |
| 608 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 608 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 609 | 609 | |
| 610 | - if ( $create_account ) { |
|
| 610 | + if ($create_account) { |
|
| 611 | 611 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 612 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 612 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 613 | 613 | $new_stripe_customer->create_customer(); |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | $source_object = $this->get_source_object(); |
| 617 | - $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source ); |
|
| 617 | + $prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source); |
|
| 618 | 618 | |
| 619 | 619 | // Check if we don't allow prepaid credit cards. |
| 620 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
| 621 | - if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
| 622 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
| 623 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
| 620 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
| 621 | + if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
| 622 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
| 623 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | - if ( empty( $prepared_source->source ) ) { |
|
| 628 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 629 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 627 | + if (empty($prepared_source->source)) { |
|
| 628 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 629 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - $this->save_source_to_order( $order, $prepared_source ); |
|
| 632 | + $this->save_source_to_order($order, $prepared_source); |
|
| 633 | 633 | |
| 634 | 634 | // Result from Stripe API request. |
| 635 | 635 | $response = null; |
| 636 | 636 | |
| 637 | - if ( $order->get_total() > 0 ) { |
|
| 637 | + if ($order->get_total() > 0) { |
|
| 638 | 638 | // This will throw exception if not valid. |
| 639 | - $this->validate_minimum_order_amount( $order ); |
|
| 639 | + $this->validate_minimum_order_amount($order); |
|
| 640 | 640 | |
| 641 | 641 | /* |
| 642 | 642 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -645,109 +645,109 @@ discard block |
||
| 645 | 645 | * Note that if we need to save source, the original source must be first |
| 646 | 646 | * attached to a customer in Stripe before it can be charged. |
| 647 | 647 | */ |
| 648 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
| 649 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
| 648 | + if ($this->is_3ds_required($source_object)) { |
|
| 649 | + $response = $this->create_3ds_source($order, $source_object); |
|
| 650 | 650 | |
| 651 | - if ( ! empty( $response->error ) ) { |
|
| 651 | + if ( ! empty($response->error)) { |
|
| 652 | 652 | $localized_message = $response->error->message; |
| 653 | 653 | |
| 654 | - $order->add_order_note( $localized_message ); |
|
| 654 | + $order->add_order_note($localized_message); |
|
| 655 | 655 | |
| 656 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 656 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | // Update order meta with 3DS source. |
| 660 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 661 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 660 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 661 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 662 | 662 | } else { |
| 663 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 663 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 664 | 664 | $order->save(); |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
| 667 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
| 668 | 668 | |
| 669 | 669 | return array( |
| 670 | 670 | 'result' => 'success', |
| 671 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 671 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 672 | 672 | ); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 675 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 676 | 676 | |
| 677 | 677 | // Make the request. |
| 678 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
| 678 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
| 679 | 679 | |
| 680 | - if ( ! empty( $response->error ) ) { |
|
| 680 | + if ( ! empty($response->error)) { |
|
| 681 | 681 | // If it is an API error such connection or server, let's retry. |
| 682 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
| 683 | - if ( $retry ) { |
|
| 684 | - sleep( 5 ); |
|
| 685 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 682 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
| 683 | + if ($retry) { |
|
| 684 | + sleep(5); |
|
| 685 | + return $this->process_payment($order_id, false, $force_save_source); |
|
| 686 | 686 | } else { |
| 687 | 687 | $localized_message = 'API connection error and retries exhausted.'; |
| 688 | - $order->add_order_note( $localized_message ); |
|
| 689 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 688 | + $order->add_order_note($localized_message); |
|
| 689 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | // We want to retry. |
| 694 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
| 695 | - if ( $retry ) { |
|
| 694 | + if ($this->is_retryable_error($response->error)) { |
|
| 695 | + if ($retry) { |
|
| 696 | 696 | // Don't do anymore retries after this. |
| 697 | - if ( 5 <= $this->retry_interval ) { |
|
| 697 | + if (5 <= $this->retry_interval) { |
|
| 698 | 698 | |
| 699 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 699 | + return $this->process_payment($order_id, false, $force_save_source); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - sleep( $this->retry_interval ); |
|
| 702 | + sleep($this->retry_interval); |
|
| 703 | 703 | |
| 704 | 704 | $this->retry_interval++; |
| 705 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
| 705 | + return $this->process_payment($order_id, true, $force_save_source); |
|
| 706 | 706 | } else { |
| 707 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
| 708 | - $order->add_order_note( $localized_message ); |
|
| 709 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 707 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
| 708 | + $order->add_order_note($localized_message); |
|
| 709 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 710 | 710 | } |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 714 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
| 715 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 716 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 717 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 714 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
| 715 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 716 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
| 717 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 718 | 718 | } else { |
| 719 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 720 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 719 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
| 720 | + $order->delete_meta_data('_stripe_customer_id'); |
|
| 721 | 721 | $order->save(); |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 725 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
| 724 | + return $this->process_payment($order_id, false, $force_save_source); |
|
| 725 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
| 726 | 726 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 727 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
| 727 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
| 728 | 728 | $wc_token->delete(); |
| 729 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 730 | - $order->add_order_note( $localized_message ); |
|
| 731 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 729 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 730 | + $order->add_order_note($localized_message); |
|
| 731 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 735 | 735 | |
| 736 | - if ( 'card_error' === $response->error->type ) { |
|
| 737 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 736 | + if ('card_error' === $response->error->type) { |
|
| 737 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 738 | 738 | } else { |
| 739 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 739 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | - $order->add_order_note( $localized_message ); |
|
| 742 | + $order->add_order_note($localized_message); |
|
| 743 | 743 | |
| 744 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 744 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 747 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
| 748 | 748 | |
| 749 | 749 | // Process valid response. |
| 750 | - $this->process_response( $response, $order ); |
|
| 750 | + $this->process_response($response, $order); |
|
| 751 | 751 | } else { |
| 752 | 752 | $order->payment_complete(); |
| 753 | 753 | } |
@@ -758,17 +758,17 @@ discard block |
||
| 758 | 758 | // Return thank you page redirect. |
| 759 | 759 | return array( |
| 760 | 760 | 'result' => 'success', |
| 761 | - 'redirect' => $this->get_return_url( $order ), |
|
| 761 | + 'redirect' => $this->get_return_url($order), |
|
| 762 | 762 | ); |
| 763 | 763 | |
| 764 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 765 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 766 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 764 | + } catch (WC_Stripe_Exception $e) { |
|
| 765 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 766 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 767 | 767 | |
| 768 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 768 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 769 | 769 | |
| 770 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 771 | - $this->send_failed_order_email( $order_id ); |
|
| 770 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 771 | + $this->send_failed_order_email($order_id); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -23,12 +23,12 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | $this->retry_interval = 2; |
| 25 | 25 | |
| 26 | - add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) ); |
|
| 27 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
| 28 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
| 29 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
| 30 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
| 31 | - add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) ); |
|
| 26 | + add_action('wp', array($this, 'maybe_process_redirect_order')); |
|
| 27 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
| 28 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
| 29 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
| 30 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
| 31 | + add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout')); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -49,25 +49,25 @@ discard block |
||
| 49 | 49 | * @since 4.0.0 |
| 50 | 50 | * @version 4.0.0 |
| 51 | 51 | */ |
| 52 | - public function process_redirect_payment( $order_id, $retry = true ) { |
|
| 52 | + public function process_redirect_payment($order_id, $retry = true) { |
|
| 53 | 53 | try { |
| 54 | - $source = wc_clean( $_GET['source'] ); |
|
| 54 | + $source = wc_clean($_GET['source']); |
|
| 55 | 55 | |
| 56 | - if ( empty( $source ) ) { |
|
| 56 | + if (empty($source)) { |
|
| 57 | 57 | return; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if ( empty( $order_id ) ) { |
|
| 60 | + if (empty($order_id)) { |
|
| 61 | 61 | return; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $order = wc_get_order( $order_id ); |
|
| 64 | + $order = wc_get_order($order_id); |
|
| 65 | 65 | |
| 66 | - if ( ! is_object( $order ) ) { |
|
| 66 | + if ( ! is_object($order)) { |
|
| 67 | 67 | return; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) { |
|
| 70 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) { |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -75,127 +75,127 @@ discard block |
||
| 75 | 75 | $response = null; |
| 76 | 76 | |
| 77 | 77 | // This will throw exception if not valid. |
| 78 | - $this->validate_minimum_order_amount( $order ); |
|
| 78 | + $this->validate_minimum_order_amount($order); |
|
| 79 | 79 | |
| 80 | - WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 80 | + WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * First check if the source is chargeable at this time. If not, |
| 84 | 84 | * webhook will take care of it later. |
| 85 | 85 | */ |
| 86 | - $source_info = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
| 86 | + $source_info = WC_Stripe_API::retrieve('sources/' . $source); |
|
| 87 | 87 | |
| 88 | - if ( ! empty( $source_info->error ) ) { |
|
| 89 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message ); |
|
| 88 | + if ( ! empty($source_info->error)) { |
|
| 89 | + throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) { |
|
| 93 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) ); |
|
| 92 | + if ('failed' === $source_info->status || 'canceled' === $source_info->status) { |
|
| 93 | + throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // If already consumed, then ignore request. |
| 97 | - if ( 'consumed' === $source_info->status ) { |
|
| 97 | + if ('consumed' === $source_info->status) { |
|
| 98 | 98 | return; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // If not chargeable, then ignore request. |
| 102 | - if ( 'chargeable' !== $source_info->status ) { |
|
| 102 | + if ('chargeable' !== $source_info->status) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Prep source object. |
| 107 | 107 | $source_object = new stdClass(); |
| 108 | 108 | $source_object->token_id = ''; |
| 109 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
| 109 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
| 110 | 110 | $source_object->source = $source_info->id; |
| 111 | 111 | |
| 112 | 112 | // Make the request. |
| 113 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
| 113 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
| 114 | 114 | |
| 115 | - if ( ! empty( $response->error ) ) { |
|
| 115 | + if ( ! empty($response->error)) { |
|
| 116 | 116 | // If it is an API error such connection or server, let's retry. |
| 117 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
| 118 | - if ( $retry ) { |
|
| 119 | - sleep( 5 ); |
|
| 120 | - return $this->process_redirect_payment( $order_id, false ); |
|
| 117 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
| 118 | + if ($retry) { |
|
| 119 | + sleep(5); |
|
| 120 | + return $this->process_redirect_payment($order_id, false); |
|
| 121 | 121 | } else { |
| 122 | - $localized_message = __( 'API connection error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
| 123 | - $order->add_order_note( $localized_message ); |
|
| 124 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 122 | + $localized_message = __('API connection error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
| 123 | + $order->add_order_note($localized_message); |
|
| 124 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // We want to retry. |
| 129 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
| 130 | - if ( $retry ) { |
|
| 129 | + if ($this->is_retryable_error($response->error)) { |
|
| 130 | + if ($retry) { |
|
| 131 | 131 | // Don't do anymore retries after this. |
| 132 | - if ( 5 <= $this->retry_interval ) { |
|
| 133 | - return $this->process_redirect_payment( $order_id, false ); |
|
| 132 | + if (5 <= $this->retry_interval) { |
|
| 133 | + return $this->process_redirect_payment($order_id, false); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - sleep( $this->retry_interval ); |
|
| 136 | + sleep($this->retry_interval); |
|
| 137 | 137 | |
| 138 | 138 | $this->retry_interval++; |
| 139 | - return $this->process_redirect_payment( $order_id, true ); |
|
| 139 | + return $this->process_redirect_payment($order_id, true); |
|
| 140 | 140 | } else { |
| 141 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
| 142 | - $order->add_order_note( $localized_message ); |
|
| 143 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 141 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
| 142 | + $order->add_order_note($localized_message); |
|
| 143 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 148 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
| 149 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 150 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 151 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 148 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
| 149 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 150 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
| 151 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 152 | 152 | } else { |
| 153 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 154 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 153 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
| 154 | + $order->delete_meta_data('_stripe_customer_id'); |
|
| 155 | 155 | $order->save(); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - return $this->process_redirect_payment( $order_id, false ); |
|
| 158 | + return $this->process_redirect_payment($order_id, false); |
|
| 159 | 159 | |
| 160 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
| 160 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
| 161 | 161 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 162 | 162 | |
| 163 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
| 163 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
| 164 | 164 | $wc_token->delete(); |
| 165 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 166 | - $order->add_order_note( $message ); |
|
| 167 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
| 165 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 166 | + $order->add_order_note($message); |
|
| 167 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 171 | 171 | |
| 172 | - if ( 'card_error' === $response->error->type ) { |
|
| 173 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 172 | + if ('card_error' === $response->error->type) { |
|
| 173 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 174 | 174 | } else { |
| 175 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 175 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
| 178 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
| 181 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
| 182 | 182 | |
| 183 | - $this->process_response( $response, $order ); |
|
| 183 | + $this->process_response($response, $order); |
|
| 184 | 184 | |
| 185 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 186 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 185 | + } catch (WC_Stripe_Exception $e) { |
|
| 186 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 187 | 187 | |
| 188 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
| 188 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
| 189 | 189 | |
| 190 | 190 | /* translators: error message */ |
| 191 | - $order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) ); |
|
| 191 | + $order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage())); |
|
| 192 | 192 | |
| 193 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 194 | - $this->send_failed_order_email( $order_id ); |
|
| 193 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 194 | + $this->send_failed_order_email($order_id); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 198 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
| 197 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 198 | + wp_safe_redirect(wc_get_checkout_url()); |
|
| 199 | 199 | exit; |
| 200 | 200 | } |
| 201 | 201 | } |
@@ -207,13 +207,13 @@ discard block |
||
| 207 | 207 | * @version 4.0.0 |
| 208 | 208 | */ |
| 209 | 209 | public function maybe_process_redirect_order() { |
| 210 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) { |
|
| 210 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) { |
|
| 211 | 211 | return; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
| 214 | + $order_id = wc_clean($_GET['order_id']); |
|
| 215 | 215 | |
| 216 | - $this->process_redirect_payment( $order_id ); |
|
| 216 | + $this->process_redirect_payment($order_id); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -223,52 +223,52 @@ discard block |
||
| 223 | 223 | * @version 4.0.0 |
| 224 | 224 | * @param int $order_id |
| 225 | 225 | */ |
| 226 | - public function capture_payment( $order_id ) { |
|
| 227 | - $order = wc_get_order( $order_id ); |
|
| 226 | + public function capture_payment($order_id) { |
|
| 227 | + $order = wc_get_order($order_id); |
|
| 228 | 228 | |
| 229 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 230 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
| 231 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
| 229 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
| 230 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
| 231 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
| 232 | 232 | |
| 233 | - if ( $charge && 'no' === $captured ) { |
|
| 233 | + if ($charge && 'no' === $captured) { |
|
| 234 | 234 | $order_total = $order->get_total(); |
| 235 | 235 | |
| 236 | - if ( 0 < $order->get_total_refunded() ) { |
|
| 236 | + if (0 < $order->get_total_refunded()) { |
|
| 237 | 237 | $order_total = $order_total - $order->get_total_refunded(); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - $result = WC_Stripe_API::request( array( |
|
| 241 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
| 240 | + $result = WC_Stripe_API::request(array( |
|
| 241 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
| 242 | 242 | 'expand[]' => 'balance_transaction', |
| 243 | - ), 'charges/' . $charge . '/capture' ); |
|
| 243 | + ), 'charges/' . $charge . '/capture'); |
|
| 244 | 244 | |
| 245 | - if ( ! empty( $result->error ) ) { |
|
| 245 | + if ( ! empty($result->error)) { |
|
| 246 | 246 | /* translators: error message */ |
| 247 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
| 247 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
| 248 | 248 | } else { |
| 249 | 249 | /* translators: transaction id */ |
| 250 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
| 251 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
| 250 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
| 251 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
| 252 | 252 | |
| 253 | 253 | // Store other data such as fees |
| 254 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id ); |
|
| 254 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id); |
|
| 255 | 255 | |
| 256 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
| 256 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
| 257 | 257 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 258 | 258 | // values are in the local currency of the Stripe account, not from WC. |
| 259 | - $fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0; |
|
| 260 | - $net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0; |
|
| 261 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee ); |
|
| 262 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net ); |
|
| 259 | + $fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0; |
|
| 260 | + $net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0; |
|
| 261 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee); |
|
| 262 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 265 | + if (is_callable(array($order, 'save'))) { |
|
| 266 | 266 | $order->save(); |
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // This hook fires when admin manually changes order status to processing or completed. |
| 271 | - do_action( 'woocommerce_stripe_process_manual_capture', $order, $result ); |
|
| 271 | + do_action('woocommerce_stripe_process_manual_capture', $order, $result); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | } |
@@ -280,14 +280,14 @@ discard block |
||
| 280 | 280 | * @version 4.0.0 |
| 281 | 281 | * @param int $order_id |
| 282 | 282 | */ |
| 283 | - public function cancel_payment( $order_id ) { |
|
| 284 | - $order = wc_get_order( $order_id ); |
|
| 283 | + public function cancel_payment($order_id) { |
|
| 284 | + $order = wc_get_order($order_id); |
|
| 285 | 285 | |
| 286 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 287 | - $this->process_refund( $order_id ); |
|
| 286 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
| 287 | + $this->process_refund($order_id); |
|
| 288 | 288 | |
| 289 | 289 | // This hook fires when admin manually changes order status to cancel. |
| 290 | - do_action( 'woocommerce_stripe_process_manual_cancel', $order ); |
|
| 290 | + do_action('woocommerce_stripe_process_manual_cancel', $order); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
@@ -299,21 +299,21 @@ discard block |
||
| 299 | 299 | * @param string $field |
| 300 | 300 | * @return string $error_field |
| 301 | 301 | */ |
| 302 | - public function normalize_field( $field ) { |
|
| 302 | + public function normalize_field($field) { |
|
| 303 | 303 | $checkout_fields = WC()->checkout->get_checkout_fields(); |
| 304 | 304 | $org_str = array(); |
| 305 | 305 | $replace_str = array(); |
| 306 | 306 | |
| 307 | - if ( array_key_exists( $field, $checkout_fields['billing'] ) ) { |
|
| 308 | - $error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label']; |
|
| 309 | - } elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) { |
|
| 310 | - $error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label']; |
|
| 311 | - } elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) { |
|
| 312 | - $error_field = $checkout_fields['order'][ $field ]['label']; |
|
| 313 | - } elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) { |
|
| 314 | - $error_field = $checkout_fields['account'][ $field ]['label']; |
|
| 307 | + if (array_key_exists($field, $checkout_fields['billing'])) { |
|
| 308 | + $error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label']; |
|
| 309 | + } elseif (array_key_exists($field, $checkout_fields['shipping'])) { |
|
| 310 | + $error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label']; |
|
| 311 | + } elseif (array_key_exists($field, $checkout_fields['order'])) { |
|
| 312 | + $error_field = $checkout_fields['order'][$field]['label']; |
|
| 313 | + } elseif (array_key_exists($field, $checkout_fields['account'])) { |
|
| 314 | + $error_field = $checkout_fields['account'][$field]['label']; |
|
| 315 | 315 | } else { |
| 316 | - $error_field = str_replace( '_', ' ', $field ); |
|
| 316 | + $error_field = str_replace('_', ' ', $field); |
|
| 317 | 317 | |
| 318 | 318 | $org_str[] = 'stripe'; |
| 319 | 319 | $replace_str[] = ''; |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | $replace_str[] = 'SOFORT'; |
| 329 | 329 | |
| 330 | 330 | $org_str[] = 'owner'; |
| 331 | - $replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' ); |
|
| 331 | + $replace_str[] = __('Owner', 'woocommerce-gateway-stripe'); |
|
| 332 | 332 | |
| 333 | - $error_field = str_replace( $org_str, $replace_str, $error_field ); |
|
| 333 | + $error_field = str_replace($org_str, $replace_str, $error_field); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | return $error_field; |
@@ -343,135 +343,135 @@ discard block |
||
| 343 | 343 | * @version 4.0.0 |
| 344 | 344 | */ |
| 345 | 345 | public function validate_checkout() { |
| 346 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) { |
|
| 347 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 346 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) { |
|
| 347 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - parse_str( $_POST['required_fields'], $required_fields ); |
|
| 351 | - parse_str( $_POST['all_fields'], $all_fields ); |
|
| 350 | + parse_str($_POST['required_fields'], $required_fields); |
|
| 351 | + parse_str($_POST['all_fields'], $all_fields); |
|
| 352 | 352 | $validate_shipping_fields = false; |
| 353 | 353 | $create_account = false; |
| 354 | 354 | $errors = new WP_Error(); |
| 355 | - $all_fields = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields ); |
|
| 356 | - $required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields ); |
|
| 355 | + $all_fields = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields); |
|
| 356 | + $required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields); |
|
| 357 | 357 | |
| 358 | - array_walk_recursive( $required_fields, 'wc_clean' ); |
|
| 359 | - array_walk_recursive( $all_fields, 'wc_clean' ); |
|
| 358 | + array_walk_recursive($required_fields, 'wc_clean'); |
|
| 359 | + array_walk_recursive($all_fields, 'wc_clean'); |
|
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | 362 | * If ship to different address checkbox is checked then we need |
| 363 | 363 | * to validate shipping fields too. |
| 364 | 364 | */ |
| 365 | - if ( isset( $all_fields['ship_to_different_address'] ) ) { |
|
| 365 | + if (isset($all_fields['ship_to_different_address'])) { |
|
| 366 | 366 | $validate_shipping_fields = true; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | // Check if createaccount is checked. |
| 370 | - if ( isset( $all_fields['createaccount'] ) ) { |
|
| 370 | + if (isset($all_fields['createaccount'])) { |
|
| 371 | 371 | $create_account = true; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // Check if required fields are empty. |
| 375 | - foreach ( $required_fields as $field => $field_value ) { |
|
| 375 | + foreach ($required_fields as $field => $field_value) { |
|
| 376 | 376 | // Check for shipping field. |
| 377 | - if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) { |
|
| 377 | + if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) { |
|
| 378 | 378 | continue; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | // Check create account name. |
| 382 | - if ( 'account_username' === $field && ! $create_account ) { |
|
| 382 | + if ('account_username' === $field && ! $create_account) { |
|
| 383 | 383 | continue; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | // Check create account password. |
| 387 | - if ( 'account_password' === $field && ! $create_account ) { |
|
| 387 | + if ('account_password' === $field && ! $create_account) { |
|
| 388 | 388 | continue; |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - if ( empty( $field_value ) || '-1' === $field_value ) { |
|
| 392 | - $error_field = $this->normalize_field( $field ); |
|
| 391 | + if (empty($field_value) || '-1' === $field_value) { |
|
| 392 | + $error_field = $this->normalize_field($field); |
|
| 393 | 393 | /* translators: error field name */ |
| 394 | - $errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) ); |
|
| 394 | + $errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field)); |
|
| 395 | 395 | } |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | // Check if email is valid format. |
| 399 | - if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) { |
|
| 400 | - $errors->add( 'validation', __( '<strong>Billing Email</strong> is not valid', 'woocommerce-gateway-stripe' ) ); |
|
| 399 | + if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) { |
|
| 400 | + $errors->add('validation', __('<strong>Billing Email</strong> is not valid', 'woocommerce-gateway-stripe')); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | // Check if phone number is valid format. |
| 404 | - if ( ! empty( $required_fields['billing_phone'] ) ) { |
|
| 405 | - $phone = wc_format_phone_number( $required_fields['billing_phone'] ); |
|
| 404 | + if ( ! empty($required_fields['billing_phone'])) { |
|
| 405 | + $phone = wc_format_phone_number($required_fields['billing_phone']); |
|
| 406 | 406 | |
| 407 | - if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) { |
|
| 407 | + if ('' !== $phone && ! WC_Validation::is_phone($phone)) { |
|
| 408 | 408 | /* translators: %s: phone number */ |
| 409 | - $errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) ); |
|
| 409 | + $errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe')); |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | // Check if postal code is valid format. |
| 414 | - if ( ! empty( $required_fields['billing_postcode'] ) ) { |
|
| 415 | - $country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
| 416 | - $postcode = wc_format_postcode( $required_fields['billing_postcode'], $country ); |
|
| 414 | + if ( ! empty($required_fields['billing_postcode'])) { |
|
| 415 | + $country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
| 416 | + $postcode = wc_format_postcode($required_fields['billing_postcode'], $country); |
|
| 417 | 417 | |
| 418 | - if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 419 | - $errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
| 418 | + if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
| 419 | + $errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) { |
|
| 423 | + if (WC()->cart->needs_shipping() && $validate_shipping_fields) { |
|
| 424 | 424 | // Check if postal code is valid format. |
| 425 | - if ( ! empty( $required_fields['shipping_postcode'] ) ) { |
|
| 426 | - $country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
| 427 | - $postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country ); |
|
| 425 | + if ( ! empty($required_fields['shipping_postcode'])) { |
|
| 426 | + $country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
| 427 | + $postcode = wc_format_postcode($required_fields['shipping_postcode'], $country); |
|
| 428 | 428 | |
| 429 | - if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 430 | - $errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
| 429 | + if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
| 430 | + $errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - if ( WC()->cart->needs_shipping() ) { |
|
| 435 | + if (WC()->cart->needs_shipping()) { |
|
| 436 | 436 | $shipping_country = WC()->customer->get_shipping_country(); |
| 437 | 437 | |
| 438 | - if ( empty( $shipping_country ) ) { |
|
| 439 | - $errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) ); |
|
| 440 | - } elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) { |
|
| 438 | + if (empty($shipping_country)) { |
|
| 439 | + $errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe')); |
|
| 440 | + } elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { |
|
| 441 | 441 | /* translators: country name */ |
| 442 | - $errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) ); |
|
| 442 | + $errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country())); |
|
| 443 | 443 | } else { |
| 444 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
| 444 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
| 445 | 445 | |
| 446 | - foreach ( WC()->shipping->get_packages() as $i => $package ) { |
|
| 447 | - if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) { |
|
| 448 | - $errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) ); |
|
| 446 | + foreach (WC()->shipping->get_packages() as $i => $package) { |
|
| 447 | + if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) { |
|
| 448 | + $errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe')); |
|
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | } |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | - if ( WC()->cart->needs_payment() ) { |
|
| 454 | + if (WC()->cart->needs_payment()) { |
|
| 455 | 455 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 456 | 456 | |
| 457 | - if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) { |
|
| 458 | - $errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) ); |
|
| 457 | + if ( ! isset($available_gateways[$all_fields['payment_method']])) { |
|
| 458 | + $errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe')); |
|
| 459 | 459 | } else { |
| 460 | - $available_gateways[ $all_fields['payment_method'] ]->validate_fields(); |
|
| 460 | + $available_gateways[$all_fields['payment_method']]->validate_fields(); |
|
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) { |
|
| 465 | - $errors->add( 'terms', __( 'You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe' ) ); |
|
| 464 | + if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) { |
|
| 465 | + $errors->add('terms', __('You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe')); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - do_action( 'wc_stripe_validate_checkout', $required_fields, $all_fields, $errors ); |
|
| 468 | + do_action('wc_stripe_validate_checkout', $required_fields, $all_fields, $errors); |
|
| 469 | 469 | |
| 470 | - if ( 0 === count( $errors->errors ) ) { |
|
| 471 | - wp_send_json( 'success' ); |
|
| 470 | + if (0 === count($errors->errors)) { |
|
| 471 | + wp_send_json('success'); |
|
| 472 | 472 | } else { |
| 473 | - foreach ( $errors->get_error_messages() as $message ) { |
|
| 474 | - wc_add_notice( $message, 'error' ); |
|
| 473 | + foreach ($errors->get_error_messages() as $message) { |
|
| 474 | + wc_add_notice($message, 'error'); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | $this->send_ajax_failure_response(); |
@@ -485,9 +485,9 @@ discard block |
||
| 485 | 485 | * @version 4.0.0 |
| 486 | 486 | */ |
| 487 | 487 | public function send_ajax_failure_response() { |
| 488 | - if ( is_ajax() ) { |
|
| 488 | + if (is_ajax()) { |
|
| 489 | 489 | // only print notices if not reloading the checkout, otherwise they're lost in the page reload. |
| 490 | - if ( ! isset( WC()->session->reload_checkout ) ) { |
|
| 490 | + if ( ! isset(WC()->session->reload_checkout)) { |
|
| 491 | 491 | ob_start(); |
| 492 | 492 | wc_print_notices(); |
| 493 | 493 | $messages = ob_get_clean(); |
@@ -495,14 +495,14 @@ discard block |
||
| 495 | 495 | |
| 496 | 496 | $response = array( |
| 497 | 497 | 'result' => 'failure', |
| 498 | - 'messages' => isset( $messages ) ? $messages : '', |
|
| 499 | - 'refresh' => isset( WC()->session->refresh_totals ), |
|
| 500 | - 'reload' => isset( WC()->session->reload_checkout ), |
|
| 498 | + 'messages' => isset($messages) ? $messages : '', |
|
| 499 | + 'refresh' => isset(WC()->session->refresh_totals), |
|
| 500 | + 'reload' => isset(WC()->session->reload_checkout), |
|
| 501 | 501 | ); |
| 502 | 502 | |
| 503 | - unset( WC()->session->refresh_totals, WC()->session->reload_checkout ); |
|
| 503 | + unset(WC()->session->refresh_totals, WC()->session->reload_checkout); |
|
| 504 | 504 | |
| 505 | - wp_send_json( $response ); |
|
| 505 | + wp_send_json($response); |
|
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | 508 | } |