getorderdetails.php 13 KB

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