square.rb 30.0.0.20230720 → 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: 148935067852283c97b96532924b8990240a8471eb1fb004af84547db7a46e6f
4
- data.tar.gz: f831947407ebced9aacc23b3db7cfae06b658899b21212c2548ca00a2acce842
3
+ metadata.gz: 6c7adca646aa24aa7a9afa7c6acd8d49e534a854fd134f6442f315015a500d77
4
+ data.tar.gz: 2ea27cf68b466c3987d01685efd65c4343c7b77c3297d5b4fc113fbe39b84cf0
5
5
  SHA512:
6
- metadata.gz: d7045748e5af0118787c3658002f2c43a6e4db0e044e2707b58ae2d6690abd16ce01ae360889552611c43967261c93b33fd2bcd610c305b349b687e0d8c77605
7
- data.tar.gz: 65360d7cd4eebb01bddba58ad85124a51d4a60ea21c8095235ce58182a2c58f26db1353374c4b914f3f1e96fd72e774efd0c0ba19c40bc231095998e1303d544
6
+ metadata.gz: 550f0b2966ced843d9300cb3bb2a9fc65d033297aa1e5f04fd3777da04703641580c6f361419477ae97c32e487bf825d4480612cf52d6a88e58056bd8fc7186b
7
+ data.tar.gz: c4f0bdfe70c66d1853a92d3eef3d314ecd2246519035039f57b44ce44e184d6fe03f8aebdb3f4a7274d337f14f2e7d8c95590a1edecefca81f7b6411b925219c
data/README.md CHANGED
@@ -77,6 +77,7 @@ rake
77
77
 
78
78
  ### Orders
79
79
  * [Orders]
80
+ * [Order Custom Attributes]
80
81
 
81
82
  ### Subscriptions
82
83
  * [Subscriptions]
@@ -103,10 +104,13 @@ rake
103
104
 
104
105
  ### Bookings
105
106
  * [Bookings]
107
+ * [Booking Custom Attributes]
106
108
 
107
109
  ### Business
108
110
  * [Merchants]
111
+ * [Merchant Custom Attributes]
109
112
  * [Locations]
113
+ * [Location Custom Attributes]
110
114
  * [Devices]
111
115
  * [Cash Drawers]
112
116
  * [Vendors]
@@ -162,9 +166,13 @@ The following Square APIs are [deprecated](https://developer.squareup.com/docs/b
162
166
  [Labor]: doc/api/labor.md
163
167
  [Loyalty]: doc/api/loyalty.md
164
168
  [Bookings]: doc/api/bookings.md
169
+ [Booking Custom Attributes]: doc/api/booking-custom-attributes.md
165
170
  [Locations]: doc/api/locations.md
171
+ [Location Custom Attributes]: doc/api/location-custom-attributes.md
166
172
  [Merchants]: doc/api/merchants.md
173
+ [Merchant Custom Attributes]: doc/api/merchant-custom-attributes.md
167
174
  [Orders]: doc/api/orders.md
175
+ [Order Custom Attributes]: doc/api/order-custom-attributes.md
168
176
  [Invoices]: doc/api/invoices.md
169
177
  [Apple Pay]: doc/api/apple-pay.md
170
178
  [Refunds]: doc/api/refunds.md
@@ -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/30.0.0.20230720 ({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
@@ -11,6 +11,9 @@ module Square
11
11
  # @param [String] cursor Optional parameter: The pagination cursor from the
12
12
  # preceding response to return the next page of the results. Do not set this
13
13
  # when retrieving the first page of the results.
14
+ # @param [String] customer_id Optional parameter: The
15
+ # [customer](entity:Customer) for whom to retrieve bookings. If this is not
16
+ # set, bookings for all customers are retrieved.
14
17
  # @param [String] team_member_id Optional parameter: The team member for
15
18
  # whom to retrieve bookings. If this is not set, bookings of all members are
16
19
  # retrieved.
@@ -26,6 +29,7 @@ module Square
26
29
  # @return [ListBookingsResponse Hash] response from the API call
27
30
  def list_bookings(limit: nil,
28
31
  cursor: nil,
32
+ customer_id: nil,
29
33
  team_member_id: nil,
30
34
  location_id: nil,
31
35
  start_at_min: nil,
@@ -36,6 +40,7 @@ module Square
36
40
  'default')
37
41
  .query_param(new_parameter(limit, key: 'limit'))
38
42
  .query_param(new_parameter(cursor, key: 'cursor'))
43
+ .query_param(new_parameter(customer_id, key: 'customer_id'))
39
44
  .query_param(new_parameter(team_member_id, key: 'team_member_id'))
40
45
  .query_param(new_parameter(location_id, key: 'location_id'))
41
46
  .query_param(new_parameter(start_at_min, key: 'start_at_min'))
@@ -110,6 +115,32 @@ module Square
110
115
  .execute
111
116
  end
112
117
 
118
+ # Bulk-Retrieves a list of bookings by booking IDs.
119
+ # To call this endpoint with buyer-level permissions, set
120
+ # `APPOINTMENTS_READ` for the OAuth scope.
121
+ # To call this endpoint with seller-level permissions, set
122
+ # `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope.
123
+ # @param [BulkRetrieveBookingsRequest] body Required parameter: An object
124
+ # containing the fields to POST for the request. See the corresponding
125
+ # object definition for field details.
126
+ # @return [BulkRetrieveBookingsResponse Hash] response from the API call
127
+ def bulk_retrieve_bookings(body:)
128
+ new_api_call_builder
129
+ .request(new_request_builder(HttpMethodEnum::POST,
130
+ '/v2/bookings/bulk-retrieve',
131
+ 'default')
132
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
133
+ .body_param(new_parameter(body))
134
+ .header_param(new_parameter('application/json', key: 'accept'))
135
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
136
+ .auth(Single.new('global')))
137
+ .response(new_response_handler
138
+ .deserializer(APIHelper.method(:json_deserialize))
139
+ .is_api_response(true)
140
+ .convertor(ApiResponse.method(:create)))
141
+ .execute
142
+ end
143
+
113
144
  # Retrieves a seller's booking profile.
114
145
  # @return [RetrieveBusinessBookingProfileResponse Hash] response from the API call
115
146
  def retrieve_business_booking_profile
@@ -160,6 +191,28 @@ module Square
160
191
  .execute
161
192
  end
162
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
+
163
216
  # Retrieves a team member's booking profile.
164
217
  # @param [String] team_member_id Required parameter: The ID of the team
165
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
@@ -13,7 +13,7 @@ module Square
13
13
  # cards of all states.
14
14
  # @param [Integer] limit Optional parameter: If a limit is provided, the
15
15
  # endpoint returns only the specified number of results per page. The
16
- # maximum value is 50. The default value is 30. For more information, see
16
+ # maximum value is 200. The default value is 30. For more information, see
17
17
  # [Pagination](https://developer.squareup.com/docs/working-with-apis/paginat
18
18
  # ion).
19
19
  # @param [String] cursor Optional parameter: A pagination cursor returned by
@@ -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
- '30.0.0.20230720'
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-07-20', 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-07-20', 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: 30.0.0.20230720
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-07-19 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