Skip to content

Commit

Permalink
allow donate from paypal
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed May 8, 2012
1 parent e339a8d commit d2b8eaf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: git@github.com:transist/payment.git
revision: 74903e087b80dd07f64dec85bea33c1fbe68f5a9
revision: 76a1a19b1077c77d64ec760fd2e3a844e4cf1a0b
specs:
payment (0.0.1)
activemerchant
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/donates_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
class DonatesController < ApplicationController
include Payment::PaypalHelper

def index
@donate = Donate.new
@alipay_donate = Donate.new(:currency => 'rmb')
@paypal_donate = Donate.new(:currency => 'usd')
end

def create
@donate = Donate.new(params[:donate])
if @donate.valid?
@donate.number = Guid.new.to_s.gsub('-', '')
if @donate.currency == "usd"
#redirect_to_paypal_gateway(:item_name => "donatecn", :amount => @donate.amount)
options = {:item_name => "donatecn", :amount => @donate.amount}
redirect_to URI.encode("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ext-enter&redirect_cmd=_xclick&charset=utf-8&business=#{Payment::CONFIGS["paypal"]["email"]}&currenct_code=USD&item_name=#{options[:item_name]}&amount=#{options[:amount]}")
return
end
render :confirm
else
render :index
Expand Down
2 changes: 1 addition & 1 deletion app/models/donate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Donate
include ActiveModel::Conversion
extend ActiveModel::Naming

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

def initialize(attributes = {})
Expand Down
12 changes: 10 additions & 2 deletions app/views/donates/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
%h2 捐助

- form_for @donate do |f|
= f.label :amount, '金额: '
= form_for @alipay_donate do |f|
= f.hidden_field :currency
= f.label :amount, '支付宝 金额: '
¥
= f.text_field :amount
= f.submit '捐助'

= form_for @paypal_donate do |f|
= f.hidden_field :currency
= f.label :amount, 'paypal amount: '
$
= f.text_field :amount
= f.submit 'donate'

%h2 捐助记录
%table.transactions
%th 捐助人
Expand Down

0 comments on commit d2b8eaf

Please sign in to comment.