Exemple #1
0
 /**
  * pay an invoice, renders the paymenthods button, anyone with an ID of an order can pay it, we do not have control
  * @return [type] [description]
  */
 public function action_checkout()
 {
     $order = new Model_Order($this->request->param('id'));
     if ($order->loaded()) {
         //hack jquery paymill
         Paymill::jquery();
         //if paid...no way jose
         if ($order->status != Model_Order::STATUS_CREATED) {
             Alert::set(Alert::INFO, __('This order was already paid.'));
             $this->redirect(Route::url('default'));
         }
         //checks coupons or amount of featured days
         $order->check_pricing();
         //template header
         $this->template->title = __('Checkout') . ' ' . Model_Order::product_desc($order->id_product);
         Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
         Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Pricing'))->set_url(Route::url('pricing')));
         Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
         Controller::$full_width = TRUE;
         $this->template->bind('content', $content);
         $this->template->content = View::factory('pages/ad/checkout', array('order' => $order));
     } else {
         //throw 404
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
 /**
  * generates HTML for apy buton
  * @param  Model_Order $order 
  * @return string                 
  */
 public static function button(Model_Order $order)
 {
     if (Core::config('payment.paymill_private') != '' and Core::config('payment.paymill_public') != '' and Theme::get('premium') == 1 and $order->loaded()) {
         return View::factory('pages/paymill/button', array('order' => $order));
     }
     return '';
 }
Exemple #3
0
 /**
  * generates HTML form
  * @param  Model_Product $order 
  * @return string                 
  */
 public static function form(Model_Order $order)
 {
     if (Core::config('payment.authorize_login') != '' and Core::config('payment.authorize_key') != '' and Auth::instance()->logged_in() and $order->loaded() and Theme::get('premium') == 1) {
         return View::factory('pages/authorize/form', array('order' => $order));
     }
     return '';
 }
Exemple #4
0
 /**
  * [action_form] generates the form to pay at paypal
  */
 public function action_pay()
 {
     $this->auto_render = FALSE;
     $order_id = $this->request->param('id');
     $order = new Model_Order();
     $order->where('id_order', '=', $order_id)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         // case when selling advert
         if ($order->id_product == Model_Order::PRODUCT_AD_SELL) {
             $paypal_account = $order->ad->paypal_account();
             $currency = i18n::get_intl_currency_symbol();
             if (isset($order->ad->cf_shipping) and Valid::numeric($order->ad->cf_shipping) and $order->ad->cf_shipping > 0) {
                 $order->amount = $order->amount + $order->ad->cf_shipping;
             }
         } else {
             $paypal_account = core::config('payment.paypal_account');
             $currency = core::config('payment.paypal_currency');
         }
         $paypal_url = Core::config('payment.sandbox') ? Paypal::url_sandbox_gateway : Paypal::url_gateway;
         $paypal_data = array('order_id' => $order_id, 'amount' => number_format($order->amount, 2, '.', ''), 'site_name' => core::config('general.site_name'), 'site_url' => URL::base(TRUE), 'paypal_url' => $paypal_url, 'paypal_account' => $paypal_account, 'paypal_currency' => $currency, 'item_name' => $order->description);
         $this->template = View::factory('paypal', $paypal_data);
         $this->response->body($this->template->render());
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->redirect(Route::url('default'));
     }
 }
 /**
  * generates HTML for apy buton
  * @param  Model_Order $order 
  * @return string                 
  */
 public static function button(Model_Order $order)
 {
     if (Core::config('payment.bitpay_apikey') != '' and Theme::get('premium') == 1 and Auth::instance()->logged_in() and $order->loaded()) {
         return View::factory('pages/bitpay/button', array('order' => $order));
     }
     return '';
 }
Exemple #6
0
 /**
  * [action_form] generates the form to pay at paypal
  */
 public function action_form()
 {
     $this->auto_render = FALSE;
     $order_id = $this->request->param('id');
     $order = new Model_Order();
     $order->where('id_order', '=', $order_id)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         // dependant on product we have different names
         if ($order->id_product == Paypal::to_featured) {
             $item_name = __('Advertisement to featured');
         } else {
             if ($order->id_product == Paypal::to_top) {
                 $item_name = __('Advertisement to top');
             } else {
                 $item_name = $order->description . __(' category');
             }
         }
         $paypal_url = Core::config('payment.sandbox') ? Paypal::url_sandbox_gateway : Paypal::url_gateway;
         $paypal_data = array('order_id' => $order_id, 'amount' => number_format($order->amount, 2, '.', ''), 'site_name' => core::config('general.site_name'), 'site_url' => URL::base(TRUE), 'paypal_url' => $paypal_url, 'paypal_account' => core::config('payment.paypal_account'), 'paypal_currency' => core::config('payment.paypal_currency'), 'item_name' => $item_name);
         $this->template = View::factory('paypal', $paypal_data);
         $this->response->body($this->template->render());
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->request->redirect(Route::url('default'));
     }
 }
