AbstractMembershipEmail.php
1 month ago
EmailDataTrait.php
5 days ago
NewOrderAdminNotification.php
2 years ago
NewOrderReceipt.php
2 years ago
RenewalOrderReceipt.php
2 years ago
SubscriptionAfterExpiredNotification.php
1 year ago
SubscriptionCancelledNotification.php
2 years ago
SubscriptionCompletedNotification.php
2 years ago
SubscriptionExpirationReminder.php
4 months ago
SubscriptionExpiredNotification.php
1 year ago
SubscriptionPaymentFailedNotification.php
5 days ago
SubscriptionRenewalReminder.php
4 months ago
index.php
4 years ago
SubscriptionPaymentFailedNotification.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Membership\Emails; |
| 4 | |
| 5 | use ProfilePress\Core\Membership\Models\Customer\CustomerFactory; |
| 6 | use ProfilePress\Core\Membership\Models\Subscription\SubscriptionEntity; |
| 7 | |
| 8 | class SubscriptionPaymentFailedNotification extends AbstractMembershipEmail |
| 9 | { |
| 10 | const ID = 'subscription_payment_failed_notification'; |
| 11 | |
| 12 | const DEDUPE_META_KEY = 'payment_failed_email_sent'; |
| 13 | |
| 14 | public function __construct() |
| 15 | { |
| 16 | add_action('ppress_subscription_payment_failed', [$this, 'dispatch_email']); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @param SubscriptionEntity $subscription |
| 21 | * |
| 22 | * @return void |
| 23 | */ |
| 24 | public function dispatch_email($subscription) |
| 25 | { |
| 26 | if ( ! apply_filters('ppress_membership_subscription_payment_failed_email_enabled', true, $subscription)) return; |
| 27 | |
| 28 | if (ppress_get_setting(self::ID . '_email_enabled', 'on') !== 'on') return; |
| 29 | |
| 30 | // ensures gateway payment retries do not re-send the email within the same billing period. |
| 31 | if ($subscription->get_meta(self::DEDUPE_META_KEY) === $subscription->expiration_date) return; |
| 32 | |
| 33 | $placeholders_values = $this->get_subscription_placeholders_values($subscription); |
| 34 | |
| 35 | $subject = apply_filters('ppress_' . self::ID . '_email_subject', $this->parse_placeholders( |
| 36 | ppress_get_setting(self::ID . '_email_subject', esc_html__('Your subscription payment failed.', 'wp-user-avatar'), true), |
| 37 | $placeholders_values, |
| 38 | $subscription |
| 39 | ), $subscription); |
| 40 | |
| 41 | $message = apply_filters('ppress_' . self::ID . '_email_content', $this->parse_placeholders( |
| 42 | ppress_get_setting(self::ID . '_email_content', $this->get_subscription_payment_failed_content(), true), |
| 43 | $placeholders_values, |
| 44 | $subscription |
| 45 | ), $subscription); |
| 46 | |
| 47 | $recipient = apply_filters('ppress_' . self::ID . '_recipient', CustomerFactory::fromId($subscription->customer_id)->get_email(), $subscription); |
| 48 | |
| 49 | if (ppress_send_email($recipient, $subject, $message)) { |
| 50 | $subscription->update_meta(self::DEDUPE_META_KEY, $subscription->expiration_date); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 |