From ad5961a4c5ddb606621bf70c8a48747b62dda5bf Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Sat, 14 Sep 2019 20:54:13 +1000 Subject: [PATCH] show the payment on the thankyou page --- app/controllers/patrons_controller.rb | 9 ++++++--- .../discourse/routes/patrons-show.js.es6 | 7 +++++++ .../templates/admin/plugins-discourse-patrons.hbs | 6 +++++- .../discourse/templates/patrons/show.hbs | 15 +++++++++++++++ config/locales/client.en.yml | 2 +- .../discourse_patrons/patrons_controller_spec.rb | 6 ++++++ 6 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 assets/javascripts/discourse/routes/patrons-show.js.es6 diff --git a/app/controllers/patrons_controller.rb b/app/controllers/patrons_controller.rb index 0b4d1ba..f1ea435 100644 --- a/app/controllers/patrons_controller.rb +++ b/app/controllers/patrons_controller.rb @@ -3,6 +3,7 @@ module DiscoursePatrons class PatronsController < ::ApplicationController skip_before_action :verify_authenticity_token, only: [:create] + before_action :set_api_key def index result = { email: '' } @@ -15,14 +16,12 @@ module DiscoursePatrons end def show - result = { } + result = Stripe::PaymentIntent.retrieve(params[:pid]) render json: result end def create - ::Stripe.api_key = SiteSetting.discourse_patrons_secret_key - begin response = ::Stripe::PaymentIntent.create( @@ -55,6 +54,10 @@ module DiscoursePatrons private + def set_api_key + ::Stripe.api_key = SiteSetting.discourse_patrons_secret_key + end + def param_currency_to_number params[:amount].to_s.sub('.', '').to_i end diff --git a/assets/javascripts/discourse/routes/patrons-show.js.es6 b/assets/javascripts/discourse/routes/patrons-show.js.es6 new file mode 100644 index 0000000..36794bb --- /dev/null +++ b/assets/javascripts/discourse/routes/patrons-show.js.es6 @@ -0,0 +1,7 @@ +import { ajax } from "discourse/lib/ajax"; + +export default Discourse.Route.extend({ + model(params) { + return ajax(`/patrons/${params.pid}`, { method: "get" }); + } +}); diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons.hbs index bd931fe..805b53d 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons.hbs @@ -20,7 +20,11 @@ {{payment.username}} {{/link-to}} - {{{stripe-payment-link payment}}} + + {{#link-to "patrons.show" payment.payment_intent_id}} + {{{payment.payment_intent_id}}} + {{/link-to}} + {{payment.receipt_email}} {{{format-duration payment.created_at_age}}} {{payment.amount_currency}} diff --git a/assets/javascripts/discourse/templates/patrons/show.hbs b/assets/javascripts/discourse/templates/patrons/show.hbs index 4d578e4..65bb8df 100644 --- a/assets/javascripts/discourse/templates/patrons/show.hbs +++ b/assets/javascripts/discourse/templates/patrons/show.hbs @@ -6,6 +6,21 @@ {{cook-text siteSettings.discourse_patrons_success_page}}

+{{#if model}} + + + + + + + + + +
Payment ID{{model.id}}
Amount{{model.amount}}
+{{/if}} + +
+ {{#d-button action="goBack" class="btn btn-primary"}} {{i18n 'discourse_patrons.buttons.success'}} {{/d-button}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 551602e..afd8302 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -40,6 +40,6 @@ en: table: head: user: User - payment_intent: Payment Intent + payment_intent: Payment ID receipt_email: Receipt Email amount: Amount diff --git a/spec/controllers/discourse_patrons/patrons_controller_spec.rb b/spec/controllers/discourse_patrons/patrons_controller_spec.rb index 3843b51..35dcf1c 100644 --- a/spec/controllers/discourse_patrons/patrons_controller_spec.rb +++ b/spec/controllers/discourse_patrons/patrons_controller_spec.rb @@ -29,9 +29,15 @@ module DiscoursePatrons describe 'show' do it 'responds ok' do + ::Stripe::PaymentIntent.expects(:retrieve) get :show, params: { pid: '123' }, format: :json expect(response).to have_http_status(200) end + + it 'requests the payment intent' do + ::Stripe::PaymentIntent.expects(:retrieve).with('abc-1234') + get :show, params: { pid: 'abc-1234' }, format: :json + end end describe 'create' do