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.5 KB
Raw Blame
import { TriggerStrategy, createTrigger } from '@activepieces/pieces-framework';
import { lemonSqueezyAuth } from '../common/auth';
import { createStoreDropdownProperty, disableWebhook, enableWebhook, handleWebhook } from '../common/webhook';
import { webhookSchemas } from '../common/output-schemas';

export const subscriptionUpdatedTrigger = createTrigger({
  auth: lemonSqueezyAuth,
  name: 'subscription_updated',
  classification: 'READ',
  displayName: 'Subscription Updated',
  description: 'Triggers when a subscription\'s data is changed or updated',
  aiMetadata: {
    description: 'Fires whenever a subscription in Lemon Squeezy changes (status change, plan/variant swap, renewal, or other attribute update). Represents the subscription in its updated state; this is a broad event covering many kinds of change.',
  },
  type: TriggerStrategy.WEBHOOK,
  props: {
    store_id: createStoreDropdownProperty()
  },
  async onEnable(context) {
    await enableWebhook({
      auth: context.auth,
      store: context.store,
      storeId: context.propsValue.store_id,
      webhookUrl: context.webhookUrl,
      eventName: 'subscription_updated',
    });
  },
  async onDisable(context) {
    await disableWebhook({ auth: context.auth, store: context.store, eventName: 'subscription_updated' });
  },
  async run(context) {
    return handleWebhook({ payload: context.payload, store: context.store, eventName: 'subscription_updated' });
  },
  outputSchema: webhookSchemas.subscription,
  sampleData: {
    meta: {
      event_name: 'subscription_updated',
      custom_data: {
        user_id: 123
      }
    },
    data: {
      type: 'subscriptions',
      id: '1',
      attributes: {
        store_id: 1,
        customer_id: 1,
        order_id: 1,
        order_item_id: 1,
        product_id: 1,
        variant_id: 1,
        product_name: 'Lemonade - 2 years',
        variant_name: 'Default',
        user_name: 'John Doe',
        user_email: '[email protected]',
        currency: 'USD',
        currency_rate: '1.0000',
        status: 'active',
        status_formatted: 'Active',
        trial_ends_at: null,
        ends_at: '2023-08-17T09:45:53.000000Z',
        created_at: '2021-08-17T09:45:53.000000Z',
        updated_at: '2021-08-17T10:45:53.000000Z',
        test_mode: false,
        pause_mode: null,
        cancelled_at: null,
        billing_anchor: 17,
        billing_anchor_type: 'day_of_month',
        renews_at: '2021-09-17T09:45:53.000000Z'
      }
    }
  }
});