Class: SubscriptionBuilder
- Inherits:
-
Object
- Object
- SubscriptionBuilder
- Defined in:
- lib/subscription_builder.rb
Instance Attribute Summary collapse
-
#coupon ⇒ Object
Returns the value of attribute coupon.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
-
#plan ⇒ Object
Returns the value of attribute plan.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#skip_trial ⇒ Object
Returns the value of attribute skip_trial.
-
#trial_days ⇒ Object
Returns the value of attribute trial_days.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #add(options = {}) ⇒ Object
- #create(token = nil, options = {}) ⇒ Object
-
#initialize(user, name, plan, *args) ⇒ SubscriptionBuilder
constructor
A new instance of SubscriptionBuilder.
Constructor Details
#initialize(user, name, plan, *args) ⇒ SubscriptionBuilder
Returns a new instance of SubscriptionBuilder.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/subscription_builder.rb', line 6 def initialize(user, name, plan, *args) @user = user @name = name @plan = plan if args[0] set_instance_vars_for_args(args[0]) else @trial_days = 0 @quantity = 1 @skip_trial = false end end |
Instance Attribute Details
#coupon ⇒ Object
Returns the value of attribute coupon.
3 4 5 |
# File 'lib/subscription_builder.rb', line 3 def coupon @coupon end |
#metadata ⇒ Object
Returns the value of attribute metadata.
3 4 5 |
# File 'lib/subscription_builder.rb', line 3 def end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/subscription_builder.rb', line 2 def name @name end |
#plan ⇒ Object
Returns the value of attribute plan.
2 3 4 |
# File 'lib/subscription_builder.rb', line 2 def plan @plan end |
#quantity ⇒ Object
Returns the value of attribute quantity.
3 4 5 |
# File 'lib/subscription_builder.rb', line 3 def quantity @quantity end |
#skip_trial ⇒ Object
Returns the value of attribute skip_trial.
4 5 6 |
# File 'lib/subscription_builder.rb', line 4 def skip_trial @skip_trial end |
#trial_days ⇒ Object
Returns the value of attribute trial_days.
4 5 6 |
# File 'lib/subscription_builder.rb', line 4 def trial_days @trial_days end |
#user ⇒ Object
Returns the value of attribute user.
2 3 4 |
# File 'lib/subscription_builder.rb', line 2 def user @user end |
Instance Method Details
#add(options = {}) ⇒ Object
19 20 21 |
# File 'lib/subscription_builder.rb', line 19 def add( = {}) create(nil, ) end |
#create(token = nil, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/subscription_builder.rb', line 23 def create(token = nil, = {}) customer = get_stripe_customer(token, ) stripe_subscription = customer.subscriptions.create(pay_load) if skip_trial trial_ends_at = nil else trial_ends_at = trial_days ? trial_days.days.from_now.to_time.to_i : nil end user.subscriptions.create( name: name, stripe_id: stripe_subscription.id, stripe_plan: plan, quantity: quantity, trial_ends_at: trial_ends_at ) end |