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:) ⇒ ApiResponse
Creates a digital gift card or registers a physical (plastic) gift card.
-
#link_customer_to_gift_card(gift_card_id:, body:) ⇒ ApiResponse
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) ⇒ ApiResponse
Lists all gift cards.
-
#retrieve_gift_card(id:) ⇒ ApiResponse
Retrieves a gift card using the gift card ID.
-
#retrieve_gift_card_from_gan(body:) ⇒ ApiResponse
Retrieves a gift card using the gift card account number (GAN).
-
#retrieve_gift_card_from_nonce(body:) ⇒ ApiResponse
Retrieves a gift card using a secure payment token that represents the gift card.
-
#unlink_customer_from_gift_card(gift_card_id:, body:) ⇒ ApiResponse
Unlinks a customer from a gift card, which is also referred to as removing a card on file.
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:) ⇒ ApiResponse
Creates a digital gift card or registers a physical (plastic) gift card. The resulting gift card has a ‘PENDING` state. To activate a gift card so that it can be redeemed for purchases, call [CreateGiftCardActivity]($e/GiftCardActivities/CreateGiftCardActivity) and create an `ACTIVATE` activity with the initial balance. Alternatively, you can use [RefundPayment]($e/Refunds/RefundPayment) to refund a payment to the new gift card. containing the fields to POST for the request. See the corresponding object definition for field details.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/square/api/gift_cards_api.rb', line 65 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 |
#link_customer_to_gift_card(gift_card_id:, body:) ⇒ ApiResponse
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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/square/api/gift_cards_api.rb', line 135 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) ⇒ ApiResponse
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.
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:) ⇒ ApiResponse
Retrieves a gift card using the gift card ID. retrieve.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/square/api/gift_cards_api.rb', line 187 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:) ⇒ ApiResponse
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.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/square/api/gift_cards_api.rb', line 87 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:) ⇒ ApiResponse
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.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/square/api/gift_cards_api.rb', line 110 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 |
#unlink_customer_from_gift_card(gift_card_id:, body:) ⇒ ApiResponse
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.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/square/api/gift_cards_api.rb', line 163 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 |