sumup 0.0.1
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 +7 -0
- data/CHANGELOG.md +18 -0
- data/LICENSE +201 -0
- data/README.md +188 -0
- data/lib/sumup/client.rb +213 -0
- data/lib/sumup/errors.rb +45 -0
- data/lib/sumup/event_types.rb +115 -0
- data/lib/sumup/events.rb +168 -0
- data/lib/sumup/model.rb +109 -0
- data/lib/sumup/pagination.rb +92 -0
- data/lib/sumup/resource.rb +36 -0
- data/lib/sumup/resources/checkouts.rb +155 -0
- data/lib/sumup/resources/customers.rb +89 -0
- data/lib/sumup/resources/members.rb +93 -0
- data/lib/sumup/resources/memberships.rb +23 -0
- data/lib/sumup/resources/merchants.rb +51 -0
- data/lib/sumup/resources/payouts.rb +29 -0
- data/lib/sumup/resources/readers.rb +264 -0
- data/lib/sumup/resources/receipts.rb +23 -0
- data/lib/sumup/resources/roles.rb +89 -0
- data/lib/sumup/resources/sales.rb +66 -0
- data/lib/sumup/resources/tokens.rb +31 -0
- data/lib/sumup/resources/transactions.rb +61 -0
- data/lib/sumup/resources.rb +83 -0
- data/lib/sumup/transport.rb +40 -0
- data/lib/sumup/types.rb +4720 -0
- data/lib/sumup/version.rb +5 -0
- data/lib/sumup.rb +13 -0
- data/sig/sumup/events.rbs +64 -0
- data/sig/sumup/resources/checkouts.rbs +35 -0
- data/sig/sumup/resources/customers.rbs +25 -0
- data/sig/sumup/resources/members.rbs +25 -0
- data/sig/sumup/resources/memberships.rbs +13 -0
- data/sig/sumup/resources/merchants.rbs +17 -0
- data/sig/sumup/resources/payouts.rbs +13 -0
- data/sig/sumup/resources/readers.rbs +45 -0
- data/sig/sumup/resources/receipts.rbs +13 -0
- data/sig/sumup/resources/roles.rbs +25 -0
- data/sig/sumup/resources/sales.rbs +19 -0
- data/sig/sumup/resources/tokens.rbs +15 -0
- data/sig/sumup/resources/transactions.rbs +19 -0
- data/sig/sumup/types.rbs +1635 -0
- data/sig/sumup.rbs +183 -0
- metadata +149 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by codegen. DO NOT EDIT.
|
|
4
|
+
|
|
5
|
+
module SumUp
|
|
6
|
+
module Resources
|
|
7
|
+
class Roles < Resource
|
|
8
|
+
# List merchant's custom roles.
|
|
9
|
+
# @return [Types::ListMerchantRolesResponse]
|
|
10
|
+
def list(merchant_code:, options: nil)
|
|
11
|
+
@client.request(method: "GET", path: "/v0.1/merchants/#{path_segment(merchant_code)}/roles",
|
|
12
|
+
query: {}, options: options,
|
|
13
|
+
response_type: {200 => [:model, "ListMerchantRolesResponse"]}, with_response: false)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def list_with_response(merchant_code:, options: nil)
|
|
17
|
+
@client.request(method: "GET", path: "/v0.1/merchants/#{path_segment(merchant_code)}/roles",
|
|
18
|
+
query: {}, options: options,
|
|
19
|
+
response_type: {200 => [:model, "ListMerchantRolesResponse"]}, with_response: true)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Create a custom role for the merchant. Roles are defined by the set of permissions that they grant to the members that they are assigned to.
|
|
23
|
+
# @return [Types::Role]
|
|
24
|
+
def create(merchant_code:, body: UNSET, options: nil, **body_fields)
|
|
25
|
+
payload = request_body(body, body_fields)
|
|
26
|
+
raise ArgumentError, "request body is required" if payload.equal?(UNSET)
|
|
27
|
+
@client.request(method: "POST", path: "/v0.1/merchants/#{path_segment(merchant_code)}/roles",
|
|
28
|
+
query: {}, body: payload, options: options,
|
|
29
|
+
response_type: {201 => [:model, "Role"]}, with_response: false)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def create_with_response(merchant_code:, body: UNSET, options: nil, **body_fields)
|
|
33
|
+
payload = request_body(body, body_fields)
|
|
34
|
+
raise ArgumentError, "request body is required" if payload.equal?(UNSET)
|
|
35
|
+
@client.request(method: "POST", path: "/v0.1/merchants/#{path_segment(merchant_code)}/roles",
|
|
36
|
+
query: {}, body: payload, options: options,
|
|
37
|
+
response_type: {201 => [:model, "Role"]}, with_response: true)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Retrieve a custom role by ID.
|
|
41
|
+
# @return [Types::Role]
|
|
42
|
+
def get(merchant_code:, role_id:, options: nil)
|
|
43
|
+
@client.request(method: "GET", path: "/v0.1/merchants/#{path_segment(merchant_code)}/roles/#{path_segment(role_id)}",
|
|
44
|
+
query: {}, options: options,
|
|
45
|
+
response_type: {200 => [:model, "Role"]}, with_response: false)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def get_with_response(merchant_code:, role_id:, options: nil)
|
|
49
|
+
@client.request(method: "GET", path: "/v0.1/merchants/#{path_segment(merchant_code)}/roles/#{path_segment(role_id)}",
|
|
50
|
+
query: {}, options: options,
|
|
51
|
+
response_type: {200 => [:model, "Role"]}, with_response: true)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Delete a custom role.
|
|
55
|
+
# @return [nil]
|
|
56
|
+
def delete(merchant_code:, role_id:, options: nil)
|
|
57
|
+
@client.request(method: "DELETE", path: "/v0.1/merchants/#{path_segment(merchant_code)}/roles/#{path_segment(role_id)}",
|
|
58
|
+
query: {}, options: options,
|
|
59
|
+
response_type: {200 => :nil}, with_response: false)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def delete_with_response(merchant_code:, role_id:, options: nil)
|
|
63
|
+
@client.request(method: "DELETE", path: "/v0.1/merchants/#{path_segment(merchant_code)}/roles/#{path_segment(role_id)}",
|
|
64
|
+
query: {}, options: options,
|
|
65
|
+
response_type: {200 => :nil}, with_response: true)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Updates a custom role's name, description, or permissions and returns the updated role.
|
|
69
|
+
#
|
|
70
|
+
# Providing `permissions` replaces the role's permission list and changes the access granted to members assigned to that role. Omitted fields remain unchanged.
|
|
71
|
+
# @return [Types::Role]
|
|
72
|
+
def update(merchant_code:, role_id:, body: UNSET, options: nil, **body_fields)
|
|
73
|
+
payload = request_body(body, body_fields)
|
|
74
|
+
payload = {} if payload.equal?(UNSET)
|
|
75
|
+
@client.request(method: "PATCH", path: "/v0.1/merchants/#{path_segment(merchant_code)}/roles/#{path_segment(role_id)}",
|
|
76
|
+
query: {}, body: payload, options: options,
|
|
77
|
+
response_type: {200 => [:model, "Role"]}, with_response: false)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def update_with_response(merchant_code:, role_id:, body: UNSET, options: nil, **body_fields)
|
|
81
|
+
payload = request_body(body, body_fields)
|
|
82
|
+
payload = {} if payload.equal?(UNSET)
|
|
83
|
+
@client.request(method: "PATCH", path: "/v0.1/merchants/#{path_segment(merchant_code)}/roles/#{path_segment(role_id)}",
|
|
84
|
+
query: {}, body: payload, options: options,
|
|
85
|
+
response_type: {200 => [:model, "Role"]}, with_response: true)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by codegen. DO NOT EDIT.
|
|
4
|
+
|
|
5
|
+
module SumUp
|
|
6
|
+
module Resources
|
|
7
|
+
class Sales < Resource
|
|
8
|
+
# Returns a paginated list of `Sale` objects. Results are sorted **newest first** by the
|
|
9
|
+
# **newest event** recorded for each sale. Pagination tokens follow that order.
|
|
10
|
+
#
|
|
11
|
+
# Covers the merchant’s **last two years** of sales. Non-finalised sales are never returned;
|
|
12
|
+
# only fully-paid sales. Use `POST /sales/search` for filtered queries.
|
|
13
|
+
# @return [Types::SalePage]
|
|
14
|
+
def list(merchant_code:, pagination_token: UNSET, pagination_limit: UNSET, options: nil)
|
|
15
|
+
@client.request(method: "GET", path: "/v1.0/merchants/#{path_segment(merchant_code)}/sales",
|
|
16
|
+
query: {"pagination_token" => pagination_token, "pagination_limit" => pagination_limit}, options: options,
|
|
17
|
+
response_type: {200 => [:model, "SalePage"]}, with_response: false)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def list_with_response(merchant_code:, pagination_token: UNSET, pagination_limit: UNSET, options: nil)
|
|
21
|
+
@client.request(method: "GET", path: "/v1.0/merchants/#{path_segment(merchant_code)}/sales",
|
|
22
|
+
query: {"pagination_token" => pagination_token, "pagination_limit" => pagination_limit}, options: options,
|
|
23
|
+
response_type: {200 => [:model, "SalePage"]}, with_response: true)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns a paginated list of `SaleSearchItem` rows matching filter criteria. Results are
|
|
27
|
+
# sorted **newest first** by **sale close date**.
|
|
28
|
+
#
|
|
29
|
+
# Filters from different categories stack with **logical AND**; multiple values in one array
|
|
30
|
+
# field stack with **logical OR**. Results cover the merchant’s **last two years** of sales
|
|
31
|
+
# (narrow further with `start_date` / `end_date`). Pagination tokens are not interchangeable
|
|
32
|
+
# with `GET /sales`.
|
|
33
|
+
# @return [Types::SaleSearchResponse]
|
|
34
|
+
def search(merchant_code:, body: UNSET, options: nil, **body_fields)
|
|
35
|
+
payload = request_body(body, body_fields)
|
|
36
|
+
payload = {} if payload.equal?(UNSET)
|
|
37
|
+
@client.request(method: "POST", path: "/v1.0/merchants/#{path_segment(merchant_code)}/sales/search",
|
|
38
|
+
query: {}, body: payload, options: options,
|
|
39
|
+
response_type: {200 => [:model, "SaleSearchResponse"]}, with_response: false)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def search_with_response(merchant_code:, body: UNSET, options: nil, **body_fields)
|
|
43
|
+
payload = request_body(body, body_fields)
|
|
44
|
+
payload = {} if payload.equal?(UNSET)
|
|
45
|
+
@client.request(method: "POST", path: "/v1.0/merchants/#{path_segment(merchant_code)}/sales/search",
|
|
46
|
+
query: {}, body: payload, options: options,
|
|
47
|
+
response_type: {200 => [:model, "SaleSearchResponse"]}, with_response: true)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Returns `Sale` for `sale_id`, including item lines and `payments[]`.
|
|
51
|
+
# Non-finalised sales are never returned; only fully-paid sales.
|
|
52
|
+
# @return [Types::Sale]
|
|
53
|
+
def get(merchant_code:, sale_id:, options: nil)
|
|
54
|
+
@client.request(method: "GET", path: "/v1.0/merchants/#{path_segment(merchant_code)}/sales/#{path_segment(sale_id)}",
|
|
55
|
+
query: {}, options: options,
|
|
56
|
+
response_type: {200 => [:model, "Sale"]}, with_response: false)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def get_with_response(merchant_code:, sale_id:, options: nil)
|
|
60
|
+
@client.request(method: "GET", path: "/v1.0/merchants/#{path_segment(merchant_code)}/sales/#{path_segment(sale_id)}",
|
|
61
|
+
query: {}, options: options,
|
|
62
|
+
response_type: {200 => [:model, "Sale"]}, with_response: true)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by codegen. DO NOT EDIT.
|
|
4
|
+
|
|
5
|
+
module SumUp
|
|
6
|
+
module Resources
|
|
7
|
+
class Tokens < Resource
|
|
8
|
+
# Creates a short-lived token for the merchant account identified by `merchant_code` and the requested actions.
|
|
9
|
+
#
|
|
10
|
+
# Call this endpoint from your backend using a [supported authentication method](https://developer.sumup.com/api/authentication). You must have access to the merchant account. Before returning the token, check that the user signed in to your application is allowed to accept payments for that account.
|
|
11
|
+
#
|
|
12
|
+
# Pass the returned `access_token` to the SDK. The token expires 15 minutes after creation; use `expires_in` for its remaining lifetime. To continue after it expires, create a new token through this endpoint.
|
|
13
|
+
# @return [Types::Token]
|
|
14
|
+
def create(merchant_code:, body: UNSET, options: nil, **body_fields)
|
|
15
|
+
payload = request_body(body, body_fields)
|
|
16
|
+
raise ArgumentError, "request body is required" if payload.equal?(UNSET)
|
|
17
|
+
@client.request(method: "POST", path: "/v0.1/merchants/#{path_segment(merchant_code)}/tokens",
|
|
18
|
+
query: {}, body: payload, options: options,
|
|
19
|
+
response_type: {200 => [:model, "Token"]}, with_response: false)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create_with_response(merchant_code:, body: UNSET, options: nil, **body_fields)
|
|
23
|
+
payload = request_body(body, body_fields)
|
|
24
|
+
raise ArgumentError, "request body is required" if payload.equal?(UNSET)
|
|
25
|
+
@client.request(method: "POST", path: "/v0.1/merchants/#{path_segment(merchant_code)}/tokens",
|
|
26
|
+
query: {}, body: payload, options: options,
|
|
27
|
+
response_type: {200 => [:model, "Token"]}, with_response: true)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by codegen. DO NOT EDIT.
|
|
4
|
+
|
|
5
|
+
module SumUp
|
|
6
|
+
module Resources
|
|
7
|
+
class Transactions < Resource
|
|
8
|
+
# Refunds a transaction identified by its SumUp transaction ID. Omit the request body to request a full refund, or provide `amount` for a partial refund in the transaction's currency.
|
|
9
|
+
#
|
|
10
|
+
# Retrieve the transaction afterwards to inspect its refunded amount and refund events. The transaction must be eligible for a refund; see the error responses for invalid amounts, permissions, and processing failures.
|
|
11
|
+
# @return [Types::RefundTransactionResponse]
|
|
12
|
+
def refund(merchant_code:, transaction_id:, body: UNSET, options: nil, **body_fields)
|
|
13
|
+
payload = request_body(body, body_fields)
|
|
14
|
+
@client.request(method: "POST", path: "/v1.0/merchants/#{path_segment(merchant_code)}/payments/#{path_segment(transaction_id)}/refunds",
|
|
15
|
+
query: {}, body: payload, options: options,
|
|
16
|
+
response_type: {201 => [:model, "RefundTransactionResponse"]}, with_response: false)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def refund_with_response(merchant_code:, transaction_id:, body: UNSET, options: nil, **body_fields)
|
|
20
|
+
payload = request_body(body, body_fields)
|
|
21
|
+
@client.request(method: "POST", path: "/v1.0/merchants/#{path_segment(merchant_code)}/payments/#{path_segment(transaction_id)}/refunds",
|
|
22
|
+
query: {}, body: payload, options: options,
|
|
23
|
+
response_type: {201 => [:model, "RefundTransactionResponse"]}, with_response: true)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Retrieves the full details of an identified transaction. The transaction resource is identified by a query parameter and *one* of following parameters is required:
|
|
27
|
+
# - `id`
|
|
28
|
+
# - `transaction_code`
|
|
29
|
+
# - `foreign_transaction_id`
|
|
30
|
+
# - `client_transaction_id`
|
|
31
|
+
# @return [Types::TransactionFull]
|
|
32
|
+
def get(merchant_code:, id: UNSET, transaction_code: UNSET, foreign_transaction_id: UNSET, client_transaction_id: UNSET, options: nil)
|
|
33
|
+
@client.request(method: "GET", path: "/v2.1/merchants/#{path_segment(merchant_code)}/transactions",
|
|
34
|
+
query: {"id" => id, "transaction_code" => transaction_code, "foreign_transaction_id" => foreign_transaction_id, "client_transaction_id" => client_transaction_id}, options: options,
|
|
35
|
+
response_type: {200 => [:model, "TransactionFull"]}, with_response: false)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get_with_response(merchant_code:, id: UNSET, transaction_code: UNSET, foreign_transaction_id: UNSET, client_transaction_id: UNSET, options: nil)
|
|
39
|
+
@client.request(method: "GET", path: "/v2.1/merchants/#{path_segment(merchant_code)}/transactions",
|
|
40
|
+
query: {"id" => id, "transaction_code" => transaction_code, "foreign_transaction_id" => foreign_transaction_id, "client_transaction_id" => client_transaction_id}, options: options,
|
|
41
|
+
response_type: {200 => [:model, "TransactionFull"]}, with_response: true)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Lists transaction history for the merchant, with optional filters for payment type, status, and date range. The response contains the current page in `items` and pagination query strings in `links`.
|
|
45
|
+
#
|
|
46
|
+
# To request another page, use the query string from the relevant link's `href` with this history endpoint. Use `changes_since` when retrieving transactions modified since a previous synchronization, including transactions created earlier whose status has changed.
|
|
47
|
+
# @return [Types::ListTransactionsV21Response]
|
|
48
|
+
def list(merchant_code:, transaction_code: UNSET, order: UNSET, limit: UNSET, users: UNSET, statuses: UNSET, payment_types: UNSET, entry_modes: UNSET, types: UNSET, changes_since: UNSET, newest_time: UNSET, newest_ref: UNSET, oldest_time: UNSET, oldest_ref: UNSET, options: nil)
|
|
49
|
+
@client.request(method: "GET", path: "/v2.1/merchants/#{path_segment(merchant_code)}/transactions/history",
|
|
50
|
+
query: {"transaction_code" => transaction_code, "order" => order, "limit" => limit, "users[]" => users, "statuses[]" => statuses, "payment_types[]" => payment_types, "entry_modes[]" => entry_modes, "types[]" => types, "changes_since" => changes_since, "newest_time" => newest_time, "newest_ref" => newest_ref, "oldest_time" => oldest_time, "oldest_ref" => oldest_ref}, options: options,
|
|
51
|
+
response_type: {200 => [:model, "ListTransactionsV21Response"]}, with_response: false)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def list_with_response(merchant_code:, transaction_code: UNSET, order: UNSET, limit: UNSET, users: UNSET, statuses: UNSET, payment_types: UNSET, entry_modes: UNSET, types: UNSET, changes_since: UNSET, newest_time: UNSET, newest_ref: UNSET, oldest_time: UNSET, oldest_ref: UNSET, options: nil)
|
|
55
|
+
@client.request(method: "GET", path: "/v2.1/merchants/#{path_segment(merchant_code)}/transactions/history",
|
|
56
|
+
query: {"transaction_code" => transaction_code, "order" => order, "limit" => limit, "users[]" => users, "statuses[]" => statuses, "payment_types[]" => payment_types, "entry_modes[]" => entry_modes, "types[]" => types, "changes_since" => changes_since, "newest_time" => newest_time, "newest_ref" => newest_ref, "oldest_time" => oldest_time, "oldest_ref" => oldest_ref}, options: options,
|
|
57
|
+
response_type: {200 => [:model, "ListTransactionsV21Response"]}, with_response: true)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by codegen. DO NOT EDIT.
|
|
4
|
+
|
|
5
|
+
require_relative "resources/checkouts"
|
|
6
|
+
require_relative "resources/customers"
|
|
7
|
+
require_relative "resources/members"
|
|
8
|
+
require_relative "resources/memberships"
|
|
9
|
+
require_relative "resources/merchants"
|
|
10
|
+
require_relative "resources/payouts"
|
|
11
|
+
require_relative "resources/readers"
|
|
12
|
+
require_relative "resources/receipts"
|
|
13
|
+
require_relative "resources/roles"
|
|
14
|
+
require_relative "resources/sales"
|
|
15
|
+
require_relative "resources/tokens"
|
|
16
|
+
require_relative "resources/transactions"
|
|
17
|
+
|
|
18
|
+
module SumUp
|
|
19
|
+
class Client
|
|
20
|
+
RESOURCES = {
|
|
21
|
+
checkouts: Resources::Checkouts,
|
|
22
|
+
customers: Resources::Customers,
|
|
23
|
+
members: Resources::Members,
|
|
24
|
+
memberships: Resources::Memberships,
|
|
25
|
+
merchants: Resources::Merchants,
|
|
26
|
+
payouts: Resources::Payouts,
|
|
27
|
+
readers: Resources::Readers,
|
|
28
|
+
receipts: Resources::Receipts,
|
|
29
|
+
roles: Resources::Roles,
|
|
30
|
+
sales: Resources::Sales,
|
|
31
|
+
tokens: Resources::Tokens,
|
|
32
|
+
transactions: Resources::Transactions
|
|
33
|
+
}.freeze
|
|
34
|
+
|
|
35
|
+
def checkouts
|
|
36
|
+
@resources.fetch(:checkouts)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def customers
|
|
40
|
+
@resources.fetch(:customers)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def members
|
|
44
|
+
@resources.fetch(:members)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def memberships
|
|
48
|
+
@resources.fetch(:memberships)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def merchants
|
|
52
|
+
@resources.fetch(:merchants)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def payouts
|
|
56
|
+
@resources.fetch(:payouts)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def readers
|
|
60
|
+
@resources.fetch(:readers)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def receipts
|
|
64
|
+
@resources.fetch(:receipts)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def roles
|
|
68
|
+
@resources.fetch(:roles)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def sales
|
|
72
|
+
@resources.fetch(:sales)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def tokens
|
|
76
|
+
@resources.fetch(:tokens)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def transactions
|
|
80
|
+
@resources.fetch(:transactions)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "openssl"
|
|
5
|
+
|
|
6
|
+
module SumUp
|
|
7
|
+
# Request passed to custom transports. Headers can contain credentials.
|
|
8
|
+
Request = Data.define(:method, :uri, :headers, :body, :open_timeout, :read_timeout, :write_timeout) do
|
|
9
|
+
def inspect
|
|
10
|
+
"#<SumUp::Request method=#{method}>"
|
|
11
|
+
end
|
|
12
|
+
alias_method :to_s, :inspect
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Transport response, before JSON decoding. Header names are normalized by Client.
|
|
16
|
+
HTTPResponse = Data.define(:status, :headers, :body) do
|
|
17
|
+
def inspect
|
|
18
|
+
"#<SumUp::HTTPResponse status=#{status}>"
|
|
19
|
+
end
|
|
20
|
+
alias_method :to_s, :inspect
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class NetHTTPTransport
|
|
24
|
+
def call(request)
|
|
25
|
+
uri = request.uri
|
|
26
|
+
http = Net::HTTP.new(uri.hostname, uri.port)
|
|
27
|
+
http.use_ssl = uri.scheme == "https"
|
|
28
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
29
|
+
http.open_timeout = request.open_timeout
|
|
30
|
+
http.read_timeout = request.read_timeout
|
|
31
|
+
http.write_timeout = request.write_timeout
|
|
32
|
+
# Retry policy belongs to Client, including the decision to retry writes.
|
|
33
|
+
http.max_retries = 0
|
|
34
|
+
message = Net::HTTPGenericRequest.new(request.method, !request.body.nil?, true, uri.request_uri, request.headers)
|
|
35
|
+
message.body = request.body
|
|
36
|
+
response = http.start { |connection| connection.request(message) }
|
|
37
|
+
HTTPResponse.new(status: response.code.to_i, headers: response.to_hash.transform_values { |values| values.join(", ") }, body: response.body.to_s)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|