Created
January 10, 2011 14:22
-
-
Save endymuhardin/772818 to your computer and use it in GitHub Desktop.
logic untuk menghandle reversal request dengan validasi padanan payment dan selisih waktu dengan request sebelumnya
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void methodYangHarusDivalidasi(Object param1, Object param2) { | |
// validasi param | |
if(param1 == null){ | |
throw new IllegalArgumentException("tidak boleh null"); | |
// throw otomatis mengakhiri method | |
} | |
if(!param1.getClass().isAssignableFrom(BigDecimal.class)){ | |
// tidak usah diproses | |
logger.warn("bukan angka, tidak bisa diproses"); | |
return; // gak lolos validasi, ngapain juga diterusin | |
} | |
// all ok, baru diterusin | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void methodYangHarusDivalidasi(Object param1, Object param2) { | |
// validasi param | |
if(param1 == null){ | |
throw new IllegalArgumentException("tidak boleh null"); | |
// throw otomatis mengakhiri method | |
} else { | |
if(!param1.getClass().isAssignableFrom(BigDecimal.class)){ | |
// tidak usah diproses | |
logger.warn("bukan angka, tidak bisa diproses"); | |
} else { | |
// all ok, baru diterusin | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void handleReversalRequest(ISOMsg reversalRequest, ISOSrc src){ | |
ISOMsg response = reversalRequest.clone(); // whatever happen, pasti kirim response | |
response.setMTI(REVERSAL_RESPONSE); | |
// cari padanan yang mau direverse | |
ISOMsg payment = findPaymentToBeReversed(reversalRequest); | |
if(payment == null) { | |
response.set(39, RC_NO_PAYMENT); | |
src.send(response); | |
return; // langsung return aja, gak perlu diterusin | |
} | |
// untuk repeat, validasi dulu interval | |
if(isRepeat(reversalRequest)){ | |
DateTime now = new DateTime(); | |
if(now.isAfter(reversalRequest.getWaktuTransaksi().plusSeconds(120))) { | |
response.set(39, RC_KELAMAAN); | |
src.send(response); | |
return; // langsung return, gak perlu diterusin | |
} | |
} | |
// reversal request valid, baru siapkan urusan ke PLN | |
ISOMsg reversalRequestPln = prepareReversalRequestPln(reversalRequest); | |
ISOMsg reversalResponsePln = null; | |
if(isRepeat(reversalRequest)){ | |
reversalResponsePln = plnGateway.reversalRepeatNonTaglis(reversalReqPLN, 1); | |
} else { | |
reversalResponsePLN = plnGateway.reversalNonTaglis(reversalReqPLN); | |
} | |
if(reversalResponsePln == null){ | |
response.set(39, RC_PLN_NO_RESPONSE); | |
src.send(response); | |
return; // langsung return, gak perlu diterusin | |
} | |
// kalo sampe di sini, berarti dapat response | |
// translate response, baru send ke hilir | |
} |
Ok done pak, sudah di push
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
di contohValidasiBenar.java, flownya tinggal dibaca dari atas ke bawah. Karena begitu error langsung return, kita gak bingung bacanya.
Bandingkan dengan contohValidasiSalah.java. Begitu error gak langsung return, tapi diam aja. Sedangkan kasus ok nya dihandle di else.
Ngetracenya sulit.