tikkie-api 0.2.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -16
- data/.travis.yml +5 -5
- data/Gemfile +3 -2
- data/Gemfile.lock +23 -24
- data/LICENSE.txt +1 -1
- data/README.md +198 -69
- data/lib/tikkie/api.rb +52 -25
- data/lib/tikkie/api/amount.rb +35 -0
- data/lib/tikkie/api/client.rb +16 -8
- data/lib/tikkie/api/clients/base.rb +16 -0
- data/lib/tikkie/api/clients/payment_requests.rb +25 -0
- data/lib/tikkie/api/clients/payment_requests_subscription.rb +20 -0
- data/lib/tikkie/api/clients/payments.rb +20 -0
- data/lib/tikkie/api/clients/refunds.rb +20 -0
- data/lib/tikkie/api/clients/sandbox_apps.rb +15 -0
- data/lib/tikkie/api/configuration.rb +8 -47
- data/lib/tikkie/api/exception.rb +28 -8
- data/lib/tikkie/api/request.rb +51 -27
- data/lib/tikkie/api/resources/base.rb +66 -0
- data/lib/tikkie/api/{responses → resources}/error.rb +11 -9
- data/lib/tikkie/api/resources/list.rb +52 -0
- data/lib/tikkie/api/resources/payment.rb +68 -0
- data/lib/tikkie/api/resources/payment_request.rb +97 -0
- data/lib/tikkie/api/resources/payment_requests.rb +40 -0
- data/lib/tikkie/api/resources/payment_requests_subscription.rb +24 -0
- data/lib/tikkie/api/resources/payments.rb +48 -0
- data/lib/tikkie/api/resources/refund.rb +71 -0
- data/lib/tikkie/api/resources/sandbox_app.rb +20 -0
- data/lib/tikkie/api/response.rb +64 -0
- data/lib/tikkie/api/v1/access_token.rb +21 -0
- data/lib/tikkie/api/v1/authentication.rb +67 -0
- data/lib/tikkie/api/v1/client.rb +26 -0
- data/lib/tikkie/api/v1/configuration.rb +64 -0
- data/lib/tikkie/api/v1/exception.rb +24 -0
- data/lib/tikkie/api/v1/request.rb +59 -0
- data/lib/tikkie/api/v1/requests/payment_requests.rb +59 -0
- data/lib/tikkie/api/v1/requests/platforms.rb +34 -0
- data/lib/tikkie/api/v1/requests/users.rb +33 -0
- data/lib/tikkie/api/v1/responses/bank_account.rb +24 -0
- data/lib/tikkie/api/v1/responses/base.rb +69 -0
- data/lib/tikkie/api/v1/responses/error.rb +36 -0
- data/lib/tikkie/api/v1/responses/pagination.rb +22 -0
- data/lib/tikkie/api/v1/responses/payment.rb +50 -0
- data/lib/tikkie/api/v1/responses/payment_request.rb +68 -0
- data/lib/tikkie/api/v1/responses/payment_request_created.rb +24 -0
- data/lib/tikkie/api/v1/responses/payment_requests.rb +44 -0
- data/lib/tikkie/api/v1/responses/platform.rb +46 -0
- data/lib/tikkie/api/v1/responses/platforms.rb +34 -0
- data/lib/tikkie/api/v1/responses/user.rb +43 -0
- data/lib/tikkie/api/v1/responses/users.rb +38 -0
- data/lib/tikkie/api/v1/types/payment_request_status.rb +17 -0
- data/lib/tikkie/api/v1/types/payment_status.rb +16 -0
- data/lib/tikkie/api/v1/types/platform_status.rb +14 -0
- data/lib/tikkie/api/v1/types/platform_usage.rb +14 -0
- data/lib/tikkie/api/v1/types/user_status.rb +14 -0
- data/lib/tikkie/api/version.rb +1 -1
- data/lib/tikkie/notification.rb +23 -0
- data/lib/tikkie/notifications/bundle_notification.rb +28 -0
- data/lib/tikkie/notifications/payment_notification.rb +32 -0
- data/lib/tikkie/notifications/refund_notification.rb +36 -0
- data/tikkie-api.gemspec +3 -2
- metadata +69 -43
- data/lib/tikkie/api/access_token.rb +0 -19
- data/lib/tikkie/api/authentication.rb +0 -65
- data/lib/tikkie/api/requests/payment_requests.rb +0 -57
- data/lib/tikkie/api/requests/platforms.rb +0 -32
- data/lib/tikkie/api/requests/users.rb +0 -31
- data/lib/tikkie/api/responses/bank_account.rb +0 -22
- data/lib/tikkie/api/responses/base.rb +0 -67
- data/lib/tikkie/api/responses/pagination.rb +0 -20
- data/lib/tikkie/api/responses/payment.rb +0 -48
- data/lib/tikkie/api/responses/payment_request.rb +0 -66
- data/lib/tikkie/api/responses/payment_request_created.rb +0 -22
- data/lib/tikkie/api/responses/payment_requests.rb +0 -42
- data/lib/tikkie/api/responses/platform.rb +0 -44
- data/lib/tikkie/api/responses/platforms.rb +0 -32
- data/lib/tikkie/api/responses/user.rb +0 -41
- data/lib/tikkie/api/responses/users.rb +0 -36
- data/lib/tikkie/api/types/payment_request_status.rb +0 -15
- data/lib/tikkie/api/types/payment_status.rb +0 -14
- data/lib/tikkie/api/types/platform_status.rb +0 -12
- data/lib/tikkie/api/types/platform_usage.rb +0 -12
- data/lib/tikkie/api/types/user_status.rb +0 -12
@@ -1,19 +0,0 @@
|
|
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
|
@@ -1,65 +0,0 @@
|
|
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
|
-
# Send header typ as String, not symbol (JWT version 1.x adds "typ" as String by default).
|
57
|
-
headers = {
|
58
|
-
"typ" => "JWT"
|
59
|
-
}
|
60
|
-
|
61
|
-
JWT.encode(payload, @config.private_data, @config.jwt_hashing_algorithm, headers)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bigdecimal'
|
4
|
-
|
5
|
-
module Tikkie
|
6
|
-
module Api
|
7
|
-
module Requests
|
8
|
-
# Payment requests operations at Tikkie.
|
9
|
-
class PaymentRequests
|
10
|
-
def initialize(request)
|
11
|
-
@request = request
|
12
|
-
end
|
13
|
-
|
14
|
-
def list(platform_token, user_token, options = {})
|
15
|
-
offset = options[:offset] || 0
|
16
|
-
limit = options[:limit] || 20
|
17
|
-
from_date = options[:from_date]
|
18
|
-
to_date = options[:to_date]
|
19
|
-
|
20
|
-
params = { offset: offset, limit: limit }
|
21
|
-
params[:fromDate] = from_date.respond_to?(:utc) ? from_date.utc.iso8601 : from_date if from_date
|
22
|
-
params[:toDate] = to_date.respond_to?(:utc) ? to_date.utc.iso8601 : to_date if to_date
|
23
|
-
|
24
|
-
response = @request.get("/tikkie/platforms/#{platform_token}/users/#{user_token}/paymentrequests", params)
|
25
|
-
Tikkie::Api::Responses::PaymentRequests.new(response, offset: offset, limit: limit)
|
26
|
-
end
|
27
|
-
|
28
|
-
def get(platform_token, user_token, payment_request_token)
|
29
|
-
response = @request.get("/tikkie/platforms/#{platform_token}/users/#{user_token}/paymentrequests/#{payment_request_token}")
|
30
|
-
|
31
|
-
Tikkie::Api::Responses::PaymentRequest.new(response)
|
32
|
-
end
|
33
|
-
|
34
|
-
def create(platform_token, user_token, bank_account_token, options = {})
|
35
|
-
params = {
|
36
|
-
currency: options.fetch(:currency),
|
37
|
-
description: options.fetch(:description)
|
38
|
-
}
|
39
|
-
params[:amountInCents] = to_cents(options[:amount]) if options.key?(:amount)
|
40
|
-
params[:externalId] = options[:external_id] if options.key?(:external_id)
|
41
|
-
|
42
|
-
response = @request.post("/tikkie/platforms/#{platform_token}/users/#{user_token}/bankaccounts/#{bank_account_token}/paymentrequests", params)
|
43
|
-
|
44
|
-
Tikkie::Api::Responses::PaymentRequestCreated.new(response)
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def to_cents(amount)
|
50
|
-
decimal = BigDecimal(amount.to_s)
|
51
|
-
decimal *= 100 # to cents
|
52
|
-
decimal.to_i
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tikkie
|
4
|
-
module Api
|
5
|
-
module Requests
|
6
|
-
# Platforms operations at Tikkie.
|
7
|
-
class Platforms
|
8
|
-
def initialize(request)
|
9
|
-
@request = request
|
10
|
-
end
|
11
|
-
|
12
|
-
def list
|
13
|
-
response = @request.get("/tikkie/platforms")
|
14
|
-
Tikkie::Api::Responses::Platforms.new(response)
|
15
|
-
end
|
16
|
-
|
17
|
-
def create(options = {})
|
18
|
-
params = {
|
19
|
-
name: options.fetch(:name),
|
20
|
-
phoneNumber: options.fetch(:phone_number),
|
21
|
-
platformUsage: options.fetch(:platform_usage),
|
22
|
-
email: options[:email],
|
23
|
-
notificationUrl: options[:notification_url]
|
24
|
-
}
|
25
|
-
response = @request.post("/tikkie/platforms", params)
|
26
|
-
|
27
|
-
Tikkie::Api::Responses::Platform.new(response)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tikkie
|
4
|
-
module Api
|
5
|
-
module Requests
|
6
|
-
# Users operations at Tikkie.
|
7
|
-
class Users
|
8
|
-
def initialize(request)
|
9
|
-
@request = request
|
10
|
-
end
|
11
|
-
|
12
|
-
def list(platform_token)
|
13
|
-
response = @request.get("/tikkie/platforms/#{platform_token}/users")
|
14
|
-
Tikkie::Api::Responses::Users.new(response)
|
15
|
-
end
|
16
|
-
|
17
|
-
def create(platform_token, options = {})
|
18
|
-
params = {
|
19
|
-
name: options.fetch(:name),
|
20
|
-
phoneNumber: options.fetch(:phone_number),
|
21
|
-
iban: options.fetch(:iban),
|
22
|
-
bankAccountLabel: options.fetch(:bank_account_label)
|
23
|
-
}
|
24
|
-
response = @request.post("/tikkie/platforms/#{platform_token}/users", params)
|
25
|
-
|
26
|
-
Tikkie::Api::Responses::User.new(response)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tikkie
|
4
|
-
module Api
|
5
|
-
module Responses
|
6
|
-
# Bank account of a user.
|
7
|
-
class BankAccount < Base
|
8
|
-
def bank_account_token
|
9
|
-
data[:bankAccountToken]
|
10
|
-
end
|
11
|
-
|
12
|
-
def bank_account_label
|
13
|
-
data[:bankAccountLabel]
|
14
|
-
end
|
15
|
-
|
16
|
-
def iban
|
17
|
-
data[:iban]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module Tikkie
|
6
|
-
module Api
|
7
|
-
module Responses
|
8
|
-
# Base class for all responses.
|
9
|
-
class Base
|
10
|
-
attr_reader :response, :data
|
11
|
-
|
12
|
-
def initialize(response)
|
13
|
-
if response.respond_to?(:body)
|
14
|
-
@response = response
|
15
|
-
@data = parse_body(response.body)
|
16
|
-
else
|
17
|
-
@data = response
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def response_code
|
22
|
-
response.code.to_i if response
|
23
|
-
end
|
24
|
-
|
25
|
-
def success?
|
26
|
-
(response_code == 200 || response_code == 201) && !@invalid
|
27
|
-
end
|
28
|
-
|
29
|
-
def error?
|
30
|
-
!success?
|
31
|
-
end
|
32
|
-
|
33
|
-
def trace_id
|
34
|
-
response["Trace-Id"] if response
|
35
|
-
end
|
36
|
-
|
37
|
-
def errors
|
38
|
-
@errors ||= begin
|
39
|
-
errors = []
|
40
|
-
|
41
|
-
if data[:errors]
|
42
|
-
data[:errors].each do |error|
|
43
|
-
errors << Tikkie::Api::Responses::Error.new(error)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
errors
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def parse_body(body)
|
54
|
-
body = body.respond_to?(:read) ? body.read : body
|
55
|
-
|
56
|
-
JSON.parse(body, symbolize_names: true)
|
57
|
-
rescue JSON::ParserError => ex
|
58
|
-
@invalid = true
|
59
|
-
|
60
|
-
{
|
61
|
-
message: "Unable to parse JSON: #{ex.message}"
|
62
|
-
}
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tikkie
|
4
|
-
module Api
|
5
|
-
module Responses
|
6
|
-
# Helper for paginated responses.
|
7
|
-
module Pagination
|
8
|
-
attr_accessor :offset, :limit, :elements, :total_elements
|
9
|
-
|
10
|
-
def more_elements?
|
11
|
-
@total_elements && @total_elements > @offset + @elements
|
12
|
-
end
|
13
|
-
|
14
|
-
def next_offset
|
15
|
-
@offset + @limit if more_elements?
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bigdecimal'
|
4
|
-
require 'time'
|
5
|
-
|
6
|
-
module Tikkie
|
7
|
-
module Api
|
8
|
-
module Responses
|
9
|
-
# Payment that is associated with a payment request.
|
10
|
-
class Payment < Base
|
11
|
-
def payment_token
|
12
|
-
data[:paymentToken]
|
13
|
-
end
|
14
|
-
|
15
|
-
def counter_party_name
|
16
|
-
data[:counterPartyName]
|
17
|
-
end
|
18
|
-
|
19
|
-
def amount
|
20
|
-
decimal = BigDecimal(data[:amountInCents])
|
21
|
-
decimal /= 100.0
|
22
|
-
decimal
|
23
|
-
end
|
24
|
-
|
25
|
-
def currency
|
26
|
-
data[:amountCurrency]
|
27
|
-
end
|
28
|
-
|
29
|
-
def description
|
30
|
-
data[:description]
|
31
|
-
end
|
32
|
-
|
33
|
-
def created_at
|
34
|
-
Time.parse(data[:created]) if data[:created]
|
35
|
-
end
|
36
|
-
|
37
|
-
# See PaymentStatus
|
38
|
-
def online_payment_status
|
39
|
-
data[:onlinePaymentStatus]
|
40
|
-
end
|
41
|
-
|
42
|
-
def paid?
|
43
|
-
online_payment_status == Tikkie::Api::Types::PaymentStatus::PAID
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bigdecimal'
|
4
|
-
require 'time'
|
5
|
-
|
6
|
-
module Tikkie
|
7
|
-
module Api
|
8
|
-
module Responses
|
9
|
-
# Response for a payment request.
|
10
|
-
class PaymentRequest < Base
|
11
|
-
def payment_request_token
|
12
|
-
data[:paymentRequestToken]
|
13
|
-
end
|
14
|
-
|
15
|
-
def amount
|
16
|
-
decimal = BigDecimal(data[:amountInCents])
|
17
|
-
decimal /= 100.0
|
18
|
-
decimal
|
19
|
-
end
|
20
|
-
|
21
|
-
def currency
|
22
|
-
data[:currency]
|
23
|
-
end
|
24
|
-
|
25
|
-
def created_at
|
26
|
-
Time.parse(data[:created]) if data[:created]
|
27
|
-
end
|
28
|
-
|
29
|
-
def expired_at
|
30
|
-
Time.parse(data[:expired]) if data[:expired]
|
31
|
-
end
|
32
|
-
|
33
|
-
# see PaymentRequestStatus
|
34
|
-
def status
|
35
|
-
data[:status]
|
36
|
-
end
|
37
|
-
|
38
|
-
def expired?
|
39
|
-
status == Tikkie::Api::Types::PaymentRequestStatus::EXPIRED
|
40
|
-
end
|
41
|
-
|
42
|
-
def bank_account_yielded_too_fast?
|
43
|
-
data[:bankAccountYieldedTooFast]
|
44
|
-
end
|
45
|
-
|
46
|
-
def external_id
|
47
|
-
data[:externalId]
|
48
|
-
end
|
49
|
-
|
50
|
-
def payments
|
51
|
-
@payments ||= begin
|
52
|
-
payments = []
|
53
|
-
|
54
|
-
if data[:payments]
|
55
|
-
data[:payments].each do |data|
|
56
|
-
payments << Tikkie::Api::Responses::Payment.new(data)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
payments
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tikkie
|
4
|
-
module Api
|
5
|
-
module Responses
|
6
|
-
# Response when creating a payment request.
|
7
|
-
class PaymentRequestCreated < Base
|
8
|
-
def payment_request_url
|
9
|
-
data[:paymentRequestUrl]
|
10
|
-
end
|
11
|
-
|
12
|
-
def payment_request_token
|
13
|
-
data[:paymentRequestToken]
|
14
|
-
end
|
15
|
-
|
16
|
-
def external_id
|
17
|
-
data[:externalId]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|