Module: RailsTrade::PaymentMethod::StripeMethod

Extended by:
ActiveSupport::Concern
Included in:
StripeMethod
Defined in:
app/models/rails_trade/payment_method/stripe_method.rb

Instance Method Summary collapse

Instance Method Details

#customer_info(customer) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/rails_trade/payment_method/stripe_method.rb', line 13

def customer_info(customer)
  card = customer.sources.data[0]
  return {} unless card
  {
    description: customer.description,
    address_zip: card.address_zip,
    address_zip_check: card.address_zip_check,
    brand: card.brand,
    country: card.country,
    cvc_check: card.cvc_check,
    exp_month: card.exp_month,
    exp_year: card.exp_year,
    fingerprint: card.fingerprint,
    funding: card.funding,
    last4: card.last4
  }
end

#detective_saveObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/rails_trade/payment_method/stripe_method.rb', line 40

def detective_save
  begin
    customer = Stripe::Customer.create(description: "buyer_id: #{payment_references.map { |i| i.buyer_id }}", source: self.token)
    self. = customer.id
    self.extra = self.customer_info(customer)
  rescue Stripe::StripeError => ex
    self.errors.add :base, ex.message
  end

  self.verified = true
  if self.errors.blank?
    self.save
  else
    false
  end
end

#removeObject



35
36
37
38
# File 'app/models/rails_trade/payment_method/stripe_method.rb', line 35

def remove
  cu = Stripe::Customer.retrieve 
  cu.delete
end

#retrieveObject



8
9
10
11
# File 'app/models/rails_trade/payment_method/stripe_method.rb', line 8

def retrieve
  customer = Stripe::Customer.retrieve 
  customer_info(customer)
end

#update_extraObject



31
32
33
# File 'app/models/rails_trade/payment_method/stripe_method.rb', line 31

def update_extra
  self.update extra: retrieve.to_h
end