PlatformCommerce
Quick Start
Get started with Hanzo Commerce in minutes
Quick Start
Install SDK
import { HanzoCommerce } from '@hanzo/commerce'
const commerce = new HanzoCommerce({
apiKey: process.env.HANZO_COMMERCE_KEY
})Create a Product
const product = await commerce.products.create({
name: 'AI API Credits',
description: 'Credits for AI inference',
price: 10.00,
currency: 'USD',
type: 'digital'
})Create a Checkout
const checkout = await commerce.checkouts.create({
items: [
{ productId: product.id, quantity: 10 }
],
successUrl: 'https://myapp.com/success',
cancelUrl: 'https://myapp.com/cancel'
})
// Redirect to checkout
window.location.href = checkout.urlHandle Webhook
app.post('/webhooks/commerce', async (req, res) => {
const event = commerce.webhooks.verify(req.body, req.headers)
switch (event.type) {
case 'checkout.completed':
await fulfillOrder(event.data)
break
case 'payment.succeeded':
await recordPayment(event.data)
break
}
res.status(200).send('ok')
})Next Steps
- Products -- Create and manage product catalog
- Subscriptions -- Set up recurring billing
- Payments -- Payment processing options
- Webhooks -- Real-time event notifications
How is this guide?
Last updated on