square.rb 26.0.0.20221214 → 26.2.0.20230315

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  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 +164 -329
  7. data/lib/square/api/bookings_api.rb +135 -260
  8. data/lib/square/api/cards_api.rb +56 -118
  9. data/lib/square/api/cash_drawers_api.rb +47 -103
  10. data/lib/square/api/catalog_api.rb +197 -423
  11. data/lib/square/api/checkout_api.rb +85 -175
  12. data/lib/square/api/customer_custom_attributes_api.rb +150 -303
  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 +130 -288
  18. data/lib/square/api/employees_api.rb +28 -63
  19. data/lib/square/api/gift_card_activities_api.rb +33 -65
  20. data/lib/square/api/gift_cards_api.rb +103 -202
  21. data/lib/square/api/inventory_api.rb +179 -366
  22. data/lib/square/api/invoices_api.rb +118 -237
  23. data/lib/square/api/labor_api.rb +223 -459
  24. data/lib/square/api/location_custom_attributes_api.rb +419 -0
  25. data/lib/square/api/locations_api.rb +54 -112
  26. data/lib/square/api/loyalty_api.rb +259 -512
  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 +168 -333
  31. data/lib/square/api/orders_api.rb +115 -222
  32. data/lib/square/api/payments_api.rb +106 -208
  33. data/lib/square/api/payouts_api.rb +47 -100
  34. data/lib/square/api/refunds_api.rb +46 -93
  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 +62 -126
  41. data/lib/square/api/v1_transactions_api.rb +155 -296
  42. data/lib/square/api/vendors_api.rb +99 -192
  43. data/lib/square/api/webhook_subscriptions_api.rb +115 -235
  44. data/lib/square/api_helper.rb +1 -437
  45. data/lib/square/client.rb +82 -46
  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 +7 -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 +12 -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,10 +1,6 @@
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
@@ -51,41 +47,25 @@ module Square
51
47
  status: nil,
52
48
  source_type: nil,
53
49
  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
- )
50
+ new_api_call_builder
51
+ .request(new_request_builder(HttpMethodEnum::GET,
52
+ '/v2/refunds',
53
+ 'default')
54
+ .query_param(new_parameter(begin_time, key: 'begin_time'))
55
+ .query_param(new_parameter(end_time, key: 'end_time'))
56
+ .query_param(new_parameter(sort_order, key: 'sort_order'))
57
+ .query_param(new_parameter(cursor, key: 'cursor'))
58
+ .query_param(new_parameter(location_id, key: 'location_id'))
59
+ .query_param(new_parameter(status, key: 'status'))
60
+ .query_param(new_parameter(source_type, key: 'source_type'))
61
+ .query_param(new_parameter(limit, key: 'limit'))
62
+ .header_param(new_parameter('application/json', key: 'accept'))
63
+ .auth(Single.new('global')))
64
+ .response(new_response_handler
65
+ .deserializer(APIHelper.method(:json_deserialize))
66
+ .is_api_response(true)
67
+ .convertor(ApiResponse.method(:create)))
68
+ .execute
89
69
  end
90
70
 
91
71
  # Refunds a payment. You can refund the entire payment amount or a
@@ -100,32 +80,20 @@ module Square
100
80
  # object definition for field details.
101
81
  # @return [RefundPaymentResponse Hash] response from the API call
102
82
  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
- )
83
+ new_api_call_builder
84
+ .request(new_request_builder(HttpMethodEnum::POST,
85
+ '/v2/refunds',
86
+ 'default')
87
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
88
+ .body_param(new_parameter(body))
89
+ .header_param(new_parameter('application/json', key: 'accept'))
90
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
91
+ .auth(Single.new('global')))
92
+ .response(new_response_handler
93
+ .deserializer(APIHelper.method(:json_deserialize))
94
+ .is_api_response(true)
95
+ .convertor(ApiResponse.method(:create)))
96
+ .execute
129
97
  end
130
98
 
131
99
  # Retrieves a specific refund using the `refund_id`.
@@ -133,34 +101,19 @@ module Square
133
101
  # desired `PaymentRefund`.
134
102
  # @return [GetPaymentRefundResponse Hash] response from the API call
135
103
  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
- )
104
+ new_api_call_builder
105
+ .request(new_request_builder(HttpMethodEnum::GET,
106
+ '/v2/refunds/{refund_id}',
107
+ 'default')
108
+ .template_param(new_parameter(refund_id, key: 'refund_id')
109
+ .should_encode(true))
110
+ .header_param(new_parameter('application/json', key: 'accept'))
111
+ .auth(Single.new('global')))
112
+ .response(new_response_handler
113
+ .deserializer(APIHelper.method(:json_deserialize))
114
+ .is_api_response(true)
115
+ .convertor(ApiResponse.method(:create)))
116
+ .execute
164
117
  end
165
118
  end
166
119
  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