Open andrii-kovalenko-ct opened 7 years ago
As discussed with @butenkor and @ahalberkamp the api should return the next HTTP statuses:
The response mime type is application/json.
The response body is optional JSON and may contain a reason why order is not created.
sound good for me! I
@andrii-kovalenko-ct +1 o last comment. Small correction: or payment is cancelled
- If payment is cancelled than there should be no transaction with state = Success, right? Another valid example would be if ```or total amount of the cart does not match paid amount anymore (for example due to expired applied discount)
if payment is cancelled, than it has last transaction CANCEL
with status aSUCCESS`. Isn't it? Or you mean that i should change transaction cancelled -> payment cancelled?
So, the latest update is:
API call: on successful order creation shop should return http status code 201
API call: status code 200 should be returned if there was an error from which shop can not recover from (expired cart discount, payment amount is less than current cart amount) and order create retry would lead to same error anyway. In this case shop should also log an error so that this case can be easily identified by logs alerting and customer notified (error message should contain all necessary data like: reason, cart id, payment id, payment referenceId (intended orderNumber taken from payment object), payone payment txid)
API call: 400 should be returned if payment to order should retry URL as for example shop run into unexpected state like wrong CTP credentials or wrong encryption key and cart id can not be decrypted ( btw.: payment to order will also retry on any status code unequal 200 or 201 so 5xx errors are covered also but it should only be the case of web app server crash)
API request should create order only if cart state is NOT ordered. In case it is ordered it should reply with status code 200 (as mentioned above)
API implementation payment/cart validation, order creation and email sending should be implemented that way that it can be reused in normal order creation.
in API implementation order can be only created if cart has at least one (might first one) payment which fulfils following criteria:
As discussed with @butenkor now the API is not described well.
https://github.com/commercetools/commercetools-payment-to-order-processor/blob/master/doc/REQUIREMENTS.MD
The basic point is: we should describe all possible cases and specify expected result in the cases, like:
Like an initial proposition: in case we received a request we should always return 200 (OK) response and JSON body with the result - successful or failed.