Skip to content

Commit

Permalink
Merge branch 'release/0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Mar 6, 2011
2 parents 6db56e6 + a963128 commit 36aacaf
Show file tree
Hide file tree
Showing 23 changed files with 115 additions and 70 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ gem 'rails', '3.0.4'
# gem 'rails', :git => 'git://github.com/rails/rails.git' # gem 'rails', :git => 'git://github.com/rails/rails.git'


gem 'mysql2', "~> 0.2.6" gem 'mysql2', "~> 0.2.6"
gem 'haml'
gem 'guid'


gem 'activemerchant', :require => "active_merchant" gem 'activemerchant', :require => "active_merchant"
gem 'activemerchant_patch_for_china', '0.1.6' gem 'activemerchant_patch_for_china', '0.1.6'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ GEM
builder (2.1.2) builder (2.1.2)
erubis (2.6.6) erubis (2.6.6)
abstract (>= 1.0.0) abstract (>= 1.0.0)
guid (0.1.1)
haml (3.0.23)
i18n (0.5.0) i18n (0.5.0)
mail (2.2.15) mail (2.2.15)
activesupport (>= 2.3.6) activesupport (>= 2.3.6)
Expand Down Expand Up @@ -79,5 +81,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
activemerchant activemerchant
activemerchant_patch_for_china (= 0.1.6) activemerchant_patch_for_china (= 0.1.6)
guid
haml
mysql2 (~> 0.2.6) mysql2 (~> 0.2.6)
rails (= 3.0.4) rails (= 3.0.4)
15 changes: 15 additions & 0 deletions app/controllers/donates_controller.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,15 @@
class DonatesController < ApplicationController
def index
@donate = Donate.new
end

def create
@donate = Donate.new(params[:donate])
if @donate.valid?
@donate.number = Guid.new.to_s.gsub('-', '')
render :confirm
else
render :index
end
end
end
5 changes: 0 additions & 5 deletions app/controllers/home_controller.rb

This file was deleted.

32 changes: 28 additions & 4 deletions app/controllers/transactions_controller.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,35 @@
class TransactionsController < ApplicationController class TransactionsController < ApplicationController
def notify def notify
end notification = ActiveMerchant::Billing::Integrations::Alipay::Notification.new(request.raw_post)


def done transaction_attributes = {
end :total_fee => notification.total_fee,
:trade_status => notification.trade_status,
:trade_no => notification.trade_no,
:notify_time => notification.notify_time,
:raw_post => request.raw_post
}


def show if transaction = Transaction.find_by_notify_id(notification_notify_id)
result = transaction.update_attributes(transaction_attributes)
else
transaction_attributes.merge!(:notify_id => notification.notify_id)
result = Transaction.create(transacation_attributes)
end

if result
render :text => "success"
else
render :text => "failure"
end
end end


def done
request = ActiveMerchant::Billing::Integrations::Alipay::Return.new(request.query_string)
if request.success?
flash[:notice] = '捐助成功!'
else
flash[:error] = '捐助失败!'
end
end
end end
2 changes: 2 additions & 0 deletions app/helpers/donates_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
module DonatesHelper
end
2 changes: 0 additions & 2 deletions app/helpers/home_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/transactions_helper.rb

This file was deleted.

18 changes: 18 additions & 0 deletions app/models/donate.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,18 @@
class Donate
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming

attr_accessor :amount, :number
validates_numericality_of :amount, :greater_than => 0

def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end

def persisted?
false
end
end
17 changes: 17 additions & 0 deletions app/views/donates/confirm.html.haml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,17 @@
%h1 捐款确认

%p 捐款金额: ¥#{@donate.amount}

- payment_service_for @donate.number, AlipayConfig[:account], :service => :alipay, :html => { :id => 'payment-form', :method => :get } do |service|
- service.total_fee @donate.amount
- service.seller :email => AlipayConfig[:email]
- service.notify_url url_for(:only_path => false, :controller => 'transactions', :action => 'notify')
- service.return_url url_for(:only_path => false, :controller => 'transactions', :action => 'done')
- service.charset "utf-8"
- service.service ActiveMerchant::Billing::Integrations::Alipay::Helper::CREATE_DIRECT_PAY_BY_USER
- service.payment_type 1
- service.subject '捐助activemerchat_ptch_for_china项目'
- service.sign

= button_to_function "确认", "document.getElementById('payment-form').firstChild.remove();document.getElementById('payment-form').submit()"

6 changes: 6 additions & 0 deletions app/views/donates/index.html.haml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,6 @@
%h1 捐款

- form_for @donate do |f|
= f.label :amount, '金额: '
= f.text_field :amount
= f.submit '捐款'
16 changes: 0 additions & 16 deletions app/views/home/index.html.erb

This file was deleted.

14 changes: 0 additions & 14 deletions app/views/layouts/application.html.erb

This file was deleted.

9 changes: 9 additions & 0 deletions app/views/layouts/application.html.haml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
!!!
%html
%head
%title Donatecn
= stylesheet_link_tag :all
= javascript_include_tag :defaults
= csrf_meta_tag
%body
= yield
2 changes: 0 additions & 2 deletions app/views/transactions/done.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/transactions/notify.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/transactions/show.html.erb

This file was deleted.

6 changes: 2 additions & 4 deletions config/routes.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,9 @@
Donatecn::Application.routes.draw do Donatecn::Application.routes.draw do
get "transactions/notify" get "transactions/notify"

get "transactions/done" get "transactions/done"


get "transactions/show" resources :donates

root :to => "donates#index"
root :to => "home#index"


# The priority is based upon order of creation: # The priority is based upon order of creation:
# first created -> highest priority. # first created -> highest priority.
Expand Down
8 changes: 8 additions & 0 deletions test/functional/donates_controller_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class DonatesControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
9 changes: 0 additions & 9 deletions test/functional/home_controller_test.rb

This file was deleted.

4 changes: 4 additions & 0 deletions test/unit/helpers/donates_helper_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class DonatesHelperTest < ActionView::TestCase
end
4 changes: 0 additions & 4 deletions test/unit/helpers/home_helper_test.rb

This file was deleted.

4 changes: 0 additions & 4 deletions test/unit/helpers/transactions_helper_test.rb

This file was deleted.

0 comments on commit 36aacaf

Please sign in to comment.