class Square::GiftCardsApi

GiftCardsApi

Public Class Methods

new(config, http_call_back: nil) click to toggle source
Calls superclass method Square::BaseApi::new
# 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

Public Instance Methods

create_gift_card(body:) click to toggle source

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). @param [CreateGiftCardRequest] body Required parameter: An object containing the fields to POST for the request. See the corresponding object definition for field details. @return [CreateGiftCardResponse Hash] response from the API call

# 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
list_gift_cards(type: nil, state: nil, limit: nil, cursor: nil, customer_id: nil) click to toggle source

Lists all gift cards. You can specify optional filters to retrieve a subset of the gift cards. @param [String] type Optional parameter: If a [type]($m/GiftCardType) is provided, the endpoint returns gift cards of the specified type. Otherwise, the endpoint returns gift cards of all types. @param [String] state Optional parameter: If a [state]($m/GiftCardStatus) is provided, the endpoint returns the gift cards in the specified state. Otherwise, the endpoint returns the gift cards of all states. @param [Integer] limit Optional parameter: If a limit is provided, the 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). @param [String] cursor Optional parameter: A pagination cursor returned by 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). @param [String] customer_id Optional parameter: If a customer ID is provided, the endpoint returns only the gift cards linked to the specified customer. @return [ListGiftCardsResponse Hash] response from the API call

# 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:) click to toggle source

Retrieves a gift card using its ID. @param [String] id Required parameter: The ID of the gift card to retrieve. @return [RetrieveGiftCardResponse Hash] response from the API call

# 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:) click to toggle source

Retrieves a gift card using the gift card account number (GAN). @param [RetrieveGiftCardFromGANRequest] body Required parameter: An object containing the fields to POST for the request. See the corresponding object definition for field details. @return [RetrieveGiftCardFromGANResponse Hash] response from the API call

# 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:) click to toggle source

Retrieves a gift card using a secure payment token that represents the gift card. @param [RetrieveGiftCardFromNonceRequest] body Required parameter: An object containing the fields to POST for the request. See the corresponding object definition for field details. @return [RetrieveGiftCardFromNonceResponse Hash] response from the API call

# 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