DRP JavaScript SDK
The official JavaScript SDK for integrating the Digital Receipt Protocol into Node.js applications, web apps, and React Native mobile apps.Installation
- Node.js 16 or higher
- TypeScript 4.5+ (optional, but recommended)
Quick Start
Merchant Integration (Server-Side)
User Integration (Client-Side)
Configuration
Client Options
Environment Variables
API Reference
Client Methods
publicKeys.get(cardToken, options?)
Retrieve customer’s public key for encryption.
Promise<PublicKeyData>
receipts.send(params)
Encrypt and send a receipt to the card issuer.
Promise<ReceiptResponse>
receipts.list(filters)
Retrieve user’s receipts (User Client only).
Promise<ReceiptsListResponse>
merchants.register(data)
Register merchant account (one-time setup).
Promise<RegistrationResponse>
Crypto Utilities
crypto.encrypt(data, publicKey)
Encrypt data with RSA-2048-OAEP.
crypto.decrypt(encryptedData, privateKey)
Decrypt data with private key.
crypto.sign(data, privateKey)
Sign data with RSA-SHA256.
crypto.verify(data, signature, publicKey)
Verify signature.
Error Handling
Error Types
DRPError- Base error classAuthenticationError- Invalid API keyRateLimitError- Rate limit exceededValidationError- Invalid request parametersNetworkError- Network/timeout issuesEncryptionError- Encryption/decryption failedSignatureError- Signature verification failed
TypeScript Support
Full TypeScript definitions included:Testing
Mock Client
Examples
Express.js Integration
React Native Integration
Webhooks
Handle webhook events from issuers:Best Practices
Store API Keys Securely
Store API Keys Securely
Never commit API keys to version control. Use environment variables or secret management systems (AWS Secrets Manager, HashiCorp Vault, etc.).
Handle Errors Gracefully
Handle Errors Gracefully
Always wrap DRP calls in try/catch. Handle
customer_not_enrolled as a normal case - not all customers will have DRP enabled.Implement Retry Logic
Implement Retry Logic
The SDK has built-in retries, but implement additional retry logic at the application level for critical workflows.
Cache Public Keys
Cache Public Keys
Public keys are valid for months. Cache them by card token to reduce API calls and improve performance.
Use Async/Await
Use Async/Await
All SDK methods return Promises. Use async/await for cleaner code and better error handling.
Enable Logging in Development
Enable Logging in Development
Set
logLevel: 'debug' during development to see detailed request/response logs. Use ‘error’ in production.Resources
GitHub Repository
Source code, examples, and issue tracking
npm Package
Package details and version history
API Reference
Complete API documentation
Support
Get help with integration
Changelog
v1.0.0 (Latest)
- Initial stable release
- Full support for DRP API v1
- TypeScript definitions included
- React Native compatibility
- Webhook verification helpers
v0.9.0 (Beta)
- Beta release for testing
- Core merchant and user APIs