Fix sending email notifications for payments and invoices
authorSteve Sutton <ssutton@gmail.com>
Wed, 14 Mar 2018 00:02:10 +0000 (20:02 -0400)
committerSteve Sutton <ssutton@gmail.com>
Wed, 14 Mar 2018 00:02:10 +0000 (20:02 -0400)
Now sending out notifications for invoice creation and payment received.

classes/billingSupport.php
classes/notifications.php
views/admin/settings/editNotificationType.html

index 923184e..0114f65 100644 (file)
@@ -302,17 +302,21 @@ class GlmBillingSupport
         // Create Notification Object
         $Notifications = new GlmNotifications( $this->wpdb, $this->config );
 
-        echo '<pre>$type: ' . print_r( $type, true ) . '</pre>';
-
         // 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 '<pre>$notices: ' . print_r( $notices, true ) . '</pre>';
             foreach ( $notices as $notice ) {
-                $Notifications->sendEmailNotification( $notice['id'], $account );
+                $Notifications->sendEmailNotification( $notice['id'], $account, $data );
             }
             break;
         default:
index 1a625aa..8badb00 100644 (file)
@@ -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 '<pre>$account: ' . print_r( $account, true ) . '</pre>';
-        // exit;
         $to_email = $account['email'];
-        // echo '<pre>$to_email: ' . print_r( $to_email, true ) . '</pre>';
         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 '<pre>$notification_type: ' . print_r( $notification_type, true ) . '</pre>';
         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 '<pre>$notification_type[message]: ' . print_r( $notification_type['message'], true ) . '</pre>';
+        // Merge any data passed into this method
+        $account_data['data'] = $data;
         $notification_message = $this->parseSmartyTemplateString(
             $account_data,
             wpautop( $notification_type['message'] )
         );
-        // echo '<pre>$account_data: ' . print_r( $account_data, true ) . '</pre>';
-        // echo '<pre>$notification_message: ' . print_r( $notification_message, true ) . '</pre>';
-        // 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 '<pre>$key: ' . print_r( $key, true ) . '</pre>';
                 $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
         );
index c52b7e6..49f8667 100644 (file)
@@ -15,7 +15,6 @@
         <input type="hidden" name="option" value="insert">
     {/if}
 
-{debug}
     <table class="glm-admin-table glm-event-table">
 
         <tr>
                         <th>{literal}{$account.phone}{/literal}</th>
                         <td>Billing Phone</td>
                     </tr>
+                    <tr>
+                        <th>{literal}{$data.amount}{/literal}</th>
+                        <td>Invoice Amount</td>
+                    </tr>
+                    <tr>
+                        <th>{literal}{$data.payment}{/literal}</th>
+                        <td>Payment Amount</td>
+                    </tr>
                 </table>
             </td>
         </tr>