Class: Square::CardsApi

Inherits:
BaseApi show all
Defined in:
lib/square/api/cards_api.rb

Overview

CardsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from Square::BaseApi

Instance Method Details

#create_card(body:) ⇒ ApiResponse

Adds a card on file to an existing merchant. the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreateCardRequest)

    Required parameter: An object containing

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/square/api/cards_api.rb', line 51

def create_card(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/cards',
                                 'default')
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end

#disable_card(card_id:) ⇒ ApiResponse

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

Parameters:

  • card_id (String)

    Required parameter: Unique ID for the desired

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/square/api/cards_api.rb', line 93

def disable_card(card_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/cards/{card_id}/disable',
                                 'default')
               .template_param(new_parameter(card_id, key: 'card_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end

#list_cards(cursor: nil, customer_id: nil, include_disabled: false, reference_id: nil, sort_order: nil) ⇒ ApiResponse

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/build-basics/common-api-p atterns/pagination) for more information. associated with the customer supplied. By default, all cards owned by the merchant are returned. Includes disabled 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.

Parameters:

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • customer_id (String) (defaults to: nil)

    Optional parameter: Limit results to cards

  • include_disabled (TrueClass | FalseClass) (defaults to: false)

    Optional parameter:

  • reference_id (String) (defaults to: nil)

    Optional parameter: Limit results to cards

  • sort_order (SortOrder) (defaults to: nil)

    Optional parameter: Sorts the returned list

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/square/api/cards_api.rb', line 23

def list_cards(cursor: nil,
               customer_id: nil,
               include_disabled: false,
               reference_id: nil,
               sort_order: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/cards',
                                 'default')
               .query_param(new_parameter(cursor, key: 'cursor'))
               .query_param(new_parameter(customer_id, key: 'customer_id'))
               .query_param(new_parameter(include_disabled, key: 'include_disabled'))
               .query_param(new_parameter(reference_id, key: 'reference_id'))
               .query_param(new_parameter(sort_order, key: 'sort_order'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end

#retrieve_card(card_id:) ⇒ ApiResponse

Retrieves details for a specific Card. Card.

Parameters:

  • card_id (String)

    Required parameter: Unique ID for the desired

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/square/api/cards_api.rb', line 72

def retrieve_card(card_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/cards/{card_id}',
                                 'default')
               .template_param(new_parameter(card_id, key: 'card_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:json_deserialize))
                .is_api_response(true)
                .convertor(ApiResponse.method(:create)))
    .execute
end