From b83da467d03c6922c9e777805e2bbaccd2818785 Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Tue, 14 Jan 2020 18:46:48 +1100 Subject: [PATCH] respond to incomplete payment --- README.md | 30 ++++++++++++++----- app/controllers/hooks_controller.rb | 6 ++-- .../discourse/controllers/s-show.js.es6 | 11 +++++-- config/locales/client.en.yml | 2 ++ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 326b7d4..e999c23 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,16 @@ See [Screenshots](#screenshots) below. * Be sure your site is enforcing https. * Follow the install instructions here: https://meta.discourse.org/t/install-a-plugin/19157 -* Add your Stripe public and private keys in settings and set the currency to your local value. + +##Settings: + +You'll need to get some info from your Stripe account to complete the steps below: https://dashboard.stripe.com/ + +* Add your Stripe public and private keys +* Set the currency to your local value. +* Add your Stripe webhook secret. + +See webhook info below. ## What are Subscriptions? @@ -34,6 +43,14 @@ Firstly, you'll need an account with the [Stripe](https://stripe.com) payment ga When you get a moment, take a look at Stripe's documentation. But for now, you can set up an account in test mode and see how it all works without making any real transactions. Then, if you're happy with how everything works, you can start taking real transactions. See below for test credit card numbers. +### Enable Webhooks in your Stripe account + +You'll need to tell Stripe where your end points are. You can enter this in your Stripe dashboard. + +The address for webhooks is: `[your server address]/s/hooks` + +Also: Add the webhook secret in settings (above). + ### Set up your User Groups in Discourse When a user successfully subscribes to your Discourse application, after their credit card transaction has been processed, they are added to a User Group. By assigning users to a User Group, you can manage what your users have access to on your website. User groups are a core functionality of Discourse and this plugin does nothing with them except and and remove users from the group you associated with your Plan. @@ -52,17 +69,14 @@ In the admin, add a new Product. Once you have a product saved, you can add plan If you take a look at your [Stripe Dashboard](https://dashboard.stripe.com), you'll see all those products and plans are listed. Discourse Subscriptions does not create them locally. They are created in Stripe. -## Enable Webhooks - -You'll need to tell Stripe where your end points are. You can enter this in your Stripe dashboard. - -The address for webhooks is: `/s/hooks` - ## Testing Test with these credit card numbers: -* 4111 1111 1111 1111 +* 4111 1111 1111 1111 (no authentication required) +* 4000 0027 6000 3184 (authentication required) + +For more test card numbers: https://stripe.com/docs/testing Visit `/s` and enter a few test transactions. diff --git a/app/controllers/hooks_controller.rb b/app/controllers/hooks_controller.rb index c87dfe9..fcc16e0 100644 --- a/app/controllers/hooks_controller.rb +++ b/app/controllers/hooks_controller.rb @@ -13,12 +13,10 @@ module DiscourseSubscriptions event = ::Stripe::Webhook.construct_event(payload, sig_header, webhook_secret) rescue JSON::ParserError => e - # Invalid payload - status 400 + render_json_error e.message return rescue Stripe::SignatureVerificationError => e - # Invalid signature - status 400 + render_json_error e.message return end diff --git a/assets/javascripts/discourse/controllers/s-show.js.es6 b/assets/javascripts/discourse/controllers/s-show.js.es6 index d0ea851..86a0c54 100644 --- a/assets/javascripts/discourse/controllers/s-show.js.es6 +++ b/assets/javascripts/discourse/controllers/s-show.js.es6 @@ -49,7 +49,7 @@ export default Ember.Controller.extend({ }); }, - createSubsciption(plan) { + createSubscription(plan) { return this.stripe.createToken(this.get("cardElement")).then(result => { if (result.error) { return result; @@ -85,7 +85,7 @@ export default Ember.Controller.extend({ let transaction; if (this.planTypeIsSelected) { - transaction = this.createSubsciption(plan); + transaction = this.createSubscription(plan); } else { transaction = this.createPayment(plan); } @@ -95,7 +95,12 @@ export default Ember.Controller.extend({ if (result.error) { bootbox.alert(result.error.message || result.error); } else { - this.alert(`${type}.success`); + if(result.status === "incomplete") { + this.alert(`${type}.incomplete`); + } + else { + this.alert(`${type}.success`); + } const success_route = this.planTypeIsSelected ? "user.billing.subscriptions" diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index bd162e6..020b917 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -32,6 +32,7 @@ en: payment_button: Subscribe success: Thank you! Your subscription has been created. + incomplete: The payment is incomplete. Your subscription will be updated when payment is complete. validate: payment_options: required: Please select a subscription plan. @@ -43,6 +44,7 @@ en: payment_button: Pay Once success: Thank you! + incomplete: Payment is incomplete. validate: payment_options: required: Please select a payment option.