Example #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);
     }
 }
Example #2
0
 /**
  * action to download a zip file directly form the API
  * @return [type] [description]
  */
 public function action_download()
 {
     $this->auto_render = FALSE;
     $license = $this->request->param('id');
     $domain = Core::request('domain');
     if ($license != NULL and $domain != NULL) {
         //ok, let's download the zip file if validated license
         if (Model_License::verify($license, $domain) === TRUE) {
             $license = Model_License::get_license($license);
             if ($license->loaded()) {
                 $license->order->download();
             }
         }
     }
     //by default return false since downlaod could not be done
     $this->response->headers('Content-type', 'application/javascript');
     $this->response->body(json_encode(FALSE));
 }
Example #3
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);
     }
 }
Example #4
0
 /**
  * confirm payment for order
  *
  * @param string    $id_order [unique indentifier of order]
  * @param string    $txn_id id of the transaction depending on provider
  */
 public function confirm_payment($paymethod = 'paypal', $txn_id = NULL, $pay_date = NULL, $amount = NULL, $currency = NULL)
 {
     // update orders
     if ($this->loaded()) {
         $product = $this->product;
         $user = $this->user;
         $this->status = self::STATUS_PAID;
         $this->pay_date = $pay_date === NULL ? Date::unix2mysql() : $pay_date;
         $this->paymethod = $paymethod;
         $this->txn_id = $txn_id;
         if ($product->support_days > 0) {
             $this->support_date = Date::unix2mysql(Date::mysql2unix($this->pay_date) + $product->support_days * 24 * 60 * 60);
         }
         if ($amount !== NULL) {
             $this->amount = $amount;
         }
         if ($currency !== NULL) {
             $this->currency = $currency;
         }
         try {
             $this->save();
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         //if saved delete coupon from session and -- number of coupons.
         Model_Coupon::sale($this->coupon);
         //add affiliate commision
         Model_Affiliate::sale($this, $product);
         //generate licenses
         $licenses = Model_License::generate($user, $this, $product);
         $license = '';
         //loop all the licenses to an string
         if (count($licenses) > 0) {
             $license = '\\n\\n==== ' . __('Your Licenses') . ' ====';
             foreach ($licenses as $l) {
                 $license .= '\\n' . $l->license;
             }
         }
         //download link
         $download = '';
         if ($product->has_file() == TRUE) {
             $dwnl_link = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'download', 'id' => $this->id_order));
             $download = '\\n\\n==== ' . __('Download') . ' ====\\n<a href="' . $dwnl_link . '">' . $dwnl_link . '</a>';
         }
         //theres an expire? 0 = unlimited
         $expire = '';
         $expire_hours = Core::config('product.download_hours');
         $expire_times = Core::config('product.download_times');
         if (($expire_hours > 0 or $expire_times > 0) and $product->has_file() == TRUE) {
             if ($expire_hours > 0 and $expire_times > 0) {
                 $expire = sprintf(__('Your download expires in %u hours and can be downloaded %u times.'), $expire_hours, $expire_times);
             } elseif ($expire_hours > 0) {
                 $expire = sprintf(__('Your download expires in %u hours.'), $expire_hours);
             } elseif ($expire_times > 0) {
                 $expire = sprintf(__('Can be downloaded %u times.'), $expire_times);
             }
             $expire = '\\n' . $expire;
         }
         //param for sale email
         $params = array('[DATE]' => $this->pay_date, '[ORDER.ID]' => $this->id_order, '[USER.NAME]' => $user->name, '[USER.EMAIL]' => $user->email, '[PRODUCT.TITLE]' => $product->title, '[PRODUCT.PRICE]' => i18n::format_currency($this->amount, $this->currency), '[PRODUCT.NOTES]' => Text::bb2html($product->email_purchase_notes, TRUE, FALSE, FALSE), '[DOWNLOAD]' => $download, '[EXPIRE]' => $expire, '[LICENSE]' => $license);
         //send email with order details download link and product notes
         $user->email('new-sale', $params);
         //notify to seller
         if (core::config('email.new_sale_notify')) {
             Email::send(core::config('email.notify_email'), '', 'New Sale! ' . $product->title, 'New Sale! ' . $product->title, core::config('email.notify_email'), '');
         }
         return TRUE;
     }
     return FALSE;
 }