Class: Square::Customers::Cards::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/customers/cards/client.rb

Instance Method Summary collapse

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
# 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: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/customers/#{params[:customer_id]}/cards",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::CreateCustomerCardResponse.load(_response.body)
  end

  raise _response.body
end

#delete(request_options: {}, **params) ⇒ Square::Types::DeleteCustomerCardResponse

Removes a card on file from a customer.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/square/customers/cards/client.rb', line 39

def delete(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "DELETE",
    path: "v2/customers/#{params[:customer_id]}/cards/#{params[:card_id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::DeleteCustomerCardResponse.load(_response.body)
  end

  raise _response.body
end