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