Skip to content

Latest commit

 

History

History
352 lines (247 loc) · 11.5 KB

payments.md

File metadata and controls

352 lines (247 loc) · 11.5 KB

Payments

payments_api = client.payments

Class Name

PaymentsApi

Methods

List Payments

Retrieves a list of payments taken by the account making the request.

Results are eventually consistent, and new payments or changes to payments might take several seconds to appear.

The maximum results per page is 100.

def list_payments(begin_time: nil,
                  end_time: nil,
                  sort_order: nil,
                  cursor: nil,
                  location_id: nil,
                  total: nil,
                  last_4: nil,
                  card_brand: nil,
                  limit: nil,
                  is_offline_payment: false,
                  offline_begin_time: nil,
                  offline_end_time: nil)

Parameters

Parameter Type Tags Description
begin_time String Query, Optional Indicates the start of the time range to retrieve payments for, in RFC 3339 format.
The range is determined using the created_at field for each Payment.
Inclusive. Default: The current time minus one year.
end_time String Query, Optional Indicates the end of the time range to retrieve payments for, in RFC 3339 format. The
range is determined using the created_at field for each Payment.

Default: The current time.
sort_order String Query, Optional The order in which results are listed by Payment.created_at:

- ASC - Oldest to newest.
- DESC - Newest to oldest (default).
cursor String Query, Optional A pagination cursor returned by a previous call to this endpoint.
Provide this cursor to retrieve the next set of results for the original query.

For more information, see Pagination.
location_id String Query, Optional Limit results to the location supplied. By default, results are returned
for the default (main) location associated with the seller.
total Integer Query, Optional The exact amount in the total_money for a payment.
last_4 String Query, Optional The last four digits of a payment card.
card_brand String Query, Optional The brand of the payment card (for example, VISA).
limit Integer Query, Optional The maximum number of results to be returned in a single page.
It is possible to receive fewer results than the specified limit on a given page.

The default value of 100 is also the maximum allowed value. If the provided value is
greater than 100, it is ignored and the default value is used instead.

Default: 100
is_offline_payment TrueClass | FalseClass Query, Optional Whether the payment was taken offline or not.
Default: false
offline_begin_time String Query, Optional Indicates the start of the time range for which to retrieve offline payments, in RFC 3339
format for timestamps. The range is determined using the
offline_payment_details.client_created_at field for each Payment. If set, payments without a
value set in offline_payment_details.client_created_at will not be returned.

Default: The current time.
offline_end_time String Query, Optional Indicates the end of the time range for which to retrieve offline payments, in RFC 3339
format for timestamps. The range is determined using the
offline_payment_details.client_created_at field for each Payment. If set, payments without a
value set in offline_payment_details.client_created_at will not be returned.

Default: The current time.

Response Type

This method returns a ApiResponse instance. The data property in this instance returns the response data which is of type List Payments Response Hash.

Example Usage

is_offline_payment = false


result = payments_api.list_payments(is_offline_payment: is_offline_payment)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Create Payment

Creates a payment using the provided source. You can use this endpoint to charge a card (credit/debit card or
Square gift card) or record a payment that the seller received outside of Square (cash payment from a buyer or a payment that an external entity processed on behalf of the seller).

The endpoint creates a Payment object and returns it in the response.

def create_payment(body:)

Parameters

Parameter Type Tags Description
body Create Payment Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a ApiResponse instance. The data property in this instance returns the response data which is of type Create Payment Response Hash.

Example Usage

body = {
  :source_id => 'ccof:GaJGNaZa8x4OgDJn4GB',
  :idempotency_key => '7b0f3ec5-086a-4871-8f13-3c81b3875218',
  :amount_money => {
    :amount => 1000,
    :currency => 'USD'
  },
  :app_fee_money => {
    :amount => 10,
    :currency => 'USD'
  },
  :autocomplete => true,
  :customer_id => 'W92WH6P11H4Z77CTET0RNTGFW8',
  :location_id => 'L88917AVBK2S5',
  :reference_id => '123456',
  :note => 'Brief description'
}


result = payments_api.create_payment(body: body)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Cancel Payment by Idempotency Key

Cancels (voids) a payment identified by the idempotency key that is specified in the request.

Use this method when the status of a CreatePayment request is unknown (for example, after you send a CreatePayment request, a network error occurs and you do not get a response). In this case, you can direct Square to cancel the payment using this endpoint. In the request, you provide the same idempotency key that you provided in your CreatePayment request that you want to cancel. After canceling the payment, you can submit your CreatePayment request again.

Note that if no payment with the specified idempotency key is found, no action is taken and the endpoint returns successfully.

def cancel_payment_by_idempotency_key(body:)

Parameters

Parameter Type Tags Description
body Cancel Payment by Idempotency Key Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a ApiResponse instance. The data property in this instance returns the response data which is of type Cancel Payment by Idempotency Key Response Hash.

Example Usage

body = {
  :idempotency_key => 'a7e36d40-d24b-11e8-b568-0800200c9a66'
}


result = payments_api.cancel_payment_by_idempotency_key(body: body)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Get Payment

Retrieves details for a specific payment.

def get_payment(payment_id:)

Parameters

Parameter Type Tags Description
payment_id String Template, Required A unique ID for the desired payment.

Response Type

This method returns a ApiResponse instance. The data property in this instance returns the response data which is of type Get Payment Response Hash.

Example Usage

payment_id = 'payment_id0'


result = payments_api.get_payment(payment_id: payment_id)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Update Payment

Updates a payment with the APPROVED status. You can update the amount_money and tip_money using this endpoint.

def update_payment(payment_id:,
                   body:)

Parameters

Parameter Type Tags Description
payment_id String Template, Required The ID of the payment to update.
body Update Payment Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a ApiResponse instance. The data property in this instance returns the response data which is of type Update Payment Response Hash.

Example Usage

payment_id = 'payment_id0'

body = {
  :idempotency_key => '956f8b13-e4ec-45d6-85e8-d1d95ef0c5de',
  :payment => {
    :amount_money => {
      :amount => 1000,
      :currency => 'USD'
    },
    :tip_money => {
      :amount => 100,
      :currency => 'USD'
    },
    :version_token => 'ODhwVQ35xwlzRuoZEwKXucfu7583sPTzK48c5zoGd0g6o'
  }
}


result = payments_api.update_payment(
  payment_id: payment_id,
  body: body
)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Cancel Payment

Cancels (voids) a payment. You can use this endpoint to cancel a payment with the APPROVED status.

def cancel_payment(payment_id:)

Parameters

Parameter Type Tags Description
payment_id String Template, Required The ID of the payment to cancel.

Response Type

This method returns a ApiResponse instance. The data property in this instance returns the response data which is of type Cancel Payment Response Hash.

Example Usage

payment_id = 'payment_id0'


result = payments_api.cancel_payment(payment_id: payment_id)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Complete Payment

Completes (captures) a payment. By default, payments are set to complete immediately after they are created.

You can use this endpoint to complete a payment with the APPROVED status.

def complete_payment(payment_id:,
                     body:)

Parameters

Parameter Type Tags Description
payment_id String Template, Required The unique ID identifying the payment to be completed.
body Complete Payment Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a ApiResponse instance. The data property in this instance returns the response data which is of type Complete Payment Response Hash.

Example Usage

payment_id = 'payment_id0'

body = {}


result = payments_api.complete_payment(
  payment_id: payment_id,
  body: body
)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end