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.
Files changed (84) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +31 -7
  3. data/.travis.yml +8 -4
  4. data/Gemfile +3 -1
  5. data/Gemfile.lock +39 -33
  6. data/LICENSE.txt +1 -1
  7. data/README.md +211 -61
  8. data/lib/tikkie/api.rb +52 -25
  9. data/lib/tikkie/api/amount.rb +35 -0
  10. data/lib/tikkie/api/client.rb +16 -8
  11. data/lib/tikkie/api/clients/base.rb +16 -0
  12. data/lib/tikkie/api/clients/payment_requests.rb +25 -0
  13. data/lib/tikkie/api/clients/payment_requests_subscription.rb +20 -0
  14. data/lib/tikkie/api/clients/payments.rb +20 -0
  15. data/lib/tikkie/api/clients/refunds.rb +20 -0
  16. data/lib/tikkie/api/clients/sandbox_apps.rb +15 -0
  17. data/lib/tikkie/api/configuration.rb +8 -47
  18. data/lib/tikkie/api/exception.rb +28 -8
  19. data/lib/tikkie/api/request.rb +51 -27
  20. data/lib/tikkie/api/resources/base.rb +66 -0
  21. data/lib/tikkie/api/{responses → resources}/error.rb +11 -9
  22. data/lib/tikkie/api/resources/list.rb +52 -0
  23. data/lib/tikkie/api/resources/payment.rb +68 -0
  24. data/lib/tikkie/api/resources/payment_request.rb +97 -0
  25. data/lib/tikkie/api/resources/payment_requests.rb +40 -0
  26. data/lib/tikkie/api/resources/payment_requests_subscription.rb +24 -0
  27. data/lib/tikkie/api/resources/payments.rb +48 -0
  28. data/lib/tikkie/api/resources/refund.rb +71 -0
  29. data/lib/tikkie/api/resources/sandbox_app.rb +20 -0
  30. data/lib/tikkie/api/response.rb +64 -0
  31. data/lib/tikkie/api/v1/access_token.rb +21 -0
  32. data/lib/tikkie/api/v1/authentication.rb +67 -0
  33. data/lib/tikkie/api/v1/client.rb +26 -0
  34. data/lib/tikkie/api/v1/configuration.rb +64 -0
  35. data/lib/tikkie/api/v1/exception.rb +24 -0
  36. data/lib/tikkie/api/v1/request.rb +59 -0
  37. data/lib/tikkie/api/v1/requests/payment_requests.rb +59 -0
  38. data/lib/tikkie/api/v1/requests/platforms.rb +34 -0
  39. data/lib/tikkie/api/v1/requests/users.rb +33 -0
  40. data/lib/tikkie/api/v1/responses/bank_account.rb +24 -0
  41. data/lib/tikkie/api/v1/responses/base.rb +69 -0
  42. data/lib/tikkie/api/v1/responses/error.rb +36 -0
  43. data/lib/tikkie/api/v1/responses/pagination.rb +22 -0
  44. data/lib/tikkie/api/v1/responses/payment.rb +50 -0
  45. data/lib/tikkie/api/v1/responses/payment_request.rb +68 -0
  46. data/lib/tikkie/api/v1/responses/payment_request_created.rb +24 -0
  47. data/lib/tikkie/api/v1/responses/payment_requests.rb +44 -0
  48. data/lib/tikkie/api/v1/responses/platform.rb +46 -0
  49. data/lib/tikkie/api/v1/responses/platforms.rb +34 -0
  50. data/lib/tikkie/api/v1/responses/user.rb +43 -0
  51. data/lib/tikkie/api/v1/responses/users.rb +38 -0
  52. data/lib/tikkie/api/v1/types/payment_request_status.rb +17 -0
  53. data/lib/tikkie/api/v1/types/payment_status.rb +16 -0
  54. data/lib/tikkie/api/v1/types/platform_status.rb +14 -0
  55. data/lib/tikkie/api/v1/types/platform_usage.rb +14 -0
  56. data/lib/tikkie/api/v1/types/user_status.rb +14 -0
  57. data/lib/tikkie/api/version.rb +1 -1
  58. data/lib/tikkie/notification.rb +23 -0
  59. data/lib/tikkie/notifications/bundle_notification.rb +28 -0
  60. data/lib/tikkie/notifications/payment_notification.rb +32 -0
  61. data/lib/tikkie/notifications/refund_notification.rb +36 -0
  62. data/tikkie-api.gemspec +4 -3
  63. metadata +69 -44
  64. data/lib/tikkie/api/access_token.rb +0 -19
  65. data/lib/tikkie/api/authentication.rb +0 -60
  66. data/lib/tikkie/api/requests/payment_requests.rb +0 -56
  67. data/lib/tikkie/api/requests/platforms.rb +0 -32
  68. data/lib/tikkie/api/requests/users.rb +0 -31
  69. data/lib/tikkie/api/responses/bank_account.rb +0 -22
  70. data/lib/tikkie/api/responses/base.rb +0 -53
  71. data/lib/tikkie/api/responses/pagination.rb +0 -20
  72. data/lib/tikkie/api/responses/payment.rb +0 -48
  73. data/lib/tikkie/api/responses/payment_request.rb +0 -64
  74. data/lib/tikkie/api/responses/payment_request_created.rb +0 -22
  75. data/lib/tikkie/api/responses/payment_requests.rb +0 -42
  76. data/lib/tikkie/api/responses/platform.rb +0 -44
  77. data/lib/tikkie/api/responses/platforms.rb +0 -30
  78. data/lib/tikkie/api/responses/user.rb +0 -39
  79. data/lib/tikkie/api/responses/users.rb +0 -34
  80. data/lib/tikkie/api/types/payment_request_status.rb +0 -15
  81. data/lib/tikkie/api/types/payment_status.rb +0 -14
  82. data/lib/tikkie/api/types/platform_status.rb +0 -12
  83. data/lib/tikkie/api/types/platform_usage.rb +0 -12
  84. data/lib/tikkie/api/types/user_status.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c0fb0212ecabd850a104349b9edff3fc279c90f9
4
- data.tar.gz: dbce2933f3a3b0750f385d1c74bb53f232256824
2
+ SHA256:
3
+ metadata.gz: c22db51585d284e809e24912acf561c023f9063da1669fdc49330dd223039f32
4
+ data.tar.gz: e7bf5498e81def5bbf47efa0800d9bb8dc1248cb154df1b227004ab7b2fc80f0
5
5
  SHA512:
6
- metadata.gz: ed9a6a3f22a00360a990527fe9700c07ad68795db7bf2474523703467726aec375bb537d7dfb766bc0fe480b7bce1a74a38cc11bab7108d8b1a50fa62dd587f9
7
- data.tar.gz: c60da0bf7f3b15499ea768389527161e0acaec5b4bbbcfc0f636862966a37406d2ef46a091c47c7b2d9539ca33c28a2c961c47a61c4bdcf4b4d2f59dba5899e0
6
+ metadata.gz: 1c99bc7d78ed22482810d6f12042fe0497ed298cee190c5a73404d9028ab408cf4770ad8650a6cab6bbe4b42b78c852b2e877fcdedc77c7d5a3ce5f778a1373b
7
+ data.tar.gz: b48d40c3a519e24a83582e5ccc1c66f882d09d16a5090f1ac628c4610c5c9e75ee2c5a8442d360adf13a60becf1f182424fe401186e2a07710e0004e37ea977c
@@ -1,29 +1,53 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
1
5
  AllCops:
2
- TargetRubyVersion: 2.3
6
+ TargetRubyVersion: 2.4
3
7
  DisplayCopNames: true
4
8
  DisplayStyleGuide: true
9
+ Exclude:
10
+ - 'lib/tikkie/api/v1/**/*'
11
+ - 'spec/tikkie/api/v1/**/*'
12
+ - 'vendor/**/*'
13
+
14
+
15
+ Layout/LineLength:
16
+ Enabled: false
17
+
5
18
 
6
19
  Metrics/AbcSize:
7
- Max: 21
20
+ Max: 43
8
21
 
9
22
  Metrics/BlockLength:
10
23
  Exclude:
11
24
  - 'spec/**/*'
12
25
 
13
26
  Metrics/CyclomaticComplexity:
14
- Max: 7
15
-
16
- Metrics/LineLength:
17
- Enabled: false
27
+ Max: 11
18
28
 
19
29
  Metrics/MethodLength:
20
30
  Enabled: false
21
31
 
32
+ Metrics/PerceivedComplexity:
33
+ Max: 9
34
+
35
+
36
+ RSpec/DescribedClass:
37
+ EnforcedStyle: explicit
38
+
39
+ RSpec/ExampleLength:
40
+ Max: 12
41
+
42
+ RSpec/MultipleExpectations:
43
+ Max: 8
44
+
45
+
22
46
  Style/Documentation:
23
47
  Exclude:
24
48
  - 'spec/**/*'
25
49
 
26
- Style/GuardClause:
50
+ Style/FormatStringToken:
27
51
  Enabled: false
28
52
 
29
53
  Style/SafeNavigation:
@@ -1,7 +1,11 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ cache: bundler
4
+ before_install:
5
+ - gem update --system
6
+ - gem install bundler -v '< 2'
3
7
  rvm:
4
- - 2.2.9
5
- - 2.3.6
6
- - 2.4.3
7
- before_install: gem install bundler -v 1.16.1
8
+ - 2.4.10
9
+ - 2.5.8
10
+ - 2.6.6
11
+ - 2.7.2
data/Gemfile CHANGED
@@ -7,4 +7,6 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
7
7
  # Specify your gem's dependencies in tikkie-api.gemspec
8
8
  gemspec
9
9
 
10
- gem 'rubocop', '~> 0.52.0'
10
+ gem 'rubocop', '~> 0.79.0'
11
+ gem 'rubocop-performance', '~> 1.6.1'
12
+ gem 'rubocop-rspec', '~> 1.41.0'
@@ -1,51 +1,54 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tikkie-api (0.1.0)
5
- jwt (>= 1.0)
4
+ tikkie-api (2.0.0)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
9
8
  specs:
10
- addressable (2.5.2)
9
+ addressable (2.6.0)
11
10
  public_suffix (>= 2.0.2, < 4.0)
12
- ast (2.3.0)
11
+ ast (2.4.1)
13
12
  crack (0.4.3)
14
13
  safe_yaml (~> 1.0.0)
15
14
  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)
15
+ hashdiff (0.3.8)
16
+ jaro_winkler (1.5.4)
17
+ jwt (2.2.2)
18
+ parallel (1.19.2)
19
+ parser (2.7.2.0)
20
+ ast (~> 2.4.1)
21
+ public_suffix (3.0.3)
23
22
  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)
23
+ rake (13.0.1)
24
+ rspec (3.8.0)
25
+ rspec-core (~> 3.8.0)
26
+ rspec-expectations (~> 3.8.0)
27
+ rspec-mocks (~> 3.8.0)
28
+ rspec-core (3.8.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-expectations (3.8.2)
32
31
  diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.7.0)
34
- rspec-mocks (3.7.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-mocks (3.8.0)
35
34
  diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.7.0)
37
- rspec-support (3.7.0)
38
- rubocop (0.52.1)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-support (3.8.0)
37
+ rubocop (0.79.0)
38
+ jaro_winkler (~> 1.5.1)
39
39
  parallel (~> 1.10)
40
- parser (>= 2.4.0.2, < 3.0)
41
- powerpack (~> 0.1)
40
+ parser (>= 2.7.0.1)
42
41
  rainbow (>= 2.2.2, < 4.0)
43
42
  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)
43
+ unicode-display_width (>= 1.4.0, < 1.7)
44
+ rubocop-performance (1.6.1)
45
+ rubocop (>= 0.71.0)
46
+ rubocop-rspec (1.41.0)
47
+ rubocop (>= 0.68.1)
48
+ ruby-progressbar (1.10.1)
49
+ safe_yaml (1.0.5)
47
50
  timecop (0.9.1)
48
- unicode-display_width (1.3.0)
51
+ unicode-display_width (1.6.1)
49
52
  webmock (2.3.2)
50
53
  addressable (>= 2.3.6)
51
54
  crack (>= 0.3.2)
@@ -56,12 +59,15 @@ PLATFORMS
56
59
 
57
60
  DEPENDENCIES
58
61
  bundler (~> 1.16)
59
- rake (~> 10.0)
62
+ jwt (>= 1.0)
63
+ rake (~> 13.0)
60
64
  rspec (~> 3.0)
61
- rubocop (~> 0.52.0)
65
+ rubocop (~> 0.79.0)
66
+ rubocop-performance (~> 1.6.1)
67
+ rubocop-rspec (~> 1.41.0)
62
68
  tikkie-api!
63
69
  timecop (~> 0.9)
64
70
  webmock (~> 2.3)
65
71
 
66
72
  BUNDLED WITH
67
- 1.16.1
73
+ 1.17.3
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 Peter Postma
3
+ Copyright (c) 2018-2020 Kentaa BV
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,13 +1,44 @@
1
1
  # Tikkie API
2
2
 
