Example #1
0
 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);
     }
 }
Example #2
0
 /**
  * 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;
             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;
     }
     return $amount;
 }
            <?php 
    }
    ?>
        
            <?php 
    if (core::config('payment.to_featured') != FALSE and $widget->ad->featured < Date::unix2mysql()) {
        ?>
                <a class="btn btn-danger center-block" type="button" href="<?php 
        echo Route::url('default', array('action' => 'to_featured', 'controller' => 'ad', 'id' => $widget->ad->id_ad));
        ?>
">
                    <?php 
        echo _e('Go Featured!');
        ?>
 <?php 
        echo i18n::money_format(Model_Order::get_featured_price(), core::config('payment.paypal_currency'));
        ?>
                </a>
            <?php 
    }
    ?>
        
            <div class="clearfix"></div><br>
        
            <a class="btn btn-primary" href="<?php 
    echo Route::url('oc-panel', array('controller' => 'myads', 'action' => 'update', 'id' => $widget->ad->id_ad));
    ?>
">
                <i class="glyphicon glyphicon-edit"></i> <?php 
    echo _e("Edit");
    ?>
 /**
  * [action_to_featured] [pay to go in featured]
  *
  */
 public function action_to_featured()
 {
     //check pay to featured top is enabled
     if (core::config('payment.to_featured') == FALSE) {
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
     $id_product = Model_Order::PRODUCT_TO_FEATURED;
     //check ad exists
     $id_ad = $this->request->param('id');
     //how many days
     if (!is_numeric($days = Core::request('featured_days'))) {
         $plans = Model_Order::get_featured_plans();
         $days = array_keys($plans);
         $days = reset($days);
     }
     //get price for the days
     $amount = Model_Order::get_featured_price($days);
     $ad = new Model_Ad($id_ad);
     if ($ad->loaded()) {
         //case when payment is set to 0,gets featured for free...
         if ($amount <= 0) {
             $ad->featured = Date::unix2mysql(time() + $days * 24 * 60 * 60);
             try {
                 $ad->save();
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
             $this->redirect(Route::url('list'));
         }
         $currency = core::config('payment.paypal_currency');
         $order = Model_Order::new_order($ad, $ad->user, $id_product, $amount, $currency, NULL, $days);
         // redirect to payment
         $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
     } else {
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
Example #5
0
                <?if(core::config('payment.pay_to_go_on_top') > 0 && core::config('payment.to_top') != FALSE):?>
                    <p class="text-info"><?php 
echo __('Your Advertisement can go on top again! For only ') . i18n::format_currency(core::config('payment.pay_to_go_on_top'), core::config('payment.paypal_currency'));
?>
</p>
                    <a class="btn btn-xs btn-primary" type="button" href="<?php 
echo Route::url('default', array('action' => 'to_top', 'controller' => 'ad', 'id' => $ad->id_ad));
?>
"><?php 
echo __('Go Top!');
?>
</a>
                <?endif?>
                <?if(core::config('payment.to_featured') != FALSE AND $ad->featured < Date::unix2mysql()):?>
                    <p class="text-info"><?php 
echo __('Your Advertisement can go to featured! For only ') . i18n::format_currency(Model_Order::get_featured_price(), core::config('payment.paypal_currency'));
?>
</p>
                    <a class="btn btn-xs btn-primary" type="button" href="<?php 
echo Route::url('default', array('action' => 'to_featured', 'controller' => 'ad', 'id' => $ad->id_ad));
?>
"><?php 
echo __('Go Featured!');
?>
</a>
                <?endif?>
            </div>
        <?endif?>
    <?endif?>
    <!-- end paypal button -->
    
Example #6
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'));
     }
 }