Search in sources :

Example 11 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 getPaymentProductNetworks.

/**
 * Retrieves a list of networks, which are allowed to be used with the payment product ID that is
 * provided.
 *
 * @param context, used to read the devices meta-data
 * @param productId, the productId for which the networks should be retrieved
 * @param paymentContext, the paymentcontext for which the networks should be checked
 *
 * @return PaymentProductNetworksResponse, or null if an error occurred.
 */
public PaymentProductNetworksResponse getPaymentProductNetworks(Context context, String productId, PaymentContext paymentContext) {
    Validate.notNull(context);
    Validate.notNull(productId);
    Validate.notNull(paymentContext);
    HttpURLConnection connection = null;
    try {
        // Build the complete url which is called
        String baseUrl = configuration.getBaseUrl();
        String paymentProductPath = Constants.GC_GATEWAY_RETRIEVE_PAYMENTPRODUCT_NETWORKS_PATH.replace("[cid]", configuration.getCustomerId()).replace("[pid]", productId);
        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 PaymentProductNetworksResponse
        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, PaymentProductNetworksResponse.class);
    } catch (CommunicationException e) {
        Log.i(TAG, "Error while getting paymentproduct networks:" + e.getMessage());
        return null;
    } catch (Exception e) {
        Log.i(TAG, "Error while getting paymentproduct networks:" + e.getMessage());
        return null;
    } finally {
        try {
            if (connection != null) {
                connection.getInputStream().close();
                connection.disconnect();
            }
        } catch (IOException e) {
            Log.i(TAG, "Error while getting paymentproduct networks:" + e.getMessage());
        }
    }
}
Also used : 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 12 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 getThirdPartyStatus.

/**
 * Retrieves the ThirdPartyStatus for a given payment
 */
public ThirdPartyStatusResponse getThirdPartyStatus(Context context, String paymentId) {
    HttpURLConnection connection = null;
    try {
        // Construct the url for the PublicKey call
        String paymentProductPath = Constants.GC_GATEWAY_THIRDPARTYSTATUS_PATH.replace("[cid]", configuration.getCustomerId()).replace("[paymentid]", paymentId);
        String url = configuration.getBaseUrl() + paymentProductPath;
        // Do the call and deserialize the result to PaymentProductPublicKeyResponse
        connection = doHTTPGetRequest(url, 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, ThirdPartyStatusResponse.class);
    } catch (CommunicationException e) {
        Log.i(TAG, "Error getting Payment Product Public key response:" + e.getMessage());
        return null;
    } catch (Exception e) {
        Log.i(TAG, "Error getting Payment Product Public key response:" + e.getMessage());
        return null;
    } finally {
        try {
            if (connection != null) {
                connection.getInputStream().close();
                connection.disconnect();
            }
        } catch (IOException e) {
            Log.i(TAG, "Error getting Payment Product Public key response:" + e.getMessage());
        }
    }
}
Also used : 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 13 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 getPaymentProduct.

/**
 * Retrieves a single paymentproduct from the GC gateway including all its fields
 *
 * @param productId, used to retrieve the PaymentProduct 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 paymentproduct
 *
 * @return PaymentProduct, or null when an error has occured
 */
public PaymentProduct getPaymentProduct(String productId, Context context, PaymentContext paymentContext) {
    if (productId == null) {
        throw new InvalidParameterException("Error getting PaymentProduct, productId 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_PAYMENTPRODUCT_PATH.replace("[cid]", configuration.getCustomerId()).replace("[pid]", productId);
        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, PaymentProduct.class);
    } catch (CommunicationException e) {
        Log.i(TAG, "Error while getting paymentproduct:" + e.getMessage());
        return null;
    } catch (Exception e) {
        Log.i(TAG, "Error while getting paymentproduct:" + e.getMessage());
        return null;
    } finally {
        try {
            if (connection != null) {
                connection.getInputStream().close();
                connection.disconnect();
            }
        } catch (IOException e) {
            Log.i(TAG, "Error while getting paymentproduct:" + 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 14 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 getPublicKey.

/**
 * Retrieves the publickey from the GC gateway
 *
 * @param context, used for reading device metada which is send to the GC gateway
 *
 * @return PublicKeyResponse response , or null when an error has occured
 */
public PublicKeyResponse getPublicKey(Context context) {
    HttpURLConnection connection = null;
    try {
        // Construct the url for the PublicKey call
        String paymentProductPath = Constants.GC_GATEWAY_PUBLIC_KEY_PATH.replace("[cid]", configuration.getCustomerId());
        String url = configuration.getBaseUrl() + paymentProductPath;
        // Do the call and deserialise the result to PublicKeyResponse
        connection = doHTTPGetRequest(url, 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, PublicKeyResponse.class);
    } catch (CommunicationException e) {
        Log.i(TAG, "Error getting Public key response:" + e.getMessage());
        return null;
    } catch (Exception e) {
        Log.i(TAG, "Error getting Public key response:" + e.getMessage());
        return null;
    } finally {
        try {
            if (connection != null) {
                connection.getInputStream().close();
                connection.disconnect();
            }
        } catch (IOException e) {
            Log.i(TAG, "Error getting Public key response:" + e.getMessage());
        }
    }
}
Also used : 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 15 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 getBasicPaymentProductGroups.

/**
 * Retrieves a list of basicpaymentproductgroups from the GC gateway without any fields
 *
 * @param context, used for reading device metadata which is send to the GC gateway
 * @param paymentContext, used to retrieve the correct productGroups from the GC gateway
 *
 * @return list of BasicPaymentProducts, or null when an error has occured
 */
public BasicPaymentProductGroups getBasicPaymentProductGroups(PaymentContext paymentContext, Context context) {
    if (paymentContext == null) {
        throw new InvalidParameterException("Error getting BasicPaymentProductGroups, request may not be null");
    }
    HttpURLConnection connection = null;
    try {
        // Build the complete url which is called
        String baseUrl = configuration.getBaseUrl();
        String paymentProductGroupsPath = Constants.GC_GATEWAY_RETRIEVE_PAYMENTPRODUCTGROUPS_PATH.replace("[cid]", configuration.getCustomerId());
        String completePath = baseUrl + paymentProductGroupsPath;
        // 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);
        }
        BasicPaymentProductGroups basicPaymentProductGroups = gson.fromJson(responseBody, BasicPaymentProductGroups.class);
        // Set the logos for all BasicPaymentProductGroups
        for (BasicPaymentProductGroup paymentProductGroup : basicPaymentProductGroups.getBasicPaymentProductGroups()) {
            AssetManager manager = AssetManager.getInstance(context);
            Drawable logo = manager.getLogo(paymentProductGroup.getId());
            paymentProductGroup.getDisplayHints().setLogo(logo);
        }
        return basicPaymentProductGroups;
    } catch (CommunicationException e) {
        Log.i(TAG, "Error while getting paymentProductGroups:" + e.getMessage());
        return null;
    } catch (Exception e) {
        Log.i(TAG, "Error while getting paymentProductGroups:" + e.getMessage());
        return null;
    } finally {
        try {
            if (connection != null) {
                connection.getInputStream().close();
                connection.disconnect();
            }
        } catch (IOException e) {
            Log.i(TAG, "Error while getting paymentProductGroups:" + e.getMessage());
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Scanner(java.util.Scanner) HttpURLConnection(java.net.HttpURLConnection) BasicPaymentProductGroups(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups) AssetManager(com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) BasicPaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup) Drawable(android.graphics.drawable.Drawable) 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)

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