Class: Square::CardsApi
Overview
CardsApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#create_card(body:) ⇒ CreateCardResponse Hash
Adds a card on file to an existing merchant.
-
#disable_card(card_id:) ⇒ DisableCardResponse Hash
Disables the card, preventing any further updates or charges.
-
#initialize(config, http_call_back: nil) ⇒ CardsApi
constructor
A new instance of CardsApi.
-
#list_cards(cursor: nil, customer_id: nil, include_disabled: false, reference_id: nil, sort_order: nil) ⇒ ListCardsResponse Hash
Retrieves a list of cards owned by the account making the request.
-
#retrieve_card(card_id:) ⇒ RetrieveCardResponse Hash
Retrieves details for a specific Card.
Methods inherited from BaseApi
#execute_request, #get_user_agent, #validate_parameters
Constructor Details
#initialize(config, http_call_back: nil) ⇒ CardsApi
Returns a new instance of CardsApi.
4 5 6 |
# File 'lib/square/api/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_card(body:) ⇒ CreateCardResponse Hash
Adds a card on file to an existing merchant. the fields to POST for the request. See the corresponding object definition for field details.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/square/api/cards_api.rb', line 70 def create_card(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/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 |
#disable_card(card_id:) ⇒ DisableCardResponse Hash
Disables the card, preventing any further updates or charges. Disabling an already disabled card is allowed but has no effect. Card.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/square/api/cards_api.rb', line 139 def disable_card(card_id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/cards/{card_id}/disable' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'card_id' => { 'value' => card_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _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 |
#list_cards(cursor: nil, customer_id: nil, include_disabled: false, reference_id: nil, sort_order: nil) ⇒ ListCardsResponse Hash
Retrieves a list of cards owned by the account making the request. A max of 25 cards will be returned. a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. See [Pagination](developer.squareup.com/docs/basics/api101/pagination) for more information. associated with the customer supplied. By default, all cards owned by the merchant are returned. cards. By default, all enabled cards owned by the merchant are returned. associated with the reference_id supplied. by when the card was created with the specified order. This field defaults to ASC.
26 27 28 29 30 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 |
# File 'lib/square/api/cards_api.rb', line 26 def list_cards(cursor: nil, customer_id: nil, include_disabled: false, reference_id: nil, sort_order: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/cards' _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'cursor' => cursor, 'customer_id' => customer_id, 'include_disabled' => include_disabled, 'reference_id' => reference_id, 'sort_order' => sort_order ) _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_card(card_id:) ⇒ RetrieveCardResponse Hash
Retrieves details for a specific Card. Card.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/square/api/cards_api.rb', line 103 def retrieve_card(card_id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/cards/{card_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'card_id' => { 'value' => card_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 |