square.rb 31.0.0.20230816 → 33.0.0.20231018

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a240a4a6d004debbbfa68cda7f06de20424c7095df8cdd3f9874dab556d6f869
4
- data.tar.gz: 5387eaf02e834b69df1cd238a8ba68e3d7195966d8b40f831e9942f52066e39f
3
+ metadata.gz: b1a9e797a4ed71794d0b22d02812a467b629f093bf7b52d0f431d1989b7674ae
4
+ data.tar.gz: b9f99ab1089d405de8c1e73efb286beed4f3c0e609c40e84a0453e403c31c57f
5
5
  SHA512:
6
- metadata.gz: d0296c13c1fc83e7e54d56cc397929f3d50ed3d243505c6372e890e7fec6cb65b6aabafd62bf15f80602982196ab36103bc8e7b816c633665717e172e0a8bdda
7
- data.tar.gz: 2dce736c93cff6399463e35427319a4fe82009019c1300eafc39b3588a0056bdbba7bc26489b31f18152e22ffe6e9c7aadf10640b46384d8d0812755e65ab431
6
+ metadata.gz: 5d425e644acdb896add3713f6a5883d998e37a9cd7ffe444186cff00b169f7a1fc2d1fbb492a75eb853547e28e2fe623829ece836224c3175eb25767aa9b65ff
7
+ data.tar.gz: 78de8fb5d730819d3e731776ed7c87c8448feec80666a1d5b9b4a594fa78f8aa1521f25c81fc7ec03bb17f762e7b80a12f436090d030d3c44c40a4468dafa210
@@ -4,7 +4,7 @@ module Square
4
4
  attr_accessor :config, :http_call_back
5
5
 
6
6
  def self.user_agent
7
- 'Square-Ruby-SDK/31.0.0.20230816 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
7
+ 'Square-Ruby-SDK/33.0.0.20231018 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
8
8
  end
9
9
 
10
10
  def self.user_agent_parameters
@@ -157,6 +157,50 @@ module Square
157
157
  .execute
158
158
  end
159
159
 
160
+ # Lists location booking profiles of a seller.
161
+ # @param [Integer] limit Optional parameter: The maximum number of results
162
+ # to return in a paged response.
163
+ # @param [String] cursor Optional parameter: The pagination cursor from the
164
+ # preceding response to return the next page of the results. Do not set this
165
+ # when retrieving the first page of the results.
166
+ # @return [ListLocationBookingProfilesResponse Hash] response from the API call
167
+ def list_location_booking_profiles(limit: nil,
168
+ cursor: nil)
169
+ new_api_call_builder
170
+ .request(new_request_builder(HttpMethodEnum::GET,
171
+ '/v2/bookings/location-booking-profiles',
172
+ 'default')
173
+ .query_param(new_parameter(limit, key: 'limit'))
174
+ .query_param(new_parameter(cursor, key: 'cursor'))
175
+ .header_param(new_parameter('application/json', key: 'accept'))
176
+ .auth(Single.new('global')))
177
+ .response(new_response_handler
178
+ .deserializer(APIHelper.method(:json_deserialize))
179
+ .is_api_response(true)
180
+ .convertor(ApiResponse.method(:create)))
181
+ .execute
182
+ end
183
+
184
+ # Retrieves a seller's location booking profile.
185
+ # @param [String] location_id Required parameter: The ID of the location to
186
+ # retrieve the booking profile.
187
+ # @return [RetrieveLocationBookingProfileResponse Hash] response from the API call
188
+ def retrieve_location_booking_profile(location_id:)
189
+ new_api_call_builder
190
+ .request(new_request_builder(HttpMethodEnum::GET,
191
+ '/v2/bookings/location-booking-profiles/{location_id}',
192
+ 'default')
193
+ .template_param(new_parameter(location_id, key: 'location_id')
194
+ .should_encode(true))
195
+ .header_param(new_parameter('application/json', key: 'accept'))
196
+ .auth(Single.new('global')))
197
+ .response(new_response_handler
198
+ .deserializer(APIHelper.method(:json_deserialize))
199
+ .is_api_response(true)
200
+ .convertor(ApiResponse.method(:create)))
201
+ .execute
202
+ end
203
+
160
204
  # Lists booking profiles for team members.
161
205
  # @param [TrueClass | FalseClass] bookable_only Optional parameter:
162
206
  # Indicates whether to include only bookable team members in the returned
@@ -191,6 +235,28 @@ module Square
191
235
  .execute
192
236
  end
193
237
 
238
+ # Retrieves one or more team members' booking profiles.
239
+ # @param [BulkRetrieveTeamMemberBookingProfilesRequest] body Required
240
+ # parameter: An object containing the fields to POST for the request. See
241
+ # the corresponding object definition for field details.
242
+ # @return [BulkRetrieveTeamMemberBookingProfilesResponse Hash] response from the API call
243
+ def bulk_retrieve_team_member_booking_profiles(body:)
244
+ new_api_call_builder
245
+ .request(new_request_builder(HttpMethodEnum::POST,
246
+ '/v2/bookings/team-member-booking-profiles/bulk-retrieve',
247
+ 'default')
248
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
249
+ .body_param(new_parameter(body))
250
+ .header_param(new_parameter('application/json', key: 'accept'))
251
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
252
+ .auth(Single.new('global')))
253
+ .response(new_response_handler
254
+ .deserializer(APIHelper.method(:json_deserialize))
255
+ .is_api_response(true)
256
+ .convertor(ApiResponse.method(:create)))
257
+ .execute
258
+ end
259
+
194
260
  # Retrieves a team member's booking profile.
195
261
  # @param [String] team_member_id Required parameter: The ID of the team
196
262
  # member to retrieve.
@@ -8,9 +8,6 @@ module Square
8
8
  # For more information, see [Checkout API
9
9
  # highlights](https://developer.squareup.com/docs/checkout-api#checkout-api-
10
10
  # highlights).
11
- # We recommend that you use the
12
- # new [CreatePaymentLink](api-endpoint:Checkout-CreatePaymentLink)
13
- # endpoint in place of this previously released endpoint.
14
11
  # @param [String] location_id Required parameter: The ID of the business
15
12
  # location to associate the checkout with.
16
13
  # @param [CreateCheckoutRequest] body Required parameter: An object
@@ -1,6 +1,42 @@
1
1
  module Square
2
2
  # DevicesApi
3
3
  class DevicesApi < BaseApi
4
+ # List devices associated with the merchant. Currently, only Terminal API
5
+ # devices are supported.
6
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
7
+ # a previous call to this endpoint. Provide this cursor to retrieve the next
8
+ # set of results for the original query. See
9
+ # [Pagination](https://developer.squareup.com/docs/build-basics/common-api-p
10
+ # atterns/pagination) for more information.
11
+ # @param [SortOrder] sort_order Optional parameter: The order in which
12
+ # results are listed. - `ASC` - Oldest to newest. - `DESC` - Newest to
13
+ # oldest (default).
14
+ # @param [Integer] limit Optional parameter: The number of results to return
15
+ # in a single page.
16
+ # @param [String] location_id Optional parameter: If present, only returns
17
+ # devices at the target location.
18
+ # @return [ListDevicesResponse Hash] response from the API call
19
+ def list_devices(cursor: nil,
20
+ sort_order: nil,
21
+ limit: nil,
22
+ location_id: nil)
23
+ new_api_call_builder
24
+ .request(new_request_builder(HttpMethodEnum::GET,
25
+ '/v2/devices',
26
+ 'default')
27
+ .query_param(new_parameter(cursor, key: 'cursor'))
28
+ .query_param(new_parameter(sort_order, key: 'sort_order'))
29
+ .query_param(new_parameter(limit, key: 'limit'))
30
+ .query_param(new_parameter(location_id, key: 'location_id'))
31
+ .header_param(new_parameter('application/json', key: 'accept'))
32
+ .auth(Single.new('global')))
33
+ .response(new_response_handler
34
+ .deserializer(APIHelper.method(:json_deserialize))
35
+ .is_api_response(true)
36
+ .convertor(ApiResponse.method(:create)))
37
+ .execute
38
+ end
39
+
4
40
  # Lists all DeviceCodes associated with the merchant.
5
41
  # @param [String] cursor Optional parameter: A pagination cursor returned by
6
42
  # a previous call to this endpoint. Provide this to retrieve the next set of
@@ -81,5 +117,25 @@ module Square
81
117
  .convertor(ApiResponse.method(:create)))
82
118
  .execute
83
119
  end
120
+
121
+ # Retrieves Device with the associated `device_id`.
122
+ # @param [String] device_id Required parameter: The unique ID for the
123
+ # desired `Device`.
124
+ # @return [GetDeviceResponse Hash] response from the API call
125
+ def get_device(device_id:)
126
+ new_api_call_builder
127
+ .request(new_request_builder(HttpMethodEnum::GET,
128
+ '/v2/devices/{device_id}',
129
+ 'default')
130
+ .template_param(new_parameter(device_id, key: 'device_id')
131
+ .should_encode(true))
132
+ .header_param(new_parameter('application/json', key: 'accept'))
133
+ .auth(Single.new('global')))
134
+ .response(new_response_handler
135
+ .deserializer(APIHelper.method(:json_deserialize))
136
+ .is_api_response(true)
137
+ .convertor(ApiResponse.method(:create)))
138
+ .execute
139
+ end
84
140
  end
85
141
  end
@@ -1,7 +1,7 @@
1
1
  module Square
2
2
  # EmployeesApi
3
3
  class EmployeesApi < BaseApi
4
- # ListEmployees
4
+ # TODO: type endpoint description here
5
5
  # @param [String] location_id Optional parameter: Example:
6
6
  # @param [EmployeeStatus] status Optional parameter: Specifies the
7
7
  # EmployeeStatus to filter the employee by.
@@ -32,7 +32,7 @@ module Square
32
32
  .execute
33
33
  end
34
34
 
35
- # RetrieveEmployee
35
+ # TODO: type endpoint description here
36
36
  # @param [String] id Required parameter: UUID for the employee that was
37
37
  # requested.
38
38
  # @return [RetrieveEmployeeResponse Hash] response from the API call
@@ -56,10 +56,7 @@ module Square
56
56
  # Revokes an access token generated with the OAuth flow.
57
57
  # If an account has more than one OAuth access token for your application,
58
58
  # this
59
- # endpoint revokes all of them, regardless of which token you specify. When
60
- # an
61
- # OAuth access token is revoked, all of the active subscriptions associated
62
- # with that OAuth token are canceled immediately.
59
+ # endpoint revokes all of them, regardless of which token you specify.
63
60
  # __Important:__ The `Authorization` header for this endpoint must have the
64
61
  # following format:
65
62
  # ```
@@ -32,6 +32,32 @@ module Square
32
32
  .execute
33
33
  end
34
34
 
35
+ # Schedules a plan variation change for all active subscriptions under a
36
+ # given plan
37
+ # variation. For more information, see [Swap Subscription Plan
38
+ # Variations](https://developer.squareup.com/docs/subscriptions-api/swap-pla
39
+ # n-variations).
40
+ # @param [BulkSwapPlanRequest] body Required parameter: An object containing
41
+ # the fields to POST for the request. See the corresponding object
42
+ # definition for field details.
43
+ # @return [BulkSwapPlanResponse Hash] response from the API call
44
+ def bulk_swap_plan(body:)
45
+ new_api_call_builder
46
+ .request(new_request_builder(HttpMethodEnum::POST,
47
+ '/v2/subscriptions/bulk-swap-plan',
48
+ 'default')
49
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
50
+ .body_param(new_parameter(body))
51
+ .header_param(new_parameter('application/json', key: 'accept'))
52
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
53
+ .auth(Single.new('global')))
54
+ .response(new_response_handler
55
+ .deserializer(APIHelper.method(:json_deserialize))
56
+ .is_api_response(true)
57
+ .convertor(ApiResponse.method(:create)))
58
+ .execute
59
+ end
60
+
35
61
  # Searches for subscriptions.
36
62
  # Results are ordered chronologically by subscription creation date. If
37
63
  # the request specifies more than one location ID,
@@ -146,6 +172,36 @@ module Square
146
172
  .execute
147
173
  end
148
174
 
175
+ # Changes the [billing anchor
176
+ # date](https://developer.squareup.com/docs/subscriptions-api/subscription-b
177
+ # illing#billing-dates)
178
+ # for a subscription.
179
+ # @param [String] subscription_id Required parameter: The ID of the
180
+ # subscription to update the billing anchor date.
181
+ # @param [ChangeBillingAnchorDateRequest] body Required parameter: An object
182
+ # containing the fields to POST for the request. See the corresponding
183
+ # object definition for field details.
184
+ # @return [ChangeBillingAnchorDateResponse Hash] response from the API call
185
+ def change_billing_anchor_date(subscription_id:,
186
+ body:)
187
+ new_api_call_builder
188
+ .request(new_request_builder(HttpMethodEnum::POST,
189
+ '/v2/subscriptions/{subscription_id}/billing-anchor',
190
+ 'default')
191
+ .template_param(new_parameter(subscription_id, key: 'subscription_id')
192
+ .should_encode(true))
193
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
194
+ .body_param(new_parameter(body))
195
+ .header_param(new_parameter('application/json', key: 'accept'))
196
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
197
+ .auth(Single.new('global')))
198
+ .response(new_response_handler
199
+ .deserializer(APIHelper.method(:json_deserialize))
200
+ .is_api_response(true)
201
+ .convertor(ApiResponse.method(:create)))
202
+ .execute
203
+ end
204
+
149
205
  # Schedules a `CANCEL` action to cancel an active subscription. This
150
206
  # sets the `canceled_date` field to the end of the active billing period.
151
207
  # After this date,
data/lib/square/client.rb CHANGED
@@ -4,7 +4,7 @@ module Square
4
4
  attr_reader :config, :auth_managers
5
5
 
6
6
  def sdk_version
7
- '31.0.0.20230816'
7
+ '33.0.0.20231018'
8
8
  end
9
9
 
10
10
  def square_version
@@ -267,7 +267,7 @@ module Square
267
267
  retry_methods: %i[get put], http_callback: nil,
268
268
  environment: 'production',
269
269
  custom_url: 'https://connect.squareup.com', access_token: '',
270
- square_version: '2023-08-16', user_agent_detail: '',
270
+ square_version: '2023-10-18', user_agent_detail: '',
271
271
  additional_headers: {}, config: nil)
272
272
  @config = if config.nil?
273
273
  Configuration.new(connection: connection, adapter: adapter,
@@ -19,7 +19,7 @@ module Square
19
19
  retry_methods: %i[get put], http_callback: nil,
20
20
  environment: 'production',
21
21
  custom_url: 'https://connect.squareup.com', access_token: '',
22
- square_version: '2023-08-16', user_agent_detail: '',
22
+ square_version: '2023-10-18', user_agent_detail: '',
23
23
  additional_headers: {})
24
24
 
25
25
  super connection: connection, adapter: adapter, timeout: timeout,
@@ -0,0 +1,23 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+
4
+ module Square
5
+ class WebhooksHelper
6
+ def self.is_valid_webhook_event_signature(request_body, signature_header, signature_key, notification_url)
7
+ return false if request_body.nil?
8
+ raise 'signature_key is null or empty' if signature_key.nil? || signature_key.empty?
9
+ raise 'notification_url is null or empty' if notification_url.nil? || notification_url.empty?
10
+
11
+ # Perform UTF-8 encoding to bytes
12
+ payload_bytes = "#{notification_url}#{request_body}".force_encoding('utf-8')
13
+ signature_key_bytes = signature_key.force_encoding('utf-8')
14
+
15
+ # Compute the hash value
16
+ hmac = OpenSSL::HMAC.digest('sha256', signature_key_bytes, payload_bytes)
17
+
18
+ # Compare the computed hash vs the value in the signature header
19
+ hash_base64 = Base64.strict_encode64(hmac)
20
+ hash_base64 == signature_header
21
+ end
22
+ end
23
+ end
data/lib/square.rb CHANGED
@@ -72,3 +72,4 @@ require_relative 'square/api/team_api'
72
72
  require_relative 'square/api/terminal_api'
