active_merchant_ebs 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in active_merchant_ebs.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Anurag Phadke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ = ActiveMerchantEbs
2
+
3
+ EBS integration for ActiveMerchant.
4
+
5
+ == Installation
6
+
7
+ === Requirements
8
+
9
+ You need to install the ActiveMerchant gem or rails plugin. More info about ActiveMerchant installation can be found at http://www.activemerchant.org.
10
+
11
+ === As a gem
12
+
13
+ Install the gem [recommended]:
14
+
15
+ > gem install active_merchant_ebs
16
+
17
+ To use the ActiveMerchantEbs gem in a Rails 3 application, add the following line in your Gemfile:
18
+
19
+ gem 'active_merchant_ebs'
20
+
21
+ == Configuration
22
+
23
+ Create a merchant account with EBS.
24
+
25
+ Then create an initializer, like initializers/payment.rb. Add the following lines:
26
+ ActiveMerchant::Billing::Integrations::Ebs.setup do |ebs|
27
+ ebs.account_id = #your EBS account ID
28
+ ebs.mode = 'TEST' #EBS Mode 'TEST' or 'LIVE'
29
+ ebs.secret_key = 'your secret key' #Provided by EBS
30
+ end
31
+ EBS_ACCOUNT = 'youraccountname'
32
+
33
+ If ActiveMerchant's actionview helpers don't load automatically, add the line in your initializer:
34
+
35
+ ActionView::Base.send :include, ActiveMerchant::Billing::Integrations::ActionViewHelper
36
+
37
+ == Example Usage
38
+ <% payment_service_for @order.id, EBS_ACCOUNT,
39
+ :amount => @order.price_in_cents,
40
+ :service => :ebs do |service| %>
41
+ <% service.customer :name => @order.fullname,
42
+ :email => "test@order.email" %>
43
+ <% service.billing_address :city => "Bang",
44
+ :address1 => "@order.billing_address.address_line_1",
45
+ :state => "@order.billing_address.state",
46
+ :pin => "123456",
47
+ :country => "IN",
48
+ :phone => "9876543210" %>
49
+ <% service.redirect :return_url => [orders_callback_url(@order),'DR={DR}'].join('?'),
50
+ :order_id => @order.id,
51
+ :order_desc => "@order.id" %>
52
+ <%= submit_tag 'Proceed to payment' %>
53
+ <% end %>
54
+
55
+ In your controller
56
+
57
+ def callback
58
+ @order = Order.find(params[:id])
59
+ logger.debug params[:DR]
60
+ @notification = ActiveMerchant::Billing::Integrations::Ebs::Notification.new(params[:DR].to_s)
61
+ logger.debug "Success -- #{@notification.successful?}"
62
+ if @notification.successful?
63
+ render :action => 'success'
64
+ else
65
+ render :action => 'failure'
66
+ end
67
+ end
68
+
69
+ == Special Thanks
70
+
71
+ This gem is heavily inspired by a similar integration done by Suman Debnath for CCavenue @ https://github.com/meshbrain/active_merchant_ccavenue <br>
72
+ Very special thanks to him.
73
+
74
+ == Copyright
75
+ See LICENSE for details.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "active_merchant_ebs/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "active_merchant_ebs"
7
+ s.version = ActiveMerchantEbs::VERSION
8
+ s.authors = ["Chaithanya Padi"]
9
+ s.email = ["padi@entersoft.in"]
10
+ s.homepage = "https://github.com/chaitu87/active_merchant_ebs.git"
11
+ s.summary = "Active merchant integration for EBS Payment Gateway from India"
12
+ s.description = "Active merchant integration for EBS Payment Gateway from India"
13
+
14
+ s.rubyforge_project = "active_merchant_ebs"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,37 @@
1
+ class RubyRc4
2
+ def initialize(str)
3
+ @q1, @q2 = 0, 0
4
+ @key = []
5
+ str.each_byte {|elem| @key << elem} while @key.size < 256
6
+ @key.slice!(256..@key.size-1) if @key.size >= 256
7
+ @s = (0..255).to_a
8
+ j = 0
9
+ 0.upto(255) do |i|
10
+ j = (j + @s[i] + @key[i] )%256
11
+ @s[i], @s[j] = @s[j], @s[i]
12
+ end
13
+ end
14
+
15
+ def encrypt!(text)
16
+ process text
17
+ end
18
+
19
+ def encrypt(text)
20
+ process text.dup
21
+ end
22
+
23
+ private
24
+
25
+ def process(text)
26
+ 0.upto(text.length-1) {|i| text[i] = text[i] ^ round} if RUBY_VERSION == '1.8.7'
27
+ 0.upto(text.length-1) {|i| text[i] = [text[i].ord ^round].pack('c')} if RUBY_VERSION == '1.9.2'
28
+ text
29
+ end
30
+
31
+ def round
32
+ @q1 = (@q1 + 1)%256
33
+ @q2 = (@q2 + @s[@q1])%256
34
+ @s[@q1], @s[@q2] = @s[@q2], @s[@q1]
35
+ @s[(@s[@q1]+@s[@q2])%256]
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ require "active_merchant_ebs/version"
2
+ require 'base64'
3
+ require "RubyRc4.rb"
4
+
5
+ module ActiveMerchant #:nodoc:
6
+ module Billing #:nodoc:
7
+ module Integrations #:nodoc:
8
+ module Ebs
9
+ #autoload :Return, File.dirname(__FILE__) + '/active_merchant_ccavenue/return.rb'
10
+ autoload :Helper, File.dirname(__FILE__) + '/active_merchant_ebs/helper.rb'
11
+ autoload :Notification, File.dirname(__FILE__) + '/active_merchant_ebs/notification.rb'
12
+
13
+ mattr_accessor :account_id
14
+ mattr_accessor :mode
15
+ mattr_accessor :service_url
16
+ mattr_accessor :secret_key
17
+
18
+ self.service_url = 'https://secure.ebs.in/pg/ma/sale/pay/'
19
+
20
+ def self.setup
21
+ yield(self)
22
+ end
23
+
24
+ def self.notification(post)
25
+ Notification.new(post)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,53 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module Integrations #:nodoc:
4
+ module Ebs
5
+ class Helper < ActiveMerchant::Billing::Integrations::Helper
6
+ mapping :account, 'account_id'
7
+ mapping :amount, 'amount'
8
+ mapping :customer, :name => 'name',
9
+ :email => 'email'
10
+
11
+ mapping :billing_address, :city => 'city',
12
+ :address1 => 'address',
13
+ :state => 'state',
14
+ :pin => 'postal_code',
15
+ :country => 'country',
16
+ :phone => 'phone'
17
+
18
+ mapping :shipping_address, :name => 'ship_name',
19
+ :city => 'ship_city',
20
+ :address1 => 'ship_address',
21
+ :state => 'ship_state',
22
+ :pin => 'ship_postal_code',
23
+ :country => 'ship_country',
24
+ :phone => 'ship_phone'
25
+
26
+ def redirect(mapping = {})
27
+ add_field 'return_url', mapping[:return_url]
28
+ add_field 'reference_no', mapping[:order_id]
29
+ add_field 'description', mapping[:order_desc]
30
+ add_field 'account_id', ActiveMerchant::Billing::Integrations::Ebs.account_id
31
+ add_field 'mode', ActiveMerchant::Billing::Integrations::Ebs.mode
32
+ add_field 'Checksum', get_checksum(
33
+ ActiveMerchant::Billing::Integrations::Ebs.account_id,
34
+ self.fields[self.mappings[:order_id]],
35
+ self.fields[self.mappings[:amount]],
36
+ mapping[:return_url],
37
+ ActiveMerchant::Billing::Integrations::Ebs.secret_key
38
+ )
39
+ end
40
+
41
+ private
42
+ def lookup_country_code(name_or_code, format = :alpha3)
43
+ country = Country.find(name_or_code)
44
+ country.code(format).to_s
45
+ rescue InvalidCountryCodeError
46
+ name_or_code
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,91 @@
1
+ require 'RubyRc4.rb'
2
+ require 'base64'
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ module Integrations #:nodoc:
6
+ module Ebs
7
+ class Notification < ActiveMerchant::Billing::Integrations::Notification
8
+
9
+ attr_accessor :params
10
+
11
+ #Necessary parameters in the :DR returned by ebs
12
+ NECESSARY = [
13
+ "Mode",
14
+ "PaymentID",
15
+ "DateCreated",
16
+ "MerchantRefNo",
17
+ "Amount",
18
+ "TransactionID",
19
+ "ResponseCode",
20
+ "ResponseMessage"
21
+ ]
22
+
23
+ # processing geteway returned data
24
+ #
25
+ def parse(post)
26
+
27
+ rc4 = RubyRc4.new(self.secret_key)
28
+ params = (Hash[ rc4.encrypt(Base64.decode64(post.gsub(/ /,'+'))).split('&').map { |x| x.split("=") } ]).slice(* NECESSARY )
29
+ self.params = params
30
+
31
+ end
32
+
33
+ def ebsin_decode(data, key)
34
+
35
+ rc4 = RubyRc4.new(key)
36
+ params = (Hash[ rc4.encrypt(Base64.decode64(data.gsub(/ /,'+'))).split('&').map { |x| x.split("=") } ]).slice(* NECESSARY )
37
+ params
38
+ end
39
+
40
+ def successful?
41
+ "Transaction Successful" == self.status
42
+ end
43
+
44
+ def valid?
45
+ verify_checksum(
46
+ ActiveMerchant::Billing::Integrations::Ebs.account_id,
47
+ self.payment_id,
48
+ self.gross,
49
+ self.status,
50
+ ActiveMerchant::Billing::Integrations::Ebs.secret_key
51
+ )
52
+ end
53
+
54
+
55
+
56
+ def complete?
57
+ 'Y' == self.status
58
+ end
59
+
60
+ def payment_id
61
+ params['PaymentID']
62
+ end
63
+
64
+ def transaction_id
65
+ params['TransactionID']
66
+ end
67
+
68
+ def secret_key
69
+ ActiveMerchant::Billing::Integrations::Ebs.secret_key
70
+ end
71
+
72
+ # the money amount we received in X.2 decimal.
73
+ def gross
74
+ params['Amount']
75
+ end
76
+
77
+ def status
78
+ params['ResponseMessage']
79
+ end
80
+
81
+ private
82
+
83
+ def verify_checksum(checksum, *args)
84
+ require 'zlib'
85
+ Zlib.adler32(args.join('|'), 1).to_s.eql?(checksum)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveMerchantEbs
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_merchant_ebs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chaithanya Padi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Active merchant integration for EBS Payment Gateway from India
15
+ email:
16
+ - padi@entersoft.in
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.rdoc
25
+ - Rakefile
26
+ - active_merchant_ebs.gemspec
27
+ - lib/RubyRc4.rb
28
+ - lib/active_merchant_ebs.rb
29
+ - lib/active_merchant_ebs/helper.rb
30
+ - lib/active_merchant_ebs/notification.rb
31
+ - lib/active_merchant_ebs/version.rb
32
+ homepage: https://github.com/chaitu87/active_merchant_ebs.git
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project: active_merchant_ebs
52
+ rubygems_version: 1.8.25
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Active merchant integration for EBS Payment Gateway from India
56
+ test_files: []
57
+ has_rdoc: