Skip to content

Commit

Permalink
Merge branch 'master' into pages
Browse files Browse the repository at this point in the history
  • Loading branch information
benubois committed Jul 15, 2019
2 parents 7baa524 + 3922dc5 commit b33cf82
Show file tree
Hide file tree
Showing 21 changed files with 247 additions and 129 deletions.
3 changes: 2 additions & 1 deletion app/assets/stylesheets/_site.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,7 @@ $hamburger-dot: 4px;
align-items: center;
flex-direction: column;
background-color: transparent;
cursor: pointer;
&:hover {
text-decoration: none;
}
Expand Down Expand Up @@ -1238,7 +1239,7 @@ $hamburger-dot: 4px;
align-items: flex-end;
display: flex;
}
.subscribe-button {
.add-button {
.has-offscreen-panels & {
display: none;
}
Expand Down
11 changes: 5 additions & 6 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ def billing
end
end

if @user.plan.stripe_id == "timed"
@billing_events = @user.in_app_purchases.order(purchase_date: :desc)
else
@billing_events = @user.billing_events.where(event_type: "charge.succeeded")
@billing_events = @billing_events.to_a.sort_by { |billing_event| -billing_event.event_object["created"] }
end
stripe_purchases = @user.billing_events.where(event_type: "charge.succeeded")
in_app_purchases = @user.in_app_purchases
all_purchases = (stripe_purchases.to_a + in_app_purchases.to_a)
@billing_events = all_purchases.sort_by { |billing_event| billing_event.purchase_date }.reverse

@plans = @user.available_plans
end

Expand Down
8 changes: 8 additions & 0 deletions app/helpers/settings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ def tag_options
}
tags.unshift ["None", ""]
end

def plan_name
if @user.plan.stripe_id == "timed"
"prepaid plan"
else
"trial"
end
end
end
24 changes: 20 additions & 4 deletions app/jobs/trial_expiration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ class TrialExpiration
sidekiq_options queue: :critical

def perform
plan = Plan.where(stripe_id: "trial").first
users = User.where(plan: plan, suspended: false).where("created_at < ?", Feedbin::Application.config.trial_days.days.ago)
Subscription.where(user_id: users).update_all(active: false)
users.update_all(suspended: true)
expire_plan("trial")
# expire_prepaid_users
end

def expire_prepaid_users
user_ids = expire_plan("timed")
user_ids.each do |user_id|
UserMailer.delay.timed_plan_expiration(user_id)
end
end

def expire_plan(stripe_id)
plan = Plan.where(stripe_id: stripe_id)
User.where(plan: plan, suspended: false).where("expires_at < ?", Time.now).pluck(:id).tap do |user_ids|
if user_ids.present?
Subscription.where(user_id: user_ids).update_all(active: false)
User.where(id: user_ids).update_all(suspended: true)
end
end
end

end
5 changes: 5 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def trial_expiration(user_id)
mail to: @user.email, subject: "[Feedbin] Your Trial is About to End"
end

def timed_plan_expiration(user_id)
@user = User.find(user_id)
mail to: @user.email, subject: "[Feedbin] Your Account has Expired"
end

def starred_export_download(user_id, download_link)
@user = User.find(user_id)
@download_link = download_link
Expand Down
4 changes: 4 additions & 0 deletions app/models/billing_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ def receipt_amount
def currency
event_object["currency"].upcase
end

def purchase_date
Time.at(event_object["created"])
end
end
1 change: 1 addition & 0 deletions app/models/in_app_purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def extend_subscription
user.expires_at = new_expires_at
user.suspended = false
user.save
user.subscriptions.update_all(active: true)
end

def product_id
Expand Down
16 changes: 10 additions & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,19 @@ def available_plans
elsif plan_stripe_id == "free"
Plan.where(price_tier: price_tier)
else
exclude = ["free", "trial"]
if plan_stripe_id != "timed"
exclude.push("timed")
end
exclude = ["free", "trial", "timed"]
Plan.where(price_tier: price_tier).where.not(stripe_id: exclude)
end
end

def timed_plan_expired?
timed_plan? && expires_at.past?
end

def timed_plan?
plan.stripe_id == "timed"
end

def trial_plan_valid
trial_plan = Plan.find_by_stripe_id("trial")
if plan_id == trial_plan.id && plan_id_was != trial_plan.id && !plan_id_was.nil?
Expand Down Expand Up @@ -366,8 +371,7 @@ def days_left

def trial_end
@trial_end ||= begin
date = created_at || Time.now
date + Feedbin::Application.config.trial_days.days
expires_at || Time.now + Feedbin::Application.config.trial_days.days
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/settings/billing.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
</div>
<% if ENV['STRIPE_API_KEY'] %>
<% if @user.plan.stripe_id == 'trial' %>
<%= render partial: 'shared/billing_subscribe' %>
<%= render partial: 'shared/billing/billing_subscribe', locals: {subscribe_title: "Plan"} %>
<% else %>
<%= render partial: 'shared/billing_status' %>
<%= render partial: 'shared/billing/billing_status' %>
<% end %>
<% else %>
<p>Billing disabled. <code>STRIPE_API_KEY</code> and <code>STRIPE_PUBLIC_KEY</code> are missing.</p>
Expand Down
101 changes: 0 additions & 101 deletions app/views/shared/_billing_status.html.erb

This file was deleted.

8 changes: 4 additions & 4 deletions app/views/shared/_feeds_toolbar.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
<span>Edit</span>
</a>

<button type="button" class="toolbar-button subscribe-button" data-behavior="show_subscribe open_modal" data-modal-target="subscribe">
<div class="toolbar-button add-button" data-behavior="show_subscribe open_modal" data-modal-target="subscribe">
<div class="toolbar-button-inner">
<div class="icon-subscribe">
<%= svg_tag "icon-plus", size: "16x16" %>
</div>
</div>
<span>Add</span>
</button>
</div>

<button class="toolbar-button" disabled="disabled" data-behavior="mark_all_as_read">
<div class="toolbar-button" disabled="disabled" data-behavior="mark_all_as_read">
<div class="toolbar-button-inner">
<%= svg_tag "icon-mark-read", size: "21x21" %>
</div>
<span>Read</span>
</button>
</div>
</div>
</div>
7 changes: 7 additions & 0 deletions app/views/shared/billing/_billing_status.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if @user.plan.stripe_id == "free" %>
<%= render partial: 'shared/billing/plan_free' %>
<% elsif @user.plan.stripe_id == "timed" %>
<%= render partial: 'shared/billing/plan_timed' %>
<% else %>
<%= render partial: 'shared/billing/plan_default' %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<% if @user.plan.stripe_id == "trial" %>
<div class="settings-outer">
<% if @user.days_left <= 0 %>
<p>Your trial has ended. Subscribe now to continue using Feedbin.</p>
<% else %>
<p>Your trial period will end in <strong><%= pluralize(@user.days_left, 'day') %></strong>. Subscribe now to continue using Feedbin uninterrupted.</p>
<% end %>
</div>
<% end %>

<div class="inset">
<%= form_for @user, html: {id: "payment-form"} do |f| %>
<%= f.hidden_field :stripe_token, id: 'stripe_token' %>
<%= hidden_field_tag :redirect_to, settings_billing_url %>
<div class="inset-content">
<h4 class="group-header">Plan</h4>
<h4 class="group-header"><%= subscribe_title %></h4>
</div>
<ul class="control-group">
<% @plans.each do |plan| %>
Expand Down Expand Up @@ -65,11 +68,11 @@
<% if @user.trial_end.future? %>
<% if plan.name == "Monthly" %>
<p class="control-group-description <%= plan == @default_plan ? '' : 'hide' %>" data-behavior="billing_help_text" data-plan-id="<%= dom_id(plan) %>">
Subscribing will charge your card <strong><%= number_to_currency(plan.price, precision: 0) %></strong> when your trial ends on <strong><%= @user.trial_end.to_s(:date) %></strong> and again each month thereafter. You can change plans or cancel any time.
Subscribing will charge your card <strong><%= number_to_currency(plan.price, precision: 0) %></strong> when your <%= plan_name %> ends on <strong><%= @user.trial_end.to_s(:date) %></strong> and again each month thereafter. You can change plans or cancel any time.
</p>
<% else %>
<p class="control-group-description <%= plan == @default_plan ? '' : 'hide' %>" data-behavior="billing_help_text" data-plan-id="<%= dom_id(plan) %>">
Subscribing will charge your card <strong><%= number_to_currency(plan.price, precision: 0) %></strong> when your trial ends on <strong><%= @user.trial_end.to_s(:date) %></strong> and again each year thereafter. You can change plans or cancel any time.
Subscribing will charge your card <strong><%= number_to_currency(plan.price, precision: 0) %></strong> when your <%= plan_name %> ends on <strong><%= @user.trial_end.to_s(:date) %></strong> and again each year thereafter. You can change plans or cancel any time.
</p>
<% end %>
<% else %>
Expand Down
21 changes: 21 additions & 0 deletions app/views/shared/billing/_payment_history.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="inset-content">
<h4 class="group-header">Payment History</h4>
</div>
<div class="control-group">
<table class="table table-rounded">
<% if @next_payment_date %>
<tr>
<td><time datetime="<%= @next_payment_date.to_s(:date) %>"><%= @next_payment_date.to_s(:date) %></time></td>
<td>&nbsp;</td>
<td><span class="extra-muted">Scheduled</span></td>
</tr>
<% end %>
<% @billing_events.each do |invoice| %>
<tr>
<td><%= invoice.receipt_date %></td>
<td><%= number_to_currency(invoice.receipt_amount) %> <%= invoice.currency %> <%= invoice.receipt_description %></td>
<td><%= link_to 'Receipt', invoice %></td>
</tr>
<% end %>
</table>
</div>
53 changes: 53 additions & 0 deletions app/views/shared/billing/_plan_default.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<div class="inset">
<%= form_tag settings_update_credit_card_path, id: "payment-form" do %>
<%= hidden_field_tag :stripe_token, nil, id: 'stripe_token' %>
<div class="inset-content">
<h4 class="group-header">Billing Info</h4>
</div>
<ul class="pill-list">
<li class="text-with-accessory">
<span data-behavior="billing_details" class="text">Loading…</span>
<button class="button-text accessory" data-behavior="show_container" data-target="credit_card_form">Update card</button>
</li>
</ul>

<div class="hide" data-container="credit_card_form">
<%= render partial: 'shared/credit_card_form' %>
<div class="description-inset">
<div class="button-wrap">
<%= submit_tag "Update", class: "button no-margin update-cc-button", id: "credit_card_button", disabled: true, data: { disable_with: false } %>
</div>
</div>
</div>

<% end %>
</div>
<div class="inset">
<div class="inset-content">
<h4 class="group-header">Change Your Plan</h4>
</div>
<div class="control-group">
<table class="table table-rounded" style="margin-bottom: 0;">
<% @plans.each do |plan| %>
<tr>
<td><%= plan.name %></td>
<td><%= number_to_currency(plan.price, precision: 0) %>/<%= plan.period %></td>
<td>
<% if @user.plan.id == plan.id %>
Your plan
<% else %>
<%= form_tag settings_update_plan_path, data: { behavior: 'change_plan' }, class: 'no-margin' do %>
<%= hidden_field_tag 'plan', plan.id %>
<%= button_tag 'Switch to this plan', class: 'button-text', data: { confirm: "Are you sure you want to switch to #{plan.name.downcase} billing?" } %>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</table>
</div>
<p class="control-group-description">Plan changes are pro-rated.</p>
<%= render partial: 'shared/billing/payment_history' %>
</div>

<%= render partial: 'shared/billing/receipt_info' %>

0 comments on commit b33cf82

Please sign in to comment.