Last active
June 24, 2018 21:12
-
-
Save mguilherme/864aeee32145aa2a8c2e4a99ec680543 to your computer and use it in GitHub Desktop.
Retrieves a status from a given code (match regex)
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
import java.util.Arrays; | |
import java.util.regex.Pattern; | |
/** | |
* Responsible for translating a given result code to a Proxy Status. | |
* | |
* @see <a href="https://sibs.docs.onlinepayments.pt/reference/resultCodes">Result Codes</a> | |
*/ | |
public enum ProxyStatus { | |
/** | |
* Result codes for successfully processed transactions. | |
**/ | |
SUCCESSFULLY_PROCESSED_TRANSACTION("^(000\\.000\\.|000\\.100\\.1|000\\.[36])"), | |
/** | |
* Result codes for successfully processed transactions that should be manually reviewed. | |
*/ | |
SUCCESSFULLY_PROCESSED_TRANSACTION_THAT_SHOULD_BE_MANUALLY_REVIEWED("^(000\\.400\\.0[^3]|000\\.400\\.100)"), | |
/** | |
* Result codes for pending transactions. | |
*/ | |
PENDING_TRANSACTION("^(000\\.200)"), | |
/** | |
* Result codes for pending transactions where the status of a transaction can change even after several days. | |
*/ | |
PENDING_TRANSACTION_WHERE_STATUS_OF_TRANSACTION_CAN_CHANGE_AFTER_SEVERAL_DAYS("^(800\\.400\\.5|100\\.400\\.500)"), | |
/** | |
* Result codes for rejections due to 3Dsecure and Intercard risk checks. | |
*/ | |
REJECTION_DUE_TO_3DSECURE_AND_INTERCARD_RISK_CHECKS("^(000\\.400\\.[1][0-9][1-9]|000\\.400\\.2)"), | |
/** | |
* Result codes for rejections by the external bank or similar payment system. | |
*/ | |
REJECTION_BY_THE_EXTERNAL_BANK_OR_SIMILAR_PAYMENT_SYSTEM("^(800\\.[17]00|800\\.800\\.[123])"), | |
/** | |
* Result codes for rejections due to communication errors. | |
*/ | |
REJECTION_DUE_TO_COMMUNICATION_ERRORS("^(900\\.[1234]00|000\\.400\\.030)"), | |
/** | |
* Result codes for rejections due to system errors. | |
*/ | |
REJECTION_DUE_TO_SYSTEM_ERRORS("^(800\\.5|999\\.|600\\.1|800\\.800\\.8)"), | |
/** | |
* Result codes for rejections due to error in asynchonous workflow. | |
*/ | |
REJECTION_DUE_TO_ERROR_IN_ASYNCHONOUS_WORKFLOW("^(100\\.39[765])"), | |
/** | |
* Result codes for rejections due to checks by external risk systems. | |
*/ | |
REJECTION_DUE_TO_CHECKS_BY_EXTERNAL_RISK_SYSTEMS("^(100\\.400|100\\.38|100\\.370\\.100|100\\.370\\.11)"), | |
/** | |
* Result codes for rejections due to avs address validation. | |
*/ | |
REJECTION_DUE_TO_AVS_ADDRESS_VALIDATION("^(800\\.400\\.1)"), | |
/** | |
* Result codes for rejections due to 3Dsecure. | |
*/ | |
REJECTION_DUE_TO_3DSECURE("^(800\\.400\\.2|100\\.380\\.4|100\\.390)"), | |
/** | |
* Result codes for rejections due to blacklist validation. | |
*/ | |
REJECTION_DUE_TO_BLACKLIST_VALIDATION("^(100\\.100\\.701|800\\.[32])"), | |
/** | |
* Result codes for rejections due to risk validation. | |
*/ | |
REJECTION_DUE_TO_RISK_VALIDATION("^(800\\.1[123456]0)"), | |
/** | |
* Result codes for rejections due to configuration validation. | |
*/ | |
REJECTION_DUE_TO_CONFIGURATION_VALIDATION("^(600\\.[23]|500\\.[12]|800\\.121)"), | |
/** | |
* Result codes for rejections due to registration validation. | |
*/ | |
REJECTION_DUE_TO_REGISTRATION_VALIDATION("^(100\\.[13]50)"), | |
/** | |
* Result codes for rejections due to job validation. | |
*/ | |
REJECTION_DUE_TO_JOB_VALIDATION("^(100\\.250|100\\.360)"), | |
/** | |
* Result codes for rejections due to reference validation. | |
*/ | |
REJECTION_DUE_TO_REFERENCE_VALIDATION("^(700\\.[1345][05]0)"), | |
/** | |
* Result codes for rejections due to format validation. | |
*/ | |
REJECTION_DUE_TO_FORMAT_VALIDATION("^(200\\.[123]|100\\.[53][07]|800\\.900|100\\.[69]00\\.500)"), | |
/** | |
* Result codes for rejections due to address validation. | |
*/ | |
REJECTION_DUE_TO_ADDRESS_VALIDATION("^(100\\.800)"), | |
/** | |
* Result codes for rejections due to contact validation. | |
*/ | |
REJECTION_DUE_TO_CONTACT_VALIDATION("^(100\\.[97]00)"), | |
/** | |
* Result codes for rejections due to account validation. | |
*/ | |
REJECTION_DUE_TO_ACCOUNT_VALIDATION("^(100\\.100|100.2[01])"), | |
/** | |
* Result codes for rejections due to amount validation. | |
*/ | |
REJECTION_DUE_TO_AMOUNT_VALIDATION("^(100\\.55)"), | |
/** | |
* Result codes for rejections due to risk management. | |
*/ | |
REJECTION_DUE_TO_RISK_MANAGEMENT("^(100\\.380\\.[23]|100\\.380\\.101)"), | |
/** | |
* Chargeback related result codes. | |
*/ | |
CHARGE_BACK("^(000\\.100\\.2)"), | |
/** | |
* Result codes that don't match. | |
*/ | |
NO_STATUS_CODE(""); | |
private final Pattern pattern; | |
ProxyStatus(String regex) { | |
pattern = Pattern.compile(regex); | |
} | |
/** | |
* Retrieves the {@link ProxyStatus} from a given code. | |
* | |
* @param code the code | |
* @return the proxy status | |
*/ | |
public static ProxyStatus getStatus(String code) { | |
return Arrays.stream(values()) | |
.filter(s -> s.pattern.matcher(code).find()) | |
.findAny() | |
.orElse(NO_STATUS_CODE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment