/**
  * 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 '';
 }
 public function sendPush($sender, $sn, $message)
 {
     return;
     //发送推送通知
     include APPLICATION_PATH . 'libs/ApnsPHP/Log/Interface.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Log/Embedded.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Log/Null.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Abstract.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Exception.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Feedback.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Message.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Push.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Message/Custom.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Message/Exception.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Push/Server.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Push/Exception.php';
     include APPLICATION_PATH . 'libs/ApnsPHP/Push/Server/Exception.php';
     $order = new Model_Order($sn);
     $passengerDeviceId = $order->get('passenger_device_id');
     $ofd = new Model_OrderForDriver($sn);
     $driver = new Model_Driver($ofd->get('driver_code'));
     $driverDeviceId = $driver->get('device_id');
     //$certSuffix = APPLICATION_ENV == 'development' ? '-dev.pem' : '.pem';
     $certSuffix = '-dev.pem';
     $passengerCert = APPLICATION_PATH . '/data/passenger' . $certSuffix;
     $driverCert = APPLICATION_PATH . '/data/driver' . $certSuffix;
     if ($sender == Model_OrderConversation::SENDER_DRIVER) {
         $this->sendPushToDevice($passengerCert, $passengerDeviceId, $message, $sn);
     } elseif ($sender == Model_OrderConversation::SENDER_PASSENGER) {
         $this->sendPushToDevice($driverCert, $driverDeviceId, $message, $sn);
     } else {
         $this->sendPushToDevice($passengerCert, $passengerDeviceId, $message, $sn);
         $this->sendPushToDevice($driverCert, $driverDeviceId, $message, $sn);
     }
 }
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_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'));
     }
 }
 /**
  * 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 #6
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'));
     }
 }
Exemple #7
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'));
     }
 }
Exemple #8
0
 public function action_commit()
 {
     $user_id = \Session::get(self::SESSION_KEY_USER_ID);
     $user = Model_Member::find($user_id);
     $address = \Session::get(self::SESSION_KEY_ADDRESS);
     /*------make order----------------------------------------------------------*/
     $order = new Model_Order();
     $order->member_id = $user->id;
     $order->postalcode = $address['postalcode'];
     $order->destination = $address['address'] . $address['billname'] . $address['companyname'];
     $date = time();
     $order->order_date = date('Y-m-d H:i:s', $date);
     $order->print_flag = 0;
     $order->status = 0;
     $order->save();
     /*-----make orderline------------------------*/
     $cart = \Session::get(self::SESSION_KEY_CART);
     foreach ($cart['orders'] as $orderline) {
         $item_id = $orderline['item_id'];
         $item = Model_Item::find($item_id);
         $num = $orderline['quantity'];
         $size = $orderline['size'];
         $neworderline = new Model_Orderline();
         $neworderline->order_id = $order->id;
         $neworderline->item_id = $item_id;
         $neworderline->num = $num;
         $neworderline->size = $size;
         $neworderline->save();
         $earning = new Model_Earning();
         $earning->member_id = $user->id;
         $earning->item_id = $item_id;
         $earning->size = $size;
         switch ($size) {
             case 'S':
                 $unit_price = $neworderline->item->unit_price_s;
                 break;
             case 'M':
                 $unit_price = $neworderline->item->unit_price_m;
                 break;
             case 'L':
                 $unit_price = $neworderline->item->unit_price_m;
                 break;
             default:
                 $unit_price = $neworderline->item->unit_price;
                 break;
         }
         $earning->unit_price = $unit_price;
         $earning->num = $num;
         $earning->date = date('Y-m-d H:i:s', $date);
         $earning->category = $item->category;
         $earning->item_name = $item->name;
         $now = date('Ymd');
         $birthday = date('Ymd', strtotime($user->birthday));
         $earning->age = (int) floor(($now - $birthday) / 10000);
         $earning->save();
     }
     \Session::delete(self::SESSION_KEY_CART);
     return Response::redirect('index.php/message/commit');
 }
 public function init()
 {
     parent::init();
     $sn = strtoupper(trim($this->_getParam('sn', '')));
     $order = new Model_Order($sn);
     if (empty($sn) || !$order->exists()) {
         $this->error('Order Not Found.');
     }
     $this->sn = $sn;
     $this->order = $order;
 }
