Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring in payment model #5678

Closed

Conversation

sauloperez
Copy link
Contributor

@sauloperez sauloperez commented Jun 26, 2020

What? Why?

Closes #5689 and it's the groundwork needed by #5449 (I'll point a new PR to this one)

This was the solution agreed in openfoodfoundation/spree#46 (review).

Please, go commit by commit.

What should we test?

We should thoroughly test payments. I'll add the scenarios I can think of.

Release notes

Move Payment model and the processing module from Spree into OFN.

Changelog Category: Changed

@sauloperez sauloperez self-assigned this Jun 26, 2020
@sauloperez sauloperez force-pushed the bring-in-payment-model branch 3 times, most recently from 17170f0 to 4b360f1 Compare June 26, 2020 16:33
Copy link
Contributor

@luisramos0 luisramos0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just add a first scan of it, looking good :-)

app/models/spree/payment/processing.rb Show resolved Hide resolved
app/models/spree/payment/processing.rb Show resolved Hide resolved
app/models/spree/payment/processing.rb Show resolved Hide resolved
@@ -2,116 +2,9 @@

module Spree
Payment.class_eval do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to delete the decorator file, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That persist invalid bugs me and I want to understand what consequences can that override have.

spec/models/spree/payment_original_spec.rb Outdated Show resolved Hide resolved
@sauloperez
Copy link
Contributor Author

I'm leaving all the code cleanups/rubocop issues until the end so I don't break any behaviour. I take note of your feedback @luisramos0

order.process_payments!
expect(order.payments.count).to eq 1
expect(order.payments).to include payment
expect(payment.state).to eq "failed"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to see what change for this state to be returned now as invalid. The other expectations are still met but this behaviour change could have other undesired consquences.

The tight coupling between doesn't give other option but to check the
private method is called. The specs successfully stub
`log_entries#create` but for some reason the model instance that gets
evaluated it's not the stubbed one.
The exact error is

```
ActiveRecord::RecordNotSaved:
       You cannot call create unless the parent is saved
```

raised from app/models/spree/payment_decorator.rb:29:in `ensure_correct_adjustment'
I'll move on to other easier issues and get back to it when we're in
a better position.
Merging Spree's an our factory didn't really work.
This way we don't mix contexts while merging in our own decorator tests.
They are now isolated from each other.
@sauloperez sauloperez force-pushed the bring-in-payment-model branch from efabf38 to 2f46483 Compare July 10, 2020 09:51
If we don't want that callback we can just as well remove it now that we
own that code.
@sauloperez
Copy link
Contributor Author

sauloperez commented Jul 10, 2020

Now that all specs are passing I'm fixing easy code quality and styling issues one by one. Once done, I'll apply the fix #5449 requires. Thanks @luisramos0 for your help!

@sauloperez sauloperez force-pushed the bring-in-payment-model branch from 64f67fc to e587b7f Compare July 10, 2020 13:19
@luisramos0 luisramos0 reopened this Jul 13, 2020
@sauloperez sauloperez force-pushed the bring-in-payment-model branch from 19522cc to 3a64cc4 Compare July 15, 2020 12:02
`#save_requested_by_customer` is an accessor we added and thus, the
Spree's spec didn't consider.
@sauloperez sauloperez marked this pull request as ready for review July 16, 2020 06:43
Copy link
Contributor

@luisramos0 luisramos0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work Pau!
As I shared on slack, you can fix 5449 in here as well as long as you dont force-push 👍

@@ -89,11 +89,15 @@ def can_credit?
end

# see https://github.com/spree/spree/issues/981
#
# Import from future Spree v.2.3.0 d470b31798f37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just remove these 2 comments. It's just history, I dont see them as useful for the future dev.

@@ -107,22 +107,19 @@ def build_source
source.user_id = order.user_id if order
end

# Pin payments lacks void and credit methods, but it does have refund
# Here we swap credit out for refund and remove void as a possible action
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now I see this could be done in pin.rb instead of here. Not in scope for this PR.

end
end

delegate :currency, to: :order
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was converted from method to delegate by rubocop, probably nicer to move it up next to the other delegate?


state_will_change!
save
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌


unless payment_method.supports?(source)
invalidate!
raise Core::GatewayError.new(Spree.t(:payment_method_not_supported))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this go back to .new ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird, I think I copied the snippet you suggested here. Whatever.

else
# Standard ActiveMerchant capture usage
response = payment_method.capture(money.money.cents,
response = if payment_method.payment_profiles_supported?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont like this rubocop rule, am I the only one? I always find the result to look worse than before and the solution is always to extract the if clause to a method. I am not requesting any change, just a comment.

Copy link
Contributor Author

@sauloperez sauloperez Jul 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on this. I do find it a bit more readable when nested because otherwise the assignment is easy to miss. As many things in Ruby though, abusing it by having a long if/else beats readability anyway, so extracting a method in those case makes sense.

Mostly styling issues.
@sauloperez
Copy link
Contributor Author

I close this in favor of #5806.

@sauloperez sauloperez closed this Jul 22, 2020
@sauloperez sauloperez deleted the bring-in-payment-model branch July 22, 2020 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ByeBye Spree] Move Payment model to OFN
2 participants