
Api.RefundApi Maven / Gradle / Ivy
/*
* CyberSource Merged Spec
* All CyberSource API specs merged together. These are available at https://developer.cybersource.com/api/reference/api-reference.html
*
* OpenAPI spec version: 0.0.1
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package Api;
import Invokers.ApiCallback;
import Invokers.ApiClient;
import Invokers.ApiException;
import Invokers.ApiResponse;
import Invokers.Configuration;
import Invokers.Pair;
import Invokers.ProgressRequestBody;
import Invokers.ProgressResponseBody;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.io.InputStream;
import Model.PtsV2PaymentsPost502Response;
import Model.PtsV2PaymentsRefundPost201Response;
import Model.PtsV2PaymentsRefundPost400Response;
import Model.RefundCaptureRequest;
import Model.RefundPaymentRequest;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import utilities.tracking.SdkTracker;
import com.cybersource.authsdk.util.mle.MLEUtility;
import com.cybersource.authsdk.util.mle.MLEException;
public class RefundApi {
private static Logger logger = LogManager.getLogger(RefundApi.class);
private ApiClient apiClient;
public RefundApi() {
this(Configuration.getDefaultApiClient());
}
public RefundApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* Build call for refundCapture
* @param refundCaptureRequest (required)
* @param id The capture ID. This ID is returned from a previous capture request. (required)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public okhttp3.Call refundCaptureCall(RefundCaptureRequest refundCaptureRequest, String id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
SdkTracker sdkTracker = new SdkTracker();
Object localVarPostBody = sdkTracker.insertDeveloperIdTracker(refundCaptureRequest, RefundCaptureRequest.class.getSimpleName(), apiClient.merchantConfig.getRunEnvironment(), apiClient.merchantConfig.getDefaultDeveloperId());
boolean isMLESupportedByCybsForApi = true;
if (MLEUtility.checkIsMLEForAPI(apiClient.merchantConfig, isMLESupportedByCybsForApi, "refundCapture,refundCaptureAsync,refundCaptureWithHttpInfo,refundCaptureCall")) {
try {
localVarPostBody = MLEUtility.encryptRequestPayload(apiClient.merchantConfig, localVarPostBody);
} catch (MLEException e) {
logger.error("Failed to encrypt request body {}", e.getMessage(), e);
throw new ApiException("Failed to encrypt request body : " + e.getMessage());
}
}
// create path and map variables
String localVarPath = "/pts/v2/captures/{id}/refunds"
.replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString()));
List localVarQueryParams = new ArrayList();
Map localVarHeaderParams = new HashMap();
Map localVarFormParams = new HashMap();
final String[] localVarAccepts = {
"application/hal+json;charset=utf-8"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
final String[] localVarContentTypes = {
"application/json;charset=utf-8"
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);
if(progressListener != null) {
apiClient.getHttpClient().newBuilder().addNetworkInterceptor(new okhttp3.Interceptor() {
@Override
public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
okhttp3.Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
});
}
String[] localVarAuthNames = new String[] { };
return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}
@SuppressWarnings("rawtypes")
private okhttp3.Call refundCaptureValidateBeforeCall(RefundCaptureRequest refundCaptureRequest, String id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
// verify the required parameter 'refundCaptureRequest' is set
if (refundCaptureRequest == null) {
logger.error("Missing the required parameter 'refundCaptureRequest' when calling refundCapture(Async)");
throw new ApiException("Missing the required parameter 'refundCaptureRequest' when calling refundCapture(Async)");
}
// verify the required parameter 'id' is set
if (id == null) {
logger.error("Missing the required parameter 'id' when calling refundCapture(Async)");
throw new ApiException("Missing the required parameter 'id' when calling refundCapture(Async)");
}
okhttp3.Call call = refundCaptureCall(refundCaptureRequest, id, progressListener, progressRequestListener);
return call;
}
/**
* Refund a Capture
* Refund a capture API is only used, if you have requested Capture independenlty using [/pts/v2/payments/{id}/captures](https://developer.cybersource.com/api-reference-assets/index.html#payments_capture) API call. Include the capture ID in the POST request to refund the captured amount.
* @param refundCaptureRequest (required)
* @param id The capture ID. This ID is returned from a previous capture request. (required)
* @return PtsV2PaymentsRefundPost201Response
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public PtsV2PaymentsRefundPost201Response refundCapture(RefundCaptureRequest refundCaptureRequest, String id) throws ApiException {
logger.info("CALL TO METHOD 'refundCapture' STARTED");
ApiResponse resp = refundCaptureWithHttpInfo(refundCaptureRequest, id);
logger.info("CALL TO METHOD 'refundCapture' ENDED");
return resp.getData();
}
/**
* Refund a Capture
* Refund a capture API is only used, if you have requested Capture independenlty using [/pts/v2/payments/{id}/captures](https://developer.cybersource.com/api-reference-assets/index.html#payments_capture) API call. Include the capture ID in the POST request to refund the captured amount.
* @param refundCaptureRequest (required)
* @param id The capture ID. This ID is returned from a previous capture request. (required)
* @return ApiResponse<PtsV2PaymentsRefundPost201Response>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse refundCaptureWithHttpInfo(RefundCaptureRequest refundCaptureRequest, String id) throws ApiException {
this.apiClient.setComputationStartTime(System.nanoTime());
okhttp3.Call call = refundCaptureValidateBeforeCall(refundCaptureRequest, id, null, null);
Type localVarReturnType = new TypeToken(){}.getType();
return apiClient.execute(call, localVarReturnType);
}
/**
* Refund a Capture (asynchronously)
* Refund a capture API is only used, if you have requested Capture independenlty using [/pts/v2/payments/{id}/captures](https://developer.cybersource.com/api-reference-assets/index.html#payments_capture) API call. Include the capture ID in the POST request to refund the captured amount.
* @param refundCaptureRequest (required)
* @param id The capture ID. This ID is returned from a previous capture request. (required)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/
public okhttp3.Call refundCaptureAsync(RefundCaptureRequest refundCaptureRequest, String id, final ApiCallback callback) throws ApiException {
this.apiClient.setComputationStartTime(System.nanoTime());
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
okhttp3.Call call = refundCaptureValidateBeforeCall(refundCaptureRequest, id, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken(){}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
/**
* Build call for refundPayment
* @param refundPaymentRequest (required)
* @param id The payment ID. This ID is returned from a previous payment request. (required)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public okhttp3.Call refundPaymentCall(RefundPaymentRequest refundPaymentRequest, String id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
SdkTracker sdkTracker = new SdkTracker();
Object localVarPostBody = sdkTracker.insertDeveloperIdTracker(refundPaymentRequest, RefundPaymentRequest.class.getSimpleName(), apiClient.merchantConfig.getRunEnvironment(), apiClient.merchantConfig.getDefaultDeveloperId());
boolean isMLESupportedByCybsForApi = true;
if (MLEUtility.checkIsMLEForAPI(apiClient.merchantConfig, isMLESupportedByCybsForApi, "refundPayment,refundPaymentAsync,refundPaymentWithHttpInfo,refundPaymentCall")) {
try {
localVarPostBody = MLEUtility.encryptRequestPayload(apiClient.merchantConfig, localVarPostBody);
} catch (MLEException e) {
logger.error("Failed to encrypt request body {}", e.getMessage(), e);
throw new ApiException("Failed to encrypt request body : " + e.getMessage());
}
}
// create path and map variables
String localVarPath = "/pts/v2/payments/{id}/refunds"
.replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString()));
List localVarQueryParams = new ArrayList();
Map localVarHeaderParams = new HashMap();
Map localVarFormParams = new HashMap();
final String[] localVarAccepts = {
"application/hal+json;charset=utf-8"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
final String[] localVarContentTypes = {
"application/json;charset=utf-8"
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);
if(progressListener != null) {
apiClient.getHttpClient().newBuilder().addNetworkInterceptor(new okhttp3.Interceptor() {
@Override
public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
okhttp3.Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
});
}
String[] localVarAuthNames = new String[] { };
return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}
@SuppressWarnings("rawtypes")
private okhttp3.Call refundPaymentValidateBeforeCall(RefundPaymentRequest refundPaymentRequest, String id, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
// verify the required parameter 'refundPaymentRequest' is set
if (refundPaymentRequest == null) {
logger.error("Missing the required parameter 'refundPaymentRequest' when calling refundPayment(Async)");
throw new ApiException("Missing the required parameter 'refundPaymentRequest' when calling refundPayment(Async)");
}
// verify the required parameter 'id' is set
if (id == null) {
logger.error("Missing the required parameter 'id' when calling refundPayment(Async)");
throw new ApiException("Missing the required parameter 'id' when calling refundPayment(Async)");
}
okhttp3.Call call = refundPaymentCall(refundPaymentRequest, id, progressListener, progressRequestListener);
return call;
}
/**
* Refund a Payment
* Refund a Payment API is only used, if you have requested Authorization and Capture together in [/pts/v2/payments](https://developer.cybersource.com/api-reference-assets/index.html#payments_payments) API call. Include the payment ID in the POST request to refund the payment amount.
* @param refundPaymentRequest (required)
* @param id The payment ID. This ID is returned from a previous payment request. (required)
* @return PtsV2PaymentsRefundPost201Response
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public PtsV2PaymentsRefundPost201Response refundPayment(RefundPaymentRequest refundPaymentRequest, String id) throws ApiException {
logger.info("CALL TO METHOD 'refundPayment' STARTED");
ApiResponse resp = refundPaymentWithHttpInfo(refundPaymentRequest, id);
logger.info("CALL TO METHOD 'refundPayment' ENDED");
return resp.getData();
}
/**
* Refund a Payment
* Refund a Payment API is only used, if you have requested Authorization and Capture together in [/pts/v2/payments](https://developer.cybersource.com/api-reference-assets/index.html#payments_payments) API call. Include the payment ID in the POST request to refund the payment amount.
* @param refundPaymentRequest (required)
* @param id The payment ID. This ID is returned from a previous payment request. (required)
* @return ApiResponse<PtsV2PaymentsRefundPost201Response>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse refundPaymentWithHttpInfo(RefundPaymentRequest refundPaymentRequest, String id) throws ApiException {
this.apiClient.setComputationStartTime(System.nanoTime());
okhttp3.Call call = refundPaymentValidateBeforeCall(refundPaymentRequest, id, null, null);
Type localVarReturnType = new TypeToken(){}.getType();
return apiClient.execute(call, localVarReturnType);
}
/**
* Refund a Payment (asynchronously)
* Refund a Payment API is only used, if you have requested Authorization and Capture together in [/pts/v2/payments](https://developer.cybersource.com/api-reference-assets/index.html#payments_payments) API call. Include the payment ID in the POST request to refund the payment amount.
* @param refundPaymentRequest (required)
* @param id The payment ID. This ID is returned from a previous payment request. (required)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/
public okhttp3.Call refundPaymentAsync(RefundPaymentRequest refundPaymentRequest, String id, final ApiCallback callback) throws ApiException {
this.apiClient.setComputationStartTime(System.nanoTime());
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
okhttp3.Call call = refundPaymentValidateBeforeCall(refundPaymentRequest, id, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken(){}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy