blob: 4920a3d9dd6aea5b50ae713081cbb1c10dd55ce9 [file] [log] [blame]
swissChilif0cbdc32023-01-05 17:21:38 -05001<?php
2/**
3 * Admin email about payment retry failed due to authentication
4 *
5 * Email sent to admins when an attempt to automatically process a subscription renewal payment has failed
6 * with the `authentication_needed` error, and a retry rule has been applied to retry the payment in the future.
7 *
8 * @version 4.3.0
9 * @package WooCommerce_Stripe/Classes/WC_Stripe_Email_Failed_Authentication_Retry
10 * @extends WC_Email_Failed_Order
11 */
12
13if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15}
16
17/**
18 * An email sent to the admin when payment fails to go through due to authentication_required error.
19 *
20 * @since 4.3.0
21 */
22class WC_Stripe_Email_Failed_Authentication_Retry extends WC_Email_Failed_Order {
23
24 /**
25 * Constructor
26 */
27 public function __construct() {
28 $this->id = 'failed_authentication_requested';
29 $this->title = __( 'Payment Authentication Requested Email', 'woocommerce-gateway-stripe' );
30 $this->description = __( 'Payment authentication requested emails are sent to chosen recipient(s) when an attempt to automatically process a subscription renewal payment fails because the transaction requires an SCA verification, the customer is requested to authenticate the payment, and a retry rule has been applied to notify the customer again within a certain time period.', 'woocommerce-gateway-stripe' );
31
32 $this->heading = __( 'Automatic renewal payment failed due to authentication required', 'woocommerce-gateway-stripe' );
33 $this->subject = __( '[{site_title}] Automatic payment failed for {order_number}. Customer asked to authenticate payment and will be notified again {retry_time}', 'woocommerce-gateway-stripe' );
34
35 $this->template_html = 'emails/failed-renewal-authentication-requested.php';
36 $this->template_plain = 'emails/plain/failed-renewal-authentication-requested.php';
37 $this->template_base = plugin_dir_path( WC_STRIPE_MAIN_FILE ) . 'templates/';
38
39 $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
40
41 // We want all the parent's methods, with none of its properties, so call its parent's constructor, rather than my parent constructor.
42 WC_Email::__construct();
43 }
44
45 /**
46 * Get the default e-mail subject.
47 *
48 * @return string
49 */
50 public function get_default_subject() {
51 return $this->subject;
52 }
53
54 /**
55 * Get the default e-mail heading.
56 *
57 * @return string
58 */
59 public function get_default_heading() {
60 return $this->heading;
61 }
62
63 /**
64 * Trigger.
65 *
66 * @param int $order_id The order ID.
67 * @param WC_Order|null $order Order object.
68 */
69 public function trigger( $order_id, $order = null ) {
70 $this->object = $order;
71
72 $this->find['retry-time'] = '{retry_time}';
73 if ( class_exists( 'WCS_Retry_Manager' ) && function_exists( 'wcs_get_human_time_diff' ) ) {
74 $this->retry = WCS_Retry_Manager::store()->get_last_retry_for_order( wcs_get_objects_property( $order, 'id' ) );
75 $this->replace['retry-time'] = wcs_get_human_time_diff( $this->retry->get_time() );
76 } else {
77 WC_Stripe_Logger::log( 'WCS_Retry_Manager class or does not exist. Not able to send admnin email about customer notification for authentication required for renewal payment.' );
78 return;
79 }
80
81 $this->find['order-number'] = '{order_number}';
82 $this->replace['order-number'] = $this->object->get_order_number();
83
84 if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
85 return;
86 }
87
88 $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
89 }
90
91 /**
92 * Get content html.
93 *
94 * @return string
95 */
96 public function get_content_html() {
97 return wc_get_template_html(
98 $this->template_html,
99 [
100 'order' => $this->object,
101 'retry' => $this->retry,
102 'email_heading' => $this->get_heading(),
103 'sent_to_admin' => true,
104 'plain_text' => false,
105 'email' => $this,
106 ],
107 '',
108 $this->template_base
109 );
110 }
111
112 /**
113 * Get content plain.
114 *
115 * @return string
116 */
117 public function get_content_plain() {
118 return wc_get_template_html(
119 $this->template_plain,
120 [
121 'order' => $this->object,
122 'retry' => $this->retry,
123 'email_heading' => $this->get_heading(),
124 'sent_to_admin' => true,
125 'plain_text' => true,
126 'email' => $this,
127 ],
128 '',
129 $this->template_base
130 );
131 }
132}