Jump to content

How To Get Total Credit Of A Client Via Api?


mauriez

Recommended Posts

No, I don't think there is a getTotal method or the like yet.

I'm not sure how the admin panel is contructed, but it may very well use queries which are unavailable through the API.

If you post the response data you get from getList() here I can probably whip up a bit of PHP to calculate the total for you.

Just guessing here, but something like this psuedo-code should work:

$total=0;
foreach(json_decode($getListResponse) as $transaction) {
  $total+=$transaction['amount'];
}
echo $total; // outputs the total amount transacted
Link to comment
Share on other sites

Ah!

 

You triggered me looking it up in the PHP source code.. and I found it!

 

http://source-docs.blesta.com/class-Transactions.html#_getTotalCredit

 

Nice ;) 

 

thanks!

I had saw this, but I'm afraid it more likely pulls any positive balance sitting in the customers account, not the total of all their transactions. I could be wrong though, the wording is vague.

Link to comment
Share on other sites

yes, the api directly calls the models, so you can use the model directly http://docs.blesta.com/display/dev/API#API-WithintheBlestaenvironment

 

// from somewhere in your controller...
$this->uses(array("Transactions"));
 
// Now invoke it
$this->Transactions->getTotalCredit(1, "USD");

 

That just throws up this error:

 

Call to undefined method View::uses() on line 73 in/home/evaske/public_html/Clients/app/views/client/default/structure.pdt

 

I had to use Loader::loadModels($this, array("Transactions")); instead :)

Link to comment
Share on other sites

That just throws up this error:

 

Call to undefined method View::uses() on line 73 in/home/evaske/public_html/Clients/app/views/client/default/structure.pdt

 

I had to use Loader::loadModels($this, array("Transactions")); instead :)

 

 

Yes, $this->uses() is available to controllers, which is where models should be loaded--not from views. While you can get away with it by calling the Loader directly, doing so partially negates the logical separation of business logic and presentation in the MVC design pattern. Generally speaking, when your solution goes against the design pattern you're working within, it's a good idea to rethink your approach.

 

I'm not sure why you opted to not use the API, but core files are included in our patches and updates, which will overwrite your custom changes if you are not keeping record of them and merging file content accordingly.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...