Sha256: 29d460378a38347e9c2a937d99ab6e4585af6335e26e331b02ced73776ed93be

Contents?: true

Size: 784 Bytes

Versions: 1

Compression:

Stored size: 784 Bytes

Contents

require 'active_support/concern'

module Tang
  module Customer
    extend ActiveSupport::Concern

    included do
      has_one :card, class_name: 'Tang::Card', foreign_key: 'customer_id'
      has_one :subscription, class_name: 'Tang::Subscription', foreign_key: 'customer_id'

      before_update :update_stripe_customer
      before_destroy :delete_stripe_customer

      validates :stripe_id, uniqueness: true, allow_nil: true
      validates :account_balance, numericality: { only_integer: true }, allow_nil: true

    end

    def generate_password
      self.password = Devise.friendly_token.first(8)
    end

    private

    def update_stripe_customer
      UpdateCustomer.call(self)
    end

    def delete_stripe_customer
      DeleteCustomer.call(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tang-0.0.1 app/models/concerns/tang/customer.rb