Skip to content

Commit 7b8f05c

Browse files
Merge pull request #128 from xendit/fix/unexpected_3ds_response
fix: Handle 3DS authentication edge case and version tracking
2 parents e9d45eb + d34cdbe commit 7b8f05c

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

Diff for: xendit-android/src/main/java/com/xendit/Xendit.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public class Xendit {
7575
private static final String GET_3DS_URL = PRODUCTION_XENDIT_BASE_URL + "/3ds_bin_recommendation";
7676
private static final String DSN_SERVER = "https://[email protected]/6314580";
7777
private static final String CLIENT_IDENTIFIER = "Xendit Android SDK";
78-
private static final String CLIENT_API_VERSION = "2.0.0";
7978
private static final String CLIENT_TYPE = "SDK";
8079
static final String ACTION_KEY = "ACTION_KEY";
8180

@@ -1499,7 +1498,7 @@ private BaseRequest buildBaseRequest(int method, String url, String onBehalfOf,
14991498
}
15001499
request.addHeader("Authorization", basicAuthCredentials.replace("\n", ""));
15011500
request.addHeader("x-client-identifier", CLIENT_IDENTIFIER);
1502-
request.addHeader("client-version", CLIENT_API_VERSION);
1501+
request.addHeader("client-version", BuildConfig.VERSION_NAME);
15031502
request.addHeader("client-type", CLIENT_TYPE);
15041503
return request;
15051504
}

Diff for: xendit-android/src/main/java/com/xendit/XenditActivity.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import android.webkit.WebView;
1414
import android.webkit.WebViewClient;
1515
import android.widget.ProgressBar;
16-
1716
import com.xendit.Models.HasAuthenticationUrl;
17+
import com.xendit.utils.Auth3DSEventValidator;
1818

1919
/**
2020
* Created by Sergey on 3/23/17.
@@ -99,9 +99,10 @@ public void postMessage(String message) {
9999
handler.post(new Runnable() {
100100
@Override
101101
public void run() {
102-
sendBroadcastReceiver(message);
103-
104-
finish();
102+
if (Auth3DSEventValidator.is3DSResultEventFromXendit(message, XenditActivity.this)) {
103+
sendBroadcastReceiver(message);
104+
finish();
105+
}
105106
}
106107
});
107108
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.xendit.utils;
2+
3+
import android.content.Context;
4+
import com.google.gson.Gson;
5+
import com.google.gson.reflect.TypeToken;
6+
import com.xendit.R;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
public class Auth3DSEventValidator {
11+
private static final String ID_FIELD = "id";
12+
private static final String STATUS_FIELD = "status";
13+
14+
private Auth3DSEventValidator() {
15+
// Private constructor to prevent instantiation
16+
}
17+
18+
public static boolean is3DSResultEventFromXendit(String message, Context context) {
19+
if (message.isEmpty()) return false;
20+
21+
return isValidJsonMessage(message) || isKnownErrorMessage(message, context);
22+
}
23+
24+
private static boolean isValidJsonMessage(String message) {
25+
try {
26+
Map<String, Object> messageInJson = new Gson().fromJson(
27+
message,
28+
new TypeToken<HashMap<String, Object>>() {}.getType()
29+
);
30+
31+
// A valid 3ds callback payload from Xendit, should contain required fields: id and status.
32+
return messageInJson.get(ID_FIELD) != null && messageInJson.get(STATUS_FIELD) != null;
33+
} catch (Exception e) {
34+
return false;
35+
}
36+
}
37+
38+
private static boolean isKnownErrorMessage(String message, Context context) {
39+
return message.equals(context.getString(R.string.create_token_error_validation)) ||
40+
message.equals(context.getString(R.string.tokenization_error));
41+
}
42+
43+
}

0 commit comments

Comments
 (0)