示例#1
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;
 }