You are here

class DunningSubscriber in Commerce Recurring Framework 8

Sends an email when the payment is declined for a recurring order.

Hierarchy

  • class \Drupal\commerce_recurring\EventSubscriber\DunningSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of DunningSubscriber

1 string reference to 'DunningSubscriber'
commerce_recurring.services.yml in ./commerce_recurring.services.yml
commerce_recurring.services.yml
1 service uses DunningSubscriber
commerce_recurring.event_subscriber.dunning_subscriber in ./commerce_recurring.services.yml
Drupal\commerce_recurring\EventSubscriber\DunningSubscriber

File

src/EventSubscriber/DunningSubscriber.php, line 13

Namespace

Drupal\commerce_recurring\EventSubscriber
View source
class DunningSubscriber implements EventSubscriberInterface {

  /**
   * The payment declined mail service.
   *
   * @var \Drupal\commerce_recurring\Mail\PaymentDeclinedMail
   */
  protected $paymentDeclinedMail;

  /**
   * Constructs a new DunningSubscriber object.
   *
   * @param \Drupal\commerce_recurring\Mail\PaymentDeclinedMail $payment_declined_mail
   *   The payment declined mail service.
   */
  public function __construct(PaymentDeclinedMail $payment_declined_mail) {
    $this->paymentDeclinedMail = $payment_declined_mail;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = [
      RecurringEvents::PAYMENT_DECLINED => [
        'sendPaymentDeclinedEmail',
        -100,
      ],
    ];
    return $events;
  }

  /**
   * Sends a payment declined email.
   *
   * @param \Drupal\commerce_recurring\Event\PaymentDeclinedEvent $event
   *   The event we subscribed to.
   */
  public function sendPaymentDeclinedEmail(PaymentDeclinedEvent $event) {
    if (empty($event
      ->getOrder()
      ->getEmail())) {
      return;
    }
    $this->paymentDeclinedMail
      ->send($event
      ->getOrder(), $event
      ->getRetryDays(), $event
      ->getNumRetries(), $event
      ->getMaxRetries());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DunningSubscriber::$paymentDeclinedMail protected property The payment declined mail service.
DunningSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
DunningSubscriber::sendPaymentDeclinedEmail public function Sends a payment declined email.
DunningSubscriber::__construct public function Constructs a new DunningSubscriber object.