Module: Effective::Providers::Stripe

Extended by:
ActiveSupport::Concern
Included in:
OrdersController
Defined in:
app/controllers/effective/providers/stripe.rb

Instance Method Summary collapse

Instance Method Details

#stripeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/effective/providers/stripe.rb', line 6

def stripe
  raise('stripe provider is not available') unless EffectiveOrders.stripe?

  @order = Order.find(params[:id])
  @customer = Effective::Customer.for_user(@order.user)

  EffectiveResources.authorize!(self, :update, @order)

  payment = validate_stripe_payment(stripe_params[:payment_intent_id])

  if payment.blank? || !payment.kind_of?(Hash)
    return order_declined(payment: payment, provider: 'stripe', declined_url: stripe_params[:declined_url])
  end

  # Update the customer payment fields
  if payment[:payment_method_id].present?
    @customer.update!(payment.slice(:payment_method_id, :active_card))
  end

  order_purchased(
    payment: payment,
    provider: 'stripe',
    card: payment[:card],
    purchased_url: stripe_params[:purchased_url]
  )
end