add inital plan
This commit is contained in:
@@ -7,7 +7,7 @@ module DiscourseDonations
|
||||
skip_before_filter :verify_authenticity_token, only: [:create]
|
||||
|
||||
def create
|
||||
params.permit(:name, :username, :email, :password, :stripeToken, :amount)
|
||||
params.permit(:name, :username, :email, :password, :stripeToken, :amount, :plan)
|
||||
|
||||
output = { 'messages' => [], 'rewards' => [] }
|
||||
|
||||
@@ -28,7 +28,12 @@ module DiscourseDonations
|
||||
end
|
||||
|
||||
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
|
||||
charge = payment.charge(email, params)
|
||||
|
||||
if params['amount'].present?
|
||||
charge = payment.charge(email, params)
|
||||
else
|
||||
charge = payment.subscribe(email, params)
|
||||
end
|
||||
|
||||
if charge['paid'] == true
|
||||
output['messages'] << I18n.t('donations.payment.success')
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { getRegister } from 'discourse-common/lib/get-owner';
|
||||
|
||||
const { computed: { alias }, observer } = Ember
|
||||
|
||||
export default Ember.Component.extend({
|
||||
|
||||
routing: Ember.inject.service('-routing'),
|
||||
params: alias('routing.router.currentState.routerJsState.fullQueryParams'),
|
||||
|
||||
donateAmounts: [
|
||||
{ value: 1, name: '$1.00'},
|
||||
{ value: 2, name: '$2.00'},
|
||||
@@ -16,6 +22,10 @@ export default Ember.Component.extend({
|
||||
transactionInProgress: null,
|
||||
settings: null,
|
||||
|
||||
consumerDefenderWithMembership: function() {
|
||||
return this.get('params.plan') == 'consumer-defender-with-membership';
|
||||
}.property('params'),
|
||||
|
||||
init() {
|
||||
this._super();
|
||||
this.set('anon', (Discourse.User.current() == null));
|
||||
@@ -64,12 +74,18 @@ export default Ember.Component.extend({
|
||||
|
||||
let params = {
|
||||
stripeToken: data.token.id,
|
||||
amount: self.get('amount') * 100,
|
||||
email: self.get('email'),
|
||||
username: self.get('username'),
|
||||
create_account: self.get('create_accounts')
|
||||
};
|
||||
|
||||
if(this.get('params.plan')) {
|
||||
params.plan = this.get('params.plan');
|
||||
}
|
||||
else {
|
||||
params.amount: self.get('amount') * 100,
|
||||
}
|
||||
|
||||
if(!self.get('paymentSuccess')) {
|
||||
ajax('/charges', { data: params, method: 'post' }).then(data => {
|
||||
self.concatMessages(data.messages);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<form id="payment-form" class="form-horizontal">
|
||||
|
||||
<!--
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="card-element">
|
||||
{{i18n 'discourse_donations.amount'}}
|
||||
@@ -9,6 +10,23 @@
|
||||
{{combo-box valueAttribute="value" content=donateAmounts value=amount}}
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
|
||||
{{#if consumerDefenderWithMembership}}
|
||||
|
||||
<h3>[$25/quarter] Consumer Defender + CHOICE Membership</h3>
|
||||
|
||||
<ul>
|
||||
<li>Choice.community Access</li>
|
||||
<li>Defender Badge (while supplies last)</li>
|
||||
<li>Priority Expert Advice</li>
|
||||
<li>All the benefits of CHOICE membership</li>
|
||||
<li>CHOICE Members Only area</li>
|
||||
</ul>
|
||||
|
||||
{{/if}}
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="control-group" style="width: 550px;">
|
||||
<label class="control-label" for="card-element">{{i18n 'discourse_donations.card'}}</label>
|
||||
|
||||
@@ -24,8 +24,8 @@ module DiscourseDonations
|
||||
end
|
||||
|
||||
it 'whitelists the params' do
|
||||
params = { email: 'email@example.com', password: 'secret', username: 'mr-pink', name: 'kirsten', amount: 100, stripeToken: 'rrurrrurrrrr' }
|
||||
should permit(:name, :username, :email, :password).for(:create, params: params)
|
||||
params = { email: 'email@example.com', password: 'secret', username: 'mr-pink', name: 'kirsten', amount: 100, plan: 'some-plan-id', stripeToken: 'rrurrrurrrrr' }
|
||||
should permit(:name, :username, :email, :password, :plan).for(:create, params: params)
|
||||
end
|
||||
|
||||
it 'responds ok for anonymous users' do
|
||||
|
||||
Reference in New Issue
Block a user