public function orderStatusChange(OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        // The order has been canceled or refunded ?
        if ($event->getOrder()->isCancelled() || $event->getOrder()->isRefunded()) {
            // Cancel usage of all coupons for this order
            $usedCoupons = OrderCouponQuery::create()
                ->filterByUsageCanceled(false)
                ->findByOrderId($event->getOrder()->getId());

            $customerId = $event->getOrder()->getCustomerId();

            /** @var OrderCoupon $usedCoupon */
            foreach ($usedCoupons as $usedCoupon) {
                if (null !== $couponModel = CouponQuery::create()->findOneByCode($usedCoupon->getCode())) {
                    // If the coupon still exists, restore one usage to the usage count.
                    $this->couponManager->incrementQuantity($couponModel, $customerId);
                }

                // Mark coupon usage as canceled in the OrderCoupon table
                $usedCoupon->setUsageCanceled(true)->save();
            }
        } else {
            // Mark canceled coupons for this order as used again
            $usedCoupons = OrderCouponQuery::create()
                ->filterByUsageCanceled(true)
                ->findByOrderId($event->getOrder()->getId());

            $customerId = $event->getOrder()->getCustomerId();

            /** @var OrderCoupon $usedCoupon */
            foreach ($usedCoupons as $usedCoupon) {
                if (null !== $couponModel = CouponQuery::create()->findOneByCode($usedCoupon->getCode())) {
                    // If the coupon still exists, mark the coupon as used
                    $this->couponManager->decrementQuantity($couponModel, $customerId);
                }

                // The coupon is no longer canceled
                $usedCoupon->setUsageCanceled(false)->save();
            }
        }
    }