Skip to content

Commit

Permalink
Merge pull request #7 from processout/3ds1
Browse files Browse the repository at this point in the history
3ds1: add support for 3DS1 fallback
  • Loading branch information
jlejoux authored Jul 29, 2019
2 parents cc9cb5b + 2323c3e commit b2ffd1b
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.processout.processout_sdk.Card;
import com.processout.processout_sdk.ProcessOut;
import com.processout.processout_sdk.TokenCallback;

import com.processout.processout_sdk.WebViewReturnAction;


public class MainActivity extends AppCompatActivity {
Expand All @@ -25,14 +25,32 @@ protected void onCreate(Bundle savedInstanceState) {
Uri data = intent.getData();
if (data == null)
this.initiatePayment();
else
Log.d("PROCESSOUT", "TOKEN=" + data.getQueryParameter("token"));
else {
// Check if the activity has been opened from ProcessOut
WebViewReturnAction returnAction = ProcessOut.handleProcessOutReturn(data);
if (returnAction == null) {
// Opening URI is not from ProcessOut
} else {
switch (returnAction.getType()) {
case APMAuthorization:
// Value contains the APM token
if (returnAction.isSuccess())
Log.d("PROCESSOUT", returnAction.getValue());
break;
case ThreeDSVerification:
// Value contains the invoice_id
if (returnAction.isSuccess())
Log.d("PROCESSOUT", returnAction.getValue());
break;
}
}
}
}

public void initiatePayment() {
final ProcessOut p = new ProcessOut(this, "test-proj_WijDbvE1oEkS67ikx2cfu25Nr5Qx4emX");
Card c = new Card("4000000000003063", 10, 20, "737");
p.tokenize(c,null, new TokenCallback() {
Card c = new Card("4000000000003246", 10, 20, "737");
p.tokenize(c, null, new TokenCallback() {
@Override
public void onError(Exception error) {
Log.e("PROCESSOUT", error.toString());
Expand All @@ -43,7 +61,7 @@ public void onSuccess(String token) {
p.makeCardPayment("invoice-id", token, ProcessOut.createDefaultTestHandler(MainActivity.this, new ProcessOut.ThreeDSHandlerTestCallback() {
@Override
public void onSuccess(String invoiceId) {
Log.d("PROCESSOUT", "invocie: " + invoiceId);
Log.d("PROCESSOUT", "invoice: " + invoiceId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.processout.processout_sdk;

import com.google.gson.annotations.SerializedName;
import com.processout.processout_sdk.CustomerAction;

class AuthorizationResult {
@SerializedName("customer_action")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.processout.processout_sdk;

import android.util.Base64;

import com.google.gson.annotations.SerializedName;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import android.content.Context;
import android.util.Base64;
import android.util.Log;

import com.android.volley.AuthFailureError;
import com.android.volley.NetworkError;
import com.android.volley.NoConnectionError;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.ServerError;
Expand All @@ -24,7 +22,6 @@
import com.processout.processout_sdk.ProcessOutExceptions.ProcessOutException;
import com.processout.processout_sdk.ProcessOutExceptions.ProcessOutNetworkException;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -77,6 +74,8 @@ public void onErrorResponse(VolleyError error) {
} catch (UnsupportedEncodingException e) {
callback.onError(e);
}
} else {
callback.onError(new ProcessOutNetworkException("Could not receive server data."));
}
} else if (error instanceof NetworkError) {
callback.onError(new ProcessOutNetworkException("Could not connect to server"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.util.Base64;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.android.volley.Request;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.processout.processout_sdk.ProcessOutExceptions.ProcessOutAuthException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Map;

/**
* Created by jeremylejoux on 17/01/2018.
Expand Down Expand Up @@ -205,7 +207,6 @@ private void handleAuthorizationResult(
}

// Customer action required
Type mapType = new TypeToken<Map<String, String>>() {}.getType();
switch (cA.getType()) {
case FINGERPRINT_MOBILE:
DirectoryServerData directoryServerData = gson.fromJson(new String(Base64.decode(cA.getValue().getBytes(), Base64.NO_WRAP)), DirectoryServerData.class);
Expand All @@ -232,18 +233,53 @@ public void error() {
}
});
break;
case URL:
WebView theWebPage = new WebView(this.context);
theWebPage.getSettings().setJavaScriptEnabled(true);
theWebPage.getSettings().setPluginState(WebSettings.PluginState.ON);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(cA.getValue()));
this.context.startActivity(browserIntent);
break;
default:
//TODO: handle FINGERPRINT, URL and REDIRECT for mobiles that don't support 3ds2 challenges
handler.onError(null);
handler.onError(new ProcessOutAuthException("Unhandled three D S action:" + cA.getType().name()));
break;
}
}


/**
* Checks if the opening URL is from ProcessOut and returns the corresponding value if so. Returns null otherwise
*
* @param intentData intentData from the Activity
* @return A WebViewReturnAction containing the return type, value and success or null if not from ProcessOut
*/
public static WebViewReturnAction handleProcessOutReturn(Uri intentData) {
if (intentData.getHost().compareToIgnoreCase("processout.return") != 0)
return null;

String token = intentData.getQueryParameter("token");
if (token != null)
return new WebViewReturnAction(true, WebViewReturnAction.WebViewReturnType.APMAuthorization, token);

String threeDSStatus = intentData.getQueryParameter("three_d_s_status");
if (threeDSStatus != null) {
switch (threeDSStatus) {
case "success":
return new WebViewReturnAction(true, WebViewReturnAction.WebViewReturnType.ThreeDSVerification, intentData.getQueryParameter("invoice_id"));
default:
return new WebViewReturnAction(false, WebViewReturnAction.WebViewReturnType.ThreeDSVerification, null);
}
}

return null;
}

public interface ThreeDSHandlerTestCallback {
void onSuccess(String invoiceId);

void onError(Exception error);
}

/**
* Generate a test ThreeDSHandler for 3DS2 challenges
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.processout.processout_sdk;

public class WebViewReturnAction {

public enum WebViewReturnType {
APMAuthorization,
ThreeDSVerification,
}

private boolean success;
private WebViewReturnType type;
private String value;

public WebViewReturnAction(boolean success, WebViewReturnType type, String value) {
this.success = success;
this.type = type;
this.value = value;
}

public boolean isSuccess() {
return success;
}

public WebViewReturnType getType() {
return type;
}

public String getValue() {
return value;
}
}

0 comments on commit b2ffd1b

Please sign in to comment.