Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ext {
siteUrl = 'https://github.com/AuthorizeNet/cybersource-android-sdk'
gitUrl = 'https://github.com/AuthorizeNet/cybersource-android-sdk.git'

libraryVersion = '1.0.0'
libraryVersion = '2.0.0'
localReleaseDest = "${buildDir}/release/${libraryVersion}"

developerId = 'fezzubair'
Expand Down Expand Up @@ -44,14 +44,19 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
versionCode 2
versionName "2.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests {
Expand Down
4 changes: 2 additions & 2 deletions proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
public protected *;
}

-keep class com.visa.inappsdk.connectors.inapp.InAppGateway
-keep class InAppGateway

-keepclassmembernames class * {
java.lang.Class class$(java.lang.String);
java.lang.Class class$(java.lang.String, boolean);
}

-keepclassmembers class com.visa.inappsdk.connectors.inapp.InAppSDKApiClient
-keepclassmembers class InAppSDKApiClient

-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.cybersource.inappsdk.common.utils;

import java.math.BigDecimal;

import static java.math.BigDecimal.ZERO;

/*
* @author fzubair
*/

public class SDKMathUtils {

/** used to calculate the percentage **/
private static BigDecimal HUNDRED = new BigDecimal("100");

/** number of decimals returned **/
private static int DECIMALS = 2;

/**
* given an amount and a percentage, the method calculates the percentage
* using BigDecimal numbers
*
* @param amount
* @param percentage
* @return the percentage of the amount input
*/
public static BigDecimal calculatePercentage(BigDecimal amount, BigDecimal percentage) {
if (isZero(percentage) || (amount == null)) {
return ZERO;
}

BigDecimal fractionalChange = amount.multiply(percentage).divide(HUNDRED);

return fractionalChange.setScale(DECIMALS, BigDecimal.ROUND_HALF_UP);
}

/**
* r checks if "number" equals zero
*
* @param number
* @return true if number equals zero, false otherwise
*/
public static boolean isZero(BigDecimal number) {
if (number == null) {
number = BigDecimal.ZERO;
}
return number.compareTo(BigDecimal.ZERO) == 0;
}

/**
* adds two BigDecimals and returns the total
*
* @param number1
* @param number2
* @return total
*/
public static BigDecimal add(BigDecimal number1, BigDecimal number2) {
if (number1 == null) {
number1 = BigDecimal.ZERO;
}
if (number2 == null) {
number2 = BigDecimal.ZERO;
}
return number1.add(number2).setScale(DECIMALS, BigDecimal.ROUND_HALF_UP);
}

/**
* substracts trwo BigDecimal numbers
*
* @param number1
* @param number2
* @return result of the subtraction
*/
public static BigDecimal substract(BigDecimal number1, BigDecimal number2) {
if (number1 == null) {
number1 = BigDecimal.ZERO;
}
if (number2 == null) {
number2 = BigDecimal.ZERO;
}
return number1.subtract(number2).setScale(DECIMALS, BigDecimal.ROUND_HALF_UP);
}

}
71 changes: 40 additions & 31 deletions src/main/java/com/cybersource/inappsdk/common/utils/SDKUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cybersource.inappsdk.common.utils;

import android.text.TextUtils;
import android.util.Base64;

