-
-
Notifications
You must be signed in to change notification settings - Fork 66
Development QoL changes and bug fixes #159
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4a18d09
Add a spec for guest checkout
elia 2dfb52b
Streamline bin helpers
elia 03663a8
Rename the watcher process in foreman
elia 15bdc7b
Add Gateway::MoneyToStripeAmountConverter.to_solidus_amount
elia 33ff898
Extract the amount converter from the Gateway
elia 888a16b
Use alias for identical partial names on the payment method
elia 3a9b7f4
Setup the debugger to run remotely from inside foreman
elia 792ba42
Gateway#credit should only rely on the `originator` option being a Sp…
elia 964932f
Add Gateway#request to get just the result ignoring the reposnse
elia 4b62589
Minimal visual adjustment for the Payment Element
elia e19c17d
Create the Stripe payment method as the first payment option
elia 403098d
Add activestorage to the gemfile
elia 2db0d9b
Always rely on the originator option for Gateway
elia d8d1d8e
Don't skip javascript when creating the dummy-app
elia 5cf43a9
Don't rely on the solidus extension orb for testing against SSF
elia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,5 @@ gem 'stringio' | |
| gem 'timeout' | ||
|
|
||
| gem 'listen' | ||
|
|
||
| gem 'activestorage' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| web: unset PORT && bin/rails-sandbox server | ||
| installer: bin/rails-sandbox g solidus_stripe:install --force --watch | ||
| web: unset PORT && env RUBY_DEBUG_OPEN=true bin/rails-sandbox server | ||
| watch: bin/rails-sandbox g solidus_stripe:install --force --watch | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/models/concerns/solidus_stripe/money_to_stripe_amount_converter.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module SolidusStripe::MoneyToStripeAmountConverter | ||
| extend ActiveSupport::Concern | ||
| extend self | ||
|
|
||
| ZERO_DECIMAL_CURRENCIES = %w[ | ||
| BIF | ||
| CLP | ||
| DJF | ||
| GNF | ||
| JPY | ||
| KMF | ||
| KRW | ||
| MGA | ||
| PYG | ||
| RWF | ||
| UGX | ||
| VND | ||
| VUV | ||
| XAF | ||
| XOF | ||
| XPF | ||
| ].freeze | ||
|
|
||
| THREE_DECIMAL_CURRENCIES = %w[ | ||
| BHD | ||
| JOD | ||
| KWD | ||
| OMR | ||
| TND | ||
| ].freeze | ||
|
|
||
| # special currencies that are represented in cents but | ||
| # should be divisible by 100, thus making them integer only. | ||
| DIVISIBLE_BY_100 = %w[ | ||
| HUF | ||
| TWD | ||
| UGX | ||
| ].freeze | ||
|
|
||
| # Solidus will provide a "fractional" amount, that is specific for each currency | ||
| # following the configurationo defined in the Money gem. | ||
| # | ||
| # Stripe uses the "smallest currency unit", | ||
| # (e.g., 100 cents to charge $1.00 or 100 to charge ¥100, a zero-decimal currency) | ||
| # https://stripe.com/docs/currencies#zero-decimal | ||
| # | ||
| # We need to ensure the fractional amount is considering the same number of decimals. | ||
| def to_stripe_amount(fractional, currency) | ||
| solidus_subunit_to_unit, stripe_subunit_to_unit = subunit_to_unit(currency) | ||
|
|
||
| if stripe_subunit_to_unit == solidus_subunit_to_unit | ||
| fractional | ||
| else | ||
| (fractional / solidus_subunit_to_unit.to_d) * stripe_subunit_to_unit.to_d | ||
| end | ||
| end | ||
|
|
||
| def to_solidus_amount(fractional, currency) | ||
| solidus_subunit_to_unit, stripe_subunit_to_unit = subunit_to_unit(currency) | ||
|
|
||
| if stripe_subunit_to_unit == solidus_subunit_to_unit | ||
| fractional | ||
| else | ||
| (fractional / stripe_subunit_to_unit.to_d) * solidus_subunit_to_unit.to_d | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def subunit_to_unit(currency) | ||
| solidus_subunit_to_unit = ::Money::Currency.new(currency).subunit_to_unit | ||
| stripe_subunit_to_unit = | ||
| case currency.to_s.upcase | ||
| when *ZERO_DECIMAL_CURRENCIES then 1 | ||
| when *THREE_DECIMAL_CURRENCIES then 1000 | ||
| when *DIVISIBLE_BY_100 then 100 | ||
| else 100 | ||
| end | ||
|
|
||
| [solidus_subunit_to_unit, stripe_subunit_to_unit] | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a comment with usage instructions here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great call, added instructions to the readme under Development so it's even more visible.