Class: Square::CheckoutApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/checkout_api.rb

Overview

CheckoutApi

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_checkout(location_id:, body:) ⇒ CreateCheckoutResponse Hash

Links a ‘checkoutId` to a `checkout_page_url` that customers are directed to in order to provide their payment information using a payment processing workflow hosted on connect.squareup.com. NOTE: The Checkout API has been updated with new features. For more information, see [Checkout API highlights](developer.squareup.com/docs/checkout-api#checkout-api- highlights). location to associate the checkout with. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • location_id (String)

    Required parameter: The ID of the business

  • body (CreateCheckoutRequest)

    Required parameter: An object

Returns:

  • (CreateCheckoutResponse Hash)

    response from the API call



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/square/api/checkout_api.rb', line 17

def create_checkout(location_id:,
                    body:)
  warn 'Endpoint create_checkout in CheckoutApi is deprecated'
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/locations/{location_id}/checkouts',
                                 'default')
               .template_param(new_parameter(location_id, key: 'location_id')
                                .should_encode(true))
               .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

Creates a Square-hosted checkout page. Applications can share the resulting payment link with their buyer to pay for goods and services. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreatePaymentLinkRequest)

    Required parameter: An object

Returns:

  • (CreatePaymentLinkResponse Hash)

    response from the API call



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/square/api/checkout_api.rb', line 74

def create_payment_link(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/online-checkout/payment-links',
                                 '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

Deletes a payment link. delete.

Parameters:

  • id (String)

    Required parameter: The ID of the payment link to

Returns:

  • (DeletePaymentLinkResponse Hash)

    response from the API call



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

def delete_payment_link(id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/v2/online-checkout/payment-links/{id}',
                                 'default')
               .template_param(new_parameter(id, key: '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

Lists all payment links. a previous call to this endpoint. Provide this cursor to retrieve the next set of results for the original query. If a cursor is not provided, the endpoint returns the first page of the results. For more information, see [Pagination](developer.squareup.com/docs/basics/api101/pagination) . results to return per page. The limit is advisory and the implementation might return more or less results. If the supplied limit is negative, zero, or greater than the maximum limit of 1000, it is ignored. Default value: ‘100`

Parameters:

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • limit (Integer) (defaults to: nil)

    Optional parameter: A limit on the number of

Returns:

  • (ListPaymentLinksResponse Hash)

    response from the API call



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

def list_payment_links(cursor: nil,
                       limit: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/online-checkout/payment-links',
                                 'default')
               .query_param(new_parameter(cursor, key: 'cursor'))
               .query_param(new_parameter(limit, key: 'limit'))
               .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

Retrieves a payment link.

Parameters:

  • id (String)

    Required parameter: The ID of link to retrieve.

Returns:

  • (RetrievePaymentLinkResponse Hash)

    response from the API call



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/square/api/checkout_api.rb', line 114

def retrieve_payment_link(id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/online-checkout/payment-links/{id}',
                                 'default')
               .template_param(new_parameter(id, key: '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

Updates a payment link. You can update the ‘payment_link` fields such as `description`, `checkout_options`, and `pre_populated_data`. You cannot update other fields such as the `order_id`, `version`, `URL`, or `timestamp` field. update. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • id (String)

    Required parameter: The ID of the payment link to

  • body (UpdatePaymentLinkRequest)

    Required parameter: An object

Returns:

  • (UpdatePaymentLinkResponse Hash)

    response from the API call



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/square/api/checkout_api.rb', line 140

def update_payment_link(id:,
                        body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/v2/online-checkout/payment-links/{id}',
                                 'default')
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .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