Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix bug on signup and add active_merchant gem

  • Loading branch information...
commit fcfec2b2440ac88f794c1eda68923aa875bf7797 1 parent 7b23595
Yen Ha-Thi-Bach authored
2  Gemfile
@@ -8,6 +8,8 @@ gem 'rails', '3.1.0'
8 8 gem 'mysql2'
9 9 gem 'omniauth'
10 10 gem "fbgraph"
  11 +gem "money"
  12 +gem "activemerchant"
11 13
12 14 # Gems used only for assets and not required
13 15 # in production environments by default.
11 Gemfile.lock
@@ -15,6 +15,11 @@ GEM
15 15 rack-mount (~> 0.8.2)
16 16 rack-test (~> 0.6.1)
17 17 sprockets (~> 2.0.0)
  18 + activemerchant (1.17.0)
  19 + activesupport (>= 2.3.11)
  20 + braintree (>= 2.0.0)
  21 + builder (>= 2.0.0)
  22 + json (>= 1.5.1)
18 23 activemodel (3.1.0)
19 24 activesupport (= 3.1.0)
20 25 bcrypt-ruby (~> 3.0.0)
@@ -34,6 +39,8 @@ GEM
34 39 ansi (1.3.0)
35 40 arel (2.2.1)
36 41 bcrypt-ruby (3.0.1)
  42 + braintree (2.11.0)
  43 + builder (>= 2.0.0)
37 44 builder (3.0.0)
38 45 coffee-rails (3.1.1)
39 46 coffee-script (>= 2.2.0)
@@ -76,6 +83,8 @@ GEM
76 83 mime-types (~> 1.16)
77 84 treetop (~> 1.4.8)
78 85 mime-types (1.16)
  86 + money (3.7.1)
  87 + i18n (~> 0.4)
79 88 multi_json (1.0.3)
80 89 multi_xml (0.2.2)
81 90 multipart-post (1.1.3)
@@ -187,9 +196,11 @@ PLATFORMS
187 196 ruby
188 197
189 198 DEPENDENCIES
  199 + activemerchant
190 200 coffee-rails (~> 3.1.0)
191 201 fbgraph
192 202 jquery-rails
  203 + money
193 204 mysql2
194 205 omniauth
195 206 rails (= 3.1.0)
3  app/assets/javascripts/payments.js.coffee
... ... @@ -0,0 +1,3 @@
  1 +# Place all the behaviors and hooks related to the matching controller here.
  2 +# All this logic will automatically be available in application.js.
  3 +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/stylesheets/payments.css.scss
... ... @@ -0,0 +1,3 @@
  1 +// Place all the styles related to the payments controller here.
  2 +// They will automatically be included in application.css.
  3 +// You can use Sass (SCSS) here: http://sass-lang.com/
5 app/controllers/payments_controller.rb
... ... @@ -0,0 +1,5 @@
  1 +class PaymentsController < ApplicationController
  2 + def new
  3 + end
  4 +
  5 +end
1  app/controllers/users_controller.rb
@@ -30,6 +30,7 @@ def create
30 30 def activate
31 31 logout_keeping_session!
32 32 user = User.find_by_activation_code(params[:activation_code]) unless params[:activation_code].blank?
  33 + puts user.inspect, "==================================="
33 34 case
34 35 when (!params[:activation_code].blank?) && user && !user.active?
35 36 user.activate!
2  app/helpers/payments_helper.rb
... ... @@ -0,0 +1,2 @@
  1 +module PaymentsHelper
  2 +end
2  app/models/user.rb
@@ -24,7 +24,7 @@ class User < ActiveRecord::Base
24 24 :if => lambda { |c| c.provider.blank? }
25 25
26 26 validates :password, :presence => true, :if => lambda { |c| c.provider.blank? }
27   - validates :password_comfirmation, :presence => true, :if => lambda { |c| c.provider.blank? }
  27 + validates :password_confirmation, :presence => true, :if => lambda { |c| c.provider.blank? }
28 28
29 29 # HACK HACK HACK -- how to do attr_accessible from here?
30 30 # prevents a user from submitting a crafted form that bypasses activation
22 app/views/payments/new.html.erb
... ... @@ -0,0 +1,22 @@
  1 +<h1>Payments</h1>
  2 +
  3 +<% payment_service_for @order.id, PAYPAL_ACCOUNT,
  4 + :amount => @order.price, :currency => 'EUR',
  5 + :service => :paypal do |service|
  6 +
  7 + service.customer :first_name => current_user.name,
  8 + :last_name => current_user.surname,
  9 + :email => current_user.email
  10 +
  11 + service.item_name @order.items_summary
  12 +
  13 + # PayPal will POST a callback here when the payment is done
  14 + service.notify_url notifications_url(@order)
  15 + # PayPal will take your user here with a POST after he pays
  16 + service.return_url paypal_return_notifications_url(@order)
  17 + # PayPal will redirect your user here if he cancels the payment
  18 + service.cancel_return_url paypal_cancel_notifications_url(@order) %>
  19 +
  20 + <%= submit_tag 'Pay this order' %>
  21 +<% end %>
  22 +
6 config/initializers/active_merchant.rb
... ... @@ -0,0 +1,6 @@
  1 +if Rails.env.production?
  2 + PAYPAL_ACCOUNT = 'yencn02@live.com'
  3 +else
  4 + PAYPAL_ACCOUNT = 'yencn02@gmail.com'
  5 + ActiveMerchant::Billing::Base.mode = :test
  6 +end
2  config/routes.rb
... ... @@ -1,5 +1,7 @@
1 1 Yenh::Application.routes.draw do
2 2
  3 + get "payments/new"
  4 +
3 5 # The priority is based upon order of creation:
4 6 # first created -> highest priority.
5 7

0 comments on commit fcfec2b

Please sign in to comment.
Something went wrong with that request. Please try again.