Search in sources :

Example 1 with PaymentProductGroup

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup in project connect-sdk-client-android by Ingenico-ePayments.

the class GcSession method getPaymentProductGroup.

/**
 * Gets PaymentProductGroup with fields from the GC gateway
 *
 * @param context, used for reading device metada which is send to the GC gateway
 * @param groupId, the productId of the group which needs to be retrieved from the GC gateway
 * @param paymentContext, PaymentContext which contains all necessary data for doing call to the GC gateway to retrieve PaymentProductGroup
 * @param listener, listener which will be called by the AsyncTask when the PaymentProductGroup with fields is retrieved
 */
public void getPaymentProductGroup(Context context, String groupId, PaymentContext paymentContext, OnPaymentProductGroupCallCompleteListener listener) {
    if (context == null) {
        throw new InvalidParameterException("Error getting paymentproduct, context may not be null");
    }
    if (groupId == 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 paymentProductGroup
    PaymentItemCacheKey key = createPaymentItemCacheKey(paymentContext, groupId);
    // If the paymentProductGroup is already in the cache, call the listener with that paymentProductGroup
    if (paymentItemMapping.containsKey(key)) {
        PaymentProductGroup cachedPPG = (PaymentProductGroup) paymentItemMapping.get(key);
        listener.onPaymentProductGroupCallComplete(cachedPPG);
    } else {
        // Add OnPaymentProductsCallComplete listener and this class to list of listeners so we can store the paymentproduct here
        List<OnPaymentProductGroupCallCompleteListener> listeners = new ArrayList<>();
        listeners.add(this);
        listeners.add(listener);
        // Do the call to the GC gateway
        PaymentProductGroupAsyncTask task = new PaymentProductGroupAsyncTask(context, groupId, paymentContext, communicator, listeners);
        task.execute();
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) PaymentItemCacheKey(com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentItemCacheKey) PaymentProductGroupAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductGroupAsyncTask) ArrayList(java.util.ArrayList) OnPaymentProductGroupCallCompleteListener(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductGroupAsyncTask.OnPaymentProductGroupCallCompleteListener) BasicPaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup) PaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup)

Example 2 with PaymentProductGroup

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup in project connect-sdk-client-android by Ingenico-ePayments.

the class GetPaymentProductGroupAsyncTaskTest method testGetPaymentProductGroupAsyncTaskWithValidRequest.

/**
 * Tests that a PaymentProductGroup can successfully be retrieved and has the minimal fields
 * Also tests that the input fields are there.
 */
@Test
public void testGetPaymentProductGroupAsyncTaskWithValidRequest() throws InterruptedException, CommunicationException {
    initializeValidMocksAndSession();
    final CountDownLatch waitForAsyncTaskCallBack = new CountDownLatch(1);
    // Create the PaymentProductsAsyncTask and then begin the test by calling execute.
    List<PaymentProductGroupAsyncTask.OnPaymentProductGroupCallCompleteListener> listeners = new ArrayList<>(1);
    Listener listener = new Listener(waitForAsyncTaskCallBack);
    listeners.add(listener);
    PaymentProductGroupAsyncTask paymentProductGroupAsyncTask = new PaymentProductGroupAsyncTask(getContext(), "cards", minimalValidPaymentContext, getCommunicator(), listeners);
    paymentProductGroupAsyncTask.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 paymentProductGroup from the listener and validate that it has the correct fields
    PaymentProductGroup paymentProductGroup = listener.getPaymentProductGroup();
    validatePaymentProductGroup(paymentProductGroup);
}
Also used : PaymentProductGroupAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductGroupAsyncTask) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup) Test(org.junit.Test)

Example 3 with PaymentProductGroup

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup in project connect-sdk-client-android by Ingenico-ePayments.

the class GetPaymentProductGroupAsyncTaskTest method testGetPaymentProductAsyncTaskWithInvalidRequest.

/**
 * Test that an invalid request for a PaymentProductGroup will return, but will not contain a PaymentProduct
 */
@Test
public void testGetPaymentProductAsyncTaskWithInvalidRequest() throws InterruptedException {
    initializeInValidMocksAndSession();
    final CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
    // Create the PaymentProductGroupAsyncTask and then begin the test by calling execute
    List<PaymentProductGroupAsyncTask.OnPaymentProductGroupCallCompleteListener> listeners = new ArrayList<>(1);
    Listener listener = new Listener(waitForAsyncCallBack);
    listeners.add(listener);
    PaymentProductGroupAsyncTask paymentProductGroupAsyncTask = new PaymentProductGroupAsyncTask(getContext(), "cards", minimalValidPaymentContext, getCommunicator(), listeners);
    paymentProductGroupAsyncTask.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
    PaymentProductGroup paymentProductGroup = listener.getPaymentProductGroup();
    assertNull(paymentProductGroup);
}
Also used : PaymentProductGroupAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductGroupAsyncTask) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup) Test(org.junit.Test)

Example 4 with PaymentProductGroup

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup in project connect-sdk-client-android by Ingenico-ePayments.

the class GetPaymentProductGroupAsyncTaskTest method testGetPaymentProductGroupAsyncTaskWithValidRequestAndAccountOnFile.

/**
 * Tests that a PaymentProductGroup can successfully be retrieved and has the minimal fields
 * Also tests that the inputfields are there.
 */
@Test
public void testGetPaymentProductGroupAsyncTaskWithValidRequestAndAccountOnFile() throws InterruptedException, CommunicationException {
    try {
        initializeValidMocksAndSessionWithToken();
        final CountDownLatch waitForAsyncTaskCallBack = new CountDownLatch(1);
        // Create the PaymentProductGroupAsyncTask and then begin the test by calling execute.
        List<PaymentProductGroupAsyncTask.OnPaymentProductGroupCallCompleteListener> listeners = new ArrayList<>(1);
        Listener listener = new Listener(waitForAsyncTaskCallBack);
        listeners.add(listener);
        PaymentProductGroupAsyncTask paymentProductGroupAsyncTask = new PaymentProductGroupAsyncTask(getContext(), "cards", minimalValidPaymentContext, getCommunicator(), listeners);
        paymentProductGroupAsyncTask.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 paymentProductGroup from the listener and validate that it has the correct fields
        PaymentProductGroup paymentProductGroup = listener.getPaymentProductGroup();
        validatePaymentProductGroup(paymentProductGroup);
        validateAccountOnFile(paymentProductGroup);
    } finally {
        deleteToken();
    }
}
Also used : PaymentProductGroupAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductGroupAsyncTask) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup) Test(org.junit.Test)

Example 5 with PaymentProductGroup

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup in project connect-sdk-client-android by Ingenico-ePayments.

the class PaymentProductSelectionActivity method determineAndStartDetailInputActivity.

private void determineAndStartDetailInputActivity(PaymentItem paymentItem) {
    // Determine what DetailInputActivity to load. The base-class just renders the fields and
    // performs default validation on the fields. In some cases this is not enough however. In
    // these cases a subclass of the DetailInputActivity will be loaded that has additional
    // functionality for these specific products/methods.
    Intent detailInputActivityIntent = null;
    if (paymentItem instanceof PaymentProductGroup && PAYMENTPRODUCTGROUPID_CARDS.equals(paymentItem.getId()) || ((PaymentProduct) paymentItem).getPaymentMethod().equals("card")) {
        detailInputActivityIntent = new Intent(this, DetailInputActivityCreditCards.class);
    } else if (PAYMENTPRODUCTID_BOLETOBANCARIO.equals(paymentItem.getId())) {
        detailInputActivityIntent = new Intent(this, DetailInputActivityBoletoBancario.class);
    } else if (PAYMENTPRODUCTID_AFTERPAY_INSTALLMENTS.equals(paymentItem.getId()) || PAYMENTPRODUCTID_AFTERPAY_INVOICE.equals(paymentItem.getId())) {
        detailInputActivityIntent = new Intent(this, DetailInputActivityAfterpay.class);
    } else {
        detailInputActivityIntent = new Intent(this, DetailInputActivity.class);
    }
    detailInputActivityIntent.putExtra(Constants.INTENT_SELECTED_ITEM, paymentItem);
    startNextActivity(detailInputActivityIntent);
}
Also used : PaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) Intent(android.content.Intent) BasicPaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup) PaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup)

Aggregations

PaymentProductGroup (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup)5 PaymentProductGroupAsyncTask (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductGroupAsyncTask)4 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 BasicPaymentProductGroup (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup)2 Intent (android.content.Intent)1 OnPaymentProductGroupCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductGroupAsyncTask.OnPaymentProductGroupCallCompleteListener)1 PaymentItemCacheKey (com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentItemCacheKey)1 BasicPaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct)1 PaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct)1 InvalidParameterException (java.security.InvalidParameterException)1