private function fee_selection()
 {
     // Cancel renewal?
     if (isset($_POST['cancel-renewal'])) {
         $this->listing->remove_category($this->category->id, true);
         if (!$this->listing->get_categories('all')) {
             $this->listing->delete();
         }
         return wpbdp_render_msg(_x('Your renewal was successfully cancelled.', 'renewal', 'WPBDM'));
     }
     $fees = wpbdp_get_fees_for_category($this->category->id);
     if (isset($_POST['fees']) && isset($_POST['fees'][$this->category->id])) {
         $fee_id = intval($_POST['fees'][$this->category->id]);
         if ($fee = wpbdp_get_fee($fee_id)) {
             $payment = new WPBDP_Payment(array('listing_id' => $this->listing->get_id()));
             $payment->add_item('fee', $fee->amount, sprintf(_x('Fee "%s" renewal for category "%s"', 'listings', 'WPBDM'), $fee->label, wpbdp_get_term_name($this->category->id)), array('fee_id' => $fee_id, 'fee_days' => $fee->days, 'fee_images' => $fee->images), $this->category->id, $fee_id);
             $payment->save();
             $this->category->payment_id = $payment->get_id();
             return $this->checkout();
         }
     }
     return wpbdp_render('renew-listing', array('listing' => $this->listing, 'category' => $this->category, 'fees' => $fees));
 }
