A
A
Alexander Evgenievich2015-10-22 16:48:19
MySQL
Alexander Evgenievich, 2015-10-22 16:48:19

How to design table(s) for monetary transactions in MySQL?

Hello.
Transactions in the project are necessary. Transactions will be:

  • crediting to the user's account from an external source;
  • crediting from internal sources (bonuses, points, etc.);
  • crediting and debiting, in general - transfers of funds between users' accounts;
  • withdrawal of funds to an external account.

The question is, is one table enough? So far, the following fields come to mind:
id
sender_id (NULL or user-id)
recepient_id (NULL or user-id)
value (transfer value)
created_at
update_at
salt (for external transfers)
active (for external transfers, you need to confirm, for internal transfers, already confirmed )
type (type INTERNAL_TRANSACTION or FOREIGN_TRANSACTION )
--
If sender_id or recepient_id are NULL , then the transfer is considered external (or crediting bonuses), if not empty, then internal.
There was an idea to split into two tables, one: for storing real transactions; another: for conducting internal transactions (as well as accounting for the crediting of funds from outside and debiting funds from outside), but then two identical tables are obtained.
--
Also, of course, you need a field to designate an external system that works with the payment, such as "PAYPAL", "WEBMONEY", "CARD", "YANDEXMONEY", etc.
-
Need advice on proper organization.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2015-10-22
@banderos120

for real money, there should be a separate table, synchronize it with the stats of payment systems,
look for discrepancies over time))
the same for the conclusions - either to this first one, or to another one
in the rest - it’s normal, just replicate / archive more often

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question