001/*
002 * jPOS Project [http://jpos.org]
003 * Copyright (C) 2000-2026 jPOS Software SRL
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jpos.rc;
020
021import java.util.HashMap;
022import java.util.Map;
023
024/** Common Message Format result codes used by jPOS Transaction Manager participants. */
025public enum CMF implements IRC {
026    // Approved
027    /** Approved. */
028    APPROVED         (0, true),
029    /** Honor With Id. */
030    HONOR_WITH_ID    (1, true),
031    /** Approved Partial. */
032    APPROVED_PARTIAL (2, true),
033    /** Approved Vip. */
034    APPROVED_VIP     (3, true),
035    /** Approved Update Track3. */
036    APPROVED_UPDATE_TRACK3 (4, true),
037    /** Approved Issuer Specified Account. */
038    APPROVED_ISSUER_SPECIFIED_ACCOUNT (5, true),
039    /** Approved Partial Issuer Specified Account. */
040    APPROVED_PARTIAL_ISSUER_SPECIFIED_ACCOUNT (6, true),
041    /** Approved Fees Disputed. */
042    APPROVED_FEES_DISPUTED(8, true),
043    /** Approved With Overdraft. */
044    APPROVED_WITH_OVERDRAFT(9, true),
045    /** Approved Customer Reactivated. */
046    APPROVED_CUSTOMER_REACTIVATED(10, true),
047    /** Approved Terminal Unable To Process Online. */
048    APPROVED_TERMINAL_UNABLE_TO_PROCESS_ONLINE(11),
049    /** Approved Offline. */
050    APPROVED_OFFLINE (12),
051    /** Approved Offline Referral. */
052    APPROVED_OFFLINE_REFERRAL (13),
053    /** No Reason To Decline. */
054    NO_REASON_TO_DECLINE(85, true),
055    /** Name Format Error. */
056    NAME_FORMAT_ERROR(7),
057
058    // Denied Authorization
059    /** Do Not Honour. */
060    DO_NOT_HONOUR(1000),
061    /** Expired. */
062    EXPIRED (1001),
063    /** Suspected Fraud. */
064    SUSPECTED_FRAUD(1002),
065    /** Contact Acquirer. */
066    CONTACT_ACQUIRER(1003),
067    /** Restricted Card. */
068    RESTRICTED_CARD(1004),
069    /** Contact Acquirer Security. */
070    CONTACT_ACQUIRER_SECURITY(1005),
071    /** Max Pin Tries Exceeded. */
072    MAX_PIN_TRIES_EXCEEDED(1006),
073    /** Refer To Issuer. */
074    REFER_TO_ISSUER(1007),
075    /** Refer To Issuer Special. */
076    REFER_TO_ISSUER_SPECIAL(1008),
077    /** Invalid Card Acceptor. */
078    INVALID_CARD_ACCEPTOR(1009),
079    /** Invalid Amount. */
080    INVALID_AMOUNT(1010),
081    /** Invalid Card Number. */
082    INVALID_CARD_NUMBER(1011),
083    /** Pin Data Required. */
084    PIN_DATA_REQUIRED(1012),
085    /** Unacceptable Fee. */
086    UNACCEPTABLE_FEE(1013),
087    /** No Account Type. */
088    NO_ACCOUNT_TYPE(1014),
089    /** Unsupported Function. */
090    UNSUPPORTED_FUNCTION(1015),
091    /** Not Sufficient Funds. */
092    NOT_SUFFICIENT_FUNDS(1016),
093    /** Incorrect Pin. */
094    INCORRECT_PIN(1017),
095    /** No Card Record. */
096    NO_CARD_RECORD(1018),
097    /** Not Permitted To Cardholder. */
098    NOT_PERMITTED_TO_CARDHOLDER(1019),
099    /** Not Permitted To Terminal. */
100    NOT_PERMITTED_TO_TERMINAL(1020),
101    /** Exceeds Withdrawal Amount Limit. */
102    EXCEEDS_WITHDRAWAL_AMOUNT_LIMIT(1021),
103    /** Security Violation. */
104    SECURITY_VIOLATION(1022),
105    /** Exceeds Withdrawal Frequency Limit. */
106    EXCEEDS_WITHDRAWAL_FREQUENCY_LIMIT(1023),
107    /** Law Violation. */
108    LAW_VIOLATION(1024),
109    /** Card Not Effective. */
110    CARD_NOT_EFFECTIVE(1025),
111    /** Invalid Pinblock. */
112    INVALID_PINBLOCK(1026),
113    /** Pin Length Error. */
114    PIN_LENGTH_ERROR(1027),
115    /** Pin Key Sync Error. */
116    PIN_KEY_SYNC_ERROR(1028),
117    /** Suspected Counterfeit Card Dont Pickup. */
118    SUSPECTED_COUNTERFEIT_CARD_DONT_PICKUP(1029),
119    /** Unaccepted Currency. */
120    UNACCEPTED_CURRENCY(1030),
121    /** Declined Fees Disputed. */
122    DECLINED_FEES_DISPUTED(1031),
123    /** Lost Or Stolen Card. */
124    LOST_OR_STOLEN_CARD(1032),
125    /** Authorization Lifecycle Unacceptable. */
126    AUTHORIZATION_LIFECYCLE_UNACCEPTABLE(1033),
127    /** Authorization Lifecycle Expired. */
128    AUTHORIZATION_LIFECYCLE_EXPIRED(1034),
129    /** Closed Account. */
130    CLOSED_ACCOUNT(1035),
131    /** Closed Savings Account. */
132    CLOSED_SAVINGS_ACCOUNT(1036),
133    /** Closed Credit Account. */
134    CLOSED_CREDIT_ACCOUNT(1037),
135    /** Closed Account Type. */
136    CLOSED_ACCOUNT_TYPE(1038),
137    /** Closed Cheque Account. */
138    CLOSED_CHEQUE_ACCOUNT(1039),
139    /** Bad Debt. */
140    BAD_DEBT(1040),
141    /** From Account Bad Status. */
142    FROM_ACCOUNT_BAD_STATUS(1041),
143    /** To Account Bad Status. */
144    TO_ACCOUNT_BAD_STATUS(1042),
145    /** Cheque Already Posted. */
146    CHEQUE_ALREADY_POSTED(1043),
147    /** Information Not On File. */
148    INFORMATION_NOT_ON_FILE(1044),
149    /** Card Verification Data Failed. */
150    CARD_VERIFICATION_DATA_FAILED(1045),
151    /** Amount Not Found. */
152    AMOUNT_NOT_FOUND(1046),
153    /** Pin Change Required. */
154    PIN_CHANGE_REQUIRED(1047),
155    /** New Pin Invalid. */
156    NEW_PIN_INVALID(1048),
157    /** Bank Not Found. */
158    BANK_NOT_FOUND(1049),
159    /** Bank Not Effective. */
160    BANK_NOT_EFFECTIVE(1050),
161    /** Customer Vendor Not Found. */
162    CUSTOMER_VENDOR_NOT_FOUND(1051),
163    /** Customer Vendor Not Effective. */
164    CUSTOMER_VENDOR_NOT_EFFECTIVE(1052),
165    /** Customer Vendor Account Invalid. */
166    CUSTOMER_VENDOR_ACCOUNT_INVALID(1053),
167    /** Vendor Not Found. */
168    VENDOR_NOT_FOUND(1054),
169    /** Vendor Not Effective. */
170    VENDOR_NOT_EFFECTIVE(1055),
171    /** Vendor Data Invalid. */
172    VENDOR_DATA_INVALID(1056),
173    /** Payment Date Invalid. */
174    PAYMENT_DATE_INVALID(1057),
175    /** Personal Id Not Found. */
176    PERSONAL_ID_NOT_FOUND(1058),
177    /** Scheduled Transaction Exists. */
178    SCHEDULED_TRANSACTION_EXISTS(1059),
179    /** Indicates the transaction was aborted at the terminal. */
180    ABORTED_AT_TERMINAL(1060),
181    /** Unsupported Transaction. */
182    UNSUPPORTED_TRANSACTION(1061),
183    /** Cashback Not Allowed. */
184    CASHBACK_NOT_ALLOWED(1062),
185    /** Cashback Amount Exceeded. */
186    CASHBACK_AMOUNT_EXCEEDED(1063),
187    /** Declined Processed Offline. */
188    DECLINED_PROCESSED_OFFLINE(1064),
189    /** Declined Unable To Process. */
190    DECLINED_UNABLE_TO_PROCESS(1065),
191    /** Declined Processed Offline Referral. */
192    DECLINED_PROCESSED_OFFLINE_REFERRAL(1066),
193    /** Id Number Invalid. */
194    ID_NUMBER_INVALID(1068),
195    /** Driver Number Invalid. */
196    DRIVER_NUMBER_INVALID(1069),
197    /** Vid Invalid. */
198    VID_INVALID(1070),
199    /** Certificate Expired. */
200    CERTIFICATE_EXPIRED(1071),
201    /** Additional Authentication Required. */
202    ADDITIONAL_AUTH_REQUIRED(1067),
203    /** Surcharge Not Permitted For Card. */
204    SURCHARGE_NOT_PERMITTED_FOR_CARD(1072),
205    /** Surcharge Not Permitted By Network. */
206    SURCHARGE_NOT_PERMITTED_BY_NETWORK(1073),
207    /** Exceeds Pre Authorizationorized Amount. */
208    EXCEEDS_PRE_AUTHORIZED_AMOUNT(1074),
209    /** Stop Payment Specific. */
210    STOP_PAYMENT_SPECIFIC(1075),
211    /** Stop Payment All Merchant. */
212    STOP_PAYMENT_ALL_MERCHANT(1076),
213    /** Stop Payment Account. */
214    STOP_PAYMENT_ACCOUNT(1077),
215    /** AML Requirements Not Met. */
216    AML_REQUIREMENTS_NOT_MET(1078),
217    /** Exceeds Withdrawal Limit. */
218    EXCEEDS_WITHDRAWAL_LIMIT(1079),
219    /** Pin Not Allowed. */
220    PIN_NOT_ALLOWED(1080),
221    /** Message Number Out Of Sequence. */
222    MESSAGE_NUMBER_OUT_OF_SEQUENCE(1081),
223    /** Original Transaction Declined. */
224    ORIGINAL_TRANSACTION_DECLINED(1082),
225
226    // ICC / chip offline decision codes (ISO 8583:2023, 1500-1511)
227    /** ICC Application Unable To Process. */
228    ICC_APPLICATION_UNABLE_TO_PROCESS(1500),
229    /** ICC Random Selection. */
230    ICC_RANDOM_SELECTION(1502),
231    /** Terminal Random Selection. */
232    TERMINAL_RANDOM_SELECTION(1503),
233    /** Terminal Not Able To Process ICC. */
234    TERMINAL_NOT_ABLE_TO_PROCESS_ICC(1504),
235    /** Online Forced By ICC. */
236    ONLINE_FORCED_BY_ICC(1505),
237    /** Online Forced By Card Acceptor. */
238    ONLINE_FORCED_BY_CARD_ACCEPTOR(1506),
239    /** Online Forced By CAD. */
240    ONLINE_FORCED_BY_CAD(1507),
241    /** Online Forced By Terminal. */
242    ONLINE_FORCED_BY_TERMINAL(1508),
243    /** Online Forced By Card Issuer. */
244    ONLINE_FORCED_BY_CARD_ISSUER(1509),
245    /** Over Floor Limit. */
246    OVER_FLOOR_LIMIT(1510),
247    /** Card Acceptor Suspicious. */
248    CARD_ACCEPTOR_SUSPICIOUS(1511),
249
250    // CMF private-use codes (ISO 8583 1800-1999 reserved for private use)
251    /** Missing Field. */
252    MISSING_FIELD(1802),
253    /** Extra Field. */
254    EXTRA_FIELD(1803),
255    /** Invalid Card. */
256    INVALID_CARD(1804),
257    /** Card Not Active. */
258    CARD_NOT_ACTIVE(1806),
259    /** Card Not Configured. */
260    CARD_NOT_CONFIGURED(1808),
261    /** System Error Db. */
262    SYSTEM_ERROR_DB(1811, false, true),
263    /** System Error Txn. */
264    SYSTEM_ERROR_TXN(1812, false, true),
265    /** Cardholder Not Active. */
266    CARDHOLDER_NOT_ACTIVE(1813),
267    /** Cardholder Not Configured. */
268    CARDHOLDER_NOT_CONFIGURED(1814),
269    /** Cardholder Expired. */
270    CARDHOLDER_EXPIRED(1815),
271    /** Original Transaction Not Found. */
272    ORIGINAL_TRANSACTION_NOT_FOUND(1816),
273    /** Usage Limit Reached. */
274    USAGE_LIMIT_REACHED(1817),
275    /** Configuration Error. */
276    CONFIGURATION_ERROR(1818),
277
278    /** Invalid Terminal. */
279    INVALID_TERMINAL(1819),
280    /** Inactive Terminal. */
281    INACTIVE_TERMINAL(1820),
282    /** Invalid Merchant. */
283    INVALID_MERCHANT(1821),
284    /** Duplicate Entity. */
285    DUPLICATE_ENTITY(1822),
286    /** Invalid Acquirer. */
287    INVALID_ACQUIRER(1823),
288    /** Previously Reversed. */
289    PREVIOUSLY_REVERSED(1824),
290    /** Further Activity Prevents Reversal. */
291    FURTHER_ACTIVITY_PREVENTS_REVERSAL(1825),
292    /** Further Activity Prevents Void. */
293    FURTHER_ACTIVITY_PREVENTS_VOID(1826),
294    /** Original Voided. */
295    ORIGINAL_VOIDED(1827),
296    /** Card Tokenization Not Supported. */
297    CARD_TOKENIZATION_NOT_SUPPORTED(1828),
298
299    /** Invalid Field. */
300    INVALID_FIELD(1830),
301    /** Misconfigured Endpoint. */
302    MISCONFIGURED_ENDPOINT(1831),
303    /** Invalid Request. */
304    INVALID_REQUEST(1832),
305    /** Host Unreachable. */
306    HOST_UNREACHABLE(1833),
307
308
309    // Denied Financial
310    /** Financial Do Not Honour. */
311    FINANCIAL_DO_NOT_HONOUR (2000),
312    /** Financial Expired. */
313    FINANCIAL_EXPIRED (2001),
314    /** Financial Suspected Fraud. */
315    FINANCIAL_SUSPECTED_FRAUD(2002),
316    /** Financial Contact Acquirer. */
317    FINANCIAL_CONTACT_ACQUIRER(2003),
318    /** Financial Restricted Card. */
319    FINANCIAL_RESTRICTED_CARD(2004),
320    /** Financial Contact Acquirer Security. */
321    FINANCIAL_CONTACT_ACQUIRER_SECURITY(2005),
322    /** Financial Max Pin Tries Exceeded. */
323    FINANCIAL_MAX_PIN_TRIES_EXCEEDED(2006),
324    /** Special Conditions. */
325    SPECIAL_CONDITIONS(2007),
326    /** Lost Card. */
327    LOST_CARD(2008),
328    /** Stolen Card. */
329    STOLEN_CARD(2009),
330    /** Suspected Counterfeit Card Pickup. */
331    SUSPECTED_COUNTERFEIT_CARD_PICKUP(2010),
332    /** Max Daily Withdrawal. */
333    MAX_DAILY_WITHDRAWAL(2011),
334    /** Max Daily Amount. */
335    MAX_DAILY_AMOUNT(2012),
336    // Chargeback pick-up resolution codes (ISO 8583:2023)
337    /** Chargeback Remedied. */
338    CHARGEBACK_REMEDIED(2013),
339    /** Duplicate Chargeback. */
340    DUPLICATE_CHARGEBACK(2014),
341    /** Past Chargeback Time Limit. */
342    PAST_CHARGEBACK_TIME_LIMIT(2015),
343    /** Chargeback Documents Provided Hardship. */
344    CHARGEBACK_DOCS_PROVIDED_HARDSHIP(2016),
345    /** Invalid Member Message Text. */
346    INVALID_MEMBER_MESSAGE_TEXT(2017),
347    /** Correct Card Acceptor Category Provided. */
348    CORRECT_CARD_ACCEPTOR_CATEGORY_PROVIDED(2018),
349    /** Authorizationorization Advised Suspicious. */
350    AUTHORIZATION_ADVISED_SUSPICIOUS(2019),
351    /** No Authorization Required. */
352    NO_AUTHORIZATION_REQUIRED(2020),
353    /** Account Not on Warning Bulletin. */
354    ACCOUNT_NOT_ON_WARNING_BULLETIN(2021),
355    /** Chargeback Documents Illegible 2022. */
356    CHARGEBACK_DOCS_ILLEGIBLE_2022(2022),
357    /** Chargeback Documents Invalid 2023. */
358    CHARGEBACK_DOCS_INVALID_2023(2023),
359
360    // File action
361    /** Successful. */
362    SUCCESSFUL(3000, true),
363    /** Not Supported By Receiver. */
364    NOT_SUPPORTED_BY_RECEIVER(3001),
365    /** Unable To Locate Record. */
366    UNABLE_TO_LOCATE_RECORD(3002),
367    /** Updated Record. */
368    UPDATED_RECORD(3003),
369    /** Field Edit Error. */
370    FIELD_EDIT_ERROR(3004),
371    /** File Locked Out. */
372    FILE_LOCKED_OUT(3005),
373    /** Not Successful. */
374    NOT_SUCCESSFUL(3006),
375    /** Format Error. */
376    FORMAT_ERROR(3007),
377    /** Duplicate. */
378    DUPLICATE(3008),
379    /** Unknown File. */
380    UNKNOWN_FILE(3009),
381    /** Invalid Card Or Cardholder Number. */
382    INVALID_CARD_OR_CARDHOLDER_NUMBER(3010),
383
384    // Reversals
385    /** Reversal Accepted. */
386    REVERSAL_ACCEPTED(4000, true),
387    /** Reversal Unspecified. */
388    REVERSAL_UNSPECIFIED(4001),
389    /** Reversal Suspected Malfunction. */
390    REVERSAL_SUSPECTED_MALFUNCTION(4002),
391    /** Reversal Format Error. */
392    REVERSAL_FORMAT_ERROR(4003),
393    /** Reversal Completed Partially. */
394    REVERSAL_COMPLETED_PARTIALLY(4004),
395    /** Reversal Original Amount Incorrect. */
396    REVERSAL_ORIGINAL_AMOUNT_INCORRECT(4005),
397    /** Reversal Response Too Late. */
398    REVERSAL_RESPONSE_TOO_LATE(4006),
399    /** Reversal Device Unable To Complete. */
400    REVERSAL_DEVICE_UNABLE_TO_COMPLETE(4007),
401    /** Reversal Deposit Out Of Balance. */
402    REVERSAL_DEPOSIT_OUT_OF_BALANCE(4008),
403    /** Reversal No Check In Envelope. */
404    REVERSAL_NO_CHECK_IN_ENVELOPE(4009),
405    /** Reversal Payment Out Of Balance. */
406    REVERSAL_PAYMENT_OUT_OF_BALANCE(4010),
407    /** Reversal Deposit Out-of-Balance Applied. */
408    REVERSAL_DEPOSIT_OOB_APPLIED(4011),
409    /** Reversal Payment Out-of-Balance Applied. */
410    REVERSAL_PAYMENT_OOB_APPLIED(4012),
411    /** Reversal Unable To Deliver. */
412    REVERSAL_UNABLE_TO_DELIVER(4013),
413    /** Reversal Suspected Malfunction Card Retained. */
414    REVERSAL_SUSPECTED_MALFUNCTION_CARD_RETAINED(4014),
415    /** Reversal Suspected Malfunction Card Returned. */
416    REVERSAL_SUSPECTED_MALFUNCTION_CARD_RETURNED(4015),
417    /** Reversal Suspected Malfunction Track3 Not Updated. */
418    REVERSAL_SUSPECTED_MALFUNCTION_TRACK3_NOT_UPDATED(4016),
419    /** Reversal Suspected Malfunction No Cash. */
420    REVERSAL_SUSPECTED_MALFUNCTION_NO_CASH(4017),
421    /** Reversal Timeout No Cash. */
422    REVERSAL_TIMEOUT_NO_CASH(4018),
423    /** Reversal Timeout Card Retained No Cash. */
424    REVERSAL_TIMEOUT_CARD_RETAINED_NO_CASH(4019),
425    /** Reversal Invalid Response. */
426    REVERSAL_INVALID_RESPONSE(4020),
427    /** Reversal Timeout Waiting Response. */
428    REVERSAL_TIMEOUT_WAITING_RESPONSE(4021),
429    // Chargeback / retrieval result codes (ISO 8583:2023 4xxx range)
430    /** Chargeback Information Not Received. */
431    CHARGEBACK_INFO_NOT_RECEIVED(4501),
432    /** Chargeback Information Illegible Or Missing. */
433    CHARGEBACK_INFO_ILLEGIBLE_OR_MISSING(4502),
434    /** Chargeback Warning Bulletin. */
435    CHARGEBACK_WARNING_BULLETIN(4507),
436    /** Chargeback Authorization Not Obtained. */
437    CHARGEBACK_AUTH_NOT_OBTAINED(4508),
438    /** Chargeback Account Not On File. */
439    CHARGEBACK_ACCOUNT_NOT_ON_FILE(4512),
440    /** Chargeback Earlier Warning Protection. */
441    CHARGEBACK_EARLIER_WARNING_PROTECTION(4524),
442    /** Chargeback Amount Differs. */
443    CHARGEBACK_AMOUNT_DIFFERS(4531),
444    /** Chargeback Duplicate Processing. */
445    CHARGEBACK_DUPLICATE_PROCESSING(4534),
446    /** Chargeback Card Invalid Or Expired. */
447    CHARGEBACK_CARD_INVALID_OR_EXPIRED(4535),
448    /** Chargeback No Cardholder Authorizationorization. */
449    CHARGEBACK_NO_CARDHOLDER_AUTHORIZATION(4537),
450    /** Chargeback Fraudulent Processing. */
451    CHARGEBACK_FRAUDULENT_PROCESSING(4540),
452    /** Chargeback Cancelled Recurring. */
453    CHARGEBACK_CANCELLED_RECURRING(4541),
454    /** Chargeback Late Presentment. */
455    CHARGEBACK_LATE_PRESENTMENT(4542),
456    /** Chargeback Wrong Currency. */
457    CHARGEBACK_WRONG_CURRENCY(4546),
458    /** Chargeback Exceeds Floor Limit Fraud. */
459    CHARGEBACK_EXCEEDS_FLOOR_LIMIT_FRAUD(4547),
460    /** Chargeback Questionable Acceptor. */
461    CHARGEBACK_QUESTIONABLE_ACCEPTOR(4549),
462    /** Chargeback Credit As Purchase. */
463    CHARGEBACK_CREDIT_AS_PURCHASE(4550),
464    /** Chargeback Not As Described. */
465    CHARGEBACK_NOT_AS_DESCRIBED(4553),
466    /** Chargeback Cardholder Dispute. */
467    CHARGEBACK_CARDHOLDER_DISPUTE(4554),
468    /** Chargeback Non-Receipt Merchandise. */
469    CHARGEBACK_NON_RECEIPT_MERCHANDISE(4555),
470    /** Chargeback Defective Merchandise. */
471    CHARGEBACK_DEFECTIVE_MERCHANDISE(4556),
472    /** Chargeback Card Activated Telephone. */
473    CHARGEBACK_CARD_ACTIVATED_TELEPHONE(4557),
474    /** Chargeback Services Not Rendered. */
475    CHARGEBACK_SERVICES_NOT_RENDERED(4559),
476    /** Chargeback Credit Not Processed. */
477    CHARGEBACK_CREDIT_NOT_PROCESSED(4560),
478    /** Chargeback Counterfeit Magnetic Stripe. */
479    CHARGEBACK_COUNTERFEIT_MAGNETIC_STRIPE(4562),
480    /** Chargeback Documents Not Received. */
481    CHARGEBACK_DOCS_NOT_RECEIVED(4563),
482    /** Chargeback Documents Illegible. */
483    CHARGEBACK_DOCS_ILLEGIBLE(4564),
484    /** Chargeback Documents Invalid. */
485    CHARGEBACK_DOCS_INVALID(4565),
486    /** Chargeback Valid ARN. */
487    CHARGEBACK_VALID_ARN(4566),
488    /** Chargeback Invalid ARN Documents Different. */
489    CHARGEBACK_INVALID_ARN_DOCS_DIFFERENT(4567),
490    /** Chargeback Invalid ARN No Documents. */
491    CHARGEBACK_INVALID_ARN_NO_DOCS(4568),
492    /** Chargeback Expired Card. */
493    CHARGEBACK_EXPIRED_CARD(4573),
494    /** Chargeback Ineligible Transaction. */
495    CHARGEBACK_INELIGIBLE_TRANSACTION(4578),
496    /** Chargeback Receipt Not Received. */
497    CHARGEBACK_RECEIPT_NOT_RECEIVED(4579),
498    /** Chargeback Processing Error. */
499    CHARGEBACK_PROCESSING_ERROR(4580),
500    /** Chargeback Missing Imprint. */
501    CHARGEBACK_MISSING_IMPRINT(4581),
502    /** Chargeback Non-Possession Of Card. */
503    CHARGEBACK_NON_POSSESSION_OF_CARD(4583),
504    /** Chargeback Missing Signature. */
505    CHARGEBACK_MISSING_SIGNATURE(4584),
506    /** Chargeback Amount Altered. */
507    CHARGEBACK_AMOUNT_ALTERED(4586),
508    /** Chargeback Domestic Processing Violation. */
509    CHARGEBACK_DOMESTIC_PROCESSING_VIOLATION(4587),
510    /** Chargeback Non-Receipt ATM. */
511    CHARGEBACK_NON_RECEIPT_ATM(4590),
512    /** Chargeback Cancelled Reservation. */
513    CHARGEBACK_CANCELLED_RESERVATION(4594),
514    /** Chargeback Advance Lodging Deposit. */
515    CHARGEBACK_ADVANCE_LODGING_DEPOSIT(4595),
516    /** Chargeback Exceeds Limited Amount. */
517    CHARGEBACK_EXCEEDS_LIMITED_AMOUNT(4596),
518
519    // Reconciliation
520    /** Reconciled In Balance. */
521    RECONCILED_IN_BALANCE(5000, true),
522    /** Reconciled Out Of Balance. */
523    RECONCILED_OUT_OF_BALANCE(5001),
524    /** Amount Not Reconciled Totals Provided. */
525    AMOUNT_NOT_RECONCILED_TOTALS_PROVIDED(5002),
526    /** Totals Not Available. */
527    TOTALS_NOT_AVAILABLE(5003),
528    /** Not Reconciled Totals Provided. */
529    NOT_RECONCILED_TOTALS_PROVIDED(5004),
530
531    // Administrative messages
532    /** Administrative message accepted. */
533    ADMIN_MESSAGE_ACCEPTED(6000, true),
534    // Retrieval / copy request reason codes (ISO 8583:2023)
535    /** Cardholder Disputes Amount. */
536    CARDHOLDER_DISPUTES_AMOUNT(6005),
537    /** Cardholder Does Not Recognize. */
538    CARDHOLDER_DOES_NOT_RECOGNIZE(6021),
539    /** ICC Certificate Requested. */
540    ICC_CERTIFICATE_REQUESTED(6022),
541    /** Cardholder Needs Records. */
542    CARDHOLDER_NEEDS_RECORDS(6023),
543    /** Copy With Signature Requested. */
544    COPY_WITH_SIGNATURE_REQUESTED(6028),
545    /** Travel And Entertainment Docs Requested. */
546    TRAVEL_AND_ENTERTAINMENT_DOCS_REQUESTED(6029),
547    /** Copy Original Lost In Transit. */
548    COPY_ORIGINAL_LOST_IN_TRANSIT(6032),
549    /** Written Request Inadequate Copy. */
550    WRITTEN_REQUEST_INADEQUATE_COPY(6035),
551    /** Legal Process Request. */
552    LEGAL_PROCESS_REQUEST(6036),
553    /** Received Copy Illegible. */
554    RECEIVED_COPY_ILLEGIBLE(6037),
555    /** Paper Handwriting Analysis Request. */
556    PAPER_HANDWRITING_ANALYSIS_REQUEST(6038),
557    /** Fraud Investigation. */
558    FRAUD_INVESTIGATION(6041),
559    /** Arbitration or Compliance Documentation Required. */
560    ARBITRATION_OR_COMPLIANCE_DOCS_REQUIRED(6042),
561    /** Retrieval Not Fulfilled Cannot Trace. */
562    RETRIEVAL_NOT_FULFILLED_CANNOT_TRACE(6043),
563    /** Retrieval Not Fulfilled Invalid Ref. */
564    RETRIEVAL_NOT_FULFILLED_INVALID_REF(6044),
565    /** Retrieval Not Fulfilled Ref PAN Incompatible. */
566    RETRIEVAL_NOT_FULFILLED_REF_PAN_INCOMPATIBLE(6045),
567    /** Retrieval Docs Supplied. */
568    RETRIEVAL_DOCS_SUPPLIED(6046),
569    /** Retrieval Cannot Fulfill Docs Unavailable. */
570    RETRIEVAL_CANNOT_FULFILL_DOCS_UNAVAILABLE(6047),
571    /** Retrieval Will Not Fulfill Not Required. */
572    RETRIEVAL_WILL_NOT_FULFILL_NOT_REQUIRED(6048),
573    /** Retrieval Cannot Fulfill ICC Cert Unavailable. */
574    RETRIEVAL_CANNOT_FULFILL_ICC_CERT_UNAVAILABLE(6049),
575
576    // Fee collection
577    /** Fee Collection Accepted. */
578    FEE_COLLECTION_ACCEPTED (7000, true),
579
580    // Network Management
581    /** Net Accepted. */
582    NET_ACCEPTED (8000, true),
583    /** Net Retry. */
584    NET_RETRY(8001),
585    /** Key Verification Failed. */
586    KEY_VERIFICATION_FAILED(8002),
587    // Key exchange / lifecycle management codes (ISO 8583:2023)
588    /** Key Exchange Activation Lifecycle. */
589    KEY_EXCHANGE_ACTIVATION_LIFECYCLE(8100),
590    /** Key Exchange Activation Out Of Sync. */
591    KEY_EXCHANGE_ACTIVATION_OUT_OF_SYNC(8101),
592    /** Key Exchange Activation Security. */
593    KEY_EXCHANGE_ACTIVATION_SECURITY(8102),
594    /** Key Exchange Deactivation. */
595    KEY_EXCHANGE_DEACTIVATION(8103),
596    /** Key Exchange Verification Lifecycle. */
597    KEY_EXCHANGE_VERIFICATION_LIFECYCLE(8104),
598    /** Key Exchange Verification Out Of Sync. */
599    KEY_EXCHANGE_VERIFICATION_OUT_OF_SYNC(8105),
600
601    // Misc
602    /** Advice acknowledged with no financial impact. */
603    ADVICE_ACK_NO_FINANCIAL(9000, true),
604    /** Advice accepted. */
605    ADVICE_ACCEPTED(9001, true),
606    /** Message Error. */
607    MESSAGE_ERROR(9100),
608    /** Invalid Transaction. */
609    INVALID_TRANSACTION(9102),
610    /** Retry Transaction. */
611    RETRY_TRANSACTION(9103),
612    /** Acquirer is not supported. */
613    ACQUIRER_NOT_SUPPORTED(9105),
614    /** Cutover In Process. */
615    CUTOVER_IN_PROCESS(9106),
616    /** Issuer Not Available. */
617    ISSUER_NOT_AVAILABLE(9107),
618    /** Routing Error. */
619    ROUTING_ERROR(9108),
620    /** System Error. */
621    SYSTEM_ERROR(9109),
622    /** Issuer Signed Off. */
623    ISSUER_SIGNED_OFF(9110),
624    /** Issuer Timeout. */
625    ISSUER_TIMEOUT(9111),
626    /** Issuer Unavailable. */
627    ISSUER_UNAVAILABLE(9112),
628    /** Duplicate Transmission. */
629    DUPLICATE_TRANSMISSION(9113),
630    /** Original Not Found. */
631    ORIGINAL_NOT_FOUND(9114),
632    /** Reconciliation Error. */
633    RECONCILIATION_ERROR(9115),
634    /** Mac Incorrect. */
635    MAC_INCORRECT(9116),
636    /** Mac Key Sync Error. */
637    MAC_KEY_SYNC_ERROR(9117),
638    /** Zmk Not Available. */
639    ZMK_NOT_AVAILABLE(9118),
640    /** Crypto Error. */
641    CRYPTO_ERROR(9119),
642    /** Hsm Error Retry. */
643    HSM_ERROR_RETRY(9120),
644    /** Hsm Error. */
645    HSM_ERROR (9121),
646    /** Out Of Sequence. */
647    OUT_OF_SEQUENCE(9122),
648    /** Request In Progress. */
649    REQUEST_IN_PROGRESS(9123),
650    /** Invalid Security Code. */
651    INVALID_SECURITY_CODE(9124),
652    /** Database Error. */
653    DATABASE_ERROR(9125),
654    /** Invalid IIN. */
655    INVALID_IIN(9126),
656    /** Customer Vendor Format Error. */
657    CUSTOMER_VENDOR_FORMAT_ERROR(9128),
658    /** Recurring Data Error. */
659    RECURRING_DATA_ERROR(9132),
660    /** Update Not Allowed. */
661    UPDATE_NOT_ALLOWED(9133),
662    /** Agreement Violation. */
663    AGREEMENT_VIOLATION(9350),
664
665    /** General Decline. */
666    GENERAL_DECLINE(9999),
667
668    // jPOS specific result codes
669    /** Jpos. */
670    JPOS(10000),
671    /** Internal Error. */
672    INTERNAL_ERROR(19999,false,true),
673
674    // User specific result codes
675    /** User-defined result code. */
676    USER(90000);
677
678    private final int irc;
679    private final String ircStr;
680
681    private final boolean success;
682    private final boolean inhibit;
683
684    private static final Map<Integer,IRC> lookupInt = new HashMap<>();
685    private static final Map<String,IRC>  lookupStr = new HashMap<>();
686    static {
687        // This section executes after all the enum instances have been constructed
688        for (IRC irc : values()) {
689            lookupInt.put(irc.irc(), irc);
690            lookupStr.put(irc.ircString(), irc);
691        }
692    }
693
694    CMF(int irc) {
695        this (irc, false, false);
696    }
697    CMF(int irc, boolean success) {
698        this(irc, success, false);
699    }
700    CMF(int irc, boolean success, boolean inhibit) {
701        this.irc = irc;
702        this.ircStr = String.format("%04d", irc);
703        this.success = success;
704        this.inhibit = inhibit;
705    }
706
707    @Override
708    public int irc() {
709        return irc;
710    }
711
712    @Override
713    public String ircString() {
714        return ircStr;
715    }
716
717    @Override
718    public boolean success() {
719        return success;
720    }
721
722    @Override
723    public boolean inhibit() {
724        return inhibit;
725    }
726
727    /**
728     * Looks up a CMF value by its integer code.
729     * @param i the integer code
730     * @return the matching IRC, or null if not found
731     */
732    public static IRC valueOf(int i) {
733        return lookupInt.get(i);
734    }
735
736    /**
737     * Returns the {@code CMF} instance that has the given String as its jPOS-CMF Result Code
738     * (usually transmitted in DE-39).
739     *
740     * @param irc a String representing a jPOS-CMF Result Code
741     * @return the corresponding CMF instance or {@code null}
742     */
743    public static CMF fromIsoString(String irc) {
744        return (irc == null) ? null : (CMF)lookupStr.get(irc.trim());
745    }
746}