Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.9 KB
Raw Blame
import { createTrigger, TriggerStrategy } from '@activepieces/pieces-framework';
import { pinchPaymentsAuth } from '../common/auth';
import { createWebhook, deleteWebhook, WebhookResponse } from '../common/client';

export const transferTrigger = createTrigger({
  auth: pinchPaymentsAuth,
  name: 'transfer',
  classification: 'READ',
  displayName: 'Transfer Created',
  description: 'Triggers when a transfer is created to settle funds to a merchant',
  aiMetadata: {
    description: 'Fires when a transfer is created to settle collected funds out to a merchant bank account in Pinch Payments. Use to react to payout/settlement events, such as reconciling deposits.',
  },
  type: TriggerStrategy.WEBHOOK,
  props: {},
  async onEnable(context) {
    const credentials = {
      username: context.auth.props.username,
      password: context.auth.props.password,
      environment: context.auth.props.environment
    };

    const webhook = await createWebhook(credentials, {
      uri: context.webhookUrl,
      webhookFormat: 'camel-case',
      eventTypes: ['transfer'],
    });

    await context.store.put<WebhookResponse>('pinch_transfer_webhook', webhook);
  },
  async onDisable(context) {
    const webhook = await context.store.get<WebhookResponse>('pinch_transfer_webhook');
    if (webhook) {
      const credentials = {
        username: context.auth.props.username,
        password: context.auth.props.password,
        environment: context.auth.props.environment
      };
      await deleteWebhook(credentials, webhook.id);
    }
  },
  async run(context) {
    return [context.payload.body];
  },
  sampleData: {
    id: 'evt_sample123456',
    type: 'transfer',
    eventDate: '2024-01-15T10:30:00Z',
    metadata: {},
    data: {
      transfer: {
        id: 'tfr_sample123456',
        amount: 50000,
        currency: 'AUD',
        status: 'completed',
      },
    },
  },
});