getorderdetails.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. foreach($serviceIds as $serviceId) {
  82. unset($service_details);
  83. $service[$serviceId->id] = localAPI('GetClientsProducts', array('serviceid' => $serviceId->id));
  84. $service_details['id'] = $serviceId->id;
  85. $service_details['name'] = $service[$serviceId->id]['products']['product'][0]['name'];
  86. $service_details['groupname'] = $service[$serviceId->id]['products']['product'][0]['groupname'];
  87. $productBillingcycle = $service[$serviceId->id]['products']['product'][0]['billingcycle'];
  88. // use domain or alternatvie custom fields for naming the service
  89. if($service[$serviceId->id]['products']['product'][0]['domain']) {
  90. $service_details['domain'] = $service[$serviceId->id]['products']['product'][0]['domain'];
  91. } else {
  92. unset($domain);
  93. unset($name);
  94. foreach($service[$serviceId->id]['products']['product'][0]['customfields']['customfield'] as $customfield) {
  95. switch($customfield['name']) {
  96. case 'E-Mail Name':
  97. case 'Login E-Mail':
  98. case 'Nextcloud Benutzername':
  99. case 'Name des VDC':
  100. $name = $customfield['value'];
  101. break;
  102. case 'Mail Domain':
  103. $domain = $customfield['value'];
  104. break;
  105. }
  106. if ($name && $domain) {
  107. $service_details['domain'] = $name . '@' . $domain;
  108. } elseif ($name) {
  109. $service_details['domain'] = $name;
  110. } elseif ($domain) {
  111. $service_details['domain'] = $domain;
  112. } else {
  113. $service_details['domain'] = 'ID:' . $serviceId->id;
  114. }
  115. }
  116. }
  117. // price
  118. if($productBillingcycle != 'Free Account') {
  119. $packageId = Capsule::table('tblhosting')
  120. ->where('id', $serviceId->id)
  121. ->value('packageid');
  122. $prorata = Capsule::table('tblproducts')
  123. ->where('id', $packageId)
  124. ->value('proratabilling');
  125. if($prorata == 1) {
  126. $service_details['prorata'] = $prorata;
  127. }
  128. $product_setup = Capsule::table('tblpricing')
  129. ->where('relid', $packageId)
  130. ->where('type', 'product')
  131. ->where('currency', $currencyId)
  132. ->value($setup[$productBillingcycle]);
  133. $product_recurring = Capsule::table('tblpricing')
  134. ->where('relid', $packageId)
  135. ->where('type', 'product')
  136. ->where('currency', $currencyId)
  137. ->value($recurring[$productBillingcycle]);
  138. if($product_setup > 0) {
  139. $service_details['setup'] = $product_setup;
  140. }
  141. if($product_recurring > 0) {
  142. $service_details['recurring'] = $product_recurring;
  143. }
  144. }
  145. $service_details['billingcycle'] = $billingterm[$productBillingcycle];
  146. // configoptions
  147. $service_details['configoptions'] = array();
  148. foreach($service[$serviceId->id]['products']['product'][0]['configoptions']['configoption'] as $configoption) {
  149. unset($option_details);
  150. if($configoption['value'] != '' && $configoption['value'] != 0) {
  151. $option_details['id'] = $configoption['id'];
  152. $option_details['name'] = $configoption['option'];
  153. $option_details['qty'] = $configoption['value'];
  154. if($productBillingcycle != 'Free Account') {
  155. $configoptionId = Capsule::table('tblhostingconfigoptions')
  156. ->where('configid', $configoption['id'])
  157. ->value('optionid');
  158. $option_setup = Capsule::table('tblpricing')
  159. ->where('type', 'configoptions')
  160. ->where('currency', $currencyId)
  161. ->where('relid', $configoptionId)
  162. ->value($setup[$productBillingcycle]);
  163. $option_recurring = Capsule::table('tblpricing')
  164. ->where('type', 'configoptions')
  165. ->where('currency', $currencyId)
  166. ->where('relid', $configoptionId)
  167. ->value($recurring[$productBillingcycle]);
  168. if($option_setup > 0) {
  169. $option_details['setup'] = $option_setup;
  170. }
  171. if ($option_recurring > 0) {
  172. $option_details['recurring'] = $option_recurring;
  173. }
  174. }
  175. array_push($service_details['configoptions'], $option_details);
  176. }
  177. }
  178. // addons
  179. $addon[$serviceId->id] = localAPI('GetClientsAddons', array('serviceid' => $serviceId->id));
  180. $service_details['addons'] = array();
  181. if($addon[$serviceId->id]['totalresults'] != 0) {
  182. foreach($addon[$serviceId->id]['addons']['addon'] as $addon) {
  183. unset($service_addon_details);
  184. $addon_details = (array) Capsule::table('tblhostingaddons')->where('id', $addon['id'])->first();
  185. $addonBillingcycle = $addon_details['billingcycle'];
  186. $service_addon_details['id'] = $addon['id'];
  187. $service_addon_details['name'] = $addon['name'];
  188. $service_addon_details['qty'] = $addon_details['qty'];
  189. if($addonBillingcycle != 'Free Account') {
  190. $addon_setup = Capsule::table('tblpricing')
  191. ->where('relid', $addon_details['addonid'])
  192. ->where('type', 'addon')
  193. ->where('currency', $currencyId)
  194. ->value($setup[$addonBillingcycle]);
  195. $addon_recurring = Capsule::table('tblpricing')
  196. ->where('relid', $addon_details['addonid'])
  197. ->where('type', 'addon')
  198. ->where('currency', $currencyId)
  199. ->value($recurring[$addonBillingcycle]);
  200. if($addon_setup > 0) {
  201. $service_addon_details['setup'] = $addon_setup;
  202. }
  203. if($addon_recurring > 0) {
  204. $service_addon_details['recurring'] = $addon_recurring;
  205. }
  206. }
  207. $service_addon_details['billingcycle'] = $billingterm[$addonBillingcycle];
  208. array_push($service_details['addons'], $service_addon_details);
  209. }
  210. }
  211. array_push($order_details['products'], $service_details);
  212. }
  213. // gathering informations of addons bought without buying a product
  214. $addons = Capsule::table('tblhostingaddons')
  215. ->where('orderid', $orderid)
  216. ->whereNotIn('hostingid', $serviceIds)
  217. ->get();
  218. $order_details['addons'] = array();
  219. foreach($addons as $addon) {
  220. unset($addon_details);
  221. $addon_details['name'] = Capsule::table('tbladdons')
  222. ->where('id', $addon->addonid)
  223. ->value('name');
  224. $addonBillingcycle = $addon->billingcycle;
  225. $addon_details['id'] = $addon->id;
  226. $addon_details['qty'] = $addon->qty;
  227. if($addonBillingcycle != 'Free Account') {
  228. $addon_setup = Capsule::table('tblpricing')
  229. ->where('relid', $addon->addonid)
  230. ->where('type', 'addon')
  231. ->where('currency', $currencyId)
  232. ->value($setup[$addonBillingcycle]);
  233. $addon_recurring = Capsule::table('tblpricing')
  234. ->where('relid', $addon->addonid)
  235. ->where('type', 'addon')
  236. ->where('currency', $currencyId)
  237. ->value($recurring[$addonBillingcycle]);
  238. if($addon_setup > 0) {
  239. $addon_details['setup'] = $addon_setup;
  240. }
  241. if($addon_recurring > 0) {
  242. $addon_details['recurring'] = $addon_recurring;
  243. }
  244. if(!empty($addon->subscriptionid)) {
  245. $addon_details['servicecode'] = $addon->subscriptionid;
  246. }
  247. }
  248. $addon_parent = localAPI('GetClientsProducts', array('serviceid' => $addon->hostingid));
  249. $addon_details['parent'] = array(
  250. 'name' => $addon_parent['products']['product'][0]['translated_name'],
  251. 'domain' => $addon_parent['products']['product'][0]['domain']
  252. );
  253. array_push($order_details['addons'], $addon_details);
  254. }
  255. // gathering informations of domains
  256. $domains = Capsule::table('tbldomains')
  257. ->where('orderid', $orderid)
  258. ->get();
  259. $order_details['domains'] = array();
  260. foreach($domains as $domain) {
  261. unset($domain_details);
  262. $domain_details['id'] = $domain->id;
  263. $domain_details['name'] = $domain->domain;
  264. $domain_details['type'] = $domain->type;
  265. $domain_details['period'] = $billingterm[(string)$domain->registrationperiod];
  266. $tld = end(explode(".", $domain->domain));
  267. $tldPricing = localAPI('GetTLDPricing', array('currencyid' => $currencyId));
  268. $domain_details['recurring'] = $tldPricing['pricing'][$tld][strtolower($domain->type)][$domain->registrationperiod];
  269. if($domain->dnsmanagement > 0){
  270. if(!empty($tldPricing['pricing'][$tld]['addons']['dns'])) {
  271. $domain_details['addons']['dnsmanagement'] = $tldPricing['pricing'][$tld]['addons']['dns'];
  272. } else {
  273. $domain_details['addons']['dnsmanagement'] = $billingterm['Free Account'];
  274. }
  275. }
  276. if($domain->emailforwarding > 0){
  277. if($tldPricing['pricing'][$tld]['addons']['dns'] > 0) {
  278. $domain_details['addons']['emailforwarding'] = $tldPricing['pricing'][$tld]['addons']['email'];
  279. } else {
  280. $domain_details['addons']['emailforwarding'] = $billingterm['Free Account'];
  281. }
  282. }
  283. if($domain->idprotection > 0){
  284. if($tldPricing['pricing'][$tld]['addons']['idprotect'] > 0) {
  285. $domain_details['addons']['idprotection'] = $tldPricing['pricing'][$tld]['addons']['idprotect'];
  286. } else {
  287. $domain_details['addons']['idprotection'] = $billingterm['Free Account'];
  288. }
  289. }
  290. array_push($order_details['domains'], $domain_details);
  291. }
  292. // response all together
  293. $apiresults['orderdetails'] = $order_details;
  294. $responsetype = "xml";