Esempio n. 2
0
 public function get_categories($info = 'current')
 {
     global $wpdb;
     $current_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT category_id FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND (expires_on >= %s OR expires_on IS NULL)", $this->id, current_time('mysql')));
     $expired_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT category_id FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND expires_on IS NOT NULL AND expires_on < %s", $this->id, current_time('mysql')));
     // Pending info.
     $pending_payments = $wpdb->get_results($wpdb->prepare("SELECT pi.payment_id, pi.id, pi.rel_id_1 FROM {$wpdb->prefix}wpbdp_payments_items pi INNER JOIN {$wpdb->prefix}wpbdp_payments p ON p.id = pi.payment_id WHERE pi.item_type IN (%s, %s) AND p.status = %s AND p.listing_id = %d", 'fee', 'recurring_fee', 'pending', $this->id));
     $pending = array();
     foreach ($pending_payments as &$p) {
         $pending[intval($p->rel_id_1)] = $p->id;
         //            $pending_payment_ids[ intval( $p->rel_id_1 ) ] = $p->payment_id;
     }
     $pending_ids = array_keys($pending);
     $category_ids = array();
     switch ($info) {
         case 'all':
             $category_ids = array_merge($current_ids, $expired_ids, $pending_ids);
             break;
         case 'pending':
             $category_ids = $pending_ids;
             break;
         case 'expired':
             $category_ids = $expired_ids;
             break;
         case 'current':
         default:
             $category_ids = $current_ids;
             break;
     }
     $results = array();
     foreach ($category_ids as $category_id) {
         if ($category_info = get_term(intval($category_id), WPBDP_CATEGORY_TAX)) {
             $category = new StdClass();
             $category->id = intval($category_info->term_id);
             $category->name = $category_info->name;
             $category->slug = $category_info->slug;
             $category->term_id = intval($category_info->term_id);
             $category->term_taxonomy_id = intval($category_info->term_taxonomy_id);
             $category->status = in_array($category_id, $pending_ids, true) ? 'pending' : (in_array($category_id, $expired_ids, true) ? 'expired' : 'ok');
             switch ($category->status) {
                 case 'expired':
                 case 'ok':
                     $fee_info = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND category_id = %d", $this->id, $category_id));
                     $fee_info_recurring_data = unserialize($fee_info->recurring_data);
                     if (!$fee_info) {
                         // $this->remove_category( $category_id );
                         continue;
                     }
                     $category->fee_id = intval($fee_info->fee_id);
                     $category->fee_days = intval($fee_info->fee_days);
                     $category->fee_images = intval($fee_info->fee_images);
                     $category->fee = wpbdp_get_fee($category->fee_id);
                     if (!$category->fee) {
                         $category->fee = new StdClass();
                         $category->fee->id = $category->fee_id;
                         $category->fee->label = _x('(Fee Unavailable)', 'listing', 'WPBDM');
                         $category->fee->amount = 0.0;
                         $category->fee->days = $category->fee_days;
                         $category->fee->images = $category->fee_images;
                         $category->fee->categories = array();
                         $category->fee->extra_data = array();
                     }
                     $category->expires_on = $fee_info->expires_on;
                     $category->expired = $category->expires_on && strtotime($category->expires_on) < time() ? true : false;
                     $category->renewal_id = $fee_info->id;
                     $category->recurring = $fee_info->recurring ? true : false;
                     $category->recurring_id = trim($fee_info->recurring_id);
                     $category->payment_id = isset($fee_info_recurring_data['payment_id']) ? $fee_info_recurring_data['payment_id'] : 0;
                     break;
                 case 'pending':
                     $payment_info = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbdp_payments_items WHERE id = %d", $pending[$category_id]));
                     $payment_info->data = unserialize($payment_info->data);
                     $category->fee_id = intval($payment_info->rel_id_2);
                     $category->fee = wpbdp_get_fee($category->fee_id);
                     if (!$category->fee) {
                         $category->fee = new StdClass();
                         $category->fee->id = $category->fee_id;
                         $category->fee->label = _x('(Fee Unavailable)', 'listing', 'WPBDM');
                         $category->fee->amount = 0.0;
                         $category->fee->days = $category->fee_days;
                         $category->fee->images = $category->fee_images;
                         $category->fee->categories = array();
                         $category->fee->extra_data = array();
                     }
                     $category->fee_days = intval($payment_info->data['fee_days']);
                     $category->fee_images = intval($payment_info->data['fee_images']);
                     $category->expires_on = null;
                     // TODO: calculate expiration date.
                     $category->expired = false;
                     $category->renewal_id = 0;
                     $category->recurring = 'recurring_fee' == $payment_info->item_type ? true : false;
                     $category->recurring_id = '';
                     $category->payment_id = intval($payment_info->payment_id);
                     break;
             }
             $results[$category_id] = $category;
         }
     }
     return $results;
 }
 protected function step_save()
 {
     $listing = $this->state->editing ? WPBDP_Listing::get($this->state->listing_id) : WPBDP_Listing::create($this->state);
     $listing->set_field_values($this->state->fields);
     $listing->set_images($this->state->images);
     $listing->set_thumbnail_id($this->state->thumbnail_id);
     if (!$this->state->editing) {
         // Generate payment for the listing.
         $payment = new WPBDP_Payment(array('listing_id' => $listing->get_id()));
         if (!$this->state->editing) {
             $payment->tag('initial');
         }
         foreach ($this->state->categories as $cat_id => $fee_id) {
             $category_info = $listing->get_category_info($cat_id);
             if (!$category_info) {
                 $fee = wpbdp_get_fee($fee_id);
                 if (!$fee) {
                     continue;
                 }
                 $payment->add_item($this->state->autorenew_fees ? 'recurring_fee' : 'fee', $fee->amount, sprintf(_x('Fee "%s" for category "%s"%s', 'listings', 'WPBDM'), $fee->label, wpbdp_get_term_name($cat_id), $this->state->autorenew_fees ? ' ' . _x('(recurring)', 'listings', 'WPBDM') : ''), array('fee_id' => $fee_id, 'fee_days' => $fee->days, 'fee_images' => $fee->images), $cat_id, $fee_id);
             }
         }
         if ($this->state->upgrade_to_sticky) {
             $payment->add_item('upgrade', wpbdp_get_option('featured-price'), _x('Listing upgrade to featured', 'submit', 'WPBDM'));
         }
         $payment->set_submit_state_id($this->state->id);
         if (current_user_can('administrator')) {
             $payment->set_status(WPBDP_Payment::STATUS_COMPLETED);
         }
         $payment->save();
         $this->state->listing_id = $listing->get_id();
         $this->state->payment_id = $payment->get_id();
     }
     do_action_ref_array('wpbdp_listing_form_extra_sections_save', array(&$this->state));
     $listing->save();
     $listing->set_post_status($this->state->editing ? wpbdp_get_option('edit-post-status') : wpbdp_get_option('new-post-status'));
     $this->state->advance(false);
     // This step is 'invisible'.
     return $this->dispatch();
 }
Esempio n. 4
0
 public function add_category_fee_item($category_id, $fee)
 {
     if (is_int($fee)) {
         $fee = wpbdp_get_fee($fee);
         if (!$fee) {
             return false;
         }
     }
     $this->add_item('fee', $fee->amount, sprintf(_x('Fee "%s" for category "%s"', 'listings', 'WPBDM'), $fee->label, wpbdp_get_term_name($category_id)), array('fee_id' => $fee->id, 'fee_days' => $fee->days, 'fee_images' => $fee->images), $category_id, $fee->id);
     return true;
 }