show the payment on the thankyou page

This commit is contained in:
Rimian Perkins 2019-09-14 20:54:13 +10:00
parent 5d94ed8974
commit ad5961a4c5
6 changed files with 40 additions and 5 deletions

View File

@ -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

View File

@ -0,0 +1,7 @@
import { ajax } from "discourse/lib/ajax";
export default Discourse.Route.extend({
model(params) {
return ajax(`/patrons/${params.pid}`, { method: "get" });
}
});

View File

@ -20,7 +20,11 @@
{{payment.username}}
{{/link-to}}
</td>
<td>{{{stripe-payment-link payment}}}</td>
<td>
{{#link-to "patrons.show" payment.payment_intent_id}}
{{{payment.payment_intent_id}}}
{{/link-to}}
</td>
<td>{{payment.receipt_email}}</td>
<td>{{{format-duration payment.created_at_age}}}</td>
<td class="amount">{{payment.amount_currency}}</td>

View File

@ -6,6 +6,21 @@
{{cook-text siteSettings.discourse_patrons_success_page}}
</p>
{{#if model}}
<table>
<tr>
<td>Payment ID</td>
<td>{{model.id}}</td>
</tr>
<tr>
<td>Amount</td>
<td>{{model.amount}}</td>
</tr>
</table>
{{/if}}
<hr>
{{#d-button action="goBack" class="btn btn-primary"}}
{{i18n 'discourse_patrons.buttons.success'}}
{{/d-button}}

View File

@ -40,6 +40,6 @@ en:
table:
head:
user: User
payment_intent: Payment Intent
payment_intent: Payment ID
receipt_email: Receipt Email
amount: Amount

View File

@ -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