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.
@@ -1,12 +1,14 @@
1
- class VMAmount
2
- attr_accessor :total, :tax
3
-
4
- def initialize(info)
5
- @total = sprintf( "%0.02f", info[:total])
6
- if info[:tax]
7
- @tax = sprintf( "%0.02f", info[:tax])
8
- else
9
- @tax = "0.00"
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
- class VMCredentials
2
- attr_accessor :account_id, :user_id, :pin, :referer, :demo
3
- def initialize(info)
4
- @account_id = info[:account_id].to_s
5
- @user_id = info[:user_id].to_s
6
- @pin = info[:pin].to_s
7
- @referer = info[:referer].to_s
8
- @demo = info[:demo] || false
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
- class VMCreditCard
2
- attr_accessor :name_on_card, :number, :expiration, :security_code, :last_four,
3
- :swipe, :track2
4
-
5
- def initialize(info)
6
- if info[:swipe]
7
- @swipe = info[:swipe]
8
- self.from_swipe(swipe)
9
- else
10
- @name_on_card = info[:name_on_card] if info[:name_on_card]
11
- @number = info[:number].to_s.gsub(/\s+/, "") if info[:number]
12
- @expiration = info[:expiration].to_s if info[:expiration]
13
- @security_code = info[:security_code].to_s if info[:security_code]
14
- @track2 = info[:track_2] if info[:track_2]
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
- end
17
-
18
- def from_swipe(swipe)
19
- self.track2 = extract_track_2(swipe)
20
- self.number = extract_card_number(swipe)
21
- self.expiration = extract_expiration(swipe)
22
- self.name_on_card = extract_name(swipe)
23
- end
24
-
25
- def extract_card_number(swipe)
26
- card_number = swipe[2.. swipe.index('^')-1]
27
- card_number = card_number.split(' ').join('')
28
- end
29
-
30
- def extract_expiration(swipe)
31
- secondCarrot = swipe.index("^", swipe.index("^")+1)
32
- card_expiration_year = swipe[secondCarrot+1..secondCarrot+2]
33
- card_expiration_month = swipe[(secondCarrot + 3)..(secondCarrot + 4)]
34
- card_expiration = card_expiration_month.to_s + card_expiration_year.to_s
35
- end
36
-
37
- def extract_name(swipe)
38
- secondCarrot = swipe.index("^", swipe.index("^")+1)
39
- if swipe.index('/')
40
- first_name_on_card = swipe[swipe.index('/')+1..secondCarrot-1]
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
- first_name_on_card = swipe.slice(swipe.index('^') + 1, swipe.index(' '))
48
- last_name_on_card = swipe.slice(swipe.index(" ") + 1, secondCarrot)
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
- name_on_card = first_name_on_card + " " + last_name_on_card
52
- end
53
-
54
- def extract_track_2(swipe)
55
- # Magtek reader: Track 2 starts with a semi-colon and goes to the end
56
- # I think that is standard for all readers, but not positive. -LQ
57
- track2 = swipe.slice(swipe.index(";"), swipe.length)
58
- if track2.index("+")
59
- # Some AMEX have extra stuff at the end of track 2 that causes
60
- #virtual merchant to return an INVLD DATA5623 message.
61
- #Soooo... let's slice that off
62
- track2 = track2.slice(0, track2.index("+"))
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
- class VMResponse
2
- attr_accessor :result_message, :result, :blurred_card_number, :exp_date, :approval_code,
3
- :cvv2_response, :transaction_id, :transaction_time, :error, :approved
4
-
5
- def initialize(info)
6
- @result_message = info[:result_message]
7
- if info[:error]
8
- @result_type = "error"
9
- @error = info[:error]
10
- @approved = false
11
- else
12
- @approved = true
13
- @result_type = "approval"
14
- @result = info[:result]
15
- @blurred_card_number = info[:blurred_card_number]
16
- @exp_date = info[:exp_date]
17
- @approval_code = info[:approval_code]
18
- @cvv2_response = info[:cvv2_response]
19
- @transaction_id = info[:transaction_id]
20
- @transaction_time = info[:transaction_time]
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
@@ -1,4 +1,4 @@
1
- class VirtualMerchant
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 = VMResponse.new(
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 = VMResponse.new(
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
 
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.0.10
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: