Skip to content

Commit

Permalink
Make Stripe OAuth functional in event wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeepgangwar committed Jun 13, 2018
1 parent 7d23f7d commit 5ca45de
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 15 deletions.
19 changes: 19 additions & 0 deletions app/components/forms/wizard/basic-details-step.js
Expand Up @@ -11,11 +11,14 @@ import {
import { countries } from 'open-event-frontend/utils/dictionary/demography';
import FormMixin from 'open-event-frontend/mixins/form';
import { orderBy, filter, find } from 'lodash';
import { inject as service } from '@ember/service';

export default Component.extend(FormMixin, {

currentTimezone: moment.tz.guess(),

torii: service('torii'),

getValidationRules() {
return {
inline : true,
Expand Down Expand Up @@ -221,6 +224,19 @@ export default Component.extend(FormMixin, {
this.getForm().form('remove prompt', 'discount_code');
}),
actions: {
connectStripe() {
this.get('data.event.stripeAuthorization.content') ? '' : this.set('data.event.stripeAuthorization', this.store.createRecord('stripe-authorization'));
this.get('torii').open('stripe')
.then(authorization => {
this.set('data.event.stripeAuthorization.stripeAuthCode', authorization.authorizationCode);
})
.catch(error => {
this.get('notify').error(this.get('l10n').t(`${error.message}. Please try again`));
});
},
disconnectStripe() {
this.get('data.event.stripeAuthorization.content').destroyRecord();
},
saveDraft() {
this.onValid(() => {
this.set('data.event.state', 'draft');
Expand Down Expand Up @@ -319,5 +335,8 @@ export default Component.extend(FormMixin, {
if (!this.get('isCreate') && this.get('data.event.tax') && !this.get('data.event.tax.content')) {
this.set('data.event.tax', this.store.createRecord('tax'));
}
if (!this.get('isCreate') && this.get('data.event.stripeAuthorization') && !this.get('data.event.stripeAuthorization.content')) {
this.set('data.event.stripeAuthorization', this.store.createRecord('stripe-authorization'));
}
}
});
21 changes: 19 additions & 2 deletions app/controllers/create.js
Expand Up @@ -3,6 +3,7 @@ import RSVP from 'rsvp';
import EventWizardMixin from 'open-event-frontend/mixins/event-wizard';

export default Controller.extend(EventWizardMixin, {

actions: {
save() {
this.set('isLoading', true);
Expand All @@ -20,12 +21,20 @@ export default Controller.extend(EventWizardMixin, {
}
if (this.get('model.data.event.tax.name')) {
let tax = this.setRelationship(this.get('model.data.event.tax.content'), data);
if (this.get('model.event.isTaxEnabled')) {
if (this.get('model.data.event.isTaxEnabled')) {
promises.push(tax.save());
} else {
promises.push(tax.destroyRecord());
}
}
if (this.get('model.data.event.stripeAuthorization.stripeAuthCode')) {
let stripeAuthorization = this.setRelationship(this.get('model.data.event.stripeAuthorization.content'), data);
if (this.get('model.data.event.canPayByStripe')) {
promises.push(stripeAuthorization.save());
} else {
promises.push(stripeAuthorization.destroyRecord());
}
}
RSVP.Promise.all(promises)
.then(() => {
this.set('isLoading', false);
Expand Down Expand Up @@ -56,12 +65,20 @@ export default Controller.extend(EventWizardMixin, {
}
if (this.get('model.data.event.tax.name')) {
let tax = this.setRelationship(this.get('model.data.event.tax.content'), data);
if (this.get('model.event.isTaxEnabled')) {
if (this.get('model.data.event.isTaxEnabled')) {
promises.push(tax.save());
} else {
promises.push(tax.destroyRecord());
}
}
if (this.get('model.data.event.stripeAuthorization.stripeAuthCode')) {
let stripeAuthorization = this.setRelationship(this.get('model.data.event.stripeAuthorization.content'), data);
if (this.get('model.data.event.canPayByStripe')) {
promises.push(stripeAuthorization.save());
} else {
promises.push(stripeAuthorization.destroyRecord());
}
}
RSVP.Promise.all(promises)
.then(() => {
this.set('isLoading', false);
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/events/view/edit/basic-details.js
Expand Up @@ -20,6 +20,13 @@ export default Controller.extend({
promises.push(this.get('model.event.tax').then(tax => tax.destroyRecord()));
}
}
if (this.get('model.event.stripeAuthorization.stripeAuthCode')) {
if (this.get('model.event.canPayByStripe')) {
promises.push(this.get('model.event.stripeAuthorization.content').save());
} else {
promises.push(this.get('model.event.stripeAuthorization.content').destroyRecord());
}
}
RSVP.Promise.all(promises)
.then(() => {
this.set('isLoading', false);
Expand Down Expand Up @@ -51,6 +58,13 @@ export default Controller.extend({
promises.push(this.get('model.event.tax').then(tax => tax.destroyRecord()));
}
}
if (this.get('model.event.stripeAuthorization.stripeAuthCode')) {
if (this.get('model.event.canPayByStripe')) {
promises.push(this.get('model.event.stripeAuthorization.content').save());
} else {
promises.push(this.get('model.event.stripeAuthorization.content').destroyRecord());
}
}
RSVP.Promise.all(promises)
.then(() => {
this.set('isLoading', false);
Expand Down
1 change: 1 addition & 0 deletions app/models/event.js
Expand Up @@ -100,6 +100,7 @@ export default ModelBase.extend(CustomPrimaryKeyMixin, {
speakers : hasMany('speaker'),
invoice : hasMany('event-invoice'),
speakersCall : belongsTo('speakers-call'),
stripeAuthorization : belongsTo('stripe-authorization'),
eventStatisticsGeneral : belongsTo('event-statistics-general'),
tax : belongsTo('tax'),
copyright : belongsTo('event-copyright'),
Expand Down
9 changes: 2 additions & 7 deletions app/models/stripe.js → app/models/stripe-authorization.js
Expand Up @@ -3,13 +3,8 @@ import ModelBase from 'open-event-frontend/models/base';
import { belongsTo } from 'ember-data/relationships';

export default ModelBase.extend({
stripeSecretKey : attr('string'),
stripeRefreshToken : attr('string'),
stripeAuthCode : attr('string'),
stripePublishableKey : attr('string'),
stripeUserId : attr('string'),
stripeEmail : attr('string'),

event: belongsTo('event'),

linked: false
event: belongsTo('event')
});
7 changes: 4 additions & 3 deletions app/routes/create.js
Expand Up @@ -10,9 +10,10 @@ export default Route.extend(AuthenticatedRouteMixin, EventWizardMixin, {
return {
data: {
event: this.store.createRecord('event', {
socialLinks : [],
tax : this.store.createRecord('tax'),
copyright : this.store.createRecord('event-copyright')
socialLinks : [],
tax : this.store.createRecord('tax'),
copyright : this.store.createRecord('event-copyright'),
stripeAuthorization : this.store.createRecord('stripe-authorization')
}),
types: this.store.query('event-type', {
sort: 'name'
Expand Down
2 changes: 1 addition & 1 deletion app/routes/events/view.js
Expand Up @@ -7,7 +7,7 @@ export default Route.extend({

model(params) {
return this.store.findRecord('event', params.event_id, {
include: 'event-topic,event-sub-topic,event-type,event-copyright,tax'
include: 'event-topic,event-sub-topic,event-type,event-copyright,tax,stripe-authorization'
});
}
});
9 changes: 7 additions & 2 deletions app/templates/components/forms/wizard/basic-details-step.hbs
Expand Up @@ -317,8 +317,13 @@
</div>
{{#if data.event.canPayByStripe}}
<div class="field">
<label class="required">{{t 'Connect to your Stripe account'}}</label>
<a href="#" class="stripe-connect"><span>{{t 'Connect with Stripe'}}</span></a>
{{#if (or data.event.stripeAuthorization.stripeAuthCode data.event.stripeAuthorization.stripePublishableKey)}}
<label class="required">{{t 'You have linked your Stripe account successfully. Click Here to Disconnect you account.'}}</label>
<a class="stripe-connect" role="button" {{action 'disconnectStripe'}}><span>{{t 'Disconnect Stripe Account'}}</span></a>
{{else}}
<label class="required">{{t 'Connect to your Stripe account'}}</label>
<a class="stripe-connect" role="button" {{action 'connectStripe'}}><span>{{t 'Connect with Stripe'}}</span></a>
{{/if}}
</div>
{{/if}}
{{/if}}
Expand Down
14 changes: 14 additions & 0 deletions app/torii-providers/stripe.js
@@ -0,0 +1,14 @@
import stripeConnect from 'torii/providers/stripe-connect';
import { alias } from '@ember/object/computed';
import { inject } from '@ember/service';
import { configurable } from 'torii/configuration';

export default stripeConnect.extend({
settings: inject(),

clientId: alias('settings.stripeClientId'),

redirectUri: configurable('redirectUri', function() {
return `${window.location.origin}/torii/redirect.html`;
})
});
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -100,6 +100,7 @@
"qunit-dom": "^0.6.3",
"sanitize-html": "^1.14.1",
"semantic-ui-ember": "^3.0.3",
"torii": "^0.10.1",
"url-parse": "^1.4.1",
"xgettext-template": "^3.4.0"
},
Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Expand Up @@ -9080,6 +9080,12 @@ to-regex@^3.0.1, to-regex@^3.0.2:
regex-not "^1.0.2"
safe-regex "^1.1.0"

torii@^0.10.1:
version "0.10.1"
resolved "https://registry.yarnpkg.com/torii/-/torii-0.10.1.tgz#caad0a81e82189fc0483b65e68ee28041ad3590f"
dependencies:
ember-cli-babel "^6.11.0"

tough-cookie@~2.3.0, tough-cookie@~2.3.3:
version "2.3.4"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655"
Expand Down

0 comments on commit 5ca45de

Please sign in to comment.