use of com.globalcollect.gateway.sdk.client.android.sdk.model.iin.IinDetailsRequest 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());
}
}
}
Aggregations