disable and use same result for error and success

This commit is contained in:
Rimian Perkins 2017-03-06 12:34:03 +11:00
parent 66b15be4d8
commit 736146854b
3 changed files with 8 additions and 15 deletions

View File

@ -3,7 +3,6 @@ import { getRegister } from 'discourse-common/lib/get-owner';
export default Ember.Component.extend({
donateAmounts: [1, 5, 10, 25],
error_message: null,
result: null,
amount: null,
stripe: null,
@ -29,26 +28,24 @@ export default Ember.Component.extend({
submitStripeCard() {
var self = this;
this.get('stripe').createToken(this.get('card')).then(function(result) {
this.get('stripe').createToken(this.get('card')).then(data => {
self.set('result', null);
if (result.error) {
self.set('error_message', result.error.message);
if (data.error) {
self.set('result', data.error.message);
}
else {
self.set('transactionInProgress', true);
var params = {
stripeToken: result.token.id,
stripeToken: data.token.id,
amount: self.get('amount') * 100
};
ajax('/charges', { data: params, method: 'post' }).then(data => {
self.set('transactionInProgress', false);
self.set('result', (data.status == 'succeeded' ? true : null));
}).catch((data) => {
console.log('catch', data);
self.set('result', data.outcome.seller_message);
});
}
});

View File

@ -14,7 +14,7 @@
<div class="control-group save-button">
<div class="controls">
{{#d-button action="submitStripeCard" class="btn btn-primary btn-payment"}}
{{#d-button action="submitStripeCard" disabled=transactionInProgress class="btn btn-primary btn-payment"}}
{{i18n 'discourse_donations.submit'}}
{{/d-button}}
@ -22,12 +22,8 @@
{{loading-spinner size="small"}}
{{/if}}
{{#if error_message}}
<span class="error">{{error_message}}</span>
{{/if}}
{{#if result}}
<span>{{i18n 'discourse_donations.success'}}</span>
<span>{{result}}</span>
{{/if}}
</div>
</div>

View File

@ -1,6 +1,6 @@
# name: discourse-donations
# about: Integrating Discourse with Stripe for donations
# version: 1.7.2
# version: 1.7.3
# url: https://github.com/choiceaustralia/discourse-donations
# authors: Rimian Perkins