Skip to main content
Glama

create_payment_token

Generate a secure payment token for storing customer payment methods, enabling recurring transactions and one-click checkouts in PayPal integrations.

Instructions

Create a payment token

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
customerYes
payment_sourceYes

Implementation Reference

  • src/index.ts:780-817 (registration)
    Registration of the 'create_payment_token' tool with its input schema definition.
    { name: 'create_payment_token', description: 'Create a payment token', inputSchema: { type: 'object', properties: { customer: { type: 'object', properties: { id: { type: 'string' }, email_address: { type: 'string' } }, required: ['id'] }, payment_source: { type: 'object', properties: { card: { type: 'object', properties: { name: { type: 'string' }, number: { type: 'string' }, expiry: { type: 'string' }, security_code: { type: 'string' } } }, paypal: { type: 'object', properties: { email_address: { type: 'string' } } } } } }, required: ['customer', 'payment_source'] } },
  • The handler function for 'create_payment_token' that calls the PayPal API to create a payment token.
    case 'create_payment_token': { const args = this.validatePaymentToken(request.params.arguments); const response = await axios.post<PayPalPaymentToken>( 'https://api-m.sandbox.paypal.com/v3/payment-tokens', args, { headers } ); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }] }; }
  • Helper function to validate and sanitize input parameters for the create_payment_token tool.
    private validatePaymentToken(args: unknown): PayPalPaymentToken { if (typeof args !== 'object' || !args) { throw new McpError(ErrorCode.InvalidParams, 'Invalid payment token data'); } const token = args as Record<string, unknown>; if (!token.customer || typeof token.customer !== 'object' || !token.payment_source || typeof token.payment_source !== 'object') { throw new McpError(ErrorCode.InvalidParams, 'Missing required payment token fields'); } const customer = token.customer as Record<string, unknown>; if (typeof customer.id !== 'string') { throw new McpError(ErrorCode.InvalidParams, 'Invalid customer ID'); } const validatedToken: PayPalPaymentToken = { customer: { id: customer.id }, payment_source: {} }; if (typeof customer.email_address === 'string') { validatedToken.customer.email_address = customer.email_address; } const source = token.payment_source as Record<string, unknown>; if (source.card && typeof source.card === 'object') { const card = source.card as Record<string, unknown>; if (typeof card.name === 'string' && typeof card.number === 'string' && typeof card.expiry === 'string' && typeof card.security_code === 'string') { validatedToken.payment_source.card = { name: card.name, number: card.number, expiry: card.expiry, security_code: card.security_code }; } } if (source.paypal && typeof source.paypal === 'object') { const paypal = source.paypal as Record<string, unknown>; if (typeof paypal.email_address === 'string') { validatedToken.payment_source.paypal = { email_address: paypal.email_address }; if (typeof paypal.account_id === 'string') { validatedToken.payment_source.paypal.account_id = paypal.account_id; } } } return validatedToken; }
  • TypeScript interface defining the structure of a PayPal payment token, used in the tool implementation.
    interface PayPalPaymentToken { id?: string; customer: { id: string; email_address?: string; phone?: { phone_type: string; phone_number: { national_number: string; }; }; }; payment_source: { card?: { name: string; number: string; expiry: string; security_code: string; }; paypal?: { email_address: string; account_id?: string; }; }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DynamicEndpoints/Paypal-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server