Search in sources :

Example 6 with BasicPaymentItems

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

the class GetBasicPaymentItemsAsyncTaskTest method testGetBasicPaymentItemsAsyncTaskWithGroupingAndAccountsOnFile.

/**
 * Test that BasicPaymentItems can be successfully retrieved as well as AccountsOnFile
 * Also test that the response contains products as well as groups
 */
@Test
public void testGetBasicPaymentItemsAsyncTaskWithGroupingAndAccountsOnFile() throws InterruptedException, CommunicationException {
    try {
        initializeValidMocksAndSessionWithToken();
        final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
        // Create the BasicPaymentItemsAsyncTask and then begin the test by calling execute.
        List<BasicPaymentItemsAsyncTask.OnBasicPaymentItemsCallCompleteListener> listeners = new ArrayList<>();
        Listener listener = new Listener(waitForAsyncCallBack);
        listeners.add(listener);
        BasicPaymentItemsAsyncTask basicPaymentItemsAsyncTask = new BasicPaymentItemsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners, true);
        basicPaymentItemsAsyncTask.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 test that it has the correct fields
        BasicPaymentItems basicPaymentItems = listener.getBasicPaymentItems();
        // Validate the returned object
        validateBasicPaymentItemsList(basicPaymentItems);
        validateProductsAndGroups(basicPaymentItems);
        validateAccountOnFile(basicPaymentItems);
    } finally {
        deleteToken();
    }
}
Also used : BasicPaymentItems(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) BasicPaymentItemsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentItemsAsyncTask) Test(org.junit.Test)

Example 7 with BasicPaymentItems

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems 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)

Aggregations

BasicPaymentItems (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems)7 ArrayList (java.util.ArrayList)6 BasicPaymentItemsAsyncTask (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentItemsAsyncTask)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Test (org.junit.Test)5 OnBasicPaymentProductGroupsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener)1 OnBasicPaymentProductsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener)1 AccountOnFile (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile)1 BasicPaymentItem (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem)1 BasicPaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct)1 BasicPaymentProductGroup (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup)1 BasicPaymentProductGroups (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups)1 BasicPaymentProducts (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts)1 InvalidParameterException (java.security.InvalidParameterException)1 LinkedList (java.util.LinkedList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1