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

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

There is a newer version: 8.1.1
Show newest version
package com.wallee.sdk.service;

import com.wallee.sdk.ApiClient;
import com.wallee.sdk.ErrorCode;
import com.wallee.sdk.WalleeSdkException;
import com.wallee.sdk.URIBuilderUtil;

import com.wallee.sdk.model.ClientError;
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;


public class TransactionMobileSdkService {
    private ApiClient apiClient;

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

    public ApiClient getApiClient() {
        return apiClient;
    }

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

  /**
    * Build Mobile SDK URL
    
    * This operation builds the URL which is used to load the payment form within a WebView on a mobile device. This operation is typically called through the mobile SDK.
    * 

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

409 - This status code indicates that there was a conflict with the current version of the data in the database and the provided data in the request. *

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 credentials The credentials identifies the transaction and contains the security details which grants the access this operation. * @return String * @throws IOException if an error occurs while attempting to invoke the API * For more information visit this link. * @see Build Mobile SDK URL Documentation **/ public String paymentFormUrl(String credentials) throws IOException { HttpResponse response = paymentFormUrlForHttpResponse(credentials); String returnType = "String"; if(returnType.equals("String")){ return (String) (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 (String)apiClient.getObjectMapper().readValue(response.getContent(), typeRef); } /** * Build Mobile SDK URL * This operation builds the URL which is used to load the payment form within a WebView on a mobile device. This operation is typically called through the mobile SDK. *

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

409 - This status code indicates that there was a conflict with the current version of the data in the database and the provided data in the request. *

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 credentials The credentials identifies the transaction and contains the security details which grants the access this operation. * @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param. * @return String * @throws IOException if an error occurs while attempting to invoke the API * For more information visit this link. * @see Build Mobile SDK URL Documentation **/ public String paymentFormUrl(String credentials, Map params) throws IOException { HttpResponse response = paymentFormUrlForHttpResponse(credentials, params); String returnType = "String"; if(returnType.equals("String")){ return (String) (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 (String)apiClient.getObjectMapper().readValue(response.getContent(), typeRef); } public HttpResponse paymentFormUrlForHttpResponse(String credentials) throws IOException { // verify the required parameter 'credentials' is set if (credentials == null) { throw new IllegalArgumentException("Missing the required parameter 'credentials' when calling paymentFormUrl"); } URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/transaction-mobile-sdk/payment-form-url"); if (credentials != null) { String key = "credentials"; Object value = credentials; uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value); } GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder)); HttpContent content = null; HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content); int readTimeOut = apiClient.getReadTimeOut() * 1000; httpRequest.setReadTimeout(readTimeOut); return httpRequest.execute(); } public HttpResponse paymentFormUrlForHttpResponse(String credentials, Map params) throws IOException { // verify the required parameter 'credentials' is set if (credentials == null) { throw new IllegalArgumentException("Missing the required parameter 'credentials' when calling paymentFormUrl"); } URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/transaction-mobile-sdk/payment-form-url"); // 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 'credentials' to the map of query params allParams.put("credentials", credentials); 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 = null; HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, 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 - 2024 Weber Informatics LLC | Privacy Policy