square.rb 26.1.0.20230119 → 27.0.0.20230419

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -0
  3. data/lib/square/api/apple_pay_api.rb +14 -30
  4. data/lib/square/api/bank_accounts_api.rb +40 -90
  5. data/lib/square/api/base_api.rb +42 -42
  6. data/lib/square/api/booking_custom_attributes_api.rb +171 -336
  7. data/lib/square/api/bookings_api.rb +140 -263
  8. data/lib/square/api/cards_api.rb +58 -120
  9. data/lib/square/api/cash_drawers_api.rb +47 -103
  10. data/lib/square/api/catalog_api.rb +200 -426
  11. data/lib/square/api/checkout_api.rb +86 -176
  12. data/lib/square/api/customer_custom_attributes_api.rb +157 -310
  13. data/lib/square/api/customer_groups_api.rb +69 -145
  14. data/lib/square/api/customer_segments_api.rb +26 -61
  15. data/lib/square/api/customers_api.rb +147 -294
  16. data/lib/square/api/devices_api.rb +42 -89
  17. data/lib/square/api/disputes_api.rb +132 -290
  18. data/lib/square/api/employees_api.rb +28 -63
  19. data/lib/square/api/gift_card_activities_api.rb +34 -66
  20. data/lib/square/api/gift_cards_api.rb +109 -207
  21. data/lib/square/api/inventory_api.rb +204 -391
  22. data/lib/square/api/invoices_api.rb +121 -240
  23. data/lib/square/api/labor_api.rb +223 -459
  24. data/lib/square/api/location_custom_attributes_api.rb +173 -338
  25. data/lib/square/api/locations_api.rb +54 -112
  26. data/lib/square/api/loyalty_api.rb +283 -535
  27. data/lib/square/api/merchants_api.rb +25 -60
  28. data/lib/square/api/mobile_authorization_api.rb +14 -30
  29. data/lib/square/api/o_auth_api.rb +54 -109
  30. data/lib/square/api/order_custom_attributes_api.rb +174 -339
  31. data/lib/square/api/orders_api.rb +115 -222
  32. data/lib/square/api/payments_api.rb +118 -217
  33. data/lib/square/api/payouts_api.rb +54 -107
  34. data/lib/square/api/refunds_api.rb +59 -104
  35. data/lib/square/api/sites_api.rb +11 -28
  36. data/lib/square/api/snippets_api.rb +42 -90
  37. data/lib/square/api/subscriptions_api.rb +150 -299
  38. data/lib/square/api/team_api.rb +114 -224
  39. data/lib/square/api/terminal_api.rb +162 -328
  40. data/lib/square/api/transactions_api.rb +64 -128
  41. data/lib/square/api/v1_transactions_api.rb +155 -296
  42. data/lib/square/api/vendors_api.rb +100 -193
  43. data/lib/square/api/webhook_subscriptions_api.rb +124 -244
  44. data/lib/square/api_helper.rb +1 -437
  45. data/lib/square/client.rb +77 -47
  46. data/lib/square/configuration.rb +28 -53
  47. data/lib/square/exceptions/api_exception.rb +1 -11
  48. data/lib/square/http/api_response.rb +13 -19
  49. data/lib/square/http/auth/o_auth2.rb +14 -7
  50. data/lib/square/http/http_call_back.rb +1 -15
  51. data/lib/square/http/http_method_enum.rb +1 -4
  52. data/lib/square/http/http_request.rb +1 -45
  53. data/lib/square/http/http_response.rb +1 -20
  54. data/lib/square/utilities/date_time_helper.rb +1 -146
  55. data/lib/square/utilities/file_wrapper.rb +5 -5
  56. data/lib/square.rb +6 -6
  57. data/spec/user_journey_spec.rb +2 -2
  58. data/test/api/api_test_base.rb +13 -5
  59. data/test/api/test_catalog_api.rb +5 -4
  60. data/test/api/test_customers_api.rb +3 -2
  61. data/test/api/test_employees_api.rb +4 -3
  62. data/test/api/test_labor_api.rb +6 -5
  63. data/test/api/test_locations_api.rb +3 -2
  64. data/test/api/test_merchants_api.rb +4 -3
  65. data/test/api/test_payments_api.rb +4 -3
  66. data/test/api/test_refunds_api.rb +4 -3
  67. metadata +11 -111
  68. data/lib/square/exceptions/validation_exception.rb +0 -13
  69. data/lib/square/http/faraday_client.rb +0 -93
  70. data/lib/square/http/http_client.rb +0 -118
  71. data/test/test_helper.rb +0 -89
