座席アドオンのために次の値を入力します:アドオン名: Additional Team Seat説明: Add extra team members to your workspace with full access to all features価格: 入力 → 2.00通貨: 基本サブスクリプションの通貨と一致する必要があります税カテゴリ: 製品に適切なカテゴリを選択します。
API キーをバージョン管理にコミットしないでください。.env をあなたの .gitignore ファイルに追加してください。
3
チェックアウトセッション作成の実装
次のコードを使って src/server.ts ファイルを作成します:
コピー
// Add this new endpoint for dynamic seat quantitiesimport 'dotenv/config';import DodoPayments from 'dodopayments';import express, { Request, Response } from 'express';const app = express();// Initialize the Dodo Payments clientconst client = new DodoPayments({ bearerToken: process.env.DODO_PAYMENTS_API_KEY, environment: 'test_mode'});async function createCheckoutSession(seatCount: number) { try { const session = await client.checkoutSessions.create({ // Products to sell - use IDs from your Dodo Payments dashboard product_cart: [ { product_id: 'pdt_7Rl9OWT2Mz4wwUTKz74iZ', // Replace with your actual product ID quantity: 1, addons: [ { addon_id: 'adn_eKQbNakKrivDpaxmI8wKI', // Replace with your actual addon ID quantity: seatCount } ] } ], // Pre-fill customer information to reduce friction customer: { email: 'steve@example.com', name: 'Steve Irwin', }, // Where to redirect after successful payment return_url: 'https://example.com/checkout/success', }); // Redirect your customer to this URL to complete payment console.log('Checkout URL:', session.checkout_url); console.log('Session ID:', session.session_id); return session; } catch (error) { console.error('Failed to create checkout session:', error); throw error; }}// Example usage in an Express.js routeapp.post('/create-checkout/:seatCount', async (req: Request, res: Response) => { try { const seatCount = parseInt(req.params.seatCount); const session = await createCheckoutSession(seatCount); res.json({ checkout_url: session.checkout_url }); } catch (error) { res.status(500).json({ error: 'Failed to create checkout session' }); }});// Add this line after your other middlewareapp.use(express.static('public'));// Add this route to serve the demo pageapp.get('/', (req, res) => { res.sendFile(__dirname + '/../public/index.html');});app.listen(3000, () => { console.log('Server is running on port 3000');});
// Add this line after your other middlewareapp.use(express.static('public'));// Add this route to serve the demo pageapp.get('/', (req, res) => { res.sendFile(__dirname + '/../public/index.html');});