A React component for accepting cryptocurrency payments with cross-chain support. Simple, secure, and powerful.
- π Zero Configuration: Auto-detects development vs production environments
- π Secure: Payment data loaded securely from AppPay servers
- π Cross-Chain: Support for multiple blockchains and tokens
- β‘ Real-Time: Live quotes and transaction updates via WebSocket
- π¨ Customizable: Light/dark themes and custom CSS styling
- π± Responsive: Works on all devices
- π No API Keys: Everything works with payment IDs only
npm install apppay-react
Note: Thirdweb is bundled with this package - no need to install it separately!
- β Zero Configuration: Just import and use - no setup required
- β Embedded ThirdwebProvider: Wallet connectivity built-in
- β Complete Wallet Integration: Connect button and wallet management included
- β
Production Ready: Uses
api.apppay.ai
andws.apppay.ai
endpoints - β Secure: Payment ID-based authentication
- β Customizable: Full styling and theming support
- β TypeScript: Full type definitions included
import { PaymentModal } from 'apppay-react';
function App() {
const [isOpen, setIsOpen] = useState(false);
const paymentId = 'pay_1234567890'; // Get this from your backend
return (
<div>
<button onClick={() => setIsOpen(true)}>
Pay Now
</button>
<PaymentModal
paymentId={paymentId}
isOpen={isOpen}
onClose={() => setIsOpen(false)}
onPaymentComplete={(result) => {
console.log('Payment successful:', result);
setIsOpen(false);
}}
theme="dark"
style={{
borderRadius: '16px',
boxShadow: '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
}}
/>
</div>
);
}
- Click "Pay Now" β Modal opens
- Connect Wallet β Thirdweb connect button appears if no wallet connected
- Find Routes β System discovers available payment routes
- Select Route β Choose preferred payment method
- Execute Payment β Complete the transaction
The PaymentModal handles everything automatically - wallet connection, route discovery, and payment execution.
Prop | Type | Required | Description |
---|---|---|---|
paymentId |
string |
β | Unique payment identifier from AppPay |
isOpen |
boolean |
β | Controls modal visibility |
onClose |
() => void |
β | Called when user closes modal |
onPaymentComplete |
(result: PaymentResult) => void |
β | Called on successful payment |
theme |
'light' | 'dark' |
β | UI theme (default: 'light') |
style |
React.CSSProperties |
β | Custom styling |
interface PaymentResult {
paymentId: string;
transactionHash: string;
amount: string;
currency: string;
status: 'completed' | 'pending' | 'failed';
timestamp: number;
metadata?: Record<string, any>;
}
- Create Payment: Use AppPay API to create a payment and get a
paymentId
- Show Modal: Pass the
paymentId
to the PaymentModal component - Auto-Connect: Modal automatically connects to correct API/WebSocket endpoints
- Load Data: Payment details are securely loaded from AppPay servers
- User Pays: Modal guides user through wallet connection and payment
- Success:
onPaymentComplete
callback is triggered with transaction details
The package automatically detects your environment:
Environment | API Endpoint | WebSocket Endpoint |
---|---|---|
Development (localhost ) |
http://localhost:3082 |
ws://localhost:3084 |
Production (all others) | https://api.apppay.ai |
wss://ws.apppay.ai |
No configuration needed! π
First, create a payment using the AppPay API:
// Example: Create payment via fetch
const response = await fetch('https://api.apppay.ai/api/mcp/create-payment', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
amount: '99.99',
currency: 'USD',
title: 'Premium Subscription',
description: 'Monthly access to premium features'
})
});
const { paymentId } = await response.json();
ThirdwebProvider is automatically included in the PaymentModal component. You don't need to set up anything additional - just use the PaymentModal component directly in your app!
<PaymentModal
paymentId={paymentId}
isOpen={isOpen}
theme="dark" // or "light"
/>
The style
prop accepts any valid React CSSProperties
object and is applied to the modal container:
<PaymentModal
paymentId={paymentId}
isOpen={isOpen}
style={{
// Modal container styling
borderRadius: '16px',
boxShadow: '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
maxWidth: '500px',
minHeight: '600px',
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
border: '2px solid #e2e8f0'
}}
/>
Rounded Corners & Shadows:
style={{
borderRadius: '24px',
boxShadow: '0 32px 64px -12px rgba(0, 0, 0, 0.35)',
border: '1px solid rgba(255, 255, 255, 0.1)'
}}
Custom Colors:
style={{
background: 'linear-gradient(135deg, #1e3a8a 0%, #3730a3 100%)',
color: 'white'
}}
Size Customization:
style={{
width: '90vw',
maxWidth: '600px',
minHeight: '700px'
}}
- CSS Priority: The
style
prop has higher priority than Tailwind classes - Theme Override: Custom
background
/color
will override light/dark theme - Responsive: Use
vw
,vh
,%
for mobile compatibility - Z-Index: Modal has
z-50
(z-index: 50) - usestyle.zIndex
to override - Animation: Framer Motion animations work with all custom styles
- Inheritance: Child elements inherit text color from modal container
- Tailwind Conflicts: Some Tailwind classes may be overridden by style prop
// Override default rounded corners
style={{ borderRadius: '8px' }} // Overrides rounded-xl
// Custom background (overrides theme)
style={{ background: '#f0f0f0' }} // Overrides bg-white/bg-slate-900
// Custom sizing
style={{ maxWidth: '400px', height: '500px' }} // Overrides max-w-md
// Custom shadows
style={{
boxShadow: '0 10px 40px rgba(0,0,0,0.3)' // Overrides shadow-2xl
}}
import { useRouteDiscovery, usePaymentExecution, AppPayAPI } from 'apppay-react';
function CustomPaymentFlow() {
const api = new AppPayAPI();
const { routes, discoverRoutes } = useRouteDiscovery(api);
const { executePayment, isProcessing } = usePaymentExecution(paymentData);
// Custom implementation...
}
The modal handles common errors automatically:
- No Wallet: Prompts user to install/connect wallet
- Network Issues: Shows retry options
- Insufficient Funds: Displays helpful error messages
- Transaction Failures: Provides clear feedback
- β No API Keys: Everything works with payment IDs
- β Server-Side Validation: Payment data is validated on AppPay servers
- β Secure Communication: HTTPS and WSS connections
- β No Sensitive Data: Payment details stay on AppPay infrastructure
- Chrome 80+
- Firefox 75+
- Safari 13+
- Edge 80+
For faster iteration during development, you can test your changes locally before publishing:
cd npm/apppay/react
npm run build
# In the npm package directory
npm run link
# In your test consumer app directory
npm uninstall apppay-react # Remove npm version
npm link apppay-react # Link local version
# In your test consumer app directory
npm run dev
Edit files in npm/apppay/react/src/
and rebuild:
cd npm/apppay/react
npm run build # Changes will appear in test app immediately
# In test consumer app
npm unlink apppay-react
npm install apppay-react@latest # Install published version
# Bump version in package.json
npm version patch # or minor/major
# Build and publish
npm run build
npm publish
# Verify
npm view apppay-react version
This package is part of the AppPay ecosystem. For contributions or issues, please visit:
- Repository: https://github.com/apppayai/react
- Issues: https://github.com/apppayai/react/issues
- NPM: https://www.npmjs.com/package/apppay-react
MIT Β© AppPay Team