@waffo/payment-sdk
v1.0.5
Published
Waffo Payment SDK for secure card tokenization
Readme
Waffo Payment SDK
Secure card tokenization SDK with 3DS verification support.
📦 Installation
npm / pnpm
npm install @waffo/payment-sdk
# or
pnpm add @waffo/payment-sdkCDN (unpkg)
<!-- Latest version -->
<script src="https://unpkg.com/@waffo/payment-sdk"></script>
<!-- Specific version (recommended for production) -->
<script src="https://unpkg.com/@waffo/[email protected]"></script>🚀 Usage
npm / ES Module
import WaffoSDK from '@waffo/payment-sdk';
// Initialize SDK
const sdk = new WaffoSDK('your-client-api-key', {
env: 'prod', // 'prod' | 'testing' | 'sandbox'
locale: 'en' // Optional, default 'en'
});
// Submit tokenization request
const result = await sdk.tokenizationSubmit('token-session-id', {
tokenDataVerification: false, // Optional, validate card data, default false
tokenData: {
pan: '4111111111111111', // Card number
name: 'John Doe', // Cardholder name
expiry: '12/2025', // Expiry date MM/YYYY
cvv: '123' // CVV (optional)
},
billingAddress: { // Optional
countryCode: 'USA',
region: 'CA',
city: 'San Francisco',
postalCode: '94102',
address: '123 Main St'
}
});
// Handle result
if (result.success) {
console.log('Token Request ID:', result.data.tokenRequestId);
if (result.data.validateUrl) {
// 3DS verification required
window.location.href = result.data.validateUrl;
}
} else {
console.error('Error:', result.error.code, result.error.message);
}
// Destroy SDK (cleanup resources)
sdk.destroy();CDN / UMD
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/@waffo/payment-sdk"></script>
</head>
<body>
<script>
// WaffoSDK is automatically mounted to window
const sdk = new WaffoSDK('your-client-api-key', {
env: 'prod',
locale: 'en'
});
async function submitPayment() {
const result = await sdk.tokenizationSubmit('token-session-id', {
tokenData: {
pan: '4111111111111111',
name: 'John Doe',
expiry: '12/2025',
cvv: '123'
}
});
if (result.success) {
console.log('Success:', result.data.tokenRequestId);
} else {
console.error('Error:', result.error);
}
}
</script>
</body>
</html>📖 API Reference
new WaffoSDK(clientApiKey, options)
Create an SDK instance.
Parameters:
clientApiKey(string): Client API keyoptions(object):env(string): Environment, values:'prod'|'testing'|'sandbox'locale(string): Language code, e.g.'en','ja','zh'(optional, default'en')
Returns: WaffoSDK instance
sdk.tokenizationSubmit(tokenSessionId, request)
Submit card tokenization request.
Parameters:
tokenSessionId(string): Token session IDrequest(object):tokenDataVerification(boolean): Validate card data (optional, defaultfalse)tokenData(object): Card datapan(string): Card numbername(string): Cardholder nameexpiry(string): Expiry date, formatMM/YYYYcvv(string): CVV security code (optional)
billingAddress(object): Billing address (optional)countryCode(string): Country code (ISO 3166-1 alpha-3)region(string): State/Province/Regioncity(string): CitypostalCode(string): Postal codeaddress(string): Street address
Returns: Promise<TokenizationResult>
Success Response:
{
success: true,
data: {
tokenRequestId: string,
validateUrl?: string // If 3DS verification is required
}
}Error Response:
{
success: false,
data: null,
error: {
code: string,
message: string
}
}Error Codes:
| Error Code | Description |
|------------|-------------|
| 011001P001 | Wrong parameters. |
| 011001P002 | Idempotent param mismatch error. |
| 011001B004 | Invalid expiry date format. |
| 011001B005 | The card has been expired. |
| 011001B006 | The card's BIN has been denied. |
| 011001B024 | The token session has expired. |
| 011001B025 | Card information is invalid. - pan, name, expiry are required |
| 011001B027 | The token session is invalid. |
| 011001B031 | The merchant contract not matched. |
| 011001S001 | System process failed. |
sdk.destroy()
Destroy SDK instance and cleanup resources.
Parameters: None
Returns: void
📄 License
MIT © Waffo
