Class: Kount::NewKhash
- Inherits:
-
Object
- Object
- Kount::NewKhash
- Defined in:
- lib/utils/khash.rb,
lib/kount/utils/khash.rb
Class Method Summary collapse
- .getKhash(data, len, m) ⇒ Object
-
.hash_token(plain_text, ptyp, ksalt, merchant_id = '') ⇒ String
KHASH version of string.
- .HashCheckPayment(plain_text, ksalt) ⇒ Object
- .HashGiftCard(plain_text, ksalt, merchant_id) ⇒ Object
- .HashPaymentToken(plain_text, ksalt) ⇒ Object
Class Method Details
.getKhash(data, len, m) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/utils/khash.rb', line 18 def self.getKhash(data, len, m) a = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' r = Digest::SHA1.hexdigest("#{data}.#{m}") c = '' len = 17 if len > 17 limit = 2 * len i = 0 while i < limit c << a[r[i..i + 6].to_i(16) % 36] i += 2 end c end |
.hash_token(plain_text, ptyp, ksalt, merchant_id = '') ⇒ String
Returns KHASH version of string.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/utils/khash.rb', line 6 def self.hash_token(plain_text, ptyp, ksalt, merchant_id = '') puts ptyp exit if ptyp == 'CARD' HashPaymentToken(plain_text, ksalt) elsif ptyp == 'CHEK' HashCheckPayment(plain_text, ksalt) else HashGiftCard(plain_text, ksalt, merchant_id) end end |
.HashCheckPayment(plain_text, ksalt) ⇒ Object
38 39 40 41 42 |
# File 'lib/utils/khash.rb', line 38 def self.HashCheckPayment(plain_text, ksalt) first_six = plain_text[0..5] mashed = getKhash(plain_text, 14, ksalt) "#{first_six}#{mashed}" end |
.HashGiftCard(plain_text, ksalt, merchant_id) ⇒ Object
44 45 46 47 |
# File 'lib/utils/khash.rb', line 44 def self.HashGiftCard(plain_text, ksalt, merchant_id) mashed = getKhash(plain_text, 14, ksalt) "#{merchant_id}#{mashed}" end |
.HashPaymentToken(plain_text, ksalt) ⇒ Object
32 33 34 35 36 |
# File 'lib/utils/khash.rb', line 32 def self.HashPaymentToken(plain_text, ksalt) first_six = plain_text[0..5] mashed = getKhash(plain_text, 14, ksalt) "#{first_six}#{mashed}" end |