Join GitHub today
Fixing locked orders due to invalid card details for a payment #2616
This fixes the locked order issue described in previous issue #1767
A brief review of the issue:
To fix this I added an after_rollback hook to payment class which forces a save on the object if its state is failed.
Along side this fix, I have included some code to add a new 'invalid' state to the payment object. Payment#process! will invoke the invalidate! event if the payment_method does not support the payment source. I have implemented Gateway#supports? to check if the card brand is supported by the chosen gateway. I have done this because using an incorrect card with some gateways (for my case Worldpay) causes an exception to be thrown due to the card having no brand (due to an incorrectly formatted card number), I added the new state as I wasnt sure if setting the state to failed would imply a greater error / enables additional functionality elsewhere in the codebase.
Please note that although I have added some specs, and fixed any which I have broken, there were already some failing which I haven't been able to fix for you...
rspec ./spec/controllers/spree/orders_controller_extension_spec.rb:27 # Spree::OrdersController extension testing update specify symbol for handler instead of Proc POST has value success
I can validate that this problem is fixed with this pull request. I've also got another commit in to ensure that only valid payment records will be displayed on the order form. This means that if subsequent payments are added to the order, they'll also be displayed on the frontend. The look of this could probably do with some work, but it is functional now.
referenced this pull request
Mar 9, 2013
Nice work. I assume this is getting committed to 1-3-stable as well?
On Sat, Mar 9, 2013 at 12:32 PM, Ryan Bigg email@example.com wrote: