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.8 KB
Raw Blame
import { httpClient, HttpMethod } from '@activepieces/pieces-common';
import { createAction, OAuth2PropertyValue, Property } from '@activepieces/pieces-framework';
import { trueLayerCommon } from '../../common';

export const confirmMandateFunds = createAction({
  auth: trueLayerCommon.auth,
  name: 'confirm-mandate-funds',
  classification: 'READ',
  displayName: 'Confirm Mandate Funds',
  description: 'Confirm that the PSU has the given funds. This API can be called using the mandate_token associated with the mandate or using a backend bearer token.',
  audience: 'both',
  aiMetadata: { description: 'Check whether the payment service user behind a mandate has sufficient funds for a given amount and currency, identified by the mandate ID. This is a read-only funds availability check that does not move money and is safe to repeat.', idempotent: true },
  props: {
    id: Property.ShortText({
      displayName: 'Mandate ID',
      description: 'ID of the Mandate to be confirmed.',
      required: true,
    }),
    amount_in_minor: Property.ShortText({
      displayName: 'Amount in Minor Units',
      description: 'A "cent" value representing the amount. For example, 100 == 1 GBP.',
      required: true,
    }),
    currency: Property.ShortText({
      displayName: 'Currency',
      description: 'Currency code (e.g., GBP, EUR).',
      required: true,
    }),
  },
  run: async (ctx) => {
    const response = await httpClient.sendRequest({
      method: HttpMethod.GET,
      url: `${trueLayerCommon.baseUrl}/v3/mandates/${ctx.propsValue.id}/funds`,
      headers: {
        Authorization: `Bearer ${(ctx.auth as OAuth2PropertyValue).access_token}`,
      },
      queryParams: {
        amount_in_minor: ctx.propsValue.amount_in_minor,
        currency: ctx.propsValue.currency,
      },
    })

    return response.body;
  },
});