merge in staging

This commit is contained in:
Rimian Perkins 2017-02-14 13:39:14 +11:00
commit 6867f584be
15 changed files with 109 additions and 32 deletions

View File

@ -9,3 +9,7 @@ Enables stripe payments from discourse.
You can either set your environment vars in docker or save them in a yaml.
# Testing
Run the local js acceptance tests here:
http://localhost:3000/qunit?module=Acceptance%3A%20Discourse%20Payments

View File

@ -1,5 +1,13 @@
module Choice
class ChoiceController < Choice::ApplicationController
class ChoiceController < ApplicationController
def index
render json: {}
end
def show
render json: {}
end
def create
badge = Badge.find_by_name('Consumer Defender')

View File

@ -0,0 +1,8 @@
export default Ember.Controller.extend({
actions: {
someThing: function() {
console.log('w00t! something happened!');
}
}
});

View File

@ -0,0 +1,11 @@
export default Ember.Controller.extend({
user: Ember.inject.controller(),
username: Ember.computed.alias('user.model.username_lower'),
email: Ember.computed.alias('user.model.email'),
actions: {
choiceTest: function() {
this.set('saved', true);
}
}
});

View File

@ -0,0 +1,6 @@
export default {
resource: 'user',
map() {
this.route('payments');
}
};

View File

@ -0,0 +1,7 @@
import { ajax } from 'discourse/lib/ajax';
export default Ember.Route.extend({
model() {
return ajax('/choice/form.json');
}
});

View File

@ -0,0 +1,4 @@
<div class="discourse-payments">
<a href="/users/{{model.username}}/payments">Payments page</a>
</div>

View File

@ -1,17 +0,0 @@
<form action="/choice/stripe">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_b8RmhzlL8QPizJRqOrKF3JEV"
data-name="CHOICE"
data-description="Consumer Defender"
data-image="https://cloud.githubusercontent.com/assets/64749/18696451/99eeb440-7ffc-11e6-8cab-905a8ea27fb6.png"
data-locale="auto"
data-zip-code="false"
data-currency="aud"
data-label="Become a Consumer Defender"
data-email="{{model.email}}"
>
</script>
</form>

View File

@ -0,0 +1,11 @@
<div class="payments">
{{username}}
</div>
<button class='btn btn-primary choice-btn' {{action "choiceTest"}}>
click
</button>
{{#if saved}}
<div class="choice-response">Response happens</div>
{{/if}}

View File

@ -1,3 +1,5 @@
Choice::Engine.routes.draw do
get 'stripe' => 'choice#create'
get 'choice-form' => 'choice#index'
get 'users/:username/payments' => 'choice#show'
end

6
config/stripe.rb Normal file
View File

@ -0,0 +1,6 @@
Rails.configuration.stripe = {
:publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'] || Rails.application.config_for(:stripe)['publishable_key'],
:secret_key => ENV['STRIPE_SECRET_KEY'] || Rails.application.config_for(:stripe)['secret_key']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]

1
jsapp Symbolic link
View File

@ -0,0 +1 @@
assets/javascripts/discourse

View File

@ -0,0 +1,6 @@
module ::Choice
class Engine < ::Rails::Engine
engine_name 'choice'
isolate_namespace Choice
end
end

View File

@ -1,21 +1,12 @@
# name: choice-plugin
# about: Integrating Discourse with Stripe
# version: 0.1.0
# authors: Rimian Perkins
# version: 1.0.1
# url: https://github.com/choiceaustralia/choice-discourse
gem 'stripe', '1.58.0'
Rails.configuration.stripe = {
:publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'] || Rails.application.config_for(:stripe)['publishable_key'],
:secret_key => ENV['STRIPE_SECRET_KEY'] || Rails.application.config_for(:stripe)['secret_key']
}
load File.expand_path('../lib/choice-discourse/engine.rb', __FILE__)
Stripe.api_key = Rails.configuration.stripe[:secret_key]
require File.expand_path('../lib/choice/engine', __FILE__)
after_initialize do
Discourse::Application.routes.prepend do
mount ::Choice::Engine, at: '/choice'
end
Discourse::Application.routes.prepend do
mount ::Choice::Engine, at: '/'
end

View File

@ -0,0 +1,29 @@
import { acceptance } from 'helpers/qunit-helpers';
acceptance('Discourse Payments', { loggedIn: true });
test('Payments Link Exists', () => {
visit('/users/eviltrout');
andThen(() => {
ok(exists('.discourse-payments > a'), 'Link exists on profile page');
});
});
test('Payments Page Exists', () => {
visit('/users/eviltrout/payments');
andThen(() => {
ok(exists('h1'), 'Heading exists');
ok($.trim($('.payments').text()) == 'eviltrout', 'username is present on page');
});
});
test('Payments Page response happens', () => {
visit('/users/eviltrout/payments');
click('.choice-btn');
andThen(() => {
ok(exists('.choice-response'), 'Response happens');
});
});