Service - User Account Balance: Difference between revisions

From Izara Wiki
Jump to navigation Jump to search
(Created page with "= Overview = Manages a users balance owed to the project. = Repository = https://bitbucket.org/izara-core-user-accounts/izara-core-user-accounts-user-account-balance = DynamoDB tables = == Standard Config Table Per Service == === Configuration tags === <syntaxhighlight lang="JavaScript"> { configKey: "..." configTag: "..." configValue: xxx // eg: "..." } </syntaxhighlight> = Working documents = :Category:Working_documents - User Account Balance|User...")
 
No edit summary
 
Line 21: Line 21:
</syntaxhighlight>
</syntaxhighlight>


== UserBalance ==


<syntaxhighlight lang="JavaScript">
{
userId: xxx
balance: xxx
currencyId: ###
}
</syntaxhighlight>


* partition key: userId
* sort key: (none)
* record is created when user is first made, but if it does not for some reason we could perhaps make the record with a default currency (eg USD)
== Transaction ==
* Want to be able to filter by time
<syntaxhighlight lang="JavaScript">
{
userId: xxx
timeTransactionId: xxx
amount: xxx
transactionTag: xxx
currencyId: ###
originalCurrencyId: ###
originalAmount: xxx
conversionRate: xxx
}
</syntaxhighlight>
* partition key: userId
* sort key: timeTransactionId
* timeTransactionId: {timestamp}_{random uuid for transactionId} add uuid to ensure each sortKey is unique
* transactionTag: standardized tag set be external service to identify the type of transaction
* currencyId: record the converted to currency (will match UserBalance currency unless we allow to change currency in future)
* originalCurrencyId: of the transaction amount from external service
* originalAmount: from external service before conversion to user's currency
* conversionRate: record the rate used to perform conversion
= Currency =
Each user sets the currency they want their account balance to be recorded in, when a transaction is received it notes which currency the amount was calculated in and this service converts it to the user's currency using our systems mid-market exchange rates.
= Running balance =
When a transaction is received, converted, and saved we update the user's balance. Be careful of race conditions and perhaps code a flow that recalculates the balance from all transactions, similar to account limits.
= When user goes negative =
Perhaps trigger adding roles to the user that restrict their limits/access to actions.


= Working documents =
= Working documents =

Latest revision as of 04:37, 20 January 2023

Overview

Manages a users balance owed to the project.

Repository

https://bitbucket.org/izara-core-user-accounts/izara-core-user-accounts-user-account-balance

DynamoDB tables

Standard Config Table Per Service

Configuration tags

{
	configKey: "..."
	configTag: "..."
	configValue: xxx // eg: "..."
}

UserBalance

{
	userId: xxx
	balance: xxx
	currencyId: ###
}
  • partition key: userId
  • sort key: (none)
  • record is created when user is first made, but if it does not for some reason we could perhaps make the record with a default currency (eg USD)

Transaction

  • Want to be able to filter by time
{
	userId: xxx
	timeTransactionId: xxx
	amount: xxx
	transactionTag: xxx
	currencyId: ###
	originalCurrencyId: ###
	originalAmount: xxx
	conversionRate: xxx
}
  • partition key: userId
  • sort key: timeTransactionId
  • timeTransactionId: {timestamp}_{random uuid for transactionId} add uuid to ensure each sortKey is unique
  • transactionTag: standardized tag set be external service to identify the type of transaction
  • currencyId: record the converted to currency (will match UserBalance currency unless we allow to change currency in future)
  • originalCurrencyId: of the transaction amount from external service
  • originalAmount: from external service before conversion to user's currency
  • conversionRate: record the rate used to perform conversion

Currency

Each user sets the currency they want their account balance to be recorded in, when a transaction is received it notes which currency the amount was calculated in and this service converts it to the user's currency using our systems mid-market exchange rates.

Running balance

When a transaction is received, converted, and saved we update the user's balance. Be careful of race conditions and perhaps code a flow that recalculates the balance from all transactions, similar to account limits.

When user goes negative

Perhaps trigger adding roles to the user that restrict their limits/access to actions.

Working documents

User Account Balance