wj-payuindia 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f10016c192ed08114a56e690f02a2b63169d09e9
4
+ data.tar.gz: 9560c337d47cf44107f585ede3b4310930ffd695
5
+ SHA512:
6
+ metadata.gz: 2eea33bd5645067fd92d3e3da046f3f276d8796c79e78fe9f8e8d7480e12e6ce5119768d105eb26e82db85eccc3e51ae24e7fecdf187022b21f797d6d25a769f
7
+ data.tar.gz: 35d4eafc911f33fba266f4b94687d87130a0dac25e5bea14efe38eb9d961ddbd196cc4b68e8ed57d67130383a92cc90bbd9d065bc67fa06c7e09d89972bb00ff
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+ /Gemfile.lock
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in payuindia.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Sandeep Kumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Payuindia
2
+
3
+ This gem is used to integrate and make transactions with PayU payment gateway. (See [PayU.in](http://payu.in/))
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'payuindia'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install payuindia
20
+
21
+ ## Usage
22
+
23
+ Check the README here https://github.com/payu-india/PayU-Integration-Kit-ROR
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/payuindia/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "payuindia"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/payuindia.rb ADDED
@@ -0,0 +1,264 @@
1
+ require "payuindia/version"
2
+ require 'payuindia/action_view_helper'
3
+ ActionView::Base.send(:include, PayuIndia::ActionViewHelper)
4
+
5
+ module PayuIndia
6
+ mattr_accessor :test_url
7
+ mattr_accessor :production_url
8
+ mattr_accessor :webservice_test_url
9
+ mattr_accessor :webservice_production_url
10
+
11
+ self.test_url = 'https://test.payu.in/_payment.php'
12
+ self.production_url = 'https://secure.payu.in/_payment.php'
13
+ self.webservice_test_url = 'https://test.payu.in/merchant/postservice.php?form=2'
14
+ self.webservice_production_url = 'https://info.payu.in/merchant/postservice.php?form=2'
15
+
16
+
17
+ def self.service_url
18
+ defined?(Rails) && Rails.env == 'production' ? self.production_url : self.test_url
19
+ end
20
+
21
+ def self.webservice_url
22
+ defined?(Rails) && Rails.env == 'production' ? self.webservice_production_url : self.webservice_test_url
23
+ end
24
+
25
+ def self.notification(post, options = {})
26
+ Notification.new(post, options)
27
+ end
28
+
29
+ def self.return(post, options = {})
30
+ Return.new(post, options)
31
+ end
32
+
33
+ def self.checksum(merchant_id, secret_key, payload_items )
34
+ puts "string for hash."
35
+ s = [merchant_id, *payload_items, secret_key].join("|")
36
+ puts s.to_s
37
+ puts "hash"
38
+ puts Digest::SHA512.hexdigest(s)
39
+ Digest::SHA512.hexdigest(s)
40
+ end
41
+
42
+ class WebService
43
+
44
+ def initialize(key,salt,options = {})
45
+ @key, @salt, @options = key, salt, options
46
+ end
47
+
48
+ CHECKSUM_FIELDS = [ :command, :var1 ]
49
+
50
+ def generate_checksum
51
+ checksum_payload_items = CHECKSUM_FIELDS.map { |field| @options[field] }
52
+ puts "checksm payload items are:"
53
+ puts checksum_payload_items.to_s
54
+ PayuIndia.checksum(@key, @salt, checksum_payload_items )
55
+ end
56
+
57
+
58
+ end
59
+
60
+ class Helper
61
+
62
+ CHECKSUM_FIELDS = [ :txnid, :amount, :productinfo, :firstname, :email, :udf1, :udf2, :udf3, :udf4,
63
+ :udf5, :udf6, :udf7, :udf8, :udf9, :udf10 ]
64
+
65
+ def initialize(key, salt, options = {})
66
+ @key, @salt, @options = key, salt, options
67
+ end
68
+
69
+ def form_fields
70
+ sanitize_fields
71
+ @options.merge(:hash => generate_checksum)
72
+ end
73
+
74
+ def generate_checksum
75
+ checksum_payload_items = CHECKSUM_FIELDS.map { |field| @options[field] }
76
+ PayuIndia.checksum(@key, @salt, checksum_payload_items )
77
+ end
78
+
79
+ def sanitize_fields
80
+ [:address1, :address2, :city, :state, :country, :productinfo, :email, :phone].each do |field|
81
+ @options[field].gsub!(/[^a-zA-Z0-9\-_@\/\s.]/, '') if @options[field]
82
+ end
83
+ end
84
+
85
+ end
86
+
87
+ class Notification
88
+ def initialize(post, options = {})
89
+ @key = options[:key]
90
+ @salt = options[:salt]
91
+ @params = options[:params]
92
+ end
93
+
94
+ def complete?
95
+ status == "Completed"
96
+ end
97
+
98
+ def params
99
+ @params
100
+ end
101
+
102
+ def status
103
+ @status ||= if checksum_ok?
104
+ if transaction_id.blank?
105
+ 'Invalid'
106
+ else
107
+ case transaction_status.downcase
108
+ when 'success' then 'Completed'
109
+ when 'failure' then 'Failed'
110
+ when 'pending' then 'Pending'
111
+ end
112
+ end
113
+ else
114
+ 'Tampered'
115
+ end
116
+ end
117
+
118
+ def invoice_ok?( order_id )
119
+ order_id.to_s == invoice.to_s
120
+ end
121
+
122
+ # Order amount should be equal to gross - discount
123
+ def amount_ok?( order_amount, order_discount = BigDecimal.new( '0.0' ) )
124
+ BigDecimal.new( gross ) == order_amount && BigDecimal.new( discount.to_s ) == order_discount
125
+ end
126
+
127
+ # Status of transaction return from the PayU. List of possible values:
128
+ # <tt>SUCCESS</tt>::
129
+ # <tt>PENDING</tt>::
130
+ # <tt>FAILURE</tt>::
131
+ def transaction_status
132
+ params['status']
133
+ end
134
+
135
+ # ID of this transaction (PayU.in number)
136
+ def transaction_id
137
+ params['mihpayid']
138
+ end
139
+
140
+ # Mode of Payment
141
+ #
142
+ # 'CC' for credit-card
143
+ # 'NB' for net-banking
144
+ # 'CD' for cheque or DD
145
+ # 'CO' for Cash Pickup
146
+ def type
147
+ params['mode']
148
+ end
149
+
150
+ # What currency have we been dealing with
151
+ def currency
152
+ 'INR'
153
+ end
154
+
155
+ # This is the invoice which you passed to PayU.in
156
+ def invoice
157
+ params['txnid']
158
+ end
159
+
160
+ # Merchant Id provided by the PayU.in
161
+ def account
162
+ params['key']
163
+ end
164
+
165
+ # original amount send by merchant
166
+ def gross
167
+ params['amount']
168
+ end
169
+
170
+ # This is discount given to user - based on promotion set by merchants.
171
+ def discount
172
+ params['discount']
173
+ end
174
+
175
+ # Description offer for what PayU given the offer to user - based on promotion set by merchants.
176
+ def offer_description
177
+ params['offer']
178
+ end
179
+
180
+ # Information about the product as send by merchant
181
+ def product_info
182
+ params['productinfo']
183
+ end
184
+
185
+ # Email of the customer
186
+ def customer_email
187
+ params['email']
188
+ end
189
+
190
+ # Phone of the customer
191
+ def customer_phone
192
+ params['phone']
193
+ end
194
+
195
+ # Firstname of the customer
196
+ def customer_first_name
197
+ params['firstname']
198
+ end
199
+
200
+ # Lastname of the customer
201
+ def customer_last_name
202
+ params['lastname']
203
+ end
204
+
205
+ # Full address of the customer
206
+ def customer_address
207
+ { :address1 => params['address1'], :address2 => params['address2'],
208
+ :city => params['city'], :state => params['state'],
209
+ :country => params['country'], :zipcode => params['zipcode'] }
210
+ end
211
+
212
+ def user_defined
213
+ @user_defined ||= 10.times.map { |i| params["udf#{i + 1}"] }
214
+ end
215
+
216
+ def checksum
217
+ params['hash']
218
+ end
219
+
220
+ def message
221
+ @message || "#{params['error']} - #{params['error_Message']}"
222
+ end
223
+
224
+ def acknowledge(authcode = nil)
225
+ checksum_ok?
226
+ end
227
+
228
+ def checksum_ok?
229
+ checksum_fields = [transaction_status, *user_defined.reverse, customer_email, customer_first_name, product_info, gross, invoice]
230
+
231
+ unless Digest::SHA512.hexdigest([@salt, *checksum_fields, @key].join("|")) == checksum
232
+ @message = 'Return checksum not matching the data provided'
233
+ return false
234
+ end
235
+ true
236
+ end
237
+ end
238
+
239
+ class Return
240
+ def initialize(query_string, options = {})
241
+ @notification = Notification.new(query_string, options)
242
+ end
243
+
244
+ def transaction_id
245
+ @notification.transaction_id
246
+ end
247
+
248
+ def status( order_id, order_amount )
249
+ if @notification.invoice_ok?( order_id ) && @notification.amount_ok?( BigDecimal.new(order_amount) )
250
+ @notification.status
251
+ else
252
+ 'Mismatch'
253
+ end
254
+ end
255
+
256
+ def success?
257
+ status( @params['txnid'], @params['amount'] ) == 'Completed'
258
+ end
259
+
260
+ def message
261
+ @notification.message
262
+ end
263
+ end
264
+ end
@@ -0,0 +1,97 @@
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
+
47
+ # This Helper creates form with all parameters added.
48
+ #
49
+ # <% payu_biz_form 'YOUR_KEY', 'YOUR_SALT',
50
+ # :txnid => @cart.id,
51
+ # :amount => @cart.total_price,
52
+ # :productinfo => 'Book',
53
+ # :firstname => 'abc',
54
+ # :email => 'abc@example.com',
55
+ # :phone => '1234567890',
56
+ # :surl => 'http://localhost:3000/payu_callback',
57
+ # :furl => 'http://localhost:3000/payu_callback',
58
+ # :html => { :id => 'payment-form', :button_text => 'Purchase' } do %>
59
+ #
60
+ # <%= label_tag 'City' %>
61
+ # <%= text_field_tag 'city' %>
62
+ #
63
+ # <%= label_tag 'Country' %>
64
+ # <%= text_field_tag 'country' %>
65
+ #
66
+ # <% end %>
67
+
68
+ def payu_biz_form(key, salt, options, &block)
69
+ if !options.is_a?(Hash) || !key.is_a?(String) || !salt.is_a?(String)
70
+ concat("Something Wrong! params order -> key (String), salt (String), options (Hash) ")
71
+ nil
72
+ else
73
+ form_options = options.delete(:html) || {}
74
+ service = PayuIndia::Helper.new(key, salt, options)
75
+ result = []
76
+
77
+ result << form_tag(PayuIndia.service_url, form_options.merge(:method => :post))
78
+
79
+ result << hidden_field_tag('key', key)
80
+
81
+ service.form_fields.each do |field, value|
82
+ result << hidden_field_tag(field, value)
83
+ end
84
+
85
+ result << capture(&block)
86
+
87
+ result << "<input type=submit value='#{form_options[:button_text] || ' Pay with PayU '}'>"
88
+ result << '</form>'
89
+ result = result.join("\n")
90
+
91
+ concat(result.respond_to?(:html_safe) ? result.html_safe : result)
92
+ nil
93
+ end
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,3 @@
1
+ module PayuIndia
2
+ VERSION = "0.1.1"
3
+ end
data/payuindia.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'payuindia/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wj-payuindia"
8
+ spec.version = PayuIndia::VERSION
9
+ spec.authors = ["greatmanta111"]
10
+ spec.email = ["bhargav.r.raut@gmail.com"]
11
+
12
+ if spec.respond_to?(:metadata)
13
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
14
+ end
15
+
16
+ spec.summary = %q{Gem for Ruby on Rails Apps.}
17
+ spec.description = %q{Gem for Ruby on Rails Apps which integrate with PayU India Payment Gateway}
18
+ spec.homepage = "https://github.com/payu-india/payuindia"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.8"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wj-payuindia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - greatmanta111
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Gem for Ruby on Rails Apps which integrate with PayU India Payment Gateway
42
+ email:
43
+ - bhargav.r.raut@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/payuindia.rb
57
+ - lib/payuindia/action_view_helper.rb
58
+ - lib/payuindia/version.rb
59
+ - payuindia.gemspec
60
+ homepage: https://github.com/payu-india/payuindia
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ allowed_push_host: https://rubygems.org
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.5
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Gem for Ruby on Rails Apps.
85
+ test_files: []