Sha256: 3b76f67733c9ea4ec6e257b1336e2d430e790b7abd2044566a26eba7db3d4a6e

Contents?: true

Size: 733 Bytes

Versions: 2

Compression:

Stored size: 733 Bytes

Contents

# frozen_string_literal: true

module Vindi
  # Customer Subscriptions
  #
  # @example Subscribe a customer to a plan
  #
  #   @subscription = Vindi::Subscription.new.tap do |s|
  #     s.customer_id = customer.id
  #     s.plan_id = plan.id
  #     s.payment_method_code = "credit_card"
  #     s.save
  #   end
  #
  class Subscription < Model
    belongs_to :customer
    belongs_to :plan

    attributes :plan_id, :customer_id, :payment_method_code

    validates :plan_id, :customer_id, :payment_method_code, presence: true

    # @example Cancel a subscription
    #
    #   @subscription = Vindi::Customer.find(1).subscriptions.active.last
    #   @subscription.cancel!
    #
    def cancel!
      destroy
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vindi-hermes-0.0.2 lib/vindi/models/subscription.rb
vindi-hermes-0.0.1 lib/vindi/models/subscription.rb