Skip to content
Last updated

NPS SDK Reference

Complete SDK Reference

All variables, functions, options, and callbacks available to merchants

Table of Contents


Constructor Options

new NPS(config)

Creates a new NPS SDK instance.

Parameters:

OptionTypeRequiredDefaultDescription
sessionTokenstringYes-JWT session token from your backend
sessionIdstringYes-Session ID from your backend
onReadyfunctionNo() => {}Callback when SDK is initialized
onTokenizationCompletefunctionNo() => {}Callback when tokenization succeeds
onErrorfunctionNo() => {}Callback for error handling

Example:

const nps = new NPS({
    sessionToken: 'your_session_token',
    sessionId: 'your_session_id',
    onReady: () => console.log('SDK ready'),
    onTokenizationComplete: (result) => console.log('Token:', result.token),
    onError: (error) => console.error('Error:', error)
});

Instance Methods

mount(containerSelector, options)

Mounts the payment form iframe to the specified container.

Parameters:

ParameterTypeRequiredDescription
containerSelectorstring or HTMLElementYesCSS selector or DOM element (e.g., '#payment-form')
optionsobjectNoMount options (see Mount Options)

Returns: void

Example:

nps.mount('#payment-form', {
    paymentMethod: 'card',
    displayOptions: { showLabels: true },
    styling: { theme: 'light' }
});

updatePaymentMethod(method)

Switches the payment method without remounting.

Parameters:

ParameterTypeRequiredDescription
methodstringYesPayment method: 'card', 'ach', or 'applepay'

Returns: void

Example:

// Switch to ACH
nps.updatePaymentMethod('ach');

// Switch to card
nps.updatePaymentMethod('card');

// Switch to Apple Pay
nps.updatePaymentMethod('applepay');

tokenize(data)

Tokenizes payment data and returns a payment token.

Parameters:

ParameterTypeRequiredDescription
dataobjectYesTokenization data (see Tokenization Data)

Returns: Promise<object> - Resolves with tokenization result

Example:

const result = await nps.tokenize({
    amount: 49.99,
    cardholderName: 'John Doe',
    billingAddress: {
        name: 'John Doe',
        street: '123 Main St',
        city: 'Anytown',
        state: 'CA',
        postalCode: '90210',
        country: 'US'
    },
    metadata: {
    }
});

console.log(result.token); // Payment token

Result Object:

PropertyTypeDescription
tokenstringPayment token to send to backend

destroy()

Removes the iframe and cleans up resources.

Parameters: None

Returns: void

Example:

nps.destroy();

Mount Options

The mount() method accepts an options object with the following properties:

Options Object:

OptionTypeRequiredDescription
paymentMethodstringNo'card', 'ach', or 'applepay' (default: 'card')
displayOptionsobjectNoDisplay options (see Display Options)
stylingobjectNoStyling options (see Styling Options)
widthstringNoIframe width (e.g., '100%', '500px', 'auto')

Example:

nps.mount('#payment-form', {
    paymentMethod: 'card',
    width: '100%',
    displayOptions: {
        showLabels: true,
        showIcons: true,
        showErrors: true
    },
    styling: {
        theme: 'light',
        colors: { focusBorder: '#3B82F6' }
    }
});

Display Options

OptionTypeRequiredDefaultDescription
showLabelsbooleanNotrueShow field labels
showIconsbooleanNotrueShow card brand icons
showErrorsbooleanNotrueShow validation error messages
showPlaceholdersbooleanNotrueShow placeholder text in inputs
showRequiredIndicatorbooleanNotrueShow asterisk (*) for required fields
showSecurityCodeIndicatorbooleanNotrueShow CVV/CVC security code icon

Example:

displayOptions: {
    showLabels: true,
    showIcons: true,
    showErrors: true,
    showPlaceholders: true,
    showRequiredIndicator: true,
    showSecurityCodeIndicator: true
}

Styling Options

Theme Options

OptionTypeRequiredDefaultDescription
themestringNo'light''light' or 'dark'
labelStylestringNo'stacked''stacked', 'floating', or 'hidden'
fieldStylestringNo'outlined''outlined', 'filled', or 'underlined'
fieldLayoutstringNo'stacked''stacked', 'inline-split', or 'inline' (Card only)

Typography Options

OptionTypeRequiredDefaultDescription
fontFamilystringNo'Inter'Font family (e.g., 'Inter, sans-serif')
fontSizenumber or stringNo15Input font size in pixels
labelFontSizenumber or stringNo14Label font size in pixels
labelFontWeightnumberNo500Label font weight (100-900)
helpTextFontSizenumber or stringNo14Help text font size in pixels
helpTextFontWeightnumberNo400Help text font weight (100-900)
errorFontSizenumber or stringNo12Error message font size in pixels

Color Options

OptionTypeRequiredDefaultDescription
colors.labelstringNo'#5A5E66'Label text color
colors.borderstringNo'#C4C8CC'Input border color
colors.focusBorderstringNo'#3B82F6'Border color when focused
colors.errorstringNo'#D32F2F'Error text and border color
colors.textstringNo'#000000'Input text color
colors.backgroundstringNo'#FFFFFF'Input background color (light theme)
colors.filledBackgroundstringNo'#F3F4F6'Background for filled field style
colors.helpTextstringNo'#9CA3AF'Help text and placeholder color
colors.buttonBackgroundstringNo'#000'Button background color (Apple Pay)
colors.buttonColorstringNo'white'Button text color
colors.buttonHoverBackgroundstringNo'#1a1a1a'Button hover background
colors.buttonBorderColorstringNotransparentButton border color

Spacing & Dimension Options

OptionTypeRequiredDefaultDescription
spacingnumberNo12Spacing between elements in pixels (0-32px)
borderRadiusnumber or stringNo4Border radius in pixels (0-32px)
borderWidthnumberNo1Border width in pixels (0-32px)
inputHeightnumberNo36Input field height in pixels (min 20px)
inputPaddingstringNo'10px 12px'Input padding (CSS format)
iframeWidthstringNo'100%'Iframe width (e.g., '100%', '500px')

Complete Example:

styling: {
    theme: 'light',
    labelStyle: 'stacked',
    fieldStyle: 'outlined',
    fieldLayout: 'stacked',
    fontFamily: 'Inter, sans-serif',
    fontSize: 15,
    labelFontSize: 14,
    labelFontWeight: 500,
    helpTextFontSize: 14,
    helpTextFontWeight: 400,
    colors: {
        label: '#5A5E66',
        border: '#C4C8CC',
        focusBorder: '#3B82F6',
        error: '#D32F2F',
        text: '#000000',
        background: '#FFFFFF',
        helpText: '#9CA3AF',
        filledBackground: '#F3F4F6'
    },
    spacing: 12,
    borderRadius: 4,
    borderWidth: 1,
    inputHeight: 36,
    inputPadding: '10px 12px',
    iframeWidth: '100%',
    focusShadow: '0 0 0 3px rgba(59, 130, 246, 0.1)'
}

Tokenization Data

The tokenize() method accepts a data object with the following structure:

Required Fields:

FieldTypeRequiredDescription
amountnumberYesPayment amount (e.g., 49.99 for $49.99)
cardholderNamestringYesFull cardholder name (e.g., 'John Doe')
billingAddressobjectYesBilling address object (see below)

Billing Address Object:

FieldTypeRequiredDescription
namestringYesFull name
streetstringYesStreet address
citystringYesCity
statestringYesState/Province (2-letter code for US)
postalCodestringYesZIP/Postal code
countrystringYesCountry code (e.g., 'US')

Optional Fields:

FieldTypeRequiredDescription
accountTypestringFor ACHAccount type: 'checking' or 'savings' (required for ACH payments)
metadataobjectNoAdditional metadata

Example:

const result = await nps.tokenize({
    amount: 49.99,
    cardholderName: 'John Doe',
    billingAddress: {
        name: 'John Doe',
        street: '123 Main St',
        city: 'Anytown',
        state: 'CA',
        postalCode: '90210',
        country: 'US'
    },
    metadata: {
    }
});

Callback Functions

onReady()

Called when the SDK is initialized and ready to use.

Parameters: None

Example:

const nps = new NPS({
    sessionToken: 'token',
    sessionId: 'session_123',
    onReady: () => {
        console.log('SDK is ready!');
        // Enable submit button, show form, etc.
    }
});

onTokenizationComplete(result)

Called when tokenization succeeds.

Parameters:

ParameterTypeDescription
resultobjectTokenization result (see Tokenization Result)

Example:

const nps = new NPS({
    sessionToken: 'token',
    sessionId: 'session_123',
    onTokenizationComplete: (result) => {
        console.log('Token:', result.token);
        
        // Send token to your backend
        fetch('/api/process-payment', {
            method: 'POST',
            body: JSON.stringify({ token: result.token })
        });
    }
});

Tokenization Result:

PropertyTypeDescription
tokenstringPayment token (send to backend)

onError(error)

Called when an error occurs.

Parameters:

ParameterTypeDescription
errorobjectError object (see Error Codes)

Example:

const nps = new NPS({
    sessionToken: 'token',
    sessionId: 'session_123',
    onError: (error) => {
        console.error('Error code:', error.code);
        console.error('Error message:', error.message);
        
        switch(error.code) {
            case 'VALIDATION_ERROR':
                // Show validation errors to user
                break;
            case 'SESSION_EXPIRED':
                // Refresh session token
                break;
            case 'NETWORK_ERROR':
                // Retry request
                break;
        }
    }
});

Error Codes

CodeDescriptionSolution
VALIDATION_ERRORInvalid input in payment fieldsCheck form fields and show errors to user
SESSION_EXPIREDSession token has expiredRequest new session token from backend
NETWORK_ERRORNetwork connectivity issueRetry request or check connection
TOKENIZATION_FAILEDTokenization request failedCheck error message and retry
SDK_ERRORSDK initialization or mount errorEnsure SDK is properly initialized

Error Object Structure:

{
    code: 'VALIDATION_ERROR',
    message: 'Invalid card number',
    fields: {
        cardNumber: 'Invalid card number'
    }
}

Payment Methods

ValueDescription
'card'Credit or debit card
'ach'ACH bank transfer
'applepay'Apple Pay

Example:

// Mount with card payment
nps.mount('#payment-form', { paymentMethod: 'card' });

// Switch to ACH
nps.updatePaymentMethod('ach');

// Switch to Apple Pay
nps.updatePaymentMethod('applepay');

Events

Custom Events (Optional)

You can also use custom events instead of callbacks:

Mount Event:

window.addEventListener('nps-mount', (event) => {
    const { containerSelector, options } = event.detail;
    // Mount will be called automatically
});

window.dispatchEvent(new CustomEvent('nps-mount', {
    detail: {
        containerSelector: '#payment-form',
        options: { paymentMethod: 'card' }
    }
}));

Update Payment Method Event:

window.addEventListener('nps-update-payment-method', (event) => {
    const { method } = event.detail;
    // Update will be called automatically
});

window.dispatchEvent(new CustomEvent('nps-update-payment-method', {
    detail: { method: 'ach' }
}));

Tokenize Event:

window.addEventListener('nps-tokenization-complete', (event) => {
    const result = event.detail;
    console.log('Token:', result.token);
});

window.addEventListener('nps-tokenization-error', (event) => {
    const error = event.detail;
    console.error('Error:', error);
});

window.dispatchEvent(new CustomEvent('nps-tokenize', {
    detail: {
        additionalData: {
            amount: 49.99,
            cardholderName: 'John Doe',
            billingAddress: { /* ... */ }
        }
    }
}));

Complete Example

// 1. Initialize SDK
const nps = new NPS({
    sessionToken: await fetchSessionToken(),
    sessionId: 'session_123',
    onReady: () => console.log('Ready'),
    onTokenizationComplete: (result) => {
        console.log('Token:', result.token);
        // Send to backend
    },
    onError: (error) => console.error('Error:', error)
});

// 2. Mount payment form
nps.mount('#payment-form', {
    paymentMethod: 'card',
    width: '100%',
    displayOptions: {
        showLabels: true,
        showIcons: true,
        showErrors: true,
        showPlaceholders: true,
        showRequiredIndicator: true,
        showSecurityCodeIndicator: true
    },
    styling: {
        theme: 'light',
        labelStyle: 'stacked',
        fieldStyle: 'outlined',
        fieldLayout: 'stacked',
        fontFamily: 'Inter, sans-serif',
        fontSize: 15,
        labelFontSize: 14,
        labelFontWeight: 500,
        colors: {
            label: '#5A5E66',
            border: '#C4C8CC',
            focusBorder: '#3B82F6',
            error: '#D32F2F',
            text: '#000000',
            helpText: '#9CA3AF'
        },
        spacing: 12,
        borderRadius: 4,
        borderWidth: 1,
        inputHeight: 36,
        iframeWidth: '100%'
    }
});

// 3. Switch payment method
nps.updatePaymentMethod('ach');

// 4. Tokenize payment
const result = await nps.tokenize({
    amount: 49.99,
    cardholderName: 'John Doe',
    billingAddress: {
        name: 'John Doe',
        street: '123 Main St',
        city: 'Anytown',
        state: 'CA',
        postalCode: '90210',
        country: 'US'
    },
    accountType: 'checking', // Required for ACH
    metadata: {
    }
});

// 5. Clean up
nps.destroy();

Support Resources

Need Help?

Technical Support
NPSTechSupport@nelnet.net