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;
        }
    }
}
 static function add_options_config_values()
 {
     add_option("cart_paypal_email", get_bloginfo('admin_email'));
     add_option("eStore_use_paypal_gateway", 1);
     add_option("cart_payment_currency", 'USD');
     add_option("cart_currency_symbol", '$');
     add_option("wp_cart_title", 'Items in Your Cart');
     add_option('wp_cart_empty_text', 'Your cart is empty');
     add_option('cart_return_from_paypal_url', get_bloginfo('wpurl'));
     add_option("eStore_auto_product_delivery", 1);
     add_option("eStore_enable_lightbox_effect", 1);
     add_option("eStore_manage_products_limit2", 50);
     add_option("eStore_auto_convert_to_relative_url", 0);
     add_option("eStore_variation_add_symbol", '+');
     add_option("eStore_download_method", '1');
     add_option('eStore_as3tp_as3key_data', '::');
     //AS3TP
     $api_access_key = uniqid('', true);
     add_option("eStore_api_access_key", $api_access_key);
     //------------------------
     $wp_eStore_config = WP_eStore_Config::getInstance();
     //Email related
     add_option("eStore_use_wp_mail", 1);
     add_option("eStore_send_buyer_email", 1);
     $from_email_address = get_bloginfo('name') . " <*****@*****.**>";
     add_option('eStore_download_email_address', $from_email_address);
     $buyer_email_subj = "Thank you for the purchase";
     add_option('eStore_buyer_email_subj', $buyer_email_subj);
     $buyer_email_body = "Dear {first_name} {last_name}" . "\n\nThank you for your purchase!" . "\n{product_details}" . "\n\nAny item(s) to be shipped will be processed as soon as possible, any digital item(s) can be downloaded using the encrypted links below." . "\n{product_link}" . "\n\nThanks";
     add_option('eStore_buyer_email_body', $buyer_email_body);
     $notify_email_address = get_bloginfo('admin_email');
     add_option('eStore_notify_email_address', $notify_email_address);
     $seller_email_subj = "Notification of product sale";
     add_option('eStore_seller_email_subj', $seller_email_subj);
     $seller_email_body = "Dear Seller" . "\n\nThis mail is to notify you of a product sale. Product Name: {product_name} Product ID: {product_id}" . "\nThe sale was made to {first_name} {last_name} ({payer_email})" . "\n\nThanks";
     add_option('eStore_seller_email_body', $seller_email_body);
     //Create a generic template page
     // Setup the author, slug, and title for the post
     $slug = 'estore-action';
     $page_title = 'Store Action';
     // If the page doesn't already exist, then create it
     if (null == get_page_by_title($page_title)) {
         $slug = 'estore-action';
         $page_title = 'Store Action';
         $page_content = 'This page has been created by WP eStore plugin. Please do not delete it. You can hide this page from your navigation menu.';
         $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $slug, 'post_title' => $page_title, 'post_content' => $page_content, 'comment_status' => 'closed');
         $page_id = wp_insert_post($page_data);
         $wp_eStore_config->addValue('eStore_template_store_action_page_id', $page_id);
     }
     //Advanced settings
     $wp_eStore_config->addValue('eStore_price_currency_position', 'left');
     $wp_eStore_config->addValue('eStore_price_decimal_separator', '.');
     $wp_eStore_config->addValue('eStore_price_thousand_separator', ',');
     $wp_eStore_config->addValue('eStore_price_num_decimals', 2);
     $wp_eStore_config->setValue('eStore_do_not_show_sc_warning', '');
     //Save the config updates
     $wp_eStore_config->saveConfig();
     //Trigger the after plugin activate check
     update_option('eStore_plugin_activation_check_flag', '1');
 }
