Block/Coupon.php
public function generateCoupon()
    {
        $params = $this->getRequest()->getParams();
        //check for param code and id
        if (! isset($params['code']) ||
            ! $this->helper->isCodeValid($params['code'])
        ) {
            return false;
        }

        $priceRuleId = (int) $params['id'];
        $expireDate = false;

        if (isset($params['expire_days']) && is_numeric($params['expire_days']) && $params['expire_days'] > 0) {
            $days = (int) $params['expire_days'];
            $expireDate = $this->_localeDate->date()
                ->add($this->dateIntervalFactory->create(['interval_spec' => sprintf('P%sD', $days)]));
        }

        return $this->dotmailerCouponGenerator->generateCoupon($priceRuleId, $expireDate);
    }
public function generateCoupon()
    {
        $params = $this->getRequest()->getParams();
        //check for param code and id
        if (! isset($params['code']) ||
            ! $this->helper->isCodeValid($params['code'])
        ) {
            return false;
        }

        $priceRuleId = (int) $params['id'];
        $expireDate = false;

        if (isset($params['expire_days']) && is_numeric($params['expire_days']) && $params['expire_days'] > 0) {
            $days = (int) $params['expire_days'];
            $expireDate = $this->_localeDate->date()
                ->add($this->dateIntervalFactory->create(['interval_spec' => sprintf('P%sD', $days)]));
        }

        return $this->dotmailerCouponGenerator->generateCoupon($priceRuleId, $expireDate);
    }
public function generateCoupon ( ) { $ params = $ this -> getRequest ( ) -> getParams ( ) ; //check for param code and id if ( ! isset ( $ params [ 'code' ] ) || ! $ this -> helper -> isCodeValid ( $ params [ 'code' ] ) ) { return false ; } $ priceRuleId = ( int ) $ params [ 'id' ] ; $ expireDate = false ; if ( isset ( $ params [ 'expire_days' ] ) && is_numeric ( $ params [ 'expire_days' ] ) && $ params [ 'expire_days' ] > 0 ) { $ days = ( int ) $ params [ 'expire_days' ] ; $ expireDate = $ this -> _localeDate -> date ( ) -> add ( $ this -> dateIntervalFactory -> create ( [ 'interval_spec' => sprintf ( 'P%sD' , $ days ) ] ) ) ; } return $ this -> dotmailerCouponGenerator -> generateCoupon ( $ priceRuleId , $ expireDate ) ; }
Generates the coupon code based on the code id.

@return bool
@throws \Magento\Framework\Exception\LocalizedException
Generates the coupon code based on the code id .