How can I show an Account's total lifetime purchase value?

How can I show an Account's total lifetime purchase value?

Hello, 

I know I am missing something. I want to visualize how much each account has paid us over the time they have been customers (lifetime value). This must have been done before but I can't find a community thread on it.

We do not bill with Zoho Finance/Books, we use Square. So I will have to import transactions or use a Flow to add each transaction as a paid invoice. I think I can do that, but how can I access that information in the Accounts Module?

I had planned to write a Flow to trigger a custom function any time a transaction is posted, using the customer ID number.

I put dummy invoices in Books to test, but I can't get the info to return from the custom function. I've scripted with deluge in Creator, but not using APIs, and I don't understand the API syntax. This what I have:

  1. float Return_Customer_Lifetime_Value(int Ident)
  2. {
  3. //Ident is the customer ID

  4. transactions = zoho.books.getRecords("customerpayment", <some OrgID number> , Ident, "zoho_books_connection");
  5. total = 0;
  6. for each  rec in transactions
  7. {
  8. total = total + "amount";  //how do I refer to the amount properly using an API?
  9. }
  10. return total;
  11. }