@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -17,15 +17,15 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @return float|int |
| 19 | 19 | */ |
| 20 | - public static function get_stripe_amount( $total, $currency = '' ) { |
|
| 21 | - if ( ! $currency ) { |
|
| 20 | + public static function get_stripe_amount($total, $currency = '') { |
|
| 21 | + if ( ! $currency) { |
|
| 22 | 22 | $currency = get_woocommerce_currency(); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) { |
|
| 26 | - return absint( $total ); |
|
| 25 | + if (in_array(strtolower($currency), self::no_decimal_currencies())) { |
|
| 26 | + return absint($total); |
|
| 27 | 27 | } else { |
| 28 | - return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents. |
|
| 28 | + return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents. |
|
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
@@ -37,25 +37,25 @@ discard block |
||
| 37 | 37 | * @return array |
| 38 | 38 | */ |
| 39 | 39 | public static function get_localized_messages() { |
| 40 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
| 41 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
| 42 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 43 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 44 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 45 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 46 | - 'incomplete_number' => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ), |
|
| 47 | - 'incomplete_cvc' => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ), |
|
| 48 | - 'incomplete_expiry' => __( 'The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ), |
|
| 49 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
| 50 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 51 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
| 52 | - 'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ), |
|
| 53 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
| 54 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
| 55 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
| 56 | - 'invalid_request_error' => __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ), |
|
| 57 | - 'invalid_sofort_country' => __( 'The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe' ), |
|
| 58 | - ) ); |
|
| 40 | + return apply_filters('wc_stripe_localized_messages', array( |
|
| 41 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
| 42 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
| 43 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
| 44 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
| 45 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 46 | + 'incomplete_number' => __('The card number is incomplete.', 'woocommerce-gateway-stripe'), |
|
| 47 | + 'incomplete_cvc' => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'), |
|
| 48 | + 'incomplete_expiry' => __('The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'), |
|
| 49 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
| 50 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 51 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
| 52 | + 'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'), |
|
| 53 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
| 54 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
| 55 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
| 56 | + 'invalid_request_error' => __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'), |
|
| 57 | + 'invalid_sofort_country' => __('The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe'), |
|
| 58 | + )); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -92,24 +92,24 @@ discard block |
||
| 92 | 92 | * @param string $type Type of number to format |
| 93 | 93 | * @return string |
| 94 | 94 | */ |
| 95 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
| 96 | - if ( ! is_object( $balance_transaction ) ) { |
|
| 95 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
| 96 | + if ( ! is_object($balance_transaction)) { |
|
| 97 | 97 | return; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
| 101 | - if ( 'fee' === $type ) { |
|
| 100 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
| 101 | + if ('fee' === $type) { |
|
| 102 | 102 | return $balance_transaction->fee; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | return $balance_transaction->net; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if ( 'fee' === $type ) { |
|
| 109 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
| 108 | + if ('fee' === $type) { |
|
| 109 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
| 112 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | public static function get_minimum_amount() { |
| 119 | 119 | // Check order amount |
| 120 | - switch ( get_woocommerce_currency() ) { |
|
| 120 | + switch (get_woocommerce_currency()) { |
|
| 121 | 121 | case 'USD': |
| 122 | 122 | case 'CAD': |
| 123 | 123 | case 'EUR': |
@@ -162,14 +162,14 @@ discard block |
||
| 162 | 162 | * @param string $method The payment method to get the settings from. |
| 163 | 163 | * @param string $setting The name of the setting to get. |
| 164 | 164 | */ |
| 165 | - public static function get_settings( $method = null, $setting = null ) { |
|
| 166 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
| 165 | + public static function get_settings($method = null, $setting = null) { |
|
| 166 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
| 167 | 167 | |
| 168 | - if ( null === $setting ) { |
|
| 168 | + if (null === $setting) { |
|
| 169 | 169 | return $all_settings; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
| 172 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @return bool |
| 181 | 181 | */ |
| 182 | 182 | public static function is_pre_30() { |
| 183 | - return version_compare( WC_VERSION, '3.0.0', '<' ); |
|
| 183 | + return version_compare(WC_VERSION, '3.0.0', '<'); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @return string |
| 194 | 194 | */ |
| 195 | 195 | public static function get_webhook_url() { |
| 196 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
| 196 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -203,13 +203,13 @@ discard block |
||
| 203 | 203 | * @version 4.0.0 |
| 204 | 204 | * @param string $source_id |
| 205 | 205 | */ |
| 206 | - public static function get_order_by_source_id( $source_id ) { |
|
| 206 | + public static function get_order_by_source_id($source_id) { |
|
| 207 | 207 | global $wpdb; |
| 208 | 208 | |
| 209 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id ) ); |
|
| 209 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id)); |
|
| 210 | 210 | |
| 211 | - if ( ! empty( $order_id ) ) { |
|
| 212 | - return wc_get_order( $order_id ); |
|
| 211 | + if ( ! empty($order_id)) { |
|
| 212 | + return wc_get_order($order_id); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | return false; |
@@ -222,13 +222,13 @@ discard block |
||
| 222 | 222 | * @version 4.0.0 |
| 223 | 223 | * @param string $charge_id |
| 224 | 224 | */ |
| 225 | - public static function get_order_by_charge_id( $charge_id ) { |
|
| 225 | + public static function get_order_by_charge_id($charge_id) { |
|
| 226 | 226 | global $wpdb; |
| 227 | 227 | |
| 228 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id ) ); |
|
| 228 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id)); |
|
| 229 | 229 | |
| 230 | - if ( ! empty( $order_id ) ) { |
|
| 231 | - return wc_get_order( $order_id ); |
|
| 230 | + if ( ! empty($order_id)) { |
|
| 231 | + return wc_get_order($order_id); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | return false; |
@@ -244,13 +244,13 @@ discard block |
||
| 244 | 244 | * @param string $statement_descriptor |
| 245 | 245 | * @return string $statement_descriptor Sanitized statement descriptor |
| 246 | 246 | */ |
| 247 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
| 248 | - $disallowed_characters = array( '<', '>', '"', "'" ); |
|
| 247 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
| 248 | + $disallowed_characters = array('<', '>', '"', "'"); |
|
| 249 | 249 | |
| 250 | 250 | // Remove special characters. |
| 251 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
| 251 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
| 252 | 252 | |
| 253 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
| 253 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
| 254 | 254 | |
| 255 | 255 | return $statement_descriptor; |
| 256 | 256 | } |
@@ -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_bancontact'; |
| 60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe Bancontact', '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,25 +71,25 @@ 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( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - 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('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_bancontact_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_bancontact_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $icons_str .= $icons['bancontact']; |
| 177 | 177 | |
| 178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | * @access public |
| 187 | 187 | */ |
| 188 | 188 | public function payment_scripts() { |
| 189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 190 | 190 | return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 194 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Initialize Gateway Settings Form Fields. |
| 199 | 199 | */ |
| 200 | 200 | public function init_form_fields() { |
| 201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
| 201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | $total = WC()->cart->total; |
| 210 | 210 | |
| 211 | 211 | // If paying from order, we need to get total from order not cart. |
| 212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 214 | 214 | $total = $order->get_total(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( is_add_payment_method_page() ) { |
|
| 218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 219 | - $total = ''; |
|
| 217 | + if (is_add_payment_method_page()) { |
|
| 218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 219 | + $total = ''; |
|
| 220 | 220 | } else { |
| 221 | 221 | $pay_button_text = ''; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo '<div |
| 225 | 225 | id="stripe-bancontact-payment-data" |
| 226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 228 | 228 | |
| 229 | - if ( $this->description ) { |
|
| 230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 229 | + if ($this->description) { |
|
| 230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | echo '</div>'; |
@@ -241,25 +241,25 @@ discard block |
||
| 241 | 241 | * @param object $order |
| 242 | 242 | * @return mixed |
| 243 | 243 | */ |
| 244 | - public function create_source( $order ) { |
|
| 244 | + public function create_source($order) { |
|
| 245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 247 | + $return_url = $this->get_stripe_return_url($order); |
|
| 248 | 248 | $post_data = array(); |
| 249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 250 | - $post_data['currency'] = strtolower( $currency ); |
|
| 249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 250 | + $post_data['currency'] = strtolower($currency); |
|
| 251 | 251 | $post_data['type'] = 'bancontact'; |
| 252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 254 | - $post_data['bancontact'] = array( 'preferred_language' => substr( get_locale(), 0, 2 ) ); |
|
| 252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 254 | + $post_data['bancontact'] = array('preferred_language' => substr(get_locale(), 0, 2)); |
|
| 255 | 255 | |
| 256 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 257 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 256 | + if ( ! empty($this->statement_descriptor)) { |
|
| 257 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
| 260 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
| 261 | 261 | |
| 262 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' ); |
|
| 262 | + return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources'); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -273,51 +273,51 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @return array|void |
| 275 | 275 | */ |
| 276 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 276 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 277 | 277 | try { |
| 278 | - $order = wc_get_order( $order_id ); |
|
| 278 | + $order = wc_get_order($order_id); |
|
| 279 | 279 | |
| 280 | 280 | // This will throw exception if not valid. |
| 281 | - $this->validate_minimum_order_amount( $order ); |
|
| 281 | + $this->validate_minimum_order_amount($order); |
|
| 282 | 282 | |
| 283 | 283 | // This comes from the create account checkbox in the checkout page. |
| 284 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 284 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 285 | 285 | |
| 286 | - if ( $create_account ) { |
|
| 286 | + if ($create_account) { |
|
| 287 | 287 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 288 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 288 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 289 | 289 | $new_stripe_customer->create_customer(); |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $response = $this->create_source( $order ); |
|
| 292 | + $response = $this->create_source($order); |
|
| 293 | 293 | |
| 294 | - if ( ! empty( $response->error ) ) { |
|
| 295 | - $order->add_order_note( $response->error->message ); |
|
| 294 | + if ( ! empty($response->error)) { |
|
| 295 | + $order->add_order_note($response->error->message); |
|
| 296 | 296 | |
| 297 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 297 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 301 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 300 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 301 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 302 | 302 | } else { |
| 303 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 303 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 304 | 304 | $order->save(); |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
| 307 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
| 308 | 308 | |
| 309 | 309 | return array( |
| 310 | 310 | 'result' => 'success', |
| 311 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 311 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 312 | 312 | ); |
| 313 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 314 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 315 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 313 | + } catch (WC_Stripe_Exception $e) { |
|
| 314 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 315 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 316 | 316 | |
| 317 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 317 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 318 | 318 | |
| 319 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 320 | - $this->send_failed_order_email( $order_id ); |
|
| 319 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 320 | + $this->send_failed_order_email($order_id); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | 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 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_p24'; |
| 60 | - $this->method_title = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe P24', '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,25 +71,25 @@ 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( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - 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('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_p24_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_p24_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | 146 | 'PLN', |
| 147 | - ) ); |
|
| 147 | + )); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @return bool |
| 156 | 156 | */ |
| 157 | 157 | public function is_available() { |
| 158 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 158 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 159 | 159 | return false; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | $icons_str .= $icons['p24']; |
| 178 | 178 | |
| 179 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 179 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -187,19 +187,19 @@ discard block |
||
| 187 | 187 | * @access public |
| 188 | 188 | */ |
| 189 | 189 | public function payment_scripts() { |
| 190 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 190 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 191 | 191 | return; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 195 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 194 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 195 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
| 199 | 199 | * Initialize Gateway Settings Form Fields. |
| 200 | 200 | */ |
| 201 | 201 | public function init_form_fields() { |
| 202 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' ); |
|
| 202 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php'); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -210,25 +210,25 @@ discard block |
||
| 210 | 210 | $total = WC()->cart->total; |
| 211 | 211 | |
| 212 | 212 | // If paying from order, we need to get total from order not cart. |
| 213 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 214 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 213 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 214 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 215 | 215 | $total = $order->get_total(); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - if ( is_add_payment_method_page() ) { |
|
| 219 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 220 | - $total = ''; |
|
| 218 | + if (is_add_payment_method_page()) { |
|
| 219 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 220 | + $total = ''; |
|
| 221 | 221 | } else { |
| 222 | 222 | $pay_button_text = ''; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | echo '<div |
| 226 | 226 | id="stripe-p24-payment-data" |
| 227 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 228 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 227 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 228 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 229 | 229 | |
| 230 | - if ( $this->description ) { |
|
| 231 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 230 | + if ($this->description) { |
|
| 231 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | echo '</div>'; |
@@ -242,20 +242,20 @@ discard block |
||
| 242 | 242 | * @param object $order |
| 243 | 243 | * @return mixed |
| 244 | 244 | */ |
| 245 | - public function create_source( $order ) { |
|
| 245 | + public function create_source($order) { |
|
| 246 | 246 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 247 | 247 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 248 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 248 | + $return_url = $this->get_stripe_return_url($order); |
|
| 249 | 249 | $post_data = array(); |
| 250 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 251 | - $post_data['currency'] = strtolower( $currency ); |
|
| 250 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 251 | + $post_data['currency'] = strtolower($currency); |
|
| 252 | 252 | $post_data['type'] = 'p24'; |
| 253 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 254 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 253 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 254 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 255 | 255 | |
| 256 | - WC_Stripe_Logger::log( 'Info: Begin creating P24 source' ); |
|
| 256 | + WC_Stripe_Logger::log('Info: Begin creating P24 source'); |
|
| 257 | 257 | |
| 258 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_p24_source', $post_data, $order ), 'sources' ); |
|
| 258 | + return WC_Stripe_API::request(apply_filters('wc_stripe_p24_source', $post_data, $order), 'sources'); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -269,51 +269,51 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | * @return array|void |
| 271 | 271 | */ |
| 272 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 272 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 273 | 273 | try { |
| 274 | - $order = wc_get_order( $order_id ); |
|
| 274 | + $order = wc_get_order($order_id); |
|
| 275 | 275 | |
| 276 | 276 | // This will throw exception if not valid. |
| 277 | - $this->validate_minimum_order_amount( $order ); |
|
| 277 | + $this->validate_minimum_order_amount($order); |
|
| 278 | 278 | |
| 279 | 279 | // This comes from the create account checkbox in the checkout page. |
| 280 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 280 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 281 | 281 | |
| 282 | - if ( $create_account ) { |
|
| 282 | + if ($create_account) { |
|
| 283 | 283 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 284 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 284 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 285 | 285 | $new_stripe_customer->create_customer(); |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - $response = $this->create_source( $order ); |
|
| 288 | + $response = $this->create_source($order); |
|
| 289 | 289 | |
| 290 | - if ( ! empty( $response->error ) ) { |
|
| 291 | - $order->add_order_note( $response->error->message ); |
|
| 290 | + if ( ! empty($response->error)) { |
|
| 291 | + $order->add_order_note($response->error->message); |
|
| 292 | 292 | |
| 293 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 293 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 297 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 296 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 297 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 298 | 298 | } else { |
| 299 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 299 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 300 | 300 | $order->save(); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - WC_Stripe_Logger::log( 'Info: Redirecting to P24...' ); |
|
| 303 | + WC_Stripe_Logger::log('Info: Redirecting to P24...'); |
|
| 304 | 304 | |
| 305 | 305 | return array( |
| 306 | 306 | 'result' => 'success', |
| 307 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 307 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 308 | 308 | ); |
| 309 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 310 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 311 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 309 | + } catch (WC_Stripe_Exception $e) { |
|
| 310 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 311 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 312 | 312 | |
| 313 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 313 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 314 | 314 | |
| 315 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 316 | - $this->send_failed_order_email( $order_id ); |
|
| 315 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 316 | + $this->send_failed_order_email($order_id); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | 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 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_giropay'; |
| 60 | - $this->method_title = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe Giropay', '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,25 +71,25 @@ 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( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - 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('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_giropay_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_giropay_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $icons_str .= $icons['giropay']; |
| 177 | 177 | |
| 178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | * @access public |
| 187 | 187 | */ |
| 188 | 188 | public function payment_scripts() { |
| 189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 190 | 190 | return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 194 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Initialize Gateway Settings Form Fields. |
| 199 | 199 | */ |
| 200 | 200 | public function init_form_fields() { |
| 201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' ); |
|
| 201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | $total = WC()->cart->total; |
| 210 | 210 | |
| 211 | 211 | // If paying from order, we need to get total from order not cart. |
| 212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 214 | 214 | $total = $order->get_total(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( is_add_payment_method_page() ) { |
|
| 218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 219 | - $total = ''; |
|
| 217 | + if (is_add_payment_method_page()) { |
|
| 218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 219 | + $total = ''; |
|
| 220 | 220 | } else { |
| 221 | 221 | $pay_button_text = ''; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo '<div |
| 225 | 225 | id="stripe-giropay-payment-data" |
| 226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 228 | 228 | |
| 229 | - if ( $this->description ) { |
|
| 230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 229 | + if ($this->description) { |
|
| 230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | echo '</div>'; |
@@ -241,24 +241,24 @@ discard block |
||
| 241 | 241 | * @param object $order |
| 242 | 242 | * @return mixed |
| 243 | 243 | */ |
| 244 | - public function create_source( $order ) { |
|
| 244 | + public function create_source($order) { |
|
| 245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 247 | + $return_url = $this->get_stripe_return_url($order); |
|
| 248 | 248 | $post_data = array(); |
| 249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 250 | - $post_data['currency'] = strtolower( $currency ); |
|
| 249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 250 | + $post_data['currency'] = strtolower($currency); |
|
| 251 | 251 | $post_data['type'] = 'giropay'; |
| 252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 256 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 255 | + if ( ! empty($this->statement_descriptor)) { |
|
| 256 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' ); |
|
| 259 | + WC_Stripe_Logger::log('Info: Begin creating Giropay source'); |
|
| 260 | 260 | |
| 261 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_giropay_source', $post_data, $order ), 'sources' ); |
|
| 261 | + return WC_Stripe_API::request(apply_filters('wc_stripe_giropay_source', $post_data, $order), 'sources'); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @return array|void |
| 274 | 274 | */ |
| 275 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 275 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 276 | 276 | try { |
| 277 | - $order = wc_get_order( $order_id ); |
|
| 277 | + $order = wc_get_order($order_id); |
|
| 278 | 278 | |
| 279 | 279 | // This will throw exception if not valid. |
| 280 | - $this->validate_minimum_order_amount( $order ); |
|
| 280 | + $this->validate_minimum_order_amount($order); |
|
| 281 | 281 | |
| 282 | 282 | // This comes from the create account checkbox in the checkout page. |
| 283 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 283 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 284 | 284 | |
| 285 | - if ( $create_account ) { |
|
| 285 | + if ($create_account) { |
|
| 286 | 286 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 287 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 287 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 288 | 288 | $new_stripe_customer->create_customer(); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - $response = $this->create_source( $order ); |
|
| 291 | + $response = $this->create_source($order); |
|
| 292 | 292 | |
| 293 | - if ( ! empty( $response->error ) ) { |
|
| 294 | - $order->add_order_note( $response->error->message ); |
|
| 293 | + if ( ! empty($response->error)) { |
|
| 294 | + $order->add_order_note($response->error->message); |
|
| 295 | 295 | |
| 296 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 296 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 300 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 300 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 301 | 301 | } else { |
| 302 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 302 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 303 | 303 | $order->save(); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' ); |
|
| 306 | + WC_Stripe_Logger::log('Info: Redirecting to Giropay...'); |
|
| 307 | 307 | |
| 308 | 308 | return array( |
| 309 | 309 | 'result' => 'success', |
| 310 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 310 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 311 | 311 | ); |
| 312 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 312 | + } catch (WC_Stripe_Exception $e) { |
|
| 313 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 314 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 315 | 315 | |
| 316 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 316 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 317 | 317 | |
| 318 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 319 | - $this->send_failed_order_email( $order_id ); |
|
| 318 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 319 | + $this->send_failed_order_email($order_id); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | 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 | |
@@ -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,25 +71,25 @@ 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( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - 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('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_ideal_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_ideal_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $icons_str .= $icons['ideal']; |
| 177 | 177 | |
| 178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | * @access public |
| 187 | 187 | */ |
| 188 | 188 | public function payment_scripts() { |
| 189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 190 | 190 | return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 194 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Initialize Gateway Settings Form Fields. |
| 199 | 199 | */ |
| 200 | 200 | public function init_form_fields() { |
| 201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' ); |
|
| 201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | $total = WC()->cart->total; |
| 210 | 210 | |
| 211 | 211 | // If paying from order, we need to get total from order not cart. |
| 212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 214 | 214 | $total = $order->get_total(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( is_add_payment_method_page() ) { |
|
| 218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 219 | - $total = ''; |
|
| 217 | + if (is_add_payment_method_page()) { |
|
| 218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 219 | + $total = ''; |
|
| 220 | 220 | } else { |
| 221 | 221 | $pay_button_text = ''; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo '<div |
| 225 | 225 | id="stripe-ideal-payment-data" |
| 226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 228 | 228 | |
| 229 | - if ( $this->description ) { |
|
| 230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 229 | + if ($this->description) { |
|
| 230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | echo '</div>'; |
@@ -241,24 +241,24 @@ discard block |
||
| 241 | 241 | * @param object $order |
| 242 | 242 | * @return mixed |
| 243 | 243 | */ |
| 244 | - public function create_source( $order ) { |
|
| 244 | + public function create_source($order) { |
|
| 245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 247 | + $return_url = $this->get_stripe_return_url($order); |
|
| 248 | 248 | $post_data = array(); |
| 249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 250 | - $post_data['currency'] = strtolower( $currency ); |
|
| 249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 250 | + $post_data['currency'] = strtolower($currency); |
|
| 251 | 251 | $post_data['type'] = 'ideal'; |
| 252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 256 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 255 | + if ( ! empty($this->statement_descriptor)) { |
|
| 256 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' ); |
|
| 259 | + WC_Stripe_Logger::log('Info: Begin creating iDeal source'); |
|
| 260 | 260 | |
| 261 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_ideal_source', $post_data, $order ), 'sources' ); |
|
| 261 | + return WC_Stripe_API::request(apply_filters('wc_stripe_ideal_source', $post_data, $order), 'sources'); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @return array|void |
| 274 | 274 | */ |
| 275 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 275 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 276 | 276 | try { |
| 277 | - $order = wc_get_order( $order_id ); |
|
| 277 | + $order = wc_get_order($order_id); |
|
| 278 | 278 | |
| 279 | 279 | // This will throw exception if not valid. |
| 280 | - $this->validate_minimum_order_amount( $order ); |
|
| 280 | + $this->validate_minimum_order_amount($order); |
|
| 281 | 281 | |
| 282 | 282 | // This comes from the create account checkbox in the checkout page. |
| 283 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 283 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 284 | 284 | |
| 285 | - if ( $create_account ) { |
|
| 285 | + if ($create_account) { |
|
| 286 | 286 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 287 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 287 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 288 | 288 | $new_stripe_customer->create_customer(); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - $response = $this->create_source( $order ); |
|
| 291 | + $response = $this->create_source($order); |
|
| 292 | 292 | |
| 293 | - if ( ! empty( $response->error ) ) { |
|
| 294 | - $order->add_order_note( $response->error->message ); |
|
| 293 | + if ( ! empty($response->error)) { |
|
| 294 | + $order->add_order_note($response->error->message); |
|
| 295 | 295 | |
| 296 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 296 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 300 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 300 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 301 | 301 | } else { |
| 302 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 302 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 303 | 303 | $order->save(); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' ); |
|
| 306 | + WC_Stripe_Logger::log('Info: Redirecting to iDeal...'); |
|
| 307 | 307 | |
| 308 | 308 | return array( |
| 309 | 309 | 'result' => 'success', |
| 310 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 310 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 311 | 311 | ); |
| 312 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 312 | + } catch (WC_Stripe_Exception $e) { |
|
| 313 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 314 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 315 | 315 | |
| 316 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 316 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 317 | 317 | |
| 318 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 319 | - $this->send_failed_order_email( $order_id ); |
|
| 318 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 319 | + $this->send_failed_order_email($order_id); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | 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 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_sofort'; |
| 60 | - $this->method_title = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe SOFORT', '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,25 +71,25 @@ 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( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - 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('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_sofort_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_sofort_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $icons_str .= $icons['sofort']; |
| 177 | 177 | |
| 178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | * @access public |
| 187 | 187 | */ |
| 188 | 188 | public function payment_scripts() { |
| 189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 190 | 190 | return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 194 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Initialize Gateway Settings Form Fields. |
| 199 | 199 | */ |
| 200 | 200 | public function init_form_fields() { |
| 201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
| 201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | $total = WC()->cart->total; |
| 210 | 210 | |
| 211 | 211 | // If paying from order, we need to get total from order not cart. |
| 212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 214 | 214 | $total = $order->get_total(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( is_add_payment_method_page() ) { |
|
| 218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 219 | - $total = ''; |
|
| 217 | + if (is_add_payment_method_page()) { |
|
| 218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 219 | + $total = ''; |
|
| 220 | 220 | } else { |
| 221 | 221 | $pay_button_text = ''; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo '<div |
| 225 | 225 | id="stripe-sofort-payment-data" |
| 226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 228 | 228 | |
| 229 | - if ( $this->description ) { |
|
| 230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 229 | + if ($this->description) { |
|
| 230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | echo '</div>'; |
@@ -241,28 +241,28 @@ discard block |
||
| 241 | 241 | * @param object $order |
| 242 | 242 | * @return mixed |
| 243 | 243 | */ |
| 244 | - public function create_source( $order ) { |
|
| 244 | + public function create_source($order) { |
|
| 245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 246 | 246 | $bank_country = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
| 247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 247 | + $return_url = $this->get_stripe_return_url($order); |
|
| 248 | 248 | $post_data = array(); |
| 249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 250 | - $post_data['currency'] = strtolower( $currency ); |
|
| 249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 250 | + $post_data['currency'] = strtolower($currency); |
|
| 251 | 251 | $post_data['type'] = 'sofort'; |
| 252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 254 | 254 | $post_data['sofort'] = array( |
| 255 | 255 | 'country' => $bank_country, |
| 256 | - 'preferred_language' => substr( get_locale(), 0, 2 ), |
|
| 256 | + 'preferred_language' => substr(get_locale(), 0, 2), |
|
| 257 | 257 | ); |
| 258 | 258 | |
| 259 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 260 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 259 | + if ( ! empty($this->statement_descriptor)) { |
|
| 260 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
| 263 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
| 264 | 264 | |
| 265 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_sofort_source', $post_data, $order ), 'sources' ); |
|
| 265 | + return WC_Stripe_API::request(apply_filters('wc_stripe_sofort_source', $post_data, $order), 'sources'); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -276,59 +276,59 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @return array|void |
| 278 | 278 | */ |
| 279 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 279 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 280 | 280 | try { |
| 281 | - $order = wc_get_order( $order_id ); |
|
| 281 | + $order = wc_get_order($order_id); |
|
| 282 | 282 | |
| 283 | 283 | // This will throw exception if not valid. |
| 284 | - $this->validate_minimum_order_amount( $order ); |
|
| 284 | + $this->validate_minimum_order_amount($order); |
|
| 285 | 285 | |
| 286 | 286 | // This comes from the create account checkbox in the checkout page. |
| 287 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 287 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 288 | 288 | |
| 289 | - if ( $create_account ) { |
|
| 289 | + if ($create_account) { |
|
| 290 | 290 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 291 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 291 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 292 | 292 | $new_stripe_customer->create_customer(); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - $response = $this->create_source( $order ); |
|
| 295 | + $response = $this->create_source($order); |
|
| 296 | 296 | |
| 297 | - if ( ! empty( $response->error ) ) { |
|
| 298 | - $order->add_order_note( $response->error->message ); |
|
| 297 | + if ( ! empty($response->error)) { |
|
| 298 | + $order->add_order_note($response->error->message); |
|
| 299 | 299 | |
| 300 | 300 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 301 | 301 | |
| 302 | - if ( 'invalid_sofort_country' === $response->error->code ) { |
|
| 303 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 302 | + if ('invalid_sofort_country' === $response->error->code) { |
|
| 303 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 304 | 304 | } else { |
| 305 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 305 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 308 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 312 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 311 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 312 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 313 | 313 | } else { |
| 314 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 314 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 315 | 315 | $order->save(); |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
| 318 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
| 319 | 319 | |
| 320 | 320 | return array( |
| 321 | 321 | 'result' => 'success', |
| 322 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 322 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 323 | 323 | ); |
| 324 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 325 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 326 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 324 | + } catch (WC_Stripe_Exception $e) { |
|
| 325 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 326 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 327 | 327 | |
| 328 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 328 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 329 | 329 | |
| 330 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 331 | - $this->send_failed_order_email( $order_id ); |
|
| 330 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 331 | + $this->send_failed_order_email($order_id); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | return array( |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | /** |
| 316 | 316 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 317 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
| 317 | + * @param integer $renewal_order |
|
| 318 | 318 | */ |
| 319 | 319 | public function delete_renewal_meta( $renewal_order ) { |
| 320 | 320 | delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
@@ -556,6 +556,8 @@ discard block |
||
| 556 | 556 | /** |
| 557 | 557 | * Process the pre-order |
| 558 | 558 | * @param int $order_id |
| 559 | + * @param boolean $retry |
|
| 560 | + * @param boolean $force_save_source |
|
| 559 | 561 | * @return array |
| 560 | 562 | */ |
| 561 | 563 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -15,24 +15,24 @@ discard block |
||
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | |
| 18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 23 | 23 | |
| 24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 26 | 26 | |
| 27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
| 28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
| 34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @since 4.0.0 |
| 44 | 44 | * @version 4.0.0 |
| 45 | 45 | */ |
| 46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 48 | 48 | return false; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param int $order_id |
| 57 | 57 | * @return boolean |
| 58 | 58 | */ |
| 59 | - public function has_subscription( $order_id ) { |
|
| 60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 59 | + public function has_subscription($order_id) { |
|
| 60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @return bool |
| 68 | 68 | */ |
| 69 | 69 | public function is_subs_change_payment() { |
| 70 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
| 70 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | * @param int $order_id |
| 76 | 76 | * @return boolean |
| 77 | 77 | */ |
| 78 | - public function is_pre_order( $order_id ) { |
|
| 79 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
| 78 | + public function is_pre_order($order_id) { |
|
| 79 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -85,26 +85,26 @@ discard block |
||
| 85 | 85 | * @since 4.0.4 |
| 86 | 86 | * @param int $order_id |
| 87 | 87 | */ |
| 88 | - public function change_subs_payment_method( $order_id ) { |
|
| 88 | + public function change_subs_payment_method($order_id) { |
|
| 89 | 89 | try { |
| 90 | - $subscription = wc_get_order( $order_id ); |
|
| 90 | + $subscription = wc_get_order($order_id); |
|
| 91 | 91 | $source_object = $this->get_source_object(); |
| 92 | - $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), true ); |
|
| 92 | + $prepared_source = $this->prepare_source($source_object, get_current_user_id(), true); |
|
| 93 | 93 | |
| 94 | 94 | // Check if we don't allow prepaid credit cards. |
| 95 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
| 96 | - if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
| 97 | - $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' ); |
|
| 98 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
| 95 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
| 96 | + if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
| 97 | + $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'); |
|
| 98 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if ( empty( $prepared_source->source ) ) { |
|
| 103 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 104 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 102 | + if (empty($prepared_source->source)) { |
|
| 103 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 104 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
| 107 | + $this->save_source_to_order($subscription, $prepared_source); |
|
| 108 | 108 | |
| 109 | 109 | /* |
| 110 | 110 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -113,41 +113,41 @@ discard block |
||
| 113 | 113 | * Note that if we need to save source, the original source must be first |
| 114 | 114 | * attached to a customer in Stripe before it can be charged. |
| 115 | 115 | */ |
| 116 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
| 116 | + if ($this->is_3ds_required($source_object)) { |
|
| 117 | 117 | $order = $subscription->get_parent(); |
| 118 | - $response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() ); |
|
| 118 | + $response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url()); |
|
| 119 | 119 | |
| 120 | - if ( ! empty( $response->error ) ) { |
|
| 120 | + if ( ! empty($response->error)) { |
|
| 121 | 121 | $localized_message = $response->error->message; |
| 122 | 122 | |
| 123 | - $order->add_order_note( $localized_message ); |
|
| 123 | + $order->add_order_note($localized_message); |
|
| 124 | 124 | |
| 125 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 125 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Update order meta with 3DS source. |
| 129 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 130 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 129 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 130 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 131 | 131 | } else { |
| 132 | - $subscription->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 132 | + $subscription->update_meta_data('_stripe_source_id', $response->id); |
|
| 133 | 133 | $subscription->save(); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
| 136 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
| 137 | 137 | |
| 138 | 138 | return array( |
| 139 | 139 | 'result' => 'success', |
| 140 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 140 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 141 | 141 | ); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | return array( |
| 145 | 145 | 'result' => 'success', |
| 146 | - 'redirect' => $this->get_return_url( $subscription ), |
|
| 146 | + 'redirect' => $this->get_return_url($subscription), |
|
| 147 | 147 | ); |
| 148 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 149 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 150 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 148 | + } catch (WC_Stripe_Exception $e) { |
|
| 149 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 150 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
@@ -156,18 +156,18 @@ discard block |
||
| 156 | 156 | * @param int $order_id |
| 157 | 157 | * @return array |
| 158 | 158 | */ |
| 159 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 160 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 161 | - if ( $this->is_subs_change_payment() ) { |
|
| 162 | - return $this->change_subs_payment_method( $order_id ); |
|
| 159 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 160 | + if ($this->has_subscription($order_id)) { |
|
| 161 | + if ($this->is_subs_change_payment()) { |
|
| 162 | + return $this->change_subs_payment_method($order_id); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Regular payment with force customer enabled |
| 166 | - return parent::process_payment( $order_id, true, true ); |
|
| 167 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
| 168 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
| 166 | + return parent::process_payment($order_id, true, true); |
|
| 167 | + } elseif ($this->is_pre_order($order_id)) { |
|
| 168 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
| 169 | 169 | } else { |
| 170 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 170 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
@@ -178,14 +178,14 @@ discard block |
||
| 178 | 178 | * @param array $metadata |
| 179 | 179 | * @param object $order |
| 180 | 180 | */ |
| 181 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
| 182 | - if ( ! $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
| 181 | + public function add_subscription_meta_data($metadata, $order) { |
|
| 182 | + if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
| 183 | 183 | return $metadata; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | return $metadata += array( |
| 187 | 187 | 'payment_type' => 'recurring', |
| 188 | - 'site_url' => esc_url( get_site_url() ), |
|
| 188 | + 'site_url' => esc_url(get_site_url()), |
|
| 189 | 189 | ); |
| 190 | 190 | } |
| 191 | 191 | |
@@ -195,24 +195,24 @@ discard block |
||
| 195 | 195 | * @since 3.1.0 |
| 196 | 196 | * @version 4.0.0 |
| 197 | 197 | */ |
| 198 | - public function save_source_to_order( $order, $source ) { |
|
| 199 | - parent::save_source_to_order( $order, $source ); |
|
| 198 | + public function save_source_to_order($order, $source) { |
|
| 199 | + parent::save_source_to_order($order, $source); |
|
| 200 | 200 | |
| 201 | 201 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 202 | 202 | |
| 203 | 203 | // Also store it on the subscriptions being purchased or paid for in the order |
| 204 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 205 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 206 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 207 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 204 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 205 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 206 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 207 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 208 | 208 | } else { |
| 209 | 209 | $subscriptions = array(); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - foreach ( $subscriptions as $subscription ) { |
|
| 212 | + foreach ($subscriptions as $subscription) { |
|
| 213 | 213 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
| 214 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 215 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 214 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 215 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
@@ -225,45 +225,45 @@ discard block |
||
| 225 | 225 | * @param mixed $renewal_order |
| 226 | 226 | * @param bool $is_retry Is this a retry process. |
| 227 | 227 | */ |
| 228 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
| 229 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 228 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) { |
|
| 229 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 230 | 230 | /* translators: minimum amount */ |
| 231 | - return new WP_Error( 'stripe_error', 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 ) ) ); |
|
| 231 | + return new WP_Error('stripe_error', 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))); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
| 235 | 235 | |
| 236 | 236 | // Get source from order |
| 237 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
| 237 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
| 238 | 238 | |
| 239 | - if ( ! $prepared_source->customer ) { |
|
| 240 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 239 | + if ( ! $prepared_source->customer) { |
|
| 240 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 243 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 244 | 244 | |
| 245 | - if ( $is_retry ) { |
|
| 245 | + if ($is_retry) { |
|
| 246 | 246 | // Passing empty source with charge customer default. |
| 247 | 247 | $prepared_source->source = ''; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
| 250 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
| 251 | 251 | $request['capture'] = 'true'; |
| 252 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 253 | - $response = WC_Stripe_API::request( $request ); |
|
| 252 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
| 253 | + $response = WC_Stripe_API::request($request); |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
| 256 | - if ( $is_retry ) { |
|
| 255 | + if ( ! empty($response->error) || is_wp_error($response)) { |
|
| 256 | + if ($is_retry) { |
|
| 257 | 257 | /* translators: error message */ |
| 258 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 258 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | return $response; // Default catch all errors. |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - $this->process_response( $response, $renewal_order ); |
|
| 264 | + $this->process_response($response, $renewal_order); |
|
| 265 | 265 | |
| 266 | - if ( ! $is_retry ) { |
|
| 266 | + if ( ! $is_retry) { |
|
| 267 | 267 | return $response; |
| 268 | 268 | } |
| 269 | 269 | } |
@@ -272,21 +272,21 @@ discard block |
||
| 272 | 272 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 273 | 273 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 274 | 274 | */ |
| 275 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 276 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 277 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 275 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 276 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 277 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 278 | 278 | // For BW compat will remove in future |
| 279 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 280 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 279 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 280 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 285 | 285 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 286 | 286 | */ |
| 287 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 288 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
| 289 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
| 287 | + public function delete_renewal_meta($renewal_order) { |
|
| 288 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
| 289 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
| 290 | 290 | return $renewal_order; |
| 291 | 291 | } |
| 292 | 292 | |
@@ -296,21 +296,21 @@ discard block |
||
| 296 | 296 | * @param $amount_to_charge float The amount to charge. |
| 297 | 297 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 298 | 298 | */ |
| 299 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 300 | - $response = $this->process_subscription_payment( $amount_to_charge, $renewal_order ); |
|
| 299 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 300 | + $response = $this->process_subscription_payment($amount_to_charge, $renewal_order); |
|
| 301 | 301 | |
| 302 | - if ( is_wp_error( $response ) ) { |
|
| 302 | + if (is_wp_error($response)) { |
|
| 303 | 303 | /* translators: error message */ |
| 304 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 304 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - if ( ! empty( $response->error ) ) { |
|
| 307 | + if ( ! empty($response->error)) { |
|
| 308 | 308 | // This is a very generic error to listen for but worth a retry before total fail. |
| 309 | - if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 310 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true ); |
|
| 309 | + if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 310 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true); |
|
| 311 | 311 | } else { |
| 312 | 312 | /* translators: error message */ |
| 313 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 313 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | } |
@@ -319,20 +319,20 @@ discard block |
||
| 319 | 319 | * Remove order meta |
| 320 | 320 | * @param object $order |
| 321 | 321 | */ |
| 322 | - public function remove_order_source_before_retry( $order ) { |
|
| 322 | + public function remove_order_source_before_retry($order) { |
|
| 323 | 323 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 324 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
| 324 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
| 325 | 325 | // For BW compat will remove in the future. |
| 326 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 326 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
| 330 | 330 | * Remove order meta |
| 331 | 331 | * @param object $order |
| 332 | 332 | */ |
| 333 | - public function remove_order_customer_before_retry( $order ) { |
|
| 333 | + public function remove_order_customer_before_retry($order) { |
|
| 334 | 334 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 335 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 335 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
@@ -344,14 +344,14 @@ discard block |
||
| 344 | 344 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 345 | 345 | * @return void |
| 346 | 346 | */ |
| 347 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 348 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 349 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 350 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 347 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 348 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 349 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 350 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 351 | 351 | |
| 352 | 352 | } else { |
| 353 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 354 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 353 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 354 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
@@ -364,21 +364,21 @@ discard block |
||
| 364 | 364 | * @param WC_Subscription $subscription An instance of a subscription object |
| 365 | 365 | * @return array |
| 366 | 366 | */ |
| 367 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 368 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 367 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 368 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 369 | 369 | |
| 370 | 370 | // For BW compat will remove in future. |
| 371 | - if ( empty( $source_id ) ) { |
|
| 372 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 371 | + if (empty($source_id)) { |
|
| 372 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 373 | 373 | |
| 374 | 374 | // Take this opportunity to update the key name. |
| 375 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
| 375 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - $payment_meta[ $this->id ] = array( |
|
| 378 | + $payment_meta[$this->id] = array( |
|
| 379 | 379 | 'post_meta' => array( |
| 380 | 380 | '_stripe_customer_id' => array( |
| 381 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 381 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 382 | 382 | 'label' => 'Stripe Customer ID', |
| 383 | 383 | ), |
| 384 | 384 | '_stripe_source_id' => array( |
@@ -401,22 +401,22 @@ discard block |
||
| 401 | 401 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 402 | 402 | * @return array |
| 403 | 403 | */ |
| 404 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 405 | - if ( $this->id === $payment_method_id ) { |
|
| 404 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 405 | + if ($this->id === $payment_method_id) { |
|
| 406 | 406 | |
| 407 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 408 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
| 409 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 410 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
| 407 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 408 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
| 409 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 410 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | if ( |
| 414 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 415 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
| 416 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 417 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
| 414 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 415 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
| 416 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 417 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
| 418 | 418 | |
| 419 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
| 419 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | } |
@@ -429,91 +429,91 @@ discard block |
||
| 429 | 429 | * @param WC_Subscription $subscription the subscription details |
| 430 | 430 | * @return string the subscription payment method |
| 431 | 431 | */ |
| 432 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 432 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 433 | 433 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
| 434 | 434 | |
| 435 | 435 | // bail for other payment methods |
| 436 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 436 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 437 | 437 | return $payment_method_to_display; |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 440 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 441 | 441 | |
| 442 | 442 | // For BW compat will remove in future. |
| 443 | - if ( empty( $stripe_source_id ) ) { |
|
| 444 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 443 | + if (empty($stripe_source_id)) { |
|
| 444 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 445 | 445 | |
| 446 | 446 | // Take this opportunity to update the key name. |
| 447 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 447 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | $stripe_customer = new WC_Stripe_Customer(); |
| 451 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 451 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 452 | 452 | |
| 453 | 453 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 454 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 454 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 455 | 455 | $user_id = $customer_user; |
| 456 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 457 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 456 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 457 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 458 | 458 | |
| 459 | 459 | // For BW compat will remove in future. |
| 460 | - if ( empty( $stripe_source_id ) ) { |
|
| 461 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 460 | + if (empty($stripe_source_id)) { |
|
| 461 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 462 | 462 | |
| 463 | 463 | // Take this opportunity to update the key name. |
| 464 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 464 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 469 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 470 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 471 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 469 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 470 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 471 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 472 | 472 | |
| 473 | 473 | // For BW compat will remove in future. |
| 474 | - if ( empty( $stripe_source_id ) ) { |
|
| 475 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 474 | + if (empty($stripe_source_id)) { |
|
| 475 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 476 | 476 | |
| 477 | 477 | // Take this opportunity to update the key name. |
| 478 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 478 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
| 479 | 479 | } |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 482 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 483 | 483 | $sources = $stripe_customer->get_sources(); |
| 484 | 484 | |
| 485 | - if ( $sources ) { |
|
| 485 | + if ($sources) { |
|
| 486 | 486 | $found_source = false; |
| 487 | - foreach ( $sources as $source ) { |
|
| 488 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 487 | + foreach ($sources as $source) { |
|
| 488 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 489 | 489 | $card = $source->card; |
| 490 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
| 490 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
| 491 | 491 | $card = $source; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - if ( $source->id === $stripe_source_id ) { |
|
| 494 | + if ($source->id === $stripe_source_id) { |
|
| 495 | 495 | $found_source = true; |
| 496 | 496 | |
| 497 | - if ( $card ) { |
|
| 497 | + if ($card) { |
|
| 498 | 498 | /* translators: 1) card brand 2) last 4 digits */ |
| 499 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 499 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 500 | 500 | } else { |
| 501 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 501 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 502 | 502 | } |
| 503 | 503 | break; |
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | - if ( ! $found_source ) { |
|
| 508 | - if ( 'card' === $sources[0]->type ) { |
|
| 507 | + if ( ! $found_source) { |
|
| 508 | + if ('card' === $sources[0]->type) { |
|
| 509 | 509 | $card = $sources[0]->card; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - if ( $card ) { |
|
| 512 | + if ($card) { |
|
| 513 | 513 | /* translators: 1) card brand 2) last 4 digits */ |
| 514 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 514 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 515 | 515 | } else { |
| 516 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 516 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | } |
@@ -526,42 +526,42 @@ discard block |
||
| 526 | 526 | * @param int $order_id |
| 527 | 527 | * @return array |
| 528 | 528 | */ |
| 529 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
| 530 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 529 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
| 530 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
| 531 | 531 | try { |
| 532 | - $order = wc_get_order( $order_id ); |
|
| 532 | + $order = wc_get_order($order_id); |
|
| 533 | 533 | |
| 534 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 534 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 535 | 535 | /* translators: minimum amount */ |
| 536 | - throw new Exception( 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 ) ) ); |
|
| 536 | + throw new Exception(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))); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - $source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true ); |
|
| 539 | + $source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true); |
|
| 540 | 540 | |
| 541 | 541 | // We need a source on file to continue. |
| 542 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 543 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 542 | + if (empty($source->customer) || empty($source->source)) { |
|
| 543 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - $this->save_source_to_order( $order, $source ); |
|
| 546 | + $this->save_source_to_order($order, $source); |
|
| 547 | 547 | |
| 548 | 548 | // Remove cart |
| 549 | 549 | WC()->cart->empty_cart(); |
| 550 | 550 | |
| 551 | 551 | // Is pre ordered! |
| 552 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 552 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 553 | 553 | |
| 554 | 554 | // Return thank you page redirect |
| 555 | 555 | return array( |
| 556 | 556 | 'result' => 'success', |
| 557 | - 'redirect' => $this->get_return_url( $order ), |
|
| 557 | + 'redirect' => $this->get_return_url($order), |
|
| 558 | 558 | ); |
| 559 | - } catch ( Exception $e ) { |
|
| 560 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 559 | + } catch (Exception $e) { |
|
| 560 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 561 | 561 | return; |
| 562 | 562 | } |
| 563 | 563 | } else { |
| 564 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 564 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 565 | 565 | } |
| 566 | 566 | } |
| 567 | 567 | |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | * @param WC_Order $order |
| 571 | 571 | * @return void |
| 572 | 572 | */ |
| 573 | - public function process_pre_order_release_payment( $order ) { |
|
| 573 | + public function process_pre_order_release_payment($order) { |
|
| 574 | 574 | try { |
| 575 | 575 | // Define some callbacks if the first attempt fails. |
| 576 | 576 | $retry_callbacks = array( |
@@ -578,33 +578,33 @@ discard block |
||
| 578 | 578 | 'remove_order_customer_before_retry', |
| 579 | 579 | ); |
| 580 | 580 | |
| 581 | - while ( 1 ) { |
|
| 582 | - $source = $this->prepare_order_source( $order ); |
|
| 583 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 581 | + while (1) { |
|
| 582 | + $source = $this->prepare_order_source($order); |
|
| 583 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 584 | 584 | |
| 585 | - if ( ! empty( $response->error ) ) { |
|
| 586 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 587 | - throw new Exception( $response->error->message ); |
|
| 585 | + if ( ! empty($response->error)) { |
|
| 586 | + if (0 === sizeof($retry_callbacks)) { |
|
| 587 | + throw new Exception($response->error->message); |
|
| 588 | 588 | } else { |
| 589 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 590 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 589 | + $retry_callback = array_shift($retry_callbacks); |
|
| 590 | + call_user_func(array($this, $retry_callback), $order); |
|
| 591 | 591 | } |
| 592 | 592 | } else { |
| 593 | 593 | // Successful |
| 594 | - $this->process_response( $response, $order ); |
|
| 594 | + $this->process_response($response, $order); |
|
| 595 | 595 | break; |
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | - } catch ( Exception $e ) { |
|
| 598 | + } catch (Exception $e) { |
|
| 599 | 599 | /* translators: error message */ |
| 600 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 600 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 601 | 601 | |
| 602 | 602 | // Mark order as failed if not already set, |
| 603 | 603 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 604 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 605 | - $order->update_status( 'failed', $order_note ); |
|
| 604 | + if ( ! $order->has_status('failed')) { |
|
| 605 | + $order->update_status('failed', $order_note); |
|
| 606 | 606 | } else { |
| 607 | - $order->add_order_note( $order_note ); |
|
| 607 | + $order->add_order_note($order_note); |
|
| 608 | 608 | } |
| 609 | 609 | } |
| 610 | 610 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | /** |
| 316 | 316 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 317 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
| 317 | + * @param integer $renewal_order |
|
| 318 | 318 | */ |
| 319 | 319 | public function delete_renewal_meta( $renewal_order ) { |
| 320 | 320 | delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
@@ -556,6 +556,8 @@ discard block |
||
| 556 | 556 | /** |
| 557 | 557 | * Process the pre-order |
| 558 | 558 | * @param int $order_id |
| 559 | + * @param boolean $retry |
|
| 560 | + * @param boolean $force_save_source |
|
| 559 | 561 | * @return array |
| 560 | 562 | */ |
| 561 | 563 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -15,24 +15,24 @@ discard block |
||
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | |
| 18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 23 | 23 | |
| 24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 26 | 26 | |
| 27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
| 28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
| 34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @since 4.0.0 |
| 44 | 44 | * @version 4.0.0 |
| 45 | 45 | */ |
| 46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 48 | 48 | return false; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param int $order_id |
| 57 | 57 | * @return boolean |
| 58 | 58 | */ |
| 59 | - public function has_subscription( $order_id ) { |
|
| 60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 59 | + public function has_subscription($order_id) { |
|
| 60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * @param int $order_id |
| 66 | 66 | * @return boolean |
| 67 | 67 | */ |
| 68 | - protected function is_pre_order( $order_id ) { |
|
| 69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
| 68 | + protected function is_pre_order($order_id) { |
|
| 69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * @param int $order_id |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 78 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 78 | + if ($this->has_subscription($order_id)) { |
|
| 79 | 79 | // Regular payment with force customer enabled |
| 80 | - return parent::process_payment( $order_id, true, true ); |
|
| 81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
| 82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
| 80 | + return parent::process_payment($order_id, true, true); |
|
| 81 | + } elseif ($this->is_pre_order($order_id)) { |
|
| 82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
| 83 | 83 | } else { |
| 84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | * @param array $metadata |
| 93 | 93 | * @param object $order |
| 94 | 94 | */ |
| 95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
| 96 | - if ( ! $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
| 95 | + public function add_subscription_meta_data($metadata, $order) { |
|
| 96 | + if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
| 97 | 97 | return $metadata; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return $metadata += array( |
| 101 | 101 | 'payment_type' => 'recurring', |
| 102 | - 'site_url' => esc_url( get_site_url() ), |
|
| 102 | + 'site_url' => esc_url(get_site_url()), |
|
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
| 109 | 109 | * @since 3.1.0 |
| 110 | 110 | * @version 4.0.0 |
| 111 | 111 | */ |
| 112 | - public function save_source_to_order( $order, $source ) { |
|
| 113 | - parent::save_source_to_order( $order, $source ); |
|
| 112 | + public function save_source_to_order($order, $source) { |
|
| 113 | + parent::save_source_to_order($order, $source); |
|
| 114 | 114 | |
| 115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 116 | 116 | |
| 117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order |
| 118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 122 | 122 | } else { |
| 123 | 123 | $subscriptions = array(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - foreach ( $subscriptions as $subscription ) { |
|
| 126 | + foreach ($subscriptions as $subscription) { |
|
| 127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
| 128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -139,45 +139,45 @@ discard block |
||
| 139 | 139 | * @param mixed $renewal_order |
| 140 | 140 | * @param bool $is_retry Is this a retry process. |
| 141 | 141 | */ |
| 142 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
| 143 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 142 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) { |
|
| 143 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 144 | 144 | /* translators: minimum amount */ |
| 145 | - return new WP_Error( 'stripe_error', 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 ) ) ); |
|
| 145 | + return new WP_Error('stripe_error', 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))); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
| 149 | 149 | |
| 150 | 150 | // Get source from order |
| 151 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
| 151 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
| 152 | 152 | |
| 153 | - if ( ! $prepared_source->customer ) { |
|
| 154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 153 | + if ( ! $prepared_source->customer) { |
|
| 154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 158 | 158 | |
| 159 | - if ( $is_retry ) { |
|
| 159 | + if ($is_retry) { |
|
| 160 | 160 | // Passing empty source with charge customer default. |
| 161 | 161 | $prepared_source->source = ''; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
| 164 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
| 165 | 165 | $request['capture'] = 'true'; |
| 166 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 167 | - $response = WC_Stripe_API::request( $request ); |
|
| 166 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
| 167 | + $response = WC_Stripe_API::request($request); |
|
| 168 | 168 | |
| 169 | - if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
| 170 | - if ( $is_retry ) { |
|
| 169 | + if ( ! empty($response->error) || is_wp_error($response)) { |
|
| 170 | + if ($is_retry) { |
|
| 171 | 171 | /* translators: error message */ |
| 172 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 172 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | return $response; // Default catch all errors. |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - $this->process_response( $response, $renewal_order ); |
|
| 178 | + $this->process_response($response, $renewal_order); |
|
| 179 | 179 | |
| 180 | - if ( ! $is_retry ) { |
|
| 180 | + if ( ! $is_retry) { |
|
| 181 | 181 | return $response; |
| 182 | 182 | } |
| 183 | 183 | } |
@@ -186,21 +186,21 @@ discard block |
||
| 186 | 186 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 187 | 187 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 188 | 188 | */ |
| 189 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 190 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 191 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 189 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 190 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 191 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 192 | 192 | // For BW compat will remove in future |
| 193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 194 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 194 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 199 | 199 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 200 | 200 | */ |
| 201 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 202 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
| 203 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
| 201 | + public function delete_renewal_meta($renewal_order) { |
|
| 202 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
| 203 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
| 204 | 204 | return $renewal_order; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -210,21 +210,21 @@ discard block |
||
| 210 | 210 | * @param $amount_to_charge float The amount to charge. |
| 211 | 211 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 212 | 212 | */ |
| 213 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 214 | - $response = $this->process_subscription_payment( $amount_to_charge, $renewal_order ); |
|
| 213 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 214 | + $response = $this->process_subscription_payment($amount_to_charge, $renewal_order); |
|
| 215 | 215 | |
| 216 | - if ( is_wp_error( $response ) ) { |
|
| 216 | + if (is_wp_error($response)) { |
|
| 217 | 217 | /* translators: error message */ |
| 218 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 218 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - if ( ! empty( $response->error ) ) { |
|
| 221 | + if ( ! empty($response->error)) { |
|
| 222 | 222 | // This is a very generic error to listen for but worth a retry before total fail. |
| 223 | - if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 224 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true ); |
|
| 223 | + if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 224 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true); |
|
| 225 | 225 | } else { |
| 226 | 226 | /* translators: error message */ |
| 227 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 227 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -233,20 +233,20 @@ discard block |
||
| 233 | 233 | * Remove order meta |
| 234 | 234 | * @param object $order |
| 235 | 235 | */ |
| 236 | - public function remove_order_source_before_retry( $order ) { |
|
| 236 | + public function remove_order_source_before_retry($order) { |
|
| 237 | 237 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 238 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
| 238 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
| 239 | 239 | // For BW compat will remove in the future. |
| 240 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 240 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
| 244 | 244 | * Remove order meta |
| 245 | 245 | * @param object $order |
| 246 | 246 | */ |
| 247 | - public function remove_order_customer_before_retry( $order ) { |
|
| 247 | + public function remove_order_customer_before_retry($order) { |
|
| 248 | 248 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 249 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 249 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -258,14 +258,14 @@ discard block |
||
| 258 | 258 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 259 | 259 | * @return void |
| 260 | 260 | */ |
| 261 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 262 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 263 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 264 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 261 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 262 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 263 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 264 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 265 | 265 | |
| 266 | 266 | } else { |
| 267 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 268 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 267 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 268 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
@@ -278,21 +278,21 @@ discard block |
||
| 278 | 278 | * @param WC_Subscription $subscription An instance of a subscription object |
| 279 | 279 | * @return array |
| 280 | 280 | */ |
| 281 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 282 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 281 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 282 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 283 | 283 | |
| 284 | 284 | // For BW compat will remove in future. |
| 285 | - if ( empty( $source_id ) ) { |
|
| 286 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 285 | + if (empty($source_id)) { |
|
| 286 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 287 | 287 | |
| 288 | 288 | // Take this opportunity to update the key name. |
| 289 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
| 289 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $payment_meta[ $this->id ] = array( |
|
| 292 | + $payment_meta[$this->id] = array( |
|
| 293 | 293 | 'post_meta' => array( |
| 294 | 294 | '_stripe_customer_id' => array( |
| 295 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 295 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 296 | 296 | 'label' => 'Stripe Customer ID', |
| 297 | 297 | ), |
| 298 | 298 | '_stripe_source_id' => array( |
@@ -313,22 +313,22 @@ discard block |
||
| 313 | 313 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 314 | 314 | * @return array |
| 315 | 315 | */ |
| 316 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 317 | - if ( $this->id === $payment_method_id ) { |
|
| 316 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 317 | + if ($this->id === $payment_method_id) { |
|
| 318 | 318 | |
| 319 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 320 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
| 321 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 322 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
| 319 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 320 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
| 321 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 322 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | if ( |
| 326 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 327 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
| 328 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 329 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
| 326 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 327 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
| 328 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 329 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
| 330 | 330 | |
| 331 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
| 331 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -341,89 +341,89 @@ discard block |
||
| 341 | 341 | * @param WC_Subscription $subscription the subscription details |
| 342 | 342 | * @return string the subscription payment method |
| 343 | 343 | */ |
| 344 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 344 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 345 | 345 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
| 346 | 346 | |
| 347 | 347 | // bail for other payment methods |
| 348 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 348 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 349 | 349 | return $payment_method_to_display; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 352 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 353 | 353 | |
| 354 | 354 | // For BW compat will remove in future. |
| 355 | - if ( empty( $stripe_source_id ) ) { |
|
| 356 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 355 | + if (empty($stripe_source_id)) { |
|
| 356 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 357 | 357 | |
| 358 | 358 | // Take this opportunity to update the key name. |
| 359 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 359 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | $stripe_customer = new WC_Stripe_Customer(); |
| 363 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 363 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 364 | 364 | |
| 365 | 365 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 366 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 366 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 367 | 367 | $user_id = $customer_user; |
| 368 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 369 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 368 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 369 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 370 | 370 | |
| 371 | 371 | // For BW compat will remove in future. |
| 372 | - if ( empty( $stripe_source_id ) ) { |
|
| 373 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 372 | + if (empty($stripe_source_id)) { |
|
| 373 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 374 | 374 | |
| 375 | 375 | // Take this opportunity to update the key name. |
| 376 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 376 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 381 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 382 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 383 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 381 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 382 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 383 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 384 | 384 | |
| 385 | 385 | // For BW compat will remove in future. |
| 386 | - if ( empty( $stripe_source_id ) ) { |
|
| 387 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 386 | + if (empty($stripe_source_id)) { |
|
| 387 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 388 | 388 | |
| 389 | 389 | // Take this opportunity to update the key name. |
| 390 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 390 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 394 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 395 | 395 | $sources = $stripe_customer->get_sources(); |
| 396 | 396 | |
| 397 | - if ( $sources ) { |
|
| 397 | + if ($sources) { |
|
| 398 | 398 | $found_source = false; |
| 399 | - foreach ( $sources as $source ) { |
|
| 400 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 399 | + foreach ($sources as $source) { |
|
| 400 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 401 | 401 | $card = $source->card; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - if ( $source->id === $stripe_source_id ) { |
|
| 404 | + if ($source->id === $stripe_source_id) { |
|
| 405 | 405 | $found_source = true; |
| 406 | 406 | |
| 407 | - if ( $card ) { |
|
| 407 | + if ($card) { |
|
| 408 | 408 | /* translators: 1) card brand 2) last 4 digits */ |
| 409 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 409 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 410 | 410 | } else { |
| 411 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 411 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 412 | 412 | } |
| 413 | 413 | break; |
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - if ( ! $found_source ) { |
|
| 418 | - if ( 'card' === $sources[0]->type ) { |
|
| 417 | + if ( ! $found_source) { |
|
| 418 | + if ('card' === $sources[0]->type) { |
|
| 419 | 419 | $card = $sources[0]->card; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - if ( $card ) { |
|
| 422 | + if ($card) { |
|
| 423 | 423 | /* translators: 1) card brand 2) last 4 digits */ |
| 424 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 424 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 425 | 425 | } else { |
| 426 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 426 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | } |
@@ -436,42 +436,42 @@ discard block |
||
| 436 | 436 | * @param int $order_id |
| 437 | 437 | * @return array |
| 438 | 438 | */ |
| 439 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
| 440 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 439 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
| 440 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
| 441 | 441 | try { |
| 442 | - $order = wc_get_order( $order_id ); |
|
| 442 | + $order = wc_get_order($order_id); |
|
| 443 | 443 | |
| 444 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 444 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 445 | 445 | /* translators: minimum amount */ |
| 446 | - throw new Exception( 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 ) ) ); |
|
| 446 | + throw new Exception(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))); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - $source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true ); |
|
| 449 | + $source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true); |
|
| 450 | 450 | |
| 451 | 451 | // We need a source on file to continue. |
| 452 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 453 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 452 | + if (empty($source->customer) || empty($source->source)) { |
|
| 453 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - $this->save_source_to_order( $order, $source ); |
|
| 456 | + $this->save_source_to_order($order, $source); |
|
| 457 | 457 | |
| 458 | 458 | // Remove cart |
| 459 | 459 | WC()->cart->empty_cart(); |
| 460 | 460 | |
| 461 | 461 | // Is pre ordered! |
| 462 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 462 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 463 | 463 | |
| 464 | 464 | // Return thank you page redirect |
| 465 | 465 | return array( |
| 466 | 466 | 'result' => 'success', |
| 467 | - 'redirect' => $this->get_return_url( $order ), |
|
| 467 | + 'redirect' => $this->get_return_url($order), |
|
| 468 | 468 | ); |
| 469 | - } catch ( Exception $e ) { |
|
| 470 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 469 | + } catch (Exception $e) { |
|
| 470 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 471 | 471 | return; |
| 472 | 472 | } |
| 473 | 473 | } else { |
| 474 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 474 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 475 | 475 | } |
| 476 | 476 | } |
| 477 | 477 | |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | * @param WC_Order $order |
| 481 | 481 | * @return void |
| 482 | 482 | */ |
| 483 | - public function process_pre_order_release_payment( $order ) { |
|
| 483 | + public function process_pre_order_release_payment($order) { |
|
| 484 | 484 | try { |
| 485 | 485 | // Define some callbacks if the first attempt fails. |
| 486 | 486 | $retry_callbacks = array( |
@@ -488,33 +488,33 @@ discard block |
||
| 488 | 488 | 'remove_order_customer_before_retry', |
| 489 | 489 | ); |
| 490 | 490 | |
| 491 | - while ( 1 ) { |
|
| 492 | - $source = $this->prepare_order_source( $order ); |
|
| 493 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 491 | + while (1) { |
|
| 492 | + $source = $this->prepare_order_source($order); |
|
| 493 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 494 | 494 | |
| 495 | - if ( ! empty( $response->error ) ) { |
|
| 496 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 497 | - throw new Exception( $response->error->message ); |
|
| 495 | + if ( ! empty($response->error)) { |
|
| 496 | + if (0 === sizeof($retry_callbacks)) { |
|
| 497 | + throw new Exception($response->error->message); |
|
| 498 | 498 | } else { |
| 499 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 500 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 499 | + $retry_callback = array_shift($retry_callbacks); |
|
| 500 | + call_user_func(array($this, $retry_callback), $order); |
|
| 501 | 501 | } |
| 502 | 502 | } else { |
| 503 | 503 | // Successful |
| 504 | - $this->process_response( $response, $order ); |
|
| 504 | + $this->process_response($response, $order); |
|
| 505 | 505 | break; |
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | - } catch ( Exception $e ) { |
|
| 508 | + } catch (Exception $e) { |
|
| 509 | 509 | /* translators: error message */ |
| 510 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 510 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 511 | 511 | |
| 512 | 512 | // Mark order as failed if not already set, |
| 513 | 513 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 514 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 515 | - $order->update_status( 'failed', $order_note ); |
|
| 514 | + if ( ! $order->has_status('failed')) { |
|
| 515 | + $order->update_status('failed', $order_note); |
|
| 516 | 516 | } else { |
| 517 | - $order->add_order_note( $order_note ); |
|
| 517 | + $order->add_order_note($order_note); |
|
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function __construct() { |
| 66 | 66 | $this->id = 'stripe_bitcoin'; |
| 67 | - $this->method_title = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
| 67 | + $this->method_title = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
| 68 | 68 | /* translators: link */ |
| 69 | - $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' ) ); |
|
| 69 | + $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')); |
|
| 70 | 70 | $this->supports = array( |
| 71 | 71 | 'products', |
| 72 | 72 | 'refunds', |
@@ -78,29 +78,29 @@ discard block |
||
| 78 | 78 | // Load the settings. |
| 79 | 79 | $this->init_settings(); |
| 80 | 80 | |
| 81 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 82 | - $this->title = $this->get_option( 'title' ); |
|
| 83 | - $this->description = $this->get_option( 'description' ); |
|
| 84 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 85 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 86 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 87 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 88 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 89 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 90 | - |
|
| 91 | - if ( $this->testmode ) { |
|
| 92 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 93 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 81 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 82 | + $this->title = $this->get_option('title'); |
|
| 83 | + $this->description = $this->get_option('description'); |
|
| 84 | + $this->enabled = $this->get_option('enabled'); |
|
| 85 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 86 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 87 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 88 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 89 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 90 | + |
|
| 91 | + if ($this->testmode) { |
|
| 92 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 93 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 97 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 98 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 99 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 100 | - add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) ); |
|
| 96 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 97 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 98 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 99 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 100 | + add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page')); |
|
| 101 | 101 | |
| 102 | 102 | // Customer Emails |
| 103 | - add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); |
|
| 103 | + add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * @version 4.0.0 |
| 111 | 111 | */ |
| 112 | 112 | public function check_environment() { |
| 113 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 113 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $environment_warning = $this->get_environment_warning(); |
| 118 | 118 | |
| 119 | - if ( $environment_warning ) { |
|
| 120 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 119 | + if ($environment_warning) { |
|
| 120 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 124 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 125 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 123 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 124 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 125 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 126 | 126 | echo '</p></div>'; |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -136,12 +136,12 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | public function get_environment_warning() { |
| 138 | 138 | // Add deprecated notice to logs. |
| 139 | - if ( 'yes' === $this->enabled ) { |
|
| 140 | - WC_Stripe_Logger::log( 'DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.' ); |
|
| 139 | + if ('yes' === $this->enabled) { |
|
| 140 | + WC_Stripe_Logger::log('DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.'); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 144 | - $message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' ); |
|
| 143 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 144 | + $message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe'); |
|
| 145 | 145 | |
| 146 | 146 | return $message; |
| 147 | 147 | } |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | * @return array |
| 158 | 158 | */ |
| 159 | 159 | public function get_supported_currency() { |
| 160 | - return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array( |
|
| 160 | + return apply_filters('wc_stripe_bitcoin_supported_currencies', array( |
|
| 161 | 161 | 'USD', |
| 162 | - ) ); |
|
| 162 | + )); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @return bool |
| 171 | 171 | */ |
| 172 | 172 | public function is_available() { |
| 173 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 173 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 174 | 174 | return false; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | $icons_str .= $icons['bitcoin']; |
| 193 | 193 | |
| 194 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 194 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -202,19 +202,19 @@ discard block |
||
| 202 | 202 | * @access public |
| 203 | 203 | */ |
| 204 | 204 | public function payment_scripts() { |
| 205 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 205 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 206 | 206 | return; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 210 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 209 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 210 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | 214 | * Initialize Gateway Settings Form Fields. |
| 215 | 215 | */ |
| 216 | 216 | public function init_form_fields() { |
| 217 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' ); |
|
| 217 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -225,25 +225,25 @@ discard block |
||
| 225 | 225 | $total = WC()->cart->total; |
| 226 | 226 | |
| 227 | 227 | // If paying from order, we need to get total from order not cart. |
| 228 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 229 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 228 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 229 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 230 | 230 | $total = $order->get_total(); |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - if ( is_add_payment_method_page() ) { |
|
| 234 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 235 | - $total = ''; |
|
| 233 | + if (is_add_payment_method_page()) { |
|
| 234 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 235 | + $total = ''; |
|
| 236 | 236 | } else { |
| 237 | 237 | $pay_button_text = ''; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | echo '<div |
| 241 | 241 | id="stripe-bitcoin-payment-data" |
| 242 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 243 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 242 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 243 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 244 | 244 | |
| 245 | - if ( $this->description ) { |
|
| 246 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 245 | + if ($this->description) { |
|
| 246 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | echo '</div>'; |
@@ -254,8 +254,8 @@ discard block |
||
| 254 | 254 | * |
| 255 | 255 | * @param int $order_id |
| 256 | 256 | */ |
| 257 | - public function thankyou_page( $order_id ) { |
|
| 258 | - $this->get_instructions( $order_id ); |
|
| 257 | + public function thankyou_page($order_id) { |
|
| 258 | + $this->get_instructions($order_id); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | * @param bool $sent_to_admin |
| 268 | 268 | * @param bool $plain_text |
| 269 | 269 | */ |
| 270 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
| 270 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
| 271 | 271 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 272 | 272 | |
| 273 | 273 | $payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method(); |
| 274 | 274 | |
| 275 | - if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) { |
|
| 276 | - $this->get_instructions( $order_id, $plain_text ); |
|
| 275 | + if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) { |
|
| 276 | + $this->get_instructions($order_id, $plain_text); |
|
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | |
@@ -284,38 +284,38 @@ discard block |
||
| 284 | 284 | * @version 4.0.0 |
| 285 | 285 | * @param int $order_id |
| 286 | 286 | */ |
| 287 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
| 288 | - $data = get_post_meta( $order_id, '_stripe_bitcoin', true ); |
|
| 287 | + public function get_instructions($order_id, $plain_text = false) { |
|
| 288 | + $data = get_post_meta($order_id, '_stripe_bitcoin', true); |
|
| 289 | 289 | |
| 290 | - if ( $plain_text ) { |
|
| 291 | - esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 290 | + if ($plain_text) { |
|
| 291 | + esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 292 | 292 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 293 | - esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 293 | + esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 294 | 294 | echo $data['amount'] . "\n\n"; |
| 295 | 295 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 296 | - esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 296 | + esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 297 | 297 | echo $data['address'] . "\n\n"; |
| 298 | 298 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 299 | - esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 299 | + esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 300 | 300 | echo $data['uri'] . "\n\n"; |
| 301 | 301 | } else { |
| 302 | 302 | ?> |
| 303 | - <h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
| 303 | + <h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3> |
|
| 304 | 304 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
| 305 | 305 | <li class="woocommerce-order-overview__order order"> |
| 306 | - <?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?> |
|
| 306 | + <?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?> |
|
| 307 | 307 | <strong><?php echo $data['amount']; ?></strong> |
| 308 | 308 | </li> |
| 309 | 309 | <li class="woocommerce-order-overview__order order"> |
| 310 | - <?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?> |
|
| 310 | + <?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?> |
|
| 311 | 311 | <strong><?php echo $data['address']; ?></strong> |
| 312 | 312 | </li> |
| 313 | 313 | <li class="woocommerce-order-overview__order order"> |
| 314 | - <?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?> |
|
| 314 | + <?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?> |
|
| 315 | 315 | <strong> |
| 316 | 316 | <?php |
| 317 | 317 | /* translators: link */ |
| 318 | - printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] ); |
|
| 318 | + printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']); |
|
| 319 | 319 | ?> |
| 320 | 320 | </strong> |
| 321 | 321 | </li> |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | * @param object $order |
| 333 | 333 | * @param object $source_object |
| 334 | 334 | */ |
| 335 | - public function save_instructions( $order, $source_object ) { |
|
| 335 | + public function save_instructions($order, $source_object) { |
|
| 336 | 336 | $data = array( |
| 337 | 337 | 'amount' => $source_object->bitcoin->amount, |
| 338 | 338 | 'address' => $source_object->bitcoin->address, |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | |
| 342 | 342 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 343 | 343 | |
| 344 | - update_post_meta( $order_id, '_stripe_bitcoin', $data ); |
|
| 344 | + update_post_meta($order_id, '_stripe_bitcoin', $data); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -355,37 +355,37 @@ discard block |
||
| 355 | 355 | * |
| 356 | 356 | * @return array|void |
| 357 | 357 | */ |
| 358 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 358 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 359 | 359 | try { |
| 360 | - $order = wc_get_order( $order_id ); |
|
| 360 | + $order = wc_get_order($order_id); |
|
| 361 | 361 | |
| 362 | 362 | // This comes from the create account checkbox in the checkout page. |
| 363 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 363 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 364 | 364 | |
| 365 | - if ( $create_account ) { |
|
| 365 | + if ($create_account) { |
|
| 366 | 366 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 367 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 367 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 368 | 368 | $new_stripe_customer->create_customer(); |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - $prepared_source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), $force_save_source ); |
|
| 371 | + $prepared_source = $this->prepare_source($this->get_source_object(), get_current_user_id(), $force_save_source); |
|
| 372 | 372 | |
| 373 | - if ( empty( $prepared_source->source ) ) { |
|
| 374 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 375 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 373 | + if (empty($prepared_source->source)) { |
|
| 374 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 375 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - $this->save_source_to_order( $order, $prepared_source ); |
|
| 378 | + $this->save_source_to_order($order, $prepared_source); |
|
| 379 | 379 | |
| 380 | 380 | // This will throw exception if not valid. |
| 381 | - $this->validate_minimum_order_amount( $order ); |
|
| 381 | + $this->validate_minimum_order_amount($order); |
|
| 382 | 382 | |
| 383 | - $this->save_instructions( $order, $this->get_source_object() ); |
|
| 383 | + $this->save_instructions($order, $this->get_source_object()); |
|
| 384 | 384 | |
| 385 | 385 | // Mark as on-hold (we're awaiting the payment) |
| 386 | - $order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) ); |
|
| 386 | + $order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe')); |
|
| 387 | 387 | |
| 388 | - wc_reduce_stock_levels( $order_id ); |
|
| 388 | + wc_reduce_stock_levels($order_id); |
|
| 389 | 389 | |
| 390 | 390 | // Remove cart |
| 391 | 391 | WC()->cart->empty_cart(); |
@@ -393,16 +393,16 @@ discard block |
||
| 393 | 393 | // Return thankyou redirect |
| 394 | 394 | return array( |
| 395 | 395 | 'result' => 'success', |
| 396 | - 'redirect' => $this->get_return_url( $order ), |
|
| 396 | + 'redirect' => $this->get_return_url($order), |
|
| 397 | 397 | ); |
| 398 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 399 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 400 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 398 | + } catch (WC_Stripe_Exception $e) { |
|
| 399 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 400 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 401 | 401 | |
| 402 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 402 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 403 | 403 | |
| 404 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 405 | - $this->send_failed_order_email( $order_id ); |
|
| 404 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 405 | + $this->send_failed_order_email($order_id); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | return array( |