Skip to content

WIP: Add support for Stripe Payment Element#409

Open
mdavo6 wants to merge 1 commit into
spree-contrib:mainfrom
mdavo6:stripe-payment-element-feat
Open

WIP: Add support for Stripe Payment Element#409
mdavo6 wants to merge 1 commit into
spree-contrib:mainfrom
mdavo6:stripe-payment-element-feat

Conversation

@mdavo6
Copy link
Copy Markdown

@mdavo6 mdavo6 commented Aug 18, 2022

@rafalcymerys @damianlegawiec
I have been working on integrating Stripe payment element with Spree Vue (see vuestorefront-community/spree#257). Here is where I am at with the spree side. Would be great to get your feedback on my current approach, and any suggestions.

Some key points:

  1. Addition of a new payment state - 'intent', which would be after checkout. This would allow the payment gateway to create the payment intent.
  2. The Stripe API does not appear to support spree's current implementation of payment profiles (spree uses the 'store' method after payment creation). With payment intents, you need to create the customer and link them to the payment intent when it is created.
  3. New endpoint to create payment intent.
  4. New 'Stripe' webhook to handle successful confirmation of payment intent and update order.

TO DO:

  • Invalidate payment intent when change to order, or change of payment method.

def self.prepended(base)
# Added the 'intent' state to allow payment gateway to handle creation of payment intent.
# Overridden here for now, but assume this would be better sitting in core.
base.state_machine initial: :checkout do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we need this additional state related to intent, or if we could just save a Payment object for StripeElementsGateway only if the payment was successfully created?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But if that needs to happen, this would probably be better of in core. This will be a breaking change though for other payment gateways.

Copy link
Copy Markdown
Author

@mdavo6 mdavo6 Sep 2, 2022

Choose a reason for hiding this comment

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

@rafalcymerys Yes, I was unsure if there was a way to avoid adding the extra 'intent' payment state. In the end I felt like it was significant enough to warrant a separate state as it may apply to other payment gateways, and seemed to make sense as a way to call the Stripe Gateway. If you were to remove the 'intent' state, how would you suggest calling the Stripe Gateway to create the payment intent prior to save? Would it be some sort of before_action related to payment? And would it go via the spree_gateway?

Comment thread lib/spree_gateway/engine.rb Outdated

config.autoload_paths += %W(#{config.root}/lib)

initializer "spree.gateway.payment_methods", :after => "spree.register.payment_methods" do |app|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yup, good point

Comment thread spree_gateway.gemspec

s.add_dependency 'spree_core', '>= 3.7.0'
s.add_dependency 'spree_extension'
s.add_dependency 'stripe'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting, so that's not already included?
I would suggest locking this dependency to a particular version - Gemfile.lock will be created in projects using this gem, and they may then resolve to an incompatible version.

Copy link
Copy Markdown
Author

@mdavo6 mdavo6 Sep 2, 2022

Choose a reason for hiding this comment

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

Yes, I only added this to make manipulating the object coming back from Stripe via webhook easier. ActiveMerchant handles the rest of the Stripe <--> Spree logic, so was not previously included. Happy to add the current version number once we've got the other points 'locked down' (pun intended).

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.

2 participants