virtual_merchant 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/virtual_merchant/amount.rb +11 -9
- data/lib/virtual_merchant/credentials.rb +10 -8
- data/lib/virtual_merchant/credit_card.rb +75 -73
- data/lib/virtual_merchant/response.rb +22 -20
- data/lib/virtual_merchant.rb +6 -3
- metadata +1 -1
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module VirtualMerchant
|
2
|
+
class Amount
|
3
|
+
attr_accessor :total, :tax
|
4
|
+
|
5
|
+
def initialize(info)
|
6
|
+
@total = sprintf( "%0.02f", info[:total])
|
7
|
+
if info[:tax]
|
8
|
+
@tax = sprintf( "%0.02f", info[:tax])
|
9
|
+
else
|
10
|
+
@tax = "0.00"
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module VirtualMerchant
|
2
|
+
class Credentials
|
3
|
+
attr_accessor :account_id, :user_id, :pin, :referer, :demo
|
4
|
+
def initialize(info)
|
5
|
+
@account_id = info[:account_id].to_s
|
6
|
+
@user_id = info[:user_id].to_s
|
7
|
+
@pin = info[:pin].to_s
|
8
|
+
@referer = info[:referer].to_s
|
9
|
+
@demo = info[:demo] || false
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
@@ -1,80 +1,82 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
module VirtualMerchant
|
2
|
+
class CreditCard
|
3
|
+
attr_accessor :name_on_card, :number, :expiration, :security_code, :last_four,
|
4
|
+
:swipe, :track2
|
5
|
+
|
6
|
+
def initialize(info)
|
7
|
+
if info[:swipe]
|
8
|
+
@swipe = info[:swipe]
|
9
|
+
self.from_swipe(swipe)
|
10
|
+
else
|
11
|
+
@name_on_card = info[:name_on_card] if info[:name_on_card]
|
12
|
+
@number = info[:number].to_s.gsub(/\s+/, "") if info[:number]
|
13
|
+
@expiration = info[:expiration].to_s if info[:expiration]
|
14
|
+
@security_code = info[:security_code].to_s if info[:security_code]
|
15
|
+
@track2 = info[:track_2] if info[:track_2]
|
16
|
+
end
|
15
17
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
last_name_on_card = swipe[swipe.index('^')+1..swipe.index('/')-1]
|
42
|
-
else
|
43
|
-
if !swipe.index(" ")
|
44
|
-
first_name_on_card = "Gift"
|
45
|
-
last_name_on_card = "Card"
|
18
|
+
|
19
|
+
def from_swipe(swipe)
|
20
|
+
self.track2 = extract_track_2(swipe)
|
21
|
+
self.number = extract_card_number(swipe)
|
22
|
+
self.expiration = extract_expiration(swipe)
|
23
|
+
self.name_on_card = extract_name(swipe)
|
24
|
+
end
|
25
|
+
|
26
|
+
def extract_card_number(swipe)
|
27
|
+
card_number = swipe[2.. swipe.index('^')-1]
|
28
|
+
card_number = card_number.split(' ').join('')
|
29
|
+
end
|
30
|
+
|
31
|
+
def extract_expiration(swipe)
|
32
|
+
secondCarrot = swipe.index("^", swipe.index("^")+1)
|
33
|
+
card_expiration_year = swipe[secondCarrot+1..secondCarrot+2]
|
34
|
+
card_expiration_month = swipe[(secondCarrot + 3)..(secondCarrot + 4)]
|
35
|
+
card_expiration = card_expiration_month.to_s + card_expiration_year.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
def extract_name(swipe)
|
39
|
+
secondCarrot = swipe.index("^", swipe.index("^")+1)
|
40
|
+
if swipe.index('/')
|
41
|
+
first_name_on_card = swipe[swipe.index('/')+1..secondCarrot-1]
|
42
|
+
last_name_on_card = swipe[swipe.index('^')+1..swipe.index('/')-1]
|
46
43
|
else
|
47
|
-
|
48
|
-
|
44
|
+
if !swipe.index(" ")
|
45
|
+
first_name_on_card = "Gift"
|
46
|
+
last_name_on_card = "Card"
|
47
|
+
else
|
48
|
+
first_name_on_card = swipe.slice(swipe.index('^') + 1, swipe.index(' '))
|
49
|
+
last_name_on_card = swipe.slice(swipe.index(" ") + 1, secondCarrot)
|
50
|
+
end
|
49
51
|
end
|
52
|
+
name_on_card = first_name_on_card + " " + last_name_on_card
|
50
53
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
track2
|
54
|
+
|
55
|
+
def extract_track_2(swipe)
|
56
|
+
# Magtek reader: Track 2 starts with a semi-colon and goes to the end
|
57
|
+
# I think that is standard for all readers, but not positive. -LQ
|
58
|
+
track2 = swipe.slice(swipe.index(";"), swipe.length)
|
59
|
+
if track2.index("+")
|
60
|
+
# Some AMEX have extra stuff at the end of track 2 that causes
|
61
|
+
#virtual merchant to return an INVLD DATA5623 message.
|
62
|
+
#Soooo... let's slice that off
|
63
|
+
track2 = track2.slice(0, track2.index("+"))
|
64
|
+
end
|
65
|
+
track2
|
66
|
+
end
|
67
|
+
|
68
|
+
def last_four
|
69
|
+
self.number[(self.number.length - 4)..self.number.length]
|
63
70
|
end
|
64
|
-
track2
|
65
|
-
end
|
66
|
-
|
67
|
-
def last_four
|
68
|
-
self.number[(self.number.length - 4)..self.number.length]
|
69
|
-
end
|
70
|
-
|
71
|
-
def blurred_number
|
72
|
-
number = self.number.to_s
|
73
|
-
leng = number.length
|
74
|
-
n = number[0..1]
|
75
|
-
(leng-6).times {n+= "*"}
|
76
|
-
n += number[number.length-4..number.length]
|
77
|
-
n
|
78
|
-
end
|
79
71
|
|
72
|
+
def blurred_number
|
73
|
+
number = self.number.to_s
|
74
|
+
leng = number.length
|
75
|
+
n = number[0..1]
|
76
|
+
(leng-6).times {n+= "*"}
|
77
|
+
n += number[number.length-4..number.length]
|
78
|
+
n
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
80
82
|
end
|
@@ -1,23 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
module VirtualMerchant
|
2
|
+
class Response
|
3
|
+
attr_accessor :result_message, :result, :blurred_card_number, :exp_date, :approval_code,
|
4
|
+
:cvv2_response, :transaction_id, :transaction_time, :error, :approved
|
5
|
+
|
6
|
+
def initialize(info)
|
7
|
+
@result_message = info[:result_message]
|
8
|
+
if info[:error]
|
9
|
+
@result_type = "error"
|
10
|
+
@error = info[:error]
|
11
|
+
@approved = false
|
12
|
+
else
|
13
|
+
@approved = true
|
14
|
+
@result_type = "approval"
|
15
|
+
@result = info[:result]
|
16
|
+
@blurred_card_number = info[:blurred_card_number]
|
17
|
+
@exp_date = info[:exp_date]
|
18
|
+
@approval_code = info[:approval_code]
|
19
|
+
@cvv2_response = info[:cvv2_response]
|
20
|
+
@transaction_id = info[:transaction_id]
|
21
|
+
@transaction_time = info[:transaction_time]
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/virtual_merchant.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
module VirtualMerchant
|
2
2
|
require "rexml/document"
|
3
3
|
require 'net/http'
|
4
4
|
require 'virtual_merchant/amount'
|
@@ -97,12 +97,12 @@ class VirtualMerchant
|
|
97
97
|
REXML::XPath.each(doc, "txn") do |xml|
|
98
98
|
if xml.elements["errorCode"]
|
99
99
|
#Something was wrong with the transaction so an errorCode and errorMessage were sent back
|
100
|
-
response =
|
100
|
+
response = VirtualMerchant::Response.new(
|
101
101
|
error: xml.elements["errorCode"].text,
|
102
102
|
result_message: xml.elements["errorMessage"].text)
|
103
103
|
else
|
104
104
|
#a clean transaction has taken place
|
105
|
-
response =
|
105
|
+
response = VirtualMerchant::Response.new(
|
106
106
|
result_message: xml.elements["ssl_result_message"].text,
|
107
107
|
result: xml.elements["ssl_result"].text,
|
108
108
|
blurred_card_number: xml.elements["ssl_card_number"].text,
|
@@ -113,6 +113,9 @@ class VirtualMerchant
|
|
113
113
|
transaction_time: xml.elements["ssl_txn_time"].text)
|
114
114
|
end
|
115
115
|
end
|
116
|
+
puts "<<<<<<<<<<<<<<<<<<<<<<"
|
117
|
+
puts response
|
118
|
+
puts "<<<<<<<<<<<<<<<<<<<<<<"
|
116
119
|
response
|
117
120
|
end
|
118
121
|
|