The Payments API allows you to create and manage payment transactions. Use this API to charge cards, record external payments, and handle payment lifecycle operations.
Client Methods
List Payments
Retrieves a list of payments taken by the account making the request.
client . Payments . List ( ctx context . Context , request * square . ListPaymentsRequest ) ( * square . ListPaymentsResponse , error )
request
*square.ListPaymentsRequest
Request parameters for listing payments Indicates the start of the time range to retrieve payments for, in RFC 3339 format. Inclusive. Default: The current time minus one year.
Indicates the end of the time range to retrieve payments for, in RFC 3339 format. Default: The current time.
The order in which results are listed:
ASC - Oldest to newest
DESC - Newest to oldest (default)
A pagination cursor returned by a previous call to this endpoint.
Limit results to the location supplied. By default, results are returned for the default location.
The exact amount in the total_money for a payment.
The last four digits of a payment card.
The brand of the payment card (for example, VISA).
The maximum number of results to be returned in a single page. Default: 100 (also the maximum allowed value).
SortField
*square.ListPaymentsRequestSortField
The field used to sort results by. The default is CREATED_AT.
response
*square.ListPaymentsResponse
The list of payments
request := & square . ListPaymentsRequest {
BeginTime : square . String ( "2024-01-01T00:00:00Z" ),
EndTime : square . String ( "2024-12-31T23:59:59Z" ),
SortOrder : square . String ( "DESC" ),
LocationID : square . String ( "L88917AVBK2S5" ),
Limit : square . Int ( 10 ),
SortField : square . ListPaymentsRequestSortFieldCreatedAt . Ptr (),
}
response , err := client . Payments . List ( context . TODO (), request )
if err != nil {
log . Fatal ( err )
}
Create Payment
Creates a payment using the provided source. You can use this endpoint to charge a card or record a payment that the seller received outside of Square.
client . Payments . Create ( ctx context . Context , request * square . CreatePaymentRequest ) ( * square . CreatePaymentResponse , error )
request
*square.CreatePaymentRequest
required
Request parameters for creating a payment The ID for the source of funds for this payment. This could be a payment token generated by the Web Payments SDK, or “CASH” or “EXTERNAL” for offline payments.
A unique string that identifies this CreatePayment request. Keys can be any valid string but must be unique for every CreatePayment request.
The amount of money to accept for this payment, not including tip_money. Must be specified in the smallest denomination of the applicable currency.
The amount designated as a tip, in addition to amount_money.
The amount of money that the developer is taking as a fee for facilitating the payment on behalf of the seller.
If set to true, this payment will be completed when possible. If set to false, this payment is held in an approved state until explicitly completed or canceled. Default: true
The Customer ID of the customer associated with the payment. Required if the source_id refers to a card on file.
The location ID to associate with the payment. If not specified, the main location is used.
A user-defined ID to associate with the payment.
An optional note to be entered by the developer when creating a payment.
response
*square.CreatePaymentResponse
The created payment details
request := & square . CreatePaymentRequest {
SourceID : "ccof:GaJGNaZa8x4OgDJn4GB" ,
IdempotencyKey : "7b0f3ec5-086a-4871-8f13-3c81b3875218" ,
AmountMoney : & square . Money {
Amount : square . Int64 ( int64 ( 1000 )),
Currency : square . CurrencyUsd . Ptr (),
},
Autocomplete : square . Bool ( true ),
CustomerID : square . String ( "W92WH6P11H4Z77CTET0RNTGFW8" ),
LocationID : square . String ( "L88917AVBK2S5" ),
ReferenceID : square . String ( "123456" ),
Note : square . String ( "Brief description" ),
}
response , err := client . Payments . Create ( context . TODO (), request )
if err != nil {
log . Fatal ( err )
}
Get Payment
Retrieves details for a specific payment.
client . Payments . Get ( ctx context . Context , request * square . GetPaymentsRequest ) ( * square . GetPaymentResponse , error )
A unique ID for the desired payment.
request := & square . GetPaymentsRequest {
PaymentID : "payment_id" ,
}
response , err := client . Payments . Get ( context . TODO (), request )
if err != nil {
log . Fatal ( err )
}
Update Payment
Updates a payment with the APPROVED status. You can update the amount_money and tip_money using this endpoint.
client . Payments . Update ( ctx context . Context , request * square . UpdatePaymentRequest ) ( * square . UpdatePaymentResponse , error )
request
*square.UpdatePaymentRequest
required
The ID of the payment to update.
The updated Payment object.
A unique string that identifies this UpdatePayment request.
request := & square . UpdatePaymentRequest {
PaymentID : "payment_id" ,
Payment : & square . Payment {
AmountMoney : & square . Money {
Amount : square . Int64 ( int64 ( 1000 )),
Currency : square . CurrencyUsd . Ptr (),
},
TipMoney : & square . Money {
Amount : square . Int64 ( int64 ( 100 )),
Currency : square . CurrencyUsd . Ptr (),
},
VersionToken : square . String ( "ODhwVQ35xwlzRuoZEwKXucfu7583sPTzK48c5zoGd0g6o" ),
},
IdempotencyKey : "956f8b13-e4ec-45d6-85e8-d1d95ef0c5de" ,
}
response , err := client . Payments . Update ( context . TODO (), request )
if err != nil {
log . Fatal ( err )
}
Cancel Payment
Cancels (voids) a payment. You can use this endpoint to cancel a payment with the APPROVED status.
client . Payments . Cancel ( ctx context . Context , request * square . CancelPaymentsRequest ) ( * square . CancelPaymentResponse , error )
The ID of the payment to cancel.
request := & square . CancelPaymentsRequest {
PaymentID : "payment_id" ,
}
response , err := client . Payments . Cancel ( context . TODO (), request )
if err != nil {
log . Fatal ( err )
}
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.
client . Payments . Complete ( ctx context . Context , request * square . CompletePaymentRequest ) ( * square . CompletePaymentResponse , error )
request
*square.CompletePaymentRequest
required
The unique ID identifying the payment to be completed.
Used for optimistic concurrency. This opaque token identifies the current Payment version that the caller expects.
request := & square . CompletePaymentRequest {
PaymentID : "payment_id" ,
}
response , err := client . Payments . Complete ( context . TODO (), request )
if err != nil {
log . Fatal ( err )
}
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.
client . Payments . CancelByIdempotencyKey ( ctx context . Context , request * square . CancelPaymentByIdempotencyKeyRequest ) ( * square . CancelPaymentByIdempotencyKeyResponse , error )
The idempotency_key identifying the payment to be canceled.
request := & square . CancelPaymentByIdempotencyKeyRequest {
IdempotencyKey : "a7e36d40-d24b-11e8-b568-0800200c9a66" ,
}
response , err := client . Payments . CancelByIdempotencyKey ( context . TODO (), request )
if err != nil {
log . Fatal ( err )
}
Learn More