All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Api.OrdersApi Maven / Gradle / Ivy

There is a newer version: 0.0.8
Show newest version
/*
 * 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.CreateOrderRequest;
import Model.PtsV2CreateOrderPost201Response;
import Model.PtsV2CreateOrderPost400Response;
import Model.PtsV2PaymentsPost502Response;
import Model.PtsV2UpdateOrderPatch201Response;
import Model.UpdateOrderRequest;

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 OrdersApi {
    private static Logger logger = LogManager.getLogger(OrdersApi.class);
    
    private ApiClient apiClient;

    public OrdersApi() {
        this(Configuration.getDefaultApiClient());
    }

    public OrdersApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Build call for createOrder
     * @param createOrderRequest  (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 createOrderCall(CreateOrderRequest createOrderRequest, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        SdkTracker sdkTracker = new SdkTracker();
        Object localVarPostBody = sdkTracker.insertDeveloperIdTracker(createOrderRequest, CreateOrderRequest.class.getSimpleName(), apiClient.merchantConfig.getRunEnvironment(), apiClient.merchantConfig.getDefaultDeveloperId());
        
        boolean isMLESupportedByCybsForApi = false;
        if (MLEUtility.checkIsMLEForAPI(apiClient.merchantConfig, isMLESupportedByCybsForApi, "createOrder,createOrderAsync,createOrderWithHttpInfo,createOrderCall")) {
            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/intents";

        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 createOrderValidateBeforeCall(CreateOrderRequest createOrderRequest, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'createOrderRequest' is set
        if (createOrderRequest == null) {
            logger.error("Missing the required parameter 'createOrderRequest' when calling createOrder(Async)");
            throw new ApiException("Missing the required parameter 'createOrderRequest' when calling createOrder(Async)");
        }
        
        
        okhttp3.Call call = createOrderCall(createOrderRequest, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Create an Order
     * A create order request enables you to send the itemized details along with the order. This API can be used by merchants initiating their transactions with the create order API.  
     * @param createOrderRequest  (required)
     * @return PtsV2CreateOrderPost201Response
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public PtsV2CreateOrderPost201Response createOrder(CreateOrderRequest createOrderRequest) throws ApiException {
        logger.info("CALL TO METHOD 'createOrder' STARTED");
        this.apiClient.setComputationStartTime(System.nanoTime());
        ApiResponse resp = createOrderWithHttpInfo(createOrderRequest);
        logger.info("CALL TO METHOD 'createOrder' ENDED");
        return resp.getData();
    }

    /**
     * Create an Order
     * A create order request enables you to send the itemized details along with the order. This API can be used by merchants initiating their transactions with the create order API.  
     * @param createOrderRequest  (required)
     * @return ApiResponse<PtsV2CreateOrderPost201Response>
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse createOrderWithHttpInfo(CreateOrderRequest createOrderRequest) throws ApiException {
        okhttp3.Call call = createOrderValidateBeforeCall(createOrderRequest, null, null);
        Type localVarReturnType = new TypeToken(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Create an Order (asynchronously)
     * A create order request enables you to send the itemized details along with the order. This API can be used by merchants initiating their transactions with the create order API.  
     * @param createOrderRequest  (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 createOrderAsync(CreateOrderRequest createOrderRequest, 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 = createOrderValidateBeforeCall(createOrderRequest, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for updateOrder
     * @param id The ID returned from the original create order response. (required)
     * @param updateOrderRequest  (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 updateOrderCall(String id, UpdateOrderRequest updateOrderRequest, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        SdkTracker sdkTracker = new SdkTracker();
        Object localVarPostBody = sdkTracker.insertDeveloperIdTracker(updateOrderRequest, UpdateOrderRequest.class.getSimpleName(), apiClient.merchantConfig.getRunEnvironment(), apiClient.merchantConfig.getDefaultDeveloperId());
        
        boolean isMLESupportedByCybsForApi = false;
        if (MLEUtility.checkIsMLEForAPI(apiClient.merchantConfig, isMLESupportedByCybsForApi, "updateOrder,updateOrderAsync,updateOrderWithHttpInfo,updateOrderCall")) {
            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/intents/{id}"
            .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, "PATCH", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private okhttp3.Call updateOrderValidateBeforeCall(String id, UpdateOrderRequest updateOrderRequest, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'id' is set
        if (id == null) {
            logger.error("Missing the required parameter 'id' when calling updateOrder(Async)");
            throw new ApiException("Missing the required parameter 'id' when calling updateOrder(Async)");
        }
        
        // verify the required parameter 'updateOrderRequest' is set
        if (updateOrderRequest == null) {
            logger.error("Missing the required parameter 'updateOrderRequest' when calling updateOrder(Async)");
            throw new ApiException("Missing the required parameter 'updateOrderRequest' when calling updateOrder(Async)");
        }
        
        
        okhttp3.Call call = updateOrderCall(id, updateOrderRequest, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Update an Order
     * This API can be used in two flavours - for updating the order as well as saving the order. 
     * @param id The ID returned from the original create order response. (required)
     * @param updateOrderRequest  (required)
     * @return PtsV2UpdateOrderPatch201Response
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public PtsV2UpdateOrderPatch201Response updateOrder(String id, UpdateOrderRequest updateOrderRequest) throws ApiException {
        logger.info("CALL TO METHOD 'updateOrder' STARTED");
        this.apiClient.setComputationStartTime(System.nanoTime());
        ApiResponse resp = updateOrderWithHttpInfo(id, updateOrderRequest);
        logger.info("CALL TO METHOD 'updateOrder' ENDED");
        return resp.getData();
    }

    /**
     * Update an Order
     * This API can be used in two flavours - for updating the order as well as saving the order. 
     * @param id The ID returned from the original create order response. (required)
     * @param updateOrderRequest  (required)
     * @return ApiResponse<PtsV2UpdateOrderPatch201Response>
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse updateOrderWithHttpInfo(String id, UpdateOrderRequest updateOrderRequest) throws ApiException {
        okhttp3.Call call = updateOrderValidateBeforeCall(id, updateOrderRequest, null, null);
        Type localVarReturnType = new TypeToken(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Update an Order (asynchronously)
     * This API can be used in two flavours - for updating the order as well as saving the order. 
     * @param id The ID returned from the original create order response. (required)
     * @param updateOrderRequest  (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 updateOrderAsync(String id, UpdateOrderRequest updateOrderRequest, 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 = updateOrderValidateBeforeCall(id, updateOrderRequest, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy