use of com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsResponse 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());
}
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsResponse in project connect-sdk-client-android by Ingenico-ePayments.
the class CustomerDetailsAsyncTaskTest method testCustomerDetailsAsyncTaskWithValidRequest.
@Test
public void testCustomerDetailsAsyncTaskWithValidRequest() throws InterruptedException, CommunicationException {
initializeValidMocksAndSession();
final CountDownLatch waitForAsyncTaskCallBack = new CountDownLatch(1);
Listener listener = new Listener(waitForAsyncTaskCallBack);
KeyValuePair keyValuePair = new KeyValuePair();
keyValuePair.setKey("fiscalNumber");
keyValuePair.setValue("4605092222");
List<KeyValuePair> values = new ArrayList<>();
values.add(keyValuePair);
// Create the CustomerDetailsAsyncTask and start the test by running execute
CustomerDetailsAsyncTask customerDetailsAsyncTask = new CustomerDetailsAsyncTask(getContext(), "9000", CountryCode.SE, values, getCommunicator(), listener);
customerDetailsAsyncTask.execute();
// Test that the getCustomerDetails call returns within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds
assertTrue(waitForAsyncTaskCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
// Retrieve the customer details response from the listener
CustomerDetailsResponse customerDetailsResponse = listener.getCustomerDetailsResponse();
assertNotNull(customerDetailsResponse);
assertEquals(customerDetailsResponse.getCountry(), "Sweden");
}
Aggregations