Web SDK
Install
Option 1: NPM
npm install @yuno-payments/sdk-webimport { Yuno } from '@yuno-payments/sdk-web';Option 2: CDN
<script src="https://sdk-web.y.uno/v1.5/main.js"></script>Option 3: Dynamic Load
const script = document.createElement('script');
script.src = 'https://sdk-web.y.uno/v1.5/main.js';
document.head.appendChild(script);
TypeScript SupportInstall types:
npm install @yuno-payments/sdk-web-types
Basic Payment Flow
1. Initialize SDK
const yuno = await Yuno.initialize('your-public-api-key');2. Create Checkout Session (Backend)
// Your backend endpoint
const session = await fetch('/api/checkout/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
customer_id: 'cus_123',
amount: { currency: 'USD', value: 2500 },
country: 'US'
})
}).then(r => r.json());3. Configure Checkout
yuno.startCheckout({
checkoutSession: session.checkout_session,
elementSelector: '#payment-container',
countryCode: 'US',
language: 'en-US',
async yunoCreatePayment(oneTimeToken) {
const result = await fetch('/api/payment/create', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
one_time_token: oneTimeToken,
checkout_session: session.checkout_session
})
}).then(r => r.json());
yuno.continuePayment({ showPaymentStatus: true });
},
yunoPaymentResult: (data) => {
console.log('Payment completed:', data.status);
}
});4. Mount Payment Form
yuno.mountCheckout();5. Start Payment Flow
Add a payment button and trigger the payment flow:
const payButton = document.querySelector('#pay-button');
payButton.addEventListener('click', () => {
yuno.startPayment();
});6. Add HTML
<div id="payment-container"></div>
<button id="pay-button">Pay Now</button>Complete Working Example
<!DOCTYPE html>
<html>
<head>
<title>Yuno Payment</title>
<script src="https://sdk-web.y.uno/v1.5/main.js"></script>
</head>
<body>
<div id="payment-container"></div>
<button id="pay-button">Pay Now</button>
<script>
async function initPayment() {
// Initialize
const yuno = await Yuno.initialize('pk_test_123');
// Create session
const session = await fetch('/api/checkout/session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
customer_id: 'cus_123',
amount: { currency: 'USD', value: 2500 },
country: 'US'
})
}).then(r => r.json());
// Configure checkout
yuno.startCheckout({
checkoutSession: session.checkout_session,
elementSelector: '#payment-container',
countryCode: 'US',
async yunoCreatePayment(token) {
await fetch('/api/payment/create', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
one_time_token: token,
checkout_session: session.checkout_session
})
});
yuno.continuePayment();
},
yunoPaymentResult: (data) => {
if (data.status === 'SUCCEEDED') {
window.location.href = '/success';
}
}
});
// Mount form
yuno.mountCheckout();
// Start payment on button click
document.querySelector('#pay-button').addEventListener('click', () => {
yuno.startPayment();
});
}
initPayment();
</script>
</body>
</html>Handling Payment Results
yuno.startCheckout({
// ... other config
yunoPaymentResult: (data) => {
switch(data.status) {
case 'SUCCEEDED':
window.location.href = '/success';
break;
case 'FAILED':
alert('Payment failed: ' + data.error?.message);
break;
case 'PENDING':
console.log('Payment is being processed');
break;
case 'REJECTED':
alert('Payment was rejected');
break;
}
},
yunoError: (error) => {
console.error('Error:', error);
}
});3DS Authentication
3DS is handled automatically by the SDK. For asynchronous payment methods:
async yunoCreatePayment(token) {
await createPaymentOnBackend(token);
// Handle redirect if needed
const result = await yuno.continuePayment();
if (result?.action === 'REDIRECT_URL') {
window.location.href = result.redirect.init_url;
}
}Configuration Options
Essential Parameters
| Parameter | Type | Description |
|---|---|---|
checkoutSession | string | Session ID from backend |
elementSelector | string | CSS selector for container |
countryCode | string | ISO country code (e.g., 'US') |
language | string | Language code (e.g., 'en-US') |
yunoCreatePayment | function | Payment creation callback |
Card Configuration
yuno.startCheckout({
// ... other config
card: {
type: 'extends', // or 'only'
cardSaveEnable: true, // Show save checkbox
isCreditCardProcessingOnly: false, // Allow debit
onChange: ({ error, data }) => {
if (error) {
console.log('Card validation error:', error);
}
}
}
});Loader & Status
yuno.startCheckout({
// ... other config
showLoading: true, // Show Yuno's loader
showPaymentStatus: true, // Show payment result page
onLoading: (isLoading) => {
console.log('Loading state:', isLoading);
}
});Next Steps
Ready to explore more advanced features? Check out the Advanced Features guide for:
- Alternative Mounting Options -
mountCheckoutLite()andmountSeamlessCheckout()for custom payment method selection - Enrollment (Save Cards) - Save payment methods for future use
- Vaulted Token Payments - One-click payments with saved cards
- Custom UI (Headless Integration) - Build completely custom payment forms
- Secure Fields - Custom card forms with PCI compliance
- Styling & Customization - Match the SDK to your brand
- Advanced Configuration - Dynamic views, render mode, and more
See also:
- Code Examples - Copy-paste examples for common scenarios
Updated about 18 hours ago