Class: Tang::UpdateCustomer

Inherits:
Object
  • Object
show all
Defined in:
app/services/tang/update_customer.rb

Class Method Summary collapse

Class Method Details

.call(customer) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/services/tang/update_customer.rb', line 3

def self.call(customer)
  return customer if !customer.valid?

  if customer.stripe_id.present?
    begin
      c = Stripe::Customer.retrieve(customer.stripe_id)
      c = populate_customer(c, customer)
      c.save
    rescue Stripe::StripeError => e
      customer.errors.add(:base, :invalid, message: e.message)
    end
  end

  return customer
end

.populate_customer(stripe_customer, customer) ⇒ Object



19
20
21
22
23
24
25
26
# File 'app/services/tang/update_customer.rb', line 19

def self.populate_customer(stripe_customer, customer)
  stripe_customer.email = customer.email
  stripe_customer. = customer. if customer..present?
  stripe_customer.business_vat_id = customer.business_vat_id if customer.business_vat_id.present?
  stripe_customer.description = customer.description
  stripe_customer.coupon = customer.coupon.stripe_id if customer.coupon.present?
  return stripe_customer
end