solidusio / solidus_stripe

💳 Integrate Solidus with Stripe
https://stripe.com
BSD 3-Clause "New" or "Revised" License
36 stars 61 forks source link

Support `auto_capture: true` for the payment method #178

Closed elia closed 1 year ago

elia commented 1 year ago

Why

Being able to auto_capture payments during the order completion is a stock solidus capability.

What

Hook into the finalization process to capture the authorized amount for stripe payments that were previously authorized if auto_capture is enabled.

A possible implementation involves using a subscriber

# app/subscribers/update_account_balance_subscriber.rb
class SolidusStripe::AutoCaptureSubscriber
  include Omnes::Subscriber

  handle :order_finalized, with: :call

  def call(event)
    stripe_payments.each(&:capture!) # pseudo-code!
  end
end

# config/initializers/solidus_stripe.rb
Rails.application.config.to_prepare do
  SolidusStripe::AutoCaptureSubscriber.new.subscribe_to(Spree::Bus)
end
waiting-for-dev commented 1 year ago

We'll need to implement something like https://github.com/solidusio/solidus_stripe/pull/245 for the unhappy path

rainerdema commented 1 year ago

This seems to work fine with the current implementation. Thanks to the implementation of the purchase action with the "automatic" capture_method, the authorization+capture happens correctly and is in line with the current Solidus logic.

As specified in the Spree::Payment::Processing module, if auto_capture is set to true, the purchase action will be invoked on the gateway of the referenced payment method.

I will do other checks, follow Marc's suggestion about the unhappy path and implement the necessary specs to cover this use case.

waiting-for-dev commented 1 year ago

Does it also work for the payment intent flow? As I understand, manual is fixed now.