public function updateProfile($invoice_id)
 {
     $this->params['METHOD'] = "UpdateRecurringPaymentsProfile";
     $invoice = new Web_Invoice_GetInfo($invoice_id);
     $user_id = $invoice->recipient('user_id');
     if (get_option('web_invoice_pfp_authentication') == '3token' || get_option('web_invoice_pfp_authentication') == 'unipay') {
         $this->params['DESC'] = $invoice->display('subscription_name');
         $this->params['PROFILESTARTDATE'] = date('c', strtotime($invoice->display('startDateM')));
         $this->params['TOTALBILLINGCYCLES'] = $invoice->display('totalOccurrences');
         $this->params['NOTE'] = "Related invoice was updated";
         $this->params['PROFILEID'] = web_invoice_meta($invoice_id, 'subscription_id');
         $this->params["FIRSTNAME"] = get_usermeta($user_id, 'first_name');
         $this->params["LASTNAME"] = get_usermeta($user_id, 'last_name');
         $this->params["STREET"] = get_usermeta($user_id, 'address');
         $this->params["CITY"] = get_usermeta($user_id, 'city');
         $this->params["STATE"] = get_usermeta($user_id, 'state');
         $this->params["COUNTRYCODE"] = get_usermeta($user_id, 'country');
         $this->params["ZIP"] = get_usermeta($user_id, 'zip');
         $this->params["PHONENUM"] = get_usermeta($user_id, 'phonenumber');
         if (get_option('web_invoice_pfp_shipping_details') == 'True') {
             //Shipping Info
             $this->params["SHIPTONAME"] = get_usermeta($user_id, 'shipto_first_name') . " " . get_usermeta($user_id, 'shipto_last_name');
             $this->params["SHIPTOSTREET"] = get_usermeta($user_id, 'shipto_address');
             $this->params["SHIPTOCITY"] = get_usermeta($user_id, 'shipto_city');
             $this->params["SHIPTOSTATE"] = get_usermeta($user_id, 'shipto_state');
             $this->params["SHIPTOCOUNTRY"] = get_usermeta($user_id, 'shipto_country');
             $this->params["SHIPTOZIP"] = get_usermeta($user_id, 'shipto_zip');
             $this->params["SHIPTOPHONENUM"] = get_usermeta($user_id, 'shipto_phonenumber');
         }
     } else {
         $this->params['ACTION'] = "M";
         $this->params['ORIGPROFILEID'] = web_invoice_meta($invoice_id, 'subscription_id');
         $this->params['PROFILENAME'] = $invoice->display('subscription_name');
         $this->params['START'] = date('mdY', strtotime($invoice->display('startDateM')) + 3600 * 24);
         $this->params['TERM'] = $invoice->display('totalOccurrences');
         $this->params['PAYPERIOD'] = web_invoice_pfp_wpppe_convert_interval($invoice->display('interval_length'), $invoice->display('interval_unit'));
         $this->params["COMMENT1"] = get_usermeta($user_id, 'first_name') . " " . get_usermeta($user_id, 'last_name') . " " . $invoice->display('subscription_name') . " Recurring";
         $this->params["FIRSTNAME"] = get_usermeta($user_id, 'first_name');
         $this->params["LASTNAME"] = get_usermeta($user_id, 'last_name');
         $this->params["STREET"] = get_usermeta($user_id, 'streetaddress');
         $this->params["CITY"] = get_usermeta($user_id, 'city');
         $this->params["STATE"] = get_usermeta($user_id, 'state');
         $this->params["COUNTRY"] = get_usermeta($user_id, 'country');
         $this->params["ZIP"] = get_usermeta($user_id, 'zip');
         $this->params["PHONENUM"] = get_usermeta($user_id, 'phonenumber');
         if (get_option('web_invoice_pfp_shipping_details') == 'True') {
             //Shipping Info
             $this->params["SHIPTONAME"] = get_usermeta($user_id, 'shipto_first_name') . " " . get_usermeta($user_id, 'shipto_last_name');
             $this->params["SHIPTOSTREET"] = get_usermeta($user_id, 'shipto_streetaddress');
             $this->params["SHIPTOCITY"] = get_usermeta($user_id, 'shipto_city');
             $this->params["SHIPTOSTATE"] = get_usermeta($user_id, 'shipto_state');
             $this->params["SHIPTOCOUNTRY"] = get_usermeta($user_id, 'shipto_country');
             $this->params["SHIPTOZIP"] = get_usermeta($user_id, 'shipto_zip');
             $this->params["SHIPTOPHONENUM"] = get_usermeta($user_id, 'shipto_phonenumber');
         }
     }
     $this->params["AMT"] = $invoice->display('amount');
     $this->params["CURRENCYCODE"] = $invoice->display('currency');
     return $this->process();
 }
