fix var scope error and diplay some html when result is success
This commit is contained in:
parent
9ed1af4538
commit
72fcb324cd
|
@ -1,6 +1,7 @@
|
||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
|
result: null,
|
||||||
stripe: Stripe('pk_test_b8RmhzlL8QPizJRqOrKF3JEV'),
|
stripe: Stripe('pk_test_b8RmhzlL8QPizJRqOrKF3JEV'),
|
||||||
|
|
||||||
card: function() {
|
card: function() {
|
||||||
|
@ -9,25 +10,31 @@ export default Ember.Component.extend({
|
||||||
}.property('stripe'),
|
}.property('stripe'),
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
|
this._super();
|
||||||
this.get('card').mount('#card-element');
|
this.get('card').mount('#card-element');
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
submitStripeCard() {
|
submitStripeCard() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
this.get('stripe').createToken(this.get('card')).then(function(result) {
|
this.get('stripe').createToken(this.get('card')).then(function(result) {
|
||||||
|
|
||||||
|
self.set('result', null);
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
console.log('error yo');
|
console.log('error yo');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var data = {
|
var params = {
|
||||||
stripeToken: result.token.id,
|
stripeToken: result.token.id,
|
||||||
amount: 1234
|
amount: 1234
|
||||||
};
|
};
|
||||||
|
|
||||||
ajax('/charges', { data: data, method: 'post' }).then(data => {
|
ajax('/charges', { data: params, method: 'post' }).then(data => {
|
||||||
console.log(data);
|
self.set('result', (data.status == 'succeeded' ? true : null));
|
||||||
}).catch(() => {
|
}).catch((data) => {
|
||||||
console.log('error');
|
console.log('catch', data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,4 +5,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button {{action "submitStripeCard"}}>Submit Payment</button>
|
<button {{action "submitStripeCard"}}>Submit Payment</button>
|
||||||
|
|
||||||
|
{{#if result}}
|
||||||
|
<div class="stripe-card-result">payment happened</div>
|
||||||
|
{{/if}}
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue