Skip to content

Commit

Permalink
Sponsor signup feature (#299)
Browse files Browse the repository at this point in the history
* Adds is_sponsorere field for sponsors[#276]

* Displays sponsor button on all webpages[#276]

A floating Sponsor button is displayed on homepage as well as at the right side of each page if user is not sponsorer

* Adds mongoid-paperclip gem for image upload[#276]

* Defines routes for sponsorer detail[#277]

* defines payment plans for sponsor[#277]

* creates sponsorer details model[#277]

* creates viewes for sponsor[#277]

* testcases for sponsor detail model[#276]

* Sponsorer need not to set goal on signup[#276]

* triggers the button click on sign up of sponsor[#276]

* creates controller for sponsorer detail[#276]

* test cases for sponsorer details controller[#276]

* modifies partial for sponsor button[#276]

* helper for sponsorer detail[#276]

* creates sidebar for sponsor[#276]

* Associates user model with sponsorer detail[#276]

* github signup of sponsor and it's testcases[#276]

* Ignores local storage of sponsor profile photos[#276]

* Adds stripe gem for recurring payments[#276]

* Configures stripe keys for application[#276]

* Changes in SponsorerDetail model[#276]

changes the type of payment plan from integer to string, adds some extra fields for subscription and changes in validations

* Changes the names of SPONSOR config variables[#276]

* Modifies sponsorship details form to add stripe checkout[#276]

* Creates stripe customer and subscription[#276]

* Modifies sponsor dashboard, sidebar and profile[#276]

* Adds route for stripe webhook[#276]

* Creates stripe controller for handling stripe events with webhook[#276]

* Creates mailer to notify sponsor[#276]

* Sends an email on payment failure to sponsorer[#276]

* Modifies stripe subscription creation[#276]

Creates subscription and customer on stripe by one function call only
instead of creating it separately

* Skips set goal for sponsorer[#276]

* Adds validations for stripe subscription details[#276]

presence validation on stripe customer id, subscription id, status etc.

* client side validation for image upload[#276]

verifies whether uploaded file is image only

* Replaces create.js.haml with create.html.haml[#276]

* Adds update credit card functionality for sponsore[#276]

Sponsor can update his credit card details

* Minor changes in sponsor index and omniauth controller[#276]

* Adds route for updating credit card[#276]

* Modifies sponsorer_details factory[#276]

* Adds stripe_ruby_mock gem for testing stripe[#276]

* Removes presence validation on stripe details[#276]

Form is validated before creating stripe subscription so removed the
validation on these fields

* Shows subscrption details on sponsor index page[#276]

Earlier subscription details were shown on users profile page

* Adds route for cancel subscription[#276]

* Allowes sponsorer to cancel subscription[#276]

* Modification in sponsorer detail testcase[#276]

* Functional test cases for SponsorerDetail[#276]

* Creates Payment model[#276]

Stores the details of monthly payment

* Creates association between sponsorer detail and payment[#276]

* Handles stripe events[#276]

* Shows payment details of sponsor[#276]

* Optimizes the stripe controller[#276]

* Saves payment details of sponsorer[#276]

Saves payment detail when invoice payment succeded event triggers

* Adds validations for payment model

* Minor modifications in sponsorer controller[#276]

* Moves subscription deletion code to concern[#276]

* Cancels subscription while deleting account[#276]

If user is sponsorer and tries to delete his account first cancel his
subscription and then delete his account

* Creates partial for mail signature[#276]

* Yields the mail signature within layout[#276]

* Renders the mail signature in the mailers[#276]

* Uses different mail signature for sponsor mailer[#276]

* Minor changes in sponsor's functional testcase[#276]

* Testcase scenarios for stripe controller[#276]

* Fixes the javascript reference error[#276]

Fixes the error that was causing to fail integration test cases

* Fixes the failure and error in test cases[#276]

* Fixes the pagination of sponsorer payment details[#276]

* Fixes failing test cases of sponsorer detail[#276]
  • Loading branch information
tejaswini-gambhire authored and sethu committed Jul 12, 2017
1 parent c82c6d9 commit 128a74c
Show file tree
Hide file tree
Showing 65 changed files with 1,088 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
# Ignore ENV variables
*.env.*

# Ignore local storage of profile photos
/public/system/sponsorer

1
dump.rdb
/repositories
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ gem 'mongoid-slug', '~> 5.2'
gem 'redcarpet'
gem 'rollbar'
gem 'mongoid-paranoia'
gem 'mongoid-paperclip', require: 'mongoid_paperclip'
gem 'stripe'

group :development, :test do
gem 'byebug'
Expand All @@ -60,6 +62,7 @@ group :test do
gem 'poltergeist'
gem 'mocha'
gem 'timecop'
gem 'stripe-ruby-mock', '~> 2.4.1', :require => 'stripe_mock'
end

group :development do
Expand Down
37 changes: 36 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ GEM
rack-test (>= 0.5.4)
xpath (~> 2.0)
chronic (0.10.2)
climate_control (0.1.0)
cliver (0.3.2)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
codeclimate-test-reporter (0.6.0)
simplecov (>= 0.7.1, < 1.0.0)
coderay (1.1.1)
Expand All @@ -97,6 +100,7 @@ GEM
connection_pool (2.2.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
dante (0.2.0)
database_cleaner (1.5.3)
debug_inspector (0.0.2)
descendants_tracker (0.0.4)
Expand All @@ -109,6 +113,8 @@ GEM
thread_safe (~> 0.1)
warden (~> 1.2.3)
docile (1.1.5)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.1.1)
dotenv-rails (2.1.1)
dotenv (= 2.1.1)
Expand Down Expand Up @@ -151,6 +157,8 @@ GEM
haml (~> 4.0.0)
nokogiri (~> 1.6.0)
ruby_parser (~> 3.5)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (0.7.0)
jbuilder (2.6.0)
activesupport (>= 3.0.0, < 5.1)
Expand All @@ -175,6 +183,7 @@ GEM
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mimemagic (0.3.2)
mina (0.3.8)
open4 (~> 1.3.4)
rake
Expand Down Expand Up @@ -208,6 +217,9 @@ GEM
mongoid-compatibility (0.4.0)
activesupport
mongoid (>= 2.0)
mongoid-paperclip (0.0.11)
mongoid
paperclip (>= 2.3.6, != 4.3.0)
mongoid-paranoia (2.0.0)
activesupport (~> 4.0)
mongoid (>= 4.0.0, <= 6.0.0)
Expand All @@ -218,6 +230,7 @@ GEM
multi_json (1.12.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
netrc (0.11.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
Expand All @@ -239,6 +252,12 @@ GEM
open4 (1.3.4)
origin (2.2.0)
orm_adapter (0.5.0)
paperclip (5.1.0)
activemodel (>= 4.2.0)
activesupport (>= 4.2.0)
cocaine (~> 0.5.5)
mime-types
mimemagic (~> 0.3.0)
pkg-config (1.1.7)
poltergeist (1.10.0)
capybara (~> 2.1)
Expand All @@ -252,7 +271,7 @@ GEM
pry (>= 0.9.10, < 0.11.0)
quiet_assets (1.1.0)
railties (>= 3.1, < 5.0)
rack (1.6.4)
rack (1.6.8)
rack-protection (1.5.3)
rack
rack-test (0.6.3)
Expand Down Expand Up @@ -305,6 +324,10 @@ GEM
redis (>= 2.2)
responders (2.2.0)
railties (>= 4.2.0, < 5.1)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rollbar (2.12.0)
multi_json
ruby_parser (3.8.2)
Expand Down Expand Up @@ -348,6 +371,12 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
stringex (2.6.1)
stripe (1.58.0)
rest-client (>= 1.4, < 4.0)
stripe-ruby-mock (2.4.1)
dante (>= 0.2.0)
multi_json (~> 1.0)
stripe (>= 1.31.0, <= 1.58.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.5)
Expand All @@ -358,6 +387,9 @@ GEM
thread_safe (~> 0.1)
uglifier (3.0.1)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
warden (1.2.6)
rack (>= 1.0)
web-console (2.3.0)
Expand Down Expand Up @@ -410,6 +442,7 @@ DEPENDENCIES
minitest-rails-capybara
mocha
mongoid (~> 5.0)
mongoid-paperclip
mongoid-paranoia
mongoid-slug (~> 5.2)
omniauth-github (~> 1.1.2)
Expand All @@ -428,6 +461,8 @@ DEPENDENCIES
simple_form (~> 3.2.1)
simplecov
spring
stripe
stripe-ruby-mock (~> 2.4.1)
timecop
turbolinks (~> 2.5)
uglifier (>= 1.3.0)
Expand Down
30 changes: 30 additions & 0 deletions app/assets/javascripts/sponsorer_details.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

$(document).on "ready", ->
$('body').on 'change', '.sponsorer_detail_avatar', () ->
inputFile = $(this).val();
validateFiles(inputFile);
if window.location.pathname == '/sponsorer_details'
showmodal();

showmodal = () ->
if modal == "true"
$("#rotate").click();

validateFiles = (inputFile) ->
extErrorMessage = 'Only image file with extension: .jpg, .jpeg, .gif or .png is allowed'
allowedExtension = [
'jpg'
'jpeg'
'gif'
'png'
]
extName = inputFile.split('.').pop()
extError = false
if $.inArray(extName, allowedExtension) == -1
window.alert extErrorMessage
$(inputFile).val ''
$(this).val ''
return
3 changes: 3 additions & 0 deletions app/assets/javascripts/stripe.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
53 changes: 53 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,56 @@
.typeahead.dropdown-menu, .tt-hint, .tt-input, .tt-menu {
width: 90%;
}

.sticky-container{
padding:0px;
margin:0px;
position:fixed;
right:-105px;
top:60%;
width:200px;
z-index: 1100;
}

.sticky li{
list-style-type:none;
//background-color:#fff;
color:#808080;
height:43px;
padding:0px;
margin:0px 0px 1px 0px;
-webkit-transition:all 0.25s ease-in-out;
-moz-transition:all 0.25s ease-in-out;
-o-transition:all 0.25s ease-in-out;
transition:all 0.25s ease-in-out;
cursor:pointer;
}
.sticky li:hover{
margin-left:-15px;
}
.sticky li span{
float:left;
}
.sticky li p{
padding-top:5px;
margin:0px;
line-height:16px;
//font-size:11px;
}

.sticky li p a{
text-decoration:none;
color:#fff;
}

#rotate{
vertical-align: top;
//margin-top: 30%;
//margin-right: 0px;
//float: right;
//width:80px;height: 30px;
transform:rotate(7deg);
-ms-transform:rotate(90deg); /* IE 9 */
-moz-transform:rotate(90deg); /* Firefox */
-webkit-transform:rotate(90deg); /* Safari and Chrome */
-o-transform:rotate(90deg); /* Opera */}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sponsorer_details.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the SponsorerDetails controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/stripe.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the stripe controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
8 changes: 7 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def select_goal
return true if params[:controller] == 'goals' && params[:action] == 'index'
return true if params[:action] == 'set_goal' || params[:controller] == 'devise/sessions'
return true if current_user.is_admin?

if current_user.goal.blank?
redirect_to goals_path, notice: I18n.t('goal.please_select')
end
Expand All @@ -49,6 +49,12 @@ def authenticate_admin!
end
end

def authenticate_sponsor!
if current_user && !current_user.is_sponsorer?
redirect_back(notice: I18n.t('messages.unauthorized_access'))
end
end

def redirect_back(opts = {})
redirect_to(request.env['HTTP_REFERER'] || root_path, opts)
end
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/concerns/sponsorer_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module SponsorerHelper
def createStripeCustomer(email, token, plan)
Stripe::Customer.create(
:email => email,
:source => token,
:plan => plan
)
end

def delete_subscription(subscription_id)
Stripe::Subscription.retrieve(subscription_id).delete
end
end
86 changes: 86 additions & 0 deletions app/controllers/sponsorer_details_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
class SponsorerDetailsController < ApplicationController
include SponsorerHelper
require "stripe"
# after_action :set_sponsorer, only: [:create]
before_action :authenticate_user!
# before_action :authenticate_sponsor!, except: [:new, :create]
skip_before_action :select_goal
before_action :load_sponsorer, only: [:update_card, :cancel_subscription]

def index
@user = current_user
@sponsor = @user.sponsorer_detail
if @sponsor
@card = SponsorerDetail.get_credit_card(@sponsor.stripe_customer_id)
@payments = @sponsor.payments.page(params[:page])
end
end

def new
@sponsorer_detail = SponsorerDetail.new
end

def create
@sponsorer = SponsorerDetail.new(sponsorer_params)
@sponsorer.user_id = current_user.id
if @sponsorer.valid?
begin
plan_id = @sponsorer.payment_plan+"-"+@sponsorer.sponsorer_type.downcase

customer = createStripeCustomer(current_user.email, params[:stripeToken], plan_id)

@sponsorer.stripe_customer_id = customer.id

subscription = customer.subscriptions.data.first
@sponsorer.stripe_subscription_id = subscription.id
@sponsorer.subscribed_at = Time.at(subscription.created).to_datetime
@sponsorer.subscription_expires_at = Time.at(subscription.current_period_end).to_datetime
@sponsorer.subscription_status = subscription.status
rescue Stripe::StripeError => e
flash[:error] = e.message
else
if @sponsorer.save
SponsorMailer.notify_subscription_details(@sponsorer.user_id.to_s, @sponsorer.payment_plan, SPONSOR[@sponsorer.sponsorer_type.downcase][@sponsorer.payment_plan]).deliver_later
redirect_to sponsorer_details_path #sponsorer dashboard
flash[:notice] = "saved sponsorship details successfully"
end
end
else
flash[:error] = @sponsorer.errors.full_messages.join(',')
end
end

def update_card
begin
customer = Stripe::Customer.retrieve(@sponsor.stripe_customer_id)
customer.source = params[:stripeToken]
rescue Stripe::StripeError => e
flash[:error] = e.message
else
customer.save
flash[:notice] = 'Your card has been updated successfully'
end
redirect_to sponsorer_details_path
end

def cancel_subscription
begin
delete_subscription(@sponsor.stripe_subscription_id)
rescue Stripe::StripeError => e
flash[:error] = e.message
else
flash[:notice] = "Your subscription has been cancelled successfully"
end
redirect_to sponsorer_details_path
end

private

def sponsorer_params
params.require(:sponsorer_detail).permit!
end

def load_sponsorer
@sponsor = SponsorerDetail.find_by(user_id: params[:id])
end
end
Loading

0 comments on commit 128a74c

Please sign in to comment.