Browse Source

Reject Broadcasts that come in when busy

hbw_build
Wong Joon Hui 2 years ago
parent
commit
58f6608411
  1. 48
      app/src/main/java/com/cst/im30/activity/MainActivity.java
  2. 6
      app/src/main/java/com/cst/im30/common/Constants.java
  3. 37
      app/src/main/java/com/cst/im30/service/IDVerificationService.java
  4. 31
      app/src/main/java/com/cst/im30/service/PaymentService.java

48
app/src/main/java/com/cst/im30/activity/MainActivity.java

@ -347,20 +347,22 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
private void receiveMessagePayment(Object... args) {
Logger.logD("Received Payment Message");
if (MainApplication.working) {
//todo hmmm
Logger.logE("Received Payment Message but IM30 is currently working!");
return;
}
JSONObject jsonObject = (JSONObject) args[1];
String data = null;
String data;
try {
data = jsonObject.getJSONObject("data").getString("code");
MainApplication.currentCode = data;
} catch (JSONException e) {
e.printStackTrace();
}
if (MainApplication.working) {
Logger.logE("Received Payment Message but IM30 is currently working!");
PaymentService service = new PaymentService(this);
service.verifyReject(MainApplication.currentCode);
return;
}
if (MainApplication.currentCode != null && !MainApplication.currentCode.isEmpty()) {
initViews();
PaymentService service = new PaymentService(this);
@ -373,20 +375,22 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
private void receiveMessageIC(Object... args) {
Logger.logD("Received IC Message");
if (MainApplication.working) {
//todo hmmm
Logger.logE("Received IC Verification Message but IM30 is currently working!");
return;
}
JSONObject jsonObject = (JSONObject) args[1];
String data = null;
String data;
try {
data = jsonObject.getJSONObject("data").getString("code");
MainApplication.currentCode = data;
} catch (JSONException e) {
e.printStackTrace();
}
if (MainApplication.working) {
Logger.logE("Received IC Verification Message but IM30 is currently working!");
IDVerificationService service = new IDVerificationService(this);
service.verifyReject(MainApplication.currentCode);
return;
}
if (MainApplication.currentCode != null && !MainApplication.currentCode.isEmpty()) {
initViews();
IDVerificationService service = new IDVerificationService(this);
@ -405,13 +409,13 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
Intent i = new Intent(MainActivity.this, ICCActivity.class);
icVerificationLauncher.launch(i);
} else if (source.equalsIgnoreCase(IDVerificationService.FAIL_GET_EVENT_LOG)) {
resetView(); //todo try again?
resetView(); //todo try again? fail?
}
else if (source.equalsIgnoreCase(IDVerificationService.SUCCESS_UPDATE_EVENT_LOG)) {
resetView();
} else if (source.equalsIgnoreCase(IDVerificationService.FAIL_UPDATE_EVENT_LOG)) {
resetView(); //todo try again?
resetView(); //todo try again? fail? (avoid infinite loop)
}
// Payment
@ -420,13 +424,21 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
paymentProcess(MainApplication.currentEventLogDetailed);
startWork();
} else if (source.equalsIgnoreCase(PaymentService.FAIL_GET_EVENT_LOG)) {
resetView(); //todo try again?
resetView(); //todo try again? ^
}
else if (source.equalsIgnoreCase(PaymentService.SUCCESS_UPDATE_EVENT_LOG)) {
resetView();
} else if (source.equalsIgnoreCase(PaymentService.FAIL_UPDATE_EVENT_LOG)) {
resetView(); //todo try again?
resetView(); //todo try again? ^
}
else if (source.equalsIgnoreCase(IDVerificationService.REJECT_EVENT_LOG)) {
String code = (String) object;
Logger.logI("Rejected Broadcast: " + code);
} else if (source.equalsIgnoreCase(PaymentService.REJECT_EVENT_LOG)) {
String code = (String) object;
Logger.logI("Rejected Broadcast: " + code);
}
}

6
app/src/main/java/com/cst/im30/common/Constants.java

@ -20,4 +20,10 @@ public class Constants {
public static final String PAY_FUNCTION_SET_DATE_TIME = "12";
public static final String PAY_FUNCTION_READ_CARD_INFORMATION = "13";
public static final String STATUS_SUCCESS = "success";
public static final String STATUS_FAIL = "fail";
public static final String STATUS_CANCELLED = "cancelled";
public static final String STATUS_REJECT = "reject";
}

37
app/src/main/java/com/cst/im30/service/IDVerificationService.java

@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
import com.cst.im30.BuildConfig;
import com.cst.im30.common.CallableInterface;
import com.cst.im30.common.Constants;
import com.cst.im30.model.EventLogDetailed;
import com.cst.im30.api.RetrofitAPICollection;
import com.cst.im30.api.RetrofitClient;
@ -24,12 +25,17 @@ public class IDVerificationService {
public static final String SUCCESS_UPDATE_EVENT_LOG = TAG + "SUCCESS_UPDATE_EVENT_LOG";
public static final String FAIL_UPDATE_EVENT_LOG = TAG + "FAIL_UPDATE_EVENT_LOG";
public static final String REJECT_EVENT_LOG = "REJECT";
private final CallableInterface callback;
private final String hostUrl;
private final String clientId;
private final String clientSecret;
private String code;
private String status;
public IDVerificationService(CallableInterface callback) {
this.callback = callback;
@ -39,7 +45,6 @@ public class IDVerificationService {
}
public void getEventLog(String code) {
RetrofitAPICollection service = RetrofitClient.getRetrofitClient(hostUrl).create(RetrofitAPICollection.class);
Call<String> call = service.getBroadcastEventLogDetails(clientId, clientSecret, code);
@ -83,12 +88,15 @@ public class IDVerificationService {
private void onFailureGetEventLog(Throwable t) {
if (t instanceof Exception) {
Logger.logE(t.getMessage());
((Exception) t).printStackTrace();
t.printStackTrace();
}
callback.callBack(FAIL_GET_EVENT_LOG, t.getMessage());
}
private void updateBroadcastEventLogDetail(String code, String status) {
this.code = code;
this.status = status;
JSONObject payload = new JSONObject();
try {
payload.put("status", status);
@ -112,7 +120,7 @@ public class IDVerificationService {
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
onFailureUpdateEventLog(t);
onFailureUpdateBroadcastEventLogDetails(t);
}
});
@ -129,8 +137,14 @@ public class IDVerificationService {
callback.callBack(FAIL_UPDATE_EVENT_LOG, responseJSON);
} else {
JSONObject responseJSON = new JSONObject(response.body());
Logger.logV(responseJSON.toString());
callback.callBack(SUCCESS_UPDATE_EVENT_LOG, responseJSON);
if (Constants.STATUS_REJECT.equalsIgnoreCase(status)) {
callback.callBack(REJECT_EVENT_LOG, code);
} else {
callback.callBack(SUCCESS_UPDATE_EVENT_LOG, responseJSON);
}
}
} catch (Exception e) {
Logger.logE(e.getMessage());
@ -138,25 +152,28 @@ public class IDVerificationService {
}
}
private void onFailureUpdateEventLog(Throwable t) {
private void onFailureUpdateBroadcastEventLogDetails(Throwable t) {
if (t instanceof Exception) {
Logger.logE(t.getMessage());
((Exception) t).printStackTrace();
t.printStackTrace();
}
callback.callBack(FAIL_UPDATE_EVENT_LOG, t.getMessage());
}
public void verifySuccess(String code) {
updateBroadcastEventLogDetail(code, "success");
updateBroadcastEventLogDetail(code, Constants.STATUS_SUCCESS);
}
public void verifyFail(String code) {
updateBroadcastEventLogDetail(code, "fail");
updateBroadcastEventLogDetail(code, Constants.STATUS_FAIL);
}
public void verifyCancel(String code) {
updateBroadcastEventLogDetail(code, "cancelled");
updateBroadcastEventLogDetail(code, Constants.STATUS_CANCELLED);
}
public void verifyReject(String code) {
updateBroadcastEventLogDetail(code, Constants.STATUS_REJECT);
}
private EventLogDetailed parseGetEventLogResponse(JSONObject jsonObject) throws Exception {

31
app/src/main/java/com/cst/im30/service/PaymentService.java

@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
import com.cst.im30.BuildConfig;
import com.cst.im30.common.CallableInterface;
import com.cst.im30.common.Constants;
import com.cst.im30.model.EventLogDetailed;
import com.cst.im30.api.RetrofitAPICollection;
import com.cst.im30.api.RetrofitClient;
@ -25,12 +26,17 @@ public class PaymentService {
public static final String SUCCESS_UPDATE_EVENT_LOG = TAG + "SUCCESS_UPDATE_EVENT_LOG";
public static final String FAIL_UPDATE_EVENT_LOG = TAG + "FAIL_UPDATE_EVENT_LOG";
public static final String REJECT_EVENT_LOG = "REJECT";
private final CallableInterface callback;
private final String hostUrl;
private final String clientId;
private final String clientSecret;
private String code;
private String status;
public PaymentService(CallableInterface callback) {
this.callback = callback;
@ -89,6 +95,9 @@ public class PaymentService {
}
private void updateBroadcastEventLogDetail(String code, String status) {
this.code = code;
this.status = status;
JSONObject payload = new JSONObject();
try {
payload.put("status", status);
@ -112,7 +121,7 @@ public class PaymentService {
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
onFailureUpdateEventLog(t);
onFailureUpdateBroadcastEventLogDetails(t);
}
});
}
@ -128,8 +137,14 @@ public class PaymentService {
callback.callBack(FAIL_UPDATE_EVENT_LOG, responseJSON);
} else {
JSONObject responseJSON = new JSONObject(response.body());
Logger.logV(responseJSON.toString());
callback.callBack(SUCCESS_UPDATE_EVENT_LOG, responseJSON);
if (Constants.STATUS_REJECT.equalsIgnoreCase(status)) {
callback.callBack(REJECT_EVENT_LOG, code);
} else {
callback.callBack(SUCCESS_UPDATE_EVENT_LOG, responseJSON);
}
}
} catch (Exception e) {
Logger.logE(e.getMessage());
@ -137,7 +152,7 @@ public class PaymentService {
}
}
private void onFailureUpdateEventLog(Throwable t) {
private void onFailureUpdateBroadcastEventLogDetails(Throwable t) {
if (t instanceof Exception) {
Logger.logE(t.getMessage());
((Exception) t).printStackTrace();
@ -146,15 +161,19 @@ public class PaymentService {
}
public void verifySuccess(String code) {
updateBroadcastEventLogDetail(code, "success");
updateBroadcastEventLogDetail(code, Constants.STATUS_SUCCESS);
}
public void verifyFail(String code) {
updateBroadcastEventLogDetail(code, "fail");
updateBroadcastEventLogDetail(code, Constants.STATUS_FAIL);
}
public void verifyCancel(String code) {
updateBroadcastEventLogDetail(code, "cancelled");
updateBroadcastEventLogDetail(code, Constants.STATUS_CANCELLED);
}
public void verifyReject(String code) {
updateBroadcastEventLogDetail(code, Constants.STATUS_REJECT);
}
private EventLogDetailed parseGetEventLogResponse(JSONObject jsonObject) {

Loading…
Cancel
Save