UNPKG

@airwallex/developer-mcp

Version:

MCP server for AI agents that assist developers integrating with the Airwallex platform

72 lines (71 loc) 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createBillingCheckoutToolConfig = exports.createBillingCheckoutSchema = void 0; exports.executeCreateBillingCheckout = executeCreateBillingCheckout; const uuid_1 = require("uuid"); const zod_1 = require("zod"); const descriptions_1 = require("../constants/descriptions"); exports.createBillingCheckoutSchema = zod_1.z.object({ mode: zod_1.z.enum(["PAYMENT", "SUBSCRIPTION"], { errorMap: () => ({ message: "Mode must be either PAYMENT or SUBSCRIPTION", }), }), price_id: zod_1.z.string().min(1, "Price ID is required"), quantity: zod_1.z .number() .int() .positive("Quantity must be a positive integer") .default(1), success_url: zod_1.z .string() .url("Success URL must be a valid URL") .default("https://demo.airwallex.com") .optional(), }); async function executeCreateBillingCheckout(airwallex, args) { try { const requestId = (0, uuid_1.v4)(); const requestBody = { line_items: [ { price_id: args.price_id, quantity: args.quantity, }, ], mode: args.mode, request_id: requestId, success_url: args.success_url, }; if (args.mode === "SUBSCRIPTION") { requestBody.subscription_data = {}; } else if (args.mode === "PAYMENT") { requestBody.invoice_data = {}; } const response = (await airwallex.post("/api/v1/billing_checkouts/create", requestBody)); return { content: [ { text: JSON.stringify(response, null, 2), type: "text", }, ], }; } catch (error) { const statusCode = error?.status || error?.statusCode || 500; const errorMessage = error?.message || "Unknown error occurred"; throw new Error(`Failed to create billing checkout (${statusCode}): ${errorMessage}`); } } exports.createBillingCheckoutToolConfig = { annotations: { openWorldHint: true, readOnlyHint: false, title: "Create billing checkout", }, description: descriptions_1.TOOL_DESCRIPTIONS.CREATE_BILLING_CHECKOUT, inputSchema: exports.createBillingCheckoutSchema, name: "create_billing_checkout", };