-1

I design a system that users can has multiple payments. Let me explain about it.

There is a user table. Each user has a total credit amount. Ex. user Alex has $100. He can either increase his credit, or pay it for some services. We have 2 services, that he can pay for.

Beside increasing his credit, he can pay for those services directly. How does my table structures should be designed? Any idea?

1

Based on the requirement, I suggest to have following 3 tables.

1) User table holding user details along with Current Credit Amount. 2) Service Table holding the details of Services. 3) UserPayment table with details of the payments to services. It will have FKs to User table and Service table.

Whenever User increases his credit Amount, you can update the Total Credit Amount. (Do you have requirement to track the transactions of increasig credit? if yes, you may need a table to track the same.) Whenever User Pays for Services, Records will be inserted in the UserPayment Table.

  • I'd would actually suggest that you explicitly track whenever the user adds money to the system (either increasing credit, or a "pass-thru" payment that doesn't change his credit amount), and whenever the user removed money from the system (paying for services, and (if appropriate) receiving refunds or closing out an account). At some point, you'll need to be able to account for everything the customer did, and this would allow you to do so. – RDFozz Feb 23 '17 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.