Exemple #7
0
 public function action_pay()
 {
     $this->auto_render = FALSE;
     $order_id = $this->request->param('id');
     $order = new Model_Order();
     $order->where('id_order', '=', $order_id)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         $paypal_url = Core::config('payment.sandbox') ? Paypal::url_sandbox_gateway : Paypal::url_gateway;
         $paypal_data = array('order_id' => $order_id, 'amount' => number_format($order->amount, 2, '.', ''), 'site_name' => core::config('general.site_name'), 'return_url' => Route::url('default', array('controller' => 'product', 'action' => 'goal', 'id' => $order->id_order)), 'paypal_url' => $paypal_url, 'paypal_account' => core::config('payment.paypal_account'), 'paypal_currency' => $order->currency, 'item_name' => $order->product->title);
         $this->template = View::factory('paypal', $paypal_data);
         $this->response->body($this->template->render());
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->redirect(Route::url('default'));
     }
 }
Exemple #8
0
 /**
  * [new_order description]
  * @param  Model_User    $user    [description]
  * @param  Model_Product $product [description]
  * @param  boolean       check_match_product, if set to false will update the order with the product if different
  * @return [type]                 [description]
  */
 public static function new_order(Model_User $user, Model_Product $product, $match_product = TRUE)
 {
     $order = new Model_Order();
     if ($user->loaded() and $product->loaded()) {
         //get if theres an unpaid order for this user we wwill use it..
         $order->where('id_user', '=', $user->id_user)->where('status', '=', Model_Order::STATUS_CREATED);
         //also check that matches the product for the order
         if ($match_product === TRUE) {
             $order->where('id_product', '=', $product->id_product)->where('amount', '=', $product->final_price())->where('currency', '=', $product->currency);
         }
         $order->limit(1)->find();
         //order didnt exist so lets create it.
         if ($order->loaded() === FALSE) {
             //create order
             $order = new Model_Order();
             $order->id_user = $user->id_user;
         }
         // no matter what happens if product is different save! this will also save the order if its new ;)
         if ($order->id_product != $product->id_product) {
             $order->ip_address = ip2long(Request::$client_ip);
             $order->id_product = $product->id_product;
             $order->currency = $product->currency;
             //add coupon ID and discount
             if (Model_Coupon::current()->loaded()) {
                 $order->id_coupon = Model_Coupon::current()->id_coupon;
             }
             $order->amount = $product->final_price();
             $order->VAT = euvat::vat_percentage();
             $order->VAT_number = $user->VAT_number;
             $order->country = $user->country;
             $order->city = $user->city;
             $order->postal_code = $user->postal_code;
             $order->address = $user->address;
             try {
                 $order->save();
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
         }
     }
     return $order;
 }
Exemple #9
0
 /**
  * creates an order
  * @param  Model_Ad $ad    
  * @param  Model_User $user          
  * @param  integer   $id_product  
  * @param  numeric   $amount      
  * @param  string   $currency    
  * @param  string   $description 
  * @return Model_Order                
  */
 public static function new_order(Model_Ad $ad, $user, $id_product, $amount, $currency = NULL, $description = NULL, $featured_days = NULL)
 {
     if ($currency === NULL) {
         $currency = core::config('payment.paypal_currency');
     }
     if ($description === NULL) {
         $description = Model_Order::product_desc($id_product);
     }
     //get if theres an unpaid order for this product and this ad
     $order = new Model_Order();
     $order->where('id_ad', '=', $ad->id_ad)->where('id_user', '=', $user->id_user)->where('status', '=', Model_Order::STATUS_CREATED)->where('id_product', '=', $id_product)->where('amount', '=', $amount)->where('currency', '=', $currency)->limit(1)->find();
     //if no unpaid create order
     if (!$order->loaded()) {
         //add coupon ID and discount only if not AD_SELL
         if (Model_Coupon::valid($id_product)) {
             $amount = Model_Coupon::price($id_product, $amount);
             $order->id_coupon = Model_Coupon::current()->id_coupon;
         }
         //create order
         $order = new Model_Order();
         $order->id_user = $user->id_user;
         $order->id_ad = $ad->id_ad;
         $order->id_product = $id_product;
         $order->currency = $currency;
         $order->amount = $amount;
         $order->description = $description;
         //store how many days the ad is featured
         if ($featured_days !== NULL and is_numeric($featured_days)) {
             $order->featured_days = $featured_days;
         }
         try {
             $order->save();
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         //send email to user with link to pay
         $url_checkout = $user->ql('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order));
         $replace = array('[ORDER.ID]' => $order->id_order, '[ORDER.DESC]' => $order->description, '[URL.CHECKOUT]' => $url_checkout);
         //$user->email('new-order',$replace);
     }
     return $order;
 }
Exemple #10
0
 /**
  * returns and order for the given product, great to check if was paid or not
  * @param  int  $id_product Model_Order::PRODUCT_
  * @return boolean/Model_Order             false if not found, Model_Order if found
  */
 public function get_order($id_product = Model_Order::PRODUCT_CATEGORY)
 {
     if ($this->loaded()) {
         //get if theres an unpaid order for this product and this ad
         $order = new Model_Order();
         $order->where('id_ad', '=', $this->id_ad)->where('id_user', '=', $this->user->id_user)->where('id_product', '=', $id_product)->limit(1)->find();
         return $order->loaded() ? $order : FALSE;
     }
     return FALSE;
 }
Exemple #11
0
 public function action_order()
 {
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('My Purchases'))->set_url(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'))));
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Order')));
     $this->template->title = __('View Order');
     $user = Auth::instance()->get_user();
     $id_order = $this->request->param('id');
     $order = new Model_Order();
     $order->where('id_order', '=', $id_order);
     //if admin we do not verify the user
     if ($user->id_role != Model_Role::ROLE_ADMIN) {
         $order->where('id_user', '=', $user->id_user);
     }
     $order->find();
     if (!$order->loaded()) {
         Alert::set(ALERT::WARNING, __('Order could not be loaded'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
     }
     $this->template->bind('content', $content);
     $this->template->content = View::factory('oc-panel/profile/order');
     $content->order = $order;
     $content->product = $order->id_product;
     $content->user = $user;
     if (core::get('print') == 1) {
         $this->template->scripts['footer'] = array('js/oc-panel/order.js');
     }
 }
 /**
  * confirms a checkout when its a free order
  * @return [type] [description]
  */
 public function action_checkoutfree()
 {
     $order = new Model_Order($this->request->param('id'));
     if ($order->loaded()) {
         //if paid...no way jose
         if ($order->status != Model_Order::STATUS_CREATED) {
             Alert::set(Alert::INFO, __('This order was already paid.'));
             $this->redirect(Route::url('default'));
         }
         //checks coupons or amount of featured days
         $order->check_pricing();
         //he needs to pay...little prick
         if ($order->amount > 0) {
             $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
         } else {
             $order->confirm_payment('cash');
             $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
         }
     } else {
         //throw 404
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
Exemple #13
0
 /**
  * pay!
  */
 public function action_checkout()
 {
     if (!Auth::instance()->logged_in()) {
         $this->redirect(Route::get('oc-panel')->uri());
     }
     $user = Auth::instance()->get_user();
     //resend confirmation email
     if (is_numeric($id_order = $this->request->param('id'))) {
         $order = new Model_Order($id_order);
         if ($order->loaded() and $order->id_user == $user->id_user and $order->status == Model_Order::STATUS_CREATED) {
             //verify the coupon and check order against user information, if its different update order info and maybe price!
             $order->check_pricing();
             $this->template->title = __('Checkout');
             Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
             $this->template->content = View::factory('pages/product/checkout', array('order' => $order, 'user' => $user, 'product' => $order->product));
         } else {
             Alert::set(Alert::WARNING, __('Order not found or already paid'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
         }
     } else {
         Alert::set(Alert::ERROR, __('Order not found'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
     }
 }
Exemple #14
0
 public function action_new()
 {
     $errors = NULL;
     $user = Auth::instance()->get_user();
     //create new ticket
     if ($_POST) {
         //if post save
         $id_order = core::post('order');
         //check if that order still have support...no cheating!! :D
         $order = new Model_Order();
         $order->where('id_order', '=', $id_order)->where('id_user', '=', $user->id_user)->where('support_date', '>', Date::unix2mysql())->where('status', '=', Model_Order::STATUS_PAID)->limit(1)->find();
         $validation = Validation::factory($this->request->post())->rule('title', 'not_empty')->rule('title', 'min_length', array(':value', 2))->rule('title', 'max_length', array(':value', 145))->rule('description', 'not_empty')->rule('description', 'min_length', array(':value', 50))->rule('description', 'max_length', array(':value', 1000))->rule('order', 'not_empty')->rule('order', 'numeric');
         if ($validation->check() and $order->loaded()) {
             $ticket = new Model_Ticket();
             $ticket->id_user = $user->id_user;
             $ticket->id_order = $id_order;
             $ticket->id_product = $order->product->id_product;
             $ticket->title = core::post('title');
             $ticket->description = core::post('description');
             $ticket->ip_address = ip2long(Request::$client_ip);
             $ticket->save();
             //send email to notify_url @todo we should add a config on general to select who gets the emails by default.
             if (core::config('email.new_sale_notify')) {
                 Email::send(core::config('email.notify_email'), '', 'New Ticket: ' . $ticket->title, Route::url('oc-panel', array('controller' => 'support', 'action' => 'ticket', 'id' => $ticket->id_ticket)) . '\\n\\n' . $ticket->description, core::config('email.notify_email'), '');
             }
             $user->email('new-ticket', array('[TITLE]' => $ticket->title, '[URL.QL]' => $user->ql('oc-panel', array('controller' => 'support', 'action' => 'ticket', 'id' => $ticket->id_ticket))));
             Alert::set(Alert::SUCCESS, __('Ticket created.'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'support', 'action' => 'index')));
         } else {
             $errors = $validation->errors('ad');
         }
     }
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('New Ticket')));
     $this->template->title = __('New Ticket');
     //get orders with support
     $orders = new Model_Order();
     $orders = $orders->where('id_user', '=', $user->id_user)->where('support_date', '>', Date::unix2mysql())->where('status', '=', Model_Order::STATUS_PAID)->find_all();
     if ($orders->count() == 0) {
         Alert::set(Alert::ALERT, __('You do not have any purchase with support active.'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'support', 'action' => 'index')));
     }
     $this->template->bind('content', $content);
     $this->template->content = View::factory('oc-panel/pages/support/new', array('orders' => $orders));
     $content->errors = $errors;
 }
Exemple #15
0
 /**
  * pay an invoice, renders the paymenthods button, anyone with an ID of an order can pay it, we do not have control
  * @return [type] [description]
  */
 public function action_checkout()
 {
     $order = new Model_Order($this->request->param('id'));
     if ($order->loaded()) {
         //if paid...no way jose
         if ($order->status != Model_Order::STATUS_CREATED) {
             Alert::set(Alert::INFO, __('This order was already paid.'));
             $this->redirect(Route::url('default'));
         }
         //update order based on the price and the amount of
         $days = core::get('featured_days');
         if (is_numeric($days) and ($price = Model_Order::get_featured_price($days)) !== FALSE) {
             $order->amount = $price;
             //get price from config
             $order->featured_days = $days;
             $order->save();
         }
         //template header
         $this->template->title = __('Checkout') . ' ' . Model_Order::product_desc($order->id_product);
         Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
         Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
         Controller::$full_width = TRUE;
         $this->template->bind('content', $content);
         $this->template->content = View::factory('pages/ad/checkout', array('order' => $order));
     } else {
         //throw 404
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
Exemple #16
0
 /**
  * user ads a new review
  * @return [type] [description]
  */
 public function action_review()
 {
     $id_order = $this->request->param('id');
     $user = Auth::instance()->get_user();
     $order = new Model_Order();
     $order->where('id_user', '=', $user->id_user)->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_PAID)->limit(1)->find();
     if ($order->loaded()) {
         $product = $order->product;
         Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Purchases'))->set_url(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'))));
         Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Review') . ' ' . $product->title));
         $this->template->title = __('Review product') . ' ' . $product->title;
         $this->template->scripts['footer'][] = 'js/jquery.raty.min.js';
         $this->template->scripts['footer'][] = 'js/oc-panel/review.js';
         //lets see if we had the review already done..
         $review = new Model_Review();
         $review->where('id_user', '=', $user->id_user)->where('id_product', '=', $product->id_product)->where('id_order', '=', $order->id_order)->where('status', '=', Model_Review::STATUS_ACTIVE)->limit(1)->find();
         $this->template->bind('content', $content);
         $errors = NULL;
         if ($this->request->post() and !$review->loaded()) {
             $validation = Validation::factory($this->request->post())->rule('rate', 'numeric')->rule('description', 'not_empty')->rule('description', 'min_length', array(':value', 5))->rule('description', 'max_length', array(':value', 1000));
             if ($validation->check()) {
                 $rate = core::post('rate');
                 if ($rate > Model_Review::RATE_MAX) {
                     $rate = Model_Review::RATE_MAX;
                 } elseif ($rate < 0) {
                     $rate = 0;
                 }
                 $review = new Model_Review();
                 $review->id_user = $user->id_user;
                 $review->id_order = $order->id_order;
                 $review->id_product = $product->id_product;
                 $review->description = core::post('description');
                 $review->status = Model_Review::STATUS_ACTIVE;
                 $review->ip_address = ip2long(Request::$client_ip);
                 $review->rate = $rate;
                 $review->save();
                 //email product owner?? notify him of new review
                 $product->user->email('review-product', array('[TITLE]' => $product->title, '[RATE]' => $review->rate, '[DESCRIPTION]' => $review->description, '[URL.QL]' => $product->user->ql('product-review', array('seotitle' => $product->seotitle, 'category' => $product->category->seoname))));
                 $product->recalculate_rate();
                 Alert::set(Alert::SUCCESS, __('Thanks for your review!'));
                 $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
             } else {
                 $errors = $validation->errors('ad');
                 foreach ($errors as $f => $err) {
                     Alert::set(Alert::ALERT, $err);
                 }
             }
         }
         $this->template->content = View::factory('oc-panel/profile/review', array('order' => $order, 'product' => $product, 'errors' => $errors, 'review' => $review));
     } else {
         $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
     }
 }