@@ -1,35 +1,33 @@
1
1
  module Square
2
2
  # RefundsApi
3
3
  class RefundsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Retrieves a list of refunds for the account making the request.
9
5
  # Results are eventually consistent, and new refunds or changes to refunds
10
6
  # might take several
11
7
  # seconds to appear.
12
8
  # The maximum results per page is 100.
13
- # @param [String] begin_time Optional parameter: The timestamp for the
14
- # beginning of the requested reporting period, in RFC 3339 format. Default:
15
- # The current time minus one year.
16
- # @param [String] end_time Optional parameter: The timestamp for the end of
17
- # the requested reporting period, in RFC 3339 format. Default: The current
18
- # time.
9
+ # @param [String] begin_time Optional parameter: Indicates the start of the
10
+ # time range to retrieve each PaymentRefund` for, in RFC 3339 format. The
11
+ # range is determined using the `created_at` field for each `PaymentRefund`.
12
+ # Default: The current time minus one year.
13
+ # @param [String] end_time Optional parameter: Indicates the end of the time
14
+ # range to retrieve each `PaymentRefund` for, in RFC 3339 format. The
15
+ # range is determined using the `created_at` field for each `PaymentRefund`.
16
+ # Default: The current time.
19
17
  # @param [String] sort_order Optional parameter: The order in which results
20
- # are listed: - `ASC` - Oldest to newest. - `DESC` - Newest to oldest
21
- # (default).
18
+ # are listed by `PaymentRefund.created_at`: - `ASC` - Oldest to newest. -
19
+ # `DESC` - Newest to oldest (default).
22
20
  # @param [String] cursor Optional parameter: A pagination cursor returned by
23
21
  # a previous call to this endpoint. Provide this cursor to retrieve the next
24
22
  # set of results for the original query. For more information, see
25
- # [Pagination](https://developer.squareup.com/docs/basics/api101/pagination)
26
- # .
23
+ # [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
24
+ # atterns/pagination).
27
25
  # @param [String] location_id Optional parameter: Limit results to the
28
26
  # location supplied. By default, results are returned for all locations
29
27
  # associated with the seller.
30
28
  # @param [String] status Optional parameter: If provided, only refunds with
31
29
  # the given status are returned. For a list of refund status values, see
32
- # [PaymentRefund]($m/PaymentRefund). Default: If omitted, refunds are
30
+ # [PaymentRefund](entity:PaymentRefund). Default: If omitted, refunds are
33
31
  # returned regardless of their status.
34
32
  # @param [String] source_type Optional parameter: If provided, only returns
35
33
  # refunds whose payments have the indicated source type. Current values
@@ -51,41 +49,25 @@ module Square
51
49
  status: nil,
52
50
  source_type: nil,
53
51
  limit: nil)
54
- # Prepare query url.
55
- _query_builder = config.get_base_uri
56
- _query_builder << '/v2/refunds'
57
- _query_builder = APIHelper.append_url_with_query_parameters(
58
- _query_builder,
59
- 'begin_time' => begin_time,
60
- 'end_time' => end_time,
61
- 'sort_order' => sort_order,
62
- 'cursor' => cursor,
63
- 'location_id' => location_id,
64
- 'status' => status,
65
- 'source_type' => source_type,
66
- 'limit' => limit
67
- )
68
- _query_url = APIHelper.clean_url _query_builder
69
-
70
- # Prepare headers.
71
- _headers = {
72
- 'accept' => 'application/json'
73
- }
74
-
75
- # Prepare and execute HttpRequest.
76
- _request = config.http_client.get(
77
- _query_url,
78
- headers: _headers
79
- )
80
- OAuth2.apply(config, _request)
81
- _response = execute_request(_request)
82
-
83
- # Return appropriate response type.
84
- decoded = APIHelper.json_deserialize(_response.raw_body)
85
- _errors = APIHelper.map_response(decoded, ['errors'])
86
- ApiResponse.new(
87
- _response, data: decoded, errors: _errors
88
- )
52
+ new_api_call_builder
53
+ .request(new_request_builder(HttpMethodEnum::GET,
54
+ '/v2/refunds',
55
+ 'default')
56
+ .query_param(new_parameter(begin_time, key: 'begin_time'))
57
+ .query_param(new_parameter(end_time, key: 'end_time'))
58
+ .query_param(new_parameter(sort_order, key: 'sort_order'))
59
+ .query_param(new_parameter(cursor, key: 'cursor'))
60
+ .query_param(new_parameter(location_id, key: 'location_id'))
61
+ .query_param(new_parameter(status, key: 'status'))
62
+ .query_param(new_parameter(source_type, key: 'source_type'))
63
+ .query_param(new_parameter(limit, key: 'limit'))
64
+ .header_param(new_parameter('application/json', key: 'accept'))
65
+ .auth(Single.new('global')))
66
+ .response(new_response_handler
67
+ .deserializer(APIHelper.method(:json_deserialize))
68
+ .is_api_response(true)
69
+ .convertor(ApiResponse.method(:create)))
70
+ .execute
89
71
  end
90
72
 
91
73
  # Refunds a payment. You can refund the entire payment amount or a
@@ -100,32 +82,20 @@ module Square
100
82
  # object definition for field details.
101
83
  # @return [RefundPaymentResponse Hash] response from the API call
102
84
  def refund_payment(body:)
103
- # Prepare query url.
104
- _query_builder = config.get_base_uri
105
- _query_builder << '/v2/refunds'
106
- _query_url = APIHelper.clean_url _query_builder
107
-
108
- # Prepare headers.
109
- _headers = {
110
- 'accept' => 'application/json',
111
- 'Content-Type' => 'application/json'
112
- }
113
-
114
- # Prepare and execute HttpRequest.
115
- _request = config.http_client.post(
116
- _query_url,
117
- headers: _headers,
118
- parameters: body.to_json
119
- )
120
- OAuth2.apply(config, _request)
121
- _response = execute_request(_request)
122
-
123
- # Return appropriate response type.
124
- decoded = APIHelper.json_deserialize(_response.raw_body)
125
- _errors = APIHelper.map_response(decoded, ['errors'])
126
- ApiResponse.new(
127
- _response, data: decoded, errors: _errors
128
- )
85
+ new_api_call_builder
86
+ .request(new_request_builder(HttpMethodEnum::POST,
87
+ '/v2/refunds',
88
+ 'default')
89
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
90
+ .body_param(new_parameter(body))
91
+ .header_param(new_parameter('application/json', key: 'accept'))
92
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
93
+ .auth(Single.new('global')))
94
+ .response(new_response_handler
95
+ .deserializer(APIHelper.method(:json_deserialize))
96
+ .is_api_response(true)
97
+ .convertor(ApiResponse.method(:create)))
98
+ .execute
129
99
  end
130
100
 
131
101
  # Retrieves a specific refund using the `refund_id`.
@@ -133,34 +103,19 @@ module Square
133
103
  # desired `PaymentRefund`.
134
104
  # @return [GetPaymentRefundResponse Hash] response from the API call
135
105
  def get_payment_refund(refund_id:)
136
- # Prepare query url.
137
- _query_builder = config.get_base_uri
138
- _query_builder << '/v2/refunds/{refund_id}'
139
- _query_builder = APIHelper.append_url_with_template_parameters(
140
- _query_builder,
141
- 'refund_id' => { 'value' => refund_id, 'encode' => true }
142
- )
143
- _query_url = APIHelper.clean_url _query_builder
144
-
145
- # Prepare headers.
146
- _headers = {
147
- 'accept' => 'application/json'
148
- }
149
-
150
- # Prepare and execute HttpRequest.
151
- _request = config.http_client.get(
152
- _query_url,
153
- headers: _headers
154
- )
155
- OAuth2.apply(config, _request)
156
- _response = execute_request(_request)
157
-
158
- # Return appropriate response type.
159
- decoded = APIHelper.json_deserialize(_response.raw_body)
160
- _errors = APIHelper.map_response(decoded, ['errors'])
161
- ApiResponse.new(
162
- _response, data: decoded, errors: _errors
163
- )
106
+ new_api_call_builder
107
+ .request(new_request_builder(HttpMethodEnum::GET,
108
+ '/v2/refunds/{refund_id}',
109
+ 'default')
110
+ .template_param(new_parameter(refund_id, key: 'refund_id')
111
+ .should_encode(true))
112
+ .header_param(new_parameter('application/json', key: 'accept'))
113
+ .auth(Single.new('global')))
114
+ .response(new_response_handler
115
+ .deserializer(APIHelper.method(:json_deserialize))
116
+ .is_api_response(true)
117
+ .convertor(ApiResponse.method(:create)))
118
+ .execute
164
119
  end
165
120
  end
166
121
  end
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # SitesApi
3
3
  class SitesApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Lists the Square Online sites that belong to a seller. Sites are listed in
9
5
  # descending order by the `created_at` date.
10
6
  # __Note:__ Square Online APIs are publicly available as part of an early
@@ -14,30 +10,17 @@ module Square
14
10
  # for-square-online-apis).
15
11
  # @return [ListSitesResponse Hash] response from the API call
16
12
  def list_sites
17
- # Prepare query url.
18
- _query_builder = config.get_base_uri
19
- _query_builder << '/v2/sites'
20
- _query_url = APIHelper.clean_url _query_builder
21
-
22
- # Prepare headers.
23
- _headers = {
24
- 'accept' => 'application/json'
25
- }
26
-
27
- # Prepare and execute HttpRequest.
28
- _request = config.http_client.get(
29
- _query_url,
30
- headers: _headers
31
- )
32
- OAuth2.apply(config, _request)
33
- _response = execute_request(_request)
34
-
35
- # Return appropriate response type.
36
- decoded = APIHelper.json_deserialize(_response.raw_body)
37
- _errors = APIHelper.map_response(decoded, ['errors'])
38
- ApiResponse.new(
39
- _response, data: decoded, errors: _errors
40
- )
13
+ new_api_call_builder
14
+ .request(new_request_builder(HttpMethodEnum::GET,
15
+ '/v2/sites',
16
+ 'default')
17
+ .header_param(new_parameter('application/json', key: 'accept'))
18
+ .auth(Single.new('global')))
19
+ .response(new_response_handler
20
+ .deserializer(APIHelper.method(:json_deserialize))
21
+ .is_api_response(true)
22
+ .convertor(ApiResponse.method(:create)))
23
+ .execute
41
24
  end
42
25
  end
43
26
  end
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # SnippetsApi
3
3
  class SnippetsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Removes your snippet from a Square Online site.
9
5
  # You can call [ListSites]($e/Sites/ListSites) to get the IDs of the sites
10
6
  # that belong to a seller.
@@ -17,34 +13,19 @@ module Square
17
13
  # contains the snippet.
18
14
  # @return [DeleteSnippetResponse Hash] response from the API call
19
15
  def delete_snippet(site_id:)
20
- # Prepare query url.
21
- _query_builder = config.get_base_uri
22
- _query_builder << '/v2/sites/{site_id}/snippet'
23
- _query_builder = APIHelper.append_url_with_template_parameters(
24
- _query_builder,
25
- 'site_id' => { 'value' => site_id, 'encode' => true }
26
- )
27
- _query_url = APIHelper.clean_url _query_builder
28
-
29
- # Prepare headers.
30
- _headers = {
31
- 'accept' => 'application/json'
32
- }
33
-
34
- # Prepare and execute HttpRequest.
35
- _request = config.http_client.delete(
36
- _query_url,
37
- headers: _headers
38
- )
39
- OAuth2.apply(config, _request)
40
- _response = execute_request(_request)
41
-
42
- # Return appropriate response type.
43
- decoded = APIHelper.json_deserialize(_response.raw_body)
44
- _errors = APIHelper.map_response(decoded, ['errors'])
45
- ApiResponse.new(
46
- _response, data: decoded, errors: _errors
47
- )
16
+ new_api_call_builder
17
+ .request(new_request_builder(HttpMethodEnum::DELETE,
18
+ '/v2/sites/{site_id}/snippet',
19
+ 'default')
20
+ .template_param(new_parameter(site_id, key: 'site_id')
21
+ .should_encode(true))
22
+ .header_param(new_parameter('application/json', key: 'accept'))
23
+ .auth(Single.new('global')))
24
+ .response(new_response_handler
25
+ .deserializer(APIHelper.method(:json_deserialize))
26
+ .is_api_response(true)
27
+ .convertor(ApiResponse.method(:create)))
28
+ .execute
48
29
  end
