Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Commit

Permalink
added payment method in tokenization response
Browse files Browse the repository at this point in the history
  • Loading branch information
jagadeeshaluri00 committed Jun 8, 2017
1 parent a1b6bd1 commit c519191
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'signing'

group = "com.aol.obi"
archivesBaseName = "android-tokenization-lib"
version = "1.0"
version = "1.1"

android {
compileSdkVersion 25
Expand Down
40 changes: 39 additions & 1 deletion app/src/main/java/com/aol/obi/android/lib/EncryptCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<String, Void, String > {

@Override
Expand Down

0 comments on commit c519191

Please sign in to comment.