@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_ideal'; |
| 60 | - $this->method_title = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | * @return array |
| 99 | 99 | */ |
| 100 | 100 | public function get_supported_currency() { |
| 101 | - return apply_filters( 'wc_stripe_ideal_supported_currencies', array( |
|
| 101 | + return apply_filters('wc_stripe_ideal_supported_currencies', array( |
|
| 102 | 102 | 'EUR', |
| 103 | - ) ); |
|
| 103 | + )); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @return bool |
| 112 | 112 | */ |
| 113 | 113 | public function is_available() { |
| 114 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 114 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 115 | 115 | return false; |
| 116 | 116 | } |
| 117 | 117 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | $icons_str .= $icons['ideal']; |
| 134 | 134 | |
| 135 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 135 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -143,19 +143,19 @@ discard block |
||
| 143 | 143 | * @access public |
| 144 | 144 | */ |
| 145 | 145 | public function payment_scripts() { |
| 146 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 146 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - wp_enqueue_style( 'stripe_styles' ); |
|
| 151 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 150 | + wp_enqueue_style('stripe_styles'); |
|
| 151 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | 155 | * Initialize Gateway Settings Form Fields. |
| 156 | 156 | */ |
| 157 | 157 | public function init_form_fields() { |
| 158 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' ); |
|
| 158 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php'); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -167,25 +167,25 @@ discard block |
||
| 167 | 167 | $description = $this->get_description(); |
| 168 | 168 | |
| 169 | 169 | // If paying from order, we need to get total from order not cart. |
| 170 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 171 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 170 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 171 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 172 | 172 | $total = $order->get_total(); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - if ( is_add_payment_method_page() ) { |
|
| 176 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 177 | - $total = ''; |
|
| 175 | + if (is_add_payment_method_page()) { |
|
| 176 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 177 | + $total = ''; |
|
| 178 | 178 | } else { |
| 179 | 179 | $pay_button_text = ''; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | echo '<div |
| 183 | 183 | id="stripe-ideal-payment-data" |
| 184 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 185 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 184 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 185 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 186 | 186 | |
| 187 | - if ( $description ) { |
|
| 188 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
| 187 | + if ($description) { |
|
| 188 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | echo '</div>'; |
@@ -199,24 +199,24 @@ discard block |
||
| 199 | 199 | * @param object $order |
| 200 | 200 | * @return mixed |
| 201 | 201 | */ |
| 202 | - public function create_source( $order ) { |
|
| 203 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
| 204 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 205 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 202 | + public function create_source($order) { |
|
| 203 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
| 204 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 205 | + $return_url = $this->get_stripe_return_url($order); |
|
| 206 | 206 | $post_data = array(); |
| 207 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 208 | - $post_data['currency'] = strtolower( $currency ); |
|
| 207 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 208 | + $post_data['currency'] = strtolower($currency); |
|
| 209 | 209 | $post_data['type'] = 'ideal'; |
| 210 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 211 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 210 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 211 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 212 | 212 | |
| 213 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 214 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 213 | + if ( ! empty($this->statement_descriptor)) { |
|
| 214 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' ); |
|
| 217 | + WC_Stripe_Logger::log('Info: Begin creating iDeal source'); |
|
| 218 | 218 | |
| 219 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_ideal_source', $post_data, $order ), 'sources' ); |
|
| 219 | + return WC_Stripe_API::request(apply_filters('wc_stripe_ideal_source', $post_data, $order), 'sources'); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -230,51 +230,51 @@ discard block |
||
| 230 | 230 | * |
| 231 | 231 | * @return array|void |
| 232 | 232 | */ |
| 233 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 233 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 234 | 234 | try { |
| 235 | - $order = wc_get_order( $order_id ); |
|
| 235 | + $order = wc_get_order($order_id); |
|
| 236 | 236 | |
| 237 | 237 | // This will throw exception if not valid. |
| 238 | - $this->validate_minimum_order_amount( $order ); |
|
| 238 | + $this->validate_minimum_order_amount($order); |
|
| 239 | 239 | |
| 240 | 240 | // This comes from the create account checkbox in the checkout page. |
| 241 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 241 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 242 | 242 | |
| 243 | - if ( $create_account ) { |
|
| 244 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
| 245 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 243 | + if ($create_account) { |
|
| 244 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
| 245 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 246 | 246 | $new_stripe_customer->create_customer(); |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $response = $this->create_source( $order ); |
|
| 249 | + $response = $this->create_source($order); |
|
| 250 | 250 | |
| 251 | - if ( ! empty( $response->error ) ) { |
|
| 252 | - $order->add_order_note( $response->error->message ); |
|
| 251 | + if ( ! empty($response->error)) { |
|
| 252 | + $order->add_order_note($response->error->message); |
|
| 253 | 253 | |
| 254 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 254 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 258 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 257 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 258 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 259 | 259 | } else { |
| 260 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 260 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 261 | 261 | $order->save(); |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' ); |
|
| 264 | + WC_Stripe_Logger::log('Info: Redirecting to iDeal...'); |
|
| 265 | 265 | |
| 266 | 266 | return array( |
| 267 | 267 | 'result' => 'success', |
| 268 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 268 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 269 | 269 | ); |
| 270 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 271 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 272 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 270 | + } catch (WC_Stripe_Exception $e) { |
|
| 271 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 272 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 273 | 273 | |
| 274 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 274 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 275 | 275 | |
| 276 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 277 | - $this->send_failed_order_email( $order_id ); |
|
| 276 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 277 | + $this->send_failed_order_email($order_id); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | 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 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | public $saved_cards; |
| 12 | 12 | |
| 13 | 13 | public function __construct() { |
| 14 | - $this->saved_cards = WC_Stripe_Helper::get_settings( 'stripe', 'saved_cards' ); |
|
| 14 | + $this->saved_cards = WC_Stripe_Helper::get_settings('stripe', 'saved_cards'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -19,68 +19,68 @@ discard block |
||
| 19 | 19 | * @param int $order_id |
| 20 | 20 | * @return boolean |
| 21 | 21 | */ |
| 22 | - public function is_pre_order( $order_id ) { |
|
| 23 | - return WC_Pre_Orders_Order::order_contains_pre_order( $order_id ); |
|
| 22 | + public function is_pre_order($order_id) { |
|
| 23 | + return WC_Pre_Orders_Order::order_contains_pre_order($order_id); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Remove order meta |
| 28 | 28 | * @param object $order |
| 29 | 29 | */ |
| 30 | - public function remove_order_source_before_retry( $order ) { |
|
| 31 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 32 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
| 30 | + public function remove_order_source_before_retry($order) { |
|
| 31 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 32 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
| 33 | 33 | // For BW compat will remove in the future. |
| 34 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 34 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Remove order meta |
| 39 | 39 | * @param object $order |
| 40 | 40 | */ |
| 41 | - public function remove_order_customer_before_retry( $order ) { |
|
| 42 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 43 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 41 | + public function remove_order_customer_before_retry($order) { |
|
| 42 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 43 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * Process the pre-order when pay upon release is used. |
| 48 | 48 | * @param int $order_id |
| 49 | 49 | */ |
| 50 | - public function process_pre_order( $order_id ) { |
|
| 50 | + public function process_pre_order($order_id) { |
|
| 51 | 51 | try { |
| 52 | - $order = wc_get_order( $order_id ); |
|
| 52 | + $order = wc_get_order($order_id); |
|
| 53 | 53 | |
| 54 | 54 | // This will throw exception if not valid. |
| 55 | - $this->validate_minimum_order_amount( $order ); |
|
| 55 | + $this->validate_minimum_order_amount($order); |
|
| 56 | 56 | |
| 57 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
| 57 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
| 58 | 58 | |
| 59 | 59 | // We need a source on file to continue. |
| 60 | - if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) { |
|
| 61 | - throw new WC_Stripe_Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 60 | + if (empty($prepared_source->customer) || empty($prepared_source->source)) { |
|
| 61 | + throw new WC_Stripe_Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $this->save_source_to_order( $order, $prepared_source ); |
|
| 64 | + $this->save_source_to_order($order, $prepared_source); |
|
| 65 | 65 | |
| 66 | 66 | // Remove cart |
| 67 | 67 | WC()->cart->empty_cart(); |
| 68 | 68 | |
| 69 | 69 | // Is pre ordered! |
| 70 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 70 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 71 | 71 | |
| 72 | 72 | // Return thank you page redirect |
| 73 | 73 | return array( |
| 74 | 74 | 'result' => 'success', |
| 75 | - 'redirect' => $this->get_return_url( $order ), |
|
| 75 | + 'redirect' => $this->get_return_url($order), |
|
| 76 | 76 | ); |
| 77 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 78 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 79 | - WC_Stripe_Logger::log( 'Pre Orders Error: ' . $e->getMessage() ); |
|
| 77 | + } catch (WC_Stripe_Exception $e) { |
|
| 78 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 79 | + WC_Stripe_Logger::log('Pre Orders Error: ' . $e->getMessage()); |
|
| 80 | 80 | |
| 81 | 81 | return array( |
| 82 | 82 | 'result' => 'success', |
| 83 | - 'redirect' => $order->get_checkout_payment_url( true ), |
|
| 83 | + 'redirect' => $order->get_checkout_payment_url(true), |
|
| 84 | 84 | ); |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param WC_Order $order |
| 91 | 91 | * @return void |
| 92 | 92 | */ |
| 93 | - public function process_pre_order_release_payment( $order ) { |
|
| 93 | + public function process_pre_order_release_payment($order) { |
|
| 94 | 94 | try { |
| 95 | 95 | // Define some callbacks if the first attempt fails. |
| 96 | 96 | $retry_callbacks = array( |
@@ -98,33 +98,33 @@ discard block |
||
| 98 | 98 | 'remove_order_customer_before_retry', |
| 99 | 99 | ); |
| 100 | 100 | |
| 101 | - while ( 1 ) { |
|
| 102 | - $source = $this->prepare_order_source( $order ); |
|
| 103 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 101 | + while (1) { |
|
| 102 | + $source = $this->prepare_order_source($order); |
|
| 103 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 104 | 104 | |
| 105 | - if ( ! empty( $response->error ) ) { |
|
| 106 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 107 | - throw new Exception( $response->error->message ); |
|
| 105 | + if ( ! empty($response->error)) { |
|
| 106 | + if (0 === sizeof($retry_callbacks)) { |
|
| 107 | + throw new Exception($response->error->message); |
|
| 108 | 108 | } else { |
| 109 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 110 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 109 | + $retry_callback = array_shift($retry_callbacks); |
|
| 110 | + call_user_func(array($this, $retry_callback), $order); |
|
| 111 | 111 | } |
| 112 | 112 | } else { |
| 113 | 113 | // Successful |
| 114 | - $this->process_response( $response, $order ); |
|
| 114 | + $this->process_response($response, $order); |
|
| 115 | 115 | break; |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | - } catch ( Exception $e ) { |
|
| 118 | + } catch (Exception $e) { |
|
| 119 | 119 | /* translators: error message */ |
| 120 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 120 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 121 | 121 | |
| 122 | 122 | // Mark order as failed if not already set, |
| 123 | 123 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 124 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 125 | - $order->update_status( 'failed', $order_note ); |
|
| 124 | + if ( ! $order->has_status('failed')) { |
|
| 125 | + $order->update_status('failed', $order_note); |
|
| 126 | 126 | } else { |
| 127 | - $order->add_order_note( $order_note ); |
|
| 127 | + $order->add_order_note($order_note); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | } |