updates for paypal support

This commit is contained in:
Kyle Drake 2016-01-22 20:38:42 +00:00
parent be9fe7ca12
commit b967093ba7
7 changed files with 37 additions and 22 deletions

View file

@ -110,24 +110,24 @@ end
def paypal_recurring_hash
{
ipn_url: "#{url}/webhooks/paypal",
description: 'Neocities Supporter',
ipn_url: "https://neocities.org/webhooks/paypal",
description: 'Neocities Supporter - Monthly',
amount: Site::PLAN_FEATURES[:supporter][:price].to_s,
currency: 'USD'
}
end
def paypal_recurring_authorization_hash
url = ENV['RACK_ENV'] == 'development' ? 'http://127.0.0.1:9292' : 'https://neocities.org'
paypal_recurring_hash.merge(
return_url: "#{url}/plan/paypal/return",
cancel_url: "#{url}/plan",
ipn_url: "#{url}/webhooks/paypal"
return_url: "https://neocities.org/plan/paypal/return",
cancel_url: "https://neocities.org/plan",
ipn_url: "https://neocities.org/webhooks/paypal"
)
end
get '/plan/paypal' do
require_login
redirect '/plan' if parent_site.supporter?
hash = paypal_recurring_authorization_hash
@ -145,13 +145,13 @@ end
get '/plan/paypal/return' do
require_login
if params[:TOKEN].nil? || params[:PAYERID].nil?
if params[:token].nil? || params[:PayerID].nil?
flash[:error] = 'Unknown error, could not complete the request. Please contact Neocities support.'
end
ppr = PayPal::Recurring.new(paypal_recurring_hash.merge(
token: params[:TOKEN],
payer_id: params[:PAYERID]
token: params[:token],
payer_id: params[:PayerID]
))
paypal_response = ppr.request_payment
@ -162,10 +162,10 @@ get '/plan/paypal/return' do
ppr = PayPal::Recurring.new(paypal_recurring_authorization_hash.merge(
frequency: 1,
token: params[:TOKEN],
token: params[:token],
period: :monthly,
reference: current_site.id.to_s,
payer_id: params[:PAYERID],
payer_id: params[:PayerID],
start_at: Time.now,
failed: 3,
outstanding: :next_billing
@ -173,9 +173,10 @@ get '/plan/paypal/return' do
paypal_response = ppr.create_recurring_profile
current_site.paypal_token = params[:TOKEN]
current_site.paypal_token = params[:token]
current_site.paypal_profile_id = paypal_response.profile_id
current_site.paypal_active = true
current_site.plan_type = 'supporter'
current_site.save_changes validate: false
redirect '/plan/thanks-paypal'
@ -185,3 +186,16 @@ get '/plan/thanks-paypal' do
require_login
erb :'plan/thanks-paypal'
end
get '/plan/paypal/cancel' do
require_login
redirect '/plan' unless parent_site.paypal_active
ppr = PayPal::Recurring.new profile_id: parent_site.paypal_profile_id
ppr.cancel
parent_site.paypal_active = false
parent_site.paypal_profile_id = nil
parent_site.paypal_token = nil
parent_site.save_changes validate: false
redirect '/plan'
end

View file

@ -105,6 +105,10 @@ def plan_pricing_button(plan_type)
button_title = parent_site.plan_type == 'free' ? 'Upgrade' : 'Change'
end
if button_title == 'Change' && parent_site && parent_site.paypal_active
return %{<a href="/plan/paypal/cancel" onclick="return confirm('This will end your supporter plan.')" class="btn-Action">Change</a>}
end
%{<a data-plan_name="#{Site::PLAN_FEATURES[plan_type.to_sym][:name]}" data-plan_type="#{plan_type}" data-plan_price="#{plan_price}" onclick="card = new Skeuocard($('#skeuocard')); return false" class="btn-Action planPricingButton">#{button_title}</a>}
end
end

View file

@ -1061,6 +1061,7 @@ class Site < Sequel::Model
# Note: Change Stat#prune! if you change this business logic.
def plan_type
return 'supporter' if owner.values[:paypal_active] == true
return 'free' if owner.values[:plan_type].nil?
return 'supporter' if owner.values[:plan_type].match /^plan_/
return 'supporter' if owner.values[:plan_type] == 'special'

View file

@ -214,7 +214,7 @@
<% unless params[:stripe_token] || (current_site && parent_site.stripe_customer_id) %>
<p>
<strong>Don't have a Credit/Debit Card?</strong> We support Bitcoin and Paypal! <a href="/plan/alternate">Click here</a> for more information.
<strong>Don't have a Credit/Debit Card?</strong> We also support <a href="/plan/paypal">Paypal</a> and <a href="/plan/bitcoin">Bitcoin</a>.
</p>
<% end %>
</div>

View file

@ -12,15 +12,15 @@
<div class="content single-Col misc-page txt-Center">
<article>
<section>
<h2>The Bitcoin Homesteader Plan</h2>
<h2>The Bitcoin Lifer Plan</h2>
<p>
We don't have a good way to charge recurring with Bitcoin (that adheres to Bitcoin's decentralized principles). So instead, we've put together a <strong>lifer plan</strong>. Basically, if you send us <strong>$50</strong> worth of BTC, we'll never charge you again for the supporter upgrade, and you'll basically get it forever!
We don't have a good way to charge recurring with Bitcoin (that adheres to Bitcoin's decentralized principles). So instead, we've put together a special <strong>Bitcoin Lifer Plan</strong>. Basically, if you send us <strong>$100</strong> worth of BTC at current market price, we'll never charge you again for the supporter upgrade, and you'll basically get it forever!
</p>
<p>Be sure to <a href="/contact">contact us</a> after sending with the transaction ID so we can confirm and upgrade your account.</p>
<p>
We don't cash out the Bitcoin. Many of our providers accept Bitcoin, and we use it to pay them.
We generally hold Bitcoin. Many of our vendors accept Bitcoin, and we often use it to pay them.
</p>
<p><img src="/img/bitcoin.png"></p>

View file

@ -12,11 +12,7 @@
<h1 class="txt-Center">You signed up for the Supporter Plan.<br>Thank you for your support!</h1>
<p>
<strong>There is one more quick thing you must do to have your supporter account enabled.</strong> <a href="/contact">Contact us</a> and give us your Neocities username so we can enable the supporter status for your account. We are working on automating this process in the near future, our apologies for the extra step!
</p>
<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.
Your support allows Neocities to continue our project to bring back the creative 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>

View file

@ -96,7 +96,7 @@
<a href="/" class="btn-Action" onclick="$('#upgradeForm').submit(); return false">
Upgrade for $<%= Site::PLAN_FEATURES[:supporter][:price] %>/mo
</a>
or pay with <a href="/plan/alternate/">PayPal</a> or <a href="/plan/alternate/">Bitcoin</a>
or pay with <a href="/plan/paypal">PayPal</a> or <a href="/plan/bitcoin">Bitcoin</a>
</div>
</div>
</div>