From 162ccc07fe10bba80383d5435b330b0be93e1338 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Sat, 13 May 2023 14:32:19 -0700 Subject: [PATCH 1/2] Add more info to invoice paid and order paid --- .../hooks/WHMCS-Discord-Notifications.php | 59 ++++++++++++++++++- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/includes/hooks/WHMCS-Discord-Notifications.php b/includes/hooks/WHMCS-Discord-Notifications.php index 01e06c9..11ecb57 100644 --- a/includes/hooks/WHMCS-Discord-Notifications.php +++ b/includes/hooks/WHMCS-Discord-Notifications.php @@ -81,10 +81,14 @@ $cancellationRequest = false; // New Cancellation Request Received Notific if($invoicePaid === true): add_hook('InvoicePaid', 1, function($vars) { + $invoice = localAPI('GetInvoice', array('invoiceid' => $vars['invoiceid']), ''); + $client = localAPI('GetClientsDetails', array('clientid' => $invoice['userid'], 'stats' => false), ''); + $dataPacket = array( 'content' => $GLOBALS['discordGroupID'], 'username' => $GLOBALS['companyName'], 'avatar_url' => $GLOBALS['discordWebHookAvatar'], + // Create a pretty embed showing the email of the user who paid as well as the amount of paid. Include each product in the order as an inline field 'embeds' => array( array( 'title' => 'Invoice ' . $vars['invoiceid'] . ' Has Been Paid', @@ -94,6 +98,18 @@ if($invoicePaid === true): 'color' => $GLOBALS['discordColor'], 'author' => array( 'name' => 'Invoice Paid' + ), + 'fields' => array( + array( + 'name' => 'User Email', + 'value' => $client['email'], + 'inline' => true + ), + array( + 'name' => 'Amount Paid', + 'value' => '$' . $invoice['total'], + 'inline' => true + ) ) ) ) @@ -242,19 +258,56 @@ endif; if($orderPaid === true): add_hook('OrderPaid', 1, function($vars) { + // Use the local api to get the order details + $postData = array( + 'id' => $vars['orderId'], + ); + $orders = localAPI('GetOrders', $postData, ''); + $order = $orders['orders']['order'][0]; + // Request information about the user who placed the order + $postData = array( + 'clientid' => $order['userid'], + ); + $clients = localAPI('GetClientsDetails', $postData, ''); + $client = $clients['client']; + $productsOrder = $order['lineitems']['lineitem']; + $products = ''; + // Loop through the line items creating a comma separated string of products + foreach($productsOrder as $product) { + $products .= $product['product'] . ', '; + } + // Remove the last comma + $products = substr($products, 0, -2); $dataPacket = array( 'content' => $GLOBALS['discordGroupID'], 'username' => $GLOBALS['companyName'], 'avatar_url' => $GLOBALS['discordWebHookAvatar'], 'embeds' => array( array( - 'title' => 'Order ' . $vars['orderid'] . ' Has Been Paid', - 'url' => $GLOBALS['whmcsAdminURL'] . 'orders.php?action=view&id=' . $vars['orderid'], + 'title' => 'Order ' . $vars['orderId'] . ' Has Been Paid', + 'url' => $GLOBALS['whmcsAdminURL'] . 'orders.php?action=view&id=' . $vars['orderId'], 'timestamp' => date(DateTime::ISO8601), 'description' => '', 'color' => $GLOBALS['discordColor'], 'author' => array( - 'name' => 'Order Has been Paid' + 'name' => 'Order Paid' + ), + 'fields' => array( + array( + 'name' => 'User Email', + 'value' => $client['email'], + 'inline' => true + ), + array( + 'name' => 'Amount Paid', + 'value' => '$' . $order['amount'], + 'inline' => true + ), + array( + 'name' => 'Products', + 'value' => $products, + 'inline' => false + ) ) ) ) From 2cb9e16dcd9fa248b17ac4e0705cbdf91b9f3c72 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Sat, 13 May 2023 14:34:24 -0700 Subject: [PATCH 2/2] Get rid of incorrect comment --- includes/hooks/WHMCS-Discord-Notifications.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/hooks/WHMCS-Discord-Notifications.php b/includes/hooks/WHMCS-Discord-Notifications.php index 11ecb57..716862b 100644 --- a/includes/hooks/WHMCS-Discord-Notifications.php +++ b/includes/hooks/WHMCS-Discord-Notifications.php @@ -88,7 +88,6 @@ if($invoicePaid === true): 'content' => $GLOBALS['discordGroupID'], 'username' => $GLOBALS['companyName'], 'avatar_url' => $GLOBALS['discordWebHookAvatar'], - // Create a pretty embed showing the email of the user who paid as well as the amount of paid. Include each product in the order as an inline field 'embeds' => array( array( 'title' => 'Invoice ' . $vars['invoiceid'] . ' Has Been Paid',