Class: Square::GiftCards::Client
- Inherits:
-
Object
- Object
- Square::GiftCards::Client
- Defined in:
- lib/square/gift_cards/client.rb
Instance Method Summary collapse
- #activities ⇒ Square::Activities::Client
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateGiftCardResponse
Creates a digital gift card or registers a physical (plastic) gift card.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetGiftCardResponse
Retrieves a gift card using the gift card ID.
-
#get_from_gan(request_options: {}, **params) ⇒ Square::Types::GetGiftCardFromGanResponse
Retrieves a gift card using the gift card account number (GAN).
-
#get_from_nonce(request_options: {}, **params) ⇒ Square::Types::GetGiftCardFromNonceResponse
Retrieves a gift card using a secure payment token that represents the gift card.
- #initialize(client:) ⇒ Square::GiftCards::Client constructor
-
#link_customer(request_options: {}, **params) ⇒ Square::Types::LinkCustomerToGiftCardResponse
Links a customer to a gift card, which is also referred to as adding a card on file.
-
#list(request_options: {}, **params) ⇒ Square::Types::ListGiftCardsResponse
Lists all gift cards.
-
#unlink_customer(request_options: {}, **params) ⇒ Square::Types::UnlinkCustomerFromGiftCardResponse
Unlinks a customer from a gift card, which is also referred to as removing a card on file.
Constructor Details
#initialize(client:) ⇒ Square::GiftCards::Client
7 8 9 |
# File 'lib/square/gift_cards/client.rb', line 7 def initialize(client:) @client = client end |
Instance Method Details
#activities ⇒ Square::Activities::Client
195 196 197 |
# File 'lib/square/gift_cards/client.rb', line 195 def activities @activities ||= Square::GiftCards::Activities::Client.new(client: @client) end |
#create(request_options: {}, **params) ⇒ Square::Types::CreateGiftCardResponse
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](api-endpoint:GiftCardActivities-CreateGiftCardActivity) and create an `ACTIVATE` activity with the initial balance. Alternatively, you can use [RefundPayment](api-endpoint:Refunds-RefundPayment) to refund a payment to the new gift card.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/square/gift_cards/client.rb', line 50 def create(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/gift-cards", body: params ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::CreateGiftCardResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Square::Types::GetGiftCardResponse
Retrieves a gift card using the gift card ID.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/square/gift_cards/client.rb', line 174 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/gift-cards/#{params[:id]}" ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::GetGiftCardResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#get_from_gan(request_options: {}, **params) ⇒ Square::Types::GetGiftCardFromGanResponse
Retrieves a gift card using the gift card account number (GAN).
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/square/gift_cards/client.rb', line 74 def get_from_gan(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/gift-cards/from-gan", body: params ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::GetGiftCardFromGanResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#get_from_nonce(request_options: {}, **params) ⇒ Square::Types::GetGiftCardFromNonceResponse
Retrieves a gift card using a secure payment token that represents the gift card.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/square/gift_cards/client.rb', line 98 def get_from_nonce(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/gift-cards/from-nonce", body: params ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::GetGiftCardFromNonceResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#link_customer(request_options: {}, **params) ⇒ Square::Types::LinkCustomerToGiftCardResponse
Links a customer to a gift card, which is also referred to as adding a card on file.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/square/gift_cards/client.rb', line 122 def link_customer(request_options: {}, **params) _path_param_names = ["gift_card_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/gift-cards/#{params[:gift_card_id]}/link-customer", body: params.except(*_path_param_names) ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::LinkCustomerToGiftCardResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Square::Types::ListGiftCardsResponse
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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/square/gift_cards/client.rb', line 15 def list(request_options: {}, **params) _query_param_names = [ %w[type state limit cursor customer_id], %i[type state limit cursor customer_id] ].flatten _query = params.slice(*_query_param_names) params.except(*_query_param_names) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "GET", path: "v2/gift-cards", query: _query ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::ListGiftCardsResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#unlink_customer(request_options: {}, **params) ⇒ Square::Types::UnlinkCustomerFromGiftCardResponse
Unlinks a customer from a gift card, which is also referred to as removing a card on file.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/square/gift_cards/client.rb', line 148 def unlink_customer(request_options: {}, **params) _path_param_names = ["gift_card_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/gift-cards/#{params[:gift_card_id]}/unlink-customer", body: params.except(*_path_param_names) ) begin _response = @client.send(_request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = _response.code.to_i if code.between?(200, 299) Square::Types::UnlinkCustomerFromGiftCardResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |