I am looking at your database model trying to understand the transaction relationship.
From your database it seems that:
- An invoice can have multiple payments.
- An invoice can have multiple transactions.
- A (finalised or captured) Payment can either be "completed" or have "Failed capture"
- A (finalised) transaction can be "Paid" (complted successfully) or have failed.
It seems to me that the transaction would be better related to the payment (as they are directly related). After all you can't have a transaction without a payment. If there was a many-to-1 relationship between payment and the transaction would that not enable a single transaction to pay off multiple invoices. What are the community thoughts on this.