Exemple #10
0
 public function action_historyin($order_id)
 {
     if (empty(\Session::get(self::SESSION_KEY_CART))) {
         \Session::set(self::SESSION_KEY_CART, array('orders' => array()));
     }
     $cart = \Session::get(self::SESSION_KEY_CART);
     $order = Model_Order::find($order_id);
     $total_money = 0;
     foreach ($order->orderline as $orderline) {
         $item = Model_Item::find($orderline['item_id']);
         $quantity = $orderline['num'];
         switch ($orderline['size']) {
             case 'S':
                 $price = $item->unit_price_s;
                 break;
             case 'M':
                 $price = $item->unit_price_m;
                 break;
             case 'L':
                 $price = $item->unit_price_l;
                 break;
             default:
                 $price = $item->unit_price;
                 break;
         }
         $money = $price * $quantity;
         array_push($cart['orders'], array('item_id' => $item['id'], 'item_name' => $item['name'], 'size' => $orderline['size'], 'quantity' => $quantity, 'money' => $money));
     }
     foreach ($cart['orders'] as $order) {
         $total_money += $order['money'];
     }
     $cart['total_money'] = $total_money;
     \Session::set(self::SESSION_KEY_CART, $cart);
     return Response::redirect('mtpizza/cart');
 }
 /**
  * expired featured ads
  * @return void
  */
 public static function renew()
 {
     if (Core::config('general.subscriptions') == TRUE) {
         //get expired subscription that are active
         $subscriptions = new Model_Subscription();
         $subscriptions = $subscriptions->where('status', '=', 1)->where('expire_date', '<=', Date::unix2mysql())->order_by('created', 'desc')->find_all();
         foreach ($subscriptions as $s) {
             //disable the plan
             $s->status = 0;
             try {
                 $s->save();
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
             $plan = $s->plan;
             if ($plan->loaded() and $plan->status == 1) {
                 //generate a new order
                 $order = Model_Order::new_order(NULL, $s->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');
                 } else {
                     $checkout_url = $s->user->ql('default', array('controller' => 'plan', 'action' => 'checkout', 'id' => $order->id_order));
                     $s->user->email('plan-expired', array('[PLAN.NAME]' => $plan->name, '[URL.CHECKOUT]' => $checkout_url));
                 }
             }
             //if plan loaded
         }
         //end foreach
     }
     //if subscription active
 }
Exemple #12
0
 public function action_order()
 {
     define("SECONDS_PER_DAY", 3600 * 24);
     $now = time();
     $cart = Session::get('cart');
     $user = Model_User::find($this->sessUser->id);
     $cart_info = [];
     $order = Model_Order::forge();
     $order->user_id = $user->id;
     $order->created_at = $now;
     $order->save();
     if (!is_null($cart)) {
         foreach ($cart as $product_id => $quantity) {
             $product = Model_Product::find($product_id);
             $order_product = Model_OrderProduct::forge();
             $order_product->order_id = $order->id;
             $order_product->product_id = $product->id;
             $order_product->quantity = $quantity;
             $order_product->price = $product->price;
             $order_product->save();
         }
     }
     Session::delete('cart');
     return Response::redirect('/cart');
 }
Exemple #13
0
 public function action_create()
 {
     try {
         if (!Valid::email(core::request('email'))) {
             $this->_error(__('Invalid email'), 501);
         } elseif (!is_numeric(core::request('id_product'))) {
             $this->_error(__('Invalid product'), 501);
         } else {
             $product = new Model_Product(core::request('id_product'));
             if ($product->loaded()) {
                 $user = Model_User::create_email(core::request('email'), core::request('name'));
                 $order = Model_Order::new_order($user, $product);
                 $order->confirm_payment(core::request('paymethod', 'API'), core::request('txn_id'), core::request('pay_date'), core::request('amount'), core::request('currency'), core::request('fee'));
                 //adding the notes
                 $order->notes = core::request('notes');
                 $order->save();
                 $this->rest_output(array('order' => self::get_order_array($order)));
             } else {
                 $this->_error(__('Something went wrong'), 501);
             }
         }
     } catch (Kohana_HTTP_Exception $khe) {
         $this->_error($khe);
     }
 }
Exemple #14
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 #15
0
 public function action_detail($order_id)
 {
     $order = Model_Order::find($order_id);
     $data['member'] = $order->member;
     $data['orders'] = $order;
     $data['details'] = $order->orderline;
     return View::forge("controlsystem/members/detail", $data);
 }
Exemple #16
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 #17
0
 /**
  *
  * view affiliates and payments
  */
 public function action_pay()
 {
     //create an order and mark it as paid to the user_id
     if (is_numeric($this->request->param('id'))) {
         //get the user
         $user = new Model_User($this->request->param('id'));
         if ($user->loaded()) {
             //commissions due to pay
             $query = DB::select(DB::expr('SUM(amount) total'))->from('affiliates')->where('id_user', '=', $user->id_user)->where('date_to_pay', '<', Date::unix2mysql())->where('status', '=', Model_Affiliate::STATUS_CREATED)->group_by('id_user')->execute();
             $due_to_pay = $query->as_array();
             $due_to_pay = isset($due_to_pay[0]['total']) ? $due_to_pay[0]['total'] : 0;
             if ($due_to_pay > 0) {
                 //create the order
                 $order = new Model_Order();
                 $order->id_user = $user->id_user;
                 $order->amount = $due_to_pay * -1;
                 //we add the order as a negative, since we pay, we don't get paid.
                 $order->currency = 'USD';
                 $order->paymethod = 'paypal';
                 $order->pay_date = Date::unix2mysql();
                 $order->notes = 'Affiliate Commissions';
                 $order->status = Model_Order::STATUS_PAID;
                 try {
                     $order->save();
                     //update the commissions
                     DB::update('affiliates')->set(array('date_paid' => Date::unix2mysql(), 'status' => Model_Affiliate::STATUS_PAID, 'id_order_payment' => $order->id_order))->where('id_user', '=', $user->id_user)->where('date_to_pay', '<', Date::unix2mysql())->where('status', '=', Model_Affiliate::STATUS_CREATED)->execute();
                     Alert::set(Alert::SUCCESS, __('Commission Paid'));
                 } catch (Exception $e) {
                 }
             }
         }
     }
     $this->template->title = __('Affiliates Payments');
     $query = DB::select(DB::expr('SUM(amount) total'))->select('id_user')->from('affiliates')->where('date_to_pay', '<', Date::unix2mysql())->where('status', '=', Model_Affiliate::STATUS_CREATED)->group_by('id_user')->having('total', '>=', core::config('affiliate.payment_min'))->execute();
     $users_to_pay = $query->as_array('id_user');
     $total_to_pay = 0;
     foreach ($users_to_pay as $key => $value) {
         $total_to_pay += $value['total'];
     }
     $users = new Model_User();
     if (count($users_to_pay)) {
         $users = $users->where('id_user', 'in', array_keys($users_to_pay))->where('status', '=', Model_User::STATUS_ACTIVE)->find_all();
     }
     $this->render('oc-panel/pages/affiliate/pay', array('users' => $users, 'total_to_pay' => $total_to_pay, 'users_to_pay' => $users_to_pay));
 }
Exemple #18
0
 public function action_cashback_records()
 {
     $params = ['title' => '提现记录'];
     $store = \Session::get('store');
     $items = \Model_Order::query()->where(['store_id' => $store->id, 'cashback_status' => 0])->where('order_status', 'IN', ['FINISH', 'SELLER_SHIPPED', 'SECTION_FINISH'])->get();
     $params['items'] = $items;
     \View::set_global($params);
     $this->template->content = \View::forge("{$this->theme}/finance/cashback_records");
 }
 /**
  * 
  * formmanager definitions
  * 
  */
 public function form_setup($form)
 {
     $form->fields['id_product']['display_as'] = 'select';
     $form->fields['id_product']['options'] = array_keys(Model_Order::products());
     $form->fields['valid_date']['attributes']['placeholder'] = 'yyyy-mm-dd';
     $form->fields['valid_date']['attributes']['data-toggle'] = 'datepicker';
     $form->fields['valid_date']['attributes']['data-date'] = '';
     $form->fields['valid_date']['attributes']['data-date-format'] = 'yyyy-mm-dd';
 }
Exemple #20
0
 public function getDeliveryList()
 {
     $deliveryid_list = Session::get(self::DELIVERYID_LIST);
     $deliverylist = array();
     foreach ((array) $deliveryid_list as $idx => $deliveryid) {
         $order = Model_Order::find($deliveryid);
         $deliverylist[] = array('index' => $idx, 'orderid' => $deliveryid, 'address' => $order->destination);
     }
     return $deliverylist;
 }
Exemple #21
0
 public static function getDetail($order_id)
 {
     $order = Model_Order::find($order_id);
     foreach ($order->orderline as $orderline) {
         $detail['orderline'][] = array('name' => $orderline->item->name, 'size' => $orderline->size, 'num' => $orderline->num);
     }
     $detail['customer'] = array('name' => $order->member->name, 'tel' => $order->member->tel);
     $detail['address'] = $order->destination;
     return $detail;
 }
Exemple #22
0
 public function action_index()
 {
     $user_id = \Session::get(self::SESSION_KEY_USER_ID);
     $order = Model_Order::find(1);
     $order->staff_id = 1;
     $order->save();
     //return $this->template->content =var_dump($user_id);
     $data['staff']['staff_id'] = $order->staff_id;
     $data['order'] = Model_Order::getDetail($order->id);
     $this->template->content = View::forge('website/content/whereismypizza', $data);
 }
Exemple #23
0
 public function action_cashback($id = 0)
 {
     $this->order = \Model_Order::find($id);
     if (!$this->order) {
         die('订单不存在');
     }
     if (!$this->cashback()) {
         die('分红时遇到问题:' . $this->result_message);
     }
     die('分红成功');
 }
Exemple #24
0
 public function action_myOrders()
 {
     $user = Model_User::find($this->sessUser->id);
     $orderField = 'created_at';
     $qualifiers = ['order_by' => [$orderField], 'where' => array(['user_id', $user->id])];
     $orders = Model_Order::find('all', $qualifiers);
     $data = array('user' => $user, 'orders' => $orders);
     $view = View::forge('user/myOrders.tpl', $data);
     $view->set('helper', new Helper(), false);
     // pass validator
     return Response::forge($view);
 }
 /**
  * expired featured ads
  * @return void
  */
 public static function renew()
 {
     if (Core::config('general.subscriptions') == TRUE) {
         //get expired subscription that are active
         $subscriptions = new Model_Subscription();
         $subscriptions = $subscriptions->where('status', '=', 1)->where('expire_date', '<=', Date::unix2mysql())->order_by('created', 'desc')->find_all();
         foreach ($subscriptions as $s) {
             //disable the plan
             $s->status = 0;
             try {
                 $s->save();
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
             $plan = $s->plan;
             if ($plan->loaded() and $plan->status == 1) {
                 //generate a new order
                 $order = Model_Order::new_order(NULL, $s->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');
                 } else {
                     $paid = FALSE;
                     //customers who paid with sripe we can charge the recurrency
                     if ($order->user->stripe_agreement != NULL) {
                         StripeKO::init();
                         // Create the charge on Stripe's servers - this will charge the user's card
                         try {
                             $charge = \Stripe\Charge::create(array("amount" => StripeKO::money_format($order->amount), "currency" => $order->currency, 'customer' => $order->user->stripe_agreement, "description" => $order->description, "metadata" => array("id_order" => $order->id_order)));
                             $paid = TRUE;
                         } catch (Exception $e) {
                             // The card has been declined
                             Kohana::$log->add(Log::ERROR, 'Stripe The card has been declined');
                             $paid = FALSE;
                         }
                     }
                     if ($paid === TRUE) {
                         //mark as paid
                         $order->confirm_payment('stripe', $charge->id);
                     } else {
                         $checkout_url = $s->user->ql('default', array('controller' => 'plan', 'action' => 'checkout', 'id' => $order->id_order));
                         $s->user->email('plan-expired', array('[PLAN.NAME]' => $plan->name, '[URL.CHECKOUT]' => $checkout_url));
                     }
                 }
             }
             //if plan loaded
         }
         //end foreach
     }
     //if subscription active
 }
 /**
  * generates HTML for apy buton
  * @param  Model_Order $order 
  * @return string                 
  */
 public static function button(Model_Order $order)
 {
     if (Core::config('payment.mercadopago_client_id') != '' and Core::config('payment.mercadopago_client_secret') != '' and Theme::get('premium') == 1) {
         // Include Mercadopago library
         require Kohana::find_file('vendor/mercadopago', 'mercadopago');
         // Create an instance with your MercadoPago credentials (CLIENT_ID and CLIENT_SECRET):
         $mp = new MP(core::config('payment.mercadopago_client_id'), core::config('payment.mercadopago_client_secret'));
         $preference_data = array("items" => array(array("id" => $order->id_order, "title" => Model_Order::product_desc($order->id_product), "currency_id" => $order->currency, "picture_url" => $order->ad->get_first_image(), "description" => Text::limit_chars(Text::removebbcode($order->description), 30, NULL, TRUE), "category_id" => $order->ad->category->name, "quantity" => 1, "unit_price" => self::money_format($order->amount))), "payer" => array("name" => Auth::instance()->get_user()->name, "email" => Auth::instance()->get_user()->email), "back_urls" => array("success" => Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')), "failure" => Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))), "auto_return" => "approved", "notification_url" => Route::url('default', array('controller' => 'mercadopago', 'action' => 'ipn', 'id' => $order->id_order)), "expires" => false);
         $preference = $mp->create_preference($preference_data);
         $link = $preference["response"]["init_point"];
         return View::factory('pages/mercadopago/button', array('link' => $link));
     }
     return '';
 }
Exemple #27
0
 /**
  * Processes an order
  *
  * @param object $order            The Model_Order object to process
  * @param string $transaction_type The transaction type to process
  * @param bool   $test_mode        set to true to force test mode. false
  *                                 will use config value. Determines which
  *                                 gateway to use.
  * @param bool   $test_flag        set to true to set test request flag
  *
  * @return object Payment_Transaction
  */
 public static function process(Model_Order $order, $transaction_type = Payment::TYPE_CARD_SALE_REQUEST, $test_mode = FALSE, $test_flag = FALSE)
 {
     $driver = Kohana::config('payment')->default['driver'];
     $class = 'Payment_' . $driver;
     $user = $order->user;
     $driver = new $class($test_mode);
     // Make sure this driver is valid
     if (!$driver instanceof Payment_Driver) {
         throw new Payment_Exception($driver . ' is not a valid payment driver!');
     }
     $driver->type = $transaction_type;
     if ($test_flag) {
         $authorize->test_request = 'TRUE';
     }
     $driver->set_credit_card($order->credit_card);
     $driver->set_amount($order->amount());
     $driver->set_name($user->first_name, $user->last_name);
     $driver->set_address($credit_card->address);
     try {
         return $driver->process();
     } catch (Payment_Exception $e) {
         throw $e;
     }
 }
Exemple #28
0
 public function post_deleteOrder()
 {
     $order_id = $_POST['order_id'];
     $deliveryid_list = Session::get(self::DELIVERYID_LIST);
     if (is_array($deliveryid_list)) {
         unset($deliveryid_list[array_search($order_id, $deliveryid_list)]);
     } else {
         return array('status' => 'NG');
     }
     $deliveryid_list = array_values($deliveryid_list);
     $order = Model_Order::find($order_id);
     $order->status = 1;
     $order->save();
     Session::set(self::DELIVERYID_LIST, $deliveryid_list);
     return array('status' => 'OK');
 }
Exemple #29
0
 /**
  * 出价
  * @param int $id 拍品ID
  */
 public function action_bid($id = 0)
 {
     if (\Input::method() == 'POST') {
         $msg = ['status' => 'err', 'msg' => '', 'errcode' => 10];
         $order_no = \Model_Order::get_order_on();
         $data = ['order_no' => $order_no, 'order_type' => 'AUCTION', 'buyer_id' => \Auth::get_user()->id, 'from_id' => \Session::get('seller')->id, 'total_fee' => \Input::post('bid'), 'original_fee' => \Input::post('bid')];
         $order = \Model_Order::forge($data);
         $order->details = [\Model_OrderDetail::forge(['goods_id' => $id, 'num' => 1, 'price' => \Input::post('bid')])];
         if ($order->save()) {
             $msg = ['status' => 'succ', 'msg' => '', 'errcode' => 0];
         }
         if (\Input::is_ajax()) {
             die(json_encode($msg));
         }
         \Session::set_flash('msg', $msg);
     }
 }
Exemple #30
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;
 }