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("¤cyCode=").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());
}
}
}
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());
}
}
}
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("¤cyCode=").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());
}
}
}
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());
}
}
}
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("¤cyCode=").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());
}
}
}
Aggregations