import com.cybersource.inappsdk.common.SDKCore;
import com.cybersource.inappsdk.common.SDKCurrency;
Expand All @@ -20,6 +21,7 @@
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
Expand Down Expand Up @@ -80,6 +82,10 @@ public class SDKUtils {
/** Port: 443 */
private final static int PORT_443 = 443;

/** SEC PUBLIC KEY **/
public static String PUBLIC_KEY = null;


/**
* This method checks if given class exists basing on its name. If it does
* exist it also checks if conforms to a given class type.
Expand Down Expand Up @@ -240,7 +246,8 @@ public static HttpsURLConnection getHttpsURLConnection(String urlString, String
urlConnection.setReadTimeout(RECIEVE_DATA_TIMEOUT);
urlConnection.setDoOutput(doOutput);
urlConnection.setDoInput(true);
//android.util.Log.d("VMposUtils", "Connection: " + requestMethod + " -to- " + urlString);
android.util.Log.d("SDKUtils", "Connection: " + requestMethod + " -to- " + urlString);

return urlConnection;
}

Expand Down Expand Up @@ -323,36 +330,6 @@ public void checkServerTrusted(X509Certificate[] certs, String authType)
}
}

/* public static HttpClient getHttpClientWithSSLSupport() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);

SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);


HttpParams params = new BasicHttpParams();
params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, CONNECTION_ATTEPTS);
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(CONNECTION_ATTEPTS));
params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, RECIEVE_DATA_TIMEOUT);

SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), PORT_80));
registry.register(new Scheme("https", sf, PORT_443));

ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}*/

private static class MySSLSocketFactory extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");

Expand Down Expand Up @@ -486,5 +463,37 @@ public static String getGatewayAmountStringFromBigDecimal(BigDecimal value){
BigDecimal amount = value.setScale(2, RoundingMode.CEILING);
return amount.toPlainString();
}


public static String getBase64Blob(String token) {
byte[] encodedTokenBytes = Base64.encode(token.getBytes(), Base64.NO_WRAP);
String encodedToken = new String(encodedTokenBytes);
return encodedToken;
}

/* private String createSecServiceJson(String androidPayBlob){
String secBlob = "{\"publicKeyHash\": \"" + getPublicKeyHash() + "\"," +
"\"version\": \"1.0\"," +
"\"data\":" + "\"" + androidPayBlob + "\"}";
return secBlob;
}*/

/**
* Uses the public passed in by client code through SDK API Client
* @return hashed sec public key
*/
public static String getPublicKeyHash() {
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
byte[] publicKeyHash;
byte[] pubKeyBytes = Base64.decode(PUBLIC_KEY, Base64.NO_WRAP);
publicKeyHash = digest.digest(pubKeyBytes);
String publicKeyHashString = new String(Base64.encode(publicKeyHash, Base64.NO_WRAP));
return publicKeyHashString;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
import android.os.ResultReceiver;
import android.util.Xml;

import com.cybersource.inappsdk.connectors.inapp.envelopes.InAppBaseEnvelope;
import com.cybersource.inappsdk.soap.connection.SDKConnectionConstants;
import com.cybersource.inappsdk.soap.parser.SDKSoapParser;
import com.cybersource.inappsdk.common.error.SDKError;
import com.cybersource.inappsdk.common.error.SDKGatewayError;
import com.cybersource.inappsdk.common.error.SDKInternalError;
import com.cybersource.inappsdk.common.utils.SDKUtils;
import com.cybersource.inappsdk.connectors.inapp.connection.InAppConnectionData;
import com.cybersource.inappsdk.connectors.inapp.envelopes.InAppBaseEnvelope;
import com.cybersource.inappsdk.connectors.inapp.receivers.TransactionResultReceiver;
import com.cybersource.inappsdk.connectors.inapp.responses.InAppResponseObject;
import com.cybersource.inappsdk.datamodel.SDKGatewayErrorMapping;
import com.cybersource.inappsdk.datamodel.response.SDKGatewayResponse;
import com.cybersource.inappsdk.soap.connection.SDKConnectionConstants;
import com.cybersource.inappsdk.soap.parser.SDKSoapParser;

import java.io.BufferedWriter;
import java.io.IOException;
Expand Down Expand Up @@ -170,6 +170,7 @@ protected void onPostHandleAction(Object result, ResultReceiver resultReceiver)
SDKGatewayResponse response = (SDKGatewayResponse)result;
resultData.putParcelable(SERVICE_RESULT_RESPONSE_KEY, response);
switch (response.getType()) {
case SDK_ANDROID_PAY:
case SDK_ENCRYPTION:
resultReceiver.send(SERVICE_RESULT_CODE_SDK_RESPONSE, resultData);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import android.os.Bundle;
import android.os.Handler;

import com.cybersource.inappsdk.connectors.inapp.envelopes.InAppAndroidPayEnvelope;
import com.cybersource.inappsdk.connectors.inapp.transaction.client.InAppTransaction;
import com.cybersource.inappsdk.datamodel.SDKGateway;
import com.cybersource.inappsdk.datamodel.transaction.callbacks.SDKApiConnectionCallback;
import com.cybersource.inappsdk.common.error.SDKError;
import com.cybersource.inappsdk.connectors.inapp.envelopes.InAppEncryptEnvelope;
import com.cybersource.inappsdk.connectors.inapp.receivers.TransactionResultReceiver;
import com.cybersource.inappsdk.datamodel.SDKGateway;
import com.cybersource.inappsdk.datamodel.response.SDKGatewayResponse;
import com.cybersource.inappsdk.datamodel.transaction.SDKTransactionObject;
import com.cybersource.inappsdk.datamodel.transaction.callbacks.SDKApiConnectionCallback;

/**
* Created by fzubair on 10/6/2015.
Expand All @@ -30,7 +31,7 @@ public static InAppGateway getGateway() {
}

@Override
protected boolean performEncryption(SDKTransactionObject transactionObject, SDKApiConnectionCallback applicationConnectionCallback) {
protected boolean performEncryption(InAppTransaction transactionObject, SDKApiConnectionCallback applicationConnectionCallback) {
if(transactionInProgress)
return transactionInProgress;
if (transactionObject == null)
Expand All @@ -47,6 +48,24 @@ protected boolean performEncryption(SDKTransactionObject transactionObject, SDKA
return transactionInProgress;
}

@Override
protected boolean performAndroidPayTransaction(InAppTransaction transactionObject, SDKApiConnectionCallback applicationConnectionCallback) {
if(transactionInProgress)
return transactionInProgress;
if (transactionObject == null)
return false;

registerResultReceiver();
transactionInProgress = true;
this.connectionCallback = applicationConnectionCallback;
InAppAndroidPayEnvelope envelope = new InAppAndroidPayEnvelope(transactionObject, merchantId,
messageSignature);
if (envelope == null)
return false;
InAppConnectionService.startActionConnect(InAppSDKApiClient.getContext().get(), envelope, resultReceiver);
return transactionInProgress;
}

private InAppGateway() {
}

Expand Down
Loading