Search in sources :

Example 1 with OnBasicPaymentProductGroupsCallCompleteListener

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

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

OnBasicPaymentProductGroupsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener)2 InvalidParameterException (java.security.InvalidParameterException)2 BasicPaymentProductGroupsAsyncTask (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask)1 OnBasicPaymentProductsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener)1 BasicPaymentItems (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems)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 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1