use of com.globalcollect.gateway.sdk.client.android.sdk.model.iin.IinDetailsResponse in project connect-sdk-client-android by Ingenico-ePayments.
the class ReadInternalStorage method getIinResponsesFromCache.
/**
* Reads all iinResponses from the cache on disk
* @param context, used for reading files
*/
@SuppressWarnings("unchecked")
public Map<String, IinDetailsResponse> getIinResponsesFromCache() {
if (context == null) {
throw new InvalidParameterException("Error getting response in cache, context may not be null");
}
// Create new map which contains all the iinResponses
Map<String, IinDetailsResponse> iinResponses = new HashMap<String, IinDetailsResponse>();
// Check if the cachefile exists
String directory = context.getFilesDir() + Constants.DIRECTORY_IINRESPONSES;
File file = new File(directory, Constants.FILENAME_IINRESPONSE_CACHE);
if (file.exists()) {
// read the content and parse it to Map<String, IinDetailsResponse>
FileInputStream fileInputStream = null;
ObjectInputStream objectInputStream = null;
try {
fileInputStream = new FileInputStream(file);
objectInputStream = new ObjectInputStream(fileInputStream);
iinResponses = (Map<String, IinDetailsResponse>) objectInputStream.readObject();
} catch (StreamCorruptedException e) {
Log.e(TAG, "Error getting List<PaymentProduct> from internal file ", e);
} catch (IOException e) {
Log.e(TAG, "Error getting List<PaymentProduct> from internal file ", e);
} catch (ClassNotFoundException e) {
Log.e(TAG, "Error getting List<PaymentProduct> from internal file ", e);
} finally {
try {
objectInputStream.close();
fileInputStream.close();
} catch (IOException e) {
}
}
}
return iinResponses;
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.iin.IinDetailsResponse in project connect-sdk-client-android by Ingenico-ePayments.
the class C2sCommunicator method getPaymentProductIdByCreditCardNumber.
/**
* Get the IIN details for the entered partial creditcardnumber
*
* @param context, used for reading device metada which is send to the GC gateway
* @param partialCreditCardNumber, entered partial creditcardnumber
* @param paymentContext, meta data for the payment that is used to get contextual information from the GC gateway
*
* @return IinDetailsResponse which contains the result of the IIN lookup, or null when an error has occured
*/
public IinDetailsResponse getPaymentProductIdByCreditCardNumber(String partialCreditCardNumber, Context context, PaymentContext paymentContext) {
if (partialCreditCardNumber == null) {
throw new InvalidParameterException("Error getting IinDetails, partialCreditCardNumber may not be null");
}
// Trim partialCreditCardNumber to MAX_CHARS_PAYMENT_PRODUCT_ID_LOOKUP digits
if (partialCreditCardNumber.length() > MAX_CHARS_PAYMENT_PRODUCT_ID_LOOKUP) {
partialCreditCardNumber = partialCreditCardNumber.substring(0, MAX_CHARS_PAYMENT_PRODUCT_ID_LOOKUP);
}
HttpURLConnection connection = null;
try {
// Construct the url for the IIN details call
String paymentProductPath = Constants.GC_GATEWAY_IIN_LOOKUP_PATH.replace("[cid]", configuration.getCustomerId());
String url = configuration.getBaseUrl() + paymentProductPath;
// Serialise the IinDetailsRequest to json, so it can be added to the postbody
IinDetailsRequest iinRequest = new IinDetailsRequest(partialCreditCardNumber, paymentContext);
String iinRequestJson = gson.toJson(iinRequest);
// Do the call and deserialise the result to IinDetailsResponse
connection = doHTTPPostRequest(url, configuration.getClientSessionId(), configuration.getMetadata(context), iinRequestJson);
String responseBody = new Scanner(connection.getInputStream(), "UTF-8").useDelimiter("\\A").next();
// Log the response
if (Constants.ENABLE_REQUEST_LOGGING) {
logResponse(connection, responseBody);
}
IinDetailsResponse iinResponse = gson.fromJson(responseBody, IinDetailsResponse.class);
return iinResponse;
} catch (Exception e) {
Log.i(TAG, "Error getting PaymentProductIdByCreditCardNumber response:" + e.getMessage());
return null;
} finally {
try {
if (connection != null) {
connection.getInputStream().close();
connection.disconnect();
}
} catch (IOException e) {
Log.i(TAG, "Error while getting PaymentProductIdByCreditCardNumber response:" + e.getMessage());
}
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.iin.IinDetailsResponse in project connect-sdk-client-android by Ingenico-ePayments.
the class WriteInternalStorage method storeIinResponseInCache.
/**
* Stores the given iinResponses in the cache on disk
*
* @param context, used for writing files
* @param partialCreditCardNumber, entered partial creditcardnumber
* @param IinDetailsResponse, the IinDetailsResponse which is added to the current cache
*/
public void storeIinResponseInCache(String partialCreditCardNumber, IinDetailsResponse iinResponse) {
if (partialCreditCardNumber == null) {
throw new InvalidParameterException("Error storing response in partialCreditCardNumber, context may not be null");
}
if (iinResponse == null) {
throw new InvalidParameterException("Error storing response in iinResponse, iinResponse may not be null");
}
// Retrieve the currenct cached items and add the new one to it
Map<String, IinDetailsResponse> currentCachedIinResponses = storage.getIinResponsesFromCache();
// Overwrite old value if it exists
if (currentCachedIinResponses.containsKey(partialCreditCardNumber)) {
currentCachedIinResponses.remove(partialCreditCardNumber);
}
currentCachedIinResponses.put(partialCreditCardNumber, iinResponse);
// Then write the currentCachedIinResponses to disk
String directory = context.getFilesDir() + Constants.DIRECTORY_IINRESPONSES;
File file = new File(directory, Constants.FILENAME_IINRESPONSE_CACHE);
file.getParentFile().mkdirs();
FileOutputStream fileOutputStream = null;
ObjectOutputStream objectOutputStream = null;
try {
fileOutputStream = new FileOutputStream(file);
objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(currentCachedIinResponses);
} catch (StreamCorruptedException e) {
Log.e(TAG, "Error storing BasicPaymentProducts on internal device storage", e);
} catch (IOException e) {
Log.e(TAG, "Error storing BasicPaymentProducts on internal device storage", e);
} finally {
try {
objectOutputStream.close();
fileOutputStream.close();
} catch (IOException e) {
}
}
}
Aggregations