rm old donation form

This commit is contained in:
Rimian Perkins 2019-12-16 10:59:59 +11:00
parent b79eed42ef
commit 7d3ca0421a
4 changed files with 0 additions and 321 deletions

View File

@ -1,55 +0,0 @@
# frozen_string_literal: true
module DiscourseSubscriptions
class PatronsController < ::ApplicationController
include DiscourseSubscriptions::Stripe
skip_before_action :verify_authenticity_token, only: [:create]
before_action :set_api_key
def index
result = { email: '' }
if current_user
result[:email] = current_user.email
end
render json: result
end
def create
begin
response = ::Stripe::PaymentIntent.create(
amount: param_currency_to_number,
currency: SiteSetting.discourse_subscriptions_currency,
payment_method_types: ['card'],
payment_method: params[:payment_method_id],
description: SiteSetting.discourse_patrons_payment_description,
receipt_email: params[:receipt_email],
confirm: true,
metadata: { user_id: user_id }
)
rescue ::Stripe::InvalidRequestError => e
response = { error: e }
rescue ::Stripe::CardError => e
response = { error: 'Card Declined' }
end
render json: response
end
private
def param_currency_to_number
params[:amount].to_s.sub('.', '').to_i
end
def user_id
if current_user
current_user.id
end
end
end
end

View File

@ -1,110 +0,0 @@
{{#if confirmation}}
{{#d-modal closeModal=(action "closeModal") modalStyle="inline-modal" title=(i18n "discourse_subscriptions.one_time.payment.payment_confirmation")}}
{{#d-modal-body}}
<div class="discourse-patrons-section-columns">
<div class="section-column discourse-patrons-confirmation-billing">
<table class="discourse-patrons-confirmation">
<tr>
<td>{{i18n 'discourse_subscriptions.billing.name'}}</td>
<td>{{billing.name}}</td>
</tr>
<tr>
<td>{{i18n 'discourse_subscriptions.billing.email'}}</td>
<td>{{billing.email}}</td>
</tr>
<tr>
<td>{{i18n 'discourse_subscriptions.billing.phone'}}</td>
<td>{{billing.phone}}</td>
</tr>
</table>
</div>
<div class="section-column">
<table class="discourse-patrons-confirmation">
<tr>
<td>{{i18n 'discourse_subscriptions.confirmation.amount'}}</td>
<td class="discourse-donations-amount">{{format-curency amount}}</td>
</tr>
<tr>
<td>{{i18n 'discourse_subscriptions.confirmation.last4'}}</td>
<td class="discourse-patrons-last4">.... .... .... {{last4}}</td>
</tr>
</table>
</div>
</div>
{{/d-modal-body}}
<div class='modal-footer'>
{{#d-button action="confirmStripeCard" class="btn btn-primary btn-payment btn-discourse-patrons"}}
{{i18n 'discourse_subscriptions.buttons.confirm_payment'}} {{format-curency amount}}
{{/d-button}}
</div>
{{/d-modal}}
{{#if paymentError}}
<div class="popup-tip bad">
{{paymentError}}
</div>
{{/if}}
{{else}}
<div class="discourse-patrons-section-columns discourse-patrons-payment-details">
<div class="section-column">
<h3>{{i18n 'discourse_subscriptions.one_time.payment.your_information'}}</h3>
<div class="user-controls discourse-patrons-fields discourse-patrons-billing">
<div class="display-row">
<div class="field">
{{i18n 'discourse_subscriptions.billing.name'}}
</div>
<div class="value">
{{input value=billing.name}}
<div class="desc">{{i18n 'discourse_subscriptions.one_time.payment.optional'}}</div>
</div>
</div>
<div class="display-row">
<div class="field">
{{i18n 'discourse_subscriptions.billing.email'}}
</div>
<div class="value">
{{input type="email" value=billing.email}}
<div class="desc">{{i18n 'discourse_subscriptions.one_time.payment.receipt_info'}}</div>
</div>
</div>
<div class="display-row">
<div class="field">
{{i18n 'discourse_subscriptions.billing.phone'}}
</div>
<div class="value">
{{input value=billing.phone}}
<div class="desc">{{i18n 'discourse_subscriptions.one_time.payment.optional'}}</div>
</div>
</div>
</div>
</div>
<div class="section-column">
<h3>{{i18n 'discourse_subscriptions.one_time.payment.payment_information'}}</h3>
<div class="user-controls discourse-patrons-fields">
<div class="display-row">
<div class="field">
{{i18n 'discourse_subscriptions.one_time.amount'}}
{{siteSettings.discourse_subscriptions_currency}}
</div>
<div class="value">
{{combo-box valueAttribute="value" content=amounts value=amount}}
</div>
</div>
</div>
{{stripe-card
amount=amount
currency=currency
billing=billing
handleConfirmStripeCard=(action "handleConfirmStripeCard")
}}
</div>
</div>
{{/if}}

View File

@ -1,107 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
module DiscourseSubscriptions
RSpec.describe PatronsController, type: :controller do
routes { DiscourseSubscriptions::Engine.routes }
describe 'index' do
it 'responds ok' do
get :index, format: :json
expect(response).to have_http_status(200)
end
it 'has a current user email' do
user = Fabricate(:user, email: 'hello@example.com')
controller.expects(:current_user).at_least(1).returns(user)
get :index, format: :json
expect(JSON.parse(response.body)['email']).to eq 'hello@example.com'
end
it 'has no current user email' do
get :index, format: :json
expect(JSON.parse(response.body)['email']).to be_empty
end
end
describe 'create' do
let!(:current_user) { Fabricate(:user) }
let(:payment) do
{
id: 'xyz-1234',
charges: { url: '/v1/charges?payment_intent=xyz-1234' },
amount: 9000,
receipt_email: 'hello@example.com',
currency: 'aud',
metadata: { user_id: current_user.id }
}
end
before do
SiteSetting.stubs(:discourse_subscriptions_currency).returns('AUD')
SiteSetting.stubs(:discourse_subscriptions_secret_key).returns('xyz-678')
controller.stubs(:current_user).returns(current_user)
end
it 'responds ok' do
::Stripe::PaymentIntent.expects(:create).returns(payment)
post :create, params: { receipt_email: 'hello@example.com', amount: '20.00' }, format: :json
expect(response).to have_http_status(200)
end
it 'has no user' do
controller.stubs(:current_user).returns(nil)
::Stripe::PaymentIntent.expects(:create).returns(payment)
post :create, format: :json
expect(response).to have_http_status(200)
end
it 'has the correct amount' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:amount, 2000)).returns(payment)
post :create, params: { amount: '20.00' }, format: :json
expect(response).to have_http_status(200)
end
it 'has no amount' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:amount, 0)).returns(payment)
post :create, params: {}, format: :json
expect(response).to have_http_status(200)
end
it 'has curency' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:currency, 'AUD')).returns(payment)
post :create, params: {}, format: :json
expect(response).to have_http_status(200)
end
it 'has the user id' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:metadata, user_id: current_user.id)).returns(payment)
post :create, params: {}, format: :json
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')).returns(payment)
post :create, params: { receipt_email: 'hello@example.com' }, format: :json
expect(response).to have_http_status(200)
end
it 'has a payment method' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:payment_method, 'xyz-1234')).returns(payment)
post :create, params: { payment_method_id: 'xyz-1234' }, 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')).returns(payment)
post :create, params: {}, format: :json
expect(response).to have_http_status(200)
end
end
end
end

View File

@ -1,49 +0,0 @@
import componentTest from "helpers/component-test";
moduleForComponent("donation-form", { integration: true });
componentTest("Discourse Patrons donation form has content", {
template: `{{donation-form}}`,
beforeEach() {
this.registry.register(
"component:stripe-card",
Ember.Component.extend({ tagName: "dummy-component-tag" })
);
Discourse.SiteSettings.discourse_patrons_amounts = "1.00|2.01";
},
async test(assert) {
assert.ok(
find(".discourse-patrons-section-columns").length,
"The card section renders"
);
assert.ok(
find("dummy-component-tag").length,
"The stripe component renders"
);
}
});
componentTest("donation form has a confirmation", {
template: `{{donation-form confirmation=confirmation}}`,
beforeEach() {
this.registry.register("component:stripe-card", Ember.Component.extend());
Discourse.SiteSettings.discourse_patrons_amounts = "1.00|2.01";
},
async skip(assert) {
this.set("confirmation", { card: { last4: "4242" } });
const confirmExists = find(".discourse-patrons-confirmation").length;
assert.ok(confirmExists, "The confirmation form renders");
const last4 = find(".discourse-patrons-last4")
.text()
.trim();
assert.equal(last4, ".... .... .... 4242", "The last 4 digits are correct");
}
});