list_customer_payment_methods
Retrieve all payment methods for a customer. Use pagination to manage large result sets.
Instructions
List all payment methods for a customer. GET /customers/{customerId}/paymentmethods. Optional: pageNo, itemPerPage.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| customerId | Yes | Customer ID (required) | |
| pageNo | No | Page number (default: 1) | |
| itemPerPage | No | Items per page (default: API default) |
Implementation Reference
- The handler function for the list_customer_payment_methods tool. It parses args with Zod (customerId required, pageNo/itemPerPage optional), then calls customerService.listCustomerPaymentMethods().
async function handler(client: Client, args: Record<string, unknown> | undefined) { const parsed = schema.safeParse(args); if (!parsed.success) { return errorResult(parsed.error.errors.map((e) => e.message).join("; ")); } const { customerId, pageNo, itemPerPage } = parsed.data; return handleToolCall(() => customerService.listCustomerPaymentMethods(client, customerId, { pageNo, itemPerPage }) ); } - Zod schema for input validation: customerId (required string), pageNo (optional positive int), itemPerPage (optional positive int).
const schema = z.object({ customerId: z.string().min(1, "customerId is required"), pageNo: z.number().int().min(1).optional(), itemPerPage: z.number().int().min(1).optional(), }); - MCP tool definition/inputSchema with name 'list_customer_payment_methods', description, and JSON Schema properties for customerId, pageNo, itemPerPage.
const definition = { name: "list_customer_payment_methods", description: "List all payment methods for a customer. GET /customers/{customerId}/paymentmethods. Optional: pageNo, itemPerPage.", inputSchema: { type: "object" as const, properties: { customerId: { type: "string", description: "Customer ID (required)" }, pageNo: { type: "number", description: "Page number (default: 1)" }, itemPerPage: { type: "number", description: "Items per page (default: API default)" }, }, required: ["customerId"], }, }; - src/tools/customers/index.ts:31-56 (registration)Registration of the tool in the registerCustomerTools() function, which returns all customer tools including listCustomerPaymentMethodsTool.
export function registerCustomerTools(): Tool[] { return [ listCustomersTool, getCustomerTool, createCustomerTool, updateCustomerTool, deleteCustomerTool, getCustomerInvoicesTool, getCustomerUnpaidInvoicesTool, getCustomerSubscriptionsTool, getCustomerLogsTool, listCustomerAddressesTool, getCustomerAddressTool, createCustomerAddressTool, updateCustomerAddressTool, deleteCustomerAddressTool, listCustomerPaymentMethodsTool, getCustomerPaymentMethodTool, createCustomerPaymentMethodTool, updateCustomerPaymentMethodTool, deleteCustomerPaymentMethodTool, listCustomerChargesCreditsTool, createCustomerChargeCreditTool, deleteCustomerChargeCreditTool, ]; } - The underlying service function that makes the GET /customers/{customerId}/paymentmethods API call with optional pageNo and itemPerPage query params.
export async function listCustomerPaymentMethods( client: Client, customerId: string, params?: Pick<PaginationIncludeParams, "pageNo" | "itemPerPage"> ): Promise<CustomerPaymentMethod[] | PaginatedResponse<CustomerPaymentMethod>> { const search = new URLSearchParams(); if (params?.pageNo != null) search.append("pageNo", String(params.pageNo)); if (params?.itemPerPage != null) search.append("itemPerPage", String(params.itemPerPage)); const q = search.toString(); return client.get<CustomerPaymentMethod[] | PaginatedResponse<CustomerPaymentMethod>>( `/customers/${customerId}/paymentmethods${q ? `?${q}` : ""}` ); }