Booth Agent for TAT Protocol - Purchase and sales protocol
npm install @tat-protocol/boothPurchase and sales protocol for TAT Protocol tokens.
The Boxoffice module provides two implementations:
booth.catalog - Browse available TATsbooth.invoice - Request purchase invoicebooth.pay - Submit paymentbooth.status - Check invoice statusUse this for spec-compliant implementations.
Use this for custom implementations with advanced features.
---
``bash`
npm install @tat-protocol/boxoffice
`typescript
import { BoxofficeServerSpec, CatalogItem } from '@tat-protocol/boxoffice';
import { NodeStorage } from '@tat-protocol/storage';
// Create spec-compliant booth
const boxoffice = await BoxofficeServerSpec.create({
storage: new NodeStorage({ path: './boxoffice' }),
keys: myKeys,
boxOfficeName: 'TATpay',
fee: 0.025, // 2.5% fee
relays: ['wss://relay.damus.io'],
supportedPaymentMethods: ['lightning', 'card']
});
// Add catalog items (per spec section 4.4)
const catalogItem: CatalogItem = {
id: 'premium-monthly',
issuer: forgePublicKey,
name: 'Premium Membership',
description: 'Monthly premium access',
price: {
amount: 5.0,
currency: 'USD'
},
tokenType: 'TAT',
duration: 2592000, // 30 days in seconds
supply: {
total: 0, // Unlimited
remaining: 0,
},
metadata: {
category: 'membership',
benefits: ['Exclusive content', 'Early access']
}
};
await boxoffice.addCatalogItem(catalogItem);
// Now clients can call:
// - booth.catalog
// - booth.invoice
// - booth.pay
// - booth.status
`
`typescript
import { BoxofficeBase, TokenOrder, Receipt } from '@tat-protocol/boxoffice';
class MyBoxoffice extends BoxofficeBase {
// Implement how to fulfill orders after payment
protected async fulfillOrder(order: TokenOrder): Promise
// Mint tokens via your forge
const tokens = await this.forge.mint({
recipient: order.buyerAddress,
quantity: order.quantity,
tokenType: order.tokenType
});
// Create receipt
return {
receiptId: receipt-${order.orderId},
orderId: order.orderId,
buyer: order.buyer,
payment: this.getPaymentForOrder(order.orderId),
tokens: tokens.map(t => t.toJWT()),
issuedAt: Date.now()
};
}
// Validate orders before creation
protected async validateOrder(order: Partial
// Custom validation logic
// Check inventory, buyer eligibility, pricing, etc.
return true;
}
}
`
`typescript
import { PaymentProvider, PaymentMethod } from '@tat-protocol/boxoffice';
class BitcoinPaymentProvider implements PaymentProvider {
readonly name = 'bitcoin';
readonly supportedMethods = [PaymentMethod.BITCOIN];
async initializePayment(payment: Payment) {
// Generate Bitcoin address
const address = await this.generateAddress();
return {
paymentId: payment.paymentId,
paymentAddress: address,
expiresAt: Date.now() + 3600000 // 1 hour
};
}
async verifyPayment(paymentId: string) {
// Check blockchain for payment
const tx = await this.checkBlockchain(paymentId);
return {
verified: tx.confirmed,
status: tx.confirmed ? 'COMPLETED' : 'PENDING',
transactionId: tx.hash,
completedAt: tx.confirmedAt
};
}
// Implement other PaymentProvider methods...
}
``
See inline documentation in the source code for detailed API information.
See the examples directory for complete usage examples.
MIT License. See LICENSE for details.