//Set it to 1 to enable this
define('WP_ESTORE_MUST_UPDATE_SHIPPING_SELECTION_TO_VIEW_SHIPPING', '0');
//Set it to 1 to enable this
define('WP_ESTORE_STAMP_PDF_FILE_AT_DOWNLOAD_TIME', '0');
//Set it to 1 to enable this
define('WP_ESTORE_VALIDATE_PAYPAL_PDT_USING_CURL', '1');
//Set it to 1 to enable this
define('WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE', '0');
//Example value "US"
define('WP_ESTORE_SAVE_SESSION_TO_COOKIE', false);
//TODO - deprecate this as the WP_ESTORE_ENABLE_NEW_CHECKOUT_REDIRECTION option becomes the new default
/* Simple php mail config */
$email_config['protocol'] = 'mail';
/*** Do not Edit Below This line ***/
/* Options that have been moved to settings menu - set these options from eStore's settings menu */
$wp_eStore_config = WP_eStore_Config::getInstance();
if ($wp_eStore_config->getValue('eStore_show_tax_inclusive_price') == '1') {
    define('WP_ESTORE_DISPLAY_TAX_INCLUSIVE_PRICE', '1');
} else {
    define('WP_ESTORE_DISPLAY_TAX_INCLUSIVE_PRICE', '0');
}
define('WP_ESTORE_REDIRECT_COMMISSION_USING_SATELLITE_AFFILIATE_PLUGIN', false);
//The plugin will automatically determine this
if ($wp_eStore_config->getValue('eStore_auto_shorten_dl_links') == '1') {
    define('WP_ESTORE_AUTO_SHORTEN_DOWNLOAD_LINKS', true);
} else {
    define('WP_ESTORE_AUTO_SHORTEN_DOWNLOAD_LINKS', false);
}
define('WP_ESTORE_SHOW_CURRENCY_SYMBOL_AFTER_AMOUNT', '0');
//Check the eStore advanced settings menu for this option
if ($wp_eStore_config->getValue('eStore_use_new_checkout_redirection') == '1') {
function wp_eStore_payment_gateway_settings()
{
    global $wp_eStore_config;
    $wp_eStore_config = WP_eStore_Config::getInstance();
    if (isset($_POST['info_update'])) {
        update_option('eStore_use_multiple_gateways', isset($_POST["eStore_use_multiple_gateways"]) ? '1' : '');
        update_option('eStore_use_manual_gateway_for_zero_dollar_co', isset($_POST["eStore_use_manual_gateway_for_zero_dollar_co"]) ? '1' : '');
        update_option('eStore_use_paypal_gateway', isset($_POST["eStore_use_paypal_gateway"]) ? '1' : '');
        update_option('cart_paypal_email', trim($_POST["cart_paypal_email"]));
        update_option('eStore_paypal_profile_shipping', isset($_POST["eStore_paypal_profile_shipping"]) ? '1' : '');
        update_option('eStore_paypal_return_button_text', (string) $_POST["eStore_paypal_return_button_text"]);
        update_option('eStore_paypal_co_page_style', trim($_POST["eStore_paypal_co_page_style"]));
        update_option('eStore_paypal_pdt_token', trim($_POST["eStore_paypal_pdt_token"]));
        update_option('eStore_use_manual_gateway', isset($_POST["eStore_use_manual_gateway"]) ? '1' : '');
        update_option('eStore_manual_notify_email', trim($_POST["eStore_manual_notify_email"]));
        $wp_eStore_config->setValue('buyer_email_subject_manual_co', trim($_POST["buyer_email_subject_manual_co"]));
        $wp_eStore_config->setValue('seller_email_subject_manual_co', trim($_POST["seller_email_subject_manual_co"]));
        update_option('eStore_manual_co_cust_direction', stripslashes((string) $_POST["eStore_manual_co_cust_direction"]));
        update_option('eStore_manual_return_url', trim($_POST["eStore_manual_return_url"]));
        update_option('eStore_manual_co_do_not_collect_shipping_charge', isset($_POST["eStore_manual_co_do_not_collect_shipping_charge"]) ? '1' : '');
        update_option('eStore_manual_co_give_aff_commission', isset($_POST["eStore_manual_co_give_aff_commission"]) ? '1' : '');
        update_option('eStore_manual_co_auto_update_db', isset($_POST["eStore_manual_co_auto_update_db"]) ? '1' : '');
        $wp_eStore_config->setValue('eStore_manual_co_auto_create_membership', isset($_POST["eStore_manual_co_auto_create_membership"]) ? '1' : '');
        update_option('eStore_manual_co_do_autoresponder_signup', isset($_POST["eStore_manual_co_do_autoresponder_signup"]) ? '1' : '');
        update_option('eStore_manual_co_give_download_links', isset($_POST["eStore_manual_co_give_download_links"]) ? '1' : '');
        $wp_eStore_config->setValue('eStore_on_page_manual_checkout_page_url', trim($_POST["eStore_on_page_manual_checkout_page_url"]));
        update_option('eStore_use_2co_gateway', isset($_POST["eStore_use_2co_gateway"]) ? '1' : '');
        update_option('eStore_2co_vendor_id', trim($_POST["eStore_2co_vendor_id"]));
        update_option('eStore_2co_secret_word', trim($_POST["eStore_2co_secret_word"]));
        update_option('eStore_use_authorize_gateway', isset($_POST["eStore_use_authorize_gateway"]) ? '1' : '');
        update_option('eStore_authorize_login', trim($_POST["eStore_authorize_login"]));
        update_option('eStore_authorize_tx_key', trim($_POST["eStore_authorize_tx_key"]));
        $wp_eStore_config->saveConfig();
        echo '<div id="message" class="updated fade"><p><strong>';
        echo 'Options Updated!';
        echo '</strong></p></div>';
    }
    $defaultEmail = get_option('cart_paypal_email');
    if (empty($defaultEmail)) {
        $defaultEmail = get_bloginfo('admin_email');
    }
    ?>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
    <input type="hidden" name="info_update" id="info_update" value="true" />

	<div class="postbox">
	<h3><label for="title">General Payment Gateway Settings</label></h3>
	<div class="inside">

    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
    <tr valign="top"><td width="25%" align="left">
    Use Multiple Payment Gateways
    </td><td align="left">
    <input name="eStore_use_multiple_gateways" type="checkbox"<?php 
    if (get_option('eStore_use_multiple_gateways') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the plugin will give the customer an option to select a payment method (Example: PayPal, 2Checkout, Manual).</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Redirect to Manual Checkout For Zero Amount Purchase
    </td><td align="left">
    <input name="eStore_use_manual_gateway_for_zero_dollar_co" type="checkbox"<?php 
    if (get_option('eStore_use_manual_gateway_for_zero_dollar_co') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Payment gateways like PayPal do not allow customers to checkout if an item has zero amount. If you want to give your customers item(s) for free then you can use this option together with the manual checkout feature. Ideally you should be using a <a href="http://tipsandtricks-hq.com/ecommerce/?p=126" target="_blank">squeeze page type form</a> to give away free items.</p>
    </td></tr>    

    </table>
    </div></div>

	<div class="postbox">
	<h3><label for="title">PayPal Settings</label></h3>
	<div class="inside">

    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
    <tr valign="top"><td width="25%" align="left">
    Use PayPal Payment Gateway
    </td><td align="left">
    <input name="eStore_use_paypal_gateway" type="checkbox"<?php 
    if (get_option('eStore_use_paypal_gateway') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the customers will be able to checkout through PayPal.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Paypal Email Address/Secure Merchant ID
    </td><td align="left">
    <input name="cart_paypal_email" type="text" size="40" value="<?php 
    echo $defaultEmail;
    ?>
"/>
    <br /><p class="description">Your PayPal email address (this is the account where the payments will go to)</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Use PayPal Profile Based Shipping
    </td><td align="left">
    <input name="eStore_paypal_profile_shipping" type="checkbox"<?php 
    if (get_option('eStore_paypal_profile_shipping') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Check this if you want to use PayPal profile based shipping that you have configured in your PayPal account. Using this will ignore any other shipping options that you have specified in this plugin.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Customize the Return Button Text
    </td><td align="left">
    <input name="eStore_paypal_return_button_text" type="text" size="40" value="<?php 
    echo get_option('eStore_paypal_return_button_text');
    ?>
"/>
    <br /><p class="description">Use this if you want to customize the return button text that is shown to your customers on the payment confirmation page on PayPal. The button text is "Return To Merchant" by default</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Custom Checkout Page Style Name
    </td><td align="left">
    <input name="eStore_paypal_co_page_style" type="text" size="40" value="<?php 
    echo get_option('eStore_paypal_co_page_style');
    ?>
"/>
    <br /><p class="description">Specify the page style name here if you want to customize the paypal checkout page with custom page style otherwise leave this field empty.</p>
    </td></tr>
    
    <tr valign="top"><td width="25%" align="left">
    PDT Identity Token
    </td><td align="left">
    <input name="eStore_paypal_pdt_token" type="text" size="100" value="<?php 
    echo get_option('eStore_paypal_pdt_token');
    ?>
"/>
    <br /><p class="description">Specify your identity token in the text field above if you want to <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=499" target="_blank">display the transaction result on the Thank You page</a>. If you need help finding your token then <a href="http://www.tipsandtricks-hq.com/forum/topic/how-do-i-setup-paypal-pdt-and-get-my-paypal-pdt-token-id" target="_blank">click here</a>.</p>
    </td></tr>
        
    </table>
    </div></div>

	<div class="postbox">
	<h3><label for="title">Manual / Off-line Checkout Settings</label></h3>
	<div class="inside">

    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
    <tr valign="top"><td width="25%" align="left">
    Use Manual Payment Option
    </td><td align="left">
    <input name="eStore_use_manual_gateway" type="checkbox"<?php 
    if (get_option('eStore_use_manual_gateway') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
     Read the various <a href="http://www.tipsandtricks-hq.com/forum/topic/wp-estores-manualoffline-checkout-methods-how-manual-checkout-works" target="_blank">manual checkout setup options</a> available in the eStore plugin.
    <br /><p class="description">When checked the customers will be able to checkout using a Manual process.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Notification Email Address for Seller
    </td><td align="left">
    <input name="eStore_manual_notify_email" type="text" size="40" value="<?php 
    echo get_option('eStore_manual_notify_email');
    ?>
"/>
    <br /><p class="description">This is where the email containg the products and customer details will be sent to when a customer checks out using the manual checkout method.</p>
    </td></tr>
    
    <tr valign="top"><td width="25%" align="left">
    Buyer Email Subject for Manual Checkout
    </td><td align="left">
    <input name="buyer_email_subject_manual_co" type="text" size="60" value="<?php 
    echo $wp_eStore_config->getValue('buyer_email_subject_manual_co');
    ?>
"/>
    <br /><p class="description">This is the email subject that will be used to notify the buyer when a customer checks out using the manual checkout method.</p>
    </td></tr>
    
    <tr valign="top"><td width="25%" align="left">
    Seller Email Subject for Manual Checkout
    </td><td align="left">
    <input name="seller_email_subject_manual_co" type="text" size="60" value="<?php 
    echo $wp_eStore_config->getValue('seller_email_subject_manual_co');
    ?>
"/>
    <br /><p class="description">This is the email subject that will be used to notify the seller when a customer checks out using the manual checkout method.</p>
    </td></tr>
                
	<tr valign="top"><td width="25%" align="left">
	Directions for the Customer
	</td><td align="left">
	<textarea name="eStore_manual_co_cust_direction" rows="6" cols="80"><?php 
    echo get_option('eStore_manual_co_cust_direction');
    ?>
</textarea>
	<br /><p class="description">You can put direction for payment here. The customer will receive this in the order confirmation email. The followiong tags can be used in this field {first_name}, {last_name}, {payer_email}, {transaction_id}, {counter}.</p>
	</td></tr>

    <tr valign="top"><td width="25%" align="left">
    Return URL
    </td><td align="left">
    <input name="eStore_manual_return_url" type="text" size="100" value="<?php 
    echo get_option('eStore_manual_return_url');
    ?>
"/>
    <br /><p class="description">This is where the customers will be redirected to after they complete the manual checkout.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Do Not Add Shipping Charge
    </td><td align="left">
    <input name="eStore_manual_co_do_not_collect_shipping_charge" type="checkbox"<?php 
    if (get_option('eStore_manual_co_do_not_collect_shipping_charge') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">If you do not want to charge shipping to customers who checkout via manual checkout (for example: if you are using store pickup) then check this option.</p>
    </td></tr>
    
    <tr valign="top"><td width="25%" align="left">
    Automatically Update Customer & Products Database
    </td><td align="left">
    <input name="eStore_manual_co_auto_update_db" type="checkbox"<?php 
    if (get_option('eStore_manual_co_auto_update_db') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Usually the customers and products database are updated after a confirmed payment. In the event of manual payment the plugin has no way of verifying the payment. Checking this option will update the customers and products database after the manual checkout submission. Alternatively, you can uncheck this option and manually enter the data after you receive the money from the customer.</p>
    </td></tr>
    
    <tr valign="top"><td width="25%" align="left">
    Create Membership Account (<a href="http://www.tipsandtricks-hq.com/wordpress-emember-easy-to-use-wordpress-membership-plugin-1706" target="_blank">WP eMember Plugin</a>)
    </td><td align="left">
    <input name="eStore_manual_co_auto_create_membership" type="checkbox"<?php 
    if ($wp_eStore_config->getValue('eStore_manual_co_auto_create_membership') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Usually the membership account is created after a confirmed payment. Checking this option will create any necessary membership account after the manual checkout submission.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Perform Autoresponder Signup
    </td><td align="left">
    <input name="eStore_manual_co_do_autoresponder_signup" type="checkbox"<?php 
    if (get_option('eStore_manual_co_do_autoresponder_signup') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Usually autoresponder signup is performed for a confirmed payment. Check this option if you want to perform autoresponder signup as soon as the customer submits the manual checkout form.</p>
    </td></tr>
        
    <tr valign="top"><td width="25%" align="left">
    Automatically Award Affiliate Commission
    </td><td align="left">
    <input name="eStore_manual_co_give_aff_commission" type="checkbox"<?php 
    if (get_option('eStore_manual_co_give_aff_commission') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the affiliate commission will be automatically awarded to the appropriate affiliate after the manual checkout submission.</p>
    </td></tr>
    
    <tr valign="top"><td width="25%" align="left">
    Send Product Download Links in the Email
    </td><td align="left">
    <input name="eStore_manual_co_give_download_links" type="checkbox"<?php 
    if (get_option('eStore_manual_co_give_download_links') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Usually the product download links are given to the customer after a confirmed payment. In the event of manual payment the plugin has no way of verifying the payment so it is preferred that you manually give out the links after you receive the payment. Checking this option will force the plugin to send out download links in the manual checkout email that the customer receives after checkout.</p>
    </td></tr>    

    <tr valign="top"><td width="25%" align="left">
    Embed Manual Checkout Form on a WordPress Page (optional)
    </td><td align="left">
    <input name="eStore_on_page_manual_checkout_page_url" type="text" size="100" value="<?php 
    echo $wp_eStore_config->getValue('eStore_on_page_manual_checkout_page_url');
    ?>
"/>    
    <br /><p class="description">If you want to place the manual checkout form on a WordPress page then create a page and use the <strong>[wp_eStore_on_page_manual_gateway_form]</strong> shortcode on that page. Specify the URL of that page in the above field so that eStore can send your customers to this page when they choose to pay using manual method.</p>
    </td></tr> 
        
    </table>
    </div></div>

	<div class="postbox">
	<h3><label for="title">2Checkout Settings</label></h3>
	<div class="inside">

	<strong><i>(Please make sure to setup your 2Checkout merchant account by following <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=1075" target="_blank">this instruction</a> first)</i></strong>
	<br /><br />
	
    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
    <tr valign="top"><td width="25%" align="left">
    Use 2Checkout Payment Gateway
    </td><td align="left">
    <input name="eStore_use_2co_gateway" type="checkbox"<?php 
    if (get_option('eStore_use_2co_gateway') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When enabled, your customers will be able to checkout using <a href="https://www.2checkout.com/referral?r=tips2co" target="_blank">2Checkout</a> payment gateway.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    2Checkout Vendor ID
    </td><td align="left">
    <input name="eStore_2co_vendor_id" type="text" size="20" value="<?php 
    echo get_option('eStore_2co_vendor_id');
    ?>
"/>
    <br /><p class="description">Your 2Checkout vendor ID.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    2Checkout Secret Word
    </td><td align="left">
    <input name="eStore_2co_secret_word" type="text" size="20" value="<?php 
    echo get_option('eStore_2co_secret_word');
    ?>
"/>
    <br /><p class="description">Your 2Checkout Secret Word. <a href="http://help.2checkout.com/articles/FAQ/Where-do-I-set-up-the-Secret-Word/" target="_blank">How to find the secret word?</a></p>
    </td></tr>

    </table>
    </div></div>

	<div class="postbox">
	<h3><label for="title">Authorize.net Settings</label></h3>
	<div class="inside">

    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
    <tr valign="top"><td width="25%" align="left">
    Use Authorize.net Payment Gateway
    </td><td align="left">
    <input name="eStore_use_authorize_gateway" type="checkbox"<?php 
    if (get_option('eStore_use_authorize_gateway') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When enabled, your customers will be able to checkout using <a href="http://www.authorize.net/" target="_blank">Authorize.net</a> payment gateway.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Authorize.net Login
    </td><td align="left">
    <input name="eStore_authorize_login" type="text" size="20" value="<?php 
    echo get_option('eStore_authorize_login');
    ?>
"/>
    <br /><p class="description">API login ID for the payment gateway account.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Authorize.net Transaction Key
    </td><td align="left">
    <input name="eStore_authorize_tx_key" type="text" size="20" value="<?php 
    echo get_option('eStore_authorize_tx_key');
    ?>
"/>
    <br /><p class="description">Transaction key obtained from the Authorize.net Merchant Interface.</p>
    </td></tr>

    </table>
    </div></div>
    
<?php 
    if (defined('WP_PAYMENT_GATEWAY_BUNDLE_VERSION')) {
        ?>

	<div class="postbox">
	<h3><label for="title">Additional Payment Gateways From Payment Gateway Bundle</label></h3>
	<div class="inside">
	<ul>	
	<li>If you want to use Google Checkout then please configure Google Checkout Settings from the <a href="admin.php?page=wp-payment-gateway&action=gateway" target="_blank">WP Payment Gateway Bundle Settings Menu</a></li>	

	<li>If you want to use PayPal Payments Pro then please configure PayPal Payments Pro Settings from the <a href="admin.php?page=wp-payment-gateway&action=gateway" target="_blank">WP Payment Gateway Bundle Settings Menu</a></li>	
		
	<li>If you want to use SagePay payment gateway then please configure SagePay Settings from the <a href="admin.php?page=wp-payment-gateway&action=gateway" target="_blank">WP Payment Gateway Bundle Settings Menu</a></li>	
		
	<li>If you want to use Authorize.net AIM (Advanced Integration Method) or ARB then please configure Authorize.net AIM Settings from the <a href="admin.php?page=wp-payment-gateway&action=gateway" target="_blank">WP Payment Gateway Bundle Settings Menu</a></li>	
		
	<li>If you want to use eWAY then please configure the eWAY gateway Settings from the <a href="admin.php?page=wp-payment-gateway&action=gateway" target="_blank">WP Payment Gateway Bundle Settings Menu</a></li>	
	
	<li>If you want to use ePay.dk then please configure the ePay.dk gateway Settings from the <a href="admin.php?page=wp-payment-gateway&action=gateway" target="_blank">WP Payment Gateway Bundle Settings Menu</a></li>	
	
	<li>If you want to use Verotel (adult payment gateway) then please configure the Verotel gateway Settings from the <a href="admin.php?page=wp-payment-gateway&action=gateway" target="_blank">WP Payment Gateway Bundle Settings Menu</a></li>
	
	<li>If you want to use ClickBank then please configure the ClickBank Settings from the <a href="admin.php?page=wp-payment-gateway&action=gateway" target="_blank">WP Payment Gateway Bundle Settings Menu</a></li>
	
	<li>If you want to use FreshBooks then please configure the FreshBooks Settings from the <a href="admin.php?page=wp-payment-gateway&action=gateway" target="_blank">WP Payment Gateway Bundle Settings Menu</a></li>
	</ul>			
    </div></div>
                      
<?php 
    }
    ?>
    
    <div class="submit">
        <input type="submit" class="button-primary" name="info_update" value="<?php 
    _e('Update');
    ?>
 &raquo;" />
    </div>
    </form>
    <br />
    <?php 
}
function eStore_process_squeeze_form_submission($name, $email, $prod_id, $ap_id, $clientip)
{
    global $eStore_debug_manager;
    $eStore_debug_manager->squeeze_form("Processing free download request for squeeze form submission...", ESTORE_LEVEL_SUCCESS);
    if (empty($email) || empty($prod_id)) {
        $eStore_debug_manager->squeeze_form("Error! Email or Product ID value is missing. Cannot process this request.", ESTORE_LEVEL_FAILURE);
    }
    if (!is_numeric($prod_id)) {
        $eStore_debug_manager->squeeze_form("Decrypting product ID value: " . $prod_id, ESTORE_LEVEL_SUCCESS);
        $prod_id = base64_decode($prod_id);
    }
    $eStore_debug_manager->squeeze_form("Received Data...[Name:" . $name . "][Email:" . $email . "][Product ID:" . $prod_id . "][ap_id:" . $ap_id . "][IP Address:" . $clientip . "]", ESTORE_LEVEL_SUCCESS);
    //Check the email address validity
    if (!is_email($email)) {
        $eStore_debug_manager->squeeze_form("Email address (" . $email . ") is not valid. This request will not be processed.", ESTORE_LEVEL_FAILURE, true);
        exit;
    }
    global $wpdb;
    $wp_eStore_config = WP_eStore_Config::getInstance();
    $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
    $customer_table_name = $wpdb->prefix . "wp_eStore_customer_tbl";
    $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$prod_id}'", OBJECT);
    //Perform verification if the the "Enforce Zero Price Checking on Free Product Download" option is enabled.
    if ($wp_eStore_config->getValue('eStore_product_price_must_be_zero_for_free_download') == '1') {
        if (!is_numeric($retrieved_product->price) || $retrieved_product->price > 0) {
            $error_msg = "Error! The admin of this site requires the product price to be set to 0.00 before it can be given as a free download!";
            eStore_send_free_download1($name, $email, $error_msg);
            $eStore_debug_manager->squeeze_form($error_msg, ESTORE_LEVEL_FAILURE, true);
            exit;
        }
    }
    // These 2 lines of code ensure the Ajax version of the "squeeze form" now passes its data through to the PDF Stamper addon.
    // -- The Assurer, 2010-09-12.
    $payment_data = free_download_pseudo_payment_data($name, $email);
    // Populate the pseudo payment data.
    $cart_items = eStore_create_item_data($prod_id);
    // Populate the pseudo cart data.
    $download = generate_download_link_for_product($prod_id, '', $payment_data);
    // Generate the download link.
    //$download = generate_download_link_for_product($prod_id);
    if (eStore_send_free_download1($name, $email, $download, $payment_data, $cart_items)) {
        $eStore_debug_manager->squeeze_form("Email with the download link sent to: " . $email, ESTORE_LEVEL_SUCCESS);
        //$retrieved_product = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = '$prod_id'", OBJECT);
        $download_email = get_option('eStore_download_email_address');
        $name_pieces = explode(' ', $name, 2);
        $firstname = $name_pieces[0];
        if (!empty($name_pieces[1])) {
            $lastname = $name_pieces[1];
        }
        $eStore_debug_manager->squeeze_form("Performing autoresponder signup if specified in the settings...", ESTORE_LEVEL_SUCCESS);
        eStore_item_specific_autoresponder_signup($cart_items, $firstname, $lastname, $email);
        eStore_global_autoresponder_signup($firstname, $lastname, $email);
        $eStore_debug_manager->squeeze_form("Updating the customers database with the visitor details...", ESTORE_LEVEL_SUCCESS);
        // Update the Customer and products table
        $cart_item_qty = 1;
        $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;
        $current_product_id = $retrieved_product->id;
        $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);
        $emailaddress = $email;
        $clientdate = date("Y-m-d");
        $txn_id = $payment_data['txn_id'];
        //"Free Download";
        $sale_price = '0';
        $coupon_code_used = "";
        $eMember_username = "";
        $product_name = $retrieved_product->name;
        $address = "";
        $phone = "";
        $subscr_id = "";
        $cart_item_qty = "1";
        $customer_ip = $clientip;
        $status = "FREE_DOWNLOAD";
        $product_key_data = "";
        $notes = "";
        $ret_customer_db = $wpdb->get_row("SELECT email_address FROM {$customer_table_name} WHERE purchased_product_id = '{$prod_id}' and email_address='{$emailaddress}'", OBJECT);
        if (!$ret_customer_db) {
            $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}','{$prod_id}','{$txn_id}','{$clientdate}','{$sale_price}','{$coupon_code_used}','{$eMember_username}','{$product_name}','{$address}','{$phone}','{$subscr_id}','{$cart_item_qty}','{$customer_ip}','{$status}','{$product_key_data}','{$notes}')";
            $results = $wpdb->query($updatedb);
        }
        if (!empty($ap_id)) {
            $eStore_debug_manager->squeeze_form("Affiliate Referrer ID Value:" . $ap_id, ESTORE_LEVEL_SUCCESS, true);
            if (get_option('eStore_aff_enable_lead_capture_for_sqeeze_form') != '') {
                if (function_exists('wp_aff_record_remote_lead')) {
                    if (empty($clientip)) {
                        $clientip = "";
                    }
                    wp_aff_record_remote_lead($ap_id, $email, $prod_id, $clientip);
                    $eStore_debug_manager->squeeze_form("Affiliate lead captured", ESTORE_LEVEL_SUCCESS, true);
                } else {
                    $eStore_debug_manager->squeeze_form("Affiliate platform plugin is not installed or it needs to be updated to use this feature!", ESTORE_LEVEL_FAILURE, true);
                }
            }
        }
        do_action('eStore_squeeze_form_processed', $payment_data, $cart_items);
        $eStore_debug_manager->squeeze_form("Squeeze form task complete.", ESTORE_LEVEL_SUCCESS, true);
    }
}
function wp_eStore_advanced_settings()
{
    $wp_eStore_config = WP_eStore_Config::getInstance();
    if (isset($_POST['advanced_settings_update'])) {
        $wp_eStore_config->setValue('eStore_price_currency_position', trim($_POST["eStore_price_currency_position"]));
        $wp_eStore_config->setValue('eStore_price_decimal_separator', trim($_POST["eStore_price_decimal_separator"]));
        $wp_eStore_config->setValue('eStore_price_thousand_separator', trim($_POST["eStore_price_thousand_separator"]));
        $wp_eStore_config->setValue('eStore_price_num_decimals', trim($_POST["eStore_price_num_decimals"]));
        //$wp_eStore_config->setValue('eStore_price_thousand_separator', isset($_POST["eStore_use_2co_gateway"])?'1':'');
        update_option('eStore_ppv_verification_failed_url', trim($_POST["eStore_ppv_verification_failed_url"]));
        /* Miscellaneous Advanced Settings */
        $wp_eStore_config->setValue('eStore_use_new_checkout_redirection', $_POST["eStore_use_new_checkout_redirection"] == '1' ? 1 : '');
        $wp_eStore_config->setValue('eStore_use_custom_text_for_thank_you_page_dl', $_POST["eStore_use_custom_text_for_thank_you_page_dl"] == '1' ? 1 : '');
        /* end of Miscellaneous Advanced Settings */
        $wp_eStore_config->saveConfig();
        echo '<div id="message" class="updated fade"><p><strong>';
        echo 'Options Updated!';
        echo '</strong></p></div>';
    }
    $curr_position = $wp_eStore_config->getValue('eStore_price_currency_position');
    if (empty($curr_position)) {
        $curr_position = "left";
    }
    ?>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">

	<div class="postbox">
	<h3><label for="title">Price Display Settings</label></h3>
	<div class="inside">

	<p>The following options affect how prices are displayed on the frontend.</p>
	
    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
    
	<tr valign="top">
	<th scope="row">Currency Position</th>
	<td>
	<select name="eStore_price_currency_position">
	<option value="left" <?php 
    if ($curr_position == "left") {
        echo 'selected="selected"';
    }
    ?>
>Left</option>
	<option value="right" <?php 
    if ($curr_position == "right") {
        echo 'selected="selected"';
    }
    ?>
>Right</option>
	</select>
	<p class="description">This controls the position of the currency symbol.</p>
	</td></tr>

	<tr valign="top">
	<th scope="row">Decimal Separator</th>
	<td>
	<input name="eStore_price_decimal_separator" type="text" size="5" value="<?php 
    echo $wp_eStore_config->getValue('eStore_price_decimal_separator');
    ?>
"/>
	<p class="description">This sets the decimal separator of the displayed price.</p>
	</td></tr>
	
	<tr valign="top">
	<th scope="row">Thousand Separator</th>
	<td>
	<input name="eStore_price_thousand_separator" type="text" size="5" value="<?php 
    echo $wp_eStore_config->getValue('eStore_price_thousand_separator');
    ?>
"/>
	<p class="description">This sets the thousand separator of the displayed price.</p>
	</td></tr>

	<tr valign="top">
	<th scope="row">Number of Decimals</th>
	<td>
	<input name="eStore_price_num_decimals" type="text" size="5" value="<?php 
    echo $wp_eStore_config->getValue('eStore_price_num_decimals');
    ?>
"/>
	<p class="description">This sets the number of decimal points shown in the displayed price.</p>
	</td></tr>
	
    </table>
    </div></div>
    
    <div class="postbox">
    <h3><label for="title">Pay Per View Content Settings</label></h3>
    <div class="inside">
    <table class="form-table">
    <tr valign="top">
    <th scope="row">Redirection Page for Unauthorized Access</th>
    <td><input type="text" name="eStore_ppv_verification_failed_url" value="<?php 
    echo get_option('eStore_ppv_verification_failed_url');
    ?>
" size="70" />
    <br /><p class="description">Visitors will be redirected to this page when trying to access the Pay Per View URL without clicking on a valid link. Only use this settings if you are selling Pay Per View content.</p></td>
    </tr>
    </table>
    </div></div>
        
    <div class="postbox">
    <h3><label for="title">Miscellaneous Advanced Settings</label></h3>
    <div class="inside">
    <table class="form-table">
        
    <tr valign="top">
    <th scope="row">Enable Alternate Redirection Method</th>        
    <td align="left">    
    <input name="eStore_use_new_checkout_redirection" type="checkbox"<?php 
    if ($wp_eStore_config->getValue('eStore_use_new_checkout_redirection') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Check this option if you want to enable the alternate redirection method. Use it if we have advised you to do so.</p>
    </td></tr>
    
    <tr valign="top">
    <th scope="row">Use Custom Anchor Text for the Thank You page Download Link</th>        
    <td align="left">    
    <input name="eStore_use_custom_text_for_thank_you_page_dl" type="checkbox"<?php 
    if ($wp_eStore_config->getValue('eStore_use_custom_text_for_thank_you_page_dl') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Check this option if you want to show a more user-friendly clickable text for the corresponding download link on the Thank You page. By default the link itself is displayed as the clickable anchor text.</p>
    </td></tr>
    
    </table>
    </div></div>
        
    <div class="submit">
    	<input type="submit" class="button-primary" name=advanced_settings_update value="<?php 
    _e('Update');
    ?>
 &raquo;" />
    </div>
    </form>
    <?php 
}
Example #7
0
function eStore_handle_item_addition_to_cart($prod_data_array)
{
    $output = "";
    $wp_eStore_config = WP_eStore_Config::getInstance();
    //Need to drop cookie?
    unset($_SESSION['eStore_last_action_msg']);
    unset($_SESSION['eStore_last_action_msg_2']);
    unset($_SESSION['eStore_last_action_msg_3']);
    if (isset($_SESSION['eStore_cart'])) {
        //Load data from standard cart items
        $estore_cart = wp_eStore_load_eStore_cart_class();
    } else {
        isset($_SESSION['eStore_cart_class']) ? $estore_cart = unserialize($_SESSION['eStore_cart_class']) : ($estore_cart = new WP_eStore_Cart());
    }
    $product_id = $prod_data_array['item_number'];
    $add_qty = $prod_data_array['add_qty'];
    if ($add_qty < 1) {
        $add_qty = 1;
        $prod_data_array['add_qty'] = 1;
    }
    eStore_general_debug("Checking if item already exists in cart", true);
    $existing_item = $estore_cart->GetItemIfInCart($prod_data_array);
    if ($existing_item !== "-1") {
        //Found an item
        eStore_general_debug("This item already exists in the cart. Updating item ...", true);
        if ($wp_eStore_config->getValue('eStore_do_not_show_qty_in_cart')) {
            $output = '<p class="eStore_error_message">' . ESTORE_ITEM_ALREADY_EXISTS . '</p>';
            eStore_ajax_send_error_response($output);
        }
        $new_qty = $existing_item->quantity + $add_qty;
        if (!is_quantity_availabe($product_id, $new_qty)) {
            //Check if the requested qty is available
            eStore_general_debug("Requested quantity is not available! Product ID: " . $product_id . " Requested qty: " . $new_qty, false);
            if (isset($_SESSION['eStore_last_action_msg'])) {
                $output = $_SESSION['eStore_last_action_msg'];
            }
            if (isset($_SESSION['eStore_last_action_msg_2'])) {
                $output = $_SESSION['eStore_last_action_msg_2'];
            }
            eStore_ajax_send_error_response($output);
        }
        //Update the quantity of this item
        $estore_cart->UpdateItemQty($existing_item, $prod_data_array['add_qty']);
    } else {
        //New item
        eStore_general_debug("Adding a brand new item to the cart", true);
        if (!is_quantity_availabe($product_id, $add_qty)) {
            //Check if the requested qty is available
            eStore_general_debug("Requested quantity is not available! Product ID: " . $product_id . " Requested qty: " . $add_qty, false);
            if (isset($_SESSION['eStore_last_action_msg'])) {
                $output = $_SESSION['eStore_last_action_msg'];
            }
            if (isset($_SESSION['eStore_last_action_msg_2'])) {
                $output = $_SESSION['eStore_last_action_msg_2'];
            }
            eStore_ajax_send_error_response($output);
        }
        if (isset($prod_data_array['custom_price'])) {
            //Check if it is a custom price amount
            if ($prod_data_array['custom_price'] < $prod_data_array['price']) {
                eStore_general_debug("Custom price value is less than the minimum amount!", false);
                $output = '<p class="eStore_error_message">' . WP_ESTORE_MINIMUM_PRICE_YOU_CAN_ENTER . WP_ESTORE_CURRENCY_SYMBOL . $prod_data_array['price'] . '</p>';
                eStore_ajax_send_error_response($output);
            }
            $prod_data_array['price'] = $prod_data_array['custom_price'];
        }
        //Add the item
        $estore_cart->AddNewItemFromDataArray($prod_data_array);
    }
    $_SESSION['eStore_cart_class'] = serialize($estore_cart);
    //$db_data_cart = $estore_cart->print_eStore_cart_details();
    //eStore_general_debug("Cart details: ".$db_data_cart,true);
    //Load to the legacy cart session
    wp_eStore_load_cart_class_to_session($estore_cart);
    $output = eStore_shopping_cart_multiple_gateway();
    return $output;
}
Example #8
0
function wp_eStore_plugin_conflict_check()
{
    $msg = "";
    //Check schemea
    $installed_schema_version = get_option("wp_eStore_db_version");
    if ($installed_schema_version != WP_ESTORE_DB_VERSION) {
        $msg .= '<p>It looks like you did not follow the <a href="http://www.tipsandtricks-hq.com/ecommerce/wordpress-estore-installation-and-usage-guide-31#upgrade" target="_blank">WP eStore upgrade instruction</a> to update the plugin. The database schema is out of sync and need to be updated. Please deactivate the plugin and follow the <a href="http://www.tipsandtricks-hq.com/ecommerce/wordpress-estore-installation-and-usage-guide-31#upgrade" target="_blank">upgrade instruction from here</a> to upgrade the plugin and correct this.</p>';
    }
    $activation_flag_value = get_option('eStore_plugin_activation_check_flag');
    if ($activation_flag_value != '1' && empty($msg)) {
        //no need check for conflict
        return;
    }
    $wp_eStore_config = WP_eStore_Config::getInstance();
    if (function_exists('bb2_install')) {
        $msg .= '<p>You have the Bad Behavior plugin active! This plugin is known to block PayPal\'s payment notification (IPN). Please see <a href="http://www.tipsandtricks-hq.com/forum/topic/list-of-plugins-that-dont-play-nice-conflicting-plugins" target="_blank">this post</a> for more details.</p>';
    }
    // WP Super cache plugin check
    if (function_exists('wp_cache_serve_cache_file') && $wp_eStore_config->getValue('eStore_do_not_show_sc_warning') != '1') {
        $sc_integration_incomplete = false;
        global $wp_super_cache_late_init;
        if (false == isset($wp_super_cache_late_init) || isset($wp_super_cache_late_init) && $wp_super_cache_late_init == 0) {
            $sc_integration_incomplete = true;
        }
        if (defined('TIPS_AND_TRICKS_SUPER_CACHE_OVERRIDE')) {
            $sc_integration_incomplete = false;
        }
        if ($sc_integration_incomplete) {
            $msg .= '<p>You have the WP Super Cache plugin active. Please make sure to follow <a href="http://www.tipsandtricks-hq.com/forum/topic/using-the-plugins-together-with-wp-super-cache-plugin" target="_blank">this instruction</a> to make it work with the WP eStore plugin. You can ignore this message if you have already applied the recommended changes. ';
            $msg .= '<input class="button " type="button" onclick="document.location.href=\'admin.php?page=wp_eStore_settings&estore_hide_sc_msg=1\';" value="Hide this Message">';
            $msg .= '</p>';
        }
    }
    if (function_exists('w3tc_pgcache_flush') && class_exists('W3_PgCache')) {
        $integration_in_place = false;
        $w3_pgcache =& W3_PgCache::instance();
        foreach ($w3_pgcache->_config->get_array('pgcache.reject.cookie') as $reject_cookie) {
            if (strstr($reject_cookie, "cart_in_use") !== false) {
                $integration_in_place = true;
            }
        }
        if (!$integration_in_place) {
            $msg .= '<p>You have the W3 Total Cache plugin active. Please make sure to follow <a href="http://www.tipsandtricks-hq.com/forum/topic/using-the-plugins-with-w3-total-cache-plugin" target="_blank">these instructions</a> to make it work with the WP eStore plugin.</p>';
        }
    }
    //Check for duplicate copies of the eStore plugin
    $plugins_list = get_plugins();
    $plugin_names_arrray = array();
    foreach ($plugins_list as $plugin) {
        $plugin_names_arrray[] = $plugin['Name'];
    }
    $plugin_unqiue_count = array_count_values($plugin_names_arrray);
    if ($plugin_unqiue_count['WP eStore'] > 1) {
        $msg .= '<br />It looks like you have two copies (potentially different versions) of the WP eStore plugin in your plugins directory. This can be the source of many problems. Please delete every copy of the eStore plugin from your plugins directory to clean it out then upload one fresh copy. <a href="http://www.tipsandtricks-hq.com/ecommerce/wordpress-estore-installation-and-usage-guide-31#upgrade" target="_blank">More Info</a><br /><br />';
    }
    if (!empty($msg)) {
        echo '<div class="updated fade">' . $msg . '</div>';
    } else {
        //Set this flag so it does not do the conflict check on every admin page load
        update_option('eStore_plugin_activation_check_flag', '');
    }
}
function wp_eStore_email_settings()
{
    $wp_eStore_config = WP_eStore_Config::getInstance();
    if (isset($_POST['estore_email_settings_update'])) {
        update_option('eStore_use_wp_mail', isset($_POST["eStore_use_wp_mail"]) ? 'checked="checked"' : '');
        $wp_eStore_config->setValue('eStore_email_content_type', trim($_POST["eStore_email_content_type"]));
        update_option('eStore_download_email_address', (string) $_POST["eStore_download_email_address"]);
        update_option('eStore_send_buyer_email', isset($_POST["eStore_send_buyer_email"]) ? 'checked="checked"' : '');
        update_option('eStore_buyer_email_subj', stripslashes((string) $_POST["eStore_buyer_email_subj"]));
        update_option('eStore_buyer_email_body', stripslashes((string) $_POST["eStore_buyer_email_body"]));
        update_option('eStore_notify_email_address', (string) $_POST["eStore_notify_email_address"]);
        update_option('eStore_seller_email_subj', stripslashes((string) $_POST["eStore_seller_email_subj"]));
        update_option('eStore_seller_email_body', stripslashes((string) $_POST["eStore_seller_email_body"]));
        $wp_eStore_config->setValue('eStore_add_payment_parameters_to_admin_email', isset($_POST["eStore_add_payment_parameters_to_admin_email"]) ? '1' : '');
        //$wp_eStore_config->setValue('eStore_price_currency_position', trim($_POST["eStore_price_currency_position"]));
        $wp_eStore_config->setValue('eStore_squeeze_form_email_subject', stripslashes($_POST["eStore_squeeze_form_email_subject"]));
        $wp_eStore_config->setValue('eStore_squeeze_form_email_body', stripslashes($_POST["eStore_squeeze_form_email_body"]));
        $wp_eStore_config->saveConfig();
        echo '<div id="message" class="updated fade"><p><strong>';
        echo 'Email Settings Updated!';
        echo '</strong></p></div>';
    }
    if (get_option('eStore_use_wp_mail')) {
        $eStore_use_wp_mail = 'checked="checked"';
    } else {
        $eStore_use_wp_mail = '';
    }
    $eStore_email_content_type = $wp_eStore_config->getValue('eStore_email_content_type');
    if (empty($eStore_email_content_type)) {
        $eStore_email_content_type = 'text';
    }
    //--------------
    if (get_option('eStore_send_buyer_email')) {
        $eStore_send_buyer_email = 'checked="checked"';
    } else {
        $eStore_send_buyer_email = '';
    }
    $eStore_download_email_address = get_option('eStore_download_email_address');
    if (empty($eStore_download_email_address)) {
        $eStore_download_email_address = get_bloginfo('name') . " <*****@*****.**>";
        //'*****@*****.**';
    }
    $eStore_buyer_email_subj = get_option('eStore_buyer_email_subj');
    if (empty($eStore_buyer_email_subj)) {
        $eStore_buyer_email_subj = "Thank you for the purchase";
    }
    $eStore_buyer_email_body = get_option('eStore_buyer_email_body');
    if (empty($eStore_buyer_email_body)) {
        $eStore_buyer_email_body = "Dear {first_name} {last_name}" . "\n\nThank you for your purchase!" . "\n{product_details}" . "\n\nAny item(s) to be shipped will be processed as soon as possible, any digital item(s) can be downloaded using the encrypted links below." . "\n{product_link}" . "\n\nThanks";
    }
    $eStore_notify_email_address = get_option('eStore_notify_email_address');
    //To allow admins to turn off admin notification email we are going to allow them to have an empty value here
    //if (empty($eStore_notify_email_address)){ $eStore_notify_email_address = get_bloginfo('admin_email'); }
    $eStore_seller_email_subj = get_option('eStore_seller_email_subj');
    if (empty($eStore_seller_email_subj)) {
        $eStore_seller_email_subj = "Notification of product sale";
    }
    $eStore_seller_email_body = get_option('eStore_seller_email_body');
    if (empty($eStore_seller_email_body)) {
        $eStore_seller_email_body = "Dear Seller" . "\n\nThis mail is to notify you of a product sale. Product Name: {product_name} Product ID: {product_id}" . "\nThe sale was made to {first_name} {last_name} ({payer_email})" . "\n\nThanks";
    }
    if ($wp_eStore_config->getValue('eStore_add_payment_parameters_to_admin_email') == '1') {
        $eStore_add_payment_parameters_to_admin_email = 'checked="checked"';
    } else {
        $eStore_add_payment_parameters_to_admin_email = '';
    }
    $eStore_squeeze_form_email_subject = $wp_eStore_config->getValue('eStore_squeeze_form_email_subject');
    if (empty($eStore_squeeze_form_email_subject)) {
        $eStore_squeeze_form_email_subject = "Your Free Download Link";
    }
    $eStore_squeeze_form_email_body = $wp_eStore_config->getValue('eStore_squeeze_form_email_body');
    if (empty($eStore_squeeze_form_email_body)) {
        $eStore_squeeze_form_email_body = 'Dear {first_name} {last_name}' . "\n\nBelow is your download link:" . "\n{product_link}" . "\n\nThank You";
    }
    ?>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">

    <div class="postbox">
    <h3><label for="title">General Email Settings</label></h3>
    <div class="inside">
    
    <table class="form-table">
    <tr valign="top">
    <th scope="row">Use WordPress Mailing System</th>
    <td><input type="checkbox" name="eStore_use_wp_mail" value="1" <?php 
    echo $eStore_use_wp_mail;
    ?>
 /><span class="description"> If checked the plugin will use the WordPress mail function to send emails (this is recommended). Otherwise it will use a simple PHP mail script that comes with this plugin.</span></td>
    </tr>    

    <tr valign="top">
    <th scope="row">Email Content Type</th>
    <td>
    <select name="eStore_email_content_type">
    <option value="text" <?php 
    if ($eStore_email_content_type == "text") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "Plain Text";
    ?>
</option>
    <option value="html" <?php 
    if ($eStore_email_content_type == "html") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "HTML";
    ?>
</option>
    </select>
    <p class="description">Choose which format of email to send. We recommend using plain text format as it has better email delivery rate. <a href="http://www.tipsandtricks-hq.com/forum/topic/why-use-plain-text-email-instead-of-html-email" target="_blank">Read More Here</a></p>
    </td></tr>    
    
    <tr valign="top">
    <th scope="row">From Email Address*</th>
    <td><input type="text" name="eStore_download_email_address" value="<?php 
    echo $eStore_download_email_address;
    ?>
" size="50" />
    <br /><p class="description">Example: Your Name &lt;sales@your-domain.com&gt; This is the email address that will be used to send the email to the buyer. This name and email address will appear in the from field of the email.</p></td>
    </tr>
    
    </table>
    </div></div>
        
    <div class="postbox">
    <h3><label for="title">Purchase Confirmation Email Settings</label></h3>
    <div class="inside">

    <p><i>The following options affect the emails that gets sent to your buyers after a purchase.</i></p>

    <table class="form-table">

    <tr valign="top">
    <th scope="row">Send Emails to Buyer After Purchase</th>
    <td><input type="checkbox" name="eStore_send_buyer_email" value="1" <?php 
    echo $eStore_send_buyer_email;
    ?>
 /><span class="description"> If checked the plugin will send an email to the buyer with the sale details. If digital goods are purchased then the email will contain encrypted download links for the downloadable products.</a></span></td>
    </tr>

    <tr valign="top">
    <th scope="row">Buyer Email Subject*</th>
    <td><input type="text" name="eStore_buyer_email_subj" value="<?php 
    echo $eStore_buyer_email_subj;
    ?>
" size="50" />
    <br /><p class="description">This is the subject of the email that will be sent to the buyer.</p></td>
    </tr>

    <tr valign="top">
    <th scope="row">Buyer Email Body*</th>
    <td>
    <?php 
    $buyer_body_settings = array('textarea_name' => 'eStore_buyer_email_body');
    wp_editor($eStore_buyer_email_body, "eStore_buyer_email_body_content", $buyer_body_settings);
    ?>
    <br /><p class="description">This is the body of the email that will be sent to the buyer. Do not change the email tags (text within the braces {}). All the available <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=460#email_tags" target="_blank">email tags are listed here</a>. Please note that the manual checkout does not use this email settings (Check the "Directions for the Customer" field in the manual checkout settings section).</p></td>
    </tr>

    <tr valign="top">
    <th scope="row">Notification Email Address*</th>
    <td><input type="text" name="eStore_notify_email_address" value="<?php 
    echo $eStore_notify_email_address;
    ?>
" size="50" />
    <br /><p class="description">This is the email address where the seller will be notified of product sales. You can put multiple email addresses separated by comma (,) in the above field to send the notification to multiple email addresses.</p></td>
    </tr>

    <tr valign="top">
    <th scope="row">Seller Email Subject*</th>
    <td><input type="text" name="eStore_seller_email_subj" value="<?php 
    echo $eStore_seller_email_subj;
    ?>
" size="50" />
    <br /><p class="description">This is the subject of the email that will be sent to the seller for record.</p></td>
    </tr>

    <tr valign="top">
    <th scope="row">Seller Email Body*</th>
    <td>
    <?php 
    $seller_email_body_settings = array('textarea_name' => 'eStore_seller_email_body');
    wp_editor($eStore_seller_email_body, "eStore_seller_email_body_content", $seller_email_body_settings);
    ?>
    <br /><p class="description">This is the body of the email that will be sent to the seller for record. Do not change the text within the braces {}. All the available <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=460#email_tags" target="_blank">email tags are listed here</a></p></td>
    </tr>

    <tr valign="top">
    <th scope="row">Append Buyer Email and Payment Parameters to Admin Email</th>
    <td><input type="checkbox" name="eStore_add_payment_parameters_to_admin_email" value="1" <?php 
    echo $eStore_add_payment_parameters_to_admin_email;
    ?>
 />
    <br /><p class="description">Check this if you want to append the buyer email body and other important payment parameters to the admin notification email body.</p></td>
    </tr>

    </table>    

    </div></div>

    <div class="postbox">
    <h3><label for="title">Squeeze Form Email Settings</label></h3>
    <div class="inside">
    
    <p><i>The following options affect the emails that gets sent to your users after a they submit a squeeze form.</i></p>
        
    <table class="form-table">
   
    <tr valign="top">
    <th scope="row">Squeeze Form Email Subject</th>
    <td><input type="text" name="eStore_squeeze_form_email_subject" value="<?php 
    echo $eStore_squeeze_form_email_subject;
    ?>
" size="50" />
    <p class="description">Specify the subject of the email that will be sent to user when a squeeze form is submitted.</p></td>
    </tr>
    
    <tr valign="top">
    <th scope="row">Squeeze Form Email Body</th>
    <td>
    <?php 
    $squeeze_form_email_body_settings = array('textarea_name' => 'eStore_squeeze_form_email_body');
    wp_editor($eStore_squeeze_form_email_body, "eStore_squeeze_form_email_body_content", $squeeze_form_email_body_settings);
    ?>
    <p class="description">Specify the email body that will be sent to the user when a squeeze form is submitted. Do not change the text within the braces {}. You can use the following email tags in this email:
    <br />{first_name} – First name of the user
    <br />{last_name} – Last name of the user
    <br />{product_link} – Download link of the product the squeeze form is giving.
    </p></td>
    </tr>
    
    </table>
    </div></div>

    <div class="submit">
    	<input type="submit" class="button-primary" name=estore_email_settings_update value="Update &raquo;" />
    </div>
    </form>
    <?php 
}
function eStore_generate_download_links_for_cart_items($payment_data, $cart_items)
{
    eStore_payment_debug('Executing eStore_generate_download_links_for_cart_items()', true);
    global $wpdb;
    $wp_eStore_config = WP_eStore_Config::getInstance();
    $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
    $product_name_array = array();
    $download_link_array = array();
    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;
            }
            $item_name = $cart_item_data_name;
            $download_link = generate_download_link($retrieved_product, $item_name, $payment_data);
            eStore_payment_debug('Download Link : ' . $download_link, true);
            array_push($product_name_array, $cart_item_data_name);
            array_push($download_link_array, $download_link);
        }
    }
    for ($i = 0; $i < sizeof($product_name_array); $i++) {
        //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];
        }
    }
    return $constructed_download_link;
}
function wp_eStore_autoresponder_settings()
{
    global $wp_eStore_config;
    $wp_eStore_config = WP_eStore_Config::getInstance();
    if (isset($_POST['info_update'])) {
        $errors = "";
        if (isset($_POST['aweber_make_connection'])) {
            if ($wp_eStore_config->getValue('eStore_aweber_authorize_status') != 'authorized') {
                $authorization_code = trim($_POST['aweber_auth_code']);
                if (!class_exists('AWeberAPI')) {
                    include_once 'lib/auto-responder/aweber_api/aweber_api.php';
                }
                $auth = AWeberAPI::getDataFromAweberID($authorization_code);
                list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = $auth;
                $eStore_aweber_access_keys = array('consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret, 'access_key' => $accessKey, 'access_secret' => $accessSecret);
                $wp_eStore_config->setValue('eStore_aweber_access_keys', $eStore_aweber_access_keys);
                //var_dump($eStore_aweber_access_keys);
                if ($eStore_aweber_access_keys['access_key']) {
                    try {
                        $aweber = new AWeberAPI($consumerKey, $consumerSecret);
                        $account = $aweber->getAccount($accessKey, $accessSecret);
                    } catch (AWeberException $e) {
                        $account = null;
                    }
                    if (!$account) {
                        //$this->deauthorize();//TODO - remove the keys
                        $errors = 'AWeber authentication failed! Please try connecting again.';
                    } else {
                        $wp_eStore_config->setValue('eStore_aweber_authorize_status', 'authorized');
                        $_POST['eStore_use_new_aweber_integration'] = '1';
                        //Set the eStore_use_new_aweber_integration flag to enabled
                        echo '<div id="message" class="updated fade"><p><strong>';
                        echo 'AWeber authorization success!';
                        echo '</strong></p></div>';
                    }
                }
            } else {
                //Remove existing connection
                $eStore_aweber_access_keys = array('consumer_key' => '', 'consumer_secret' => '', 'access_key' => '', 'access_secret' => '');
                $wp_eStore_config->setValue('eStore_aweber_access_keys', $eStore_aweber_access_keys);
                $wp_eStore_config->setValue('eStore_aweber_authorize_status', '');
                $_POST['eStore_use_new_aweber_integration'] = '';
                //Set the eStore_use_new_aweber_integration flag to disabled
                echo '<div id="message" class="updated fade"><p><strong>';
                echo 'AWeber connection removed!';
                echo '</strong></p></div>';
            }
        }
        update_option('eStore_enable_aweber_int', isset($_POST["eStore_enable_aweber_int"]) ? '1' : '');
        update_option('eStore_aweber_list_name', trim($_POST["eStore_aweber_list_name"]));
        $wp_eStore_config->setValue('eStore_use_new_aweber_integration', isset($_POST["eStore_use_new_aweber_integration"]) ? '1' : '');
        update_option('eStore_use_mailchimp', isset($_POST["eStore_use_mailchimp"]) ? '1' : '');
        update_option('eStore_enable_global_chimp_int', isset($_POST["eStore_enable_global_chimp_int"]) ? '1' : '');
        update_option('eStore_chimp_list_name', trim(stripslashes($_POST["eStore_chimp_list_name"])));
        update_option('eStore_chimp_api_key', trim($_POST["eStore_chimp_api_key"]));
        update_option('eStore_mailchimp_disable_double_optin', isset($_POST["eStore_mailchimp_disable_double_optin"]) ? '1' : '');
        update_option('eStore_mailchimp_disable_final_welcome_email', isset($_POST["eStore_mailchimp_disable_final_welcome_email"]) ? '1' : '');
        update_option('eStore_signup_date_field_name', trim($_POST["eStore_signup_date_field_name"]));
        update_option('eStore_use_getResponse', isset($_POST["eStore_use_getResponse"]) ? '1' : '');
        update_option('eStore_enable_global_getResponse_int', isset($_POST["eStore_enable_global_getResponse_int"]) ? '1' : '');
        update_option('eStore_getResponse_campaign_name', trim($_POST["eStore_getResponse_campaign_name"]));
        update_option('eStore_getResponse_api_key', trim($_POST["eStore_getResponse_api_key"]));
        //update_option('eStore_enable_infusionsoft_int', ($_POST['eStore_enable_infusionsoft_int']=='1') ? '1':'' );
        //update_option('eStore_infusionsoft_group_number', (string)$_POST["eStore_infusionsoft_group_number"]);
        $wp_eStore_config->setValue('eStore_use_generic_autoresponder_integration', isset($_POST["eStore_use_generic_autoresponder_integration"]) ? '1' : '');
        $wp_eStore_config->setValue('eStore_use_global_generic_autoresponder_integration', isset($_POST["eStore_use_global_generic_autoresponder_integration"]) ? '1' : '');
        $wp_eStore_config->setValue('eStore_generic_autoresponder_target_list_email', trim($_POST["eStore_generic_autoresponder_target_list_email"]));
        $wp_eStore_config->saveConfig();
        if (!empty($errors)) {
            echo '<div id="message" class="error"><p>';
            echo $errors;
            echo '</p></div>';
        } else {
            echo '<div id="message" class="updated fade"><p><strong>';
            echo 'Autoresponder Options Updated!';
            echo '</strong></p></div>';
        }
    }
    ?>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
    <input type="hidden" name="info_update" id="info_update" value="true" />

	<div class="postbox">
	<h3><label for="title">AWeber Settings (<a href="http://www.tipsandtricks-hq.com/ecommerce/?p=615" target="_blank">AWeber Integration Instructions</a>)</label></h3>
	<div class="inside">

    <table class="form-table">
    
    <tr valign="top"><td width="25%" align="left">
    Enable AWeber Integration:
    </td><td align="left">    
    <input name="eStore_use_new_aweber_integration" type="checkbox"<?php 
    if ($wp_eStore_config->getValue('eStore_use_new_aweber_integration') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Check this option if you want to enable AWeber integration and signup your customers to your AWeber list after purchase.</p>
    </td></tr>
    
    <tr valign="top"><td width="25%" align="left">
    Global AWeber List Signup (optional):
    </td><td align="left">
    <input name="eStore_enable_aweber_int" type="checkbox"<?php 
    if (get_option('eStore_enable_aweber_int') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Use this option if you want to sign up the customers of every transaction to one big AWeber List (specify the list name below). If you want to selectively signup customers to a different list on a per product basis then configure it in the Autoresponder settings section of the product in question.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Global AWeber List Name (optional):
    </td><td align="left">
    <input name="eStore_aweber_list_name" type="text" size="30" value="<?php 
    echo get_option('eStore_aweber_list_name');
    ?>
"/>
    <br /><p class="description">The name of the AWeber list where the customers will be signed up to (example, listname@aweber.com)</p>
    </td></tr>
    </table>
    
    <div style="border-bottom: 1px solid #dedede; height: 10px"></div>
    <p><strong>Configure AWeber API</strong></p>
    <table class="form-table">
    
    <tr valign="top"><td width="25%" align="left">
    Step 1: Get Your AWeber Authorization Code:
    </td><td align="left">    
    <a href="https://auth.aweber.com/1.0/oauth/authorize_app/999d6172" target="_blank">Click here to get your authorization code</a>
    <br /><p class="description">Clicking on the above link will take you to the AWeber site where you will need to log in using your AWeber username and password. Then give access to the Tips and Tricks HQ AWeber app.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Step 2: Paste in Your Authorization Code:
    </td><td align="left">
    <input name="aweber_auth_code" type="text" size="140" value=""/>
    <br /><p class="description">Paste the long authorization code that you got from AWeber in the above field.</p>
    </td></tr>    

	<tr valign="top"><td colspan="2" align="left">
	Step 3: Hit the following "Make Connection" button
	</td></tr>

	<tr valign="top"><td colspan="2" align="left">
	<?php 
    if ($wp_eStore_config->getValue('eStore_aweber_authorize_status') == 'authorized') {
        echo '<input type="submit" name="aweber_make_connection" value="Remove Connection" class= "button button" />';
    } else {
        echo '<input type="submit" name="aweber_make_connection" value="Make Connection" class= "button-primary" />';
    }
    ?>
	</td></tr>	

    </table>
    </div></div>
 
	<div class="postbox">
	<h3><label for="title">MailChimp Settings (<a href="http://www.tipsandtricks-hq.com/ecommerce/?p=753" target="_blank">MailChimp Integration Instructions</a>)</label></h3>
	<div class="inside">

    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">

    <tr valign="top"><td width="25%" align="left">
    Enable MailChimp Integration:
    </td><td align="left">
    <input name="eStore_use_mailchimp" type="checkbox"<?php 
    if (get_option('eStore_use_mailchimp') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Check this if you want to signup your customers to your MailChimp list.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Global MailChimp Integration:
    </td><td align="left">
    <input name="eStore_enable_global_chimp_int" type="checkbox"<?php 
    if (get_option('eStore_enable_global_chimp_int') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the plugin will automatically sign up the customer of every transaction to your MailChimp List specified below. If you want to selectively signup customers on a per product basis then use the Autoresponder settings of that product.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    MailChimp List Name:
    </td><td align="left">
    <input name="eStore_chimp_list_name" type="text" size="30" value="<?php 
    echo get_option('eStore_chimp_list_name');
    ?>
"/>
    <br /><p class="description">The name of the MailChimp list where the customers will be signed up to when using the global signup option (example: Customer List)</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    MailChimp API Key:
    </td><td align="left">
    <input name="eStore_chimp_api_key" type="text" size="50" value="<?php 
    echo get_option('eStore_chimp_api_key');
    ?>
"/>
    <br /><p class="description">The API Key of your MailChimp account (can be found under the "Account" tab). By default the API Key is not active so make sure you activate it in your Mailchimp account.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Disable Double Opt-In:
    </td><td align="left">
    <input name="eStore_mailchimp_disable_double_optin" type="checkbox"<?php 
    if (get_option('eStore_mailchimp_disable_double_optin') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    Do not send double opt-in confirmation email  
    <p class="description">Use this checkbox if you do not wish to use the double opt-in option. Please note that abusing this option may cause your MailChimp account to be suspended.</p>
    
    <input name="eStore_mailchimp_disable_final_welcome_email" type="checkbox"<?php 
    if (get_option('eStore_mailchimp_disable_final_welcome_email') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    Do not send welcome email  
    <p class="description">Use this checkbox if you do not wish to send the welcome email sent by MailChimp when a user subscribes to your list. This will only work if you disable the double opt-in option above.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Signup Date Field Name (optional):
    </td><td align="left">
    <input name="eStore_signup_date_field_name" type="text" size="30" value="<?php 
    echo get_option('eStore_signup_date_field_name');
    ?>
"/>
    <br /><p class="description">If you have configured a signup date field for your mailchimp list then specify the name of the field here (example: SIGNUPDATE). <a href="http://kb.mailchimp.com/article/how-do-i-create-a-date-field-in-my-signup-form" target="_blank">More Info</a></p>
    </td></tr>
            
    </table>
    </div></div>

	<div class="postbox">
	<h3><label for="title">GetResponse Settings (<a href="http://www.tipsandtricks-hq.com/ecommerce/?p=898" target="_blank">GetResponse Integration Instructions</a>)</label></h3>
	<div class="inside">

    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">

    <tr valign="top"><td width="25%" align="left">
    Enable GetResponse Integration:
    </td><td align="left">
    <input name="eStore_use_getResponse" type="checkbox"<?php 
    if (get_option('eStore_use_getResponse') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Check this if you want to signup your customers to your GetResponse list.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Global GetResponse Integration:
    </td><td align="left">
    <input name="eStore_enable_global_getResponse_int" type="checkbox"<?php 
    if (get_option('eStore_enable_global_getResponse_int') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the plugin will automatically sign up the customer of every transaction to your GetResponse campaign specified below. If you want to selectively signup customers on a per product basis then use the Autoresponder settings of that product.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    GetResponse Campaign Name:
    </td><td align="left">
    <input name="eStore_getResponse_campaign_name" type="text" size="30" value="<?php 
    echo get_option('eStore_getResponse_campaign_name');
    ?>
"/>
    <br /><p class="description">The name of the GetResponse campaign where the customers will be signed up to (e.g. marketing)</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    GetResponse API Key:
    </td><td align="left">
    <input name="eStore_getResponse_api_key" type="text" size="50" value="<?php 
    echo get_option('eStore_getResponse_api_key');
    ?>
"/>
    <br /><p class="description">The API Key of your GetResponse account (can be found inside your GetResponse Account).</p>
    </td></tr>

    </table>
    </div></div>
    
	<div class="postbox">
	<h3><label for="title">Generic Autoresponder Integration Settings</label></h3>
	<div class="inside">

	<br /><strong>&nbsp; &nbsp; If your autoresponder provider allows you to signup users just by sending an email to the list email address with the user's email as the from address then you can use this method of integration</strong>
	
    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">

    <tr valign="top"><td width="25%" align="left">
    Use Generic Autoresponder Integration:
    </td><td align="left">
    <input name="eStore_use_generic_autoresponder_integration" type="checkbox"<?php 
    if ($wp_eStore_config->getValue('eStore_use_generic_autoresponder_integration') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Use this option if you want to use the generic auotoresponder integration option.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Enbale Global Integration:
    </td><td align="left">
    <input name="eStore_use_global_generic_autoresponder_integration" type="checkbox"<?php 
    if ($wp_eStore_config->getValue('eStore_use_global_generic_autoresponder_integration') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the plugin will automatically sign up the customer of every transaction to your list/campaign specified below. If you want to selectively signup customers on a per product basis then use the Autoresponder settings of that product.</p>
    </td></tr>
    
    <tr valign="top"><td width="25%" align="left">
    Global List/Campaign Email Address:
    </td><td align="left">
    <input name="eStore_generic_autoresponder_target_list_email" type="text" size="40" value="<?php 
    echo $wp_eStore_config->getValue('eStore_generic_autoresponder_target_list_email');
    ?>
"/>
    <br /><p class="description">The email address of the list where the customer will be signed up to. The plugin will send the autoresponder signup email to this address.</p>
    </td></tr>

    </table>
    </div></div>
    
    <div class="submit">
        <input type="submit" class="button-primary" name="info_update" value="<?php 
    _e('Update');
    ?>
 &raquo;" />
    </div>
    </form>
    <?php 
}
function eStore_gateway_specific_buy_now_submit_listener()
{
    if (isset($_REQUEST['eStore_gs_buy_now_submit'])) {
        $wp_eStore_config = WP_eStore_Config::getInstance();
        $cookie_domain = eStore_get_top_level_domain();
        setcookie("cart_in_use", "true", time() + 21600, "/", $cookie_domain);
        if (function_exists('wp_cache_serve_cache_file')) {
            //WP Super cache workaround
            setcookie("comment_author_", "eStore", time() + 21600, "/", $cookie_domain);
        }
        unset($_SESSION['eStore_last_action_msg']);
        unset($_SESSION['eStore_last_action_msg_2']);
        unset($_SESSION['eStore_last_action_msg_3']);
        unset($_SESSION['eStore_gs_bn_co_error_msg']);
        if (isset($_SESSION['eStore_cart'])) {
            unset($_SESSION['eStore_cart']);
        }
        //sanitize data
        $_REQUEST['product'] = strip_tags($_REQUEST['product']);
        //for PHP5.2 use filter_var($_REQUEST['product'], FILTER_SANITIZE_STRING);
        $_REQUEST['add_qty'] = strip_tags($_REQUEST['add_qty']);
        $_REQUEST['item_number'] = strip_tags($_REQUEST['item_number']);
        if (isset($_REQUEST['custom_price'])) {
            $_REQUEST['custom_price'] = strip_tags($_REQUEST['custom_price']);
        }
        if (isset($_REQUEST['price'])) {
            $_REQUEST['price'] = strip_tags($_REQUEST['price']);
        }
        isset($_REQUEST['shipping']) ? $_REQUEST['shipping'] = strip_tags($_REQUEST['shipping']) : ($_REQUEST['shipping'] = '');
        isset($_REQUEST['cartLink']) ? $_REQUEST['cartLink'] = strip_tags($_REQUEST['cartLink']) : ($_REQUEST['cartLink'] = '');
        isset($_REQUEST['thumbnail_url']) ? $_REQUEST['thumbnail_url'] = strip_tags($_REQUEST['thumbnail_url']) : ($_REQUEST['thumbnail_url'] = '');
        isset($_REQUEST['tax']) ? $_REQUEST['tax'] = strip_tags($_REQUEST['tax']) : ($_REQUEST['tax'] = '');
        if (isset($_REQUEST['digital_flag'])) {
            $_REQUEST['digital_flag'] = strip_tags($_REQUEST['digital_flag']);
        } else {
            $_REQUEST['digital_flag'] = '';
        }
        $gateway = strip_tags($_REQUEST['eStore_gsbn_gateway']);
        $products = array();
        $eStore_gs_buy_now_checkout_error = false;
        $count = 1;
        if ($count == 1) {
            $item_addittion_permitted = true;
            $quantity_available = is_quantity_availabe($_REQUEST['item_number'], $_REQUEST['add_qty']);
            if (!$quantity_available) {
                //Requested qty not available
                $_REQUEST['add_qty'] = 1;
                //Add one by default
                $eStore_gs_buy_now_checkout_error = true;
            }
            if (isset($_SESSION['eStore_last_action_msg'])) {
                $_SESSION['eStore_gs_bn_co_error_msg'] = $_SESSION['eStore_last_action_msg'];
            }
            if ($item_addittion_permitted) {
                if (!empty($_REQUEST[$_REQUEST['product']])) {
                    $price = $_REQUEST[$_REQUEST['product']];
                } else {
                    if (isset($_REQUEST['custom_price'])) {
                        global $wpdb;
                        $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
                        $id = $_REQUEST['item_number'];
                        $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT);
                        if ($_REQUEST['custom_price'] < $retrieved_product->price) {
                            $price = $retrieved_product->price;
                            $currSymbol = get_option('cart_currency_symbol');
                            $eStore_gs_buy_now_checkout_error = true;
                            $_SESSION['eStore_gs_bn_co_error_msg'] = '<p style="color: red;">' . WP_ESTORE_MINIMUM_PRICE_YOU_CAN_ENTER . $currSymbol . $retrieved_product->price . '</p>';
                        } else {
                            $price = $_REQUEST['custom_price'];
                        }
                    } else {
                        $price = $_REQUEST['price'];
                    }
                }
                $product = array('name' => stripslashes($_REQUEST['product']), 'price' => $price, 'quantity' => $_REQUEST['add_qty'], 'shipping' => $_REQUEST['shipping'], 'item_number' => $_REQUEST['item_number'], 'cartLink' => $_REQUEST['cartLink'], 'thumbnail_url' => $_REQUEST['thumbnail_url'], 'tax' => $_REQUEST['tax'], 'digital_flag' => $_REQUEST['digital_flag']);
                array_push($products, $product);
            }
        }
        if (!$eStore_gs_buy_now_checkout_error) {
            $_SESSION['eStore_cart'] = $products;
            $_SESSION['eStore_url'] = WP_ESTORE_URL;
            $_SESSION['eStore_cart_sub_total'] = eStore_get_cart_total();
            $_SESSION['eStore_cart_postage_cost'] = eStore_get_cart_shipping();
            $_SESSION['eStore_cart_total_tax'] = eStore_calculate_total_cart_tax();
            wp_eStore_check_cookie_flag_and_store_values();
            if (WP_ESTORE_ENABLE_NEW_CHECKOUT_REDIRECTION === '1') {
                $redirect_page = WP_ESTORE_WP_SITE_URL . '/?eStore_checkout=process&eStore_gateway=' . $gateway;
            } else {
                $redirect_page = WP_ESTORE_URL . '/eStore_payment_submission.php?eStore_gateway=' . $gateway;
            }
            eStore_redirect_to_url($redirect_page);
        }
    }
}
Example #13
0
function eStore_cart_save_retrieve_cart_part()
{
    $wp_eStore_config = WP_eStore_Config::getInstance();
    if ($wp_eStore_config->getValue('eStore_enable_save_retrieve_cart') == '1') {
        $output = "";
        $output .= '<tr><td colspan="4">';
        $output .= '<div class="eStore_save_retrieve_cart_section">';
        $output .= '<div class="eStore_save_retrieve_cart_body">';
        $output .= '<span class="eStore_save_cart_section">';
        $output .= '<a href="#" class="eStore_save_cart_button" title="' . ESTORE_SAVE . '">' . ESTORE_SAVE . '</a>';
        $output .= '</span>';
        //eStore_save_cart_section
        $output .= '<span class="eStore_retrieve_cart_section">';
        $output .= '<a href="#" class="eStore_retrieve_cart_button" title="' . ESTORE_RETRIEVE . '">' . ESTORE_RETRIEVE . '</a>';
        $output .= '</span>';
        //eStore_retrieve_cart_section
        $output .= '</div>';
        //end of eStore_save_retrieve_cart_body
        $output .= '<div class="eStore_save_retrieve_cart_message"></div>';
        $output .= '</div>';
        //end of eStore_save_retrieve_cart_section
        $output .= '</td></tr>';
        return $output;
    }
}
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);
        }
    }
}
function wp_eStore_addon_settings()
{
    global $wp_eStore_config;
    $wp_eStore_config = WP_eStore_Config::getInstance();
    if (isset($_POST['info_update'])) {
        $retVal = '';
        update_option('eStore_aff_allow_aff_id', isset($_POST['eStore_aff_allow_aff_id']) ? '1' : '');
        update_option('eStore_aff_link_coupon_aff_id', isset($_POST['eStore_aff_link_coupon_aff_id']) ? '1' : '');
        update_option('eStore_aff_one_time_commission', isset($_POST['eStore_aff_one_time_commission']) ? '1' : '');
        update_option('eStore_aff_enable_revenue_sharing', isset($_POST['eStore_aff_enable_revenue_sharing']) ? '1' : '');
        $wp_eStore_config->setValue('eStore_enable_stats_for_author_role', isset($_POST['eStore_enable_stats_for_author_role']) ? '1' : '');
        update_option('eStore_aff_enable_lead_capture_for_sqeeze_form', isset($_POST['eStore_aff_enable_lead_capture_for_sqeeze_form']) ? '1' : '');
        update_option('eStore_create_auto_affiliate_account', isset($_POST['eStore_create_auto_affiliate_account']) ? '1' : '');
        update_option('eStore_aff_enable_commission_per_transaction', isset($_POST['eStore_aff_enable_commission_per_transaction']) ? '1' : '');
        update_option('eStore_aff_no_commission_if_coupon_used', isset($_POST['eStore_aff_no_commission_if_coupon_used']) ? '1' : '');
        update_option('eStore_eMember_must_be_logged_to_checkout', isset($_POST['eStore_eMember_must_be_logged_to_checkout']) ? '1' : '');
        update_option('eStore_eMember_redirection_url_when_not_logged', (string) $_POST["eStore_eMember_redirection_url_when_not_logged"]);
        eStore_dlmgradm::settings_menu_post($_POST['eStore_auto_convert_to_relative_url'], $_POST['eStore_download_method']);
        $retVal .= eStore_as3tpadm::settings_menu_post($_POST['eStore_as3tp_aws_acckey'], $_POST['eStore_as3tp_aws_seckey'], $_POST['eStore_as3tp_expiry']);
        if ($retVal != TRUE) {
            $retVal .= '<br />';
        }
        update_option('eStore_lic_mgr_post_url', isset($_POST["eStore_lic_mgr_post_url"]) ? $_POST["eStore_lic_mgr_post_url"] : '');
        update_option('eStore_lic_mgr_secret_word', isset($_POST["eStore_lic_mgr_secret_word"]) ? $_POST["eStore_lic_mgr_secret_word"] : '');
        update_option('wp_eStore_use_recaptcha', isset($_POST['wp_eStore_use_recaptcha']) ? '1' : '');
        update_option('wp_eStore_captcha_public_key', (string) $_POST["wp_eStore_captcha_public_key"]);
        update_option('wp_eStore_captcha_private_key', (string) $_POST["wp_eStore_captcha_private_key"]);
        $wp_eStore_config->saveConfig();
        echo '<div id="message" class="updated fade"><p><strong>';
        echo 'Options Updated!';
        echo '<br />Return Value: ' . $retVal;
        echo '</strong></p></div>';
    }
    $defaultEmail = get_option('cart_paypal_email');
    if (empty($defaultEmail)) {
        $defaultEmail = get_bloginfo('admin_email');
    }
    ?>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
    <input type="hidden" name="info_update" id="info_update" value="true" />

	<div class="postbox">
	<h3><label for="title">WP Affiliate Platform Plugin Specific Settings</label></h3>
	<div class="inside">

    <br /><strong>Only use these options if you are using the <a href="http://www.tipsandtricks-hq.com/?p=1474" target="_blank">WP Affiliate Platform Plugin</a></strong>
    <br /><br />

    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
      
    <tr valign="top"><td width="25%" align="left">
    Allow Affiliate ID Entry 
    </td><td align="left">
    <input name="eStore_aff_allow_aff_id" type="checkbox"<?php 
    if (get_option('eStore_aff_allow_aff_id') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the plugin will give the customer an option to enter an "Affiliate ID" in the shopping cart to give reward to an affiliate</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Link Affiliate ID with Coupons Table 
    </td><td align="left">
    <input name="eStore_aff_link_coupon_aff_id" type="checkbox"<?php 
    if (get_option('eStore_aff_link_coupon_aff_id') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the customer entering an "Affiliate ID" in the shopping cart will also be able to receive a discount if there is a coupon code in the coupons table that matches with the Affiliate ID. Useful when trying to promote a special deal with an affiliate</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    One Time Commission for Subscription Payment 
    </td><td align="left">
    <input name="eStore_aff_one_time_commission" type="checkbox"<?php 
    if (get_option('eStore_aff_one_time_commission') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the plugin will award commission only once for the subscription payment. Recurring payments will not award affiliate commission.</p>
    </td></tr>            
    
    <tr valign="top"><td width="25%" align="left">
    Enable Revenue Sharing
    </td><td align="left">
    <input name="eStore_aff_enable_revenue_sharing" type="checkbox"<?php 
    if (get_option('eStore_aff_enable_revenue_sharing') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the plugin will enable the revenue sharing feature. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=930" target="_blnak">Read More Here</a></p>
    </td></tr>  

    <tr valign="top"><td width="25%" align="left">
    Add Another Stats Menu for Users with Author Role
    </td><td align="left">
    <input name="eStore_enable_stats_for_author_role" type="checkbox"<?php 
    if ($wp_eStore_config->getValue('eStore_enable_stats_for_author_role') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">If you want your WordPress users with a role of Author or above to be able to see the eStore stats menu then check this option. This is helpful when you want another user (example: revenue sharing partner) to be able to see the stats without giving them admin privilege.</p>
    </td></tr>  
    
    <tr valign="top"><td width="25%" align="left">
    Capture Lead on Squeeze Form Submission
    </td><td align="left">
    <input name="eStore_aff_enable_lead_capture_for_sqeeze_form" type="checkbox"<?php 
    if (get_option('eStore_aff_enable_lead_capture_for_sqeeze_form') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the plugin will capture the lead on <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=126" target="_blnak">sqeeze form</a> submission if this user was referred by an affiliate.</p>
    </td></tr>  
       
    <?php 
    if (function_exists('wp_aff_check_if_account_exists')) {
        ?>
            
    <tr valign="top"><td width="25%" align="left">
    Automatically Create Affiliate Account After Purchase
    </td><td align="left">
    <input name="eStore_create_auto_affiliate_account" type="checkbox"<?php 
        if (get_option('eStore_create_auto_affiliate_account') != '') {
            echo ' checked="checked"';
        }
        ?>
 value="1"/>
    <br /><p class="description">When checked the plugin will automatically create an affiliate account with a unique affiliate ID for the buyer after the purchase. If the email address used to make the purchase already exists in the affiliate database then a new account will not be created.</p>
    </td></tr>     
    <?php 
    }
    ?>

    <tr valign="top"><td width="25%" align="left">
    Award Fixed Commission Per Transaction
    </td><td align="left">
    <input name="eStore_aff_enable_commission_per_transaction" type="checkbox"<?php 
    if (get_option('eStore_aff_enable_commission_per_transaction') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">By default the commission is awarded for every item purchased from your store. When you check this option the plugin will award the commission once per transaction. This can be useful when you want to give out a fixed commission per transaction rather than for every item purchased in that transaction.</p>
    </td></tr>  

    <tr valign="top"><td width="25%" align="left">
    Do Not Award Commission if Coupon Used
    </td><td align="left">
    <input name="eStore_aff_no_commission_if_coupon_used" type="checkbox"<?php 
    if (get_option('eStore_aff_no_commission_if_coupon_used') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">If you do not want to award commission for transactions where a coupon code is used then check this option.</p>
    </td></tr>  
                        
    </table>
    </div></div>

	<div class="postbox">
	<h3><label for="title">WP eMember Plugin Specific Settings</label></h3>
	<div class="inside">

    <br /><strong>Only use these options if you are using the <a href="http://www.tipsandtricks-hq.com/?p=1706" target="_blank">WP eMember Plugin</a></strong>
    <br /><br />

    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
    <tr valign="top"><td width="25%" align="left">
    Only Logged In Members Can Checkout 
    </td><td align="left">
    <input name="eStore_eMember_must_be_logged_to_checkout" type="checkbox"<?php 
    if (get_option('eStore_eMember_must_be_logged_to_checkout') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">When checked the plugin will not allow an anonymous user to continue shopping cart checkout unless the user logs in or registers for an account in eMember.</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    Redirection URL for Anonymous Checkout
    </td><td align="left">
    <input name="eStore_eMember_redirection_url_when_not_logged" type="text" size="100" value="<?php 
    echo get_option('eStore_eMember_redirection_url_when_not_logged');
    ?>
"/>
    <br /><p class="description">When an anonymous user clicks the "Checkout" button in the shopping cart, the user will be reditected to this URL requesting him/her to log in or register for an account.</p>
    </td></tr>        
    
    </table>
    </div></div>
    
<?php 
    if (function_exists('wp_lic_manager_install')) {
        ?>
	<div class="postbox">
	<h3><label for="title">WP License Manager Plugin Specific Settings</label></h3>
	<div class="inside">

    <br /><strong>Only use these options if you are using the <a href="http://www.tipsandtricks-hq.com/" target="_blank">WP License Manager Plugin</a></strong>
    <br /><br />

    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
    <tr valign="top"><td width="25%" align="left">
    License Creation POST URL 
    </td><td align="left">
    <input name="eStore_lic_mgr_post_url" type="text" size="100" value="<?php 
        echo get_option('eStore_lic_mgr_post_url');
        ?>
"/>
    <br /><p class="description">Get this value from the WP License Manager plugin's settings tab</p>
    </td></tr>

    <tr valign="top"><td width="25%" align="left">
    License Creation Secret Word
    </td><td align="left">
    <input name="eStore_lic_mgr_secret_word" type="text" size="50" value="<?php 
        echo get_option('eStore_lic_mgr_secret_word');
        ?>
"/>
    <br /><p class="description">Get this value from the WP License Manager plugin's settings tab</p>
    </td></tr>        
    
    </table>
    </div></div>
<?php 
    }
    ?>
    
	<div class="postbox">
	<h3><label for="title">WP eStore Download Manager Related</label></h3>
	<div class="inside">
	<?php 
    echo eStore_dlmgradm::settings_menu_html();
    ?>
	</div></div>
        
	<div class="postbox">
	<h3><label for="title">Amazon Web Services (AWS) Simple Storage Service (S3) Related (<a href="http://www.tipsandtricks-hq.com/ecommerce/?p=1101" target="_blank">Read Integration Details</a>)</label></h3>
	<div class="inside">
	<?php 
    echo eStore_as3tpadm::settings_menu_html();
    ?>
	</div></div>
        
	<div class="postbox">
	<h3><label for="title">reCAPTCHA Settings (If you want to use <a href="http://recaptcha.net/learnmore.html" target="_blank">reCAPTCHA</a> then you need to get reCAPTCHA API keys from <a href="http://recaptcha.net/whyrecaptcha.html" target="_blank">here</a> and use in the settings below)</label></h3>
	<div class="inside">
    <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">

    <tr valign="top"><td width="25%" align="left">
    Use reCAPTCHA
    </td><td align="left">
    <input name="wp_eStore_use_recaptcha" type="checkbox"<?php 
    if (get_option('wp_eStore_use_recaptcha') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
    <br /><p class="description">Check this box if you want to use <a href="http://recaptcha.net/learnmore.html" target="_blank">reCAPTCHA</a>.</p>
    </td></tr>
    <tr valign="top"><td width="25%" align="left">
    Public Key
    </td><td align="left">
    <input name="wp_eStore_captcha_public_key" type="text" size="100" value="<?php 
    echo get_option('wp_eStore_captcha_public_key');
    ?>
"/>
    <br /><p class="description">The public key for the reCAPTCHA API</p>
    </td></tr>  
    <tr valign="top"><td width="25%" align="left">
    Private Key
    </td><td align="left">
    <input name="wp_eStore_captcha_private_key" type="text" size="100" value="<?php 
    echo get_option('wp_eStore_captcha_private_key');
    ?>
"/>
    <br /><p class="description">The private key for the reCAPTCHA API</p>
    </td></tr>
    </table>
    </div></div>
            
    <div class="submit">
        <input type="submit" class="button-primary" name="info_update" value="<?php 
    _e('Update');
    ?>
 &raquo;" />
    </div>
    </form>
    <?php 
}
function eStore_apply_post_payment_dynamic_tags($string_to_process, $payment_data, $cart_items = '', $additional_data = '')
{
    //TODO - refactor and use this function from the post payment processing areas everywhere
    $wp_eStore_config = WP_eStore_Config::getInstance();
    //Counter for incremental receipt number
    $receipt_counter = $wp_eStore_config->getValue('eStore_custom_receipt_counter');
    eStore_payment_debug('Incremental counter value: ' . $receipt_counter, true);
    $download_url_life = get_option('eStore_download_url_life');
    $purchase_date = date("Y-m-d");
    $total_minus_total_tax = round($payment_data['mc_gross'] - $payment_data['mc_tax'], 2);
    $payment_data['mc_tax'] = round($payment_data['mc_tax'], 2);
    $txn_id = $payment_data['txn_id'];
    $buyer_shipping_info = $payment_data['address'];
    $buyer_phone = $payment_data['phone'];
    $product_key_data = $payment_data['product_key_data'];
    //Custom data
    $customvariables = get_custom_var($payment_data['custom']);
    $shipping_option = $customvariables['ship_option'];
    if (empty($shipping_option)) {
        $shipping_option = "Default";
    }
    $coupon_code = $customvariables['coupon'];
    //Item specific data
    if (empty($additional_data) && !empty($cart_items)) {
        $additional_data = array();
        $payment_currency = get_option('cart_payment_currency');
        $currency_symbol = get_option('cart_currency_symbol');
        foreach ($cart_items as $current_cart_item) {
            $additional_data['constructed_products_name'] .= $current_cart_item['item_name'] . ", ";
            $additional_data['constructed_products_price'] .= $current_cart_item['mc_gross'] . ", ";
            $additional_data['constructed_products_id'] .= $current_cart_item['item_number'] . ", ";
            eStore_payment_debug('Value of current cart item: ' . $current_cart_item['subs_product'], true);
            if (isset($current_cart_item['subs_product']) && $current_cart_item['subs_product'] == '1') {
                // this is a subscription item
                eStore_payment_debug('eStore_apply_post_payment_dynamic_tags() - Constructing product details for a subscription', true);
                $terms = "\n" . wp_eStore_get_subscription_summary_string($current_cart_item['item_number'], $current_cart_item['item_name'], $current_cart_item['mc_gross']);
                $additional_data['constructed_products_details'] .= $terms;
            } else {
                $additional_data['constructed_products_details'] .= "\n" . $current_cart_item['item_name'] . " x " . $current_cart_item['quantity'] . " - " . $currency_symbol . $current_cart_item['mc_gross'] . " (" . $payment_currency . ")";
                $tax_inc_price = eStore_get_tax_include_price_by_prod_id($current_cart_item['item_number'], $current_cart_item['mc_gross']);
                $additional_data['constructed_products_details_tax_inc'] .= "\n" . $current_cart_item['item_name'] . " x " . $current_cart_item['quantity'] . " - " . $currency_symbol . $tax_inc_price . " (" . $payment_currency . ")";
            }
        }
    }
    //The following code will be used for all online gateway checkout because they will pass the $additional_data value
    if (!empty($additional_data)) {
        $constructed_products_name = $additional_data['constructed_products_name'];
        $constructed_products_price = $additional_data['constructed_products_price'];
        $constructed_products_id = $additional_data['constructed_products_id'];
        $constructed_products_details = $additional_data['constructed_products_details'];
        $constructed_products_details_tax_inc = $additional_data['constructed_products_details_tax_inc'];
        $product_specific_instructions = $additional_data['product_specific_instructions'];
        $constructed_download_link = $additional_data['constructed_download_link'];
        $constructed_download_link_for_digital_item = $additional_data['constructed_download_link_for_digital_item'];
        $product_license_data = $additional_data['product_license_data'];
        //this is the license mgr key (not the normal serial key code)
    }
    $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($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, $constructed_products_details_tax_inc, $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);
    $string_to_process = str_replace($tags, $vals, $string_to_process);
    return $string_to_process;
}
function eStore_global_autoresponder_signup($firstname, $lastname, $emailaddress)
{
    global $wp_eStore_config;
    $wp_eStore_config = WP_eStore_Config::getInstance();
    if ($wp_eStore_config->getValue('eStore_use_new_aweber_integration') == '1') {
        if (get_option('eStore_enable_aweber_int') == 1) {
            eStore_payment_debug('Global AWeber list signup option is enabled.', true);
            $aweber_list = get_option('eStore_aweber_list_name');
            eStore_aweber_new_signup_user($aweber_list, $firstname, $lastname, $emailaddress);
        } else {
            eStore_payment_debug('Global AWeber list signup option is disabled. No global list signup will be performed.', true);
        }
    }
    if (get_option('eStore_enable_global_chimp_int') == 1) {
        eStore_payment_debug('Mailchimp integration is being used.', true);
        $api = eStore_get_chimp_api_new();
        $target_list_name = get_option('eStore_chimp_list_name');
        $retval = eStore_mailchimp_subscribe($api, $target_list_name, $firstname, $lastname, $emailaddress);
        eStore_payment_debug('MailChimp global list signup operation performed. Return value is: ' . $retval, true);
    }
    if (get_option('eStore_enable_global_getResponse_int') == 1) {
        eStore_payment_debug('GetResponse integration is being used.', true);
        $campaign_name = get_option('eStore_getResponse_campaign_name');
        eStore_payment_debug('GetResponse campaign to signup to:' . $campaign_name, true);
        $retval = eStore_getResponse_subscribe($campaign_name, $firstname, $lastname, $emailaddress);
        eStore_payment_debug('GetResponse global list signup operation performed. Return value is: ' . $retval, true);
    }
    if ($wp_eStore_config->getValue('eStore_use_global_generic_autoresponder_integration') == '1') {
        eStore_payment_debug('Generic global autoresponder integration is being used.', true);
        $list_email_address = $wp_eStore_config->getValue('eStore_generic_autoresponder_target_list_email');
        $result = eStore_generic_autoresponder_signup($firstname, $lastname, $emailaddress, $list_email_address);
        eStore_payment_debug('Generic autoresponder signup result: ' . $result, true);
    }
    // API call for plugins extending the global autoresponder signup
    $signup_data = array('firstname' => $firstname, 'lastname' => $lastname, 'email' => $emailaddress);
    do_action('eStore_global_autoresponder_signup', $signup_data);
}
function show_wp_digi_cart_settings_page()
{
    global $eStore_debug_manager;
    $wp_eStore_config = WP_eStore_Config::getInstance();
    if (isset($_POST['reset_logfiles'])) {
        // Reset the debug log files...
        $eStore_debug_manager->reset_logfiles();
        echo '<div id="message" class="updated fade"><p><strong>Debug log files have been reset!</strong></p></div>';
    }
    if (isset($_POST['info_update'])) {
        $error_msg = "";
        update_option('eStore_cart_language', (string) $_POST["eStore_cart_language"]);
        if (trim($_POST["cart_payment_currency"]) == "CAN") {
            $_POST["cart_payment_currency"] = "CAD";
        }
        update_option('cart_payment_currency', trim($_POST["cart_payment_currency"]));
        update_option('cart_currency_symbol', (string) $_POST["cart_currency_symbol"]);
        $wp_eStore_config->setValue('cart_currency_symbol', (string) $_POST["cart_currency_symbol"]);
        update_option('eStore_variation_add_symbol', trim(stripslashes($_POST["eStore_variation_add_symbol"])));
        //update_option('eStore_paypal_profile_shipping', ($_POST['eStore_paypal_profile_shipping']!='') ? 'checked="checked"':'' );
        update_option('eStore_products_per_page', (string) $_POST["eStore_products_per_page"]);
        //update_option('cart_paypal_email', (string)$_POST["cart_paypal_email"]);
        update_option('addToCartButtonName', trim($_POST["addToCartButtonName"]));
        update_option('soldOutImage', trim($_POST["soldOutImage"]));
        update_option('wp_eStore_widget_title', stripslashes((string) $_POST["wp_eStore_widget_title"]));
        update_option('wp_cart_title', stripslashes((string) $_POST["wp_cart_title"]));
        update_option('wp_cart_empty_text', (string) $_POST["wp_cart_empty_text"]);
        update_option('cart_return_from_paypal_url', trim($_POST["cart_return_from_paypal_url"]));
        update_option('cart_cancel_from_paypal_url', trim($_POST["cart_cancel_from_paypal_url"]));
        update_option('eStore_products_page_url', trim($_POST["eStore_products_page_url"]));
        update_option('eStore_display_continue_shopping', isset($_POST["eStore_display_continue_shopping"]) ? 'checked="checked"' : '');
        $wp_eStore_config->setValue('eStore_do_not_show_qty_in_cart', isset($_POST["eStore_do_not_show_qty_in_cart"]) ? 'checked="checked"' : '');
        update_option('eStore_checkout_page_url', trim($_POST["eStore_checkout_page_url"]));
        update_option('eStore_auto_checkout_redirection', isset($_POST["eStore_auto_checkout_redirection"]) ? 'checked="checked"' : '');
        update_option('eStore_auto_cart_anchor', isset($_POST["eStore_auto_cart_anchor"]) ? 'checked="checked"' : '');
        update_option('eStore_shopping_cart_image_hide', isset($_POST["eStore_shopping_cart_image_hide"]) ? 'checked="checked"' : '');
        update_option('eStore_show_t_c', isset($_POST["eStore_show_t_c"]) ? 'checked="checked"' : '');
        update_option('eStore_show_t_c_for_buy_now', isset($_POST["eStore_show_t_c_for_buy_now"]) ? 'checked="checked"' : '');
        update_option('eStore_show_t_c_for_squeeze_form', isset($_POST["eStore_show_t_c_for_squeeze_form"]) ? 'checked="checked"' : '');
        update_option('eStore_t_c_url', trim($_POST["eStore_t_c_url"]));
        update_option('eStore_show_compact_cart', isset($_POST["eStore_show_compact_cart"]) ? 'checked="checked"' : '');
        update_option('eStore_enable_fancy_redirection_on_checkout', isset($_POST["eStore_enable_fancy_redirection_on_checkout"]) ? 'checked="checked"' : '');
        $wp_eStore_config->setValue('eStore_enable_fancy_redirection_on_checkout', isset($_POST["eStore_enable_fancy_redirection_on_checkout"]) ? 'checked="checked"' : '');
        $wp_eStore_config->setValue('eStore_enable_save_retrieve_cart', isset($_POST["eStore_enable_save_retrieve_cart"]) ? '1' : '');
        $wp_eStore_config->setValue('eStore_enable_checkout_amt_limit', isset($_POST["eStore_enable_checkout_amt_limit"]) ? '1' : '');
        $min_cart_co_limit_amt = trim($_POST["eStore_checkout_amt_limit_minimum"]);
        if (!empty($min_cart_co_limit_amt) && !is_numeric($min_cart_co_limit_amt)) {
            $error_msg .= '<br />The Minimum Checkout Amount limitation value must be a numeric number! Please check the value of this field again.';
        }
        $wp_eStore_config->setValue('eStore_checkout_amt_limit_minimum', $min_cart_co_limit_amt);
        $max_cart_co_limit_amt = trim($_POST["eStore_checkout_amt_limit_maximum"]);
        if (!empty($max_cart_co_limit_amt) && !is_numeric($max_cart_co_limit_amt)) {
            $error_msg .= '<br />The Maximum Checkout Amount limitation value must be a numeric number! Please check the value of this field again.';
        }
        $wp_eStore_config->setValue('eStore_checkout_amt_limit_maximum', $max_cart_co_limit_amt);
        update_option('eStore_enable_lightbox_effect', isset($_POST["eStore_enable_lightbox_effect"]) ? 'checked="checked"' : '');
        update_option('eStore_enable_smart_thumb', isset($_POST["eStore_enable_smart_thumb"]) ? '1' : '');
        update_option('eStore_base_shipping', trim($_POST["eStore_base_shipping"]));
        update_option('eStore_shipping_variation', trim($_POST["eStore_shipping_variation"]));
        update_option('eStore_always_display_shipping_variation', isset($_POST["eStore_always_display_shipping_variation"]) ? '1' : '');
        $wp_eStore_config->setValue('eStore_enable_store_pickup', isset($_POST["eStore_enable_store_pickup"]) ? '1' : '');
        update_option('eStore_enable_tax', isset($_POST["eStore_enable_tax"]) ? 'checked="checked"' : '');
        update_option('eStore_global_tax_rate', (string) $_POST["eStore_global_tax_rate"]);
        $wp_eStore_config->setValue('eStore_enable_tax_on_shipping', isset($_POST["eStore_enable_tax_on_shipping"]) ? '1' : '');
        $wp_eStore_config->setValue('eStore_show_tax_inclusive_price', isset($_POST["eStore_show_tax_inclusive_price"]) ? '1' : '');
        update_option('eStore_secondary_currency_code', trim($_POST["eStore_secondary_currency_code"]));
        update_option('eStore_secondary_currency_symbol', (string) $_POST["eStore_secondary_currency_symbol"]);
        update_option('eStore_secondary_currency_conversion_rate', (string) $_POST["eStore_secondary_currency_conversion_rate"]);
        update_option('eStore_random_code', trim(stripslashes($_POST["eStore_random_code"])));
        update_option('eStore_download_url_life', trim($_POST["eStore_download_url_life"]));
        update_option('eStore_download_url_limit_count', trim($_POST["eStore_download_url_limit_count"]));
        //update_option('eStore_download_enable_ip_address_lock', ($_POST['eStore_download_enable_ip_address_lock']=='1') ? '1':'' );
        update_option('eStore_download_script', trim($_POST["eStore_validation_sc_url"]));
        $wp_eStore_config->setValue('eStore_auto_shorten_dl_links', isset($_POST["eStore_auto_shorten_dl_links"]) ? '1' : '');
        $wp_eStore_config->setValue('eStore_product_price_must_be_zero_for_free_download', isset($_POST["eStore_product_price_must_be_zero_for_free_download"]) ? '1' : '');
        update_option('eStore_auto_product_delivery', isset($_POST["eStore_auto_product_delivery"]) ? 'checked="checked"' : '');
        update_option('eStore_display_tx_result', isset($_POST["eStore_display_tx_result"]) ? 'checked="checked"' : '');
        update_option('eStore_strict_email_check', isset($_POST["eStore_strict_email_check"]) ? 'checked="checked"' : '');
        update_option('eStore_auto_customer_removal', isset($_POST["eStore_auto_customer_removal"]) ? 'checked="checked"' : '');
        // Update debug manager related settings...
        eStore_dbgmgradm::settings_menu_post($_POST['eStore_cart_enable_debug'], $_POST['eStore_cart_enable_sandbox']);
        $wp_eStore_config->saveConfig();
        wp_eStore_clear_cache();
        if (!empty($error_msg)) {
            echo '<div id="message" class="error">';
            echo $error_msg;
            echo '<br /><br /></div>';
        }
        echo '<div id="message" class="updated fade">';
        echo '<p><strong>Options Updated!</strong></p></div>';
    }
    $cart_language = get_option('eStore_cart_language');
    if (empty($cart_language)) {
        $cart_language = 'eng.php';
    }
    $defaultCurrency = get_option('cart_payment_currency');
    if (empty($defaultCurrency)) {
        $defaultCurrency = 'USD';
    }
    $eStore_variation_add_symbol = get_option('eStore_variation_add_symbol');
    if (empty($eStore_variation_add_symbol)) {
        $eStore_variation_add_symbol = '+';
    }
    $defaultSymbol = get_option('cart_currency_symbol');
    if (empty($defaultSymbol)) {
        $defaultSymbol = '$';
    }
    $eStore_products_per_page = get_option('eStore_products_per_page');
    if (empty($eStore_products_per_page)) {
        $eStore_products_per_page = '20';
    }
    //$notify_url =  get_option('eStore_notify_url');
    $return_url = get_option('cart_return_from_paypal_url');
    $cancel_url = get_option('cart_cancel_from_paypal_url');
    $eStore_products_page_url = get_option('eStore_products_page_url');
    $eStore_checkout_page_url = get_option('eStore_checkout_page_url');
    $addcart = get_option('addToCartButtonName');
    if (empty($addcart)) {
        $addcart = 'Add to Cart';
    }
    $soldOut = get_option('soldOutImage');
    if (empty($soldOut)) {
        $soldOut = WP_ESTORE_URL . '/images/sold_out.png';
    }
    $title = get_option('wp_cart_title');
    //if (empty($title)) $title = 'Your Shopping Cart';
    $widget_title = get_option('wp_eStore_widget_title');
    $emptyCartText = get_option('wp_cart_empty_text');
    if (get_option('eStore_display_continue_shopping')) {
        $eStore_display_continue_shopping = 'checked="checked"';
    } else {
        $eStore_display_continue_shopping = '';
    }
    if ($wp_eStore_config->getValue('eStore_do_not_show_qty_in_cart')) {
        $eStore_do_not_show_qty_in_cart = 'checked="checked"';
    } else {
        $eStore_do_not_show_qty_in_cart = '';
    }
    if (get_option('eStore_auto_checkout_redirection')) {
        $eStore_auto_checkout_redirection = 'checked="checked"';
    } else {
        $eStore_auto_checkout_redirection = '';
    }
    if (get_option('eStore_auto_cart_anchor')) {
        $eStore_cart_anchor = 'checked="checked"';
    } else {
        $eStore_cart_anchor = '';
    }
    if (get_option('eStore_shopping_cart_image_hide')) {
        $eStore_cart_image_hide = 'checked="checked"';
    } else {
        $eStore_cart_image_hide = '';
    }
    if (get_option('eStore_show_t_c')) {
        $eStore_show_t_c = 'checked="checked"';
    } else {
        $eStore_show_t_c = '';
    }
    if (get_option('eStore_show_t_c_for_buy_now')) {
        $eStore_show_t_c_for_buy_now = 'checked="checked"';
    } else {
        $eStore_show_t_c_for_buy_now = '';
    }
    if (get_option('eStore_show_t_c_for_squeeze_form')) {
        $eStore_show_t_c_for_squeeze_form = 'checked="checked"';
    } else {
        $eStore_show_t_c_for_squeeze_form = '';
    }
    $eStore_t_c_url = get_option('eStore_t_c_url');
    if (get_option('eStore_show_compact_cart')) {
        $eStore_show_compact_cart = 'checked="checked"';
    } else {
        $eStore_show_compact_cart = '';
    }
    if (get_option('eStore_enable_fancy_redirection_on_checkout')) {
        $eStore_enable_fancy_redirection_on_checkout = 'checked="checked"';
    } else {
        $eStore_enable_fancy_redirection_on_checkout = '';
    }
    if ($wp_eStore_config->getValue('eStore_enable_save_retrieve_cart') == '1') {
        $eStore_enable_save_retrieve_cart = 'checked="checked"';
    } else {
        $eStore_enable_save_retrieve_cart = '';
    }
    if ($wp_eStore_config->getValue('eStore_enable_checkout_amt_limit') == '1') {
        $eStore_enable_checkout_amt_limit = 'checked="checked"';
    } else {
        $eStore_enable_checkout_amt_limit = '';
    }
    if (get_option('eStore_enable_lightbox_effect')) {
        $eStore_enable_lightbox_effect = 'checked="checked"';
    } else {
        $eStore_enable_lightbox_effect = '';
    }
    if (get_option('eStore_enable_smart_thumb')) {
        $eStore_enable_smart_thumb = 'checked="checked"';
    } else {
        $eStore_enable_smart_thumb = '';
    }
    $baseShipping = get_option('eStore_base_shipping');
    if (empty($baseShipping)) {
        $baseShipping = '0';
    }
    $shippingVar = get_option('eStore_shipping_variation');
    if (get_option('eStore_always_display_shipping_variation') != '') {
        $always_display_shipping_var = ' checked="checked"';
    } else {
        $always_display_shipping_var = '';
    }
    $enable_store_pickup = $wp_eStore_config->getValue('eStore_enable_store_pickup');
    if ($enable_store_pickup) {
        $enable_store_pickup = ' checked="checked"';
    } else {
        $enable_store_pickup = '';
    }
    if (get_option('eStore_enable_tax')) {
        $eStore_enable_tax = 'checked="checked"';
    } else {
        $eStore_enable_tax = '';
    }
    if ($wp_eStore_config->getValue('eStore_enable_tax_on_shipping') == '1') {
        $eStore_enable_tax_on_shipping = 'checked="checked"';
    } else {
        $eStore_enable_tax_on_shipping = '';
    }
    if ($wp_eStore_config->getValue('eStore_show_tax_inclusive_price') == '1') {
        $eStore_show_tax_inclusive_price = 'checked="checked"';
    } else {
        $eStore_show_tax_inclusive_price = '';
    }
    if (get_option('eStore_auto_product_delivery')) {
        $eStore_auto_delivery = 'checked="checked"';
    } else {
        $eStore_auto_delivery = '';
    }
    $eStore_random_code = get_option('eStore_random_code');
    if (empty($eStore_random_code)) {
        $eStore_random_code = 'AZ#Ui$335UBSD)AminOc32j90';
    }
    $eStore_download_url_limit_count = get_option('eStore_download_url_limit_count');
    //if (empty($eStore_download_url_limit_count)) $eStore_download_url_limit_count = '3';
    $eStore_download_url_life = get_option('eStore_download_url_life');
    if (empty($eStore_download_url_life)) {
        $eStore_download_url_life = '24';
    }
    $eStore_download_script = get_option('eStore_download_script');
    if (empty($eStore_download_script)) {
        $eStore_download_script = WP_ESTORE_URL . "/";
        update_option('eStore_download_script', $eStore_download_script);
    }
    if ($wp_eStore_config->getValue('eStore_auto_shorten_dl_links') == '1') {
        $eStore_auto_shorten_dl_links = 'checked="checked"';
    } else {
        $eStore_auto_shorten_dl_links = '';
    }
    if ($wp_eStore_config->getValue('eStore_product_price_must_be_zero_for_free_download') == '1') {
        $eStore_product_price_must_be_zero_for_free_download = 'checked="checked"';
    } else {
        $eStore_product_price_must_be_zero_for_free_download = '';
    }
    if (get_option('eStore_strict_email_check')) {
        $eStore_strict_email_check = 'checked="checked"';
    } else {
        $eStore_strict_email_check = '';
    }
    if (get_option('eStore_auto_customer_removal')) {
        $eStore_auto_customer_removal = 'checked="checked"';
    } else {
        $eStore_auto_customer_removal = '';
    }
    if (get_option('eStore_display_tx_result')) {
        $eStore_display_tx_result = 'checked="checked"';
    } else {
        $eStore_display_tx_result = '';
    }
    ?>
 	

	<div class="eStore_grey_box">
 	<p>For information, updates and detailed documentation, please visit the <a href="http://www.tipsandtricks-hq.com/ecommerce/wp-estore-documentation" target="_blank">WP eStore Documentation</a> or
    the main plugin page <a href="http://www.tipsandtricks-hq.com/?p=1059" target="_blank">WP eStore</a></p>
    </div>

	<div class="postbox">
	<h3><label for="title">Quick Usage Guide</label></h3>
	<div class="inside">

	<p><strong>1.</strong> WP eStore has a lot of setting options but don't get intimidated by it. Most of the default settings are good to get you started (keep things simple at first). Remember to watch the video tutorials from our documentation.</p>
	<p><strong>2.</strong> First add products to the database through the 'Add/Edit Products' interface. Products can be modified through the 'Manage Products' interface.</p>
    <p><strong>3.</strong> To add an 'Add to Cart' button simply add the shortcode <strong>[wp_eStore_add_to_cart id=PRODUCT-ID]</strong> on your landing page of a product. Replace PRODUCT-ID with the actual product id (example: [wp_eStore_add_to_cart id=1] ). Product IDs for all your products can be found in the 'Manage Products' section</p>
	<p><strong>4.</strong> To add the shopping cart to a post or page (example: a checkout page) simply add the shortcode <strong>[wp_eStore_cart]</strong> to the post or page. You can also use the shortcode in a text widget to add the shopping cart to the sidebar.</p>
	<p>Check out the <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=460" target="_blank">shortcodes and function reference page</a> for a full list of usable shortcodes.</p>
    <p>Like the plugin? Give us a <a href="http://www.tipsandtricks-hq.com/?p=1059#gfts_share" target="_blank">thumbs up here</a> by clicking on a share button.</p>
	
    </div></div>
    
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">

 	<?php 
    // Compute the $wp_home_dir configuration hint.
    // -- The Assurer
    $wp_home_dir = '';
    $current_eStore_script_filepath_parts = explode('/', $_SERVER['PHP_SELF']);
    while ($current_eStore_script_filepath_parts[0] != 'wp-admin' and count($current_eStore_script_filepath_parts) > 1) {
        $wp_home_dir .= '/' . array_shift($current_eStore_script_filepath_parts);
    }
    $wp_home_dir = trim($wp_home_dir, '/');
    echo '
	<div class="postbox">
	<h3><label for="title">General eStore Settings</label></h3>
	<div class="inside">';
    echo '
<table class="form-table">';
    ?>
<tr valign="top">
<th scope="row">Language</th>
<td>
<select name="eStore_cart_language">
<option value="eng.php" <?php 
    if ($cart_language == "eng.php") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "English";
    ?>
</option>
<option value="i18n.php" <?php 
    if ($cart_language == "i18n.php") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "i18n";
    ?>
</option>
<option value="ita.php" <?php 
    if ($cart_language == "ita.php") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "Italian";
    ?>
</option>
<option value="spa.php" <?php 
    if ($cart_language == "spa.php") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "Spanish";
    ?>
</option>
<option value="cat.php" <?php 
    if ($cart_language == "cat.php") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "Catalan";
    ?>
</option>
<option value="ger.php" <?php 
    if ($cart_language == "ger.php") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "German";
    ?>
</option>
<option value="nld.php" <?php 
    if ($cart_language == "nld.php") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "Dutch";
    ?>
</option>
<option value="fr.php" <?php 
    if ($cart_language == "fr.php") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "French";
    ?>
</option>
<option value="heb.php" <?php 
    if ($cart_language == "heb.php") {
        echo 'selected="selected"';
    }
    ?>
><?php 
    echo "Hebrew";
    ?>
</option>
</select>
<p class="description">Select a language that you want your shopping cart to be displayed in (Contact us for other language options).</p>
</td></tr>
<?php 
    echo '
<tr valign="top">
<th scope="row">Currency Code</th>
<td><input type="text" name="cart_payment_currency" value="' . $defaultCurrency . '" size="4" /><span class="description"> (example: USD, CAD, EUR, GBP, AUD)</span></td>
</tr>

<tr valign="top">
<th scope="row">Currency Symbol</th>
<td><input type="text" name="cart_currency_symbol" value="' . $defaultSymbol . '" size="4" /><span class="description"> (example: $, &#163;, &#8364;)</span>
</td>
</tr>

<tr valign="top">
<th scope="row">Variation Addition Symbol</th>
<td><input type="text" name="eStore_variation_add_symbol" value="' . $eStore_variation_add_symbol . '" size="4" /><span class="description"> (example: +, add) </span>
<br /><p class="description">This only applies to variation control display. By default, the plus (+) sign is used as the add symbol for your variations. You can however customize it to use any character or word for display purpose (for example: you can use the word "add"). 
<a href="http://www.tipsandtricks-hq.com/ecommerce/?p=345" target="_blank">Read More on Variation Control</a></p>
</td>
</tr>

<tr valign="top">
<th scope="row">Terms & Conditions Page URL</th>
<td><input type="text" name="eStore_t_c_url" value="' . $eStore_t_c_url . '" size="70" /><br />
<p class="description">The URL of your Terms and Conditions page if you have one.</p>
</td>
</tr>

<tr valign="top">
<th scope="row">Show Terms & Conditions Checkbox</th>
<td>
<input type="checkbox" name="eStore_show_t_c" value="1" ' . $eStore_show_t_c . ' /> For Shopping Cart (Add to Cart Type Buttons)
<br /><input type="checkbox" name="eStore_show_t_c_for_buy_now" value="1" ' . $eStore_show_t_c_for_buy_now . ' /> For Buy Now and Subscription Type Buttons
<br /><input type="checkbox" name="eStore_show_t_c_for_squeeze_form" value="1" ' . $eStore_show_t_c_for_squeeze_form . ' /> For Free Download Squeeze Forms
<br /><p class="description">If checked the customers will have to agree to the Terms and Conditions before they can make a purchase.</p></td>
</tr>

<tr valign="top">
<th scope="row">Enable Lightbox effect on Images</th>
<td><input type="checkbox" name="eStore_enable_lightbox_effect" value="1" ' . $eStore_enable_lightbox_effect . ' />
<br /><p class="description">Check this if you want lightbox effect on the product thumbnail images.</p></td>
</tr>

<tr valign="top">
<th scope="row">Enable Smart Thumbnail Option</th>
<td><input type="checkbox" name="eStore_enable_smart_thumb" value="1" ' . $eStore_enable_smart_thumb . ' />
<br /><p class="description">If your product thumbnail images look a little bit squashed then check this option which will take a snapshot of a square section (fit for the thumbnail area) from the image. The thumbnail images must be stored on the same server that this eStore plugin is installed on (not an external server) for this option to work.</p></td>
</tr>

<tr valign="top">
<th scope="row">Products Per Page Limit</th>
<td><input type="text" name="eStore_products_per_page" value="' . $eStore_products_per_page . '" size="4" /> (example: 20) 
<br /><p class="description">This number is used for pagination purpose. This is the number of products that will be displayed per page when displaying the full list of products on a page.</p></td>
</tr>

</table>
</div></div>

<div class="postbox">
<h3><label for="title">General Image and Page URL Settings</label></h3>
<div class="inside">
<table class="form-table">

<tr valign="top">
<th scope="row">Add to Cart Button Text or Image</th>
<td><input type="text" name="addToCartButtonName" value="' . $addcart . '" size="100" />
<br /><p class="description">To use a customized image as the button, simply enter the URL of the image file in the above field. For example, <code>http://example.com/my-images/add-button.jpg</code>
<br />You can specify a customized button image for a particular product from the Add/Edit products menu.</p>
</td>
</tr>

<tr valign="top">
<th scope="row">Sold Out Button Text or Image URL</th>
<td><input type="text" name="soldOutImage" value="' . $soldOut . '" size="100" />
<br /><p class="description">When selling limited copies of a product, this image will be shown instead of the payment button when the product is sold out. You can also use a text in the above field (example text: Sold Out).</p></td>
</tr>

<tr valign="top">
<th scope="row">Products/Store Page URL</th>
<td><input type="text" name="eStore_products_page_url" value="' . $eStore_products_page_url . '" size="100" />
<br /><p class="description">If used, the shopping cart widget will display a link to this page when the cart is empty. Leave empty if you do not have a store or products page.</p></td>
</tr>

<tr valign="top">
<th scope="row">Return URL</th>
<td><input type="text" name="cart_return_from_paypal_url" value="' . $return_url . '" size="100" />
<br /><p class="description">This is the URL the customer will be redirected to after a successful payment. Enter the URL of your Thank You page here.</p></td>
</tr>

<tr valign="top">
<th scope="row">Cancel URL</th>
<td><input type="text" name="cart_cancel_from_paypal_url" value="' . $cancel_url . '" size="100" />
<br /><p class="description">The customer will be redirected to the above page if the payment is cancelled.</p></td>
</tr>

</table>
</div></div>

<div class="postbox">
<h3><label for="title">Shopping Cart Specific Settings</label></h3>
<div class="inside">
<table class="form-table">

<tr valign="top">
<th scope="row">Shopping Cart Widget Title</th>
<td><input type="text" name="wp_eStore_widget_title" value="' . $widget_title . '" size="50" /></td>
</tr>

<tr valign="top">
<th scope="row">Shopping Cart Header</th>
<td><input type="text" name="wp_cart_title" value="' . $title . '" size="50" />
<br /><p class="description">Leave empty if you do not want the shopping cart header to appear</p></td>
</tr>

<tr valign="top">
<th scope="row">Text or Image to Show When the Cart is Empty</th>
<td><input type="text" name="wp_cart_empty_text" value="' . $emptyCartText . '" size="100" />
<br /><p class="description">To use a customized image for the empty cart display instead of a plain text, simply enter the URL of the image file in the above field.</p></td>
</tr>

<tr valign="top">
<th scope="row">Display Continue Shopping Link</th>
<td><input type="checkbox" name="eStore_display_continue_shopping" value="1" ' . $eStore_display_continue_shopping . ' />
<br /><p class="description">If checked the shopping cart will display a continue shopping link. There must be a URL in the "Products Page" field for this to work.</p></td>
</tr>

<tr valign="top">
<th scope="row">Do Not Show Quantity in Shopping Cart</th>
<td><input type="checkbox" name="eStore_do_not_show_qty_in_cart" value="1" ' . $eStore_do_not_show_qty_in_cart . ' />
<br /><p class="description">Check this if you do not want the shopping cart to display the product quantity. Your customer can only add one copy of the product to the shopping cart. Can be helpful if you are only selling digital products and you do not want your customers to buy multiple copies of a product.</p></td>
</tr>

<tr valign="top">
<th scope="row">Checkout Page</th>
<td><input type="text" name="eStore_checkout_page_url" value="' . $eStore_checkout_page_url . '" size="100" />
<p class="description">You can optionally create a specific checkout page for eStore if you want. <a href="http://www.tipsandtricks-hq.com/forum/topic/how-to-create-a-specific-checkout-page-for-estore" target="_blank">More Details Here</a></p>
</td>
</tr>

<tr valign="top">
<th scope="row">Automatic redirection to checkout page</th>
<td><input type="checkbox" name="eStore_auto_checkout_redirection" value="1" ' . $eStore_auto_checkout_redirection . ' />
<br /><p class="description">If checked the visitor will be redirected to the Checkout page after a product is added to the cart. You must enter a URL in the Checkout Page field for this to work.</p></td>
</tr>

<tr valign="top">
<th scope="row">Allow Shopping Cart Anchor</th>
<td><input type="checkbox" name="eStore_auto_cart_anchor" value="1" ' . $eStore_cart_anchor . ' />
<br /><p class="description">If checked the visitor will be taken to the Shopping cart anchor point within the page after a product Add, Delete or Quantity Change.</p></td>
</tr>

<tr valign="top">
<th scope="row">Hide Shopping Cart Image</th>
<td><input type="checkbox" name="eStore_shopping_cart_image_hide" value="1" ' . $eStore_cart_image_hide . ' />
<br /><p class="description">If checked the shopping cart image in the title will not be shown.</p></td>
</tr>

<tr valign="top">
<th scope="row">Show Compact Cart in Widget</th>
<td><input type="checkbox" name="eStore_show_compact_cart" value="1" ' . $eStore_show_compact_cart . ' /> 
<br /><p class="description">If checked the shopping cart displayed in the sidebar widget will display only the number of items in the cart instead of the full item listing. Useful for sites with narrow sidebar.</p></td>
</tr>

<tr valign="top">
<th scope="row">Enable Fancy Redirection On Checkout</th>
<td><input type="checkbox" name="eStore_enable_fancy_redirection_on_checkout" value="1" ' . $eStore_enable_fancy_redirection_on_checkout . ' /> 
<br /><p class="description">This feature requires WordPress 3.0, if this option conflicts with other plugin(s) then simply uncheck this option. If checked the redirection to the payment page will be displayed using a fancy JQuery effect. If unchecked it will redirect using the standard method.</p></td>
</tr>

<tr valign="top">
<th scope="row">Enable Save and Retrieve Cart Feature</th>
<td><input type="checkbox" name="eStore_enable_save_retrieve_cart" value="1" ' . $eStore_enable_save_retrieve_cart . ' /> 
<br /><p class="description">If enabled your customers will be able to save the content of their cart and retrieve it at a later time and continue shopping.</p></td>
</tr>

<tr valign="top">
<th scope="row">Enable Checkout Amount Limitations (optional)</th>
<td>
<input type="checkbox" name="eStore_enable_checkout_amt_limit" value="1" ' . $eStore_enable_checkout_amt_limit . ' />
<span class="description">Only enable this option if you want to impose a checkout amount limitation in the shopping cart. For example: only allow a customer to checkout if the minimum amount in the cart is more than $20.00</span>
<br />' . $defaultSymbol . ' <input type="text" name="eStore_checkout_amt_limit_minimum" value="' . $wp_eStore_config->getValue('eStore_checkout_amt_limit_minimum') . '" size="5" /> Minimum Checkout Amount (Example: 20.00)
<br />' . $defaultSymbol . ' <input type="text" name="eStore_checkout_amt_limit_maximum" value="' . $wp_eStore_config->getValue('eStore_checkout_amt_limit_maximum') . '" size="5" /> Maximum Checkout Amount (Example: 99.00)
<br /><p class="description">You can enter a value in one of the above fields or both</p>
</td>
</tr>

</table>
</div></div>

	<div class="postbox">
	<h3><label for="title">Shipping & Tax Related Settings</label></h3>
	<div class="inside">
	
<table class="form-table">	
<tr valign="top">
<th scope="row">Base Shipping Cost</th>
<td><input type="text" name="eStore_base_shipping" value="' . $baseShipping . '" size="2" /> 
<span class="description">(Example: 5.00) Used for non digital Products. This amount is added to the total of the individual products shipping cost. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=50" target="_blank">Read More Here</a></span></td>
</tr>

<tr valign="top">
<th scope="row">Shipping Variation Option</th>
<td><textarea name="eStore_shipping_variation" cols="83" rows="2">' . $shippingVar . '</textarea>
<br /><p class="description">Can be used to offer shipping variation option to customers. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=1056" target="_blank">Read More Here</a></p></td>
</tr>

<tr valign="top">
<th scope="row">Always Display Shipping Variation</th>
<td><input type="checkbox" name="eStore_always_display_shipping_variation" value="1" ' . $always_display_shipping_var . ' />
<br /><p class="description">If you want to display the shipping variation in the cart all the time then check this field. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=1056#when_to_use_always_display_shipping_var" target="_blank">Read More Here</a></p></td>
</tr>

<tr valign="top">
<th scope="row">Enable Store Pickup</th>
<td><input type="checkbox" name="eStore_enable_store_pickup" value="1" ' . $enable_store_pickup . ' />
<br /><p class="description">Check this option if you want to allow your users to be able to pick up from your store. When this is enabled, the users will be able to choose to pickup the items from the store. In that case the cart will not charge any shipping.</p></td>
</tr>

<tr valign="top">
<th scope="row">Calculate Tax</th>
<td><input type="checkbox" name="eStore_enable_tax" value="1" ' . $eStore_enable_tax . ' /> Enables tax calculation
<br />Tax Rate <input type="text" name="eStore_global_tax_rate" value="' . get_option('eStore_global_tax_rate') . '" size="2" />% 
<p class="description">Enter the tax rate in the above field (Example: 10). You can override the tax rate of an individual item by editing the product. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=916" target="_blank">Read More Here</a></p>
<input type="checkbox" name="eStore_enable_tax_on_shipping" value="1" ' . $eStore_enable_tax_on_shipping . ' /> Calculate Tax on Shipping Amount
<p class="description">If you want to add tax on the shipping amount then check this option.</p>
<input type="checkbox" name="eStore_show_tax_inclusive_price" value="1" ' . $eStore_show_tax_inclusive_price . ' /> Show Tax Inclusive Amount
<p class="description">The tax amount is shown separately in the shopping cart by default (this is the popular choice). However, If you want to show tax inclusive amount for each product then check this option.</p>
</td>
</tr>

</table>
</div></div>

	<div class="postbox">
	<h3><label for="title">Secondary Currency Settings (This is for Display Purpose Only)</label></h3>
	<div class="inside">
<i>&nbsp;&nbsp;If you want to display the price of your products in a secondary currency side by side with your primary currency then use this section otherwise leave the fields empty.</i>	

<table class="form-table">	
<tr valign="top">
<th scope="row">Secondary Currency Code </th>
<td><input type="text" name="eStore_secondary_currency_code" value="' . get_option('eStore_secondary_currency_code') . '" size="3" /> 
<span class="description"> (e.g. USD, EUR, GBP, AUD)</span</td>
</tr>

<tr valign="top">
<th scope="row">Secondary Currency Symbol </th>
<td><input type="text" name="eStore_secondary_currency_symbol" value="' . get_option('eStore_secondary_currency_symbol') . '" size="3" /> 
<span class="description"> (e.g. $, &#163;, &#8364;)</span></td>
</tr>

<tr valign="top">
<th scope="row">Conversion Rate</th>
<td><input type="text" name="eStore_secondary_currency_conversion_rate" value="' . get_option('eStore_secondary_currency_conversion_rate') . '" size="3" /> 
<br /><p class="description">Conversion rate for the primary to secondary currency. For example if your primary currency is USD and the secondary currency is EUR then a rough conversion rate would be .775</p></td>
</tr>

</table>
</div></div>

	<div class="postbox">
	<h3><label for="title">Digital Product Delivery Settings</label></h3>
	<div class="inside">		
		
<table class="form-table">
<tr valign="top">
<th scope="row">Random Code</th>
<td><input type="text" name="eStore_random_code" value="' . $eStore_random_code . '" size="70" />
<br /><p class="description">This Random code is used as a key to generate the encrypted download link for your downloadable products. Change it to something random.</p></td>
</tr>

<tr valign="top">
<th scope="row">Duration of Download Link</th>
<td><input type="text" name="eStore_download_url_life" value="' . $eStore_download_url_life . '" size="3" /> Hours
<br /><p class="description">This is the duration of time the encrypted links will remain active. After this amount of time the link will expire.</p></td>
</tr>
	
<tr valign="top">
<th scope="row">Download Limit Count</th>
<td><input type="text" name="eStore_download_url_limit_count" value="' . $eStore_download_url_limit_count . '" size="3" /> Times
<br /><p class="description">Number of times an item can be downloaded before the link expires. Leave empty or set a high value (e.g. 999) if you do not want to limit downloads by download count.</p></td>
</tr>

<tr valign="top">
<th scope="row">Download Validation Script Location</th>
<td><input type="text" name="eStore_validation_sc_url" value="' . $eStore_download_script . '" size="100" />
<br /><p class="description">You do not need to change this value unless you want to customize this. Can be used to customize the download URL <a href="http://tipsandtricks-hq.com/ecommerce/?p=224" target="_blank">Read More Here</a>.<br>Configuration hint for the custom_download.php file is --> <font style="background-color:#ffff66">$wp_home_dir = \'' . $wp_home_dir . '\';</font></p>';
    $dl_script_file_path = $eStore_download_script . 'download.php';
    if (!file_exists(eStore_dlfilepath::absolute_from_url($dl_script_file_path))) {
        echo '<br><strong><font color=#ff0000>ADVISORY: If you changed the download validation script location, please remember to install a customized version of download.php as per the above instructions.</font></strong>';
        echo '  Note: If you are using a subdomain for the download validation script location, that is different from that of the eStore plugin, this message may be a false positive.  But just to be sure, please double check your work, before ignoring this message.';
    }
    if (!file_exists('../wp-content/plugins/wp-cart-for-digital-products/download.php')) {
        echo '<br>i<strong><font color=#ff0000>WARNING: Cannot locate file download.php in the eStore plugin directory.</font></strong>';
    }
    echo '</td>
</tr>

<tr valign="top">
<th scope="row">Shorten Encrypted Download Links</th>
<td><input type="checkbox" name="eStore_auto_shorten_dl_links" value="1" ' . $eStore_auto_shorten_dl_links . ' />
<br /><p class="description">Use this option if you want to automatically shorten the encrypted download links/URLs using Google URL shortener service. The encrypted download links will look like the following when you use this feature.
<br /><code>http://goo.gl/bV9Z1</code>
</p></td>
</tr>

<tr valign="top">
<th scope="row">Enforce Zero Price Checking on Free Product Download</th>
<td><input type="checkbox" name="eStore_product_price_must_be_zero_for_free_download" value="1" ' . $eStore_product_price_must_be_zero_for_free_download . ' />
<br /><p class="description">Enabling this option will add an extra security check in eStore before free downloads are given to the users (example: via a squeeze form). It will make sure that the product has a price value of zero (0.00) before offering the download.</p></td>
</tr>

</table>
</div></div>

	<div class="postbox">
	<h3><label for="title">Post Payment Processing Settings</label></h3>
	<div class="inside">	
<table class="form-table">
<tr valign="top">
<th scope="row">Use Automatic Post Payment Processing</th>
<td><input type="checkbox" name="eStore_auto_product_delivery" value="1" ' . $eStore_auto_delivery . ' />
<br /><p class="description">If checked the plugin will perform the post payment processing after every purchase. This option must be checked if you want certain functionality eg. automatically send emails after purchase, award affiliate commission automatically if you are using the affiliate platform plugin etc.</p></td>
</tr>

<tr valign="top">
<th scope="row">Use Strict PayPal Email Address Checking</th>
<td><input type="checkbox" name="eStore_strict_email_check" value="1" ' . $eStore_strict_email_check . ' />
<br /><p class="description">If checked the script will check to make sure that the PayPal email address specified is the same as the account where the payment was deposited (Usage of PayPal Email Alias will fail too).</p></td>
</tr>

<tr valign="top">
<th scope="row">Use Automatic Customer Record Removal</th>
<td><input type="checkbox" name="eStore_auto_customer_removal" value="1" ' . $eStore_auto_customer_removal . ' />
<br /><p class="description">If checked the plugin will delete a customer record from the customer database when a refund is issued.</p></td>
</tr>

<tr valign="top">
<th scope="row">Enable Transaction Result Display</th>
<td><input type="checkbox" name="eStore_display_tx_result" value="1" ' . $eStore_display_tx_result . ' />
<br /><p class="description">Check this if you want to display the transaction result containing the product delivery message on a post-payment return page (eg. a Thank You page). This allows the customer to be able to download the Digital goods via an encrypted link from this page instantly. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=499" target="_blank">Learn How To</a></p></td>
</tr>
</table>
		
</div></div>
		
<div class="postbox">
<h3><label for="title">Email Settings</label></h3>
<div class="inside">					
<p>The email settings fields have been <a href="admin.php?page=wp_eStore_settings&settings_action=email" target="_blank">moved here</a></p>
</div></div>
		
	<div class="postbox">
	<h3><label for="title">Testing and Debugging Settings</label></h3>
	<div class="inside">' . eStore_dbgmgradm::settings_menu_html() . '</div></div>
    
    <div class="submit">
        <input type="submit" class="button-primary" name="info_update" value="Update Options &raquo;" />
    </div>

 </form><p></p> 
 ';
}
function eStore_get_store_action_page_obj()
{
    $wp_eStore_config = WP_eStore_Config::getInstance();
    $page_id = $wp_eStore_config->getValue('eStore_template_store_action_page_id');
    $sp_obj = get_post($page_id);
    return $sp_obj;
}
Example #20
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;
 }