Complete API reference for the Widget SDK. This document describes every constructor option, method, callback, styling property, and error code available in the SDK.
For step-by-step integration guides, see Card & ACH, Apple Pay, and PayPal & Venmo.
Creates a new SDK instance and establishes a session. onTokenizationComplete is required. Everything else is optional and depends on which payment methods you plan to use.
Creating Session Token Using JWT
| Option | Type | Required | Description |
|---|---|---|---|
tokenGroup | string | No | Token group name as per NPS |
entityId | string | Preferred | A unique ID assigned by NPS that represents the client |
For Apple Pay, the merchant identifier is passed in the applePay mount options (not the constructor), and the domain is detected automatically from the page — see applePay Sub-Options.
| Option | Type | Required | Description |
|---|---|---|---|
onReady | function | No | Invoked when the payment form is fully initialized |
onTokenizationComplete | function | Yes | Invoked after successful tokenization |
onError | function | No | Invoked on SDK or tokenization errors (see Error Codes) |
onCancel | function | No | Invoked when the user cancels a PayPal/Venmo/Apple Pay payment |
onHelpClick | function | No | Invoked when the payer clicks a field's help icon (see onHelpClick) |
onFormReady | function | No | Invoked when the card/ACH form becomes complete and valid, or regresses (see onFormReady) |
onFieldErrors | function | No | Invoked when tokenize() is blocked by field validation errors (see onFieldErrors) |
const wg = new Widget({
tokenGroup: '<TOKEN_GROUP>',
entityId: '<ENTITY_ID>',
onReady: () => {},
onTokenizationComplete: (result) => {},
onError: (error) => {},
onCancel: (payload) => {}
});Renders the payment UI inside the specified container element.
- For card and ACH, this renders a secure hosted payment form inside an iframe.
- For paypal, venmo, or paypalVenmo, this loads the PayPal SDK and renders checkout button(s) directly in the container.
- For applePay, the SDK loads the Apple Pay JS SDK and renders the Apple Pay button directly in the container.
Styling and display options can be passed here to control the look and feel of the payment form. See Styling and Display Options for all available options.
| Parameter | Type | Required | Description |
|---|---|---|---|
container | stringHTMLElement | Yes | CSS selector or DOM element |
options | object | No | Mount configuration |
| Option | Type | Description |
|---|---|---|
paymentMethod | string | card, ach, paypal, venmo, paypalVenmo, or applePay |
styling | object | Styling configuration (see Styling) |
displayOptions | object | Field visibility toggles (see Display Options) |
width | string | Payment form width (e.g. '100%') |
paypal | object | PayPal/Venmo options (see below) |
applePay | object | Apple Pay options (see applePay Sub-Options) |
supportedCardBrands | array | Card only. Accepted card brands (see Card and ACH Field Options) |
requireAccountConfirmation | boolean | ACH only. Renders a Confirm Account Number field (see Card and ACH Field Options) |
helpIcons | array | Field ids that render a help icon (see Card and ACH Field Options) |
locale | string | Payer-facing language of the payment form: en (default) or es (see Card and ACH Field Options) |
These options apply to the direct card and ACH mounts only; they do not apply to PayPal, Venmo, Apple Pay, or the hosted Payment Widget modes. All are optional.
| Option | Applies to | Description |
|---|---|---|
supportedCardBrands | Card | Array of accepted brands: visa, mastercard, amex, discover, diners, jcb, unionpay. Common aliases are normalized (e.g. 'American Express' → amex, 'MC' → mastercard); case, spaces, hyphens, and underscores are ignored; unknown entries are dropped. If the option is omitted, or nothing valid remains after normalization, all detected brands are accepted, so a mistyped list can never block the payment form. When the payer enters a card of an unsupported brand, a localized inline error appears below the card field and the brand's icon is hidden. |
requireAccountConfirmation | ACH | Renders a "Confirm Account Number" field that must match the account number before tokenization. Paste is blocked in the confirm field, and the confirm value never leaves the payment form; it is not transmitted or included in tokenize data. Default false. |
helpIcons | Both | Array of field ids that render a keyboard-accessible ? icon beside the field label: cardNumber, expiryDate, securityCode, routingNumber, accountNumber, confirmAccountNumber. Clicking the icon invokes onHelpClick. The SDK renders no help content itself; your page shows the modal or tooltip. |
locale | Both | Language of the payer-facing text inside the payment form (labels, placeholders, validation messages): en (default) or es. Region variants are normalized (es-MX → es); unknown values fall back to en. Your surrounding page is unaffected. |
const wg = new Widget({
onTokenizationComplete: (result) => { /* ... */ },
onHelpClick: ({ field }) => showHelpModal(field),
onFormReady: ({ ready }) => { payButton.disabled = !ready; }
});
wg.mount('#payment-form', {
paymentMethod: 'card',
supportedCardBrands: ['visa', 'mastercard'],
helpIcons: ['securityCode'],
locale: 'es'
});| Option | Type | Required | Description |
|---|---|---|---|
returnUrl | string | Yes | URL PayPal redirects to on approval |
cancelUrl | string | Yes | URL PayPal redirects to on cancellation |
| Value | Renders |
|---|---|
card | Secure card input form (iframe) |
ach | Secure ACH input form (iframe) |
paypal | PayPal checkout button |
venmo | Venmo checkout button |
paypalVenmo | Both PayPal and Venmo buttons (only eligible buttons are shown) |
applePay | Apple Pay button |
Card / ACH Example:
wg.mount('#payment-container', {
paymentMethod: 'card',
styling: { ... },
displayOptions: { ... }
});PayPal Example:
wg.mount('#paypalVenmo-container', {
paymentMethod: 'paypal',
paypal: {
returnUrl: 'https://example.com/success',
cancelUrl: 'https://example.com/cancel'
}
});paypalVenmo Example (Renders Both PayPal And Venmo):
wg.mount('#paypalVenmo-container', {
paymentMethod: 'paypalVenmo',
paypal: {
returnUrl: 'https://example.com/success',
cancelUrl: 'https://example.com/cancel'
}
});Sets or refreshes the session token used by the SDK for all payment API calls. This method must be called before tokenize() (for card/ACH) or before the user clicks a PayPal, Venmo, or Apple Pay button. The token is stored internally and used for all subsequent API calls until updated again.
Call this method whenever you need to provide a fresh session token — for example, when the user selects a paypalVenmo payment method, or right before submitting a card/ACH payment.
| Parameter | Type | Required | Description |
|---|---|---|---|
token | string | Yes | A valid session token |
const token = await fetchSessionToken();
wg.updateSessionToken(token);Switches the active payment method without tearing down and remounting. This is useful when your checkout page lets the customer toggle between card, ACH, and paypalVenmo payment methods.
When switching between card/ACH and PayPal/Venmo/paypalVenmo, the SDK automatically handles cleanup and re-rendering.
| Parameter | Type | Required | Description |
|---|---|---|---|
method | string | Yes | card, ach, paypal, venmo, or paypalVenmo |
options | object | No | Additional options |
| Option | Type | Description |
|---|---|---|
accountType | string | checking or savings (ACH only) |
wg.updatePaymentMethod('ach', { accountType: 'checking' });wg.updatePaymentMethod('paypalVenmo');Triggers tokenization for card and ACH payment methods only. When called, the SDK securely collects the payment data from the hosted form and exchanges it for an NPS token.
A session token must be set via updateSessionToken() before calling this method.
On success, onTokenizationComplete is invoked with the token and associated metadata. On failure, onError is invoked with a structured error payload. If the iframe does not respond within 30 seconds, the SDK automatically times out and emits an UNEXPECTED_ERROR.
Apple Pay, PayPal, and Venmo do not use this method. Those payment methods handle tokenization through their respective button clicks — the customer's interaction triggers the flow directly, and results are delivered via onTokenizationComplete.
| Field | Type | Required | Description |
|---|---|---|---|
amount | number | Yes | Payment amount |
accountHolderName | string | Preferred | Payer name |
billingAddress | object | Preferred | Billing address (see fields below) |
accountType | string | ACH only | checking or savings |
tenderType | string | ACH only | e.g. Consumer |
metadata | object | No | Merchant-defined metadata |
| Field | Type | Required | Description |
|---|---|---|---|
addressLine1 | string | Yes | Street address |
addressLine2 | string | No | Apartment, suite, unit, etc. |
city | string | Yes | City |
state | string | Yes | State or province |
postalCode | string | Yes | Postal / ZIP code |
country | string | Yes | Country code (e.g. US) |
const token = await fetchSessionToken();
wg.updateSessionToken(token);
const result = await wg.tokenize({
amount: 125.00,
accountHolderName: 'Jane Smith',
billingAddress: {
addressLine1: '123 Main St',
addressLine2: 'Suite 100', // optional
city: 'Omaha',
state: 'NE',
postalCode: '68102',
country: 'US'
}
});Apple Pay is rendered via mount() with paymentMethod: 'applePay' and an applePay options object. The SDK renders an Apple Pay button directly on the merchant page. When the customer clicks the button, the native Apple Pay payment sheet opens with the amount specified in applePay.total. After the customer authorizes, onTokenizationComplete is invoked with the token (result.paymentMethod is 'applePay'). There is no separate tokenize() call for Apple Pay.
The SDK automatically loads the Apple Pay JS SDK. On non-Safari browsers (Chrome, Edge, including Windows), the payment sheet is replaced by a code the customer scans with an iPhone (iOS 18+) to authorize the payment there.
The merchant must host the Apple domain verification file at /.well-known/apple-developer-merchantid-domain-association on their registered domain. The SDK always uses the hostname of the page for merchant validation, so the checkout page must be served from that verified domain — there is no domain option to configure.
A session token must be set via updateSessionToken() before the customer clicks the button. The country and currency are always US and USD. Supported card networks are Visa, Mastercard, American Express, and Discover.
| Field | Type | Required | Description |
|---|---|---|---|
total | object | Yes | { label, amount } — the payment sheet total. Both fields are required; amount is a string (e.g. '75.00') greater than zero. |
displayName | string | No | Merchant name used during Apple merchant validation. Defaults to total.label. |
partnerInternalMerchantIdentifier | string | No | Apple Pay merchant identifier, used during merchant validation. For multi-merchant, defaults to the first context's partnerMerchantIdentifier. |
lineItems | array | No | Itemized breakdown shown on the sheet above the total (see below) |
multiTokenContexts | array | Multi-merchant only | Array of merchant contexts (see below). Requires Apple Pay version 14+. Cannot be combined with recurringPaymentRequest. |
recurringPaymentRequest | object | Recurring only | Recurring payment configuration (see below). Requires Apple Pay version 14+. |
The sum of the context amounts cannot exceed total.amount.
| Field | Type | Required | Description |
|---|---|---|---|
partnerMerchantIdentifier | string | Yes | Apple Pay merchant identifier |
entityId | string | Yes | A unique ID assigned by NPS that represents the client |
amount | string | Yes | Amount for this merchant |
entityName | string | No | The merchant's display name (merchantName is accepted as an alias). Defaults to the total label. |
merchantDomain | string | No | Domain for this merchant. Defaults to the page's hostname. |
| Field | Type | Required | Description |
|---|---|---|---|
label | string | Yes | Description of the line item (e.g. Tuition, Service Fee) |
amount | string | Yes | Amount for this line item |
The SDK validates the required fields and rejects the request with an error if any are missing. The recurring payment plan (billing schedule, agreement, and any trial pricing) is managed by NPS, not Apple.
| Field | Type | Required | Description |
|---|---|---|---|
paymentDescription | string | Yes | Description of the recurring payment shown on the payment sheet |
regularBilling | object | Yes | Recurring line item: label and amount |
managementURL | string | Yes | Page on your site where the customer can manage or cancel the subscription. Apple links to it from the Wallet app. |
One-time payment:
wg.mount('#apple-pay-button', {
paymentMethod: 'applePay',
applePay: {
total: { label: 'Nelnet Campus Commerce', amount: '75.00' },
partnerInternalMerchantIdentifier: '<MERCHANT_IDENTIFIER>'
}
});Multi-merchant payment:
wg.mount('#apple-pay-button', {
paymentMethod: 'applePay',
applePay: {
total: { label: 'Total Amount', amount: '110.00' },
lineItems: [
{ label: 'AAA University', amount: '100.00' },
{ label: 'BBB Service Fee', amount: '10.00' }
],
multiTokenContexts: [
{
partnerMerchantIdentifier: 'TESTCLIENT_a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',
entityId: 'A-123',
entityName: 'AAA University',
amount: '100.00'
},
{
partnerMerchantIdentifier: 'TESTCLIENT_a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',
entityId: 'B-456',
entityName: 'BBB Service Fee',
amount: '10.00'
}
]
}
});Recurring payment:
Set total.amount (the sheet total) to the recurring amount in regularBilling.
wg.mount('#apple-pay-button', {
paymentMethod: 'applePay',
applePay: {
total: { label: 'Meal Plan Subscription', amount: '9.99' },
partnerInternalMerchantIdentifier: '<MERCHANT_IDENTIFIER>',
recurringPaymentRequest: {
paymentDescription: 'Campus Meal Plan — billed monthly',
regularBilling: {
label: 'Meal Plan Subscription',
amount: '9.99'
},
managementURL: 'https://checkout.example.com/account/subscriptions'
}
}
});Moves keyboard focus to a field inside the secure payment form (card and ACH mounts only). Typically used together with onFieldErrors so an error-summary banner on your page can jump the payer to the field that needs attention.
| Parameter | Type | Required | Description |
|---|---|---|---|
field | string | Yes | One of cardNumber, expiryDate, securityCode, routingNumber, accountNumber, confirmAccountNumber |
wg.focusField('cardNumber');Unmounts the payment form, removes event listeners, and releases all resources held by the SDK instance. Call this when the checkout page is being torn down or when the payment form is no longer needed.
wg.destroy();Invoked when the payment form is fully initialized and ready to accept input. This is a good place to enable your "Pay" button or show the payment form container if it was hidden during loading.
Invoked after successful tokenization. This callback is used by all payment methods — card, ACH, Apple Pay, PayPal, and Venmo. The result contains the NPS token and metadata about the payment credential. The exact set of properties depends on the payment method. Some of them are given below.
| Property | Type | Description |
|---|---|---|
token | string | Secure payment token |
category | string | Card category (e.g. CREDIT, DEBIT) |
lastFourtokenLastFour | string | Last four digits of the card or account number |
network | string | Card network (e.g. VISA, MASTERCARD, AMEX, DISCOVER) |
isoCountry | string | Issuing country name |
isoCountryCode | string | Issuing country code |
isInternational | boolean | Whether the card is international |
tokenGroupName | string | Token group name |
paymentMethod | string | Payment method used (applePay, paypal, or venmo; not set for card/ACH) |
paymentTransactionId | string | Transaction ID (PayPal/Venmo only) |
accountHolderName | string | Name of the account holder (PayPal, Venmo) |
accountHolderId | string | Unique ID of the account holder record (PayPal, Venmo) |
phoneNumber | string | Account holder's phone number (PayPal, Venmo) |
emailAddress | string | Account holder's email address (PayPal, Venmo) |
Invoked when a validation, session, network, or provider error occurs. The error object always contains responseCode, responseMessage, and a description string.
| Property | Type | Description |
|---|---|---|
responseCode | string | Standardized error code (see Error Codes) |
responseMessage | string | Error category identifier |
description | string | Human-readable error detail |
onError: (error) => {
console.error(`[${error.responseCode}] ${error.responseMessage}: ${error.description}`);
}Invoked when the user cancels a PayPal, Venmo, or Apple Pay payment (e.g. closes the popup without completing). This callback is not fired for card or ACH — those flows have no cancel concept since the form is inline.
The payload follows the same structure as error payloads.
| Property | Type | Description |
|---|---|---|
responseCode | string | E402 |
responseMessage | string | PAYMENT_CANCELLED |
description | string | Human-readable cancellation message |
onCancel: (payload) => {
console.log(payload.description); // "Payment cancelled by user"
}Invoked when the payer clicks the ? help icon beside a field (rendered via the helpIcons mount option). The SDK renders no help content; displaying a modal or tooltip is your page's job.
| Property | Type | Description |
|---|---|---|
field | string | Id of the field whose icon was clicked (e.g. securityCode) |
Also dispatched as a window CustomEvent named wg-help-click with the same payload in event.detail.
onHelpClick: ({ field }) => {
showHelpModal(field); // e.g. explain what a CVV is
}Invoked when the aggregate validity of the card/ACH form changes: ready: true when every required field for the active payment method is complete and valid, ready: false if the form regresses (for example, the payer edits a field back to an invalid state). Informational only; it does not start tokenization. The typical use is enabling or disabling your Pay button.
| Property | Type | Description |
|---|---|---|
ready | boolean | Whether the form is complete and valid |
Also dispatched as a window CustomEvent named wg-form-ready with the same payload in event.detail.
onFormReady: ({ ready }) => {
document.getElementById('pay-btn').disabled = !ready;
}Invoked when a tokenize() attempt is blocked by field validation. The payload lists every errored field with its localized message, which is useful for building an accessible error-summary banner on your page. Pair each entry with focusField(field) to jump the payer to the field. On a blocked tokenize the SDK also automatically scrolls the page to the first errored field; no wiring is needed for that.
| Property | Type | Description |
|---|---|---|
errors | array | [{ field, message }]: errored field ids with localized messages |
Also dispatched as a window CustomEvent named wg-field-errors with the same payload in event.detail.
onFieldErrors: ({ errors }) => {
renderErrorSummary(errors.map(e => ({
text: e.message,
onClick: () => wg.focusField(e.field)
})));
}Styling is passed via options.styling in the mount() call. All styling options affect the payment form only — the surrounding page layout, fonts, and design remain fully under merchant control.
These options control the overall visual structure of the payment form.
| Option | Type | Values | Default |
|---|---|---|---|
theme | string | lightdark | light |
labelStyle | string | stackedfloatinghidden | stacked |
fieldStyle | string | outlinedfilledunderlined | outlined |
fieldLayout | string | stackedinline-splitinline | stacked |
When fieldLayout is inline, labelStyle is automatically forced to hidden.
Color values are passed via styling.colors. These control the color scheme of input fields, labels, and error states inside the payment form.
| Key | Type | Description |
|---|---|---|
label | string | Label text color |
text | string | Input text color |
border | string | Default border color |
focusBorder | string | Border color on focus |
error | string | Error border and text color |
helpText | string | Placeholder and help text color |
These options control font choices and sizing for various elements inside the payment form.
| Option | Type | Description |
|---|---|---|
fontFamily | string | Font family (e.g. 'Inter') |
fontSize | number | Input text font size in pixels (10–24) |
labelFontSize | number | Label font size in pixels (10–24) |
labelFontWeight | number | Label font weight (100–900) |
helpTextFontSize | number | Help text font size in pixels (10–24) |
helpTextFontWeight | number | Help text font weight (100–900) |
These options control the physical sizing and spacing of input fields and the payment form.
| Option | Type | Description |
|---|---|---|
spacing | number | Spacing from top and between elements (0–32px) |
labelSpacing | number | Gap between a field label and its input in pixels. Defaults to half of spacing, clamped to 4–8px, so labels stay visually attached to their inputs |
borderRadius | number | Input corner radius (0–32px) |
borderWidth | number | Border width in pixels (0–32px) |
inputHeight | number | Input height in pixels (min 20) |
iframeWidth | string | Total width of the payment form (e.g. '100%') |
wg.mount('#payment-container', {
paymentMethod: 'card',
styling: {
theme: 'light',
labelStyle: 'floating',
fieldStyle: 'outlined',
fieldLayout: 'stacked',
fontFamily: 'Inter',
fontSize: 15,
labelFontSize: 14,
labelFontWeight: 500,
helpTextFontSize: 14,
helpTextFontWeight: 400,
spacing: 12,
borderRadius: 4,
borderWidth: 1,
inputHeight: 36,
iframeWidth: '100%',
colors: {
label: '#5A5E66',
border: '#C4C8CC',
error: '#D32F2F',
text: '#000000',
focusBorder: '#3B82F6',
helpText: '#9CA3AF'
}
}
});Display options are passed via options.displayOptions in the mount() call. They control the visibility of labels, icons, placeholders, and other UI elements inside the payment form.
| Option | Type | Default | Description |
|---|---|---|---|
showLabels | boolean | true | Show field labels |
showIcons | boolean | true | Show card brand icons |
showErrors | boolean | true | Show validation error messages |
showPlaceholders | boolean | true | Show placeholder text |
showSecurityCodeIndicator | boolean | true | Show CVC/CVV icon |
wg.mount('#payment-container', {
paymentMethod: 'card',
displayOptions: {
showLabels: true,
showIcons: true,
showErrors: true,
showPlaceholders: true,
showSecurityCodeIndicator: true
}
});All errors surfaced through onError or onCancel use a standardized payload format. The same codes are used consistently across all payment methods — the description field identifies the specific cause.
{
"responseCode": "E400",
"responseMessage": "SDK_ERROR",
"description": "Human-readable detail about what went wrong"
}| responseCode | responseMessage | Delivered Via | When |
|---|---|---|---|
E400 | SDK_ERROR | onError | Config/setup issues — invalid or missing mount options, container not found, the payment method is not available on the device/browser, or a payment provider script failed to load |
E400 | VALIDATION_ERROR | onError | Missing required fields (sessionToken, accountHolderName, billingAddress) |
E400 | TOKENIZATION_FAILED | onError | Tokenization fails — the payment could not be converted into a token (including provider and merchant validation failures) |
E402 | PAYMENT_CANCELLED | onCancel | User cancels the payment before authorizing |
E500 | UNEXPECTED_ERROR | onError | Any unhandled exception, network failure, or tokenization timeout (30s) |
- Card/ACH errors are returned both as promise rejections from
tokenize()and via theonErrorcallback. - PayPal/Venmo and Apple Pay errors are delivered only via the
onErrorcallback (there is no promise to reject). onCancelis only fired for PayPal, Venmo, and Apple Pay. Card and ACH have no cancel concept.- The
descriptionfield always contains a human-readable message suitable for logging or display.
This table shows which fields are required in the tokenize() call for card and ACH. A session token must be set via updateSessionToken() before calling tokenize().
| Field | Card | ACH |
|---|---|---|
amount | Required | Required |
accountHolderName | Preferred | Preferred |
billingAddress | Preferred | Preferred |
accountType | — | Required |
Apple Pay, PayPal, and Venmo do not use tokenize(). Their transaction details are passed directly in the mount() options (applePay or paypal), and the SDK handles the flow on button click. For PayPal, Venmo, and Apple Pay, call updateSessionToken() before the user clicks the payment button.