Class: CoreMerchant::SubscriptionPlan

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/core_merchant/subscription_plan.rb

Overview

Represents a subscription plan in CoreMerchant. Subscription plans are used to define the pricing and features of a subscription. All prices are in cents.

Attributes:

  • ‘name_key`: A unique key for the subscription plan.

    This key is used to identify the plan in the application,
    as well as the translation key for the plan name through `core_merchant.subscription_plans`.
    
  • ‘price_cents`: The price of the subscription plan in cents.

  • ‘duration`: The duration of the subscription plan.

    Consists of a number and a letter representing the time unit as day, week, month, or year.
    For example, `1w` for 1 week, `3m` for 3 months, `1y` for 1 year.
    
  • ‘introductory_price_cents`: The introductory price of the subscription plan in cents.

  • ‘introductory_duration`: The duration of the introductory price of the subscription plan.

Usage:

```
 plan = CoreMerchant::SubscriptionPlan.new(name_key: "basic_monthly", price_cents: 7_99)
 plan.save
```

Instance Method Summary collapse

Instance Method Details

#duration_in_dateObject



48
49
50
# File 'lib/core_merchant/subscription_plan.rb', line 48

def duration_in_date
  date_from_duration(duration)
end

#introductory_duration_in_dateObject



52
53
54
# File 'lib/core_merchant/subscription_plan.rb', line 52

def introductory_duration_in_date
  date_from_duration(introductory_duration) if introductory_duration
end

#introductory_priceObject



44
45
46
# File 'lib/core_merchant/subscription_plan.rb', line 44

def introductory_price
  introductory_price_cents / 100.0 if introductory_price_cents
end

#nameObject



36
37
38
# File 'lib/core_merchant/subscription_plan.rb', line 36

def name
  I18n.t(name_key, scope: "core_merchant.subscription_plans", default: name_key.humanize)
end

#priceObject



40
41
42
# File 'lib/core_merchant/subscription_plan.rb', line 40

def price
  price_cents / 100.0
end

#to_sObject



56
57
58
# File 'lib/core_merchant/subscription_plan.rb', line 56

def to_s
  "#{name} - #{price}"
end