Class: Square::Customers::Cards::Client
- Inherits:
-
Object
- Object
- Square::Customers::Cards::Client
- Defined in:
- lib/square/customers/cards/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateCustomerCardResponse
Adds a card on file to an existing customer.
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteCustomerCardResponse
Removes a card on file from a customer.
- #initialize(client:) ⇒ Square::Customers::Cards::Client constructor
Constructor Details
#initialize(client:) ⇒ Square::Customers::Cards::Client
8 9 10 |
# File 'lib/square/customers/cards/client.rb', line 8 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Square::Types::CreateCustomerCardResponse
Adds a card on file to an existing customer.
As with charges, calls to ‘CreateCustomerCard` are idempotent. Multiple calls with the same card nonce return the same card record that was created with the provided nonce during the first call.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/square/customers/cards/client.rb', line 19 def create(request_options: {}, **params) _path_param_names = ["customer_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "POST", path: "v2/customers/#{params[:customer_id]}/cards", 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::CreateCustomerCardResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteCustomerCardResponse
Removes a card on file from a customer.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/square/customers/cards/client.rb', line 45 def delete(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::PRODUCTION, method: "DELETE", path: "v2/customers/#{params[:customer_id]}/cards/#{params[:card_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::DeleteCustomerCardResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |