-
public class PayuUtilsCreated by franklin on 6/18/15. Payu util class provides protected, public functions to sdk and App. Use the SBI_MAES_BIN set to find whether the number is state bank maestro number or not Use the validateCardNumber method to validate user card number, it includes length luhn validation. Use the luhn method to validate card number, use this function only if you validate length at your end. Use the getIssuer method to get the issuer, it will return the issuer from {VISA, AMEX, MAES, MAST, SMAE, LASER, DINR, JCB} use the validateCvv method to validate cvv, AMEX has 4 digit, SMAE has no cvv, other has 3 dight cvv. use the validateExpiry method to validate whether the card is expired or not!. use the concatParams method to concat both params1 and param2 using equal to (=) and add a ampersand at the end! adding default argumentsgetReturnDatagetReturnData use the getReturnData to send the data back to app as PostData use the trimAmpersand remove leading ampersand if any!.
-
-
Field Summary
Fields Modifier and Type Field Description public static StringcbVersionpublic static Set<String>SBI_MAES_BIN
-
Method Summary
Modifier and Type Method Description BooleanvalidateCardNumber(String cardNumber)includes length validation alsouse luhn to validate. Booleanluhn(String cardNumber)Universal luhn validation for Credit, Debit cards. StringgetIssuer(String mCardNumber)Gives the Issuer of the card number. booleanvalidateCvv(String cardNumber, String cvv)helps to validate cvvwe need card bin to figure out issuer,from issuer we validate cvvOh! booleanvalidateExpiry(int expiryMonth, int expiryYear)helps to validate whether the card is expired or not!. voiddeviceAnalytics(Context context, String merchantKey, String transactionId)convert params to json object, and call device analytics voidstoreInSharedPreferences(Context context, String key, String value)Store key value pair in shared preference StringgetFromSharedPreferences(Context context, String key)Get the value for the provided key from shared preference StringgetFromSharedPreferences(Context context, String key, String defaultValue)voidremoveFromSharedPreferences(Context context, String key)Delete the key from shared preference HashMap<String, ArrayList<StoredCard>>getStoredCard(Context context, ArrayList<StoredCard> cardList)Segregate onclick payment cards and stored cards. HashMap<String, ArrayList<StoredCard>>getStoredCard(ArrayList<StoredCard> cardList)Segregate onclick payment cards and stored cardsShould be used when STORE_ONE_CLICK_HASH_SERVER static voidsetAnalyticsKeyCB(PayuConfig payuConfig)set the analytics key for the analytics of events and device static voidsetAnalyticsKeyCB(String analyticsKey)set the analytics key for the analytics of events and device static voidsetVariableCB(String pakageName, HashMap<String, String> cbAnalyticsKeys, String Version)TransactionResponsegetTransactionResponse(String transactionRespObj)JSONObjectgetTransactionResponseJson(JSONObject transactionRespObj)StringgetUdid()Phone's UDID, will be required in every communication with payu server. static HttpsURLConnectiongetHttpsConn(String strURL, String postData)*Return HttpsURLConnection object static HttpsURLConnectiongetHttpsConn(String strURL, String postData, String requestProperty)*Return HttpsURLConnection object static HttpsURLConnectiongetHttpsConn(String strURL, String postData, int timeout)*Return HttpsURLConnection object static HttpsURLConnectiongetHttpsConnForGetRequest(HttpRequest request)Return the connection object static StringgetAnalyticsString(String analyticsData)Return Analytics JSON String so as to append it to postdata BooleanvalidateCardNumber(String cardNumber, String issuer)static HttpsURLConnectiongetHttpsConn(HttpRequest request)*Return HttpsURLConnection object static StringBuffergetStringBuffer(HttpsURLConnection conn)static StringupdateAnalytics(String data)static StringgetPaymentTypeValue(String payMode)static voidsafeClose(InputStream inputStream)static StringreplaceString(String skuDetails, String key1, String key2)static doublegetDoubleValue(JSONObject value, String key)static StringgetStringValue(JSONObject value, String key)static URLgetApiV2Url(PayuConfig payuConfig)static StringBuildergetStringBuilder(HttpsURLConnection conn, Boolean handleStatusCode)static StringBuffergetStringBuffer(HttpsURLConnection conn, Boolean handleStatusCode)-
-
Method Detail
-
validateCardNumber
Boolean validateCardNumber(String cardNumber)
includes length validation alsouse luhn to validate.
- Parameters:
cardNumber- any card number
-
luhn
Boolean luhn(String cardNumber)
Universal luhn validation for Credit, Debit cards.
- Parameters:
cardNumber- any card number
-
getIssuer
String getIssuer(String mCardNumber)
Gives the Issuer of the card number.using simple regex we can actually figure out the card belong to which issuer amoung VISA, AMEX, MAES, MAST, SMAE, LASER, DINR, JCB
- Parameters:
mCardNumber- first 6 digit of card number is more than enough to figure out.
-
validateCvv
boolean validateCvv(String cardNumber, String cvv)
helps to validate cvvwe need card bin to figure out issuer,from issuer we validate cvvOh! AMEX has 4 digit,Crap! SMAE has no cvv,okay, other has 3 dight cvv.
- Parameters:
cardNumber- Card bincvv- cvv
-
validateExpiry
boolean validateExpiry(int expiryMonth, int expiryYear)
helps to validate whether the card is expired or not!.
- Parameters:
expiryMonth- expmonexpiryYear- expyr
-
deviceAnalytics
void deviceAnalytics(Context context, String merchantKey, String transactionId)
convert params to json object, and call device analytics
- Parameters:
context- base activity instancemerchantKey- merchant keytransactionId- transaction id
-
storeInSharedPreferences
void storeInSharedPreferences(Context context, String key, String value)
Store key value pair in shared preference
- Parameters:
context- activity instancekey- key for shared preferencevalue- value of the corresponding key
-
getFromSharedPreferences
String getFromSharedPreferences(Context context, String key)
Get the value for the provided key from shared preference
- Parameters:
context- base activity contextkey- shared preference key
-
getFromSharedPreferences
String getFromSharedPreferences(Context context, String key, String defaultValue)
- Parameters:
context- base activity contextkey- shared preference keydefaultValue- default value
-
removeFromSharedPreferences
void removeFromSharedPreferences(Context context, String key)
Delete the key from shared preference
- Parameters:
context- base activity contextkey- shared preference key
-
getStoredCard
HashMap<String, ArrayList<StoredCard>> getStoredCard(Context context, ArrayList<StoredCard> cardList)
Segregate onclick payment cards and stored cards.should be used when STORE_ONE_CLICK_HASH_MOBILE
- Parameters:
context- app contextcardList- list of cards get from payu serverHash map ONE_CLICK_CHECKOUT - one click cardsHash map STORED_CARD - stored cards
-
getStoredCard
HashMap<String, ArrayList<StoredCard>> getStoredCard(ArrayList<StoredCard> cardList)
Segregate onclick payment cards and stored cardsShould be used when STORE_ONE_CLICK_HASH_SERVER
- Parameters:
cardList- list of stored cards received from payu serverHash map ONE_CLICK_CHECKOUT - one click cardsHash map STORED_CARD - stored cards
-
setAnalyticsKeyCB
static void setAnalyticsKeyCB(PayuConfig payuConfig)
set the analytics key for the analytics of events and device
- Parameters:
payuConfig- payment params
-
setAnalyticsKeyCB
static void setAnalyticsKeyCB(String analyticsKey)
set the analytics key for the analytics of events and device
- Parameters:
analyticsKey- analytics key
-
setVariableCB
static void setVariableCB(String pakageName, HashMap<String, String> cbAnalyticsKeys, String Version)
-
getTransactionResponse
TransactionResponse getTransactionResponse(String transactionRespObj)
-
getTransactionResponseJson
JSONObject getTransactionResponseJson(JSONObject transactionRespObj)
-
getHttpsConn
static HttpsURLConnection getHttpsConn(String strURL, String postData)
*Return HttpsURLConnection object
- Parameters:
strURL- postURLpostData- data to be posted
-
getHttpsConn
static HttpsURLConnection getHttpsConn(String strURL, String postData, String requestProperty)
*Return HttpsURLConnection object
- Parameters:
strURL- postURLpostData- data to be posted
-
getHttpsConn
static HttpsURLConnection getHttpsConn(String strURL, String postData, int timeout)
*Return HttpsURLConnection object
- Parameters:
strURL- postURLpostData- data to be postedtimeout- timeout
-
getHttpsConnForGetRequest
static HttpsURLConnection getHttpsConnForGetRequest(HttpRequest request)
Return the connection object
- Parameters:
request- HttpRequest
-
getAnalyticsString
static String getAnalyticsString(String analyticsData)
Return Analytics JSON String so as to append it to postdata
-
validateCardNumber
Boolean validateCardNumber(String cardNumber, String issuer)
-
getHttpsConn
static HttpsURLConnection getHttpsConn(HttpRequest request)
*Return HttpsURLConnection object
- Parameters:
request- HttpRequest
-
getStringBuffer
static StringBuffer getStringBuffer(HttpsURLConnection conn)
- Parameters:
conn- HttpsURLConnection
-
updateAnalytics
static String updateAnalytics(String data)
-
getPaymentTypeValue
static String getPaymentTypeValue(String payMode)
-
safeClose
static void safeClose(InputStream inputStream)
-
replaceString
static String replaceString(String skuDetails, String key1, String key2)
-
getDoubleValue
static double getDoubleValue(JSONObject value, String key)
-
getStringValue
static String getStringValue(JSONObject value, String key)
-
getApiV2Url
static URL getApiV2Url(PayuConfig payuConfig)
-
getStringBuilder
static StringBuilder getStringBuilder(HttpsURLConnection conn, Boolean handleStatusCode)
-
getStringBuffer
static StringBuffer getStringBuffer(HttpsURLConnection conn, Boolean handleStatusCode)
-
-
-
-