private function checkout() { $sticky_info = $this->upgrades_api->get_info($this->listing->get_id()); if ($sticky_info->pending || !$sticky_info->upgradeable || !wpbdp_payments_possible()) { return; } $payment = new WPBDP_Payment(array('listing_id' => $this->listing->get_id())); $payment->add_item('upgrade', $sticky_info->upgrade->cost, _x('Listing upgrade to featured', 'submit', 'WPBDM')); $payment->save(); update_post_meta($this->listing->get_id(), '_wpbdp[sticky]', 'pending'); // FIXME: maybe this should be set automatically when saving the payment? require_once WPBDP_PATH . 'core/view-checkout.php'; $checkout = new WPBDP_Checkout_Page($payment); return $checkout->dispatch(); }
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)); }
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(); }
public function generate_recurring_payment() { $recurring_item = $this->get_recurring_item(); if (!$recurring_item) { return null; } $rp = new WPBDP_Payment(array('listing_id' => $this->get_listing_id(), 'gateway' => $this->get_gateway(), 'currency_code' => $this->get_currency_code(), 'amount' => 0.0, 'payerinfo' => $this->payerinfo, 'extra_data' => array('recurring_id' => $this->get_data('recurring_id'), 'parent_payment_id' => $this->id))); $rp->add_item('recurring_fee', $recurring_item->amount, $recurring_item->description, $recurring_item->data, $recurring_item->rel_id_1, $recurring_item->rel_id_2); $rp->save(); return $rp; }