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

1008 ideal integration online payment provider #1031

Merged
merged 4 commits into from
Apr 8, 2024

Conversation

yksflip
Copy link
Member

@yksflip yksflip commented Oct 2, 2023

This PR adds the online payment provider mollie as a plugin. User can add credit to their ordergroups balance via various payment methods. wvengen implemented this already in the foodsoft-adams fork. I rewrote some parts to make it work with the newest mollie api version and added some bits to improve the usability.

Changes relevant to the foodsoft core:

  • added new attributes to the financial_transaction model to keep track of the state of a transaction
  • financial_transaction.value may be nil now, this indicates an incomplete transaction

Changes on the plugin:

  • payment_method is no longer choosen in the foodsoft form but on the mollie checkout
  • information regarding the transaction fee is displayed
  • settings can be configured in the admin screen
  • the transaction_type for mollie transactions can be configured in the administration settings

still open

  • [ ] move accept_return_to to ApplicationController?
  • open currency refactoring issue, implement FoodsoftMollie.currency
  • write financial transaction documentation
  • reverting a pending financial transaction?
  • handle amount < min ?
  • squash commits

@yksflip yksflip force-pushed the 1008-ideal-integration-online-payment-provider branch 5 times, most recently from 685552a to cda0f4b Compare October 5, 2023 21:08
@yksflip yksflip marked this pull request as ready for review October 5, 2023 21:09
@yksflip yksflip force-pushed the 1008-ideal-integration-online-payment-provider branch from cda0f4b to 70944a7 Compare October 6, 2023 15:17
Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

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

Wow, great to see this coming back, now properly as a core Foodsoft plugin! :)

It's been a long time, probably some questions I'm asking are about pieces you've just copied from the original code. Nevertheless, it's good to remain critical (also on my past self).

There are two possibly important assumptions that change:

  • A FinancialTransaction's amount may be nil
  • A FinancialTransaction is mutable

This is something important to think through. Solid accounting has no changing history, but in this case we make an exception. I think this is justified, but I'm not 100% sure - both in Foodsoft core (not all parts of the code are tested fully), and by plugins/integrations people have written. This even affects the API (financial transations), where software using it may not expect nil for amount.
I think before this PR is merged, someone needs to have a good look at this. Perhaps you've done that already.

Do we need to make a new API version for this, hide the unfinished transactions by default, or accept a possibly incompatible change (the API is relatively young, so maybe ok)?
One way to get an answer to this is to ask this question on the forum and/or Github.

I also asked some questions to which I could have found the answer myself. Hope that's ok, and you're patient enough to go look, think about it, and respond.

Some general things to improve could be (partly already mentioned in separate comments):

  • Use strong parameters, they're standard now, and with finance-related code it's good to be safe.
  • I think it's good to document what we expect from financial transactions, just some background in the main Foodsoft (I guess in-tree) developer docs, about the assumptions. Maybe it's not really a question for you. I think it would have best been done already with the introduction of financial transaction types and such. But this PR touches something quite important, so I think writing down something about financial transactions may help even getting your own mental model right.

Please feel free to disagree too, I hope we can have a constructive conversation :)
Thanks for all your work in making this ready for prime-time!

app/models/financial_transaction.rb Outdated Show resolved Hide resolved
app/views/finance/index.html.haml Outdated Show resolved Hide resolved
app/views/home/index.html.haml Show resolved Hide resolved
plugins/mollie/config/locales/nl.yml Outdated Show resolved Hide resolved
plugins/mollie/config/locales/nl.yml Outdated Show resolved Hide resolved
plugins/mollie/config/locales/nl.yml Outdated Show resolved Hide resolved
plugins/mollie/config/locales/nl.yml Outdated Show resolved Hide resolved
@wvengen
Copy link
Member

wvengen commented Oct 7, 2023

p.s. if the amount can be nil in the API, the API docs (swagger) may need updating.

@yksflip yksflip self-assigned this Oct 12, 2023
Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

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

This is shaping up nicely!

