diff --git a/app/controllers/discourse_donations/charges_controller.rb b/app/controllers/discourse_donations/charges_controller.rb index e151a34..8865871 100644 --- a/app/controllers/discourse_donations/charges_controller.rb +++ b/app/controllers/discourse_donations/charges_controller.rb @@ -8,13 +8,13 @@ module DiscourseDonations def create 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? - response = {'messages' => 'Please enter a username'} + response = {'messages' => ['Please enter a username']} else payment = DiscourseDonations::Stripe.new(secret_key, stripe_options) response = payment.charge(email, params) - response['messages'] = response['outcome']['seller_message'] + response['messages'] = [response['outcome']['seller_message']] end response['rewards'] = [] diff --git a/assets/javascripts/discourse/components/stripe-card.js.es6 b/assets/javascripts/discourse/components/stripe-card.js.es6 index b116bfe..e3a1063 100644 --- a/assets/javascripts/discourse/components/stripe-card.js.es6 +++ b/assets/javascripts/discourse/components/stripe-card.js.es6 @@ -10,7 +10,7 @@ export default Ember.Component.extend({ { value: 20, name: '$20.00'}, { value: 50, name: '$50.00'} ], - result: null, + result: [], amount: null, stripe: null, transactionInProgress: null, @@ -44,6 +44,10 @@ export default Ember.Component.extend({ this.set('transactionInProgress', false); }, + concatMessages(messages) { + this.set('result', this.get('result').concat(messages)); + }, + createUser() { let self = this; ajax('/users/hp', { method: 'get' }).then(data => { @@ -58,7 +62,7 @@ export default Ember.Component.extend({ ajax('/users', { data: params, method: 'post' }).then(data => { self.setSuccess(); - self.set('result', self.get('result') + data.messages); + self.concatMessages(data.messages); self.endTranscation(); }); }); @@ -70,7 +74,7 @@ export default Ember.Component.extend({ this.get('stripe').createToken(this.get('card')).then(data => { - self.set('result', ''); + self.set('result', []); if (data.error) { self.set('result', data.error.message); @@ -88,7 +92,7 @@ export default Ember.Component.extend({ if(!self.get('paymentSuccess')) { ajax('/charges', { data: params, method: 'post' }).then(data => { - self.set('result', data.messages); + self.concatMessages(data.messages); if(!this.get('create_accounts')) { if(data.status == 'succeeded') { this.setSuccess() }; @@ -105,7 +109,7 @@ export default Ember.Component.extend({ }); } else if (this.get('create_accounts')) { - self.set('result', ''); + self.set('result', []); self.createUser(); } } diff --git a/assets/javascripts/discourse/templates/components/stripe-card.hbs b/assets/javascripts/discourse/templates/components/stripe-card.hbs index 674077d..c9a8405 100644 --- a/assets/javascripts/discourse/templates/components/stripe-card.hbs +++ b/assets/javascripts/discourse/templates/components/stripe-card.hbs @@ -60,9 +60,11 @@ {{#if transactionInProgress}} {{loading-spinner size="small"}} {{/if}} - {{#if result}} -

{{{result}}}

- {{/if}} + + {{#each result as |message|}} +

{{{message}}}

+ {{/each}} + {{#if success}}

{{i18n 'discourse_donations.messages.success'}}

{{/if}} diff --git a/spec/controllers/discourse_donations/charges_controller_spec.rb b/spec/controllers/discourse_donations/charges_controller_spec.rb index 8b7af3d..87a8fb3 100644 --- a/spec/controllers/discourse_donations/charges_controller_spec.rb +++ b/spec/controllers/discourse_donations/charges_controller_spec.rb @@ -14,32 +14,32 @@ module DiscourseDonations it 'responds ok for anonymous users' do 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) end it 'responds ok when the email is empty' do 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) end it 'responds ok when the email is empty' do 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) end it 'expects a username if accounts are being created' do 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) end it 'does not expect a username or email if accounts are not being created' do current_user = log_in(:coding_horror) 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) end