Skip to content
Browse files

Also works as a plugin

  • Loading branch information...
1 parent 2a75e0f commit 691588442732c3daa754ad503b83945b30c00537 @tempmeshbrain tempmeshbrain committed Sep 24, 2010
View
3 .gitignore
@@ -13,6 +13,9 @@ tmtags
## VIM
*.swp
+## Netbeans
+nbproject
+
## PROJECT::GENERAL
coverage
rdoc
View
46 Rakefile
@@ -2,32 +2,32 @@ require 'rubygems'
require 'rake'
begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "active_merchant_ccavenue"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
- gem.email = "contact@meshbrain.com"
- gem.homepage = "http://github.com/meshbrain/active_merchant_ccavenue"
- gem.authors = ["Suman Debnath"]
- gem.add_development_dependency "rspec", ">= 1.2.9"
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
- end
- Jeweler::GemcutterTasks.new
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = 'active_merchant_ccavenue'
+ gem.summary = %Q{ActiveMerchantCCAvenue}
+ gem.description = %Q{CCAvenue integration for ActiveMerchant}
+ gem.email = 'contact@meshbrain.com'
+ gem.homepage = 'http://github.com/meshbrain/active_merchant_ccavenue'
+ gem.authors = ['Suman Debnath']
+ gem.add_development_dependency 'rspec', '>= 1.2.9'
+ gem.add_dependency 'activemerchant', '>= 1.7.3'
+ end
+ Jeweler::GemcutterTasks.new
rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
end
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.spec_files = FileList['spec/**/*_spec.rb']
+ spec.libs << 'lib' << 'spec'
+ spec.spec_files = FileList['spec/**/*_spec.rb']
end
Spec::Rake::SpecTask.new(:rcov) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.pattern = 'spec/**/*_spec.rb'
- spec.rcov = true
+ spec.libs << 'lib' << 'spec'
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
end
task :spec => :check_dependencies
@@ -36,10 +36,10 @@ task :default => :spec
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = "active_merchant_ccavenue #{version}"
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "active_merchant_ccavenue #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
end
View
57 active_merchant_ccavenue.gemspec
@@ -0,0 +1,57 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{active_merchant_ccavenue}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Suman Debnath"]
+ s.date = %q{2010-09-24}
+ s.description = %q{CCAvenue integration for ActiveMerchant}
+ s.email = %q{contact@meshbrain.com}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.rdoc"
+ ]
+ s.files = [
+ ".document",
+ ".gitignore",
+ "LICENSE",
+ "README.rdoc",
+ "Rakefile",
+ "VERSION",
+ "lib/active_merchant_ccavenue.rb",
+ "spec/active_merchant_ccavenue_spec.rb",
+ "spec/spec.opts",
+ "spec/spec_helper.rb"
+ ]
+ s.homepage = %q{http://github.com/meshbrain/active_merchant_ccavenue}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{ActiveMerchantCCAvenue}
+ s.test_files = [
+ "spec/active_merchant_ccavenue_spec.rb",
+ "spec/spec_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
+ s.add_runtime_dependency(%q<activemerchant>, [">= 1.7.3"])
+ else
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
+ s.add_dependency(%q<activemerchant>, [">= 1.7.3"])
+ end
+ else
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
+ s.add_dependency(%q<activemerchant>, [">= 1.7.3"])
+ end
+end
+
View
1 init.rb
@@ -0,0 +1 @@
+require 'active_merchant_ccavenue'
View
28 lib/active_merchant_ccavenue.rb
@@ -0,0 +1,28 @@
+#require File.dirname(__FILE__) + '/active_merchant_ccavenue/helper.rb'
+#require File.dirname(__FILE__) + '/active_merchant_ccavenue/notification.rb'
+
+module ActiveMerchant #:nodoc:
+ module Billing #:nodoc:
+ module Integrations #:nodoc:
+ module Ccavenue
+ #autoload :Return, File.dirname(__FILE__) + '/active_merchant_ccavenue/return.rb'
+ autoload :Helper, File.dirname(__FILE__) + '/active_merchant_ccavenue/helper.rb'
+ autoload :Notification, File.dirname(__FILE__) + '/active_merchant_ccavenue/notification.rb'
+
+ mattr_accessor :merchant_id
+ mattr_accessor :work_key
+ mattr_accessor :service_url
+
+ self.service_url = 'https://www.ccavenue.com/shopzone/cc_details.jsp'
+
+ def self.setup
+ yield(self)
+ end
+
+ def self.notification(post)
+ Notification.new(post)
+ end
+ end
+ end
+ end
+end
View
34 lib/active_merchant_ccavenue/helper.rb
@@ -0,0 +1,34 @@
+module ActiveMerchant #:nodoc:
+ module Billing #:nodoc:
+ module Integrations #:nodoc:
+ module Ccavenue
+ class Helper < ActiveMerchant::Billing::Integrations::Helper
+ mapping :amount, 'Amount'
+ mapping :order, 'Order_Id'
+ mapping :customer, :name => 'billing_cust_name',
+ :email => 'billing_cust_email',
+ :phone => 'billing_cust_tel'
+
+ def redirect(mapping = {})
+ add_field 'Redirect_Url', mapping[:return_url]
+ add_field 'Merchant_Id', ActiveMerchant::Billing::Integrations::Ccavenue.merchant_id
+ add_field 'Checksum', get_checksum(
+ ActiveMerchant::Billing::Integrations::Ccavenue.merchant_id,
+ self.fields[self.mappings[:order]],
+ self.fields[self.mappings[:amount]],
+ mapping[:return_url],
+ ActiveMerchant::Billing::Integrations::Ccavenue.work_key
+ )
+ end
+
+ private
+
+ def get_checksum(*args)
+ require 'zlib'
+ Zlib.adler32 args.join('|'), 1
+ end
+ end
+ end
+ end
+ end
+end
View
52 lib/active_merchant_ccavenue/notification.rb
@@ -0,0 +1,52 @@
+module ActiveMerchant #:nodoc:
+ module Billing #:nodoc:
+ module Integrations #:nodoc:
+ module Ccavenue
+ class Notification < ActiveMerchant::Billing::Integrations::Notification
+ def valid?
+ verify_checksum(
+ self.security_key,
+ ActiveMerchant::Billing::Integrations::Ccavenue.merchant_id,
+ self.payment_id,
+ self.gross,
+ self.status,
+ ActiveMerchant::Billing::Integrations::Ccavenue.work_key
+ )
+ end
+
+ def complete?
+ 'Y' == self.status
+ end
+
+ def payment_id
+ params['Order_Id']
+ end
+
+ def transaction_id
+ params['nb_order_no']
+ end
+
+ def security_key
+ params['Checksum']
+ end
+
+ # the money amount we received in X.2 decimal.
+ def gross
+ params['Amount']
+ end
+
+ def status
+ params['AuthDesc']
+ end
+
+ private
+
+ def verify_checksum(checksum, *args)
+ require 'zlib'
+ Zlib.adler32(args.join('|'), 1).to_s.eql?(checksum)
+ end
+ end
+ end
+ end
+ end
+end

0 comments on commit 6915884

Please sign in to comment.
Something went wrong with that request. Please try again.