Class: Square::Cards::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Cards::Client



7
8
9
# File 'lib/square/cards/client.rb', line 7

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ Square::Types::CreateCardResponse

Adds a card on file to an existing merchant.



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

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

  raise _response.body
end

#disable(request_options: {}, **params) ⇒ Square::Types::DisableCardResponse

Disables the card, preventing any further updates or charges. Disabling an already disabled card is allowed but has no effect.



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/square/cards/client.rb', line 71

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

  raise _response.body
end

#get(request_options: {}, **params) ⇒ Square::Types::GetCardResponse

Retrieves details for a specific Card.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/square/cards/client.rb', line 55

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

  raise _response.body
end

#list(request_options: {}, **params) ⇒ Square::Types::ListCardsResponse

Retrieves a list of cards owned by the account making the request. A max of 25 cards will be returned.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/square/cards/client.rb', line 15

def list(request_options: {}, **params)
  _query_param_names = %w[cursor customer_id include_disabled reference_id sort_order]
  _query = params.slice(*_query_param_names)
  params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/cards",
    query: _query
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::ListCardsResponse.load(_response.body)
  end

  raise _response.body
end