From c51919107eda89cf399a2c0be831baa9a742b385 Mon Sep 17 00:00:00 2001 From: Jgadeesh Aluri Date: Thu, 8 Jun 2017 17:28:48 -0400 Subject: [PATCH] added payment method in tokenization response --- app/build.gradle | 2 +- .../com/aol/obi/android/lib/EncryptCard.java | 40 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9d20755..9ef944b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'signing' group = "com.aol.obi" archivesBaseName = "android-tokenization-lib" -version = "1.0" +version = "1.1" android { compileSdkVersion 25 diff --git a/app/src/main/java/com/aol/obi/android/lib/EncryptCard.java b/app/src/main/java/com/aol/obi/android/lib/EncryptCard.java index ab290a4..a885104 100644 --- a/app/src/main/java/com/aol/obi/android/lib/EncryptCard.java +++ b/app/src/main/java/com/aol/obi/android/lib/EncryptCard.java @@ -25,6 +25,7 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.util.UUID; @@ -56,6 +57,7 @@ public static String encryptCard(String cardNumber, String cardCvv, String domai String cardNumberWithCvv = cardNumber + ";" + cardCvv; String encodedCardNumber = EncryptCard.encrypt(cardNumberWithCvv, reqToken); + String cardType = getCardType(cardNumber); TokenizePaymentMethod tokenizePaymentMethod = new TokenizePaymentMethod(); @@ -90,7 +92,17 @@ public static String encryptCard(String cardNumber, String cardCvv, String domai JSONObject oneObjectData = jObjectTokenizedPaymentMethod.getJSONObject("data"); JSONObject oneObjectResponse = oneObjectData.getJSONObject("m:tokenizePaymentMethodResponse"); - return oneObjectResponse.getString("m:result")+";"+reqToken; + String fullResult = oneObjectResponse.getString("m:result")+";"+reqToken+";;"+cardType; + String encodedFullResult = ""; + + try { + byte[] fullResultByte = fullResult.getBytes("UTF-8"); + encodedFullResult = Base64.encodeToString(fullResultByte, Base64.NO_WRAP); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + return encodedFullResult; } catch (JSONException e) { e.printStackTrace(); @@ -138,6 +150,32 @@ private static byte[] getPaddedByte(byte[] inp) { return in; } + private static String getCardType(String cardNumber) { + String cardType = ""; + + if (cardNumber.length() > 2) { + if (cardNumber.startsWith("4")) { + cardType = "VISA"; + } else if((Short.valueOf(cardNumber.substring(0, 2))>=51 && Short.valueOf(cardNumber.substring(0, 2))<=55) || + (Short.valueOf(cardNumber.substring(0, 4))>=2221 && Short.valueOf(cardNumber.substring(0, 4))<=2720)){ + cardType = "MASTER_CARD"; + }else if ( cardNumber.startsWith("34") || cardNumber.startsWith("37") ) { + cardType = "AMERICAN_EXPRESS"; + } else if ( (Integer.parseInt(cardNumber.substring(0, 3)) > 299 && + Integer.parseInt(cardNumber.substring(0, 3)) < 306 ) || + cardNumber.startsWith("36") || cardNumber.startsWith("38") ) { + cardType = "DINERS CLUB"; + } else if ( cardNumber.startsWith("6011") || cardNumber.startsWith("65") ) { + cardType = "DISCOVER"; + } else if ( cardNumber.startsWith("1800") || cardNumber.startsWith("2131") || + cardNumber.startsWith("35")) { + cardType = "JCB"; + } + } + + return cardType; + } + private static class TokenizePaymentMethod extends AsyncTask { @Override