if t.amount
format_currency t.amount
elsif t.payment_amount && t.payment_state
content_tag :span, "#{number_to_currency t.payment_amount}) (#{t.payment_state})", class: :disabled_amount
Copy link
Member

Choose a reason for hiding this comment

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

Maybe even a title to explain that this is a transaction that is in progress, which may or may not be completed (but more concise maybe)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought it would be the best to just display the payment state as a seperate column. It felt weird to use the amount column for this information.

app/models/financial_transaction.rb Outdated Show resolved Hide resolved
doc/API.md Outdated Show resolved Hide resolved
@yksflip
Copy link
Member Author

yksflip commented Oct 25, 2023

This is shaping up nicely!

thx! your comment are very helpful :)

@yksflip yksflip force-pushed the 1008-ideal-integration-online-payment-provider branch 4 times, most recently from 1513b41 to f777310 Compare November 14, 2023 11:40
@yksflip
Copy link
Member Author

yksflip commented Nov 14, 2023

Hey I've been working a bit more an introduced some changes:

  • transactions with nil value are no longer revertable
  • display payment_state in transaction views
  • strong params on api controller
  • api-key is now used in function call (around filter didn't work)
  • introduce currency config
    Mollie returns fee amounts always in EUR, no matter what currency is
    selected. Because of that there is a constraint to charge fees for
    EUR only.
  • introduce default amount config
  • some code refactoring

Hopefully I can finish up on this until end of this week :)

@yksflip yksflip force-pushed the 1008-ideal-integration-online-payment-provider branch from f777310 to 4b846ae Compare November 24, 2023 12:11
@wvengen
Copy link
Member

wvengen commented Feb 3, 2024

Please let me know when it is ready for review (comment or the re-request review button), as it's been a while. Would be great to have this included in the next release.

@yksflip yksflip added this to the 4.9 milestone Mar 11, 2024
@yksflip yksflip force-pushed the 1008-ideal-integration-online-payment-provider branch 3 times, most recently from f711db6 to ab8bd3a Compare March 29, 2024 14:23
@yksflip
Copy link
Member Author

yksflip commented Mar 29, 2024

hey @wvengen, thanks for the reminder. I know it's been a while ... I tried to write some documentation, though I don't feel very confident with it. I still don't understand very much of the banking feature. I see this docs as a starting point...
I'd happy to hear your feedback and would be great to see this finally merged :)

Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

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

Thank you for working on this PR!
Some small comments, I think it would be almost ready for merging.

Super you added some documentation. I find the financial transaction types and such also not that easy to comprehend. I think it's mostly the Austrian foodcoops using this, so they can best provide input here. See also this forum thread, here is an issue showing a use-case, and this issue has also some background.

app/helpers/application_helper.rb Show resolved Hide resolved
%th= heading_helper FinancialTransaction, :payment_method
%th= heading_helper FinancialTransaction, :payment_amount
%th= heading_helper FinancialTransaction, :payment_fee
%th= heading_helper FinancialTransaction, :payment_state
Copy link
Member

Choose a reason for hiding this comment

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

Is the table still readable with a number of added columns (with possibly long names)?
This is especially relevant for foodcoops not using a payment plugin.

Copy link
Member Author

Choose a reason for hiding this comment

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

hm maybe I can add a check if payment_plugin is not null and only display then? Or I could introduce another config setting that "enables" payments in general

Copy link
Member

Choose a reason for hiding this comment

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

If we don't need a config option, let's avoid it (as it's complex enough as it is). So if they're a straightforward way to derive this, yes. Looking at payment_plugin config seems sensible here, yes.

Could there be a situation where this information is still relevant but the payment plugin is disabled? E.g. a payment plugin was enabled, but now disabled? I think we can just hide it, because any payment-plugin-related things will fail anyway. But just checking. E.g. at some places we check if there's more than one financial transaction type, and only show certain things if there is (to avoid UI complexity when a feature is not used).

spec/swagger_helper.rb Outdated Show resolved Hide resolved
app/models/financial_transaction.rb Outdated Show resolved Hide resolved
app/models/financial_transaction.rb Show resolved Hide resolved
@yksflip
Copy link
Member Author

yksflip commented Apr 5, 2024

thanks for your feedback!
I've added some basic model tests for financial_transactions, refactored the search_scope, and implemented the around_save.
I also just had a chat with leo and he mentioned the user documentation on https://docs.foodcoops.net/de/documentation/admin/finances

I'll squash the commits later, I thought it could be easier for you to review like this?

Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! We're definitely getting there 🚀
Great you found the documentation, I didn't know about this, thanks for sharing.

spec/models/financial_transaction_spec.rb Outdated Show resolved Hide resolved
spec/models/financial_transaction_spec.rb Outdated Show resolved Hide resolved
%th= heading_helper FinancialTransaction, :payment_method
%th= heading_helper FinancialTransaction, :payment_amount
%th= heading_helper FinancialTransaction, :payment_fee
%th= heading_helper FinancialTransaction, :payment_state
Copy link
Member

Choose a reason for hiding this comment

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

If we don't need a config option, let's avoid it (as it's complex enough as it is). So if they're a straightforward way to derive this, yes. Looking at payment_plugin config seems sensible here, yes.

Could there be a situation where this information is still relevant but the payment plugin is disabled? E.g. a payment plugin was enabled, but now disabled? I think we can just hide it, because any payment-plugin-related things will fail anyway. But just checking. E.g. at some places we check if there's more than one financial transaction type, and only show certain things if there is (to avoid UI complexity when a feature is not used).

app/helpers/application_helper.rb Show resolved Hide resolved
@yksflip yksflip force-pushed the 1008-ideal-integration-online-payment-provider branch 2 times, most recently from 067c424 to 18a889e Compare April 5, 2024 16:02
@yksflip
Copy link
Member Author

yksflip commented Apr 5, 2024

Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

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

Super! Some small notes, otherwise good to go, I think 🚀

app/views/home/index.html.haml Outdated Show resolved Hide resolved
app/views/finance/index.html.haml Show resolved Hide resolved
plugins/mollie/README.md Outdated Show resolved Hide resolved
plugins/mollie/config/locales/nl.yml Outdated Show resolved Hide resolved
@yksflip yksflip force-pushed the 1008-ideal-integration-online-payment-provider branch from 18a889e to db46544 Compare April 7, 2024 17:06
@yksflip
Copy link
Member Author

yksflip commented Apr 7, 2024

@wvengen let's merge? :)

Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

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

Yes! Many many thanks for completing this (and for keeping up with my feedback, requesting changes several times).

Feel free to press the merge button! (And I would suggest rebase merge in this case - and I would reword the commits to add "(#1008 , PR #1031)" but maybe that's overthinking it.)

@wvengen
Copy link
Member

wvengen commented Apr 8, 2024

Ah, and for a future PR, it's good to mention the issue number in the PR description (e.g. in this case "Implements #1008"), so that Github recognizes this and provides cross-references. The "1008" in the PR title didn't do this.

@yksflip yksflip force-pushed the 1008-ideal-integration-online-payment-provider branch from db46544 to 84998c3 Compare April 8, 2024 19:40
@yksflip
Copy link
Member Author

yksflip commented Apr 8, 2024

Thank you for also keeping up and your helpful advise :)

@yksflip yksflip merged commit 8b4c36e into master Apr 8, 2024
3 of 4 checks passed
yksflip added a commit that referenced this pull request Apr 8, 2024
…1008 , PR #1031)

Co-authored-by: wvengen <willem@thequestionmark.org>
yksflip added a commit that referenced this pull request Apr 8, 2024
Co-authored-by: wvengen <willem@thequestionmark.org>
yksflip added a commit that referenced this pull request Apr 8, 2024
@yksflip yksflip deleted the 1008-ideal-integration-online-payment-provider branch April 8, 2024 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants