Example #1
0
 public function isValid($value, $context = null)
 {
     $registry = Zend_Registry::getInstance();
     $signedUserInfo = $registry->get("signedUserInfo");
     $valueString = (string) $value;
     $this->_setValue($valueString);
     if (mb_strlen($value) > 16) {
         $this->_error(self::INVALID_Redeem);
         return false;
     }
     if (empty($value)) {
         $this->_error(self::EMPTY_Redeem);
         return false;
     }
     $coupons = Ml_Model_Coupons::getInstance();
     $token = $coupons->get($value);
     if (!$token) {
         $this->_error(self::NOTFOUND_Redeem);
         return false;
     }
     if (!$token['active']) {
         $this->_error(self::USED_Redeem);
         return false;
     }
     if (!$token['unique_use']) {
         $credits = Ml_Model_Credits::getInstance();
         $isItUsed = $credits->getCouponRedeemed($signedUserInfo['id'], $token['id']);
         if ($isItUsed) {
             $this->_error(self::YUSED_Redeem);
             return false;
         }
     }
     return true;
 }
Example #2
0
 public function orderAction()
 {
     $registry = Zend_Registry::getInstance();
     $config = $registry->get("config");
     $signedUserInfo = $registry->get("signedUserInfo");
     $request = $this->getRequest();
     $orderPid = $request->getUserParam("order_pid");
     $credits = Ml_Model_Credits::getInstance();
     $order = $credits->getByPid($orderPid);
     if (!$order || $order['uid'] != $signedUserInfo['id']) {
         $registry->set("notfound", true);
         throw new Exception("Order doesn't exists.");
     }
     if ($order['reason_type'] == 'redeem') {
         $coupons = Ml_Model_Coupons::getInstance();
         $this->view->orderCoupon = $coupons->getById($order['reason_id']);
     }
     $this->view->order = $order;
 }
Example #3
0
 /**
  * makes a coupon's based transaction
  * @param big int $uid
  * @param faken hexdec $coupon
  */
 public function couponTransaction($uid, $coupon)
 {
     $coupons = Ml_Model_Coupons::getInstance();
     $logger = Ml_Model_Logger::getInstance();
     $this->_dbAdapter->beginTransaction();
     $couponData = $coupons->get($coupon, true);
     if (is_array($couponData)) {
         if ($couponData['unique_use']) {
             $stateChange = $coupons->state($couponData['hash'], false);
             if (!$stateChange) {
                 $this->_dbAdapter->rollBack();
                 return false;
             }
         } else {
             if (!$couponData['unique_use']) {
                 //then checks if it was already used by this user:
                 //using fetchRow 'cause 1 result is enough
                 $isItUsed = $this->_dbTable->fetchRow($this->_dbTable->select()->where("binary `uid` = ?", $uid)->where("reason_type = ?", self::COUPON_REDEEM)->where("binary `reason_id` = ?", $couponData['id']));
                 if (is_object($isItUsed)) {
                     $this->_dbAdapter->rollBack();
                     return false;
                 }
             }
         }
         $this->insert(array("pid" => $this->makeUUId(), "uid" => $uid, "amount" => $couponData['amount'], "sack" => $couponData['sack'], "reason_type" => self::COUPON_REDEEM, "reason_id" => $couponData['id']));
         $transactionId = $this->_dbAdapter->lastInsertId();
         $logger->log(array("action" => "transaction", "transaction" => $transactionId));
         $this->_dbAdapter->commit();
         return $transactionId;
     }
 }