Skip to content

Commit

Permalink
Added remaining files
Browse files Browse the repository at this point in the history
  • Loading branch information
five18pm committed Jan 17, 2012
1 parent 01babe1 commit 4b19617
Show file tree
Hide file tree
Showing 35 changed files with 983 additions and 0 deletions.
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--colour
13 changes: 13 additions & 0 deletions Gemfile
@@ -0,0 +1,13 @@
source 'http://rubygems.org'

group :test do
gem 'ffaker'
end

if RUBY_VERSION < "1.9"
gem "ruby-debug"
else
gem "ruby-debug19"
end

gemspec
208 changes: 208 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,208 @@
PATH
remote: .
specs:
spree_ccavenue (1.1.0)
spree_core (>= 1.0.0.rc1)

GEM
remote: http://rubygems.org/
specs:
actionmailer (3.1.3)
actionpack (= 3.1.3)
mail (~> 2.3.0)
actionpack (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.5)
rack-cache (~> 1.1)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.3)
active_utils (1.0.1)
activesupport (>= 2.3.11)
i18n
activemerchant (1.20.1)
active_utils (>= 1.0.1)
activesupport (>= 2.3.11)
braintree (>= 2.0.0)
builder (>= 2.0.0)
i18n
json (>= 1.5.1)
money (<= 3.7.1)
activemodel (3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
arel (~> 2.2.1)
tzinfo (~> 0.3.29)
activeresource (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
activesupport (3.1.3)
multi_json (~> 1.0)
acts_as_list (0.1.4)
arel (2.2.1)
braintree (2.13.2)
builder (>= 2.0.0)
builder (3.0.0)
capybara (1.0.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
childprocess (0.2.8)
ffi (~> 1.0.6)
cocaine (0.2.1)
columnize (0.3.6)
database_cleaner (0.7.0)
deface (0.7.2)
nokogiri (~> 1.5.0)
rails (>= 3.0.9)
diff-lcs (1.1.3)
erubis (2.7.0)
factory_girl (2.3.2)
activesupport
ffaker (1.12.1)
ffi (1.0.11)
highline (1.6.8)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.4)
kaminari (0.13.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
linecache (0.46)
rbx-require-relative (> 0.0.4)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
meta_search (1.1.1)
actionpack (~> 3.1.0)
activerecord (~> 3.1.0)
activesupport (~> 3.1.0)
polyamorous (~> 0.5.0)
mime-types (1.17.2)
money (3.7.1)
i18n (~> 0.4)
multi_json (1.0.4)
nested_set (1.6.8)
activerecord (>= 3.0.0)
railties (>= 3.0.0)
nokogiri (1.5.0)
paperclip (2.4.1)
activerecord (>= 2.3.0)
activesupport (>= 2.3.2)
cocaine (>= 0.0.2)
mime-types
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.1.3)
actionmailer (= 3.1.3)
actionpack (= 3.1.3)
activerecord (= 3.1.3)
activeresource (= 3.1.3)
activesupport (= 3.1.3)
bundler (~> 1.0)
railties (= 3.1.3)
railties (3.1.3)
actionpack (= 3.1.3)
activesupport (= 3.1.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rbx-require-relative (0.0.5)
rdoc (3.12)
json (~> 1.4)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
rspec-rails (2.8.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.8.0)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
rubyzip (0.9.5)
selenium-webdriver (2.16.0)
childprocess (>= 0.2.5)
ffi (~> 1.0.9)
multi_json (~> 1.0.4)
rubyzip
shoulda-matchers (1.0.0)
spree_core (1.0.0.rc1)
activemerchant (= 1.20.1)
acts_as_list (= 0.1.4)
deface (>= 0.7.2)
ffaker (~> 1.12.0)
highline (= 1.6.8)
jquery-rails (>= 1.0.18, <= 1.0.19)
kaminari (>= 0.13.0)
meta_search (= 1.1.1)
nested_set (= 1.6.8)
paperclip (= 2.4.1)
rails (>= 3.1.1, <= 3.1.3)
state_machine (= 1.1.1)
stringex (~> 1.3.0)
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
state_machine (1.1.1)
stringex (1.3.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.31)
xpath (0.1.4)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
capybara (= 1.0.1)
database_cleaner
factory_girl
ffaker
rspec-rails (~> 2.7)
ruby-debug
shoulda-matchers (~> 1.0.0)
spree_ccavenue!
sqlite3
1 change: 1 addition & 0 deletions app/assets/javascripts/admin/spree_ccavenue.js
@@ -0,0 +1 @@
//= require admin/spree_core
2 changes: 2 additions & 0 deletions app/assets/javascripts/spree/ccavenue/gateway.js
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
1 change: 1 addition & 0 deletions app/assets/javascripts/store/spree_ccavenue.js
@@ -0,0 +1 @@
//= require store/spree_core
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/spree_ccavenue.css
@@ -0,0 +1,3 @@
/*
*= require admin/spree_core
*/
4 changes: 4 additions & 0 deletions app/assets/stylesheets/spree/ccavenue/gateway.css
@@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/store/spree_ccavenue.css
@@ -0,0 +1,3 @@
/*
*= require store/spree_core
*/
81 changes: 81 additions & 0 deletions app/controllers/spree/ccavenue/gateway_controller.rb
@@ -0,0 +1,81 @@
class Spree::Ccavenue::GatewayController < Spree::BaseController
helper "spree/checkout"
def show
@order = Spree::Order.find_by_number(params[:order_id])
if !@order
flash[:error] = "Unknown order"
render :error
return
end

@payment_method = Spree::PaymentMethod.find(params[:payment_method_id])
if !@payment_method or !@payment_method.kind_of?(Spree::Ccavenue::PaymentMethod)
flash[:error] = "Invalid payment method for this transaction"
render :error
return
end

if @order.has_authorized_ccavenue_transaction?
flash[:error] = "Order #{@order.number} is already authorized at CCAvenue"
render :error
return
end

@order.cancel_existing_ccavenue_transactions!
@order.payments.destroy_all
@order.payments.build(:amount => @order.total, :payment_method_id => @payment_method.id)
@transaction = @order.ccavenue_transactions.build(:amount => @order.total,
:payment_method_id => @payment_method.id)

@transaction.transact
@order.save!
logger.info("Sending order #{@order.number} to CCAvenue via transaction id #{@transaction.id}")
@bill_address, @ship_address = @order.bill_address, (@order.ship_address || @order.bill_address)
end

def callback
@transaction = Spree::Ccavenue::Transaction.find(params[:id])
if !@transaction
# raise error
end

logger.info "Received transaction from CCAvenue #{params.inspect}"

@transaction.auth_desc = params['AuthDesc']
@transaction.checksum = params['Checksum']
@transaction.card_category = params['card_category']
@transaction.ccavenue_order_number = params['nb_order_no']
@transaction.ccavenue_amount = params['Amount']

session[:access_token] = @transaction.order.token if @transaction.order.respond_to?(:token)
session[:order_id] = @transaction.order.id

if @transaction.next
if @transaction.authorized? or (@transaction.batch? and @transaction.order.complete?)
session[:order_id] = nil
flash.notice = I18n.t(:order_processed_successfully)
flash[:commerce_tracking] = "nothing special"
# We are setting token here so that even if the URL is copied and reused later on
# the completed order page still gets displayed
if session[:access_token].nil?
redirect_to spree.order_path(@transaction.order, { :checkout_complete => true })
else
redirect_to spree.order_path(@transaction.order, { :checkout_complete => true, :token => session[:access_token] })
end
elsif @transaction.rejected?
redirect_to spree.edit_order_path(@transaction.order), :error => I18n.t("payment_rejected")
elsif @transaction.canceled?
redirect_to spree.edit_order_path(@transaction.order), :notice => I18n.t("payment_canceled")
elsif @transaction.batch?
# Don't allow the order to be reused.
session[:order_id] = nil
render 'batch'
elsif @transaction.error_state?
flash[:error] = I18n.t(:ccavenue_invalid_transaction)
redirect_to spree.edit_order_path(@transaction.order)
end
else
render 'error'
end
end
end
20 changes: 20 additions & 0 deletions app/controllers/spree/checkout_controller_decorator.rb
@@ -0,0 +1,20 @@
Spree::CheckoutController.class_eval do
before_filter :ccavenue_redirect, :only => :update

private
def ccavenue_redirect
return unless params[:state] == 'payment'
@payment_method = Spree::PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
if @payment_method && @payment_method.kind_of?(Spree::Ccavenue::PaymentMethod)
if @order.update_attributes(object_params)
fire_event('spree.checkout.update')
if @order.next
redirect_to gateway_ccavenue_path(@order.number, @payment_method.id)
else
logger.error("Order transition failed for order #{@order.number}")
raise Exception.new(:message => "Order transition failed")
end
end
end
end
end
5 changes: 5 additions & 0 deletions app/helpers/spree/ccavenue/gateway_helper.rb
@@ -0,0 +1,5 @@
module Spree::Ccavenue::GatewayHelper
def transaction_checksum(*args)
Zlib.adler32(args.join('|')).to_s
end
end
5 changes: 5 additions & 0 deletions app/models/spree/ccavenue.rb
@@ -0,0 +1,5 @@
module Spree::Ccavenue
def self.table_name_prefix
'spree_ccavenue_'
end
end
23 changes: 23 additions & 0 deletions app/models/spree/ccavenue/payment_method.rb
@@ -0,0 +1,23 @@
class Spree::Ccavenue::PaymentMethod < Spree::PaymentMethod
preference :account_id, :string
preference :url, :string, :default => "https://www.ccavenue.com/shopzone/cc_details.jsp"
preference :working_key, :string
preference :mode, :string
preference :batch_transaction_should_complete_order, :boolean, :default => true

def payment_profiles_supported?
true # we want to show the confirm step.
end

def provider_class
Spree::Ccavenue::Transaction
end

def payment_source_class
Spree::Ccavenue::Transaction
end

def method_type
'ccavenue'
end
end

0 comments on commit 4b19617

Please sign in to comment.