I’m writing a stripe integration to pay for an Order. The order structure has multiple parts each of which can be a different customer party and vendor party. Each order part can essentially be split into an arbitrary amount of configurations.
How do you use multiple order parts, (if you use the same customer party on them) so that I can understand how to handle this integration. Maybe the community can come to a point where there is a fairly standard way to handle order parts.
I’m thinking that maybe instead of paying for an order, the integration will just take in a payment and pay for that. That payment would be attached to an order part of the the order items would be listed. Then if a customer has multiple parts in an order, they would have to go through the stripe checkout multiple times. This may be required if the order parts need different times to be paid. Like say one order part is a small ecommerce order to a company that needs to be handled immediately, but the other order part is for the same company but regularly orders large amounts and the payment should be paid later.
Moqui has payment and billingItem. BillingItem connects to orderItem. Payment has a field orderId.
Stripe has paymentIntent to represent a paying action.
I never figured out how payment can be easily correctly connect to a orderitem/orderpart
I think the first thing is to find a standard/general way to effectively find the unpaid items for a order. or/and find all orderitems with its payment information. And find a payment is for what orderitems.
What i come up with is loop through payment → billing-> order. But this seems too complex and resource consuming .
I would try to keep it as simple as possible. What you pay are not Orders nor OrderParts but rather Invoices (through PaymentApplication). So if there is some uncommon way to pay for orders, let that logic be encapsulated in the generation of these invoices. Once you need to receive a payment, you will have the invoices ready and don’t need to worry about how this relates to the Orders or whether you are considering any future requirements.
The invoice specifies who is paying and who is receiving the payment, so one restriction when applying a payment is that both, payer and receiver, do match. This is enforced in mantle, see for example the PaymentServices.apply#InvoicePayment service.
The payment can be applied to one or more invoices, which can be paid partially or fully. So what you really need to determine is how to define the payment amount (the parties are already fixed):
Will you allow payments for less than the total of the invoice? This would make sense if there are limits at the payment method level, if the customer really is a group of people where each one would pay for a part (however they decide to do it) and maybe some other reasons.
Will you allow payments for more than one invoice, and in this case, require payment of the exact amount or have some strategy to apply the paid amount to the invoices and what to do with any excess payment.