/** * Class constructor. * * @since 1.0.0 */ public function __construct() { global $woocommerce; parent::__construct(); $this->id = 'klarna_invoice'; $this->method_title = __('Klarna Invoice', 'woocommerce-gateway-klarna'); $this->method_description = sprintf(__('With Klarna your customers can pay by invoice. Klarna works by adding extra personal information fields and then sending the details to Klarna for verification. Documentation <a href="%s" target="_blank">can be found here</a>.', 'woocommerce-gateway-klarna'), 'https://docs.woothemes.com/document/klarna/'); $this->has_fields = true; $this->order_button_text = apply_filters('klarna_order_button_text', __('Place order', 'woocommerce')); $this->pclass_type = array(2); // Load the form fields. $this->init_form_fields(); // Load the settings. $this->init_settings(); // Define user set variables include KLARNA_DIR . 'includes/variables-invoice.php'; // Load shortcodes. // This is used so that the merchant easily can modify the displayed monthly // cost text (on single product and shop page) via the settings page. include_once KLARNA_DIR . 'classes/class-klarna-shortcodes.php'; // Klarna PClasses handling. include_once KLARNA_DIR . 'classes/class-klarna-pclasses.php'; // Helper class include_once KLARNA_DIR . 'classes/class-klarna-helper.php'; $this->klarna_helper = new WC_Gateway_Klarna_Helper($this); // Test mode or Live mode if ($this->testmode == 'yes') { // Disable SSL if in testmode $this->klarna_ssl = 'false'; $this->klarna_mode = Klarna::BETA; } else { // Set SSL if used in webshop if (is_ssl()) { $this->klarna_ssl = 'true'; } else { $this->klarna_ssl = 'false'; } $this->klarna_mode = Klarna::LIVE; } // Apply filters to Country and language $this->klarna_invoice_info = apply_filters('klarna_invoice_info', ''); $this->icon = apply_filters('klarna_invoice_icon', $this->klarna_helper->get_account_icon()); $this->icon_basic = apply_filters('klarna_basic_icon', ''); // Apply filters to Klarna warning banners (NL only) $klarna_wb = $this->get_klarna_wb(); $this->klarna_wb_img_checkout = apply_filters('klarna_wb_img_checkout', $klarna_wb['img_checkout']); $this->klarna_wb_img_single_product = apply_filters('klarna_wb_img_single_product', $klarna_wb['img_single_product']); $this->klarna_wb_img_product_list = apply_filters('klarna_wb_img_product_list', $klarna_wb['img_product_list']); // Refunds support $this->supports = array('products', 'refunds'); // Actions add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); add_action('woocommerce_receipt_klarna_invoice', array($this, 'receipt_page')); add_action('wp_print_footer_scripts', array($this, 'footer_scripts')); // Check Klarna pending order add_action('check_klarna_pending', array($this, 'check_klarna_pending_callback')); // Add Klarna shipping info to order confirmation page and email add_filter('woocommerce_thankyou_order_received_text', array($this, 'output_klarna_details_confirmation'), 20, 2); // add_action( 'woocommerce_email_after_order_table', array( $this, 'output_klarna_details_confirmation_email' ), 10, 3 ); }
/** * Class constructor. * * @since 1.0.0 */ public function __construct() { global $woocommerce; parent::__construct(); $this->id = 'klarna_checkout'; $this->method_title = __('Klarna Checkout', 'woocommerce-gateway-klarna'); $this->has_fields = false; // Load the form fields. $this->init_form_fields(); // Load the settings. $this->init_settings(); // Define user set variables include KLARNA_DIR . 'includes/variables-checkout.php'; // Helper class include_once KLARNA_DIR . 'classes/class-klarna-helper.php'; $this->klarna_helper = new WC_Gateway_Klarna_Helper($this); // Test mode or Live mode if ($this->testmode == 'yes') { // Disable SSL if in testmode $this->klarna_ssl = 'false'; $this->klarna_mode = Klarna::BETA; } else { // Set SSL if used in webshop if (is_ssl()) { $this->klarna_ssl = 'true'; } else { $this->klarna_ssl = 'false'; } $this->klarna_mode = Klarna::LIVE; } // Actions add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); // Push listener add_action('woocommerce_api_wc_gateway_klarna_checkout', array($this, 'check_checkout_listener')); // Validate listener add_action('woocommerce_api_wc_gateway_klarna_order_validate', array('WC_Gateway_Klarna_Order_Validate', 'validate_checkout_listener')); // We execute the woocommerce_thankyou hook when the KCO Thank You page is rendered, // because other plugins use this, but we don't want to display the actual WC Order // details table in KCO Thank You page. This action is removed here, but only when // in Klarna Thank You page. if (is_page()) { global $post; $klarna_checkout_page_id = url_to_postid($this->klarna_checkout_thanks_url); if ($post->ID == $klarna_checkout_page_id) { remove_action('woocommerce_thankyou', 'woocommerce_order_details_table', 10); } } // Subscription support $this->supports = array('products', 'refunds', 'subscriptions', 'subscription_cancellation', 'subscription_suspension', 'subscription_reactivation', 'subscription_amount_changes', 'subscription_date_changes', 'subscription_payment_method_change', 'multiple_subscriptions'); // Add link to KCO page in standard checkout /** * Checkout page AJAX */ // Add coupon add_action('wp_ajax_klarna_checkout_coupons_callback', array($this, 'klarna_checkout_coupons_callback')); add_action('wp_ajax_nopriv_klarna_checkout_coupons_callback', array($this, 'klarna_checkout_coupons_callback')); // Remove coupon add_action('wp_ajax_klarna_checkout_remove_coupon_callback', array($this, 'klarna_checkout_remove_coupon_callback')); add_action('wp_ajax_nopriv_klarna_checkout_remove_coupon_callback', array($this, 'klarna_checkout_remove_coupon_callback')); // Cart quantity add_action('wp_ajax_klarna_checkout_cart_callback_update', array($this, 'klarna_checkout_cart_callback_update')); add_action('wp_ajax_nopriv_klarna_checkout_cart_callback_update', array($this, 'klarna_checkout_cart_callback_update')); // Cart remove add_action('wp_ajax_klarna_checkout_cart_callback_remove', array($this, 'klarna_checkout_cart_callback_remove')); add_action('wp_ajax_nopriv_klarna_checkout_cart_callback_remove', array($this, 'klarna_checkout_cart_callback_remove')); // Shipping method selector add_action('wp_ajax_klarna_checkout_shipping_callback', array($this, 'klarna_checkout_shipping_callback')); add_action('wp_ajax_nopriv_klarna_checkout_shipping_callback', array($this, 'klarna_checkout_shipping_callback')); // Shipping option inside KCO iframe add_action('wp_ajax_kco_iframe_shipping_option_change_cb', array($this, 'kco_iframe_shipping_option_change_cb')); add_action('wp_ajax_nopriv_kco_iframe_shipping_option_change_cb', array($this, 'kco_iframe_shipping_option_change_cb')); // Country selector add_action('wp_ajax_klarna_checkout_country_callback', array($this, 'klarna_checkout_country_callback')); add_action('wp_ajax_nopriv_klarna_checkout_country_callback', array($this, 'klarna_checkout_country_callback')); // Order note add_action('wp_ajax_klarna_checkout_order_note_callback', array($this, 'klarna_checkout_order_note_callback')); add_action('wp_ajax_nopriv_klarna_checkout_order_note_callback', array($this, 'klarna_checkout_order_note_callback')); // KCO iframe JS event callbacks // V2 add_action('wp_ajax_kco_iframe_change_cb', array($this, 'kco_iframe_change_cb')); add_action('wp_ajax_nopriv_kco_iframe_change_cb', array($this, 'kco_iframe_change_cb')); // V3 add_action('wp_ajax_kco_iframe_shipping_address_change_cb', array($this, 'kco_iframe_shipping_address_change_cb')); add_action('wp_ajax_nopriv_kco_iframe_shipping_address_change_cb', array($this, 'kco_iframe_shipping_address_change_cb')); if (class_exists('WC_Subscriptions_Order')) { // Process subscription payment // add_action( 'woocommerce_scheduled_subscription_renewal_klarna_checkout', array( $this, 'scheduled_subscription_payment' ), 10, 2 ); add_action('woocommerce_scheduled_subscription_payment_klarna_checkout', array($this, 'scheduled_subscription_payment'), 10, 2); // Do not copy invoice number to recurring orders // add_filter( 'woocommerce_subscriptions_renewal_order_meta_query', array( $this, 'kco_recurring_do_not_copy_meta_data' ), 10, 4 ); } // Purge kco_incomplete orders hourly add_action('wp', array($this, 'register_purge_cron_job')); add_action('klarna_purge_cron_job_hook', array($this, 'purge_kco_incomplete')); // Add activate settings field for recurring orders add_filter('klarna_checkout_form_fields', array($this, 'add_activate_recurring_option')); // Register new order status add_action('init', array($this, 'register_klarna_incomplete_order_status')); add_filter('wc_order_statuses', array($this, 'add_kco_incomplete_to_order_statuses')); add_filter('woocommerce_valid_order_statuses_for_payment_complete', array($this, 'kco_incomplete_payment_complete')); add_filter('woocommerce_valid_order_statuses_for_payment', array($this, 'kco_incomplete_payment_complete')); // Hide "Refunded" and "KCO Incomplete" statuses for KCO orders add_filter('wc_order_statuses', array($this, 'remove_refunded_and_kco_incomplete'), 1000); // Hide "Manual Refund" button for KCO orders add_action('admin_head', array($this, 'remove_refund_manually')); // Cancel unpaid orders for KCO orders too add_filter('woocommerce_cancel_unpaid_order', array($this, 'cancel_unpaid_kco'), 10, 2); }