Skip to content

Commit

Permalink
Feature/Add stripe toolkit (#3522)
Browse files Browse the repository at this point in the history
add stripe toolkit
  • Loading branch information
HenryHengZJ authored Nov 15, 2024
1 parent eaec34f commit 38ddbd8
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/components/credentials/StripeApi.credential.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { INodeParams, INodeCredential } from '../src/Interface'

class StripeApi implements INodeCredential {
label: string
name: string
version: number
description: string
inputs: INodeParams[]

constructor() {
this.label = 'Stripe API'
this.name = 'stripeApi'
this.version = 1.0
this.description =
'Refer to <a target="_blank" href="https://support.airtable.com/docs/creating-and-using-api-keys-and-access-tokens">official guide</a> on how to get accessToken on Airtable'
this.inputs = [
{
label: 'Stripe API Token',
name: 'stripeApiToken',
type: 'password',
placeholder: '<STRIPE_API_TOKEN>'
}
]
}
}

module.exports = { credClass: StripeApi }
271 changes: 271 additions & 0 deletions packages/components/nodes/tools/StripeTool/StripeTool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
import { StripeAgentToolkit } from '@stripe/agent-toolkit/langchain'
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { convertMultiOptionsToStringArray, getCredentialData, getCredentialParam } from '../../../src/utils'

class StripeTool_Tools implements INode {
label: string
name: string
version: number
description: string
type: string
icon: string
category: string
baseClasses: string[]
credential: INodeParams
inputs: INodeParams[]
badge?: string

constructor() {
this.label = 'StripeAgentTool'
this.name = 'stripeAgentTool'
this.version = 1.0
this.type = 'stripeAgentTool'
this.icon = 'stripe.png'
this.category = 'Tools'
this.description = 'Use Stripe Agent function calling for financial transactions'
this.badge = 'BETA'
this.inputs = [
{
label: 'Payment Links',
name: 'paymentLinks',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Products',
name: 'products',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Prices',
name: 'prices',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Balance',
name: 'balance',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Invoice Items',
name: 'invoiceItems',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Invoices',
name: 'invoices',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
},
{
label: 'Customers',
name: 'customers',
type: 'multiOptions',
options: [
{
label: 'Create',
name: 'create'
},
{
label: 'Update',
name: 'update'
},
{
label: 'Read',
name: 'read'
}
],
optional: true,
additionalParams: true
}
]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['stripeApi']
}
this.baseClasses = [this.type, 'Tool']
}

async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const stripeApiToken = getCredentialParam('stripeApiToken', credentialData, nodeData)

const _paymentLinks = nodeData.inputs?.paymentLinks as string
let paymentLinks: string[] = convertMultiOptionsToStringArray(_paymentLinks)

const _products = nodeData.inputs?.products as string
let products: string[] = convertMultiOptionsToStringArray(_products)

const _prices = nodeData.inputs?.prices as string
let prices: string[] = convertMultiOptionsToStringArray(_prices)

const _balance = nodeData.inputs?.balance as string
let balance: string[] = convertMultiOptionsToStringArray(_balance)

const _invoiceItems = nodeData.inputs?.invoiceItems as string
let invoiceItems: string[] = convertMultiOptionsToStringArray(_invoiceItems)

const _invoices = nodeData.inputs?.invoices as string
let invoices: string[] = convertMultiOptionsToStringArray(_invoices)

const _customers = nodeData.inputs?.customers as string
let customers: string[] = convertMultiOptionsToStringArray(_customers)

const actionObj: any = {}
if (paymentLinks.length > 0) {
actionObj['paymentLinks'] = {}
if (paymentLinks.includes('create')) actionObj['paymentLinks'].create = true
if (paymentLinks.includes('read')) actionObj['paymentLinks'].read = true
if (paymentLinks.includes('update')) actionObj['paymentLinks'].update = true
}
if (products.length > 0) {
actionObj['products'] = {}
if (products.includes('create')) actionObj['products'].create = true
if (products.includes('read')) actionObj['products'].read = true
if (products.includes('update')) actionObj['products'].update = true
}
if (prices.length > 0) {
actionObj['prices'] = {}
if (prices.includes('create')) actionObj['prices'].create = true
if (prices.includes('read')) actionObj['prices'].read = true
if (prices.includes('update')) actionObj['prices'].update = true
}
if (balance.length > 0) {
actionObj['balance'] = {}
if (balance.includes('create')) actionObj['balance'].create = true
if (balance.includes('read')) actionObj['balance'].read = true
if (balance.includes('update')) actionObj['balance'].update = true
}
if (invoiceItems.length > 0) {
actionObj['invoiceItems'] = {}
if (invoiceItems.includes('create')) actionObj['invoiceItems'].create = true
if (invoiceItems.includes('read')) actionObj['invoiceItems'].read = true
if (invoiceItems.includes('update')) actionObj['invoiceItems'].update = true
}
if (invoices.length > 0) {
actionObj['invoices'] = {}
if (invoices.includes('create')) actionObj['invoices'].create = true
if (invoices.includes('read')) actionObj['invoices'].read = true
if (invoices.includes('update')) actionObj['invoices'].update = true
}
if (customers.length > 0) {
actionObj['customers'] = {}
if (customers.includes('create')) actionObj['customers'].create = true
if (customers.includes('read')) actionObj['customers'].read = true
if (customers.includes('update')) actionObj['customers'].update = true
}

const stripeAgentToolkit = new StripeAgentToolkit({
secretKey: stripeApiToken,
configuration: {
actions: actionObj
}
})

const stripeTool = stripeAgentToolkit.getTools()
for (const tool of stripeTool) {
// convert tool name into small letter, and space to underscore, ex: Create Payment Link => create_payment_link
tool.name = tool.name.split(' ').join('_').toLowerCase()
}

return stripeTool
}
}

module.exports = { nodeClass: StripeTool_Tools }
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@opensearch-project/opensearch": "^1.2.0",
"@pinecone-database/pinecone": "2.2.2",
"@qdrant/js-client-rest": "^1.9.0",
"@stripe/agent-toolkit": "^0.1.20",
"@supabase/supabase-js": "^2.29.0",
"@types/js-yaml": "^4.0.5",
"@types/jsdom": "^21.1.1",
Expand All @@ -69,9 +70,9 @@
"assemblyai": "^4.2.2",
"axios": "1.6.2",
"cheerio": "^1.0.0-rc.12",
"couchbase": "4.4.1",
"chromadb": "^1.5.11",
"cohere-ai": "^7.7.5",
"couchbase": "4.4.1",
"crypto-js": "^4.1.1",
"css-what": "^6.1.0",
"d3-dsv": "2",
Expand Down
26 changes: 26 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 38ddbd8

Please sign in to comment.