Class: SolidusStripe::Customer

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/solidus_stripe/customer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.retrieve_or_create_stripe_customer_id(payment_method:, order:) ⇒ Object



10
11
12
13
14
15
# File 'app/models/solidus_stripe/customer.rb', line 10

def self.retrieve_or_create_stripe_customer_id(payment_method:, order:)
  instance = find_or_initialize_by(payment_method: payment_method, source: order.user || order)

  instance.stripe_id ||
    instance.create_stripe_customer.tap { instance.update!(stripe_id: _1.id) }.id
end

Instance Method Details

#create_stripe_customerObject



17
18
19
# File 'app/models/solidus_stripe/customer.rb', line 17

def create_stripe_customer
  payment_method.gateway.request { Stripe::Customer.create(email: source.email) }
end