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
- Create a Payment Request for immediate processing
- Create an Element to collect payment info
- Mount the element to your page
- Handle the payment method callback
- Confirm the payment
Tokenization Flow
- Create a Tokenization Request to save payment methods
- Create an Element to collect payment info
- Mount the element to your page
- Handle the payment method callback
- 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
| Parameter | Type | Required | Description |
|---|---|---|---|
amount | number | ✅ | Amount in smallest currency unit (e.g., cents) |
currency | string | ✅ | ISO 4217 currency code |
description | string | ❌ | Payment description |
customer | object | ❌ | Customer information |
allowedMethods | array | ❌ | Allowed payment methods (defaults to ['card']) |
returnUrl | string | ❌ | Success redirect URL |
cancelUrl | string | ❌ | Cancel redirect URL |
webhook | string | ❌ | Webhook URL for payment events |
metadata | object | ❌ | Custom key-value data |
Supported Payment Methods
card- Credit/debit cardsapple_pay- Apple Pay (Safari only)google_pay- Google Paypaypal- PayPalbank_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
| Parameter | Type | Description |
|---|---|---|
theme | string | Visual theme: 'default', 'dark', 'minimal' |
locale | string | Language code (e.g., 'en', 'fr', 'es') |
appearance | object | Custom 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
| Parameter | Type | Required | Description |
|---|---|---|---|
customer | object | ✅ | Customer information with ID |
allowedMethods | array | ❌ | Allowed payment methods |
usage | string | ❌ | Token usage: 'single_use' or 'reusable' |
metadata | object | ❌ | Custom 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
| Event | Description | Payload |
|---|---|---|
ready | Element is mounted and ready | - |
change | Form validation state changed | { complete, empty, invalid } |
payment_method | Payment method successfully created | { id, type, ... } |
error | An error occurred | { type, message, ... } |
focus | A field received focus | { elementType } |
blur | A 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 Type | Number | CVC | Expiry |
|---|---|---|---|
| Visa | 4242424242424242 | Any 3 digits | Any future date |
| Visa (debit) | 4000056655665556 | Any 3 digits | Any future date |
| Mastercard | 5555555555554444 | Any 3 digits | Any future date |
| American Express | 378282246310005 | Any 4 digits | Any future date |
| Declined | 4000000000000002 | Any 3 digits | Any future date |
| 3D Secure | 4000000000003220 | Any 3 digits | Any 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 endpointAPI Reference
Acclaim Constructor
new Acclaim(options)Options:
apiKey(string, required): Your Acclaim publishable API keyenvironment(string):'production'or'sandbox'(default:'production')cdnUrl(string): Custom CDN URL (optional)
Methods
createPaymentRequest(data)
createPaymentRequest(data)Creates a payment request for immediate processing.
Returns: Promise<PaymentRequest>
createTokenizationRequest(data)
createTokenizationRequest(data)Creates a tokenization request for saving payment methods.
Returns: Promise<TokenizationRequest>
createElement(requestId, options)
createElement(requestId, options)Creates a payment element for the given request.
Returns: Promise<Element>
handle3DSecure(paymentIntentId, options)
handle3DSecure(paymentIntentId, options)Manually handle 3D Secure authentication.
Returns: Promise<AuthenticationResult>
PaymentRequest Methods
confirm(paymentMethodId)
confirm(paymentMethodId)Confirm and process the payment.
Returns: Promise<PaymentResult>
TokenizationRequest Methods
confirm()
confirm()Confirm tokenization and save the payment method.
Returns: Promise<TokenizationResult>
Element Methods
mount(container)
mount(container)Mount the element to a DOM container.
Parameters:
container(string|Element): CSS selector or DOM element
Returns: Promise<void>
unmount()
unmount()Remove the element from the DOM.
Returns: void
on(event, callback)
on(event, callback)Listen for element events.
Parameters:
event(string): Event namecallback(function): Event handler
update(options)
update(options)Update element appearance or configuration.
Parameters:
options(object): New options to apply
Updated 5 days ago
