OpenAI Integration
This guide demonstrates how to integrate PayLink with OpenAI’s models to create AI assistants that can process payments. The integration uses PayLink’s OpenAI adapter, which formats PayLink tools to be compatible with OpenAI’s function calling API.Prerequisites
Before you begin, make sure you have:- Installed the PayLink SDK
- An OpenAI API key
- Access to a PayLink server with payment tools
Installation
Install the required packages:Basic Integration
Step 1: Initialize the PayLink Client
First, initialize the PayLink client using the OpenAI adapter:PayLinkClient
from the openai_adapter.toolkit
module automatically formats PayLink tools in a way that’s compatible with OpenAI’s function calling API.
Step 2: Set Up OpenAI Client
Initialize the OpenAI client:Step 3: Create a Conversation with Tool Calls
Send a user message to OpenAI with the PayLink tools:Step 4: Execute the PayLink Tool
Once you have the tool call from OpenAI, you can execute it using the PayLink client:Error Handling
When integrating with payment systems, proper error handling is essential. Here’s how to handle errors:Tips for Effective Integration
- System Instructions: Include clear instructions in your system message about payment capabilities.
-
Validation: Although OpenAI models can extract payment details, add validation before processing:
-
User Confirmation: For better user experience, confirm payment details before processing:
-
Status Updates: Keep the user informed about the payment status:
Next Steps
Now that you’ve integrated PayLink with OpenAI, you can:- Explore other PayLink tools like checking payment status or refunds
- Enhance your assistant with more complex payment workflows
- Implement user authentication and authorization
Troubleshooting
Tool Not Found Error: If you receive a “Tool not found” error, ensure that:- The PayLink server is running and accessible
- You’re using the correct tool name (case-sensitive)
- Your PayLink SDK is up to date
- The phone number is in the correct format (e.g., 254XXXXXXXXX)
- The amount is within acceptable limits
- The PayLink server can connect to the payment provider