├── lib └── tasks │ └── .gitkeep ├── public ├── favicon.ico ├── javascripts │ └── .gitkeep ├── stylesheets │ └── .gitkeep ├── images │ └── rails.png ├── robots.txt ├── 422.html ├── 404.html └── 500.html ├── vendor └── plugins │ └── .gitkeep ├── app ├── helpers │ ├── donates_helper.rb │ └── application_helper.rb ├── controllers │ ├── application_controller.rb │ ├── donates_controller.rb │ └── transactions_controller.rb ├── models │ ├── transaction.rb │ └── donate.rb ├── assets │ └── stylesheets │ │ ├── application.css │ │ └── donatecn.css └── views │ ├── layouts │ └── application.html.haml │ └── donates │ ├── index.html.haml │ └── confirm.html.haml ├── test ├── unit │ ├── helpers │ │ └── donates_helper_test.rb │ └── transaction_test.rb ├── functional │ ├── donates_controller_test.rb │ └── transactions_controller_test.rb ├── performance │ └── browsing_test.rb ├── fixtures │ └── transactions.yml └── test_helper.rb ├── config.ru ├── config ├── environment.rb ├── boot.rb ├── initializers │ ├── mime_types.rb │ ├── backtrace_silencers.rb │ ├── session_store.rb │ ├── secret_token.rb │ ├── wrap_parameters.rb │ └── inflections.rb ├── locales │ └── en.yml ├── database.yml.example ├── deploy.rb ├── environments │ ├── development.rb │ ├── test.rb │ └── production.rb ├── routes.rb └── application.rb ├── doc └── README_FOR_APP ├── README.md ├── Capfile ├── .gitignore ├── Rakefile ├── script └── rails ├── db ├── seeds.rb ├── migrate │ ├── 20120514124833_create_pay_fu_transactions.rb │ ├── 20110123133433_create_transactions.rb │ └── 20110306145518_add_buyer_email_to_transactions.rb └── schema.rb ├── Gemfile └── Gemfile.lock /lib/tasks/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/plugins/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/javascripts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/stylesheets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/helpers/donates_helper.rb: -------------------------------------------------------------------------------- 1 | module DonatesHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /public/images/rails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bob/donatecn/master/public/images/rails.png -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | end 4 | -------------------------------------------------------------------------------- /test/unit/helpers/donates_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class DonatesHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /app/models/transaction.rb: -------------------------------------------------------------------------------- 1 | class Transaction < ActiveRecord::Base 2 | scope :histories, where(:trade_status => "TRADE_SUCCESS").order("notify_time desc") 3 | end 4 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Donatecn::Application 5 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | Donatecn::Application.initialize! 6 | -------------------------------------------------------------------------------- /test/unit/transaction_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class TransactionTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | # Set up gems listed in the Gemfile. 4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 5 | 6 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 7 | -------------------------------------------------------------------------------- /doc/README_FOR_APP: -------------------------------------------------------------------------------- 1 | Use this README file to introduce your application and point to useful places in the API for learning more. 2 | Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. 3 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-Agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /test/functional/donates_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class DonatesControllerTest < ActionController::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | README 2 | ====== 3 | 4 | this is the demo for [activemerchant_patch_for_china][0]. 5 | 6 | Website 7 | ------- 8 | 9 | 10 | 11 | 12 | [0]: http://github.com/flyerhzm/activemerchant_patch_for_china 13 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /Capfile: -------------------------------------------------------------------------------- 1 | load 'deploy' if respond_to?(:namespace) # cap2 differentiator 2 | load 'deploy/assets' 3 | 4 | Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } 5 | 6 | load 'config/deploy' # remove this line to skip loading any of the default tasks 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | *.sassc 3 | .sass-cache 4 | capybara-*.html 5 | .rspec 6 | /.bundle 7 | /vendor/bundle 8 | /log/* 9 | /tmp/* 10 | /db/*.sqlite3 11 | /public/system/* 12 | /coverage/ 13 | /spec/tmp/* 14 | **.orig 15 | config/*.yml 16 | rerun.txt 17 | .rvmrc 18 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | require 'rake' 6 | 7 | Donatecn::Application.load_tasks 8 | -------------------------------------------------------------------------------- /test/performance/browsing_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | require 'rails/performance_test_help' 3 | 4 | # Profiling results for each test method are written to tmp/performance. 5 | class BrowsingTest < ActionDispatch::PerformanceTest 6 | def test_homepage 7 | get '/' 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) 7 | # Mayor.create(:name => 'Daley', :city => cities.first) 8 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll automatically include all the stylesheets available in this directory 3 | * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at 4 | * the top of the compiled file, but it's generally better to create a new file per style scope. 5 | *= require_self 6 | *= require_tree . 7 | */ 8 | -------------------------------------------------------------------------------- /test/functional/transactions_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class TransactionsControllerTest < ActionController::TestCase 4 | test "should get notify" do 5 | get :notify 6 | assert_response :success 7 | end 8 | 9 | test "should get done" do 10 | get :done 11 | assert_response :success 12 | end 13 | 14 | test "should get show" do 15 | get :show 16 | assert_response :success 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | gem 'rails', "3.2.2" 4 | 5 | gem 'mysql2' 6 | gem 'haml' 7 | gem 'guid' 8 | 9 | gem 'activemerchant' 10 | gem 'activemerchant_patch_for_china' 11 | gem 'pay_fu', :git => "git@github.com:transist/pay_fu.git" 12 | 13 | group :assets do 14 | gem 'sass-rails' 15 | gem 'coffee-rails' 16 | gem 'uglifier' 17 | end 18 | 19 | gem 'jquery-rails' 20 | 21 | group :production do 22 | gem 'therubyracer' 23 | end 24 | -------------------------------------------------------------------------------- /app/models/donate.rb: -------------------------------------------------------------------------------- 1 | class Donate 2 | include ActiveModel::Validations 3 | include ActiveModel::Conversion 4 | extend ActiveModel::Naming 5 | 6 | attr_accessor :amount, :number, :currency 7 | validates_numericality_of :amount, :greater_than => 0 8 | 9 | def initialize(attributes = {}) 10 | attributes.each do |name, value| 11 | send("#{name}=", value) 12 | end 13 | end 14 | 15 | def persisted? 16 | false 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.haml: -------------------------------------------------------------------------------- 1 | !!! 2 | %html 3 | %head 4 | %title Donatecn 5 | = stylesheet_link_tag "application" 6 | = csrf_meta_tag 7 | %body 8 | #container 9 | #header 10 | %h1 捐助activemerchant_patch_for_china项目 11 | #wrapper 12 | - unless flash.blank? 13 | #flash 14 | - flash.each do |type, message| 15 | .message{:class => type}= message 16 | #main= yield 17 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /db/migrate/20120514124833_create_pay_fu_transactions.rb: -------------------------------------------------------------------------------- 1 | class CreatePayFuTransactions < ActiveRecord::Migration 2 | def change 3 | create_table :pay_fu_transactions do |t| 4 | t.string :type 5 | t.string :transaction_id 6 | t.string :transaction_type 7 | t.string :payment_status 8 | t.datetime :payment_date 9 | t.integer :gross 10 | t.string :raw_post 11 | 12 | t.timestamps 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /test/fixtures/transactions.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html 2 | 3 | one: 4 | notify_id: MyString 5 | total_fee: 1.5 6 | trade_status: MyString 7 | trade_no: MyString 8 | notify_time: 2011-01-23 21:34:33 9 | raw_post: MyText 10 | 11 | two: 12 | notify_id: MyString 13 | total_fee: 1.5 14 | trade_status: MyString 15 | trade_no: MyString 16 | notify_time: 2011-01-23 21:34:33 17 | raw_post: MyText 18 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Donatecn::Application.config.session_store :cookie_store, key: '_donatecn_session' 4 | 5 | # Use the database for sessions instead of the cookie-based default, 6 | # which shouldn't be used to store highly confidential information 7 | # (create the session table with "rails generate session_migration") 8 | # Donatecn::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /db/migrate/20110123133433_create_transactions.rb: -------------------------------------------------------------------------------- 1 | class CreateTransactions < ActiveRecord::Migration 2 | def self.up 3 | create_table :transactions do |t| 4 | t.string :notify_id 5 | t.float :total_fee 6 | t.string :trade_status 7 | t.string :trade_no 8 | t.datetime :notify_time 9 | t.text :raw_post 10 | 11 | t.timestamps 12 | end 13 | end 14 | 15 | def self.down 16 | drop_table :transactions 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] = "test" 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. 7 | # 8 | # Note: You'll currently still have to declare fixtures explicitly in integration tests 9 | # -- they do not yet inherit this setting 10 | fixtures :all 11 | 12 | # Add more helper methods to be used by all tests here... 13 | end 14 | -------------------------------------------------------------------------------- /config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | # Make sure the secret is at least 30 characters and all random, 6 | # no regular words or you'll be exposed to dictionary attacks. 7 | Donatecn::Application.config.secret_token = '7669a6ae794221df041d6c451f4407a4ad44b6bb43a132b9df2a4e447851f515a6c8134c32c62a5f856021d2126565322f4c7d7c396d0267f17433f582fc9ff9' 8 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # Disable root element in JSON by default. 12 | ActiveSupport.on_load(:active_record) do 13 | self.include_root_in_json = false 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20110306145518_add_buyer_email_to_transactions.rb: -------------------------------------------------------------------------------- 1 | class AddBuyerEmailToTransactions < ActiveRecord::Migration 2 | def self.up 3 | add_column :transactions, :buyer_email, :string 4 | 5 | say_with_time "add buy email" do 6 | Transaction.all.each do |transaction| 7 | notification = ActiveMerchant::Billing::Integrations::Alipay::Notification.new(transaction.raw_post) 8 | transaction.update_attribute(:buyer_email, notification.buyer_email) 9 | end 10 | end 11 | end 12 | 13 | def self.down 14 | remove_column :transactions, :buyer_email 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format 4 | # (all these examples are active by default): 5 | # ActiveSupport::Inflector.inflections do |inflect| 6 | # inflect.plural /^(ox)$/i, '\1en' 7 | # inflect.singular /^(ox)en/i, '\1' 8 | # inflect.irregular 'person', 'people' 9 | # inflect.uncountable %w( fish sheep ) 10 | # end 11 | # 12 | # These inflection rules are supported but not enabled by default: 13 | # ActiveSupport::Inflector.inflections do |inflect| 14 | # inflect.acronym 'RESTful' 15 | # end 16 | -------------------------------------------------------------------------------- /config/database.yml.example: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3-ruby (not necessary on OS X Leopard) 3 | development: 4 | adapter: sqlite3 5 | database: db/development.sqlite3 6 | pool: 5 7 | timeout: 5000 8 | 9 | # Warning: The database defined as "test" will be erased and 10 | # re-generated from your development database when you run "rake". 11 | # Do not set this db to the same as development or production. 12 | test: 13 | adapter: sqlite3 14 | database: db/test.sqlite3 15 | pool: 5 16 | timeout: 5000 17 | 18 | production: 19 | adapter: sqlite3 20 | database: db/production.sqlite3 21 | pool: 5 22 | timeout: 5000 23 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The change you wanted was rejected.

23 |

Maybe you tried to change something you didn't have access to.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /app/views/donates/index.html.haml: -------------------------------------------------------------------------------- 1 | %h2 捐助 2 | 3 | = form_for @alipay_donate do |f| 4 | = f.hidden_field :currency 5 | = f.label :amount, '支付宝 金额: ' 6 | ¥ 7 | = f.text_field :amount 8 | = f.submit '捐助' 9 | 10 | = form_for @paypal_donate do |f| 11 | = f.hidden_field :currency 12 | = f.label :amount, 'paypal amount: ' 13 | $ 14 | = f.text_field :amount 15 | = f.submit 'donate' 16 | 17 | %h2 捐助记录 18 | %table.transactions 19 | %th 捐助人 20 | %th 捐助金额 21 | %th 捐助时间 22 | - Transaction.histories.each do |transaction| 23 | %tr.transaction{:class => cycle("even", "odd")} 24 | %td.buyer_email= transaction.buyer_email.sub('%40', ' at ').gsub(/\./, ' dot ') 25 | %td.total_fee= number_to_currency(transaction.total_fee, :unit => '¥') 26 | %td.donate_time= distance_of_time_in_words_to_now(transaction.notify_time) 27 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The page you were looking for doesn't exist.

23 |

You may have mistyped the address or the page may have moved.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

