コード例 #1
0
 /**
  * Get current discount
  *
  * @return integer
  */
 public function getCurrentDiscount()
 {
     return PaymentService::getDiscountCouponInfo() ? PaymentService::getDiscountCouponInfo()['discount'] : 0;
 }
コード例 #2
0
 /**
  * Deactivate current discount coupon
  */
 public function ajaxDeactivateDiscountCouponAction()
 {
     $request = $this->getRequest();
     if ($request->isPost() && $this->applicationCsrf()->isTokenValid($request->getPost('csrf'))) {
         if (null != ($discountCouponInfo = PaymentService::getDiscountCouponInfo())) {
             PaymentService::setDiscountCouponId(null);
             // fire the deactivate discount coupon event
             PaymentEvent::fireDeactivateDiscountCouponEvent($discountCouponInfo['slug']);
             $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('The coupon code has been deactivated'));
         }
     }
     return $this->getResponse();
 }
コード例 #3
0
 /**
  * Add a new transaction
  *
  * @param integer $userId
  * @param array $transactionInfo
  *      integer payment_type - required
  *      string comments - optional
  *      string first_name - required
  *      string last_name - required
  *      string email - required
  *      string phone - required
  *      string address - optional
  * @param array $items
  *      integer object_id
  *      integer module
  *      string title
  *      string slug
  *      float cost
  *      float discount
  *      integer count
  * @return integer|string
  */
 public function addTransaction($userId, array $transactionInfo, array $items)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $basicData = ['user_hidden' => self::TRANSACTION_USER_NOT_HIDDEN, 'paid' => self::TRANSACTION_NOT_PAID, 'language' => $this->getCurrentLanguage(), 'date' => time(), 'currency' => PaymentService::getPrimaryCurrency()['id']];
         // add the user id
         if (UserBaseModel::DEFAULT_GUEST_ID != $userId) {
             $basicData['user_id'] = $userId;
         }
         // add the discount id
         if (PaymentService::getDiscountCouponInfo()) {
             $basicData['discount_coupon'] = PaymentService::getDiscountCouponInfo()['id'];
         }
         if (!$transactionInfo['comments']) {
             $transactionInfo['comments'] = null;
         }
         $insert = $this->insert()->into('payment_transaction_list')->values(array_merge($transactionInfo, $basicData));
         $statement = $this->prepareStatementForSqlObject($insert);
         $statement->execute();
         $transactionId = $this->adapter->getDriver()->getLastGeneratedValue();
         // generate a random slug
         $update = $this->update()->table('payment_transaction_list')->set(['slug' => strtoupper($this->generateSlug($transactionId, $this->generateRandString(self::TRANSACTION_MIN_SLUG_LENGTH, self::ALLOWED_SLUG_CHARS), 'payment_transaction_list', 'id'))])->where(['id' => $transactionId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
         // update the discount coupon info
         if (PaymentService::getDiscountCouponInfo()) {
             $update = $this->update()->table('payment_discount_coupon')->set(['used' => self::COUPON_USED])->where(['id' => PaymentService::getDiscountCouponInfo()['id']]);
             $statement = $this->prepareStatementForSqlObject($update);
             $statement->execute();
         }
         // add  transaction's items
         foreach ($items as $item) {
             $insert = $this->insert()->into('payment_transaction_item')->values(['transaction_id' => $transactionId, 'object_id' => $item['object_id'], 'module' => $item['module'], 'title' => $item['title'], 'slug' => $item['slug'], 'cost' => $item['cost'], 'discount' => $item['discount'], 'count' => $item['count'], 'paid' => self::TRANSACTION_NOT_PAID, 'extra_options' => !empty($item['extra_options']) ? $item['extra_options'] : null]);
             $statement = $this->prepareStatementForSqlObject($insert);
             $statement->execute();
         }
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the add payment transaction event
     PaymentEvent::fireAddPaymentTransactionEvent($transactionId, $transactionInfo);
     return $transactionId;
 }