Esempio n. 1
0
 /**
  * Handle GET requests.
  */
 public function action_device()
 {
     try {
         $result = FALSE;
         if (($license = $this->request->param('id')) != NULL) {
             $device_id = Core::request('device_id');
             if ($license != NULL and $device_id != NULL) {
                 $result = Model_License::verify_device($license, $device_id);
             }
         }
         $this->rest_output(array('valid' => $result));
     } catch (Kohana_HTTP_Exception $khe) {
         $this->_error($khe);
     }
 }
Esempio n. 2
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();
                 //in case the device id or domain is provided
                 if (core::request('device_id') !== NULL or core::request('domain') !== NULL) {
                     $license = $order->licenses->find(1);
                     if ($license->loaded()) {
                         if (core::request('device_id') !== NULL) {
                             Model_License::verify_device($license->license, core::request('device_id'));
                         }
                         if (core::request('domain') !== NULL) {
                             Model_License::verify($license->license, core::request('domain'));
                         }
                     }
                 }
                 $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);
     }
 }