hummingbird-me/kitsu-server

View on GitHub
app/models/pro_subscription.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
90%
class ProSubscription < ApplicationRecord
  class NoCancellationError < StandardError; end

  belongs_to :user, required: true
  enum tier: {
    pro: 1,
    patron: 2
  }

  validates :type, presence: true
  validates :billing_id, presence: true
  validates :tier, presence: true

  def cancel!
    raise NoCancellationError
  end

  def to_json(*args)
    {
      user: user_id,
      service: billing_service,
      tier: tier
    }.to_json(*args)
  end
end