6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
133 lines
4.0 KiB
TypeScript
133 lines
4.0 KiB
TypeScript
import { generateId } from '@sim/utils/id'
|
|
import { ErrorExtractorId } from '@/tools/error-extractors'
|
|
import type { CreatePaymentParams, PaymentResponse } from '@/tools/square/types'
|
|
import {
|
|
PAYMENT_METADATA_OUTPUT_PROPERTIES,
|
|
PAYMENT_OUTPUT,
|
|
SQUARE_BASE_URL,
|
|
squareHeaders,
|
|
} from '@/tools/square/types'
|
|
import type { ToolConfig } from '@/tools/types'
|
|
|
|
export const squareCreatePaymentTool: ToolConfig<CreatePaymentParams, PaymentResponse> = {
|
|
id: 'square_create_payment',
|
|
name: 'Square Create Payment',
|
|
description: 'Take a payment using a payment source such as a card nonce or a card on file',
|
|
version: '1.0.0',
|
|
errorExtractor: ErrorExtractorId.SQUARE_ERRORS,
|
|
|
|
params: {
|
|
apiKey: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-only',
|
|
description: 'Square access token (personal access token)',
|
|
},
|
|
sourceId: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description: 'ID of the payment source (card nonce, card-on-file ID, or wallet token)',
|
|
},
|
|
amount: {
|
|
type: 'number',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description: 'Amount in the smallest currency denomination (e.g. 1000 = $10.00)',
|
|
},
|
|
currency: {
|
|
type: 'string',
|
|
required: true,
|
|
visibility: 'user-or-llm',
|
|
description: 'Three-letter ISO 4217 currency code (e.g. USD)',
|
|
},
|
|
idempotencyKey: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-only',
|
|
description: 'Unique key to make the request idempotent (auto-generated if omitted)',
|
|
},
|
|
customerId: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'ID of the customer associated with the payment',
|
|
},
|
|
locationId: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'ID of the location where the payment is taken (defaults to the main location)',
|
|
},
|
|
orderId: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'ID of the order associated with the payment',
|
|
},
|
|
referenceId: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Optional external reference for the payment',
|
|
},
|
|
note: {
|
|
type: 'string',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Optional note attached to the payment',
|
|
},
|
|
autocomplete: {
|
|
type: 'boolean',
|
|
required: false,
|
|
visibility: 'user-or-llm',
|
|
description: 'Whether to immediately capture the payment (defaults to true)',
|
|
},
|
|
},
|
|
|
|
request: {
|
|
url: () => `${SQUARE_BASE_URL}/v2/payments`,
|
|
method: 'POST',
|
|
headers: (params) => squareHeaders(params.apiKey),
|
|
body: (params) => {
|
|
const body: Record<string, unknown> = {
|
|
idempotency_key: params.idempotencyKey || generateId(),
|
|
source_id: params.sourceId,
|
|
amount_money: { amount: params.amount, currency: params.currency },
|
|
}
|
|
if (params.customerId) body.customer_id = params.customerId
|
|
if (params.locationId) body.location_id = params.locationId
|
|
if (params.orderId) body.order_id = params.orderId
|
|
if (params.referenceId) body.reference_id = params.referenceId
|
|
if (params.note) body.note = params.note
|
|
if (params.autocomplete !== undefined) body.autocomplete = params.autocomplete
|
|
return body
|
|
},
|
|
},
|
|
|
|
transformResponse: async (response) => {
|
|
const data = await response.json()
|
|
const payment = data.payment ?? {}
|
|
return {
|
|
success: true,
|
|
output: {
|
|
payment,
|
|
metadata: {
|
|
id: payment.id,
|
|
status: payment.status ?? null,
|
|
order_id: payment.order_id ?? null,
|
|
},
|
|
},
|
|
}
|
|
},
|
|
|
|
outputs: {
|
|
payment: { ...PAYMENT_OUTPUT, description: 'The created payment object' },
|
|
metadata: {
|
|
type: 'json',
|
|
description: 'Payment summary metadata',
|
|
properties: PAYMENT_METADATA_OUTPUT_PROPERTIES,
|
|
},
|
|
},
|
|
}
|