Adding additional stripe triggers and added initial stripe integration docs

This commit is contained in:
Eric Allam
2023-08-27 14:09:24 +01:00
parent de7e8c783e
commit 760f5de248
7 changed files with 801 additions and 12 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/stripe": patch
---
Adding additional Stripe triggers for account.updated, account.external_account._, customer._, person._, and charge._
+215
View File
@@ -0,0 +1,215 @@
---
title: Stripe
---
<Snippet file="integration-getting-started.mdx" />
## Installation
<CodeGroup>
```bash npm
npm install @trigger.dev/stripe@latest
```
```bash pnpm
pnpm install @trigger.dev/stripe@latest
```
```bash yarn
yarn add @trigger.dev/stripe@latest
```
</CodeGroup>
## Authentication
The Stripe integration supports secret API Keys
```ts
import { Stripe } from "@trigger.dev/stripe";
const stripe = new Stripe({
id: "stripe",
apiKey: process.env.STRIPE_API_KEY!,
});
```
## Triggers
The Stripe integration exposes a number of triggers that can be used on a job, powered by Stripe webhooks.
```ts
client.defineJob({
id: "stripe-price",
name: "Stripe Price",
version: "0.1.0",
trigger: stripe.onPriceCreated(),
run: async (payload, io, ctx) => {
console.log(ctx.event.name); // "price.created"
},
});
```
As you can see above, the job will be triggered on the `price.created` event. If you'd like to trigger a job on multiple events, you can use the aggregate version of the trigger:
```ts
client.defineJob({
id: "stripe-price",
name: "Stripe Price",
version: "0.1.0",
trigger: stripe.onPrice(),
run: async (payload, io, ctx) => {
console.log(ctx.event.name); // "price.created", "price.updated", "price.deleted"
},
});
```
"Aggregate" triggers also give you the ability to filter on specific events:
```ts
client.defineJob({
id: "stripe-price",
name: "Stripe Price",
version: "0.1.0",
trigger: stripe.onPrice({
events: ["price.created", "price.updated"],
}),
run: async (payload, io, ctx) => {
console.log(ctx.event.name); // "price.created", "price.updated"
},
});
```
Available triggers are listed below:
| Function Name | Events | Description | Aggregate Version |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | ------------------------ |
| `onCharge` | `charge.succeeded`, `charge.failed`, `charge.captured`, `charge.refunded`, `charge.updated` | Triggered on all charge events | ✔️ |
| `onChargeSucceeded` | `charge.succeeded` | Triggered on charge succeeded events | `onCharge` |
| `onChargeFailed` | `charge.failed` | Triggered on charge failed events | `onCharge` |
| `onChargeCaptured` | `charge.captured` | Triggered on charge captured events | `onCharge` |
| `onChargeRefunded` | `charge.refunded` | Triggered on charge refunded events | `onCharge` |
| `onChargeUpdated` | `charge.updated` | Triggered on charge updated events | `onCharge` |
| `onProduct` | `product.created`, `product.updated`, `product.deleted` | Triggered on all product events | ✔️ |
| `onProductCreated` | `product.created` | Triggered on product created events | `onProduct` |
| `onProductUpdated` | `product.updated` | Triggered on product updated events | `onProduct` |
| `onProductDeleted` | `product.deleted` | Triggered on product deleted events | `onProduct` |
| `onPrice` | `price.created`, `price.updated`, `price.deleted` | Triggered on all price events | ✔️ |
| `onPriceCreated` | `price.created` | Triggered on price created events | `onPrice` |
| `onPriceUpdated` | `price.updated` | Triggered on price updated events | `onPrice` |
| `onPriceDeleted` | `price.deleted` | Triggered on price deleted events | `onPrice` |
| `onCheckoutSession` | `checkout.session.completed`, `checkout.session.async_payment_succeeded`, `checkout.session.async_payment_failed`, `checkout.session.expired` | Triggered on all checkout session events | ✔️ |
| `onCheckoutSessionCompleted` | `checkout.session.completed` | Triggered on checkout session completed events | `onCheckoutSession` |
| `onCheckoutSessionExpired` | `checkout.session.expired` | Triggered on checkout session expired events | `onCheckoutSession` |
| `onCustomerSubscription` | `customer.subscription.created`, `customer.subscription.updated`, `customer.subscription.deleted`, `customer.subscription.paused`, `customer.subscription.pending_updated_applied`, `customer.subscription.pending_update_expired`, `customer.subscription.resumed` | Triggered on all customer subscription events | ✔️ |
| `onCustomerSubscriptionCreated` | `customer.subscription.created` | Triggered on customer subscription created events | `onCustomerSubscription` |
| `onCustomerSubscriptionUpdated` | `customer.subscription.updated` | Triggered on customer subscription updated events | `onCustomerSubscription` |
| `onCustomerSubscriptionDeleted` | `customer.subscription.deleted` | Triggered on customer subscription deleted events | `onCustomerSubscription` |
| `onCustomerSubscriptionPaused` | `customer.subscription.paused` | Triggered on customer subscription paused events | `onCustomerSubscription` |
| `onCustomerSubscriptionPending` | `customer.subscription.pending_updated_applied`, `customer.subscription.pending_update_expired` | Triggered on customer subscription pending events | `onCustomerSubscription` |
| `onCustomerSubscriptionResumed` | `customer.subscription.resumed` | Triggered on customer subscription resumed events | `onCustomerSubscription` |
| `onCustomer` | `customer.created`, `customer.updated`, `customer.deleted` | Triggered on all customer events | ✔️ |
| `onCustomerCreated` | `customer.created` | Triggered on customer created events | `onCustomer` |
| `onCustomerUpdated` | `customer.updated` | Triggered on customer updated events | `onCustomer` |
| `onCustomerDeleted` | `customer.deleted` | Triggered on customer deleted events | `onCustomer` |
| `onExternalAccount` | `account.external_account.created`, `account.external_account.updated`, `account.external_account.deleted` | Triggered on all external account events | ✔️ |
| `onExternalAccountCreated` | `account.external_account.created` | Triggered on external account created events | `onExternalAccount` |
| `onExternalAccountUpdated` | `account.external_account.updated` | Triggered on external account updated events | `onExternalAccount` |
| `onExternalAccountDeleted` | `account.external_account.deleted` | Triggered on external account deleted events | `onExternalAccount` |
| `onPerson` | `account.person.created`, `account.person.updated`, `account.person.deleted` | Triggered on all person events | ✔️ |
| `onPersonCreated` | `account.person.created` | Triggered on person created events | `onPerson` |
| `onPersonUpdated` | `account.person.updated` | Triggered on person updated events | `onPerson` |
| `onPersonDeleted` | `account.person.deleted` | Triggered on person deleted events | `onPerson` |
If there are any triggers missing that you'd like to see added, please [open a new GitHub Issue](https://github.com/triggerdotdev/trigger.dev/issues/new)
## Tasks
You can make reliable calls to the Stripe API inside of jobs using the exposed stripe tasks:
```ts
const stripe = new Stripe({
id: "stripe",
apiKey: process.env["STRIPE_API_KEY"]!,
});
client.defineJob({
id: "stripe-example-1",
name: "Stripe Example 1",
version: "0.1.0",
trigger: eventTrigger({
name: "stripe.example",
schema: z.object({
customerId: z.string(),
source: z.string(),
}),
}),
integrations: {
stripe,
},
run: async (payload, io, ctx) => {
await io.stripe.createCharge("create-charge", {
amount: 100,
currency: "usd",
source: payload.source,
customer: payload.customerId,
});
},
});
```
We automatically fill in the `idempotencyKey` for you, so we can gaurentee that the API call will only be executed once.
Available tasks are listed below:
| Function Name | Description |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `createCharge` | Use the Payment Intents API to initiate a new payment instead of using this method. Confirmation of the PaymentIntent creates the Charge object used to request payment, so this method is limited to legacy integrations. |
| `createCustomer` | Creates a new customer object |
| `updateCustomer` | Updates the specified customer by setting the values of the parameters passed |
| `retrieveSubscription` | Retrieves the subscription with the given ID. |
| `createCheckoutSession` | Creates a new Checkout Session object. |
If there are any tasks missing that you'd like to see added, please [open a new GitHub Issue](https://github.com/triggerdotdev/trigger.dev/issues/new)
## Using the underlying Stripe client
You can use the underlying client to do anything the [stripe-node](https://github.com/stripe/stripe-node) client supports by using the `client` property on the integration:
```ts
const stripe = new Stripe({
id: "stripe",
apiKey: process.env["STRIPE_API_KEY"]!,
});
client.defineJob({
id: "stripe-example-1",
name: "Stripe Example 1",
version: "0.1.0",
trigger: eventTrigger({
name: "stripe.example",
}),
integrations: {
stripe,
},
run: async (payload, io, ctx) => {
await io.runTask("create-price", { name: "Create Price" }, async (task) => {
return stripe.client.prices.create(
{
unit_amount: 2000,
currency: "usd",
product_data: {
name: "T-shirt",
},
},
{
idempotencyKey: task.idempotencyKey,
}
);
});
},
});
```
Make sure to pass the `idempotencyKey` to the underlying client to ensure that the API call is only executed once. This is only needed for mutating API calls.
+1
View File
@@ -193,6 +193,7 @@
"integrations/apis/openai"
]
},
"integrations/apis/stripe",
"integrations/apis/plain",
{
"group": "Resend",
+260 -1
View File
@@ -6,7 +6,17 @@ import {
pausedSubscriptionExample,
updatedSubscriptionExample,
} from "./examples";
import { OnCheckoutSession, OnCustomerSubscription, OnPriceEvent, OnProductEvent } from "./types";
import {
OnAccountEvent,
OnChargeEvent,
OnCheckoutSession,
OnCustomerEvent,
OnCustomerSubscription,
OnExternalAccountEvent,
OnPersonEvent,
OnPriceEvent,
OnProductEvent,
} from "./types";
export const onPriceCreated: EventSpecification<OnPriceEvent> = {
name: "price.created",
@@ -451,3 +461,252 @@ export const onCustomerSubscriptionUpdated: EventSpecification<OnCustomerSubscri
{ label: "Status", text: payload.status },
],
};
export const onAccountUpdated: EventSpecification<OnAccountEvent> = {
name: "account.updated",
title: "On Account Updated",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnAccountEvent,
runProperties: (payload) => [
{ label: "Account ID", text: payload.id },
...(payload.business_type ? [{ label: "Business Type", text: payload.business_type }] : []),
],
};
export const onCustomer: EventSpecification<OnCustomerEvent> = {
name: ["customer.created", "customer.deleted", "customer.updated"],
title: "On Customer Event",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnCustomerEvent,
runProperties: (payload) => [{ label: "Customer ID", text: payload.id }],
};
export const onCustomerCreated: EventSpecification<OnCustomerEvent> = {
name: "customer.created",
title: "On Customer Created",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnCustomerEvent,
runProperties: (payload) => [{ label: "Customer ID", text: payload.id }],
};
export const onCustomerDeleted: EventSpecification<OnCustomerEvent> = {
name: "customer.deleted",
title: "On Customer Deleted",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnCustomerEvent,
runProperties: (payload) => [{ label: "Customer ID", text: payload.id }],
};
export const onCustomerUpdated: EventSpecification<OnCustomerEvent> = {
name: "customer.updated",
title: "On Customer Updated",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnCustomerEvent,
runProperties: (payload) => [{ label: "Customer ID", text: payload.id }],
};
export const onCharge: EventSpecification<OnChargeEvent> = {
name: [
"charge.captured",
"charge.expired",
"charge.failed",
"charge.pending",
"charge.refunded",
"charge.succeeded",
"charge.updated",
],
title: "On Charge Event",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnChargeEvent,
runProperties: (payload) => [{ label: "Charge ID", text: payload.id }],
};
export const onChargeCaptured: EventSpecification<OnChargeEvent> = {
name: "charge.captured",
title: "On Charge Captured",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnChargeEvent,
runProperties: (payload) => [{ label: "Charge ID", text: payload.id }],
};
export const onChargeExpired: EventSpecification<OnChargeEvent> = {
name: "charge.expired",
title: "On Charge Expired",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnChargeEvent,
runProperties: (payload) => [{ label: "Charge ID", text: payload.id }],
};
export const onChargeFailed: EventSpecification<OnChargeEvent> = {
name: "charge.failed",
title: "On Charge Failed",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnChargeEvent,
runProperties: (payload) => [{ label: "Charge ID", text: payload.id }],
};
export const onChargePending: EventSpecification<OnChargeEvent> = {
name: "charge.pending",
title: "On Charge Pending",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnChargeEvent,
runProperties: (payload) => [{ label: "Charge ID", text: payload.id }],
};
export const onChargeRefunded: EventSpecification<OnChargeEvent> = {
name: "charge.refunded",
title: "On Charge Refunded",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnChargeEvent,
runProperties: (payload) => [{ label: "Charge ID", text: payload.id }],
};
export const onChargeSucceeded: EventSpecification<OnChargeEvent> = {
name: "charge.succeeded",
title: "On Charge Succeeded",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnChargeEvent,
runProperties: (payload) => [{ label: "Charge ID", text: payload.id }],
};
export const onChargeUpdated: EventSpecification<OnChargeEvent> = {
name: "charge.updated",
title: "On Charge Updated",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnChargeEvent,
runProperties: (payload) => [{ label: "Charge ID", text: payload.id }],
};
export const onExternalAccount: EventSpecification<OnExternalAccountEvent> = {
name: [
"account.external_account.created",
"account.external_account.deleted",
"account.external_account.updated",
],
title: "On External Account Event",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnExternalAccountEvent,
runProperties: (payload) => [
{ label: "Type", text: payload.object },
{ label: payload.object === "bank_account" ? "Bank Account ID" : "Card ID", text: payload.id },
],
};
export const onExternalAccountCreated: EventSpecification<OnExternalAccountEvent> = {
name: "account.external_account.created",
title: "On External Account Created",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnExternalAccountEvent,
runProperties: (payload) => [
{ label: "Type", text: payload.object },
{ label: payload.object === "bank_account" ? "Bank Account ID" : "Card ID", text: payload.id },
],
};
export const onExternalAccountDeleted: EventSpecification<OnExternalAccountEvent> = {
name: "account.external_account.deleted",
title: "On External Account Deleted",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnExternalAccountEvent,
runProperties: (payload) => [
{ label: "Type", text: payload.object },
{ label: payload.object === "bank_account" ? "Bank Account ID" : "Card ID", text: payload.id },
],
};
export const onExternalAccountUpdated: EventSpecification<OnExternalAccountEvent> = {
name: "account.external_account.updated",
title: "On External Account Updated",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnExternalAccountEvent,
runProperties: (payload) => [
{ label: "Type", text: payload.object },
{ label: payload.object === "bank_account" ? "Bank Account ID" : "Card ID", text: payload.id },
],
};
export const onPerson: EventSpecification<OnPersonEvent> = {
name: ["person.created", "person.deleted", "person.updated"],
title: "On Person Event",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnPersonEvent,
runProperties: (payload) => [
{ label: "Person ID", text: payload.id },
{ label: "Account", text: payload.account },
],
};
export const onPersonCreated: EventSpecification<OnPersonEvent> = {
name: "person.created",
title: "On Person Created",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnPersonEvent,
runProperties: (payload) => [
{ label: "Person ID", text: payload.id },
{ label: "Account", text: payload.account },
],
};
export const onPersonDeleted: EventSpecification<OnPersonEvent> = {
name: "person.deleted",
title: "On Person Deleted",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnPersonEvent,
runProperties: (payload) => [
{ label: "Person ID", text: payload.id },
{ label: "Account", text: payload.account },
],
};
export const onPersonUpdated: EventSpecification<OnPersonEvent> = {
name: "person.updated",
title: "On Person Updated",
source: "stripe.com",
icon: "stripe",
examples: [],
parsePayload: (payload) => payload as OnPersonEvent,
runProperties: (payload) => [
{ label: "Person ID", text: payload.id },
{ label: "Account", text: payload.account },
],
};
+283
View File
@@ -338,6 +338,289 @@ export class Stripe implements StripeIntegration {
params ?? { connect: false }
);
}
/**
* Occurs whenever an account status or property has changed.
*/
onAccountUpdated(params?: TriggerParams) {
return createTrigger(this.source, events.onAccountUpdated, params ?? { connect: false });
}
/**
* Occurs on customer.created, customer.deleted, and customer.updated
*
* @example
* ```ts
* stripe.onCustomer()
* ```
*
* You can detect the event name in your job by using the `ctx.event.name` property:
*
* ```ts
* client.defineJob({
* id: "stripe-example",
* name: "Stripe Example",
* version: "0.1.0",
* trigger: stripe.onCustomer(),
* run: async (payload, io, ctx) => {
* console.log(ctx.event.name); // "customer.created" or "customer.deleted"
* },
* });
* ```
*/
onCustomer(
params?: TriggerParams & {
events?: Array<"customer.created" | "customer.deleted">;
}
) {
const event = {
...events.onCustomer,
name: params?.events ?? events.onCustomer.name,
};
return createTrigger(this.source, event, params ?? { connect: false });
}
/**
* Occurs whenever a new customer is created.
*/
onCustomerCreated(params?: TriggerParams) {
return createTrigger(this.source, events.onCustomerCreated, params ?? { connect: false });
}
/**
* Occurs whenever a new customer is deleted.
*/
onCustomerDeleted(params?: TriggerParams) {
return createTrigger(this.source, events.onCustomerDeleted, params ?? { connect: false });
}
/**
* Occurs whenever a new customer is updated.
*/
onCustomerUpdated(params?: TriggerParams) {
return createTrigger(this.source, events.onCustomerUpdated, params ?? { connect: false });
}
/**
* Occurs on any charge.* event. Accepts an optional array of events to filter on. By default it will listen to all charge.* events.
*
* @example
* ```ts
* stripe.onCharge({ events: ["charge.refunded", "charge.succeeded"] })
* ```
*
* You can detect the event name in your job by using the `ctx.event.name` property:
*
* ```ts
* client.defineJob({
* id: "stripe-example",
* name: "Stripe Example",
* version: "0.1.0",
* trigger: stripe.onCharge({ events: ["charge.refunded", "charge.succeeded"] }),
* run: async (payload, io, ctx) => {
* console.log(ctx.event.name); // "charge.refunded" or "charge.succeeded"
* },
* });
* ```
*/
onCharge(
params?: TriggerParams & {
events?: Array<
| "charge.captured"
| "charge.expired"
| "charge.failed"
| "charge.pending"
| "charge.refunded"
| "charge.succeeded"
| "charge.updated"
>;
}
) {
const event = {
...events.onCharge,
name: params?.events ?? events.onCharge.name,
};
return createTrigger(this.source, event, params ?? { connect: false });
}
/**
* Occurs whenever a previously uncaptured charge is captured
*/
onChargeCaptured(params?: TriggerParams) {
return createTrigger(this.source, events.onChargeCaptured, params ?? { connect: false });
}
/**
* Occurs whenever an uncaptured charge expires.
*/
onChargeExpired(params?: TriggerParams) {
return createTrigger(this.source, events.onChargeExpired, params ?? { connect: false });
}
/**
* Occurs whenever a failed charge attempt occurs
*/
onChargeFailed(params?: TriggerParams) {
return createTrigger(this.source, events.onChargeFailed, params ?? { connect: false });
}
/**
* Occurs whenever a pending charge is created
*/
onChargePending(params?: TriggerParams) {
return createTrigger(this.source, events.onChargePending, params ?? { connect: false });
}
/**
* Occurs whenever a charge is refunded, including partial refunds
*/
onChargeRefunded(params?: TriggerParams) {
return createTrigger(this.source, events.onChargeRefunded, params ?? { connect: false });
}
/**
* Occurs whenever a charge is successful
*/
onChargeSucceeded(params?: TriggerParams) {
return createTrigger(this.source, events.onChargeSucceeded, params ?? { connect: false });
}
/**
* Occurs whenever a charge description or metadata is updated, or upon an asynchronous capture
*/
onChargeUpdated(params?: TriggerParams) {
return createTrigger(this.source, events.onChargeUpdated, params ?? { connect: false });
}
/**
* Occurs on any account.external_account.* event. Accepts an optional array of events to filter on. By default it will listen to all charge.* events.
*
* @example
* ```ts
* stripe.onExternalAccount({ events: ["account.external_account.created", "account.external_account.deleted"] })
* ```
*
* You can detect the event name in your job by using the `ctx.event.name` property:
*
* ```ts
* client.defineJob({
* id: "stripe-example",
* name: "Stripe Example",
* version: "0.1.0",
* trigger: stripe.onExternalAccount({ events: ["account.external_account.created", "account.external_account.deleted"] }),
* run: async (payload, io, ctx) => {
* console.log(ctx.event.name); // "account.external_account.created" or "account.external_account.deleted"
* },
* });
* ```
*/
onExternalAccount(
params?: TriggerParams & {
events?: Array<
| "account.external_account.created"
| "account.external_account.deleted"
| "account.external_account.updated"
>;
}
) {
const event = {
...events.onExternalAccount,
name: params?.events ?? events.onExternalAccount.name,
};
return createTrigger(this.source, event, params ?? { connect: false });
}
/**
* Occurs whenever an external account is created.
* */
onExternalAccountCreated(params?: TriggerParams) {
return createTrigger(
this.source,
events.onExternalAccountCreated,
params ?? { connect: false }
);
}
/**
* Occurs whenever an external account is deleted.
* */
onExternalAccountDeleted(params?: TriggerParams) {
return createTrigger(
this.source,
events.onExternalAccountDeleted,
params ?? { connect: false }
);
}
/**
* Occurs whenever an external account is updated.
* */
onExternalAccountUpdated(params?: TriggerParams) {
return createTrigger(
this.source,
events.onExternalAccountUpdated,
params ?? { connect: false }
);
}
/**
* Occurs on any person.* event. Accepts an optional array of events to filter on. By default it will listen to all person.* events.
*
* @example
* ```ts
* stripe.onPerson({ events: ["person.created", "person.deleted"] })
* ```
*
* You can detect the event name in your job by using the `ctx.event.name` property:
*
* ```ts
* client.defineJob({
* id: "stripe-example",
* name: "Stripe Example",
* version: "0.1.0",
* trigger: stripe.onPerson({ events: ["person.created", "person.deleted"] }),
* run: async (payload, io, ctx) => {
* console.log(ctx.event.name); // "person.created" or "person.deleted"
* },
* });
* ```
*/
onPerson(
params?: TriggerParams & {
events?: Array<"person.created" | "person.deleted" | "person.updated">;
}
) {
const event = {
...events.onPerson,
name: params?.events ?? events.onPerson.name,
};
return createTrigger(this.source, event, params ?? { connect: false });
}
/**
* Occurs whenever a person associated with an account is created.
* */
onPersonCreated(params?: TriggerParams) {
return createTrigger(this.source, events.onPersonCreated, params ?? { connect: false });
}
/**
* Occurs whenever a person associated with an account is deleted.
* */
onPersonDeleted(params?: TriggerParams) {
return createTrigger(this.source, events.onPersonDeleted, params ?? { connect: false });
}
/**
* Occurs whenever a person associated with an account is updated.
* */
onPersonUpdated(params?: TriggerParams) {
return createTrigger(this.source, events.onPersonUpdated, params ?? { connect: false });
}
}
export type TriggerParams = {
+26 -11
View File
@@ -1,26 +1,30 @@
import { AuthenticatedTask } from "@trigger.dev/sdk";
import type {
StripeSDK,
CreateChargeParams,
CreateChargeResponse,
CreateCustomerResponse,
CreateCustomerParams,
UpdateCustomerParams,
UpdateCustomerResponse,
RetrieveSubscriptionParams,
RetrieveSubscriptionResponse,
CreateCheckoutSessionParams,
CreateCheckoutSessionResponse,
CreateCustomerParams,
CreateCustomerResponse,
CreateWebhookParams,
CreateWebhookResponse,
ListWebhooksParams,
ListWebhooksResponse,
RetrieveSubscriptionParams,
RetrieveSubscriptionResponse,
StripeSDK,
UpdateCustomerParams,
UpdateCustomerResponse,
UpdateWebhookParams,
UpdateWebhookResponse,
ListWebhooksResponse,
ListWebhooksParams,
} from "./types";
import { AuthenticatedTask } from "@trigger.dev/sdk";
import { Stripe } from "stripe";
import { omit } from "./utils";
/**
* Use the [Payment Intents API](https://stripe.com/docs/api/payment_intents) to initiate a new payment instead
* of using this method. Confirmation of the PaymentIntent creates the Charge
* object used to request payment, so this method is limited to legacy integrations.
*/
export const createCharge: AuthenticatedTask<StripeSDK, CreateChargeParams, CreateChargeResponse> =
{
run: async (params, client, task) => {
@@ -124,6 +128,11 @@ export const createCustomer: AuthenticatedTask<
},
};
/**
* Updates the specified customer by setting the values of the parameters passed. Any parameters not provided will be left unchanged. For example, if you pass the source parameter, that becomes the customer's active source (e.g., a card) to be used for all charges in the future. When you update a customer to a new valid card source by passing the source parameter: for each of the customer's current subscriptions, if the subscription bills automatically and is in the past_due state, then the latest open invoice for the subscription with automatic collection enabled will be retried. This retry will not count as an automatic retry, and will not affect the next regularly scheduled payment for the invoice. Changing the default_source for a customer will not trigger this behavior.
*
* This request accepts mostly the same arguments as the customer creation call.
*/
export const updateCustomer: AuthenticatedTask<
StripeSDK,
UpdateCustomerParams,
@@ -171,6 +180,9 @@ export const updateCustomer: AuthenticatedTask<
},
};
/**
* Retrieves the subscription with the given ID.
*/
export const retrieveSubscription: AuthenticatedTask<
StripeSDK,
RetrieveSubscriptionParams,
@@ -206,6 +218,9 @@ export const retrieveSubscription: AuthenticatedTask<
},
};
/**
* Creates a Session object.
*/
export const createCheckoutSession: AuthenticatedTask<
StripeSDK,
CreateCheckoutSessionParams,
+11
View File
@@ -70,3 +70,14 @@ export type OnCheckoutSession =
export type OnCustomerSubscription =
ExtractWebhookPayload<Stripe.DiscriminatedEvent.CustomerSubscriptionEvent>;
export type OnAccountEvent = ExtractWebhookPayload<Stripe.DiscriminatedEvent.AccountEvent>;
export type OnCustomerEvent = ExtractWebhookPayload<Stripe.DiscriminatedEvent.CustomerEvent>;
export type OnChargeEvent = ExtractWebhookPayload<Stripe.DiscriminatedEvent.ChargeEvent>;
export type OnExternalAccountEvent =
ExtractWebhookPayload<Stripe.DiscriminatedEvent.AccountExternalAccountEvent>;
export type OnPersonEvent = ExtractWebhookPayload<Stripe.DiscriminatedEvent.PersonEvent>;