Our API Docs just got a new look!

Lite

Installation

NPM

npm install @d24/sdk-minimal

HTML Script Tag

<script type="module" src="https://d24sdk.s3.amazonaws.com/releases/d24-minimal-1.0.19.es.js"></script>

Constructor

Initializes the SDK. This must be called before any other methods.

new SDK(publicKey, options)

Parameters

Parameter
Type
Description
Required
Possible Values

publicKey

string

Your public API key provided by D24.

Yes

options

object

Configuration options for the SDK.

Yes

options.environment

string

The environment to use.

Yes

'stg', 'production'

Usage

// NPM/ESM
import SDK from '@d24/sdk-minimal';
new SDK('as1i2nxal12bvd', { environment: 'stg' });

// UMD/Script Tag
new window.D24.SDK('as1i2nxal12bvd', { environment: 'stg' });

Errors

Error Message
Reason

SDK was already instantiate.

The SDK constructor was called more than once.

The environment [environment] is not supported.

An invalid value was passed for options.environment.

Methods

generateToken({ card })

Validates credit card details and exchanges them for a secure, single-use token. This is an asynchronous method.

Returns: Promise<{token: string}> - A promise that resolves to an object containing the token.

Parameters

Parameter
Type
Description
Required

card

object

An object containing the credit card details.

Yes

card.number

string

The full credit card number.

Yes

card.holder

string

The full name of the cardholder.

Yes

card.cvv

string

The 3-digit (or 4-digit for Amex) security code.

Yes

card.expirationMonth

string

The 2-digit expiration month (e.g., "09").

Yes

card.expirationYear

string

The 2-digit expiration year (e.g., "25").

Yes

Usage

const cardDetails = {
  number: '4509953566233704',
  holder: 'Juan Perez',
  cvv: '123',
  expirationMonth: '11',
  expirationYear: '25',
};

try {
  const response = await window.D24.generateToken({ card: cardDetails });
  const token = response.token;
  // Send token to your server
} catch (error) {
  // Handle validation errors from the Joi library or API errors.
  console.error(error);
}

Errors

Error Message
Reason

You must instantiate D24CreditCardSDK before using SDK methods

generateToken was called before the SDK was initialized with new SDK().

(Joi Validation Error)

The card object failed validation. The error message will describe the specific field that is invalid.

Last updated

Was this helpful?