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 + ")");
|
Log.e(TAG, "EMV Transaction failed: " + desc + " (Code: " + code + ")");
|
||||||
|
|
||||||
modalManager.hideModal();
|
modalManager.hideModal();
|
||||||
if (code == -50009) {
|
|
||||||
// EMV process conflict - reset and retry
|
// Handle specific error codes
|
||||||
Log.d(TAG, "EMV process conflict detected - resetting...");
|
if (code == -4125) {
|
||||||
|
showToast("Card not supported. Please try another card or insert chip.");
|
||||||
|
performCompleteReset();
|
||||||
|
} else if (code == -50009) {
|
||||||
showToast("EMV busy, resetting...");
|
showToast("EMV busy, resetting...");
|
||||||
resetEMVAndRetry();
|
performCompleteReset();
|
||||||
} else {
|
} else {
|
||||||
// Other errors - show message and restart scanning
|
|
||||||
showToast("Transaction failed: " + desc);
|
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) {
|
private void showSuccessScreen(Runnable onAnimationComplete) {
|
||||||
// Hide modal first
|
// Hide modal first
|
||||||
modalManager.hideModal();
|
modalManager.hideModal();
|
||||||
|
@ -121,58 +121,68 @@ public class EMVManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startEMVTransaction(String transactionAmount, int cardType) {
|
public void startEMVTransaction(String transactionAmount, int cardType) {
|
||||||
if (mProcessStep != 0) {
|
// Force reset jika masih ada proses berjalan
|
||||||
Log.d(TAG, "EMV transaction already in progress (step: " + mProcessStep + ") - ignoring call");
|
if (mProcessStep > 0) {
|
||||||
return;
|
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;
|
mProcessStep = 1;
|
||||||
mCardType = cardType;
|
mCardType = cardType;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Extended initialization
|
||||||
mEMVOptV2.initEmvProcess();
|
mEMVOptV2.initEmvProcess();
|
||||||
|
Thread.sleep(500);
|
||||||
|
|
||||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
try {
|
try {
|
||||||
if (mProcessStep <= 0) {
|
|
||||||
Log.d(TAG, "EMV process was cancelled - not starting");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("amount", transactionAmount);
|
bundle.putString("amount", transactionAmount);
|
||||||
bundle.putString("transType", "00");
|
bundle.putString("transType", "00");
|
||||||
bundle.putInt("flowType", AidlConstantsV2.EMV.FlowType.TYPE_EMV_STANDARD);
|
bundle.putInt("flowType", AidlConstantsV2.EMV.FlowType.TYPE_EMV_STANDARD);
|
||||||
bundle.putInt("cardType", mCardType);
|
bundle.putInt("cardType", mCardType);
|
||||||
|
|
||||||
Log.d(TAG, "Starting transactProcessEx with reset EMV");
|
Log.d(TAG, "Starting EMV with reset state");
|
||||||
mEMVOptV2.transactProcessEx(bundle, mEMVListener);
|
mEMVOptV2.transactProcessEx(bundle, mEMVListener);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} 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) {
|
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) {
|
} 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) {
|
if (callback != null) {
|
||||||
callback.onTransactionFailed(-1, "Error starting EMV transaction: " + e.getMessage());
|
callback.onTransactionFailed(-1, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetEMVProcess() {
|
public void resetEMVProcess() {
|
||||||
try {
|
try {
|
||||||
if (mEMVOptV2 != null) {
|
Log.d(TAG, "Resetting EMV process - current step: " + mProcessStep);
|
||||||
mEMVOptV2.initEmvProcess();
|
|
||||||
}
|
// Reset semua state variables FIRST
|
||||||
mProcessStep = 0;
|
mProcessStep = 0;
|
||||||
mCardNo = null;
|
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) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Error resetting EMV process: " + e.getMessage());
|
Log.e(TAG, "Error resetting EMV process: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user