Search in sources :

Example 1 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 testGetBasicPaymentItemsAsyncTaskWithoutGroupingWithAccountOnFile.

/**
 * Test that BasicPaymentItems can be successfully retrieved, not containing groups.
 * Also test that an account on file is returned
 */
@Test
public void testGetBasicPaymentItemsAsyncTaskWithoutGroupingWithAccountOnFile() 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, false);
        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 validate that it has the correct fields
        BasicPaymentItems basicPaymentItems = listener.getBasicPaymentItems();
        // Validate the returned object
        validateBasicPaymentItemsList(basicPaymentItems);
        validateOnlyProducts(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 2 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 testGetBasicPaymentItemsAsyncTaskWithoutGrouping.

/**
 * Test that BasicPaymentItems can be successfully retrieved, not containing groups.
 */
@Test
public void testGetBasicPaymentItemsAsyncTaskWithoutGrouping() throws InterruptedException, CommunicationException {
    initializeValidMocksAndSession();
    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, false);
    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 validate that it has the correct fields
    BasicPaymentItems basicPaymentItems = listener.getBasicPaymentItems();
    // Validate the returned object
    validateBasicPaymentItemsList(basicPaymentItems);
    validateOnlyProducts(basicPaymentItems);
}
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 3 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 createBasicPaymentItems.

private BasicPaymentItems createBasicPaymentItems(BasicPaymentProducts basicPaymentProducts, BasicPaymentProductGroups basicPaymentProductGroups) {
    // Validate the results of the calls
    if (basicPaymentProducts == null && basicPaymentProductGroups == null) {
        // If both basicPaymentProducts and basicPaymentProductGroups are null, return nul
        return null;
    } else if (basicPaymentProductGroups == null) {
        // If basicPaymentProductGroups == null, return just the basicPaymentProducts
        return new BasicPaymentItems(basicPaymentProducts.getPaymentProductsAsItems(), basicPaymentProducts.getAccountsOnFile());
    } else if (basicPaymentProducts == null) {
        // If basicPaymentProducts == null, return just the basicPaymentProductGroups
        return new BasicPaymentItems(basicPaymentProductGroups.getPaymentProductGroupsAsItems(), basicPaymentProductGroups.getAccountsOnFile());
    }
    // Else: Merge the paymentItems together.
    // Create a list of PaymentProductSelectables that will be filled and stored in the basicPaymentItems object that is returned
    List<BasicPaymentItem> basicPaymentItems = new ArrayList<>();
    // Create a list of AccountOnFiles that will be filled and stored in the basicPaymentItems object that is returned
    List<AccountOnFile> accountsOnFile = new LinkedList<>();
    // list of basicPaymentItems that will be returned.
    for (BasicPaymentProduct paymentProduct : basicPaymentProducts.getBasicPaymentProducts()) {
        // Add the accountsOnFile of the current paymentProduct to the collection of accountOnFiles.
        accountsOnFile.addAll(paymentProduct.getAccountsOnFile());
        // becomes true if the paymentProduct has been matched with a group.
        boolean groupMatch = false;
        for (BasicPaymentProductGroup paymentProductGroup : basicPaymentProductGroups.getBasicPaymentProductGroups()) {
            // Does the current paymentProduct belong to the current paymentProductGroup
            if (paymentProduct.getPaymentProductGroup() != null && paymentProduct.getPaymentProductGroup().equals(paymentProductGroup.getId())) {
                // Add the paymentProductGroup to the basicPaymentItems that will be returned if it is not already in the list
                if (!basicPaymentItems.contains(paymentProductGroup)) {
                    // Set the displayOrder of the group to the displayOrder of the first paymentProduct match
                    paymentProductGroup.getDisplayHints().setDisplayOrder(paymentProduct.getDisplayHints().getDisplayOrder());
                    basicPaymentItems.add(paymentProductGroup);
                }
                // Product has been matched to a group
                groupMatch = true;
                // Products can not match with more then one group
                break;
            }
        }
        if (!groupMatch) {
            // If the paymentProduct does not belong to a paymentProductGroup, add the paymentProduct to the
            // basicPaymentItems that will be returned
            basicPaymentItems.add(paymentProduct);
        }
    }
    // Return a new BasicPaymentItems object that contains the paymentItems and the accountsOnFile
    return new BasicPaymentItems(basicPaymentItems, accountsOnFile);
}
Also used : BasicPaymentItems(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems) AccountOnFile(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile) BasicPaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup) ArrayList(java.util.ArrayList) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) LinkedList(java.util.LinkedList) BasicPaymentItem(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem)

Example 4 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 testGetBasicPaymentItemsAsyncTaskWithGrouping.

/**
 * Test that BasicPaymentItems can be successfully retrieved
 * Also test that the response contains products as well as groups
 */
@Test
public void testGetBasicPaymentItemsAsyncTaskWithGrouping() throws InterruptedException, CommunicationException {
    initializeValidMocksAndSession();
    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 validate that it has the correct fields
    BasicPaymentItems basicPaymentItems = listener.getBasicPaymentItems();
    // Validate the returned object
    validateBasicPaymentItemsList(basicPaymentItems);
    validateProductsAndGroups(basicPaymentItems);
}
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 5 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 testGetBasicPaymentItemsAsyncTaskWithInvalidRequest.

/**
 * Test that an invalid request for BasicPaymentProducts will still return, but will not retrieve PaymentItems
 */
@Test
public void testGetBasicPaymentItemsAsyncTaskWithInvalidRequest() throws InterruptedException {
    initializeInValidMocksAndSession();
    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 validate that it is indeed null
    BasicPaymentItems basicPaymentItems = listener.getBasicPaymentItems();
    assertNull(basicPaymentItems);
}
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)

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