use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts in project connect-sdk-client-android by Ingenico-ePayments.
the class GetBasicPaymentProductsAsyncTaskTest method testGetBasicPaymentProductsAsyncTaskWithInvalidRequest.
/**
* Test that an invalid request for BasicPaymentProducts will still return, but will not retrieve PaymentProducts
*/
@Test
public void testGetBasicPaymentProductsAsyncTaskWithInvalidRequest() throws InterruptedException {
initializeInValidMocksAndSession();
final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
// Create the BasicPaymentProductsAsyncTask and then begin the test by calling execute.
List<BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener> listeners = new ArrayList<>();
Listener listener = new Listener(waitForAsyncCallBack);
listeners.add(listener);
BasicPaymentProductsAsyncTask basicPaymentProductsAsyncTask = new BasicPaymentProductsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
basicPaymentProductsAsyncTask.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
BasicPaymentProducts basicPaymentProducts = listener.getBasicPaymentProducts();
assertNull(basicPaymentProducts);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts in project connect-sdk-client-android by Ingenico-ePayments.
the class GetBasicPaymentProductsAsyncTaskTest method testGetBasicPaymentProductsAsyncTaskWithValidRequest.
/**
* Test that BasicPaymentProducts can be successfully retrieved and have the minimal fields
*/
@Test
public void testGetBasicPaymentProductsAsyncTaskWithValidRequest() throws InterruptedException, CommunicationException {
initializeValidMocksAndSession();
final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
// Create the BasicPaymentProductsAsyncTask and then begin the test by calling execute.
List<BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener> listeners = new ArrayList<>(1);
Listener listener = new Listener(waitForAsyncCallBack);
listeners.add(listener);
BasicPaymentProductsAsyncTask basicPaymentProductsAsyncTask = new BasicPaymentProductsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
basicPaymentProductsAsyncTask.execute();
// Test that the response 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
BasicPaymentProducts basicPaymentProducts = listener.getBasicPaymentProducts();
validateBasicPaymentProductsList(basicPaymentProducts);
// Validate that the first paymentProduct in the returned list has the required fields
validateBasicPaymentProduct(basicPaymentProducts.getBasicPaymentProducts().get(0));
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts in project connect-sdk-client-android by Ingenico-ePayments.
the class GetBasicPaymentProductsAsyncTaskTest method testGetBasicPaymentProductsAsyncTaskWithValidRequestAndAccountsOnFile.
/**
* Test that BasicPaymentProducts can be successfully retrieved including AccountOnFiles and that they both have the minimal fields
*/
@Test
public void testGetBasicPaymentProductsAsyncTaskWithValidRequestAndAccountsOnFile() throws InterruptedException, CommunicationException {
try {
initializeValidMocksAndSessionWithToken();
final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
// Create the BasicPaymentProductsAsyncTask and then begin the test by calling execute.
List<BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener> listeners = new ArrayList<>();
Listener listener = new Listener(waitForAsyncCallBack);
listeners.add(listener);
BasicPaymentProductsAsyncTask basicPaymentProductsAsyncTask = new BasicPaymentProductsAsyncTask(getContext(), minimalValidPaymentContext, getCommunicator(), listeners);
basicPaymentProductsAsyncTask.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
BasicPaymentProducts basicPaymentProducts = listener.getBasicPaymentProducts();
validateBasicPaymentProductsList(basicPaymentProducts);
// Test that the first paymentProduct in the returned list has the required fields
validateBasicPaymentProduct(basicPaymentProducts.getBasicPaymentProducts().get(0));
validateAccountOnFile(basicPaymentProducts);
} finally {
deleteToken();
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts 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.BasicPaymentProducts in project connect-sdk-client-android by Ingenico-ePayments.
the class C2sCommunicator method getBasicPaymentProducts.
/**
* Retrieves a list of basicpaymentproducts from the GC gateway without any fields
*
* @param context, used for reading device metadata which is send to the GC gateway
* @param paymentContext, payment information that is used to retrieve the correct payment products
*
* @return list of BasicPaymentProducts, or null when an error has occured
*/
public BasicPaymentProducts getBasicPaymentProducts(PaymentContext paymentContext, Context context) {
if (paymentContext == null) {
throw new InvalidParameterException("Error getting BasicPaymentProducts, request may not be null");
}
HttpURLConnection connection = null;
try {
// Build the complete url which is called
String baseUrl = configuration.getBaseUrl();
String paymentProductPath = Constants.GC_GATEWAY_RETRIEVE_PAYMENTPRODUCTS_PATH.replace("[cid]", configuration.getCustomerId());
String completePath = baseUrl + paymentProductPath;
// 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);
}
BasicPaymentProducts basicPaymentProducts = gson.fromJson(responseBody, BasicPaymentProducts.class);
// Set the logos for all paymentproducts
for (BasicPaymentProduct paymentProduct : basicPaymentProducts.getBasicPaymentProducts()) {
AssetManager manager = AssetManager.getInstance(context);
Drawable logo = manager.getLogo(paymentProduct.getId());
paymentProduct.getDisplayHints().setLogo(logo);
}
return basicPaymentProducts;
} catch (CommunicationException e) {
Log.i(TAG, "Error while getting paymentproducts:" + e.getMessage());
return null;
} catch (Exception e) {
Log.i(TAG, "Error while getting paymentproducts:" + e.getMessage());
return null;
} finally {
try {
if (connection != null) {
connection.getInputStream().close();
connection.disconnect();
}
} catch (IOException e) {
Log.i(TAG, "Error while getting paymentproducts:" + e.getMessage());
}
}
}
Aggregations