Ejemplo n.º 1
0
 function display($what)
 {
     global $_web_invoice_clear_cache, $wpdb;
     if (!$this->_row_cache || $_web_invoice_clear_cache) {
         $this->_setRowCache($wpdb->get_row("SELECT * FROM " . Web_Invoice::tablename('main') . " WHERE invoice_num = '{$this->id}'"));
         $_web_invoice_clear_cache = false;
     }
     $invoice_info = $this->_row_cache;
     switch ($what) {
         case 'log_status':
             if ($status_update = $wpdb->get_row("SELECT * FROM " . Web_Invoice::tablename('log') . " WHERE invoice_id = " . $this->id . " ORDER BY `" . Web_Invoice::tablename('log') . "`.`time_stamp` DESC LIMIT 0 , 1")) {
                 return $status_update->value . " - " . web_invoice_Date::convert($status_update->time_stamp, 'Y-m-d H', __('M d Y', WEB_INVOICE_TRANS_DOMAIN));
             }
             break;
         case 'paid_date':
             $paid_date = $wpdb->get_var("SELECT time_stamp FROM  " . Web_Invoice::tablename('log') . " WHERE action_type = 'paid' AND invoice_id = '" . $this->id . "' ORDER BY time_stamp DESC LIMIT 0, 1");
             if ($paid_date) {
                 return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime(web_invoice_Date::convert($paid_date, 'Y-m-d H', __('M d Y', WEB_INVOICE_TRANS_DOMAIN))));
             }
             break;
         case 'paid_date_raw':
             $paid_date = $wpdb->get_var("SELECT time_stamp FROM  " . Web_Invoice::tablename('log') . " WHERE action_type = 'paid' AND invoice_id = '" . $this->id . "' ORDER BY time_stamp DESC LIMIT 0, 1");
             if ($paid_date) {
                 return $paid_date;
             }
             break;
         case 'subscription_name':
             return web_invoice_meta($this->id, 'web_invoice_subscription_name');
             break;
         case 'interval_length':
             return web_invoice_meta($this->id, 'web_invoice_subscription_length');
             break;
         case 'interval_unit':
             return web_invoice_meta($this->id, 'web_invoice_subscription_unit');
             break;
         case 'totalOccurrences':
             return web_invoice_meta($this->id, 'web_invoice_subscription_total_occurances');
             break;
         case 'installment':
             return web_invoice_meta($this->id, 'installment', 0);
             break;
         case 'startDate':
             $web_invoice_subscription_start_day = web_invoice_meta($this->id, 'web_invoice_subscription_start_day');
             $web_invoice_subscription_start_year = web_invoice_meta($this->id, 'web_invoice_subscription_start_year');
             $web_invoice_subscription_start_month = web_invoice_meta($this->id, 'web_invoice_subscription_start_month');
             if ($web_invoice_subscription_start_month && $web_invoice_subscription_start_year && $web_invoice_subscription_start_day && strtotime($web_invoice_subscription_start_year . "-" . $web_invoice_subscription_start_month . "-" . $web_invoice_subscription_start_day) > time()) {
                 return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime($web_invoice_subscription_start_year . "-" . $web_invoice_subscription_start_month . "-" . $web_invoice_subscription_start_day));
             } else {
                 return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), time() + 1800);
             }
             break;
         case 'endDate':
             return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime("+" . $this->display('interval_length') * $this->display('totalOccurrences') . " " . $this->display('interval_unit'), strtotime($this->display('startDateM'))));
             break;
         case 'nextDate':
             if ($this->display('totalOccurrences') > $this->display('installment')) {
                 if ($this->display('installment') == 0 && strtotime($this->display('startDateM')) >= strtotime($this->display('due_dateM'))) {
                     $start_date = $this->display('due_dateM');
                 } else {
                     $start_date = $this->display('startDateM');
                 }
                 return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime("+" . $this->display('interval_length') * $this->display('installment') . " " . $this->display('interval_unit'), strtotime($start_date)));
             }
             return $this->display('endDate');
             break;
         case 'startDateM':
             $web_invoice_subscription_start_day = web_invoice_meta($this->id, 'web_invoice_subscription_start_day');
             $web_invoice_subscription_start_year = web_invoice_meta($this->id, 'web_invoice_subscription_start_year');
             $web_invoice_subscription_start_month = web_invoice_meta($this->id, 'web_invoice_subscription_start_month');
             if ($web_invoice_subscription_start_month && $web_invoice_subscription_start_year && $web_invoice_subscription_start_day && strtotime($web_invoice_subscription_start_year . "-" . $web_invoice_subscription_start_month . "-" . $web_invoice_subscription_start_day) > time()) {
                 return date('Y-m-d', strtotime($web_invoice_subscription_start_year . "-" . $web_invoice_subscription_start_month . "-" . $web_invoice_subscription_start_day));
             } else {
                 return date('Y-m-d', time() + 1800);
             }
             break;
         case 'endDateM':
             return date('Y-m-d', strtotime("+" . $this->display('interval_length') * $this->display('totalOccurrences') . " " . $this->display('interval_unit'), strtotime($this->display('startDateM'))));
             break;
         case 'nextDateM':
             if ($this->display('totalOccurrences') > $this->display('installment')) {
                 if ($this->display('installment') == 0 && strtotime($this->display('startDateM')) >= strtotime($this->display('due_dateM'))) {
                     $start_date = $this->display('due_dateM');
                 } else {
                     $start_date = $this->display('startDateM');
                 }
                 return date('Y-m-d', strtotime("+" . $this->display('interval_length') * $this->display('installment') . " " . $this->display('interval_unit'), strtotime($start_date)));
             }
             return $this->display('endDate');
             break;
         case 'profileEndDate':
             return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime("+" . $this->display('interval_length') * ($this->display('totalOccurrences') - 1) . " " . $this->display('interval_unit'), strtotime($this->display('startDate')) + 3600 * 24));
             break;
         case 'archive_status':
             $result = $wpdb->get_col("SELECT action_type FROM  " . Web_Invoice::tablename('log') . " WHERE invoice_id = '" . $this->id . "' ORDER BY time_stamp DESC");
             foreach ($result as $event) {
                 if ($event == 'unarchive') {
                     return '';
                     break;
                 }
                 if ($event == 'archive') {
                     return 'archive';
                     break;
                 }
             }
             break;
         case 'display_billing_rate':
             $length = web_invoice_meta($this->id, 'web_invoice_subscription_length');
             $unit = web_invoice_meta($this->id, 'web_invoice_subscription_unit');
             $occurances = web_invoice_meta($this->id, 'web_invoice_subscription_total_occurances');
             // days
             if ($unit == "days") {
                 if ($length == '1') {
                     return "daily for {$occurances} days";
                 }
                 if ($length > '1') {
                     return "every {$length} days for a total of {$occurances} billing cycles";
                 }
             }
             //months
             if ($unit == "months") {
                 if ($length == '1') {
                     return "monthly for {$occurances} months";
                 }
                 if ($length > '1') {
                     return "every {$length} months {$occurances} times";
                 }
             }
             if ($unit == "years") {
                 if ($length == '1') {
                     return "annually for {$occurances} years";
                 }
                 if ($length > '1') {
                     return "every {$length} years {$occurances} times";
                 }
             }
             break;
         case 'link':
             $link_to_page = get_permalink(get_option('web_invoice_web_invoice_page'));
             $hashed = md5($this->id);
             if (get_option("permalink_structure")) {
                 return $link_to_page . "?invoice_id=" . $hashed;
             } else {
                 return $link_to_page . "&invoice_id=" . $hashed;
             }
             break;
         case 'invoice_hash':
             return md5($this->id);
             break;
         case 'print_link':
             return $this->display('link') . '&print=1';
             break;
         case 'hash':
             return md5($this->id);
             break;
         case 'currency':
             if (web_invoice_meta($this->id, 'web_invoice_currency_code') != '') {
                 $currency_code = web_invoice_meta($this->id, 'web_invoice_currency_code');
             } else {
                 if (get_option('web_invoice_default_currency_code') != '') {
                     $currency_code = get_option('web_invoice_default_currency_code');
                 } else {
                     $currency_code = "USD";
                 }
             }
             return $currency_code;
             break;
         case 'display_id':
             $web_invoice_custom_invoice_id = web_invoice_meta($this->id, 'web_invoice_custom_invoice_id');
             if (empty($web_invoice_custom_invoice_id)) {
                 return $this->id;
             } else {
                 return $web_invoice_custom_invoice_id;
             }
             break;
         case 'due_date':
             $web_invoice_due_date_month = web_invoice_meta($this->id, 'web_invoice_due_date_month');
             $web_invoice_due_date_year = web_invoice_meta($this->id, 'web_invoice_due_date_year');
             $web_invoice_due_date_day = web_invoice_meta($this->id, 'web_invoice_due_date_day');
             if (!empty($web_invoice_due_date_month) && !empty($web_invoice_due_date_year) && !empty($web_invoice_due_date_day)) {
                 return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime("{$web_invoice_due_date_year}-{$web_invoice_due_date_month}-{$web_invoice_due_date_day}"));
             }
             return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)));
             break;
         case 'due_dateM':
             $web_invoice_due_date_month = web_invoice_meta($this->id, 'web_invoice_due_date_month');
             $web_invoice_due_date_year = web_invoice_meta($this->id, 'web_invoice_due_date_year');
             $web_invoice_due_date_day = web_invoice_meta($this->id, 'web_invoice_due_date_day');
             if (!empty($web_invoice_due_date_month) && !empty($web_invoice_due_date_year) && !empty($web_invoice_due_date_day)) {
                 return date('Y-m-d', strtotime("{$web_invoice_due_date_year}-{$web_invoice_due_date_month}-{$web_invoice_due_date_day}"));
             }
             return date('Y-m-d');
             break;
         case 'invoice_date':
             if ($invoice_info && $invoice_info->invoice_date && !empty($invoice_info->invoice_date)) {
                 date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)), strtotime($invoice_info->invoice_date));
             }
             return date(get_option('date_format', __('Y-m-d', WEB_INVOICE_TRANS_DOMAIN)));
             break;
         case 'amount':
             return $invoice_info->amount;
             break;
         case 'due_amount':
             $payments = web_invoice_sum_payments($this->id);
             return max(0, $invoice_info->amount - $payments);
             break;
         case 'tax_percent':
             $_tax_values = unserialize(web_invoice_meta($this->id, 'tax_value'));
             if (is_array($_tax_values)) {
                 $_tax_value = 0;
                 foreach ($_tax_values as $_tax_valuex) {
                     $_tax_value += $_tax_valuex;
                 }
             } else {
                 $_tax_value = $_tax_values;
             }
             return $_tax_value;
             break;
         case 'tax_total':
             $_tax_values = unserialize(web_invoice_meta($this->id, 'tax_value'));
             if (is_array($_tax_values)) {
                 $_tax_value = 0;
                 foreach ($_tax_values as $_tax_valuex) {
                     $_tax_value += $_tax_valuex;
                 }
             } else {
                 $_tax_value = $_tax_values;
             }
             return $_tax_value * $invoice_info->amount;
             break;
         case 'subject':
             return $invoice_info->subject;
             break;
         case 'display_amount':
             return web_invoice_display_payment($this->display('currency'), $invoice_info->amount);
             break;
         case 'description':
             return str_replace("\n", "<br />", $invoice_info->description);
             break;
         case 'itemized':
             return unserialize(urldecode($invoice_info->itemized));
             break;
         case 'status':
             return $invoice_info->status;
             break;
         case 'trx_id':
             return web_invoice_payment_register($this->id, $this->display('amount'));
             break;
     }
 }
Ejemplo n.º 2
0
 function processRequest($ip, $request)
 {
     $this->ip = $ip;
     $this->tco_order_number = $request['order_number'];
     $this->tco_cart_order_id = $request['cart_order_id'];
     $this->tco_credit_card_processed = $request['credit_card_processed'];
     $this->tco_key = $request['key'];
     $this->tco_demo = $request['demo'];
     $this->tco_total = $request['total'];
     if (!$this->invoice->id) {
         $this->_logFailure('Invoice not found');
         header('HTTP/1.0 404 Not Found');
         header('Content-type: text/plain; charset=UTF-8');
         print 'Invoice not found';
         exit(0);
     }
     $calc_key = md5(get_option('web_invoice_2co_secret_word') . get_option('web_invoice_2co_sid') . $this->tco_order_number . $this->tco_total);
     if (strtolower($this->tco_key) != strtolower($calc_key)) {
         $this->_logFailure('Invalid security code');
         header('HTTP/1.0 403 Forbidden');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were unable to authenticate the request';
         exit(0);
     }
     if (strtolower($this->tco_credit_card_processed) != "y") {
         $this->_logSuccess('2CO order # ' . $this->tco_order_number);
         header('HTTP/1.0 200 OK');
         header('Content-type: text/plain; charset=UTF-8');
         print 'Thank you very much for letting us know. REF: Not success';
         exit(0);
     }
     if (strtolower($this->tco_demo) == "y") {
         if (get_option('web_invoice_2co_demo_mode') == 'TRUE') {
             $this->_logFailure('Test payment');
         }
     } else {
         if (intval($this->tco_total) >= $this->invoice->display('due_amount')) {
             web_invoice_mark_as_paid($this->invoice->id);
         }
         $payment_id = web_invoice_payment_register($this->invoice->id, $this->tco_total, $this->trx_id, 1);
         web_invoice_update_payment_meta($payment_id, 'time_stamp', time());
     }
     header('HTTP/1.0 200 OK');
     header('Content-type: text/plain; charset=UTF-8');
     print 'Thank you very much for letting us know';
     exit(0);
 }