diff --git a/app/controllers/patrons_controller.rb b/app/controllers/patrons_controller.rb index 6b4a8c0..a45e3cd 100644 --- a/app/controllers/patrons_controller.rb +++ b/app/controllers/patrons_controller.rb @@ -25,6 +25,7 @@ module DiscoursePatrons payment_method_types: ['card'], payment_method: params[:paymentMethodId], description: SiteSetting.discourse_patrons_payment_description, + receipt_email: params[:receiptEmail], confirm: true, ) diff --git a/assets/javascripts/discourse/components/donation-form.js.es6 b/assets/javascripts/discourse/components/donation-form.js.es6 index 4438c3b..42d59cf 100644 --- a/assets/javascripts/discourse/components/donation-form.js.es6 +++ b/assets/javascripts/discourse/components/donation-form.js.es6 @@ -26,13 +26,19 @@ export default Ember.Component.extend({ this.set("confirmation", false); }, - handleConfirmStripeCard(paymentMethod) { + handleConfirmStripeCard(paymentMethod, receiptEmail) { + this.set("receiptEmail", receiptEmail); this.set("confirmation", paymentMethod); }, confirmStripeCard() { - const paymentMethodId = this.confirmation.id; - this.stripePaymentHandler(paymentMethodId, this.amount).then( + const data = { + paymentMethodId: this.confirmation.id, + amount: this.amount, + receiptEmail: this.receiptEmail + }; + + this.stripePaymentHandler(data).then( paymentIntent => { if (paymentIntent.error) { this.set("paymentError", paymentIntent.error); diff --git a/assets/javascripts/discourse/components/stripe-card.js.es6 b/assets/javascripts/discourse/components/stripe-card.js.es6 index 63a5a65..b72938a 100644 --- a/assets/javascripts/discourse/components/stripe-card.js.es6 +++ b/assets/javascripts/discourse/components/stripe-card.js.es6 @@ -62,7 +62,10 @@ export default Ember.Component.extend({ if (result.error) { this.set("cardError", result.error.message); } else { - this.handleConfirmStripeCard(result.paymentMethod); + this.handleConfirmStripeCard( + result.paymentMethod, + this.get("billing.email") + ); } }, () => { diff --git a/assets/javascripts/discourse/controllers/patrons-index.js.es6 b/assets/javascripts/discourse/controllers/patrons-index.js.es6 index 5c35e9d..628cd5d 100644 --- a/assets/javascripts/discourse/controllers/patrons-index.js.es6 +++ b/assets/javascripts/discourse/controllers/patrons-index.js.es6 @@ -3,9 +3,9 @@ import { ajax } from "discourse/lib/ajax"; export default Ember.Controller.extend({ actions: { - stripePaymentHandler(paymentMethodId, amount) { + stripePaymentHandler(data) { return ajax("/patrons/patrons", { - data: { paymentMethodId, amount }, + data, method: "post" }).catch(() => { return { error: "An error occured while submitting the form." }; diff --git a/assets/javascripts/discourse/routes/patrons.js.es6 b/assets/javascripts/discourse/routes/patrons.js.es6 index d60d670..2c3a21b 100644 --- a/assets/javascripts/discourse/routes/patrons.js.es6 +++ b/assets/javascripts/discourse/routes/patrons.js.es6 @@ -10,11 +10,13 @@ export default Discourse.Route.extend({ return ajax("/patrons/patrons", { method: "get" - }).then((result) => { - user.set('email', result.email); - return user; - }).catch(() => { - return user; - }); + }) + .then(result => { + user.set("email", result.email); + return user; + }) + .catch(() => { + return user; + }); } }); diff --git a/assets/javascripts/discourse/templates/components/donation-form.hbs b/assets/javascripts/discourse/templates/components/donation-form.hbs index 37d052e..0396a71 100644 --- a/assets/javascripts/discourse/templates/components/donation-form.hbs +++ b/assets/javascripts/discourse/templates/components/donation-form.hbs @@ -69,7 +69,7 @@