virtual_merchant 0.1.3 → 0.2.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 +15 -0
- data/lib/virtual_merchant/communication.rb +4 -4
- data/lib/virtual_merchant/credit_card.rb +13 -5
- data/lib/virtual_merchant/gateway.rb +31 -0
- data/lib/virtual_merchant/response.rb +6 -3
- data/lib/virtual_merchant/xml_generator.rb +3 -3
- data/lib/virtual_merchant.rb +19 -24
- metadata +5 -6
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZWRkYmEzZDFhMTBlZmIzNjgyMzYxZGYwYTIxYTJlNzU3MWQ3YjJmOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2ZjYzllMDY5OTYxZWU2NzIwMDE0NjUzNDFiNGFiNzgzODdlMjA4Nw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTFiZTM4NWFjODQ1MTlkNzE1ZWM5ZWYyZmM1YzUwZTRiMmJmMjFmZmYwMTBh
|
10
|
+
MmM0YjU2OGM2YzExOTVjMWE2Y2ZiOWQ1OGMyNjU3M2Q2YTc0YmQyMzBiZjRh
|
11
|
+
MzZkYjE4ODdiZWZlYjhiMjlkNmM3MDc5N2NmYTRmYzkwZDc5MTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZGZkMjE2NTRhNWE0NWFiMzAzMTg4YWMxNjkyY2UxNGQyZWE0ZWU0ZjcwMmI2
|
14
|
+
MDU1MDMzNmMwYzYzYzRhMjdmZDA3ZjA4NzYzNjNmYWEwNDU1NzgwMzIzODA5
|
15
|
+
MmM3YjA5YWU1NDBlOWFhMzJiMDYxNjg3MWE0MDZhYzBkOTllZjk=
|
@@ -2,16 +2,16 @@ module VirtualMerchant
|
|
2
2
|
class Communication
|
3
3
|
require 'net/http'
|
4
4
|
require "rexml/document"
|
5
|
-
|
5
|
+
|
6
6
|
attr_accessor :xml, :url, :http_referer, :uri
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(data)
|
9
9
|
@xml = data[:xml]
|
10
10
|
@url = data[:url]
|
11
11
|
@uri = URI.parse(@url)
|
12
12
|
@http_referer = data[:http_referer]
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def send
|
16
16
|
http = Net::HTTP.new(@uri.host, @uri.port)
|
17
17
|
http.use_ssl = true
|
@@ -22,7 +22,7 @@ module VirtualMerchant
|
|
22
22
|
false
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
private
|
27
27
|
def header
|
28
28
|
if @http_referer
|
@@ -1,8 +1,16 @@
|
|
1
1
|
module VirtualMerchant
|
2
2
|
class CreditCard
|
3
|
-
attr_accessor :name_on_card, :number, :expiration, :security_code, :last_four,
|
3
|
+
attr_accessor :name_on_card, :number, :expiration, :security_code, :last_four,
|
4
4
|
:swipe, :track2
|
5
|
-
|
5
|
+
|
6
|
+
def self.from_swipe(swipe)
|
7
|
+
new(swipe: swipe)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.from_manual(data)
|
11
|
+
new(data)
|
12
|
+
end
|
13
|
+
|
6
14
|
def initialize(info)
|
7
15
|
if info[:swipe]
|
8
16
|
@swipe = info[:swipe]
|
@@ -15,19 +23,19 @@ module VirtualMerchant
|
|
15
23
|
@track2 = info[:track_2] if info[:track_2]
|
16
24
|
end
|
17
25
|
end
|
18
|
-
|
26
|
+
|
19
27
|
def from_swipe(swipe)
|
20
28
|
self.track2 = extract_track_2(swipe)
|
21
29
|
self.number = extract_card_number(swipe)
|
22
30
|
self.expiration = extract_expiration(swipe)
|
23
31
|
self.name_on_card = extract_name(swipe)
|
24
32
|
end
|
25
|
-
|
33
|
+
|
26
34
|
def extract_card_number(swipe)
|
27
35
|
card_number = swipe[2.. swipe.index('^')-1]
|
28
36
|
card_number = card_number.split(' ').join('')
|
29
37
|
end
|
30
|
-
|
38
|
+
|
31
39
|
def extract_expiration(swipe)
|
32
40
|
secondCarrot = swipe.index("^", swipe.index("^")+1)
|
33
41
|
card_expiration_year = swipe[secondCarrot+1..secondCarrot+2]
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "pp"
|
2
|
+
class Gateway
|
3
|
+
attr_reader :creds
|
4
|
+
|
5
|
+
def initialize(creds)
|
6
|
+
@creds = creds
|
7
|
+
end
|
8
|
+
|
9
|
+
def ccsale(card, amount)
|
10
|
+
xml = VirtualMerchant::XMLGenerator.generate(card, amount, creds, "ccsale")
|
11
|
+
process(xml, amount)
|
12
|
+
end
|
13
|
+
|
14
|
+
def process(xml, amount=0)
|
15
|
+
communication = VirtualMerchant::Communication.new(
|
16
|
+
{xml: xml, url: url(creds.demo), referer: creds.referer})
|
17
|
+
vm_response = communication.send
|
18
|
+
response = VirtualMerchant::Response.new(vm_response)
|
19
|
+
VirtualMerchant::Logger.new(response)
|
20
|
+
response
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def url(demo)
|
25
|
+
if demo
|
26
|
+
'https://demo.myvirtualmerchant.com/VirtualMerchantDemo/processxml.do'
|
27
|
+
else
|
28
|
+
'https://www.myvirtualmerchant.com/VirtualMerchant/processxml.do'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -5,6 +5,8 @@ module VirtualMerchant
|
|
5
5
|
:approval_code, :cvv2_response, :transaction_id, :transaction_time, :error,
|
6
6
|
:approved
|
7
7
|
|
8
|
+
alias_method :approved?, :approved
|
9
|
+
|
8
10
|
def initialize(xml_string)
|
9
11
|
if xml_string == false
|
10
12
|
error_response("-1", "VirtualMerchant did not respond.")
|
@@ -13,12 +15,13 @@ module VirtualMerchant
|
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
18
|
+
|
16
19
|
private
|
17
|
-
def decode_xml(xml_string)
|
20
|
+
def decode_xml(xml_string)
|
18
21
|
doc = REXML::Document.new(xml_string)
|
19
22
|
REXML::XPath.each(doc, "txn") do |xml|
|
20
|
-
if xml.elements["errorCode"]
|
21
|
-
#Something was wrong with the transaction so an
|
23
|
+
if xml.elements["errorCode"]
|
24
|
+
#Something was wrong with the transaction so an
|
22
25
|
#errorCode and errorMessage were sent back
|
23
26
|
error_response(
|
24
27
|
xml.elements["errorCode"].text, xml.elements["errorMessage"].text)
|
@@ -10,7 +10,7 @@ module VirtualMerchant
|
|
10
10
|
</txn>"
|
11
11
|
return xml
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def self.generate(card, amount, creds, transaction_type)
|
15
15
|
xml = "xmldata=<txn>
|
16
16
|
<ssl_merchant_id>" + creds.account_id + "</ssl_merchant_id>
|
@@ -29,14 +29,14 @@ module VirtualMerchant
|
|
29
29
|
xml += "<ssl_card_number>" + card.number.to_s + "</ssl_card_number>
|
30
30
|
<ssl_exp_date>" + card.expiration + "</ssl_exp_date>"
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
if !card.security_code || card.security_code == ""
|
34
34
|
xml += "<ssl_cvv2cvc2_indicator>0</ssl_cvv2cvc2_indicator>"
|
35
35
|
else
|
36
36
|
xml += "<ssl_cvv2cvc2_indicator>1</ssl_cvv2cvc2_indicator>
|
37
37
|
<ssl_cvv2cvc2>" + card.security_code + "</ssl_cvv2cvc2>"
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
xml += "</txn>"
|
41
41
|
return xml
|
42
42
|
end
|
data/lib/virtual_merchant.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
+
require "rexml/document"
|
2
|
+
require 'virtual_merchant/amount'
|
3
|
+
require 'virtual_merchant/communication'
|
4
|
+
require 'virtual_merchant/credentials'
|
5
|
+
require 'virtual_merchant/credit_card'
|
6
|
+
require 'virtual_merchant/response'
|
7
|
+
require 'virtual_merchant/logger'
|
8
|
+
require 'virtual_merchant/xml_generator'
|
9
|
+
require 'virtual_merchant/gateway'
|
1
10
|
module VirtualMerchant
|
2
|
-
require "rexml/document"
|
3
|
-
require 'virtual_merchant/amount'
|
4
|
-
require 'virtual_merchant/communication'
|
5
|
-
require 'virtual_merchant/credentials'
|
6
|
-
require 'virtual_merchant/credit_card'
|
7
|
-
require 'virtual_merchant/response'
|
8
|
-
require 'virtual_merchant/logger'
|
9
|
-
require 'virtual_merchant/xml_generator'
|
10
11
|
|
11
|
-
def self.charge(card, amount, creds)
|
12
|
-
|
13
|
-
|
12
|
+
def self.charge(card, amount, creds, gateway=Gateway.new(creds))
|
13
|
+
gateway.ccsale(card, amount)
|
14
|
+
#xml = VirtualMerchant::XMLGenerator.generate(card, amount, creds, "ccsale")
|
14
15
|
end
|
15
16
|
|
16
17
|
def self.refund(card, amount, creds)
|
@@ -25,19 +26,13 @@ module VirtualMerchant
|
|
25
26
|
|
26
27
|
private
|
27
28
|
def self.process(xml, creds, amount=0)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
VirtualMerchant::
|
33
|
-
response
|
29
|
+
Gateway.new(creds).process(xml, amount=0)
|
30
|
+
#communication = VirtualMerchant::Communication.new(
|
31
|
+
# {xml: xml, url: self.url(creds.demo), referer: creds.referer})
|
32
|
+
#vm_response = communication.send
|
33
|
+
#response = VirtualMerchant::Response.new(vm_response)
|
34
|
+
#VirtualMerchant::Logger.new(response)
|
35
|
+
#response
|
34
36
|
end
|
35
37
|
|
36
|
-
def self.url(demo)
|
37
|
-
if demo
|
38
|
-
'https://demo.myvirtualmerchant.com/VirtualMerchantDemo/processxml.do'
|
39
|
-
else
|
40
|
-
'https://www.myvirtualmerchant.com/VirtualMerchant/processxml.do'
|
41
|
-
end
|
42
|
-
end
|
43
38
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtual_merchant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Lee Quarella
|
@@ -25,28 +24,28 @@ files:
|
|
25
24
|
- lib/virtual_merchant/logger.rb
|
26
25
|
- lib/virtual_merchant/response.rb
|
27
26
|
- lib/virtual_merchant/xml_generator.rb
|
27
|
+
- lib/virtual_merchant/gateway.rb
|
28
28
|
homepage: https://github.com/leequarella/VirtualMerchant-Ruby
|
29
29
|
licenses: []
|
30
|
+
metadata: {}
|
30
31
|
post_install_message:
|
31
32
|
rdoc_options: []
|
32
33
|
require_paths:
|
33
34
|
- lib
|
34
35
|
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
36
|
requirements:
|
37
37
|
- - ! '>='
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
41
|
requirements:
|
43
42
|
- - ! '>='
|
44
43
|
- !ruby/object:Gem::Version
|
45
44
|
version: '0'
|
46
45
|
requirements: []
|
47
46
|
rubyforge_project:
|
48
|
-
rubygems_version:
|
47
|
+
rubygems_version: 2.0.3
|
49
48
|
signing_key:
|
50
|
-
specification_version:
|
49
|
+
specification_version: 4
|
51
50
|
summary: Virtual Merchant API
|
52
51
|
test_files: []
|