@@ -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 | } |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | * @version 4.0.0 |
| 136 | 136 | */ |
| 137 | 137 | public function get_environment_warning() { |
| 138 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 139 | - $message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' ); |
|
| 138 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 139 | + $message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe'); |
|
| 140 | 140 | |
| 141 | 141 | return $message; |
| 142 | 142 | } |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | * @return array |
| 153 | 153 | */ |
| 154 | 154 | public function get_supported_currency() { |
| 155 | - return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array( |
|
| 155 | + return apply_filters('wc_stripe_bitcoin_supported_currencies', array( |
|
| 156 | 156 | 'USD', |
| 157 | - ) ); |
|
| 157 | + )); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @return bool |
| 166 | 166 | */ |
| 167 | 167 | public function is_available() { |
| 168 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 168 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 169 | 169 | return false; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | * @return array |
| 181 | 181 | */ |
| 182 | 182 | public function payment_icons() { |
| 183 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 183 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 184 | 184 | 'bitcoin' => '<i class="stripe-pf stripe-pf-bitcoin stripe-pf-right" alt="Bitcoin" aria-hidden="true"></i>', |
| 185 | - ) ); |
|
| 185 | + )); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $icons_str .= $icons['bitcoin']; |
| 201 | 201 | |
| 202 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 202 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -210,19 +210,19 @@ discard block |
||
| 210 | 210 | * @access public |
| 211 | 211 | */ |
| 212 | 212 | public function payment_scripts() { |
| 213 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 213 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 214 | 214 | return; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 218 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 217 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 218 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | 222 | * Initialize Gateway Settings Form Fields. |
| 223 | 223 | */ |
| 224 | 224 | public function init_form_fields() { |
| 225 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' ); |
|
| 225 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php'); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -233,25 +233,25 @@ discard block |
||
| 233 | 233 | $total = WC()->cart->total; |
| 234 | 234 | |
| 235 | 235 | // If paying from order, we need to get total from order not cart. |
| 236 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 237 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 236 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 237 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 238 | 238 | $total = $order->get_total(); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if ( is_add_payment_method_page() ) { |
|
| 242 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 243 | - $total = ''; |
|
| 241 | + if (is_add_payment_method_page()) { |
|
| 242 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 243 | + $total = ''; |
|
| 244 | 244 | } else { |
| 245 | 245 | $pay_button_text = ''; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | echo '<div |
| 249 | 249 | id="stripe-bitcoin-payment-data" |
| 250 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 251 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 250 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 251 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 252 | 252 | |
| 253 | - if ( $this->description ) { |
|
| 254 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 253 | + if ($this->description) { |
|
| 254 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | echo '</div>'; |
@@ -262,8 +262,8 @@ discard block |
||
| 262 | 262 | * |
| 263 | 263 | * @param int $order_id |
| 264 | 264 | */ |
| 265 | - public function thankyou_page( $order_id ) { |
|
| 266 | - $this->get_instructions( $order_id ); |
|
| 265 | + public function thankyou_page($order_id) { |
|
| 266 | + $this->get_instructions($order_id); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -275,13 +275,13 @@ discard block |
||
| 275 | 275 | * @param bool $sent_to_admin |
| 276 | 276 | * @param bool $plain_text |
| 277 | 277 | */ |
| 278 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
| 278 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
| 279 | 279 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 280 | 280 | |
| 281 | 281 | $payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method(); |
| 282 | 282 | |
| 283 | - if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) { |
|
| 284 | - $this->get_instructions( $order_id, $plain_text ); |
|
| 283 | + if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) { |
|
| 284 | + $this->get_instructions($order_id, $plain_text); |
|
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | |
@@ -292,38 +292,38 @@ discard block |
||
| 292 | 292 | * @version 4.0.0 |
| 293 | 293 | * @param int $order_id |
| 294 | 294 | */ |
| 295 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
| 296 | - $data = get_post_meta( $order_id, '_stripe_bitcoin', true ); |
|
| 295 | + public function get_instructions($order_id, $plain_text = false) { |
|
| 296 | + $data = get_post_meta($order_id, '_stripe_bitcoin', true); |
|
| 297 | 297 | |
| 298 | - if ( $plain_text ) { |
|
| 299 | - esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 298 | + if ($plain_text) { |
|
| 299 | + esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 300 | 300 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 301 | - esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 301 | + esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 302 | 302 | echo $data['amount'] . "\n\n"; |
| 303 | 303 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 304 | - esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 304 | + esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 305 | 305 | echo $data['address'] . "\n\n"; |
| 306 | 306 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 307 | - esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 307 | + esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 308 | 308 | echo $data['uri'] . "\n\n"; |
| 309 | 309 | } else { |
| 310 | 310 | ?> |
| 311 | - <h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
| 311 | + <h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3> |
|
| 312 | 312 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
| 313 | 313 | <li class="woocommerce-order-overview__order order"> |
| 314 | - <?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?> |
|
| 314 | + <?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?> |
|
| 315 | 315 | <strong><?php echo $data['amount']; ?></strong> |
| 316 | 316 | </li> |
| 317 | 317 | <li class="woocommerce-order-overview__order order"> |
| 318 | - <?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?> |
|
| 318 | + <?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?> |
|
| 319 | 319 | <strong><?php echo $data['address']; ?></strong> |
| 320 | 320 | </li> |
| 321 | 321 | <li class="woocommerce-order-overview__order order"> |
| 322 | - <?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?> |
|
| 322 | + <?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?> |
|
| 323 | 323 | <strong> |
| 324 | 324 | <?php |
| 325 | 325 | /* translators: link */ |
| 326 | - printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] ); |
|
| 326 | + printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']); |
|
| 327 | 327 | ?> |
| 328 | 328 | </strong> |
| 329 | 329 | </li> |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | * @param object $order |
| 341 | 341 | * @param object $source_object |
| 342 | 342 | */ |
| 343 | - public function save_instructions( $order, $source_object ) { |
|
| 343 | + public function save_instructions($order, $source_object) { |
|
| 344 | 344 | $data = array( |
| 345 | 345 | 'amount' => $source_object->bitcoin->amount, |
| 346 | 346 | 'address' => $source_object->bitcoin->address, |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | |
| 350 | 350 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 351 | 351 | |
| 352 | - update_post_meta( $order_id, '_stripe_bitcoin', $data ); |
|
| 352 | + update_post_meta($order_id, '_stripe_bitcoin', $data); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -363,40 +363,40 @@ discard block |
||
| 363 | 363 | * |
| 364 | 364 | * @return array|void |
| 365 | 365 | */ |
| 366 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 366 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 367 | 367 | try { |
| 368 | - $order = wc_get_order( $order_id ); |
|
| 369 | - $source_object = ! empty( $_POST['stripe_source'] ) ? json_decode( stripslashes( $_POST['stripe_source'] ) ) : false; |
|
| 368 | + $order = wc_get_order($order_id); |
|
| 369 | + $source_object = ! empty($_POST['stripe_source']) ? json_decode(stripslashes($_POST['stripe_source'])) : false; |
|
| 370 | 370 | |
| 371 | 371 | // This comes from the create account checkbox in the checkout page. |
| 372 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 372 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 373 | 373 | |
| 374 | - if ( $create_account ) { |
|
| 374 | + if ($create_account) { |
|
| 375 | 375 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 376 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 376 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 377 | 377 | $new_stripe_customer->create_customer(); |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
| 380 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
| 381 | 381 | |
| 382 | - if ( empty( $prepared_source->source ) ) { |
|
| 383 | - $error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 384 | - throw new Exception( $error_msg ); |
|
| 382 | + if (empty($prepared_source->source)) { |
|
| 383 | + $error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 384 | + throw new Exception($error_msg); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | // Store source to order meta. |
| 388 | - $this->save_source( $order, $prepared_source ); |
|
| 388 | + $this->save_source($order, $prepared_source); |
|
| 389 | 389 | |
| 390 | 390 | |
| 391 | 391 | // This will throw exception if not valid. |
| 392 | - $this->validate_minimum_order_amount( $order ); |
|
| 392 | + $this->validate_minimum_order_amount($order); |
|
| 393 | 393 | |
| 394 | - $this->save_instructions( $order, $source_object ); |
|
| 394 | + $this->save_instructions($order, $source_object); |
|
| 395 | 395 | |
| 396 | 396 | // Mark as on-hold (we're awaiting the payment) |
| 397 | - $order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) ); |
|
| 397 | + $order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe')); |
|
| 398 | 398 | |
| 399 | - wc_reduce_stock_levels( $order_id ); |
|
| 399 | + wc_reduce_stock_levels($order_id); |
|
| 400 | 400 | |
| 401 | 401 | // Remove cart |
| 402 | 402 | WC()->cart->empty_cart(); |
@@ -404,16 +404,16 @@ discard block |
||
| 404 | 404 | // Return thankyou redirect |
| 405 | 405 | return array( |
| 406 | 406 | 'result' => 'success', |
| 407 | - 'redirect' => $this->get_return_url( $order ), |
|
| 407 | + 'redirect' => $this->get_return_url($order), |
|
| 408 | 408 | ); |
| 409 | - } catch ( Exception $e ) { |
|
| 410 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 411 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 409 | + } catch (Exception $e) { |
|
| 410 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 411 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 412 | 412 | |
| 413 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 413 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 414 | 414 | |
| 415 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 416 | - $this->send_failed_order_email( $order_id ); |
|
| 415 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 416 | + $this->send_failed_order_email($order_id); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | 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_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 | |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | */ |
| 171 | 171 | public function payment_icons() { |
| 172 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 172 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 173 | 173 | 'bancontact' => '<i class="stripe-pf stripe-pf-bancontact-mister-cash stripe-pf-right" alt="Bancontact" aria-hidden="true"></i>', |
| 174 | - ) ); |
|
| 174 | + )); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $icons_str .= $icons['bancontact']; |
| 190 | 190 | |
| 191 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 191 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,19 +199,19 @@ discard block |
||
| 199 | 199 | * @access public |
| 200 | 200 | */ |
| 201 | 201 | public function payment_scripts() { |
| 202 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 202 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 203 | 203 | return; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 207 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 206 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 207 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
| 211 | 211 | * Initialize Gateway Settings Form Fields. |
| 212 | 212 | */ |
| 213 | 213 | public function init_form_fields() { |
| 214 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
| 214 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -222,25 +222,25 @@ discard block |
||
| 222 | 222 | $total = WC()->cart->total; |
| 223 | 223 | |
| 224 | 224 | // If paying from order, we need to get total from order not cart. |
| 225 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 226 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 225 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 226 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 227 | 227 | $total = $order->get_total(); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ( is_add_payment_method_page() ) { |
|
| 231 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 232 | - $total = ''; |
|
| 230 | + if (is_add_payment_method_page()) { |
|
| 231 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 232 | + $total = ''; |
|
| 233 | 233 | } else { |
| 234 | 234 | $pay_button_text = ''; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | echo '<div |
| 238 | 238 | id="stripe-bancontact-payment-data" |
| 239 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 240 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 239 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 240 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 241 | 241 | |
| 242 | - if ( $this->description ) { |
|
| 243 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 242 | + if ($this->description) { |
|
| 243 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | echo '</div>'; |
@@ -254,24 +254,24 @@ discard block |
||
| 254 | 254 | * @param object $order |
| 255 | 255 | * @return mixed |
| 256 | 256 | */ |
| 257 | - public function create_source( $order ) { |
|
| 257 | + public function create_source($order) { |
|
| 258 | 258 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 259 | 259 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 260 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 260 | + $return_url = $this->get_stripe_return_url($order); |
|
| 261 | 261 | $post_data = array(); |
| 262 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 263 | - $post_data['currency'] = strtolower( $currency ); |
|
| 262 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 263 | + $post_data['currency'] = strtolower($currency); |
|
| 264 | 264 | $post_data['type'] = 'bancontact'; |
| 265 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 266 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 265 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 266 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 267 | 267 | |
| 268 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 269 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 268 | + if ( ! empty($this->statement_descriptor)) { |
|
| 269 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
| 272 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
| 273 | 273 | |
| 274 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 274 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -285,51 +285,51 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @return array|void |
| 287 | 287 | */ |
| 288 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 288 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 289 | 289 | try { |
| 290 | - $order = wc_get_order( $order_id ); |
|
| 290 | + $order = wc_get_order($order_id); |
|
| 291 | 291 | |
| 292 | 292 | // This will throw exception if not valid. |
| 293 | - $this->validate_minimum_order_amount( $order ); |
|
| 293 | + $this->validate_minimum_order_amount($order); |
|
| 294 | 294 | |
| 295 | 295 | // This comes from the create account checkbox in the checkout page. |
| 296 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 296 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 297 | 297 | |
| 298 | - if ( $create_account ) { |
|
| 298 | + if ($create_account) { |
|
| 299 | 299 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 300 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 300 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 301 | 301 | $new_stripe_customer->create_customer(); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - $response = $this->create_source( $order ); |
|
| 304 | + $response = $this->create_source($order); |
|
| 305 | 305 | |
| 306 | - if ( ! empty( $response->error ) ) { |
|
| 307 | - $order->add_order_note( $response->error->message ); |
|
| 306 | + if ( ! empty($response->error)) { |
|
| 307 | + $order->add_order_note($response->error->message); |
|
| 308 | 308 | |
| 309 | - throw new Exception( $response->error->message ); |
|
| 309 | + throw new Exception($response->error->message); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 313 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 312 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 313 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 314 | 314 | } else { |
| 315 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 315 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 316 | 316 | $order->save(); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
| 319 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
| 320 | 320 | |
| 321 | 321 | return array( |
| 322 | 322 | 'result' => 'success', |
| 323 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 323 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 324 | 324 | ); |
| 325 | - } catch ( Exception $e ) { |
|
| 326 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 327 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 325 | + } catch (Exception $e) { |
|
| 326 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 327 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 328 | 328 | |
| 329 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 329 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 330 | 330 | |
| 331 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 332 | - $this->send_failed_order_email( $order_id ); |
|
| 331 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 332 | + $this->send_failed_order_email($order_id); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | 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 | |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | */ |
| 171 | 171 | public function payment_icons() { |
| 172 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 172 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 173 | 173 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
| 174 | - ) ); |
|
| 174 | + )); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $icons_str .= $icons['sofort']; |
| 190 | 190 | |
| 191 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 191 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,19 +199,19 @@ discard block |
||
| 199 | 199 | * @access public |
| 200 | 200 | */ |
| 201 | 201 | public function payment_scripts() { |
| 202 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 202 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 203 | 203 | return; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 207 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 206 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 207 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
| 211 | 211 | * Initialize Gateway Settings Form Fields. |
| 212 | 212 | */ |
| 213 | 213 | public function init_form_fields() { |
| 214 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
| 214 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -230,24 +230,24 @@ discard block |
||
| 230 | 230 | 'IT' => 'Italy', |
| 231 | 231 | ); |
| 232 | 232 | ?> |
| 233 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
| 234 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
| 233 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
| 234 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
| 235 | 235 | <label for="stripe-bank-country"> |
| 236 | - <?php _e( 'Country origin of your bank.', 'woocommerce-gateway-stripe' ); ?> |
|
| 236 | + <?php _e('Country origin of your bank.', 'woocommerce-gateway-stripe'); ?> |
|
| 237 | 237 | </label> |
| 238 | 238 | <br /> |
| 239 | 239 | <p class="form-row form-row-wide validate-required"> |
| 240 | 240 | <select id="stripe-bank-country" class="wc-enhanced-select" name="stripe_sofort_bank_country"> |
| 241 | - <option value="-1"><?php esc_html_e( 'Choose Bank Country', 'woocommerce-gateway-stripe' ); ?></option> |
|
| 242 | - <?php foreach ( $supported_countries as $code => $country ) { ?> |
|
| 243 | - <option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $country ); ?></option> |
|
| 241 | + <option value="-1"><?php esc_html_e('Choose Bank Country', 'woocommerce-gateway-stripe'); ?></option> |
|
| 242 | + <?php foreach ($supported_countries as $code => $country) { ?> |
|
| 243 | + <option value="<?php echo esc_attr($code); ?>"><?php echo esc_html($country); ?></option> |
|
| 244 | 244 | <?php } ?> |
| 245 | 245 | </select> |
| 246 | 246 | </p> |
| 247 | 247 | |
| 248 | 248 | <!-- Used to display form errors --> |
| 249 | 249 | <div class="stripe-source-errors" role="alert"></div> |
| 250 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
| 250 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
| 251 | 251 | <div class="clear"></div> |
| 252 | 252 | </fieldset> |
| 253 | 253 | <?php |
@@ -261,25 +261,25 @@ discard block |
||
| 261 | 261 | $total = WC()->cart->total; |
| 262 | 262 | |
| 263 | 263 | // If paying from order, we need to get total from order not cart. |
| 264 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 265 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 264 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 265 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 266 | 266 | $total = $order->get_total(); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - if ( is_add_payment_method_page() ) { |
|
| 270 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 271 | - $total = ''; |
|
| 269 | + if (is_add_payment_method_page()) { |
|
| 270 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 271 | + $total = ''; |
|
| 272 | 272 | } else { |
| 273 | 273 | $pay_button_text = ''; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | echo '<div |
| 277 | 277 | id="stripe-sofort-payment-data" |
| 278 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 279 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 278 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 279 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 280 | 280 | |
| 281 | - if ( $this->description ) { |
|
| 282 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 281 | + if ($this->description) { |
|
| 282 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | $this->form(); |
@@ -295,26 +295,26 @@ discard block |
||
| 295 | 295 | * @param object $order |
| 296 | 296 | * @return mixed |
| 297 | 297 | */ |
| 298 | - public function create_source( $order ) { |
|
| 298 | + public function create_source($order) { |
|
| 299 | 299 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 300 | 300 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 301 | - $bank_country = wc_clean( $_POST['stripe_sofort_bank_country'] ); |
|
| 302 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 301 | + $bank_country = wc_clean($_POST['stripe_sofort_bank_country']); |
|
| 302 | + $return_url = $this->get_stripe_return_url($order); |
|
| 303 | 303 | $post_data = array(); |
| 304 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 305 | - $post_data['currency'] = strtolower( $currency ); |
|
| 304 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 305 | + $post_data['currency'] = strtolower($currency); |
|
| 306 | 306 | $post_data['type'] = 'sofort'; |
| 307 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 308 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 309 | - $post_data['sofort'] = array( 'country' => $bank_country ); |
|
| 307 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 308 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 309 | + $post_data['sofort'] = array('country' => $bank_country); |
|
| 310 | 310 | |
| 311 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 312 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 311 | + if ( ! empty($this->statement_descriptor)) { |
|
| 312 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
| 315 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
| 316 | 316 | |
| 317 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 317 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -328,51 +328,51 @@ discard block |
||
| 328 | 328 | * |
| 329 | 329 | * @return array|void |
| 330 | 330 | */ |
| 331 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 331 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 332 | 332 | try { |
| 333 | - $order = wc_get_order( $order_id ); |
|
| 333 | + $order = wc_get_order($order_id); |
|
| 334 | 334 | |
| 335 | 335 | // This will throw exception if not valid. |
| 336 | - $this->validate_minimum_order_amount( $order ); |
|
| 336 | + $this->validate_minimum_order_amount($order); |
|
| 337 | 337 | |
| 338 | 338 | // This comes from the create account checkbox in the checkout page. |
| 339 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 339 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 340 | 340 | |
| 341 | - if ( $create_account ) { |
|
| 341 | + if ($create_account) { |
|
| 342 | 342 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 343 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 343 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 344 | 344 | $new_stripe_customer->create_customer(); |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - $response = $this->create_source( $order ); |
|
| 347 | + $response = $this->create_source($order); |
|
| 348 | 348 | |
| 349 | - if ( ! empty( $response->error ) ) { |
|
| 350 | - $order->add_order_note( $response->error->message ); |
|
| 349 | + if ( ! empty($response->error)) { |
|
| 350 | + $order->add_order_note($response->error->message); |
|
| 351 | 351 | |
| 352 | - throw new Exception( $response->error->message ); |
|
| 352 | + throw new Exception($response->error->message); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 356 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 355 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 356 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 357 | 357 | } else { |
| 358 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 358 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 359 | 359 | $order->save(); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
| 362 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
| 363 | 363 | |
| 364 | 364 | return array( |
| 365 | 365 | 'result' => 'success', |
| 366 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 366 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 367 | 367 | ); |
| 368 | - } catch ( Exception $e ) { |
|
| 369 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 370 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 368 | + } catch (Exception $e) { |
|
| 369 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 370 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 371 | 371 | |
| 372 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 372 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 373 | 373 | |
| 374 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 375 | - $this->send_failed_order_email( $order_id ); |
|
| 374 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 375 | + $this->send_failed_order_email($order_id); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | 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_alipay'; |
| 60 | - $this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe Alipay', '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 | } |
@@ -125,10 +125,10 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | 127 | if ( |
| 128 | - 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) |
|
| 128 | + 'yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency()) |
|
| 129 | 129 | ) { |
| 130 | 130 | /* translators: supported currency list */ |
| 131 | - $message = sprintf( __( 'Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe' ), implode( ', ', $this->get_supported_currency() ) ); |
|
| 131 | + $message = sprintf(__('Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe'), implode(', ', $this->get_supported_currency())); |
|
| 132 | 132 | |
| 133 | 133 | return $message; |
| 134 | 134 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return array |
| 145 | 145 | */ |
| 146 | 146 | public function get_supported_currency() { |
| 147 | - return apply_filters( 'wc_stripe_alipay_supported_currencies', array( |
|
| 147 | + return apply_filters('wc_stripe_alipay_supported_currencies', array( |
|
| 148 | 148 | 'EUR', |
| 149 | 149 | 'AUD', |
| 150 | 150 | 'CAD', |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | 'NZD', |
| 155 | 155 | 'SGD', |
| 156 | 156 | 'USD', |
| 157 | - ) ); |
|
| 157 | + )); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @return bool |
| 166 | 166 | */ |
| 167 | 167 | public function is_available() { |
| 168 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 168 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 169 | 169 | return false; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | * @return array |
| 181 | 181 | */ |
| 182 | 182 | public function payment_icons() { |
| 183 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 183 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 184 | 184 | 'alipay' => '<i class="stripe-pf stripe-pf-alipay stripe-pf-right" alt="Alipay" aria-hidden="true"></i>', |
| 185 | - ) ); |
|
| 185 | + )); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $icons_str .= $icons['alipay']; |
| 201 | 201 | |
| 202 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 202 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -209,19 +209,19 @@ discard block |
||
| 209 | 209 | * @version 4.0.0 |
| 210 | 210 | */ |
| 211 | 211 | public function payment_scripts() { |
| 212 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 212 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 213 | 213 | return; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 217 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 216 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 217 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
| 221 | 221 | * Initialize Gateway Settings Form Fields. |
| 222 | 222 | */ |
| 223 | 223 | public function init_form_fields() { |
| 224 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
| 224 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -232,25 +232,25 @@ discard block |
||
| 232 | 232 | $total = WC()->cart->total; |
| 233 | 233 | |
| 234 | 234 | // If paying from order, we need to get total from order not cart. |
| 235 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 236 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 235 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 236 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 237 | 237 | $total = $order->get_total(); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - if ( is_add_payment_method_page() ) { |
|
| 241 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 242 | - $total = ''; |
|
| 240 | + if (is_add_payment_method_page()) { |
|
| 241 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 242 | + $total = ''; |
|
| 243 | 243 | } else { |
| 244 | 244 | $pay_button_text = ''; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | echo '<div |
| 248 | 248 | id="stripe-alipay-payment-data" |
| 249 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 250 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 249 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 250 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 251 | 251 | |
| 252 | - if ( $this->description ) { |
|
| 253 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 252 | + if ($this->description) { |
|
| 253 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | echo '</div>'; |
@@ -264,24 +264,24 @@ discard block |
||
| 264 | 264 | * @param object $order |
| 265 | 265 | * @return mixed |
| 266 | 266 | */ |
| 267 | - public function create_source( $order ) { |
|
| 267 | + public function create_source($order) { |
|
| 268 | 268 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 269 | 269 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 270 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 270 | + $return_url = $this->get_stripe_return_url($order); |
|
| 271 | 271 | $post_data = array(); |
| 272 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 273 | - $post_data['currency'] = strtolower( $currency ); |
|
| 272 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 273 | + $post_data['currency'] = strtolower($currency); |
|
| 274 | 274 | $post_data['type'] = 'alipay'; |
| 275 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 276 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 275 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 276 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 277 | 277 | |
| 278 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 279 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 278 | + if ( ! empty($this->statement_descriptor)) { |
|
| 279 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
| 282 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
| 283 | 283 | |
| 284 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 284 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -295,53 +295,53 @@ discard block |
||
| 295 | 295 | * |
| 296 | 296 | * @return array|void |
| 297 | 297 | */ |
| 298 | - public function process_payment( $order_id, $retry = true, $force_save_save = false ) { |
|
| 298 | + public function process_payment($order_id, $retry = true, $force_save_save = false) { |
|
| 299 | 299 | try { |
| 300 | - $order = wc_get_order( $order_id ); |
|
| 300 | + $order = wc_get_order($order_id); |
|
| 301 | 301 | |
| 302 | 302 | // This will throw exception if not valid. |
| 303 | - $this->validate_minimum_order_amount( $order ); |
|
| 303 | + $this->validate_minimum_order_amount($order); |
|
| 304 | 304 | |
| 305 | 305 | // This comes from the create account checkbox in the checkout page. |
| 306 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 306 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 307 | 307 | |
| 308 | - if ( $create_account ) { |
|
| 308 | + if ($create_account) { |
|
| 309 | 309 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 310 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 310 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 311 | 311 | $new_stripe_customer->create_customer(); |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - $response = $this->create_source( $order ); |
|
| 314 | + $response = $this->create_source($order); |
|
| 315 | 315 | |
| 316 | - if ( ! empty( $response->error ) ) { |
|
| 317 | - $order->add_order_note( $response->error->message ); |
|
| 316 | + if ( ! empty($response->error)) { |
|
| 317 | + $order->add_order_note($response->error->message); |
|
| 318 | 318 | |
| 319 | - throw new Exception( $response->error->message ); |
|
| 319 | + throw new Exception($response->error->message); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 323 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 322 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 323 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 324 | 324 | } else { |
| 325 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 325 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 326 | 326 | $order->save(); |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
| 329 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
| 330 | 330 | |
| 331 | 331 | return array( |
| 332 | 332 | 'result' => 'success', |
| 333 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 333 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 334 | 334 | ); |
| 335 | - } catch ( Exception $e ) { |
|
| 336 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 337 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 335 | + } catch (Exception $e) { |
|
| 336 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 337 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 338 | 338 | |
| 339 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 339 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 340 | 340 | |
| 341 | - $statuses = array( 'pending', 'failed' ); |
|
| 341 | + $statuses = array('pending', 'failed'); |
|
| 342 | 342 | |
| 343 | - if ( $order->has_status( $statuses ) ) { |
|
| 344 | - $this->send_failed_order_email( $order_id ); |
|
| 343 | + if ($order->has_status($statuses)) { |
|
| 344 | + $this->send_failed_order_email($order_id); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | 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 | |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | */ |
| 171 | 171 | public function payment_icons() { |
| 172 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 172 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 173 | 173 | 'giropay' => '<i class="stripe-pf stripe-pf-giropay stripe-pf-right" alt="Giropay" aria-hidden="true"></i>', |
| 174 | - ) ); |
|
| 174 | + )); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $icons_str .= $icons['giropay']; |
| 190 | 190 | |
| 191 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 191 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,19 +199,19 @@ discard block |
||
| 199 | 199 | * @access public |
| 200 | 200 | */ |
| 201 | 201 | public function payment_scripts() { |
| 202 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 202 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 203 | 203 | return; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 207 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 206 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 207 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
| 211 | 211 | * Initialize Gateway Settings Form Fields. |
| 212 | 212 | */ |
| 213 | 213 | public function init_form_fields() { |
| 214 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' ); |
|
| 214 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php'); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -222,25 +222,25 @@ discard block |
||
| 222 | 222 | $total = WC()->cart->total; |
| 223 | 223 | |
| 224 | 224 | // If paying from order, we need to get total from order not cart. |
| 225 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 226 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 225 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 226 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 227 | 227 | $total = $order->get_total(); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ( is_add_payment_method_page() ) { |
|
| 231 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 232 | - $total = ''; |
|
| 230 | + if (is_add_payment_method_page()) { |
|
| 231 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 232 | + $total = ''; |
|
| 233 | 233 | } else { |
| 234 | 234 | $pay_button_text = ''; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | echo '<div |
| 238 | 238 | id="stripe-giropay-payment-data" |
| 239 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 240 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 239 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 240 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 241 | 241 | |
| 242 | - if ( $this->description ) { |
|
| 243 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 242 | + if ($this->description) { |
|
| 243 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | echo '</div>'; |
@@ -254,24 +254,24 @@ discard block |
||
| 254 | 254 | * @param object $order |
| 255 | 255 | * @return mixed |
| 256 | 256 | */ |
| 257 | - public function create_source( $order ) { |
|
| 257 | + public function create_source($order) { |
|
| 258 | 258 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 259 | 259 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 260 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 260 | + $return_url = $this->get_stripe_return_url($order); |
|
| 261 | 261 | $post_data = array(); |
| 262 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 263 | - $post_data['currency'] = strtolower( $currency ); |
|
| 262 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 263 | + $post_data['currency'] = strtolower($currency); |
|
| 264 | 264 | $post_data['type'] = 'giropay'; |
| 265 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 266 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 265 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 266 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 267 | 267 | |
| 268 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 269 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 268 | + if ( ! empty($this->statement_descriptor)) { |
|
| 269 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' ); |
|
| 272 | + WC_Stripe_Logger::log('Info: Begin creating Giropay source'); |
|
| 273 | 273 | |
| 274 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 274 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -285,51 +285,51 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @return array|void |
| 287 | 287 | */ |
| 288 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 288 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 289 | 289 | try { |
| 290 | - $order = wc_get_order( $order_id ); |
|
| 290 | + $order = wc_get_order($order_id); |
|
| 291 | 291 | |
| 292 | 292 | // This will throw exception if not valid. |
| 293 | - $this->validate_minimum_order_amount( $order ); |
|
| 293 | + $this->validate_minimum_order_amount($order); |
|
| 294 | 294 | |
| 295 | 295 | // This comes from the create account checkbox in the checkout page. |
| 296 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 296 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 297 | 297 | |
| 298 | - if ( $create_account ) { |
|
| 298 | + if ($create_account) { |
|
| 299 | 299 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 300 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 300 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 301 | 301 | $new_stripe_customer->create_customer(); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - $response = $this->create_source( $order ); |
|
| 304 | + $response = $this->create_source($order); |
|
| 305 | 305 | |
| 306 | - if ( ! empty( $response->error ) ) { |
|
| 307 | - $order->add_order_note( $response->error->message ); |
|
| 306 | + if ( ! empty($response->error)) { |
|
| 307 | + $order->add_order_note($response->error->message); |
|
| 308 | 308 | |
| 309 | - throw new Exception( $response->error->message ); |
|
| 309 | + throw new Exception($response->error->message); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 313 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 312 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 313 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 314 | 314 | } else { |
| 315 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 315 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 316 | 316 | $order->save(); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' ); |
|
| 319 | + WC_Stripe_Logger::log('Info: Redirecting to Giropay...'); |
|
| 320 | 320 | |
| 321 | 321 | return array( |
| 322 | 322 | 'result' => 'success', |
| 323 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 323 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 324 | 324 | ); |
| 325 | - } catch ( Exception $e ) { |
|
| 326 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 327 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 325 | + } catch (Exception $e) { |
|
| 326 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 327 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 328 | 328 | |
| 329 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 329 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 330 | 330 | |
| 331 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 332 | - $this->send_failed_order_email( $order_id ); |
|
| 331 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 332 | + $this->send_failed_order_email($order_id); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | 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 | |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | */ |
| 171 | 171 | public function payment_icons() { |
| 172 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 172 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 173 | 173 | 'ideal' => '<i class="stripe-pf stripe-pf-ideal stripe-pf-right" alt="iDeal" aria-hidden="true"></i>', |
| 174 | - ) ); |
|
| 174 | + )); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $icons_str .= $icons['ideal']; |
| 190 | 190 | |
| 191 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 191 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,19 +199,19 @@ discard block |
||
| 199 | 199 | * @access public |
| 200 | 200 | */ |
| 201 | 201 | public function payment_scripts() { |
| 202 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 202 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 203 | 203 | return; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 207 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 206 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 207 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
| 211 | 211 | * Initialize Gateway Settings Form Fields. |
| 212 | 212 | */ |
| 213 | 213 | public function init_form_fields() { |
| 214 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' ); |
|
| 214 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php'); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -222,25 +222,25 @@ discard block |
||
| 222 | 222 | $total = WC()->cart->total; |
| 223 | 223 | |
| 224 | 224 | // If paying from order, we need to get total from order not cart. |
| 225 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 226 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 225 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 226 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 227 | 227 | $total = $order->get_total(); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ( is_add_payment_method_page() ) { |
|
| 231 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 232 | - $total = ''; |
|
| 230 | + if (is_add_payment_method_page()) { |
|
| 231 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 232 | + $total = ''; |
|
| 233 | 233 | } else { |
| 234 | 234 | $pay_button_text = ''; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | echo '<div |
| 238 | 238 | id="stripe-ideal-payment-data" |
| 239 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 240 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 239 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 240 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 241 | 241 | |
| 242 | - if ( $this->description ) { |
|
| 243 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 242 | + if ($this->description) { |
|
| 243 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | echo '</div>'; |
@@ -254,24 +254,24 @@ discard block |
||
| 254 | 254 | * @param object $order |
| 255 | 255 | * @return mixed |
| 256 | 256 | */ |
| 257 | - public function create_source( $order ) { |
|
| 257 | + public function create_source($order) { |
|
| 258 | 258 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 259 | 259 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 260 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 260 | + $return_url = $this->get_stripe_return_url($order); |
|
| 261 | 261 | $post_data = array(); |
| 262 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 263 | - $post_data['currency'] = strtolower( $currency ); |
|
| 262 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 263 | + $post_data['currency'] = strtolower($currency); |
|
| 264 | 264 | $post_data['type'] = 'ideal'; |
| 265 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 266 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 265 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 266 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 267 | 267 | |
| 268 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 269 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 268 | + if ( ! empty($this->statement_descriptor)) { |
|
| 269 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' ); |
|
| 272 | + WC_Stripe_Logger::log('Info: Begin creating iDeal source'); |
|
| 273 | 273 | |
| 274 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 274 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -285,51 +285,51 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @return array|void |
| 287 | 287 | */ |
| 288 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 288 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 289 | 289 | try { |
| 290 | - $order = wc_get_order( $order_id ); |
|
| 290 | + $order = wc_get_order($order_id); |
|
| 291 | 291 | |
| 292 | 292 | // This will throw exception if not valid. |
| 293 | - $this->validate_minimum_order_amount( $order ); |
|
| 293 | + $this->validate_minimum_order_amount($order); |
|
| 294 | 294 | |
| 295 | 295 | // This comes from the create account checkbox in the checkout page. |
| 296 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 296 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 297 | 297 | |
| 298 | - if ( $create_account ) { |
|
| 298 | + if ($create_account) { |
|
| 299 | 299 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 300 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 300 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 301 | 301 | $new_stripe_customer->create_customer(); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - $response = $this->create_source( $order ); |
|
| 304 | + $response = $this->create_source($order); |
|
| 305 | 305 | |
| 306 | - if ( ! empty( $response->error ) ) { |
|
| 307 | - $order->add_order_note( $response->error->message ); |
|
| 306 | + if ( ! empty($response->error)) { |
|
| 307 | + $order->add_order_note($response->error->message); |
|
| 308 | 308 | |
| 309 | - throw new Exception( $response->error->message ); |
|
| 309 | + throw new Exception($response->error->message); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 313 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 312 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 313 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 314 | 314 | } else { |
| 315 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 315 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 316 | 316 | $order->save(); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' ); |
|
| 319 | + WC_Stripe_Logger::log('Info: Redirecting to iDeal...'); |
|
| 320 | 320 | |
| 321 | 321 | return array( |
| 322 | 322 | 'result' => 'success', |
| 323 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 323 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 324 | 324 | ); |
| 325 | - } catch ( Exception $e ) { |
|
| 326 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 327 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 325 | + } catch (Exception $e) { |
|
| 326 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 327 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 328 | 328 | |
| 329 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 329 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 330 | 330 | |
| 331 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 332 | - $this->send_failed_order_email( $order_id ); |
|
| 331 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 332 | + $this->send_failed_order_email($order_id); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | 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 | |
@@ -170,9 +170,9 @@ discard block |
||
| 170 | 170 | * @return array |
| 171 | 171 | */ |
| 172 | 172 | public function payment_icons() { |
| 173 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 173 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 174 | 174 | 'p24' => '<i class="stripe-pf stripe-pf-p24 stripe-pf-right" alt="P24" aria-hidden="true"></i>', |
| 175 | - ) ); |
|
| 175 | + )); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | $icons_str .= $icons['p24']; |
| 191 | 191 | |
| 192 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 192 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -200,19 +200,19 @@ discard block |
||
| 200 | 200 | * @access public |
| 201 | 201 | */ |
| 202 | 202 | public function payment_scripts() { |
| 203 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 203 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 204 | 204 | return; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 208 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 207 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 208 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | 212 | * Initialize Gateway Settings Form Fields. |
| 213 | 213 | */ |
| 214 | 214 | public function init_form_fields() { |
| 215 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' ); |
|
| 215 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php'); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -223,25 +223,25 @@ discard block |
||
| 223 | 223 | $total = WC()->cart->total; |
| 224 | 224 | |
| 225 | 225 | // If paying from order, we need to get total from order not cart. |
| 226 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 227 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 226 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 227 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 228 | 228 | $total = $order->get_total(); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if ( is_add_payment_method_page() ) { |
|
| 232 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 233 | - $total = ''; |
|
| 231 | + if (is_add_payment_method_page()) { |
|
| 232 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 233 | + $total = ''; |
|
| 234 | 234 | } else { |
| 235 | 235 | $pay_button_text = ''; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | echo '<div |
| 239 | 239 | id="stripe-p24-payment-data" |
| 240 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 241 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 240 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 241 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 242 | 242 | |
| 243 | - if ( $this->description ) { |
|
| 244 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 243 | + if ($this->description) { |
|
| 244 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | echo '</div>'; |
@@ -255,20 +255,20 @@ discard block |
||
| 255 | 255 | * @param object $order |
| 256 | 256 | * @return mixed |
| 257 | 257 | */ |
| 258 | - public function create_source( $order ) { |
|
| 258 | + public function create_source($order) { |
|
| 259 | 259 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 260 | 260 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 261 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 261 | + $return_url = $this->get_stripe_return_url($order); |
|
| 262 | 262 | $post_data = array(); |
| 263 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 264 | - $post_data['currency'] = strtolower( $currency ); |
|
| 263 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 264 | + $post_data['currency'] = strtolower($currency); |
|
| 265 | 265 | $post_data['type'] = 'p24'; |
| 266 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 267 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 266 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 267 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 268 | 268 | |
| 269 | - WC_Stripe_Logger::log( 'Info: Begin creating P24 source' ); |
|
| 269 | + WC_Stripe_Logger::log('Info: Begin creating P24 source'); |
|
| 270 | 270 | |
| 271 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 271 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -282,51 +282,51 @@ discard block |
||
| 282 | 282 | * |
| 283 | 283 | * @return array|void |
| 284 | 284 | */ |
| 285 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 285 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 286 | 286 | try { |
| 287 | - $order = wc_get_order( $order_id ); |
|
| 287 | + $order = wc_get_order($order_id); |
|
| 288 | 288 | |
| 289 | 289 | // This will throw exception if not valid. |
| 290 | - $this->validate_minimum_order_amount( $order ); |
|
| 290 | + $this->validate_minimum_order_amount($order); |
|
| 291 | 291 | |
| 292 | 292 | // This comes from the create account checkbox in the checkout page. |
| 293 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 293 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 294 | 294 | |
| 295 | - if ( $create_account ) { |
|
| 295 | + if ($create_account) { |
|
| 296 | 296 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 297 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 297 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 298 | 298 | $new_stripe_customer->create_customer(); |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - $response = $this->create_source( $order ); |
|
| 301 | + $response = $this->create_source($order); |
|
| 302 | 302 | |
| 303 | - if ( ! empty( $response->error ) ) { |
|
| 304 | - $order->add_order_note( $response->error->message ); |
|
| 303 | + if ( ! empty($response->error)) { |
|
| 304 | + $order->add_order_note($response->error->message); |
|
| 305 | 305 | |
| 306 | - throw new Exception( $response->error->message ); |
|
| 306 | + throw new Exception($response->error->message); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 310 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 309 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 310 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 311 | 311 | } else { |
| 312 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 312 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 313 | 313 | $order->save(); |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - WC_Stripe_Logger::log( 'Info: Redirecting to P24...' ); |
|
| 316 | + WC_Stripe_Logger::log('Info: Redirecting to P24...'); |
|
| 317 | 317 | |
| 318 | 318 | return array( |
| 319 | 319 | 'result' => 'success', |
| 320 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 320 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 321 | 321 | ); |
| 322 | - } catch ( Exception $e ) { |
|
| 323 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 324 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 322 | + } catch (Exception $e) { |
|
| 323 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 324 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 325 | 325 | |
| 326 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 326 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 327 | 327 | |
| 328 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 329 | - $this->send_failed_order_email( $order_id ); |
|
| 328 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 329 | + $this->send_failed_order_email($order_id); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | return array( |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | +if ( ! defined('ABSPATH')) { |
|
| 4 | 4 | exit; // Exit if accessed directly |
| 5 | 5 | } |
| 6 | 6 | |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | * @param string $deprecated Deprecated since WooCommerce 3.0 |
| 36 | 36 | * @return string |
| 37 | 37 | */ |
| 38 | - public function get_display_name( $deprecated = '' ) { |
|
| 38 | + public function get_display_name($deprecated = '') { |
|
| 39 | 39 | $display = sprintf( |
| 40 | 40 | /* translators: last 4 digits of IBAN account */ |
| 41 | - __( 'SEPA IBAN ending in %s', 'woocommerce-gateway-stripe' ), |
|
| 41 | + __('SEPA IBAN ending in %s', 'woocommerce-gateway-stripe'), |
|
| 42 | 42 | $this->get_last4() |
| 43 | 43 | ); |
| 44 | 44 | |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | * @return boolean True if the passed data is valid |
| 67 | 67 | */ |
| 68 | 68 | public function validate() { |
| 69 | - if ( false === parent::validate() ) { |
|
| 69 | + if (false === parent::validate()) { |
|
| 70 | 70 | return false; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if ( ! $this->get_last4( 'edit' ) ) { |
|
| 73 | + if ( ! $this->get_last4('edit')) { |
|
| 74 | 74 | return false; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | * @param string $context |
| 86 | 86 | * @return string Last 4 digits |
| 87 | 87 | */ |
| 88 | - public function get_last4( $context = 'view' ) { |
|
| 89 | - return $this->get_prop( 'last4', $context ); |
|
| 88 | + public function get_last4($context = 'view') { |
|
| 89 | + return $this->get_prop('last4', $context); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @version 4.0.0 |
| 96 | 96 | * @param string $last4 |
| 97 | 97 | */ |
| 98 | - public function set_last4( $last4 ) { |
|
| 99 | - $this->set_prop( 'last4', $last4 ); |
|
| 98 | + public function set_last4($last4) { |
|
| 99 | + $this->set_prop('last4', $last4); |
|
| 100 | 100 | } |
| 101 | 101 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | public function __construct() { |
| 22 | 22 | self::$_this = $this; |
| 23 | 23 | |
| 24 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
| 25 | - add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'get_account_saved_payment_methods_list_item_sepa' ), 10, 2 ); |
|
| 26 | - add_filter( 'woocommerce_get_credit_card_type_label', array( $this, 'normalize_sepa_label' ) ); |
|
| 27 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
| 28 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
| 24 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
| 25 | + add_filter('woocommerce_payment_methods_list_item', array($this, 'get_account_saved_payment_methods_list_item_sepa'), 10, 2); |
|
| 26 | + add_filter('woocommerce_get_credit_card_type_label', array($this, 'normalize_sepa_label')); |
|
| 27 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
| 28 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | * @param string $label |
| 47 | 47 | * @return string $label |
| 48 | 48 | */ |
| 49 | - public function normalize_sepa_label( $label ) { |
|
| 50 | - if ( 'sepa iban' === strtolower( $label ) ) { |
|
| 49 | + public function normalize_sepa_label($label) { |
|
| 50 | + if ('sepa iban' === strtolower($label)) { |
|
| 51 | 51 | return 'SEPA IBAN'; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -62,67 +62,67 @@ discard block |
||
| 62 | 62 | * @param array $tokens |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) { |
|
| 66 | - if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 65 | + public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) { |
|
| 66 | + if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) { |
|
| 67 | 67 | $stored_tokens = array(); |
| 68 | 68 | |
| 69 | - foreach ( $tokens as $token ) { |
|
| 69 | + foreach ($tokens as $token) { |
|
| 70 | 70 | $stored_tokens[] = $token->get_token(); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if ( 'stripe' === $gateway_id ) { |
|
| 74 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 73 | + if ('stripe' === $gateway_id) { |
|
| 74 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 75 | 75 | $stripe_sources = $stripe_customer->get_sources(); |
| 76 | 76 | |
| 77 | - foreach ( $stripe_sources as $source ) { |
|
| 78 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 79 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
| 77 | + foreach ($stripe_sources as $source) { |
|
| 78 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 79 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
| 80 | 80 | $token = new WC_Payment_Token_CC(); |
| 81 | - $token->set_token( $source->id ); |
|
| 82 | - $token->set_gateway_id( 'stripe' ); |
|
| 83 | - |
|
| 84 | - if ( 'source' === $source->object && 'card' === $source->type ) { |
|
| 85 | - $token->set_card_type( strtolower( $source->card->brand ) ); |
|
| 86 | - $token->set_last4( $source->card->last4 ); |
|
| 87 | - $token->set_expiry_month( $source->card->exp_month ); |
|
| 88 | - $token->set_expiry_year( $source->card->exp_year ); |
|
| 81 | + $token->set_token($source->id); |
|
| 82 | + $token->set_gateway_id('stripe'); |
|
| 83 | + |
|
| 84 | + if ('source' === $source->object && 'card' === $source->type) { |
|
| 85 | + $token->set_card_type(strtolower($source->card->brand)); |
|
| 86 | + $token->set_last4($source->card->last4); |
|
| 87 | + $token->set_expiry_month($source->card->exp_month); |
|
| 88 | + $token->set_expiry_year($source->card->exp_year); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - $token->set_user_id( $customer_id ); |
|
| 91 | + $token->set_user_id($customer_id); |
|
| 92 | 92 | $token->save(); |
| 93 | - $tokens[ $token->get_id() ] = $token; |
|
| 93 | + $tokens[$token->get_id()] = $token; |
|
| 94 | 94 | } |
| 95 | 95 | } else { |
| 96 | - if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) { |
|
| 96 | + if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) { |
|
| 97 | 97 | $token = new WC_Payment_Token_CC(); |
| 98 | - $token->set_token( $source->id ); |
|
| 99 | - $token->set_gateway_id( 'stripe' ); |
|
| 100 | - $token->set_card_type( strtolower( $source->brand ) ); |
|
| 101 | - $token->set_last4( $source->last4 ); |
|
| 102 | - $token->set_expiry_month( $source->exp_month ); |
|
| 103 | - $token->set_expiry_year( $source->exp_year ); |
|
| 104 | - $token->set_user_id( $customer_id ); |
|
| 98 | + $token->set_token($source->id); |
|
| 99 | + $token->set_gateway_id('stripe'); |
|
| 100 | + $token->set_card_type(strtolower($source->brand)); |
|
| 101 | + $token->set_last4($source->last4); |
|
| 102 | + $token->set_expiry_month($source->exp_month); |
|
| 103 | + $token->set_expiry_year($source->exp_year); |
|
| 104 | + $token->set_user_id($customer_id); |
|
| 105 | 105 | $token->save(); |
| 106 | - $tokens[ $token->get_id() ] = $token; |
|
| 106 | + $tokens[$token->get_id()] = $token; |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if ( 'stripe_sepa' === $gateway_id ) { |
|
| 113 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 112 | + if ('stripe_sepa' === $gateway_id) { |
|
| 113 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 114 | 114 | $stripe_sources = $stripe_customer->get_sources(); |
| 115 | 115 | |
| 116 | - foreach ( $stripe_sources as $source ) { |
|
| 117 | - if ( isset( $source->type ) && 'sepa_debit' === $source->type ) { |
|
| 118 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
| 116 | + foreach ($stripe_sources as $source) { |
|
| 117 | + if (isset($source->type) && 'sepa_debit' === $source->type) { |
|
| 118 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
| 119 | 119 | $token = new WC_Payment_Token_SEPA(); |
| 120 | - $token->set_token( $source->id ); |
|
| 121 | - $token->set_gateway_id( 'stripe_sepa' ); |
|
| 122 | - $token->set_last4( $source->sepa_debit->last4 ); |
|
| 123 | - $token->set_user_id( $customer_id ); |
|
| 120 | + $token->set_token($source->id); |
|
| 121 | + $token->set_gateway_id('stripe_sepa'); |
|
| 122 | + $token->set_last4($source->sepa_debit->last4); |
|
| 123 | + $token->set_user_id($customer_id); |
|
| 124 | 124 | $token->save(); |
| 125 | - $tokens[ $token->get_id() ] = $token; |
|
| 125 | + $tokens[$token->get_id()] = $token; |
|
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | * @param WC_Payment_Token $payment_token The payment token associated with this method entry |
| 142 | 142 | * @return array Filtered item |
| 143 | 143 | */ |
| 144 | - public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) { |
|
| 145 | - if ( 'sepa' !== strtolower( $payment_token->get_type() ) ) { |
|
| 144 | + public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) { |
|
| 145 | + if ('sepa' !== strtolower($payment_token->get_type())) { |
|
| 146 | 146 | return $item; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | $item['method']['last4'] = $payment_token->get_last4(); |
| 150 | - $item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' ); |
|
| 150 | + $item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe'); |
|
| 151 | 151 | |
| 152 | 152 | return $item; |
| 153 | 153 | } |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | * @since 3.1.0 |
| 159 | 159 | * @version 4.0.0 |
| 160 | 160 | */ |
| 161 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
| 162 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
| 163 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 164 | - $stripe_customer->delete_source( $token->get_token() ); |
|
| 161 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
| 162 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
| 163 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 164 | + $stripe_customer->delete_source($token->get_token()); |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
@@ -171,12 +171,12 @@ discard block |
||
| 171 | 171 | * @since 3.1.0 |
| 172 | 172 | * @version 4.0.0 |
| 173 | 173 | */ |
| 174 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
| 175 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 174 | + public function woocommerce_payment_token_set_default($token_id) { |
|
| 175 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 176 | 176 | |
| 177 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
| 178 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 179 | - $stripe_customer->set_default_source( $token->get_token() ); |
|
| 177 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
| 178 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 179 | + $stripe_customer->set_default_source($token->get_token()); |
|
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | } |