track subscription ids

This commit is contained in:
Kyle Drake 2014-10-25 16:56:53 -07:00
parent 5235286d8a
commit 609cee1c17
6 changed files with 147 additions and 86 deletions

51
app.rb
View file

@ -271,30 +271,43 @@ post '/plan/update' do
require_login
DB.transaction do
customer = Stripe::Customer.create(
card: params[:stripe_token],
description: "#{parent_site.username} - #{parent_site.id}",
email: (current_site.email || parent_site.email),
plan: params[:plan_type]
)
if parent_site.stripe_subscription_id
customer = Stripe::Customer.retrieve parent_site.stripe_customer_id
subscription = customer.subscriptions.retrieve parent_site.stripe_subscription_id
subscription.plan = params[:plan_type]
subscription.save
parent_site.update(
stripe_customer_id: customer.id,
plan_ended: false,
plan_type: params[:plan_type]
)
parent_site.update(
plan_ended: false,
plan_type: params[:plan_type]
)
else
customer = Stripe::Customer.create(
card: params[:stripe_token],
description: "#{parent_site.username} - #{parent_site.id}",
email: (current_site.email || parent_site.email),
plan: params[:plan_type]
)
if current_site.email || parent_site.email
EmailWorker.perform_async({
from: 'web@neocities.org',
reply_to: 'contact@neocities.org',
to: current_site.email || parent_site.email,
subject: "[Neocities] You've become a supporter!",
body: Tilt.new('./views/templates/email_subscription.erb', pretty: true).render(self, plan_name: Site::PLAN_FEATURES[params[:plan_type].to_sym][:name])
})
parent_site.update(
stripe_customer_id: customer.id,
stripe_subscription_id: customer.subscriptions.first.id,
plan_ended: false,
plan_type: params[:plan_type]
)
end
end
if current_site.email || parent_site.email
EmailWorker.perform_async({
from: 'web@neocities.org',
reply_to: 'contact@neocities.org',
to: current_site.email || parent_site.email,
subject: "[Neocities] You've become a supporter!",
body: Tilt.new('./views/templates/email_subscription.erb', pretty: true).render(self, plan_name: Site::PLAN_FEATURES[params[:plan_type].to_sym][:name])
})
end
redirect '/plan/thanks'
end

View file

@ -0,0 +1,9 @@
Sequel.migration do
up {
DB.add_column :sites, :stripe_subscription_id, :text
}
down {
DB.drop_column :sites, :stripe_subscription_id
}
end

33
views/_team.erb Normal file
View file

@ -0,0 +1,33 @@
<hr />
<section>
<h1 class="beta txt-Center">The Neocities Team</h1>
<div class="row txt-Center">
<div class="col col-33">
<a href="https://kyledrake.neocities.org" title="Visit Kyle's Website">
<img src="https://0.gravatar.com/avatar/62a43048a3c2c688654274abdc0ecb9c?d=https%3A%2F%2Fidenticons.github.com%2Ffde07ba82b25f95afa9d080819f95717.png&amp;r=x&amp;s=440" alt="kyle drake" class="pic-Rounded" />
</a>
<br />
<a href="https://kyledrake.neocities.org" title="Kyle Drake" class="eps">Kyle Drake</a>
</div>
<div class="col col-33">
<a href="https://victoria.neocities.org" title="Visit Victoria's Website">
<img src="https://1.gravatar.com/avatar/2b577f8b3e5ab79bc927ed5185c0eae0?d=https%3A%2F%2Fidenticons.github.com%2Fe03006819f4a835afa237716f6701c95.png&amp;r=x&amp;s=440" alt="Victoria Wang" class="pic-Rounded" />
</a>
<br />
<a href="https://victoria.neocities.org" title="Visit Victoria's Website" class="eps">Victoria Wang</a>
</div>
<div class="col col-33">
<a href="http://scottohara.neocities.org" title="Visit Scott's Website">
<img src="https://0.gravatar.com/avatar/6ade16e6184b3efb573ee91255ff7abe?d=https%3A%2F%2Fidenticons.github.com%2Fa6362986538cdcb93a8b04f6c3f66b5e.png&amp;r=x&amp;s=440" alt="Scott O'Hara" class="pic-Rounded" />
</a>
<br />
<a href="http://scottohara.neocities.org" title="Visit Scott's Website" class="eps">Scott O'Hara</a>
</div>
</div>
</section>
<hr />
<section>
<h2 class="txt-Center"><a href="https://twitter.com/neocitiesweb">Follow us on Twitter</a></h2>
</section>

View file

@ -48,38 +48,5 @@
If you share our values, we would love your support. Spread the word! We also have a <a href="/plan">supporter plan</a> to help pay for the site, and we accept <a href="/donate">donations</a> through multiple options (including Bitcoin... and Dogecoin).
</p>
</article>
<hr />
<section>
<h1 class="beta txt-Center">The Neocities Team</h1>
<div class="row txt-Center">
<div class="col col-33">
<a href="https://kyledrake.neocities.org" title="Visit Kyle's Website">
<img src="https://0.gravatar.com/avatar/62a43048a3c2c688654274abdc0ecb9c?d=https%3A%2F%2Fidenticons.github.com%2Ffde07ba82b25f95afa9d080819f95717.png&amp;r=x&amp;s=440" alt="kyle drake" class="pic-Rounded" />
</a>
<br />
<a href="https://kyledrake.neocities.org" title="Kyle Drake" class="eps">Kyle Drake</a>
</div>
<div class="col col-33">
<a href="https://victoria.neocities.org" title="Visit Victoria's Website">
<img src="https://1.gravatar.com/avatar/2b577f8b3e5ab79bc927ed5185c0eae0?d=https%3A%2F%2Fidenticons.github.com%2Fe03006819f4a835afa237716f6701c95.png&amp;r=x&amp;s=440" alt="Victoria Wang" class="pic-Rounded" />
</a>
<br />
<a href="https://victoria.neocities.org" title="Visit Victoria's Website" class="eps">Victoria Wang</a>
</div>
<div class="col col-33">
<a href="http://scottohara.neocities.org" title="Visit Scott's Website">
<img src="https://0.gravatar.com/avatar/6ade16e6184b3efb573ee91255ff7abe?d=https%3A%2F%2Fidenticons.github.com%2Fa6362986538cdcb93a8b04f6c3f66b5e.png&amp;r=x&amp;s=440" alt="Scott O'Hara" class="pic-Rounded" />
</a>
<br />
<a href="http://scottohara.neocities.org" title="Visit Scott's Website" class="eps">Scott O'Hara</a>
</div>
</div>
</section>
<hr />
<section>
<h2 class="txt-Center"><a href="https://twitter.com/neocitiesweb">Follow us on Twitter</a></h2>
</section>
<%== erb :'_team', layout: false %>
</div>

View file

@ -332,7 +332,7 @@
<strong>It's affordable.</strong> As low as <strong>$<%= Site::PLAN_FEATURES[:supporter][:price] %>/month</strong> (billed once every year). Higher tiers are optional (and appreciated!)
</li>
<li>
<strong>You can cancel anytime.</strong>
<strong>You can cancel or change plans anytime.</strong> If you do, we'll refund/prorate the amount you didn't use.
</li>
</ul>
</div>
@ -375,7 +375,10 @@
</div>
<div class="modal-body">
<div>
You are <% if current_site && parent_site.plan_type == 'free' %>upgrading<%else%>changing<%end%> to the <strong><span id="upgradeFormPlanName"></span> Plan</strong>. You will be charged <span id="upgradeFormPlanPrice"></span>. Please enter your Credit Card number:
You are <% if current_site && parent_site.plan_type == 'free' %>upgrading<%else%>changing<%end%> to the <strong><span id="upgradeFormPlanName"></span> Plan</strong>. You will be charged <span id="upgradeFormPlanPrice"></span>.
<% unless current_site && parent_site.stripe_customer_id %>
Please enter your Credit Card number:
<% end %>
</div>
<input id="stripe_token" name="stripe_token" type="hidden" value="<%= params[:stripe_token] %>">
@ -383,38 +386,40 @@
<div style="margin-top: 30px">
<div id="plan_error" class="alert alert-block alert-error" style="display:none"></div>
<% if params[:stripe_token] %>
<p>Billing information has been saved, thank you!</p>
<% else %>
<div class="credit-card-input no-js" id="skeuocard" style="margin-left: auto; margin-right: auto; margin-bottom: 20px">
<p class="no-support-warning"></p>
<label for="cc_type">Card Type</label>
<select name="cc_type">
<option value="">...</option>
<option value="visa">Visa</option>
<option value="discover">Discover</option>
<option value="mastercard">MasterCard</option>
<option value="maestro">Maestro</option>
<option value="jcb">JCB</option>
<option value="unionpay">China UnionPay</option>
<option value="amex">American Express</option>
<option value="dinersclubintl">Diners Club</option>
</select>
<label for="cc_number">Card Number</label>
<input type="text" name="cc_number" id="cc_number" placeholder="XXXX XXXX XXXX XXXX" maxlength="19" size="19">
<label for="cc_exp_month">Expiration Month</label>
<input type="text" name="cc_exp_month" id="cc_exp_month" placeholder="00">
<label for="cc_exp_year">Expiration Year</label>
<input type="text" name="cc_exp_year" id="cc_exp_year" placeholder="00">
<label for="cc_name">Cardholder's Name</label>
<input type="text" name="cc_name" id="cc_name" placeholder="John Doe">
<label for="cc_cvc">Card Validation Code</label>
<input type="text" name="cc_cvc" id="cc_cvc" placeholder="123" maxlength="3" size="3">
</div>
<% unless params[:stripe_token] || (current_site && parent_site.stripe_customer_id) %>
<div class="credit-card-input no-js" id="skeuocard" style="margin-left: auto; margin-right: auto; margin-bottom: 20px">
<p class="no-support-warning"></p>
<label for="cc_type">Card Type</label>
<select name="cc_type">
<option value="">...</option>
<option value="visa">Visa</option>
<option value="discover">Discover</option>
<option value="mastercard">MasterCard</option>
<option value="maestro">Maestro</option>
<option value="jcb">JCB</option>
<option value="unionpay">China UnionPay</option>
<option value="amex">American Express</option>
<option value="dinersclubintl">Diners Club</option>
</select>
<label for="cc_number">Card Number</label>
<input type="text" name="cc_number" id="cc_number" placeholder="XXXX XXXX XXXX XXXX" maxlength="19" size="19">
<label for="cc_exp_month">Expiration Month</label>
<input type="text" name="cc_exp_month" id="cc_exp_month" placeholder="00">
<label for="cc_exp_year">Expiration Year</label>
<input type="text" name="cc_exp_year" id="cc_exp_year" placeholder="00">
<label for="cc_name">Cardholder's Name</label>
<input type="text" name="cc_name" id="cc_name" placeholder="John Doe">
<label for="cc_cvc">Card Validation Code</label>
<input type="text" name="cc_cvc" id="cc_cvc" placeholder="123" maxlength="3" size="3">
</div>
<% end %>
</div>
<p><strong>Don't have a Credit Card?</strong> We support Bitcoin and Paypal! <a href="/donate" target="_blank">Click here</a> for more information.</p>
<% unless params[:stripe_token] || (current_site && parent_site.stripe_customer_id) %>
<p>
<strong>Don't have a Credit Card?</strong> We support Bitcoin and Paypal! <a href="/donate" target="_blank">Click here</a> for more information.
</p>
<% end %>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
@ -441,11 +446,14 @@
if($('#stripe_token').val() != '')
return true
console.log(event)
var signupform = $(event.target)
<% if current_site && parent_site.stripe_subscription_id %>
return true
<% end %>
var planError = $('#plan_error')
planError.css('display', 'none')
var signupform = $(event.target)
signupform.find(':submit').prop('disabled', true)
Stripe.card.createToken({

31
views/plan/thanks.erb Normal file
View file

@ -0,0 +1,31 @@
<div class="header-Outro">
<div class="row content single-Col">
<h1>Thank You!</h1>
<h3 class="subtitle">Your support means a lot to us.</h3>
</div>
</div>
<div class="content single-Col misc-page">
<h3></h3>
<article>
<div class="txt-Center"><img src="/img/heartcat.png"></div>
<h1 class="txt-Center">Thank you for your support.</h1>
<p>
Your support allows Neocities to continue our project to bring back the web. We will do our best to ensure that the site remains a great place for people to express themselves - one web page at a time.
</p>
<p>
If you need anything, please don't hesitate to <a href="/contact">contact us</a>!
</p>
<p>
On behalf of Penelope (the Neocities' cat) and everyone else at Neocities, thank you.
</p>
<p>
<a href="/">Get Started</a>
</p>
</article>
<%== erb :'_team', layout: false %>
</div>