-
Notifications
You must be signed in to change notification settings - Fork 0
Change subscription #21
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
base: development
Are you sure you want to change the base?
Changes from all commits
437ea76
b472794
c18ddca
ed93fdc
0f59b9b
fee0f28
70101d1
4272c38
86a063f
1a25d9d
e598965
f54e5aa
51ce505
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 |
---|---|---|
@@ -1,11 +1,24 @@ | ||
import Ember from 'ember'; | ||
import extractError from 'teamplaybook-ember/lib/extract-error'; | ||
import ajax from 'ic-ajax'; | ||
import ENV from 'teamplaybook-ember/config/environment'; | ||
|
||
export default Ember.Controller.extend({ | ||
|
||
showError: false, | ||
errorMessage: null, | ||
cardToken: null, | ||
|
||
currentPlan: Ember.computed('model.planSlug', function (){ | ||
var plans = this.store.all('plan'); | ||
return plans.findBy('slug', this.get('model.planSlug')); | ||
}), | ||
|
||
currentPlanIsPaid: Ember.computed.alias('currentPlan.isPaid'), | ||
|
||
plans: Ember.computed(function(){ | ||
return this.store.find('plan'); | ||
}), | ||
|
||
actions: { | ||
delete: function() { | ||
|
@@ -26,6 +39,52 @@ export default Ember.Controller.extend({ | |
}); | ||
}); | ||
} | ||
}, | ||
changePlan: function(){ | ||
var controller = this; | ||
if(this.get('currentPlanIsPaid')){ | ||
this.createStripeToken().then(function(){ | ||
controller.requestPlanChange(); | ||
}); | ||
}else{ | ||
this.requestPlanChange(); | ||
} | ||
} | ||
}, | ||
|
||
_buildURL: function(path) { | ||
var apiUrl = this.get('urlInfo.apiUrl'); | ||
return apiUrl + '/' + path; | ||
}, | ||
|
||
requestPlanChange: function(){ | ||
var team = this.get('model'); | ||
|
||
ajax({ | ||
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. You just want to be able to call 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. Lets not waste time on it in this PR and get this merged though. |
||
type: 'POST', | ||
url: this._buildURL('team/change_plan'), | ||
data: { | ||
plan_slug: team.get('planSlug'), | ||
card_token: this.get('cardToken') | ||
} | ||
}).then(function(){ | ||
alert("You have changed your plan"); | ||
}, function(response){ | ||
alert(extractError(response)); | ||
}); | ||
}, | ||
|
||
createStripeToken: function(){ | ||
var Stripe = window.Stripe; | ||
Stripe.setPublishableKey(ENV.STRIPE_PUBLIC_KEY); | ||
var controller = this; | ||
var $form = Ember.$('#payment-form'); | ||
|
||
return new Ember.RSVP.Promise(function(resolve) { | ||
Stripe.card.createToken($form, function(status, response) { | ||
controller.set('cardToken', response.id); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import DS from 'ember-data'; | ||
import Ember from 'ember'; | ||
|
||
export default DS.Model.extend({ | ||
slug: DS.attr('string'), | ||
name: DS.attr('string'), | ||
trialPeriodDays: DS.attr('number'), | ||
amount: DS.attr('number'), | ||
isPaid: Ember.computed.gt('amount', 0) | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
{{/if}} | ||
</ul> | ||
</section> | ||
</nav> | ||
</nav> |
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.
This doesn't follow the what do I want principle because you just want to be able to call requestPlanChange directly.