id = 'afterpay_no_openinvoice'; $this->method_title = __( 'AfterPay Norway Digital Invoice', 'afterpay' ); $this->has_fields = true; // Load the form fields. $this->init_form_fields(); $this->show_bankaccount = false; $this->order_type = 'B2C'; // Load the settings. $this->init_settings(); // Define user set variables for basic settings. $this->enabled = ( isset( $this->settings['enabled'] ) ) ? $this->settings['enabled'] : ''; $this->title = ( isset( $this->settings['title'] ) ) ? $this->settings['title'] : ''; $this->extra_information = ( isset( $this->settings['extra_information'] ) ) ? $this->settings['extra_information'] : ''; $this->merchantid = ( isset( $this->settings['merchantid'] ) ) ? $this->settings['merchantid'] : ''; $this->lower_threshold = ( isset( $this->settings['lower_threshold'] ) ) ? $this->settings['lower_threshold'] : ''; $this->upper_threshold = ( isset( $this->settings['upper_threshold'] ) ) ? $this->settings['upper_threshold'] : ''; $this->testmode = ( isset( $this->settings['testmode'] ) ) ? $this->settings['testmode'] : ''; $this->debug_mail = ( isset( $this->settings['debug_mail'] ) ) ? $this->settings['debug_mail'] : ''; $this->ip_restriction = ( isset( $this->settings['ip_restriction'] ) ) ? $this->settings['ip_restriction'] : ''; $this->show_advanced = ( isset( $this->settings['show_advanced'] ) ) ? $this->settings['show_advanced'] : 'no'; // Advanced settings. $this->show_phone = ( isset( $this->settings['show_phone'] ) ) ? $this->settings['show_phone'] : ''; $this->show_termsandconditions = ( isset( $this->settings['show_termsandconditions'] ) ) ? $this->settings['show_termsandconditions'] : ''; $this->use_custom_housenumber_field = ( isset( $this->settings['use_custom_housenumber_field'] ) ) ? $this->settings['use_custom_housenumber_field'] : ''; $this->use_custom_housenumber_addition_field = ( isset( $this->settings['use_custom_housenumber_addition_field'] ) ) ? $this->settings['use_custom_housenumber_addition_field'] : ''; // Captures and refunds. $this->captures = ( isset( $this->settings['captures'] ) ) ? $this->settings['captures'] : ''; $this->captures_way = ( isset( $this->settings['captures_way'] ) ) ? $this->settings['captures_way'] : ''; $this->captures_way_based_on_status = ( isset( $this->settings['captures_way_based_on_status'] ) ) ? $this->settings['captures_way_based_on_status'] : ''; $this->refunds = ( isset( $this->settings['refunds'] ) ) ? $this->settings['refunds'] : ''; $this->refund_tax_percentage = ( isset( $this->settings['refund_tax_percentage'] ) ) ? $this->settings['refund_tax_percentage'] : ''; if ( isset( $this->settings['refunds'] ) && 'yes' === $this->settings['refunds'] ) { $this->supports = array( 'refunds' ); } $afterpay_country = 'NO'; $afterpay_language = 'NO'; $afterpay_currency = 'NOK'; $afterpay_invoice_terms = 'https://documents.myafterpay.com/consumer-terms-conditions/no_no/' . $this->merchantid; $afterpay_privacy_statement = 'https://documents.myafterpay.com/privacy-statement/no_no/' . $this->merchantid; $afterpay_invoice_icon = plugins_url( basename( dirname( __FILE__ ) ) . '/images/afterpay.png' ); // Apply filters to Country and language. $this->afterpay_country = apply_filters( 'afterpay_country', $afterpay_country ); $this->afterpay_language = apply_filters( 'afterpay_language', $afterpay_language ); $this->afterpay_currency = apply_filters( 'afterpay_currency', $afterpay_currency ); $this->afterpay_invoice_terms = apply_filters( 'afterpay_invoice_terms', $afterpay_invoice_terms ); $this->afterpay_privacy_statement = apply_filters( 'afterpay_privacy_statement', $afterpay_privacy_statement ); $this->icon = apply_filters( 'afterpay_invoice_icon', $afterpay_invoice_icon ); // Actions /* 2.0.0 */ add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_receipt_afterpay', array( &$this, 'receipt_page' ) ); // Add event handler for an order Status change. add_action( 'woocommerce_order_status_changed', array( $this, 'order_status_change_callback' ), 1000, 4 ); } /** * Initialise Gateway Settings Form Fields * * @access public * @return void */ public function init_form_fields() { $this->form_fields = apply_filters( 'afterpay_no_openinvoice_form_fields', array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'afterpay' ), 'type' => 'checkbox', 'label' => __( 'Enable AfterPay Norway Digital Invoice', 'afterpay' ), 'default' => 'no', ), 'title' => array( 'title' => __( 'Title', 'afterpay' ), 'type' => 'text', 'description' => __( 'This controls the title which the user sees during checkout.', 'afterpay' ), 'default' => __( 'Betal senere', 'afterpay' ), ), 'extra_information' => array( 'title' => __( 'Extra information', 'afterpay' ), 'type' => 'textarea', 'description' => __( 'Extra information to show to the customer in the checkout', 'afterpay' ), 'default' => 'Kjøp nå, betal senere', ), 'api_key' => array( 'title' => __( 'API Key', 'afterpay' ), 'type' => 'text', 'description' => __( 'Please enter your AfterPay API Key; this is needed in order to take payment!', 'afterpay' ), 'default' => '', ), 'lower_threshold' => array( 'title' => __( 'Lower threshold', 'afterpay' ), 'type' => 'text', 'description' => __( 'Disable AfterPay Invoice if Cart Total is lower than the specified value. Leave blank to disable this feature.', 'afterpay' ), 'default' => '5', ), 'upper_threshold' => array( 'title' => __( 'Upper threshold', 'afterpay' ), 'type' => 'text', 'description' => __( 'Disable AfterPay Invoice if Cart Total is higher than the specified value. Leave blank to disable this feature.', 'afterpay' ), 'default' => '', ), 'testmode' => array( 'title' => __( 'Test Mode', 'afterpay' ), 'type' => 'select', 'description' => __( 'Enable or disable test mode. The sandbox option is for testing with API keys from developer.afterpay.io.', 'afterpay' ), 'options' => array( 'yes' => 'Yes', 'sandbox' => 'Yes - Sandbox', 'no' => 'No', ), ), 'debug_mail' => array( 'title' => __( 'Debug mail', 'afterpay' ), 'type' => 'text', 'description' => __( 'Use debug mail to send the complete AfterPay request to your mail, for debug functionality only. Leave empty to disable.', 'afterpay' ), 'default' => '', ), 'ip_restriction' => array( 'title' => __( 'IP restriction', 'afterpay' ), 'type' => 'text', 'description' => __( 'Fill in IP address to only show the payment method for that specific IP address. Leave empty to disable', 'afterpay' ), 'default' => '', ), 'show_advanced' => array( 'title' => __( 'Show advanced settings', 'afterpay' ), 'type' => 'select', 'description' => __( 'Show advanced settings' ), 'options' => array( 'yes' => 'Yes', 'no' => 'No', ), 'default' => 'no', ), 'display_settings' => array( 'title' => __( 'Display settings', 'afterpay' ), 'type' => 'title', 'description' => '', 'class' => 'afterpay_advanced_setting', ), 'show_phone' => array( 'title' => __( 'Show phone number', 'afterpay' ), 'type' => 'checkbox', 'description' => __( 'Show phone number field instead of Woocommerce default field. If this field is missing in default checkout', 'afterpay' ), 'default' => 'no', 'class' => 'afterpay_advanced_setting', ), 'show_termsandconditions' => array( 'title' => __( 'Show terms and conditions', 'afterpay' ), 'type' => 'checkbox', 'description' => __( 'Show terms and conditions of AfterPay', 'afterpay' ), 'default' => 'yes', 'class' => 'afterpay_advanced_setting', ), 'use_custom_housenumber_field' => array( 'title' => __( 'Use custom housenumber field', 'afterpay' ), 'type' => 'text', 'description' => __( 'Fill in the custom field name used for the housenumber, without billing_ or shipping_', 'afterpay' ), 'default' => '', 'class' => 'afterpay_advanced_setting', ), 'use_custom_housenumber_addition_field' => array( 'title' => __( 'Use custom housenumber addition field', 'afterpay' ), 'type' => 'text', 'description' => __( 'Fill in the custom field name used for the housenumber addition, without billing_ or shipping_', 'afterpay' ), 'default' => '', 'class' => 'afterpay_advanced_setting', ), 'merchantid' => array( 'title' => __( 'Merchant ID', 'afterpay' ), 'type' => 'text', 'default' => '', 'class' => 'afterpay_advanced_setting', ), 'captures_and_refunds_section' => array( 'title' => __( 'Captures and refunds', 'afterpay' ), 'type' => 'title', 'description' => '', 'class' => 'afterpay_advanced_setting', ), 'captures' => array( 'title' => __( 'Enable captures', 'afterpay' ), 'type' => 'checkbox', 'label' => __( 'Enable capturing', 'afterpay' ), 'default' => 'yes', 'class' => 'afterpay_advanced_setting', ), 'captures_way' => array( 'title' => __( 'Way of captures', 'afterpay' ), 'label' => __( 'Way of capturing', 'afterpay' ), 'type' => 'select', 'default' => 'auto_after_authorization', 'options' => array( 'auto_after_authorization' => __( 'Automatically after authorization', 'afterpay' ), 'based_on_status' => __( 'Based on Woocommerce Status', 'afterpay' ), ), 'class' => 'afterpay_advanced_setting', ), 'captures_way_based_on_status' => array( 'title' => __( 'Status to capture based on', 'afterpay' ), 'label' => __( 'Status to capture based on', 'afterpay' ), 'type' => 'select', 'options' => $this->get_all_possible_order_statuses(), 'class' => 'afterpay_advanced_setting', ), 'refunds' => array( 'title' => __( 'Enable refunds', 'afterpay' ), 'type' => 'checkbox', 'label' => __( 'Enable refunding', 'afterpay' ), 'default' => 'yes', 'class' => 'afterpay_advanced_setting', ), 'refund_tax_percentage' => array( 'title' => __( 'Refund tax percentage', 'afterpay' ), 'type' => 'text', 'label' => __( 'Default percentage calculated on refunds to AfterPay', 'afterpay' ), 'default' => '0', 'class' => 'afterpay_advanced_setting', ), ) ); } /** * Payment form on checkout page * * @acces public * @return void */ public function payment_fields() { global $woocommerce; if ( 'yes' === $this->testmode ) : ?>
testmode ) : ?> show_phone && ! isset( $_POST[ $this->id . '_phone' ] ) ) { wc_add_notice( esc_html__( 'Phone number is a required field', 'afterpay' ), 'error' ); return false; } if ( ! isset( $_POST[ $this->id . '_ssn' ] ) ) { wc_add_notice( esc_html__( 'Social security number is a required field', 'afterpay' ), 'error' ); return false; } if ( 'yes' === $this->show_termsandconditions && ! isset( $_POST[ $this->id . '_terms' ] ) ) { wc_add_notice( esc_html__( 'Please accept the AfterPay terms.', 'afterpay' ), 'error' ); return false; } return true; } }