Log In

Embeddable Components

Acclaim.js is a comprehensive payment processing SDK that handles credit cards, digital wallets, and alternative payment methods with built-in PCI compliance and 3D Secure support.

Quick Start

Installation

<!-- CDN (Recommended) -->
<script src="https://cdn.withacclaim.com/v1/acclaim.js"></script>

Alternative Installation Methods

<!-- NPM -->
npm install @acclaim/sdk

// ES6 Import
import Acclaim from '@acclaim/sdk';

// CommonJS
const Acclaim = require('@acclaim/sdk');

Basic Setup

const acclaim = new Acclaim({
    apiKey: 'pk_live_your_api_key_here',
    environment: 'production' // or 'sandbox'
});

Core Concepts

Requests vs Elements

Acclaim uses two main concepts:

  • Requests: Server-side objects that define what you want to do (payment or tokenization)
  • Elements: Client-side UI components that collect payment information

Payment Flow

  1. Create a Payment Request for immediate processing
  2. Create an Element to collect payment info
  3. Mount the element to your page
  4. Handle the payment method callback
  5. Confirm the payment

Tokenization Flow

  1. Create a Tokenization Request to save payment methods
  2. Create an Element to collect payment info
  3. Mount the element to your page
  4. Handle the payment method callback
  5. Confirm tokenization

Payment Processing

Creating a Payment Request

const paymentRequest = await acclaim.createPaymentRequest({
    amount: 29999,           // Amount in cents ($299.99)
    currency: 'USD',        // ISO currency code
    description: 'POL-1234 Premium',
    customer: {
        email: '[email protected]',
        name: 'John Doe'
    },
    allowedMethods: ['card', 'apple_pay', 'google_pay', 'paypal'],
    returnUrl: 'https://yoursite.com/success',
    cancelUrl: 'https://yoursite.com/cancel',
    metadata: {
        policy_id: 'pol_123',
        source: 'web'
    }
});

Payment Request Options

ParameterTypeRequiredDescription
amountnumberAmount in smallest currency unit (e.g., cents)
currencystringISO 4217 currency code
descriptionstringPayment description
customerobjectCustomer information
allowedMethodsarrayAllowed payment methods (defaults to ['card'])
returnUrlstringSuccess redirect URL
cancelUrlstringCancel redirect URL
webhookstringWebhook URL for payment events
metadataobjectCustom key-value data

Supported Payment Methods

  • card - Credit/debit cards
  • apple_pay - Apple Pay (Safari only)
  • google_pay - Google Pay
  • paypal - PayPal
  • bank_transfer - Bank transfers

Creating and Mounting Elements

// Create payment element
const element = await acclaim.createElement(paymentRequest.id, {
    theme: 'default',       // 'default', 'dark', 'minimal'
    locale: 'en',          // Language code
    appearance: {
        primaryColor: '#007bff',
        borderRadius: '8px',
        fontFamily: 'Inter, sans-serif'
    }
});

// Mount to DOM
await element.mount('#payment-container');

Element Options

ParameterTypeDescription
themestringVisual theme: 'default', 'dark', 'minimal'
localestringLanguage code (e.g., 'en', 'fr', 'es')
appearanceobjectCustom styling options

Appearance Customization

const element = await acclaim.createElement(requestId, {
    appearance: {
        primaryColor: '#6366f1',        // Brand color
        backgroundColor: '#ffffff',     // Background color
        textColor: '#1f2937',          // Text color
        borderColor: '#d1d5db',        // Border color
        borderRadius: '8px',           // Border radius
        fontFamily: 'Inter, sans-serif', // Font family
        fontSize: '16px',              // Base font size
        padding: '12px',               // Input padding
        focusColor: '#3b82f6'          // Focus highlight color
    }
});

Handling Payment Completion

element.on('payment_method', async (paymentMethod) => {
    try {
        // Confirm the payment
        const result = await paymentRequest.confirm(paymentMethod.id);
        
        if (result.status === 'succeeded') {
            // Payment successful
            window.location.href = '/success';
        } else if (result.status === 'requires_action') {
            // 3D Secure or additional authentication required
            // Acclaim handles this automatically
            console.log('Additional authentication in progress...');
        } else if (result.status === 'failed') {
            // Payment failed
            showError(result.error.message);
        }
    } catch (error) {
        showError(error.message);
    }
});

element.on('error', (error) => {
    showError(error.message);
});

Complete Payment Example

