Class: Square::CheckoutApi
- Defined in:
- lib/square/api/checkout_api.rb
Overview
CheckoutApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#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.
-
#create_payment_link(body:) ⇒ CreatePaymentLinkResponse Hash
Creates a Square-hosted checkout page.
-
#delete_payment_link(id:) ⇒ DeletePaymentLinkResponse Hash
Deletes a payment link.
-
#initialize(config, http_call_back: nil) ⇒ CheckoutApi
constructor
A new instance of CheckoutApi.
-
#list_payment_links(cursor: nil, limit: nil) ⇒ ListPaymentLinksResponse Hash
Lists all payment links.
-
#retrieve_payment_link(id:) ⇒ RetrievePaymentLinkResponse Hash
Retrieves a payment link.
-
#update_payment_link(id:, body:) ⇒ UpdatePaymentLinkResponse Hash
Updates a payment link.
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.
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 |
#create_payment_link(body:) ⇒ CreatePaymentLinkResponse Hash
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.
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 |
#delete_payment_link(id:) ⇒ DeletePaymentLinkResponse Hash
Deletes a payment link. delete.
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 |
#list_payment_links(cursor: nil, limit: nil) ⇒ ListPaymentLinksResponse Hash
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`
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 |
#retrieve_payment_link(id:) ⇒ RetrievePaymentLinkResponse Hash
Retrieves a payment link.
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 |
#update_payment_link(id:, body:) ⇒ UpdatePaymentLinkResponse Hash
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.
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 |