use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems in project connect-sdk-client-android by Ingenico-ePayments.
the class GetBasicPaymentItemsAsyncTaskTest method testGetBasicPaymentItemsAsyncTaskWithGroupingAndAccountsOnFile.
/**
* Test that BasicPaymentItems can be successfully retrieved as well as AccountsOnFile
* Also test that the response contains products as well as groups
*/
@Test
public void testGetBasicPaymentItemsAsyncTaskWithGroupingAndAccountsOnFile() throws InterruptedException, CommunicationException {
try {
initializeValidMocksAndSessionWithToken();
final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
// Create the BasicPaymentItemsAsyncTask and then begin the test by calling execute.
List<BasicPaymentItemsAsyncTask.OnBasicPaymentItemsCallCompleteListener> listeners = new ArrayList<>();
Listener listener = new Listener(waitForAsyncCallBack);
listeners.add(listener);
BasicPaymentItemsAsyncTask basicPaymentItemsAsyncTask = new BasicPaymentItemsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners, true);
basicPaymentItemsAsyncTask.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 test that it has the correct fields
BasicPaymentItems basicPaymentItems = listener.getBasicPaymentItems();
// Validate the returned object
validateBasicPaymentItemsList(basicPaymentItems);
validateProductsAndGroups(basicPaymentItems);
validateAccountOnFile(basicPaymentItems);
} finally {
deleteToken();
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems 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