All files / src/constants mspResponseCodes.ts

35.71% Statements 5/14
0% Branches 0/8
0% Functions 0/4
38.46% Lines 5/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652                              53x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               53x                                                         53x                 53x                 53x          
/**
 * RS2 MSP Response Code Mappings
 * Maps payment processor response codes to user-friendly error messages
 *
 * @see RS2_TEST_CARDS.md for test card numbers
 */
 
export interface MspResponseCodeInfo {
  code: string;
  label: string;
  description: string;
  userMessage: string;
  category: "declined" | "fraud" | "technical" | "auth_required" | "card_issue";
}
 
export const MSP_RESPONSE_CODES: Record<string, MspResponseCodeInfo> = {
  // 01-05: General Declines
  "01": {
    code: "01",
    label: "Refer to Issuer",
    description: "The card issuer needs to be contacted",
    userMessage:
      "Please contact your card issuer to authorize this transaction.",
    category: "declined",
  },
  "02": {
    code: "02",
    label: "Refer to Issuer (Special Condition)",
    description: "Special condition requires issuer contact",
    userMessage: "Please contact your card issuer for assistance.",
    category: "declined",
  },
  "03": {
    code: "03",
    label: "Invalid Merchant",
    description: "Merchant configuration issue",
    userMessage:
      "Unable to process payment. Please try again or contact support.",
    category: "technical",
  },
  "04": {
    code: "04",
    label: "Pick Up Card",
    description: "Card should be retained",
    userMessage:
      "This card cannot be used. Please use a different payment method.",
    category: "card_issue",
  },
  "05": {
    code: "05",
    label: "Do Not Honor",
    description: "Transaction declined by issuer",
    userMessage:
      "Your card was declined. Please try a different payment method.",
    category: "declined",
  },
 
  // 12-19: Transaction Issues
  "12": {
    code: "12",
    label: "Invalid Transaction",
    description: "Transaction is not valid",
    userMessage: "Transaction cannot be processed. Please try again.",
    category: "technical",
  },
  "13": {
    code: "13",
    label: "Invalid Amount",
    description: "Amount is invalid or out of range",
    userMessage: "Payment amount is invalid. Please try again.",
    category: "technical",
  },
  "14": {
    code: "14",
    label: "Invalid Card Number",
    description: "Card number is not valid",
    userMessage: "Invalid card number. Please check and try again.",
    category: "card_issue",
  },
  "15": {
    code: "15",
    label: "Invalid Issuer",
    description: "Card issuer is invalid or unknown",
    userMessage: "This card cannot be processed. Please use a different card.",
    category: "card_issue",
  },
  "17": {
    code: "17",
    label: "Customer Cancellation",
    description: "Cardholder cancelled the transaction",
    userMessage: "Transaction was cancelled.",
    category: "declined",
  },
  "19": {
    code: "19",
    label: "Re-enter Transaction",
    description: "Transaction needs to be re-entered",
    userMessage: "Please try submitting your payment again.",
    category: "technical",
  },
 
  // 30-40: Format & Support Errors
  "30": {
    code: "30",
    label: "Format Error",
    description: "Message format error",
    userMessage: "Payment processing error. Please try again.",
    category: "technical",
  },
  "31": {
    code: "31",
    label: "Bank Not Supported",
    description: "Issuing bank not supported",
    userMessage: "This card is not supported. Please use a different card.",
    category: "card_issue",
  },
  "33": {
    code: "33",
    label: "Expired Card",
    description: "Card has expired",
    userMessage:
      "Your card has expired. Please use a different payment method.",
    category: "card_issue",
  },
  "34": {
    code: "34",
    label: "Suspected Fraud",
    description: "Transaction flagged for fraud",
    userMessage:
      "Transaction declined for security reasons. Please contact your card issuer.",
    category: "fraud",
  },
  "36": {
    code: "36",
    label: "Restricted Card",
    description: "Card is restricted",
    userMessage:
      "This card is restricted. Please use a different payment method.",
    category: "card_issue",
  },
  "37": {
    code: "37",
    label: "Call Acquirer Security",
    description: "Security issue detected",
    userMessage:
      "Payment declined for security reasons. Please contact your bank.",
    category: "fraud",
  },
  "38": {
    code: "38",
    label: "PIN Tries Exceeded",
    description: "Maximum PIN attempts exceeded",
    userMessage:
      "Too many incorrect PIN attempts. Please contact your card issuer.",
    category: "card_issue",
  },
  "40": {
    code: "40",
    label: "Function Not Supported",
    description: "Requested function not supported",
    userMessage:
      "This transaction type is not supported. Please try a different method.",
    category: "technical",
  },
 
  // 41-46: Card Status Issues
  "41": {
    code: "41",
    label: "Lost Card",
    description: "Card reported as lost",
    userMessage:
      "This card has been reported lost. Please use a different payment method.",
    category: "card_issue",
  },
  "43": {
    code: "43",
    label: "Stolen Card",
    description: "Card reported as stolen",
    userMessage:
      "This card has been reported stolen. Please use a different payment method.",
    category: "card_issue",
  },
  "46": {
    code: "46",
    label: "Closed Account",
    description: "Account has been closed",
    userMessage:
      "This account is closed. Please use a different payment method.",
    category: "card_issue",
  },
 
  // 51-59: Insufficient Funds & Limits
  "51": {
    code: "51",
    label: "Insufficient Funds",
    description: "Not enough funds available",
    userMessage: "Insufficient funds. Please use a different payment method.",
    category: "declined",
  },
  "52": {
    code: "52",
    label: "No Checking Account",
    description: "No checking account available",
    userMessage: "Account type not supported. Please use a different card.",
    category: "card_issue",
  },
  "53": {
    code: "53",
    label: "No Savings Account",
    description: "No savings account available",
    userMessage: "Account type not supported. Please use a different card.",
    category: "card_issue",
  },
  "54": {
    code: "54",
    label: "Expired Card",
    description: "Card expiration date has passed",
    userMessage:
      "Your card has expired. Please use a different payment method.",
    category: "card_issue",
  },
  "55": {
    code: "55",
    label: "Incorrect PIN",
    description: "PIN entered is incorrect",
    userMessage: "Incorrect PIN. Please verify and try again.",
    category: "declined",
  },
  "56": {
    code: "56",
    label: "No Card Record",
    description: "Card not on file",
    userMessage: "Card information not found. Please check your card details.",
    category: "card_issue",
  },
  "57": {
    code: "57",
    label: "Transaction Not Permitted",
    description: "Cardholder not permitted to make this transaction",
    userMessage:
      "This transaction is not allowed on your card. Please use a different payment method.",
    category: "declined",
  },
  "58": {
    code: "58",
    label: "Not Allowed at Terminal",
    description: "Transaction not permitted at this terminal",
    userMessage:
      "This type of transaction is not allowed. Please try a different method.",
    category: "declined",
  },
  "59": {
    code: "59",
    label: "Suspected Fraud",
    description: "Transaction suspected to be fraudulent",
    userMessage:
      "Transaction declined for security reasons. Please contact your card issuer to authorize.",
    category: "fraud",
  },
 
  // 61-68: Security & Restrictions
  "61": {
    code: "61",
    label: "Usage Limit Exceeded",
    description: "Card usage limit has been exceeded",
    userMessage:
      "Card usage limit exceeded. Please use a different payment method.",
    category: "declined",
  },
  "62": {
    code: "62",
    label: "Restricted Card",
    description: "Card has restrictions",
    userMessage:
      "This card has restrictions. Please use a different payment method.",
    category: "card_issue",
  },
  "63": {
    code: "63",
    label: "Security Violation",
    description: "Security policy violation",
    userMessage:
      "Transaction declined for security reasons. Please contact your bank.",
    category: "fraud",
  },
  "64": {
    code: "64",
    label: "AML Requirements Not Met",
    description: "Anti-money laundering requirements not satisfied",
    userMessage:
      "Additional verification required. Please contact your card issuer.",
    category: "auth_required",
  },
  "65": {
    code: "65",
    label: "Frequency Limit Exceeded",
    description: "Transaction frequency limit exceeded",
    userMessage:
      "Too many transactions. Please try again later or use a different card.",
    category: "declined",
  },
  "66": {
    code: "66",
    label: "Call Security Department",
    description: "Security department contact required",
    userMessage: "Please contact your bank's security department.",
    category: "fraud",
  },
  "67": {
    code: "67",
    label: "Hard Capture",
    description: "Card should be retained",
    userMessage: "This card cannot be used. Please contact your card issuer.",
    category: "card_issue",
  },
  "68": {
    code: "68",
    label: "Late Response",
    description: "Response received too late",
    userMessage: "Transaction timeout. Please try again.",
    category: "technical",
  },
  "6P": {
    code: "6P",
    label: "Verification Failed",
    description: "Card verification failed",
    userMessage:
      "Card verification failed. Please check your card details and try again.",
    category: "declined",
  },
 
  // 71-87: PIN & Account Issues
  "71": {
    code: "71",
    label: "PIN Not Changed",
    description: "PIN change was not successful",
    userMessage: "PIN issue detected. Please contact your card issuer.",
    category: "card_issue",
  },
  "72": {
    code: "72",
    label: "Account Not Activated",
    description: "Card account not yet activated",
    userMessage: "Your card is not activated. Please contact your card issuer.",
    category: "card_issue",
  },
  "75": {
    code: "75",
    label: "Exceeded PIN Tries",
    description: "Maximum PIN entry attempts exceeded",
    userMessage:
      "Too many incorrect PIN attempts. Please contact your card issuer.",
    category: "card_issue",
  },
  "76": {
    code: "76",
    label: "Authentication Required",
    description: "Additional authentication needed",
    userMessage:
      "Additional verification required. Please contact your card issuer.",
    category: "auth_required",
  },
  "77": {
    code: "77",
    label: "Authentication Required (PIN)",
    description: "PIN authentication required",
    userMessage: "PIN verification required. Please contact your card issuer.",
    category: "auth_required",
  },
  "78": {
    code: "78",
    label: "Card Blocked",
    description: "Card has been blocked",
    userMessage: "Your card has been blocked. Please contact your card issuer.",
    category: "card_issue",
  },
  "79": {
    code: "79",
    label: "Lifecycle Decline",
    description: "Card declined due to lifecycle status",
    userMessage:
      "This card cannot be used. Please use a different payment method.",
    category: "card_issue",
  },
  "80": {
    code: "80",
    label: "Recurring Cancellation",
    description: "Recurring payment was cancelled",
    userMessage:
      "Recurring payment cancelled. Please set up a new payment method.",
    category: "declined",
  },
  "81": {
    code: "81",
    label: "Cryptographic Error",
    description: "Encryption/security error",
    userMessage: "Security error occurred. Please try again.",
    category: "technical",
  },
  "82": {
    code: "82",
    label: "Invalid CVV2",
    description: "CVV code is incorrect",
    userMessage:
      "Invalid CVV code. Please check your card security code and try again.",
    category: "declined",
  },
  "84": {
    code: "84",
    label: "Re-enter Transaction",
    description: "Transaction must be re-entered",
    userMessage: "Please try submitting your payment again.",
    category: "technical",
  },
  "85": {
    code: "85",
    label: "Invalid CVV",
    description: "CVV verification failed",
    userMessage:
      "Invalid CVV code. Please verify your card security code and try again.",
    category: "declined",
  },
  "86": {
    code: "86",
    label: "Cannot Verify PIN",
    description: "PIN verification not possible",
    userMessage: "PIN verification failed. Please contact your card issuer.",
    category: "card_issue",
  },
  "87": {
    code: "87",
    label: "Account Does Not Exist",
    description: "Card account not found",
    userMessage:
      "Card account not found. Please use a different payment method.",
    category: "card_issue",
  },
 
  // 90-96: System Issues
  "90": {
    code: "90",
    label: "Cutoff in Process",
    description: "System cutoff in progress",
    userMessage:
      "System maintenance in progress. Please try again in a few minutes.",
    category: "technical",
  },
  "91": {
    code: "91",
    label: "Issuer/Switch Down",
    description: "Card issuer system is unavailable",
    userMessage: "Card issuer system unavailable. Please try again later.",
    category: "technical",
  },
  "92": {
    code: "92",
    label: "Unable to Route",
    description: "Transaction routing failed",
    userMessage: "Unable to process payment. Please try again.",
    category: "technical",
  },
  "93": {
    code: "93",
    label: "Cannot Complete",
    description: "Transaction cannot be completed",
    userMessage: "Transaction could not be completed. Please try again.",
    category: "technical",
  },
  "94": {
    code: "94",
    label: "Duplicate Transmission",
    description: "Duplicate transaction detected",
    userMessage:
      "Duplicate transaction detected. Please check if your payment was already processed.",
    category: "technical",
  },
  "95": {
    code: "95",
    label: "Reconcile Error",
    description: "Reconciliation error occurred",
    userMessage: "Processing error occurred. Please try again.",
    category: "technical",
  },
  "96": {
    code: "96",
    label: "System Malfunction",
    description: "System error occurred",
    userMessage: "System error. Please try again later.",
    category: "technical",
  },
 
  // B1-B2: Surcharge Issues
  B1: {
    code: "B1",
    label: "Surcharge Not Permitted",
    description: "Surcharge is not allowed",
    userMessage: "Surcharge not allowed for this transaction.",
    category: "declined",
  },
  B2: {
    code: "B2",
    label: "Surcharge Not Supported",
    description: "Surcharge not supported by card",
    userMessage: "This card does not support surcharges.",
    category: "card_issue",
  },
 
  // N3-N8: Cash & Amount Limits
  N3: {
    code: "N3",
    label: "Cash Service Not Available",
    description: "Cash service not available",
    userMessage:
      "Cash service not available. Please use a different payment method.",
    category: "declined",
  },
  N4: {
    code: "N4",
    label: "Cash Limit Exceeded",
    description: "Cash withdrawal limit exceeded",
    userMessage: "Cash limit exceeded. Please use a different payment method.",
    category: "declined",
  },
  N8: {
    code: "N8",
    label: "Amount Limit Exceeded",
    description: "Transaction amount exceeds limit",
    userMessage:
      "Transaction amount exceeds your card limit. Please use a different payment method.",
    category: "declined",
  },
 
  // P5-P6: PIN Management
  P5: {
    code: "P5",
    label: "PIN Unblock Denied",
    description: "PIN unblock request denied",
    userMessage: "PIN issue detected. Please contact your card issuer.",
    category: "card_issue",
  },
  P6: {
    code: "P6",
    label: "PIN Change Denied",
    description: "PIN change request denied",
    userMessage: "PIN change denied. Please contact your card issuer.",
    category: "card_issue",
  },
 
  // R2: Rewards
  R2: {
    code: "R2",
    label: "Does Not Qualify",
    description: "Transaction does not qualify",
    userMessage:
      "This transaction does not qualify. Please use a different payment method.",
    category: "declined",
  },
 
  // C1-C2: Geographic Issues
  C1: {
    code: "C1",
    label: "Invalid Country Code",
    description: "Country code is invalid",
    userMessage: "Invalid country code. Please check your billing information.",
    category: "declined",
  },
  C2: {
    code: "C2",
    label: "Invalid Region Code",
    description: "Region code is invalid",
    userMessage: "Invalid region code. Please check your billing information.",
    category: "declined",
  },
 
  // 5C: Issuer Support
  "5C": {
    code: "5C",
    label: "Not Supported by Issuer",
    description: "Transaction type not supported by card issuer",
    userMessage: "This transaction type is not supported by your card issuer.",
    category: "card_issue",
  },
 
  // 9G: Cardholder Block
  "9G": {
    code: "9G",
    label: "Blocked by Cardholder",
    description: "Transaction blocked by cardholder",
    userMessage:
      "For your security, your bank requires you to authorize this purchase. Please log into your banking portal or app, or call your bank directly to confirm the transaction.",
    category: "auth_required",
  },
};
 
/**
 * Get response code information
 * @param code - MSP response code
 * @returns Response code information or generic decline message
 */
export const getMspResponseCodeInfo = (code?: string): MspResponseCodeInfo => {
  if (!code) {
    return {
      code: "UNKNOWN",
      label: "Payment Declined",
      description: "Payment was declined",
      userMessage:
        "Your card was declined. Please try again or use a different card.",
      category: "declined",
    };
  }
 
  return (
    MSP_RESPONSE_CODES[code] || {
      code,
      label: "Payment Declined",
      description: `Response code: ${code}`,
      userMessage:
        "Your card was declined. Please try again or use a different card.",
      category: "declined",
    }
  );
};
 
/**
 * Get a short user-friendly message for a response code
 * @param code - MSP response code
 * @returns Short user message
 */
export const getMspResponseMessage = (code?: string): string => {
  return getMspResponseCodeInfo(code).userMessage;
};
 
/**
 * Get the label/title for a response code
 * @param code - MSP response code
 * @returns Human-readable label
 */
export const getMspResponseLabel = (code?: string): string => {
  return getMspResponseCodeInfo(code).label;
};
 
/**
 * Check if response code requires user to contact their bank
 * @param code - MSP response code
 * @returns True if bank contact is needed
 */
export const requiresBankContact = (code?: string): boolean => {
  if (!code) return false;
  const info = getMspResponseCodeInfo(code);
  return info.category === "auth_required" || info.category === "fraud";
};