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

2.3 KB
Raw Blame
import { httpClient, HttpMethod } from '@activepieces/pieces-common';
import { createAction, OAuth2PropertyValue, Property } from '@activepieces/pieces-framework';
import { trueLayerCommon } from '../../common';

export const merchantAccountSetupSweeping = createAction({
  auth: trueLayerCommon.auth,
  name: 'merchant-account-setup-sweeping',
  classification: 'WRITE',
  displayName: 'Set Up or Update Sweeping',
  description: 'Set the automatic sweeping settings for a merchant account. At regular intervals, any available balance in excess of the configured `max_amount_in_minor` is withdrawn to a pre-configured IBAN.',
  audience: 'both',
  aiMetadata: { description: 'Configure or update automatic sweeping for a merchant account so balance above a threshold is periodically withdrawn to a fixed IBAN at the chosen frequency. Idempotent: it sets the full sweeping configuration for the account, so repeating with the same values leaves the same settings. To stop sweeping use Disable Sweeping; to read current settings use Get Sweeping Settings.', idempotent: true },
  props: {
    id: Property.ShortText({
      displayName: 'Merchant Account ID',
      description: 'The ID of the merchant account to set or update sweeping settings for.',
      required: true,
    }),
    max_amount_in_minor: Property.ShortText({
      displayName: 'Max Amount in Minor Units',
      description: 'The amount above which sweeping will occur, expressed in minor units (e.g., 100 means 1 GBP).',
      required: true,
    }),
    frequency: Property.ShortText({
      displayName: 'Sweeping Frequency',
      description: 'The frequency of the sweeping operation (e.g., daily, weekly).',
      required: true,
    }),
    iban: Property.ShortText({
      displayName: 'IBAN',
      description: 'The IBAN to which sweeping funds will be transferred.',
      required: true,
    }),
  },
  run: async (ctx) => {
    const response =  await httpClient.sendRequest({
      method: HttpMethod.POST,
      url: `${trueLayerCommon.baseUrl}/v3/merchant-accounts/${ctx.propsValue.id}/sweeping`,
      headers: {
        Authorization: `Bearer ${(ctx.auth as OAuth2PropertyValue).access_token}`,
      },
      body: {
        max_amount_in_minor: ctx.propsValue.max_amount_in_minor,
        frequency: ctx.propsValue.frequency,
        iban: ctx.propsValue.iban,
      },
    })

    return response.body;
  },
});