Search in sources :

Example 1 with BasicPaymentProductGroupsAsyncTask

use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask in project connect-sdk-client-android by Ingenico-ePayments.

the class GcSession method getBasicPaymentProductGroups.

/**
 * Gets BasicPaymentProducts for the given PaymentRequest
 *
 * @param context, used for reading device metada which is send to the GC gateway
 * @param paymentContext, C2sPaymentProductContext which contains all neccesary data for doing call to the GC gateway to retrieve paymentproducts
 * @param listener, OnPaymentProductsCallComplete which will be called by the BasicPaymentProductsAsyncTask when the BasicPaymentProducts are loaded
 */
public void getBasicPaymentProductGroups(Context context, PaymentContext paymentContext, OnBasicPaymentProductGroupsCallCompleteListener listener) {
    if (context == null) {
        throw new InvalidParameterException("Error getting paymentProductGroups, context may not be null");
    }
    if (paymentContext == null) {
        throw new InvalidParameterException("Error getting paymentProductGroups, paymentContext may not be null");
    }
    if (listener == null) {
        throw new InvalidParameterException("Error getting paymentProductGroups, listener may not be null");
    }
    this.paymentContext = paymentContext;
    // Add OnBasicPaymentProductGroupsCallCompleteListener and this class to list of listeners so we can store the paymentProductGroups here
    List<OnBasicPaymentProductGroupsCallCompleteListener> listeners = new ArrayList<>();
    listeners.add(this);
    listeners.add(listener);
    // Start the task which gets paymentproducts
    BasicPaymentProductGroupsAsyncTask task = new BasicPaymentProductGroupsAsyncTask(context, paymentContext, communicator, listeners);
    task.execute();
}
Also used : InvalidParameterException(java.security.InvalidParameterException) OnBasicPaymentProductGroupsCallCompleteListener(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener) ArrayList(java.util.ArrayList) BasicPaymentProductGroupsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask)

Example 2 with BasicPaymentProductGroupsAsyncTask

use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask 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 3 with BasicPaymentProductGroupsAsyncTask

use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask 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 4 with BasicPaymentProductGroupsAsyncTask

use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask 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)

Aggregations

BasicPaymentProductGroupsAsyncTask (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask)4 ArrayList (java.util.ArrayList)4 BasicPaymentProductGroups (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 OnBasicPaymentProductGroupsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener)1 InvalidParameterException (java.security.InvalidParameterException)1