@tooly/paypal
v0.0.2
Published
PayPal API tools for OpenAI, Anthropic, and AI SDK
Maintainers
Readme
@tooly/paypal
PayPal API tools for AI applications, compatible with OpenAI function calling, Anthropic tool use, and AI SDK.
Installation
npm install @tooly/paypal
# or
yarn add @tooly/paypal
# or
pnpm add @tooly/paypalSetup
Get your PayPal client ID and secret from your PayPal Developer Dashboard.
Usage
Basic Usage
import { PayPalTools } from '@tooly/paypal'
const paypal = new PayPalTools('client-id', 'client-secret', 'sandbox') // or 'live'
// Get available tools for function calling
const tools = paypal.getTools()
// Execute a function
const result = await paypal.executeFunction('createOrder', {
intent: 'CAPTURE',
purchase_units: [
{
amount: {
currency_code: 'USD',
value: '10.00',
},
},
],
})AI SDK
import { createAITools } from '@tooly/paypal'
const tools = createAITools('client-id', 'client-secret', 'sandbox')
// Use with generateText
import { generateText } from 'ai'
const result = await generateText({
model: openai('gpt-4.1-nano'),
messages: [{ role: 'user', content: 'Create a payment order for $50' }],
tools,
})OpenAI Function Calling
import { createOpenAIFunctions } from '@tooly/paypal'
const { tools, executeFunction } = createOpenAIFunctions('client-id', 'client-secret', 'sandbox')
// Use with OpenAI client
const completion = await openai.chat.completions.create({
model: 'gpt-4.1-nano',
messages: [{ role: 'user', content: 'Create an order and capture payment' }],
tools,
})
// Execute function calls
for (const toolCall of completion.choices[0].message.tool_calls || []) {
const result = await executeFunction(toolCall.function.name, JSON.parse(toolCall.function.arguments))
}Anthropic Tool Use
import { createAnthropicTools } from '@tooly/paypal'
const { tools, executeFunction } = createAnthropicTools('client-id', 'client-secret', 'sandbox')
// Use with Anthropic client
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
messages: [{ role: 'user', content: 'Process a refund for order' }],
tools,
})
// Execute tool calls
for (const toolUse of message.content.filter((c) => c.type === 'tool_use')) {
const result = await executeFunction(toolUse.name, toolUse.input)
}Available Tools
createOrder- Create a new payment ordershowOrderDetails- Get order details by IDcaptureOrder- Capture payment for an orderauthorizeOrder- Authorize payment for an ordershowAuthorizedPayment- Show authorized payment detailscaptureAuthorizedPayment- Capture an authorized paymentvoidAuthorizedPayment- Void an authorized paymentreauthorizePayment- Reauthorize an authorized paymentshowCapturedPayment- Show captured payment detailsrefundCapturedPayment- Refund a captured paymentshowRefundDetails- Show refund details
License
MIT
