From 9da064a2faed639182832f05c57b6b2ec051e428 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 13 Mar 2018 20:02:10 -0400 Subject: [PATCH] Fix sending email notifications for payments and invoices Now sending out notifications for invoice creation and payment received. --- classes/billingSupport.php | 12 +++++++---- classes/notifications.php | 20 ++++++------------- .../admin/settings/editNotificationType.html | 9 ++++++++- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 923184e..0114f65 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -302,17 +302,21 @@ class GlmBillingSupport // Create Notification Object $Notifications = new GlmNotifications( $this->wpdb, $this->config ); - echo '
$type: ' . print_r( $type, true ) . '
'; - // Trigger sending the email notifications for send by action 'payment received' switch ( $type ) { case $this->config['transaction_numb']['Invoice']: case $this->config['transaction_numb']['Payment']: + $data = array( + 'type' => $type, + 'type_id' => $type_id, + 'account' => $account, + 'amount' => $current_invoice_total, + 'payment' => $current_payment_total, + ); $notices = $Notifications->getNotificationsWithSendByAction( $type ); - echo '
$notices: ' . print_r( $notices, true ) . '
'; foreach ( $notices as $notice ) { - $Notifications->sendEmailNotification( $notice['id'], $account ); + $Notifications->sendEmailNotification( $notice['id'], $account, $data ); } break; default: diff --git a/classes/notifications.php b/classes/notifications.php index 1a625aa..8badb00 100644 --- a/classes/notifications.php +++ b/classes/notifications.php @@ -68,7 +68,7 @@ class GlmNotifications * @access public * @return void */ - public function sendEmailNotification( $notification_id, $account_id ) + public function sendEmailNotification( $notification_id, $account_id, $data = null ) { // Support Class $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); @@ -78,19 +78,14 @@ class GlmNotifications // If there's no account then return false. return false; } - // echo '
$account: ' . print_r( $account, true ) . '
'; - // exit; $to_email = $account['email']; - // echo '
$to_email: ' . print_r( $to_email, true ) . '
'; if ( !$to_email ) { // If there's no email then return false. return false; } // get the Notification type - // var_dump( $notification_id ); $notification_type = $this->getNotificationTypeById( $notification_id ); - // echo '
$notification_type: ' . print_r( $notification_type, true ) . '
'; if ( !$notification_type ) { // If there's no notification type then return false. return false; @@ -124,14 +119,12 @@ class GlmNotifications 'phone' => $account['billing_phone'], ) ); - // echo '
$notification_type[message]: ' . print_r( $notification_type['message'], true ) . '
'; + // Merge any data passed into this method + $account_data['data'] = $data; $notification_message = $this->parseSmartyTemplateString( $account_data, wpautop( $notification_type['message'] ) ); - // echo '
$account_data: ' . print_r( $account_data, true ) . '
'; - // echo '
$notification_message: ' . print_r( $notification_message, true ) . '
'; - // exit; $smarty->templateAssign( 'title', $notification_type['subject'] ); $smarty->templateAssign( 'html_content', $notification_message ); @@ -194,7 +187,6 @@ class GlmNotifications // Add data from model to Smarty template if ( is_array( $data ) && count( $data ) > 0 ) { foreach ( $data as $key => $value ) { - echo '
$key: ' . print_r( $key, true ) . '
'; $smarty->templateAssign( $key, $value ); } } @@ -271,7 +263,7 @@ class GlmNotifications * * Return array of notifications with send_by_action as $type * - * @param mixed $type Type of send_by_action ('Create Invoice', 'Payment Received') + * @param int $type Type of send_by_action (10 => 'Create Invoice', 20 => 'Payment Received') * * @access public * @return array @@ -282,9 +274,9 @@ class GlmNotifications $this->wpdb->prepare( "SELECT id FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_types - WHERE send_by_action + WHERE send_by_action <> false AND send_action = %d", - $this->config['send_action'][$type] + $type ), ARRAY_A ); diff --git a/views/admin/settings/editNotificationType.html b/views/admin/settings/editNotificationType.html index c52b7e6..49f8667 100644 --- a/views/admin/settings/editNotificationType.html +++ b/views/admin/settings/editNotificationType.html @@ -15,7 +15,6 @@ {/if} -{debug} @@ -150,6 +149,14 @@ + + + + + + + +
{literal}{$account.phone}{/literal} Billing Phone
{literal}{$data.amount}{/literal}Invoice Amount
{literal}{$data.payment}{/literal}Payment Amount
-- 2.17.1