-
-
Notifications
You must be signed in to change notification settings - Fork 65
MVP implementation that can complete a checkout #156
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
elia
merged 18 commits into
master
from
elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem
Jan 24, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f47df41
Cleanup the sandbox script
elia 6a7d661
Add a --watch option to the install generator
elia 410e775
Add a --sync option to the installer that will just copy the files
elia 5bf23e4
Add a comment about why we have stlib gems in the gemfile
elia 28aa006
Add a bin/dev script that will start both the server and the watcher
elia e0f0cc1
Add the payment method basic info
elia e2a55fd
Attach the stripe payment source to a payment intent id
elia 467f235
Add a basic gateway implementation
elia 3022fbf
Reimplement bin/rspec in ruby
elia 6c8d8d7
Add a payment intent creation endpoint
elia cbc782b
Set a table-name prefix for the whole extension
elia d63c96b
Fix the Spree namespace reference in the generator
elia 8bfc6da
Add a simple checkout flow with specs
elia 592ec83
Add an admin partial for payments
elia fd5c326
Adjust a few rubocop rules to our specific needs
elia e206a15
Setup static payment method prefs if the ENV key is available
elia d6a7c23
Move the dashboard link generation to PaymentSource
elia 9bf87a4
Document the gateway with YARD
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
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,2 @@ | ||
| web: unset PORT && bin/rails-sandbox server | ||
| installer: 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
35 changes: 35 additions & 0 deletions
35
app/controllers/solidus_stripe/payment_intents_controller.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,35 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'stripe' | ||
|
|
||
| class SolidusStripe::PaymentIntentsController < Spree::BaseController | ||
| include Spree::Core::ControllerHelpers::Order | ||
|
|
||
| def create | ||
| payment_method = current_order(create_order_if_necessary: true) | ||
| .available_payment_methods.find(params[:payment_method_id]) | ||
|
|
||
| currency = current_order.currency | ||
| amount = SolidusStripe::Gateway::MoneyToStripeAmountConverter.to_stripe_amount( | ||
| current_order.display_total.money.fractional, | ||
| currency, | ||
| ) | ||
|
|
||
| intent, _response = payment_method.gateway.client.request do | ||
| Stripe::PaymentIntent.create({ | ||
| amount: amount, | ||
| currency: currency, | ||
| capture_method: 'manual', | ||
| }) | ||
| end | ||
|
|
||
| # TODO: send the payment source information to the frontend so | ||
| # it can be used for the payment step form. | ||
| _payment_source = SolidusStripe::PaymentSource.create!( | ||
| stripe_payment_intent_id: intent.id, | ||
| payment_method: payment_method, | ||
| ) | ||
|
|
||
| render json: { client_secret: intent.client_secret } | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module SolidusStripe | ||
| def self.table_name_prefix | ||
| "solidus_stripe_" | ||
| 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
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
16 changes: 16 additions & 0 deletions
16
app/views/spree/admin/payments/source_views/_stripe.html.erb
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,16 @@ | ||
| <fieldset data-hook="credit_card"> | ||
| <legend align="center"><%= SolidusStripe::PaymentSource.model_name.human %></legend> | ||
|
|
||
| <div class="row"> | ||
| <div class="col-4"> | ||
| <dl> | ||
| <dt><%= SolidusStripe::PaymentSource.human_attribute_name(:stripe_payment_intent_id) %>:</dt> | ||
| <dd><%= link_to( | ||
| payment.source.stripe_payment_intent_id, | ||
| payment.source.stripe_dashboard_url, | ||
| target: :_blank, | ||
| ) %></dd> | ||
| </dl> | ||
| </div> | ||
| </div> | ||
| </fieldset> |
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,8 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| if ! gem list foreman -i --silent; then | ||
| echo "Installing foreman..." | ||
| gem install foreman | ||
| fi | ||
|
|
||
| exec foreman start -f Procfile.dev "$@" |
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,11 +1,5 @@ | ||
| #!/usr/bin/env bash | ||
| #!/usr/bin/env ruby | ||
|
|
||
| set -e | ||
|
|
||
| bin/rails-dummy-app generate solidus_stripe:install --force --migrate --specs=all | ||
|
|
||
| cd dummy-app/ | ||
| rspec "$@" | ||
| exit_status=$? | ||
| cd - | ||
| exit $exit_status | ||
| system "bin/rails-dummy-app generate solidus_stripe:install --force --migrate --specs=all --sync" | ||
| Dir.chdir "dummy-app/" | ||
| exec "rspec", *ARGV |
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 if
bin/devalso creates the payment method if needed? I think it would be a great UX improvement but don't know if that's easy to do. Thoughts?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.
Added the static pref that for some reason was left out of the PR and bin/sandbox will auto-create the payment method connecting to the static pref if the same env var is present. 👍