Search in sources :

Example 1 with CustomerDetailsRequest

use of com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsRequest in project connect-sdk-client-android by Ingenico-ePayments.

the class C2sCommunicator method getCustomerDetails.

public CustomerDetailsResponse getCustomerDetails(String productId, CountryCode countryCode, List<KeyValuePair> values, Context context) {
    if (productId == null) {
        throw new InvalidParameterException("Error getting CustomerDetails, productId may not be null");
    }
    if (countryCode == null) {
        throw new InvalidParameterException("Error getting CustomerDetails, countryCode may not be null");
    }
    if (values == null) {
        throw new InvalidParameterException("Error getting CustomerDetails, values may not be null");
    }
    HttpURLConnection connection = null;
    try {
        // Construct the url for the getCustomerDetailsCall
        String paymentProductPath = Constants.GC_GATEWAY_CUSTOMERDETAILS_PATH.replace("[cid]", configuration.getCustomerId()).replace("[pid]", productId);
        String url = configuration.getBaseUrl() + paymentProductPath;
        // Serialise the getCustomerDetailsRequest to json, so it can be added to the postbody
        CustomerDetailsRequest customerDetailsRequest = new CustomerDetailsRequest(countryCode, values);
        String customerDetailsRequestJson = gson.toJson(customerDetailsRequest);
        // Do the call and deserialize the result to IinDetailsResponse
        connection = doHTTPPostRequest(url, configuration.getClientSessionId(), configuration.getMetadata(context), customerDetailsRequestJson);
        String responseBody = new Scanner(connection.getInputStream(), "UTF-8").useDelimiter("\\A").next();
        // Log the response
        if (Constants.ENABLE_REQUEST_LOGGING) {
            logResponse(connection, responseBody);
        }
        CustomerDetailsResponse customerDetailsResponse = gson.fromJson(responseBody, CustomerDetailsResponse.class);
        return customerDetailsResponse;
    } catch (CommunicationException e) {
        Log.i(TAG, "Error while getting customer details:" + e.getMessage());
        return null;
    } catch (Exception e) {
        Log.i(TAG, "Error while getting customer details:" + e.getMessage());
        return null;
    } finally {
        try {
            if (connection != null) {
                connection.getInputStream().close();
                connection.disconnect();
            }
        } catch (IOException e) {
            Log.i(TAG, "Error while getting customer details:" + e.getMessage());
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Scanner(java.util.Scanner) HttpURLConnection(java.net.HttpURLConnection) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) IOException(java.io.IOException) CustomerDetailsResponse(com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsResponse) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) InvalidParameterException(java.security.InvalidParameterException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CustomerDetailsRequest(com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsRequest)

Aggregations

CommunicationException (com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException)1 CustomerDetailsRequest (com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsRequest)1 CustomerDetailsResponse (com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsResponse)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 InvalidParameterException (java.security.InvalidParameterException)1 Scanner (java.util.Scanner)1