codym Posted June 14, 2020 Author Report Posted June 14, 2020 On 6/11/2020 at 5:36 PM, Jono said: try ServiceChanges::getItems(). I know it's deprecated but I believe it will get the results you want in a way that can be sent to node. Expand I see why ServiceChanges::getItems() endpoint was deprecated... it sucks. I can't really use it at all to calculate the prorated charges for a service change and create an invoice unless I write a bunch of regex to match descriptions for each possible configurable option. I'm not sure why this endpoint doesn't return actual line items with corresponding config options, must have been in use to have service changes in a pretty format for Blesta invoices huh?
Jono Posted June 15, 2020 Report Posted June 15, 2020 The other option here is to make a custom edit to your Blesta installation. Something like ServiceChanges::getLineItems() that makes the line items, similar to the controller method AdminClients::makeLineItems()? This seems to be a total pain so I'm thinking about how we can make this work better for API user in the future.
codym Posted June 15, 2020 Author Report Posted June 15, 2020 I don't see a custom edit to the Blesta installation happening. Too much of a headache... especially when we upgrade in the future. On 6/15/2020 at 3:26 PM, Jono said: This seems to be a total pain so I'm thinking about how we can make this work better for API user in the future. Expand You're totally right. The easiest way on dev side would be to fix the encoding on ServiceChanges::getPresenter(), since that should return everything needed so that I can manually create an invoice for a service upgrade/downgrade. The easiest thing for the customer (me) would be for Services::edit() to automatically create a prorated invoice for the change. However, you said previously that is a purposeful design consideration. Possibly for admin functions? I'm not sure. If that's the case, then having an endpoint we can hit that returns the prorated differences according to line item (in JSON encoding) would be the most helpful. In that case, I could easily create a manual invoice from that using the Invoices::add() endpoint. However, (as I haven't gotten this far in testing yet) I'm not sure if the subsequent recurring invoice (1 month after the edit) would include the service update (assuming the Services::edit() function is used to change the service). Again, that would all require testing and I'm not quite as experienced with this system as you.
coreyman Posted August 10, 2020 Report Posted August 10, 2020 On 6/15/2020 at 3:26 PM, Jono said: The other option here is to make a custom edit to your Blesta installation. Something like ServiceChanges::getLineItems() that makes the line items, similar to the controller method AdminClients::makeLineItems()? This seems to be a total pain so I'm thinking about how we can make this work better for API user in the future. Expand Have there been any changes to this in the latest version of Blesta?
Jono Posted August 11, 2020 Report Posted August 11, 2020 Unfortunately not. Our current priority is on the affiliate system (released in 4.11) and the domain manager (TBD) so some of the dev stuff is taking a bit of a back seat for now though I'd like to make a lot of dev improvements soon.
Arda ALTAY Posted December 21, 2024 Report Posted December 21, 2024 The getPresenter method in the service_changes module always returns an empty JSON. This is because the object “Blesta\Core\Pricing\Presenter\Type\ServiceChangePresenter” is returned and this object cannot be JSON serialized But if I use the php extension instead, I can get a result Since I was trying to get data from a laravel application, I parsed it with the code below as a temporary and quick solution. As I said before, if anyone has a better solution or refactor the code below better and share it, I would appreciate it. Maybe I can do a module and api. But for the moment I needed a quick solution. Maybe someone who made and used it might want to share it. class UnserializeHandler { public static function unserializeData($serializedData) { $pattern = '/O:\d+:"[^"]+"/'; // Tüm sınıf referanslarını stdClass'a çevir $convertedData = preg_replace($pattern, 'O:8:"stdClass"', $serializedData); return unserialize($convertedData); } } private function getPresenterLocal(){ $result = []; $result['kdvOran'] = 0; $result['kdvDescription'] = ''; $result['price'] = 0; $result['qty'] = 0; $result['description'] = ''; $result['total'] = 0; $result['totalWithTax'] = 0; $result['error'] = ''; $result['sonuc'] = true; try { $response = Http::withBasicAuth('username', 'password') ->withoutVerifying() // SSL sertifika doğrulamasını devre dışı bırakır ->get('https://blesta.test/api/service_changes/getpresenter.php', [ 'service_id' => 51, 'vars' => [ 'pricing_id' => 16, 'qty' => 1 ] ]); // Serialize edilmiş veriyi al $serializedData = $response->body(); // Özel handler ile unserialize yap $data = UnserializeHandler::unserializeData(serializedData: $serializedData); $collectionArray = (array)$data['response']; if(array_key_exists('0',$collectionArray) && $collectionArray[0] == false){ $result['sonuc'] = false; dd($result); //return $result; } $reflection = new \ReflectionObject($data['response']); $key = $reflection->getProperties()[0]; $responseData = $collectionArray[$key->name]; $reflection = new \ReflectionObject($responseData); $key = $reflection->getProperties()[0]; $metaItem = ((array)$responseData)[$key->name]; $priceItem = $metaItem[0]; foreach((array)$priceItem as $key => $value){ if(is_array($value) && str_contains($key, 'taxes')){ foreach($value as $k => $v){ if(is_array($v)){ $taxArray = (array)$v[0]; foreach($taxArray as $kk => $vv){ if(str_contains($kk, 'amount')){ $result['kdvOran'] = $vv; } if(str_contains($kk, 'description')){ $result['kdvDescription'] = $vv; } } } } } else{ if(gettype($key) == 'string' && str_contains($key, 'price')){ $result['price'] = $value; } if(gettype($key) == 'string' && str_contains($key, 'qty')){ $result['qty'] = $value; } if(gettype($key) == 'string' && str_contains($key, 'description')){ $result['description'] = $value; } } } if($result['price'] > 0 && $result['qty'] > 0){ $result['total'] = $result['price'] * $result['qty']; $result['totalWithTax'] = $result['total'] + ($result['total'] * $result['kdvOran'] / 100); } } catch (\Throwable $th) { //throw $th; $result['error'] = $th->getMessage(); } dd($result); }
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now