Sha256: 8109e93d1b9532e3da3f366ad76bff2f1268bd9eb0bc5aa933860657ad08f88f

Contents?: true

Size: 914 Bytes

Versions: 4

Compression:

Stored size: 914 Bytes

Contents

module Tang
  class UpdateCustomer
    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[:base] << e.message
        end
      end

      return customer
    end

    def self.populate_customer(stripe_customer, customer)
      stripe_customer.email = customer.email
      stripe_customer.account_balance = customer.account_balance if customer.account_balance.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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tang-0.2.0 app/services/tang/update_customer.rb
tang-0.1.0 app/services/tang/update_customer.rb
tang-0.0.9 app/services/tang/update_customer.rb
tang-0.0.8 app/services/tang/update_customer.rb