Search in sources :

Example 1 with BasicPaymentProductsAsyncTask

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

the class GetBasicPaymentProductsAsyncTaskTest method testGetBasicPaymentProductsAsyncTaskWithInvalidRequest.

/**
 * Test that an invalid request for BasicPaymentProducts will still return, but will not retrieve PaymentProducts
 */
@Test
public void testGetBasicPaymentProductsAsyncTaskWithInvalidRequest() throws InterruptedException {
    initializeInValidMocksAndSession();
    final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
    // Create the BasicPaymentProductsAsyncTask and then begin the test by calling execute.
    List<BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener> listeners = new ArrayList<>();
    Listener listener = new Listener(waitForAsyncCallBack);
    listeners.add(listener);
    BasicPaymentProductsAsyncTask basicPaymentProductsAsyncTask = new BasicPaymentProductsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
    basicPaymentProductsAsyncTask.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
    BasicPaymentProducts basicPaymentProducts = listener.getBasicPaymentProducts();
    assertNull(basicPaymentProducts);
}
Also used : ArrayList(java.util.ArrayList) BasicPaymentProductsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts) Test(org.junit.Test)

Example 2 with BasicPaymentProductsAsyncTask

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

the class GetBasicPaymentProductsAsyncTaskTest method testGetBasicPaymentProductsAsyncTaskWithValidRequest.

/**
 * Test that BasicPaymentProducts can be successfully retrieved and have the minimal fields
 */
@Test
public void testGetBasicPaymentProductsAsyncTaskWithValidRequest() throws InterruptedException, CommunicationException {
    initializeValidMocksAndSession();
    final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
    // Create the BasicPaymentProductsAsyncTask and then begin the test by calling execute.
    List<BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener> listeners = new ArrayList<>(1);
    Listener listener = new Listener(waitForAsyncCallBack);
    listeners.add(listener);
    BasicPaymentProductsAsyncTask basicPaymentProductsAsyncTask = new BasicPaymentProductsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
    basicPaymentProductsAsyncTask.execute();
    // Test that the response 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
    BasicPaymentProducts basicPaymentProducts = listener.getBasicPaymentProducts();
    validateBasicPaymentProductsList(basicPaymentProducts);
    // Validate that the first paymentProduct in the returned list has the required fields
    validateBasicPaymentProduct(basicPaymentProducts.getBasicPaymentProducts().get(0));
}
Also used : ArrayList(java.util.ArrayList) BasicPaymentProductsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts) Test(org.junit.Test)

Example 3 with BasicPaymentProductsAsyncTask

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

the class GetBasicPaymentProductsAsyncTaskTest method testGetBasicPaymentProductsAsyncTaskWithValidRequestAndAccountsOnFile.

/**
 * Test that BasicPaymentProducts can be successfully retrieved including AccountOnFiles and that they both have the minimal fields
 */
@Test
public void testGetBasicPaymentProductsAsyncTaskWithValidRequestAndAccountsOnFile() throws InterruptedException, CommunicationException {
    try {
        initializeValidMocksAndSessionWithToken();
        final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
        // Create the BasicPaymentProductsAsyncTask and then begin the test by calling execute.
        List<BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener> listeners = new ArrayList<>();
        Listener listener = new Listener(waitForAsyncCallBack);
        listeners.add(listener);
        BasicPaymentProductsAsyncTask basicPaymentProductsAsyncTask = new BasicPaymentProductsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
        basicPaymentProductsAsyncTask.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
        BasicPaymentProducts basicPaymentProducts = listener.getBasicPaymentProducts();
        validateBasicPaymentProductsList(basicPaymentProducts);
        // Test that the first paymentProduct in the returned list has the required fields
        validateBasicPaymentProduct(basicPaymentProducts.getBasicPaymentProducts().get(0));
        validateAccountOnFile(basicPaymentProducts);
    } finally {
        deleteToken();
    }
}
Also used : ArrayList(java.util.ArrayList) BasicPaymentProductsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts) Test(org.junit.Test)

Example 4 with BasicPaymentProductsAsyncTask

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

the class GcSession method getBasicPaymentProducts.

/**
 * Gets BasicPaymentProducts for the given PaymentRequest
 *
 * @param context, used for reading device metadata which is send to the GC gateway
 * @param paymentContext, PaymentContext 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 getBasicPaymentProducts(Context context, PaymentContext paymentContext, OnBasicPaymentProductsCallCompleteListener listener) {
    if (context == null) {
        throw new InvalidParameterException("Error getting paymentproduct, context may not be null");
    }
    if (paymentContext == null) {
        throw new InvalidParameterException("Error getting paymentproducts, paymentContext may not be null");
    }
    if (listener == null) {
        throw new InvalidParameterException("Error getting paymentproducts, listener may not be null");
    }
    this.paymentContext = paymentContext;
    // Add OnBasicPaymentProductsCallCompleteListener and this class to list of listeners so we can store the paymentproducts here
    List<OnBasicPaymentProductsCallCompleteListener> listeners = new ArrayList<OnBasicPaymentProductsCallCompleteListener>();
    listeners.add(this);
    listeners.add(listener);
    // Start the task which gets paymentproducts
    BasicPaymentProductsAsyncTask task = new BasicPaymentProductsAsyncTask(context, paymentContext, communicator, listeners);
    task.execute();
}
Also used : InvalidParameterException(java.security.InvalidParameterException) OnBasicPaymentProductsCallCompleteListener(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener) ArrayList(java.util.ArrayList) BasicPaymentProductsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask)

Aggregations

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