UNPKG

@paybyrd/ai-agent-toolkit

Version:

Toolkit for building AI agents with various models

37 lines (36 loc) 1.4 kB
import { createPaymentLink, createRefund, retrieveOrder } from './functions.js'; // Helper function to check if a string is in GUID format const isGuid = (value) => { const guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; return guidRegex.test(value); }; class PaybyrdAPI { constructor(authToken, context) { this.authToken = authToken; this.isApiKey = isGuid(authToken); this.baseUrl = (context === null || context === void 0 ? void 0 : context.baseUrl) || 'https://gateway.paybyrd.com/api/v2'; this.context = context || {}; } async run(method, arg) { const authInfo = { authToken: this.authToken, isApiKey: this.isApiKey }; if (method === 'create_payment_link') { const output = JSON.stringify(await createPaymentLink(authInfo, this.baseUrl, arg)); return output; } else if (method === 'create_refund') { const output = JSON.stringify(await createRefund(authInfo, this.baseUrl, arg)); return output; } else if (method === 'retrieve_order') { const output = JSON.stringify(await retrieveOrder(authInfo, this.baseUrl, arg)); return output; } else { throw new Error('Invalid method ' + method); } } } export default PaybyrdAPI;