disable and use same result for error and success
This commit is contained in:
parent
66b15be4d8
commit
736146854b
|
@ -3,7 +3,6 @@ import { getRegister } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
donateAmounts: [1, 5, 10, 25],
|
donateAmounts: [1, 5, 10, 25],
|
||||||
error_message: null,
|
|
||||||
result: null,
|
result: null,
|
||||||
amount: null,
|
amount: null,
|
||||||
stripe: null,
|
stripe: null,
|
||||||
|
@ -29,26 +28,24 @@ export default Ember.Component.extend({
|
||||||
submitStripeCard() {
|
submitStripeCard() {
|
||||||
var self = this;
|
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);
|
self.set('result', null);
|
||||||
|
|
||||||
if (result.error) {
|
if (data.error) {
|
||||||
self.set('error_message', result.error.message);
|
self.set('result', data.error.message);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.set('transactionInProgress', true);
|
self.set('transactionInProgress', true);
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
stripeToken: result.token.id,
|
stripeToken: data.token.id,
|
||||||
amount: self.get('amount') * 100
|
amount: self.get('amount') * 100
|
||||||
};
|
};
|
||||||
|
|
||||||
ajax('/charges', { data: params, method: 'post' }).then(data => {
|
ajax('/charges', { data: params, method: 'post' }).then(data => {
|
||||||
self.set('transactionInProgress', false);
|
self.set('transactionInProgress', false);
|
||||||
self.set('result', (data.status == 'succeeded' ? true : null));
|
self.set('result', data.outcome.seller_message);
|
||||||
}).catch((data) => {
|
|
||||||
console.log('catch', data);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
<div class="control-group save-button">
|
<div class="control-group save-button">
|
||||||
<div class="controls">
|
<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'}}
|
{{i18n 'discourse_donations.submit'}}
|
||||||
{{/d-button}}
|
{{/d-button}}
|
||||||
|
|
||||||
|
@ -22,12 +22,8 @@
|
||||||
{{loading-spinner size="small"}}
|
{{loading-spinner size="small"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if error_message}}
|
|
||||||
<span class="error">{{error_message}}</span>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
{{#if result}}
|
{{#if result}}
|
||||||
<span>{{i18n 'discourse_donations.success'}}</span>
|
<span>{{result}}</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# name: discourse-donations
|
# name: discourse-donations
|
||||||
# about: Integrating Discourse with Stripe for donations
|
# about: Integrating Discourse with Stripe for donations
|
||||||
# version: 1.7.2
|
# version: 1.7.3
|
||||||
# url: https://github.com/choiceaustralia/discourse-donations
|
# url: https://github.com/choiceaustralia/discourse-donations
|
||||||
# authors: Rimian Perkins
|
# authors: Rimian Perkins
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue