Search in sources :

Example 1 with OnBasicPaymentProductsCallCompleteListener

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

Example 2 with OnBasicPaymentProductsCallCompleteListener

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

OnBasicPaymentProductsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener)2 InvalidParameterException (java.security.InvalidParameterException)2 OnBasicPaymentProductGroupsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener)1 BasicPaymentProductsAsyncTask (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask)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