-
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 7 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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import Ember from 'ember'; | ||
| import ajax from 'ic-ajax'; | ||
| import ENV from 'teamplaybook-ember/config/environment'; | ||
| import extractError from 'teamplaybook-ember/lib/extract-error'; | ||
|
|
||
| var $ = window.$; | ||
|
|
||
| export default Ember.Controller.extend({ | ||
| 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:{ | ||
| changePlan: function(){ | ||
| if(this.get('currentPlanIsPaid')){ | ||
| this.createStripeToken(this.requestPlanChange.bind(this)); | ||
| }else{ | ||
| this.requestPlanChange(); | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| _buildURL: function(path) { | ||
| var apiUrl = this.get('urlInfo.apiUrl'); | ||
| return apiUrl + '/' + path; | ||
| }, | ||
|
|
||
| requestPlanChange: function(){ | ||
| var team = this.get('model'); | ||
|
|
||
| ajax({ | ||
| 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(callback){ | ||
| var Stripe = window.Stripe; | ||
| Stripe.setPublishableKey(ENV.STRIPE_PUBLIC_KEY); | ||
| var controller = this; | ||
| var $form = $('#payment-form'); | ||
|
|
||
| var stripeCallback = function(status, response){ | ||
| controller.set('cardToken', response.id); | ||
| callback(); | ||
| }; | ||
| Stripe.card.createToken($form, stripeCallback); | ||
| } | ||
| }); | ||
| 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'), | ||
| trial_period_days: DS.attr('number'), | ||
|
Contributor
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. This isn't camelized. Any reason, or did it just slip through? I ask because I had issues with current user's |
||
| amount: DS.attr('number'), | ||
| isPaid: Ember.computed.gt('amount', 0) | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ export default Router.map(function() { | |
| this.route('team-members', { path: 'members' }, function() { | ||
| this.route('index', { path: '/' }); | ||
| }); | ||
| this.route('settings'); | ||
| this.route('manage'); | ||
|
||
| }); | ||
| } else if (shouldMapGeneralRoutes) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import Ember from 'ember'; | ||
| import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'; | ||
|
|
||
| export default Ember.Route.extend(AuthenticatedRouteMixin, { | ||
| model: function() { | ||
| return this.store.find('team', 'current'); | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,4 +12,4 @@ | |
| {{/if}} | ||
| </ul> | ||
| </section> | ||
| </nav> | ||
| </nav> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <script type="text/javascript" src="https://js.stripe.com/v2/"></script> | ||
|
|
||
| <h1> Setting for {{model.name}}</h1> | ||
| <h4> Your team is currently subscribed to the {{model.planName}}</h4> | ||
|
|
||
| <form> | ||
| {{#each plan in plans}} | ||
| {{radio-button | ||
| value=plan.slug | ||
| groupValue=model.planSlug | ||
| required=true | ||
| name="plan"}} | ||
| {{plan.name}} | ||
| {{/each}} | ||
| </form> | ||
|
|
||
| {{#if currentPlanIsPaid}} | ||
|
|
||
| <h3>This is a paid plan, add your credit card information</h3> | ||
|
|
||
| <form action="" method="POST" id="payment-form"> | ||
| <!-- Add a section to display errors if you want --> | ||
| <span class='payment-errors'></span> | ||
| <label>Card Number</label> | ||
| <input data-stripe="number"/> | ||
| <label>CVC</label> | ||
| <input data-stripe="cvc"/> | ||
| <label>Card Expiration Month</label> | ||
| <input data-stripe="exp-month"/> | ||
| <label>Card Expiration Year</label> | ||
| <input data-stripe="exp-year"/> | ||
| </form> | ||
| {{/if}} | ||
| <button {{action 'changePlan'}}>Change plan</button> |
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.
Would this work here?
Then in the
createPlanaction, you could haveor
, whichever works.
Also, if you move the form and related logic to a component, I think it would be more nicely abstracted, though I think something like that is big enough for a refactor task of it's own.