Module: SpreeStripe::OrderDecorator

Defined in:
app/models/spree_stripe/order_decorator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



3
4
5
6
7
# File 'app/models/spree_stripe/order_decorator.rb', line 3

def self.prepended(base)
  base.has_many :payment_intents, class_name: 'SpreeStripe::PaymentIntent', dependent: :destroy

  base.store_accessor :private_metadata, :stripe_tax_calculation_id
end

Instance Method Details

#associate_user!(user, override_email = true) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'app/models/spree_stripe/order_decorator.rb', line 18

def associate_user!(user, override_email = true)
  super(user, override_email)

  return if payment_intents.empty?

  responses = payment_intents.map { |payment_intent| payment_intent.update_stripe_payment_intent }
  customer_id = responses.find { |response| response.params['customer'].present? }&.params['customer']

  payment_intents.update_all(customer_id: customer_id) if customer_id.present?
end

#persist_user_credit_cardObject



29
30
31
32
33
34
35
# File 'app/models/spree_stripe/order_decorator.rb', line 29

def persist_user_credit_card
  super
  stripe_gateway = store.stripe_gateway
  return if stripe_gateway.blank?

  stripe_gateway.attach_customer_to_credit_card(user)
end

#stripe_payment_intentObject



37
38
39
# File 'app/models/spree_stripe/order_decorator.rb', line 37

def stripe_payment_intent
  @stripe_payment_intent ||= payment_intents.last.stripe_payment_intent
end

#update_payment_intentsObject



9
10
11
12
13
14
15
16
# File 'app/models/spree_stripe/order_decorator.rb', line 9

def update_payment_intents
  return if completed?
  return unless total_minus_store_credits.positive?

  payment_intents.each do |payment_intent|
    payment_intent.update!(amount: total_minus_store_credits)
  end
end