/**
  * Add new coupon
  *
  * @param array $couponInfo
  *      integer discount
  *      integer date_start
  *      integer date_end
  * @return integer|string
  */
 public function addCoupon(array $couponInfo)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         if (!$couponInfo['date_start']) {
             $couponInfo['date_start'] = null;
         }
         if (!$couponInfo['date_end']) {
             $couponInfo['date_end'] = null;
         }
         $insert = $this->insert()->into('payment_discount_coupon')->values(array_merge($couponInfo, ['used' => self::COUPON_NOT_USED]));
         $statement = $this->prepareStatementForSqlObject($insert);
         $statement->execute();
         $insertId = $this->adapter->getDriver()->getLastGeneratedValue();
         // generate a random slug
         $update = $this->update()->table('payment_discount_coupon')->set(['slug' => strtoupper($this->generateSlug($insertId, $this->generateRandString(self::COUPON_MIN_SLUG_LENGTH, self::ALLOWED_SLUG_CHARS), 'payment_discount_coupon', 'id'))])->where(['id' => $insertId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the add discount coupon event
     PaymentEvent::fireAddDiscountCouponEvent($insertId);
     return $insertId;
 }