Back to BlogDeveloper Portal
API Tutorial
Building a Custom Checkout with NoPOS API
Michael Rodriguez••15 min read
Learn how to build a custom checkout experience that perfectly matches your brand and business requirements using the NoPOS API.
Prerequisites
Before starting, ensure you have:
- NoPOS API credentials
- Node.js 18+ installed
- Basic knowledge of REST APIs
- A payment gateway account (Stripe, Square, etc.)
Step 1: Initialize the Transaction
First, create a new transaction with the items being purchased:
const response = await fetch('https://api.nopos.dev/v1/transactions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
items: [
{
product_id: 'prod_123',
quantity: 2,
price: 29.99
}
],
customer_id: 'cust_456'
})const transaction = await response.json();
`
Step 2: Calculate Tax and Totals
The API automatically calculates taxes based on your location and settings:
const totals = transaction.totals;
console.log('Subtotal:', totals.subtotal);
console.log('Tax:', totals.tax);
console.log('Total:', totals.total);Step 3: Process Payment
Integrate with your payment provider:
const paymentResponse = await fetch(
`https://api.nopos.dev/v1/transactions/${transaction.id}/payment`,
{
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
payment_method: 'stripe',
payment_token: stripeToken,
amount: totals.total
})
}
);Step 4: Handle Payment Confirmation
Listen for payment confirmation and update your UI:
if (paymentResponse.ok) {
const result = await paymentResponse.json();
// Update inventory automatically
// Send receipt to customer
// Show confirmation page
console.log('Order confirmed:', result.order_id);
}Advanced Features
Split Payments
Support multiple payment methods in a single transaction:
const splitPayment = {
payments: [
{ method: 'card', amount: 50.00 },
{ method: 'gift_card', amount: 25.00 }
]
};Loyalty Points
Apply loyalty points during checkout:
const withLoyalty = {
customer_id: 'cust_456',
apply_loyalty_points: true,
loyalty_points_to_redeem: 500
};Error Handling
Always implement robust error handling:
try {
const response = await processTransaction();
if (!response.ok) {
throw new Error(`Payment failed: ${response.statusText}`);
}
} catch (error) {
console.error('Transaction error:', error);
// Show user-friendly error message
// Log for debugging
}Next Steps
- Explore [payment webhooks](https://developer.nopos.dev/webhooks) for real-time updates
- Implement [refunds and returns](https://developer.nopos.dev/refunds)
- Add [subscription billing](https://developer.nopos.dev/subscriptions) for recurring payments
Check out the full API documentation for more details.
Ready to dive deeper?
Explore our comprehensive API documentation and code examples.