Class: Square::CheckoutApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/checkout_api.rb

Overview

CheckoutApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#execute_request, #get_user_agent, #validate_parameters

Constructor Details

#initialize(config, http_call_back: nil) ⇒ CheckoutApi

Returns a new instance of CheckoutApi.



4
5
6
# File 'lib/square/api/checkout_api.rb', line 4

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#create_checkout(location_id:, body:) ⇒ CreateCheckoutResponse Hash

Links a ‘checkoutId` to a `checkout_page_url` that customers are directed to in order to provide their payment information using a payment processing workflow hosted on connect.squareup.com. NOTE: The Checkout API has been updated with new features. For more information, see [Checkout API highlights](developer.squareup.com/docs/checkout-api#checkout-api- highlights). We recommend that you use the new ($e/Checkout/CreatePaymentLink) endpoint in place of this previously released endpoint. location to associate the checkout with. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • location_id (String)

    Required parameter: The ID of the business

  • body (CreateCheckoutRequest)

    Required parameter: An object

Returns:

  • (CreateCheckoutResponse Hash)

    response from the API call



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/square/api/checkout_api.rb', line 24

def create_checkout(location_id:,
                    body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/locations/{location_id}/checkouts'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'location_id' => { 'value' => location_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

Creates a Square-hosted checkout page. Applications can share the resulting payment link with their buyer to pay for goods and services. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreatePaymentLinkRequest)

    Required parameter: An object

Returns:

  • (CreatePaymentLinkResponse Hash)

    response from the API call



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/square/api/checkout_api.rb', line 111

def create_payment_link(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/online-checkout/payment-links'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

Deletes a payment link. delete.

Parameters:

  • id (String)

    Required parameter: The ID of the payment link to

Returns:

  • (DeletePaymentLinkResponse Hash)

    response from the API call



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/square/api/checkout_api.rb', line 144

def delete_payment_link(id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/online-checkout/payment-links/{id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'id' => { 'value' => id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.delete(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

Lists all payment links. a previous call to this endpoint. Provide this cursor to retrieve the next set of results for the original query. If a cursor is not provided, the endpoint returns the first page of the results. For more information, see [Pagination](developer.squareup.com/docs/basics/api101/pagination) . results to return per page. The limit is advisory and the implementation might return more or less results. If the supplied limit is negative, zero, or greater than the maximum limit of 1000, it is ignored. Default value: ‘100`

Parameters:

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • limit (Integer) (defaults to: nil)

    Optional parameter: A limit on the number of

Returns:

  • (ListPaymentLinksResponse Hash)

    response from the API call



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/square/api/checkout_api.rb', line 72

def list_payment_links(cursor: nil,
                       limit: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/online-checkout/payment-links'
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'cursor' => cursor,
    'limit' => limit
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

Retrieves a payment link.

Parameters:

  • id (String)

    Required parameter: The ID of link to retrieve.

Returns:

  • (RetrievePaymentLinkResponse Hash)

    response from the API call



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/square/api/checkout_api.rb', line 178

def retrieve_payment_link(id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/online-checkout/payment-links/{id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'id' => { 'value' => id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

Updates a payment link. You can update the ‘payment_link` fields such as `description`, `checkout_options`, and `pre_populated_data`. You cannot update other fields such as the `order_id`, `version`, `URL`, or `timestamp` field. update. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • id (String)

    Required parameter: The ID of the payment link to

  • body (UpdatePaymentLinkRequest)

    Required parameter: An object

Returns:

  • (UpdatePaymentLinkResponse Hash)

    response from the API call



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/square/api/checkout_api.rb', line 219

def update_payment_link(id:,
                        body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/online-checkout/payment-links/{id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'id' => { 'value' => id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.put(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end