payuindia 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDI2NmI4YzFjMWQzODBlODFmOTI4ZWIwZjA4YzNkMDQ4MzU4MGUzYw==
4
+ YWRhNWVmZjBjNTdhODk1YTEwYzM1OGRlNThkZDA0MjA5YTFjYjcwOA==
5
5
  data.tar.gz: !binary |-
6
- NzhkOTc4OWY5MTdiNmNmNTFkMWYwNDA1YTc3ZGU4Y2M2ZTZmZGY4Mw==
6
+ ZDc3Yjg3YmViOGE4ODQ5MjJiY2EwYjAxYjU4ZmM5ODFjMDUxZjU4OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTA1NTA4Y2E1ZDA1MzNkZjNkOGIwZGIzOTkzZjNlYmJlZGU2NTU2NmE0MGUy
10
- MWFkMmFhZTMyNzUxOTFiODc2MDg0YTBmZWMxZWIzMGI1YjI0Y2ZhYTM0YTk0
11
- YzhmY2Y4ZmRkMDc5M2Q2NGVhZTUzMDYyMDU3MDIxMDY2NDIxMTQ=
9
+ ZDlhNmE5MWFlYzMyOTIxN2M4NjIzNzdmZmJmMDBjMTA2MDMwOGE1YjU5ZmIw
10
+ ZmYwZmVhYzcyYzY2NDgxMWNiZGZhYmFjNDMwNTkzYTA0MjBhODkwYmIxNmEw
11
+ ZTAwNzE1NGQxNDY4YmJlNGRjODJiOTE4MDE5NWVmYWQ0NDM5MzM=
12
12
  data.tar.gz: !binary |-
13
- NDZkNzk0NTQxMTE0MTM0Mzc2NWEyMTBjMTBjN2JkYzRkNTZlZWNmZDU4ODc0
14
- MjNjNTFkMGMwODA5ODE2MTczM2Q5Y2NjYWU5M2ZjYTBiZGEyZmNlZDExY2Rl
15
- M2NhZGY3YTdjYWIxOTNmMmM0NDRjZmY2ZjE4ZjNhMDE1MzM1NDI=
13
+ NjU1NGRlOTZmYzM4ZWQyOTI1NDBhNGJkYWZkNzA0ZDhiMDUxYzYzNWMxNjgy
14
+ MmE2OTE1OTY2NmY2NTJkN2I1YjQzMmVmYjgwNmE5ZDdhYjIwYjAwNjhiZGM5
15
+ MTI5MGQwYzc4M2E1MzQ3OTE5ZDBkYmY4N2RlNDNhNTJmZjc5OWY=
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in payuindia.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Payuindia
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/payuindia`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ This gem is used to integrate and make transactions with PayU payment gateway. (See [PayU.in](http://payu.in/))
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,13 +20,7 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
23
+ Check the README here https://github.com/payu-india/PayU-Integration-Kit-ROR
32
24
 
33
25
  ## Contributing
34
26
 
@@ -1,5 +1,232 @@
1
1
  require "payuindia/version"
2
+ require 'payuindia/action_view_helper'
3
+ ActionView::Base.send(:include, PayuIndia::ActionViewHelper)
2
4
 
3
- module Payuindia
4
- # Your code goes here...
5
- end
5
+ module PayuIndia
6
+ mattr_accessor :test_url
7
+ mattr_accessor :production_url
8
+
9
+ self.test_url = 'https://test.payu.in/_payment.php'
10
+ self.production_url = 'https://secure.payu.in/_payment.php'
11
+
12
+ def self.service_url
13
+ defined?(Rails) && Rails.env == 'production' ? self.production_url : self.test_url
14
+ end
15
+
16
+ def self.notification(post, options = {})
17
+ Notification.new(post, options)
18
+ end
19
+
20
+ def self.return(post, options = {})
21
+ Return.new(post, options)
22
+ end
23
+
24
+ def self.checksum(merchant_id, secret_key, payload_items )
25
+ Digest::SHA512.hexdigest([merchant_id, *payload_items, secret_key].join("|"))
26
+ end
27
+
28
+ class Helper
29
+
30
+ CHECKSUM_FIELDS = [ :txnid, :amount, :productinfo, :firstname, :email, :udf1, :udf2, :udf3, :udf4,
31
+ :udf5, :udf6, :udf7, :udf8, :udf9, :udf10 ]
32
+
33
+ def initialize(key, salt, options = {})
34
+ @key, @salt, @options = key, salt, options
35
+ end
36
+
37
+ def form_fields
38
+ sanitize_fields
39
+ @options.merge(:hash => generate_checksum)
40
+ end
41
+
42
+ def generate_checksum
43
+ checksum_payload_items = CHECKSUM_FIELDS.map { |field| @options[field] }
44
+ PayuIndia.checksum(@key, @salt, checksum_payload_items )
45
+ end
46
+
47
+ def sanitize_fields
48
+ [:address1, :address2, :city, :state, :country, :productinfo, :email, :phone].each do |field|
49
+ @options[field].gsub!(/[^a-zA-Z0-9\-_@\/\s.]/, '') if @options[field]
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ class Notification
56
+ def initialize(post, options = {})
57
+ @key = options[:key]
58
+ @salt = options[:salt]
59
+ @params = options[:params]
60
+ end
61
+
62
+ def complete?
63
+ status == "Completed"
64
+ end
65
+
66
+ def params
67
+ @params
68
+ end
69
+
70
+ def status
71
+ @status ||= if checksum_ok?
72
+ if transaction_id.blank?
73
+ 'Invalid'
74
+ else
75
+ case transaction_status.downcase
76
+ when 'success' then 'Completed'
77
+ when 'failure' then 'Failed'
78
+ when 'pending' then 'Pending'
79
+ end
80
+ end
81
+ else
82
+ 'Tampered'
83
+ end
84
+ end
85
+
86
+ def invoice_ok?( order_id )
87
+ order_id.to_s == invoice.to_s
88
+ end
89
+
90
+ # Order amount should be equal to gross - discount
91
+ def amount_ok?( order_amount, order_discount = BigDecimal.new( '0.0' ) )
92
+ BigDecimal.new( gross ) == order_amount && BigDecimal.new( discount.to_s ) == order_discount
93
+ end
94
+
95
+ # Status of transaction return from the PayU. List of possible values:
96
+ # <tt>SUCCESS</tt>::
97
+ # <tt>PENDING</tt>::
98
+ # <tt>FAILURE</tt>::
99
+ def transaction_status
100
+ params['status']
101
+ end
102
+
103
+ # ID of this transaction (PayU.in number)
104
+ def transaction_id
105
+ params['mihpayid']
106
+ end
107
+
108
+ # Mode of Payment
109
+ #
110
+ # 'CC' for credit-card
111
+ # 'NB' for net-banking
112
+ # 'CD' for cheque or DD
113
+ # 'CO' for Cash Pickup
114
+ def type
115
+ params['mode']
116
+ end
117
+
118
+ # What currency have we been dealing with
119
+ def currency
120
+ 'INR'
121
+ end
122
+
123
+ # This is the invoice which you passed to PayU.in
124
+ def invoice
125
+ params['txnid']
126
+ end
127
+
128
+ # Merchant Id provided by the PayU.in
129
+ def account
130
+ params['key']
131
+ end
132
+
133
+ # original amount send by merchant
134
+ def gross
135
+ params['amount']
136
+ end
137
+
138
+ # This is discount given to user - based on promotion set by merchants.
139
+ def discount
140
+ params['discount']
141
+ end
142
+
143
+ # Description offer for what PayU given the offer to user - based on promotion set by merchants.
144
+ def offer_description
145
+ params['offer']
146
+ end
147
+
148
+ # Information about the product as send by merchant
149
+ def product_info
150
+ params['productinfo']
151
+ end
152
+
153
+ # Email of the customer
154
+ def customer_email
155
+ params['email']
156
+ end
157
+
158
+ # Phone of the customer
159
+ def customer_phone
160
+ params['phone']
161
+ end
162
+
163
+ # Firstname of the customer
164
+ def customer_first_name
165
+ params['firstname']
166
+ end
167
+
168
+ # Lastname of the customer
169
+ def customer_last_name
170
+ params['lastname']
171
+ end
172
+
173
+ # Full address of the customer
174
+ def customer_address
175
+ { :address1 => params['address1'], :address2 => params['address2'],
176
+ :city => params['city'], :state => params['state'],
177
+ :country => params['country'], :zipcode => params['zipcode'] }
178
+ end
179
+
180
+ def user_defined
181
+ @user_defined ||= 10.times.map { |i| params["udf#{i + 1}"] }
182
+ end
183
+
184
+ def checksum
185
+ params['hash']
186
+ end
187
+
188
+ def message
189
+ @message || "#{params['error']} - #{params['error_Message']}"
190
+ end
191
+
192
+ def acknowledge(authcode = nil)
193
+ checksum_ok?
194
+ end
195
+
196
+ def checksum_ok?
197
+ checksum_fields = [transaction_status, *user_defined.reverse, customer_email, customer_first_name, product_info, gross, invoice]
198
+
199
+ unless Digest::SHA512.hexdigest([@salt, *checksum_fields, @key].join("|")) == checksum
200
+ @message = 'Return checksum not matching the data provided'
201
+ return false
202
+ end
203
+ true
204
+ end
205
+ end
206
+
207
+ class Return
208
+ def initialize(query_string, options = {})
209
+ @notification = Notification.new(query_string, options)
210
+ end
211
+
212
+ def transaction_id
213
+ @notification.transaction_id
214
+ end
215
+
216
+ def status( order_id, order_amount )
217
+ if @notification.invoice_ok?( order_id ) && @notification.amount_ok?( BigDecimal.new(order_amount) )
218
+ @notification.status
219
+ else
220
+ 'Mismatch'
221
+ end
222
+ end
223
+
224
+ def success?
225
+ status( @params['txnid'], @params['amount'] ) == 'Completed'
226
+ end
227
+
228
+ def message
229
+ @notification.message
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,47 @@
1
+ require 'action_pack'
2
+ require 'payuindia'
3
+
4
+ module PayuIndia #:nodoc:
5
+ ActionViewHelperError = Class.new(StandardError)
6
+
7
+ module ActionViewHelper
8
+ # This Helper creates form with all parameters added.
9
+ #
10
+ # <% payment_form_for_payu 'YOUR_KEY', 'YOUR_SALT',
11
+ # :txnid => @cart.id,
12
+ # :amount => @cart.total_price,
13
+ # :productinfo => 'Book',
14
+ # :firstname => 'abc',
15
+ # :email => 'abc@example.com',
16
+ # :phone => '1234567890',
17
+ # :surl => 'http://localhost:3000/payu_callback',
18
+ # :furl => 'http://localhost:3000/payu_callback',
19
+ # :html => { :id => 'payment-form' } %>
20
+
21
+ def payment_form_for_payu(key, salt, options = {})
22
+ if !options.is_a?(Hash) || !key.is_a?(String) || !salt.is_a?(String)
23
+ concat("Something Wrong! params order -> key (String), salt (String), options (Hash) ")
24
+ nil
25
+ else
26
+ form_options = options.delete(:html) || {}
27
+ service = PayuIndia::Helper.new(key, salt, options)
28
+ result = []
29
+
30
+ result << form_tag(PayuIndia.service_url, form_options.merge(:method => :post))
31
+
32
+ result << hidden_field_tag('key', key)
33
+
34
+ service.form_fields.each do |field, value|
35
+ result << hidden_field_tag(field, value)
36
+ end
37
+
38
+ result << '<input type=submit value=" Pay with PayU ">'
39
+ result << '</form>'
40
+ result= result.join("\n")
41
+
42
+ concat(result.respond_to?(:html_safe) ? result.html_safe : result)
43
+ nil
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
- module Payuindia
2
- VERSION = "0.1.0"
1
+ module PayuIndia
2
+ VERSION = "0.1.1"
3
3
  end
@@ -5,12 +5,12 @@ require 'payuindia/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "payuindia"
8
- spec.version = Payuindia::VERSION
8
+ spec.version = PayuIndia::VERSION
9
9
  spec.authors = ["Sandeep Kumar"]
10
10
  spec.email = ["sandeep.kumar@payu.in"]
11
11
 
12
12
  if spec.respond_to?(:metadata)
13
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
13
+ spec.metadata['allowed_push_host'] = "http://rubygems.org"
14
14
  end
15
15
 
16
16
  spec.summary = %q{Gem for Ruby on Rails Apps.}
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "bundler", "~> 1.8"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payuindia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandeep Kumar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2015-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.8'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -54,13 +54,14 @@ files:
54
54
  - bin/console
55
55
  - bin/setup
56
56
  - lib/payuindia.rb
57
+ - lib/payuindia/action_view_helper.rb
57
58
  - lib/payuindia/version.rb
58
59
  - payuindia.gemspec
59
60
  homepage: https://github.com/payu-india/payuindia
60
61
  licenses:
61
62
  - MIT
62
63
  metadata:
63
- allowed_push_host: https://rubygems.org
64
+ allowed_push_host: http://rubygems.org
64
65
  post_install_message:
65
66
  rdoc_options: []
66
67
  require_paths:
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  version: '0'
78
79
  requirements: []
79
80
  rubyforge_project:
80
- rubygems_version: 2.2.2
81
+ rubygems_version: 2.4.6
81
82
  signing_key:
82
83
  specification_version: 4
83
84
  summary: Gem for Ruby on Rails Apps.