class PaymentDeclinedMail in Commerce Recurring Framework 8
Sends an email when the payment is declined for a recurring order.
Hierarchy
- class \Drupal\commerce_recurring\Mail\PaymentDeclinedMail implements PaymentDeclinedMailInterface uses StringTranslationTrait
Expanded class hierarchy of PaymentDeclinedMail
1 file declares its use of PaymentDeclinedMail
- DunningSubscriber.php in src/
EventSubscriber/ DunningSubscriber.php
1 string reference to 'PaymentDeclinedMail'
1 service uses PaymentDeclinedMail
File
- src/
Mail/ PaymentDeclinedMail.php, line 16
Namespace
Drupal\commerce_recurring\MailView source
class PaymentDeclinedMail implements PaymentDeclinedMailInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The mail handler.
*
* @var \Drupal\commerce\MailHandlerInterface
*/
protected $mailHandler;
/**
* The order total summary.
*
* @var \Drupal\commerce_order\OrderTotalSummaryInterface
*/
protected $orderTotalSummary;
/**
* The time.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* Constructs a new PaymentDeclinedMail object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\commerce\MailHandlerInterface $mail_handler
* The mail handler.
* @param \Drupal\commerce_order\OrderTotalSummaryInterface $order_total_summary
* The order total summary.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, MailHandlerInterface $mail_handler, OrderTotalSummaryInterface $order_total_summary, TimeInterface $time) {
$this->entityTypeManager = $entity_type_manager;
$this->mailHandler = $mail_handler;
$this->orderTotalSummary = $order_total_summary;
$this->time = $time;
}
/**
* {@inheritdoc}
*/
public function send(OrderInterface $order, $retry_days, $num_retries, $max_retries) {
$customer = $order
->getCustomer();
if ($customer
->isAnonymous()) {
return FALSE;
}
$order_type_storage = $this->entityTypeManager
->getStorage('commerce_order_type');
/** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
$order_type = $order_type_storage
->load($order
->bundle());
$payment_methods_url = Url::fromRoute('entity.commerce_payment_method.collection', [
'user' => $order
->getCustomerId(),
], [
'absolute' => TRUE,
]);
$subject = $this
->t('Payment declined - Order #@number.', [
'@number' => $order
->getOrderNumber(),
]);
$body = [
'#theme' => 'commerce_recurring_payment_declined',
'#order_entity' => $order,
'#retry_num' => $num_retries,
'#retry_days' => "+{$retry_days} days",
'#max_retries' => $max_retries,
'#remaining_retries' => $max_retries - $num_retries,
'#now' => $this->time
->getCurrentTime(),
'#payment_method_link' => $payment_methods_url
->toString(),
'#totals' => $this->orderTotalSummary
->buildTotals($order),
];
if ($billing_profile = $order
->getBillingProfile()) {
$profile_view_builder = $this->entityTypeManager
->getViewBuilder('profile');
$body['#billing_information'] = $profile_view_builder
->view($billing_profile);
}
$params = [
'id' => 'recurring_payment_declined',
'from' => $order
->getStore()
->getEmail(),
'bcc' => $order_type
->getReceiptBcc(),
'order' => $order,
'langcode' => $customer
->getPreferredLangcode(),
];
return $this->mailHandler
->sendMail($order
->getEmail(), $subject, $body, $params);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentDeclinedMail:: |
protected | property | The entity type manager. | |
PaymentDeclinedMail:: |
protected | property | The mail handler. | |
PaymentDeclinedMail:: |
protected | property | The order total summary. | |
PaymentDeclinedMail:: |
protected | property | The time. | |
PaymentDeclinedMail:: |
public | function |
Sends a payment declined email. Overrides PaymentDeclinedMailInterface:: |
|
PaymentDeclinedMail:: |
public | function | Constructs a new PaymentDeclinedMail object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |