mollie-api-ruby 4.12.0 → 4.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/push.yml +27 -0
- data/CHANGELOG.md +5 -0
- data/Rakefile +2 -0
- data/examples/terminals/get.rb +1 -0
- data/examples/terminals/list.rb +1 -0
- data/lib/mollie/client.rb +2 -2
- data/lib/mollie/exception.rb +14 -1
- data/lib/mollie/terminal.rb +59 -0
- data/lib/mollie/version.rb +1 -1
- data/lib/mollie.rb +1 -0
- data/test/fixtures/terminals/get.json +23 -0
- data/test/fixtures/terminals/list.json +34 -0
- data/test/mollie/base_test.rb +1 -0
- data/test/mollie/exception_test.rb +87 -0
- data/test/mollie/terminal_test.rb +54 -0
- metadata +18 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58916be713b9cf5128476188f1b0e61dc51f04d9e41b48b09c053b923e9daf39
|
4
|
+
data.tar.gz: 2f514f685d55211565be7197d5b9b36e587894582bdc515f4eb75ce19c481f10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3dd1ed54bf737169dbd652f3314ce258c03a87d3b73ed0f8e2473ff2acfef1c08cd5b06349d370f564ee318964a78757978fc948d975f6e0733b1d60a69ff52
|
7
|
+
data.tar.gz: cad4e544c9cb525bbc94d1a4caf5585590456345ec1bd74fe08f4fe73a5292d4c721b7df2226f6721311487f3ef319bc69d8664863ca864792399cd48f067669
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Publish gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- v[0-9]+.[0-9]+.[0-9]+*
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
publish:
|
10
|
+
name: Push gem to RubyGems.org
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
permissions:
|
14
|
+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
15
|
+
contents: write # IMPORTANT: this permission is required for `rake release` to push the release tag
|
16
|
+
|
17
|
+
steps:
|
18
|
+
# Set up
|
19
|
+
- uses: actions/checkout@v4
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
bundler-cache: true
|
24
|
+
ruby-version: ruby
|
25
|
+
|
26
|
+
# Release
|
27
|
+
- uses: rubygems/release-gem@v1
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@
|
|
4
4
|
|
5
5
|
All notable changes to this project will be documented in this file.
|
6
6
|
|
7
|
+
## 4.13.0 - 2023-05-22
|
8
|
+
|
9
|
+
- (09489be) Add HTTP response details to RequestError
|
10
|
+
- (fe5d114) Add Terminals API
|
11
|
+
|
7
12
|
## 4.12.0 - 2023-01-29
|
8
13
|
|
9
14
|
- (f180b47) Add support for idempotency keys
|
data/Rakefile
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
terminal = Mollie::Terminal.get("term_7MgL4wea46qkRcoTZjWEH")
|
@@ -0,0 +1 @@
|
|
1
|
+
terminals = Mollie::Terminal.all
|
data/lib/mollie/client.rb
CHANGED
@@ -130,11 +130,11 @@ module Mollie
|
|
130
130
|
{} # No Content
|
131
131
|
when 404
|
132
132
|
json = JSON.parse(response.body)
|
133
|
-
exception = ResourceNotFoundError.new(json)
|
133
|
+
exception = ResourceNotFoundError.new(json, response)
|
134
134
|
raise exception
|
135
135
|
else
|
136
136
|
json = JSON.parse(response.body)
|
137
|
-
exception = Mollie::RequestError.new(json)
|
137
|
+
exception = Mollie::RequestError.new(json, response)
|
138
138
|
raise exception
|
139
139
|
end
|
140
140
|
end
|
data/lib/mollie/exception.rb
CHANGED
@@ -5,17 +5,30 @@ module Mollie
|
|
5
5
|
class RequestError < Mollie::Exception
|
6
6
|
attr_accessor :status, :title, :detail, :field, :links
|
7
7
|
|
8
|
-
def initialize(error)
|
8
|
+
def initialize(error, response = nil)
|
9
9
|
exception.status = error['status']
|
10
10
|
exception.title = error['title']
|
11
11
|
exception.detail = error['detail']
|
12
12
|
exception.field = error['field']
|
13
13
|
exception.links = error['_links']
|
14
|
+
self.response = response
|
14
15
|
end
|
15
16
|
|
16
17
|
def to_s
|
17
18
|
"#{status} #{title}: #{detail}"
|
18
19
|
end
|
20
|
+
|
21
|
+
def http_headers
|
22
|
+
response.to_hash if response
|
23
|
+
end
|
24
|
+
|
25
|
+
def http_body
|
26
|
+
response.body if response
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_accessor :response
|
19
32
|
end
|
20
33
|
|
21
34
|
class ResourceNotFoundError < RequestError
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Terminal < Base
|
3
|
+
|
4
|
+
STATUS_PENDING = "pending".freeze
|
5
|
+
STATUS_ACTIVE = "active".freeze
|
6
|
+
STATUS_INACTIVE = "inactive".freeze
|
7
|
+
|
8
|
+
attr_accessor :id,
|
9
|
+
:profile_id,
|
10
|
+
:status,
|
11
|
+
:brand,
|
12
|
+
:model,
|
13
|
+
:serial_number,
|
14
|
+
:currency,
|
15
|
+
:description,
|
16
|
+
:created_at,
|
17
|
+
:updated_at,
|
18
|
+
:deactivated_at,
|
19
|
+
:_links
|
20
|
+
|
21
|
+
alias links _links
|
22
|
+
|
23
|
+
def pending?
|
24
|
+
status == STATUS_PENDING
|
25
|
+
end
|
26
|
+
|
27
|
+
def active?
|
28
|
+
status == STATUS_ACTIVE
|
29
|
+
end
|
30
|
+
|
31
|
+
def inactive?
|
32
|
+
status == STATUS_INACTIVE
|
33
|
+
end
|
34
|
+
|
35
|
+
def created_at=(created_at)
|
36
|
+
@created_at = begin
|
37
|
+
Time.parse(created_at.to_s)
|
38
|
+
rescue StandardError
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def updated_at=(updated_at)
|
44
|
+
@updated_at = begin
|
45
|
+
Time.parse(updated_at.to_s)
|
46
|
+
rescue StandardError
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def deactivated_at=(deactivated_at)
|
52
|
+
@deactivated_at = begin
|
53
|
+
Time.parse(deactivated_at.to_s)
|
54
|
+
rescue StandardError
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/mollie/version.rb
CHANGED
data/lib/mollie.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"id": "term_7MgL4wea46qkRcoTZjWEH",
|
3
|
+
"profileId": "pfl_QkEhN94Ba",
|
4
|
+
"status": "active",
|
5
|
+
"brand": "PAX",
|
6
|
+
"model": "A920",
|
7
|
+
"serialNumber": "1234567890",
|
8
|
+
"currency": "EUR",
|
9
|
+
"description": "Terminal #12345",
|
10
|
+
"createdAt": "2022-02-12T11:58:35.0Z",
|
11
|
+
"updatedAt": "2022-11-15T13:32:11+00:00",
|
12
|
+
"deactivatedAt": "2022-02-12T12:13:35.0Z",
|
13
|
+
"_links": {
|
14
|
+
"self": {
|
15
|
+
"href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH",
|
16
|
+
"type": "application/hal+json"
|
17
|
+
},
|
18
|
+
"documentation": {
|
19
|
+
"href": "https://docs.mollie.com/reference/v2/terminals-api/get-terminal",
|
20
|
+
"type": "text/html"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"count": 3,
|
3
|
+
"_embedded": {
|
4
|
+
"terminals": [
|
5
|
+
{
|
6
|
+
"resource": "terminal",
|
7
|
+
"id": "terminal_one"
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"resource": "terminal",
|
11
|
+
"id": "terminal_two"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"resource": "terminal",
|
15
|
+
"id": "terminal_three"
|
16
|
+
}
|
17
|
+
]
|
18
|
+
},
|
19
|
+
"_links": {
|
20
|
+
"self": {
|
21
|
+
"href": "https://api.mollie.com/v2/terminals",
|
22
|
+
"type": "application/hal+json"
|
23
|
+
},
|
24
|
+
"previous": null,
|
25
|
+
"next": {
|
26
|
+
"href": "https://api.mollie.com/v2/terminals?from=term_7MgL4wea46qkRcoTZjWEH",
|
27
|
+
"type": "application/hal+json"
|
28
|
+
},
|
29
|
+
"documentation": {
|
30
|
+
"href": "https://docs.mollie.com/reference/v2/terminals-api/list-terminals",
|
31
|
+
"type": "text/html"
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
data/test/mollie/base_test.rb
CHANGED
@@ -44,6 +44,7 @@ module Mollie
|
|
44
44
|
assert_equal 'my-id', resource.id
|
45
45
|
assert_equal 'object-id', resource.testobject_id
|
46
46
|
end
|
47
|
+
|
47
48
|
def test_get_with_invalid_identifiers
|
48
49
|
assert_raises(Mollie::Exception) { TestObject.get(nil) }
|
49
50
|
assert_raises(Mollie::Exception) { TestObject.get(" ") }
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
class ExceptionTest < Test::Unit::TestCase
|
5
|
+
def test_attributes
|
6
|
+
stub_request(:post, 'https://api.mollie.com/v2/payments')
|
7
|
+
.to_return(status: 422, headers: { "Content-Type" => "application/hal+json}" }, body: %(
|
8
|
+
{
|
9
|
+
"status": 422,
|
10
|
+
"title": "Unprocessable Entity",
|
11
|
+
"detail": "The amount is higher than the maximum",
|
12
|
+
"field": "amount",
|
13
|
+
"_links": {
|
14
|
+
"documentation": {
|
15
|
+
"href": "https://docs.mollie.com/errors",
|
16
|
+
"type": "text/html"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
))
|
21
|
+
|
22
|
+
exception = assert_raise(Mollie::RequestError) do
|
23
|
+
Mollie::Payment.create(
|
24
|
+
amount: { value: "1000000000.00", currency: "EUR" },
|
25
|
+
description: "Order #66",
|
26
|
+
redirect_url: "https://www.example.org/payment/completed",
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
assert_equal 422, exception.status
|
31
|
+
assert_equal "Unprocessable Entity", exception.title
|
32
|
+
assert_equal "The amount is higher than the maximum", exception.detail
|
33
|
+
assert_equal "amount", exception.field
|
34
|
+
assert_equal "https://docs.mollie.com/errors", exception.links["documentation"]["href"]
|
35
|
+
assert_equal "text/html", exception.links["documentation"]["type"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_exception_message
|
39
|
+
stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg')
|
40
|
+
.to_return(status: 401, headers: { "Content-Type" => "application/hal+json}" }, body: %(
|
41
|
+
{
|
42
|
+
"status": 401,
|
43
|
+
"title": "Unauthorized Request",
|
44
|
+
"detail": "Missing authentication, or failed to authenticate",
|
45
|
+
"_links": {
|
46
|
+
"documentation": {
|
47
|
+
"href": "https://docs.mollie.com/overview/authentication",
|
48
|
+
"type": "text/html"
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
))
|
53
|
+
|
54
|
+
exception = assert_raise(Mollie::RequestError) { Payment.get('tr_WDqYK6vllg') }
|
55
|
+
assert_equal '401 Unauthorized Request: Missing authentication, or failed to authenticate', exception.message
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_http_attributes
|
59
|
+
body = %({
|
60
|
+
"status": 422,
|
61
|
+
"title": "Unprocessable Entity",
|
62
|
+
"detail": "The amount is higher than the maximum",
|
63
|
+
"field": "amount",
|
64
|
+
"_links": {
|
65
|
+
"documentation": {
|
66
|
+
"href": "https://docs.mollie.com/errors",
|
67
|
+
"type": "text/html"
|
68
|
+
}
|
69
|
+
}
|
70
|
+
})
|
71
|
+
|
72
|
+
stub_request(:post, 'https://api.mollie.com/v2/payments')
|
73
|
+
.to_return(status: 422, headers: { "Content-Type" => "application/hal+json" }, body: body)
|
74
|
+
|
75
|
+
exception = assert_raise(Mollie::RequestError) do
|
76
|
+
Mollie::Payment.create(
|
77
|
+
amount: { value: "1000000000.00", currency: "EUR" },
|
78
|
+
description: "Order #66",
|
79
|
+
redirect_url: "https://www.example.org/payment/completed",
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
assert_equal({ "content-type" => ["application/hal+json"] }, exception.http_headers)
|
84
|
+
assert_equal(body, exception.http_body)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
class TerminalTest < Test::Unit::TestCase
|
5
|
+
GET_TERMINAL = read_fixture('terminals/get.json')
|
6
|
+
LIST_TERMINALS = read_fixture('terminals/list.json')
|
7
|
+
|
8
|
+
def test_get_terminal
|
9
|
+
stub_request(:get, "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH")
|
10
|
+
.to_return(status: 200, body: GET_TERMINAL, headers: {})
|
11
|
+
|
12
|
+
terminal = Terminal.get("term_7MgL4wea46qkRcoTZjWEH")
|
13
|
+
|
14
|
+
assert_equal "term_7MgL4wea46qkRcoTZjWEH", terminal.id
|
15
|
+
assert_equal "pfl_QkEhN94Ba", terminal.profile_id
|
16
|
+
assert_equal "active", terminal.status
|
17
|
+
assert_equal "PAX", terminal.brand
|
18
|
+
assert_equal "A920", terminal.model
|
19
|
+
assert_equal "1234567890", terminal.serial_number
|
20
|
+
assert_equal "EUR", terminal.currency
|
21
|
+
assert_equal "Terminal #12345", terminal.description
|
22
|
+
assert_equal Time.parse("2022-02-12T11:58:35.0Z"), terminal.created_at
|
23
|
+
assert_equal Time.parse("2022-11-15T13:32:11+00:00"), terminal.updated_at
|
24
|
+
assert_equal Time.parse("2022-02-12T12:13:35.0Z"), terminal.deactivated_at
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_status_pending
|
28
|
+
assert Terminal.new(status: Terminal::STATUS_PENDING).pending?
|
29
|
+
assert !Terminal.new(status: "not-pending").pending?
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_status_active
|
33
|
+
assert Terminal.new(status: Terminal::STATUS_ACTIVE).active?
|
34
|
+
assert !Terminal.new(status: "not-active").active?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_status_inactive
|
38
|
+
assert Terminal.new(status: Terminal::STATUS_INACTIVE).inactive?
|
39
|
+
assert !Terminal.new(status: "not-inactive").inactive?
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_list_terminals
|
43
|
+
stub_request(:get, "https://api.mollie.com/v2/terminals")
|
44
|
+
.to_return(status: 200, body: LIST_TERMINALS, headers: {})
|
45
|
+
|
46
|
+
terminals = Terminal.all
|
47
|
+
|
48
|
+
assert_equal 3, terminals.size
|
49
|
+
assert_equal "terminal_one", terminals[0].id
|
50
|
+
assert_equal "terminal_two", terminals[1].id
|
51
|
+
assert_equal "terminal_three", terminals[2].id
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mollie-api-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mollie B.V.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -81,6 +81,7 @@ extra_rdoc_files: []
|
|
81
81
|
files:
|
82
82
|
- ".github/workflows/build.yml"
|
83
83
|
- ".github/workflows/codeql.yml"
|
84
|
+
- ".github/workflows/push.yml"
|
84
85
|
- ".gitignore"
|
85
86
|
- ".rubocop.yml"
|
86
87
|
- ".rubocop_todo.yml"
|
@@ -180,6 +181,8 @@ files:
|
|
180
181
|
- examples/subscriptions/get.rb
|
181
182
|
- examples/subscriptions/list.rb
|
182
183
|
- examples/subscriptions/update.rb
|
184
|
+
- examples/terminals/get.rb
|
185
|
+
- examples/terminals/list.rb
|
183
186
|
- lib/cacert.pem
|
184
187
|
- lib/mollie-api-ruby.rb
|
185
188
|
- lib/mollie.rb
|
@@ -216,6 +219,7 @@ files:
|
|
216
219
|
- lib/mollie/settlement/payment.rb
|
217
220
|
- lib/mollie/settlement/refund.rb
|
218
221
|
- lib/mollie/subscription.rb
|
222
|
+
- lib/mollie/terminal.rb
|
219
223
|
- lib/mollie/util.rb
|
220
224
|
- lib/mollie/version.rb
|
221
225
|
- mollie-api-ruby.gemspec
|
@@ -250,6 +254,8 @@ files:
|
|
250
254
|
- test/fixtures/shipments/update.json
|
251
255
|
- test/fixtures/subscriptions/get.json
|
252
256
|
- test/fixtures/subscriptions/get_payments.json
|
257
|
+
- test/fixtures/terminals/get.json
|
258
|
+
- test/fixtures/terminals/list.json
|
253
259
|
- test/helper.rb
|
254
260
|
- test/mollie/amount_test.rb
|
255
261
|
- test/mollie/base_test.rb
|
@@ -259,6 +265,7 @@ files:
|
|
259
265
|
- test/mollie/customer/payment_test.rb
|
260
266
|
- test/mollie/customer/subscription_test.rb
|
261
267
|
- test/mollie/customer_test.rb
|
268
|
+
- test/mollie/exception_test.rb
|
262
269
|
- test/mollie/invoice_test.rb
|
263
270
|
- test/mollie/list_test.rb
|
264
271
|
- test/mollie/method_test.rb
|
@@ -280,13 +287,14 @@ files:
|
|
280
287
|
- test/mollie/settlement/payment_test.rb
|
281
288
|
- test/mollie/settlement/refund_test.rb
|
282
289
|
- test/mollie/settlement_test.rb
|
290
|
+
- test/mollie/terminal_test.rb
|
283
291
|
- test/mollie/util_test.rb
|
284
292
|
- test/run-test.rb
|
285
293
|
homepage: https://github.com/mollie/mollie-api-ruby
|
286
294
|
licenses:
|
287
295
|
- BSD
|
288
296
|
metadata: {}
|
289
|
-
post_install_message:
|
297
|
+
post_install_message:
|
290
298
|
rdoc_options: []
|
291
299
|
require_paths:
|
292
300
|
- lib
|
@@ -301,8 +309,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
301
309
|
- !ruby/object:Gem::Version
|
302
310
|
version: '0'
|
303
311
|
requirements: []
|
304
|
-
rubygems_version: 3.5.
|
305
|
-
signing_key:
|
312
|
+
rubygems_version: 3.5.9
|
313
|
+
signing_key:
|
306
314
|
specification_version: 4
|
307
315
|
summary: Official Mollie API Client for Ruby
|
308
316
|
test_files:
|
@@ -337,6 +345,8 @@ test_files:
|
|
337
345
|
- test/fixtures/shipments/update.json
|
338
346
|
- test/fixtures/subscriptions/get.json
|
339
347
|
- test/fixtures/subscriptions/get_payments.json
|
348
|
+
- test/fixtures/terminals/get.json
|
349
|
+
- test/fixtures/terminals/list.json
|
340
350
|
- test/helper.rb
|
341
351
|
- test/mollie/amount_test.rb
|
342
352
|
- test/mollie/base_test.rb
|
@@ -346,6 +356,7 @@ test_files:
|
|
346
356
|
- test/mollie/customer/payment_test.rb
|
347
357
|
- test/mollie/customer/subscription_test.rb
|
348
358
|
- test/mollie/customer_test.rb
|
359
|
+
- test/mollie/exception_test.rb
|
349
360
|
- test/mollie/invoice_test.rb
|
350
361
|
- test/mollie/list_test.rb
|
351
362
|
- test/mollie/method_test.rb
|
@@ -367,5 +378,6 @@ test_files:
|
|
367
378
|
- test/mollie/settlement/payment_test.rb
|
368
379
|
- test/mollie/settlement/refund_test.rb
|
369
380
|
- test/mollie/settlement_test.rb
|
381
|
+
- test/mollie/terminal_test.rb
|
370
382
|
- test/mollie/util_test.rb
|
371
383
|
- test/run-test.rb
|