Search in sources :

Example 1 with 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 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);
}
Also used : ArrayList(java.util.ArrayList) BasicPaymentProductsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts) Test(org.junit.Test)

Example 2 with 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));
}
Also used : ArrayList(java.util.ArrayList) BasicPaymentProductsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts) Test(org.junit.Test)

Example 3 with 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 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();
    }
}
Also used : ArrayList(java.util.ArrayList) BasicPaymentProductsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts) Test(org.junit.Test)

Example 4 with BasicPaymentProducts

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;
}
Also used : BasicPaymentProductGroups(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups) OnBasicPaymentProductGroupsCallCompleteListener(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener) OnBasicPaymentProductsCallCompleteListener(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener) ExecutionException(java.util.concurrent.ExecutionException) InvalidParameterException(java.security.InvalidParameterException) BasicPaymentItems(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts)

Example 5 with BasicPaymentProducts

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("&currencyCode=").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());
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Scanner(java.util.Scanner) HttpURLConnection(java.net.HttpURLConnection) AssetManager(com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) Drawable(android.graphics.drawable.Drawable) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) IOException(java.io.IOException) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) InvalidParameterException(java.security.InvalidParameterException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts)

Aggregations

BasicPaymentProducts (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts)5 BasicPaymentProductsAsyncTask (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 InvalidParameterException (java.security.InvalidParameterException)2 Drawable (android.graphics.drawable.Drawable)1 OnBasicPaymentProductGroupsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductGroupsAsyncTask.OnBasicPaymentProductGroupsCallCompleteListener)1 OnBasicPaymentProductsCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentProductsAsyncTask.OnBasicPaymentProductsCallCompleteListener)1 CommunicationException (com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException)1 AssetManager (com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager)1 BasicPaymentItems (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems)1 BasicPaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct)1 BasicPaymentProductGroups (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 Scanner (java.util.Scanner)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1