Skip to main content

TumiPay Cards JS

JavaScript/TypeScript SDK for secure credit and debit card tokenization.

Installation

npm install tumipay-cards-js

Quick Start

import { TumiPayCardPaymentSDK } from 'tumipay-cards-js';

const sdk = new TumiPayCardPaymentSDK({
  environment: 'staging',
  currency: 'COP',
});

await sdk.initialize({ merchantId: 'your-merchant-id' });

const validation = sdk.validateCard({
  cardNumber: '4111111111111111',
  cardHolderName: 'John Doe',
  expirationMonth: '12',
  expirationYear: '29',
  cvv: '123',
});

if (validation.status) {
  const tokenResult = await sdk.generateSubscriptionToken({
    cardNumber: '4111111111111111',
    cardHolderName: 'John Doe',
    expirationMonth: '12',
    expirationYear: '29',
    cvv: '123',
  });
  // tokenResult.data.token → subscription token
}

Standard Response

All methods return the same envelope:
{
  code: string;      // "SUCCESS" or error code
  status: boolean;   // true = success
  message: string;   // Human-readable description
  data?: T;          // Payload (when status is true)
  errors?: Array<{   // Only in validateCard when status is false
    code: string;
    field: string;
    message: string;
  }>;
}

Constructor

new TumiPayCardPaymentSDK({
  environment: 'staging' | 'production',
  currency: string,   // e.g. "COP", "USD"
})
Does not make network calls. Only configures the instance.

initialize({ merchantId })

Fetches merchant configuration from the TumiPay server and prepares the SDK for operation. Must be called before generateSubscriptionToken and getBinInfo.
const result = await sdk.initialize({ merchantId: 'your-merchant-id' });

Response

{
  "initialized": true,
  "code": "SUCCESS",
  "status": true,
  "message": "Configuración obtenida correctamente",
  "data": {
    "payment_provider": {
      "external_merchant_id": "1c038e84ed014abb94eb229447f3684d",
      "public_key": "e7c352d9a067475f90bfd92301265efe",
      "environment": "uat"
    },
    "otp_config": {
      "id_credentials": "9c642a3e5034468693fbf2830146c08c",
      "public_key": "55ced6048f19446aa0f0ae26dcf10abf",
      "private_key": "6aaa48606fde4a10aef6833627c9677f"
    }
  }
}

Error Codes

CodeDescriptionHow to Fix
INVALID_MERCHANT_IDmerchantId is empty or not providedEnsure a valid merchantId is passed
APP_CONFIGURATION_ERRORFailed to retrieve configuration from serverCheck connectivity and that the merchantId exists in TumiPay
SDK_INIT_ERRORGeneric initialization errorCheck the error message for more details

validateCard(request)

Validates card data locally — no network calls. Does not require initialization.

Parameters

FieldTypeRequiredDescription
cardNumberstringCard number (13–19 digits)
cardHolderNamestringCardholder name (min. 2 characters)
expirationMonthstringExpiry month: "01""12"
expirationYearstringExpiry year: "YY" or "YYYY"
cvvstringCVV: 3 digits (4 for Amex)

Response — success

{
  "code": "SUCCESS",
  "status": true,
  "message": "Tarjeta válida",
  "data": {
    "bin": "411111",
    "brand": "visa",
    "lastFourDigits": "1111",
    "maskedCard": "****1111"
  }
}

Response — validation error

{
  "code": "CARD_EXPIRED",
  "status": false,
  "message": "La validación de la tarjeta falló",
  "errors": [
    { "code": "CARD_EXPIRED", "field": "expiration", "message": "La tarjeta ha expirado" }
  ]
}

Supported Brands

BrandPattern
visaStarts with 4, 13–16 digits
mastercardStarts with 5155, 16 digits
amexStarts with 34 or 37, 15 digits
discoverStarts with 6011 or 65, 16 digits
dinersStarts with 300305, 36 or 38, 14 digits
jcbStarts with 2131, 1800 or 35, 15–16 digits

