Class: Square::GiftCardsApi
- Defined in:
- lib/square/api/gift_cards_api.rb
Overview
GiftCardsApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#create_gift_card(body:) ⇒ CreateGiftCardResponse Hash
Creates a digital gift card or registers a physical (plastic) gift card.
-
#initialize(config, http_call_back: nil) ⇒ GiftCardsApi
constructor
A new instance of GiftCardsApi.
-
#link_customer_to_gift_card(gift_card_id:, body:) ⇒ LinkCustomerToGiftCardResponse Hash
Links a customer to a gift card to link.
-
#list_gift_cards(type: nil, state: nil, limit: nil, cursor: nil, customer_id: nil) ⇒ ListGiftCardsResponse Hash
Lists all gift cards.
-
#retrieve_gift_card(id:) ⇒ RetrieveGiftCardResponse Hash
Retrieves a gift card using its ID.
-
#retrieve_gift_card_from_gan(body:) ⇒ RetrieveGiftCardFromGANResponse Hash
Retrieves a gift card using the gift card account number (GAN).
-
#retrieve_gift_card_from_nonce(body:) ⇒ RetrieveGiftCardFromNonceResponse Hash
Retrieves a gift card using a nonce (a secure token) that represents the gift card.
-
#unlink_customer_from_gift_card(gift_card_id:, body:) ⇒ UnlinkCustomerFromGiftCardResponse Hash
Unlinks a customer from a gift card object containing the fields to POST for the request.
Methods inherited from BaseApi
#execute_request, #validate_parameters
Constructor Details
#initialize(config, http_call_back: nil) ⇒ GiftCardsApi
Returns a new instance of GiftCardsApi.
4 5 6 |
# File 'lib/square/api/gift_cards_api.rb', line 4 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#create_gift_card(body:) ⇒ CreateGiftCardResponse Hash
Creates a digital gift card or registers a physical (plastic) gift card. You must activate the gift card before it can be used for payment. For more information, see [Selling gift cards](developer.squareup.com/docs/gift-cards/using-gift-cards-api #selling-square-gift-cards). containing the fields to POST for the request. See the corresponding object definition for field details.
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 104 105 |
# File 'lib/square/api/gift_cards_api.rb', line 78 def create_gift_card(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/gift-cards' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # 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 |
#link_customer_to_gift_card(gift_card_id:, body:) ⇒ LinkCustomerToGiftCardResponse Hash
Links a customer to a gift card to link. containing the fields to POST for the request. See the corresponding object definition for field details.
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 208 209 210 211 212 213 214 215 |
# File 'lib/square/api/gift_cards_api.rb', line 183 def link_customer_to_gift_card(gift_card_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/gift-cards/{gift_card_id}/link-customer' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'gift_card_id' => { 'value' => gift_card_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # 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 |
#list_gift_cards(type: nil, state: nil, limit: nil, cursor: nil, customer_id: nil) ⇒ ListGiftCardsResponse Hash
Lists all gift cards. You can specify optional filters to retrieve a subset of the gift cards. of this type are returned (see [GiftCardType]($m/GiftCardType)). If no type is provided, it returns gift cards of all types. returns the gift cards in the specified state (see [GiftCardStatus]($m/GiftCardStatus)). Otherwise, it returns the gift cards of all states. returns only that number of results per page. The maximum number of results allowed per page is 50. The default value is 30. 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, it returns the first page of the results. For more information, see [Pagination](developer.squareup.com/docs/working-with-apis/paginat ion). returns only the gift cards linked to the specified customer
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 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/square/api/gift_cards_api.rb', line 29 def list_gift_cards(type: nil, state: nil, limit: nil, cursor: nil, customer_id: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/gift-cards' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'type' => type, 'state' => state, 'limit' => limit, 'cursor' => cursor, 'customer_id' => customer_id ) _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_gift_card(id:) ⇒ RetrieveGiftCardResponse Hash
Retrieves a gift card using its ID. retrieve.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/square/api/gift_cards_api.rb', line 261 def retrieve_gift_card(id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/gift-cards/{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 |
#retrieve_gift_card_from_gan(body:) ⇒ RetrieveGiftCardFromGANResponse Hash
Retrieves a gift card using the gift card account number (GAN). containing the fields to POST for the request. See the corresponding object definition for field details.
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 139 |
# File 'lib/square/api/gift_cards_api.rb', line 112 def retrieve_gift_card_from_gan(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/gift-cards/from-gan' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # 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 |
#retrieve_gift_card_from_nonce(body:) ⇒ RetrieveGiftCardFromNonceResponse Hash
Retrieves a gift card using a nonce (a secure token) that represents the gift card. object containing the fields to POST for the request. See the corresponding object definition for field details.
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 174 |
# File 'lib/square/api/gift_cards_api.rb', line 147 def retrieve_gift_card_from_nonce(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/gift-cards/from-nonce' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # 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 |
#unlink_customer_from_gift_card(gift_card_id:, body:) ⇒ UnlinkCustomerFromGiftCardResponse Hash
Unlinks a customer from a gift card object containing the fields to POST for the request. See the corresponding object definition for field details.
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 252 253 254 255 |
# File 'lib/square/api/gift_cards_api.rb', line 223 def unlink_customer_from_gift_card(gift_card_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/gift-cards/{gift_card_id}/unlink-customer' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'gift_card_id' => { 'value' => gift_card_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # 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 |