async function setupPayment() {
    // Initialize Acclaim
    const acclaim = new acclaim({
        apiKey: 'pk_test_your_api_key',
        environment: 'sandbox'
    });
    
    // Create payment request
    const paymentRequest = await acclaim.createPaymentRequest({
        amount: 29999, // $299.99
        currency: 'USD',
        description: 'POL-1234 Premium',
        customer: {
            email: '[email protected]'
        },
        allowedMethods: ['card', 'apple_pay', 'google_pay']
    });
    
    // Create and mount element
    const element = await acclaim.createElement(paymentRequest.id);
    await element.mount('#payment-form');
    
    // Handle payment completion
    element.on('payment_method', async (method) => {
        const submitButton = document.querySelector('#submit-button');
        submitButton.disabled = true;
        submitButton.textContent = 'Processing...';
        
        try {
            const result = await paymentRequest.confirm(method.id);
            
            if (result.status === 'succeeded') {
                window.location.href = '/success';
            } else {
                throw new Error(result.error?.message || 'Payment failed');
            }
        } catch (error) {
            showError(error.message);
            submitButton.disabled = false;
            submitButton.textContent = 'Pay Now';
        }
    });
    
    element.on('error', (error) => {
        showError(error.message);
    });
}

function showError(message) {
    const errorElement = document.querySelector('#error-message');
    errorElement.textContent = message;
    errorElement.style.display = 'block';
}

Tokenization (Saving Payment Methods)

Creating a Tokenization Request

const tokenRequest = await acclaim.createTokenizationRequest({
    customer: {
        id: 'cust_123',
        email: '[email protected]'
    },
    allowedMethods: ['card'],
    usage: 'reusable',      // 'single_use' or 'reusable'
    metadata: {
        source: 'profile_page'
    }
});

Tokenization Request Options

ParameterTypeRequiredDescription
customerobjectCustomer information with ID
allowedMethodsarrayAllowed payment methods
usagestringToken usage: 'single_use' or 'reusable'
metadataobjectCustom key-value data

Handling Tokenization

const element = await acclaim.createElement(tokenRequest.id);
await element.mount('#save-card-form');

element.on('payment_method', async (method) => {
    try {
        const result = await tokenRequest.confirm();
        
        if (result.status === 'succeeded') {
            console.log('Payment method saved:', result.payment_method);
            // Show success message
            showSuccess('Payment method saved successfully');
        }
    } catch (error) {
        showError(error.message);
    }
});

3D Secure Authentication

Acclaim automatically handles 3D Secure authentication when required. The process is transparent to your integration.

Manual 3DS Handling

// If you need manual control over 3DS
try {
    const result = await paymentRequest.confirm(paymentMethodId);
    
    if (result.requires_action) {
        // Handle 3DS authentication
        const authResult = await acclaim.handle3DSecure(result.payment_intent);
        
        if (authResult.status === 'succeeded') {
            // Authentication successful
            console.log('Payment completed after 3DS');
        }
    }
} catch (error) {
    console.error('3DS authentication failed:', error);
}

Digital Wallets

Apple Pay

Apple Pay is automatically detected on supported devices and browsers. No additional setup required.

// Apple Pay is included in allowedMethods
const paymentRequest = await acclaim.createPaymentRequest({
    amount: 2999,
    currency: 'USD',
    allowedMethods: ['card', 'apple_pay'] // Apple Pay included
});

Requirements:

  • Safari browser
  • macOS with Touch ID or iPhone/iPad with Face ID/Touch ID
  • Valid Apple Pay merchant certificate (handled by Acclaim)

Google Pay

Google Pay is automatically detected when the Google Pay API is available.

// Include Google Pay script before Acclaim
<script async src="https://pay.google.com/gp/p/js/pay.js"></script>
<script src="https://cdn.withacclaim.com/v1/acclaim.js"></script>

// Google Pay included in payment request
const paymentRequest = await acclaim.createPaymentRequest({
    amount: 2999,
    currency: 'USD',
    allowedMethods: ['card', 'google_pay']
});

Requirements:

  • Google Pay API loaded
  • Supported browser (Chrome, Edge, etc.)
  • Valid Google Pay merchant configuration

PayPal

const paymentRequest = await acclaim.createPaymentRequest({
    amount: 2999,
    currency: 'USD',
    allowedMethods: ['card', 'paypal'],
    returnUrl: 'https://yoursite.com/success', // Required for PayPal
    cancelUrl: 'https://yoursite.com/cancel'   // Required for PayPal
});

Event Handling

Element Events

element.on('ready', () => {
    console.log('Element is ready');
});

element.on('change', (state) => {
    console.log('Element state changed:', state);
    // Update submit button based on validation
    document.querySelector('#submit-btn').disabled = !state.complete;
});

element.on('payment_method', (method) => {
    console.log('Payment method created:', method);
});

element.on('error', (error) => {
    console.error('Element error:', error);
});

