'radio', 'escape_options' => false, 'multi_options' => [ self::PAYMENT_METHOD_STRIPE => fqp_esc_html__( 'Online Payment with Credit Card' ) . 'STRIPE', self::PAYMENT_METHOD_INVOICE => fqp_esc_html__( 'Payment by Invoice' ) . " (+ CHF {$offline_payment_fee})", ], 'input_attribs' => [ self::PAYMENT_METHOD_STRIPE => [ 'data-method-title' => fqp_esc_html__( 'Stripe' ), 'data-fee' => 0.0, ], self::PAYMENT_METHOD_INVOICE => [ 'data-method-title' => fqp_esc_html__( 'Payment by Invoice' ), 'data-fee' => $offline_payment_fee, ], ], ]; $fields['comment'] = [ 'type' => 'textarea', 'attribs' => [], ]; $fields['email_subscription'] = [ 'type' => 'checkbox', 'label' => 'EN Ja, ich möchte über Tipps und News rund um die Firmengründung und das Unternehmertum informiert werden. (Keine Angst, wir werden Sie nicht mit Unmengen an E-Mails belästigen und Sie können die Informationen jederzeit wieder abbestellen.)', 'attribs' => [] ]; $lang = FQP\FQP::get_curr_lang(); $url = get_site_url(); if ( 'de' == $lang ) { $url = "{$url}/{$lang}/agb/"; } else { $url = "{$url}/{$lang}/agb/"; // англійська має мити власний урл } $fields['agree'] = [ 'type' => 'checkbox', 'label' => sprintf( fqp__( 'EN Ja, ich akzeptiere die AGB\'s' ), $url ), 'escape_label' => false, 'attribs' => [ 'required' => true, ] ]; $fields['zc_gad'] = [ 'type' => 'hidden', ]; $fields['loyalty_card_id'] = [ 'type' => 'hidden', 'attribs' => [], ]; $fields['loyalty_card_value'] = [ 'type' => 'hidden', 'attribs' => [], ]; static::$fields = $fields; } public static function get_fields( $name = null ) { if ( empty( static::$fields ) ) { static::init_fields(); } return fqp_array_get( static::$fields, $name ); } /** * Return array [ 'price', 'partner_discount', 'total_discount', 'payment_fee', 'payment_fee_tax', 'total', 'tax', 'VAT' ] * * @param $all_data * * @return array */ public static function get_order_total($all_data, $payment_method = null ) { $price = $total_discount = $total = $tax = 0; $partner_discount = []; if ( is_array( $all_data ) && ! empty( $all_data ) ) { $entry_types = FQP\DB::get_entry_types(); $prices = FQP\Settings::get_prices(); $curr_lang = FQP\FQP::get_curr_lang(); $et_id = @$all_data['step1']['entry_type']; $bt_id = @$all_data['step1']['backing_type']; $et = $entry_types[$et_id]; if ( 'y' == $et['hasBacking'] ) { $price = $total = $prices['price'][ $et_id ][ $bt_id ][ $curr_lang ]; } else { $price = $total = $prices['price'][ $et_id ][ $curr_lang ]; } if ( ! empty( $all_data['step1']['partners'] ) ) { $partners = FQP\DB::get_partners_query(); while ( $partners->have_posts() ) { $partner = $partners->next_post(); if ( in_array( $partner->ID, $all_data['step1']['partners'] ) ) { if ( 'y' == $et['hasBacking'] ) { $discount = $prices['partner_discount'][ $partner->ID ][ $et_id ][ $bt_id ]; } else { $discount = $prices['partner_discount'][ $partner->ID ][ $et_id ]; } if ($discount) { $discount_price = bcdiv( bcmul( $price, $discount, 2 ), '100', 2 ); if ( 1 == bccomp( $discount_price, $total, 2 ) ) { $discount_price = $total; } $total = bcsub( $total, $discount_price, 2 ); if ( - 1 == bccomp( $total, '0', 2 ) ) { $total = 0; } $partner_discount[ $partner->ID ] = $discount_price; } else { $partner_discount[ $partner->ID ] = 0; } } } $banks = FQP\Bank::get(); foreach ( $banks as $bank ) { if (in_array($bank->ID, $all_data['step1']['partners'])) { $b_discounts = FQP\Bank::fetch_discounts( $bank ); if ( 'y' == $et['hasBacking'] ) { $discount = $b_discounts[ $et_id ][ $bt_id ]; } else { $discount = $b_discounts[ $et_id ]; } if ($discount) { $discount_price = bcdiv( bcmul( $price, $discount, 2 ), '100', 2 ); if ( 1 == bccomp( $discount_price, $total, 2 ) ) { $discount_price = $total; } $total = bcsub( $total, $discount_price, 2 ); if ( - 1 == bccomp( $total, '0', 2 ) ) { $total = 0; } $partner_discount[ $bank->ID ] = $discount_price; } else { $partner_discount[ $bank->ID ] = 0; } } } if ( 0 != bccomp( $price, $total, 2 ) ) { $total_discount = bcsub( $price, $total, 2 ); } } $products_total = 0; $products_tax = 0; if ( ! empty( $all_data['step6']['products'] ) ) { $products = FQP\Product::get_query( $all_data['step1']['entry_type'], @$all_data['step1']['backing_type'] ); if ( $products && $products->have_posts() ) { while ( $products->have_posts() ) { $product = $products->next_post(); if ( in_array( $product->ID, $all_data['step6']['products'] ) ) { $products_total = bcadd( $products_total, get_field( 'price', $product ), 2); } } } if ($products_total > 0) { $products_tax = FQP\Shortcode\QuotePrice::claclulateTax( $products_total, FQP\FQP::VAT ); } } $payment_fee = 0.0; $payment_fee_tax = 0.0; $VAT = FQP\FQP::VAT; if ( $total > 0 || $products_total > 0 ) { if ( $payment_method && self::PAYMENT_METHOD_INVOICE == $payment_method ) { $payment_fee = floatval( get_option( 'fqp-main-offline-payment-fee' ) ); $payment_fee_tax = FQP\Shortcode\QuotePrice::claclulateTax( $payment_fee, $VAT ); } $tax = FQP\Shortcode\QuotePrice::claclulateTax( $total, $VAT ); } } $loyalty_card_value = 0; if ( $all_data['step6']['loyalty_card_id'] ) { try { $card = InnocardLoyalty\Card::get( $all_data['step6']['loyalty_card_id'] ); $loyalty_card_value = $card['Balance']; } catch (InnocardLoyalty\InnocadLoyaltyException $e) { if ( WP_DEBUG ) { wp_die( $e->getMessage() ); } } } $loyalty_card_discount = '0.00'; if ( $loyalty_card_value > 0 ) { $amount = '0.00'; $amount = bcadd( $amount, $total, 2 ); $amount = bcadd( $amount, $tax, 2 ); $amount = bcadd( $amount, $products_total, 2 ); $amount = bcadd( $amount, $products_tax, 2 ); $amount = bcadd( $amount, $payment_fee, 2 ); $amount = bcadd( $amount, $payment_fee_tax, 2 ); if ( 1 == bccomp($amount, $loyalty_card_value, 2) ) { $loyalty_card_discount = $loyalty_card_value; } else { $loyalty_card_discount = $amount; } } return compact( 'price', // ціна за тип фірми 'products_total', // загальна сума за всі продукти 'products_tax', // податок за всі продукти 'partner_discount', // масив знижок по кожному партнеру 'total_discount', // зазальга знижка (сума partner_discount) 'payment_fee', // ціна за тип "payment_method" 'payment_fee_tax', // податок за payment_fee 'total', // загальна сума ( price - total_discount ) 'tax', // податок за total 'VAT', // ПДВ% 'loyalty_card_value', // баланс на карті лояльності 'loyalty_card_discount' // сума списання з карти лояльності ); } public static function sanitize_data( &$data, $all_data = []) { if ( !is_array( $data ) ) { $data = []; } $errors = []; $required_msg = fqp__( '%s is required' ); $fields = static::get_fields(); $order_total = self::get_order_total( $all_data ); if ( empty( $data['payment_method'] ) && $order_total['total'] > 0 ) { $errors[] = esc_html( sprintf( $required_msg, fqp__( 'Bezahlverfahren' ) ) ); } unset( $fields['payment_method'] ); foreach ( $fields as $name => $specs ) { if ( @$specs['attribs']['required'] && empty( $data[$name] ) ) { $title = ( ! empty( $specs['label'] ) ) ? $specs['label'] : $specs['attribs']['placeholder']; $errors[] = esc_html( sprintf( $required_msg, fqp__( $title ) ) ); } } if ( ! empty( $data['products'] ) && ! empty( $all_data['step1'] ) ) { $products = FQP\Product::get_query( $all_data['step1']['entry_type'], @$all_data['step1']['backing_type'] ); if ( $products && $products->have_posts() ) { $products = array_column( $products->posts, 'ID' ); foreach ( $data['products'] as $index => $product_id ) { if ( ! in_array( $product_id, $products ) ) { unset( $data['products'][$index] ); } } } } $loyalty_card_id = trim( fqp_array_get( $data, 'loyalty_card_id', '' ) ); if ( $loyalty_card_id ) { try { InnocardLoyalty\Card::get( $loyalty_card_id ); } catch (InnocardLoyalty\InnocadLoyaltyException $e) { $errors[] = esc_html( $e->getMessage() ); } } return ( empty( $errors ) ) ? true : $errors; } public static function get_filter_fields() { $fields = parent::get_filter_fields(); $fields['products'] = []; return $fields; } }