virtual_merchant 0.3.10 → 0.4.0
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 +4 -4
- data/lib/virtual_merchant/credit_card.rb +52 -98
- data/lib/virtual_merchant/user_input.rb +55 -0
- data/lib/virtual_merchant.rb +2 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e30717bdee04d446b5cc2417afcc1f9150a6192d
|
4
|
+
data.tar.gz: b6fd4d4393eac6a25c7ab0c30a809da460d74e43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 945cbe1b26950f5a61cd8a5375cb52d589cede8b9a9bbedeb5a09c4911e0aefa6ff2a68a5a6040177b6624de90fb08eb3baf2d4771598cf7990709a019693da9
|
7
|
+
data.tar.gz: 9cfecd9fa7316803cfed450af806750f46e5807366fc9bcb395cf8124d20cf1c443bb3bf999472b50c83e62f53e5f656ed2dd965dd17ac07985a7ca11b3cbd78
|
@@ -1,70 +1,26 @@
|
|
1
1
|
require 'virtual_merchant/swipe_extractor'
|
2
|
+
require 'virtual_merchant/user_input'
|
2
3
|
module VirtualMerchant
|
3
4
|
class CreditCard
|
4
5
|
attr_accessor :name_on_card, :number, :expiration, :security_code, :swipe, :track2,
|
5
|
-
:encrypted_track_1, :encrypted_track_2, :last_four, :encrypted, :swiped, :valid,
|
6
|
-
|
7
|
-
def self.from_swipe(swipe)
|
8
|
-
if swipe.class == Hash && swipe[:encrypted]
|
9
|
-
new(swipe)
|
10
|
-
else
|
11
|
-
new(swipe: swipe)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.from_manual(data)
|
16
|
-
new(data)
|
17
|
-
end
|
6
|
+
:encrypted_track_1, :encrypted_track_2, :last_four, :encrypted, :swiped, :valid,
|
7
|
+
:errors
|
18
8
|
|
19
9
|
def initialize(info)
|
20
10
|
@errors = {}
|
11
|
+
check_for_errors(info) unless info[:encrypted]
|
12
|
+
return unless valid?
|
21
13
|
if info[:encrypted]
|
22
|
-
|
14
|
+
from_encrypted(info)
|
23
15
|
elsif info[:swipe]
|
24
|
-
|
25
|
-
else
|
26
|
-
self.from_manual(info)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def from_encrypted (info)
|
31
|
-
@errors = {}
|
32
|
-
@encrypted = true
|
33
|
-
@encrypted_track_1 = info[:track_1]
|
34
|
-
@encrypted_track_2 = info[:track_2]
|
35
|
-
@last_four = info[:last_four]
|
36
|
-
end
|
37
|
-
|
38
|
-
def from_swipe(swipe_raw)
|
39
|
-
@errors = {}
|
40
|
-
if check_swipe(swipe_raw)
|
41
|
-
@valid = true
|
42
|
-
@swiped = true
|
43
|
-
@swipe = swipe_raw
|
44
|
-
@track2 = SwipeExtractor.get_track_2(swipe)
|
45
|
-
@number = SwipeExtractor.get_card_number(swipe)
|
46
|
-
@expiration = SwipeExtractor.get_expiration(swipe)
|
47
|
-
@name_on_card = SwipeExtractor.get_name(swipe)
|
48
|
-
@last_four = SwipeExtractor.get_last_four(@number)
|
16
|
+
from_unencrypted_swipe(info[:swipe])
|
49
17
|
else
|
50
|
-
|
18
|
+
from_manual(info)
|
51
19
|
end
|
52
20
|
end
|
53
21
|
|
54
|
-
def
|
55
|
-
@errors =
|
56
|
-
if info[:number] && check_luhn(info[:number].to_s.gsub(/\s+/, ""))
|
57
|
-
@name_on_card = info[:name_on_card] if info[:name_on_card]
|
58
|
-
@number = info[:number].to_s.gsub(/\s+/, "")
|
59
|
-
@expiration = info[:expiration].to_s if info[:expiration]
|
60
|
-
@security_code = info[:security_code].to_s if info[:security_code]
|
61
|
-
@track2 = info[:track_2] if info[:track_2]
|
62
|
-
@last_four = SwipeExtractor.get_last_four(@number)
|
63
|
-
@valid = true
|
64
|
-
else
|
65
|
-
errors[5000] = "The Credit Card Number supplied in the authorization request appears to be invalid."
|
66
|
-
@valid = false
|
67
|
-
end
|
22
|
+
def check_for_errors info
|
23
|
+
@errors = VirtualMerchant::UserInput.new(info).errors
|
68
24
|
end
|
69
25
|
|
70
26
|
def encrypted?
|
@@ -76,57 +32,55 @@ module VirtualMerchant
|
|
76
32
|
end
|
77
33
|
|
78
34
|
def valid?
|
79
|
-
|
35
|
+
errors.count == 0
|
80
36
|
end
|
81
37
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
38
|
+
def blurred_number
|
39
|
+
begin
|
40
|
+
number = self.number.to_s
|
41
|
+
leng = number.length
|
42
|
+
n = number[0..1]
|
43
|
+
(leng-6).times {n+= "*"}
|
44
|
+
n += number[number.length-4..number.length]
|
45
|
+
n
|
46
|
+
rescue Exception => e
|
47
|
+
puts "-"
|
48
|
+
puts "Error in VirtualMerchant-Ruby Gem when trying to blur card number: #{e}."
|
49
|
+
puts "You either passed a nil value for card_number or a number that is too short."
|
50
|
+
puts caller
|
51
|
+
puts "-"
|
90
52
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def from_encrypted (info)
|
57
|
+
@encrypted = true
|
58
|
+
@encrypted_track_1 = info[:track_1]
|
59
|
+
@encrypted_track_2 = info[:track_2]
|
60
|
+
@last_four = info[:last_four]
|
95
61
|
end
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
return false
|
62
|
+
|
63
|
+
def from_unencrypted_swipe(swipe_raw)
|
64
|
+
build_card_from swipe_raw if valid?
|
100
65
|
end
|
101
|
-
return true
|
102
|
-
end
|
103
66
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
67
|
+
def build_card_from swipe
|
68
|
+
@swiped = true
|
69
|
+
@swipe = swipe
|
70
|
+
@track2 = SwipeExtractor.get_track_2(swipe)
|
71
|
+
@number = SwipeExtractor.get_card_number(swipe)
|
72
|
+
@expiration = SwipeExtractor.get_expiration(swipe)
|
73
|
+
@name_on_card = SwipeExtractor.get_name(swipe)
|
74
|
+
@last_four = SwipeExtractor.get_last_four(@number)
|
111
75
|
end
|
112
|
-
(s1 + s2) % 10 == 0
|
113
|
-
end
|
114
76
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
rescue Exception => e
|
124
|
-
puts "-"
|
125
|
-
puts "Error in VirtualMerchant-Ruby Gem when trying to blur card number: #{e}."
|
126
|
-
puts "You either passed a nil value for card_number or a number that is too short."
|
127
|
-
puts caller
|
128
|
-
puts "-"
|
129
|
-
end
|
130
|
-
end
|
77
|
+
def from_manual(info)
|
78
|
+
@name_on_card = info[:name_on_card] if info[:name_on_card]
|
79
|
+
@number = info[:number].to_s.gsub(/\s+/, "")
|
80
|
+
@expiration = info[:expiration].to_s if info[:expiration]
|
81
|
+
@security_code = info[:security_code].to_s if info[:security_code]
|
82
|
+
@track2 = info[:track_2] if info[:track_2]
|
83
|
+
@last_four = SwipeExtractor.get_last_four(@number)
|
84
|
+
end
|
131
85
|
end
|
132
86
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module VirtualMerchant
|
2
|
+
class UserInput
|
3
|
+
attr_accessor :errors
|
4
|
+
def initialize(user_input)
|
5
|
+
@errors = {}
|
6
|
+
if user_input[:swipe]
|
7
|
+
validate_unencrypted_swipe(user_input[:swipe])
|
8
|
+
else
|
9
|
+
validate_card_number(user_input[:number])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate_card_number(number)
|
14
|
+
unless number && luhn_validate(number.to_s.gsub(/\s+/, ""))
|
15
|
+
errors[5000] = "The Credit Card Number supplied in the authorization request appears to be invalid."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def luhn_validate(number)
|
21
|
+
s1 = s2 = 0
|
22
|
+
number.to_s.reverse.chars.each_slice(2) do |odd, even|
|
23
|
+
s1 += odd.to_i
|
24
|
+
double = even.to_i * 2
|
25
|
+
double -= 9 if double >= 10
|
26
|
+
s2 += double
|
27
|
+
end
|
28
|
+
(s1 + s2) % 10 == 0
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_unencrypted_swipe(swipe_raw)
|
32
|
+
if swipe_raw.index('%') == nil
|
33
|
+
@errors[5012] = "The track data sent appears to be invalid."
|
34
|
+
end
|
35
|
+
validate_track_1 swipe_raw
|
36
|
+
validate_track_2 swipe_raw
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate_track_1 swipe_raw
|
40
|
+
track1 = swipe_raw[1.. swipe_raw.index('?') - 1]
|
41
|
+
if track1 == nil || track1 == "E"
|
42
|
+
@errors[5012] = "The track data sent appears to be invalid."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_track_2 swipe_raw
|
47
|
+
unless swipe_raw.index(';')
|
48
|
+
return @errors[5013] = "Transaction requires Track2 data to be sent."
|
49
|
+
end
|
50
|
+
track2 = swipe_raw[(swipe_raw.index(';') + 1).. swipe_raw.length-2]
|
51
|
+
return unless track2 == nil || track2 == "E"
|
52
|
+
@errors[5013] = "Transaction requires track 2 data to be sent."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/virtual_merchant.rb
CHANGED
@@ -3,10 +3,10 @@ require 'virtual_merchant/amount'
|
|
3
3
|
require 'virtual_merchant/communication'
|
4
4
|
require 'virtual_merchant/credentials'
|
5
5
|
require 'virtual_merchant/credit_card'
|
6
|
-
require 'virtual_merchant/
|
6
|
+
require 'virtual_merchant/gateway'
|
7
7
|
require 'virtual_merchant/logger'
|
8
|
+
require 'virtual_merchant/response'
|
8
9
|
require 'virtual_merchant/xml_generator'
|
9
|
-
require 'virtual_merchant/gateway'
|
10
10
|
module VirtualMerchant
|
11
11
|
def self.charge(card, amount, creds, custom_fields={}, gateway=Gateway.new(creds))
|
12
12
|
gateway.ccsale(card, amount, custom_fields)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtual_merchant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Quarella
|
@@ -21,11 +21,12 @@ files:
|
|
21
21
|
- lib/virtual_merchant/communication.rb
|
22
22
|
- lib/virtual_merchant/credentials.rb
|
23
23
|
- lib/virtual_merchant/credit_card.rb
|
24
|
-
- lib/virtual_merchant/gateway.rb
|
25
24
|
- lib/virtual_merchant/logger.rb
|
26
25
|
- lib/virtual_merchant/response.rb
|
27
26
|
- lib/virtual_merchant/swipe_extractor.rb
|
27
|
+
- lib/virtual_merchant/user_input.rb
|
28
28
|
- lib/virtual_merchant/xml_generator.rb
|
29
|
+
- lib/virtual_merchant/gateway.rb
|
29
30
|
homepage: https://github.com/leequarella/VirtualMerchant-Ruby
|
30
31
|
licenses:
|
31
32
|
- MIT
|
@@ -36,17 +37,17 @@ require_paths:
|
|
36
37
|
- lib
|
37
38
|
required_ruby_version: !ruby/object:Gem::Requirement
|
38
39
|
requirements:
|
39
|
-
- -
|
40
|
+
- - '>='
|
40
41
|
- !ruby/object:Gem::Version
|
41
42
|
version: '0'
|
42
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
|
-
- -
|
45
|
+
- - '>='
|
45
46
|
- !ruby/object:Gem::Version
|
46
47
|
version: '0'
|
47
48
|
requirements: []
|
48
49
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.
|
50
|
+
rubygems_version: 2.1.10
|
50
51
|
signing_key:
|
51
52
|
specification_version: 4
|
52
53
|
summary: Virtual Merchant API
|