diff --git a/Gemfile b/Gemfile index 8fd15b4f1..ece2d4de9 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,8 @@ gem 'redcarpet' gem 'gibbon', '~> 1.1.5' +gem 'stripe' + group :development do gem 'letter_opener' gem 'better_errors' diff --git a/Gemfile.lock b/Gemfile.lock index 40d7f33ac..502d7a135 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -454,6 +456,7 @@ DEPENDENCIES sass-rails (~> 5.0.1) shoulda-matchers (~> 3.1) simple_form + stripe timecop turbolinks tzinfo-data @@ -463,4 +466,4 @@ RUBY VERSION ruby 2.3.3p222 BUNDLED WITH - 1.14.6 + 1.15.1 diff --git a/app/assets/images/dot.png b/app/assets/images/dot.png deleted file mode 100644 index a0f12c84e..000000000 Binary files a/app/assets/images/dot.png and /dev/null differ diff --git a/app/assets/images/sponsors/8th-Light.png b/app/assets/images/sponsors/8th-Light.png new file mode 100644 index 000000000..86339e7a7 Binary files /dev/null and b/app/assets/images/sponsors/8th-Light.png differ diff --git a/app/assets/images/sponsors/StreetTeam.png b/app/assets/images/sponsors/StreetTeam.png new file mode 100644 index 000000000..98b050779 Binary files /dev/null and b/app/assets/images/sponsors/StreetTeam.png differ diff --git a/app/assets/images/sponsors/bloomberg.png b/app/assets/images/sponsors/bloomberg.png new file mode 100644 index 000000000..528db78ff Binary files /dev/null and b/app/assets/images/sponsors/bloomberg.png differ diff --git a/app/assets/images/sponsors/gds-logo.png b/app/assets/images/sponsors/gds-logo.png new file mode 100644 index 000000000..65ec102c2 Binary files /dev/null and b/app/assets/images/sponsors/gds-logo.png differ diff --git a/app/assets/images/sponsors/google.png b/app/assets/images/sponsors/google.png new file mode 100644 index 000000000..a008c8d1e Binary files /dev/null and b/app/assets/images/sponsors/google.png differ diff --git a/app/assets/images/sponsors/mozilla.png b/app/assets/images/sponsors/mozilla.png new file mode 100644 index 000000000..8911b81ce Binary files /dev/null and b/app/assets/images/sponsors/mozilla.png differ diff --git a/app/assets/images/sponsors/pivotal.png b/app/assets/images/sponsors/pivotal.png new file mode 100644 index 000000000..1cb86fe10 Binary files /dev/null and b/app/assets/images/sponsors/pivotal.png differ diff --git a/app/assets/images/sponsors/shutl_logo.png b/app/assets/images/sponsors/shutl_logo.png new file mode 100644 index 000000000..c686beb51 Binary files /dev/null and b/app/assets/images/sponsors/shutl_logo.png differ diff --git a/app/assets/images/sponsors/softwire.png b/app/assets/images/sponsors/softwire.png new file mode 100644 index 000000000..c99a20550 Binary files /dev/null and b/app/assets/images/sponsors/softwire.png differ diff --git a/app/assets/images/sponsors/the-guardian.png b/app/assets/images/sponsors/the-guardian.png new file mode 100644 index 000000000..ae831b3e0 Binary files /dev/null and b/app/assets/images/sponsors/the-guardian.png differ diff --git a/app/assets/images/sponsors/ticketmaster.png b/app/assets/images/sponsors/ticketmaster.png new file mode 100644 index 000000000..c267d6d44 Binary files /dev/null and b/app/assets/images/sponsors/ticketmaster.png differ diff --git a/app/assets/images/sponsors/ustwo.png b/app/assets/images/sponsors/ustwo.png new file mode 100644 index 000000000..00a26f2ca Binary files /dev/null and b/app/assets/images/sponsors/ustwo.png differ diff --git a/app/assets/images/students.png b/app/assets/images/students.png deleted file mode 100644 index 2c208eeda..000000000 Binary files a/app/assets/images/students.png and /dev/null differ diff --git a/app/assets/images/teaching.png b/app/assets/images/teaching.png deleted file mode 100644 index 78c194d11..000000000 Binary files a/app/assets/images/teaching.png and /dev/null differ diff --git a/app/assets/javascripts/donations.js b/app/assets/javascripts/donations.js new file mode 100644 index 000000000..411de1231 --- /dev/null +++ b/app/assets/javascripts/donations.js @@ -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(); + }); +}); diff --git a/app/assets/stylesheets/partials/_sponsors.scss b/app/assets/stylesheets/partials/_sponsors.scss index f7048da46..9cee43bae 100644 --- a/app/assets/stylesheets/partials/_sponsors.scss +++ b/app/assets/stylesheets/partials/_sponsors.scss @@ -4,3 +4,12 @@ } } +.small-image { + max-height: 100px; +} + +.sponsor-row { + display: flex; + justify-content: center; + align-items: center; +} diff --git a/app/controllers/donations_controller.rb b/app/controllers/donations_controller.rb new file mode 100644 index 000000000..42705481d --- /dev/null +++ b/app/controllers/donations_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fd8946486..f705c4064 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -43,4 +43,9 @@ def twitter_id def contact_email @contact_email ||= @session.present? ? @session.chapter.email : "hello@codebar.io" end + + def active_link_class(link_path) + current_page?(link_path) ? "active" : "" + end + end diff --git a/app/views/donations/create.html.haml b/app/views/donations/create.html.haml new file mode 100644 index 000000000..f20ba5cdf --- /dev/null +++ b/app/views/donations/create.html.haml @@ -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 company@codebar.io diff --git a/app/views/donations/new.html.haml b/app/views/donations/new.html.haml new file mode 100644 index 000000000..59909b2b5 --- /dev/null +++ b/app/views/donations/new.html.haml @@ -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" diff --git a/app/views/jobs/new.html.haml b/app/views/jobs/new.html.haml index 60edd541a..475b301d6 100644 --- a/app/views/jobs/new.html.haml +++ b/app/views/jobs/new.html.haml @@ -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. diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 2a3a92bf0..f2b9a085d 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -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' diff --git a/app/views/layouts/_meta.html.haml b/app/views/layouts/_meta.html.haml index 9095edf14..3a6ac4387 100644 --- a/app/views/layouts/_meta.html.haml +++ b/app/views/layouts/_meta.html.haml @@ -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' } diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 6a7f08de4..d89524ff0 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -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 diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 3ddef671d..f0def7df7 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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 diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 000000000..ab858655f --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1 @@ +Rails.application.config.assets.precompile += %w( donations.js ) diff --git a/config/initializers/stripe.rb b/config/initializers/stripe.rb new file mode 100644 index 000000000..7e4a7875f --- /dev/null +++ b/config/initializers/stripe.rb @@ -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] diff --git a/config/routes.rb b/config/routes.rb index 92a51b26b..17fada32b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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" @@ -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 @@ -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 @@ -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" @@ -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 @@ -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 @@ -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] @@ -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) @@ -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