function eStore_get_gateway_specific_buy_now_button_code($id, $gateway = 'paypal', $button_text = '', $line_break = true, $nggImage = '', $buttonImage = '')
{
    global $wpdb;
    $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
    $id = strip_tags($id);
    $ret_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT);
    if (!$ret_product) {
        return eStore_wrong_product_id_error_msg($id);
    }
    $replacement = "";
    if (is_numeric($ret_product->available_copies)) {
        if ($ret_product->available_copies < 1) {
            // No more copies left
            return eStore_get_sold_out_button();
        }
    }
    if (!empty($ret_product->target_button_url)) {
        $replacement = '<form method="post" action="' . $ret_product->target_button_url . '">';
        $replacement .= eStore_get_buy_now_submit_input($ret_product->button_image_url);
        $replacement .= '</form>';
        return $replacement;
    }
    if (isset($_SESSION['eStore_gs_bn_co_error_msg']) && $_REQUEST['item_number'] == $id) {
        $replacement .= $_SESSION['eStore_gs_bn_co_error_msg'];
    }
    //$replacement .= '<object class="eStore_button_object">';
    $replacement .= '<form method="post" class="wppg-eStore-buy-button-form" action="" style="display:inline" onsubmit="return ReadForm1(this, 1);">';
    $var_output = get_variation_and_input_code($ret_product, $line_break, 1, $nggImage);
    if (!empty($var_output)) {
        $replacement .= $var_output;
    }
    //If custom price option is set
    if ($ret_product->custom_price_option == '1') {
        $currSymbol = WP_ESTORE_CURRENCY_SYMBOL;
        //get_option('cart_currency_symbol');
        $replacement .= '<div class="wppg-eStore-buy-button-custom-price">' . WP_ESTORE_YOUR_PRICE . ': ' . $currSymbol . '<input type="text" name="custom_price" size="3" value="" /></div>';
    }
    if ($ret_product->show_qty == '1') {
        $replacement .= '<div class="wppg-eStore-buy-button-qty">' . eStore_get_default_purchase_qty_input_data() . '</div>';
    } else {
        $replacement .= '<div class="wppg-eStore-buy-button-qty"><input type="hidden" name="add_qty" value="1" /></div>';
    }
    if (!empty($nggImage->alttext)) {
        $replacement .= '<input type="hidden" name="product" value="' . htmlspecialchars($nggImage->alttext) . '" /><input type="hidden" name="product_name_tmp1" value="' . htmlspecialchars($nggImage->alttext) . '" />';
    } else {
        $replacement .= '<input type="hidden" name="product" value="' . htmlspecialchars($ret_product->name) . '" /><input type="hidden" name="product_name_tmp1" value="' . htmlspecialchars($ret_product->name) . '" />';
    }
    if (!empty($nggImage->thumbURL)) {
        //$nggImage->imageURL
        $replacement .= '<input type="hidden" name="thumbnail_url" value="' . $nggImage->thumbURL . '" />';
    } else {
        $replacement .= '<input type="hidden" name="thumbnail_url" value="' . $ret_product->thumbnail_url . '" />';
    }
    $replacement .= '<input type="hidden" name="price" value="' . $ret_product->price . '" /><input type="hidden" name="price_tmp1" value="' . $ret_product->price . '" />';
    $replacement .= '<input type="hidden" name="item_number" value="' . $ret_product->id . '" /><input type="hidden" name="shipping" value="' . $ret_product->shipping_cost . '" /><input type="hidden" name="tax" value="' . $ret_product->tax . '" />';
    if (!empty($ret_product->product_url)) {
        $replacement .= '<input type="hidden" name="cartLink" value="' . $ret_product->product_url . '" />';
    } else {
        $replacement .= '<input type="hidden" name="cartLink" value="' . digi_cart_current_page_url() . '" />';
    }
    if (wp_eStore_is_digital_product($ret_product)) {
        //flag this as a digital product
        $replacement .= '<input type="hidden" name="digital_flag" value="1" />';
    }
    $replacement .= '<input type="hidden" name="eStore_gsbn_gateway" value="' . $gateway . '" />';
    $replacement .= '<input type="hidden" name="eStore_gs_buy_now_submit" value="1" />';
    if (empty($buttonImage)) {
        $buttonImage = $ret_product->button_image_url;
    }
    if (!empty($buttonImage)) {
        $replacement .= eStore_get_buy_now_submit_input($buttonImage);
    } else {
        $replacement .= eStore_get_buy_now_submit_input("", $button_text);
    }
    $replacement .= '</form>';
    //$replacement .= '</object>';
    return $replacement;
}
function print_eStore_subscribe_button_form($id)
{
    global $wpdb;
    $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
    $ret_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT);
    $output = "";
    if (is_numeric($ret_product->available_copies)) {
        if ($ret_product->available_copies < 1) {
            return eStore_get_sold_out_button();
        }
    }
    if (!empty($ret_product->paypal_email)) {
        $paypal_email = $ret_product->paypal_email;
    } else {
        $paypal_email = get_option('cart_paypal_email');
    }
    if (!empty($ret_product->currency_code)) {
        $paypal_currency = $ret_product->currency_code;
    } else {
        $paypal_currency = get_option('cart_payment_currency');
    }
    //$paypal_currency = get_option('cart_payment_currency');
    $return = get_option('cart_return_from_paypal_url');
    // Find out if the product should be delivered automatically through a notify email
    if (get_option('eStore_auto_product_delivery') == '') {
        $notify = '';
    } else {
        if (WP_ESTORE_ENABLE_NEW_CHECKOUT_REDIRECTION === '1') {
            $notify = WP_ESTORE_WP_SITE_URL . '/?estore_pp_ipn=process';
        } else {
            $notify = WP_ESTORE_URL . '/paypal.php';
        }
    }
    $urls = "";
    if (!empty($notify)) {
        $urls .= '<input type="hidden" name="notify_url" value="' . $notify . '" />';
    }
    if (!empty($ret_product->return_url)) {
        $urls .= '<input type="hidden" name="return" value="' . $ret_product->return_url . '" />';
    } else {
        if (!empty($return)) {
            $urls .= '<input type="hidden" name="return" value="' . $return . '" />';
        }
    }
    $cancel_url = get_option('cart_cancel_from_paypal_url');
    if (!empty($cancel_url)) {
        $urls .= '<input type="hidden" name="cancel_return" value="' . $cancel_url . '" />';
    }
    $button = $ret_product->button_image_url;
    $button_type = "";
    if (!empty($button)) {
        $button_type .= '<input type="image" src="' . $button . '" class="eStore_subscribe_button" alt="' . WP_ESTORE_SUBSCRIBE . '"/>';
    } else {
        $button_type .= '<input type="submit" class="eStore_subscribe_button" value="' . WP_ESTORE_SUBSCRIBE . '" />';
    }
    $sandbox_enabled = get_option('eStore_cart_enable_sandbox');
    if ($sandbox_enabled) {
        $form_submit_url = PAYPAL_SANDBOX_URL;
    } else {
        $form_submit_url = PAYPAL_LIVE_URL;
    }
    $form_submit_url = apply_filters('eStore_pp_subscribe_form_submit_url', $form_submit_url);
    //Subscribe button form
    $output = "";
    $output .= '<div class="eStore_button_wrapper eStore_pp_subscribe_wrapper">';
    $output .= '<form action="' . $form_submit_url . '" method="post" onsubmit="return ReadForm1(this, 3);">';
    $line_break = true;
    //variation code
    $output .= get_variation_and_input_code($ret_product, $line_break, 3);
    //Custom price
    if ($ret_product->custom_price_option == '1') {
        $currSymbol = get_option('cart_currency_symbol');
        $output .= WP_ESTORE_YOUR_PRICE . ': ' . $currSymbol . '<input type="text" name="custom_price" size="3" value="" />&nbsp;';
        if ($line_break) {
            $output .= '<br />';
        }
    }
    $output .= '<input type="hidden" name="product_name_tmp1" value="' . htmlspecialchars($ret_product->name) . '" /><input type="hidden" name="price_tmp1" value="' . $ret_product->a3 . '" />';
    if (defined('WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE') && WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE !== '0') {
        //Set the country/region preference by force.
        $output .= '<input type="hidden" name="lc" value="' . WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE . '" />';
    }
    $output .= '<input type="hidden" name="cmd" value="_xclick-subscriptions" />';
    $output .= '<input type="hidden" name="charset" value="utf-8" />';
    $output .= "<input type=\"hidden\" name=\"business\" value=\"{$paypal_email}\" />";
    $output .= '<input type="hidden" name="item_name" value="' . htmlspecialchars($ret_product->name) . '" />';
    $output .= "<input type=\"hidden\" name=\"currency_code\" value=\"{$paypal_currency}\" />";
    $output .= "<input type=\"hidden\" name=\"item_number\" value=\"{$id}\" />";
    $output .= '<input type="hidden" name="rm" value="2" /><input type="hidden" name="no_note" value="1" />';
    if (!empty($ret_product->p1)) {
        $output .= "<input type=\"hidden\" name=\"a1\" value=\"{$ret_product->a1}\" /><input type=\"hidden\" name=\"p1\" value=\"{$ret_product->p1}\" /><input type=\"hidden\" name=\"t1\" value=\"{$ret_product->t1}\" />";
    }
    if (!empty($ret_product->p3)) {
        if (empty($ret_product->a3)) {
            $output .= "<div style='color:red;'>Looks like you did not specify a recurring amount in the subscription details. Please note that you must specify a value for the Recurring Billing Amount to create a working subscription payment button!</div>";
        } else {
            $output .= "<input type=\"hidden\" name=\"a3\" value=\"{$ret_product->a3}\" /><input type=\"hidden\" name=\"p3\" value=\"{$ret_product->p3}\" /><input type=\"hidden\" name=\"t3\" value=\"{$ret_product->t3}\" />";
        }
    }
    if ($ret_product->sra == '1') {
        $output .= '<input type="hidden" name="sra" value="1" />';
    }
    if ($ret_product->srt > 1) {
        $output .= "<input type=\"hidden\" name=\"src\" value=\"1\" /><input type=\"hidden\" name=\"srt\" value=\"{$ret_product->srt}\" />";
    } else {
        if ($ret_product->srt == '0') {
            $output .= "<input type=\"hidden\" name=\"src\" value=\"1\" />";
        }
    }
    if (is_numeric($ret_product->shipping_cost) && $ret_product->shipping_cost == 0) {
        $output .= "<input type=\"hidden\" name=\"no_shipping\" value='1' />";
    }
    $output .= $urls;
    $output .= '<input type="hidden" name="mrb" value="3FWGC6LFTMTUG" />';
    $returnButtonText = get_option('eStore_paypal_return_button_text');
    $output .= '<input type="hidden" name="cbt" value="' . $returnButtonText . '" />';
    $page_style_name = get_option('eStore_paypal_co_page_style');
    $output .= '<input type="hidden" name="page_style" value="' . $page_style_name . '" />';
    if (empty($ret_product->ref_text)) {
        $output .= aff_add_custom_field();
    } else {
        $custom_field_val = eStore_get_custom_field_value();
        $subsc_ref_val = 'subsc_ref=' . $ret_product->ref_text;
        if (empty($custom_field_val)) {
            $custom_field_val = $subsc_ref_val;
        } else {
            $custom_field_val = $custom_field_val . '&' . $subsc_ref_val;
        }
        $output .= '<input type="hidden" name="custom" value="' . $custom_field_val . '" id="eStore_custom_values" />';
    }
    if (get_option('eStore_show_t_c_for_buy_now')) {
        $output .= eStore_show_terms_and_cond();
    }
    $output .= $button_type;
    $output .= '</form>';
    $output .= '</div>';
    return $output;
}