checkout
Process and finalize orders, manage shopping carts, and handle subscriptions through Terminal.shop's API, enabling streamlined e-commerce transactions for AI assistants.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.js:716-773 (handler)Handler for the 'checkout' tool: Converts the shopping cart to an order by calling the /cart/convert API endpoint. Formats a detailed markdown response with order ID, shipping information, tracking details (if available), order items, and totals. Includes error handling with console logging and error response.server.tool("checkout", {}, async () => { try { const response = await terminalApi.post("/cart/convert"); const order = response.data.data; let formattedText = "# Order Placed Successfully!\n\n"; formattedText += `Order ID: ${order.id}\n`; // Shipping information formattedText += "\n## Shipping Information\n"; formattedText += `Name: ${order.shipping.name}\n`; formattedText += `Address: ${order.shipping.street1}${order.shipping.street2 ? `, ${order.shipping.street2}` : ""}\n`; formattedText += `${order.shipping.city}, ${order.shipping.province || ""} ${order.shipping.zip}\n`; formattedText += `Country: ${order.shipping.country}\n`; if (order.shipping.phone) formattedText += `Phone: ${order.shipping.phone}\n`; // Tracking information if available if (order.tracking) { formattedText += "\n## Tracking Information\n"; formattedText += `Service: ${order.tracking.service}\n`; formattedText += `Tracking Number: ${order.tracking.number}\n`; formattedText += `Tracking URL: ${order.tracking.url}\n`; } // Order details formattedText += "\n## Order Details\n"; order.items.forEach((item) => { formattedText += `- Quantity: ${item.quantity}, Amount: $${item.amount / 100}, Variant ID: ${item.productVariantID}\n`; }); // Totals formattedText += "\n## Order Totals\n"; formattedText += `Subtotal: $${order.amount.subtotal / 100}\n`; formattedText += `Shipping: $${order.amount.shipping / 100}\n`; formattedText += `Total: $${(order.amount.subtotal + order.amount.shipping) / 100}\n`; return { content: [ { type: "text", text: formattedText, }, ], }; } catch (error) { console.error("Error during checkout:", error); return { content: [ { type: "text", text: `Error during checkout: ${error.message}`, }, ], isError: true, }; } });
- server.js:716-773 (registration)Registration of the 'checkout' tool using server.tool with empty schema and inline async handler.server.tool("checkout", {}, async () => { try { const response = await terminalApi.post("/cart/convert"); const order = response.data.data; let formattedText = "# Order Placed Successfully!\n\n"; formattedText += `Order ID: ${order.id}\n`; // Shipping information formattedText += "\n## Shipping Information\n"; formattedText += `Name: ${order.shipping.name}\n`; formattedText += `Address: ${order.shipping.street1}${order.shipping.street2 ? `, ${order.shipping.street2}` : ""}\n`; formattedText += `${order.shipping.city}, ${order.shipping.province || ""} ${order.shipping.zip}\n`; formattedText += `Country: ${order.shipping.country}\n`; if (order.shipping.phone) formattedText += `Phone: ${order.shipping.phone}\n`; // Tracking information if available if (order.tracking) { formattedText += "\n## Tracking Information\n"; formattedText += `Service: ${order.tracking.service}\n`; formattedText += `Tracking Number: ${order.tracking.number}\n`; formattedText += `Tracking URL: ${order.tracking.url}\n`; } // Order details formattedText += "\n## Order Details\n"; order.items.forEach((item) => { formattedText += `- Quantity: ${item.quantity}, Amount: $${item.amount / 100}, Variant ID: ${item.productVariantID}\n`; }); // Totals formattedText += "\n## Order Totals\n"; formattedText += `Subtotal: $${order.amount.subtotal / 100}\n`; formattedText += `Shipping: $${order.amount.shipping / 100}\n`; formattedText += `Total: $${(order.amount.subtotal + order.amount.shipping) / 100}\n`; return { content: [ { type: "text", text: formattedText, }, ], }; } catch (error) { console.error("Error during checkout:", error); return { content: [ { type: "text", text: `Error during checkout: ${error.message}`, }, ], isError: true, }; } });
- server.js:716-716 (schema)Empty schema for the 'checkout' tool (no input parameters required).server.tool("checkout", {}, async () => {