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.

  1. Create Pine Labs Online Merchant Account. You can register to Pine Labs Online Merchant Account here.
  2. After Creating Successfully, Login to our Dashboard and generate the client_id and client_secret.
  3. Ensure Node.js version 18 or later is installed.

Framework support

The toolkit supports the following frameworks, each accessible through a dedicated sub-path.

FrameworkImport PathDescription
OpenAI@plural_pinelabs/agent-toolkit/openaiFor Open AI Agents SDK
LangChain@plural_pinelabs/agent-toolkit/langchainFor LangChain agents
Vercel AI SDK@plural_pinelabs/agent-toolkit/ai-sdkFor 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.

ToolDescription
createOrderUse this tool to create an Order.
getOrderUse this tool to retrieve the order by order ID.
cancelOrderUse this tool to cancel the Payment against an order.
createRefundUse 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

VariableDescription
PINE_CLIENT_IDClient ID from the Pine Labs Online Developer Dashboard
PINE_CLIENT_SECRETClient Secret from the Pine Labs Online Developer Dashboard

Environments

EnvironmentConstantBase URL
UATpinelabsEnvironment.UAThttps://pluraluat.v2.pinepg.in
ProductionpinelabsEnvironment.PRODUCTIONhttps://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


Ask AI
Assistant
Order Lifecycle
Refunds
Settlements
Checkout
Dashboard
International Payments
How do I implement webhook notifications for payment status updates, and what's the recommended way to verify webhook authenticity?
How do I integrate Pine Labs payment gateway with my React Native mobile app and what are the required API credentials?
Can I customize the payment UI for card transactions, and what parameters can I pass to modify the checkout experience for my customers?
Assistant