paytm-merchant 0.1.3.1 → 0.2

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad90b32141af42df9c734f456958f692932746a2
4
- data.tar.gz: 19d2b2ca4013ece0410b6737a446803656b40b45
3
+ metadata.gz: 446ec3210601afb50b53fff81af88086739e3d64
4
+ data.tar.gz: 1bf046b041205cce69719f384b5d07bb269fa70c
5
5
  SHA512:
6
- metadata.gz: 114f539cf536f372a344cdf79924ad36023f7dd79ece3b1ced3382fd12f833b8509214fdb696929ab49159b58b0f87fccd3e2c61140494795c41c2cbc877af41
7
- data.tar.gz: d493ee4c2642fb5e1cf1654494e29b0887a593c13abb08c9677df45ba7fae0e2e701f6e37577ffa4de4d5e978f084262e3396ad3f7f7e22011ca97eea70fdb68
6
+ metadata.gz: aeadf4a5e56f6ea21b422c7222da26fd629773f2447d6070bf000c250179eb52b56661e49a6c81687d4b9ab3d711d6f1b8f998b0174d062dd747abef2b89b266
7
+ data.tar.gz: ee6b371b15d6a2608fe402ec9d45fd4d3d1cda4047737726e65fd95c6765474f8e9adca06aa27e30a5d6a1152134a1dde19e32a3d09bd1d7427a57ca5bbe84e9
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Paytm Merchant
1
+ # Paytm Merchant [![Gem Version](https://badge.fury.io/rb/paytm-merchant.svg)](https://badge.fury.io/rb/paytm-merchant)
2
2
 
3
3
  This is a ruby library(and not just rails gem) for PayTM Merchant transactions API. You can easily integrate you application to pay your users/winners by calling `Paytm.new({amount: 110, phone: '7777777777'}).transfer`
4
4
 
@@ -135,7 +135,7 @@ Response
135
135
 
136
136
  ## Contributing
137
137
 
138
- Bug reports and pull requests are welcome on GitHub at https://github.com/schnmudgal/paytm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
138
+ Bug reports and pull requests are welcome on GitHub at https://github.com/schnmudgal/paytm-merchant. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
139
139
 
140
140
 
141
141
  ## License
@@ -135,7 +135,7 @@ module PayTM
135
135
  end
136
136
 
137
137
  def generate_hash(key, params={})
138
- @checksum = Paytm.new_pg_checksum_by_str(params.to_json, key).gsub("\n",'')
138
+ @checksum = Paytm.new_pg_checksum_by_String(params.to_json, key).gsub("\n",'')
139
139
  end
140
140
  end
141
141
  end
@@ -1,3 +1,8 @@
1
+ ######################################## Encryption module #########################################
2
+ ############################ AES 128-bit encryption with SHA256 Hash ###############################
3
+
4
+ ####################################### New PG Encryption ##########################################
5
+
1
6
  module EncryptionNewPG
2
7
 
3
8
  require 'openssl'
@@ -8,20 +13,21 @@ module EncryptionNewPG
8
13
  ### function returns dictionary of encrypted data ###
9
14
  ### accepts a dictionary with data and key to encrypt with ###
10
15
  ### can accept multiple key value pairs in the dictionary ###
11
- def new_pg_encrypt(params)
12
- if (params.class != Hash) || (params.keys == [])
16
+ def new_pg_encrypt(paytmparams)
17
+ if (paytmparams.class != Hash) || (paytmparams.keys == [])
13
18
  return false
14
19
  end
15
- if !params.has_key?(:key)
20
+ if !paytmparams.has_key?(:key)
16
21
  return false
17
22
  end
18
23
  encrypted_data = Hash[]
19
- key = params.delete(:key)
20
- keys = params.keys
21
- aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
24
+ key = paytmparams.delete(:key)
25
+ keys = paytmparams.keys
26
+ ###aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
27
+ aes = OpenSSL::Cipher::AES.new('128-CBC')
22
28
  begin
23
29
  keys.each do |k|
24
- data = params[k]
30
+ data = paytmparams[k]
25
31
  aes.encrypt
26
32
  aes.key = key
27
33
  aes.iv = '@@@@&&&&####$$$$'
@@ -43,7 +49,8 @@ module EncryptionNewPG
43
49
  ### input data -> value to be encrypted ###
44
50
  ### key -> key to use for encryption ###
45
51
  def new_pg_encrypt_variable(data, key)
46
- aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
52
+ ##aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
53
+ aes = OpenSSL::Cipher::AES.new('128-CBC')
47
54
  aes.encrypt
48
55
  aes.key = key
49
56
  aes.iv = '@@@@&&&&####$$$$'
@@ -61,20 +68,21 @@ module EncryptionNewPG
61
68
  ### function returns dictionary of decrypted data ###
62
69
  ### accepts a dictionary with data and key to decrypt with ###
63
70
  ### can accept multiple key value pairs in the dictionary ###
64
- def new_pg_decrypt(params)
65
- if (params.class != Hash) || (params.keys == [])
71
+ def new_pg_decrypt(paytmparams)
72
+ if (paytmparams.class != Hash) || (paytmparams.keys == [])
66
73
  return false
67
74
  end
68
- if !params.has_key?(:key)
75
+ if !paytmparams.has_key?(:key)
69
76
  return false
70
77
  end
71
78
  decrypted_data = Hash[]
72
- key = params.delete(:key)
73
- keys = params.keys
74
- aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
79
+ key = paytmparams.delete(:key)
80
+ keys = paytmparams.keys
81
+ ##aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
82
+ aes = OpenSSL::Cipher::AES.new('128-CBC')
75
83
  begin
76
84
  keys.each do |k|
77
- data = params[k]
85
+ data = paytmparams[k]
78
86
  aes.decrypt
79
87
  aes.key = key
80
88
  aes.iv = '@@@@&&&&####$$$$'
@@ -101,7 +109,8 @@ module EncryptionNewPG
101
109
  ### input data -> value to be decrypted ###
102
110
  ### key -> key to use for decryption ###
103
111
  def new_pg_decrypt_variable(data, key)
104
- aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
112
+ ##aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
113
+ aes = OpenSSL::Cipher::AES.new('128-CBC')
105
114
  aes.decrypt
106
115
  aes.key = key
107
116
  aes.iv = '@@@@&&&&####$$$$'
@@ -125,23 +134,23 @@ module EncryptionNewPG
125
134
  ### function returns checksum of given key value pairs ###
126
135
  ### accepts a hash with key value pairs ###
127
136
  ### calculates sha256 checksum of given values ###
128
- def new_pg_checksum(params, key, salt_length = 4)
129
- if params.class != Hash
137
+ def new_pg_checksum(paytmparams, key, salt_length = 4)
138
+ if paytmparams.class != Hash
130
139
  return false
131
140
  end
132
141
  if key.empty?
133
142
  return false
134
143
  end
135
144
  salt = new_pg_generate_salt(salt_length)
136
- keys = params.keys
145
+ keys = paytmparams.keys
137
146
  str = nil
138
147
  keys = keys.sort
139
148
  keys.each do |k|
140
149
  if str.nil?
141
- str = params[k].to_s
150
+ str = paytmparams[k].to_s
142
151
  next
143
152
  end
144
- str = str + '|' + params[k].to_s
153
+ str = str + '|' + paytmparams[k].to_s
145
154
  end
146
155
  str = str + '|' + salt
147
156
  check_sum = Digest::SHA256.hexdigest(str)
@@ -151,14 +160,19 @@ module EncryptionNewPG
151
160
  return check_sum
152
161
  end
153
162
 
154
-
155
- def new_pg_checksum_by_str(paramstr, key, salt_length = 4)
156
-
163
+ ### function returns checksum of given String ###
164
+ ### accepts a hash with String ###
165
+ ### calculates sha256 checksum of given values ###
166
+ def new_pg_checksum_by_String(strdata, key, salt_length = 4)
167
+ if strdata.empty?
168
+ return false
169
+ end
170
+ if key.empty?
171
+ return false
172
+ end
157
173
  salt = new_pg_generate_salt(salt_length)
158
-
159
174
  str = nil
160
-
161
- str = paramstr + '|' + salt
175
+ str = strdata + '|' + salt
162
176
  check_sum = Digest::SHA256.hexdigest(str)
163
177
  check_sum = check_sum + salt
164
178
  ### encrypting checksum ###
@@ -166,43 +180,111 @@ module EncryptionNewPG
166
180
  return check_sum
167
181
  end
168
182
 
183
+ ### function returns checksum of given key value pairs ###
184
+ ### accepts a hash with key value pairs ###
185
+ ### calculates sha256 checksum of given values ###
186
+ def new_pg_refund_checksum(paytmparams, key, salt_length = 4)
187
+ keys = paytmparams.keys
188
+ keys.each do |k|
189
+ if ! paytmparams[k].empty?
190
+ #if params[k].to_s.include? "REFUND"
191
+ unless paytmparams[k].to_s.include? "|"
192
+ next
193
+ end
194
+ paytmparams[k] = paytmparams[k]
195
+ end
196
+ end
197
+ if paytmparams.class != Hash
198
+ return false
199
+ end
200
+ if key.empty?
201
+ return false
202
+ end
203
+ salt = new_pg_generate_salt(salt_length)
204
+ keys = paytmparams.keys
205
+ str = nil
206
+ keys = keys.sort
207
+ keys.each do |k|
208
+ if str.nil?
209
+ str = paytmparams[k].to_s
210
+ next
211
+ end
212
+ str = str + '|' + paytmparams[k].to_s
213
+ end
214
+ str = str + '|' + salt
215
+ check_sum = Digest::SHA256.hexdigest(str)
216
+ check_sum = check_sum + salt
217
+ ### encrypting checksum ###
218
+ check_sum = new_pg_encrypt_variable(check_sum, key)
219
+ return check_sum
220
+ end
169
221
 
170
222
  ### function returns checksum of given key value pairs (must contain the :checksum key) ###
171
223
  ### accepts a hash with key value pairs ###
172
224
  ### calculates sha256 checksum of given values ###
173
225
  ### returns true if checksum is consistent ###
174
226
  ### returns false in case of inconsistency ###
175
- def new_pg_verify_checksum(params, check_sum, key, salt_length = 4)
176
-
177
- if params.class != Hash
227
+ def new_pg_verify_checksum_by_String(strdata, check_sum, key, salt_length = 4)
228
+ if strdata.empty?
178
229
  return false
179
230
  end
180
-
181
231
  if key.empty?
182
232
  return false
183
233
  end
184
-
185
234
  if check_sum.nil? || check_sum.empty?
186
235
  return false
187
236
  end
188
-
189
237
  generated_check_sum = nil
190
238
  check_sum = new_pg_decrypt_variable(check_sum, key)
239
+ if check_sum == false
240
+ return false
241
+ end
242
+ begin
243
+ salt = check_sum[(check_sum.length-salt_length), (check_sum.length)]
244
+ str = strdata + '|' + salt
245
+ generated_check_sum = Digest::SHA256.hexdigest(str)
246
+ generated_check_sum = generated_check_sum + salt
247
+ rescue Exception => e
248
+ return false
249
+ end
250
+ if check_sum == generated_check_sum
251
+ return true
252
+ else
253
+ return false
254
+ end
255
+ end
191
256
 
257
+ ### function returns checksum of given key value pairs (must contain the :checksum key) ###
258
+ ### accepts a hash with key value pairs ###
259
+ ### calculates sha256 checksum of given values ###
260
+ ### returns true if checksum is consistent ###
261
+ ### returns false in case of inconsistency ###
262
+ def new_pg_verify_checksum(paytmparams, check_sum, key, salt_length = 4)
263
+ if paytmparams.class != Hash
264
+ return false
265
+ end
266
+ if key.empty?
267
+ return false
268
+ end
269
+ if check_sum.nil? || check_sum.empty?
270
+ return false
271
+ end
272
+ generated_check_sum = nil
273
+ check_sum = new_pg_decrypt_variable(check_sum, key)
192
274
  if check_sum == false
193
275
  return false
194
276
  end
195
277
  begin
196
278
  salt = check_sum[(check_sum.length-salt_length), (check_sum.length)]
197
- keys = params.keys
279
+ keys = paytmparams.keys
198
280
  str = nil
199
281
  keys = keys.sort
200
282
  keys.each do |k|
201
283
  if str.nil?
202
- str = params[k].to_s
284
+ str = paytmparams[k].to_s
203
285
  next
204
286
  end
205
- str = str + '|' + params[k].to_s
287
+ str = str + '|' + paytmparams[k].to_s
206
288
  end
207
289
  str = str + '|' + salt
208
290
  generated_check_sum = Digest::SHA256.hexdigest(str)
@@ -210,7 +292,6 @@ module EncryptionNewPG
210
292
  rescue Exception => e
211
293
  return false
212
294
  end
213
-
214
295
  if check_sum == generated_check_sum
215
296
  return true
216
297
  else
@@ -1,5 +1,5 @@
1
1
  module PayTM
2
2
  module Merchant
3
- VERSION = '0.1.3.1'
3
+ VERSION = '0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paytm-merchant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.1
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sachin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-28 00:00:00.000000000 Z
11
+ date: 2018-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.4.6
95
+ rubygems_version: 2.5.1
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: 'Paytm: Merchant to User waller transfer library.'