49
30
 
50
31
  # Retrieves your snippet from a Square Online site. A site can contain
@@ -61,34 +42,19 @@ module Square
61
42
  # contains the snippet.
62
43
  # @return [RetrieveSnippetResponse Hash] response from the API call
63
44
  def retrieve_snippet(site_id:)
64
- # Prepare query url.
65
- _query_builder = config.get_base_uri
66
- _query_builder << '/v2/sites/{site_id}/snippet'
67
- _query_builder = APIHelper.append_url_with_template_parameters(
68
- _query_builder,
69
- 'site_id' => { 'value' => site_id, 'encode' => true }
70
- )
71
- _query_url = APIHelper.clean_url _query_builder
72
-
73
- # Prepare headers.
74
- _headers = {
75
- 'accept' => 'application/json'
76
- }
77
-
78
- # Prepare and execute HttpRequest.
79
- _request = config.http_client.get(
80
- _query_url,
81
- headers: _headers
82
- )
83
- OAuth2.apply(config, _request)
84
- _response = execute_request(_request)
85
-
86
- # Return appropriate response type.
87
- decoded = APIHelper.json_deserialize(_response.raw_body)
88
- _errors = APIHelper.map_response(decoded, ['errors'])
89
- ApiResponse.new(
90
- _response, data: decoded, errors: _errors
91
- )
45
+ new_api_call_builder
46
+ .request(new_request_builder(HttpMethodEnum::GET,
47
+ '/v2/sites/{site_id}/snippet',
48
+ 'default')
49
+ .template_param(new_parameter(site_id, key: 'site_id')
50
+ .should_encode(true))
51
+ .header_param(new_parameter('application/json', key: 'accept'))
52
+ .auth(Single.new('global')))
53
+ .response(new_response_handler
54
+ .deserializer(APIHelper.method(:json_deserialize))
55
+ .is_api_response(true)
56
+ .convertor(ApiResponse.method(:create)))
57
+ .execute
92
58
  end
93
59
 
94
60
  # Adds a snippet to a Square Online site or updates the existing snippet on
@@ -111,36 +77,22 @@ module Square
111
77
  # @return [UpsertSnippetResponse Hash] response from the API call
112
78
  def upsert_snippet(site_id:,
113
79
  body:)
114
- # Prepare query url.
115
- _query_builder = config.get_base_uri
116
- _query_builder << '/v2/sites/{site_id}/snippet'
117
- _query_builder = APIHelper.append_url_with_template_parameters(
118
- _query_builder,
119
- 'site_id' => { 'value' => site_id, 'encode' => true }
120
- )
121
- _query_url = APIHelper.clean_url _query_builder
122
-
123
- # Prepare headers.
124
- _headers = {
125
- 'accept' => 'application/json',
126
- 'Content-Type' => 'application/json'
127
- }
128
-
129
- # Prepare and execute HttpRequest.
130
- _request = config.http_client.post(
131
- _query_url,
132
- headers: _headers,
133
- parameters: body.to_json
134
- )
135
- OAuth2.apply(config, _request)
136
- _response = execute_request(_request)
137
-
138
- # Return appropriate response type.
139
- decoded = APIHelper.json_deserialize(_response.raw_body)
140
- _errors = APIHelper.map_response(decoded, ['errors'])
141
- ApiResponse.new(
142
- _response, data: decoded, errors: _errors
143
- )
80
+ new_api_call_builder
81
+ .request(new_request_builder(HttpMethodEnum::POST,
82
+ '/v2/sites/{site_id}/snippet',
83
+ 'default')
84
+ .template_param(new_parameter(site_id, key: 'site_id')
85
+ .should_encode(true))
86
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
87
+ .body_param(new_parameter(body))
88
+ .header_param(new_parameter('application/json', key: 'accept'))
89
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
90
+ .auth(Single.new('global')))
91
+ .response(new_response_handler
92
+ .deserializer(APIHelper.method(:json_deserialize))
93
+ .is_api_response(true)
94
+ .convertor(ApiResponse.method(:create)))
95
+ .execute
144
96
  end
145
97
  end
146
98
  end