use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups in project connect-sdk-client-android by Ingenico-ePayments.
the class GetBasicPaymentProductGroupsAsyncTaskTest method testGetBasicPaymentProductGroupsAsyncTaskWithValidRequestWithAccountOnFile.
/**
* Test that BasicPaymentProductGroups can be successfully retrieved by doing the required call
*/
@Test
public // Test that BasicPaymentProductGroups can be successfully retrieved by doing the required call
void testGetBasicPaymentProductGroupsAsyncTaskWithValidRequestWithAccountOnFile() throws InterruptedException, CommunicationException {
try {
initializeValidMocksAndSessionWithToken();
final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
// Create the BasicPaymentProductGroupsAsyncTask and then begin the test by calling execute.
List<BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener> listeners = new ArrayList<>();
Listener listener = new Listener(waitForAsyncCallBack);
listeners.add(listener);
BasicPaymentProductGroupsAsyncTask basicPaymentProductGroupsAsyncTask = new BasicPaymentProductGroupsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
basicPaymentProductGroupsAsyncTask.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
BasicPaymentProductGroups basicPaymentProductGroups = listener.getBasicPaymentProductGroups();
validateBasicPaymentProductGroupsList(basicPaymentProductGroups);
// Validate that the first paymentProductGroup in the returned list has the required fields
validateBasicPaymentProductGroup(basicPaymentProductGroups.getBasicPaymentProductGroups().get(0));
validateAccountOnFile(basicPaymentProductGroups);
} finally {
deleteToken();
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups in project connect-sdk-client-android by Ingenico-ePayments.
the class GetBasicPaymentProductGroupsAsyncTaskTest method testGetBasicPaymentProductGroupsAsyncTaskWithInvalidRequest.
/**
* Test that an invalid request for BasicPaymentProductGroups will still return, but will not retrieve PaymentProductGroups
*/
@Test
public void testGetBasicPaymentProductGroupsAsyncTaskWithInvalidRequest() throws InterruptedException {
initializeInValidMocksAndSession();
final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
// Create the BasicPaymentProductsAsyncTask and then begin the test by calling execute.
List<BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener> listeners = new ArrayList<>();
Listener listener = new Listener(waitForAsyncCallBack);
listeners.add(listener);
BasicPaymentProductGroupsAsyncTask basicPaymentProductGroupsAsyncTask = new BasicPaymentProductGroupsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
basicPaymentProductGroupsAsyncTask.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
BasicPaymentProductGroups basicPaymentProductGroups = listener.getBasicPaymentProductGroups();
assertNull(basicPaymentProductGroups);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups in project connect-sdk-client-android by Ingenico-ePayments.
the class GetBasicPaymentProductGroupsAsyncTaskTest method testGetBasicPaymentProductGroupsAsyncTaskWithValidRequest.
/**
* Test that BasicPaymentProductGroups can be successfully retrieved by doing the required call
*/
@Test
public // Test that BasicPaymentProductGroups can be successfully retrieved by doing the required call
void testGetBasicPaymentProductGroupsAsyncTaskWithValidRequest() throws InterruptedException, CommunicationException {
initializeValidMocksAndSession();
final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
// Create the BasicPaymentProductGroupsAsyncTask and then begin the test by calling execute.
List<BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener> listeners = new ArrayList<>();
Listener listener = new Listener(waitForAsyncCallBack);
listeners.add(listener);
BasicPaymentProductGroupsAsyncTask basicPaymentProductGroupsAsyncTask = new BasicPaymentProductGroupsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
basicPaymentProductGroupsAsyncTask.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
BasicPaymentProductGroups basicPaymentProductGroups = listener.getBasicPaymentProductGroups();
validateBasicPaymentProductGroupsList(basicPaymentProductGroups);
// Validate that the first paymentProductGroup in the returned list has the required fields
validateBasicPaymentProductGroup(basicPaymentProductGroups.getBasicPaymentProductGroups().get(0));
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups 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.model.paymentproduct.BasicPaymentProductGroups in project connect-sdk-client-android by Ingenico-ePayments.
the class C2sCommunicator method getBasicPaymentProductGroups.
/**
* Retrieves a list of basicpaymentproductgroups from the GC gateway without any fields
*
* @param context, used for reading device metadata which is send to the GC gateway
* @param paymentContext, used to retrieve the correct productGroups from the GC gateway
*
* @return list of BasicPaymentProducts, or null when an error has occured
*/
public BasicPaymentProductGroups getBasicPaymentProductGroups(PaymentContext paymentContext, Context context) {
if (paymentContext == null) {
throw new InvalidParameterException("Error getting BasicPaymentProductGroups, request may not be null");
}
HttpURLConnection connection = null;
try {
// Build the complete url which is called
String baseUrl = configuration.getBaseUrl();
String paymentProductGroupsPath = Constants.GC_GATEWAY_RETRIEVE_PAYMENTPRODUCTGROUPS_PATH.replace("[cid]", configuration.getCustomerId());
String completePath = baseUrl + paymentProductGroupsPath;
// Add query parameters
StringBuilder queryString = new StringBuilder();
queryString.append("?countryCode=").append(paymentContext.getCountryCode());
queryString.append("&amount=").append(paymentContext.getAmountOfMoney().getAmount());
queryString.append("&isRecurring=").append(paymentContext.isRecurring());
queryString.append("¤cyCode=").append(paymentContext.getAmountOfMoney().getCurrencyCode());
queryString.append("&hide=fields");
queryString.append("&").append(createCacheBusterParameter());
// Add query string to complete path
completePath += queryString.toString();
// Do the call and deserialise the result to BasicPaymentProducts
connection = doHTTPGetRequest(completePath, configuration.getClientSessionId(), configuration.getMetadata(context));
String responseBody = new Scanner(connection.getInputStream(), "UTF-8").useDelimiter("\\A").next();
// Log the response
if (Constants.ENABLE_REQUEST_LOGGING) {
logResponse(connection, responseBody);
}
BasicPaymentProductGroups basicPaymentProductGroups = gson.fromJson(responseBody, BasicPaymentProductGroups.class);
// Set the logos for all BasicPaymentProductGroups
for (BasicPaymentProductGroup paymentProductGroup : basicPaymentProductGroups.getBasicPaymentProductGroups()) {
AssetManager manager = AssetManager.getInstance(context);
Drawable logo = manager.getLogo(paymentProductGroup.getId());
paymentProductGroup.getDisplayHints().setLogo(logo);
}
return basicPaymentProductGroups;
} catch (CommunicationException e) {
Log.i(TAG, "Error while getting paymentProductGroups:" + e.getMessage());
return null;
} catch (Exception e) {
Log.i(TAG, "Error while getting paymentProductGroups:" + e.getMessage());
return null;
} finally {
try {
if (connection != null) {
connection.getInputStream().close();
connection.disconnect();
}
} catch (IOException e) {
Log.i(TAG, "Error while getting paymentProductGroups:" + e.getMessage());
}
}
}
Aggregations