element.on('focus', (field) => {
    console.log('Field focused:', field.elementType);
});

element.on('blur', (field) => {
    console.log('Field blurred:', field.elementType);
});

Available Events

EventDescriptionPayload
readyElement is mounted and ready-
changeForm validation state changed{ complete, empty, invalid }
payment_methodPayment method successfully created{ id, type, ... }
errorAn error occurred{ type, message, ... }
focusA field received focus{ elementType }
blurA field lost focus{ elementType }

Error Handling

Common Error Types

element.on('error', (error) => {
    switch (error.type) {
        case 'validation_error':
            // Invalid card number, expired card, etc.
            showFieldError(error.field, error.message);
            break;
            
        case 'card_declined':
            // Card was declined by issuer
            showError('Your card was declined. Please try a different payment method.');
            break;
            
        case 'network_error':
            // Network connectivity issues
            showError('Network error. Please check your connection and try again.');
            break;
            
        case 'api_error':
            // Server-side error
            showError('Something went wrong. Please try again.');
            break;
            
        default:
            showError(error.message);
    }
});

Error Object Structure

{
    type: 'validation_error',
    message: 'Your card number is invalid.',
    field: 'cardNumber',
    code: 'invalid_number'
}

Styling and Themes

Built-in Themes

// Default theme
const element = await acclaim.createElement(requestId, {
    theme: 'default'
});

// Dark theme
const element = await acclaim.createElement(requestId, {
    theme: 'dark'
});

// Minimal theme
const element = await acclaim.createElement(requestId, {
    theme: 'minimal'
});

Custom Styling

const element = await acclaim.createElement(requestId, {
    appearance: {
        // Colors
        primaryColor: '#6366f1',
        backgroundColor: '#ffffff',
        textColor: '#1f2937',
        placeholderColor: '#9ca3af',
        borderColor: '#d1d5db',
        focusColor: '#3b82f6',
        errorColor: '#ef4444',
        
        // Typography
        fontFamily: 'Inter, -apple-system, sans-serif',
        fontSize: '16px',
        fontWeight: '400',
        
        // Layout
        borderRadius: '8px',
        borderWidth: '1px',
        padding: '12px 16px',
        
        // States
        ':hover': {
            borderColor: '#9ca3af'
        },
        ':focus': {
            borderColor: '#3b82f6',
            boxShadow: '0 0 0 3px rgba(59, 130, 246, 0.1)'
        },
        '.invalid': {
            borderColor: '#ef4444'
        }
    }
});

Testing

Test Cards

Use these test card numbers in sandbox mode:

Card TypeNumberCVCExpiry
Visa4242424242424242Any 3 digitsAny future date
Visa (debit)4000056655665556Any 3 digitsAny future date
Mastercard5555555555554444Any 3 digitsAny future date
American Express378282246310005Any 4 digitsAny future date
Declined4000000000000002Any 3 digitsAny future date
3D Secure4000000000003220Any 3 digitsAny future date

Test Environment

const acclaim = new Acclaim({
    apiKey: 'pk_test_your_test_key',
    environment: 'sandbox'
});

Webhook Testing

Use tools like ngrok to test webhooks locally:

# Install ngrok
npm install -g ngrok

# Expose local server
ngrok http 3000

# Use the HTTPS URL for webhook endpoint

API Reference

Acclaim Constructor

new Acclaim(options)

Options:

  • apiKey (string, required): Your Acclaim publishable API key
  • environment (string): 'production' or 'sandbox' (default: 'production')
  • cdnUrl (string): Custom CDN URL (optional)

Methods

createPaymentRequest(data)

Creates a payment request for immediate processing.

Returns: Promise<PaymentRequest>

createTokenizationRequest(data)

Creates a tokenization request for saving payment methods.

Returns: Promise<TokenizationRequest>

createElement(requestId, options)

Creates a payment element for the given request.

Returns: Promise<Element>

handle3DSecure(paymentIntentId, options)

Manually handle 3D Secure authentication.

Returns: Promise<AuthenticationResult>

PaymentRequest Methods

confirm(paymentMethodId)

Confirm and process the payment.

Returns: Promise<PaymentResult>

TokenizationRequest Methods

confirm()

Confirm tokenization and save the payment method.

Returns: Promise<TokenizationResult>

Element Methods

mount(container)

Mount the element to a DOM container.

Parameters:

  • container (string|Element): CSS selector or DOM element

Returns: Promise<void>

unmount()

Remove the element from the DOM.

Returns: void

on(event, callback)

Listen for element events.

Parameters:

  • event (string): Event name
  • callback (function): Event handler

update(options)

Update element appearance or configuration.

Parameters:

  • options (object): New options to apply