Right now if a booking is canceled, it is unclear if the payment was made or not.
We used to store "charge" -> although I see it says "old api" in the comments now.
Let's change to have a new "charges" array which contains a list of charges with: {status: "paid", amount: xx, method: "stripe", meta: "stripe.data"}
When I pay a booking, it would mean adding an item to the array {status: "paid"}. If I cancel, I add an item {status: "refunded"} (this should be triggered in stripe directly). When I spend carrots it should add an item {status: "paid", amount: 2, method: "credits"}. If I use tokens to book it should be added {status: "staked", amount: 2, method: "token"}.
In the UI for the booking, we should show a list of charges relating to that booking.
Add a webhook for charges/refunds. If I refund on Stripe, I want the refund to be added to the charges - i.e. The webhook should be able to match based on a stripe transactionID or similar - so we need to make the bookings indexed with that - (not sure if mongo supports doing something like bookings.find({charges.any.txId: ID}). Or maybe there's a way to store a booking reference to Stripe so we can match it back.
if booking.total != sumarray(charges) it means there's a missing payment of refund to be processed. The booking status should be "pending-payment" or "pending-refund".
When I cancel a booking, it should set the status to "pending-refund". Once refund is processed (should happen automatically via stripe ideally), then the refund charge is added, and status goes to "cancelled".
When I update a booking (either admin or guest), the status should go to "pending-payment" until the difference between booking.total & sumarray(charges) is paid (by adding another charge). If the difference is negative, we need to look also consider the cancelation policy. This means we need to store yet another payment variable - let's call it booking.cancelationFees which would be for example 50% of the difference in a booking. So if I booked 2 nights for 100€, then I cancel 1 night, and the policy says to refund 50%, then we would add cancelationFees = 25€, which means that the booking.total should now be 75€, and in the charges it would have: [{amount: 100, status: 'paid'}, {amount: -25, status: 'refunded'}]
One final variable for the price would be to add a booking.accomodationDiscount which would reduce the booking price. This discount could be set manually by a space host (we can eventually add that in the UI), or it can be with a discount code in the checkout.
As a first step, let's start by making charges visible so we can reconcile between payments that have been made etc. Already having the history of payments on the booking would be good. Then we can slowly implement the other steps.
To be discussed:
Should this rather be stored in a separate "charges" model, where you could have multiple charges per booking?
How can we streamline the payment flows for more product types (bookings but also product sales, subscriptions etc), and allow for payments with more methods (i.e. crypto)
@francaye could you please make a small UI of the transaction list appearing on the booking page?
Invoicing & refunds
booking.total & sumarray(charges)
is paid (by adding another charge). If the difference is negative, we need to look also consider the cancelation policy. This means we need to store yet another payment variable - let's call it booking.cancelationFees which would be for example 50% of the difference in a booking. So if I booked 2 nights for 100€, then I cancel 1 night, and the policy says to refund 50%, then we would add cancelationFees = 25€, which means that the booking.total should now be 75€, and in the charges it would have: [{amount: 100, status: 'paid'}, {amount: -25, status: 'refunded'}]As a first step, let's start by making charges visible so we can reconcile between payments that have been made etc. Already having the history of payments on the booking would be good. Then we can slowly implement the other steps.
To be discussed:
@francaye could you please make a small UI of the transaction list appearing on the booking page?