delete_customer_payment_method
Remove a customer's saved payment method using their customer ID and payment method ID. Helps manage billing information by deleting outdated or invalid payment methods.
Instructions
Delete a payment method. DELETE /customers/{customerId}/paymentmethods/{paymentMethodId}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| customerId | Yes | Customer ID (required) | |
| paymentMethodId | Yes | Payment method ID (required) |
Implementation Reference
- The handler function that parses the Zod-validated customerId and paymentMethodId arguments and delegates to customerService.deleteCustomerPaymentMethod.
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, paymentMethodId } = parsed.data; return handleToolCall(() => customerService.deleteCustomerPaymentMethod(client, customerId, paymentMethodId) ); } - Zod schema for input validation: requires customerId (string) and paymentMethodId (string), both min length 1.
const schema = z.object({ customerId: z.string().min(1, "customerId is required"), paymentMethodId: z.string().min(1, "paymentMethodId is required"), }); - MCP ToolDefinition with name 'delete_customer_payment_method', description, and JSON Schema inputSchema listing customerId and paymentMethodId as required string properties.
const definition = { name: "delete_customer_payment_method", description: "Delete a payment method. DELETE /customers/{customerId}/paymentmethods/{paymentMethodId}.", inputSchema: { type: "object" as const, properties: { customerId: { type: "string", description: "Customer ID (required)" }, paymentMethodId: { type: "string", description: "Payment method ID (required)" }, }, required: ["customerId", "paymentMethodId"], }, }; - src/tools/customers/deleteCustomerPaymentMethod.ts:37-40 (registration)Exported Tool object combining the definition and handler. Imported and registered in tools/customers/index.ts via deleteCustomerPaymentMethodTool.
export const deleteCustomerPaymentMethodTool: Tool = { definition, handler, }; - The service-layer function that performs the DELETE HTTP call to /customers/{customerId}/paymentmethods/{paymentMethodId} and returns the result, falling back to a success message if empty.
export async function deleteCustomerPaymentMethod( client: Client, customerId: string, paymentMethodId: string ): Promise<Record<string, unknown>> { const result = await client.delete<Record<string, unknown>>( `/customers/${customerId}/paymentmethods/${paymentMethodId}` ); return Object.keys(result ?? {}).length ? result : { success: true, message: "Payment method deleted" }; }