create_invoice
Generate invoices in Visa Acceptance by providing invoice details, customer information, and delivery preferences to process payments.
Instructions
This tool will create an invoice in Visa Acceptance.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| invoice_number | Yes | Unique invoice number (letters & numbers only, <20 chars) | |
| totalAmount | Yes | Invoice total amount e.g. "100.00" | |
| currency | Yes | Invoice currency code e.g. "USD" | |
| customerName | No | Customer name for invoice | |
| customerEmail | No | Customer email for invoice | |
| invoiceInformation | Yes | Invoice information object |
Implementation Reference
- The main handler function 'createInvoice' that executes the tool logic by calling the Cybersource Invoices API to create an invoice.export const createInvoice = async ( visaClient: any, context: VisaContext, params: z.infer<ReturnType<typeof createInvoiceParameters>> ) => { try { const invoiceApiInstance = new cybersourceRestApi.InvoicesApi(visaClient.configuration, visaClient.visaApiClient); const requestObj = { merchantId: context.merchantId, customerInformation: { name: params.customerName, email: params.customerEmail }, orderInformation: { amountDetails: { totalAmount: params.totalAmount, currency: params.currency } }, invoiceInformation: { description: params.invoiceInformation?.description, dueDate: params.invoiceInformation?.dueDate || new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString().split('T')[0], invoiceNumber: params.invoice_number, sendImmediately: params.invoiceInformation?.sendImmediately !== undefined ? params.invoiceInformation.sendImmediately : true, deliveryMode: params.invoiceInformation?.deliveryMode || 'email' } }; const result = await new Promise((resolve, reject) => { invoiceApiInstance.createInvoice(requestObj, (error: any, data: any) => { if (error) { reject(error); } else { resolve(data); } }); }); const maskedResult = maskInvoiceCustomerInfo(result); return maskedResult; } catch (error) { return 'Failed to create invoice'; } };
- Zod schema defining the input parameters for the 'create_invoice' tool.export const createInvoiceParameters = ( context: VisaContext = {} as VisaContext ) => { return z.object({ invoice_number: z.string().describe('Unique invoice number (letters & numbers only, <20 chars)'), totalAmount: z.string().describe('Invoice total amount e.g. "100.00"'), currency: z.string().describe('Invoice currency code e.g. "USD"'), customerName: z.string().optional().describe('Customer name for invoice'), customerEmail: z.string().optional().describe('Customer email for invoice'), invoiceInformation: z.object({ description: z.string().describe('Short invoice description (max 50 characters)'), dueDate: z.string().describe('Due date in YYYY-MM-DD format'), sendImmediately: z.boolean().describe('Whether to send the invoice immediately'), deliveryMode: z.string().describe('Delivery mode e.g. "email"') }).required().describe('Invoice information object'), }); };
- typescript/src/shared/invoices/createInvoice.ts:87-98 (registration)Tool registration object that defines the 'create_invoice' tool, wiring the schema, description, and handler.const tool = (context: VisaContext): Tool => ({ method: 'create_invoice', name: 'Create Invoice', description: createInvoicePrompt(context), parameters: createInvoiceParameters(context), actions: { invoices: { create: true, }, }, execute: createInvoice, });
- typescript/src/shared/tools.ts:40-53 (registration)Central registration where the create_invoice tool module is included in the list of all tools returned by createTools.export function createTools(context: VisaContext): Tool[] { return [ createInvoiceToolModule(context), updateInvoiceToolModule(context), getInvoiceToolModule(context), listInvoicesToolModule(context), sendInvoiceToolModule(context), cancelInvoiceToolModule(context), createPaymentLinkToolModule(context), updatePaymentLinkToolModule(context), getPaymentLinkToolModule(context), listPaymentLinkToolModule(context) ]; }