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 @@
{{input type="email" value=billing.email}} -
{{i18n 'discourse_patrons.payment.email_info'}}
+
{{i18n 'discourse_patrons.payment.receipt_info'}}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index c4c76af..296e1fa 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -19,6 +19,7 @@ en: success: Thank you! payment: optional: Optional + receipt_info: A receipt is sent to this email address your_information: Your information payment_information: Payment information payment_confirmation: Confirm information @@ -26,7 +27,6 @@ en: billing: name: Full name email: Email - email_info: A receipt is sent to this email address phone: Phone Number confirmation: amount: Amount diff --git a/spec/controllers/discourse_patrons/patrons_controller_spec.rb b/spec/controllers/discourse_patrons/patrons_controller_spec.rb index e3455c5..2ab8ec8 100644 --- a/spec/controllers/discourse_patrons/patrons_controller_spec.rb +++ b/spec/controllers/discourse_patrons/patrons_controller_spec.rb @@ -57,6 +57,12 @@ module DiscoursePatrons expect(response).to have_http_status(200) end + it 'has a receipt email' do + ::Stripe::PaymentIntent.expects(:create).with(has_entry(:receipt_email, 'hello@example.com')) + post :create, params: { receiptEmail: 'hello@example.com' }, format: :json + expect(response).to have_http_status(200) + end + it 'has a description' do SiteSetting.stubs(:discourse_patrons_payment_description).returns('hello-world') ::Stripe::PaymentIntent.expects(:create).with(has_entry(:description, 'hello-world'))