-
Notifications
You must be signed in to change notification settings - Fork 313
Fix new subscriptions #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,22 +18,12 @@ class Teams::Account < ActiveRecord::Base | |
has_many :plans, through: :account_plans | ||
belongs_to :admin, class_name: 'User' | ||
|
||
validates :team_id, presence: true, uniqueness: true | ||
validates_presence_of :stripe_card_token | ||
validates_presence_of :stripe_customer_token | ||
validates :team_id, presence: true, uniqueness: true | ||
|
||
attr_protected :stripe_customer_token, :admin_id | ||
|
||
validate :stripe_customer_token, presence: true | ||
validate :stripe_card_token, presence: true | ||
validate :admin_id, :payer_is_team_admin | ||
|
||
def payer_is_team_admin | ||
if admin_id.nil? #or !team.admin?(admin) | ||
errors.add(:admin_id, "must be team admin to create an account") | ||
end | ||
end | ||
|
||
def subscribe_to!(plan, force=false) | ||
self.plan_ids = [plan.id] | ||
if force || update_on_stripe(plan) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can drop admin_id There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a change that should be made in #463. It'll involve modifying the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
@@ -46,10 +36,10 @@ def subscribe_to!(plan, force=false) | |
end | ||
|
||
def save_with_payment(plan=nil) | ||
if valid? | ||
if stripe_card_token | ||
create_customer unless plan.try(:one_time?) | ||
subscribe_to!(plan) unless plan.nil? | ||
team.save! | ||
save! | ||
return true | ||
else | ||
return false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about
validate :stripe_customer_token, presence: true , if: ->(r){r.state == 'active'}
we need a migration to add add this field :string, default: 'pending'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that unnecessary? As far as I understand - Teams who haven't paid, don't have Accounts/Plans. We only create Accounts/Plans for teams who are paying customers, so a vanilla
presence
validation makes sense.The only way I see a team going to an inactive state, is if they decided to cancel their subscription, in which case they should be moved to the free plan. In that case, they'll still have the old
stripe_customer_token
, so our validation still holds.