tikkie-api 0.1.0 → 2.0.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 +5 -5
- data/.rubocop.yml +31 -7
- data/.travis.yml +8 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +39 -33
- data/LICENSE.txt +1 -1
- data/README.md +211 -61
- 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 +4 -3
- metadata +69 -44
- data/lib/tikkie/api/access_token.rb +0 -19
- data/lib/tikkie/api/authentication.rb +0 -60
- data/lib/tikkie/api/requests/payment_requests.rb +0 -56
- 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 -53
- 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 -64
- 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 -30
- data/lib/tikkie/api/responses/user.rb +0 -39
- data/lib/tikkie/api/responses/users.rb +0 -34
- 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
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tikkie
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
# Base class for all resources.
|
7
|
+
class Base
|
8
|
+
attr_reader :config, :options
|
9
|
+
|
10
|
+
def initialize(config, options = {})
|
11
|
+
@config = config
|
12
|
+
@options = options
|
13
|
+
@body = options.delete(:body) if options.key?(:body)
|
14
|
+
end
|
15
|
+
|
16
|
+
def load
|
17
|
+
@response ||= load_resource
|
18
|
+
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def save(attributes = {})
|
23
|
+
@response = create_resource(attributes)
|
24
|
+
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete
|
29
|
+
delete_resource
|
30
|
+
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def loaded?
|
35
|
+
!@response.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def load_resource
|
41
|
+
raise NotImplementedError
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_resource
|
45
|
+
raise NotImplementedError
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete_resource
|
49
|
+
raise NotImplementedError
|
50
|
+
end
|
51
|
+
|
52
|
+
def body
|
53
|
+
@body ||= begin
|
54
|
+
load unless loaded?
|
55
|
+
|
56
|
+
@response.body
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def request
|
61
|
+
@request ||= Tikkie::Api::Request.new(config)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -2,9 +2,15 @@
|
|
2
2
|
|
3
3
|
module Tikkie
|
4
4
|
module Api
|
5
|
-
module
|
6
|
-
# Error
|
7
|
-
class Error
|
5
|
+
module Resources
|
6
|
+
# Error object in non-successful responses.
|
7
|
+
class Error
|
8
|
+
attr_reader :data
|
9
|
+
|
10
|
+
def initialize(data)
|
11
|
+
@data = data
|
12
|
+
end
|
13
|
+
|
8
14
|
def code
|
9
15
|
data[:code]
|
10
16
|
end
|
@@ -17,16 +23,12 @@ module Tikkie
|
|
17
23
|
data[:reference]
|
18
24
|
end
|
19
25
|
|
20
|
-
def trace_id
|
21
|
-
data[:traceId]
|
22
|
-
end
|
23
|
-
|
24
26
|
def status
|
25
27
|
data[:status]
|
26
28
|
end
|
27
29
|
|
28
|
-
def
|
29
|
-
data[:
|
30
|
+
def trace_id
|
31
|
+
data[:traceId]
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
module Tikkie
|
6
|
+
module Api
|
7
|
+
module Resources
|
8
|
+
# Base class for all list resources.
|
9
|
+
class List < Base
|
10
|
+
attr_reader :page_number, :page_size
|
11
|
+
|
12
|
+
def initialize(config, options = {})
|
13
|
+
@page_number = options.fetch(:page_number, 0)
|
14
|
+
@page_size = options.fetch(:page_size, 50)
|
15
|
+
super(config, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def total_elements
|
19
|
+
body[:totalElementCount].to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
def total_pages
|
23
|
+
(total_elements / BigDecimal(page_size)).ceil
|
24
|
+
end
|
25
|
+
|
26
|
+
def next_page
|
27
|
+
page_number + 1 if next_page?
|
28
|
+
end
|
29
|
+
|
30
|
+
def next_page?
|
31
|
+
page_number && (page_number + 1) < total_pages
|
32
|
+
end
|
33
|
+
|
34
|
+
def previous_page
|
35
|
+
page_number - 1 if previous_page?
|
36
|
+
end
|
37
|
+
|
38
|
+
def previous_page?
|
39
|
+
page_number && page_number.positive?
|
40
|
+
end
|
41
|
+
|
42
|
+
def next
|
43
|
+
self.class.new(config, options.merge(page_number: next_page)) if next_page?
|
44
|
+
end
|
45
|
+
|
46
|
+
def previous
|
47
|
+
self.class.new(config, options.merge(page_number: previous_page)) if previous_page?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Tikkie
|
6
|
+
module Api
|
7
|
+
module Resources
|
8
|
+
# Resource for a Payment.
|
9
|
+
class Payment < Base
|
10
|
+
attr_reader :payment_request_token
|
11
|
+
|
12
|
+
def initialize(config, options = {})
|
13
|
+
@payment_request_token = options.delete(:payment_request_token)
|
14
|
+
@payment_token = options.delete(:payment_token)
|
15
|
+
super(config, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def payment_token
|
19
|
+
@payment_token || body[:paymentToken]
|
20
|
+
end
|
21
|
+
|
22
|
+
def tikkie_id
|
23
|
+
body[:tikkieId]
|
24
|
+
end
|
25
|
+
|
26
|
+
def counter_party_name
|
27
|
+
body[:counterPartyName]
|
28
|
+
end
|
29
|
+
|
30
|
+
def counter_party_account_number
|
31
|
+
body[:counterPartyAccountNumber]
|
32
|
+
end
|
33
|
+
|
34
|
+
def amount
|
35
|
+
Tikkie::Api::Amount.from_cents(body[:amountInCents]).to_d
|
36
|
+
end
|
37
|
+
|
38
|
+
def description
|
39
|
+
body[:description]
|
40
|
+
end
|
41
|
+
|
42
|
+
def created_at
|
43
|
+
Time.parse(body[:createdDateTime]) if body[:createdDateTime]
|
44
|
+
end
|
45
|
+
|
46
|
+
def refunds
|
47
|
+
@refunds ||= begin
|
48
|
+
refunds = []
|
49
|
+
|
50
|
+
if body[:refunds]
|
51
|
+
body[:refunds].each do |refund|
|
52
|
+
refunds << Tikkie::Api::Resources::Refund.new(config, body: refund)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
refunds
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def load_resource
|
63
|
+
request.get("paymentrequests/#{payment_request_token}/payments/#{payment_token}", options)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Tikkie
|
6
|
+
module Api
|
7
|
+
module Resources
|
8
|
+
# Resource for a Payment Request.
|
9
|
+
class PaymentRequest < Base
|
10
|
+
STATUS_OPEN = "OPEN"
|
11
|
+
STATUS_CLOSED = "CLOSED"
|
12
|
+
STATUS_EXPIRED = "EXPIRED"
|
13
|
+
STATUS_MAX_YIELDED_REACHED = "MAX_YIELD_REACHED"
|
14
|
+
STATUS_MAX_SUCCESSFUL_PAYMENTS_REACHED = "MAX_SUCCESSFUL_PAYMENTS_REACHED"
|
15
|
+
|
16
|
+
def initialize(config, options = {})
|
17
|
+
@payment_request_token = options.delete(:payment_request_token)
|
18
|
+
super(config, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def payment_request_token
|
22
|
+
@payment_request_token || body[:paymentRequestToken]
|
23
|
+
end
|
24
|
+
|
25
|
+
def url
|
26
|
+
body[:url]
|
27
|
+
end
|
28
|
+
|
29
|
+
def amount
|
30
|
+
Tikkie::Api::Amount.from_cents(body[:amountInCents]).to_d
|
31
|
+
end
|
32
|
+
|
33
|
+
def description
|
34
|
+
body[:description]
|
35
|
+
end
|
36
|
+
|
37
|
+
def reference_id
|
38
|
+
body[:referenceId]
|
39
|
+
end
|
40
|
+
|
41
|
+
def created_at
|
42
|
+
Time.parse(body[:createdDateTime]) if body[:createdDateTime]
|
43
|
+
end
|
44
|
+
|
45
|
+
def expiry_date
|
46
|
+
Date.parse(body[:expiryDate]) if body[:expiryDate]
|
47
|
+
end
|
48
|
+
|
49
|
+
def status
|
50
|
+
body[:status]
|
51
|
+
end
|
52
|
+
|
53
|
+
def open?
|
54
|
+
status == STATUS_OPEN
|
55
|
+
end
|
56
|
+
|
57
|
+
def closed?
|
58
|
+
status == STATUS_CLOSED
|
59
|
+
end
|
60
|
+
|
61
|
+
def expired?
|
62
|
+
status == STATUS_EXPIRED
|
63
|
+
end
|
64
|
+
|
65
|
+
def number_of_payments
|
66
|
+
body[:numberOfPayments]
|
67
|
+
end
|
68
|
+
|
69
|
+
def total_amount_paid
|
70
|
+
Tikkie::Api::Amount.from_cents(body[:totalAmountPaidInCents]).to_d
|
71
|
+
end
|
72
|
+
|
73
|
+
def payments
|
74
|
+
@payments ||= Tikkie::Api::Resources::Payments.new(config, payment_request_token: payment_request_token)
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def load_resource
|
80
|
+
request.get("paymentrequests/#{payment_request_token}", options)
|
81
|
+
end
|
82
|
+
|
83
|
+
def create_resource(attributes)
|
84
|
+
params = { description: attributes.fetch(:description) }
|
85
|
+
if attributes.key?(:amount)
|
86
|
+
amount = Tikkie::Api::Amount.new(attributes[:amount])
|
87
|
+
params[:amountInCents] = amount.to_cents
|
88
|
+
end
|
89
|
+
params[:expiryDate] = attributes[:expiry_date].respond_to?(:strftime) ? attributes[:expiry_date].strftime("%F") : attributes[:expiry_date] if attributes.key?(:expiry_date)
|
90
|
+
params[:referenceId] = attributes[:reference_id] if attributes.key?(:reference_id)
|
91
|
+
|
92
|
+
request.post("paymentrequests", options, params)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tikkie
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
# Resource for Payment Requests.
|
7
|
+
class PaymentRequests < List
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
def each(&block)
|
11
|
+
payment_requests.each(&block)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def load_resource
|
17
|
+
params = { pageNumber: page_number, pageSize: page_size }
|
18
|
+
params[:fromDate] = options[:from_date].respond_to?(:utc) ? options[:from_date].utc.iso8601 : options[:from_date] if options.key?(:from_date)
|
19
|
+
params[:toDate] = options[:to_date].respond_to?(:utc) ? options[:to_date].utc.iso8601 : options[:to_date] if options.key?(:to_date)
|
20
|
+
|
21
|
+
request.get("paymentrequests", params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def payment_requests
|
25
|
+
@payment_requests ||= begin
|
26
|
+
payment_requests = []
|
27
|
+
|
28
|
+
if body[:paymentRequests]
|
29
|
+
body[:paymentRequests].each do |payment_request|
|
30
|
+
payment_requests << Tikkie::Api::Resources::PaymentRequest.new(config, body: payment_request)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
payment_requests
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tikkie
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
# Resource for a Payment Request Subscription.
|
7
|
+
class PaymentRequestsSubscription < Base
|
8
|
+
def subscription_id
|
9
|
+
body[:subscriptionId]
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def create_resource(attributes)
|
15
|
+
request.post("paymentrequestssubscription", options, attributes)
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete_resource
|
19
|
+
request.delete("paymentrequestssubscription", options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tikkie
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
# Resource for Payments.
|
7
|
+
class Payments < List
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
attr_reader :payment_request_token
|
11
|
+
|
12
|
+
def initialize(config, options = {})
|
13
|
+
@payment_request_token = options.delete(:payment_request_token)
|
14
|
+
super(config, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def each(&block)
|
18
|
+
payments.each(&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def load_resource
|
24
|
+
params = { pageNumber: page_number, pageSize: page_size }
|
25
|
+
params[:fromDate] = options[:from_date].respond_to?(:utc) ? options[:from_date].utc.iso8601 : options[:from_date] if options.key?(:from_date)
|
26
|
+
params[:toDate] = options[:to_date].respond_to?(:utc) ? options[:to_date].utc.iso8601 : options[:to_date] if options.key?(:to_date)
|
27
|
+
params[:includeRefunds] = options[:include_refunds] if options.key?(:include_refunds)
|
28
|
+
|
29
|
+
request.get("paymentrequests/#{payment_request_token}/payments", params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def payments
|
33
|
+
@payments ||= begin
|
34
|
+
payments = []
|
35
|
+
|
36
|
+
if body[:payments]
|
37
|
+
body[:payments].each do |payment|
|
38
|
+
payments << Tikkie::Api::Resources::Payment.new(config, body: payment)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
payments
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Tikkie
|
6
|
+
module Api
|
7
|
+
module Resources
|
8
|
+
# Resource for a Refund.
|
9
|
+
class Refund < Base
|
10
|
+
STATUS_PENDING = "PENDING"
|
11
|
+
STATUS_PAID = "PAID"
|
12
|
+
|
13
|
+
attr_reader :payment_request_token, :payment_token
|
14
|
+
|
15
|
+
def initialize(config, options = {})
|
16
|
+
@payment_request_token = options.delete(:payment_request_token)
|
17
|
+
@payment_token = options.delete(:payment_token)
|
18
|
+
@refund_token = options.delete(:refund_token)
|
19
|
+
super(config, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def refund_token
|
23
|
+
@refund_token || body[:refundToken]
|
24
|
+
end
|
25
|
+
|
26
|
+
def amount
|
27
|
+
Tikkie::Api::Amount.from_cents(body[:amountInCents]).to_d
|
28
|
+
end
|
29
|
+
|
30
|
+
def description
|
31
|
+
body[:description]
|
32
|
+
end
|
33
|
+
|
34
|
+
def reference_id
|
35
|
+
body[:referenceId]
|
36
|
+
end
|
37
|
+
|
38
|
+
def created_at
|
39
|
+
Time.parse(body[:createdDateTime]) if body[:createdDateTime]
|
40
|
+
end
|
41
|
+
|
42
|
+
def status
|
43
|
+
body[:status]
|
44
|
+
end
|
45
|
+
|
46
|
+
def pending?
|
47
|
+
status == STATUS_PENDING
|
48
|
+
end
|
49
|
+
|
50
|
+
def paid?
|
51
|
+
status == STATUS_PAID
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def load_resource
|
57
|
+
request.get("paymentrequests/#{payment_request_token}/payments/#{payment_token}/refunds/#{refund_token}", options)
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_resource(attributes)
|
61
|
+
params = { description: attributes.fetch(:description) }
|
62
|
+
amount = Tikkie::Api::Amount.new(attributes.fetch(:amount))
|
63
|
+
params[:amountInCents] = amount.to_cents
|
64
|
+
params[:referenceId] = attributes[:reference_id] if attributes.key?(:reference_id)
|
65
|
+
|
66
|
+
request.post("paymentrequests/#{payment_request_token}/payments/#{payment_token}/refunds", options, params)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|