messages are an array
This commit is contained in:
parent
c80a003922
commit
256b44ad60
|
@ -8,13 +8,13 @@ module DiscourseDonations
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if create_account && (email.nil? || email.empty?)
|
if create_account && (email.nil? || email.empty?)
|
||||||
response = {'messages' => 'Please enter your email address'}
|
response = {'messages' => ['Please enter your email address']}
|
||||||
elsif create_account && params[:username].nil?
|
elsif create_account && params[:username].nil?
|
||||||
response = {'messages' => 'Please enter a username'}
|
response = {'messages' => ['Please enter a username']}
|
||||||
else
|
else
|
||||||
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
|
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
|
||||||
response = payment.charge(email, params)
|
response = payment.charge(email, params)
|
||||||
response['messages'] = response['outcome']['seller_message']
|
response['messages'] = [response['outcome']['seller_message']]
|
||||||
end
|
end
|
||||||
|
|
||||||
response['rewards'] = []
|
response['rewards'] = []
|
||||||
|
|
|
@ -10,7 +10,7 @@ export default Ember.Component.extend({
|
||||||
{ value: 20, name: '$20.00'},
|
{ value: 20, name: '$20.00'},
|
||||||
{ value: 50, name: '$50.00'}
|
{ value: 50, name: '$50.00'}
|
||||||
],
|
],
|
||||||
result: null,
|
result: [],
|
||||||
amount: null,
|
amount: null,
|
||||||
stripe: null,
|
stripe: null,
|
||||||
transactionInProgress: null,
|
transactionInProgress: null,
|
||||||
|
@ -44,6 +44,10 @@ export default Ember.Component.extend({
|
||||||
this.set('transactionInProgress', false);
|
this.set('transactionInProgress', false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
concatMessages(messages) {
|
||||||
|
this.set('result', this.get('result').concat(messages));
|
||||||
|
},
|
||||||
|
|
||||||
createUser() {
|
createUser() {
|
||||||
let self = this;
|
let self = this;
|
||||||
ajax('/users/hp', { method: 'get' }).then(data => {
|
ajax('/users/hp', { method: 'get' }).then(data => {
|
||||||
|
@ -58,7 +62,7 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
ajax('/users', { data: params, method: 'post' }).then(data => {
|
ajax('/users', { data: params, method: 'post' }).then(data => {
|
||||||
self.setSuccess();
|
self.setSuccess();
|
||||||
self.set('result', self.get('result') + data.messages);
|
self.concatMessages(data.messages);
|
||||||
self.endTranscation();
|
self.endTranscation();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -70,7 +74,7 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
this.get('stripe').createToken(this.get('card')).then(data => {
|
this.get('stripe').createToken(this.get('card')).then(data => {
|
||||||
|
|
||||||
self.set('result', '');
|
self.set('result', []);
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
self.set('result', data.error.message);
|
self.set('result', data.error.message);
|
||||||
|
@ -88,7 +92,7 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
if(!self.get('paymentSuccess')) {
|
if(!self.get('paymentSuccess')) {
|
||||||
ajax('/charges', { data: params, method: 'post' }).then(data => {
|
ajax('/charges', { data: params, method: 'post' }).then(data => {
|
||||||
self.set('result', data.messages);
|
self.concatMessages(data.messages);
|
||||||
|
|
||||||
if(!this.get('create_accounts')) {
|
if(!this.get('create_accounts')) {
|
||||||
if(data.status == 'succeeded') { this.setSuccess() };
|
if(data.status == 'succeeded') { this.setSuccess() };
|
||||||
|
@ -105,7 +109,7 @@ export default Ember.Component.extend({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (this.get('create_accounts')) {
|
else if (this.get('create_accounts')) {
|
||||||
self.set('result', '');
|
self.set('result', []);
|
||||||
self.createUser();
|
self.createUser();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,9 +60,11 @@
|
||||||
{{#if transactionInProgress}}
|
{{#if transactionInProgress}}
|
||||||
{{loading-spinner size="small"}}
|
{{loading-spinner size="small"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if result}}
|
|
||||||
<p>{{{result}}}</p>
|
{{#each result as |message|}}
|
||||||
{{/if}}
|
<p>{{{message}}}</p>
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
{{#if success}}
|
{{#if success}}
|
||||||
<p>{{i18n 'discourse_donations.messages.success'}}</p>
|
<p>{{i18n 'discourse_donations.messages.success'}}</p>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -14,32 +14,32 @@ module DiscourseDonations
|
||||||
|
|
||||||
it 'responds ok for anonymous users' do
|
it 'responds ok for anonymous users' do
|
||||||
post :create, { email: 'foobar@example.com' }
|
post :create, { email: 'foobar@example.com' }
|
||||||
expect(body['messages']).to eq(body['outcome']['seller_message'])
|
expect(body['messages']).to include(body['outcome']['seller_message'])
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'responds ok when the email is empty' do
|
it 'responds ok when the email is empty' do
|
||||||
post :create, { create_account: 'true', email: '' }
|
post :create, { create_account: 'true', email: '' }
|
||||||
expect(body['messages']).to eq('Please enter your email address')
|
expect(body['messages']).to include('Please enter your email address')
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'responds ok when the email is empty' do
|
it 'responds ok when the email is empty' do
|
||||||
post :create, { create_account: 'true' }
|
post :create, { create_account: 'true' }
|
||||||
expect(body['messages']).to eq('Please enter your email address')
|
expect(body['messages']).to include('Please enter your email address')
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'expects a username if accounts are being created' do
|
it 'expects a username if accounts are being created' do
|
||||||
post :create, { email: 'zipitydoodah@example.com', create_account: 'true' }
|
post :create, { email: 'zipitydoodah@example.com', create_account: 'true' }
|
||||||
expect(body['messages']).to eq('Please enter a username')
|
expect(body['messages']).to include('Please enter a username')
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not expect a username or email if accounts are not being created' do
|
it 'does not expect a username or email if accounts are not being created' do
|
||||||
current_user = log_in(:coding_horror)
|
current_user = log_in(:coding_horror)
|
||||||
post :create, { create_account: 'false' }
|
post :create, { create_account: 'false' }
|
||||||
expect(body['messages']).to eq('Payment complete.')
|
expect(body['messages']).to include('Payment complete.')
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue