com.squareup.square.api.DefaultRefundsApi Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of square Show documentation
Show all versions of square Show documentation
Java client library for the Square API
package com.squareup.square.api;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.squareup.square.ApiHelper;
import com.squareup.square.Server;
import com.squareup.square.exceptions.ApiException;
import com.squareup.square.http.client.HttpContext;
import com.squareup.square.http.request.HttpMethod;
import com.squareup.square.models.GetPaymentRefundResponse;
import com.squareup.square.models.ListPaymentRefundsResponse;
import com.squareup.square.models.RefundPaymentRequest;
import com.squareup.square.models.RefundPaymentResponse;
import io.apimatic.core.ApiCall;
import io.apimatic.core.GlobalConfiguration;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
/**
* This class lists all the endpoints of the groups.
*/
public final class DefaultRefundsApi extends BaseApi implements RefundsApi {
/**
* Initializes the controller.
* @param globalConfig Configurations added in client.
*/
public DefaultRefundsApi(GlobalConfiguration globalConfig) {
super(globalConfig);
}
/**
* Retrieves a list of refunds for the account making the request. Results are eventually
* consistent, and new refunds or changes to refunds might take several seconds to appear. The
* maximum results per page is 100.
* @param beginTime Optional parameter: Indicates the start of the time range to retrieve each
* PaymentRefund` for, in RFC 3339 format. The range is determined using the
* `created_at` field for each `PaymentRefund`. Default: The current time minus one
* year.
* @param endTime Optional parameter: Indicates the end of the time range to retrieve each
* `PaymentRefund` for, in RFC 3339 format. The range is determined using the
* `created_at` field for each `PaymentRefund`. Default: The current time.
* @param sortOrder Optional parameter: The order in which results are listed by
* `PaymentRefund.created_at`: - `ASC` - Oldest to newest. - `DESC` - Newest to oldest
* (default).
* @param cursor Optional parameter: 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](https://developer.squareup.com/docs/build-basics/common-api-patterns/pagination).
* @param locationId Optional parameter: Limit results to the location supplied. By default,
* results are returned for all locations associated with the seller.
* @param status Optional parameter: If provided, only refunds with the given status are
* returned. For a list of refund status values, see
* [PaymentRefund](entity:PaymentRefund). Default: If omitted, refunds are returned
* regardless of their status.
* @param sourceType Optional parameter: If provided, only returns refunds whose payments have
* the indicated source type. Current values include `CARD`, `BANK_ACCOUNT`, `WALLET`,
* `CASH`, and `EXTERNAL`. For information about these payment source types, see [Take
* Payments](https://developer.squareup.com/docs/payments-api/take-payments). Default:
* If omitted, refunds are returned regardless of the source type.
* @param limit Optional parameter: 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. If the supplied value is greater than 100, no more than 100 results are
* returned. Default: 100
* @return Returns the ListPaymentRefundsResponse response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public ListPaymentRefundsResponse listPaymentRefunds(
final String beginTime,
final String endTime,
final String sortOrder,
final String cursor,
final String locationId,
final String status,
final String sourceType,
final Integer limit) throws ApiException, IOException {
return prepareListPaymentRefundsRequest(beginTime, endTime, sortOrder, cursor, locationId,
status, sourceType, limit).execute();
}
/**
* Retrieves a list of refunds for the account making the request. Results are eventually
* consistent, and new refunds or changes to refunds might take several seconds to appear. The
* maximum results per page is 100.
* @param beginTime Optional parameter: Indicates the start of the time range to retrieve each
* PaymentRefund` for, in RFC 3339 format. The range is determined using the
* `created_at` field for each `PaymentRefund`. Default: The current time minus one
* year.
* @param endTime Optional parameter: Indicates the end of the time range to retrieve each
* `PaymentRefund` for, in RFC 3339 format. The range is determined using the
* `created_at` field for each `PaymentRefund`. Default: The current time.
* @param sortOrder Optional parameter: The order in which results are listed by
* `PaymentRefund.created_at`: - `ASC` - Oldest to newest. - `DESC` - Newest to oldest
* (default).
* @param cursor Optional parameter: 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](https://developer.squareup.com/docs/build-basics/common-api-patterns/pagination).
* @param locationId Optional parameter: Limit results to the location supplied. By default,
* results are returned for all locations associated with the seller.
* @param status Optional parameter: If provided, only refunds with the given status are
* returned. For a list of refund status values, see
* [PaymentRefund](entity:PaymentRefund). Default: If omitted, refunds are returned
* regardless of their status.
* @param sourceType Optional parameter: If provided, only returns refunds whose payments have
* the indicated source type. Current values include `CARD`, `BANK_ACCOUNT`, `WALLET`,
* `CASH`, and `EXTERNAL`. For information about these payment source types, see [Take
* Payments](https://developer.squareup.com/docs/payments-api/take-payments). Default:
* If omitted, refunds are returned regardless of the source type.
* @param limit Optional parameter: 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. If the supplied value is greater than 100, no more than 100 results are
* returned. Default: 100
* @return Returns the ListPaymentRefundsResponse response from the API call
*/
public CompletableFuture listPaymentRefundsAsync(
final String beginTime,
final String endTime,
final String sortOrder,
final String cursor,
final String locationId,
final String status,
final String sourceType,
final Integer limit) {
try {
return prepareListPaymentRefundsRequest(beginTime, endTime, sortOrder, cursor, locationId,
status, sourceType, limit).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for listPaymentRefunds.
*/
private ApiCall prepareListPaymentRefundsRequest(
final String beginTime,
final String endTime,
final String sortOrder,
final String cursor,
final String locationId,
final String status,
final String sourceType,
final Integer limit) throws IOException {
return new ApiCall.Builder()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/refunds")
.queryParam(param -> param.key("begin_time")
.value(beginTime).isRequired(false))
.queryParam(param -> param.key("end_time")
.value(endTime).isRequired(false))
.queryParam(param -> param.key("sort_order")
.value(sortOrder).isRequired(false))
.queryParam(param -> param.key("cursor")
.value(cursor).isRequired(false))
.queryParam(param -> param.key("location_id")
.value(locationId).isRequired(false))
.queryParam(param -> param.key("status")
.value(status).isRequired(false))
.queryParam(param -> param.key("source_type")
.value(sourceType).isRequired(false))
.queryParam(param -> param.key("limit")
.value(limit).isRequired(false))
.headerParam(param -> param.key("accept").value("application/json"))
.authenticationKey(BaseApi.AUTHENTICATION_KEY)
.httpMethod(HttpMethod.GET))
.responseHandler(responseHandler -> responseHandler
.deserializer(
response -> ApiHelper.deserialize(response, ListPaymentRefundsResponse.class))
.nullify404(false)
.contextInitializer((context, result) ->
result.toBuilder().httpContext((HttpContext)context).build())
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
/**
* Refunds a payment. You can refund the entire payment amount or a portion of it. You can use
* this endpoint to refund a card payment or record a refund of a cash or external payment. For
* more information, see [Refund
* Payment](https://developer.squareup.com/docs/payments-api/refund-payments).
* @param body Required parameter: An object containing the fields to POST for the request.
* See the corresponding object definition for field details.
* @return Returns the RefundPaymentResponse response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public RefundPaymentResponse refundPayment(
final RefundPaymentRequest body) throws ApiException, IOException {
return prepareRefundPaymentRequest(body).execute();
}
/**
* Refunds a payment. You can refund the entire payment amount or a portion of it. You can use
* this endpoint to refund a card payment or record a refund of a cash or external payment. For
* more information, see [Refund
* Payment](https://developer.squareup.com/docs/payments-api/refund-payments).
* @param body Required parameter: An object containing the fields to POST for the request.
* See the corresponding object definition for field details.
* @return Returns the RefundPaymentResponse response from the API call
*/
public CompletableFuture refundPaymentAsync(
final RefundPaymentRequest body) {
try {
return prepareRefundPaymentRequest(body).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for refundPayment.
*/
private ApiCall prepareRefundPaymentRequest(
final RefundPaymentRequest body) throws JsonProcessingException, IOException {
return new ApiCall.Builder()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/refunds")
.bodyParam(param -> param.value(body))
.bodySerializer(() -> ApiHelper.serialize(body))
.headerParam(param -> param.key("Content-Type")
.value("application/json").isRequired(false))
.headerParam(param -> param.key("accept").value("application/json"))
.authenticationKey(BaseApi.AUTHENTICATION_KEY)
.httpMethod(HttpMethod.POST))
.responseHandler(responseHandler -> responseHandler
.deserializer(
response -> ApiHelper.deserialize(response, RefundPaymentResponse.class))
.nullify404(false)
.contextInitializer((context, result) ->
result.toBuilder().httpContext((HttpContext)context).build())
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
/**
* Retrieves a specific refund using the `refund_id`.
* @param refundId Required parameter: The unique ID for the desired `PaymentRefund`.
* @return Returns the GetPaymentRefundResponse response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public GetPaymentRefundResponse getPaymentRefund(
final String refundId) throws ApiException, IOException {
return prepareGetPaymentRefundRequest(refundId).execute();
}
/**
* Retrieves a specific refund using the `refund_id`.
* @param refundId Required parameter: The unique ID for the desired `PaymentRefund`.
* @return Returns the GetPaymentRefundResponse response from the API call
*/
public CompletableFuture getPaymentRefundAsync(
final String refundId) {
try {
return prepareGetPaymentRefundRequest(refundId).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for getPaymentRefund.
*/
private ApiCall prepareGetPaymentRefundRequest(
final String refundId) throws IOException {
return new ApiCall.Builder()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/refunds/{refund_id}")
.templateParam(param -> param.key("refund_id").value(refundId)
.shouldEncode(true))
.headerParam(param -> param.key("accept").value("application/json"))
.authenticationKey(BaseApi.AUTHENTICATION_KEY)
.httpMethod(HttpMethod.GET))
.responseHandler(responseHandler -> responseHandler
.deserializer(
response -> ApiHelper.deserialize(response, GetPaymentRefundResponse.class))
.nullify404(false)
.contextInitializer((context, result) ->
result.toBuilder().httpContext((HttpContext)context).build())
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy