/** * [action_buy] Pay for ad, and set new order * */ public function action_buy() { if (Core::config('general.subscriptions') == FALSE) { throw HTTP_Exception::factory(404, __('Page not found')); } //getting the user that wants to buy now if (!Auth::instance()->logged_in()) { Alert::set(Alert::INFO, __('To buy this product you need to register first.')); $this->redirect(Route::url('oc-panel')); } //check plan exists $plan = new Model_Plan(); $plan->where('seoname', '=', $this->request->param('id'))->where('status', '=', 1)->find(); //loaded published and with stock if we control the stock. if ($plan->loaded() and $plan->status == 1) { //free plan can not be renewed if ($plan->price == 0 and $this->user->subscription()->id_plan == $plan->id_plan) { Alert::set(Alert::WARNING, __('Free plan can not be renewed, before expired')); HTTP::redirect(Route::url('pricing')); } $order = Model_Order::new_order(NULL, $this->user, $plan->id_plan, $plan->price, core::config('payment.paypal_currency'), __('Subscription to ') . $plan->name); //free plan no checkout if ($plan->price == 0) { $order->confirm_payment('cash'); $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'))); } else { $this->redirect(Route::url('default', array('controller' => 'plan', 'action' => 'checkout', 'id' => $order->id_order))); } } else { throw HTTP_Exception::factory(404, __('Page not found')); } }
/** * returns the original price of the order * @return float */ public function original_price() { //get original price for the product switch ($this->id_product) { case self::PRODUCT_CATEGORY: $amount = $this->ad->category->price > 0 ? $this->ad->category->price : $this->ad->category->parent->price; break; case self::PRODUCT_TO_TOP: $amount = core::config('payment.pay_to_go_on_top'); break; case self::PRODUCT_TO_FEATURED: $amount = Model_Order::get_featured_price($this->featured_days); break; case self::PRODUCT_AD_SELL: $amount = $this->ad->price; break; default: $plan = new Model_Plan($this->id_product); $amount = $plan->loaded() ? $plan->price : 0; break; } return $amount; }
public function action_create() { try { if (!is_numeric(core::request('id_ad')) or !is_numeric(core::request('id_product')) or !is_numeric(core::request('id_user'))) { $this->_error(__('Missing parameters'), 501); } else { $user = new Model_User(core::request('id_user')); $ad = new Model_Ad(core::request('id_ad')); if ($user->loaded() and $ad->loaded()) { $id_product = core::request('id_product'); $amount = core::request('amount'); //in case not set by request if (!is_numeric($amount)) { //get original price for the product switch ($id_product) { case Model_Order::PRODUCT_CATEGORY: $amount = $ad->category->price; break; case Model_Order::PRODUCT_TO_TOP: $amount = core::config('payment.pay_to_go_on_top'); break; case Model_Order::PRODUCT_TO_FEATURED: $amount = Model_Order::get_featured_price(core::request('featured_days')); break; case Model_Order::PRODUCT_AD_SELL: $amount = $ad->price; break; default: $plan = new Model_Plan($id_product); $amount = $plan->loaded() ? $plan->price : 0; break; } } $order = Model_Order::new_order($ad, $user, $id_product, $amount, core::request('currency'), Model_Order::product_desc(core::request('id_product')), core::request('featured_days')); $order->confirm_payment(core::request('paymethod', 'API'), core::request('txn_id')); $order->save(); $this->rest_output(array('order' => self::get_order_array($order))); } else { $this->_error(__('User or Ad not loaded'), 501); } } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); } }