function handle_payment_data($raw_data, $gateway)
{
    eStore_payment_debug("Handling payment data from: " . $gateway, true);
    if ($gateway == "2co") {
        $mc_currency = $raw_data['list_currency'];
        if (empty($mc_currency)) {
            $mc_currency = $raw_data['currency_code'];
        }
        $uniqueOrderId = $raw_data['item_id_1'];
        if (empty($uniqueOrderId)) {
            //This is a tank you page post (not a background IPN post)
            $uniqueOrderId = $raw_data['cart_order_id'];
        }
        $cart_items = eStore_retrieve_order_details_from_db($uniqueOrderId, $gateway, $mc_currency);
        if (empty($raw_data['message_type'])) {
            //Normal Thank You page post
            $payment_data = extract_2co_general_payment_data_secondary($raw_data, $gateway, $cart_items);
        } else {
            //proper INS post
            $payment_data = extract_2co_general_payment_data($raw_data, $gateway, $cart_items);
        }
        if ($payment_data['txn_type'] == "ORDER_CREATED") {
            eStore_payment_debug("Order Received... verifying payment data.", true);
            eStore_do_post_payment_tasks($payment_data, $cart_items);
        }
        //Log the payment and cart data to the debug file
        foreach ($payment_data as $key => $value) {
            $text .= "{$key}={$value}, ";
        }
        foreach ($cart_items as $key => $value) {
            $text .= "{$key}={$value}, ";
        }
        eStore_payment_debug($text, true, true);
    } else {
        if ($gateway == "authorize") {
            $cart_items = eStore_retrieve_order_details_from_db($raw_data['x_cust_id'], $gateway);
            $payment_data = extract_authorize_general_payment_data($raw_data, $gateway, $cart_items);
            //print_r($cart_items);
            if (!empty($cart_items)) {
                eStore_payment_debug("Order Received... verifying payment data.", true);
                eStore_do_post_payment_tasks($payment_data, $cart_items);
            } else {
                eStore_payment_debug("Cart items empty! Could not retrieve items from the database.", false);
            }
            //Log the payment data to the debug file
            foreach ($payment_data as $key => $value) {
                $text .= "{$key}={$value}, ";
            }
            foreach ($cart_items as $key => $value) {
                $text .= "{$key}={$value}, ";
            }
            eStore_payment_debug($text, true, true);
            //The pending payment data can be deleted at this stage
        }
    }
    //file_put_contents('2co_process.txt', $text);
    reset_eStore_cart();
    $post_payment_return_url = get_option('cart_return_from_paypal_url');
    $post_payment_return_url = eStore_append_http_get_data_to_url($post_payment_return_url, "reset_eStore_cart", "1");
    eStore_redirect_to_url($post_payment_return_url);
}
function eStore_manual_gateway_form_processing_code()
{
    if (isset($_POST['submit_shipping'])) {
        if (eStore_get_total_cart_item_qty() < 1) {
            //Cart does not have any item
            echo '<div class="eStore_error_message">Error! Your shopping cart is empty. Please add items to your cart before checking out.</div>';
            return;
        }
        $input_verified = false;
        global $wpdb;
        $wp_eStore_config = WP_eStore_Config::getInstance();
        $err_msg = eStore_check_address_details();
        if (!empty($err_msg)) {
            $msg = '<div id="error">';
            $msg .= ESTORE_REQUIRED_FIELDS_MISSING;
            $msg .= $err_msg;
            $msg .= '</div>';
            echo $msg;
        } else {
            //Fire the begin processing hook
            $clientip = $_SERVER['REMOTE_ADDR'];
            $clientemail = $_POST['email'];
            do_action('eStore_begin_manual_co_processing', $clientemail, $clientip);
            $last_records_id = $wp_eStore_config->getValue('eStore_custom_receipt_counter');
            //get_option('eStore_custom_receipt_counter');
            if (empty($last_records_id)) {
                $last_records_id = 0;
            }
            $receipt_counter = $last_records_id + 1;
            $wp_eStore_config->setValue('eStore_custom_receipt_counter', $receipt_counter);
            $wp_eStore_config->saveConfig();
            $address = $_POST['address'] . ", " . $_POST['city'] . ", " . $_POST['state'] . " " . $_POST['postcode'] . " " . $_POST['country'];
            $payment_data = extract_manaul_co_general_payment_data($_POST['firstname'], $_POST['lastname'], $_POST['email'], $address, $_POST['phone']);
            $cart_items = extract_manual_item_data();
            $cust_direction = get_option('eStore_manual_co_cust_direction');
            $curr_symbol = get_option('cart_currency_symbol');
            if (!empty($cust_direction)) {
                $cust_direction_mod = eStore_apply_post_payment_dynamic_tags($cust_direction, $payment_data, $cart_items);
                $body .= "\n-------------------------------\n";
                $body .= $cust_direction_mod;
                $body .= "\n-------------------------------\n";
            }
            $count = 1;
            $constructed_download_link .= "<br />";
            $product_key_data = "";
            $show_tax_inc_price = $wp_eStore_config->getValue('eStore_show_tax_inclusive_price');
            foreach ($_SESSION['eStore_cart'] as $item) {
                $products_table_name = $wpdb->prefix . "wp_eStore_tbl";
                $key = $item['item_number'];
                $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$key}'", OBJECT);
                $rounded_price = round($item['price'], 2);
                $body .= "\n" . WP_ESTORE_DETAILS_OF_ORDERED_PRODUCT . ": " . $count;
                $body .= "\n-------------------------";
                $body .= "\n" . ESTORE_PRODUCT_ID . ": " . $item['item_number'];
                $body .= "\n" . ESTORE_PRODUCT_NAME . ": " . $item['name'];
                if ($show_tax_inc_price == '1') {
                    $rounded_price = eStore_get_tax_include_price_by_prod_id($item['item_number'], $rounded_price);
                }
                $formatted_price = print_digi_cart_payment_currency($rounded_price, $curr_symbol);
                $body .= "\n" . ESTORE_PRICE . ": " . $formatted_price;
                $body .= "\n" . ESTORE_QUANTITY . ": " . $item['quantity'] . "\n";
                if (get_option('eStore_manual_co_give_download_links') != '') {
                    $download_link = generate_download_link_for_product($item['item_number'], $item['name'], $payment_data);
                    $constructed_download_link .= $download_link . "<br />";
                    $body .= $download_link . "\n";
                    $product_key = eStore_post_sale_retrieve_serial_key_and_update($retrieved_product, $item['name'], $item['quantity']);
                    $product_key_data .= $product_key;
                    $body .= $product_key;
                    $product_specific_instructions = eStore_get_product_specific_instructions($retrieved_product);
                    $product_specific_instructions = eStore_apply_post_payment_dynamic_tags($product_specific_instructions, $payment_data, $cart_items);
                    $body .= $product_specific_instructions;
                }
                $count++;
                //Check and signup WishList or WP eMember user if needed
                //if(get_option('eStore_manual_co_auto_update_db')=='1')
                if ($wp_eStore_config->getValue('eStore_manual_co_auto_create_membership') == '1') {
                    $member_ref = $retrieved_product->ref_text;
                    eStore_payment_debug('Checking if membership inegration is being used. Reference Text Value: ' . $member_ref, true);
                    if (!empty($member_ref)) {
                        if (get_option('eStore_enable_wishlist_int')) {
                            eStore_payment_debug('WishList integration is being used... doing member account creation/upgrade task... see the "subscription_handle_debug.log" file for details', true);
                            wl_handle_subsc_signup($payment_data, $member_ref, $payment_data['txn_id']);
                        } else {
                            if (function_exists('wp_eMember_install')) {
                                $eMember_id = $payment_data['eMember_userid'];
                                eStore_payment_debug('eMember integration is being used... doing member account creation/upgrade task... see the "subscription_handle_debug.log" file for details', true);
                                eMember_handle_subsc_signup($payment_data, $member_ref, $payment_data['txn_id'], $eMember_id);
                            }
                        }
                    }
                }
                //=== End of membership handling code ===
            }
            $body .= "\n-------------------------------\n";
            if ($show_tax_inc_price != '1') {
                $body .= ESTORE_SUB_TOTAL . ": " . print_digi_cart_payment_currency($_SESSION['eStore_cart_sub_total'], $curr_symbol);
            }
            if (!empty($_SESSION['eStore_cart_postage_cost'])) {
                $body .= "\n" . ESTORE_SHIPPING . ": " . print_digi_cart_payment_currency($_SESSION['eStore_cart_postage_cost'], $curr_symbol);
            }
            if (!empty($_SESSION['eStore_cart_total_tax'])) {
                $body .= "\n" . WP_ESTORE_TAX . ": " . print_digi_cart_payment_currency($_SESSION['eStore_cart_total_tax'], $curr_symbol);
            }
            $total = $_SESSION['eStore_cart_sub_total'] + $_SESSION['eStore_cart_postage_cost'] + $_SESSION['eStore_cart_total_tax'];
            $body .= "\n" . ESTORE_TOTAL . ": " . print_digi_cart_payment_currency($total, $curr_symbol);
            $conversion_rate = get_option('eStore_secondary_currency_conversion_rate');
            if (!empty($conversion_rate)) {
                $secondary_curr_symbol = get_option('eStore_secondary_currency_symbol');
                $body .= "\n" . ESTORE_TOTAL . ' (' . get_option('eStore_secondary_currency_code') . '): ' . print_digi_cart_payment_currency($total * $conversion_rate, $secondary_curr_symbol);
            }
            if (isset($_SESSION['eStore_store_pickup_checked']) && $_SESSION['eStore_store_pickup_checked'] == '1') {
                $body .= "\nStore Pickup: Yes";
            }
            $total_items = $count - 1;
            $body .= "\n" . WP_ESTORE_TOTAL_ITEMS_ORDERED . ": " . $total_items;
            $body .= "\n" . ESTORE_TRANSACTION_ID . ": " . $payment_data['txn_id'];
            $body .= "\n\n" . WP_ESTORE_CUSTOMER_DETAILS;
            $body .= "\n-------------------------";
            $body .= "\n" . WP_ESTORE_NAME . ": " . $_POST['firstname'] . " " . $_POST['lastname'];
            $body .= "\n" . ESTORE_EMAIL . ": " . $_POST['email'];
            $body .= "\n" . ESTORE_PHONE . ": " . $_POST['phone'];
            $body .= "\n" . ESTORE_ADDRESS . ": " . $_POST['address'];
            $body .= "\n" . ESTORE_CITY . ": " . $_POST['city'];
            $body .= "\n" . ESTORE_STATE . ": " . $_POST['state'];
            $body .= "\n" . ESTORE_POSTCODE . ": " . $_POST['postcode'];
            $body .= "\n" . ESTORE_COUNTRY . ": " . $_POST['country'];
            $body .= "\n" . WP_ESTORE_ADDITIONAL_COMMENT . ": " . $_POST['additional_comment'];
            $notify_email = get_option('eStore_manual_notify_email');
            $buyer_email = $_POST['email'];
            if (empty($notify_email)) {
                $notify_email = get_bloginfo('admin_email');
            }
            // Get referrer
            if (!empty($_SESSION['ap_id'])) {
                $referrer = $_SESSION['ap_id'];
            } else {
                if (isset($_COOKIE['ap_id'])) {
                    $referrer = $_COOKIE['ap_id'];
                }
            }
            //Call the filter for email notification body
            eStore_payment_debug('Applying filter - eStore_notification_email_body_filter', true);
            $body = apply_filters('eStore_notification_email_body_filter', $body, $payment_data, $cart_items);
            $seller_email_body = $body . "\n\n" . WP_ESTORE_REFERRER . ": " . $referrer;
            $from_email_address = get_option('eStore_download_email_address');
            $headers = 'From: ' . $from_email_address . "\r\n";
            // Notify Seller
            $n_subject = $wp_eStore_config->getValue('seller_email_subject_manual_co');
            if (empty($n_subject)) {
                $n_subject = get_option('eStore_seller_email_subj');
            }
            wp_mail($notify_email, $n_subject, $seller_email_body, $headers);
            // Notify Buyer
            $buyer_email_subj = $wp_eStore_config->getValue('buyer_email_subject_manual_co');
            if (empty($buyer_email_subj)) {
                $buyer_email_subj = get_option('eStore_buyer_email_subj');
            }
            wp_mail($buyer_email, $buyer_email_subj, $body, $headers);
            if (!empty($product_key_data)) {
                //Lets add any serial key info to the data
                $payment_data['product_key_data'] = $product_key_data;
            }
            //Fire the manual checkout hook
            do_action('eStore_manual_checkout_form_data', $payment_data, $cart_items);
            //Add to the customer database if the option is enabled
            if (get_option('eStore_manual_co_auto_update_db') == '1') {
                record_sales_data($payment_data, $cart_items);
            }
            //Perform autoresponder signup
            if (get_option('eStore_manual_co_do_autoresponder_signup') == '1') {
                eStore_item_specific_autoresponder_signup($cart_items, $_POST['firstname'], $_POST['lastname'], $_POST['email']);
                eStore_global_autoresponder_signup($_POST['firstname'], $_POST['lastname'], $_POST['email']);
            }
            //Award Affiliate Commission
            eStore_award_commission_manual_co($payment_data, $cart_items);
            // Revenue sharing
            eStore_award_author_commission_manual_co($payment_data, $cart_items);
            //Create affiliate account if needed
            eStore_handle_auto_affiliate_account_creation($payment_data);
            //Post IPN data to external site if needed
            eStore_POST_IPN_data_to_url($payment_data, '', $cart_items);
            //Save transaction result for thank you page display
            if (get_option('eStore_manual_co_give_download_links') != '') {
                $constructed_download_link = wp_eStore_replace_url_in_string_with_link($constructed_download_link);
                eStore_save_trans_result_for_thank_you_page_display($payment_data, $constructed_download_link, $cart_items);
            }
            $return_url = get_option('eStore_manual_return_url');
            if (empty($return_url)) {
                $return_url = get_bloginfo('wpurl');
            }
            //Google analytics tracking
            if (get_option('eStore_enable_analytics_tracking') && get_option('eStore_manual_co_give_download_links') != '') {
                eStore_track_ga_ecommerce($payment_data, $cart_items);
                $return_url = eStore_append_http_get_data_to_url($return_url, "eStore_manual_co_track_ga", "1");
            }
            //Reset cart and redirect to Thank you page
            reset_eStore_cart();
            eStore_redirect_to_url($return_url);
        }
    }
}
Exemplo n.º 3
0
function eStore_misc_loader_handlers()
{
    if (isset($_REQUEST['estore_pagination_go'])) {
        //Pagination go request
        $target_page_no = sanitize_text_field($_REQUEST['estore_pagination_page_no']);
        $parameter_name = sanitize_text_field($_REQUEST['estore_pagination_parameter_name']);
        $page_url = esc_url($_REQUEST['estore_pagination_raw_url']);
        $target_page = eStore_append_http_get_data_to_url($page_url, $parameter_name, $target_page_no);
        eStore_redirect_to_url($target_page);
    }
    eStore_download_now_button_request_handler();
}