Skip to content

Commit

Permalink
add donating through the codebar website
Browse files Browse the repository at this point in the history
  • Loading branch information
KimberleyCook committed Jul 15, 2017
1 parent 007734e commit 39ace08
Show file tree
Hide file tree
Showing 31 changed files with 187 additions and 48 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ gem 'redcarpet'

gem 'gibbon', '~> 1.1.5'

gem 'stripe'

group :development do
gem 'letter_opener'
gem 'better_errors'
Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
stripe (3.0.1)
faraday (~> 0.9)
term-ansicolor (1.3.2)
tins (~> 1.0)
thor (0.19.1)
Expand Down Expand Up @@ -454,6 +456,7 @@ DEPENDENCIES
sass-rails (~> 5.0.1)
shoulda-matchers (~> 3.1)
simple_form
stripe
timecop
turbolinks
tzinfo-data
Expand All @@ -463,4 +466,4 @@ RUBY VERSION
ruby 2.3.3p222

BUNDLED WITH
1.14.6
1.15.1
Binary file removed app/assets/images/dot.png
Binary file not shown.
Binary file added app/assets/images/sponsors/8th-Light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/StreetTeam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/bloomberg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/gds-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/google.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/mozilla.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/pivotal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/shutl_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/softwire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/the-guardian.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/ticketmaster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/sponsors/ustwo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/assets/images/students.png
Binary file not shown.
Binary file removed app/assets/images/teaching.png
Binary file not shown.
41 changes: 41 additions & 0 deletions app/assets/javascripts/donations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
$(function() {
var handler = StripeCheckout.configure({
key: stripePublishableKey,
image: "https://avatars1.githubusercontent.com/u/5642384?v=3&s=300",
currency: 'GBP',
token: function(token) {
var name = $('#donation_name').val();
var amount = $('#donation_amount').val();
$.ajax({
type: "POST",
url: '/donations',
data: { amount: amount*100, name: name, data: token }
}).done(function(response) {
$('.donation-container').html(response);
}).fail(function(xhr, status, e){
$('.message').html("Your transaction has not been succesful. Please try again.");
});
}
});

$('#donate').on('click', function(e) {
var amount = $('#donation_amount').val();
if (!$.isNumeric(amount)) {
$('.message').html("You have not entered a valid amount.");
return;
}

$('.message').html("");

handler.open({
name: 'codebar',
description: 'Donation of £' + amount,
amount: amount*100
});
e.preventDefault();
});

$(window).on('popstate', function() {
handler.close();
});
});
9 changes: 9 additions & 0 deletions app/assets/stylesheets/partials/_sponsors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@
}
}

.small-image {
max-height: 100px;
}

.sponsor-row {
display: flex;
justify-content: center;
align-items: center;
}
23 changes: 23 additions & 0 deletions app/controllers/donations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class DonationsController < ApplicationController
def new
end

def create
@amount = params[:amount]

customer = Stripe::Customer.create(
email: params[:data][:email],
description: params[:name],
source: params[:data][:id]
)

charge = Stripe::Charge.create(
:amount => @amount,
:description => 'Donation to Codebar',
:currency => 'gbp',
:customer => customer.id,
)

render layout: false
end
end
5 changes: 5 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ def twitter_id
def contact_email
@contact_email ||= @session.present? ? @session.chapter.email : "[email protected]"
end

def active_link_class(link_path)
current_page?(link_path) ? "active" : ""
end

end
5 changes: 5 additions & 0 deletions app/views/donations/create.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.stripe.reverse
.row
%h3 Thank You
%p Your donation has been processed. Thank you for supporting our effort to create a more diverse tech community.
%p If you would like an invoice for your donation, please send an email to [email protected]
56 changes: 56 additions & 0 deletions app/views/donations/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
- content_for :head do
%script{:type => "text/javascript", :src => "https://checkout.stripe.com/checkout.js"}

:javascript
var stripePublishableKey = "#{Rails.configuration.stripe[:publishable_key]}"


= javascript_include_tag 'donations'

.stripe.reverse
.row
.large-12.columns
%h2 Donations

.stripe.reverse.donation-container
.row
.medium-6.columns
%p.lead Firstly thank you for considering a donation to codebar, without your support we would not be able to continue.
%p.lead By donating to codebar you are helping to promote diversity in the tech industry so that more women, LGBTQA and other underrepresented folks will be able to get started with programming and raise their skills to the next level.
.medium-6.columns
= simple_form_for :donation, url: donations_path, method: :post do |f|
= f.input :name, placeholder: "Name (blank for anonymous donations)", required: false, html: {id: "name"}
= f.input :amount, placeholder: "25.00", required: true, id: "amount"
= f.submit :Donate, class: 'button', id: "donate"
.message

.stripe.reverse.text-center
.row
.small-12.columns
%h3 A big thank you to some of our sponsors
.row.sponsor-row
.medium-2.small-4.columns
= image_tag "sponsors/8th-Light.png", class: "small-image", alt: "codebar logo"
.medium-2.small-4.columns
=image_tag "sponsors/bloomberg.png", alt: "Bloomberg"
.medium-2.small-4.columns
=image_tag "sponsors/ustwo.png", alt: "ustwo"
.medium-2.small-4.columns
=image_tag "sponsors/gds-logo.png", alt: "GDS"
.medium-2.small-4.columns
=image_tag "sponsors/google.png", alt: "Google"
.medium-2.small-4.columns
=image_tag "sponsors/mozilla.png", alt: "Mozilla"
.row.sponsor-row
.medium-2.small-4.columns
=image_tag "sponsors/pivotal.png", alt: "Pivotal Labs"
.medium-2.small-4.columns
=image_tag "sponsors/shutl_logo.png", alt: "Shutl"
.medium-2.small-4.columns
=image_tag "sponsors/softwire.png", alt: "Softwire"
.medium-2.small-4.columns
=image_tag "sponsors/StreetTeam.png", alt: "StreetTeam"
.medium-2.small-4.columns
=image_tag "sponsors/the-guardian.png", alt: "The Guardian"
.medium-2.small-4.columns
=image_tag "sponsors/ticketmaster.png", alt: "Ticketmaster"
2 changes: 1 addition & 1 deletion app/views/jobs/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
%input#short{type: 'checkbox'}
%label{for: 'short'} It's short and to the point

=link_to "Make payment", "https://donate.codebar.io", class: 'button tiny round'
=link_to "Make payment", "https://codebar.io/donations/new", class: 'button tiny round'
%br
%small *Posted jobs will only be visible to our members after they are reviewed and approved by an organiser.

Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_footer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
%li= link_to t("navigation.coaches"), coaches_path
%li= link_to t("navigation.sponsors"), sponsors_path
%li= link_to t("navigation.events"), events_path
-# %li.active= link_to t("navigation.donate"), "http://donate.codebar.io"
%li.active= link_to t("navigation.donate"), new_donation_path

.large-3.columns
= render partial: 'shared/social_media'
2 changes: 1 addition & 1 deletion app/views/layouts/_meta.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%meta{ property: 'og:type', content: 'website' }
%meta{ property: 'og:locale', content: 'en_GB' }
%meta{ property: 'og:site_name', content: 'codebar' }
%meta{ name: 'keywords', content: 'codebar, programming, diversity, html, css, javascript, ruby' }
%meta{ name: 'keywords', content: 'codebar, programming, diversity, html, css, javascript, ruby, python' }
%meta{ property: 'og:image', content: 'http://codebar.io/images/logo-square.png' }
%meta{ property: 'og:url', content: "http://codebar.io#{url_for(nil)}" }
%meta{ property: 'og:title', content: 'codebar' }
Expand Down
42 changes: 13 additions & 29 deletions app/views/layouts/_navigation.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,22 @@
%li
= link_to 'https://medium.com/@codebar' do
%span Blog
- if current_page?(events_path)
%li.active
= link_to events_path do
%span Events
- else
%li
= link_to events_path do
%span Events
%li{class: active_link_class(events_path)}
= link_to events_path do
%span Events
%li
= link_to 'http://tutorials.codebar.io' do
%span Tutorials

- if current_page?(coaches_path)
%li.active
= link_to coaches_path do
%span Coaches
- else
%li
= link_to coaches_path do
%span Coaches
- if current_page?(sponsors_path)
%li.active
= link_to sponsors_path do
%span Sponsors
- else
%li
= link_to sponsors_path do
%span Sponsors
-# %li
-# = link_to 'http://donate.codebar.io' do
-# %span
-# %highlight Donate
%li{class: active_link_class(coaches_path)}
= link_to coaches_path do
%span Coaches
%li{class: active_link_class(sponsors_path)}
= link_to sponsors_path do
%span Sponsors
%li{class: active_link_class(new_donation_path)}
= link_to new_donation_path do
%span
%highlight Donate
- if !logged_in?
%li
= link_to '/auth/github' do
Expand Down
6 changes: 4 additions & 2 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': true
= javascript_include_tag 'vendor/modernizr'
= javascript_include_tag 'application', 'data-turbolinks-track': true
%link{ href: 'https://fonts.googleapis.com/css?family=Gabriela', rel: 'stylesheet', type: 'text/css' }
%link{ href: 'https://fonts.googleapis.com/css?family=Cousine:400,700', rel:'stylesheet', type:'text/css'}
%link{ href: 'https://fonts.googleapis.com/css?family=Open+Sans:400,300', rel:'stylesheet', type:'text/css' }

// this gets any content from page templates
= content_for :head

= csrf_meta_tags

%body.no-js
Expand Down
1 change: 1 addition & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rails.application.config.assets.precompile += %w( donations.js )
6 changes: 6 additions & 0 deletions config/initializers/stripe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Rails.configuration.stripe = {
:publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'],
:secret_key => ENV['STRIPE_SECRET_KEY']
}

Stripe.api_key = Rails.configuration.stripe[:secret_key]
28 changes: 15 additions & 13 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

get '/profile' => "members#profile", as: :profile

resources :subscriptions, only: [ :index, :create ]
resources :subscriptions, only: [:index, :create]
delete '/subscriptions' => 'subscriptions#destroy', as: :destroy_subscriptions

get "unsubscribe/:token" => "members#unsubscribe", as: :unsubscribe

resources :invitation, only: [ :show ] do
resources :invitation, only: [:show] do
member do
post "accept_with_note", as: :accept_with_note
post "update_note"
Expand All @@ -39,7 +39,7 @@
resource :waiting_list, only: [:create, :destroy]
end

resources :invitations, only: [ :index ]
resources :invitations, only: [:index]

resources :meetings, only: [:show] do
get 'invitation/attend' => 'invitations#rsvp_meeting', as: :invitation
Expand All @@ -55,7 +55,7 @@
end
end

resources :events, only: [ :index, :show ] do
resources :events, only: [:index, :show] do
post 'rsvp'
get 'student', as: :student_rsvp
get 'coach', as: :coach_rsvp
Expand All @@ -64,15 +64,15 @@
post 'invitation/:token/reject' => 'invitations#reject', as: :reject
end

resources :courses, only: [ :show ] do
resources :courses, only: [:show] do
get "rsvp"
end
resources :workshops, only: [ :show ] do
resources :workshops, only: [:show] do
member do
post 'rsvp'
end
end
resources :feedback, only: [ :show ] do
resources :feedback, only: [:show] do
member do
patch "submit"
get "success"
Expand All @@ -95,7 +95,7 @@
get '/guide' => "portal#guide", as: :guide


resources :jobs, only: [ :index, :show] do
resources :jobs, only: [:index, :show] do
get 'all', on: :collection
get 'approve'
end
Expand All @@ -105,13 +105,13 @@
get :send_eligibility_email
get :send_attendance_email
get :update_subscriptions
resources :bans, only: [ :index, :new, :create ]
resources :bans, only: [:index, :new, :create]
end
resources :member_notes, only: [:create]

resources :chapters, only: [ :index, :new, :create, :show, :edit, :update] do
resources :chapters, only: [:index, :new, :create, :show, :edit, :update] do
get :members
resources :workshops, only: [ :index ]
resources :workshops, only: [:index]
end

resources :events, only: [:new, :create, :show, :edit, :update] do
Expand All @@ -134,7 +134,7 @@

resources :meeting_invitations, only: [:create, :update]

resources :groups, only: [ :index, :new, :create, :show]
resources :groups, only: [:index, :new, :create, :show]
resources :sponsors, except: [:destroy]

resources :feedback, only: [:index]
Expand All @@ -155,7 +155,7 @@
end

namespace :coach do
resources :feedback, only: [ :index ]
resources :feedback, only: [:index]
end

match '/auth/:service/callback' => 'auth_services#create', via: %i(get post)
Expand All @@ -164,5 +164,7 @@
match '/register' => 'auth_sessions#create', via: %i(get), as: :registration

resources :sponsors, only: [:index]
resources :donations, only: [:new, :create]

get ':id' => 'chapter#show', as: :chapter
end

0 comments on commit 39ace08

Please sign in to comment.