Example #2
0
function web_invoice_generate_pdf_content($invoice_id)
{
    global $post, $web_invoice_print;
    $web_invoice_print = true;
    $invoice = new Web_Invoice_GetInfo($invoice_id);
    $lines = preg_split("/\n/", get_option('web_invoice_business_address'));
    $lines_recepient = preg_split("/\n/", $invoice->recipient('streetaddress'));
    $lc = max(count($lines_recepient), count($lines));
    ob_start();
    ?>
	<style type="text/css">
		.noprint { display: none; }
		#invoice_page { width: 500px; margin: 0 auto; font-size: 11px; font-family: 'Trebuchet MS','Lucida Grande',Verdana,Tahoma,Arial; }
		th { text-align: left; font-size: 13px; padding: 5px; }
		td { font-size: 12px; vertical-align: top; padding: 5px; }
		tr td { background-color: #fefefe; }
		tr.alt_row  td { background-color: #eee; }
		span.description_text { color: #333; font-size: 0.8em; }
		tr.web_invoice_bottom_line { font-size: 1.1em; font-weight: bold; }
		table { width: 100%; }
		h2 { font-size: 1.1em; }
		h1 { text-align: center; }
		p { margin: 5px 0px; }
		div.clear { clear: both; }
		
		#invoice_client_info { width: 100%; text-align: right; padding-top: -<?php 
    print ($lc + 3) * 20 + 7;
    ?>
px; }
		#invoice_business_info { width: 100%; text-align: left; height: <?php 
    print ($lc + 3) * 15 + 7;
    ?>
px; }
	</style>
	<?php 
    do_action('web_invoice_front_top', $invoice_id);
    print '<div class="clear"></div>';
    //If this is not recurring invoice, show regular message
    if (!($recurring = web_invoice_recurring($invoice_id))) {
        web_invoice_show_invoice_overview($invoice_id);
    }
    // Show this if recurring
    if ($recurring) {
        web_invoice_show_recurring_info($invoice_id);
    }
    if (web_invoice_paid_status($invoice_id)) {
        web_invoice_show_already_paid($invoice_id);
        do_action('web_invoice_front_paid', $invoice_id);
    } else {
        //Show Billing Information
        web_invoice_show_billing_information($invoice_id);
        do_action('web_invoice_front_unpaid', $invoice_id);
    }
    do_action('web_invoice_front_bottom', $invoice_id);
    ?>
	<script type="text/php">
		if ( isset($pdf) ) {
    		$font = Font_Metrics::get_font("verdana", "bold");
			$font_light = Font_Metrics::get_font("verdana");
			$pdf->page_text(52, 810, "Powered by Web Invoice ".WEB_INVOICE_VERSION_NUM, $font_light, 10, array(0,0,0));
    		$pdf->page_text(510, 810, "Page {PAGE_NUM} of {PAGE_COUNT}", $font, 10, array(0,0,0));
  		}
	</script>
	<?php 
    $content = ob_get_contents();
    ob_clean();
    return $content;
}
Example #3
0
function web_invoice_process_invoice_update($invoice_id, $unprivileged = false)
{
    global $wpdb;
    if ($unprivileged) {
        $profileuser = get_currentuserinfo();
    } else {
        $profileuser = get_userdata($_POST['user_id']);
    }
    $description = $_REQUEST['description'];
    $subject = $_REQUEST['subject'];
    $amount = $_REQUEST['amount'];
    $user_id = $_REQUEST['user_id'];
    $web_invoice_tax = serialize($_REQUEST['web_invoice_tax']);
    $itemized_list = $_REQUEST['itemized_list'];
    $web_invoice_custom_invoice_id = $_REQUEST['web_invoice_custom_invoice_id'];
    $web_invoice_date = "{$_REQUEST['web_invoice_date_year']}-{$_REQUEST['web_invoice_date_month']}-{$_REQUEST['web_invoice_date_day']}";
    $web_invoice_due_date_month = $_REQUEST['web_invoice_due_date_month'];
    $web_invoice_due_date_day = $_REQUEST['web_invoice_due_date_day'];
    $web_invoice_due_date_year = $_REQUEST['web_invoice_due_date_year'];
    $web_invoice_first_name = $_REQUEST['web_invoice_first_name'];
    $web_invoice_last_name = $_REQUEST['web_invoice_last_name'];
    $web_invoice_tax_id = $_REQUEST['web_invoice_tax_id'];
    $web_invoice_company_name = $_REQUEST['web_invoice_company_name'];
    $web_invoice_streetaddress = $_REQUEST['web_invoice_streetaddress'];
    $web_invoice_city = $_REQUEST['web_invoice_city'];
    $web_invoice_state = $_REQUEST['web_invoice_state'];
    $web_invoice_zip = $_REQUEST['web_invoice_zip'];
    $web_invoice_country = $_REQUEST['web_invoice_country'];
    $web_invoice_currency_code = $_REQUEST['web_invoice_currency_code'];
    $web_invoice_subscription_name = $_REQUEST['web_invoice_subscription_name'];
    $web_invoice_subscription_unit = $_REQUEST['web_invoice_subscription_unit'];
    $web_invoice_subscription_length = $_REQUEST['web_invoice_subscription_length'];
    $web_invoice_subscription_start_month = $_REQUEST['web_invoice_subscription_start_month'];
    $web_invoice_subscription_start_day = $_REQUEST['web_invoice_subscription_start_day'];
    $web_invoice_subscription_start_year = $_REQUEST['web_invoice_subscription_start_year'];
    $web_invoice_subscription_total_occurances = $_REQUEST['web_invoice_subscription_total_occurances'];
    $web_invoice_payment_methods = join(',', $_REQUEST['web_invoice_payment_methods']);
    $web_invoice_tax_names = unserialize(get_option('web_invoice_tax_name'));
    if (!is_array($web_invoice_tax_names)) {
        $web_invoice_tax_names = array();
    }
    for ($_txc = 0; $_txc < get_option('web_invoice_tax_count'); $_txc++) {
        if (!isset($_REQUEST['web_invoice_tax_name_' . $_txc])) {
            continue;
        }
        $web_invoice_tax_names[$_txc] = $_REQUEST['web_invoice_tax_name_' . $_txc];
    }
    //remove items from itemized list that are missing a title, they are most likely deleted
    if (is_array($itemized_list)) {
        $counter = 1;
        foreach ($itemized_list as $itemized_item) {
            if (empty($itemized_item[name])) {
                unset($itemized_list[$counter]);
            }
            $counter++;
        }
        array_values($itemized_list);
    }
    $itemized = urlencode(serialize($itemized_list));
    // Check if this is new invoice creation, or an update
    if (web_invoice_does_invoice_exist($invoice_id)) {
        // Updating Old Invoice
        if (web_invoice_get_invoice_attrib($invoice_id, 'subject') != $subject) {
            $wpdb->query("UPDATE " . Web_Invoice::tablename('main') . " SET subject = '{$subject}' WHERE invoice_num = {$invoice_id}");
            web_invoice_update_log($invoice_id, 'updated', ' Subject Updated ');
            $message .= "Subject updated. ";
            web_invoice_clear_cache();
        }
        if (web_invoice_get_invoice_attrib($invoice_id, 'description') != $description) {
            $wpdb->query("UPDATE " . Web_Invoice::tablename('main') . " SET description = '{$description}' WHERE invoice_num = {$invoice_id}");
            web_invoice_update_log($invoice_id, 'updated', ' Description Updated ');
            $message .= "Description updated. ";
            web_invoice_clear_cache();
        }
        if (web_invoice_get_invoice_attrib($invoice_id, 'amount') != $amount) {
            $wpdb->query("UPDATE " . Web_Invoice::tablename('main') . " SET amount = '{$amount}' WHERE invoice_num = {$invoice_id}");
            web_invoice_update_log($invoice_id, 'updated', ' Amount Updated ');
            $message .= "Amount updated. ";
            web_invoice_clear_cache();
        }
        if (web_invoice_get_invoice_attrib($invoice_id, 'invoice_date') != $web_invoice_date) {
            $wpdb->query("UPDATE " . Web_Invoice::tablename('main') . " SET invoice_date = '{$web_invoice_date}' WHERE invoice_num = {$invoice_id}");
            web_invoice_update_log($invoice_id, 'updated', ' Invoice Date Updated ');
            $message .= "Invoice date updated. ";
            web_invoice_clear_cache();
        }
        if (web_invoice_get_invoice_attrib($invoice_id, 'itemized') != $itemized) {
            $wpdb->query("UPDATE " . Web_Invoice::tablename('main') . " SET itemized = '{$itemized}' WHERE invoice_num = {$invoice_id}");
            web_invoice_update_log($invoice_id, 'updated', ' Itemized List Updated ');
            $message .= "Itemized List updated. ";
            web_invoice_clear_cache();
        }
    } else {
        // Create New Invoice
        if ($wpdb->query("INSERT INTO " . Web_Invoice::tablename('main') . " (amount,invoice_date,description,invoice_num,user_id,subject,itemized,status)\tVALUES ('{$amount}','{$web_invoice_date}','{$description}','{$invoice_id}','{$user_id}','{$subject}','{$itemized}','0')")) {
            $message = "New Invoice saved.";
            web_invoice_update_log($invoice_id, 'created', ' Created ');
        } else {
            $error = true;
            $message = "There was a problem saving invoice. Try deactivating and reactivating plugin. REF: " . mysql_errno();
        }
    }
    // See if invoice is recurring
    if (!empty($web_invoice_subscription_name) && !empty($web_invoice_subscription_unit) && !empty($web_invoice_subscription_total_occurances)) {
        $web_invoice_recurring_status = true;
        web_invoice_update_invoice_meta($invoice_id, "web_invoice_recurring_billing", true);
        $message .= " Recurring invoice saved.  This invoice may be viewed under \"Recurring Billing\". ";
    }
    // See if invoice is recurring
    if (empty($web_invoice_subscription_name) && empty($web_invoice_subscription_unit) && empty($web_invoice_subscription_total_occurances)) {
        $web_invoice_recurring_status = false;
        web_invoice_update_invoice_meta($invoice_id, "web_invoice_recurring_billing", false);
    }
    // Update Invoice Meta
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_custom_invoice_id", $web_invoice_custom_invoice_id);
    web_invoice_update_invoice_meta($invoice_id, "tax_value", $web_invoice_tax);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_currency_code", $web_invoice_currency_code);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_due_date_day", $web_invoice_due_date_day);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_due_date_month", $web_invoice_due_date_month);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_due_date_year", $web_invoice_due_date_year);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_payment_methods", $web_invoice_payment_methods);
    // Update Invoice Recurring Meta
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_name", $web_invoice_subscription_name);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_unit", $web_invoice_subscription_unit);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_length", $web_invoice_subscription_length);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_start_month", $web_invoice_subscription_start_month);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_start_day", $web_invoice_subscription_start_day);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_start_year", $web_invoice_subscription_start_year);
    web_invoice_update_invoice_meta($invoice_id, "web_invoice_subscription_total_occurances", $web_invoice_subscription_total_occurances);
    //Update User Information
    if (!empty($web_invoice_first_name)) {
        update_usermeta($user_id, 'first_name', $web_invoice_first_name);
    }
    if (!empty($web_invoice_last_name)) {
        update_usermeta($user_id, 'last_name', $web_invoice_last_name);
    }
    if (!empty($web_invoice_company_name)) {
        update_usermeta($user_id, 'company_name', $web_invoice_company_name);
    }
    if (!empty($web_invoice_tax_id)) {
        update_usermeta($user_id, 'tax_id', $web_invoice_tax_id);
    }
    if (!empty($web_invoice_streetaddress)) {
        update_usermeta($user_id, 'streetaddress', $web_invoice_streetaddress);
    }
    if (!empty($web_invoice_city)) {
        update_usermeta($user_id, 'city', $web_invoice_city);
    }
    if (!empty($web_invoice_state)) {
        update_usermeta($user_id, 'state', $web_invoice_state);
    }
    if (!empty($web_invoice_zip)) {
        update_usermeta($user_id, 'zip', $web_invoice_zip);
    }
    if (!empty($web_invoice_country)) {
        update_usermeta($user_id, 'country', $web_invoice_country);
    }
    if (is_array($web_invoice_tax_names)) {
        update_option('web_invoice_tax_name', serialize($web_invoice_tax_names));
    }
    //If there is a message, append it with the web invoice link
    if ($message && $invoice_id) {
        $invoice_info = new Web_Invoice_GetInfo($invoice_id);
        $message .= " <a href='" . $invoice_info->display('link') . "'>View Web Invoice</a>.";
    }
    if (!$error) {
        return $message;
    }
    if ($error) {
        return "An error occured: {$message}.";
    }
}
Example #4
0
 function api()
 {
     if (get_option('web_invoice_web_invoice_page') != '' && is_page(get_option('web_invoice_web_invoice_page'))) {
         if (get_option('web_invoice_moneybookers_merchant') == 'True' && isset($_POST['mb_transaction_id']) && isset($_POST['status'])) {
             require_once "gateways/moneybookers.class.php";
             $moneybookers_obj = new Web_Invoice_Moneybookers($_POST['transaction_id']);
             $moneybookers_obj->processRequest($_SERVER['REMOTE_ADDR'], $_POST);
         } else {
             if (get_option('web_invoice_alertpay_merchant') == 'True' && isset($_POST['ap_itemname']) && isset($_POST['ap_securitycode'])) {
                 require_once "gateways/alertpay.class.php";
                 $alertpay_obj = new Web_Invoice_AlertPay($_POST['ap_itemname']);
                 $alertpay_obj->processRequest($_SERVER['REMOTE_ADDR'], $_POST);
             } else {
                 if (get_option('web_invoice_google_checkout_level2') == 'True' && isset($_POST['_type'])) {
                     require_once "gateways/googlecheckout.class.php";
                     $gc_obj = new Web_Invoice_GoogleCheckout($_POST['_type'], $_POST);
                     $gc_obj->processRequest($_SERVER['REMOTE_ADDR'], $_POST);
                 } else {
                     if (get_option('web_invoice_payflow_silent_post') == 'True' && isset($_POST['PNREF'])) {
                         require_once "gateways/payflow.class.php";
                         $pf_obj = new Web_Invoice_Payflow($_POST['CUSTID'], $_POST);
                         $pf_obj->processRequest($_SERVER['REMOTE_ADDR'], $_POST);
                     } else {
                         if (isset($_GET['crypt'])) {
                             require_once "gateways/sagepay.class.php";
                             $pf_obj = new Web_Invoice_SagePay($_GET['crypt']);
                             $pf_obj->processRequest($_SERVER['REMOTE_ADDR']);
                         } else {
                             if (isset($_GET['paypal_ipn'])) {
                                 require_once "gateways/paypal.class.php";
                                 $pf_obj = new Web_Invoice_Paypal($_POST['invoice']);
                                 $pf_obj->processRequest($_SERVER['REMOTE_ADDR'], $_POST);
                             } else {
                                 if (isset($_REQUEST['order_number'])) {
                                     require_once "gateways/2co.class.php";
                                     $tco_obj = new Web_Invoice_2CO($_GET['cart_order_id']);
                                     $tco_obj->processRequest($_SERVER['REMOTE_ADDR'], $_REQUEST);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         wp_enqueue_script('jquery');
         wp_enqueue_script('web-invoice', $this->uri . "/js/web-invoice-frontend.js", array('jquery'), WEB_INVOICE_VERSION_NUM);
         // Make sure proper MD5 is being passed (32 chars), and strip of everything but numbers and letters
         if (isset($_GET['invoice_id']) && strlen($_GET['invoice_id']) != 32) {
             unset($_GET['invoice_id']);
         }
         $_GET['invoice_id'] = preg_replace('/[^A-Za-z0-9-]/', '', $_GET['invoice_id']);
         // Make sure proper MD5 is being passed (32 chars), and strip of everything but numbers and letters
         if (isset($_GET['generate_from']) && strlen($_GET['generate_from']) != 32) {
             unset($_GET['generate_from']);
         }
         $_GET['generate_from'] = preg_replace('/[^A-Za-z0-9-]/', '', $_GET['generate_from']);
         if (isset($_GET['generate_from']) && !empty($_GET['generate_from']) && get_option('web_invoice_self_generate_from_template') == "yes") {
             global $current_user;
             get_currentuserinfo();
             if ($current_user->ID > 0) {
                 // Convert MD5 hash into Actual Invoice ID
                 $template_id = web_invoice_md5_to_invoice($_GET['generate_from']);
                 $invoice_id = web_invoice_self_generate_from_template($template_id, $current_user->ID);
                 $web_invoice_getinfo = new Web_Invoice_GetInfo($invoice_id);
                 wp_redirect($web_invoice_getinfo->display('link'));
                 exit(0);
             }
         }
         if (isset($_GET['print'])) {
             web_invoice_print_pdf();
         }
     }
 }