I'm building the order endpoint for an ecommerce rest api so that clients can place orders. I'm trying to determine the advantages or disadvantages of two approaches:
Approach 1
Payload:
{
'total',
'customer': {'firstName', etc.},
'shipping_address':{'address1', etc.}
'items': [{'nameOfItem', 'sku', 'price', etc.}, ...]
'payment': {'type', 'credit_card':{'number', 'expiration_date', etc.}}
}
Pro:
- Let users pass the payment in the payload. I think this is a simple approach; clients and also the api don't have to synchronize orders and payments. With one POST request, the authorization and capture will be executed for the order.
Con:
- I think it is less flexible. If I want to support different payment types in the future like saved payments, paypal, etc., I might have to make changes that might affect the payload and make it more complex. Also, I think it couples my order placement flow with the transaction operations - authorization and capture.
Approach 2
Take out the payment information from the order POST request payload and have a different endpoint to handle the transaction operations for a given order.
order/<ordernumber>/transaction/capture
{
'payment': {'type', 'credit_card':{'number', 'expiration_date', etc.}}
}
Pro:
- Decouples operation to create an order from the transaction operations. I'm not sure if flexibility is even needed for this though.
- It seems like it is a pattern used by most ecommerce apis - shopify, woo, magneto - to decouple the payment from the orders, carts, etc. so developers that will use this api will most likely be familiar with this pattern.
Con:
- Not as simple. We need to synchronize two operations: creating orders and paying for them.
I don't have good reasons for going with approach 2 and the software that our organization owns follow the pattern in approach 1. Therefore, I am hoping that someone here can provide guidance or information for me to consider. Thanks.