Search in sources :

Example 6 with CommunicationException

use of com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException in project connect-sdk-client-android by Ingenico-ePayments.

the class C2sCommunicator method getPaymentProductGroup.

/**
 * Retrieves a single paymentProductGroup from the GC gateway including all its fields
 *
 * @param groupId, used to retrieve the BasicPaymentProductGroup that is associated with this id
 * @param context, used for reading device metada which is send to the GC gateway
 * @param paymentContext, PaymentContext which contains all neccesary data to retrieve a paymentProductGroup
 *
 * @return PaymentProduct, or null when an error has occured
 */
public PaymentProductGroup getPaymentProductGroup(String groupId, Context context, PaymentContext paymentContext) {
    if (groupId == null) {
        throw new InvalidParameterException("Error getting paymentProductGroup, groupId 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_PAYMENTPRODUCTGROUP_PATH.replace("[cid]", configuration.getCustomerId()).replace("[gid]", groupId);
        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("&").append(createCacheBusterParameter());
        completePath += queryString.toString();
        // Do the call and deserialise the result to PaymentProduct
        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);
        }
        return gson.fromJson(responseBody, PaymentProductGroup.class);
    } catch (CommunicationException e) {
        Log.i(TAG, "Error while getting paymentProductGroup:" + e.getMessage());
        return null;
    } catch (Exception e) {
        Log.i(TAG, "Error while getting paymentProductGroup:" + e.getMessage());
        return null;
    } finally {
        try {
            if (connection != null) {
                connection.getInputStream().close();
                connection.disconnect();
            }
        } catch (IOException e) {
            Log.i(TAG, "Error while getting paymentProductGroup: " + e.getMessage());
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Scanner(java.util.Scanner) HttpURLConnection(java.net.HttpURLConnection) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) 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)

Example 7 with CommunicationException

use of com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException in project connect-sdk-client-android by Ingenico-ePayments.

the class GcSessionPreparePaymentRequestTest method testGetPreparedPaymentRequestWithAccountOnFileAndValidRequest.

@Test
public void testGetPreparedPaymentRequestWithAccountOnFileAndValidRequest() throws InterruptedException {
    try {
        initializeValidGcSessionMocksAndSessionWithToken();
        CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
        PaymentRequest paymentRequest = constructValidPaymentRequest(true, false);
        Listener listener = new Listener(waitForAsyncCallBack);
        getSession().preparePaymentRequest(paymentRequest, getContext(), listener);
        // Test that the request is prepared within 'PREPAREPAYMENTREQUEST_CALLBACK_TEST_TIMEOUT_SEC' seconds
        assertTrue(waitForAsyncCallBack.await(PREPAREPAYMENTREQUEST_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
        PreparedPaymentRequest preparedPaymentRequest = listener.getPreparedPaymentRequest();
        // Test that the encrypted blob that will be used for the payment has been created successfully
        validateValidPreparedPaymentRequest(preparedPaymentRequest);
    } catch (CommunicationException e) {
        e.printStackTrace();
    } finally {
        deleteToken();
    }
}
Also used : PreparedPaymentRequest(com.globalcollect.gateway.sdk.client.android.sdk.model.PreparedPaymentRequest) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) PreparedPaymentRequest(com.globalcollect.gateway.sdk.client.android.sdk.model.PreparedPaymentRequest) CreatePaymentRequest(com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest) PaymentRequest(com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentRequest) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 8 with CommunicationException

use of com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException in project connect-sdk-client-android by Ingenico-ePayments.

the class BaseAsyncTaskTest method initializeValidMocksAndSessionWithToken.

/**
 * Create a mocked configuration that produces valid requests and contains an AccountOnFile
 */
void initializeValidMocksAndSessionWithToken() throws CommunicationException {
    CreateTokenRequest body = GsonHelper.fromResourceJson("getTokenJSONCard.json", CreateTokenRequest.class);
    try {
        token = tokenUtil.createToken(testMerchantId, body);
    } catch (ApiException e) {
        throw new CommunicationException("ApiException while creating token. Token is: " + token, e);
    }
    initializeValidMocksAndSession();
}
Also used : CreateTokenRequest(com.ingenico.connect.gateway.sdk.java.domain.token.CreateTokenRequest) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) ApiException(com.ingenico.connect.gateway.sdk.java.ApiException)

Example 9 with CommunicationException

use of com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException in project connect-sdk-client-android by Ingenico-ePayments.

the class BaseAsyncTaskTest method initializeValidMocksAndSession.

/**
 * Creates a mocked configuration that produces valid requests
 */
void initializeValidMocksAndSession() throws CommunicationException {
    SessionRequest request = new SessionRequest();
    if (token != null) {
        request.setTokens(Collections.singletonList(token));
    }
    try {
        SessionResponse response = sessionUtil.createSession(testMerchantId, request);
        initializeValidMocks(response);
    } catch (ApiException e) {
        throw new CommunicationException("ApiException while creating session", e);
    }
}
Also used : CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) SessionResponse(com.ingenico.connect.gateway.sdk.java.domain.sessions.SessionResponse) SessionRequest(com.ingenico.connect.gateway.sdk.java.domain.sessions.SessionRequest) ApiException(com.ingenico.connect.gateway.sdk.java.ApiException)

Example 10 with CommunicationException

use of com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException 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

CommunicationException (com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException)16 IOException (java.io.IOException)13 HttpURLConnection (java.net.HttpURLConnection)13 MalformedURLException (java.net.MalformedURLException)13 InvalidParameterException (java.security.InvalidParameterException)11 Scanner (java.util.Scanner)11 Drawable (android.graphics.drawable.Drawable)2 AssetManager (com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager)2 ApiException (com.ingenico.connect.gateway.sdk.java.ApiException)2 URL (java.net.URL)2 ConvertedAmountResponse (com.globalcollect.gateway.sdk.client.android.sdk.model.ConvertedAmountResponse)1 CustomerDetailsRequest (com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsRequest)1 CustomerDetailsResponse (com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsResponse)1 PaymentRequest (com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentRequest)1 PreparedPaymentRequest (com.globalcollect.gateway.sdk.client.android.sdk.model.PreparedPaymentRequest)1 BasicPaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct)1 BasicPaymentProductGroup (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup)1 BasicPaymentProductGroups (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups)1 BasicPaymentProducts (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts)1 CreatePaymentRequest (com.ingenico.connect.gateway.sdk.java.domain.payment.CreatePaymentRequest)1