Skip to content

Commit

Permalink
fix for spree 2-2stable
Browse files Browse the repository at this point in the history
  • Loading branch information
qinghe committed May 29, 2014
1 parent 903cf6f commit 55f53d0
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 56 deletions.
7 changes: 5 additions & 2 deletions Gemfile
Expand Up @@ -5,10 +5,13 @@ source 'http://ruby.taobao.org/'

gem 'ruby-hmac' #http://ryanbigg.com/2009/07/no-such-file-to-load-hmac-sha1/

gem 'activemerchant', :require => 'active_merchant'
gem 'activemerchant_patch_for_china' #support alipay
group :test,:development do
#https://github.com/spree/spree/issues/4442
gem 'sprockets', '2.11.0'
# Provides basic authentication functionality for testing parts of your engine
gem 'spree','~> 2.2.0'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable'
end
gem 'activemerchant', :require => 'active_merchant'
gem 'activemerchant_patch_for_china' #support alipay
gemspec
55 changes: 51 additions & 4 deletions Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/spree/spree_auth_devise.git
revision: 6469c80cbb8f7bd09fe302c2d0e7fdcb187e38de
revision: 4959656be98742249f85879207a606e05d622cc6
branch: 2-2-stable
specs:
spree_auth_devise (2.2.0)
Expand All @@ -15,6 +15,7 @@ PATH
remote: .
specs:
spree_alipay (2.2.0)
spree_core (~> 2.2.0)

GEM
remote: http://ruby.taobao.org/
Expand Down Expand Up @@ -68,6 +69,8 @@ GEM
bcrypt (3.1.7)
builder (3.1.4)
cancan (1.6.10)
canonical-rails (0.0.7)
rails (>= 3.1, < 5.0)
capybara (2.2.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand Down Expand Up @@ -117,6 +120,11 @@ GEM
json (~> 1.8)
multi_xml (>= 0.5.2)
i18n (0.6.9)
jquery-rails (3.1.0)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (4.1.2)
railties (>= 3.1.0)
json (1.8.1)
kaminari (0.15.1)
actionpack (>= 3.0.0)
Expand All @@ -131,7 +139,7 @@ GEM
money (6.0.1)
i18n (~> 0.6.4)
monetize (~> 0.1.3)
multi_json (1.9.2)
multi_json (1.10.1)
multi_xml (0.5.5)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
Expand All @@ -147,6 +155,8 @@ GEM
polyamorous (0.6.4)
activerecord (>= 3.0)
polyglot (0.3.4)
rabl (0.9.3)
activesupport (>= 2.3.14)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
Expand Down Expand Up @@ -187,6 +197,9 @@ GEM
railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10)
sprockets-rails (~> 2.0.0)
select2-rails (3.4.9)
sass-rails
thor (~> 0.14)
selenium-webdriver (2.41.0)
childprocess (>= 0.5.0)
multi_json (~> 1.0)
Expand All @@ -197,6 +210,25 @@ GEM
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
spree (2.2.1)
spree_api (= 2.2.1)
spree_backend (= 2.2.1)
spree_cmd (= 2.2.1)
spree_core (= 2.2.1)
spree_frontend (= 2.2.1)
spree_sample (= 2.2.1)
spree_api (2.2.1)
rabl (= 0.9.3)
spree_core (= 2.2.1)
versioncake (~> 1.2.0)
spree_backend (2.2.1)
jquery-rails (~> 3.1.0)
jquery-ui-rails (~> 4.1.0)
select2-rails (~> 3.4.7)
spree_api (= 2.2.1)
spree_core (= 2.2.1)
spree_cmd (2.2.1)
thor (~> 0.14)
spree_core (2.2.1)
activemerchant (~> 1.42.3)
acts_as_list (= 0.3.0)
Expand All @@ -217,7 +249,15 @@ GEM
state_machine (= 1.2.0)
stringex (~> 1.5.1)
truncate_html (= 0.9.2)
sprockets (2.12.0)
spree_frontend (2.2.1)
canonical-rails (~> 0.0.4)
jquery-rails (~> 3.1.0)
spree_api (= 2.2.1)
spree_core (= 2.2.1)
stringex (~> 1.5.1)
spree_sample (2.2.1)
spree_core (= 2.2.1)
sprockets (2.11.0)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
Expand All @@ -239,6 +279,11 @@ GEM
truncate_html (0.9.2)
tzinfo (0.3.39)
uuidtools (2.1.4)
versioncake (1.2.0)
actionpack (>= 3.2)
activesupport (>= 3.2)
railties (>= 3.2)
tzinfo
warden (1.2.3)
rack (>= 1.0)
websocket (1.0.7)
Expand All @@ -254,13 +299,15 @@ DEPENDENCIES
capybara (~> 2.1)
coffee-rails
database_cleaner
factory_girl (~> 4.2)
factory_girl (~> 4.4)
ffaker
rspec-rails (~> 2.13)
ruby-hmac
sass-rails
selenium-webdriver
simplecov
spree (~> 2.2.0)
spree_alipay!
spree_auth_devise!
sprockets (= 2.11.0)
sqlite3
10 changes: 8 additions & 2 deletions Rakefile
Expand Up @@ -6,10 +6,16 @@ require 'spree/testing_support/extension_rake'

RSpec::Core::RakeTask.new

task :default => [:spec]
task :default do
if Dir["spec/dummy"].empty?
Rake::Task[:test_app].invoke
Dir.chdir("../../")
end
Rake::Task[:spec].invoke
end

desc 'Generates a dummy app for testing'
task :test_app do
ENV['LIB_NAME'] = 'spree_alipay'
Rake::Task['extension:test_app'].invoke
end
end
1 change: 0 additions & 1 deletion app/assets/javascripts/spree/admin/spree_alipay.js

This file was deleted.

1 change: 1 addition & 0 deletions app/assets/javascripts/spree/backend/spree_alipay.js
@@ -0,0 +1 @@

Empty file.
1 change: 0 additions & 1 deletion app/assets/javascripts/spree/store/spree_alipay.js

This file was deleted.

3 changes: 0 additions & 3 deletions app/assets/stylesheets/spree/admin/spree_alipay.css

This file was deleted.

3 changes: 3 additions & 0 deletions app/assets/stylesheets/spree/backend/spree_alipay.css
@@ -0,0 +1,3 @@
/*
*
*/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/spree/frontend/spree_alipay.css
@@ -0,0 +1,3 @@
/*
*
*/
3 changes: 0 additions & 3 deletions app/assets/stylesheets/spree/store/spree_alipay.css

This file was deleted.

26 changes: 13 additions & 13 deletions app/controllers/spree/checkout_controller_decorator.rb
Expand Up @@ -45,15 +45,15 @@ def alipay_notify
#https://github.com/flyerhzm/donatecn
#demo for activemerchant_patch_for_china
#since alipay_full_service_url is working, it is only for debug for now.
def alipay_checkout_payment
payment_method = PaymentMethod.find(params[:payment_method_id])
#Rails.logger.debug "@payment_method=#{@payment_method.inspect}"
Rails.logger.debug "alipay_full_service_url:"+aplipay_full_service_url(@order, payment_method)
# notice that load_order would call before_payment, if 'http==put' and 'order.state == payment', the payments will be deleted.
# so we have to create payment again
@order.payments.create(:amount => @order.total, :payment_method_id => payment_method.id)
#redirect_to_alipay_gateway(:subject => "donatecn", :body => "donatecn", :amount => @donate.amount, :out_trade_no => "123", :notify_url => pay_fu.alipay_transactions_notify_url)
end
#def alipay_checkout_payment
# payment_method = PaymentMethod.find(params[:payment_method_id])
# #Rails.logger.debug "@payment_method=#{@payment_method.inspect}"
# Rails.logger.debug "alipay_full_service_url:"+aplipay_full_service_url(@order, payment_method)
# # notice that load_order would call before_payment, if 'http==put' and 'order.state == payment', the payments will be deleted.
# # so we have to create payment again
# @order.payments.create(:amount => @order.total, :payment_method_id => payment_method.id)
# #redirect_to_alipay_gateway(:subject => "donatecn", :body => "donatecn", :amount => @donate.amount, :out_trade_no => "123", :notify_url => pay_fu.alipay_transactions_notify_url)
#end

private

Expand All @@ -79,10 +79,10 @@ def checkout_hook
return unless @order.next_step_complete?
return unless params[:order][:payments_attributes].present?
Rails.logger.debug "--->before update_attributes"
if @order.update_attributes(object_params) #it would create payments
if params[:order][:coupon_code] and !params[:order][:coupon_code].blank? and @order.coupon_code.present?
fire_event('spree.checkout.coupon_code_added', :coupon_code => @order.coupon_code)
end
if @order.update_from_params(params, permitted_checkout_attributes) #it would create payments
#if params[:order][:coupon_code] and !params[:order][:coupon_code].blank? and @order.coupon_code.present?
# fire_event('spree.checkout.coupon_code_added', :coupon_code => @order.coupon_code)
#end
end
if pay_by_billing_integration?
Rails.logger.debug "--->before handle_billing_integration"
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/billing_integration/alipay.rb
Expand Up @@ -4,7 +4,7 @@ class BillingIntegration::Alipay < BillingIntegration
preference :sign, :string
preference :email, :string
preference :using_direct_pay_service, :boolean, :default => false #CREATE_DIRECT_PAY_BY_USER
attr_accessible :preferred_server, :preferred_test_mode, :preferred_email, :preferred_partner, :preferred_sign, :preferred_using_direct_pay_service
#attr_accessible :preferred_server, :preferred_test_mode, :preferred_email, :preferred_partner, :preferred_sign, :preferred_using_direct_pay_service


def provider_class
Expand Down
28 changes: 14 additions & 14 deletions config/routes.rb
@@ -1,22 +1,22 @@
Spree::Core::Engine.routes.prepend do
resources :orders do
resource :checkout, :controller => 'checkout' do
member do
get :alipay_checkout_payment
get :alipay_done
post :alipay_notify
end
end
end
Spree::Core::Engine.add_routes do
#resources :orders do
# resource :checkout, :controller => 'checkout' do
# member do
# get :alipay_checkout_payment
# get :alipay_done
# post :alipay_notify
# end
# end
#end

# Add your extension routes here
match '/alipay_checkout/done/' => 'checkout#alipay_done', :as => :alipay_done
match '/alipay_checkout/notify/' => 'checkout#alipay_notify', :as => :alipay_notify
get '/alipay_checkout/done/', :to => 'checkout#alipay_done', :as => :alipay_done
get '/alipay_checkout/notify/', :to => 'checkout#alipay_notify', :as => :alipay_notify

#fix issue
#https://github.com/spree/spree_auth_devise/commit/bab2593f75909feeed3f53b54a63c2edd25f7ba5
get '/checkout/registration' => 'checkout#registration', :as => :checkout_registration
put '/checkout/registration' => 'checkout#update_registration', :as => :update_checkout_registration
#get '/checkout/registration', :to => 'checkout#registration', :as => :checkout_registration
#put '/checkout/registration', :to => 'checkout#update_registration', :as => :update_checkout_registration

end

22 changes: 12 additions & 10 deletions lib/generators/spree_alipay/install/install_generator.rb
Expand Up @@ -2,27 +2,29 @@ module SpreeAlipay
module Generators
class InstallGenerator < Rails::Generators::Base

class_option :auto_run_migrations, :type => :boolean, :default => false

def add_javascripts
append_file "app/assets/javascripts/store/all.js", "//= require store/spree_alipay\n"
append_file "app/assets/javascripts/admin/all.js", "//= require admin/spree_alipay\n"
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_alipay\n"
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_alipay\n"
end

def add_stylesheets
inject_into_file "app/assets/stylesheets/store/all.css", " *= require store/spree_alipay\n", :before => /\*\//, :verbose => true
inject_into_file "app/assets/stylesheets/admin/all.css", " *= require admin/spree_alipay\n", :before => /\*\//, :verbose => true
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/spree_alipay\n", :before => /\*\//, :verbose => true
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/spree_alipay\n", :before => /\*\//, :verbose => true
end

def add_migrations
run 'bundle exec rake railties:install:migrations FROM=spree_alipay'
end

def run_migrations
res = ask "Would you like to run the migrations now? [Y/n]"
if res == "" || res.downcase == "y"
run 'bundle exec rake db:migrate'
else
puts "Skiping rake db:migrate, don't forget to run it!"
end
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
if run_migrations
run 'bundle exec rake db:migrate'
else
puts 'Skipping rake db:migrate, don\'t forget to run it!'
end
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions spree_alipay.gemspec
Expand Up @@ -16,12 +16,14 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency 'spree_core', '~> 2.2.0'

s.add_development_dependency 'capybara', '~> 2.1'
s.add_development_dependency 'coffee-rails'
s.add_development_dependency 'database_cleaner'
s.add_development_dependency 'factory_girl', '~> 4.2'
s.add_development_dependency 'factory_girl', '~> 4.4'
s.add_development_dependency 'ffaker'
s.add_development_dependency 'rspec-rails', '~> 2.13'
s.add_development_dependency 'rspec-rails', '~> 2.13'
s.add_development_dependency 'sass-rails'
s.add_development_dependency 'selenium-webdriver'
s.add_development_dependency 'simplecov'
Expand Down

0 comments on commit 55f53d0

Please sign in to comment.