Class: SolidusStripe::IntentsController

Inherits:
Spree::BaseController
  • Object
show all
Includes:
Spree::Core::ControllerHelpers::Order
Defined in:
app/controllers/solidus_stripe/intents_controller.rb

Instance Method Summary collapse

Instance Method Details

#after_confirmationObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/solidus_stripe/intents_controller.rb', line 10

def after_confirmation
  unless params[:payment_intent]
    return head :unprocessable_entity
  end

  unless current_order.confirm?
    redirect_to main_app.checkout_state_path(current_order.state)
    return
  end

  intent = SolidusStripe::PaymentIntent.find_by!(
    payment_method: @payment_method,
    order: current_order,
    stripe_intent_id: params[:payment_intent],
  )

  if intent.process_payment
    flash.notice = t('spree.order_processed_successfully')

    flash['order_completed'] = true

    redirect_to(
      spree_current_user ?
        main_app.order_path(current_order) :
        main_app.token_order_path(current_order, current_order.guest_token)
    )
  else
    flash[:error] = params[:error_message] || t('spree.payment_processing_failed')
    redirect_to(main_app.checkout_state_path(:payment))
  end
end