square.rb 31.0.0.20230816 → 32.0.0.20230925

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: 6c7adca646aa24aa7a9afa7c6acd8d49e534a854fd134f6442f315015a500d77
4
+ data.tar.gz: 2ea27cf68b466c3987d01685efd65c4343c7b77c3297d5b4fc113fbe39b84cf0
5
5
  SHA512:
6
- metadata.gz: d0296c13c1fc83e7e54d56cc397929f3d50ed3d243505c6372e890e7fec6cb65b6aabafd62bf15f80602982196ab36103bc8e7b816c633665717e172e0a8bdda
7
- data.tar.gz: 2dce736c93cff6399463e35427319a4fe82009019c1300eafc39b3588a0056bdbba7bc26489b31f18152e22ffe6e9c7aadf10640b46384d8d0812755e65ab431
6
+ metadata.gz: 550f0b2966ced843d9300cb3bb2a9fc65d033297aa1e5f04fd3777da04703641580c6f361419477ae97c32e487bf825d4480612cf52d6a88e58056bd8fc7186b
7
+ data.tar.gz: c4f0bdfe70c66d1853a92d3eef3d314ecd2246519035039f57b44ce44e184d6fe03f8aebdb3f4a7274d337f14f2e7d8c95590a1edecefca81f7b6411b925219c
@@ -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/32.0.0.20230925 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
8
8
  end
9
9
 
10
10
  def self.user_agent_parameters
@@ -191,6 +191,28 @@ module Square
191
191
  .execute
192
192
  end
193
193
 
194
+ # Retrieves one or more team members' booking profiles.
195
+ # @param [BulkRetrieveTeamMemberBookingProfilesRequest] body Required
196
+ # parameter: An object containing the fields to POST for the request. See
197
+ # the corresponding object definition for field details.
198
+ # @return [BulkRetrieveTeamMemberBookingProfilesResponse Hash] response from the API call
199
+ def bulk_retrieve_team_member_booking_profiles(body:)
200
+ new_api_call_builder
201
+ .request(new_request_builder(HttpMethodEnum::POST,
202
+ '/v2/bookings/team-member-booking-profiles/bulk-retrieve',
203
+ 'default')
204
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
205
+ .body_param(new_parameter(body))
206
+ .header_param(new_parameter('application/json', key: 'accept'))
207
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
208
+ .auth(Single.new('global')))
209
+ .response(new_response_handler
210
+ .deserializer(APIHelper.method(:json_deserialize))
211
+ .is_api_response(true)
212
+ .convertor(ApiResponse.method(:create)))
213
+ .execute
214
+ end
215
+
194
216
  # Retrieves a team member's booking profile.
195
217
  # @param [String] team_member_id Required parameter: The ID of the team
196
218
  # 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
@@ -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
  # ```
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
+ '32.0.0.20230925'
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-09-25', 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-09-25', 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: 32.0.0.20230925
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-09-26 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