73
73
  require_relative 'square/api/vendors_api'
74
74
  require_relative 'square/api/webhook_subscriptions_api'
75
+ require_relative 'square/utilities/webhooks_helper'
@@ -0,0 +1,136 @@
1
+ require_relative '../../lib/square/utilities/webhooks_helper.rb'
2
+ require 'minitest/autorun'
3
+ require 'minitest/hell'
4
+ require 'minitest/pride'
5
+ require 'minitest/proveit'
6
+ require 'logger'
7
+
8
+ class WebhooksHelperTest < Minitest::Test
9
+ # Called only once for the class before any test has executed
10
+ def setup
11
+ @logger = Logger.new(STDOUT) # Create a Logger instance for logging
12
+ @logger.level = Logger::INFO # Set the log level to INFO or any desired level
13
+ @request_body = '{"merchant_id":"MLEFBHHSJGVHD","type":"webhooks.test_notification","event_id":"ac3ac95b-f97d-458c-a6e6-18981597e05f","created_at":"2022-07-13T20:30:59.037339943Z","data":{"type":"webhooks","id":"bc368e64-01aa-407e-b46e-3231809b1129"}}'
14
+ @signature_header = 'GF4YkrJgGBDZ9NIYbNXBnMzqb2HoL4RW/S6vkZ9/2N4='
15
+ @signature_key = 'Ibxx_5AKakO-3qeNVR61Dw'
16
+ @notification_url = 'https://webhook.site/679a4f3a-dcfa-49ee-bac5-9d0edad886b9'
17
+ end
18
+
19
+ def test_signature_validation_pass
20
+ @logger.info('Running test_signature_validation_pass') # Log a message
21
+ is_valid = Square::WebhooksHelper.is_valid_webhook_event_signature(
22
+ @request_body,
23
+ @signature_header,
24
+ @signature_key,
25
+ @notification_url
26
+ )
27
+ assert_equal true, is_valid
28
+ end
29
+
30
+ def test_signature_validation_fails_on_notification_url_mismatch
31
+ @logger.info('Running test_signature_validation_fails_on_notification_url_mismatch') # Log a message
32
+ is_valid = Square::WebhooksHelper.is_valid_webhook_event_signature(
33
+ @request_body,
34
+ @signature_header,
35
+ @signature_key,
36
+ 'https://webhook.site/79a4f3a-dcfa-49ee-bac5-9d0edad886b9'
37
+ )
38
+ assert_equal false, is_valid
39
+ end
40
+
41
+ def test_signature_validation_fails_on_invalid_signature_key
42
+ @logger.info('Running test_signature_validation_fails_on_invalid_signature_key') # Log a message
43
+ is_valid = Square::WebhooksHelper.is_valid_webhook_event_signature(
44
+ @request_body,
45
+ @signature_header,
46
+ 'MCmhFRxGX82xMwg5FsaoQA',
47
+ @notification_url
48
+ )
49
+ assert_equal false, is_valid
50
+ end
51
+
52
+ def test_signature_validation_fails_on_invalid_signature_header
53
+ is_valid = Square::WebhooksHelper.is_valid_webhook_event_signature(
54
+ @request_body,
55
+ '1z2n3DEJJiUPKcPzQo1ftvbxGdw=',
56
+ @signature_key,
57
+ @notification_url
58
+ )
59
+ assert_equal false, is_valid
60
+ end
61
+
62
+ def test_signature_validation_fails_on_request_body_mismatch
63
+ request_body = '{"merchant_id":"MLEFBHHSJGVHD","type":"webhooks.test_notification","event_id":"ac3ac95b-f97d-458c-a6e6-18981597e05f","created_at":"2022-06-13T20:30:59.037339943Z","data":{"type":"webhooks","id":"bc368e64-01aa-407e-b46e-3231809b1129"}}'
64
+ is_valid = Square::WebhooksHelper.is_valid_webhook_event_signature(
65
+ request_body,
66
+ @signature_header,
67
+ @signature_key,
68
+ @notification_url
69
+ )
70
+ assert_equal false, is_valid
71
+ end
72
+
73
+ def test_signature_validation_fails_on_request_body_formatted
74
+ request_body = '{
75
+ "merchant_id": "MLEFBHHSJGVHD",
76
+ "type": "webhooks.test_notification",
77
+ "event_id": "ac3ac95b-f97d-458c-a6e6-18981597e05f",
78
+ "created_at": "2022-07-13T20:30:59.037339943Z",
79
+ "data": {
80
+ "type": "webhooks",
81
+ "id": "bc368e64-01aa-407e-b46e-3231809b1129"
82
+ }
83
+ }'
84
+ is_valid = Square::WebhooksHelper.is_valid_webhook_event_signature(
85
+ request_body,
86
+ @signature_header,
87
+ @signature_key,
88
+ @notification_url
89
+ )
90
+ assert_equal false, is_valid
91
+ end
92
+
93
+ def test_throws_error_on_empty_signature_key
94
+ assert_raises(RuntimeError, 'signature_key is null or empty') do
95
+ Square::WebhooksHelper.is_valid_webhook_event_signature(
96
+ @request_body,
97
+ @signature_header,
98
+ '',
99
+ @notification_url
100
+ )
101
+ end
102
+ end
103
+
104
+ def test_throws_error_on_signature_key_not_configured
105
+ assert_raises(RuntimeError) do
106
+ Square::WebhooksHelper.is_valid_webhook_event_signature(
107
+ @request_body,
108
+ @signature_header,
109
+ nil,
110
+ @notification_url
111
+ )
112
+ end
113
+ end
114
+
115
+ def test_throws_error_on_empty_notification_url
116
+ assert_raises(RuntimeError, 'notification_url is null or empty') do
117
+ Square::WebhooksHelper.is_valid_webhook_event_signature(
118
+ @request_body,
119
+ @signature_header,
120
+ @signature_key,
121
+ ''
122
+ )
123
+ end
124
+ end
125
+
126
+ def test_throws_error_on_notification_url_not_configured
127
+ assert_raises(RuntimeError) do
128
+ Square::WebhooksHelper.is_valid_webhook_event_signature(
129
+ @request_body,
130
+ @signature_header,
131
+ @signature_key,
132
+ nil
133
+ )
134
+ end
135
+ end
136
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: square.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 31.0.0.20230816
4
+ version: 33.0.0.20231018
5
5
  platform: ruby
6
6
  authors:
7
7
  - Square Developer Platform
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-15 00:00:00.000000000 Z
11
+ date: 2023-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apimatic_core_interfaces
@@ -150,6 +150,7 @@ files:
150
150
  - lib/square/http/http_response.rb
151
151
  - lib/square/utilities/date_time_helper.rb
152
152
  - lib/square/utilities/file_wrapper.rb
153
+ - lib/square/utilities/webhooks_helper.rb
153
154
  - spec/user_journey_spec.rb
154
155
  - test/api/api_test_base.rb
155
156
  - test/api/test_catalog_api.rb
@@ -161,6 +162,7 @@ files:
161
162
  - test/api/test_payments_api.rb
162
163
  - test/api/test_refunds_api.rb
163
164
  - test/http_response_catcher.rb
165
+ - test/webhooks/test_webhooks_helper.rb
164
166
  homepage: ''
165
167
  licenses:
166
168
  - Apache-2.0