Search in sources :

Example 6 with PaymentProduct

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct 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);
}
Also used : PaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentProductAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask) Test(org.junit.Test)

Example 7 with PaymentProduct

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct 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();
    }
}
Also used : PaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentProductAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask) Test(org.junit.Test)

Example 8 with PaymentProduct

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct 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();
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) PaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) PaymentItemCacheKey(com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentItemCacheKey) ArrayList(java.util.ArrayList) PaymentProductAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask) OnPaymentProductCallCompleteListener(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask.OnPaymentProductCallCompleteListener)

Example 9 with PaymentProduct

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct 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)

Example 10 with PaymentProduct

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

the class PaymentProductSelectionActivity method retrievePaymentProductFieldsBcmc.

private void retrievePaymentProductFieldsBcmc(PaymentItem bcmc) {
    if (PAYMENTPRODUCTID_BanContact.equals(bcmc.getId())) {
        // Because the BanContact payment product (BCMC, PPid 3012) has, apart from regular
        // credit card inputFields, other ways for the customer to complete the transaction, it
        // is required that a payment is created first, before rendering the Input Fields. A create
        // payment call cannot be made via this Client 2 Server API, but should be made from your
        // payment server instead. You should add code here that triggers that payment and then
        // have the result sent back to the Client.
        // Since this is an example application, we will simply pretend that the call has been
        // made and load an example JSON response from the resources. This resource is not the
        // full createPaymentResponse, but only the MerchantAction, which contains the fields and
        // showdata required to render the qrCode/button for BCMC.
        Reader reader = new InputStreamReader(getResources().openRawResource(R.raw.bcmc_merchantaction_example));
        MerchantAction bcmcMerchantActionExample = new Gson().fromJson(reader, MerchantAction.class);
        // Add the payment product fields from the merchantAction to the payment item, so that the
        // DetailInputActivity can render them as usual.
        ((PaymentProduct) bcmc).setPaymentProductFields(bcmcMerchantActionExample.getFormFields());
        Intent bcmcDetailInputActivityIntent = new Intent(this, DetailInputActivityBCMC.class);
        bcmcDetailInputActivityIntent.putExtra(Constants.INTENT_SELECTED_ITEM, bcmc);
        bcmcDetailInputActivityIntent.putExtra(Constants.INTENT_BCMC_SHOWDATA, ((Serializable) bcmcMerchantActionExample.getShowData()));
        startNextActivity(bcmcDetailInputActivityIntent);
    } else {
        throw new InvalidParameterException("Can not retrieve fields for BCMC, payment item is not BCMC");
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) PaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) Serializable(java.io.Serializable) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Gson(com.google.gson.Gson) Intent(android.content.Intent) MerchantAction(com.globalcollect.gateway.sdk.client.android.exampleapp.model.MerchantAction)

Aggregations

PaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct)11 PaymentProductAsyncTask (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask)5 ArrayList (java.util.ArrayList)5 BasicPaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 Intent (android.content.Intent)2 InvalidParameterException (java.security.InvalidParameterException)2 MerchantAction (com.globalcollect.gateway.sdk.client.android.exampleapp.model.MerchantAction)1 OnPaymentProductCallCompleteListener (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask.OnPaymentProductCallCompleteListener)1 PaymentItemCacheKey (com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentItemCacheKey)1 PaymentRequest (com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentRequest)1 PreparedPaymentRequest (com.globalcollect.gateway.sdk.client.android.sdk.model.PreparedPaymentRequest)1 IinDetail (com.globalcollect.gateway.sdk.client.android.sdk.model.iin.IinDetail)1 BasicPaymentItem (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem)1 BasicPaymentProductGroup (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup)1 PaymentProductField (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductField)1 PaymentProductGroup (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup)1 PaymentMethodToken (com.google.android.gms.wallet.PaymentMethodToken)1 Gson (com.google.gson.Gson)1