Пример #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)
 {
     // update orders
     if ($this->loaded()) {
         $this->status = self::STATUS_PAID;
         $this->pay_date = Date::unix2mysql();
         $this->paymethod = $paymethod;
         $this->txn_id = $txn_id;
         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);
         //for membership plans
         if ($this->id_product >= 100) {
             Model_Subscription::new_order($this);
             $replace_email = array('[AD.TITLE]' => $this->description, '[URL.AD]' => Route::url('pricing'), '[ORDER.ID]' => $this->id_order, '[PRODUCT.ID]' => $this->id_product, '[VAT.COUNTRY]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT_country : '', '[VAT.NUMBER]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT_number : '', '[VAT.PERCENTAGE]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT : '');
         } else {
             $ad = $this->ad;
             //depending on the product different actions
             switch ($this->id_product) {
                 case Model_Order::PRODUCT_AD_SELL:
                     $ad->sale($this);
                     break;
                 case Model_Order::PRODUCT_TO_TOP:
                     $ad->to_top();
                     break;
                 case Model_Order::PRODUCT_TO_FEATURED:
                     $ad->to_feature($this->featured_days);
                     Social::social_post_featured_ad($ad);
                     break;
                 case Model_Order::PRODUCT_CATEGORY:
                     $ad->paid_category();
                     break;
             }
             $url_ad = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
             $replace_email = array('[AD.TITLE]' => $ad->title, '[URL.AD]' => $url_ad, '[ORDER.ID]' => $this->id_order, '[PRODUCT.ID]' => $this->id_product, '[VAT.COUNTRY]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT_country : '', '[VAT.NUMBER]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT_number : '', '[VAT.PERCENTAGE]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT : '');
         }
         //send email to site owner! new sale!!
         if (core::config('email.new_ad_notify') == TRUE) {
             Email::content(core::config('email.notify_email'), core::config('general.site_name'), core::config('email.notify_email'), core::config('general.site_name'), 'ads-sold', $replace_email);
         }
     }
 }