From 21c93db714045e90dc9850938189a0f9ac03eb64 Mon Sep 17 00:00:00 2001 From: Montazar Date: Sun, 23 Nov 2025 15:44:02 +0100 Subject: [PATCH 01/44] PHPCS --- src/Gateway.php | 1642 +++++++++++++++++++------------------ src/View/CheckoutForm.php | 25 +- 2 files changed, 842 insertions(+), 825 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index b4f47419..bc9cb29b 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -58,8 +58,6 @@ final class Gateway extends \WC_Payment_Gateway { /** * Transaction settlement declaration - * - * */ protected $transaction_settlement_enable; @@ -70,6 +68,7 @@ final class Gateway extends \WC_Payment_Gateway { */ public $enable_test_mode = false; + /** * Whether the debug mode is enabled. * @@ -84,7 +83,7 @@ final class Gateway extends \WC_Payment_Gateway { * * @var array */ - public $supports = [ + public $supports = array( 'products', 'refunds', 'tokenization', @@ -97,15 +96,15 @@ final class Gateway extends \WC_Payment_Gateway { 'subscription_payment_method_change', 'subscription_payment_method_change_customer', 'subscription_payment_method_change_admin', - 'multiple_subscriptions' - ]; + 'multiple_subscriptions', + ); /** * Dynamic method info that will be populated from an endpoint. * * @var array */ - public $method_info = []; + public $method_info = array(); /** * WooCommerce logger instance @@ -127,13 +126,14 @@ final class Gateway extends \WC_Payment_Gateway { * @var Helper */ protected $helper = null; - const TAX_RATE_PRECISION = 1; - const SUPPORTED_CURRENCIES = ['EUR']; + + const TAX_RATE_PRECISION = 1; + const SUPPORTED_CURRENCIES = array( 'EUR' ); /** * Object constructor */ - public function __construct( $params = []) { + public function __construct( $params = array() ) { // Set payment gateway ID $this->id = Plugin::GATEWAY_ID; @@ -147,8 +147,8 @@ public function __construct( $params = []) { $this->method_description = $this->method_info['description']; // These strings may show in the frontend. - $this->title = !empty($this->get_option('custom_provider_name')) ? $this->get_option('custom_provider_name') : $this->method_info['title']; - $this->description = !empty($this->get_option('custom_provider_description')) ? $this->get_option('custom_provider_description') : $this->method_info['description']; + $this->title = ! empty( $this->get_option( 'custom_provider_name' ) ) ? $this->get_option( 'custom_provider_name' ) : $this->method_info['title']; + $this->description = ! empty( $this->get_option( 'custom_provider_description' ) ) ? $this->get_option( 'custom_provider_description' ) : $this->method_info['description']; // Icon temporarily disabled for size issues // $this->icon = Plugin::ICON_URL; @@ -160,15 +160,15 @@ public function __construct( $params = []) { $this->init_settings(); // Whether we are in test mode or not. - $this->enable_test_mode = 'yes' === $this->get_option('enable_test_mode', 'no'); + $this->enable_test_mode = 'yes' === $this->get_option( 'enable_test_mode', 'no' ); // Set merchant ID and secret key either from the options or for test mode. - if ($this->enable_test_mode) { + if ( $this->enable_test_mode ) { $this->merchant_id = (int) Plugin::TEST_MERCHANT_ID; $this->secret_key = Plugin::TEST_SECRET_KEY; } else { - $this->merchant_id = (int) $this->get_option('merchant_id'); - $this->secret_key = $this->get_option('secret_key'); + $this->merchant_id = (int) $this->get_option( 'merchant_id' ); + $this->secret_key = $this->get_option( 'secret_key' ); } $platformName = 'paytrail-for-woocommerce-' . \Paytrail\WooCommercePaymentGateway\Plugin::$version; @@ -184,15 +184,17 @@ public function __construct( $params = []) { $this->helper = new Helper(); // Whether we are in debug mode or not. - $this->debug = 'yes' === $this->get_option('debug', 'no'); + $this->debug = 'yes' === $this->get_option( 'debug', 'no' ); // Check if transaction settlement is enabled $this->transaction_settlement_enable = $this->get_option( 'settlement_enablement', 'no' ) === 'yes'; - if (!empty($params) && isset($params['callbackMode'])) { + if ( ! empty( $params ) && isset( $params['callbackMode'] ) ) { $this->callbackMode = true; } + $this->settlement_prefix = $this->get_option( 'settlement_prefix', '10' ); + // Add actions and filters. $this->add_actions(); @@ -212,41 +214,40 @@ public function __construct( $params = []) { * @return void */ protected function add_actions() { - add_action('woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ]); - add_action('woocommerce_scheduled_subscription_payment_' . Plugin::GATEWAY_ID, [ $this, 'scheduled_subscription_payment' ], 10, 2); - add_action('woocommerce_receipt_' . $this->id, [ $this, 'receipt_page' ]); - add_filter('woocommerce_admin_order_items_after_refunds', [ $this, 'refund_items' ], 10, 1); - add_filter('woocommerce_order_data_store_cpt_get_orders_query', [ $this, 'handle_custom_searches' ], 10, 2); - add_filter('woocommerce_payment_gateway_get_saved_payment_method_option_html', [ $this, 'get_token_payment_option_html' ], 10, 2); - add_action('admin_footer', [$this, 'display_user_data_form']); - add_action('admin_notices', [$this, 'admin_notices']); - add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']); - add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_styles']); - + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + add_action( 'woocommerce_scheduled_subscription_payment_' . Plugin::GATEWAY_ID, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); + add_action( 'woocommerce_receipt_' . $this->id, array( $this, 'receipt_page' ) ); + add_filter( 'woocommerce_admin_order_items_after_refunds', array( $this, 'refund_items' ), 10, 1 ); + add_filter( 'woocommerce_order_data_store_cpt_get_orders_query', array( $this, 'handle_custom_searches' ), 10, 2 ); + add_filter( 'woocommerce_payment_gateway_get_saved_payment_method_option_html', array( $this, 'get_token_payment_option_html' ), 10, 2 ); + add_action( 'admin_footer', array( $this, 'display_user_data_form' ) ); + add_action( 'admin_notices', array( $this, 'admin_notices' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) ); } /** * Display the user_data_form as an overlay */ public function display_user_data_form() { - $merchant_id = $this->get_option('merchant_id'); - $test_mode_enabled = $this->get_option('enable_test_mode', 'no') === 'yes'; - $current_screen = get_current_screen(); + $merchant_id = $this->get_option( 'merchant_id' ); + $test_mode_enabled = $this->get_option( 'enable_test_mode', 'no' ) === 'yes'; + $current_screen = get_current_screen(); $is_paytrail_settings_page = ( - !$test_mode_enabled && + ! $test_mode_enabled && $current_screen && 'woocommerce_page_wc-settings' === $current_screen->id && - isset($_GET['tab']) && 'checkout' === $_GET['tab'] && - isset($_GET['section']) && 'paytrail' === $_GET['section'] + isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && + isset( $_GET['section'] ) && 'paytrail' === $_GET['section'] ); // Check if merchant_id is already submitted - if (!empty($merchant_id) || $this->get_option('enable_test_mode', 'no') === 'yes') { + if ( ! empty( $merchant_id ) || $this->get_option( 'enable_test_mode', 'no' ) === 'yes' ) { return; } - if ($is_paytrail_settings_page) { - $template_path = plugin_dir_path(__FILE__) . 'View/Intro-form.php'; - if (file_exists($template_path)) { + if ( $is_paytrail_settings_page ) { + $template_path = plugin_dir_path( __FILE__ ) . 'View/Intro-form.php'; + if ( file_exists( $template_path ) ) { include_once $template_path; } } @@ -258,33 +259,32 @@ public function display_user_data_form() { */ public function user_data_form() { $current_user = wp_get_current_user(); - $user_email = $current_user->user_email; - $first_name = $current_user->first_name; - $last_name = $current_user->last_name; + $user_email = $current_user->user_email; + $first_name = $current_user->first_name; + $last_name = $current_user->last_name; - if (class_exists('WooCommerce')) { - $wc_billing_data = get_user_meta($current_user->ID, 'billing', true); - $company_name = isset($wc_billing_data['company']) ? $wc_billing_data['company'] : ''; - $phone_number = isset($wc_billing_data['phone']) ? $wc_billing_data['phone'] : ''; + if ( class_exists( 'WooCommerce' ) ) { + $wc_billing_data = get_user_meta( $current_user->ID, 'billing', true ); + $company_name = isset( $wc_billing_data['company'] ) ? $wc_billing_data['company'] : ''; + $phone_number = isset( $wc_billing_data['phone'] ) ? $wc_billing_data['phone'] : ''; // Fetch shop's address using WC_Countries - $wc_countries = WC()->countries; - $shop_address = $wc_countries->get_base_address(); - $shop_city = $wc_countries->get_base_city(); + $wc_countries = WC()->countries; + $shop_address = $wc_countries->get_base_address(); + $shop_city = $wc_countries->get_base_city(); $shop_postcode = $wc_countries->get_base_postcode(); } else { - $company_name = ''; - $phone_number = ''; - $shop_address = ''; - $shop_city = ''; + $company_name = ''; + $phone_number = ''; + $shop_address = ''; + $shop_city = ''; $shop_postcode = ''; } + $site_url = esc_url( get_site_url() ); - $site_url = esc_url(get_site_url()); - - $template_path = plugin_dir_path(__FILE__) . 'View/User-data-form.php'; - if (file_exists($template_path)) { + $template_path = plugin_dir_path( __FILE__ ) . 'View/User-data-form.php'; + if ( file_exists( $template_path ) ) { include_once $template_path; } } @@ -296,11 +296,11 @@ public function user_data_form() { * @return array */ protected function get_method_info() { - $method_info = [ - 'title' => __('Paytrail for WooCommerce', 'paytrail-for-woocommerce'), - 'description' => __('Paytrail for WooCommerce - the most comprehensive suite of payment methods in the market with a single contract', 'paytrail-for-woocommerce'), - 'save_card' => 1, - ]; + $method_info = array( + 'title' => __( 'Paytrail for WooCommerce', 'paytrail-for-woocommerce' ), + 'description' => __( 'Paytrail for WooCommerce - the most comprehensive suite of payment methods in the market with a single contract', 'paytrail-for-woocommerce' ), + 'save_card' => 1, + ); return $method_info; } @@ -310,131 +310,131 @@ protected function get_method_info() { * @return void */ protected function set_form_fields() { - $test_mode_enabled = $this->get_option('enable_test_mode', 'no') === 'yes'; - $merchant_id_disabled = $this->get_option( 'enable_test_mode', 'no' ) === 'yes'; - $secret_key_disabled = $this->get_option( 'enable_test_mode', 'no' ) === 'yes'; - $enable_test_mode_disabled = !$test_mode_enabled && ( - !empty($this->get_option('merchant_id')) || - !empty($this->get_option('secret_key')) + $test_mode_enabled = $this->get_option( 'enable_test_mode', 'no' ) === 'yes'; + $merchant_id_disabled = $this->get_option( 'enable_test_mode', 'no' ) === 'yes'; + $secret_key_disabled = $this->get_option( 'enable_test_mode', 'no' ) === 'yes'; + $enable_test_mode_disabled = ! $test_mode_enabled && ( + ! empty( $this->get_option( 'merchant_id' ) ) || + ! empty( $this->get_option( 'secret_key' ) ) ); - $this->form_fields = [ + $this->form_fields = array( // Whether the payment gateway is enabled. - 'enabled' => [ - 'title' => __('Payment gateway status', 'paytrail-for-woocommerce'), + 'enabled' => array( + 'title' => __( 'Payment gateway status', 'paytrail-for-woocommerce' ), 'type' => 'checkbox', - 'label' => __('Enable Paytrail for WooCommerce', 'paytrail-for-woocommerce'), + 'label' => __( 'Enable Paytrail for WooCommerce', 'paytrail-for-woocommerce' ), 'default' => 'yes', - ], + ), // Credentials - 'credentials_title' => [ - 'title' => __('Credentials', 'paytrail-for-woocommerce'), - 'type' => 'title', - ], + 'credentials_title' => array( + 'title' => __( 'Credentials', 'paytrail-for-woocommerce' ), + 'type' => 'title', + ), // Paytrail credentials - 'merchant_id' => [ - 'title' => __('Paytrail Merchant ID', 'paytrail-for-woocommerce'), - 'type' => 'text', - 'label' => __('Merchant ID', 'paytrail-for-woocommerce'), - 'default' => '', + 'merchant_id' => array( + 'title' => __( 'Paytrail Merchant ID', 'paytrail-for-woocommerce' ), + 'type' => 'text', + 'label' => __( 'Merchant ID', 'paytrail-for-woocommerce' ), + 'default' => '', 'disabled' => $merchant_id_disabled, // Disable if enable_test_mode is checked - ], - 'secret_key' => [ - 'title' => __('Paytrail Secret key', 'paytrail-for-woocommerce'), - 'type' => 'password', - 'label' => __('Secret key', 'paytrail-for-woocommerce'), - 'default' => '', - 'description' => __('Credentials can be found in the merchant panel.', 'paytrail-for-woocommerce'), - 'disabled' => $secret_key_disabled, // Disable if enable_test_mode is checked - ], + ), + 'secret_key' => array( + 'title' => __( 'Paytrail Secret key', 'paytrail-for-woocommerce' ), + 'type' => 'password', + 'label' => __( 'Secret key', 'paytrail-for-woocommerce' ), + 'default' => '', + 'description' => __( 'Credentials can be found in the merchant panel.', 'paytrail-for-woocommerce' ), + 'disabled' => $secret_key_disabled, // Disable if enable_test_mode is checked + ), // Whether test mode is enabled - 'enable_test_mode' => [ - 'title' => __('Test mode', 'paytrail-for-woocommerce'), + 'enable_test_mode' => array( + 'title' => __( 'Test mode', 'paytrail-for-woocommerce' ), 'type' => 'checkbox', - 'label' => __('Enable test mode', 'paytrail-for-woocommerce'), + 'label' => __( 'Enable test mode', 'paytrail-for-woocommerce' ), 'default' => 'no', - 'description' => __('You can use test mode to simulate payments with Paytrail\'s test credentials. To enable test mode, please first clear the Credentials and save settings.', 'paytrail-for-woocommerce'), + 'description' => __( 'You can use test mode to simulate payments with Paytrail\'s test credentials. To enable test mode, please first clear the Credentials and save settings.', 'paytrail-for-woocommerce' ), 'disabled' => $enable_test_mode_disabled, // Disable the checkbox if merchant_id or secret_key has a value - ], + ), // General settings - 'general_settings_title' => [ - 'title' => __('General settings', 'paytrail-for-woocommerce'), - 'type' => 'title', - ], + 'general_settings_title' => array( + 'title' => __( 'General settings', 'paytrail-for-woocommerce' ), + 'type' => 'title', + ), // Whether to show the payment provider wall or choose the method in the store - 'provider_selection' => [ - 'title' => __('Payment provider selection', 'paytrail-for-woocommerce'), + 'provider_selection' => array( + 'title' => __( 'Payment provider selection', 'paytrail-for-woocommerce' ), 'type' => 'checkbox', - 'label' => __('Enable payment provider selection in the checkout page', 'paytrail-for-woocommerce'), + 'label' => __( 'Enable payment provider selection in the checkout page', 'paytrail-for-woocommerce' ), 'default' => 'yes', - 'description' => __('Choose whether you want the payment provider selection to happen in the checkout page or in a separate page.', 'paytrail-for-woocommerce'), - ], + 'description' => __( 'Choose whether you want the payment provider selection to happen in the checkout page or in a separate page.', 'paytrail-for-woocommerce' ), + ), // Alternative text + description to show on the Checkout page - 'custom_provider_name' => [ - 'title' => __('Payment provider title', 'paytrail-for-woocommerce'), + 'custom_provider_name' => array( + 'title' => __( 'Payment provider title', 'paytrail-for-woocommerce' ), 'type' => 'text', - 'label' => __('Used on the Checkout page title', 'paytrail-for-woocommerce'), + 'label' => __( 'Used on the Checkout page title', 'paytrail-for-woocommerce' ), 'default' => 'Paytrail for WooCommerce', - 'description' => __('This title is displayed on the Checkout page before the payment provider images.', 'paytrail-for-woocommerce') - ], - 'custom_provider_description' => [ - 'title' => __('Payment provider description', 'paytrail-for-woocommerce'), + 'description' => __( 'This title is displayed on the Checkout page before the payment provider images.', 'paytrail-for-woocommerce' ), + ), + 'custom_provider_description' => array( + 'title' => __( 'Payment provider description', 'paytrail-for-woocommerce' ), 'type' => 'text', - 'label' => __('Used on the Checkout page title', 'paytrail-for-woocommerce'), + 'label' => __( 'Used on the Checkout page title', 'paytrail-for-woocommerce' ), 'default' => 'Paytrail for WooCommerce', - 'description' => __('Depending on your theme, this description might be displayed on the Checkout page before the payment provider images.', 'paytrail-for-woocommerce') - ], + 'description' => __( 'Depending on your theme, this description might be displayed on the Checkout page before the payment provider images.', 'paytrail-for-woocommerce' ), + ), // OP Lasku - 'op_lasku_calculator' => [ + 'op_lasku_calculator' => array( 'title' => OPLasku::settings_title(), 'type' => 'checkbox', - 'label' => __('Enable OP Lasku calculator', 'paytrail-for-woocommerce'), + 'label' => __( 'Enable OP Lasku calculator', 'paytrail-for-woocommerce' ), 'default' => 'no', - 'description' => __('Display OP Lasku calculator on the product and cart page.', 'paytrail-for-woocommerce'), - ], + 'description' => __( 'Display OP Lasku calculator on the product and cart page.', 'paytrail-for-woocommerce' ), + ), // Advanced settings - 'advanced_settings_title' => [ - 'title' => __('Advanced settings', 'paytrail-for-woocommerce'), - 'type' => 'title', - ], - 'settlement_enablement' => [ - 'title' => __( 'Enable individual settlements', 'paytrail-for-woocommerce' ), - 'type' => 'checkbox', - 'default' => 'no', + 'advanced_settings_title' => array( + 'title' => __( 'Advanced settings', 'paytrail-for-woocommerce' ), + 'type' => 'title', + ), + 'settlement_enablement' => array( + 'title' => __( 'Enable individual settlements', 'paytrail-for-woocommerce' ), + 'type' => 'checkbox', + 'default' => 'no', 'description' => __( 'This setting is required only if you are using transaction-by-transaction settlements in Paytrail.', 'paytrail-for-woocommerce' ), - ], - 'settlement_prefix' => [ - 'title' => __( 'Bank reference prefix', 'paytrail-for-woocommerce' ), - 'type' => 'text', + ), + 'settlement_prefix' => array( + 'title' => __( 'Bank reference prefix', 'paytrail-for-woocommerce' ), + 'type' => 'text', 'description' => __( 'Add Prefix', 'paytrail-for-woocommerce' ), - 'default' => '10' - ], - 'fallback_country' => [ - 'title' => __('Default country', 'paytrail-for-woocommerce'), - 'type' => 'select', - 'label' => __('Fallback country', 'paytrail-for-woocommerce'), - 'default' => '', - 'description' => __('Select country to be used as fallback if no country specified in checkout.', 'paytrail-for-woocommerce'), - 'options' => array_merge(['' => 'Select country'], WC()->countries->get_countries()) - ], + 'default' => '10', + ), + 'fallback_country' => array( + 'title' => __( 'Default country', 'paytrail-for-woocommerce' ), + 'type' => 'select', + 'label' => __( 'Fallback country', 'paytrail-for-woocommerce' ), + 'default' => '', + 'description' => __( 'Select country to be used as fallback if no country specified in checkout.', 'paytrail-for-woocommerce' ), + 'options' => array_merge( array( '' => 'Select country' ), WC()->countries->get_countries() ), + ), // Whether debug mode is enabled - 'debug' => [ - 'title' => __('Debug log', 'paytrail-for-woocommerce'), + 'debug' => array( + 'title' => __( 'Debug log', 'paytrail-for-woocommerce' ), 'type' => 'checkbox', - 'label' => __('Enable logging', 'paytrail-for-woocommerce'), + 'label' => __( 'Enable logging', 'paytrail-for-woocommerce' ), 'default' => 'no', // translators: %s: URL - 'description' => sprintf(__('This enables logging all payment gateway events. The log will be written in %1$s. Recommended only for debugging purposes as this might save personal data. All logs can be viewed here: %2$s', 'paytrail-for-woocommerce'), '' . \WC_Log_Handler_File::get_log_file_path(Plugin::GATEWAY_ID) . '', 'Logs'), - ], + 'description' => sprintf( __( 'This enables logging all payment gateway events. The log will be written in %1$s. Recommended only for debugging purposes as this might save personal data. All logs can be viewed here: %2$s', 'paytrail-for-woocommerce' ), '' . \WC_Log_Handler_File::get_log_file_path( Plugin::GATEWAY_ID ) . '', 'Logs' ), + ), // Update tokens if enabled - 'tokenize' => [ - 'title' => __('Update tokens', 'paytrail-for-woocommerce'), + 'tokenize' => array( + 'title' => __( 'Update tokens', 'paytrail-for-woocommerce' ), 'type' => 'checkbox', - 'label' => __('Enable token update', 'paytrail-for-woocommerce'), + 'label' => __( 'Enable token update', 'paytrail-for-woocommerce' ), 'default' => 'no', // translators: %s: URL - 'description' => __('Choose this to update card information (tokens) from the old Checkout Finland for WooCommerce -plugin. The update is done upon saving settings. This will also update tokens for the current WooCommerce Subscriptions orders, if that module is in use.
CAUTION: This action cannot be reverted.', 'paytrail-for-woocommerce'), - ], - ]; + 'description' => __( 'Choose this to update card information (tokens) from the old Checkout Finland for WooCommerce -plugin. The update is done upon saving settings. This will also update tokens for the current WooCommerce Subscriptions orders, if that module is in use.
CAUTION: This action cannot be reverted.', 'paytrail-for-woocommerce' ), + ), + ); } /** @@ -446,16 +446,16 @@ public function process_admin_options() { $saved = parent::process_admin_options(); // Clear logs if debugging was disabled. - if ('yes' !== $this->get_option('debug', 'no')) { - if (empty($this->logger)) { + if ( 'yes' !== $this->get_option( 'debug', 'no' ) ) { + if ( empty( $this->logger ) ) { $this->logger = wc_get_logger(); } - $this->logger->clear(Plugin::GATEWAY_ID); + $this->logger->clear( Plugin::GATEWAY_ID ); } // Update tokens if checkbx was checked - if ('yes' === $this->get_option('tokenize', 'yes')) { + if ( 'yes' === $this->get_option( 'tokenize', 'yes' ) ) { $token_migration = new PaymentTokenMigration(); $token_migration->execute(); $subscription_migration = new PaymentSubscriptionMigration(); @@ -470,19 +470,19 @@ public function process_admin_options() { */ public function display_test_mode_notice() { // Check if test mode is enabled - $test_mode_enabled = $this->get_option('enable_test_mode', 'no') === 'yes'; + $test_mode_enabled = $this->get_option( 'enable_test_mode', 'no' ) === 'yes'; // Check if the notice should be displayed - if ($test_mode_enabled) { + if ( $test_mode_enabled ) { ?>

' . esc_html__('here', 'paytrail-for-woocommerce') . '' + esc_html__( 'If you have not registered yet, you can do so on our website %s to get your credentials!', 'paytrail-for-woocommerce' ), + '' . esc_html__( 'here', 'paytrail-for-woocommerce' ) . '' ); ?>

@@ -498,20 +498,21 @@ public function display_test_mode_notice() { */ public function display_currency_notice() { // Check the currently selected currency - $current_currency = get_woocommerce_currency(); - $currency_is_not_supported = !in_array($current_currency, self::SUPPORTED_CURRENCIES); + $current_currency = get_woocommerce_currency(); + $currency_is_not_supported = ! in_array( $current_currency, self::SUPPORTED_CURRENCIES ); // Check if the notice should be displayed - if ($currency_is_not_supported) { - $currency_settings_url = admin_url('admin.php?page=wc-settings&tab=general'); + if ( $currency_is_not_supported ) { + $currency_settings_url = admin_url( 'admin.php?page=wc-settings&tab=general' ); ?>

' . esc_html__('Please set the WooCommerce currency to Euro (€)', 'paytrail-for-woocommerce') . '', esc_url($currency_settings_url) - ); + '' . esc_html__( 'Please set the WooCommerce currency to Euro (€)', 'paytrail-for-woocommerce' ) . '', + esc_url( $currency_settings_url ) + ); ?>

@@ -531,9 +532,9 @@ public function admin_notices() { * Calculate bank reference */ private function calculate_reference( $base ) { - $base = sprintf( '%s%s', $this->settlement_prefix, $base ); - $base = trim( str_replace( ' ', '', $base ) ); - $base = str_split( $base ); + $base = sprintf( '%s%s', $this->settlement_prefix, $base ); + $base = trim( str_replace( ' ', '', $base ) ); + $base = str_split( $base ); $reversed_base = array_reverse( $base ); $weights = array( 7, 3, 1, 7, 3, 1, 7, 3, 1, 7, 3, 1, 7, 3, 1, 7, 3, 1, 7 ); @@ -541,7 +542,7 @@ private function calculate_reference( $base ) { $sum = 0; for ( $i = 0; $i < count( $reversed_base ); $i++ ) { $coefficient = array_shift( $weights ); - $sum += intval( $reversed_base[$i] ) * $coefficient; + $sum += intval( $reversed_base[ $i ] ) * $coefficient; } $checksum = ( 0 == ( $sum % 10 ) ) ? 0 : ( 10 - ( $sum % 10 ) ); @@ -557,11 +558,11 @@ private function calculate_reference( $base ) { * @return void */ public function receipt_page() { - $view = new View('CheckoutForm'); + $view = new View( 'CheckoutForm' ); - $provider = WC()->session->get('payment_provider'); + $provider = WC()->session->get( 'payment_provider' ); - $view->render($provider); + $view->render( $provider ); } /** @@ -570,7 +571,7 @@ public function receipt_page() { * @return void */ public function render_saved_payment_methods() { - $view = new View('SavedPaymentMethods'); + $view = new View( 'SavedPaymentMethods' ); $view->render(); } @@ -582,44 +583,44 @@ public function render_saved_payment_methods() { * @throws HmacException * @throws ValidationException */ - public function add_card_form( $context = Plugin::ADD_CARD_CONTEXT_CHECKOUT) { - $datetime = new \DateTime(); - $checkout_nonce = sha1(uniqid(true)); + public function add_card_form( $context = Plugin::ADD_CARD_CONTEXT_CHECKOUT ) { + $datetime = new \DateTime(); + $checkout_nonce = sha1( uniqid( true ) ); - if (Plugin::ADD_CARD_CONTEXT_MY_ACCOUNT === $context) { - $success_url = Router::get_url(Plugin::ADD_CARD_REDIRECT_SUCCESS_URL, Plugin::ADD_CARD_CONTEXT_MY_ACCOUNT); - $cancel_url = Router::get_url(Plugin::ADD_CARD_REDIRECT_CANCEL_URL, Plugin::ADD_CARD_CONTEXT_MY_ACCOUNT); - } elseif (Helper::getIsChangeSubscriptionPaymentMethod()) { + if ( Plugin::ADD_CARD_CONTEXT_MY_ACCOUNT === $context ) { + $success_url = Router::get_url( Plugin::ADD_CARD_REDIRECT_SUCCESS_URL, Plugin::ADD_CARD_CONTEXT_MY_ACCOUNT ); + $cancel_url = Router::get_url( Plugin::ADD_CARD_REDIRECT_CANCEL_URL, Plugin::ADD_CARD_CONTEXT_MY_ACCOUNT ); + } elseif ( Helper::getIsChangeSubscriptionPaymentMethod() ) { $success_url = Router::get_url( Plugin::ADD_CARD_REDIRECT_SUCCESS_URL, Plugin::ADD_CARD_CONTEXT_CHANGE_PAYMENT_METHOD ); - $cancel_url = Router::get_url( + $cancel_url = Router::get_url( Plugin::ADD_CARD_REDIRECT_CANCEL_URL, Plugin::ADD_CARD_CONTEXT_CHANGE_PAYMENT_METHOD ); } else { - $success_url = Router::get_url(Plugin::ADD_CARD_REDIRECT_SUCCESS_URL, Plugin::ADD_CARD_CONTEXT_CHECKOUT); - $cancel_url = Router::get_url(Plugin::ADD_CARD_REDIRECT_CANCEL_URL, Plugin::ADD_CARD_CONTEXT_CHECKOUT); + $success_url = Router::get_url( Plugin::ADD_CARD_REDIRECT_SUCCESS_URL, Plugin::ADD_CARD_CONTEXT_CHECKOUT ); + $cancel_url = Router::get_url( Plugin::ADD_CARD_REDIRECT_CANCEL_URL, Plugin::ADD_CARD_CONTEXT_CHECKOUT ); } - $this->log('Paytrail: try to add new card', 'debug'); + $this->log( 'Paytrail: try to add new card', 'debug' ); $add_card_form_request = new AddCardFormRequest(); - $add_card_form_request->setCheckoutAccount($this->merchant_id); - $add_card_form_request->setCheckoutAlgorithm('sha256'); - $add_card_form_request->setCheckoutMethod('POST'); - $add_card_form_request->setCheckoutTimestamp($datetime->format('Y-m-d\TH:i:s.u\Z')); - $add_card_form_request->setCheckoutNonce($checkout_nonce); - $add_card_form_request->setCheckoutRedirectSuccessUrl($success_url); - $add_card_form_request->setCheckoutRedirectCancelUrl($cancel_url); - $add_card_form_request->setLanguage(Helper::getLocale()); + $add_card_form_request->setCheckoutAccount( $this->merchant_id ); + $add_card_form_request->setCheckoutAlgorithm( 'sha256' ); + $add_card_form_request->setCheckoutMethod( 'POST' ); + $add_card_form_request->setCheckoutTimestamp( $datetime->format( 'Y-m-d\TH:i:s.u\Z' ) ); + $add_card_form_request->setCheckoutNonce( $checkout_nonce ); + $add_card_form_request->setCheckoutRedirectSuccessUrl( $success_url ); + $add_card_form_request->setCheckoutRedirectCancelUrl( $cancel_url ); + $add_card_form_request->setLanguage( Helper::getLocale() ); // Create a addCardFormRequest via Paytrail SDK // @var \GuzzleHttp\Psr7\Response $response - $response = $this->client->createAddCardFormRequest($add_card_form_request); + $response = $this->client->createAddCardFormRequest( $add_card_form_request ); - if ($response->getHeader('Location')) { - wp_redirect($response->getHeader('Location')[0]); + if ( $response->getHeader( 'Location' ) ) { + wp_redirect( $response->getHeader( 'Location' )[0] ); exit; } } @@ -633,12 +634,12 @@ public function add_card_form( $context = Plugin::ADD_CARD_CONTEXT_CHECKOUT) { */ public function process_card_token() { $getTokenRequest = new GetTokenRequest(); - $getTokenRequest->setCheckoutTokenizationId(filter_input(INPUT_GET, 'checkout-tokenization-id')); - $this->log('Paytrail: process_card_token', 'debug'); + $getTokenRequest->setCheckoutTokenizationId( filter_input( INPUT_GET, 'checkout-tokenization-id' ) ); + $this->log( 'Paytrail: process_card_token', 'debug' ); - $response = $this->client->createGetTokenRequest($getTokenRequest); + $response = $this->client->createGetTokenRequest( $getTokenRequest ); - return (bool) $this->save_card_token($response); + return (bool) $this->save_card_token( $response ); } /** @@ -646,18 +647,18 @@ public function process_card_token() { * * @param GetTokenResponse $card_token */ - private function save_card_token( GetTokenResponse $card_token) { - $this->log('Paytrail: save_card_token', 'debug'); + private function save_card_token( GetTokenResponse $card_token ) { + $this->log( 'Paytrail: save_card_token', 'debug' ); $token = new WC_Payment_Token_CC(); - $token->set_card_type($card_token->getCard()->getType()); - $token->set_expiry_month($card_token->getCard()->getExpireMonth()); - $token->set_expiry_year($card_token->getCard()->getExpireYear()); - $token->set_last4($card_token->getCard()->getPartialPan()); - $token->set_token($card_token->getToken()); - $token->set_user_id(get_current_user_id()); - $token->set_gateway_id(Plugin::GATEWAY_ID); - \WC_Payment_Tokens::set_users_default(get_current_user_id(), $token->get_id()); + $token->set_card_type( $card_token->getCard()->getType() ); + $token->set_expiry_month( $card_token->getCard()->getExpireMonth() ); + $token->set_expiry_year( $card_token->getCard()->getExpireYear() ); + $token->set_last4( $card_token->getCard()->getPartialPan() ); + $token->set_token( $card_token->getToken() ); + $token->set_user_id( get_current_user_id() ); + $token->set_gateway_id( Plugin::GATEWAY_ID ); + \WC_Payment_Tokens::set_users_default( get_current_user_id(), $token->get_id() ); return $token->save(); } @@ -670,11 +671,11 @@ private function save_card_token( GetTokenResponse $card_token) { * @throws ValidationException */ public function add_payment_method() { - $this->add_card_form(Plugin::ADD_CARD_CONTEXT_MY_ACCOUNT); + $this->add_card_form( Plugin::ADD_CARD_CONTEXT_MY_ACCOUNT ); return array( - 'result' => 'success', - 'redirect' => wc_get_endpoint_url('payment-methods'), + 'result' => 'success', + 'redirect' => wc_get_endpoint_url( 'payment-methods' ), ); } @@ -682,33 +683,33 @@ public function add_payment_method() { * Grab and display users saved card payment methods. */ public function saved_payment_methods() { - $html = '