create_payment_link
Generate secure payment links for purchases or donations through Visa Acceptance, specifying currency, amount, and line items for customer transactions.
Instructions
This tool will create a payment link in Visa Acceptance.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| linkType | Yes | Type of payment link (PURCHASE OR DONATION) | |
| purchaseNumber | Yes | Unique alphanumeric id, no special chararacters for the purchase less than 20 characters | |
| currency | Yes | Currency code e.g. "USD" (Required) | |
| totalAmount | No | Total payment amount e.g. "100.00" | |
| requestPhone | No | Request phone number from customer | |
| requestShipping | No | Request shipping address from customer | |
| clientReferenceCode | No | Custom client reference code for the transaction | |
| lineItems | Yes | Line items in the purchase |
Implementation Reference
- The main handler function that executes the create_payment_link tool logic by constructing a CreatePaymentLinkRequest and calling the Cybersource PaymentLinksApi.export const createPaymentLink = async ( visaClient: any, context: VisaContext, params: z.infer<ReturnType<typeof createPaymentLinkParameters>> ) => { try { const paymentLinkApiInstance = new cybersourceRestApi.PaymentLinksApi(visaClient.configuration, visaClient.visaApiClient); const processingInformation = new cybersourceRestApi.Iplv2paymentlinksProcessingInformation( params.linkType, params.requestPhone, params.requestShipping ); const purchaseInformation = new cybersourceRestApi.Iplv2paymentlinksPurchaseInformation(params.purchaseNumber); const amountDetails = new cybersourceRestApi.Iplv2paymentlinksOrderInformationAmountDetails(params.currency); amountDetails.totalAmount = params.totalAmount; const lineItems = params.lineItems.map((item: LineItem) => { const lineItem = new cybersourceRestApi.Iplv2paymentlinksOrderInformationLineItems(item.productName); lineItem.productSku = item.productSKU; lineItem.productDescription = item.productDescription; lineItem.quantity = parseInt(item.quantity, 10); lineItem.unitPrice = item.unitPrice; return lineItem; }); const orderInformation = new cybersourceRestApi.Iplv2paymentlinksOrderInformation(amountDetails, lineItems); const requestObj = new cybersourceRestApi.CreatePaymentLinkRequest( processingInformation, purchaseInformation, orderInformation ); const clientReferenceInformation = new cybersourceRestApi.Invoicingv2invoicesClientReferenceInformation(); if (params.clientReferenceCode) { clientReferenceInformation.code = params.clientReferenceCode; } else if (context.merchantId) { clientReferenceInformation.code = context.merchantId; } requestObj.clientReferenceInformation = clientReferenceInformation; // Initialize partner object if it doesn't exist requestObj.clientReferenceInformation.partner = {}; // Set the developer ID based on the context mode setDeveloperId(requestObj, context); const result = await new Promise((resolve, reject) => { paymentLinkApiInstance.createPaymentLink(requestObj, (error: any, data: any) => { if (error) { reject(error); } else { resolve(data); } }); }); return result; } catch (error) { return 'Failed to create payment link'; } };
- Zod schema defining the input parameters for the create_payment_link tool.export const createPaymentLinkParameters = ( context: VisaContext = {} as VisaContext ) => { return z.object({ linkType: z.string().describe('Type of payment link (PURCHASE OR DONATION)'), purchaseNumber: z.string().describe('Unique alphanumeric id, no special chararacters for the purchase less than 20 characters'), currency: z.string().describe('Currency code e.g. "USD" (Required)'), totalAmount: z.string().optional().describe('Total payment amount e.g. "100.00"'), requestPhone: z.boolean().optional().default(false).describe('Request phone number from customer'), requestShipping: z.boolean().optional().default(false).describe('Request shipping address from customer'), clientReferenceCode: z.string().optional().describe('Custom client reference code for the transaction'), lineItems: z.array( z.object({ productName: z.string().describe('Name of the product'), productSKU: z.string().optional().describe('Product SKU identifier'), productDescription: z.string().optional().describe('Product description'), quantity: z.string().describe('Quantity of the product'), unitPrice: z.string().describe('Unit price of the product') }) ).describe('Line items in the purchase') }); };
- Tool module definition and export, registering the create_payment_link tool with its handler, schema, and metadata.const tool = (context: VisaContext): Tool => ({ method: 'create_payment_link', name: 'Create Payment Link', description: createPaymentLinkPrompt(context), parameters: createPaymentLinkParameters(context), actions: { paymentLinks: { create: true, }, }, execute: createPaymentLink, }); export default tool;
- typescript/src/shared/tools.ts:40-52 (registration)Function that collects and returns all tools, including createPaymentLinkToolModule, for overall tool registration.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) ];