Ejemplo n.º 1
0
 public function __construct()
 {
     global $wpshop;
     $wpshop_paypal = new wpshop_paypal();
     // If the CIC payment method is active
     $wpshop_paymentMethod = get_option('wps_payment_mode');
     if (WPSHOP_PAYMENT_METHOD_CIC && (!empty($wpshop_paymentMethod['mode']) && !empty($wpshop_paymentMethod['mode']['cic']) && !empty($wpshop_paymentMethod['mode']['cic']['active']))) {
         $wpshop_cic = new wpshop_CIC();
     }
     wpshop_tools::create_custom_hook('wpshop_bankserver_reponse');
 }
<div class="wps-boxed">
<?php 
echo wpshop_tools::create_custom_hook('wpshop_payment_actions');
// Empty the cart
$wps_cart->empty_cart();
?>
</div>
Ejemplo n.º 3
0
 public static function process_checkout($paymentMethod = 'paypal', $order_id = 0, $customer_id = 0, $customer_billing_address_id = 0, $customer_shipping_address_id = 0)
 {
     global $wpdb, $wpshop, $wpshop_cart;
     $wps_message = new wps_message_ctr();
     $shipping_address_option = get_option('wpshop_shipping_address_choice');
     if (is_user_logged_in()) {
         $user_id = get_current_user_id();
         if ($customer_id != 0) {
             $user_id = $customer_id;
         }
         // If the order is already created in the db
         if (!empty($order_id) && is_numeric($order_id)) {
             $order = get_post_meta($order_id, '_order_postmeta', true);
             if (!empty($order)) {
                 if ($order['customer_id'] == $user_id) {
                     $order['payment_method'] = $paymentMethod;
                     $_SESSION['order_id'] = wpshop_tools::varSanitizer($order_id);
                     // Store cart in session
                     //wpshop_cart::store_cart_in_session($order);
                     // Add a payment
                     $order['order_payment']['received'][] = array('method' => $paymentMethod, 'waited_amount' => $order['order_amount_to_pay_now'], 'status' => 'waiting_payment', 'author' => get_current_user_id());
                     // On enregistre la commande
                     update_post_meta($order_id, '_order_postmeta', $order);
                     update_post_meta($order_id, '_wpshop_order_customer_id', $user_id);
                 } else {
                     $wpshop->add_error(__('You don\'t own the order', 'wpshop'));
                 }
             } else {
                 $wpshop->add_error(__('The order doesn\'t exist.', 'wpshop'));
             }
         } else {
             $order_data = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'post_title' => sprintf(__('Order - %s', 'wpshop'), mysql2date('d M Y\\, H:i:s', current_time('mysql', 0), true)), 'post_status' => 'publish', 'post_excerpt' => !empty($_POST['wps-customer-comment']) ? $_POST['wps-customer-comment'] : '', 'post_author' => $user_id, 'comment_status' => 'closed');
             // Cart items
             $order_items = array();
             $order_tva = array();
             //$cart = (array)$wpshop_cart->cart;
             if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['shipping_method'])) {
                 $_SESSION['cart']['shipping_method'] = __('Standard shipping method', 'wpshop');
             }
             $cart = (array) $_SESSION['cart'];
             $download_codes = array();
             // Nouvelle commande
             $order_id = wp_insert_post($order_data);
             $_SESSION['order_id'] = $order_id;
             // Cr�ation des codes de t�l�chargement si il y a des produits t�l�chargeable dans le panier
             if (!empty($cart['order_items'])) {
                 foreach ($cart['order_items'] as $c) {
                     $product = wpshop_products::get_product_data($c['item_id']);
                     /** Check if it's a variation and check the parent product **/
                     if (get_post_type($c['item_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                         $parent_def = wpshop_products::get_parent_variation($c['item_id']);
                         if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['is_downloadable_'])) {
                             $product['is_downloadable_'] = $parent_def['parent_post_meta']['is_downloadable_'];
                         }
                     }
                     if (!empty($product['is_downloadable_'])) {
                         $download_codes[$c['item_id']] = array('item_id' => $c['item_id'], 'download_code' => uniqid('', true));
                     }
                 }
             }
             if (!empty($download_codes)) {
                 update_user_meta($user_id, '_order_download_codes_' . $order_id, $download_codes);
             }
             // Informations de commande � stocker
             $currency = wpshop_tools::wpshop_get_currency(true);
             $order = array_merge(array('order_key' => NULL, 'customer_id' => $user_id, 'order_status' => 'awaiting_payment', 'order_date' => current_time('mysql', 0), 'order_shipping_date' => null, 'order_invoice_ref' => '', 'order_currency' => $currency, 'order_payment' => array('customer_choice' => array('method' => $paymentMethod), 'received' => array('0' => array('method' => $paymentMethod, 'waited_amount' => $cart['order_amount_to_pay_now'], 'status' => 'waiting_payment', 'author' => $user_id)), 'shipping_method' => !empty($_SESSION['shipping_method']) ? wpshop_tools::varSanitizer($_SESSION['shipping_method']) : __('Standard shipping method', 'wpshop'))), $cart);
             // Si c'est un devis
             if ($paymentMethod == 'quotation') {
                 $order['order_temporary_key'] = wpshop_orders::get_new_pre_order_reference();
             } else {
                 $order['order_key'] = wpshop_orders::get_new_order_reference();
             }
             //Round final amount
             $order['order_grand_total'] = number_format(round($order['order_grand_total'], 2), 2, '.', '');
             $order['order_total_ttc'] = number_format(round($order['order_total_ttc'], 2), 2, '.', '');
             $order['order_amount_to_pay_now'] = number_format(round($order['order_amount_to_pay_now'], 2), 2, '.', '');
             /** On enregistre la commande	*/
             update_post_meta($order_id, '_order_postmeta', $order);
             update_post_meta($order_id, '_wpshop_order_customer_id', $order['customer_id']);
             update_post_meta($order_id, '_wpshop_order_shipping_date', $order['order_shipping_date']);
             update_post_meta($order_id, '_wpshop_order_status', $order['order_status']);
             do_action('wps_order_extra_save', $order_id);
             //Add an action to extra actions on order save
             $args = array('order_id' => $order_id, 'posted_data' => $_REQUEST);
             wpshop_tools::create_custom_hook('wps_order_extra_save_action', $args);
             /**	Set custmer information for the order	*/
             $shipping_address = !empty($shipping_address_option) && !empty($shipping_address_option['activate']) ? !empty($_SESSION['shipping_address']) ? wpshop_tools::varSanitizer($_SESSION['shipping_address']) : $customer_shipping_address_id : '';
             $billing_address = !empty($_SESSION['billing_address']) ? wpshop_tools::varSanitizer($_SESSION['billing_address']) : $customer_billing_address_id;
             if (!empty($billing_address)) {
                 wpshop_orders::set_order_customer_addresses($user_id, $order_id, $shipping_address, $billing_address);
             }
             if (!empty($_SESSION['shipping_address_to_save'])) {
                 $order_infos_postmeta = get_post_meta($order_id, '_order_info', true);
                 $order_infos_postmeta['shipping']['address'] = $_SESSION['shipping_address_to_save'];
                 $order_infos_postmeta['shipping']['address_id'] = '';
                 update_post_meta($order_id, '_order_info', $order_infos_postmeta);
                 unset($_SESSION['shipping_address_to_save']);
             }
             /** Save Coupon use **/
             if (!empty($_SESSION['cart']['coupon_id'])) {
                 $wps_coupon_mdl = new wps_coupon_model();
                 $wps_coupon_mdl->save_coupon_use($_SESSION['cart']['coupon_id']);
             }
             /**	Notify the customer as the case	*/
             $user_info = get_userdata($user_id);
             $email = $user_info->user_email;
             $first_name = $user_info->user_firstname;
             $last_name = $user_info->user_lastname;
             // Envoie du message de confirmation de commande au client
             $order_meta = get_post_meta($order_id, '_order_postmeta', true);
             $shipping_mode_option = get_option('wps_shipping_mode');
             $shipping_method = !empty($order_meta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_meta['order_payment']['shipping_method'], $shipping_mode_option['modes']) ? $shipping_mode_option['modes'][$order_meta['order_payment']['shipping_method']]['name'] : (!empty($order_meta['order_payment']['shipping_method']) ? $order_meta['order_payment']['shipping_method'] : '');
             if (!empty($order_meta) && !empty($order_meta['cart_type']) && $order_meta['cart_type'] == 'quotation' && empty($order_meta['order_key'])) {
                 $wps_message->wpshop_prepared_email($email, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE', array('order_id' => $order_id, 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'customer_email' => $email, 'order_date' => current_time('mysql', 0), 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method, 'order_personnal_informations' => ''));
             } else {
                 $email_option = get_option('wpshop_emails');
                 if (empty($email_option['send_confirmation_order_message'])) {
                     $payment_method_option = get_option('wps_payment_mode');
                     $order_payment_method = !empty($payment_method_option) && !empty($payment_method_option['mode']) && !empty($order_meta['order_payment']['customer_choice']['method']) && !empty($payment_method_option['mode'][$order_meta['order_payment']['customer_choice']['method']]) ? $payment_method_option['mode'][$order_meta['order_payment']['customer_choice']['method']]['name'] : $order_meta['order_payment']['customer_choice']['method'];
                     $wps_message->wpshop_prepared_email($email, 'WPSHOP_ORDER_CONFIRMATION_MESSAGE', array('order_id' => $order_id, 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'customer_email' => $email, 'order_key' => !empty($order_meta['order_key']) ? $order_meta['order_key'] : '', 'order_date' => current_time('mysql', 0), 'order_payment_method' => $order_payment_method, 'order_content' => '', 'order_addresses' => '', 'order_customer_comments' => '', 'order_billing_address' => '', 'order_shipping_address' => '', 'order_shipping_method' => $shipping_method, 'order_personnal_informations' => ''));
                 }
             }
             if (empty($_SESSION['wps-pos-addon'])) {
                 $email_option = get_option('wpshop_emails');
                 if (empty($email_option) || !empty($email_option) && empty($email_option['send_confirmation_order_message'])) {
                     self::send_order_email_to_administrator($order_id, $user_info);
                 }
             }
             /** IF Order amount is 0, Finish the Order **/
             if ($cart['order_amount_to_pay_now'] == 0) {
                 $order_meta = get_post_meta($order_id, '_order_postmeta', true);
                 $payment_status = 'completed';
                 $params_array = array('method' => 'free', 'waited_amount' => $order_meta['order_amount_to_pay_now'], 'status' => 'payment_received', 'author' => $order_meta['customer_id'], 'payment_reference' => 'FREE_ORDER', 'date' => current_time('mysql', 0), 'received_amount' => $order_meta['order_amount_to_pay_now']);
                 wpshop_payment::check_order_payment_total_amount($order_id, $params_array, $payment_status);
             }
             apply_filters('wpshop_finish_order_extra_actions', $order_id);
         }
     }
     return $order_id;
 }
Ejemplo n.º 4
0
 /** Ajax action to reload mini cart */
 public static function wps_reload_mini_cart()
 {
     $wps_cart = new wps_cart();
     $result = $wps_cart->mini_cart_content(sanitize_title($_POST['type']));
     $count_items = !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ? $wps_cart->total_cart_items($_SESSION['cart']['order_items']) : 0;
     $free_shipping_alert = wpshop_tools::create_custom_hook('wpshop_free_shipping_cost_alert');
     echo json_encode(array('response' => $result, 'count_items' => $count_items, 'free_shipping_alert' => $free_shipping_alert));
     die;
 }
Ejemplo n.º 5
0
require_once '../../../wp-load.php';
/*	Wordpress - Admin page that define some needed vars and include file	*/
require_once ABSPATH . 'wp-admin/includes/admin.php';
// T�l�chargement produit t�l�chargeable
if (!empty($_GET['download']) && !empty($_GET['oid'])) {
    $variation_id = '';
    if (is_user_logged_in()) {
        $user_id = get_current_user_id();
        $order = get_post_meta($_GET['oid'], '_order_postmeta', true);
        if (!empty($order)) {
            $download_codes = get_user_meta($user_id, '_order_download_codes_' . $_GET['oid'], true);
            if (!empty($download_codes) && is_array($download_codes)) {
                foreach ($download_codes as $downloadable_product_id => $d) {
                    $is_encrypted = false;
                    if ($d['download_code'] == $_GET['download']) {
                        wpshop_tools::create_custom_hook('encrypt_actions_for_downloadable_product', array('order_id' => $_GET['oid'], 'download_product_id' => $downloadable_product_id));
                        if (get_post_type($downloadable_product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
                            $parent_def = wpshop_products::get_parent_variation($downloadable_product_id);
                            if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
                                $parent_post = $parent_def['parent_post'];
                                $variation_id = $downloadable_product_id;
                                $downloadable_product_id = $parent_post->ID;
                            }
                        }
                        $link = wpshop_attributes::get_attribute_option_output(array('item_id' => $downloadable_product_id, 'item_is_downloadable_' => 'yes'), 'is_downloadable_', 'file_url', $order);
                        if ($link !== false) {
                            $uploads = wp_upload_dir();
                            $basedir = $uploads['basedir'];
                            $pos = strpos($link, 'uploads');
                            $link = $basedir . substr($link, $pos + 7);
                            /** If plugin is encrypted **/
Ejemplo n.º 6
0
    } else {
        ?>
	<button class="wps-bton-first-alignRight-rounded" id="wps-cart-order-action"><?php 
        _e('Order', 'wpshop');
        ?>
</button>
	<?php 
    }
    ?>
	<button class="wps-bton-second-alignRight-rounded emptyCart"><?php 
    _e('Empty the cart', 'wpshop');
    ?>
</button>
</div>
<div style="clear : both; text-align : right; padding : 8px 0; margin-top : 8px; font-size : 14px; font-style : italic; font-weight : bold; color : #C7CE06;"><span class="wps-mini-cart-free-shipping-alert"><?php 
    echo wpshop_tools::create_custom_hook('wpshop_free_shipping_cost_alert');
    ?>
</span></div>
<?php 
}
?>

<?php 
if (!empty($cart_type) && $cart_type == 'admin-panel' && (empty($cart_content['order_status']) || $cart_content['order_status'] == 'awaiting_payment')) {
    ?>
<button class="wps-bton-second-rounded alignRight" id="wps-orders-update-cart-informations"><i class="dashicons dashicons-update"></i><?php 
    _e('Update order informations', 'wpshop');
    ?>
</button>
<?php 
}
 /**
  * AJAX - Valid Checkout step four
  */
 function wps_checkout_valid_step_five()
 {
     $status = false;
     $response = '';
     $payment_method = !empty($_POST['wps-payment-method']) ? wpshop_tools::varSanitizer($_POST['wps-payment-method']) : null;
     $order_id = !empty($_SESSION['cart']['order_id']) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0;
     $customer_comment = !empty($_POST['wps-customer-comment']) ? wpshop_tools::varSanitizer($_POST['wps-customer-comment']) : null;
     $terms_of_sale_checking = isset($_POST['terms_of_sale_indicator']) && !empty($_POST['terms_of_sale']) || !empty($_POST['terms_of_sale']) || !isset($_POST['terms_of_sale_indicator']) && empty($_POST['terms_of_sale']) ? true : false;
     if ($terms_of_sale_checking) {
         if (!empty($payment_method)) {
             /** Check if the payment method exist for the shop **/
             $payment_option = get_option('wps_payment_mode');
             if (!empty($payment_option) && !empty($payment_option['mode']) && array_key_exists($payment_method, $payment_option['mode']) && !empty($payment_option['mode'][$payment_method]['active'])) {
                 $order_id = wpshop_checkout::process_checkout($payment_method, $order_id, get_current_user_id(), $_SESSION['billing_address'], $_SESSION['shipping_address']);
                 if (!empty($order_id) && !empty($customer_comment)) {
                     wp_update_post(array('ID' => $order_id, 'post_excerpt' => $customer_comment));
                 }
                 $permalink_option = get_option('permalink_structure');
                 $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'));
                 $response = get_permalink($checkout_page_id) . (!empty($permalink_option) ? '?' : '&') . 'order_step=6';
                 $_SESSION['payment_method'] = $payment_method;
                 $status = true;
                 //Add an action to extra actions on order save
                 $args = array('order_id' => $order_id, 'posted_data' => $_REQUEST);
                 wpshop_tools::create_custom_hook('wps_order_extra_save_action', $args);
             } else {
                 $response = '<div class="wps-alert-error">' . __('This payment method is unavailable', 'wpshop') . '</div>';
             }
         } else {
             $response = '<div class="wps-alert-error">' . __('You must choose a payment method', 'wpshop') . '</div>';
         }
     } else {
         $response = '<div class="wps-alert-error">' . __('You must accept the terms of sale to order', 'wpshop') . '</div>';
     }
     echo json_encode(array('status' => $status, 'response' => $response));
     die;
 }