Issue #747: Add Stripe invoice triggers
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/stripe": patch
|
||||
---
|
||||
|
||||
Added invoice and invoice item webhook triggers
|
||||
@@ -140,6 +140,21 @@ Available triggers are listed below:
|
||||
| `onPayoutPaid` | [Payout](https://stripe.com/docs/api/events/types#payout_object) | `payout.paid` | `onPayout` |
|
||||
| `onPayoutFailed` | [Payout](https://stripe.com/docs/api/events/types#payout_object) | `payout.failed` | `onPayout` |
|
||||
| `onPayoutReconciliationCompleted` | [Payout](https://stripe.com/docs/api/events/types#payout_object) | `payout.reconciliation_completed` | `onPayout` |
|
||||
| `onInvoice` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.created`, `payout.updated`, `payout.canceled`, `payout.paid`, `payout.failed`, `payout.reconciliation_completed` | ✔️ |
|
||||
| `onInvoiceCreated` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.created` | `onInvoice` |
|
||||
| `onInvoiceFinalized` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.updated` | `onInvoice` |
|
||||
| `onInvoiceFinalizationFailed` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.canceled` | `onInvoice` |
|
||||
| `onInvoiceDeleted` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.paid` | `onInvoice` |
|
||||
| `onInvoiceMarkedUncollectible` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.failed` | `onInvoice` |
|
||||
| `onInvoicePaid` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.reconciliation_completed` | `onInvoice` |
|
||||
| `onInvoicePaymentActionRequired` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.reconciliation_completed` | `onInvoice` |
|
||||
| `onInvoicePaymentFailed` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.reconciliation_completed` | `onInvoice` |
|
||||
| `onInvoicePaymentSucceeded` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.reconciliation_completed` | `onInvoice` |
|
||||
| `onInvoiceSent` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.reconciliation_completed` | `onInvoice` |
|
||||
| `onInvoiceUpcoming` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.reconciliation_completed` | `onInvoice` |
|
||||
| `onInvoiceVoided` | [Invoice](https://stripe.com/docs/api/invoices/object) | `payout.reconciliation_completed` | `onInvoice` |
|
||||
| `onInvoiceItemCreated` | [InvoiceItem](https://stripe.com/docs/api/invoiceitems/object) | `payout.reconciliation_completed` | N/A |
|
||||
| `onInvoiceItemDeleted` | [InvoiceItem](https://stripe.com/docs/api/invoiceitems/object) | `payout.reconciliation_completed` | N/A |
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ import {
|
||||
OnCustomerEvent,
|
||||
OnCustomerSubscription,
|
||||
OnExternalAccountEvent,
|
||||
OnInvoiceEvent,
|
||||
OnInvoiceItemEvent,
|
||||
OnPaymentIntentEvent,
|
||||
OnPayoutEvent,
|
||||
OnPersonEvent,
|
||||
@@ -932,3 +934,660 @@ export const onPayoutUpdated: EventSpecification<OnPayoutEvent> = {
|
||||
{ label: "Amount", text: `${payload.amount} ${payload.currency}` },
|
||||
],
|
||||
};
|
||||
|
||||
export const onInvoice: EventSpecification<OnInvoiceEvent> = {
|
||||
name: [
|
||||
"invoice.created",
|
||||
"invoice.finalized",
|
||||
"invoice.finalization_failed",
|
||||
"invoice.deleted",
|
||||
"invoice.marked_uncollectible",
|
||||
"invoice.paid",
|
||||
"invoice.payment_action_required",
|
||||
"invoice.payment_failed",
|
||||
"invoice.payment_succeeded",
|
||||
"invoice.sent",
|
||||
"invoice.upcoming",
|
||||
"invoice.voided",
|
||||
],
|
||||
title: "On Invoice Event",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
examples: [],
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceCreated: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.created",
|
||||
title: "On Invoice Created",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
examples: [
|
||||
{
|
||||
id: "invoice.created",
|
||||
name: "Invoice Created",
|
||||
icon: "stripe",
|
||||
payload: {
|
||||
id: "in_1OIBngI0XSgju2urLPfyF8yN",
|
||||
object: "invoice",
|
||||
account_country: "GB",
|
||||
account_name: "Trigger.dev",
|
||||
account_tax_ids: null,
|
||||
amount_due: 2000,
|
||||
amount_paid: 0,
|
||||
amount_remaining: 2000,
|
||||
amount_shipping: 0,
|
||||
application: null,
|
||||
application_fee_amount: null,
|
||||
attempt_count: 0,
|
||||
attempted: false,
|
||||
auto_advance: false,
|
||||
automatic_tax: {
|
||||
enabled: false,
|
||||
status: null,
|
||||
},
|
||||
billing_reason: "manual",
|
||||
charge: null,
|
||||
collection_method: "charge_automatically",
|
||||
created: 1701356712,
|
||||
currency: "usd",
|
||||
custom_fields: null,
|
||||
customer: "cus_P6Oaqh5b0bx59U",
|
||||
customer_address: null,
|
||||
customer_email: null,
|
||||
customer_name: null,
|
||||
customer_phone: null,
|
||||
customer_shipping: null,
|
||||
customer_tax_exempt: "none",
|
||||
customer_tax_ids: [],
|
||||
default_payment_method: null,
|
||||
default_source: null,
|
||||
default_tax_rates: [],
|
||||
description: "(created by Stripe CLI)",
|
||||
discount: null,
|
||||
discounts: [],
|
||||
due_date: null,
|
||||
effective_at: null,
|
||||
ending_balance: null,
|
||||
footer: null,
|
||||
from_invoice: null,
|
||||
hosted_invoice_url: null,
|
||||
invoice_pdf: null,
|
||||
last_finalization_error: null,
|
||||
latest_revision: null,
|
||||
lines: {
|
||||
object: "list",
|
||||
data: [
|
||||
{
|
||||
id: "il_1OIBngI0XSgju2urOIBrJ3GK",
|
||||
object: "line_item",
|
||||
amount: 2000,
|
||||
amount_excluding_tax: 2000,
|
||||
currency: "usd",
|
||||
description: "(created by Stripe CLI)",
|
||||
discount_amounts: [],
|
||||
discountable: true,
|
||||
discounts: [],
|
||||
invoice_item: "ii_1OIBngI0XSgju2urw3wl9FUf",
|
||||
livemode: false,
|
||||
metadata: {},
|
||||
period: {
|
||||
end: 1701356712,
|
||||
start: 1701356712,
|
||||
},
|
||||
plan: null,
|
||||
price: {
|
||||
id: "price_1OIBngI0XSgju2urxiG1M9fT",
|
||||
object: "price",
|
||||
active: false,
|
||||
billing_scheme: "per_unit",
|
||||
created: 1701356712,
|
||||
currency: "usd",
|
||||
custom_unit_amount: null,
|
||||
livemode: false,
|
||||
lookup_key: null,
|
||||
metadata: {},
|
||||
nickname: null,
|
||||
product: "prod_P6Oatqn6T5L2Ey",
|
||||
recurring: null,
|
||||
tax_behavior: "unspecified",
|
||||
tiers_mode: null,
|
||||
transform_quantity: null,
|
||||
type: "one_time",
|
||||
unit_amount: 2000,
|
||||
unit_amount_decimal: "2000",
|
||||
},
|
||||
proration: false,
|
||||
proration_details: {
|
||||
credited_items: null,
|
||||
},
|
||||
quantity: 1,
|
||||
subscription: null,
|
||||
tax_amounts: [],
|
||||
tax_rates: [],
|
||||
type: "invoiceitem",
|
||||
unit_amount_excluding_tax: "2000",
|
||||
},
|
||||
],
|
||||
has_more: false,
|
||||
total_count: 1,
|
||||
url: "/v1/invoices/in_1OIBngI0XSgju2urLPfyF8yN/lines",
|
||||
},
|
||||
livemode: false,
|
||||
metadata: {},
|
||||
next_payment_attempt: null,
|
||||
number: null,
|
||||
on_behalf_of: null,
|
||||
paid: false,
|
||||
paid_out_of_band: false,
|
||||
payment_intent: null,
|
||||
payment_settings: {
|
||||
default_mandate: null,
|
||||
payment_method_options: null,
|
||||
payment_method_types: null,
|
||||
},
|
||||
period_end: 1701356712,
|
||||
period_start: 1701356712,
|
||||
post_payment_credit_notes_amount: 0,
|
||||
pre_payment_credit_notes_amount: 0,
|
||||
quote: null,
|
||||
receipt_number: null,
|
||||
rendering: {
|
||||
amount_tax_display: null,
|
||||
pdf: {
|
||||
page_size: "auto",
|
||||
},
|
||||
},
|
||||
rendering_options: null,
|
||||
shipping_cost: null,
|
||||
shipping_details: null,
|
||||
starting_balance: 0,
|
||||
statement_descriptor: null,
|
||||
status: "draft",
|
||||
status_transitions: {
|
||||
finalized_at: null,
|
||||
marked_uncollectible_at: null,
|
||||
paid_at: null,
|
||||
voided_at: null,
|
||||
},
|
||||
subscription: null,
|
||||
subscription_details: {
|
||||
metadata: null,
|
||||
},
|
||||
subtotal: 2000,
|
||||
subtotal_excluding_tax: 2000,
|
||||
tax: null,
|
||||
test_clock: null,
|
||||
total: 2000,
|
||||
total_discount_amounts: [],
|
||||
total_excluding_tax: 2000,
|
||||
total_tax_amounts: [],
|
||||
transfer_data: null,
|
||||
webhooks_delivered_at: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceFinalized: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.finalized",
|
||||
title: "On Invoice Finalized",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
examples: [
|
||||
{
|
||||
id: "invoice.finalized",
|
||||
name: "Invoice Finalized",
|
||||
icon: "stripe",
|
||||
payload: {
|
||||
id: "in_1OIBqbI0XSgju2urMmXEFbj3",
|
||||
object: "invoice",
|
||||
account_country: "GB",
|
||||
account_name: "Trigger.dev",
|
||||
account_tax_ids: null,
|
||||
amount_due: 2000,
|
||||
amount_paid: 0,
|
||||
amount_remaining: 2000,
|
||||
amount_shipping: 0,
|
||||
application: null,
|
||||
application_fee_amount: null,
|
||||
attempt_count: 0,
|
||||
attempted: false,
|
||||
auto_advance: false,
|
||||
automatic_tax: {
|
||||
enabled: false,
|
||||
status: null,
|
||||
},
|
||||
billing_reason: "manual",
|
||||
charge: null,
|
||||
collection_method: "charge_automatically",
|
||||
created: 1701356892,
|
||||
currency: "usd",
|
||||
custom_fields: null,
|
||||
customer: "cus_P6Od2vu85eNeMI",
|
||||
customer_address: null,
|
||||
customer_email: null,
|
||||
customer_name: null,
|
||||
customer_phone: null,
|
||||
customer_shipping: null,
|
||||
customer_tax_exempt: "none",
|
||||
customer_tax_ids: [],
|
||||
default_payment_method: null,
|
||||
default_source: null,
|
||||
default_tax_rates: [],
|
||||
description: "(created by Stripe CLI)",
|
||||
discount: null,
|
||||
discounts: [],
|
||||
due_date: null,
|
||||
effective_at: 1701356893,
|
||||
ending_balance: 0,
|
||||
footer: null,
|
||||
from_invoice: null,
|
||||
hosted_invoice_url:
|
||||
"https://invoice.stripe.com/i/acct_1MRmG4I0XSgju2ur/test_YWNjdF8xTVJtRzRJMFhTZ2p1MnVyLF9QNk9kYmlDaVZyek53UXRJbUhEdmNxa1pPSUtKbmdPLDkxODk3Njk00200Ibh1G5H7?s=ap",
|
||||
invoice_pdf:
|
||||
"https://pay.stripe.com/invoice/acct_1MRmG4I0XSgju2ur/test_YWNjdF8xTVJtRzRJMFhTZ2p1MnVyLF9QNk9kYmlDaVZyek53UXRJbUhEdmNxa1pPSUtKbmdPLDkxODk3Njk00200Ibh1G5H7/pdf?s=ap",
|
||||
last_finalization_error: null,
|
||||
latest_revision: null,
|
||||
lines: {
|
||||
object: "list",
|
||||
data: [
|
||||
{
|
||||
id: "il_1OIBqaI0XSgju2urWRv5yH9h",
|
||||
object: "line_item",
|
||||
amount: 2000,
|
||||
amount_excluding_tax: 2000,
|
||||
currency: "usd",
|
||||
description: "(created by Stripe CLI)",
|
||||
discount_amounts: [],
|
||||
discountable: true,
|
||||
discounts: [],
|
||||
invoice_item: "ii_1OIBqaI0XSgju2urik7fdYlI",
|
||||
livemode: false,
|
||||
metadata: {},
|
||||
period: {
|
||||
end: 1701356892,
|
||||
start: 1701356892,
|
||||
},
|
||||
plan: null,
|
||||
price: {
|
||||
id: "price_1OIBngI0XSgju2urxiG1M9fT",
|
||||
object: "price",
|
||||
active: false,
|
||||
billing_scheme: "per_unit",
|
||||
created: 1701356712,
|
||||
currency: "usd",
|
||||
custom_unit_amount: null,
|
||||
livemode: false,
|
||||
lookup_key: null,
|
||||
metadata: {},
|
||||
nickname: null,
|
||||
product: "prod_P6Oatqn6T5L2Ey",
|
||||
recurring: null,
|
||||
tax_behavior: "unspecified",
|
||||
tiers_mode: null,
|
||||
transform_quantity: null,
|
||||
type: "one_time",
|
||||
unit_amount: 2000,
|
||||
unit_amount_decimal: "2000",
|
||||
},
|
||||
proration: false,
|
||||
proration_details: {
|
||||
credited_items: null,
|
||||
},
|
||||
quantity: 1,
|
||||
subscription: null,
|
||||
tax_amounts: [],
|
||||
tax_rates: [],
|
||||
type: "invoiceitem",
|
||||
unit_amount_excluding_tax: "2000",
|
||||
},
|
||||
],
|
||||
has_more: false,
|
||||
total_count: 1,
|
||||
url: "/v1/invoices/in_1OIBqbI0XSgju2urMmXEFbj3/lines",
|
||||
},
|
||||
livemode: false,
|
||||
metadata: {},
|
||||
next_payment_attempt: null,
|
||||
number: "FD943C29-0111",
|
||||
on_behalf_of: null,
|
||||
paid: false,
|
||||
paid_out_of_band: false,
|
||||
payment_intent: "pi_3OIBqbI0XSgju2ur0BelVhdO",
|
||||
payment_settings: {
|
||||
default_mandate: null,
|
||||
payment_method_options: null,
|
||||
payment_method_types: null,
|
||||
},
|
||||
period_end: 1701356892,
|
||||
period_start: 1701356892,
|
||||
post_payment_credit_notes_amount: 0,
|
||||
pre_payment_credit_notes_amount: 0,
|
||||
quote: null,
|
||||
receipt_number: null,
|
||||
rendering: {
|
||||
amount_tax_display: null,
|
||||
pdf: {
|
||||
page_size: "letter",
|
||||
},
|
||||
},
|
||||
rendering_options: null,
|
||||
shipping_cost: null,
|
||||
shipping_details: null,
|
||||
starting_balance: 0,
|
||||
statement_descriptor: null,
|
||||
status: "open",
|
||||
status_transitions: {
|
||||
finalized_at: 1701356893,
|
||||
marked_uncollectible_at: null,
|
||||
paid_at: null,
|
||||
voided_at: null,
|
||||
},
|
||||
subscription: null,
|
||||
subscription_details: {
|
||||
metadata: null,
|
||||
},
|
||||
subtotal: 2000,
|
||||
subtotal_excluding_tax: 2000,
|
||||
tax: null,
|
||||
test_clock: null,
|
||||
total: 2000,
|
||||
total_discount_amounts: [],
|
||||
total_excluding_tax: 2000,
|
||||
total_tax_amounts: [],
|
||||
transfer_data: null,
|
||||
webhooks_delivered_at: 1701356893,
|
||||
},
|
||||
},
|
||||
],
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceFinalizationFailed: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.finalization_failed",
|
||||
title: "On Invoice Finalization failed",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceDeleted: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.deleted",
|
||||
title: "On Invoice Deleted",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceMarkedUncollectible: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.marked_uncollectible",
|
||||
title: "On Invoice Deleted",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoicePaid: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.paid",
|
||||
title: "On Invoice Paid",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
examples: [
|
||||
{
|
||||
id: "invoice.paid",
|
||||
name: "Invoice Paid",
|
||||
icon: "stripe",
|
||||
payload: {
|
||||
id: "in_1OIBuTI0XSgju2urKkqZFraX",
|
||||
object: "invoice",
|
||||
account_country: "GB",
|
||||
account_name: "Trigger.dev",
|
||||
account_tax_ids: null,
|
||||
amount_due: 2000,
|
||||
amount_paid: 2000,
|
||||
amount_remaining: 0,
|
||||
amount_shipping: 0,
|
||||
application: null,
|
||||
application_fee_amount: null,
|
||||
attempt_count: 1,
|
||||
attempted: true,
|
||||
auto_advance: false,
|
||||
automatic_tax: {
|
||||
enabled: false,
|
||||
status: null,
|
||||
},
|
||||
billing_reason: "manual",
|
||||
charge: "ch_3OIBuUI0XSgju2ur1ibTvTmE",
|
||||
collection_method: "charge_automatically",
|
||||
created: 1701357133,
|
||||
currency: "usd",
|
||||
custom_fields: null,
|
||||
customer: "cus_P6OhphiNsxG9aM",
|
||||
customer_address: null,
|
||||
customer_email: null,
|
||||
customer_name: null,
|
||||
customer_phone: null,
|
||||
customer_shipping: null,
|
||||
customer_tax_exempt: "none",
|
||||
customer_tax_ids: [],
|
||||
default_payment_method: null,
|
||||
default_source: null,
|
||||
default_tax_rates: [],
|
||||
description: "(created by Stripe CLI)",
|
||||
discount: null,
|
||||
discounts: [],
|
||||
due_date: null,
|
||||
effective_at: 1701357134,
|
||||
ending_balance: 0,
|
||||
footer: null,
|
||||
from_invoice: null,
|
||||
hosted_invoice_url:
|
||||
"https://invoice.stripe.com/i/acct_1MRmG4I0XSgju2ur/test_YWNjdF8xTVJtRzRJMFhTZ2p1MnVyLF9QNk9oeUJwdXpYVUtrb0hVQmJHYUFDclZhbmVha2w5LDkxODk3OTM20200JlMCKvkD?s=ap",
|
||||
invoice_pdf:
|
||||
"https://pay.stripe.com/invoice/acct_1MRmG4I0XSgju2ur/test_YWNjdF8xTVJtRzRJMFhTZ2p1MnVyLF9QNk9oeUJwdXpYVUtrb0hVQmJHYUFDclZhbmVha2w5LDkxODk3OTM20200JlMCKvkD/pdf?s=ap",
|
||||
last_finalization_error: null,
|
||||
latest_revision: null,
|
||||
lines: {
|
||||
object: "list",
|
||||
data: [
|
||||
{
|
||||
id: "il_1OIBuTI0XSgju2urpRdDk5DO",
|
||||
object: "line_item",
|
||||
amount: 2000,
|
||||
amount_excluding_tax: 2000,
|
||||
currency: "usd",
|
||||
description: "(created by Stripe CLI)",
|
||||
discount_amounts: [],
|
||||
discountable: true,
|
||||
discounts: [],
|
||||
invoice_item: "ii_1OIBuTI0XSgju2urRDAJz6ec",
|
||||
livemode: false,
|
||||
metadata: {},
|
||||
period: {
|
||||
end: 1701357133,
|
||||
start: 1701357133,
|
||||
},
|
||||
plan: null,
|
||||
price: {
|
||||
id: "price_1OIBngI0XSgju2urxiG1M9fT",
|
||||
object: "price",
|
||||
active: false,
|
||||
billing_scheme: "per_unit",
|
||||
created: 1701356712,
|
||||
currency: "usd",
|
||||
custom_unit_amount: null,
|
||||
livemode: false,
|
||||
lookup_key: null,
|
||||
metadata: {},
|
||||
nickname: null,
|
||||
product: "prod_P6Oatqn6T5L2Ey",
|
||||
recurring: null,
|
||||
tax_behavior: "unspecified",
|
||||
tiers_mode: null,
|
||||
transform_quantity: null,
|
||||
type: "one_time",
|
||||
unit_amount: 2000,
|
||||
unit_amount_decimal: "2000",
|
||||
},
|
||||
proration: false,
|
||||
proration_details: {
|
||||
credited_items: null,
|
||||
},
|
||||
quantity: 1,
|
||||
subscription: null,
|
||||
tax_amounts: [],
|
||||
tax_rates: [],
|
||||
type: "invoiceitem",
|
||||
unit_amount_excluding_tax: "2000",
|
||||
},
|
||||
],
|
||||
has_more: false,
|
||||
total_count: 1,
|
||||
url: "/v1/invoices/in_1OIBuTI0XSgju2urKkqZFraX/lines",
|
||||
},
|
||||
livemode: false,
|
||||
metadata: {},
|
||||
next_payment_attempt: null,
|
||||
number: "FD943C29-0112",
|
||||
on_behalf_of: null,
|
||||
paid: true,
|
||||
paid_out_of_band: false,
|
||||
payment_intent: "pi_3OIBuUI0XSgju2ur15gtauR9",
|
||||
payment_settings: {
|
||||
default_mandate: null,
|
||||
payment_method_options: null,
|
||||
payment_method_types: null,
|
||||
},
|
||||
period_end: 1701357133,
|
||||
period_start: 1701357133,
|
||||
post_payment_credit_notes_amount: 0,
|
||||
pre_payment_credit_notes_amount: 0,
|
||||
quote: null,
|
||||
receipt_number: null,
|
||||
rendering: {
|
||||
amount_tax_display: null,
|
||||
pdf: {
|
||||
page_size: "letter",
|
||||
},
|
||||
},
|
||||
rendering_options: null,
|
||||
shipping_cost: null,
|
||||
shipping_details: null,
|
||||
starting_balance: 0,
|
||||
statement_descriptor: null,
|
||||
status: "paid",
|
||||
status_transitions: {
|
||||
finalized_at: 1701357134,
|
||||
marked_uncollectible_at: null,
|
||||
paid_at: 1701357134,
|
||||
voided_at: null,
|
||||
},
|
||||
subscription: null,
|
||||
subscription_details: {
|
||||
metadata: null,
|
||||
},
|
||||
subtotal: 2000,
|
||||
subtotal_excluding_tax: 2000,
|
||||
tax: null,
|
||||
test_clock: null,
|
||||
total: 2000,
|
||||
total_discount_amounts: [],
|
||||
total_excluding_tax: 2000,
|
||||
total_tax_amounts: [],
|
||||
transfer_data: null,
|
||||
webhooks_delivered_at: 1701357134,
|
||||
},
|
||||
},
|
||||
],
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoicePaymentActionRequired: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.payment_action_required",
|
||||
title: "On Invoice Payment Action Required",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoicePaymentFailed: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.payment_failed",
|
||||
title: "On Invoice Payment Failed",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoicePaymentSucceeded: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.payment_succeeded",
|
||||
title: "On Invoice Payment Succeeded",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceSent: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.sent",
|
||||
title: "On Invoice Sent",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceUpcoming: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.upcoming",
|
||||
title: "On Invoice Upcoming",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceUpdated: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.updated",
|
||||
title: "On Invoice Updated",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceVoided: EventSpecification<OnInvoiceEvent> = {
|
||||
name: "invoice.voided",
|
||||
title: "On Invoice Voided",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceItemCreated: EventSpecification<OnInvoiceItemEvent> = {
|
||||
name: "invoiceitem.created",
|
||||
title: "On Invoice Item Created",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceItemEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice Item ID", text: payload.id }],
|
||||
};
|
||||
|
||||
export const onInvoiceItemDeleted: EventSpecification<OnInvoiceItemEvent> = {
|
||||
name: "invoiceitem.deleted",
|
||||
title: "On Invoice Item Deleted",
|
||||
source: "stripe.com",
|
||||
icon: "stripe",
|
||||
parsePayload: (payload) => payload as OnInvoiceItemEvent,
|
||||
runProperties: (payload) => [{ label: "Invoice Item ID", text: payload.id }],
|
||||
};
|
||||
|
||||
@@ -32,6 +32,8 @@ import {
|
||||
CustomerSubscriptionEventNamesSchema,
|
||||
ExternalAccountEventNames,
|
||||
ExternalAccountEventNamesSchema,
|
||||
InvoiceEventNames,
|
||||
InvoiceEventNamesSchema,
|
||||
PaymentIntentEventNames,
|
||||
PaymentIntentEventNamesSchema,
|
||||
PayoutEventNames,
|
||||
@@ -901,6 +903,123 @@ export class Stripe implements TriggerIntegration {
|
||||
params ?? { connect: false }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurs on any invoice.* event. Accepts an optional array of events to filter on. By default it will listen to all invoice.* events.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* stripe.onInvoice({ events: ["invoice.created", "invoice.paid"] })
|
||||
* ```
|
||||
*
|
||||
* 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.onInvoice({ events: ["invoice.created", "invoice.paid"] }),
|
||||
* run: async (payload, io, ctx) => {
|
||||
* console.log(ctx.event.name); // "invoice.created" or "invoice.paid"
|
||||
* },
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
onInvoice(params?: TriggerParams & { events?: InvoiceEventNames }) {
|
||||
const parsedEvents = InvoiceEventNamesSchema.optional().parse(params?.events);
|
||||
|
||||
const event = {
|
||||
...events.onInvoice,
|
||||
name: parsedEvents ?? events.onPayout.name,
|
||||
};
|
||||
|
||||
return createTrigger(this.source, event, params ?? { connect: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurs whenever an invoice is created.
|
||||
*/
|
||||
onInvoiceCreated(params?: TriggerParams) {
|
||||
return createTrigger(this.source, events.onInvoiceCreated, params ?? { connect: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurs whenever an invoice is finalized.
|
||||
*/
|
||||
onInvoiceFinalized(params?: TriggerParams) {
|
||||
return createTrigger(this.source, events.onInvoiceFinalized, params ?? { connect: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* The invoice couldn’t be finalized.
|
||||
*/
|
||||
onInvoiceFinalizationFailed(params?: TriggerParams) {
|
||||
return createTrigger(
|
||||
this.source,
|
||||
events.onInvoiceFinalizationFailed,
|
||||
params ?? { connect: false }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Occurs whenever an invoice is marked uncollectible.
|
||||
*/
|
||||
onInvoiceMarkedUncollectible(params?: TriggerParams) {
|
||||
return createTrigger(
|
||||
this.source,
|
||||
events.onInvoiceMarkedUncollectible,
|
||||
params ?? { connect: false }
|
||||
);
|
||||
}
|
||||
|
||||
onInvoicePaid(params?: TriggerParams) {
|
||||
return createTrigger(this.source, events.onInvoicePaid, params ?? { connect: false });
|
||||
}
|
||||
|
||||
onInvoicePaymentActionRequired(params?: TriggerParams) {
|
||||
return createTrigger(
|
||||
this.source,
|
||||
events.onInvoicePaymentActionRequired,
|
||||
params ?? { connect: false }
|
||||
);
|
||||
}
|
||||
|
||||
onInvoicePaymentFailed(params?: TriggerParams) {
|
||||
return createTrigger(this.source, events.onInvoicePaymentFailed, params ?? { connect: false });
|
||||
}
|
||||
|
||||
onInvoicePaymentSucceeded(params?: TriggerParams) {
|
||||
return createTrigger(
|
||||
this.source,
|
||||
events.onInvoicePaymentSucceeded,
|
||||
params ?? { connect: false }
|
||||
);
|
||||
}
|
||||
|
||||
onInvoiceSent(params?: TriggerParams) {
|
||||
return createTrigger(this.source, events.onInvoiceSent, params ?? { connect: false });
|
||||
}
|
||||
|
||||
onInvoiceUpcoming(params?: TriggerParams) {
|
||||
return createTrigger(this.source, events.onInvoiceUpcoming, params ?? { connect: false });
|
||||
}
|
||||
|
||||
onInvoiceUpdated(params?: TriggerParams) {
|
||||
return createTrigger(this.source, events.onInvoiceUpdated, params ?? { connect: false });
|
||||
}
|
||||
|
||||
onInvoiceVoided(params?: TriggerParams) {
|
||||
return createTrigger(this.source, events.onInvoiceVoided, params ?? { connect: false });
|
||||
}
|
||||
|
||||
onInvoiceItemCreated(params?: TriggerParams) {
|
||||
return createTrigger(this.source, events.onInvoiceItemCreated, params ?? { connect: false });
|
||||
}
|
||||
|
||||
onInvoiceItemDeleted(params?: TriggerParams) {
|
||||
return createTrigger(this.source, events.onInvoiceItemDeleted, params ?? { connect: false });
|
||||
}
|
||||
}
|
||||
|
||||
export type TriggerParams = {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { z } from "zod"
|
||||
import { z } from "zod";
|
||||
|
||||
export const PriceEventNamesSchema = z.array(z.enum(["price.created", "price.updated", "price.deleted"]));
|
||||
export const PriceEventNamesSchema = z.array(
|
||||
z.enum(["price.created", "price.updated", "price.deleted"])
|
||||
);
|
||||
export type PriceEventNames = z.infer<typeof PriceEventNamesSchema>;
|
||||
|
||||
export const ProductEventNamesSchema = z.array(
|
||||
@@ -87,4 +89,22 @@ export const PayoutEventNamesSchema = z.array(
|
||||
"payout.updated",
|
||||
])
|
||||
);
|
||||
export type PayoutEventNames = z.infer<typeof PayoutEventNamesSchema>;
|
||||
export type PayoutEventNames = z.infer<typeof PayoutEventNamesSchema>;
|
||||
|
||||
export const InvoiceEventNamesSchema = z.array(
|
||||
z.enum([
|
||||
"invoice.created",
|
||||
"invoice.finalized",
|
||||
"invoice.finalization_failed",
|
||||
"invoice.deleted",
|
||||
"invoice.marked_uncollectible",
|
||||
"invoice.paid",
|
||||
"invoice.payment_action_required",
|
||||
"invoice.payment_failed",
|
||||
"invoice.payment_succeeded",
|
||||
"invoice.sent",
|
||||
"invoice.upcoming",
|
||||
"invoice.voided",
|
||||
])
|
||||
);
|
||||
export type InvoiceEventNames = z.infer<typeof InvoiceEventNamesSchema>;
|
||||
|
||||
@@ -86,3 +86,7 @@ export type OnPaymentIntentEvent =
|
||||
ExtractWebhookPayload<Stripe.DiscriminatedEvent.PaymentIntentEvent>;
|
||||
|
||||
export type OnPayoutEvent = ExtractWebhookPayload<Stripe.DiscriminatedEvent.PayoutEvent>;
|
||||
|
||||
export type OnInvoiceEvent = ExtractWebhookPayload<Stripe.DiscriminatedEvent.InvoiceEvent>;
|
||||
|
||||
export type OnInvoiceItemEvent = ExtractWebhookPayload<Stripe.DiscriminatedEvent.InvoiceitemEvent>;
|
||||
|
||||
Reference in New Issue
Block a user