Explorar o código

orderdetails api & hook

andre %!s(int64=3) %!d(string=hai) anos
pai
achega
3d504b99f1
Modificáronse 2 ficheiros con 215 adicións e 0 borrados
  1. 196 0
      getorderdetails.php
  2. 19 0
      orderdetails.php

+ 196 - 0
getorderdetails.php

@@ -0,0 +1,196 @@
+<?php
+use WHMCS\Database\Capsule;
+
+if (!defined("WHMCS")) {
+    exit("This file cannot be accessed directly");
+}
+
+$data = $_REQUEST;
+
+if(empty($data['orderid'])) {
+    $apiresults = array('result' => 'error', 'message' => 'OrderID is required');
+    return ;
+}
+
+$orderid = (int) $data['orderid'];
+
+$setup = array(
+    'One Time'      => 'msetupfee',
+    'Monthly'       => 'msetupfee',
+    'Quarterly'     => 'qsetupfee',
+    'Semi-Annually' => 'ssetupfee',
+    'Annually'      => 'asetupfee',
+    'Biennially'    => 'bsetupfee',
+    'Triennially'   => 'tsetupfee',
+);
+$recurring = array(
+    'One Time'      => 'monthly',
+    'Monthly'       => 'monthly',
+    'Quarterly'     => 'quarterly',
+    'Semi-Annually' => 'semiannually',
+    'Annually'      => 'annually',
+    'Biennially'    => 'biennially',
+    'Triennially'   => 'triennially',
+);
+$billingterm = array(
+    'Free Account'  => $_LANG['orderpaymenttermfree'],
+    'One Time'      => $_LANG['orderpaymenttermonetime'],
+    'Monthly'       => $_LANG['orderpaymenttermmonthly'],
+    'Quarterly'     => $_LANG['orderpaymenttermquarterly'],
+    'Semi-Annually' => $_LANG['orderpaymenttermsemiannually'],
+    'Annually'      => $_LANG['orderpaymenttermannually'],
+    'Biennially'    => $_LANG['orderpaymenttermbiennially'],
+    'Triennially'   => $_LANG['orderpaymenttermtriennially'],
+);
+
+$order_details = array();
+$order = localAPI('GetOrders', array('id' => $orderid));
+$order_details['ordernumber'] = $order['orders']['order'][0]['ordernum'];
+$order_details['date'] = $order['orders']['order'][0]['date'];
+$order_details['invoiceid'] = $order['orders']['order'][0]['invoiceid'];
+$order_details['currency'] = $order['orders']['order'][0]['currencyprefix'];
+$order_details['amount'] = $order['orders']['order'][0]['amount'];
+$currencyId = Capsule::table('tblcurrencies')
+    ->where('prefix', $order_details['currency'])
+    ->value('id');
+$serviceIds = Capsule::table('tblhosting')
+    ->where('orderid', $orderid)
+    ->get('id');
+$order_details['products'] = array();
+foreach($serviceIds as $serviceId) {
+    unset($service_details);
+    $service[$serviceId->id] = localAPI('GetClientsProducts', array('serviceid' => $serviceId->id));
+    $service_details['id'] = $serviceId->id;
+    $service_details['name'] = $service[$serviceId->id]['products']['product'][0]['name'];
+    $service_details['groupname'] = $service[$serviceId->id]['products']['product'][0]['groupname'];
+    $productBillingcycle = $service[$serviceId->id]['products']['product'][0]['billingcycle'];
+    // use domain or alternatvie custom fields for naming the service
+    if($service[$serviceId->id]['products']['product'][0]['domain']) {
+        $service_details['domain'] = $service[$serviceId->id]['products']['product'][0]['domain'];
+    } else {
+        unset($domain);
+        unset($name);
+        foreach($service[$serviceId->id]['products']['product'][0]['customfields']['customfield'] as $customfield) {
+            switch($customfield['name']) {
+                case 'E-Mail Name':
+                case 'Login E-Mail':
+                case 'Nextcloud Benutzername':
+                case 'Name des VDC':
+                    $name = $customfield['value'];
+                    break;
+                case 'Mail Domaine':
+                    $domain = $customfield['value'];
+                    break;
+            }
+            if ($name && $domain) {
+                $service_details['altdomain'] = $name . '@' . $domain;
+            } elseif ($name) {
+                $service_details['altdomain'] = $name;
+            } elseif ($domain) {
+                $service_details['altdomain'] = $domain;
+            } else {
+                $service_details['altdomain'] = 'ID:' . $serviceId->id;
+            }
+        }
+    }
+    // price
+    if($productBillingcycle != 'Free Account') {
+        $packageId = Capsule::table('tblhosting')
+            ->where('id', $serviceId->id)
+            ->value('packageid');
+        $prorata = Capsule::table('tblproducts')
+            ->where('id', $packageId)
+            ->value('proratabilling');
+        if($prorata == 1) {
+            $service_details['prorata'] = $prorata;
+        }
+        $product_setup = Capsule::table('tblpricing')
+            ->where('relid', $packageId)
+            ->where('type', 'product')
+            ->where('currency', $currencyId)
+            ->value($setup[$productBillingcycle]);
+        $product_recurring = Capsule::table('tblpricing')
+            ->where('relid', $packageId)
+            ->where('type', 'product')
+            ->where('currency', $currencyId)
+            ->value($recurring[$productBillingcycle]);
+        if($product_setup > 0) {
+            $service_details['setup'] = $product_setup;
+        }
+        if($product_recurring > 0) {
+            $service_details['recurring'] = $product_recurring;
+        }
+    }
+    $service_details['billingcycle'] = $billingterm[$productBillingcycle];
+    // configoptions
+    $service_details['configoptions'] = array();
+    foreach($service[$serviceId->id]['products']['product'][0]['configoptions']['configoption'] as $configoption) {
+        unset($option_details);
+        if($configoption['value'] != '' && $configoption['value'] != 0) {
+            $option_details['id'] = $configoption['id'];
+            $option_details['name'] = $configoption['option'];
+            $option_details['qty'] = $configoption['value'];
+            if($productBillingcycle != 'Free Account') {
+                $configoptionId = Capsule::table('tblhostingconfigoptions')
+                    ->where('relid', $serviceId->id)
+                    ->value('optionid');
+                $option_setup = Capsule::table('tblpricing')
+                    ->where('type', 'configoptions')
+                    ->where('currency', $currencyId)
+                    ->where('relid', $configoptionId)
+                    ->value($setup[$productBillingcycle]);
+                $option_recurring = Capsule::table('tblpricing')
+                    ->where('type', 'configoptions')
+                    ->where('currency', $currencyId)
+                    ->where('relid', $configoptionId)
+                    ->value($recurring[$productBillingcycle]);
+                if($option_setup > 0) {
+                    $option_details['setup'] = $option_setup;
+                }
+                if ($option_recurring > 0) {
+                    $option_details['recurring'] = $option_recurring;
+                }
+            }
+        array_push($service_details['configoptions'], $option_details);
+        }
+    }
+    if(empty($service_details['configoptions'])) {
+        unset($service_details['configoptions']);
+    }
+    // addons
+    $addon[$serviceId->id] = localAPI('GetClientsAddons', array('serviceid' => $serviceId->id));
+    if($addon[$serviceId->id]['totalresults'] != 0) {
+        $service_details['addons'] = array();
+        foreach($addon[$serviceId->id]['addons']['addon'] as $addon) {
+            unset($service_addon_details);
+            $addon_details = (array) Capsule::table('tblhostingaddons')->where('id', $addon['id'])->first();
+            $addonBillingcycle = $addon_details['billingcycle'];
+            $service_addon_details['id'] = $addon['id'];
+            $service_addon_details['name'] = $addon['name'];
+            $service_addon_details['qty'] = $addon_details['qty'];
+            if($addonBillingcycle != 'Free Account') {
+                $addon_setup = Capsule::table('tblpricing')
+                    ->where('relid', $addon_details['addonid'])
+                    ->where('type', 'addon')
+                    ->where('currency', $currencyId)
+                    ->value($setup[$addonBillingcycle]);
+                $addon_recurring = Capsule::table('tblpricing')
+                    ->where('relid', $addon_details['addonid'])
+                    ->where('type', 'addon')
+                    ->where('currency', $currencyId)
+                    ->value($recurring[$addonBillingcycle]);
+                if($addon_setup > 0) {
+                    $service_addon_details['setup'] = $addon_setup;
+                }
+                if($addon_recurring > 0) {
+                    $service_addon_details['recurring'] = $addon_recurring;
+                }
+            }
+            $service_addon_details['billingcycle'] = $billingterm[$addonBillingcycle];
+            array_push($service_details['addons'], $service_addon_details);
+        }
+    }
+    array_push($order_details['products'], $service_details);
+}
+$apiresults['orderdetails'] = $order_details;
+$responsetype = "xml";

+ 19 - 0
orderdetails.php

@@ -0,0 +1,19 @@
+<?php
+if (!defined("WHMCS"))
+    die("This file cannot be accessed directly");
+
+add_hook("EmailPreSend", 1, function($vars) {
+	if($vars['messagename'] == 'Order Confirmation') {
+		$result = localapi('GetOrderDetails', array('orderid' => $vars['mergefields']['order_id']));
+		logModuleCall(
+			'EmailPreSend',
+			__FUNCTION__,
+			$result,
+			'debug',
+			''
+		);
+		return $result;
+	}
+	return false;	
+});
+