I am designing an e-commerce website that has the following scenario:
- A customer can purchase items and create an order.
- The order may have unknown fee that will be added after the customer pays the total amount of the items. That is, the customer pays certain amount first. The order adds some fee and changes the total. And the customer pays again for the difference. But the two (or more) payments are associated with the same order.
- (Optional) The customer can submit a single payment for multiple orders.
Currently, I have an Order
table and each order may consist of multiple OrderLineItem
s (simplified schema):
Order
=====
customer
line_items
total
status
OrderLineItem
=============
price
quantity
order
product
A payment is associated with an order (simplified schema):
Payment
=======
order
payment_account
total
result
It seems to be very hard to support the multiple payments for a single order scenario in the current implementation. I reckon that I have to introduce immutable invoices in the system, and the payment should be associated with an invoice instead of an order. However, I would need some help with the order/invoice/payment modeling for the above scenario. Some specific questions I have:
- An order and an invoice look very similar to me (e.g. both have items and totals). What is the major difference in typical e-commerce systems?
- How should I model invoices for my scenario? Should I have
OrderLineItem
s for anOrder
ANDInvoiceLineItem
s for anInvoice
? - Some preliminary thoughts: I will have multiple invoices associated with a certain order. Whenever the order changes the total, I have to somehow calculate the difference and send a new/immutable invoice to the customer. Then, the customer can pay and the payment will be associated with the invoice.
Would love to hear some advice. Much appreciated. Thanks!