hummingbird-me/kitsu-server

View on GitHub
app/models/pro_subscription/stripe_subscription.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
class ProSubscription
  class StripeSubscription < ProSubscription
    def billing_service
      :stripe
    end

    def subscription
      @subscription ||= Stripe::Subscription.retrieve(billing_id)
    end

    alias_method :cancel!, :destroy!

    after_destroy do
      subscription.delete
    end

    before_validation on: :create do
      self.billing_id = Stripe::Subscription.create(
        customer: user.stripe_customer.id,
        items: [{ plan: "#{tier}-yearly" }]
      ).id
    end
  end
end