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, which is also referred to as adding a card on file.
-
#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 the gift card 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 secure payment token that represents the gift card.
-
#unlink_customer_from_gift_card(gift_card_id:, body:) ⇒ UnlinkCustomerFromGiftCardResponse Hash
Unlinks a customer from a gift card, which is also referred to as removing a card on file.
Methods inherited from BaseApi
#execute_request, #get_user_agent, #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. After the gift card is created, you must call [CreateGiftCardActivity]($e/GiftCardActivities/CreateGiftCardActivity) to activate the card with an initial balance before it can be used for payment. containing the fields to POST for the request. See the corresponding object definition for field details.
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 106 107 |
# File 'lib/square/api/gift_cards_api.rb', line 80 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' } # 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, which is also referred to as adding a card on file. to be linked. containing the fields to POST for the request. See the corresponding object definition for field details.
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 216 217 218 |
# File 'lib/square/api/gift_cards_api.rb', line 186 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' } # 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. provided, the endpoint returns gift cards of the specified type. Otherwise, the endpoint returns gift cards of all types. is provided, the endpoint returns the gift cards in the specified state. Otherwise, the endpoint returns the gift cards of all states. endpoint returns only the specified number of results per page. The maximum value is 50. The default value is 30. For more information, see [Pagination](developer.squareup.com/docs/working-with-apis/paginat ion). 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/working-with-apis/paginat ion). provided, the endpoint returns only the gift cards linked to the specified customer.
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 67 68 |
# File 'lib/square/api/gift_cards_api.rb', line 31 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 the gift card ID. retrieve.
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 291 292 293 294 295 |
# File 'lib/square/api/gift_cards_api.rb', line 266 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.
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 140 141 |
# File 'lib/square/api/gift_cards_api.rb', line 114 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' } # 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 secure payment token that represents the gift card. object containing the fields to POST for the request. See the corresponding object definition for field details.
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 175 176 |
# File 'lib/square/api/gift_cards_api.rb', line 149 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' } # 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, which is also referred to as removing a card on file. to be unlinked. object containing the fields to POST for the request. See the corresponding object definition for field details.
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 256 257 258 259 260 |
# File 'lib/square/api/gift_cards_api.rb', line 228 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' } # 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 |