| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- <?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'];
- // mappings for WHMCS inconsistency
- $setup = array(
- 'One Time' => 'msetupfee',
- 'Monthly' => 'msetupfee',
- 'Quarterly' => 'qsetupfee',
- 'Semi-Annually' => 'ssetupfee',
- 'Annually' => 'asetupfee',
- 'Biennially' => 'bsetupfee',
- 'Triennially' => 'tsetupfee',
- 'onetime' => 'msetupfee',
- 'monthly' => 'msetupfee',
- 'quarterly' => 'qsetupfee',
- 'semiannually' => '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',
- 'onetime' => 'monthly',
- 'monthly' => 'monthly',
- 'quarterly' => 'quarterly',
- 'semiannually' => 'semiannually',
- 'annually' => 'annually',
- 'biennially' => 'biennially',
- 'triennially' => 'triennially',
- );
- $billingterm = array(
- 'Free Account' => Lang::trans('orderpaymenttermfree'),
- 'One Time' => Lang::trans('orderpaymenttermonetime'),
- 'Monthly' => Lang::trans('orderpaymenttermmonthly'),
- 'Quarterly' => Lang::trans('orderpaymenttermquarterly'),
- 'Semi-Annually' => Lang::trans('orderpaymenttermsemiannually'),
- 'Annually' => Lang::trans('orderpaymenttermannually'),
- 'Biennially' => Lang::trans('orderpaymenttermbiennially'),
- 'Triennially' => Lang::trans('orderpaymenttermtriennially'),
- 'onetime' => Lang::trans('orderpaymenttermonetime'),
- 'monthly' => Lang::trans('orderpaymenttermmonthly'),
- 'quarterly' => Lang::trans('orderpaymenttermquarterly'),
- 'semiannually' => Lang::trans('orderpaymenttermsemiannually'),
- 'annually' => Lang::trans('orderpaymenttermannually'),
- 'biennially' => Lang::trans('orderpaymenttermbiennially'),
- 'triennially' => Lang::trans('orderpaymenttermtriennially'),
- '1' => Lang::trans('orderpaymenttermannually'),
- '2' => Lang::trans('orderpaymenttermbiennially'),
- '3' => Lang::trans('orderpaymenttermtriennially'),
- );
- // gathering globals
- $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');
- // gathering informations of products
- $order_details['products'] = array();
- $serviceIdsArray = array();
- foreach($serviceIds as $serviceId) {
- array_push($serviceIdsArray, $serviceId->id);
- 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 alternative 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 Domain':
- case 'Mail Domaine':
- $domain = $customfield['value'];
- break;
- }
- if ($name && $domain) {
- $service_details['domain'] = $name . '@' . $domain;
- } elseif ($name) {
- $service_details['domain'] = $name;
- } elseif ($domain) {
- $service_details['domain'] = $domain;
- } else {
- $service_details['domain'] = '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('configid', $configoption['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);
- }
- }
- // addons
- $addon[$serviceId->id] = localAPI('GetClientsAddons', array('serviceid' => $serviceId->id));
- $service_details['addons'] = array();
- if($addon[$serviceId->id]['totalresults'] != 0) {
- 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);
- }
- // gathering informations of addons bought without buying a product
- $addons = Capsule::table('tblhostingaddons')
- ->where('orderid', $orderid)
- ->whereNotIn('hostingid', $serviceIdsArray)
- ->get();
- $order_details['addons'] = array();
- foreach($addons as $addon) {
- unset($addon_details);
- $addon_details['name'] = Capsule::table('tbladdons')
- ->where('id', $addon->addonid)
- ->value('name');
- $addonBillingcycle = $addon->billingcycle;
- $addon_details['id'] = $addon->id;
- $addon_details['qty'] = $addon->qty;
- if($addonBillingcycle != 'Free Account') {
- $addon_setup = Capsule::table('tblpricing')
- ->where('relid', $addon->addonid)
- ->where('type', 'addon')
- ->where('currency', $currencyId)
- ->value($setup[$addonBillingcycle]);
- $addon_recurring = Capsule::table('tblpricing')
- ->where('relid', $addon->addonid)
- ->where('type', 'addon')
- ->where('currency', $currencyId)
- ->value($recurring[$addonBillingcycle]);
- if($addon_setup > 0) {
- $addon_details['setup'] = $addon_setup;
- }
- if($addon_recurring > 0) {
- $addon_details['recurring'] = $addon_recurring;
- }
- if(!empty($addon->subscriptionid)) {
- $addon_details['servicecode'] = $addon->subscriptionid;
- }
- }
- $addon_parent = localAPI('GetClientsProducts', array('serviceid' => $addon->hostingid));
- $addon_details['parent'] = array(
- 'name' => $addon_parent['products']['product'][0]['translated_name'],
- 'domain' => $addon_parent['products']['product'][0]['domain']
- );
- $addon_details['billingcycle'] = $billingterm[$addonBillingcycle];
- array_push($order_details['addons'], $addon_details);
- }
- // gathering informations of domains
- $domains = Capsule::table('tbldomains')
- ->where('orderid', $orderid)
- ->get();
- $order_details['domains'] = array();
- foreach($domains as $domain) {
- unset($domain_details);
- $domain_details['id'] = $domain->id;
- $domain_details['name'] = $domain->domain;
- $domain_details['type'] = $domain->type;
- if(!empty($domain->registrar)) {
- $domain_details['registrar'] = $domain->registrar;
- }
- $domain_details['period'] = $billingterm[(string)$domain->registrationperiod];
- $tld = end(explode(".", $domain->domain));
- $tldPricing = localAPI('GetTLDPricing', array('currencyid' => $currencyId));
- $domain_details['recurring'] = $tldPricing['pricing'][$tld][strtolower($domain->type)][$domain->registrationperiod];
- if($domain->dnsmanagement > 0){
- if(!empty($tldPricing['pricing'][$tld]['addons']['dns'])) {
- $domain_details['addons']['dnsmanagement'] = $tldPricing['pricing'][$tld]['addons']['dns'];
- } else {
- $domain_details['addons']['dnsmanagement'] = $billingterm['Free Account'];
- }
- }
- if($domain->emailforwarding > 0){
- if($tldPricing['pricing'][$tld]['addons']['dns'] > 0) {
- $domain_details['addons']['emailforwarding'] = $tldPricing['pricing'][$tld]['addons']['email'];
- } else {
- $domain_details['addons']['emailforwarding'] = $billingterm['Free Account'];
- }
- }
- if($domain->idprotection > 0){
- if($tldPricing['pricing'][$tld]['addons']['idprotect'] > 0) {
- $domain_details['addons']['idprotection'] = $tldPricing['pricing'][$tld]['addons']['idprotect'];
- } else {
- $domain_details['addons']['idprotection'] = $billingterm['Free Account'];
- }
- }
- array_push($order_details['domains'], $domain_details);
- }
- // response all together
- $apiresults['orderdetails'] = $order_details;
- $responsetype = "xml";
|