Error Codes

CodeFieldDescriptionHow to Fix
CARD_NUMBER_EMPTYcardNumberCard number is emptyProvide the card number
CARD_NUMBER_INVALID_FORMATcardNumberNon-numeric characters foundUse digits only, no spaces or dashes
CARD_NUMBER_INVALID_LENGTHcardNumberLength outside 13–19 rangeVerify the full card number is entered
CARD_NUMBER_LUHN_FAILEDcardNumberFails Luhn algorithmThe card number is invalid; double-check it
CARDHOLDER_NAME_EMPTYcardHolderNameCardholder name is emptyProvide the name as shown on the card
CARDHOLDER_NAME_TOO_SHORTcardHolderNameName shorter than 2 charactersEnter the cardholder’s full name
EXPIRY_MONTH_INVALIDexpirationMonthMonth outside 01–12Use format "01" to "12"
EXPIRY_YEAR_INVALIDexpirationYearYear not providedProvide the expiration year
CARD_EXPIREDexpirationCard is expiredUse a card with a valid expiration date
CVV_EMPTYcvvCVV is emptyProvide the security code
CVV_INVALID_LENGTHcvvCVV has wrong lengthUse 3 digits (4 for American Express)
BRAND_NOT_ALLOWEDcardNumberUnsupported card brandUse Visa, Mastercard, Amex, Discover, Diners or JCB

generateSubscriptionToken(card)

Generates a subscription token via Kushki. Requires prior initialization. Kushki credentials are sourced automatically from the context loaded in initialize().

Parameters

FieldTypeRequiredDescription
cardNumberstringCard number
cardHolderNamestringCardholder name
expirationMonthstringExpiry month
expirationYearstringExpiry year
cvvstringCVV
documentNumberstringDocument number (optional, required in some markets)
emailstringEmail address (optional)

Response

{
  "code": "SUCCESS",
  "status": true,
  "message": "Token de suscripción generado correctamente",
  "data": {
    "token": "2da0dd03c6e54ebd80b1a09a2d17ea9e"
  }
}

Error Codes

CodeDescriptionHow to Fix
SDK_NOT_INITIALIZEDinitialize() was not called firstCall sdk.initialize({ merchantId }) before this method
MISSING_PUBLIC_KEYpublic_key missing in configuration responseVerify the merchant has a payment provider configured
MISSING_CURRENCYcurrency not set in constructorPass currency when creating the SDK instance

getBinInfo(bin)

Fetches bank, brand, and card type from Kushki. Requires prior initialization.
const result = await sdk.getBinInfo('411111');

Parameters

FieldTypeRequiredDescription
binstringFirst 6 digits of the card number (or full number)

Response

{
  "code": "SUCCESS",
  "status": true,
  "message": "Información de BIN obtenida correctamente",
  "data": {
    "brand": "visa",
    "bank": "JPMORGAN CHASE BANK, N.A.",
    "cardType": "credit"
  }
}

Error Codes

CodeDescriptionHow to Fix
SDK_NOT_INITIALIZEDinitialize() was not called firstCall sdk.initialize({ merchantId }) before this method
INVALID_BINBIN has fewer than 6 digitsProvide at least the first 6 digits of the card number

Helper Methods

sdk.isInitialized()  // boolean — true if initialize() succeeded
sdk.getConfig()      // { environment, currency }

TypeScript Types

import type {
  SdkConfig,
  SdkInitOptions,
  SdkInitializationResult,
  ValidateCardRequest,
  ValidateCardResult,
  ValidateCardError,
  ValidateCardSuccessData,
  GenerateTokenResult,
  GetBinInfoResult,
} from 'tumipay-cards-js';

Utility Functions

import {
  validateCardNumber,
  validateCard,
  detectCardBrand,
  getCardBrand,
  luhnCheck,
  formatCardNumber,
  formatExpiry,
  maskCardNumber,
  ALLOWED_CARD_BRANDS,
} from 'tumipay-cards-js';