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());
}
}
}
Aggregations