tikkie-api 0.1.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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +36 -0
- data/.travis.yml +7 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +67 -0
- data/LICENSE.txt +21 -0
- data/README.md +150 -0
- data/Rakefile +10 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/tikkie/api.rb +32 -0
- data/lib/tikkie/api/access_token.rb +19 -0
- data/lib/tikkie/api/authentication.rb +60 -0
- data/lib/tikkie/api/client.rb +24 -0
- data/lib/tikkie/api/configuration.rb +62 -0
- data/lib/tikkie/api/exception.rb +22 -0
- data/lib/tikkie/api/request.rb +57 -0
- data/lib/tikkie/api/requests/payment_requests.rb +56 -0
- data/lib/tikkie/api/requests/platforms.rb +32 -0
- data/lib/tikkie/api/requests/users.rb +31 -0
- data/lib/tikkie/api/responses/bank_account.rb +22 -0
- data/lib/tikkie/api/responses/base.rb +53 -0
- data/lib/tikkie/api/responses/error.rb +34 -0
- data/lib/tikkie/api/responses/pagination.rb +20 -0
- data/lib/tikkie/api/responses/payment.rb +48 -0
- data/lib/tikkie/api/responses/payment_request.rb +64 -0
- data/lib/tikkie/api/responses/payment_request_created.rb +22 -0
- data/lib/tikkie/api/responses/payment_requests.rb +42 -0
- data/lib/tikkie/api/responses/platform.rb +44 -0
- data/lib/tikkie/api/responses/platforms.rb +30 -0
- data/lib/tikkie/api/responses/user.rb +39 -0
- data/lib/tikkie/api/responses/users.rb +34 -0
- data/lib/tikkie/api/types/payment_request_status.rb +15 -0
- data/lib/tikkie/api/types/payment_status.rb +14 -0
- data/lib/tikkie/api/types/platform_status.rb +12 -0
- data/lib/tikkie/api/types/platform_usage.rb +12 -0
- data/lib/tikkie/api/types/user_status.rb +12 -0
- data/lib/tikkie/api/version.rb +7 -0
- data/tikkie-api.gemspec +31 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0fb0212ecabd850a104349b9edff3fc279c90f9
|
4
|
+
data.tar.gz: dbce2933f3a3b0750f385d1c74bb53f232256824
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed9a6a3f22a00360a990527fe9700c07ad68795db7bf2474523703467726aec375bb537d7dfb766bc0fe480b7bce1a74a38cc11bab7108d8b1a50fa62dd587f9
|
7
|
+
data.tar.gz: c60da0bf7f3b15499ea768389527161e0acaec5b4bbbcfc0f636862966a37406d2ef46a091c47c7b2d9539ca33c28a2c961c47a61c4bdcf4b4d2f59dba5899e0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
DisplayCopNames: true
|
4
|
+
DisplayStyleGuide: true
|
5
|
+
|
6
|
+
Metrics/AbcSize:
|
7
|
+
Max: 21
|
8
|
+
|
9
|
+
Metrics/BlockLength:
|
10
|
+
Exclude:
|
11
|
+
- 'spec/**/*'
|
12
|
+
|
13
|
+
Metrics/CyclomaticComplexity:
|
14
|
+
Max: 7
|
15
|
+
|
16
|
+
Metrics/LineLength:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/Documentation:
|
23
|
+
Exclude:
|
24
|
+
- 'spec/**/*'
|
25
|
+
|
26
|
+
Style/GuardClause:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/SafeNavigation:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/StringLiterals:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/SymbolArray:
|
36
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tikkie-api (0.1.0)
|
5
|
+
jwt (>= 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.5.2)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
ast (2.3.0)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
hashdiff (0.3.7)
|
17
|
+
jwt (2.1.0)
|
18
|
+
parallel (1.12.1)
|
19
|
+
parser (2.4.0.2)
|
20
|
+
ast (~> 2.3)
|
21
|
+
powerpack (0.1.1)
|
22
|
+
public_suffix (3.0.1)
|
23
|
+
rainbow (3.0.0)
|
24
|
+
rake (10.5.0)
|
25
|
+
rspec (3.7.0)
|
26
|
+
rspec-core (~> 3.7.0)
|
27
|
+
rspec-expectations (~> 3.7.0)
|
28
|
+
rspec-mocks (~> 3.7.0)
|
29
|
+
rspec-core (3.7.1)
|
30
|
+
rspec-support (~> 3.7.0)
|
31
|
+
rspec-expectations (3.7.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.7.0)
|
34
|
+
rspec-mocks (3.7.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.7.0)
|
37
|
+
rspec-support (3.7.0)
|
38
|
+
rubocop (0.52.1)
|
39
|
+
parallel (~> 1.10)
|
40
|
+
parser (>= 2.4.0.2, < 3.0)
|
41
|
+
powerpack (~> 0.1)
|
42
|
+
rainbow (>= 2.2.2, < 4.0)
|
43
|
+
ruby-progressbar (~> 1.7)
|
44
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
45
|
+
ruby-progressbar (1.9.0)
|
46
|
+
safe_yaml (1.0.4)
|
47
|
+
timecop (0.9.1)
|
48
|
+
unicode-display_width (1.3.0)
|
49
|
+
webmock (2.3.2)
|
50
|
+
addressable (>= 2.3.6)
|
51
|
+
crack (>= 0.3.2)
|
52
|
+
hashdiff
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
bundler (~> 1.16)
|
59
|
+
rake (~> 10.0)
|
60
|
+
rspec (~> 3.0)
|
61
|
+
rubocop (~> 0.52.0)
|
62
|
+
tikkie-api!
|
63
|
+
timecop (~> 0.9)
|
64
|
+
webmock (~> 2.3)
|
65
|
+
|
66
|
+
BUNDLED WITH
|
67
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Peter Postma
|
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,150 @@
|
|
1
|
+
# Tikkie API
|
2
|
+
|
3
|
+
Unofficial Ruby library for communicating with the [Tikkie API](https://developer.abnamro.com/content/tikkie).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'tikkie-api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install tikkie-api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Initialization
|
24
|
+
|
25
|
+
First create a Tikkie configuration and specify your API key and the path to your private RSA key. See also the [developer documentation from ABN AMRO](https://developer.abnamro.com/get-started) to get started.
|
26
|
+
|
27
|
+
Use the configuration to initialize a Tikkie client:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'tikkie/api'
|
31
|
+
|
32
|
+
config = Tikkie::Api::Configuration.new("your_api_key", "private_rsa.pem")
|
33
|
+
client = Tikkie::Api::Client.new(config)
|
34
|
+
```
|
35
|
+
|
36
|
+
### Platforms
|
37
|
+
|
38
|
+
Retrieve all platforms:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
platforms = client.platforms.list
|
42
|
+
```
|
43
|
+
|
44
|
+
Create a new platform:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
platform = client.platforms.create(
|
48
|
+
name: "Kentaa",
|
49
|
+
phone_number: "0601234567",
|
50
|
+
platform_usage: Tikkie::Api::Types::PlatformUsage::FOR_MYSELF,
|
51
|
+
email: "info@kentaa.nl", # optional
|
52
|
+
notification_url: "https://kentaa.nl/tikkie" # optional
|
53
|
+
)
|
54
|
+
|
55
|
+
platform_token = platform.platform_token
|
56
|
+
```
|
57
|
+
|
58
|
+
### Users
|
59
|
+
|
60
|
+
Retrieve all users for a platform:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
users = client.users.list("platform_token")
|
64
|
+
```
|
65
|
+
|
66
|
+
Create a new user for a platform:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
user = client.users.create("platform_token",
|
70
|
+
name: "Kentaa",
|
71
|
+
phone_number: "0601234567",
|
72
|
+
iban: "NL02ABNA0123456789",
|
73
|
+
bank_account_label: "Personal account"
|
74
|
+
)
|
75
|
+
|
76
|
+
user_token = user.user_token
|
77
|
+
bank_account_token = user.bank_accounts.first.bank_account_token
|
78
|
+
```
|
79
|
+
|
80
|
+
### Payment requests
|
81
|
+
|
82
|
+
Retrieve all payment requests for a user on a platform:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
payment_requests = client.payment_requests.list("platform_token", "user_token")
|
86
|
+
```
|
87
|
+
|
88
|
+
The payments requests response is paginated. You can use the method `more_elements?` to determine if there's more data to retrieve. In the next request, set the `offset` parameter to the new offset using the method `next_offset` from the previous response. For example:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
response = client.payment_requests.list("platform_token", "user_token")
|
92
|
+
payment_requests = response.to_a
|
93
|
+
|
94
|
+
while response.more_elements?
|
95
|
+
response = client.payment_requests.list("platform_token", "user_token", offset: response.next_offset)
|
96
|
+
payment_requests << response.to_a
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
To retrieve a single payment request:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
payment_request = client.payment_requests.get("platform_token", "user_token", "payment_request_token")
|
104
|
+
```
|
105
|
+
|
106
|
+
Create a new payment request for an existing user:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
payment_request = client.payment_requests.create("platform_token", "user_token", "bank_account_token",
|
110
|
+
amount: "5.00",
|
111
|
+
currency: "EUR",
|
112
|
+
description: "Test",
|
113
|
+
external_id: "Invoice 12345" # optional
|
114
|
+
)
|
115
|
+
|
116
|
+
tikkie_url = payment_request.payment_request_url
|
117
|
+
payment_request_token =payment_request.payment_request_token
|
118
|
+
```
|
119
|
+
|
120
|
+
### Error handling
|
121
|
+
|
122
|
+
All responses to an API request include the methods `success?` and `error?` to determine whether the API call was successful or not. When the API request was not successful, the method `errors` will return details about the error response.
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
payment_request = client.payment_requests.create("platform_token", "user_token", "bank_account_token", ...)
|
126
|
+
|
127
|
+
if payment_request.success?
|
128
|
+
# Success handling...
|
129
|
+
|
130
|
+
redirect_to payment_request.payment_request_url
|
131
|
+
else
|
132
|
+
# Error handling...
|
133
|
+
|
134
|
+
puts payment_request.errors
|
135
|
+
end
|
136
|
+
```
|
137
|
+
|
138
|
+
## Development
|
139
|
+
|
140
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
141
|
+
|
142
|
+
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).
|
143
|
+
|
144
|
+
## Contributing
|
145
|
+
|
146
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/KentaaNL/tikkie-api.
|
147
|
+
|
148
|
+
## License
|
149
|
+
|
150
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "tikkie/api"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/tikkie/api.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tikkie/api/access_token"
|
4
|
+
require "tikkie/api/authentication"
|
5
|
+
require "tikkie/api/client"
|
6
|
+
require "tikkie/api/configuration"
|
7
|
+
require "tikkie/api/exception"
|
8
|
+
require "tikkie/api/request"
|
9
|
+
require "tikkie/api/version"
|
10
|
+
|
11
|
+
require "tikkie/api/requests/payment_requests"
|
12
|
+
require "tikkie/api/requests/platforms"
|
13
|
+
require "tikkie/api/requests/users"
|
14
|
+
|
15
|
+
require "tikkie/api/responses/base"
|
16
|
+
require "tikkie/api/responses/bank_account"
|
17
|
+
require "tikkie/api/responses/error"
|
18
|
+
require "tikkie/api/responses/pagination"
|
19
|
+
require "tikkie/api/responses/payment_request_created"
|
20
|
+
require "tikkie/api/responses/payment_request"
|
21
|
+
require "tikkie/api/responses/payment_requests"
|
22
|
+
require "tikkie/api/responses/payment"
|
23
|
+
require "tikkie/api/responses/platform"
|
24
|
+
require "tikkie/api/responses/platforms"
|
25
|
+
require "tikkie/api/responses/user"
|
26
|
+
require "tikkie/api/responses/users"
|
27
|
+
|
28
|
+
require "tikkie/api/types/payment_request_status"
|
29
|
+
require "tikkie/api/types/payment_status"
|
30
|
+
require "tikkie/api/types/platform_status"
|
31
|
+
require "tikkie/api/types/platform_usage"
|
32
|
+
require "tikkie/api/types/user_status"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tikkie
|
4
|
+
module Api
|
5
|
+
# Access token that can be used to make API calls.
|
6
|
+
class AccessToken
|
7
|
+
attr_accessor :token
|
8
|
+
|
9
|
+
def initialize(token, expires_in)
|
10
|
+
@token = token
|
11
|
+
@expires_at = Time.now + expires_in.to_i
|
12
|
+
end
|
13
|
+
|
14
|
+
def expired?
|
15
|
+
Time.now > @expires_at
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'jwt'
|
5
|
+
require 'net/http'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
module Tikkie
|
9
|
+
module Api
|
10
|
+
# Provides authentication for the ABN AMRO OAuth API.
|
11
|
+
# see https://developer.abnamro.com/get-started#authentication
|
12
|
+
class Authentication
|
13
|
+
def initialize(config)
|
14
|
+
@config = config
|
15
|
+
end
|
16
|
+
|
17
|
+
def authenticate
|
18
|
+
uri = URI.parse(File.join(@config.api_url, "/oauth/token"))
|
19
|
+
|
20
|
+
request = Net::HTTP::Post.new(uri)
|
21
|
+
request["Api-Key"] = @config.api_key
|
22
|
+
|
23
|
+
request.set_form_data(
|
24
|
+
client_assertion: jwt_token,
|
25
|
+
client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
|
26
|
+
grant_type: "client_credentials",
|
27
|
+
scope: "tikkie"
|
28
|
+
)
|
29
|
+
|
30
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
31
|
+
http.request(request)
|
32
|
+
end
|
33
|
+
|
34
|
+
if response.is_a?(Net::HTTPSuccess)
|
35
|
+
json = JSON.parse(response.body, symbolize_names: true)
|
36
|
+
|
37
|
+
Tikkie::Api::AccessToken.new(json[:access_token], json[:expires_in])
|
38
|
+
else
|
39
|
+
raise Tikkie::Api::AuthenticationException, response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def jwt_token
|
46
|
+
now = Time.now.to_i
|
47
|
+
|
48
|
+
payload = {
|
49
|
+
nbf: now - 120,
|
50
|
+
exp: now + 120, # Token is valid for 2 minutes
|
51
|
+
iss: "Ruby Tikkie client",
|
52
|
+
sub: @config.api_key,
|
53
|
+
aud: @config.oauth_token_url
|
54
|
+
}
|
55
|
+
|
56
|
+
JWT.encode(payload, @config.private_data, @config.jwt_hashing_algorithm, typ: "JWT")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|