Skip to content

Commit

Permalink
Merge pull request #164 from mollie/terminals-api
Browse files Browse the repository at this point in the history
Add Terminals API
  • Loading branch information
justincase committed Jun 18, 2023
2 parents 21a8bf1 + fe5d114 commit bde1a0b
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/terminals/get.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terminal = Mollie::Terminal.get("term_7MgL4wea46qkRcoTZjWEH")
1 change: 1 addition & 0 deletions examples/terminals/list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terminals = Mollie::Terminal.all
1 change: 1 addition & 0 deletions lib/mollie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Mollie
require 'mollie/refund'
require 'mollie/settlement'
require 'mollie/subscription'
require 'mollie/terminal'

require 'mollie/customer/mandate'
require 'mollie/customer/payment'
Expand Down
59 changes: 59 additions & 0 deletions lib/mollie/terminal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Mollie
class Terminal < Base

STATUS_PENDING = "pending".freeze
STATUS_ACTIVE = "active".freeze
STATUS_INACTIVE = "inactive".freeze

attr_accessor :id,
:profile_id,
:status,
:brand,
:model,
:serial_number,
:currency,
:description,
:created_at,
:updated_at,
:deactivated_at,
:_links

alias links _links

def pending?
status == STATUS_PENDING
end

def active?
status == STATUS_ACTIVE
end

def inactive?
status == STATUS_INACTIVE
end

def created_at=(created_at)
@created_at = begin
Time.parse(created_at.to_s)
rescue StandardError
nil
end
end

def updated_at=(updated_at)
@updated_at = begin
Time.parse(updated_at.to_s)
rescue StandardError
nil
end
end

def deactivated_at=(deactivated_at)
@deactivated_at = begin
Time.parse(deactivated_at.to_s)
rescue StandardError
nil
end
end
end
end
23 changes: 23 additions & 0 deletions test/fixtures/terminals/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"id": "term_7MgL4wea46qkRcoTZjWEH",
"profileId": "pfl_QkEhN94Ba",
"status": "active",
"brand": "PAX",
"model": "A920",
"serialNumber": "1234567890",
"currency": "EUR",
"description": "Terminal #12345",
"createdAt": "2022-02-12T11:58:35.0Z",
"updatedAt": "2022-11-15T13:32:11+00:00",
"deactivatedAt": "2022-02-12T12:13:35.0Z",
"_links": {
"self": {
"href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH",
"type": "application/hal+json"
},
"documentation": {
"href": "https://docs.mollie.com/reference/v2/terminals-api/get-terminal",
"type": "text/html"
}
}
}
34 changes: 34 additions & 0 deletions test/fixtures/terminals/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"count": 3,
"_embedded": {
"terminals": [
{
"resource": "terminal",
"id": "terminal_one"
},
{
"resource": "terminal",
"id": "terminal_two"
},
{
"resource": "terminal",
"id": "terminal_three"
}
]
},
"_links": {
"self": {
"href": "https://api.mollie.com/v2/terminals",
"type": "application/hal+json"
},
"previous": null,
"next": {
"href": "https://api.mollie.com/v2/terminals?from=term_7MgL4wea46qkRcoTZjWEH",
"type": "application/hal+json"
},
"documentation": {
"href": "https://docs.mollie.com/reference/v2/terminals-api/list-terminals",
"type": "text/html"
}
}
}
54 changes: 54 additions & 0 deletions test/mollie/terminal_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'helper'

module Mollie
class TerminalTest < Test::Unit::TestCase
GET_TERMINAL = read_fixture('terminals/get.json')
LIST_TERMINALS = read_fixture('terminals/list.json')

def test_get_terminal
stub_request(:get, "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH")
.to_return(status: 200, body: GET_TERMINAL, headers: {})

terminal = Terminal.get("term_7MgL4wea46qkRcoTZjWEH")

assert_equal "term_7MgL4wea46qkRcoTZjWEH", terminal.id
assert_equal "pfl_QkEhN94Ba", terminal.profile_id
assert_equal "active", terminal.status
assert_equal "PAX", terminal.brand
assert_equal "A920", terminal.model
assert_equal "1234567890", terminal.serial_number
assert_equal "EUR", terminal.currency
assert_equal "Terminal #12345", terminal.description
assert_equal Time.parse("2022-02-12T11:58:35.0Z"), terminal.created_at
assert_equal Time.parse("2022-11-15T13:32:11+00:00"), terminal.updated_at
assert_equal Time.parse("2022-02-12T12:13:35.0Z"), terminal.deactivated_at
end

def test_status_pending
assert Terminal.new(status: Terminal::STATUS_PENDING).pending?
assert !Terminal.new(status: "not-pending").pending?
end

def test_status_active
assert Terminal.new(status: Terminal::STATUS_ACTIVE).active?
assert !Terminal.new(status: "not-active").active?
end

def test_status_inactive
assert Terminal.new(status: Terminal::STATUS_INACTIVE).inactive?
assert !Terminal.new(status: "not-inactive").inactive?
end

def test_list_terminals
stub_request(:get, "https://api.mollie.com/v2/terminals")
.to_return(status: 200, body: LIST_TERMINALS, headers: {})

terminals = Terminal.all

assert_equal 3, terminals.size
assert_equal "terminal_one", terminals[0].id
assert_equal "terminal_two", terminals[1].id
assert_equal "terminal_three", terminals[2].id
end
end
end

0 comments on commit bde1a0b

Please sign in to comment.