Search in sources :

Example 1 with CustomerDetailsResponse

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

Example 2 with CustomerDetailsResponse

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");
}
Also used : KeyValuePair(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair) ArrayList(java.util.ArrayList) CustomerDetailsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.CustomerDetailsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) CustomerDetailsResponse(com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsResponse) Test(org.junit.Test)

Aggregations

CustomerDetailsResponse (com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsResponse)2 CustomerDetailsAsyncTask (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.CustomerDetailsAsyncTask)1 CommunicationException (com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException)1 CustomerDetailsRequest (com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsRequest)1 KeyValuePair (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1 Scanner (java.util.Scanner)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1