3
- Unofficial Ruby library for communicating with the [Tikkie API](https://developer.abnamro.com/content/tikkie).
3
+ [![Gem Version](https://badge.fury.io/rb/tikkie-api.svg)](https://badge.fury.io/rb/tikkie-api)
4
+ [![Build Status](https://travis-ci.org/KentaaNL/tikkie-api.svg?branch=master)](https://travis-ci.org/KentaaNL/tikkie-api)
5
+ [![Code Climate](https://codeclimate.com/github/KentaaNL/tikkie-api/badges/gpa.svg)](https://codeclimate.com/github/KentaaNL/tikkie-api)
6
+
7
+ Unofficial Ruby library for communicating with the [Tikkie API](https://developer.abnamro.com/api-products/tikkie).
8
+
9
+ ## Table of Contents
10
+
11
+ - [Installation](#installation)
12
+ - [Usage](#usage)
13
+ - [Payment requests](#payment-requests)
14
+ - [Create a Payment request](#create-a-payment-request)
15
+ - [List Payment requests](#list-payment-requests)
16
+ - [Get Payment request](#get-payment-request)
17
+ - [Payments](#payments)
18
+ - [List Payments](#list-payments)
19
+ - [Get Payment](#get-payment)
20
+ - [Refunds](#refunds)
21
+ - [Create a Refund](#create-a-refund)
22
+ - [Get Refund](#get-refund)
23
+ - [Payment requests notification](#payment-requests-notification)
24
+ - [Create a subscription](#create-a-subscription)
25
+ - [Delete subscription](#delete-subscription)
26
+ - [Sandbox apps](#sandbox-apps)
27
+ - [Create a Sandbox app](#create-a-sandbox-app)
28
+ - [Error handling](#error-handling)
29
+ - [Notifications](#notifications)
30
+ - [API support](#api-support)
31
+ - [Development](#development)
32
+ - [Contributing](#contributing)
33
+ - [License](#license)
34
+
4
35
 
5
36
  ## Installation
6
37
 
7
38
  Add this line to your application's Gemfile:
8
39
 
9
40
  ```ruby
10
- gem 'tikkie-api'
41
+ gem 'tikkie-api', '~> 2.0'
11
42
  ```
12
43
 
13
44
  And then execute:
@@ -20,121 +51,240 @@ Or install it yourself as:
20
51
 
21
52
  ## Usage
22
53
 
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:
54
+ Create a Tikkie client using your API key and an App token. If you don't have an App token yet, please read the [documentation about App tokens](https://developer.abnamro.com/api-products/tikkie/reference-documentation#section/Overview/App-token) or use the [Sandbox apps endpoint](#sandbox-apps) to create an App token in the sandbox environment.
28
55
 
29
56
  ```ruby
30
57
  require 'tikkie/api'
31
58
 
32
- config = Tikkie::Api::Configuration.new("your_api_key", "private_rsa.pem")
33
- client = Tikkie::Api::Client.new(config)
59
+ client = Tikkie::Api::Client.new(api_key: "12345", app_token: "abcdef")
34
60
  ```
35
61
 
36
- ### Platforms
37
-
38
- Retrieve all platforms:
62
+ The client is created for the production environment by default. If you want to use the sandbox environment, then add `sandbox: true`:
39
63
 
40
64
  ```ruby
41
- platforms = client.platforms.list
65
+ client = Tikkie::Api::Client.new(api_key: "12345", app_token: "abcdef", sandbox: true)
42
66
  ```
43
67
 
44
- Create a new platform:
68
+ ### Payment requests
69
+
70
+ #### Create a Payment request
71
+
72
+ Creates a new payment request. When the parameter `amount` is omitted, it will create a payment request with an open amount, where the payer can decide on the amount.
45
73
 
46
74
  ```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
75
+ payment_request = client.payment_requests.create(
76
+ description: "Test", # mandatory
77
+ amount: "12.50",
78
+ expiry_date: "2021-01-01",
79
+ reference_id: "Invoice 12345"
53
80
  )
54
81
 
55
- platform_token = platform.platform_token
82
+ payment_request.payment_request_token # => "qzdnzr8hnVWTgXXcFRLUMc"
83
+ payment_request.url # => "https://tikkie.me/pay/Tikkie/qzdnzr8hnVWTgXXcFRLUMc"
84
+ payment_request.amount # => BigDecimal("12.50")
56
85
  ```
57
86
 
58
- ### Users
87
+ See [Tikkie::Api::Resources::PaymentRequest](lib/tikkie/api/resources/payment_request.rb) for all available properties.
59
88
 
60
- Retrieve all users for a platform:
89
+ #### List Payment requests
90
+
91
+ Retrieves all payment requests.
61
92
 
62
93
  ```ruby
63
- users = client.users.list("platform_token")
94
+ payment_requests = client.payment_requests.list
64
95
  ```
65
96
 
66
- Create a new user for a platform:
97
+ The payments requests response is paginated. You can iterate through the pages using `payment_requests.next` and checking the result:
67
98
 
68
99
  ```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
- )
100
+ payment_requests = client.payment_requests.list
75
101
 
76
- user_token = user.user_token
77
- bank_account_token = user.bank_accounts.first.bank_account_token
102
+ loop do
103
+ # Do something with payment requests
104
+
105
+ payment_requests = payment_requests.next
106
+ break if payment_requests.nil?
107
+ end
78
108
  ```
79
109
 
80
- ### Payment requests
110
+ See [Tikkie::Api::Resources::PaymentRequests](lib/tikkie/api/resources/payment_requests.rb) for all available properties.
111
+
112
+ #### Get Payment request
113
+
114
+ Retrieve details of a specific payment request.
115
+
116
+ ```ruby
117
+ payment_request = client.payment_requests.get("payment_request_token")
118
+
119
+ payment_request.payment_request_token # => "qzdnzr8hnVWTgXXcFRLUMc"
120
+ payment_request.url # => "https://tikkie.me/pay/Tikkie/qzdnzr8hnVWTgXXcFRLUMc"
121
+ payment_request.amount # => BigDecimal("12.50")
122
+ payment_request.payments # => Tikkie::Api::Resources::Payments
123
+ ```
81
124
 
82
- Retrieve all payment requests for a user on a platform:
125
+ See [Tikkie::Api::Resources::PaymentRequest](lib/tikkie/api/resources/payment_request.rb) for all available properties.
126
+
127
+
128
+ ### Payments
129
+
130
+ #### List Payments
131
+
132
+ Retrieves all payments for a specific payment request.
83
133
 
84
134
  ```ruby
85
- payment_requests = client.payment_requests.list("platform_token", "user_token")
135
+ payments = client.payments.list("payment_request_token")
86
136
  ```
87
137
 
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:
138
+ The payments requests response is paginated. You can iterate through the pages using `payments.next` and checking the result:
89
139
 
90
140
  ```ruby
91
- response = client.payment_requests.list("platform_token", "user_token")
92
- payment_requests = response.to_a
141
+ payments = client.payments.list("qzdnzr8hnVWTgXXcFRLUMc")
142
+
143
+ loop do
144
+ # Do something with payments
93
145
 
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
146
+ payments = payments.next
147
+ break if payments.nil?
97
148
  end
98
149
  ```
99
150
 
100
- To retrieve a single payment request:
151
+ See [Tikkie::Api::Resources::Payments](lib/tikkie/api/resources/payments.rb) for all available properties.
152
+
153
+ #### Get Payment
154
+
155
+ Retrieves details of specific payment based on the token value.
101
156
 
102
157
  ```ruby
103
- payment_request = client.payment_requests.get("platform_token", "user_token", "payment_request_token")
158
+ payment = client.payments.get("payment_request_token", "payment_token")
159
+
160
+ payment.payment_token # => "21ef7413-cc3c-4c80-9272-6710fada28e4"
161
+ payment.amount # => BigDecimal("12.50")
162
+ payment.description # => "Test"
163
+ payment.refunds # => Array[Tikkie::Api::Resources::Refund]
104
164
  ```
105
165
 
106
- Create a new payment request for an existing user:
166
+ See [Tikkie::Api::Resources::Payment](lib/tikkie/api/resources/payment.rb) for all available properties.
167
+
168
+ ### Refunds
169
+
170
+ #### Create a Refund
171
+
172
+ Creates a refund for a specific payment.
107
173
 
108
174
  ```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
175
+ refund = client.refunds.create("payment_request_token", "payment_token",
176
+ description: "Test", # mandatory
177
+ amount: "10.00", # mandatory
178
+ reference_id: "Invoice 12345"
114
179
  )
115
180
 
116
- tikkie_url = payment_request.payment_request_url
117
- payment_request_token =payment_request.payment_request_token
181
+ refund.refund_token # => "abcdzr8hnVWTgXXcFRLUMc"
182
+ refund.amount # => BigDecimal("10.00")
183
+ refund.paid? # => true
184
+ ```
185
+
186
+ See [Tikkie::Api::Resources::Refund](lib/tikkie/api/resources/refund.rb) for all available properties.
187
+
188
+ #### Get Refund
189
+
190
+ Retrieves details of a specific refund based on the token value.
191
+
192
+ ```ruby
193
+ refund = client.refunds.get("payment_request_token", "payment_token", "refund_token")
194
+
195
+ refund.refund_token # => "abcdzr8hnVWTgXXcFRLUMc"
196
+ refund.amount # => BigDecimal("10.00")
197
+ refund.paid? # => true
118
198
  ```
119
199
 
120
- ### Error handling
200
+ See [Tikkie::Api::Resources::Refund](lib/tikkie/api/resources/refund.rb) for all available properties.
121
201
 
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.
202
+ ### Payment requests notification
203
+
204
+ See [Notifications](#notifications) for information about parsing the callbacks.
205
+
206
+ #### Create a subscription
207
+
208
+ Subscribes to payment request related notifications.
209
+
210
+ ```ruby
211
+ subscription = client.payment_requests_subscription.create(url: "https://www.example.com/notification")
212
+
213
+ subscription.subscription_id # => "e0111835-e8df-4070-874a-f12cf3f77e39"
214
+ ```
215
+
216
+ See [Tikkie::Api::Resources::PaymentRequestsSubscription](lib/tikkie/api/resources/payment_requests_subscription.rb) for all available properties.
217
+
218
+ #### Delete subscription
219
+
220
+ Deletes the current subscription.
221
+
222
+ ```ruby
223
+ client.payment_requests_subscription.delete
224
+ ```
225
+
226
+ ### Sandbox apps
227
+
228
+ A sandbox app is used to make API requests in the sandbox environment.
229
+
230
+ You must initialize the Tikkie client by omitting the App token and adding the option `sandbox: true`:
231
+
232
+ ```ruby
233
+ client = Tikkie::Api::Client.new(api_key: "12345", sandbox: true)
234
+ ```
235
+
236
+ #### Create a Sandbox app
237
+
238
+ Creates an app in the sandbox. The returned `app_token` should be used for all other API operations.
123
239
 
124
240
  ```ruby
125
- payment_request = client.payment_requests.create("platform_token", "user_token", "bank_account_token", ...)
241
+ sandbox_app = client.sandbox_apps.create
242
+
243
+ sandbox_app.app_token # => "935059a6-58b3-4f8d-a021-7bdda0d8d6ad"
244
+ ```
126
245
 
127
- if payment_request.success?
128
- # Success handling...
246
+ See [Tikkie::Api::Resources::SandboxApp](lib/tikkie/api/resources/sandbox_app.rb) for all available properties.
129
247
 
130
- redirect_to payment_request.payment_request_url
131
- else
132
- # Error handling...
248
+ ## Error handling
133
249
 
134
- puts payment_request.errors
250
+ All responses that are not HTTP status 20x will result in a [Tikkie::Api::RequestError](lib/tikkie/api/exception.rb).
251
+
252
+ ```ruby
253
+ begin
254
+ client.payment_requests.get("invalid")
255
+ rescue Tikkie::Api::RequestError => e
256
+ e.http_code # => 404
257
+ e.http_message # => Not Found
258
+ e.errors # => Array[Tikkie::Api::Resources::Error]
259
+ e.messages # => "No payment request was found for the specified paymentRequestToken."
135
260
  end
136
261
  ```
137
262
 
263
+ ## Notifications
264
+
265
+ When subscribed to notifications, you can use `Tikkie::Notification.parse` to parse the payload of a callback.
266
+
267
+ ```ruby
268
+ require 'tikkie/notification'
269
+
270
+ notification = Tikkie::Notification.parse(request.raw_post)
271
+
272
+ notification # => Tikkie::Notifications::PaymentNotification
273
+ notification.subscription_id # => "e0111835-e8df-4070-874a-f12cf3f77e39"
274
+ notification.notification_type # => "PAYMENT"
275
+ notification.payment_request_token # => "qzdnzr8hnVWTgXXcFRLUMc"
276
+ notification.payment_token # => "21ef7413-cc3c-4c80-9272-6710fada28e4"
277
+ ```
278
+
279
+ See [Tikkie::Notifications](lib/tikkie/notifications/) for all types of notifications.
280
+
281
+ ## API support
282
+
283
+ This gem supports [Tikkie API (v2)](https://developer.abnamro.com/api-products/tikkie) as of release 2.0.0.
284
+
285
+ The deprecated [Tikkie Payment Request API (v1)](https://developer.abnamro.com/api-products/tikkie-payment-request) is currently namespaced under [Tikkie::Api::V1](lib/tikkie/api/v1/) to allow migration to Tikkie v2. This code is not supported anymore and will be removed in a future release of this gem.
286
+ To use the Tikkie v1 code, make sure to include the [jwt gem](https://rubygems.org/gems/jwt) in your code.
287
+
138
288
  ## Development
139
289
 
140
290
  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.