We're sorry, but something went wrong.

23 |

We've been notified about this issue and we'll take a look at it shortly.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /app/controllers/donates_controller.rb: -------------------------------------------------------------------------------- 1 | class DonatesController < ApplicationController 2 | include PayFu::PaypalHelper 3 | include PayFu::AlipayHelper 4 | 5 | def index 6 | @alipay_donate = Donate.new(:currency => 'rmb') 7 | @paypal_donate = Donate.new(:currency => 'usd') 8 | end 9 | 10 | def create 11 | @donate = Donate.new(params[:donate]) 12 | if @donate.valid? 13 | @donate.number = Guid.new.to_s.gsub('-', '') 14 | case @donate.currency 15 | when "usd" 16 | redirect_to_paypal_gateway(:item_name => "donatecn", :amount => @donate.amount) 17 | return 18 | when "rmb" 19 | redirect_to_alipay_gateway(:subject => "donatecn", :body => "donatecn", :amount => @donate.amount, :out_trade_no => "123", :notify_url => pay_fu.alipay_transactions_notify_url) 20 | end 21 | else 22 | render :index 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /app/views/donates/confirm.html.haml: -------------------------------------------------------------------------------- 1 | %h1 捐助确认 2 | 3 | %p.info 捐助金额: ¥#{@donate.amount} 4 | 5 | - payment_service_for @donate.number, AlipayConfig[:account], :service => :alipay, :html => { :id => 'payment-form', :method => :get } do |service| 6 | - service.total_fee @donate.amount 7 | - service.seller :email => AlipayConfig[:email] 8 | - service.notify_url url_for(:only_path => false, :controller => 'transactions', :action => 'notify') 9 | - service.return_url url_for(:only_path => false, :controller => 'transactions', :action => 'done') 10 | - service.charset "utf-8" 11 | - service.service ActiveMerchant::Billing::Integrations::Alipay::Helper::CREATE_DIRECT_PAY_BY_USER 12 | - service.payment_type 1 13 | - service.subject '捐助activemerchat_ptch_for_china项目' 14 | - service.sign 15 | 16 | = button_to_function "确认", "document.getElementById('payment-form').firstChild.remove();document.getElementById('payment-form').submit()" 17 |    18 | = link_to '返回首页', root_path 19 | -------------------------------------------------------------------------------- /app/controllers/transactions_controller.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | class TransactionsController < ApplicationController 3 | def notify 4 | notification = ActiveMerchant::Billing::Integrations::Alipay::Notification.new(request.raw_post) 5 | 6 | transaction_attributes = { 7 | :total_fee => notification.total_fee, 8 | :trade_status => notification.trade_status, 9 | :trade_no => notification.trade_no, 10 | :notify_time => notification.notify_time, 11 | :buyer_email => notification.buyer_email, 12 | :raw_post => request.raw_post 13 | } 14 | 15 | if transaction = Transaction.find_by_notify_id(notification.notify_id) 16 | result = transaction.update_attributes(transaction_attributes) 17 | else 18 | transaction_attributes.merge!(:notify_id => notification.notify_id) 19 | result = Transaction.create(transaction_attributes) 20 | end 21 | 22 | if result 23 | render :text => "success" 24 | else 25 | render :text => "failure" 26 | end 27 | end 28 | 29 | def done 30 | r = ActiveMerchant::Billing::Integrations::Alipay::Return.new(request.query_string) 31 | if r.success? 32 | flash[:notice] = '捐助成功!' 33 | else 34 | flash[:error] = '捐助失败!' 35 | end 36 | redirect_to root_path 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /config/deploy.rb: -------------------------------------------------------------------------------- 1 | set :application, "donate.huangzhimin" 2 | set :repository, "git@github.com:flyerhzm/donatecn.git" 3 | set :rails_env, :production 4 | set :deploy_to, "/home/huangzhi/sites/donate.huangzhimin.com/production" 5 | 6 | set :scm, :git 7 | set :deploy_via, :remote_cache 8 | set :user, 'huangzhi' 9 | set :use_sudo, false 10 | 11 | role :web, "donate.huangzhimin.com" 12 | role :app, "donate.huangzhimin.com" 13 | role :db, "donate.huangzhimin.com", :primary => true 14 | 15 | require 'bundler/capistrano' 16 | 17 | $:.unshift(File.expand_path('./lib', ENV['rvm_path'])) 18 | require "rvm/capistrano" 19 | set :rvm_ruby_string, '1.9.2-p290@donate.huangzhimin.com' 20 | set :rvm_type, :user 21 | 22 | after "deploy:update_code", "config:init" 23 | 24 | namespace :config do 25 | task :init do 26 | run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" 27 | run "ln -nfs #{shared_path}/config/alipay.yml #{release_path}/config/alipay.yml" 28 | run "ln -nfs #{shared_path}/config/pay_fu.yml #{release_path}/config/pay_fu.yml" 29 | end 30 | end 31 | 32 | namespace :deploy do 33 | task :start do ; end 34 | task :stop do ; end 35 | task :restart, :roles => :app, :except => { :no_release => true } do 36 | migrate 37 | cleanup 38 | run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Donatecn::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Log error messages when you accidentally call methods on nil. 10 | config.whiny_nils = true 11 | 12 | # Show full error reports and disable caching 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger 20 | config.active_support.deprecation = :log 21 | 22 | # Only use best-standards-support built into browsers 23 | config.action_dispatch.best_standards_support = :builtin 24 | 25 | # Raise exception on mass assignment protection for Active Record models 26 | config.active_record.mass_assignment_sanitizer = :strict 27 | 28 | # Log the query plan for queries taking more than this (works 29 | # with SQLite, MySQL, and PostgreSQL) 30 | config.active_record.auto_explain_threshold_in_seconds = 0.5 31 | 32 | # Do not compress assets 33 | config.assets.compress = false 34 | 35 | # Expands the lines which load the assets 36 | config.assets.debug = true 37 | end 38 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Donatecn::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | config.whiny_nils = true 16 | 17 | # Show full error reports and disable caching 18 | config.consider_all_requests_local = true 19 | config.action_controller.perform_caching = false 20 | 21 | # Raise exceptions instead of rendering exception templates 22 | config.action_dispatch.show_exceptions = false 23 | 24 | # Disable request forgery protection in test environment 25 | config.action_controller.allow_forgery_protection = false 26 | 27 | # Tell Action Mailer not to deliver emails to the real world. 28 | # The :test delivery method accumulates sent emails in the 29 | # ActionMailer::Base.deliveries array. 30 | config.action_mailer.delivery_method = :test 31 | 32 | # Raise exception on mass assignment protection for Active Record models 33 | config.active_record.mass_assignment_sanitizer = :strict 34 | 35 | # Print deprecation notices to the stderr 36 | config.active_support.deprecation = :stderr 37 | end 38 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended to check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(:version => 20120514124833) do 15 | 16 | create_table "pay_fu_transactions", :force => true do |t| 17 | t.string "type" 18 | t.string "transaction_id" 19 | t.string "transaction_type" 20 | t.string "payment_status" 21 | t.datetime "payment_date" 22 | t.integer "gross" 23 | t.string "raw_post" 24 | t.datetime "created_at", :null => false 25 | t.datetime "updated_at", :null => false 26 | end 27 | 28 | create_table "payment_transactions", :force => true do |t| 29 | t.string "type" 30 | t.string "transaction_id" 31 | t.string "transaction_type" 32 | t.string "payment_status" 33 | t.datetime "payment_date" 34 | t.integer "gross" 35 | t.string "raw_post" 36 | t.datetime "created_at", :null => false 37 | t.datetime "updated_at", :null => false 38 | end 39 | 40 | create_table "transactions", :force => true do |t| 41 | t.string "notify_id" 42 | t.float "total_fee" 43 | t.string "trade_status" 44 | t.string "trade_no" 45 | t.datetime "notify_time" 46 | t.text "raw_post" 47 | t.datetime "created_at", :null => false 48 | t.datetime "updated_at", :null => false 49 | t.string "buyer_email" 50 | end 51 | 52 | end 53 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Donatecn::Application.routes.draw do 2 | mount PayFu::Engine => '/pay_fu', :as => 'pay_fu' 3 | 4 | post "transactions/notify" 5 | get "transactions/done" 6 | 7 | resources :donates 8 | root :to => "donates#index" 9 | # The priority is based upon order of creation: 10 | # first created -> highest priority. 11 | 12 | # Sample of regular route: 13 | # match 'products/:id' => 'catalog#view' 14 | # Keep in mind you can assign values other than :controller and :action 15 | 16 | # Sample of named route: 17 | # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase 18 | # This route can be invoked with purchase_url(:id => product.id) 19 | 20 | # Sample resource route (maps HTTP verbs to controller actions automatically): 21 | # resources :products 22 | 23 | # Sample resource route with options: 24 | # resources :products do 25 | # member do 26 | # get 'short' 27 | # post 'toggle' 28 | # end 29 | # 30 | # collection do 31 | # get 'sold' 32 | # end 33 | # end 34 | 35 | # Sample resource route with sub-resources: 36 | # resources :products do 37 | # resources :comments, :sales 38 | # resource :seller 39 | # end 40 | 41 | # Sample resource route with more complex sub-resources 42 | # resources :products do 43 | # resources :comments 44 | # resources :sales do 45 | # get 'recent', :on => :collection 46 | # end 47 | # end 48 | 49 | # Sample resource route within a namespace: 50 | # namespace :admin do 51 | # # Directs /admin/products/* to Admin::ProductsController 52 | # # (app/controllers/admin/products_controller.rb) 53 | # resources :products 54 | # end 55 | 56 | # You can have the root of your site routed with "root" 57 | # just remember to delete public/index.html. 58 | # root :to => 'welcome#index' 59 | 60 | # See how all your routes lay out with "rake routes" 61 | 62 | # This is a legacy wild controller route that's not recommended for RESTful applications. 63 | # Note: This route will make all actions in every controller accessible via GET requests. 64 | # match ':controller(/:action(/:id))(.:format)' 65 | end 66 | -------------------------------------------------------------------------------- /app/assets/stylesheets/donatecn.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | } 5 | body { 6 | color: #111; 7 | background: #e5e5e5; 8 | font-family: helvetica, arial, sans-serif; 9 | font-size: 12px; 10 | margin: 0; 11 | } 12 | 13 | #container { 14 | min-width: 960px; 15 | } 16 | #header { 17 | background: #002134; 18 | } 19 | #header h1 { 20 | padding: 15px 0; 21 | font-size: 32px; 22 | font-style: normal; 23 | font-weight: bold; 24 | text-transform: none; 25 | letter-spacing: -1px; 26 | line-height: 1.2em; 27 | color: white; 28 | text-shadow: black 1px 1px 2px; 29 | } 30 | #header, #wrapper { 31 | padding: 0 20px; 32 | } 33 | #wrapper { 34 | padding-top: 20px; 35 | } 36 | #flash { 37 | margin: 0 0 20px 0; 38 | } 39 | #flash .message { 40 | padding: 10px; 41 | } 42 | #flash .notice { 43 | background-color: #fff6bf; 44 | border: 2px solid #ffd324; 45 | color: #514721; 46 | } 47 | #flash .error { 48 | background-color: #fbe3e4; 49 | border: 2px solid #fbc2c4; 50 | color: #8a1f11; 51 | } 52 | #main { 53 | -moz-border-radius: 9px; 54 | -webkit-border-radius: 9px; 55 | border-radius: 9px; 56 | border-top-left-radius: 9px 9px; 57 | border-top-right-radius: 9px 9px; 58 | border-bottom-right-radius: 9px 9px; 59 | border-bottom-left-radius: 9px 9px; 60 | 61 | padding: 15px; 62 | background: white; 63 | -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); 64 | -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); 65 | box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); 66 | } 67 | #main h2 { 68 | margin-bottom: 15px; 69 | font-size: 22px; 70 | font-style: normal; 71 | font-weight: bold; 72 | text-transform: none; 73 | letter-spacing: -1px; 74 | line-height: 1.2em; 75 | } 76 | #main form label { 77 | color: #666; 78 | font-weight: bold; 79 | font-size: 1.2em; 80 | margin-right: 10px; 81 | padding: 1px 0; 82 | } 83 | #main form { 84 | margin-bottom: 50px; 85 | } 86 | #main form input[type=text] { 87 | border: 1px solid #E2E2E2; 88 | width: 50px; 89 | height: 18px; 90 | margin-right: 10px; 91 | } 92 | 93 | table { 94 | width: 100%; 95 | border-collapse: collapse; 96 | margin-bottom: 15px; 97 | } 98 | table th { 99 | background: #EAEAEA; 100 | color: #222; 101 | font-weight: normal; 102 | padding: 10px; 103 | text-align: left; 104 | } 105 | table tr.even { 106 | background: #F8F8F8; 107 | } 108 | table td { 109 | border-bottom: 1px solid #EAEAEA; 110 | padding: 10px; 111 | } 112 | 113 | form#payment-form { 114 | margin: 0; 115 | } 116 | 117 | p.info { 118 | margin: 20px 0; 119 | font-size: 1.2em; 120 | } 121 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Donatecn::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # Code is not reloaded between requests 5 | config.cache_classes = true 6 | 7 | # Full error reports are disabled and caching is turned on 8 | config.consider_all_requests_local = false 9 | config.action_controller.perform_caching = true 10 | 11 | # Disable Rails's static asset server (Apache or nginx will already do this) 12 | config.serve_static_assets = false 13 | 14 | # Compress JavaScripts and CSS 15 | config.assets.compress = true 16 | 17 | # Don't fallback to assets pipeline if a precompiled asset is missed 18 | config.assets.compile = false 19 | 20 | # Generate digests for assets URLs 21 | config.assets.digest = true 22 | 23 | # Defaults to Rails.root.join("public/assets") 24 | # config.assets.manifest = YOUR_PATH 25 | 26 | # Specifies the header that your server uses for sending files 27 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 28 | config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 29 | 30 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 31 | # config.force_ssl = true 32 | 33 | # See everything in the log (default is :info) 34 | # config.log_level = :debug 35 | 36 | # Prepend all log lines with the following tags 37 | # config.log_tags = [ :subdomain, :uuid ] 38 | 39 | # Use a different logger for distributed setups 40 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 41 | 42 | # Use a different cache store in production 43 | # config.cache_store = :mem_cache_store 44 | 45 | # Enable serving of images, stylesheets, and JavaScripts from an asset server 46 | # config.action_controller.asset_host = "http://assets.example.com" 47 | 48 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 49 | # config.assets.precompile += %w( search.js ) 50 | 51 | # Disable delivery errors, bad email addresses will be ignored 52 | # config.action_mailer.raise_delivery_errors = false 53 | 54 | # Enable threaded mode 55 | # config.threadsafe! 56 | 57 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 58 | # the I18n.default_locale when a translation can not be found) 59 | config.i18n.fallbacks = true 60 | 61 | # Send deprecation notices to registered listeners 62 | config.active_support.deprecation = :notify 63 | 64 | # Log the query plan for queries taking more than this (works 65 | # with SQLite, MySQL, and PostgreSQL) 66 | # config.active_record.auto_explain_threshold_in_seconds = 0.5 67 | end 68 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | if defined?(Bundler) 6 | # If you precompile assets before deploying to production, use this line 7 | Bundler.require(*Rails.groups(:assets => %w(development test))) 8 | # If you want your assets lazily compiled in production, use this line 9 | # Bundler.require(:default, :assets, Rails.env) 10 | end 11 | 12 | module Donatecn 13 | class Application < Rails::Application 14 | # Settings in config/environments/* take precedence over those specified here. 15 | # Application configuration should go into files in config/initializers 16 | # -- all .rb files in that directory are automatically loaded. 17 | 18 | # Custom directories with classes and modules you want to be autoloadable. 19 | # config.autoload_paths += %W(#{config.root}/extras) 20 | 21 | # Only load the plugins named here, in the order given (default is alphabetical). 22 | # :all can be used as a placeholder for all plugins not explicitly named. 23 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 24 | 25 | # Activate observers that should always be running. 26 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 27 | 28 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 29 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 30 | # config.time_zone = 'Central Time (US & Canada)' 31 | 32 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 33 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 34 | # config.i18n.default_locale = :de 35 | 36 | # Configure the default encoding used in templates for Ruby 1.9. 37 | config.encoding = "utf-8" 38 | 39 | # Configure sensitive parameters which will be filtered from the log file. 40 | config.filter_parameters += [:password] 41 | 42 | # Use SQL instead of Active Record's schema dumper when creating the database. 43 | # This is necessary if your schema can't be completely dumped by the schema dumper, 44 | # like if you have constraints or database-specific column types 45 | # config.active_record.schema_format = :sql 46 | 47 | # Enforce whitelist mode for mass assignment. 48 | # This will create an empty whitelist of attributes available for mass-assignment for all models 49 | # in your app. As such, your models will need to explicitly whitelist or blacklist accessible 50 | # parameters by using an attr_accessible or attr_protected declaration. 51 | config.active_record.whitelist_attributes = true 52 | 53 | # Enable the asset pipeline 54 | config.assets.enabled = true 55 | 56 | # Version of your assets, change this if you want to expire all your assets 57 | config.assets.version = '1.0' 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GIT 2 | remote: git@github.com:transist/pay_fu.git 3 | revision: f678b0d0e3e54576a51309c1ee11532b026f3b7d 4 | specs: 5 | pay_fu (0.0.1) 6 | activemerchant 7 | activemerchant_patch_for_china 8 | rails 9 | 10 | GEM 11 | remote: http://rubygems.org/ 12 | specs: 13 | actionmailer (3.2.2) 14 | actionpack (= 3.2.2) 15 | mail (~> 2.4.0) 16 | actionpack (3.2.2) 17 | activemodel (= 3.2.2) 18 | activesupport (= 3.2.2) 19 | builder (~> 3.0.0) 20 | erubis (~> 2.7.0) 21 | journey (~> 1.0.1) 22 | rack (~> 1.4.0) 23 | rack-cache (~> 1.1) 24 | rack-test (~> 0.6.1) 25 | sprockets (~> 2.1.2) 26 | active_utils (1.0.3) 27 | activesupport (>= 2.3.11) 28 | i18n 29 | activemerchant (1.21.0) 30 | active_utils (>= 1.0.2) 31 | activesupport (>= 2.3.11) 32 | builder (>= 2.0.0) 33 | i18n 34 | json (>= 1.5.1) 35 | money (<= 3.7.1) 36 | activemerchant_patch_for_china (0.1.6) 37 | activemerchant (>= 1.4.2) 38 | activemodel (3.2.2) 39 | activesupport (= 3.2.2) 40 | builder (~> 3.0.0) 41 | activerecord (3.2.2) 42 | activemodel (= 3.2.2) 43 | activesupport (= 3.2.2) 44 | arel (~> 3.0.2) 45 | tzinfo (~> 0.3.29) 46 | activeresource (3.2.2) 47 | activemodel (= 3.2.2) 48 | activesupport (= 3.2.2) 49 | activesupport (3.2.2) 50 | i18n (~> 0.6) 51 | multi_json (~> 1.0) 52 | arel (3.0.2) 53 | builder (3.0.0) 54 | coffee-rails (3.2.2) 55 | coffee-script (>= 2.2.0) 56 | railties (~> 3.2.0) 57 | coffee-script (2.2.0) 58 | coffee-script-source 59 | execjs 60 | coffee-script-source (1.3.1) 61 | erubis (2.7.0) 62 | execjs (1.3.2) 63 | multi_json (~> 1.0) 64 | guid (0.1.1) 65 | haml (3.1.5) 66 | hike (1.2.1) 67 | i18n (0.6.0) 68 | journey (1.0.3) 69 | jquery-rails (2.0.2) 70 | railties (>= 3.2.0, < 5.0) 71 | thor (~> 0.14) 72 | json (1.7.1) 73 | libv8 (3.3.10.4) 74 | mail (2.4.4) 75 | i18n (>= 0.4.0) 76 | mime-types (~> 1.16) 77 | treetop (~> 1.4.8) 78 | mime-types (1.18) 79 | money (3.7.1) 80 | i18n (~> 0.4) 81 | multi_json (1.3.4) 82 | mysql2 (0.3.11) 83 | polyglot (0.3.3) 84 | rack (1.4.1) 85 | rack-cache (1.2) 86 | rack (>= 0.4) 87 | rack-ssl (1.3.2) 88 | rack 89 | rack-test (0.6.1) 90 | rack (>= 1.0) 91 | rails (3.2.2) 92 | actionmailer (= 3.2.2) 93 | actionpack (= 3.2.2) 94 | activerecord (= 3.2.2) 95 | activeresource (= 3.2.2) 96 | activesupport (= 3.2.2) 97 | bundler (~> 1.0) 98 | railties (= 3.2.2) 99 | railties (3.2.2) 100 | actionpack (= 3.2.2) 101 | activesupport (= 3.2.2) 102 | rack-ssl (~> 1.3.2) 103 | rake (>= 0.8.7) 104 | rdoc (~> 3.4) 105 | thor (~> 0.14.6) 106 | rake (0.9.2.2) 107 | rdoc (3.12) 108 | json (~> 1.4) 109 | sass (3.1.17) 110 | sass-rails (3.2.5) 111 | railties (~> 3.2.0) 112 | sass (>= 3.1.10) 113 | tilt (~> 1.3) 114 | sprockets (2.1.3) 115 | hike (~> 1.2) 116 | rack (~> 1.0) 117 | tilt (~> 1.1, != 1.3.0) 118 | therubyracer (0.10.1) 119 | libv8 (~> 3.3.10) 120 | thor (0.14.6) 121 | tilt (1.3.3) 122 | treetop (1.4.10) 123 | polyglot 124 | polyglot (>= 0.3.1) 125 | tzinfo (0.3.33) 126 | uglifier (1.2.4) 127 | execjs (>= 0.3.0) 128 | multi_json (>= 1.0.2) 129 | 130 | PLATFORMS 131 | ruby 132 | 133 | DEPENDENCIES 134 | activemerchant 135 | activemerchant_patch_for_china 136 | coffee-rails 137 | guid 138 | haml 139 | jquery-rails 140 | mysql2 141 | pay_fu! 142 | rails (= 3.2.2) 143 | sass-rails 144 | therubyracer 145 | uglifier 146 | --------------------------------------------------------------------------------