workarea-commerce / workarea

Workarea is an enterprise-grade Ruby on Rails commerce platform
https://www.workarea.com
Other
326 stars 66 forks source link

Return Status of `Checkout#update` #481

Closed tubbo closed 4 years ago

tubbo commented 4 years ago

For APIs and other consumers of the Checkout model, return a boolean response from the #update method to signify whether the operation succeeded or failed. This response is used directly in the API to return an :unprocessable_entity response code when an update operation fails.

tubbo commented 4 years ago

this build may not ever end :D

tubbo commented 4 years ago

@mttdffy Yeah, that seems to be the issue I'm running into now. When you're mid-checkout, obviously not all steps are going to be #complete?, so it always fails even though all of the steps you've encountered are complete. I'm thinking next true if step.update(params).nil? would fix that. In other words, we still need to check whether #update just returned out early vs tried to update and failed.

This might be too big for a patch release, but we should definitely consider refactoring how this works someday. If there was a central #errors object on Workarea::Checkout that mimicked an ActiveModel::Errors, we could just check errors.any? at the end of this method.

edit: apparently, I was wrong about my assumption :( https://github.com/workarea-commerce/workarea/blob/master/core/app/models/workarea/checkout/steps/payment.rb#L19