use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask in project connect-sdk-client-android by Ingenico-ePayments.
the class GetPaymentProductAsyncTaskTest method testGetPaymentProductAsyncTaskWithInvalidRequest.
/**
* Test that an invalid request for a PaymentProduct will return, but will not contain a PaymentProduct
*/
@Test
public void testGetPaymentProductAsyncTaskWithInvalidRequest() throws InterruptedException {
initializeInValidMocksAndSession();
final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
// Create the PaymentProductAsyncTask and then begin the test by calling execute
List<PaymentProductAsyncTask.OnPaymentProductCallCompleteListener> listeners = new ArrayList<>(1);
Listener listener = new Listener(waitForAsyncCallBack);
listeners.add(listener);
PaymentProductAsyncTask paymentProductAsyncTask = new PaymentProductAsyncTask(getContext(), "1", minimalValidPaymentContext, getCommunicator(), listeners);
paymentProductAsyncTask.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 test that it is null
PaymentProduct paymentProduct = listener.getPaymentProduct();
assertNull(paymentProduct);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask in project connect-sdk-client-android by Ingenico-ePayments.
the class GetPaymentProductAsyncTaskTest method testGetPaymentProductAsyncTaskWithValidRequest.
/**
* Tests that a PaymentProduct can successfully be retrieved and has the minimal fields
* Also tests that the input fields are there.
*/
@Test
public void testGetPaymentProductAsyncTaskWithValidRequest() throws InterruptedException, CommunicationException {
initializeValidMocksAndSession();
final CountDownLatch waitForAsyncTaskCallBack = new CountDownLatch(1);
// Create the PaymentProductsAsyncTask and then begin the test by calling execute.
List<PaymentProductAsyncTask.OnPaymentProductCallCompleteListener> listeners = new ArrayList<>(1);
Listener listener = new Listener(waitForAsyncTaskCallBack);
listeners.add(listener);
PaymentProductAsyncTask paymentProductAsyncTask = new PaymentProductAsyncTask(getContext(), "1", minimalValidPaymentContext, getCommunicator(), listeners);
paymentProductAsyncTask.execute();
// Test that the response is received within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds
assertTrue(waitForAsyncTaskCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
// Retrieve the paymentProduct from the listener and validate that it has the correct fields
PaymentProduct paymentProduct = listener.getPaymentProduct();
validatePaymentProduct(paymentProduct);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask in project connect-sdk-client-android by Ingenico-ePayments.
the class GetPaymentProductAsyncTaskTest method testGetPaymentProductAsyncTaskWithValidRequestAndAccountOnFile.
/**
* Tests that a PaymentProduct can successfully be retrieved and has the minimal fields
* Also tests that the input fields are there.
*/
@Test
public void testGetPaymentProductAsyncTaskWithValidRequestAndAccountOnFile() throws InterruptedException, CommunicationException {
try {
initializeValidMocksAndSessionWithToken();
final CountDownLatch waitForAsyncTaskCallBack = new CountDownLatch(1);
// Create the PaymentProductsAsyncTask and then begin the test by calling execute.
List<PaymentProductAsyncTask.OnPaymentProductCallCompleteListener> listeners = new ArrayList<>(1);
Listener listener = new Listener(waitForAsyncTaskCallBack);
listeners.add(listener);
PaymentProductAsyncTask paymentProductAsyncTask = new PaymentProductAsyncTask(getContext(), "1", minimalValidPaymentContext, getCommunicator(), listeners);
paymentProductAsyncTask.execute();
// Test that the response is received within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds
assertTrue(waitForAsyncTaskCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
// Retrieve the paymentProduct from the listener and validate that it has the correct fields
PaymentProduct paymentProduct = listener.getPaymentProduct();
validatePaymentProduct(paymentProduct);
validateAccountOnFile(paymentProduct);
} finally {
deleteToken();
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask in project connect-sdk-client-android by Ingenico-ePayments.
the class GcSession method getPaymentProduct.
/**
* Gets PaymentProduct with fields from the GC gateway
*
* @param context, used for reading device metada which is send to the GC gateway
* @param productId, the productId of the product which needs to be retrieved from the GC gateway
* @param paymentContext, PaymentContext which contains all neccesary data for doing call to the GC gateway to retrieve BasicPaymentProducts
* @param listener, listener which will be called by the AsyncTask when the PaymentProduct with fields is retrieved
*/
public void getPaymentProduct(Context context, String productId, PaymentContext paymentContext, OnPaymentProductCallCompleteListener listener) {
if (context == null) {
throw new InvalidParameterException("Error getting paymentproduct, context may not be null");
}
if (productId == null) {
throw new InvalidParameterException("Error getting paymentproduct, groupId may not be null");
}
if (paymentContext == null) {
throw new InvalidParameterException(("Error getting paymentproduct, paymentContext may not be null"));
}
if (listener == null) {
throw new InvalidParameterException("Error getting paymentproduct, listener may not be null");
}
this.paymentContext = paymentContext;
// Create the cache key for this paymentProduct
PaymentItemCacheKey key = createPaymentItemCacheKey(paymentContext, productId);
// If the paymentProduct is already in the cache, call the listener with that paymentproduct
if (paymentItemMapping.containsKey(key)) {
PaymentProduct cachedPP = (PaymentProduct) paymentItemMapping.get(key);
listener.onPaymentProductCallComplete(cachedPP);
} else {
// Add OnPaymentProductsCallComplete listener and this class to list of listeners so we can store the paymentproduct here
List<OnPaymentProductCallCompleteListener> listeners = new ArrayList<OnPaymentProductCallCompleteListener>();
listeners.add(this);
listeners.add(listener);
// Do the call to the GC gateway
PaymentProductAsyncTask task = new PaymentProductAsyncTask(context, productId, paymentContext, communicator, listeners);
task.execute();
}
}
Aggregations