discourse-subscriptions/assets/javascripts/discourse/components/donation-form.js.es6

51 lines
1.2 KiB
Plaintext
Raw Normal View History

2019-09-11 06:19:50 -04:00
import { default as computed } from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend({
@computed("confirmation.card.last4")
last4() {
return this.get("confirmation.card.last4");
},
init() {
this._super(...arguments);
const settings = Discourse.SiteSettings;
2019-10-09 22:52:55 -04:00
const amounts = settings.discourse_patrons_amounts.split("|");
2019-09-11 06:19:50 -04:00
this.setProperties({
confirmation: false,
2019-09-11 21:21:27 -04:00
currency: settings.discourse_donations_currency,
amounts,
amount: amounts[0]
2019-09-11 06:19:50 -04:00
});
},
actions: {
closeModal() {
2019-09-11 17:14:16 -04:00
this.set("paymentError", false);
this.set("confirmation", false);
2019-09-11 06:19:50 -04:00
},
2019-09-12 23:46:32 -04:00
handleConfirmStripeCard(paymentMethod, receiptEmail) {
this.set("receiptEmail", receiptEmail);
2019-09-11 17:14:16 -04:00
this.set("confirmation", paymentMethod);
2019-09-11 06:19:50 -04:00
},
confirmStripeCard() {
2019-09-12 23:46:32 -04:00
const data = {
2019-09-13 00:34:06 -04:00
payment_method_id: this.confirmation.id,
2019-09-12 23:46:32 -04:00
amount: this.amount,
2019-09-13 00:34:06 -04:00
receipt_email: this.receiptEmail
2019-09-12 23:46:32 -04:00
};
2019-09-12 23:52:41 -04:00
this.stripePaymentHandler(data).then(paymentIntent => {
if (paymentIntent.error) {
this.set("paymentError", paymentIntent.error);
} else {
2019-09-14 04:31:11 -04:00
this.paymentSuccessHandler(paymentIntent.id);
2019-09-11 06:19:50 -04:00
}
2019-09-12 23:52:41 -04:00
});
2019-09-11 17:14:16 -04:00
}
}
2019-09-11 06:19:50 -04:00
});