Пример #1
0
                                </div>
                                <button class="btn btn-primary"
                                        type="submit"><?php 
    _e('Apply Coupon', ST_TEXTDOMAIN);
    ?>
</button>
                            </form>
                        </div>
                        <div class="booking-item-payment-total text-right">
                            <?php 
    /*if(st()->get_option('tax_enable','off')=='on'):*/
    $tax = st()->get_option('tax_value', 0);
    $tax_money = STCart::get_tax_amount();
    $total_without_tax = STCart::get_total_with_out_tax();
    if (STCart::is_tax_included_listing_page()) {
        $tax_money = $total_without_tax / 100 * STCart::get_tax(true);
        $total_without_tax -= $tax_money;
    }
    ?>
                            <table border="0" class="table_checkout">
                                <tr>
                                    <td class="text-left title"><?php 
    st_the_language('sub_total:');
    ?>
 </td>
                                    <td class="text-right "><?php 
    echo TravelHelper::format_money($total_without_tax);
    ?>
</td>
                                </tr>
                                <?php 
Пример #2
0
 static function booking_form_submit($item_id = '')
 {
     if (STInput::post('st_payment_gateway') and wp_verify_nonce(STInput::post('travel_order'), 'submit_form_order')) {
         $payment_gateways = STInput::post('st_payment_gateway');
         $payment_gateway_used = false;
         if (!is_array($payment_gateways) or empty($payment_gateways)) {
             return array('status' => false, 'message' => __('Sorry! No payment gateway found', ST_TEXTDOMAIN));
         } else {
             foreach ($payment_gateways as $key => $value) {
                 $payment_gateway_id = $key;
                 $payment_gateway_used = STPaymentGateways::get_gateway($payment_gateway_id);
             }
             //Validate gateway is avaible
             if (!isset($payment_gateway_id) or !$payment_gateway_used) {
                 return array('status' => false, 'message' => sprintf(__('Sorry! Payment Gateway: <code>%s</code> is not available!', ST_TEXTDOMAIN), $payment_gateway_id));
             }
         }
         // Action before submit form
         do_action('st_before_form_submit_run');
         $form_validate = true;
         if (!self::check_cart()) {
             return array('status' => false, 'message' => __('Your cart is currently empty.', ST_TEXTDOMAIN), 'code' => '1');
         }
         if ($coupon_code = STInput::request('coupon_code')) {
             $status = self::do_apply_coupon($coupon_code);
             if (!$status['status']) {
                 return array('status' => false, 'message' => $status['message']);
             }
         }
         if (st()->get_option('booking_enable_captcha', 'on') == 'on') {
             $st_security_key = STInput::request('st_security_key');
             if (!$st_security_key) {
                 return array('status' => false, 'message' => __('You dose not enter the captcha', ST_TEXTDOMAIN));
             }
             $valid = STCoolCaptcha::validate_captcha($st_security_key);
             if (!$valid) {
                 return array('status' => false, 'message' => __('Captcha is not correct', ST_TEXTDOMAIN), 'error_code' => 'invalid_captcha');
             }
         }
         $default = array('st_note' => '', 'term_condition' => '', 'create_account' => false, 'paypal_checkout' => false);
         extract(wp_parse_args($_POST, $default));
         //Term and condition
         if (!$term_condition) {
             return array('status' => false, 'message' => __('Please accept our terms and conditions', ST_TEXTDOMAIN));
         }
         $form_validate = self::validate_checkout_fields();
         if ($form_validate) {
             // Payment method pre checkout validate
             $form_validate = $payment_gateway_used->_pre_checkout_validate();
         }
         if ($form_validate) {
             // Allow to hook before save order
             $form_validate = apply_filters('st_checkout_form_validate', $form_validate);
         }
         if (!$form_validate) {
             $message = array('status' => false, 'message' => STTemplate::get_message_content(), 'form_validate' => 'false');
             STTemplate::clear();
             return $message;
         }
         $post = array('post_title' => __('Order', ST_TEXTDOMAIN) . ' - ' . date(get_option('date_format')) . ' @ ' . date(get_option('time_format')), 'post_type' => 'st_order', 'post_status' => 'publish');
         //save the order
         $insert_post = wp_insert_post($post);
         if ($insert_post) {
             $cart = self::get_items();
             // Update checkout fields
             $fields = self::get_checkout_fields();
             if (!empty($fields)) {
                 foreach ($fields as $key => $value) {
                     update_post_meta($insert_post, $key, STInput::post($key));
                 }
             }
             update_post_meta($insert_post, 'st_tax', STCart::get_tax());
             update_post_meta($insert_post, 'st_tax_percent', STCart::get_tax(true));
             update_post_meta($insert_post, 'st_is_tax_included_listing_page', STCart::is_tax_included_listing_page() ? 'on' : 'off');
             update_post_meta($insert_post, 'st_currency', TravelHelper::get_current_currency('symbol'));
             update_post_meta($insert_post, 'coupon_code', STCart::get_coupon_code());
             update_post_meta($insert_post, 'coupon_amount', STCart::get_coupon_amount());
             update_post_meta($insert_post, 'status', 'pending');
             update_post_meta($insert_post, 'st_cart_info', $cart);
             update_post_meta($insert_post, 'total_price', STCart::get_total());
             update_post_meta($insert_post, 'ip_address', STInput::ip_address());
             update_post_meta($insert_post, 'order_token_code', wp_hash($insert_post));
             self::saveOrderItems($insert_post);
             if (!is_user_logged_in()) {
                 $user_name = STInput::post('st_email');
                 $user_id = username_exists($user_name);
                 //Now Create Account if user agree
                 if ($create_account) {
                     if (!$user_id and email_exists($user_name) == false) {
                         $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
                         $userdata = array('user_login' => $user_name, 'user_pass' => $random_password, 'user_email' => $user_name, 'first_name' => STInput::post('st_first_name'), 'last_name' => STInput::post('st_last_name'));
                         $user_id = wp_insert_user($userdata);
                         //Create User Success, send the nofitication
                         wp_new_user_notification($user_id, $random_password);
                     }
                 }
             } else {
                 $user_id = get_current_user_id();
             }
             if ($user_id) {
                 //Now Update the Post Meta
                 update_post_meta($insert_post, 'id_user', $user_id);
                 //Update User Meta
                 update_user_meta($user_id, 'st_phone', STInput::post('st_phone'));
                 update_user_meta($user_id, 'first_name', STInput::post('st_first_name'));
                 update_user_meta($user_id, 'last_name', STInput::post('st_last_name'));
                 update_user_meta($user_id, 'st_address', STInput::post('st_address'));
                 update_user_meta($user_id, 'st_address2', STInput::post('st_address2'));
                 update_user_meta($user_id, 'st_city', STInput::post('st_city'));
                 update_user_meta($user_id, 'st_province', STInput::post('st_province'));
                 update_user_meta($user_id, 'st_zip_code', STInput::post('st_zip_code'));
                 update_user_meta($user_id, 'st_country', STInput::post('st_country'));
                 update_user_meta($user_id, 'st_zip_code', STInput::post('st_zip_code'));
             }
             update_post_meta($insert_post, 'payment_method', $payment_gateway_id);
             do_action('st_booking_success', $insert_post);
             // Now gateway do the rest
             return $payment_gateway_used->do_checkout($insert_post);
         } else {
             return array('status' => false, 'message' => __('Can not save order.', ST_TEXTDOMAIN));
         }
     }
 }