Search in sources :

Example 1 with BasicPaymentProductGroups

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

the class GetBasicPaymentProductGroupsAsyncTaskTest method testGetBasicPaymentProductGroupsAsyncTaskWithValidRequestWithAccountOnFile.

/**
 * Test that BasicPaymentProductGroups can be successfully retrieved by doing the required call
 */
@Test
public // Test that BasicPaymentProductGroups can be successfully retrieved by doing the required call
void testGetBasicPaymentProductGroupsAsyncTaskWithValidRequestWithAccountOnFile() throws InterruptedException, CommunicationException {
    try {
        initializeValidMocksAndSessionWithToken();
        final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
        // Create the BasicPaymentProductGroupsAsyncTask and then begin the test by calling execute.
        List<BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener> listeners = new ArrayList<>();
        Listener listener = new Listener(waitForAsyncCallBack);
        listeners.add(listener);
        BasicPaymentProductGroupsAsyncTask basicPaymentProductGroupsAsyncTask = new BasicPaymentProductGroupsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
        basicPaymentProductGroupsAsyncTask.execute();
        // Test that the request for the call is received within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds.
        assertTrue(waitForAsyncCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
        // Retrieve the response from the callback and validate that it has the correct fields
        BasicPaymentProductGroups basicPaymentProductGroups = listener.getBasicPaymentProductGroups();
        validateBasicPaymentProductGroupsList(basicPaymentProductGroups);
        // Validate that the first paymentProductGroup in the returned list has the required fields
        validateBasicPaymentProductGroup(basicPaymentProductGroups.getBasicPaymentProductGroups().get(0));
        validateAccountOnFile(basicPaymentProductGroups);
    } finally {
        deleteToken();
    }
}
Also used : BasicPaymentProductGroups(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups) ArrayList(java.util.ArrayList) BasicPaymentProductGroupsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with BasicPaymentProductGroups

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

the class GetBasicPaymentProductGroupsAsyncTaskTest method testGetBasicPaymentProductGroupsAsyncTaskWithInvalidRequest.

/**
 * Test that an invalid request for BasicPaymentProductGroups will still return, but will not retrieve PaymentProductGroups
 */
@Test
public void testGetBasicPaymentProductGroupsAsyncTaskWithInvalidRequest() throws InterruptedException {
    initializeInValidMocksAndSession();
    final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
    // Create the BasicPaymentProductsAsyncTask and then begin the test by calling execute.
    List<BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener> listeners = new ArrayList<>();
    Listener listener = new Listener(waitForAsyncCallBack);
    listeners.add(listener);
    BasicPaymentProductGroupsAsyncTask basicPaymentProductGroupsAsyncTask = new BasicPaymentProductGroupsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
    basicPaymentProductGroupsAsyncTask.execute();
    // Test that the request for the call is received within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds.
    assertTrue(waitForAsyncCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
    // Retrieve the response from the callback and validate that it is indeed null
    BasicPaymentProductGroups basicPaymentProductGroups = listener.getBasicPaymentProductGroups();
    assertNull(basicPaymentProductGroups);
}
Also used : BasicPaymentProductGroups(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups) ArrayList(java.util.ArrayList) BasicPaymentProductGroupsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with BasicPaymentProductGroups

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

the class GetBasicPaymentProductGroupsAsyncTaskTest method testGetBasicPaymentProductGroupsAsyncTaskWithValidRequest.

/**
 * Test that BasicPaymentProductGroups can be successfully retrieved by doing the required call
 */
@Test
public // Test that BasicPaymentProductGroups can be successfully retrieved by doing the required call
void testGetBasicPaymentProductGroupsAsyncTaskWithValidRequest() throws InterruptedException, CommunicationException {
    initializeValidMocksAndSession();
    final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
    // Create the BasicPaymentProductGroupsAsyncTask and then begin the test by calling execute.
    List<BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener> listeners = new ArrayList<>();
    Listener listener = new Listener(waitForAsyncCallBack);
    listeners.add(listener);
    BasicPaymentProductGroupsAsyncTask basicPaymentProductGroupsAsyncTask = new BasicPaymentProductGroupsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
    basicPaymentProductGroupsAsyncTask.execute();
    // Test that the request for the call is received within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds.
    assertTrue(waitForAsyncCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
    // Retrieve the response from the callback and validate that it has the correct fields
    BasicPaymentProductGroups basicPaymentProductGroups = listener.getBasicPaymentProductGroups();
    validateBasicPaymentProductGroupsList(basicPaymentProductGroups);
    // Validate that the first paymentProductGroup in the returned list has the required fields
    validateBasicPaymentProductGroup(basicPaymentProductGroups.getBasicPaymentProductGroups().get(0));
}
Also used : BasicPaymentProductGroups(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups) ArrayList(java.util.ArrayList) BasicPaymentProductGroupsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with BasicPaymentProductGroups

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

the class BasicPaymentItemsAsyncTask method doInBackground.

@Override
protected BasicPaymentItems doInBackground(String... params) {
    // Check whether the paymentProducts will be shown in groups
    if (groupPaymentItems) {
        // Create a threadpool that will execute the tasks of getting the paymentproducts and the paymentproductgroups
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        // Create the callables that will be executed
        Callable<BasicPaymentProducts> paymentProductsCallable = new BasicPaymentProductsAsyncTask(context, paymentContext, communicator, new LinkedList<OnBasicPaymentProductsCallCompleteListener>());
        Callable<BasicPaymentProductGroups> paymentProductGroupsCallable = new BasicPaymentProductGroupsAsyncTask(context, paymentContext, communicator, new LinkedList<OnBasicPaymentProductGroupsCallCompleteListener>());
        // Retrieve the futures from the callable tasks
        Future<BasicPaymentProducts> paymentProductsFuture = executorService.submit(paymentProductsCallable);
        Future<BasicPaymentProductGroups> paymentProductGroupsFuture = executorService.submit(paymentProductGroupsCallable);
        try {
            // Retrieve the basicPaymentProducts and basicPaymentProductGroups from the futures
            BasicPaymentProducts basicPaymentProducts = paymentProductsFuture.get();
            BasicPaymentProductGroups basicPaymentProductGroups = paymentProductGroupsFuture.get();
            // Return a list of the basicPaymentProducts and basicPaymentProductGroups combined
            return createBasicPaymentItems(basicPaymentProducts, basicPaymentProductGroups);
        } catch (InterruptedException e) {
            Log.i(TAG, "Error while getting paymentItems: " + e.getMessage());
            e.printStackTrace();
        } catch (ExecutionException e) {
            Log.i(TAG, "Error while getting paymentItems: " + e.getMessage());
            e.printStackTrace();
        }
    } else {
        // Create the paymentProductsCallable
        Callable<BasicPaymentProducts> paymentProductsCallable = new BasicPaymentProductsAsyncTask(context, paymentContext, communicator, new LinkedList<OnBasicPaymentProductsCallCompleteListener>());
        try {
            // Retrieve the basicPaymentProducts
            BasicPaymentProducts basicPaymentProducts = paymentProductsCallable.call();
            return new BasicPaymentItems(basicPaymentProducts.getPaymentProductsAsItems(), basicPaymentProducts.getAccountsOnFile());
        } catch (Exception e) {
            Log.i(TAG, "Error while getting paymentItems: " + e.getMessage());
            e.printStackTrace();
        }
    }
    // If an error occurred no valid paymentItems can be returned
    return null;
}
Also used : BasicPaymentProductGroups(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups) OnBasicPaymentProductGroupsCallCompleteListener(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener) OnBasicPaymentProductsCallCompleteListener(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener) ExecutionException(java.util.concurrent.ExecutionException) InvalidParameterException(java.security.InvalidParameterException) BasicPaymentItems(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts)

Example 5 with BasicPaymentProductGroups

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

the class C2sCommunicator method getBasicPaymentProductGroups.

/**
 * Retrieves a list of basicpaymentproductgroups from the GC gateway without any fields
 *
 * @param context, used for reading device metadata which is send to the GC gateway
 * @param paymentContext, used to retrieve the correct productGroups from the GC gateway
 *
 * @return list of BasicPaymentProducts, or null when an error has occured
 */
public BasicPaymentProductGroups getBasicPaymentProductGroups(PaymentContext paymentContext, Context context) {
    if (paymentContext == null) {
        throw new InvalidParameterException("Error getting BasicPaymentProductGroups, request may not be null");
    }
    HttpURLConnection connection = null;
    try {
        // Build the complete url which is called
        String baseUrl = configuration.getBaseUrl();
        String paymentProductGroupsPath = Constants.GC_GATEWAY_RETRIEVE_PAYMENTPRODUCTGROUPS_PATH.replace("[cid]", configuration.getCustomerId());
        String completePath = baseUrl + paymentProductGroupsPath;
        // Add query parameters
        StringBuilder queryString = new StringBuilder();
        queryString.append("?countryCode=").append(paymentContext.getCountryCode());
        queryString.append("&amount=").append(paymentContext.getAmountOfMoney().getAmount());
        queryString.append("&isRecurring=").append(paymentContext.isRecurring());
        queryString.append("&currencyCode=").append(paymentContext.getAmountOfMoney().getCurrencyCode());
        queryString.append("&hide=fields");
        queryString.append("&").append(createCacheBusterParameter());
        // Add query string to complete path
        completePath += queryString.toString();
        // Do the call and deserialise the result to BasicPaymentProducts
        connection = doHTTPGetRequest(completePath, configuration.getClientSessionId(), configuration.getMetadata(context));
        String responseBody = new Scanner(connection.getInputStream(), "UTF-8").useDelimiter("\\A").next();
        // Log the response
        if (Constants.ENABLE_REQUEST_LOGGING) {
            logResponse(connection, responseBody);
        }
        BasicPaymentProductGroups basicPaymentProductGroups = gson.fromJson(responseBody, BasicPaymentProductGroups.class);
        // Set the logos for all BasicPaymentProductGroups
        for (BasicPaymentProductGroup paymentProductGroup : basicPaymentProductGroups.getBasicPaymentProductGroups()) {
            AssetManager manager = AssetManager.getInstance(context);
            Drawable logo = manager.getLogo(paymentProductGroup.getId());
            paymentProductGroup.getDisplayHints().setLogo(logo);
        }
        return basicPaymentProductGroups;
    } catch (CommunicationException e) {
        Log.i(TAG, "Error while getting paymentProductGroups:" + e.getMessage());
        return null;
    } catch (Exception e) {
        Log.i(TAG, "Error while getting paymentProductGroups:" + e.getMessage());
        return null;
    } finally {
        try {
            if (connection != null) {
                connection.getInputStream().close();
                connection.disconnect();
            }
        } catch (IOException e) {
            Log.i(TAG, "Error while getting paymentProductGroups:" + e.getMessage());
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Scanner(java.util.Scanner) HttpURLConnection(java.net.HttpURLConnection) BasicPaymentProductGroups(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups) AssetManager(com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) BasicPaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup) Drawable(android.graphics.drawable.Drawable) IOException(java.io.IOException) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) InvalidParameterException(java.security.InvalidParameterException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

BasicPaymentProductGroups (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups)5 BasicPaymentProductGroupsAsyncTask (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 InvalidParameterException (java.security.InvalidParameterException)2 Drawable (android.graphics.drawable.Drawable)1 OnBasicPaymentProductGroupsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener)1 OnBasicPaymentProductsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener)1 CommunicationException (com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException)1 AssetManager (com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager)1 BasicPaymentItems (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems)1 BasicPaymentProductGroup (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup)1 BasicPaymentProducts (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 Scanner (java.util.Scanner)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1