Skip to content

MVP implementation that can complete a checkout#156

Merged
elia merged 18 commits into
masterfrom
elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem
Jan 24, 2023
Merged

MVP implementation that can complete a checkout#156
elia merged 18 commits into
masterfrom
elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem

Conversation

@elia

@elia elia commented Dec 30, 2022

Copy link
Copy Markdown
Member

Summary

Aiming at the simplest implementation that allows completing a checkout.
The mapping between Stripe and Solidus models won't be final and subject to deep changes.
We don't expect anyone grabbing this extension from master given the big warning against that that we have at the top of the readme.

Fixes #152

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

  • I have written a thorough PR description.
  • I have kept my commits small and atomic.
  • I have used clear, explanatory commit messages.

The following are not always needed (cross them out if they are not):

  • I have added automated tests to cover my changes.
  • I have attached screenshots to demo visual changes.
  • I have opened a PR to update the guides.
  • I have updated the README to account for my changes.

@elia elia self-assigned this Dec 30, 2022
@elia elia linked an issue Dec 30, 2022 that may be closed by this pull request
6 tasks
@elia elia force-pushed the elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem branch 2 times, most recently from 028c385 to 0da82df Compare January 9, 2023 18:46
@elia elia changed the title Implement the standard gateway interfaces using the stripe gem MVP implementation that can complete a checkout Jan 11, 2023
@elia elia force-pushed the elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem branch from 0da82df to 4a69d77 Compare January 11, 2023 18:45
elia added 3 commits January 12, 2023 14:13
Follow the same style we already have for the dummy-app script.
This is only useful for development. It runs again the installer
whenever one of the relevant sources changes, and only runs the parts
of the installers necessary for an update, which is faster than
running everything.
@elia elia force-pushed the elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem branch 3 times, most recently from 5a83713 to 8c07acf Compare January 13, 2023 10:02
@elia elia force-pushed the elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem branch 2 times, most recently from b95c06e to 6813058 Compare January 16, 2023 12:40
@elia elia force-pushed the elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem branch from 6813058 to 92cc121 Compare January 19, 2023 12:36
@elia elia marked this pull request as ready for review January 19, 2023 12:49
@elia elia force-pushed the elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem branch from 92cc121 to a8bf830 Compare January 19, 2023 12:49

@kennyadsl kennyadsl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank @elia, this is a great start. I left just some questions/comments.

Also, now that we are fresh with some concept, I think this might be a good moment to add some YARD documentation to the main gateway/payment method methods that could help us in the future. Do you think this might have some value?


module SolidusStripe
class PaymentSource < ::Spree::PaymentSource
def gateway_payment_profile_id=(value)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread app/models/solidus_stripe/gateway.rb Outdated
end

# To create a requires_capture PaymentIntent,
# see our guide at: https://stripe.com/docs/payments/capture-later

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is our referring to Stripe here? Maybe we can be more explicit about it.

Comment thread README.md
Set `SOLIDUS_STRIPE_API_KEY` and `SOLIDUS_STRIPE_PUBLISHABLE_KEY` environment variables (e.g. via `direnv`), this
will trigger the default initializer to create a static preference for SolidusStripe.

Run `bin/dev` to start both the sandbox rail server and the file watcher that will update the sandbox whenever

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if bin/dev also 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?

Copy link
Copy Markdown
Member Author

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. 👍

end

def create_profile(payment)
pi = payment.source.payment_intent

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer to avoid 2-letter variables. payment_intent is not that long that will create problems IMHO, thoughts?


require 'solidus_stripe_spec_helper'

RSpec.describe SolidusStripe::PaymentIntentsController, type: :request do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I'm not mistaken here, the best practice is to avoid adding the _controller part to the filename and to the main describe name. In general, the file seems too tied to the controller, while requests specs should be more of a full request-cycle spec.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I just checked the RSpec generator as I wasn't sure about what changes I added, this is how it looks like:

require 'rails_helper'

RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
  describe "GET /<%= name.underscore.pluralize %>" do
    it "works! (now write some real specs)" do
      get <%= index_helper %>_path
      expect(response).to have_http_status(200)
    end
  end
end

So the only thing I changed was removing the quotes from around the class name so I could use described_class, happy to change it if there's a different/better way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, but I think that the class should not be a controller in the request specs. Looking around for examples it seems like it's a more high level concept that a specific class.

>
<div data-solidus-stripe-payment-target="paymentElement">
<!-- Elements will create form elements here -->
<em>Loading...</em>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good candidate for I18n?

<dt><%= SolidusStripe::PaymentSource.human_attribute_name(:stripe_payment_intent_id) %>:</dt>
<dd><%= link_to(
payment.source.stripe_payment_intent_id,
"https://dashboard.stripe.com/#{'test/' if payment.payment_method.preferred_test_mode}payments/#{payment.source.stripe_payment_intent_id}",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thought about moving this URL generation to the payment source model?

elia added 9 commits January 20, 2023 17:39
It's shorter (and works better with my editor, but please don't tell
anyone! :P).
It will be used by the frontend code to generate a client-secret.
In order for the routes to be defined on SolidusStripe we need to
isolate the namespace on the extension itself.
Only the happy path is taken into account, support for saving profiles
and wallet is yet to be added.
This will allow capturing, voiding, and canceling stripe payments.
elia added 2 commits January 20, 2023 17:44
Make auto create a payment method in development if the same env var
is available.
@elia elia force-pushed the elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem branch from a8bf830 to d6a7c23 Compare January 20, 2023 16:52
@elia elia requested a review from kennyadsl January 20, 2023 16:52
@kennyadsl

Copy link
Copy Markdown
Member

@elia I think you missed the YARD documentation part of my review comment, I can't find any reply to that and nothing changed in the code proposed. 👓

@elia

elia commented Jan 23, 2023

Copy link
Copy Markdown
Member Author

@elia I think you missed the YARD documentation part of my review comment, I can't find any reply to that and nothing changed in the code proposed. 👓

Thanks for calling that out, I indeed missed the comment.

It's probably early for adding documentation but I did it anyway mostly to have an idea of what it looks like, many gateway methods are still incomplete and will change considerably, but the current situation should be covered accurately.

@kennyadsl kennyadsl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks Elia, I'm sure that even if it's going to change, this Yard documentation won't be regretted.

@elia elia merged commit 7340550 into master Jan 24, 2023
@elia elia deleted the elia/152-implement-the-standard-gateway-interfaces-using-the-stripe-gem branch January 24, 2023 11:09
@elia elia added this to the v5 milestone Feb 22, 2023
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.

Implement the standard gateway interfaces using the Stripe gem

2 participants