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 testGetBasicPaymentItemsAsyncTaskWithoutGroupingWithAccountOnFile.
/**
* Test that BasicPaymentItems can be successfully retrieved, not containing groups.
* Also test that an account on file is returned
*/
@Test
public void testGetBasicPaymentItemsAsyncTaskWithoutGroupingWithAccountOnFile() 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, false);
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 validate that it has the correct fields
BasicPaymentItems basicPaymentItems = listener.getBasicPaymentItems();
// Validate the returned object
validateBasicPaymentItemsList(basicPaymentItems);
validateOnlyProducts(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 GetBasicPaymentItemsAsyncTaskTest method testGetBasicPaymentItemsAsyncTaskWithoutGrouping.
/**
* Test that BasicPaymentItems can be successfully retrieved, not containing groups.
*/
@Test
public void testGetBasicPaymentItemsAsyncTaskWithoutGrouping() throws InterruptedException, CommunicationException {
initializeValidMocksAndSession();
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, false);
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 validate that it has the correct fields
BasicPaymentItems basicPaymentItems = listener.getBasicPaymentItems();
// Validate the returned object
validateBasicPaymentItemsList(basicPaymentItems);
validateOnlyProducts(basicPaymentItems);
}
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 createBasicPaymentItems.
private BasicPaymentItems createBasicPaymentItems(BasicPaymentProducts basicPaymentProducts, BasicPaymentProductGroups basicPaymentProductGroups) {
// Validate the results of the calls
if (basicPaymentProducts == null && basicPaymentProductGroups == null) {
// If both basicPaymentProducts and basicPaymentProductGroups are null, return nul
return null;
} else if (basicPaymentProductGroups == null) {
// If basicPaymentProductGroups == null, return just the basicPaymentProducts
return new BasicPaymentItems(basicPaymentProducts.getPaymentProductsAsItems(), basicPaymentProducts.getAccountsOnFile());
} else if (basicPaymentProducts == null) {
// If basicPaymentProducts == null, return just the basicPaymentProductGroups
return new BasicPaymentItems(basicPaymentProductGroups.getPaymentProductGroupsAsItems(), basicPaymentProductGroups.getAccountsOnFile());
}
// Else: Merge the paymentItems together.
// Create a list of PaymentProductSelectables that will be filled and stored in the basicPaymentItems object that is returned
List<BasicPaymentItem> basicPaymentItems = new ArrayList<>();
// Create a list of AccountOnFiles that will be filled and stored in the basicPaymentItems object that is returned
List<AccountOnFile> accountsOnFile = new LinkedList<>();
// list of basicPaymentItems that will be returned.
for (BasicPaymentProduct paymentProduct : basicPaymentProducts.getBasicPaymentProducts()) {
// Add the accountsOnFile of the current paymentProduct to the collection of accountOnFiles.
accountsOnFile.addAll(paymentProduct.getAccountsOnFile());
// becomes true if the paymentProduct has been matched with a group.
boolean groupMatch = false;
for (BasicPaymentProductGroup paymentProductGroup : basicPaymentProductGroups.getBasicPaymentProductGroups()) {
// Does the current paymentProduct belong to the current paymentProductGroup
if (paymentProduct.getPaymentProductGroup() != null && paymentProduct.getPaymentProductGroup().equals(paymentProductGroup.getId())) {
// Add the paymentProductGroup to the basicPaymentItems that will be returned if it is not already in the list
if (!basicPaymentItems.contains(paymentProductGroup)) {
// Set the displayOrder of the group to the displayOrder of the first paymentProduct match
paymentProductGroup.getDisplayHints().setDisplayOrder(paymentProduct.getDisplayHints().getDisplayOrder());
basicPaymentItems.add(paymentProductGroup);
}
// Product has been matched to a group
groupMatch = true;
// Products can not match with more then one group
break;
}
}
if (!groupMatch) {
// If the paymentProduct does not belong to a paymentProductGroup, add the paymentProduct to the
// basicPaymentItems that will be returned
basicPaymentItems.add(paymentProduct);
}
}
// Return a new BasicPaymentItems object that contains the paymentItems and the accountsOnFile
return new BasicPaymentItems(basicPaymentItems, accountsOnFile);
}
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 testGetBasicPaymentItemsAsyncTaskWithGrouping.
/**
* Test that BasicPaymentItems can be successfully retrieved
* Also test that the response contains products as well as groups
*/
@Test
public void testGetBasicPaymentItemsAsyncTaskWithGrouping() throws InterruptedException, CommunicationException {
initializeValidMocksAndSession();
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 validate that it has the correct fields
BasicPaymentItems basicPaymentItems = listener.getBasicPaymentItems();
// Validate the returned object
validateBasicPaymentItemsList(basicPaymentItems);
validateProductsAndGroups(basicPaymentItems);
}
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 testGetBasicPaymentItemsAsyncTaskWithInvalidRequest.
/**
* Test that an invalid request for BasicPaymentProducts will still return, but will not retrieve PaymentItems
*/
@Test
public void testGetBasicPaymentItemsAsyncTaskWithInvalidRequest() throws InterruptedException {
initializeInValidMocksAndSession();
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 validate that it is indeed null
BasicPaymentItems basicPaymentItems = listener.getBasicPaymentItems();
assertNull(basicPaymentItems);
}
Aggregations