Class: Square::GiftCardsApi

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

Overview

GiftCardsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from Square::BaseApi

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.

Parameters:

  • body (CreateGiftCardRequest)

    Required parameter: An object

Returns:

  • (CreateGiftCardResponse Hash)

    response from the API call



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/square/api/gift_cards_api.rb', line 62

def create_gift_card(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/gift-cards',
                                 'default')
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end

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.

Parameters:

  • gift_card_id (String)

    Required parameter: The ID of the gift card

  • body (LinkCustomerToGiftCardRequest)

    Required parameter: An object

Returns:

  • (LinkCustomerToGiftCardResponse Hash)

    response from the API call



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/square/api/gift_cards_api.rb', line 132

def link_customer_to_gift_card(gift_card_id:,
                               body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/gift-cards/{gift_card_id}/link-customer',
                                 'default')
               .template_param(new_parameter(gift_card_id, key: 'gift_card_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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. Results are sorted by ‘created_at` in ascending order. is provided, the endpoint returns gift cards of the specified type. Otherwise, the endpoint returns gift cards of all types. [state](entity:GiftCardStatus) 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 200. 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.

Parameters:

  • type (String) (defaults to: nil)

    Optional parameter: If a [type](entity:GiftCardType)

  • state (String) (defaults to: nil)

    Optional parameter: If a

  • limit (Integer) (defaults to: nil)

    Optional parameter: If a limit is provided, the

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • customer_id (String) (defaults to: nil)

    Optional parameter: If a customer ID is

Returns:

  • (ListGiftCardsResponse Hash)

    response from the API call



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/gift-cards',
                                 'default')
               .query_param(new_parameter(type, key: 'type'))
               .query_param(new_parameter(state, key: 'state'))
               .query_param(new_parameter(limit, key: 'limit'))
               .query_param(new_parameter(cursor, key: 'cursor'))
               .query_param(new_parameter(customer_id, key: 'customer_id'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end

#retrieve_gift_card(id:) ⇒ RetrieveGiftCardResponse Hash

Retrieves a gift card using the gift card ID. retrieve.

Parameters:

  • id (String)

    Required parameter: The ID of the gift card to

Returns:

  • (RetrieveGiftCardResponse Hash)

    response from the API call



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/square/api/gift_cards_api.rb', line 184

def retrieve_gift_card(id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/gift-cards/{id}',
                                 'default')
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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.

Parameters:

  • body (RetrieveGiftCardFromGANRequest)

    Required parameter: An object

Returns:

  • (RetrieveGiftCardFromGANResponse Hash)

    response from the API call



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/square/api/gift_cards_api.rb', line 84

def retrieve_gift_card_from_gan(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/gift-cards/from-gan',
                                 'default')
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
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.

Parameters:

  • body (RetrieveGiftCardFromNonceRequest)

    Required parameter: An

Returns:

  • (RetrieveGiftCardFromNonceResponse Hash)

    response from the API call



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/square/api/gift_cards_api.rb', line 107

def retrieve_gift_card_from_nonce(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/gift-cards/from-nonce',
                                 'default')
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end

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.

Parameters:

  • gift_card_id (String)

    Required parameter: The ID of the gift card

  • body (UnlinkCustomerFromGiftCardRequest)

    Required parameter: An

Returns:

  • (UnlinkCustomerFromGiftCardResponse Hash)

    response from the API call



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/square/api/gift_cards_api.rb', line 160

def unlink_customer_from_gift_card(gift_card_id:,
                                   body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/gift-cards/{gift_card_id}/unlink-customer',
                                 'default')
               .template_param(new_parameter(gift_card_id, key: 'gift_card_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end