E-commerce Integration
Integrate Looping Binary's coin system into your e-commerce platform for seamless product purchases and marketplace transactions.
What You Get
- Accept LB Coins as payment method
- Instant payment verification
- Automated order fulfillment
- Seller payouts from General Treasury
- Refund management
Step 1: Display Product with LB Coin Price
Show product prices in LB Coins and check user balance:
JavaScript
// Fetch user's balance
const balanceResponse = await fetch('https://api.loopingbinary.com/api/wallets/me', {
headers: {
'Authorization': 'Bearer ' + token
}
});
const { balance } = await balanceResponse.json();
// Display product with price
const product = {
name: 'Wireless Headphones',
price: 75, // LB Coins
image: '/products/headphones.jpg'
};
// Check if user can afford
const canPurchase = balance >= product.price;
console.log(`Balance: $${balance} LB Coins`);
console.log(`Product: $${product.name} - $${product.price} LB Coins`);
console.log(`Can Purchase: $${canPurchase}`);Step 2: Process Purchase
When customer clicks "Buy Now", transfer coins to General Treasury:
JavaScript
// Process product purchase
const orderId = generateOrderId();
const purchaseResponse = await fetch('https://api.loopingbinary.com/api/coins/transfer-to-treasury', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
},
body: JSON.stringify(({
treasuryType: 'GENERAL',
amount: product.price,
reason: `Order #$${orderId}: $${product.name}`
})
});
if (purchaseResponse.ok) {
const transaction = await purchaseResponse.json();
// Create order in your database
await createOrder({
orderId,
userId: user.id,
productId: product.id,
amount: product.price,
transactionId: transaction.id,
status: 'PAID'
});
console.log('✓ Order placed successfully!');
console.log(`Order ID: $${orderId}`);
} else {
console.log('✗ Payment failed - Insufficient balance');
}Step 3: Process Refunds (Admin)
When an order is cancelled, refund coins from General Treasury back to customer:
JavaScript (Admin)
// Process refund (admin operation)
const refundResponse = await fetch('https://api.loopingbinary.com/api/admin/treasury/transfer', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': adminApiKey,
'Authorization': 'Bearer ' + adminToken
},
body: JSON.stringify(({
fromTreasury: 'GENERAL',
toUserId: order.userId,
amount: order.amount,
reason: `Refund for Order #$${order.orderId}`
})
});
if (refundResponse.ok) {
// Update order status
await updateOrderStatus(order.orderId, 'REFUNDED');
console.log('✓ Refund processed successfully');
} else {
console.log('✗ Refund failed');
}E-commerce Best Practices
- Always verify balance before checkout
- Store transaction IDs with orders for tracking
- Implement automatic refund processing
- Display clear coin pricing on product pages
- Provide order history with transaction details
- Send email confirmations with transaction IDs