getorderdetails.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. use WHMCS\Database\Capsule;
  3. if (!defined("WHMCS")) {
  4. exit("This file cannot be accessed directly");
  5. }
  6. $data = $_REQUEST;
  7. if(empty($data['orderid'])) {
  8. $apiresults = array('result' => 'error', 'message' => 'OrderID is required');
  9. return ;
  10. }
  11. $orderid = (int) $data['orderid'];
  12. // mappings for WHMCS inconsistency
  13. $setup = array(
  14. 'One Time' => 'msetupfee',
  15. 'Monthly' => 'msetupfee',
  16. 'Quarterly' => 'qsetupfee',
  17. 'Semi-Annually' => 'ssetupfee',
  18. 'Annually' => 'asetupfee',
  19. 'Biennially' => 'bsetupfee',
  20. 'Triennially' => 'tsetupfee',
  21. 'onetime' => 'msetupfee',
  22. 'monthly' => 'msetupfee',
  23. 'quarterly' => 'qsetupfee',
  24. 'semiannually' => 'ssetupfee',
  25. 'annually' => 'asetupfee',
  26. 'biennially' => 'bsetupfee',
  27. 'triennially' => 'tsetupfee',
  28. );
  29. $recurring = array(
  30. 'One Time' => 'monthly',
  31. 'Monthly' => 'monthly',
  32. 'Quarterly' => 'quarterly',
  33. 'Semi-Annually' => 'semiannually',
  34. 'Annually' => 'annually',
  35. 'Biennially' => 'biennially',
  36. 'Triennially' => 'triennially',
  37. 'onetime' => 'monthly',
  38. 'monthly' => 'monthly',
  39. 'quarterly' => 'quarterly',
  40. 'semiannually' => 'semiannually',
  41. 'annually' => 'annually',
  42. 'biennially' => 'biennially',
  43. 'triennially' => 'triennially',
  44. );
  45. $billingterm = array(
  46. 'Free Account' => Lang::trans('orderpaymenttermfree'),
  47. 'One Time' => Lang::trans('orderpaymenttermonetime'),
  48. 'Monthly' => Lang::trans('orderpaymenttermmonthly'),
  49. 'Quarterly' => Lang::trans('orderpaymenttermquarterly'),
  50. 'Semi-Annually' => Lang::trans('orderpaymenttermsemiannually'),
  51. 'Annually' => Lang::trans('orderpaymenttermannually'),
  52. 'Biennially' => Lang::trans('orderpaymenttermbiennially'),
  53. 'Triennially' => Lang::trans('orderpaymenttermtriennially'),
  54. 'onetime' => Lang::trans('orderpaymenttermonetime'),
  55. 'monthly' => Lang::trans('orderpaymenttermmonthly'),
  56. 'quarterly' => Lang::trans('orderpaymenttermquarterly'),
  57. 'semiannually' => Lang::trans('orderpaymenttermsemiannually'),
  58. 'annually' => Lang::trans('orderpaymenttermannually'),
  59. 'biennially' => Lang::trans('orderpaymenttermbiennially'),
  60. 'triennially' => Lang::trans('orderpaymenttermtriennially'),
  61. '1' => Lang::trans('orderpaymenttermannually'),
  62. '2' => Lang::trans('orderpaymenttermbiennially'),
  63. '3' => Lang::trans('orderpaymenttermtriennially'),
  64. );
  65. // gathering globals
  66. $order_details = array();
  67. $order = localAPI('GetOrders', array('id' => $orderid));
  68. $order_details['ordernumber'] = $order['orders']['order'][0]['ordernum'];
  69. $order_details['date'] = $order['orders']['order'][0]['date'];
  70. $order_details['invoiceid'] = $order['orders']['order'][0]['invoiceid'];
  71. $order_details['currency'] = $order['orders']['order'][0]['currencyprefix'];
  72. $order_details['amount'] = $order['orders']['order'][0]['amount'];
  73. $currencyId = Capsule::table('tblcurrencies')
  74. ->where('prefix', $order_details['currency'])
  75. ->value('id');
  76. $serviceIds = Capsule::table('tblhosting')
  77. ->where('orderid', $orderid)
  78. ->get('id');
  79. // gathering informations of products
  80. $order_details['products'] = array();
  81. $serviceIdsArray = array();
  82. foreach($serviceIds as $serviceId) {
  83. array_push($serviceIdsArray, $serviceId->id);
  84. unset($service_details);
  85. $service[$serviceId->id] = localAPI('GetClientsProducts', array('serviceid' => $serviceId->id));
  86. $service_details['id'] = $serviceId->id;
  87. $service_details['name'] = $service[$serviceId->id]['products']['product'][0]['name'];
  88. $service_details['groupname'] = $service[$serviceId->id]['products']['product'][0]['groupname'];
  89. $productBillingcycle = $service[$serviceId->id]['products']['product'][0]['billingcycle'];
  90. // use domain or alternatvie custom fields for naming the service
  91. if($service[$serviceId->id]['products']['product'][0]['domain']) {
  92. $service_details['domain'] = $service[$serviceId->id]['products']['product'][0]['domain'];
  93. } else {
  94. unset($domain);
  95. unset($name);
  96. foreach($service[$serviceId->id]['products']['product'][0]['customfields']['customfield'] as $customfield) {
  97. switch($customfield['name']) {
  98. case 'E-Mail Name':
  99. case 'Login E-Mail':
  100. case 'Nextcloud Benutzername':
  101. case 'Name des VDC':
  102. $name = $customfield['value'];
  103. break;
  104. case 'Mail Domain':
  105. $domain = $customfield['value'];
  106. break;
  107. }
  108. if ($name && $domain) {
  109. $service_details['domain'] = $name . '@' . $domain;
  110. } elseif ($name) {
  111. $service_details['domain'] = $name;
  112. } elseif ($domain) {
  113. $service_details['domain'] = $domain;
  114. } else {
  115. $service_details['domain'] = 'ID:' . $serviceId->id;
  116. }
  117. }
  118. }
  119. // price
  120. if($productBillingcycle != 'Free Account') {
  121. $packageId = Capsule::table('tblhosting')
  122. ->where('id', $serviceId->id)
  123. ->value('packageid');
  124. $prorata = Capsule::table('tblproducts')
  125. ->where('id', $packageId)
  126. ->value('proratabilling');
  127. if($prorata == 1) {
  128. $service_details['prorata'] = $prorata;
  129. }
  130. $product_setup = Capsule::table('tblpricing')
  131. ->where('relid', $packageId)
  132. ->where('type', 'product')
  133. ->where('currency', $currencyId)
  134. ->value($setup[$productBillingcycle]);
  135. $product_recurring = Capsule::table('tblpricing')
  136. ->where('relid', $packageId)
  137. ->where('type', 'product')
  138. ->where('currency', $currencyId)
  139. ->value($recurring[$productBillingcycle]);
  140. if($product_setup > 0) {
  141. $service_details['setup'] = $product_setup;
  142. }
  143. if($product_recurring > 0) {
  144. $service_details['recurring'] = $product_recurring;
  145. }
  146. }
  147. $service_details['billingcycle'] = $billingterm[$productBillingcycle];
  148. // configoptions
  149. $service_details['configoptions'] = array();
  150. foreach($service[$serviceId->id]['products']['product'][0]['configoptions']['configoption'] as $configoption) {
  151. unset($option_details);
  152. if($configoption['value'] != '' && $configoption['value'] != 0) {
  153. $option_details['id'] = $configoption['id'];
  154. $option_details['name'] = $configoption['option'];
  155. $option_details['qty'] = $configoption['value'];
  156. if($productBillingcycle != 'Free Account') {
  157. $configoptionId = Capsule::table('tblhostingconfigoptions')
  158. ->where('configid', $configoption['id'])
  159. ->value('optionid');
  160. $option_setup = Capsule::table('tblpricing')
  161. ->where('type', 'configoptions')
  162. ->where('currency', $currencyId)
  163. ->where('relid', $configoptionId)
  164. ->value($setup[$productBillingcycle]);
  165. $option_recurring = Capsule::table('tblpricing')
  166. ->where('type', 'configoptions')
  167. ->where('currency', $currencyId)
  168. ->where('relid', $configoptionId)
  169. ->value($recurring[$productBillingcycle]);
  170. if($option_setup > 0) {
  171. $option_details['setup'] = $option_setup;
  172. }
  173. if ($option_recurring > 0) {
  174. $option_details['recurring'] = $option_recurring;
  175. }
  176. }
  177. array_push($service_details['configoptions'], $option_details);
  178. }
  179. }
  180. // addons
  181. $addon[$serviceId->id] = localAPI('GetClientsAddons', array('serviceid' => $serviceId->id));
  182. $service_details['addons'] = array();
  183. if($addon[$serviceId->id]['totalresults'] != 0) {
  184. foreach($addon[$serviceId->id]['addons']['addon'] as $addon) {
  185. unset($service_addon_details);
  186. $addon_details = (array) Capsule::table('tblhostingaddons')->where('id', $addon['id'])->first();
  187. $addonBillingcycle = $addon_details['billingcycle'];
  188. $service_addon_details['id'] = $addon['id'];
  189. $service_addon_details['name'] = $addon['name'];
  190. $service_addon_details['qty'] = $addon_details['qty'];
  191. if($addonBillingcycle != 'Free Account') {
  192. $addon_setup = Capsule::table('tblpricing')
  193. ->where('relid', $addon_details['addonid'])
  194. ->where('type', 'addon')
  195. ->where('currency', $currencyId)
  196. ->value($setup[$addonBillingcycle]);
  197. $addon_recurring = Capsule::table('tblpricing')
  198. ->where('relid', $addon_details['addonid'])
  199. ->where('type', 'addon')
  200. ->where('currency', $currencyId)
  201. ->value($recurring[$addonBillingcycle]);
  202. if($addon_setup > 0) {
  203. $service_addon_details['setup'] = $addon_setup;
  204. }
  205. if($addon_recurring > 0) {
  206. $service_addon_details['recurring'] = $addon_recurring;
  207. }
  208. }
  209. $service_addon_details['billingcycle'] = $billingterm[$addonBillingcycle];
  210. array_push($service_details['addons'], $service_addon_details);
  211. }
  212. }
  213. array_push($order_details['products'], $service_details);
  214. }
  215. // gathering informations of addons bought without buying a product
  216. $addons = Capsule::table('tblhostingaddons')
  217. ->where('orderid', $orderid)
  218. ->whereNotIn('hostingid', $serviceIdsArray)
  219. ->get();
  220. $order_details['addons'] = array();
  221. foreach($addons as $addon) {
  222. unset($addon_details);
  223. $addon_details['name'] = Capsule::table('tbladdons')
  224. ->where('id', $addon->addonid)
  225. ->value('name');
  226. $addonBillingcycle = $addon->billingcycle;
  227. $addon_details['id'] = $addon->id;
  228. $addon_details['qty'] = $addon->qty;
  229. if($addonBillingcycle != 'Free Account') {
  230. $addon_setup = Capsule::table('tblpricing')
  231. ->where('relid', $addon->addonid)
  232. ->where('type', 'addon')
  233. ->where('currency', $currencyId)
  234. ->value($setup[$addonBillingcycle]);
  235. $addon_recurring = Capsule::table('tblpricing')
  236. ->where('relid', $addon->addonid)
  237. ->where('type', 'addon')
  238. ->where('currency', $currencyId)
  239. ->value($recurring[$addonBillingcycle]);
  240. if($addon_setup > 0) {
  241. $addon_details['setup'] = $addon_setup;
  242. }
  243. if($addon_recurring > 0) {
  244. $addon_details['recurring'] = $addon_recurring;
  245. }
  246. if(!empty($addon->subscriptionid)) {
  247. $addon_details['servicecode'] = $addon->subscriptionid;
  248. }
  249. }
  250. $addon_parent = localAPI('GetClientsProducts', array('serviceid' => $addon->hostingid));
  251. $addon_details['parent'] = array(
  252. 'name' => $addon_parent['products']['product'][0]['translated_name'],
  253. 'domain' => $addon_parent['products']['product'][0]['domain']
  254. );
  255. $addon_details['billingcycle'] = $billingterm[$addonBillingcycle];
  256. array_push($order_details['addons'], $addon_details);
  257. }
  258. // gathering informations of domains
  259. $domains = Capsule::table('tbldomains')
  260. ->where('orderid', $orderid)
  261. ->get();
  262. $order_details['domains'] = array();
  263. foreach($domains as $domain) {
  264. unset($domain_details);
  265. $domain_details['id'] = $domain->id;
  266. $domain_details['name'] = $domain->domain;
  267. $domain_details['type'] = $domain->type;
  268. if(!empty($domain->registrar)) {
  269. $domain_details['registrar'] = $domain->registrar;
  270. }
  271. $domain_details['period'] = $billingterm[(string)$domain->registrationperiod];
  272. $tld = end(explode(".", $domain->domain));
  273. $tldPricing = localAPI('GetTLDPricing', array('currencyid' => $currencyId));
  274. $domain_details['recurring'] = $tldPricing['pricing'][$tld][strtolower($domain->type)][$domain->registrationperiod];
  275. if($domain->dnsmanagement > 0){
  276. if(!empty($tldPricing['pricing'][$tld]['addons']['dns'])) {
  277. $domain_details['addons']['dnsmanagement'] = $tldPricing['pricing'][$tld]['addons']['dns'];
  278. } else {
  279. $domain_details['addons']['dnsmanagement'] = $billingterm['Free Account'];
  280. }
  281. }
  282. if($domain->emailforwarding > 0){
  283. if($tldPricing['pricing'][$tld]['addons']['dns'] > 0) {
  284. $domain_details['addons']['emailforwarding'] = $tldPricing['pricing'][$tld]['addons']['email'];
  285. } else {
  286. $domain_details['addons']['emailforwarding'] = $billingterm['Free Account'];
  287. }
  288. }
  289. if($domain->idprotection > 0){
  290. if($tldPricing['pricing'][$tld]['addons']['idprotect'] > 0) {
  291. $domain_details['addons']['idprotection'] = $tldPricing['pricing'][$tld]['addons']['idprotect'];
  292. } else {
  293. $domain_details['addons']['idprotection'] = $billingterm['Free Account'];
  294. }
  295. }
  296. array_push($order_details['domains'], $domain_details);
  297. }
  298. // response all together
  299. $apiresults['orderdetails'] = $order_details;
  300. $responsetype = "xml";