Reference: Error Codes

Complete reference for all error codes, messages, and resolution steps in the ConnexPay payments SDK


Error Categories

All SDK errors fall into two main categories:

  • VALIDATION_ERROR - Form field validation and input errors
  • PAYMENT_ERROR - Payment processing and system errors

Validation Errors (VALIDATION_ERROR)

Card Number Validation

Error MessageCauseResolution
"Card number is required"Empty card number fieldPrompt user to enter card number
"Invalid card number"Invalid card number format or fails Luhn algorithmGuide user to check card number
"Card type not supported"Card network not acceptedDisplay accepted card types
"Card number too short"Incomplete card numberPrompt user to complete entry
"Card number too long"Card number exceeds maximum lengthGuide user to check entry

Field Name: cardNumber

Example Handling:

connexpay.on('error', (error) => {
  if (error.category === 'VALIDATION_ERROR') {
    const cardNumberError = error.fields?.find(f => f.field === 'cardNumber');
    if (cardNumberError) {
      showFieldError('card-number', cardNumberError.message);
    }
  }
});

Expiration Date Validation

Error MessageCauseResolution
"Expiration date is required"Empty expiration fieldPrompt user to enter expiration date
"Invalid expiration date"Invalid date formatShow expected format (MM/YY)
"Card has expired"Expiration date is in the pastRequest different payment method
"Invalid expiration month"Month not between 01-12Guide user to correct month
"Invalid expiration year"Year format invalidShow expected year format
"Expiration date too far in future"Date more than 20 years aheadGuide user to check date

Field Name: expirationDate

Expected Formats:

  • MM/YY (preferred)
  • MM/YYYY
  • MMYY

Example Handling:

function handleExpirationError(fieldError) {
  const input = document.getElementById('expiry-input');
  const errorDiv = document.getElementById('expiry-error');
  
  errorDiv.textContent = fieldError.message;
  errorDiv.style.display = 'block';
  input.classList.add('error');
  
  // Show format hint for format errors
  if (fieldError.message.includes('Invalid expiration date')) {
    errorDiv.textContent += ' (Use MM/YY format)';
  }
}

Security Code Validation

Error MessageCauseResolution
"Security code is required"Empty CVV fieldPrompt user to enter security code
"Invalid security code"Wrong CVV format for card typeShow where to find CVV on card
"Security code too short"CVV shorter than expectedGuide user to complete entry
"Security code too long"CVV longer than expectedGuide user to check entry

Field Name: securityCode

Expected Formats:

  • Visa, Mastercard, Discover: 3 digits
  • American Express: 4 digits

Example Handling:

function showCVVHelp(cardType) {
  const helpText = cardType === 'amex' 
    ? 'Enter the 4-digit code on the front of your card'
    : 'Enter the 3-digit code on the back of your card';
    
  showTooltip('cvv-help', helpText);
}

General Form Validation

Error MessageCauseResolution
"Please complete all required fields"Multiple fields missingHighlight missing fields
"Form contains invalid data"Multiple validation errorsShow field-specific errors
"Payment method validation failed"Overall form validation failedReview all field errors

Payment Errors (PAYMENT_ERROR)

Payment Method and Transaction Errors

Based on the actual SDK implementation, these are the real error messages:

Error MessageCauseResolution
"No payment method has been selected"User hasn't selected payment methodShow payment method options
"Payment already performed"Checkout session already usedCreate new checkout session
"ConnexPay SDK is not ready"SDK not initializedWait for 'ready' event
"Apple Pay: User canceled."User canceled Apple PayAllow retry with different method
"Google Pay: User canceled."User canceled Google PayAllow retry with different method

Example Handling:

function handlePaymentError(error) {
  switch (error.message) {
    case 'No payment method has been selected':
      showPaymentMethodSelection();
      break;
    case 'Payment already performed':
      // Create new checkout session
      window.location.reload();
      break;
    case 'ConnexPay SDK is not ready':
      // Wait for SDK to be ready
      connexpay.on('ready', () => processPayment());
      break;
    case 'Apple Pay: User canceled.':
    case 'Google Pay: User canceled.':
      // Don't show error for user cancellation
      resetPaymentForm();
      break;
    default:
      showGenericError('Payment error: ' + error.message);
  }
}

Example Prevention:

let paymentInProgress = false;

async function processPayment() {
  if (paymentInProgress) {
    console.log('Payment already in progress');
    return;
  }
  
  try {
    paymentInProgress = true;
    const result = await connexpay.confirmPayment();
    // Handle success
  } catch (error) {
    if (error.message === 'Payment already performed') {
      // Create new checkout session
      window.location.reload();
    }
  } finally {
    paymentInProgress = false;
  }
}

Digital Wallet Errors

Error MessageCauseResolution
"Apple Pay: User canceled."User canceled Apple PayAllow retry with different method
"Google Pay: User canceled."User canceled Google PayAllow retry with different method

Example Handling:

function handleWalletError(error) {
  switch (error.message) {
    case 'Apple Pay: User canceled.':
    case 'Google Pay: User canceled.':
      // Don't show error for user cancellation
      resetPaymentForm();
      break;
      
    default:
      showError('Payment method error: ' + error.message);
  }
}

SDK State Management

Error MessageCauseResolution
"ConnexPay SDK is not ready"SDK not initializedWait for 'ready' event
"Payment already performed"Checkout session already usedCreate new checkout session

Error Response Structure

Complete Error Object

interface UserError extends Error {
  category: 'VALIDATION_ERROR' | 'PAYMENT_ERROR';
  message: string;         // Human-readable error message
  fields?: FieldError[];   // Field-specific errors (validation only)
}

interface FieldError {
  field: 'cardNumber' | 'expirationDate' | 'securityCode';
  message: string;
}

Example Error Responses

Validation Error:

{
  "category": "VALIDATION_ERROR",
  "message": "Please correct the following errors",
  "fields": [
    {
      "field": "cardNumber",
      "message": "Invalid card number"
    },
    {
      "field": "expirationDate", 
      "message": "Card has expired"
    }
  ]
}

Payment Error:

{
  "category": "PAYMENT_ERROR",
  "message": "No payment method has been selected"
}

Next Steps