Пример #1
0
function eStore_send_free_download1($name, $to_email_address, $download, $payment_data = '', $cart_items = '')
{
    if (WP_ESTORE_DO_NOT_SEND_EMAIL_FROM_SQUEEZE_FORM === '1') {
        //Don't send the email for the squeeze form submission
        return true;
    }
    $wp_eStore_config = WP_eStore_Config::getInstance();
    $attachment = '';
    $from_email_address = get_option('eStore_download_email_address');
    $headers = 'From: ' . $from_email_address . "\r\n";
    $email_subj = $wp_eStore_config->getValue('eStore_squeeze_form_email_subject');
    if (empty($email_subj)) {
        $email_subj = ESTORE_FREE_DOWNLOAD_SUBJECT;
    }
    $email_body = $wp_eStore_config->getValue('eStore_squeeze_form_email_body');
    if (empty($email_body)) {
        $email_body = ESTORE_DEAR . ' ' . $name . "\n\n" . ESTORE_FREE_DOWNLOAD_EMAIL_BODY . "\n" . $download . "\n\n" . ESTORE_THANK_YOU;
    } else {
        //Apply the email tag filtering
        $email_body = str_replace("{product_link}", $download, $email_body);
        $email_body = eStore_apply_post_payment_dynamic_tags($email_body, $payment_data, $cart_items);
    }
    if (get_option('eStore_use_wp_mail')) {
        wp_eStore_send_wp_mail($to_email_address, $email_subj, $email_body, $headers);
        return true;
    } else {
        if (@eStore_send_mail($to_email_address, $email_body, $email_subj, $from_email_address, $attachment)) {
            return true;
        } else {
            return false;
        }
    }
}
Пример #2
0
function eStore_send_notification_email($to_address, $subject, $body, $from_address, $attachment = '')
{
    if (get_option('eStore_use_wp_mail')) {
        $headers = 'From: ' . $from_address . "\r\n";
        wp_mail($to_address, $subject, $body, $headers);
        return true;
    } else {
        if (@eStore_send_mail($to_address, $body, $subject, $from_address, $attachment)) {
            return true;
        } else {
            return false;
        }
    }
}
function eStore_generic_autoresponder_signup($firstname, $lastname, $emailaddress, $list_email_address)
{
    eStore_payment_debug('Preparing to send signup request email for generic autoresponder integration.', true);
    //$from_address = $emailaddress;//Use customer email address as the from address for this email
    $from_address = $firstname . " " . $lastname . " <" . $emailaddress . ">";
    $subject = "Autoresponder Automatic Sign up email";
    $body = "\n\nThis is an automatic email that is sent to the autoresponder for user signup purpose\n" . "\nEmail: " . $emailaddress . "\nName: " . $firstname . " " . $lastname;
    if (get_option('eStore_use_wp_mail')) {
        eStore_payment_debug('Sending signup request email via WordPress mailing system. From email address: ' . $from_address, true);
        $headers = 'From: ' . $from_address . "\r\n";
        wp_mail($list_email_address, $subject, $body, $headers);
        eStore_payment_debug('Signup email request successfully sent to:' . $list_email_address, true);
        return 1;
    } else {
        eStore_payment_debug('Sending signup request email via eStore\'s generic mail script.', true);
        $attachment = '';
        if (@eStore_send_mail($list_email_address, $body, $subject, $from_address, $attachment)) {
            eStore_payment_debug('Signup email request successfully sent to:' . $list_email_address, true);
            return 1;
        } else {
            return 0;
        }
    }
}
function process_payment_data(&$payment_data, $cart_items)
{
    global $wpdb, $wp_eStore_config;
    $wp_eStore_config = WP_eStore_Config::getInstance();
    $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
    $script_location = get_option('eStore_download_script');
    $random_key = get_option('eStore_random_code');
    $payment_currency = get_option('cart_payment_currency');
    $customvariables = get_custom_var($payment_data['custom']);
    $product_specific_instructions = "";
    $currency_symbol = get_option('cart_currency_symbol');
    //Fire the begin processing hook
    do_action('eStore_begin_payment_processing', $payment_data['payer_email'], $customvariables['ip']);
    $product_id_array = array();
    $product_name_array = array();
    $product_price_array = array();
    $product_qty_array = array();
    $download_link_array = array();
    $download_link_for_digital_item = array();
    $counter = 0;
    $product_key_data = "";
    foreach ($cart_items as $current_cart_item) {
        $cart_item_data_num = $current_cart_item['item_number'];
        $cart_item_data_name = $current_cart_item['item_name'];
        $cart_item_data_quantity = $current_cart_item['quantity'];
        $cart_item_data_total = $current_cart_item['mc_gross'];
        $cart_item_data_currency = $current_cart_item['mc_currency'];
        eStore_payment_debug('Item Number: ' . $cart_item_data_num, true);
        eStore_payment_debug('Item Name: ' . $cart_item_data_name, true);
        eStore_payment_debug('Item Quantity: ' . $cart_item_data_quantity, true);
        eStore_payment_debug('Item Total: ' . $cart_item_data_total, true);
        eStore_payment_debug('Item Currency: ' . $cart_item_data_currency, true);
        if ($cart_item_data_num != "SHIPPING") {
            // Compare the values with the values stored in the database
            $key = $cart_item_data_num;
            $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$key}'", OBJECT);
            if (!$retrieved_product) {
                eStore_payment_debug('No Item found for the Item ID: ' . $cart_item_data_num, false);
                return false;
            }
            $coupon_code = $customvariables['coupon'];
            if (!empty($coupon_code)) {
                eStore_payment_debug('Coupon Code Used : ' . $coupon_code, true);
                $coupon_table_name = $wpdb->prefix . "wp_eStore_coupon_tbl";
                $ret_coupon = $wpdb->get_row("SELECT * FROM {$coupon_table_name} WHERE coupon_code = '{$coupon_code}'", OBJECT);
                if ($ret_coupon) {
                    $discount_amount = $ret_coupon->discount_value;
                    $discount_type = $ret_coupon->discount_type;
                    if ($discount_type == 0) {
                        //apply % discount
                        $discount = $retrieved_product->price * $discount_amount / 100;
                        $true_product_price = $retrieved_product->price - $discount;
                        eStore_payment_debug('Product Price after applying % discount: ' . $true_product_price, true);
                    } else {
                        // apply value discount
                        $true_product_price = $retrieved_product->price - $discount_amount;
                        eStore_payment_debug('Product Price after applying fixed amount discount: ' . $true_product_price, true);
                    }
                } else {
                    eStore_payment_debug('Could not find the coupon in the database: ' . $coupon_code, false);
                }
            } else {
                if (is_numeric($retrieved_product->a3)) {
                    $true_product_price = 0;
                    //subscription product
                } else {
                    if (is_numeric($retrieved_product->price)) {
                        $true_product_price = $retrieved_product->price * $cart_item_data_quantity;
                    } else {
                        $true_product_price = 0;
                        //most likely a subscription
                    }
                }
            }
            $true_product_price = round($true_product_price, 2);
            if ($cart_item_data_total < $true_product_price) {
                eStore_payment_debug('Wrong Product Price Detected. Actual Product Price : ' . $true_product_price, false);
                eStore_payment_debug('Paid Product Price : ' . $cart_item_data_total, false);
                return false;
            }
            if ($payment_currency != $cart_item_data_currency) {
                eStore_payment_debug('Invalid Product Currency. Expected currency: ' . $payment_currency . ', Received Currency: ' . $cart_item_data_currency, false);
                return false;
            }
            //*** Handle Membership Payment ***
            eStore_payment_debug('Checking if membership inegration is being used.', true);
            $member_ref = $retrieved_product->ref_text;
            if (!empty($member_ref)) {
                if (get_option('eStore_enable_wishlist_int')) {
                    eStore_payment_debug('WishList integration is being used... creating member account... 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 = $customvariables['eMember_id'];
                        eStore_payment_debug('eMember integration is being used... creating member account... 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 payment handling ==
            $item_name = $cart_item_data_name;
            //$retrieved_product->name;
            $download_link = generate_download_link($retrieved_product, $item_name, $payment_data);
            eStore_payment_debug('Download Link: [hidden]', true);
            //$download_link
            $product_specific_instructions .= eStore_get_product_specific_instructions($retrieved_product);
            if ($retrieved_product->create_license == 1) {
                $license_key = eStore_generate_license_key($payment_data);
                $product_license_data .= "\n" . $cart_item_data_name . " License Key: " . $license_key;
                eStore_payment_debug('License Key: [hidden]', true);
                //$license_key
            }
            //Issue serial key if this feature is being used
            $product_key_data .= eStore_post_sale_retrieve_serial_key_and_update($retrieved_product, $cart_item_data_name, $cart_item_data_quantity);
            array_push($product_name_array, $cart_item_data_name);
            array_push($product_id_array, $cart_item_data_num);
            if (empty($cart_item_data_total)) {
                $cart_item_data_total = $retrieved_product->price;
            }
            array_push($product_price_array, $cart_item_data_total);
            array_push($product_qty_array, $cart_item_data_quantity);
            array_push($download_link_array, $download_link);
            if (eStore_check_if_string_contains_url($download_link)) {
                array_push($download_link_for_digital_item, $download_link);
            }
        }
        $counter++;
    }
    if (!empty($product_key_data)) {
        $payment_data['product_key_data'] = $product_key_data;
    }
    // How long the download link remain valid (hours)
    $download_url_life = get_option('eStore_download_url_life');
    // Emails
    $notify_email = get_option('eStore_notify_email_address');
    // Email which will recive notification of sale (sellers email)
    $download_email = get_option('eStore_download_email_address');
    // Email from which the mail wil be sent
    $email_subject = get_option('eStore_buyer_email_subj');
    $email_body = get_option('eStore_buyer_email_body');
    $notify_subject = get_option('eStore_seller_email_subj');
    $notify_body = get_option('eStore_seller_email_body');
    // Send the product
    for ($i = 0; $i < sizeof($product_name_array); $i++) {
        $constructed_products_name .= $product_name_array[$i];
        $constructed_products_name .= ", ";
        $constructed_products_price .= $product_price_array[$i];
        $constructed_products_price .= ", ";
        $constructed_products_id .= $product_id_array[$i];
        $constructed_products_id .= ", ";
        $constructed_products_details .= "\n" . $product_name_array[$i] . " x " . $product_qty_array[$i] . " - " . $currency_symbol . $product_price_array[$i] . " (" . $payment_currency . ")";
        $tax_inc_price = eStore_get_tax_include_price_by_prod_id($product_id_array[$i], $product_price_array[$i]);
        $constructed_products_details_tax_inc .= "\n" . $product_name_array[$i] . " x " . $product_qty_array[$i] . " - " . $currency_symbol . $tax_inc_price . " (" . $payment_currency . ")";
        //Download links list for all items in the cart
        $constructed_download_link .= "\n";
        if (is_array($download_link_array[$i])) {
            $package_downloads = $download_link_array[$i];
            for ($j = 0; $j < sizeof($package_downloads); $j++) {
                $constructed_download_link .= $package_downloads[$j];
                $constructed_download_link .= "\n";
            }
        } else {
            $constructed_download_link .= $download_link_array[$i];
        }
        //Download links for only digital items in the cart
        $constructed_download_link_for_digital_item .= "\n";
        if (is_array($download_link_for_digital_item[$i])) {
            $package_downloads2 = $download_link_for_digital_item[$i];
            for ($j = 0; $j < sizeof($package_downloads2); $j++) {
                $constructed_download_link_for_digital_item .= $package_downloads2[$j];
                $constructed_download_link_for_digital_item .= "\n";
            }
        } else {
            $constructed_download_link_for_digital_item .= $download_link_for_digital_item[$i];
        }
    }
    //Counter for incremental receipt number
    $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;
    eStore_payment_debug('Incremental counter value: ' . $receipt_counter, true);
    $wp_eStore_config->setValue('eStore_custom_receipt_counter', $receipt_counter);
    $wp_eStore_config->saveConfig();
    $purchase_date = date("Y-m-d");
    //$total_purchase_amt = $payment_data['mc_gross'];
    $total_minus_total_tax = number_format($payment_data['mc_gross'] - $payment_data['mc_tax'], 2);
    $txn_id = $payment_data['txn_id'];
    $buyer_shipping_info = $payment_data['address'];
    $buyer_phone = $payment_data['phone'];
    $shipping_option = $customvariables['ship_option'];
    if (empty($shipping_option)) {
        $shipping_option = "Default";
    }
    $product_specific_instructions = eStore_apply_post_payment_dynamic_tags($product_specific_instructions, $payment_data, $cart_items);
    //$tags = array("{first_name}","{last_name}","{payer_email}","{product_name}","{product_link}","{product_price}","{product_id}","{download_life}","{product_specific_instructions}","{product_details}","{shipping_info}","{license_data}","{purchase_date}","{purchase_amt}","{transaction_id}","{shipping_option_selected}","{product_link_digital_items_only}","{total_tax}","{total_shipping}","{total_minus_total_tax}","{customer_phone}","{counter}","{coupon_code}","{serial_key}");
    //$vals = array($payment_data['first_name'],$payment_data['last_name'],$payment_data['payer_email'],$constructed_products_name,$constructed_download_link,$constructed_products_price,$constructed_products_id,$download_url_life,$product_specific_instructions,$constructed_products_details,$buyer_shipping_info,$product_license_data,$purchase_date,$payment_data['mc_gross'],$txn_id,$shipping_option,$constructed_download_link_for_digital_item,$payment_data['mc_tax'],$payment_data['mc_shipping'],$total_minus_total_tax,$buyer_phone,$receipt_counter,$coupon_code,$product_key_data);
    $additional_data = array();
    $additional_data['constructed_products_name'] = $constructed_products_name;
    $additional_data['constructed_products_price'] = $constructed_products_price;
    $additional_data['constructed_products_id'] = $constructed_products_id;
    $additional_data['constructed_products_details'] = $constructed_products_details;
    $additional_data['constructed_products_details_tax_inc'] = $constructed_products_details_tax_inc;
    $additional_data['product_specific_instructions'] = $product_specific_instructions;
    $additional_data['constructed_download_link'] = $constructed_download_link;
    $additional_data['constructed_download_link_for_digital_item'] = $constructed_download_link_for_digital_item;
    $additional_data['product_license_data'] = $product_license_data;
    //this is the license mgr key (not the normal serial key code)
    $subject = eStore_apply_post_payment_dynamic_tags($email_subject, $payment_data, $cart_items, $additional_data);
    //str_replace($tags,$vals,$email_subject);
    $body = eStore_apply_post_payment_dynamic_tags($email_body, $payment_data, $cart_items, $additional_data);
    //str_replace($tags,$vals,$email_body);
    $headers = 'From: ' . $download_email . "\r\n";
    $attachment = '';
    //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);
    eStore_payment_debug('Sending product email to : ' . $payment_data["payer_email"], true);
    if (get_option('eStore_use_wp_mail')) {
        wp_eStore_send_wp_mail($payment_data['payer_email'], $subject, $body, $headers);
        //wp_mail($payment_data['payer_email'], $subject, $body, $headers);
        eStore_payment_debug('Product Email successfully sent to ' . $payment_data['payer_email'] . '.', true);
    } else {
        if (@eStore_send_mail($payment_data['payer_email'], $body, $subject, $download_email, $attachment)) {
            eStore_payment_debug('Product Email successfully sent (using PHP mail) to ' . $payment_data['payer_email'] . '.', true);
        } else {
            eStore_payment_debug('Error sending product Email (using PHP mail) to ' . $payment_data['payer_email'] . '.', false);
        }
    }
    // Notify seller
    foreach ($payment_data as $key => $value) {
        $post_string .= "{$key}={$value}, ";
    }
    $n_subject = eStore_apply_post_payment_dynamic_tags($notify_subject, $payment_data, $cart_items, $additional_data);
    //str_replace($tags,$vals,$notify_subject);
    $n_body = eStore_apply_post_payment_dynamic_tags($notify_body, $payment_data, $cart_items, $additional_data);
    //str_replace($tags,$vals,$notify_body);
    if ($wp_eStore_config->getValue('eStore_add_payment_parameters_to_admin_email') == '1') {
        $n_body .= "\n\n------- User Email ----------\n" . $body . "\n\n------- Paypal Parameters (Only admin will receive this) -----\n" . $post_string;
    }
    $n_body = stripslashes($n_body);
    $notify_emails_array = explode(",", $notify_email);
    foreach ($notify_emails_array as $notify_email_address) {
        if (!empty($notify_email_address)) {
            $recipient_email_address = trim($notify_email_address);
            if (get_option('eStore_use_wp_mail')) {
                wp_eStore_send_wp_mail($recipient_email_address, $n_subject, $n_body, $headers);
                //wp_mail($recipient_email_address, $n_subject, $n_body, $headers);
                eStore_payment_debug('Notify Email successfully sent to ' . $recipient_email_address . '.', true);
            } else {
                if (@eStore_send_mail($recipient_email_address, $n_body, $n_subject, $download_email)) {
                    eStore_payment_debug('Notify Email successfully sent (using PHP mail) to ' . $recipient_email_address . '.', true);
                } else {
                    eStore_payment_debug('Error sending notify Email (using PHP mail) to ' . $recipient_email_address . '.', false);
                }
            }
        }
    }
    //Record details for the Thank You page display
    eStore_payment_debug('Creating transaction result display value', true);
    //Save transaction result for thank you page display
    $constructed_download_link = nl2br($constructed_download_link);
    $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);
    global $wp_eStore_transaction_result_display_content;
    $wp_eStore_transaction_result_display_content = $_SESSION['eStore_tx_result'];
    eStore_payment_debug('Transaction result display value set', true);
    return true;
}
function wp_estore_admin_menu()
{
    echo '<div class="wrap">';
    echo '<h2>Admin Functions</h2>';
    echo '<div id="poststuff"><div id="post-body">';
    echo eStore_admin_css();
    global $wpdb;
    echo '<div class="eStore_yellow_box">These helpful admin functions allow you to do various manual admin stuff from time to time like generating an encrypted download link for any product, sending email to any customer etc.</div>';
    $message = "";
    $eStore_product_id = "";
    $wp_eStore_variation_name = "";
    $eStore_download_link = "";
    if (isset($_POST['generate_download_link'])) {
        $eStore_product_id = trim($_POST["wp_eStore_product_id"]);
        $wp_eStore_variation_name = stripslashes($_POST["wp_eStore_variation_name"]);
        $products_table_name = $wpdb->prefix . "wp_eStore_tbl";
        $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$eStore_product_id}'", OBJECT);
        if (!empty($wp_eStore_variation_name)) {
            $item_name = $retrieved_product->name . " (" . $wp_eStore_variation_name . ")";
        } else {
            $item_name = $retrieved_product->name;
        }
        $eStore_download_link = generate_download_link($retrieved_product, $item_name);
        if (empty($eStore_download_link)) {
            $eStore_download_link = "Download link generation failed! Make sure the digital product variation name is correct if this product uses digital product variation.";
        }
        $message .= 'Download Link Generated!';
    }
    if (isset($_POST['send_email'])) {
        update_option('eStore_from_email', stripslashes($_POST["wp_eStore_from_email"]));
        update_option('eStore_to_email', stripslashes($_POST["wp_eStore_to_email"]));
        update_option('eStore_email_subject', stripslashes($_POST["wp_eStore_email_subject"]));
        update_option('eStore_admin_email_body', stripslashes($_POST["wp_eStore_email_body"]));
        $attachment = '';
        if (get_option('eStore_use_wp_mail')) {
            $from = get_option('eStore_from_email');
            $headers = 'From: ' . $from . "\r\n";
            wp_mail(get_option('eStore_to_email'), get_option('eStore_email_subject'), get_option('eStore_admin_email_body'), $headers);
            $message .= "Email sent successfully!";
        } else {
            if (@eStore_send_mail(get_option('eStore_to_email'), get_option('eStore_admin_email_body'), get_option('eStore_email_subject'), get_option('eStore_from_email'), $attachment)) {
                $message .= "Email sent successfully!";
            } else {
                $message .= "Email Sending failed!";
            }
        }
    }
    if (isset($_POST['bulk_delete'])) {
        $interval_val = $_POST['bulk_delete_hours'];
        $interval_unit = 'HOUR';
        //MINUTE
        $cur_time = current_time('mysql');
        $download_links_table_name = $wpdb->prefix . "wp_eStore_download_links_tbl";
        $cond = " DATE_SUB('{$cur_time}',INTERVAL '{$interval_val}' {$interval_unit}) > creation_time";
        $result = $wpdb->query("DELETE FROM {$download_links_table_name} WHERE {$cond}", OBJECT);
        if ($result) {
            $message .= "The download links have been deleted! The current timestamp value used was: " . $cur_time;
        } else {
            $message .= "Nothing to delete!";
        }
    }
    if (isset($_POST['reset_settings_to_default'])) {
        wp_eStore_reset_settings_to_default();
        $message .= "Settings options have been reset to default!";
    }
    if (isset($_POST['reset_sales_data'])) {
        wp_eStore_reset_sales_data();
        $message .= "Sales data have been reset!";
    }
    if (isset($_POST['reset_product_sales_counter_data'])) {
        wp_eStore_reset_product_sales_counter();
        $message .= "All product sales counter have been reset to 0!";
    }
    if (isset($_POST['refresh_prod_cat_relations_tbl'])) {
        wp_eStore_refresh_product_category_relation_tbl();
        $message .= "The products and category relations table has been resynced.";
    }
    if (isset($_POST['remove_all_db_tables'])) {
        wp_eStore_remove_all_db_tables();
        $message .= "All Database tables have been removed! Remember, eStore will not work unless you deactivate and reactivate it again!";
    }
    //Display message to the user
    if (!empty($message)) {
        echo '<div id="message" class="updated fade"><p><strong>';
        echo $message;
        echo '</strong></p></div>';
    }
    ?>
	<div class="postbox">
	<h3><label for="title">Generate an Encrypted download link for a Product</label></h3>
	<div class="inside">

    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
    <input type="hidden" name="generate_download_link" id="generate_download_link" value="true" />
    
    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
    <tr valign="top"><td align="left">
    Product ID: 
    </td><td align="left">
    <input name="wp_eStore_product_id" type="text" size="10" value="<?php 
    echo $eStore_product_id;
    ?>
" />
    <br /><i>(i) Enter the product id of the product that you want to generate an encrypted download link for.</i>
    </td></tr>

    <tr valign="top"><td align="left">
    Digital Product Variation Name: 
    </td><td align="left">
    <input name="wp_eStore_variation_name" type="text" size="30" value="<?php 
    echo $wp_eStore_variation_name;
    ?>
" />
    <br /><i>(ii) Enter the digital product variation name if you are using it. Leave empty if this product does not use the digital product variation field.</i>
    </td></tr>
    
    <tr valign="top"><td align="left">
    </td><td align="left">
    <input type="submit" name="generate_download_link" value="Generate Link &raquo;" />
    <br /><i>(iii) Hit the "Generate Link" button.</i><br /><br />
    </td></tr>
    
    <tr valign="top"><td align="left">
    Download Link: 
    </td><td align="left">
    <textarea name="wp_eStore_download_link" rows="6" cols="70"><?php 
    echo $eStore_download_link;
    ?>
</textarea>
    <br /><i>The encrypted download link for a product will be shown in the above area when you hit the Generate Link button.</i><br />
    </td></tr>
    </table>
    </form>
	</div></div>
	
	<div class="postbox">
	<h3><label for="title">Send Email to Customers</label></h3>
	<div class="inside">
	
	<div class="eStore_yellow_box">You can use this section to send a quick email to your customer. 
	If you want to send a download link for a product then first generate the link from the above section then copy and paste 
	the encrypted link in the body section below.
	</div>
	
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
    <input type="hidden" name="send_email" id="send_email" value="true" />

    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
    <tr valign="top"><td align="left">
    From Email Address:
    </td><td align="left">
    <input name="wp_eStore_from_email" type="text" size="50" value="<?php 
    echo get_option('eStore_from_email');
    ?>
" />
    <br /><i>This email address will appear in the from field of the email.</i>
    </td></tr>

    <tr valign="top"><td align="left">
    To Email Address:
    </td><td align="left">
    <input name="wp_eStore_to_email" type="text" size="50" value="<?php 
    echo get_option('eStore_to_email');
    ?>
" />
    <br /><i>This is the email address where the email will be sent to.</i>
    </td></tr>

    <tr valign="top"><td align="left">
    Email Subject: 
    </td><td align="left">
    <input name="wp_eStore_email_subject" type="text" size="50" value="<?php 
    echo get_option('eStore_email_subject');
    ?>
" />
    <br /><i>This is the email subject.</i>
    </td></tr>

    <tr valign="top"><td align="left">
    Email Body: 
    </td><td align="left">
    <textarea name="wp_eStore_email_body" rows="10" cols="70"><?php 
    echo get_option('eStore_admin_email_body');
    ?>
</textarea>
    <br /><i>Type your email and hit Send Email button below.</i><br /><br />
    <input type="submit" name="send_email" value="<?php 
    _e('Send Email');
    ?>
 &raquo;" />
    </td></tr>

	</table>
	</form>
	</div></div>
	
    <div class="postbox">
    <h3><label for="title">Clean The Encrypted Download Links Table</label></h3>
    <div class="inside">
    <br />
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
	 Delete All Links Older Than
    <input name="bulk_delete_hours" type="text" size="3" value=""/> Hours
    <div class="submit">
        <input type="submit" name="bulk_delete" value="Bulk Delete &raquo;" />
    </div>
    </form>
    </div></div>

    <div class="postbox">
    <h3><label for="title">The Almighty Reset Buttons</label></h3>
    <div class="inside">
    
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
" onSubmit="return confirm('Are you sure you want to reset all the settings options to default?');" >    
    <div class="submit">
        <input type="submit" name="reset_settings_to_default" value="Reset eStore Settings to Default" />
    </div>    
    </form> 
       
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
" onSubmit="return confirm('Are you sure you want to reset all sales related data? Useful if you are trying to reset all the test transactions before going live.');" >    
    <div class="submit">
        <input type="submit" name="reset_sales_data" value="Reset All Sales Data" />
    </div>    
    </form> 

    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
" onSubmit="return confirm('Are you sure you want to reset all product sales counter to 0?');" >    
    <div class="submit">
        <input type="submit" name="reset_product_sales_counter_data" value="Reset Product Sales Counter" />
    </div>    
    </form> 
    
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
" onSubmit="return confirm('Are you sure you want to run this operation?');" >    
    <div class="submit">
        <input type="submit" name="refresh_prod_cat_relations_tbl" value="Resync Products and Category Relations Table" />
    </div>    
    </form> 
        
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
" onSubmit="return confirm('Are you sure you want to remove all eStore database tables? Useful if you are trying to do a clean reinstall of the plugin.');" >    
    <div class="submit">
        <input type="submit" name="remove_all_db_tables" value="Remove All eStore Database Tables" />
    </div>    
    </form> 
               
    </div></div>

    <div class="postbox">
    <h3><label for="title">Site Diagnostics</label></h3>
    <div class="inside">
	<strong>WP eStore Version: </strong><code><?php 
    echo WP_ESTORE_VERSION;
    ?>
</code><br />
	<strong>WP Version: </strong><code><?php 
    echo get_bloginfo("version");
    ?>
</code><br />
	<strong>WPMU: </strong><code><?php 
    echo !defined('MULTISITE') || !MULTISITE ? "No" : "Yes";
    ?>
</code><br />
	<strong>MySQL Version: </strong><code><?php 
    echo $wpdb->db_version();
    ?>
</code><br />
	<strong>WP Table Prefix: </strong><code><?php 
    echo $wpdb->prefix;
    ?>
</code><br />
	<strong>PHP Version: </strong><code><?php 
    echo phpversion();
    ?>
</code><br />
	<strong>Session Save Path: </strong><code><?php 
    echo ini_get("session.save_path");
    ?>
</code><br />
	<strong>WP URL: </strong><code><?php 
    echo get_bloginfo('wpurl');
    ?>
</code><br />
	<strong>Server Name: </strong><code><?php 
    echo $_SERVER['SERVER_NAME'];
    ?>
</code><br />
	<strong>Cookie Domain: </strong><code><?php 
    $cookieDomain = parse_url(strtolower(get_bloginfo('wpurl')));
    echo $cookieDomain['host'];
    ?>
</code><br />
	<strong>CURL Library Present: </strong><code><?php 
    echo function_exists('curl_init') ? "Yes" : "No";
    ?>
</code><br />
	<strong>Debug File Write Permissions: </strong><code><?php 
    echo is_writable(WP_ESTORE_PATH) ? "Writable" : "Not Writable";
    ?>
</code><br />		
    </div></div>
    <?php 
    echo '</div></div>';
    echo '</div>';
}
function eMember_handle_subsc_signup($ipn_data, $subsc_ref, $unique_ref, $eMember_id = '')
{
    global $wpdb, $emember_config;
    $emember_config = Emember_Config::getInstance();
    $members_table_name = $wpdb->prefix . "wp_eMember_members_tbl";
    $membership_level_table = $wpdb->prefix . "wp_eMember_membership_tbl";
    $email = $ipn_data['payer_email'];
    if (empty($eMember_id)) {
        //TODO - query db using subscr_id if the txn_type is recurring payment
        debug_log_subsc("eMember ID is empty. Checking the database for existing record of this email address..", true);
        $query_db = $wpdb->get_row("SELECT * FROM {$members_table_name} WHERE email = '{$email}'", OBJECT);
        if ($query_db) {
            $eMember_id = $query_db->member_id;
            debug_log_subsc("Found record in the members table. The account will be upgraded. Member ID: " . $eMember_id, true);
        } else {
            debug_log_subsc("Did not find record in the members table. A new member account will be created for: " . $email, true);
        }
    }
    debug_log_subsc("eMember user payment debug data: Unique ID: " . $unique_ref . "| Email: " . $email . "| Level: " . $subsc_ref, true);
    if (!empty($eMember_id)) {
        // upgrade the member account or assign new membership levels to his/her profile
        debug_log_subsc("Upgrading member account", true);
        $account_state = 'active';
        $membership_level = $subsc_ref;
        $subscription_starts = date("Y-m-d");
        $subscr_id = $unique_ref;
        $resultset = "";
        $resultset = $wpdb->get_row("SELECT * FROM {$members_table_name} where member_id='{$eMember_id}'", OBJECT);
        if (!$resultset) {
            debug_log_subsc("Error! Could not find a member account for the given eMember ID: " . $eMember_id, false);
            return;
        }
        $old_membership_level = $resultset->membership_level;
        if ($emember_config->getValue('eMember_enable_secondary_membership')) {
            debug_log_subsc("Using secondary membership level feature... adding additional levels to the existing profile of member ID:" . $eMember_id, true);
            debug_log_subsc("Quering the table :" . $members_table_name . ", to retrieve member profile of eMember ID: " . $eMember_id, true);
            debug_log_subsc("Retrieved member profile. Need to add membership level ID: " . $membership_level . ", to this profile", true);
            $additional_levels = $resultset->more_membership_levels;
            debug_log_subsc("Current additional levels for this profile: " . $additional_levels, true);
            if (is_null($additional_levels)) {
                $additional_levels = $resultset->membership_level;
                //assign the current primary level to the additional level
                debug_log_subsc("Current additional levels for this profile is null. Adding level: " . $additional_levels, true);
            } else {
                if (empty($additional_levels)) {
                    $additional_levels = $resultset->membership_level;
                    //assign the current primary level to the additional level
                    debug_log_subsc("Current additional levels for this profile is empty. Adding level: " . $additional_levels, true);
                } else {
                    $additional_levels = $additional_levels . "," . $resultset->membership_level;
                    //add the current primary level to the list of additional levels
                    $sec_levels = explode(',', $additional_levels);
                    $additional_levels = implode(',', array_unique($sec_levels));
                    //make sure there is no duplicate entry
                    debug_log_subsc("New additional level set: " . $additional_levels, true);
                }
            }
            $membership_level = apply_filters('emember_secondary_before_updating_primary_level', $membership_level, $subsc_ref, $eMember_id);
            $additional_levels = apply_filters('emember_secondary_before_updating_additional_level', $additional_levels, $subsc_ref, $eMember_id);
            debug_log_subsc("Updating additional levels column for username: "******" with value: " . $additional_levels, true);
            $updatedb = "UPDATE {$members_table_name} SET more_membership_levels='{$additional_levels}' WHERE member_id='{$eMember_id}'";
            $results = $wpdb->query($updatedb);
            debug_log_subsc("Upgrading the primary membership level to the recently paid level. New primary membership level ID for this member is: " . $membership_level, true);
            $updatedb = "UPDATE {$members_table_name} SET account_state='{$account_state}',membership_level='{$membership_level}',subscription_starts='{$subscription_starts}',subscr_id='{$subscr_id}' WHERE member_id='{$eMember_id}'";
            $results = $wpdb->query($updatedb);
            do_action('emember_membership_changed', array('member_id' => $eMember_id, 'from_level' => $old_membership_level, 'to_level' => $membership_level));
        } else {
            debug_log_subsc("Not using secondary membership level feature... upgrading the current membership level of member ID: " . $eMember_id, true);
            if (function_exists('emember_get_expiry_by_member_id')) {
                $current_expiry_date = emember_get_expiry_by_member_id($eMember_id);
                if ($current_expiry_date != "noexpire") {
                    if (strtotime($current_expiry_date) > strtotime($subscription_starts)) {
                        //Expiry time is in the future
                        $subscription_starts = $current_expiry_date;
                        //Start at the end of the previous expiry date to make sure he doesn't loose the remaning days from the current level
                        debug_log_subsc("Updating the subscription start date to the current expiry date value: " . $subscription_starts, true);
                    }
                }
            }
            debug_log_subsc("Executing DB update. Debug data: " . $account_state . "|" . $membership_level . "|" . $subscription_starts, true);
            $updatedb = "UPDATE {$members_table_name} SET account_state='{$account_state}',membership_level='{$membership_level}',subscription_starts='{$subscription_starts}',subscr_id='{$subscr_id}' WHERE member_id='{$eMember_id}'";
            $results = $wpdb->query($updatedb);
            do_action('emember_membership_changed', array('member_id' => $eMember_id, 'from_level' => $old_membership_level, 'to_level' => $membership_level));
        }
        //If using the WP user integration then update the role on WordPress too
        if ($emember_config->getValue('eMember_create_wp_user')) {
            debug_log_subsc("Updating WordPress user role...", true);
            $resultset = $wpdb->get_row("SELECT * FROM {$members_table_name} where member_id='{$eMember_id}'", OBJECT);
            $membership_level = $resultset->membership_level;
            $username = $resultset->user_name;
            $membership_level_resultset = $wpdb->get_row("SELECT * FROM {$membership_level_table} where id='{$membership_level}'", OBJECT);
            $user_info = get_user_by('login', $username);
            $role_name = $membership_level_resultset->role;
            debug_log_subsc("The member username :"******" ,WP User ID is: " . $user_info->ID . " , Target role name: " . $role_name, true);
            if (!empty($role_name)) {
                update_wp_user_Role($user_info->ID, $role_name);
                debug_log_subsc("Current WP users role updated to: " . $membership_level_resultset->role, true);
            } else {
                debug_log_subsc("You have a configuration error. Could not retrieve role name from the membership level. Level ID: " . $membership_level, false);
            }
        }
        // Set "notify email address" to the member's email address
        $resultset = $wpdb->get_row("SELECT * FROM {$members_table_name} where member_id='{$eMember_id}'", OBJECT);
        $email = $resultset->email;
        //$email = $ipn_data['payer_email'];
        debug_log_subsc("Setting the TO EMAIL address for membership upgrade notification to: " . $email, true);
        $subject = $emember_config->getValue('eMember_account_upgrade_email_subject');
        if (empty($subject)) {
            $subject = WP_ESTORE_EMEMBER_ACCOUNT_UPGRADE_SUBJECT;
        }
        $body = $emember_config->getValue('eMember_account_upgrade_email_body');
        if (empty($body)) {
            $body = WP_ESTORE_EMEMBER_ACCOUNT_UPGRADE_BODY;
        }
        $from_address = get_option('senders_email_address');
        //$email_body = $body;
        $login_link = $emember_config->getValue('login_page_url');
        $tags1 = array("{first_name}", "{last_name}", "{user_name}", "{login_link}");
        $vals1 = array($resultset->first_name, $resultset->last_name, $resultset->user_name, $login_link);
        $email_body = str_replace($tags1, $vals1, $body);
        $headers = 'From: ' . $from_address . "\r\n";
    } else {
        // create fresh new member account
        debug_log_subsc("Creating new member account", true);
        $user_name = '';
        $password = '';
        $first_name = $ipn_data['first_name'];
        $last_name = $ipn_data['last_name'];
        $email = $ipn_data['payer_email'];
        $membership_level = $subsc_ref;
        $subscr_id = $unique_ref;
        $address_street = $ipn_data['address_street'];
        $address_city = $ipn_data['address_city'];
        $address_state = $ipn_data['address_state'];
        $address_zipcode = $ipn_data['address_zip'];
        $country = $ipn_data['address_country'];
        $gender = 'not specified';
        $date = date("Y-m-d");
        $account_state = 'active';
        $reg_code = uniqid();
        //rand(10, 1000);
        $md5_code = md5($reg_code);
        $updatedb = "INSERT INTO {$members_table_name} (user_name,first_name,last_name,password,member_since,membership_level,account_state,last_accessed,last_accessed_from_ip,email,address_street,address_city,address_state,address_zipcode,country,gender,referrer,extra_info,reg_code,subscription_starts,txn_id,subscr_id) VALUES ('{$user_name}','{$first_name}','{$last_name}','{$password}', '{$date}','{$membership_level}','{$account_state}','{$date}','IP','{$email}','{$address_street}','{$address_city}','{$address_state}','{$address_zipcode}','{$country}','{$gender}','','','{$reg_code}','{$date}','','{$subscr_id}')";
        $results = $wpdb->query($updatedb);
        $results = $wpdb->get_row("SELECT * FROM {$members_table_name} where subscr_id='{$subscr_id}' and reg_code='{$reg_code}'", OBJECT);
        $id = $results->member_id;
        $separator = '?';
        $url = $emember_config->getValue('eMember_registration_page');
        if (empty($url)) {
            $url = get_option('eMember_registration_page');
        }
        if (strpos($url, '?') !== false) {
            $separator = '&';
        }
        $reg_url = $url . $separator . 'member_id=' . $id . '&code=' . $md5_code;
        debug_log_subsc("Member signup URL :" . $reg_url, true);
        //Save the registration signup URL value
        eStore_save_membership_signup_rego_url($email, $reg_url, $ipn_data);
        $subject = get_option('eMember_email_subject');
        $body = get_option('eMember_email_body');
        $from_address = get_option('senders_email_address');
        $tags = array("{first_name}", "{last_name}", "{reg_link}");
        $vals = array($first_name, $last_name, $reg_url);
        $email_body = str_replace($tags, $vals, $body);
        $headers = 'From: ' . $from_address . "\r\n";
    }
    if (get_option('eStore_use_wp_mail')) {
        wp_mail($email, $subject, $email_body, $headers);
        debug_log_subsc("Member signup/upgrade completion email successfully sent to:" . $email . " From email address value used:" . $from_address, true);
    } else {
        $attachment = '';
        if (@eStore_send_mail($email, $email_body, $subject, $from_address, $attachment)) {
            debug_log_subsc("Member signup/upgrade completion email successfully sent (using PHP mail) to:" . $email . " From email address value used:" . $from_address, true);
        } else {
            debug_log_subsc("Member signup/upgrade completion email sending failed (using PHP mail) ", false);
        }
    }
}
Пример #7
0
 function validate_and_dispatch_product()
 {
     // Check Product Name , Price , Currency , Receivers email ,
     global $error_msg;
     global $wpdb;
     $wp_eStore_config = WP_eStore_Config::getInstance();
     $clientdate = date("Y-m-d");
     $clienttime = date("H:i:s");
     $product_specific_instructions = "";
     $currency_symbol = get_option('cart_currency_symbol');
     //Post/Forward IPN data to external URL if needed
     eStore_POST_IPN_data_to_url($this->ipn_data);
     // Read the IPN and validate
     if (get_option('eStore_strict_email_check') != '') {
         $seller_paypal_email = get_option('cart_paypal_email');
         if ($seller_paypal_email != $this->ipn_data['receiver_email']) {
             $error_msg .= 'Invalid Seller Paypal Email Address : ' . $this->ipn_data['receiver_email'];
             $this->debug_log($error_msg, false);
             return false;
         } else {
             $this->debug_log('Seller Paypal Email Address is Valid: ' . $this->ipn_data['receiver_email'], true);
         }
     }
     $payment_status = $this->ipn_data['payment_status'];
     if (!empty($payment_status)) {
         if ($payment_status == "Denied") {
             $error_msg .= 'Payment status for this transaction is DENIED. You denied the transaction... most likely a cancellation of an eCheque.';
             $this->debug_log("You denied the transaction. Most likely a cancellation of an eCheque. Nothing to do here.", false);
             return false;
         }
         if ($payment_status == "Canceled_Reversal") {
             $this->debug_log("This is a dispute closed notification in your favour. The plugin will not do anyting.", false);
             return true;
         }
         if ($payment_status != "Completed" && $payment_status != "Processed" && $payment_status != "Refunded" && $payment_status != "Reversed") {
             $error_msg .= 'Funds have not been cleared yet. Product(s) will be delivered when the funds clear!';
             $this->debug_log($error_msg, false);
             $to_address = $this->ipn_data['payer_email'];
             $subject = ESTORE_PENDING_PAYMENT_EMAIL_SUBJECT;
             $body = ESTORE_PENDING_PAYMENT_EMAIL_BODY;
             $from_address = get_option('eStore_download_email_address');
             eStore_send_notification_email($to_address, $subject, $body, $from_address);
             return false;
         }
     }
     $transaction_type = $this->ipn_data['txn_type'];
     if ($transaction_type == "new_case") {
         $this->debug_log('This is a dispute case', true);
         return true;
     }
     $transaction_id = $this->ipn_data['txn_id'];
     $transaction_subject = $this->ipn_data['transaction_subject'];
     $custom = $this->ipn_data['custom'];
     $delimiter = "&";
     $customvariables = array();
     $namevaluecombos = explode($delimiter, $custom);
     foreach ($namevaluecombos as $keyval_unparsed) {
         $equalsignposition = strpos($keyval_unparsed, '=');
         if ($equalsignposition === false) {
             $customvariables[$keyval_unparsed] = '';
             continue;
         }
         $key = substr($keyval_unparsed, 0, $equalsignposition);
         $value = substr($keyval_unparsed, $equalsignposition + 1);
         $customvariables[$key] = $value;
     }
     $eMember_id = $customvariables['eMember_id'];
     $pictureID = $customvariables['ngg_pid'];
     //Check for refund payment
     $gross_total = $this->ipn_data['mc_gross'];
     if ($gross_total < 0) {
         // This is a refund or reversal so handle the refund
         eStore_handle_refund($this->ipn_data);
         $this->debug_log('This is a refund/reversal. Refund amount: ' . $gross_total, true);
         return true;
     }
     //Check for duplicate notification due to server setup issue
     if (eStore_is_txn_already_processed($this->ipn_data)) {
         $error_msg .= 'The transaction ID and the email address already exists in the database. So this seems to be a duplicate transaction notification. This usually happens with bad server setup.';
         $this->debug_log('The transaction ID and the email address already exists in the database. So this seems to be a duplicate transaction notification. This usually happens with bad server setup.', false);
         return true;
         //No need to be alarmed
     }
     //=== End of duplicate notification check ===
     //Fire the begin processing hook
     do_action('eStore_begin_payment_processing', $this->ipn_data['payer_email'], $customvariables['ip']);
     $time = time();
     global $wpdb;
     $products_table_name = $wpdb->prefix . "wp_eStore_tbl";
     $customer_table_name = $wpdb->prefix . "wp_eStore_customer_tbl";
     $sales_table_name = $wpdb->prefix . "wp_eStore_sales_tbl";
     if ($transaction_type == "cart") {
         $this->debug_log('Transaction Type: Shopping Cart', true);
         // Cart Items
         $num_cart_items = $this->ipn_data['num_cart_items'];
         $this->debug_log('Number of Cart Items: ' . $num_cart_items, true);
         $i = 1;
         $cart_items = array();
         while ($i < $num_cart_items + 1) {
             $item_number = $this->ipn_data['item_number' . $i];
             $item_name = $this->ipn_data['item_name' . $i];
             //$item_name = mb_convert_encoding($item_name, "UTF-8");
             $quantity = $this->ipn_data['quantity' . $i];
             $mc_gross = $this->ipn_data['mc_gross_' . $i];
             $mc_shipping = $this->ipn_data['mc_shipping' . $i];
             $mc_currency = $this->ipn_data['mc_currency'];
             $current_item = array('item_number' => $item_number, 'item_name' => $item_name, 'quantity' => $quantity, 'mc_gross' => $mc_gross, 'mc_shipping' => $mc_shipping, 'mc_currency' => $mc_currency);
             array_push($cart_items, $current_item);
             $i++;
         }
     } else {
         if ($transaction_type == "subscr_signup") {
             $this->debug_log('Subscription signup IPN received... (handled by the subscription IPN handler). Check the "subscription_handle_debug.log" file more details.', true);
             if (eStore_chk_and_record_cust_data_for_free_trial_signup($this->ipn_data)) {
                 //Check and record customer data for free trial
                 return true;
             }
             $subsc_prod_id = $this->ipn_data['item_number'];
             $ret_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$subsc_prod_id}'", OBJECT);
             if (!$ret_product) {
                 $error_msg .= 'Request received for subscription product ID: ' . $subsc_prod_id . '. Could not find this Product ID in the product database (please check the manage products menu and verify that you have specified the correct product ID).';
                 $this->debug_log($error_msg, false);
                 return false;
             }
             $subsc_ref = $ret_product->ref_text;
             if (!empty($subsc_ref)) {
                 //Do membership signup task
                 $this->debug_log('Reference Text field value: ' . $subsc_ref, true);
                 if (get_option('eStore_enable_wishlist_int')) {
                     $this->debug_log('WishList integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true);
                     wl_handle_subsc_signup($this->ipn_data, $subsc_ref, $this->ipn_data['subscr_id']);
                 } else {
                     if (function_exists('wp_eMember_install')) {
                         $this->debug_log('eMember integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true);
                         eMember_handle_subsc_signup($this->ipn_data, $subsc_ref, $this->ipn_data['subscr_id'], $eMember_id);
                     }
                 }
             }
             return true;
         } else {
             if ($transaction_type == "subscr_cancel" || $transaction_type == "subscr_eot" || $transaction_type == "subscr_failed") {
                 if (get_option('eStore_enable_wishlist_int')) {
                     wl_handle_subsc_cancel($this->ipn_data);
                 } else {
                     // Code to handle the IPN for subscription cancellation
                     if (function_exists('wp_eMember_install')) {
                         eMember_handle_subsc_cancel($this->ipn_data);
                     }
                 }
                 $this->debug_log('Subscription cancellation IPN received... nothing to do here(handled by the subscription IPN handler)', true);
                 return true;
             } else {
                 $cart_items = array();
                 $this->debug_log('Transaction Type (Buy Now/Subscribe): ' . $transaction_type, true);
                 $item_number = $this->ipn_data['item_number'];
                 $item_name = $this->ipn_data['item_name'];
                 //$item_name = mb_convert_encoding($item_name, "UTF-8");
                 $quantity = $this->ipn_data['quantity'];
                 if (empty($quantity)) {
                     $quantity = 1;
                 }
                 $mc_tax = $this->ipn_data['tax'];
                 if (!empty($mc_tax)) {
                     //For "web_accept" txn, the total tax is included in the "mc_gross" amt.
                     $mc_gross = $this->ipn_data['mc_gross'] - $mc_tax;
                     $this->debug_log('Deducting tax amount (' . $mc_tax . ') from mc_gross amt', true);
                 } else {
                     $mc_gross = $this->ipn_data['mc_gross'];
                 }
                 $mc_shipping = $this->ipn_data['mc_shipping'];
                 $mc_currency = $this->ipn_data['mc_currency'];
                 $current_item = array('item_number' => $item_number, 'item_name' => $item_name, 'quantity' => $quantity, 'mc_gross' => $mc_gross, 'mc_shipping' => $mc_shipping, 'mc_currency' => $mc_currency);
                 array_push($cart_items, $current_item);
             }
         }
     }
     // URL of directory where script is stored ( include trailing slash )
     $script_location = get_option('eStore_download_script');
     $random_key = get_option('eStore_random_code');
     $payment_currency = get_option('cart_payment_currency');
     $product_id_array = array();
     $product_name_array = array();
     $product_price_array = array();
     $product_qty_array = array();
     $download_link_array = array();
     $download_link_for_digital_item = array();
     $product_key_data = "";
     $counter = 0;
     foreach ($cart_items as $current_cart_item) {
         $cart_item_data_num = $current_cart_item['item_number'];
         $key = $cart_item_data_num;
         $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$key}'", OBJECT);
         if (!$retrieved_product) {
             $error_msg .= 'Request received for product ID: ' . $cart_item_data_num . '. Could not find this Product ID in the product database (please check the manage products menu and verify that you have specified the correct product ID).';
             $this->debug_log($error_msg, false);
             return false;
         }
         $cart_item_data_name = trim($current_cart_item['item_name']);
         //$retrieved_product->name;
         $cart_item_data_quantity = $current_cart_item['quantity'];
         $cart_item_data_total = $current_cart_item['mc_gross'];
         $cart_item_shipping = $current_cart_item['mc_shipping'];
         $cart_item_data_currency = $current_cart_item['mc_currency'];
         if (empty($cart_item_data_quantity)) {
             $cart_item_data_quantity = 1;
         }
         $this->debug_log('Item Number: ' . $cart_item_data_num, true);
         $this->debug_log('Item Name: ' . $cart_item_data_name, true);
         $this->debug_log('Item Quantity: ' . $cart_item_data_quantity, true);
         $this->debug_log('Item Price: ' . $cart_item_data_total, true);
         $this->debug_log('Item Shipping: ' . $cart_item_shipping, true);
         $this->debug_log('Item Currency: ' . $cart_item_data_currency, true);
         // Compare the values with the values stored in the database
         $coupon_code = $customvariables['coupon'];
         if (!empty($coupon_code)) {
             $this->debug_log('Coupon Code Used : ' . $coupon_code, true);
             $coupon_table_name = $wpdb->prefix . "wp_eStore_coupon_tbl";
             $ret_coupon = $wpdb->get_row("SELECT * FROM {$coupon_table_name} WHERE coupon_code = '{$coupon_code}'", OBJECT);
             if ($ret_coupon) {
                 $discount_amount = $ret_coupon->discount_value;
                 $discount_type = $ret_coupon->discount_type;
                 if ($discount_type == 0) {
                     //apply % discount
                     $discount = $retrieved_product->price * $discount_amount / 100;
                     $true_product_price = $retrieved_product->price - $discount;
                 } else {
                     // apply value discount
                     $true_product_price = $retrieved_product->price - $discount_amount;
                 }
             } else {
                 eStore_payment_debug('Could not find the coupon in the database: ' . $coupon_code, false);
             }
             if ($transaction_type == "subscr_payment") {
                 $true_product_price = 0;
                 //Used coupon on subscription product
                 eStore_payment_debug('Coupon discount was used on a subscription product', true);
             }
         } else {
             if (is_numeric($retrieved_product->a3)) {
                 $true_product_price = 0;
                 //subscription product
             } else {
                 if (is_numeric($retrieved_product->price)) {
                     $true_product_price = $retrieved_product->price * $cart_item_data_quantity;
                 } else {
                     $true_product_price = 0;
                     //most likely a subscription
                 }
             }
         }
         $check_price = true;
         $msg = "";
         $msg = apply_filters('eStore_before_checking_price_filter', $msg, $current_cart_item);
         if (!empty($msg) && $msg == "currency-check-override") {
             $check_price = false;
             $this->debug_log('Price and currency check override enabled by filter eStore_before_checking_price_filter', true);
         }
         if ($check_price) {
             $true_product_price = round($true_product_price, 2);
             if ($cart_item_data_total < $true_product_price) {
                 $error_msg .= 'Wrong Product Price Detected! Actual Product Price : ' . $true_product_price . ' Amount Paid: ' . $cart_item_data_total;
                 $this->debug_log($error_msg, false);
                 return false;
             }
             if (!empty($retrieved_product->currency_code)) {
                 $payment_currency = $retrieved_product->currency_code;
             }
             if ($payment_currency != $cart_item_data_currency) {
                 $error_msg .= 'Invalid Product Currency Detected! The payment was made in currency: ' . $cart_item_data_currency;
                 $this->debug_log($error_msg, false);
                 $this->debug_log('You specified to receive payment in: ' . $payment_currency . ' for this product. Check eStore settings or this product\'s Buy Now/Subscription section and correct the currency code to fix this issue.', false);
                 return false;
             }
         }
         //*** Handle Membership Payment ***
         $member_ref = $retrieved_product->ref_text;
         $this->debug_log('Value of the reference text field for this product: ' . $member_ref, true);
         if (!empty($member_ref)) {
             if ($transaction_type == "web_accept") {
                 if (get_option('eStore_enable_wishlist_int')) {
                     $this->debug_log('WishList integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true);
                     wl_handle_subsc_signup($this->ipn_data, $member_ref, $this->ipn_data['txn_id']);
                 } else {
                     if (function_exists('wp_eMember_install')) {
                         $this->debug_log('eMember integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true);
                         eMember_handle_subsc_signup($this->ipn_data, $member_ref, $this->ipn_data['txn_id'], $eMember_id);
                     }
                 }
             } else {
                 if ($transaction_type == "cart") {
                     if (get_option('eStore_enable_wishlist_int')) {
                         $this->debug_log('WishList integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true);
                         wl_handle_subsc_signup($this->ipn_data, $member_ref, $this->ipn_data['txn_id']);
                     } else {
                         if (function_exists('wp_eMember_install')) {
                             $this->debug_log('eMember integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true);
                             eMember_handle_subsc_signup($this->ipn_data, $member_ref, $this->ipn_data['txn_id'], $eMember_id);
                         }
                     }
                 } else {
                     if ($transaction_type == "subscr_payment") {
                         $subscr_id = $this->ipn_data['subscr_id'];
                         eStore_update_member_subscription_start_date_if_applicable($this->ipn_data, $subscr_id);
                     }
                 }
             }
         }
         //== End of Membership payment handling ==
         $product_id = $retrieved_product->id;
         //Check if nextgen gallery integration is being used
         $pid_check_value = eStore_is_ngg_pid_present($cart_item_data_name);
         if ($pid_check_value != -1) {
             $pictureID = $pid_check_value;
         }
         //Generate link from Nextgen gallery if PID is present.
         if (!empty($pictureID)) {
             $download_link = eStore_get_ngg_image_url($pictureID, $cart_item_data_name);
             $pictureID = "";
         } else {
             $this->debug_log('Generating encrypted download link for this product.', true);
             $download_link = generate_download_link($retrieved_product, $cart_item_data_name, $this->ipn_data);
         }
         $this->debug_log('Download Link: [hidden]', true);
         //$download_link
         $product_specific_instructions .= eStore_get_product_specific_instructions($retrieved_product);
         //Product license key generation if using the license manager
         if (function_exists('wp_lic_manager_install')) {
             $product_license_data .= eStore_check_and_generate_license_key($retrieved_product, $this->ipn_data);
             $this->debug_log('License Data: [hidden]', true);
             //$product_license_data
         }
         //Issue serial key if this feature is being used
         $product_key_data .= eStore_post_sale_retrieve_serial_key_and_update($retrieved_product, $cart_item_data_name, $cart_item_data_quantity);
         array_push($product_name_array, $cart_item_data_name);
         array_push($product_id_array, $product_id);
         array_push($product_price_array, $cart_item_data_total);
         array_push($product_qty_array, $cart_item_data_quantity);
         array_push($download_link_array, $download_link);
         if (eStore_check_if_string_contains_url($download_link)) {
             array_push($download_link_for_digital_item, $download_link);
         }
         $counter++;
         $download_link = '';
     }
     if (!empty($product_key_data)) {
         $this->ipn_data['product_key_data'] = $product_key_data;
     }
     // How long the download link remain valid (hours)
     $download_url_life = get_option('eStore_download_url_life');
     // Email settings data
     $notify_email = get_option('eStore_notify_email_address');
     // Email which will receive notification of sale (sellers email)
     $download_email = get_option('eStore_download_email_address');
     // Email from which the mail wil be sent from
     $email_subject = get_option('eStore_buyer_email_subj');
     $email_body = get_option('eStore_buyer_email_body');
     $notify_subject = get_option('eStore_seller_email_subj');
     $notify_body = get_option('eStore_seller_email_body');
     // Send the product
     for ($i = 0; $i < sizeof($product_name_array); $i++) {
         $constructed_products_name .= $product_name_array[$i];
         $constructed_products_name .= ", ";
         $constructed_products_price .= $product_price_array[$i];
         $constructed_products_price .= ", ";
         $constructed_products_id .= $product_id_array[$i];
         $constructed_products_id .= ", ";
         $constructed_products_details .= "\n" . $product_name_array[$i] . " x " . $product_qty_array[$i] . " - " . $currency_symbol . $product_price_array[$i] . " (" . $payment_currency . ")";
         $tax_inc_price = eStore_get_tax_include_price_by_prod_id($product_id_array[$i], $product_price_array[$i]);
         $constructed_products_details_tax_inc .= "\n" . $product_name_array[$i] . " x " . $product_qty_array[$i] . " - " . $currency_symbol . $tax_inc_price . " (" . $payment_currency . ")";
         //Download links list for all items in the cart
         $constructed_download_link .= "\n";
         if (is_array($download_link_array[$i])) {
             $package_downloads = $download_link_array[$i];
             for ($j = 0; $j < sizeof($package_downloads); $j++) {
                 $constructed_download_link .= $package_downloads[$j];
                 $constructed_download_link .= "\n";
             }
         } else {
             $constructed_download_link .= $download_link_array[$i];
         }
         //Download links for only digital items in the cart
         $constructed_download_link_for_digital_item .= "\n";
         if (is_array($download_link_for_digital_item[$i])) {
             $package_downloads2 = $download_link_for_digital_item[$i];
             for ($j = 0; $j < sizeof($package_downloads2); $j++) {
                 $constructed_download_link_for_digital_item .= $package_downloads2[$j];
                 $constructed_download_link_for_digital_item .= "\n";
             }
         } else {
             $constructed_download_link_for_digital_item .= $download_link_for_digital_item[$i];
         }
     }
     $purchase_date = date("Y-m-d");
     $total_purchase_amt = $this->ipn_data['mc_gross'];
     $txn_id = $this->ipn_data['txn_id'];
     $total_tax = $this->ipn_data['tax'];
     $total_shipping = round($this->ipn_data['mc_handling'] + $this->ipn_data['mc_shipping'], 2);
     $total_minus_total_tax = round($total_purchase_amt - $total_tax, 2);
     $this->ipn_data['mc_tax'] = $total_tax;
     $this->ipn_data['mc_shipping'] = $total_shipping;
     //Counter for incremental receipt number
     $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;
     $this->debug_log('Incremental counter value for PayPal checkout: ' . $receipt_counter, true);
     $wp_eStore_config->setValue('eStore_custom_receipt_counter', $receipt_counter);
     $wp_eStore_config->saveConfig();
     $buyer_shipping_info = "\n" . $this->ipn_data['address_name'];
     $buyer_shipping_info .= "\n" . $this->ipn_data['address_street'];
     $buyer_shipping_info .= "\n" . $this->ipn_data['address_city'];
     $buyer_shipping_info .= "\n" . $this->ipn_data['address_state'] . " " . $this->ipn_data['address_zip'];
     $buyer_shipping_info .= "\n" . $this->ipn_data['address_country'];
     $buyer_shipping_info .= "\n" . $this->ipn_data['contact_phone'];
     $this->ipn_data['address'] = $buyer_shipping_info;
     $buyer_phone = $this->ipn_data['contact_phone'];
     $shipping_option = $customvariables['ship_option'];
     if (empty($shipping_option)) {
         $shipping_option = "Default";
     }
     $product_specific_instructions = eStore_apply_post_payment_dynamic_tags($product_specific_instructions, $this->ipn_data, $cart_items);
     $tags = array("{first_name}", "{last_name}", "{payer_email}", "{product_name}", "{product_link}", "{product_price}", "{product_id}", "{download_life}", "{product_specific_instructions}", "{product_details}", "{product_details_tax_inclusive}", "{shipping_info}", "{license_data}", "{purchase_date}", "{purchase_amt}", "{transaction_id}", "{shipping_option_selected}", "{product_link_digital_items_only}", "{total_tax}", "{total_shipping}", "{total_minus_total_tax}", "{customer_phone}", "{counter}", "{coupon_code}", "{serial_key}");
     $vals = array($this->ipn_data['first_name'], $this->ipn_data['last_name'], $this->ipn_data['payer_email'], $constructed_products_name, $constructed_download_link, $constructed_products_price, $constructed_products_id, $download_url_life, $product_specific_instructions, $constructed_products_details, $constructed_products_details_tax_inc, $buyer_shipping_info, $product_license_data, $purchase_date, $total_purchase_amt, $txn_id, $shipping_option, $constructed_download_link_for_digital_item, $total_tax, $total_shipping, $total_minus_total_tax, $buyer_phone, $receipt_counter, $coupon_code, $product_key_data);
     $subject = str_replace($tags, $vals, $email_subject);
     $body = stripslashes(str_replace($tags, $vals, $email_body));
     $headers = 'From: ' . $download_email . "\r\n";
     $attachment = '';
     //Call the filter for email notification body
     $this->debug_log('Applying filter - eStore_notification_email_body_filter', true);
     $body = apply_filters('eStore_notification_email_body_filter', $body, $this->ipn_data, $cart_items);
     // Determine if it's a recurring payment
     $recurring_payment = is_paypal_recurring_payment($this->ipn_data);
     if (!$recurring_payment) {
         if (get_option('eStore_send_buyer_email')) {
             if (get_option('eStore_use_wp_mail')) {
                 wp_eStore_send_wp_mail($this->ipn_data['payer_email'], $subject, $body, $headers);
                 //wp_mail($this->ipn_data['payer_email'], $subject, $body, $headers);
                 $this->debug_log('Product Email successfully sent to ' . $this->ipn_data['payer_email'] . '.', true);
             } else {
                 if (@eStore_send_mail($this->ipn_data['payer_email'], $body, $subject, $download_email, $attachment)) {
                     $this->debug_log('Product Email successfully sent (using PHP mail) to ' . $this->ipn_data['payer_email'] . '.', true);
                 } else {
                     $this->debug_log('Error sending product Email (using PHP mail) to ' . $this->ipn_data['payer_email'] . '.', false);
                 }
             }
         }
     }
     // Notify seller
     $n_subject = str_replace($tags, $vals, $notify_subject);
     $n_body = str_replace($tags, $vals, $notify_body);
     if ($wp_eStore_config->getValue('eStore_add_payment_parameters_to_admin_email') == '1') {
         $n_body .= "\n\n------- User Email ----------\n" . $body . "\n\n------- Paypal Parameters (Only admin will receive this) -----\n" . $this->post_string;
     }
     $n_body = stripslashes($n_body);
     if (!$recurring_payment) {
         $notify_emails_array = explode(",", $notify_email);
         foreach ($notify_emails_array as $notify_email_address) {
             if (!empty($notify_email_address)) {
                 $recipient_email_address = trim($notify_email_address);
                 if (get_option('eStore_use_wp_mail')) {
                     wp_eStore_send_wp_mail($recipient_email_address, $n_subject, $n_body, $headers);
                     //wp_mail($recipient_email_address, $n_subject, $n_body, $headers);
                     $this->debug_log('Notify Email successfully sent to ' . $recipient_email_address . '.', true);
                 } else {
                     if (@eStore_send_mail($recipient_email_address, $n_body, $n_subject, $download_email)) {
                         $this->debug_log('Notify Email successfully sent (using PHP mail) to ' . $recipient_email_address . '.', true);
                     } else {
                         $this->debug_log('Error sending notify Email (using PHP mail) to ' . $recipient_email_address . '.', false);
                     }
                 }
             }
         }
     }
     // Do Post operations
     if (!$recurring_payment) {
         $this->debug_log('Updating Products, Customers, Coupons, Sales Database Tables with Sales Data.', true);
         $firstname = $this->ipn_data['first_name'];
         $lastname = $this->ipn_data['last_name'];
         $emailaddress = $this->ipn_data['payer_email'];
         $address = esc_sql(stripslashes($buyer_shipping_info));
         $phone = $this->ipn_data['contact_phone'];
         $subscr_id = $this->ipn_data['subscr_id'];
         $customer_ip = $customvariables['ip'];
         if (empty($customer_ip)) {
             $customer_ip = "No information";
         }
         $product_key_data = $this->ipn_data['product_key_data'];
         if (empty($product_key_data)) {
             $product_key_data = "";
         }
         $notes = "";
         $status = "Paid";
         if (function_exists('wp_eMember_install') && empty($eMember_id)) {
             //eMember purchase history additional check
             $this->debug_log('No eMember ID was passed so the user was not logged in. Quering member database to see if a user account exists for: ' . $emailaddress, true);
             $members_table_name = $wpdb->prefix . "wp_eMember_members_tbl";
             $query_emem_db = $wpdb->get_row("SELECT member_id FROM {$members_table_name} WHERE email = '{$emailaddress}'", OBJECT);
             if ($query_emem_db) {
                 $eMember_id = $query_emem_db->member_id;
                 $this->debug_log('Found a user account with the purchaser email address. adding this purchase to account ID: ' . $eMember_id, true);
             }
         }
         $counter = 0;
         foreach ($cart_items as $current_cart_item) {
             $cart_item_data_num = $current_cart_item['item_number'];
             $cart_item_data_name = $current_cart_item['item_name'];
             $key = $cart_item_data_num;
             $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$key}'", OBJECT);
             $current_product_id = $cart_item_data_num;
             $cart_item_qty = $current_cart_item['quantity'];
             $sale_price = $current_cart_item['mc_gross'];
             if (empty($cart_item_qty)) {
                 $cart_item_qty = 1;
             }
             $this->debug_log('Product ID: ' . $cart_item_data_num . '. Current available copies value: ' . $retrieved_product->available_copies . ' Sales count value: ' . $retrieved_product->sales_count, true);
             $new_available_copies = "";
             if (is_numeric($retrieved_product->available_copies)) {
                 $new_available_copies = $retrieved_product->available_copies - $cart_item_qty;
             }
             $new_sales_count = $retrieved_product->sales_count + $cart_item_qty;
             $this->debug_log('New available copies value: ' . $new_available_copies . ' New sales count value: ' . $new_sales_count, true);
             $updatedb = "UPDATE {$products_table_name} SET available_copies = '{$new_available_copies}', sales_count = '{$new_sales_count}' WHERE id='{$current_product_id}'";
             $results = $wpdb->query($updatedb);
             // Update the Customer table
             $product_name = esc_sql(stripslashes($cart_item_data_name));
             $eMember_username = $eMember_id;
             $updatedb = "INSERT INTO {$customer_table_name} (first_name, last_name, email_address, purchased_product_id,txn_id,date,sale_amount,coupon_code_used,member_username,product_name,address,phone,subscr_id,purchase_qty,ipaddress,status,serial_number,notes) VALUES ('{$firstname}', '{$lastname}','{$emailaddress}','{$current_product_id}','{$transaction_id}','{$clientdate}','{$sale_price}','{$coupon_code}','{$eMember_username}','{$product_name}','{$address}','{$phone}','{$subscr_id}','{$cart_item_qty}','{$customer_ip}','{$status}','{$product_key_data}','{$notes}')";
             $results = $wpdb->query($updatedb);
             $updatedb2 = "INSERT INTO {$sales_table_name} (cust_email, date, time, item_id, sale_price) VALUES ('{$emailaddress}','{$clientdate}','{$clienttime}','{$current_product_id}','{$sale_price}')";
             $results = $wpdb->query($updatedb2);
         }
         if (!empty($coupon_code)) {
             $coupon_table_name = $wpdb->prefix . "wp_eStore_coupon_tbl";
             $ret_coupon = $wpdb->get_row("SELECT * FROM {$coupon_table_name} WHERE coupon_code = '{$coupon_code}'", OBJECT);
             if ($ret_coupon) {
                 $redemption_count = $ret_coupon->redemption_count + 1;
                 $updatedb = "UPDATE {$coupon_table_name} SET redemption_count = '{$redemption_count}' WHERE coupon_code='{$coupon_code}'";
                 $results = $wpdb->query($updatedb);
             }
         }
         $this->debug_log('Products, Customers, Coupons, Sales Database Tables Updated.', true);
         //Autoresponder signups
         eStore_item_specific_autoresponder_signup($cart_items, $firstname, $lastname, $emailaddress);
         eStore_global_autoresponder_signup($firstname, $lastname, $emailaddress);
         $this->ipn_data['eMember_userid'] = $eMember_id;
         //need to add the member ID to the IPN data
         do_action('eStore_product_database_updated_after_payment', $this->ipn_data, $cart_items);
         //eStore's action after post payment product database is update
     }
     $this->debug_log('Updating Affiliate Database Table with Sales Data if Using the WP Affiliate Platform Plugin.', true);
     if (eStore_affiliate_capability_exists()) {
         //$this->debug_log('WP Affiliate Platform is installed, checking referral details...',true);
         $award_commission = true;
         if (get_option('eStore_aff_one_time_commission')) {
             if ($recurring_payment) {
                 $award_commission = false;
                 $this->debug_log('One time commission option is being used, This is a recurring payment and will not generate affiliate commission.', true);
             }
         }
         if ($award_commission) {
             $this->debug_log('Affiliate Commission may need to be tracked. See the "eStore_post_payment_debug.log" file for more details on commission calculation', true);
             eStore_aff_award_commission($this->ipn_data, $cart_items);
         }
         //Handle auto affiliate account creation if this feature is used
         eStore_handle_auto_affiliate_account_creation($this->ipn_data);
     } else {
         $this->debug_log('Not Using the WP Affiliate Platform Plugin.', true);
     }
     //Fire Recurring payment action hook
     if ($recurring_payment) {
         $this->debug_log('Firing the PayPal recurring payment action hook.', true);
         do_action('eStore_paypal_recurring_payment_received', $this->ipn_data, $cart_items);
     }
     //Revenue sharing
     $share_revenue = get_option('eStore_aff_enable_revenue_sharing');
     if (!empty($share_revenue)) {
         eStore_award_author_commission($this->ipn_data, $cart_items);
     }
     //POST IPN Data to memberwing script if specified in the settings
     $memberwing_external_post_url = get_option('eStore_memberwing_ipn_post_url');
     if (!empty($memberwing_external_post_url)) {
         $this->debug_log('Posting IPN data to Memberwing plugin :' . $memberwing_external_post_url, true);
         eStore_POST_IPN_data_to_url($this->ipn_data, $memberwing_external_post_url);
     }
     return true;
 }