PaymentsApi paymentsApi = client.getPaymentsApi();
PaymentsApi
- List Payments
- Create Payment
- Cancel Payment by Idempotency Key
- Get Payment
- Cancel Payment
- Complete Payment
Retrieves a list of payments taken by the account making the request.
Max results per page: 100
CompletableFuture<ListPaymentsResponse> listPaymentsAsync(
final String beginTime,
final String endTime,
final String sortOrder,
final String cursor,
final String locationId,
final Long total,
final String last4,
final String cardBrand,
final Integer limit)
Parameter | Type | Tags | Description |
---|---|---|---|
beginTime |
String |
Query, Optional | Timestamp for the beginning of the reporting period, in RFC 3339 format. Inclusive. Default: The current time minus one year. |
endTime |
String |
Query, Optional | Timestamp for the end of the requested reporting period, in RFC 3339 format. Default: The current time. |
sortOrder |
String |
Query, Optional | The order in which results are listed. - 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 to retrieve the next set of results for the original query. See Pagination for more information. |
locationId |
String |
Query, Optional | Limit results to the location supplied. By default, results are returned for the default (main) location associated with the merchant. |
total |
Long |
Query, Optional | The exact amount in the total_money for a Payment . |
last4 |
String |
Query, Optional | The last 4 digits of Payment card. |
cardBrand |
String |
Query, Optional | The brand of Payment card. For example, VISA |
limit |
Integer |
Query, Optional | 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. If the supplied value is greater than 100, at most 100 results will be returned. Default: 100 |
String beginTime = "begin_time2";
String endTime = "end_time2";
String sortOrder = "sort_order0";
String cursor = "cursor6";
String locationId = "location_id4";
Long total = 10L;
String last4 = "last_42";
String cardBrand = "card_brand6";
Integer limit = 172;
paymentsApi.listPaymentsAsync(beginTime, endTime, sortOrder, cursor, locationId, total, last4, cardBrand, limit).thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});
Charges a payment source, for example, a card represented by customer's card on file or a card nonce. In addition to the payment source, the request must also include the amount to accept for the payment.
There are several optional parameters that you can include in the request. For example, tip money, whether to autocomplete the payment, or a reference ID to correlate this payment with another system.
The PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS
OAuth permission is required
to enable application fees.
Take Payments: https://developer.squareup.com/docs/payments-api/take-payments
CompletableFuture<CreatePaymentResponse> createPaymentAsync(
final CreatePaymentRequest body)
Parameter | Type | Tags | Description |
---|---|---|---|
body |
CreatePaymentRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
Money bodyAmountMoney = new Money.Builder()
.amount(200L)
.currency("USD")
.build();
Money bodyTipMoney = new Money.Builder()
.amount(198L)
.currency("CHF")
.build();
Money bodyAppFeeMoney = new Money.Builder()
.amount(10L)
.currency("USD")
.build();
CreatePaymentRequest body = new CreatePaymentRequest.Builder(
"ccof:uIbfJXhXETSP197M3GB",
"4935a656-a929-4792-b97c-8848be85c27c",
bodyAmountMoney)
.tipMoney(bodyTipMoney)
.appFeeMoney(bodyAppFeeMoney)
.delayDuration("delay_duration6")
.autocomplete(true)
.orderId("order_id0")
.customerId("VDKXEEKPJN48QDG3BGGFAK05P8")
.locationId("XK3DBG77NJBFX")
.referenceId("123456")
.note("Brief description")
.build();
paymentsApi.createPaymentAsync(body).thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});
Cancels (voids) a payment identified by the idempotency key that is specified in the request.
Use this method when status of a CreatePayment request is unknown. For example, after you send a CreatePayment request a network error occurs and you don't 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 you want to cancel. After cancelling 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, the end point returns successfully.
CompletableFuture<CancelPaymentByIdempotencyKeyResponse> cancelPaymentByIdempotencyKeyAsync(
final CancelPaymentByIdempotencyKeyRequest body)
Parameter | Type | Tags | Description |
---|---|---|---|
body |
CancelPaymentByIdempotencyKeyRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
CancelPaymentByIdempotencyKeyResponse
CancelPaymentByIdempotencyKeyRequest body = new CancelPaymentByIdempotencyKeyRequest.Builder(
"a7e36d40-d24b-11e8-b568-0800200c9a66")
.build();
paymentsApi.cancelPaymentByIdempotencyKeyAsync(body).thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});
Retrieves details for a specific Payment.
CompletableFuture<GetPaymentResponse> getPaymentAsync(
final String paymentId)
Parameter | Type | Tags | Description |
---|---|---|---|
paymentId |
String |
Template, Required | Unique ID for the desired Payment . |
String paymentId = "payment_id0";
paymentsApi.getPaymentAsync(paymentId).thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});
Cancels (voids) a payment. If you set autocomplete
to false when creating a payment,
you can cancel the payment using this endpoint.
Delayed capture: https://developer.squareup.com/docs/payments-api/take-payments#delayed-payments
CompletableFuture<CancelPaymentResponse> cancelPaymentAsync(
final String paymentId)
Parameter | Type | Tags | Description |
---|---|---|---|
paymentId |
String |
Template, Required | payment_id identifying the payment to be canceled. |
String paymentId = "payment_id0";
paymentsApi.cancelPaymentAsync(paymentId).thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});
Completes (captures) a payment.
By default, payments are set to complete immediately after they are created. If you set autocomplete to false when creating a payment, you can complete (capture) the payment using this endpoint.
Delayed capture: https://developer.squareup.com/docs/payments-api/take-payments#delayed-payments
CompletableFuture<CompletePaymentResponse> completePaymentAsync(
final String paymentId)
Parameter | Type | Tags | Description |
---|---|---|---|
paymentId |
String |
Template, Required | Unique ID identifying the payment to be completed. |
String paymentId = "payment_id0";
paymentsApi.completePaymentAsync(paymentId).thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});