jumio_rock 0.0.1
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +12 -0
- data/jumio_rock.gemspec +27 -0
- data/lib/jumio_rock.rb +16 -0
- data/lib/jumio_rock/client.rb +114 -0
- data/lib/jumio_rock/configuration.rb +24 -0
- data/lib/jumio_rock/embed_netverify_params.rb +18 -0
- data/lib/jumio_rock/multi_document_netverify_params.rb +18 -0
- data/lib/jumio_rock/netverify_params.rb +33 -0
- data/lib/jumio_rock/perform_netverify_params.rb +33 -0
- data/lib/jumio_rock/post_parser.rb +20 -0
- data/lib/jumio_rock/redirect_netverify_params.rb +14 -0
- data/lib/jumio_rock/version.rb +3 -0
- data/test/example.rb +33 -0
- data/test/lib/jumio_rock/jumio_rock_test.rb +72 -0
- data/test/lib/jumio_rock/perform_netverify_params_test.rb +28 -0
- data/test/lib/jumio_rock/version_test.rb +9 -0
- data/test/minitest_helper.rb +133 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79f167bbb44aee514fdc352519cdaa2104a68157
|
4
|
+
data.tar.gz: 95cdacf2f400d87f714322c18b4f1e6ffb76a9cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be228cb58c13c0a6bca0d506cec1992239b1b3afbc2fb925d9c734a4d036b22d74f7614f65b075a3bef3ccaf06d5e0662a54a35b76f658977e619484c2c79904
|
7
|
+
data.tar.gz: f4061e823bc6f21ee686ac379ba45b00781602d7b65452b080907487d75bde373a2b0c741c06a4362dced2be012687d27bb49d17a491182d622a2daa1e248668
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Michele Minazzato
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# JumioRock
|
2
|
+
|
3
|
+
Unofficial Jumio Netverify implementation
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'jumio_rock'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install jumio_rock
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Config
|
22
|
+
|
23
|
+
JumioRock::Configuration.configure do |config|
|
24
|
+
config.api_token = "1e1789e9-5687-451a-9e4c-30d3434ad0a9"
|
25
|
+
config.api_secret = "0zHY1OSefp4qhk5zol9qoQ5t3UqkrOhn"
|
26
|
+
end
|
27
|
+
|
28
|
+
### Embed in Iframe
|
29
|
+
@client = JumioRock::Client.new
|
30
|
+
response = @client.init_embed(scan_reference, success_url, error_url, options = {})
|
31
|
+
|
32
|
+
### Embed in Iframe not ID document
|
33
|
+
|
34
|
+
@client = JumioRock::Client.new
|
35
|
+
response = @client.init_multidocument(document_type, merchant_scan_reference, customer_id, success_url, error_url, options = {})
|
36
|
+
|
37
|
+
### Redirect to Jumio platform
|
38
|
+
|
39
|
+
@client = JumioRock::Client.new
|
40
|
+
response = @client.init_redirect(scan_reference, customer_id, options = {})
|
41
|
+
redirect_to response.clientRedirectUrl
|
42
|
+
|
43
|
+
### API
|
44
|
+
client = JumioRock::Client.new
|
45
|
+
response = client.call_api(scan_reference, front_side_image_path, options = {})
|
46
|
+
|
47
|
+
### In your view
|
48
|
+
|
49
|
+
After embed or multidocument initilization in your controller
|
50
|
+
|
51
|
+
<%= raw @client.iframe %>
|
data/Rakefile
ADDED
data/jumio_rock.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jumio_rock/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jumio_rock"
|
8
|
+
spec.version = JumioRock::VERSION
|
9
|
+
spec.authors = ["Michele Minazzato"]
|
10
|
+
spec.email = ["michelemina@gmail.com"]
|
11
|
+
spec.summary = "Unofficial Jumio API implementation"
|
12
|
+
spec.description = ""
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "excon"
|
22
|
+
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "chunky_png"
|
26
|
+
spec.add_development_dependency "webmock"
|
27
|
+
end
|
data/lib/jumio_rock.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "jumio_rock/version"
|
2
|
+
require "jumio_rock/configuration"
|
3
|
+
require "jumio_rock/netverify_params"
|
4
|
+
require "jumio_rock/perform_netverify_params"
|
5
|
+
require "jumio_rock/embed_netverify_params"
|
6
|
+
require "jumio_rock/multi_document_netverify_params"
|
7
|
+
require "jumio_rock/redirect_netverify_params"
|
8
|
+
require "jumio_rock/client"
|
9
|
+
require "jumio_rock/post_parser"
|
10
|
+
|
11
|
+
require 'excon'
|
12
|
+
require "base64"
|
13
|
+
|
14
|
+
module JumioRock
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module JumioRock
|
2
|
+
class Client
|
3
|
+
attr_reader :authorization_token
|
4
|
+
attr_accessor :api_url, :init_embed_url, :init_redirect_url, :multi_document_url
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@api_url = conf.api_url
|
8
|
+
@init_embed_url = conf.init_embed_url
|
9
|
+
@init_redirect_url = conf.init_redirect_url
|
10
|
+
@multi_document_url = conf.multi_document_url
|
11
|
+
@initialization_type = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def call_api(scan_reference, front_side_image_path, options = {})
|
15
|
+
body = PerformNetverifyParams.new(scan_reference, front_side_image_path)
|
16
|
+
body = set_options body, options
|
17
|
+
post(api_url, body.to_json)
|
18
|
+
end
|
19
|
+
|
20
|
+
def init_embed(scan_reference, success_url, error_url, options = {})
|
21
|
+
@initialization_type = :embed
|
22
|
+
body = EmbedNetverifyParams.new(scan_reference, success_url, error_url)
|
23
|
+
body = set_options body, options
|
24
|
+
response = post(init_embed_url, body.to_json)
|
25
|
+
@authorization_token = response.authorizationToken
|
26
|
+
response
|
27
|
+
end
|
28
|
+
|
29
|
+
def init_redirect(scan_reference, customer_id, options = {})
|
30
|
+
@initialization_type = :redirect
|
31
|
+
body = RedirectNetverifyParams.new(scan_reference, customer_id)
|
32
|
+
body = set_options body, options
|
33
|
+
post(init_redirect_url, body.to_json)
|
34
|
+
end
|
35
|
+
|
36
|
+
def init_multidocument(document_type, merchant_scan_reference, customer_id, success_url, error_url, options = {})
|
37
|
+
@initialization_type = :multi
|
38
|
+
body = MultiDocumentNetverifyParams.new(document_type, merchant_scan_reference, customer_id, success_url, error_url)
|
39
|
+
body = set_options body, options
|
40
|
+
response = post(multi_document_url, body.to_json)
|
41
|
+
@authorization_token = response.authorizationToken
|
42
|
+
response
|
43
|
+
end
|
44
|
+
|
45
|
+
def iframe(locale = "en")
|
46
|
+
iframe_html(locale, js_type)
|
47
|
+
end
|
48
|
+
|
49
|
+
def iframe_html(locale = "en", type = "initVerify")
|
50
|
+
<<-TEXT
|
51
|
+
#{self.class.jumio_js}
|
52
|
+
<script type="text/javascript">
|
53
|
+
/*<![CDATA[*/
|
54
|
+
#{js_request(locale, type)}
|
55
|
+
/*]]>*/
|
56
|
+
</script>
|
57
|
+
TEXT
|
58
|
+
end
|
59
|
+
|
60
|
+
def js(locale = "en")
|
61
|
+
js_request(locale, js_type)
|
62
|
+
end
|
63
|
+
|
64
|
+
def js_request(locale, type)
|
65
|
+
<<-TEXT
|
66
|
+
JumioClient.setVars({
|
67
|
+
authorizationToken: \"#{authorization_token}\",
|
68
|
+
locale: \"#{locale}\"
|
69
|
+
}).#{type}(\"JUMIOIFRAME\");
|
70
|
+
TEXT
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.jumio_js
|
74
|
+
'<script type="text/javascript" src="https://netverify.com/widget/jumio-verify/2.0/iframe-script.js"> </script>'
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def js_type
|
80
|
+
raise "Client not initialized (init_embed or init_multidocument)" unless @initialization_type
|
81
|
+
@initialization_type == :multi ? "initMDM" : "initVerify"
|
82
|
+
end
|
83
|
+
|
84
|
+
def set_options(body, options)
|
85
|
+
options.each do |k, v|
|
86
|
+
body.send("#{k}=", v)
|
87
|
+
end
|
88
|
+
body
|
89
|
+
end
|
90
|
+
|
91
|
+
def post(url, body)
|
92
|
+
connection = Excon.new(url, :user => conf.api_token, :password => conf.api_secret)
|
93
|
+
response = connection.request(
|
94
|
+
method: 'POST',
|
95
|
+
headers: headers,
|
96
|
+
body: body
|
97
|
+
)
|
98
|
+
OpenStruct.new JSON.parse(response.body)
|
99
|
+
end
|
100
|
+
|
101
|
+
def conf
|
102
|
+
Configuration.configuration
|
103
|
+
end
|
104
|
+
|
105
|
+
def headers
|
106
|
+
{
|
107
|
+
'Accept' => 'application/json',
|
108
|
+
'Content-Type' => 'application/json',
|
109
|
+
'User-Agent' => "#{conf.company_name} #{conf.app_name}/#{conf.version}"
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module JumioRock
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :app_name, :company_name, :version, :api_url, :api_token, :api_secret, :init_redirect_url, :init_embed_url, :multi_document_url
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.company_name = 'YOURCOMPANYNAME'
|
7
|
+
self.app_name = 'YOURAPPLICATIONNAME'
|
8
|
+
self.version = VERSION
|
9
|
+
self.api_url = "https://netverify.com/api/netverify/v2/performNetverify"
|
10
|
+
self.init_redirect_url = "https://netverify.com/api/netverify/v2/initiateNetverifyRedirect"
|
11
|
+
self.init_embed_url = "https://netverify.com/api/netverify/v2/initiateNetverify"
|
12
|
+
self.multi_document_url = "https://netverify.com/api/netverify/v2/createDocumentAcquisition"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configuration
|
16
|
+
@configuration ||= Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure
|
20
|
+
yield(configuration) if block_given?
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module JumioRock
|
2
|
+
|
3
|
+
class EmbedNetverifyParams < NetverifyParams
|
4
|
+
|
5
|
+
attr_reader :merchantIdScanReference, :successUrl, :errorUrl
|
6
|
+
attr_accessor :enabledFields, :authorizationTokenLifetime, :merchantReportingCriteria,
|
7
|
+
:callbackUrl, :locale, :clientIp, :customerId, :firstName, :lastName, :country,
|
8
|
+
:usState, :expiry, :number, :dob, :idType, :personalNumber, :mrzCheck, :additionalInformation
|
9
|
+
|
10
|
+
def initialize(scan_reference, success_url, error_url)
|
11
|
+
@merchantIdScanReference = scan_reference
|
12
|
+
@successUrl = success_url
|
13
|
+
@errorUrl = error_url
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module JumioRock
|
2
|
+
|
3
|
+
class MultiDocumentNetverifyParams < NetverifyParams
|
4
|
+
|
5
|
+
attr_reader :documentType, :merchantScanReference, :customerID, :successUrl, :errorUrl
|
6
|
+
attr_accessor :authorizationTokenLifetime, :merchantReportingCriteria, :callbackUrl, :clientIp
|
7
|
+
|
8
|
+
def initialize(document_type, merchant_scan_reference, customer_id, success_url, error_url)
|
9
|
+
@documentType = document_type
|
10
|
+
@merchantScanReference = merchant_scan_reference
|
11
|
+
@customerID = customer_id
|
12
|
+
@successUrl = success_url
|
13
|
+
@errorUrl = error_url
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module JumioRock
|
4
|
+
|
5
|
+
class NetverifyParams
|
6
|
+
|
7
|
+
def to_json
|
8
|
+
JSON.generate(params)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def params
|
14
|
+
data = {}
|
15
|
+
self.instance_variables.each do |v|
|
16
|
+
name = v.to_s.sub('@', '')
|
17
|
+
data[name] = self.send(name)
|
18
|
+
end
|
19
|
+
check_mandatory(data)
|
20
|
+
data
|
21
|
+
end
|
22
|
+
|
23
|
+
# attr_reader instance variables must be set
|
24
|
+
def check_mandatory(data)
|
25
|
+
required_params = self.instance_variables.select{|v| !respond_to?("#{v.to_s.gsub('@','')}=")}
|
26
|
+
required_params.each do |r|
|
27
|
+
name = r.to_s.sub('@', '')
|
28
|
+
raise "#{name} is a required param" unless data[name]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module JumioRock
|
2
|
+
|
3
|
+
class PerformNetverifyParams < NetverifyParams
|
4
|
+
|
5
|
+
IMAGE_MAX_SIZE = 5 *1024 *1014
|
6
|
+
|
7
|
+
attr_accessor :callbackUrl
|
8
|
+
attr_reader :merchantIdScanReference, :frontsideImage
|
9
|
+
|
10
|
+
def initialize(scan_reference, front_side_image_path)
|
11
|
+
@merchantIdScanReference = scan_reference
|
12
|
+
encode_image front_side_image_path
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def encode_image(path)
|
18
|
+
file = File.read(path)
|
19
|
+
encode(file)
|
20
|
+
end
|
21
|
+
|
22
|
+
def encode(str)
|
23
|
+
image_base64 = Base64.encode64(str)
|
24
|
+
raise "image max size 5MB" unless check_image_size(image_base64.bytesize())
|
25
|
+
@frontsideImage = image_base64.gsub(/\n/, "")
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_image_size(bytesize)
|
29
|
+
bytesize < IMAGE_MAX_SIZE
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module JumioRock
|
2
|
+
class PostParser
|
3
|
+
attr_reader :params
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
@params = params
|
7
|
+
# @params.keys.each do |method|
|
8
|
+
# self.class.send(:define_method, method) do
|
9
|
+
# return @params[method] if @params.has_key?(method)
|
10
|
+
# nil
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
end
|
14
|
+
|
15
|
+
def status
|
16
|
+
(@params[:callBackType] == "NETVERIFYID") ? @params[:verificationStatus] : params[:documentStatus]
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module JumioRock
|
2
|
+
|
3
|
+
class RedirectNetverifyParams < NetverifyParams
|
4
|
+
|
5
|
+
attr_reader :merchantIdScanReference, :customerId
|
6
|
+
|
7
|
+
def initialize(scan_reference, customer_id)
|
8
|
+
@merchantIdScanReference = scan_reference
|
9
|
+
@customerId = customer_id
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/test/example.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
JumioRock::Configuration.configure do |config|
|
2
|
+
config.api_token = "1e1789e9-5687-451a-9e4c-30d3434ad0a9"
|
3
|
+
config.api_secret = "0zHY1OSefp4qhk5zol9qoQ5t3UqkrOhn"
|
4
|
+
config.url = "https://netverify.com/api/netverify/v2/performNetverify"
|
5
|
+
#config.url = "http://95.240.235.90/"
|
6
|
+
end
|
7
|
+
|
8
|
+
pnp = JumioRock::PerformNetverifyParams.new("api_test_dr","/home/mina/mina_driver_license.jpg")
|
9
|
+
pnp.callbackUrl = "https://95.240.235.90/"
|
10
|
+
|
11
|
+
gateway = JumioRock::Client.new
|
12
|
+
response = client.call pnp.to_json
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"frontsideImage":"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAgMAAABinRfyAAAACVBMVEUAAAAAAAAKFB5aVYYgAAAAA3RSTlMAgIAsTd", "merchantIdScanReference":"fake_with_curl"}' https://1e1789e9-5687-451a-9e4c-30d3434ad0a9:0zHY1OSefp4qhk5zol9qoQ5t3UqkrOhn@netverify.com/api/netverify/v2/performNetverify
|
17
|
+
curl -v -H "Accept: application/json" -H "Content-type: application/json" https://1e1789e9-5687-451a-9e4c-30d3434ad0a9:0zHY1OSefp4qhk5zol9qoQ5t3UqkrOhn@netverify.com/api/netverify/v2/supportedDocumentTypes
|
18
|
+
|
19
|
+
#connection = Excon.new("https://1e1789e9-5687-451a-9e4c-30d3434ad0a9:0zHY1OSefp4qhk5zol9qoQ5t3UqkrOhn@netverify.com/api/netverify/v2/performNetverify")
|
20
|
+
connection = Excon.new("https://netverify.com/api/netverify/v2/initiateNetverify", :user => "1e1789e9-5687-451a-9e4c-30d3434ad0a9", :password => "0zHY1OSefp4qhk5zol9qoQ5t3UqkrOhn")
|
21
|
+
response = connection.request(
|
22
|
+
method: 'POST',
|
23
|
+
headers: {
|
24
|
+
'Accept' => 'application/json',
|
25
|
+
'Content-Type' => 'application/json',
|
26
|
+
'User-Agent' => "COMPANYNAME APPNAME/0.0.1"
|
27
|
+
},
|
28
|
+
body: {
|
29
|
+
merchantIdScanReference: "YOURSCANREFERENCE",
|
30
|
+
successUrl: "https://www.your-site.com/sucess",
|
31
|
+
errorUrl: "https://www.your-site.com/error"
|
32
|
+
}
|
33
|
+
)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative '../../minitest_helper'
|
2
|
+
|
3
|
+
describe JumioRock::Client do
|
4
|
+
before :once do
|
5
|
+
JumioRock::Configuration.configure do |config|
|
6
|
+
config.api_token = "username"
|
7
|
+
config.api_secret = "password"
|
8
|
+
end
|
9
|
+
@path = create_test_image
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should post image using api" do
|
13
|
+
stub_api_request
|
14
|
+
|
15
|
+
client = JumioRock::Client.new
|
16
|
+
response = client.call_api("1", @path)
|
17
|
+
assert_equal response.timestamp, "2012-08-16T10:37:44.623Z"
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'initialize embed iframe' do
|
22
|
+
stub_init_embed_request
|
23
|
+
|
24
|
+
auth_token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
25
|
+
|
26
|
+
client = JumioRock::Client.new
|
27
|
+
response = client.init_embed("scanID", "http://success_url", "http://error_url")
|
28
|
+
|
29
|
+
assert_equal response.authorizationToken, auth_token
|
30
|
+
iframe = client.iframe response.authorizationToken
|
31
|
+
assert_match auth_token, iframe
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'initialize multi document' do
|
36
|
+
stub_multi_document_request
|
37
|
+
auth_token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
38
|
+
|
39
|
+
client = JumioRock::Client.new
|
40
|
+
response = client.init_multidocument('CC',"YOURSCANREFERENCE", "CUSTOMERID","https://95.240.235.90/success", "https://95.240.235.90/error")
|
41
|
+
|
42
|
+
assert_equal response.authorizationToken, auth_token
|
43
|
+
|
44
|
+
iframe = client.iframe response.authorizationToken
|
45
|
+
assert_match auth_token, iframe
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'initialize redirect' do
|
50
|
+
stub_redirect_request
|
51
|
+
auth_token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
52
|
+
|
53
|
+
client = JumioRock::Client.new
|
54
|
+
response = client.init_redirect("scan_id", "customer_id")
|
55
|
+
|
56
|
+
assert_equal response.clientRedirectUrl, "https://[your-domain-prefix].netverify.com/v2?authorizationToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "success response" do
|
60
|
+
params = parse_post(success_api_response)
|
61
|
+
pp = JumioRock::PostParser.new(params)
|
62
|
+
assert_equal("APPROVED_VERIFIED", pp.status)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "fraud response" do
|
66
|
+
params = parse_post(fraud_api_response)
|
67
|
+
pp = JumioRock::PostParser.new(params)
|
68
|
+
refute_same("APPROVED_VERIFIED", pp.status)
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative '../../minitest_helper'
|
2
|
+
require 'chunky_png'
|
3
|
+
|
4
|
+
describe JumioRock::PerformNetverifyParams do
|
5
|
+
before :once do
|
6
|
+
@path = create_test_image
|
7
|
+
end
|
8
|
+
|
9
|
+
it "must check required params" do
|
10
|
+
pnp = JumioRock::PerformNetverifyParams.new(nil, @path)
|
11
|
+
proc { pnp.to_json }.must_raise RuntimeError
|
12
|
+
end
|
13
|
+
|
14
|
+
it "create json based on instace variables" do
|
15
|
+
fields = ["merchantIdScanReference", "frontsideImage"]
|
16
|
+
pnp = JumioRock::PerformNetverifyParams.new("scanID", @path)
|
17
|
+
json = pnp.to_json
|
18
|
+
object = JSON.parse(json)
|
19
|
+
fields.each do |f|
|
20
|
+
object.keys.must_include f
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'encode image' do
|
25
|
+
pnp = JumioRock::PerformNetverifyParams.new("scanID", @path)
|
26
|
+
assert_equal pnp.frontsideImage, "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAgMAAABinRfyAAAACVBMVEUAAAAAAAAKFB5aVYYgAAAAA3RSTlMAgIAsTd+1AAAAFUlEQVR4nGNiAAImFRBxB0QwUEgAAEtUASFOz9UDAAAAAElFTkSuQmCC"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/pride'
|
3
|
+
require 'webmock/minitest'
|
4
|
+
|
5
|
+
require File.expand_path('../../lib/jumio_rock.rb', __FILE__)
|
6
|
+
|
7
|
+
def create_test_image
|
8
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), "../../../tmp/filename.png"))
|
9
|
+
|
10
|
+
png = ChunkyPNG::Image.new(16, 16, ChunkyPNG::Color::TRANSPARENT)
|
11
|
+
png[1,1] = ChunkyPNG::Color.rgba(10, 20, 30, 128)
|
12
|
+
png[2,1] = ChunkyPNG::Color('black @ 0.5')
|
13
|
+
png.save(path)
|
14
|
+
|
15
|
+
path
|
16
|
+
end
|
17
|
+
|
18
|
+
def stub_api_request
|
19
|
+
prefix = jumio_conf.api_url.match(/^https/) ? "https" : "http"
|
20
|
+
url = jumio_conf.api_url.gsub(/http[s]:\/\//,'')
|
21
|
+
stub_request(:post, "#{prefix}://#{jumio_conf.api_token}:#{jumio_conf.api_secret}@#{url}").
|
22
|
+
with(:headers => {
|
23
|
+
'Host'=>'netverify.com:443',
|
24
|
+
'User-Agent'=>"#{jumio_conf.company_name} #{jumio_conf.app_name}/#{jumio_conf.version}"
|
25
|
+
}).
|
26
|
+
to_return(:status => 200, :body => json_api_response, :headers => {})
|
27
|
+
end
|
28
|
+
|
29
|
+
def stub_init_embed_request
|
30
|
+
stub_request(:post, "https://username:password@netverify.com/api/netverify/v2/initiateNetverify").
|
31
|
+
with(
|
32
|
+
:body => "{\"merchantIdScanReference\":\"scanID\",\"successUrl\":\"http://success_url\",\"errorUrl\":\"http://error_url\"}",
|
33
|
+
:headers => {
|
34
|
+
'Accept'=>'application/json',
|
35
|
+
'Authorization'=>'Basic dXNlcm5hbWU6cGFzc3dvcmQ=',
|
36
|
+
'Content-Type'=>'application/json',
|
37
|
+
'Host'=>'netverify.com:443',
|
38
|
+
'User-Agent'=>'YOURCOMPANYNAME YOURAPPLICATIONNAME/0.0.1'}).
|
39
|
+
to_return(:status => 200, :body => json_init_embed_response, :headers => {})
|
40
|
+
end
|
41
|
+
|
42
|
+
def stub_multi_document_request
|
43
|
+
stub_request(:post, "https://username:password@netverify.com/api/netverify/v2/createDocumentAcquisition").
|
44
|
+
with(:body => "{\"documentType\":\"CC\",\"merchantScanReference\":\"YOURSCANREFERENCE\",\"customerID\":\"CUSTOMERID\",\"successUrl\":\"https://95.240.235.90/success\",\"errorUrl\":\"https://95.240.235.90/error\"}",
|
45
|
+
:headers => {'Accept'=>'application/json', 'Authorization'=>'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', 'Content-Type'=>'application/json', 'Host'=>'netverify.com:443', 'User-Agent'=>'YOURCOMPANYNAME YOURAPPLICATIONNAME/0.0.1'}).
|
46
|
+
to_return(:status => 200, :body => json_multi_document_response, :headers => {})
|
47
|
+
end
|
48
|
+
|
49
|
+
def stub_redirect_request
|
50
|
+
stub_request(:post, "https://username:password@netverify.com/api/netverify/v2/initiateNetverifyRedirect").
|
51
|
+
with(:body => "{\"merchantIdScanReference\":\"scan_id\",\"customerId\":\"customer_id\"}",
|
52
|
+
:headers => {'Accept'=>'application/json', 'Authorization'=>'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', 'Content-Type'=>'application/json', 'Host'=>'netverify.com:443', 'User-Agent'=>'YOURCOMPANYNAME YOURAPPLICATIONNAME/0.0.1'}).
|
53
|
+
to_return(:status => 200, :body => json_redirect_response, :headers => {})
|
54
|
+
end
|
55
|
+
|
56
|
+
def jumio_conf
|
57
|
+
JumioRock::Configuration.configuration
|
58
|
+
end
|
59
|
+
|
60
|
+
def json_api_response
|
61
|
+
<<-EOF
|
62
|
+
{
|
63
|
+
"timestamp": "2012-08-16T10:37:44.623Z",
|
64
|
+
"jumioIdScanReference": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
65
|
+
}
|
66
|
+
EOF
|
67
|
+
end
|
68
|
+
|
69
|
+
def json_init_embed_response
|
70
|
+
<<-EOF
|
71
|
+
{
|
72
|
+
"timestamp": "2012-08-16T10:27:29.494Z",
|
73
|
+
"authorizationToken": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
74
|
+
"jumioIdScanReference": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
75
|
+
}
|
76
|
+
EOF
|
77
|
+
end
|
78
|
+
|
79
|
+
def json_multi_document_response
|
80
|
+
<<-EOF
|
81
|
+
{
|
82
|
+
"timestamp": "2012-08-16T10:27:29.494Z",
|
83
|
+
"authorizationToken": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
84
|
+
"jumioIdScanReference": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
85
|
+
}
|
86
|
+
EOF
|
87
|
+
end
|
88
|
+
|
89
|
+
def json_redirect_response
|
90
|
+
<<-EOF
|
91
|
+
{
|
92
|
+
"timestamp": "2012-08-16T10:27:29.494Z",
|
93
|
+
"authorizationToken": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
94
|
+
"clientRedirectUrl": "https://[your-domain-prefix].netverify.com/v2?authorizationToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
95
|
+
"jumioIdScanReference": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
96
|
+
}
|
97
|
+
EOF
|
98
|
+
end
|
99
|
+
|
100
|
+
def success_api_response
|
101
|
+
"idExpiry=2022-12-31&idType=PASSPORT&idDob=1990-01-01&idCheckSignature=OK&idCheckDataPositions=OK&idCheckHologram=OK&idCheckMicroprint=OK&idCheckDocumentValidation=OK&idCountry=USA&idScanSource=WEB_UPLOAD&idFirstName=FIRSTNAME&verificationStatus=APPROVED_VERIFIED&jumioIdScanReference=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&personalNumber=N%2FA&merchantIdScanReference=YOURIDSCANREFERENCE&idCheckSecurityFeatures=OK&idCheckMRZcode=OK&idScanImage=https%3A%2F%2Fnetverify.com%2Frecognition%2Fv1%2Fidscan%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%2Ffront&callBackType=NETVERIFYID&clientIp=xxx.xxx.xxx.xxx&idLastName=LASTNAME&idAddress=%7B%22country%22%3A%22USA%22%2C%22state%22%3A%22OH%22%7D&idScanStatus=SUCCESS&idNumber=P1234"
|
102
|
+
end
|
103
|
+
|
104
|
+
def fraud_api_response
|
105
|
+
"idType=PASSPORT&idCheckSignature=N%2FA&rejectReason=%7B%20%22rejectReasonCode%22%3A%22100%22%2C%20%22rejectReasonDescription%22%3A%22MANIPULATED_DOCUMENT%22%2C%20%22rejectReasonDetails%22%3A%20%5B%7B%20%22detailsCode%22%3A%20%221001%22%2C%20%22detailsDescription%22%3A%20%22PHOTO%22%20%7D%2C%7B%20%22detailsCode%22%3A%20%221004%22%2C%20%22detailsDescription%22%3A%20%22DOB%22%20%7D%5D%7D&idCheckDataPositions=N%2FA&idCheckHologram=N%2FA&idCheckMicroprint=N%2FA&idCheckDocumentValidation=N%2FA&idCountry=USA&idScanSource=WEB_UPLOAD&verificationStatus=DENIED_FRAUD&jumioIdScanReference=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&merchantIdScanReference=YOURSCANREFERENCE&idCheckSecurityFeatures=N%2FA&idCheckMRZcode=N%2FA&idScanImage=https%3A%2F%2Fnetverify.com%2Frecognition%2Fv1%2Fidscan%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%2Ffront&callBackType=NETVERIFYID&clientIp=xxx.xxx.xxx.xxx&idScanStatus=ERROR"
|
106
|
+
end
|
107
|
+
|
108
|
+
def success_callback
|
109
|
+
<<-EOF
|
110
|
+
EOF
|
111
|
+
end
|
112
|
+
|
113
|
+
def callback_document_present
|
114
|
+
"jumioScanReference=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&documentType=CC&merchantScanReference=YOURSCANREFERENCE&documentPageImageUrls=%5Bhttps%3A%2F%2Fnetverify.com%2Frecognition%2Fv1%2Fdocuments%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%2Fimages%2F512ccacce4b08a828bd46ec8%2C+https%3A%2F%2Fnetverify.com%2Frecognition%2Fv1%2Fdocuments%xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%2Fimages%2F512ccacce4b08a828bd46ecd%5D&callBackType=DOCUMENT&customerID=CUSTOMERID&documentStatus=DOCUMENT_PRESENT"
|
115
|
+
end
|
116
|
+
|
117
|
+
def callback_no_document_present
|
118
|
+
"jumioScanReference=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&documentType=CC&merchantScanReference=YOURSCANREFERENCE&callBackType=DOCUMENT&customerID=CUSTOMERID&documentStatus=NO_DOCUMENT_PRESENT"
|
119
|
+
end
|
120
|
+
|
121
|
+
def callback_unsupported_document_type
|
122
|
+
"jumioScanReference=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&documentType=CC&merchantScanReference=YOURSCANREFERENCE&callBackType=DOCUMENT&customerID=CUSTOMERID&documentStatus=DENIED_UNSUPPORTED_DOCUMENT_TYPE"
|
123
|
+
end
|
124
|
+
|
125
|
+
def parse_post(str)
|
126
|
+
params = {}
|
127
|
+
splitted_values = str.split('&')
|
128
|
+
splitted_values.each do |v|
|
129
|
+
kv = v.match(/^([\w\W]+)=([\w\W]+)/)
|
130
|
+
params[kv[1].to_sym] = kv[2]
|
131
|
+
end
|
132
|
+
params
|
133
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jumio_rock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michele Minazzato
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: chunky_png
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: ''
|
98
|
+
email:
|
99
|
+
- michelemina@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- jumio_rock.gemspec
|
110
|
+
- lib/jumio_rock.rb
|
111
|
+
- lib/jumio_rock/client.rb
|
112
|
+
- lib/jumio_rock/configuration.rb
|
113
|
+
- lib/jumio_rock/embed_netverify_params.rb
|
114
|
+
- lib/jumio_rock/multi_document_netverify_params.rb
|
115
|
+
- lib/jumio_rock/netverify_params.rb
|
116
|
+
- lib/jumio_rock/perform_netverify_params.rb
|
117
|
+
- lib/jumio_rock/post_parser.rb
|
118
|
+
- lib/jumio_rock/redirect_netverify_params.rb
|
119
|
+
- lib/jumio_rock/version.rb
|
120
|
+
- test/example.rb
|
121
|
+
- test/lib/jumio_rock/jumio_rock_test.rb
|
122
|
+
- test/lib/jumio_rock/perform_netverify_params_test.rb
|
123
|
+
- test/lib/jumio_rock/version_test.rb
|
124
|
+
- test/minitest_helper.rb
|
125
|
+
homepage: ''
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.2.2
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Unofficial Jumio API implementation
|
149
|
+
test_files:
|
150
|
+
- test/example.rb
|
151
|
+
- test/lib/jumio_rock/jumio_rock_test.rb
|
152
|
+
- test/lib/jumio_rock/perform_netverify_params_test.rb
|
153
|
+
- test/lib/jumio_rock/version_test.rb
|
154
|
+
- test/minitest_helper.rb
|