Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Add credit card expiring email class #3218

Open
wants to merge 1 commit into
base: enhancement/email-template-abstraction
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 2 additions & 45 deletions classes/class.pmproemail.php
Original file line number Diff line number Diff line change
Expand Up @@ -1081,51 +1081,8 @@ function sendCreditCardExpiringEmail($user = NULL, $order = NULL) {
return false;
}

$membership_level = pmpro_getSpecificMembershipLevelForUser($user->ID, $order->membership_id);

$this->email = $user->user_email;
$this->subject = sprintf(__("Credit card on file expiring soon at %s", "paid-memberships-pro"), get_option("blogname"));

$this->data = array(
'subject' => $this->subject,
'header_name' => $user->display_name,
'name' => $user->display_name,
'user_login' => $user->user_login,
'sitename' => get_option( 'blogname' ),
'siteemail' => get_option( 'pmpro_from_email' ),
'membership_id' => $membership_level->id,
'membership_level_name' => $membership_level->name,
'display_name' => $user->display_name,
'user_email' => $user->user_email,
'billing_name' => $order->billing->name,
'billing_street' => $order->billing->street,
'billing_street2' => $order->billing->street2,
'billing_city' => $order->billing->city,
'billing_state' => $order->billing->state,
'billing_zip' => $order->billing->zip,
'billing_country' => $order->billing->country,
'billing_phone' => $order->billing->phone,
'cardtype' => $order->cardtype,
'accountnumber' => hideCardNumber($order->accountnumber),
'expirationmonth' => $order->expirationmonth,
'expirationyear' => $order->expirationyear,
'login_link' => pmpro_login_url( pmpro_url( 'billing' ) ),
'login_url' => pmpro_login_url( pmpro_url( 'billing' ) ),
'levels_url' => pmpro_url( 'levels' )

);
$this->data["billing_address"] = pmpro_formatAddress($order->billing->name,
$order->billing->street,
$order->billing->street2,
$order->billing->city,
$order->billing->state,
$order->billing->zip,
$order->billing->country,
$order->billing->phone);

$this->template = apply_filters("pmpro_email_template", "credit_card_expiring", $this);

return $this->sendEmail();
$email = new PMPro_Email_Template_Credit_Card_Expiring( $user, $order );
return $email->send();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<?php
class PMPro_Email_Template_Credit_Card_Expiring extends PMPro_Email_Template {

/**
* The user object of the user to send the email to.
*
* @var WP_User
*/
protected $user;

/**
* The {@link MemberOrder} object of the order that was updated.
*
* @var MemberOrder
*/
protected $order;

/**
* Constructor.
*
* @since TBD
*
* @param WP_User $user The user object of the user to send the email to.
* @param MemberOrder $order The order object that is associated to the member.
*/
public function __construct( WP_User $user, MemberOrder $order ) {
$this->user = $user;
$this->order = $order;
}

/**
* Get the email template slug.
*
* @since TBD
*
* @return string The email template slug.
*/
public static function get_template_slug() {
return 'credit_card_expiring';
}

/**
* Get the "nice name" of the email template.
*
* @since TBD
*
* @return string The "nice name" of the email template.
*/
public static function get_template_name() {
return __( 'Credit Card Expiring', 'paid-memberships-pro' );
}

/**
* Get "help text" to display to the admin when editing the email template.
*
* @since TBD
*
* @return string The "help text" to display to the admin when editing the email template.
*/
public static function get_template_description() {
return __( 'This is the membership confirmation email sent to the site administrator for every paid membership checkout on the site.', 'paid-memberships-pro' );
}

/**
* Get the default subject for the email.
*
* @since TBD
*
* @return string The default subject for the email.
*/
public static function get_default_subject() {
return __( 'Credit card on file expiring soon at !!sitename!!', 'paid-memberships-pro' );
}

/**
* Get the default body content for the email.
*
* @since TBD
*
* @return string The default body content for the email.
*/
public static function get_default_body() {
return __( '<p>The payment method used for your membership at !!sitename!! will expire soon. <strong>Please click the following link to log in and update your billing information to avoid account suspension. !!login_url!!</strong></p>
<p>Account: !!display_name!! (!!user_email!!)</p>
<p>The most recent account information we have on file is:</p>

<p>!!billing_name!!</br />
!!billing_address!!
</p>

<p>
!!cardtype!!: !!accountnumber!!<br />
Expires: !!expirationmonth!!/!!expirationyear!!
</p>', 'paid-memberships-pro' );
}

/**
* Get the email address to send the email to.
*
* @since TBD
*
* @return string The email address to send the email to.
*/
public function get_recipient_email() {
return $this->user->user_email;
}

/**
* Get the name of the email recipient.
*
* @since TBD
*
* @return string The name of the email recipient.
*/
public function get_recipient_name() {
return $this->user->display_name;
}

/**
* Get the email template variables for the email paired with a description of the variable.
*
* @since TBD
*
* @return array The email template variables for the email (key => value pairs).
*/
public static function get_email_template_variables_with_description() {
return array(
'!!subject!!' => __( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ),
'!!header_name!!' => __( 'The name of the email recipient.', 'paid-memberships-pro' ),
'!!name!!' => __( 'The display name of the user.', 'paid-memberships-pro' ),
'!!membership_id!!' => __( 'The ID of the membership level.', 'paid-memberships-pro' ),
'!!membership_level_name!!' => __( 'The name of the membership level.', 'paid-memberships-pro' ),
'!!user_login!!' => __( 'The username of the user.', 'paid-memberships-pro' ),
'!!user_email!!' => __( 'The email address of the user.', 'paid-memberships-pro' ),
'!!display_name!!' => __( 'The display name of the user.', 'paid-memberships-pro' ),
'!!subject!!' => __( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ),
'!!billing_address!!' => __( 'Billing Info Complete Address', 'paid-memberships-pro' ),
'!!billing_name!!' => __( 'The billing name of the user.', 'paid-memberships-pro' ),
'!!billing_street!!' => __( 'The billing street address of the user.', 'paid-memberships-pro' ),
'!!billing_street2!!' => __( 'The second billing street field address of the user.', 'paid-memberships-pro' ),
'!!billing_city!!' => __( 'The billing city of the user.', 'paid-memberships-pro' ),
'!!billing_state!!' => __( 'The billing state of the user.', 'paid-memberships-pro' ),
'!!billing_zip!!' => __( 'The billing ZIP code of the user.', 'paid-memberships-pro' ),
'!!billing_country!!' => __( 'The billing country of the user.', 'paid-memberships-pro' ),
'!!billing_phone!!' => __( 'The billing phone number of the user.', 'paid-memberships-pro' ),
'!!cardtype!!' => __( 'The type of credit card used.', 'paid-memberships-pro' ),
'!!accountnumber!!' => __( 'The last four digits of the credit card number.', 'paid-memberships-pro' ),
'!!expirationmonth!!' => __( 'The expiration month of the credit card.', 'paid-memberships-pro' ),
'!!expirationyear!!' => __( 'The expiration year of the credit card.', 'paid-memberships-pro' ),
);
}

/**
* Get the email template variables for the email.
*
* @since TBD
*
* @return array The email template variables for the email (key => value pairs).
*/
public function get_email_template_variables() {
$order = $this->order;
$membership_level = pmpro_getLevel( $order->membership_id );

return array(
'subject' => $this->subject,
'header_name' => $user->display_name,
'name' => $user->display_name,
'user_login' => $user->user_login,
'sitename' => get_option( 'blogname' ),
'siteemail' => get_option( 'pmpro_from_email' ),
'membership_id' => $membership_level->id,
'membership_level_name' => $membership_level->name,
'display_name' => $user->display_name,
'user_email' => $user->user_email,
'billing_name' => $order->billing->name,
'billing_street' => $order->billing->street,
'billing_street2' => $order->billing->street2,
'billing_city' => $order->billing->city,
'billing_state' => $order->billing->state,
'billing_zip' => $order->billing->zip,
'billing_country' => $order->billing->country,
'billing_phone' => $order->billing->phone,
'billing_address'=> pmpro_formatAddress( $order->billing->name,
$order->billing->street,
$order->billing->street2,
$order->billing->city,
$order->billing->state,
$order->billing->zip,
$order->billing->country,
$order->billing->phone ),
'cardtype' => $order->cardtype,
'accountnumber' => hideCardNumber( $order->accountnumber ),
'expirationmonth' => $order->expirationmonth,
'expirationyear' => $order->expirationyear,
);
}
}

/**
* Register the email template.
*
* @since TBD
*
* @param array $email_templates The email templates (template slug => email template class name)
* @return array The modified email templates array.
*/
function pmpro_email_templates_credit_card_expiring( $email_templates ) {
$email_templates['credit_card_expiring'] = 'PMPro_Email_Template_Credit_Card_Expiring';
return $email_templates;
}
add_filter( 'pmpro_email_templates', 'pmpro_email_templates_credit_card_expiring' );
18 changes: 0 additions & 18 deletions includes/email-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,6 @@
<p>Log in to your membership account here: !!login_url!!</p>', 'paid-memberships-pro' ),
'help_text' => __( 'This is the membership confirmation email sent to the site administrator for every paid membership checkout on the site.', 'paid-memberships-pro' )
),
'credit_card_expiring' => array(
'subject' => __( "Credit card on file expiring soon at !!sitename!!", 'paid-memberships-pro' ),
'description' => __('Credit Card Expiring', 'paid-memberships-pro'),
'body' => __( '<p>The payment method used for your membership at !!sitename!! will expire soon. <strong>Please click the following link to log in and update your billing information to avoid account suspension. !!login_url!!</strong></p>

<p>Account: !!display_name!! (!!user_email!!)</p>
<p>The most recent account information we have on file is:</p>

<p>!!billing_name!!</br />
!!billing_address!!
</p>

<p>
!!cardtype!!: !!accountnumber!!<br />
Expires: !!expirationmonth!!/!!expirationyear!!
</p>', 'paid-memberships-pro' ),
'help_text' => __( 'This email is sent when a member\'s payment method will be expiring soon. This allows the member to update their payment method before a payment failure, which may result in lost access to member features.', 'paid-memberships-pro' )
),
'invoice' => array(
'subject' => __( "Recurring payment receipt for !!sitename!! membership", 'paid-memberships-pro' ),
'description' => __('Recurring Payment Receipt', 'paid-memberships-pro'),
Expand Down
4 changes: 4 additions & 0 deletions includes/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ function pmpro_email_templates_send_test() {
$send_email = 'sendPaymentActionRequiredAdminEmail';
$params = array($test_user, $test_order, "http://www.example-notification-url.com/not-a-real-site");
break;
case 'credit_card_expiring':
$send_email = 'sendCreditCardExpiringEmail';
$params = array($test_user, $test_order, "http://www.example-notification-url.com/not-a-real-site");
break;
default:
$send_email = 'sendEmail';
$params = array();
Expand Down
1 change: 1 addition & 0 deletions paid-memberships-pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-cancel-admin.php' ); // cancel email template
require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-admin-change.php' ); // change email template
require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-admin-change-admin.php' ); // change email template
require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-credit-card-expiring.php' ); // credit card expiring email template
require_once( PMPRO_DIR . '/includes/filters.php' ); // filters, hacks, etc, moved into the plugin
require_once( PMPRO_DIR . '/includes/reports.php' ); // load reports for admin (reports may also include tracking code, etc)

Expand Down