prevent_go 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +45 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +21 -0
- data/README.md +200 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/prevent_go.rb +73 -0
- data/lib/prevent_go/bank_account.rb +25 -0
- data/lib/prevent_go/base.rb +39 -0
- data/lib/prevent_go/configuration.rb +11 -0
- data/lib/prevent_go/identity.rb +45 -0
- data/lib/prevent_go/property_tax_notice.rb +16 -0
- data/lib/prevent_go/provider_invoice.rb +16 -0
- data/lib/prevent_go/response_error.rb +22 -0
- data/lib/prevent_go/tax_notice.rb +44 -0
- data/lib/prevent_go/version.rb +3 -0
- data/prevent_go.gemspec +36 -0
- data/rubocop.yml +80 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6bfaa578b8bc1b3d30a95d9195779a6e8eb351d6d836f29cc59ad9dbf731e678
|
4
|
+
data.tar.gz: 209d667d18b22b251d094c1c6110af0500ffa2344af41a87f5568857910a467e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f30f7d6a792ca4d8a9f5cbf663cf4097db48d701ee0c1c1862462d082999650163f32f0620acf2b8d09a779bd2cfe8ad9c1ff6ef92785bd5e7801259f9cd11c
|
7
|
+
data.tar.gz: d9a01cd361f3cea165d433dd54e9a9d7790e81ff2b6e33bb636cca3053d12f9677b898fc16be81737ce36514f5bf25461f9e37074f875390a70367a31a343f01
|
@@ -0,0 +1,45 @@
|
|
1
|
+
version: 2.1
|
2
|
+
orbs:
|
3
|
+
ruby: circleci/ruby@0.1.2
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
docker:
|
8
|
+
- image: circleci/ruby:2.6.3-stretch-node
|
9
|
+
executor: ruby/default
|
10
|
+
steps:
|
11
|
+
- checkout
|
12
|
+
- run:
|
13
|
+
name: Bundle install
|
14
|
+
command: |
|
15
|
+
gem install bundler -v "~>2.0"
|
16
|
+
bundle install --path vendor/bundle
|
17
|
+
- run:
|
18
|
+
name: Test
|
19
|
+
command: bundle exec rspec
|
20
|
+
- run:
|
21
|
+
name: Coding style
|
22
|
+
command: |
|
23
|
+
gem install rubocop
|
24
|
+
mkdir -p rubocop
|
25
|
+
rubocop --format html -o rubocop/rubocop.html || true
|
26
|
+
- run:
|
27
|
+
name: Notation
|
28
|
+
command: |
|
29
|
+
gem install sexp_processor -v 4.13.0
|
30
|
+
gem install rubycritic -v 4.3.2
|
31
|
+
rubycritic app --no-browser || true
|
32
|
+
- run:
|
33
|
+
name: "Axe d'optimisation"
|
34
|
+
command: |
|
35
|
+
gem install fasterer
|
36
|
+
fasterer || true
|
37
|
+
- run:
|
38
|
+
name: "Audit Securité du Gemfile"
|
39
|
+
command: |
|
40
|
+
gem install bundler-audit
|
41
|
+
bundle audit --update
|
42
|
+
- store_artifacts:
|
43
|
+
path: rubocop/rubocop.html
|
44
|
+
- store_artifacts:
|
45
|
+
path: tmp/rubycritic
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at development@capsens.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
prevent_go (0.1.0)
|
5
|
+
mime-types (~> 3.0)
|
6
|
+
multipart-post (~> 2.1, >= 2.1.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
crack (0.4.4)
|
14
|
+
diff-lcs (1.4.4)
|
15
|
+
hashdiff (1.0.1)
|
16
|
+
mime-types (3.3.1)
|
17
|
+
mime-types-data (~> 3.2015)
|
18
|
+
mime-types-data (3.2020.0512)
|
19
|
+
multipart-post (2.1.1)
|
20
|
+
public_suffix (4.0.6)
|
21
|
+
rake (12.3.3)
|
22
|
+
rspec (3.10.0)
|
23
|
+
rspec-core (~> 3.10.0)
|
24
|
+
rspec-expectations (~> 3.10.0)
|
25
|
+
rspec-mocks (~> 3.10.0)
|
26
|
+
rspec-core (3.10.0)
|
27
|
+
rspec-support (~> 3.10.0)
|
28
|
+
rspec-expectations (3.10.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.10.0)
|
31
|
+
rspec-mocks (3.10.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.10.0)
|
34
|
+
rspec-support (3.10.0)
|
35
|
+
vcr (5.0.0)
|
36
|
+
webmock (3.9.3)
|
37
|
+
addressable (>= 2.3.6)
|
38
|
+
crack (>= 0.3.2)
|
39
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
prevent_go!
|
46
|
+
rake (~> 12.1)
|
47
|
+
rspec (~> 3.0)
|
48
|
+
vcr (~> 5.0)
|
49
|
+
webmock (~> 3.9)
|
50
|
+
|
51
|
+
BUNDLED WITH
|
52
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 CapSens
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
# PreventGO
|
2
|
+
|
3
|
+
Ruby gem made to use PreventGO OCR in your applications.
|
4
|
+
Official documentation is available [here](https://www.preventgo.io/)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'prevent_go'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install prevent_go
|
21
|
+
|
22
|
+
## Configuration
|
23
|
+
|
24
|
+
Create an account on [PreventGO website](https://www.preventgo.io/) and ask for API keys.
|
25
|
+
|
26
|
+
And then add an initializer
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# config/initializers/prevent_go.rb
|
30
|
+
|
31
|
+
PreventGo.configure do |config|
|
32
|
+
config.site_key = 'YOUR_PUBLIC_SITE_KEY'
|
33
|
+
config.secret_key = 'YOUR_SECRET_KEY'
|
34
|
+
config.api_root_url = 'API_ENDPOINT'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Parent module
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
module PreventGo
|
44
|
+
```
|
45
|
+
|
46
|
+
Each type of document that can be verified has his own class as follow:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
PreventGo::BankAccount
|
50
|
+
PreventGo::Identity
|
51
|
+
PreventGo::PropertyTaxNotice
|
52
|
+
PreventGo::TaxNotice
|
53
|
+
PreventGo::ProviderInvoice
|
54
|
+
```
|
55
|
+
|
56
|
+
Each instance of one of the previous classes can be initialized as following:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
PreventGo::BankAccount.new(file, file_back, params)
|
60
|
+
```
|
61
|
+
- `:file`: mandatory - can be a path or IO file
|
62
|
+
- `:file_back`: optional - can be a path or IO file
|
63
|
+
- `params`: optional - ask preventGo to make additional controls on documents (details per document below)
|
64
|
+
|
65
|
+
|
66
|
+
And can access to thoses methods
|
67
|
+
|
68
|
+
| method | Description |
|
69
|
+
|----------------------|-------------|
|
70
|
+
| `.document_type` | return document type as string |
|
71
|
+
| `.document_details` | return a hash with informations givent by the API or an empty hash |
|
72
|
+
| `.document_controls` | return a hash with the api response on control_groups about document or an empty hash |
|
73
|
+
| `.holder_controls` | return a hash with the api response on control_groups about document holder or an empty hash |
|
74
|
+
| `.quality_validated?`| return a boolean with api response on document quality |
|
75
|
+
|
76
|
+
------
|
77
|
+
|
78
|
+
`PreventGo::BankAccount`
|
79
|
+
|
80
|
+
optional params to pass to bank_account validation are:
|
81
|
+
- holder: { "firstName":"Scarlette", "birthName":"Johansson", "lastName":"Bauer"} or {"legalEntityName":"NETHEOS"}
|
82
|
+
- bank_account: { "iban":"FR7600000000000000000000000", "bicCode":"AGRIFRPP" }
|
83
|
+
|
84
|
+
example:
|
85
|
+
```ruby
|
86
|
+
PrevenGo::BankAccount.new(
|
87
|
+
file,
|
88
|
+
holder: {legalEntityName:"NETHEOS"},
|
89
|
+
bank_account: {iban: "FR7600000000000000000000000"}
|
90
|
+
)
|
91
|
+
```
|
92
|
+
|
93
|
+
additional instance methods available:
|
94
|
+
- `:iban`
|
95
|
+
- `:bic`
|
96
|
+
------
|
97
|
+
|
98
|
+
`PreventGo::Identity`
|
99
|
+
|
100
|
+
Individual person identity document, can be either ID card, passport or driver license
|
101
|
+
|
102
|
+
optional params to pass to bank_account validation are:
|
103
|
+
- holder: { "firstName":"John", "birthName":"Doe", "lastName":"Simpson", "birthDate":"1987-12-25", "gender":"M" }
|
104
|
+
|
105
|
+
example:
|
106
|
+
```ruby
|
107
|
+
PrevenGo::Identity.new(
|
108
|
+
file,
|
109
|
+
holder: {"firstName":"John", "birthName":"Doe"}
|
110
|
+
)
|
111
|
+
```
|
112
|
+
|
113
|
+
additional instance methods available:
|
114
|
+
- `:iban`
|
115
|
+
- `:bic`
|
116
|
+
|
117
|
+
------
|
118
|
+
|
119
|
+
`PreventGo::PropertyTaxNotice`
|
120
|
+
|
121
|
+
optional params to pass to bank_account validation are:
|
122
|
+
- holder: { "firstName":"James","lastName":"Bond","birthName": "Martinet","address": {"address1":"29 rue du Cheval blanc", "postalCode":"34000", "city":"Montpellier"}}
|
123
|
+
|
124
|
+
example:
|
125
|
+
```ruby
|
126
|
+
PrevenGo::PropertyTaxNotice.new(
|
127
|
+
file,
|
128
|
+
holder: {"firstName":"John", "birthName":"Doe"}
|
129
|
+
)
|
130
|
+
```
|
131
|
+
------
|
132
|
+
|
133
|
+
`PreventGo::TaxNotice`
|
134
|
+
|
135
|
+
Only works with french tax notices
|
136
|
+
|
137
|
+
optional params to pass to bank_account validation are:
|
138
|
+
- holder_1: { "firstName":"James","lastName":"Bond" }
|
139
|
+
- holder_2: { "firstName":"James","lastName":"Bond" }
|
140
|
+
- taxHouseHold: {
|
141
|
+
"familyStatusCode":"SINGLE",
|
142
|
+
"partsCount":1.5,
|
143
|
+
"dependentPersonsCount":2,
|
144
|
+
"globalGrossIncome":23456,
|
145
|
+
"referenceIncome":12345,
|
146
|
+
"taxableIncome":1234,
|
147
|
+
"taxAmount":123,
|
148
|
+
"address": {"address1":"29 rue du Cheval anc","postalCode":"34000","city":"Montpellier"}
|
149
|
+
}
|
150
|
+
|
151
|
+
example:
|
152
|
+
```ruby
|
153
|
+
PrevenGo::TaxNotice.new(
|
154
|
+
file,
|
155
|
+
holder_1: {"firstName":"John", "birthName":"Do"},
|
156
|
+
holder_2: {"firstName":"Jane", "birthName":"Undo"}
|
157
|
+
)
|
158
|
+
```
|
159
|
+
------
|
160
|
+
|
161
|
+
`PreventGo::ProviderInvoice`
|
162
|
+
|
163
|
+
Provider invoice or schedule accepted
|
164
|
+
|
165
|
+
optional params to pass to bank_account validation are:
|
166
|
+
- holder: { "firstName":"James","lastName":"Bond","birthName": "Martinet","address": {"address1":"29 rue du Cheval blanc", "postalCode":"34000", "city":"Montpellier"}}
|
167
|
+
|
168
|
+
example:
|
169
|
+
```ruby
|
170
|
+
PrevenGo::ProviderInvoice.new(
|
171
|
+
file,
|
172
|
+
holder: {"firstName":"John", "birthName":"Doe"}
|
173
|
+
)
|
174
|
+
```
|
175
|
+
|
176
|
+
## Development
|
177
|
+
|
178
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
179
|
+
|
180
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
181
|
+
|
182
|
+
## Contributing
|
183
|
+
|
184
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/CapSens/prevent_go
|
185
|
+
|
186
|
+
1. **Fork** the repo on GitHub
|
187
|
+
2. **Clone** the project to your own machine
|
188
|
+
3. **Commit** changes to your own branch
|
189
|
+
4. **Push** your work back up to your fork
|
190
|
+
5. Submit a **Pull request** so that we can review your changes
|
191
|
+
|
192
|
+
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
|
193
|
+
|
194
|
+
## License
|
195
|
+
|
196
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
197
|
+
|
198
|
+
## Code of Conduct
|
199
|
+
|
200
|
+
Everyone interacting in the PreventGo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Capsens/prevent_go/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "prevent_go"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/prevent_go.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/http/post/multipart'
|
5
|
+
|
6
|
+
require 'prevent_go/version'
|
7
|
+
require 'prevent_go/configuration'
|
8
|
+
require 'prevent_go/response_error'
|
9
|
+
|
10
|
+
module PreventGo
|
11
|
+
autoload :Base, 'prevent_go/base'
|
12
|
+
autoload :BankAccount, 'prevent_go/bank_account'
|
13
|
+
autoload :DriverLicense, 'prevent_go/driver_license'
|
14
|
+
autoload :Identity, 'prevent_go/identity'
|
15
|
+
autoload :PropertyTaxNotice, 'prevent_go/property_tax_notice'
|
16
|
+
autoload :ProviderInvoice, 'prevent_go/provider_invoice'
|
17
|
+
autoload :TaxNotice, 'prevent_go/tax_notice'
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def configuration
|
21
|
+
@configuration ||= PreventGo::Configuration.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def configure
|
25
|
+
yield(configuration)
|
26
|
+
end
|
27
|
+
|
28
|
+
def api_root_url
|
29
|
+
configuration.api_root_url
|
30
|
+
end
|
31
|
+
|
32
|
+
def api_uri(path='')
|
33
|
+
URI(api_root_url + path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def request(url, params={})
|
37
|
+
uri = api_uri(url)
|
38
|
+
|
39
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 1000) do |http|
|
40
|
+
req = Net::HTTP::Post::Multipart.new(uri.request_uri, params)
|
41
|
+
req.basic_auth(ENV['PREVENT_GO_ID'], ENV['PREVENT_GO_SECRET'])
|
42
|
+
http.request(req)
|
43
|
+
end
|
44
|
+
|
45
|
+
# decode json data
|
46
|
+
data = res.body.to_s.empty? ? {} : JSON.parse(res.body.to_s)
|
47
|
+
|
48
|
+
raise PreventGo::ResponseError.new(uri, res.code, data) unless res.is_a?(Net::HTTPOK)
|
49
|
+
|
50
|
+
data
|
51
|
+
end
|
52
|
+
|
53
|
+
def detect_mime_type_for(file)
|
54
|
+
if file.respond_to?(:content_type)
|
55
|
+
file.content_type
|
56
|
+
elsif file.respond_to?(:path)
|
57
|
+
MIME::Types.type_for(File.basename(file.path))[0]
|
58
|
+
elsif file.is_a?(String)
|
59
|
+
MIME::Types.type_for(File.basename(file))[0]
|
60
|
+
else
|
61
|
+
''
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def concat_params(files, params={})
|
66
|
+
params = params.each { |k, v| params[k] = JSON.dump(v) }
|
67
|
+
files.compact.each.with_index(1) do |file, index|
|
68
|
+
params["file_#{index}"] = UploadIO.new(file, detect_mime_type_for(file))
|
69
|
+
end
|
70
|
+
params
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Params to pass to bank accounts:
|
2
|
+
# holder: { "firstName":"Scarlette", "birthName":"Johansson", "lastName":"Bauer"} or {"legalEntityName":"NETHEOS"} => (optional)
|
3
|
+
# bank_account: { "iban":"FR7600000000000000000000000", "bicCode":"AGRIFRPP" } => (optional)
|
4
|
+
# file_1: file => required
|
5
|
+
# file_2: file => optional
|
6
|
+
|
7
|
+
module PreventGo
|
8
|
+
class BankAccount < Base
|
9
|
+
attr_accessor :params, :request
|
10
|
+
|
11
|
+
def bic
|
12
|
+
@request.dig('documentDetails', 'bicCode')
|
13
|
+
end
|
14
|
+
|
15
|
+
def iban
|
16
|
+
@request.dig('documentDetails', 'iban')
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def endpoint
|
22
|
+
'/bank-account'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module PreventGo
|
2
|
+
class Base
|
3
|
+
attr_accessor :params, :request
|
4
|
+
|
5
|
+
def initialize(file_front, file_back=nil, **params)
|
6
|
+
@params = PreventGo.concat_params([file_front, file_back], params)
|
7
|
+
@request = PreventGo.request(endpoint, @params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def document_type
|
11
|
+
@request["documentType"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def document_details
|
15
|
+
@_document_details ||= @request['documentDetails'] || {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def document_controls
|
19
|
+
@_document_controls ||= @request.dig('controlsGroups', 'document') || {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def holder_controls
|
23
|
+
@_holder_controls ||= @request.dig('controlsGroups', 'holder')
|
24
|
+
end
|
25
|
+
|
26
|
+
def quality_validated?
|
27
|
+
[
|
28
|
+
document_controls['typeRecognized'],
|
29
|
+
document_controls.dig('quality', 'aboveMinimumThreshold'),
|
30
|
+
].all? { |entry| entry == 'OK' }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def endpoint
|
36
|
+
''
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Params to pass to bank accounts:
|
2
|
+
# holder: { "firstName":"Quentin", "birthName":"Doe", "lastName":"Simpson", "birthDate":"1987-12-25", "gender":"M" } => (optional)
|
3
|
+
# file_1: file => required
|
4
|
+
# file_2: file => optional
|
5
|
+
|
6
|
+
module PreventGo
|
7
|
+
class Identity < Base
|
8
|
+
|
9
|
+
def holder_controls
|
10
|
+
@_holder_controls ||= @request.dig('controlsGroups', 'holder') || {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def holder_data
|
14
|
+
@_holder_data || @request.dig('documentDetails', 'holder') || {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch_holder_infos(*keys)
|
18
|
+
keys = default_holder_keys if keys.empty?
|
19
|
+
holder_data.slice(*keys).values.compact
|
20
|
+
end
|
21
|
+
|
22
|
+
def quality_validated?
|
23
|
+
[
|
24
|
+
document_controls['typeRecognized'],
|
25
|
+
document_controls.dig('quality', 'aboveMinimumThreshold'),
|
26
|
+
document_controls['notExpired'],
|
27
|
+
document_controls['mrzValid']
|
28
|
+
].all? { |entry| entry == 'OK' }
|
29
|
+
end
|
30
|
+
|
31
|
+
def not_expired?
|
32
|
+
@request.dig('controlsGroups', 'document', 'notExpired') == 'OK'
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def endpoint
|
38
|
+
'/identity/individual'
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_holder_keys
|
42
|
+
%w[firstName lastName birthName birthDate gender]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Params to pass to bank accounts:
|
2
|
+
# holder: { "firstName":"James","lastName":"Bond","birthName": "Martinet","address": {"address1":"29 rue du Cheval blanc", "postalCode":"34000", "city":"Montpellier"}}
|
3
|
+
# file_1: file => required
|
4
|
+
# file_2: file => optional
|
5
|
+
|
6
|
+
module PreventGo
|
7
|
+
class PropertyTaxNotice < Base
|
8
|
+
def endpoint
|
9
|
+
'/property-tax-notice'
|
10
|
+
end
|
11
|
+
|
12
|
+
def holder_controls
|
13
|
+
@_holder_controls ||= @request.dig('controlsGroups', 'holder') || {}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Params to pass to provider invoice:
|
2
|
+
# holder: { "firstName":"James","lastName":"Bond","birthName": "Martinet","address": {"address1":"29 rue du Cheval blanc", "postalCode":"34000", "city":"Montpellier"}} => (optional)
|
3
|
+
# file_1: file => required
|
4
|
+
# file_2: file => optional
|
5
|
+
|
6
|
+
module PreventGo
|
7
|
+
class ProviderInvoice < Base
|
8
|
+
def endpoint
|
9
|
+
'/provider-invoice'
|
10
|
+
end
|
11
|
+
|
12
|
+
def holder_controls
|
13
|
+
@_holder_controls ||= @request.dig('controlsGroups', 'holder') || {}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PreventGo
|
2
|
+
class ResponseError < StandardError
|
3
|
+
attr_reader :request_url, :code, :details
|
4
|
+
|
5
|
+
def initialize(request_url, code, details)
|
6
|
+
@request_url, @code, @details = request_url, code, details
|
7
|
+
|
8
|
+
@details['Code'] = code
|
9
|
+
@details['Url'] = request_url.request_uri
|
10
|
+
|
11
|
+
super(message) if message
|
12
|
+
end
|
13
|
+
|
14
|
+
def type
|
15
|
+
@details.dig('error', 'code')
|
16
|
+
end
|
17
|
+
|
18
|
+
def message
|
19
|
+
@details.dig('error', 'message')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Params to pass to bank accounts:
|
2
|
+
# holder_1: { "firstName":"James","lastName":"Bond" } => (optional)
|
3
|
+
# holder_2: { "firstName":"James","lastName":"Bond" } => (optional)
|
4
|
+
# taxHouseHold: {
|
5
|
+
# "familyStatusCode":"SINGLE",
|
6
|
+
# "partsCount":1.5,
|
7
|
+
# "dependentPersonsCount":2,
|
8
|
+
# "globalGrossIncome":23456,
|
9
|
+
# "referenceIncome":12345,
|
10
|
+
# "taxableIncome":1234,
|
11
|
+
# "taxAmount":123,
|
12
|
+
# "address": {"address1":"29 rue du Cheval blanc","postalCode":"34000","city":"Montpellier"}
|
13
|
+
# } => optional
|
14
|
+
# file_1: file => required
|
15
|
+
|
16
|
+
module PreventGo
|
17
|
+
class TaxNotice < Base
|
18
|
+
def endpoint
|
19
|
+
'/tax-notice'
|
20
|
+
end
|
21
|
+
|
22
|
+
def holders_data
|
23
|
+
@_holders_data ||=
|
24
|
+
[@request.dig('taxNoticeDetails', 'holder1'), @request.dig('taxNoticeDetails', 'holder2')].compact
|
25
|
+
end
|
26
|
+
|
27
|
+
def quality_validated?
|
28
|
+
[
|
29
|
+
document_controls['typeRecognized'],
|
30
|
+
document_controls.dig('quality', 'aboveMinimumThreshold'),
|
31
|
+
document_controls['fiscalNumberFound']
|
32
|
+
].all? { |entry| entry == 'OK' }
|
33
|
+
end
|
34
|
+
|
35
|
+
def fetch_holders_infos(*keys)
|
36
|
+
keys = default_holders_keys if keys.empty?
|
37
|
+
holders_data.map { |holder| holder.compact.slice(*keys).values }
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_holders_keys
|
41
|
+
%w[firstName lastName birthName birthDate]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/prevent_go.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'lib/prevent_go/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "prevent_go"
|
5
|
+
spec.version = PreventGo::VERSION
|
6
|
+
spec.authors = ["Quentin Degraeve"]
|
7
|
+
spec.email = ["development@capsens.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{PreventGo sdk}
|
10
|
+
spec.description = %q{PreventGo sdk}
|
11
|
+
spec.homepage = 'https://rubygems.org/gems/prevent_go'
|
12
|
+
spec.metadata = { "source_code_uri" => "https://github.com/CapSens/prevent_go.git" }
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency('multipart-post', '~> 2.1', '>= 2.1.1')
|
30
|
+
spec.add_dependency('mime-types', '~> 3.0')
|
31
|
+
|
32
|
+
spec.add_development_dependency('rake', '~> 12.1')
|
33
|
+
spec.add_development_dependency('rspec', '~> 3.0')
|
34
|
+
spec.add_development_dependency('vcr', '~> 5.0')
|
35
|
+
spec.add_development_dependency('webmock', '~> 3.9')
|
36
|
+
end
|
data/rubocop.yml
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
---
|
2
|
+
|
3
|
+
inherit_mode:
|
4
|
+
merge:
|
5
|
+
- Include
|
6
|
+
|
7
|
+
AllCops:
|
8
|
+
TargetRubyVersion: 2.6
|
9
|
+
|
10
|
+
Exclude:
|
11
|
+
- demo/rails_demo/node_modules/**/*
|
12
|
+
- demo/rails_demo/bin/**/*
|
13
|
+
- vendor/bundle/**/*
|
14
|
+
|
15
|
+
Layout/LineLength:
|
16
|
+
Max: 120
|
17
|
+
|
18
|
+
Style/StringLiterals:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/BlockLength:
|
22
|
+
Exclude:
|
23
|
+
- spec/**/*
|
24
|
+
|
25
|
+
Style/RegexpLiteral:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/FrozenStringLiteralComment:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Bundler/OrderedGems:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/Documentation:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/RaiseArgs:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
EnforcedStyle: compact
|
41
|
+
|
42
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
Layout/SpaceAroundMethodCallOperator:
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
Lint/DeprecatedOpenSSLConstant:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
Lint/MixedRegexpCaptureTypes:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
Lint/RaiseException:
|
55
|
+
Enabled: true
|
56
|
+
|
57
|
+
Lint/StructNewOverride:
|
58
|
+
Enabled: true
|
59
|
+
|
60
|
+
Style/ExponentialNotation:
|
61
|
+
Enabled: true
|
62
|
+
|
63
|
+
Style/HashEachMethods:
|
64
|
+
Enabled: true
|
65
|
+
|
66
|
+
Style/HashTransformKeys:
|
67
|
+
Enabled: true
|
68
|
+
|
69
|
+
Style/HashTransformValues:
|
70
|
+
Enabled: true
|
71
|
+
|
72
|
+
Style/RedundantRegexpCharacterClass:
|
73
|
+
Enabled: true
|
74
|
+
|
75
|
+
Style/RedundantRegexpEscape:
|
76
|
+
Enabled: true
|
77
|
+
|
78
|
+
Style/SlicingWithRange:
|
79
|
+
Enabled: true
|
80
|
+
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prevent_go
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Quentin Degraeve
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multipart-post
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mime-types
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '12.1'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '12.1'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: vcr
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '5.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '5.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: webmock
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.9'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.9'
|
103
|
+
description: PreventGo sdk
|
104
|
+
email:
|
105
|
+
- development@capsens.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".circleci/config.yml"
|
111
|
+
- ".gitignore"
|
112
|
+
- ".rspec"
|
113
|
+
- ".travis.yml"
|
114
|
+
- CHANGELOG.md
|
115
|
+
- CODE_OF_CONDUCT.md
|
116
|
+
- Gemfile
|
117
|
+
- Gemfile.lock
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- bin/console
|
122
|
+
- bin/setup
|
123
|
+
- lib/prevent_go.rb
|
124
|
+
- lib/prevent_go/bank_account.rb
|
125
|
+
- lib/prevent_go/base.rb
|
126
|
+
- lib/prevent_go/configuration.rb
|
127
|
+
- lib/prevent_go/identity.rb
|
128
|
+
- lib/prevent_go/property_tax_notice.rb
|
129
|
+
- lib/prevent_go/provider_invoice.rb
|
130
|
+
- lib/prevent_go/response_error.rb
|
131
|
+
- lib/prevent_go/tax_notice.rb
|
132
|
+
- lib/prevent_go/version.rb
|
133
|
+
- prevent_go.gemspec
|
134
|
+
- rubocop.yml
|
135
|
+
homepage: https://rubygems.org/gems/prevent_go
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata:
|
139
|
+
source_code_uri: https://rubygems.org/gems/prevent_go
|
140
|
+
homepage_uri: https://rubygems.org/gems/prevent_go
|
141
|
+
changelog_uri: https://rubygems.org/gems/prevent_go/CHANGELOG.md
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 2.4.0
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubygems_version: 3.1.2
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: PreventGo sdk
|
161
|
+
test_files: []
|