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;
}
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();
}
Aggregations