Create Transaction bug reset State
This commit is contained in:
parent
671b585fe5
commit
a38cea065f
@ -500,18 +500,54 @@ public class CreateTransactionActivity extends AppCompatActivity implements
|
||||
Log.e(TAG, "EMV Transaction failed: " + desc + " (Code: " + code + ")");
|
||||
|
||||
modalManager.hideModal();
|
||||
if (code == -50009) {
|
||||
// EMV process conflict - reset and retry
|
||||
Log.d(TAG, "EMV process conflict detected - resetting...");
|
||||
|
||||
// Handle specific error codes
|
||||
if (code == -4125) {
|
||||
showToast("Card not supported. Please try another card or insert chip.");
|
||||
performCompleteReset();
|
||||
} else if (code == -50009) {
|
||||
showToast("EMV busy, resetting...");
|
||||
resetEMVAndRetry();
|
||||
performCompleteReset();
|
||||
} else {
|
||||
// Other errors - show message and restart scanning
|
||||
showToast("Transaction failed: " + desc);
|
||||
restartScanningAfterDelay();
|
||||
performCompleteReset();
|
||||
}
|
||||
}
|
||||
|
||||
private void performCompleteReset() {
|
||||
Log.d(TAG, "Performing complete system reset...");
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
// 1. Stop all scanning
|
||||
if (cardScannerManager != null) {
|
||||
cardScannerManager.stopScanning();
|
||||
}
|
||||
Thread.sleep(500);
|
||||
|
||||
// 2. Reset EMV completely
|
||||
if (emvManager != null) {
|
||||
emvManager.resetEMVProcess();
|
||||
Thread.sleep(1000);
|
||||
emvManager.resetEMVProcess(); // Double reset
|
||||
}
|
||||
|
||||
// 3. Restart after proper delay
|
||||
runOnUiThread(() -> {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
if (!isFinishing()) {
|
||||
Log.d(TAG, "Complete reset done - restarting");
|
||||
startCardScanningFlow();
|
||||
}
|
||||
}, 3000); // 3 detik delay
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error in complete reset: " + e.getMessage());
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void showSuccessScreen(Runnable onAnimationComplete) {
|
||||
// Hide modal first
|
||||
modalManager.hideModal();
|
||||
|
@ -121,58 +121,68 @@ public class EMVManager {
|
||||
}
|
||||
|
||||
public void startEMVTransaction(String transactionAmount, int cardType) {
|
||||
if (mProcessStep != 0) {
|
||||
Log.d(TAG, "EMV transaction already in progress (step: " + mProcessStep + ") - ignoring call");
|
||||
return;
|
||||
// Force reset jika masih ada proses berjalan
|
||||
if (mProcessStep > 0) {
|
||||
Log.w(TAG, "Forcing EMV reset - previous step: " + mProcessStep);
|
||||
resetEMVProcess();
|
||||
try { Thread.sleep(1000); } catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
Log.d(TAG, "Starting EMV transaction process");
|
||||
Log.d(TAG, "Starting fresh EMV transaction");
|
||||
mProcessStep = 1;
|
||||
mCardType = cardType;
|
||||
|
||||
try {
|
||||
// Extended initialization
|
||||
mEMVOptV2.initEmvProcess();
|
||||
Thread.sleep(500);
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
try {
|
||||
if (mProcessStep <= 0) {
|
||||
Log.d(TAG, "EMV process was cancelled - not starting");
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("amount", transactionAmount);
|
||||
bundle.putString("transType", "00");
|
||||
bundle.putInt("flowType", AidlConstantsV2.EMV.FlowType.TYPE_EMV_STANDARD);
|
||||
bundle.putInt("cardType", mCardType);
|
||||
|
||||
Log.d(TAG, "Starting transactProcessEx with reset EMV");
|
||||
Log.d(TAG, "Starting EMV with reset state");
|
||||
mEMVOptV2.transactProcessEx(bundle, mEMVListener);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error in delayed EMV start: " + e.getMessage(), e);
|
||||
Log.e(TAG, "Error starting EMV: " + e.getMessage());
|
||||
if (callback != null) {
|
||||
callback.onTransactionFailed(-1, "Error starting EMV: " + e.getMessage());
|
||||
callback.onTransactionFailed(-1, "EMV start error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}, 300);
|
||||
}, 800); // Longer delay
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error starting EMV transaction: " + e.getMessage());
|
||||
Log.e(TAG, "Error in EMV transaction setup: " + e.getMessage());
|
||||
if (callback != null) {
|
||||
callback.onTransactionFailed(-1, "Error starting EMV transaction: " + e.getMessage());
|
||||
callback.onTransactionFailed(-1, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetEMVProcess() {
|
||||
try {
|
||||
if (mEMVOptV2 != null) {
|
||||
mEMVOptV2.initEmvProcess();
|
||||
}
|
||||
Log.d(TAG, "Resetting EMV process - current step: " + mProcessStep);
|
||||
|
||||
// Reset semua state variables FIRST
|
||||
mProcessStep = 0;
|
||||
mCardNo = null;
|
||||
Log.d(TAG, "EMV process reset");
|
||||
mPinType = 0;
|
||||
mCertInfo = null;
|
||||
mCardType = 0;
|
||||
|
||||
if (mEMVOptV2 != null) {
|
||||
// Double reset untuk memastikan
|
||||
mEMVOptV2.initEmvProcess();
|
||||
Thread.sleep(300);
|
||||
mEMVOptV2.initEmvProcess();
|
||||
}
|
||||
|
||||
Log.d(TAG, "EMV process reset completed");
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error resetting EMV process: " + e.getMessage());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user