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

com.wallee.sdk.service.InstallmentPlanCalculationService Maven / Gradle / Ivy

The newest version!
package com.wallee.sdk.service;

import static com.wallee.sdk.ErrorCode.*;

import com.wallee.sdk.ApiClient;
import com.wallee.sdk.ErrorCode;
import com.wallee.sdk.exception.WalleeSdkException;
import com.wallee.sdk.util.URIBuilderUtil;
import com.wallee.sdk.StringUtil;

import com.wallee.sdk.model.ClientError;
import com.wallee.sdk.model.InstallmentCalculatedPlan;
import com.wallee.sdk.model.ServerError;


import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.http.*;
import com.google.api.client.json.Json;

import org.apache.http.client.utils.URIBuilder;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.Objects;



public class InstallmentPlanCalculationService {
    private ApiClient apiClient;

    public InstallmentPlanCalculationService(ApiClient apiClient) {
        this.apiClient = Objects.requireNonNull(apiClient, "ApiClient must be non null");
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = Objects.requireNonNull(apiClient, "ApiClient must be non null");
    }

  /**
    * Calculate Plans
    
    * This operation allows to calculate all plans for the given transaction. The transaction will not be changed in any way.
    * 

200 - This status code indicates that a client request was successfully received, understood, and accepted. *

442 - This status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error. *

542 - This status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the client request. * @param spaceId * @param transactionId The transaction for which the plans should be calculated for. * @return List<InstallmentCalculatedPlan> * @throws IOException if an error occurs while attempting to invoke the API * For more information visit this link. * @see Calculate Plans Documentation **/ public List calculatePlans(Long spaceId, Long transactionId) throws IOException { HttpResponse response = calculatePlansForHttpResponse(spaceId, transactionId); String returnType = "List<InstallmentCalculatedPlan>"; if(returnType.equals("String")){ return (List) (Object) response.parseAsString(); } TypeReference typeRef = new TypeReference>() {}; if (isNoBodyResponse(response)) { throw new WalleeSdkException(ErrorCode.ENTITY_NOT_FOUND, "Entity was not found for: " + typeRef.getType().getTypeName()); } return (List)apiClient.getObjectMapper().readValue(response.getContent(), typeRef); } /** * Calculate Plans * This operation allows to calculate all plans for the given transaction. The transaction will not be changed in any way. *

200 - This status code indicates that a client request was successfully received, understood, and accepted. *

442 - This status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error. *

542 - This status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the client request. * @param spaceId * @param transactionId The transaction for which the plans should be calculated for. * @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param. * @return List<InstallmentCalculatedPlan> * @throws IOException if an error occurs while attempting to invoke the API * For more information visit this link. * @see Calculate Plans Documentation **/ public List calculatePlans(Long spaceId, Long transactionId, Map params) throws IOException { HttpResponse response = calculatePlansForHttpResponse(spaceId, transactionId, params); String returnType = "List<InstallmentCalculatedPlan>"; if(returnType.equals("String")){ return (List) (Object) response.parseAsString(); } TypeReference typeRef = new TypeReference>() {}; if (isNoBodyResponse(response)) { throw new WalleeSdkException(ErrorCode.ENTITY_NOT_FOUND, "Entity was not found for: " + typeRef.getType().getTypeName()); } return (List)apiClient.getObjectMapper().readValue(response.getContent(), typeRef); } public HttpResponse calculatePlansForHttpResponse(Long spaceId, Long transactionId) throws IOException { // verify the required parameter 'spaceId' is set if (spaceId == null) { throw new IllegalArgumentException("Missing the required parameter 'spaceId' when calling calculatePlans"); } // verify the required parameter 'transactionId' is set if (transactionId == null) { throw new IllegalArgumentException("Missing the required parameter 'transactionId' when calling calculatePlans"); } URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/installment-plan-calculation/calculatePlans"); if (spaceId != null) { String key = "spaceId"; Object value = spaceId; uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value); } if (transactionId != null) { String key = "transactionId"; Object value = transactionId; uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value); } GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder)); HttpContent content = apiClient.new JacksonJsonHttpContent(null); HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content); int readTimeOut = apiClient.getReadTimeOut() * 1000; httpRequest.setReadTimeout(readTimeOut); return httpRequest.execute(); } public HttpResponse calculatePlansForHttpResponse(Long spaceId, Long transactionId, Map params) throws IOException { // verify the required parameter 'spaceId' is set if (spaceId == null) { throw new IllegalArgumentException("Missing the required parameter 'spaceId' when calling calculatePlans"); } // verify the required parameter 'transactionId' is set if (transactionId == null) { throw new IllegalArgumentException("Missing the required parameter 'transactionId' when calling calculatePlans"); } URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/installment-plan-calculation/calculatePlans"); // Copy the params argument if present, to allow passing in immutable maps Map allParams = params == null ? new HashMap() : new HashMap(params); // Add the required query param 'spaceId' to the map of query params allParams.put("spaceId", spaceId); // Add the required query param 'transactionId' to the map of query params allParams.put("transactionId", transactionId); for (Map.Entry entryMap: allParams.entrySet()) { String key = entryMap.getKey(); Object value = entryMap.getValue(); if (key != null && value != null) { uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value); } } GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder)); HttpContent content = apiClient.new JacksonJsonHttpContent(null); HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content); int readTimeOut = apiClient.getReadTimeOut() * 1000; httpRequest.setReadTimeout(readTimeOut); return httpRequest.execute(); } private boolean isNoBodyResponse(HttpResponse response) throws IOException { java.io.InputStream content = response.getContent(); return content.available() == 0; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy