Agent Enablement Toolkit
Learn how you can build AI-powered payment agents with LangChain, Vercel AI SDK, and Open AI SDK agents.
Pine Labs Online Agent Toolkit enables developers to build AI-powered payment agents using frameworks such as LangChain, Vercel AI SDK, and the OpenAI Agents SDK. It connects these frameworks with Pine Labs Online payment APIs via function calling, allowing agents to create orders, process payments, and manage transactions programmatically.
Prerequisites
Complete the following prerequisites before building PineLabs payment agents.
- Create Pine Labs Online Merchant Account. You can register to Pine Labs Online Merchant Account here.
- After Creating Successfully, Login to our Dashboard and generate the
client_idandclient_secret. - Ensure
Node.jsversion18or later is installed.
Framework support
The toolkit supports the following frameworks, each accessible through a dedicated sub-path.
| Framework | Import Path | Description |
|---|---|---|
| OpenAI | @plural_pinelabs/agent-toolkit/openai | For Open AI Agents SDK |
| LangChain | @plural_pinelabs/agent-toolkit/langchain | For LangChain agents |
| Vercel AI SDK | @plural_pinelabs/agent-toolkit/ai-sdk | For Vercel's AI SDK |
Installation
Use the below code to Install the toolkit using your preferred package manager:
npm install @plural_pinelabs/agent-toolkit
yarn add @plural_pinelabs/agent-toolkit
pnpm add @plural_pinelabs/agent-toolkit
Available Tools
The table below shows the list of PineLabs Tools available.
| Tool | Description |
|---|---|
createOrder | Use this tool to create an Order. |
getOrder | Use this tool to retrieve the order by order ID. |
cancelOrder | Use this tool to cancel the Payment against an order. |
createRefund | Use this tool to initiate a refund against an order. |
Sample Codes
Use the below code samples to test and integrate quickly.
import { Agent, run } from '@openai/agents';
import {
PinelabsAgentToolkit,
pinelabsEnvironment,
} from '@plural_pinelabs/agent-toolkit/openai';
const pinelabs = new PinelabsAgentToolkit(
pinelabsEnvironment.UAT, // or pinelabsEnvironment.PRODUCTION
process.env.PINE_CLIENT_ID!,
process.env.PINE_CLIENT_SECRET!
);
const agent = new Agent({
name: 'Payment Agent',
instructions: 'You are a helpful payment assistant.',
model: 'gpt-4o',
tools: pinelabs.getAgentTools(),
});
const result = await run(agent, 'Create an order for Rs. 500 for customer [email protected]');
console.log(result.finalOutput);
Expected Result
{
"token": "<<Redirect Token>>",
"order_id": "v1-5757575757-aa-hU1rUd",
"redirect_url": "https://api.pluralonline.com/api/v3/checkout-bff/redirect/checkout?token=<<Redirect Token>>",
"response_code": 200,
"response_message": "Order Creation Successful."
}
import OpenAI from 'openai';
import {
PinelabsAgentToolkit,
pinelabsEnvironment,
} from '@plural_pinelabs/agent-toolkit/openai';
const openai = new OpenAI();
const pinelabs = new PinelabsAgentToolkit(
pinelabsEnvironment.UAT,
process.env.PINE_CLIENT_ID!,
process.env.PINE_CLIENT_SECRET!
);
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Create an order for Rs. 500' }],
tools: pinelabs.getTools(),
});
for (const toolCall of response.choices[0].message.tool_calls ?? []) {
const result = await pinelabs.handleToolCall(
toolCall.function.name,
JSON.parse(toolCall.function.arguments)
);
console.log(result);
}
Expected Result
{
"token": "<<Redirect Token>>",
"order_id": "v1-5757575757-aa-hU1rUd",
"redirect_url": "https://api.pluralonline.com/api/v3/checkout-bff/redirect/checkout?token=<<Redirect Token>>",
"response_code": 200,
"response_message": "Order Creation Successful."
}
import { ChatOpenAI } from '@langchain/openai';
import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';
import { ChatPromptTemplate } from '@langchain/core/prompts';
import {
PinelabsAgentToolkit,
pinelabsEnvironment,
} from '@plural_pinelabs/agent-toolkit/langchain';
const pinelabs = new PinelabsAgentToolkit(
pinelabsEnvironment.UAT,
process.env.PINE_CLIENT_ID!,
process.env.PINE_CLIENT_SECRET!
);
const tools = pinelabs.getTools(); // DynamicStructuredTool[]
const llm = new ChatOpenAI({ model: 'gpt-4o' });
const prompt = ChatPromptTemplate.fromMessages([
['system', 'You are a helpful payment assistant.'],
['human', '{input}'],
['placeholder', '{agent_scratchpad}'],
]);
const agent = await createOpenAIFunctionsAgent({ llm, tools, prompt });
const executor = new AgentExecutor({ agent, tools });
const result = await executor.invoke({ input: 'Create an order for Rs. 500' });
console.log(result.output);
Expected Result
{
"token": "<<Redirect Token>>",
"order_id": "v1-5757575757-aa-hU1rUd",
"redirect_url": "https://api.pluralonline.com/api/v3/checkout-bff/redirect/checkout?token=<<Redirect Token>>",
"response_code": 200,
"response_message": "Order Creation Successful."
}
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import {
PinelabsAgentToolkit,
pinelabsEnvironment,
} from '@plural_pinelabs/agent-toolkit/ai-sdk';
const pinelabs = new PinelabsAgentToolkit(
pinelabsEnvironment.UAT,
process.env.PINE_CLIENT_ID!,
process.env.PINE_CLIENT_SECRET!
);
const result = await generateText({
model: openai('gpt-4o'),
tools: pinelabs.getTools(),
prompt: 'Create an order for Rs. 500',
maxSteps: 5,
});
console.log(result.text);
Expected Result
{
"token": "<<Redirect Token>>",
"order_id": "v1-5757575757-aa-hU1rUd",
"redirect_url": "https://api.pluralonline.com/api/v3/checkout-bff/redirect/checkout?token=<<Redirect Token>>",
"response_code": 200,
"response_message": "Order Creation Successful."
}
Environment Variables
| Variable | Description |
|---|---|
PINE_CLIENT_ID | Client ID from the Pine Labs Online Developer Dashboard |
PINE_CLIENT_SECRET | Client Secret from the Pine Labs Online Developer Dashboard |
Environments
| Environment | Constant | Base URL |
|---|---|---|
| UAT | pinelabsEnvironment.UAT | https://pluraluat.v2.pinepg.in |
| Production | pinelabsEnvironment.PRODUCTION | https://api.pluralpay.in |
Authentication
Authentication is handled automatically. The toolkit uses your PINE_CLIENT_ID and PINE_CLIENT_SECRET to obtain a Bearer token via the Pine Labs Online OAuth2 token API. Tokens are cached and refreshed automatically before expiry — no manual token management required.
Resources
Updated about 4 hours ago
