2022-08-17 08:50:24 -07:00
/* eslint-disable n8n-nodes-base/node-param-description-excess-final-period */
2023-01-27 03:22:44 -08:00
import type { IHookFunctions , IWebhookFunctions } from 'n8n-core' ;
2019-10-14 17:43:19 -07:00
2023-02-27 19:39:43 -08:00
import type {
IDataObject ,
INodeType ,
INodeTypeDescription ,
IWebhookResponseData ,
JsonObject ,
} from 'n8n-workflow' ;
2023-01-27 03:22:44 -08:00
import { NodeApiError } from 'n8n-workflow' ;
2019-10-14 17:43:19 -07:00
2022-08-17 08:50:24 -07:00
import { stripeApiRequest } from './helpers' ;
2019-10-14 17:43:19 -07:00
export class StripeTrigger implements INodeType {
2020-05-11 15:06:51 -07:00
description : INodeTypeDescription = {
displayName : 'Stripe Trigger' ,
2020-05-12 06:08:19 -07:00
name : 'stripeTrigger' ,
2021-06-12 12:00:37 -07:00
icon : 'file:stripe.svg' ,
2020-05-11 15:06:51 -07:00
group : [ 'trigger' ] ,
version : 1 ,
description : 'Handle Stripe events via webhooks' ,
defaults : {
name : 'Stripe Trigger' ,
} ,
inputs : [ ] ,
outputs : [ 'main' ] ,
credentials : [
2019-10-15 05:46:42 -07:00
{
name : 'stripeApi' ,
required : true ,
2020-10-22 06:46:03 -07:00
} ,
2019-10-15 05:46:42 -07:00
] ,
2020-05-11 15:06:51 -07:00
webhooks : [
{
name : 'default' ,
httpMethod : 'POST' ,
reponseMode : 'onReceived' ,
path : 'webhook' ,
} ,
] ,
properties : [
{
displayName : 'Events' ,
name : 'events' ,
type : 'multiOptions' ,
required : true ,
default : [ ] ,
2022-05-06 14:01:25 -07:00
description : 'The event to listen to' ,
2022-08-17 08:50:24 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-multi-options-type-unsorted-items
2020-05-11 15:06:51 -07:00
options : [
{
name : '*' ,
value : '*' ,
2022-05-06 14:01:25 -07:00
description : 'Any time any event is triggered (Wildcard Event)' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Account Updated' ,
value : 'account.updated' ,
description : 'Occurs whenever an account status or property has changed' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Account Application.authorized' ,
value : 'account.application.authorized' ,
description :
'Occurs whenever a user authorizes an application. Sent to the related application only.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Account Application.deauthorized' ,
value : 'account.application.deauthorized' ,
description :
'Occurs whenever a user deauthorizes an application. Sent to the related application only.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Account External_account.created' ,
value : 'account.external_account.created' ,
description : 'Occurs whenever an external account is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Account External_account.deleted' ,
value : 'account.external_account.deleted' ,
description : 'Occurs whenever an external account is deleted.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Account External_account.updated' ,
value : 'account.external_account.updated' ,
description : 'Occurs whenever an external account is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Application Fee.created' ,
value : 'application_fee.created' ,
description : 'Occurs whenever an application fee is created on a charge.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Application Fee.refunded' ,
value : 'application_fee.refunded' ,
description :
'Occurs whenever an application fee is refunded, whether from refunding a charge or from refunding the application fee directly. This includes partial refunds.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Application Fee.refund.updated' ,
value : 'application_fee.refund.updated' ,
description : 'Occurs whenever an application fee refund is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Balance Available' ,
value : 'balance.available' ,
description :
'Occurs whenever your Stripe balance has been updated (e.g., when a charge is available to be paid out). By default, Stripe automatically transfers funds in your balance to your bank account on a daily basis.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Capability Updated' ,
value : 'capability.updated' ,
description : 'Occurs whenever a capability has new requirements or a new status.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Captured' ,
value : 'charge.captured' ,
description : 'Occurs whenever a previously uncaptured charge is captured.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Expired' ,
value : 'charge.expired' ,
description : 'Occurs whenever an uncaptured charge expires.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Failed' ,
value : 'charge.failed' ,
description : 'Occurs whenever a failed charge attempt occurs.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Pending' ,
value : 'charge.pending' ,
description : 'Occurs whenever a pending charge is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Refunded' ,
value : 'charge.refunded' ,
description : 'Occurs whenever a charge is refunded, including partial refunds.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Succeeded' ,
value : 'charge.succeeded' ,
description : 'Occurs whenever a new charge is created and is successful.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Updated' ,
value : 'charge.updated' ,
description : 'Occurs whenever a charge description or metadata is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Dispute.closed' ,
value : 'charge.dispute.closed' ,
description :
'Occurs when a dispute is closed and the dispute status changes to lost, warning_closed, or won.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Dispute.created' ,
value : 'charge.dispute.created' ,
description : 'Occurs whenever a customer disputes a charge with their bank.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Dispute.funds_reinstated' ,
value : 'charge.dispute.funds_reinstated' ,
description :
'Occurs when funds are reinstated to your account after a dispute is closed. This includes partially refunded payments.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Dispute.funds_withdrawn' ,
value : 'charge.dispute.funds_withdrawn' ,
description : 'Occurs when funds are removed from your account due to a dispute.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Dispute.updated' ,
value : 'charge.dispute.updated' ,
description : 'Occurs when the dispute is updated (usually with evidence).' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Charge Refund.updated' ,
value : 'charge.refund.updated' ,
description : 'Occurs whenever a refund is updated, on selected payment methods.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Checkout Session.completed' ,
value : 'checkout.session.completed' ,
description : 'Occurs when a Checkout Session has been successfully completed.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Coupon Created' ,
value : 'coupon.created' ,
description : 'Occurs whenever a coupon is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Coupon Deleted' ,
value : 'coupon.deleted' ,
description : 'Occurs whenever a coupon is deleted.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Coupon Updated' ,
value : 'coupon.updated' ,
description : 'Occurs whenever a coupon is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Credit Note.created' ,
value : 'credit_note.created' ,
description : 'Occurs whenever a credit note is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Credit Note.updated' ,
value : 'credit_note.updated' ,
description : 'Occurs whenever a credit note is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Credit Note.voided' ,
value : 'credit_note.voided' ,
description : 'Occurs whenever a credit note is voided.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Created' ,
value : 'customer.created' ,
description : 'Occurs whenever a new customer is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Deleted' ,
value : 'customer.deleted' ,
description : 'Occurs whenever a customer is deleted.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Updated' ,
value : 'customer.updated' ,
description : 'Occurs whenever any property of a customer changes.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Discount.created' ,
value : 'customer.discount.created' ,
description : 'Occurs whenever a coupon is attached to a customer.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Discount.deleted' ,
value : 'customer.discount.deleted' ,
description : 'Occurs whenever a coupon is removed from a customer.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Discount.updated' ,
value : 'customer.discount.updated' ,
description : 'Occurs whenever a customer is switched from one coupon to another.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Source.created' ,
value : 'customer.source.created' ,
description : 'Occurs whenever a new source is created for a customer.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Source.deleted' ,
value : 'customer.source.deleted' ,
description : 'Occurs whenever a source is removed from a customer.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Source.expiring' ,
value : 'customer.source.expiring' ,
description : 'Occurs whenever a card or source will expire at the end of the month.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Source.updated' ,
value : 'customer.source.updated' ,
description : "Occurs whenever a source's details are changed." ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Subscription.created' ,
value : 'customer.subscription.created' ,
description : 'Occurs whenever a customer is signed up for a new plan.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Subscription.deleted' ,
value : 'customer.subscription.deleted' ,
description : "Occurs whenever a customer's subscription ends." ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Subscription.trial_will_end' ,
value : 'customer.subscription.trial_will_end' ,
description :
"Occurs three days before a subscription's trial period is scheduled to end, or when a trial is ended immediately (using trial_end=now)." ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Subscription.updated' ,
value : 'customer.subscription.updated' ,
description :
'Occurs whenever a subscription changes (e.g., switching from one plan to another, or changing the status from trial to active).' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Tax_id.created' ,
value : 'customer.tax_id.created' ,
description : 'Occurs whenever a tax ID is created for a customer.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Tax_id.deleted' ,
value : 'customer.tax_id.deleted' ,
description : 'Occurs whenever a tax ID is deleted from a customer.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Customer Tax_id.updated' ,
value : 'customer.tax_id.updated' ,
description : "Occurs whenever a customer's tax ID is updated." ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'File Created' ,
value : 'file.created' ,
description :
'Occurs whenever a new Stripe-generated file is available for your account.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Created' ,
value : 'invoice.created' ,
description :
'Occurs whenever a new invoice is created. To learn how webhooks can be used with this event, and how they can affect it, see Using Webhooks with Subscriptions.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Deleted' ,
value : 'invoice.deleted' ,
description : 'Occurs whenever a draft invoice is deleted.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Finalized' ,
value : 'invoice.finalized' ,
description :
'Occurs whenever a draft invoice is finalized and updated to be an open invoice.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Marked_uncollectible' ,
value : 'invoice.marked_uncollectible' ,
description : 'Occurs whenever an invoice is marked uncollectible.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Payment_action_required' ,
value : 'invoice.payment_action_required' ,
description :
'Occurs whenever an invoice payment attempt requires further user action to complete.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Payment_failed' ,
value : 'invoice.payment_failed' ,
description :
'Occurs whenever an invoice payment attempt fails, due either to a declined payment or to the lack of a stored payment method.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Payment_succeeded' ,
value : 'invoice.payment_succeeded' ,
description : 'Occurs whenever an invoice payment attempt succeeds.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Sent' ,
value : 'invoice.sent' ,
description : 'Occurs whenever an invoice email is sent out.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Upcoming' ,
value : 'invoice.upcoming' ,
description :
'Occurs X number of days before a subscription is scheduled to create an invoice that is automatically charged—where X is determined by your subscriptions settings. Note: The received Invoice object will not have an invoice ID.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Updated' ,
value : 'invoice.updated' ,
description : 'Occurs whenever an invoice changes (e.g., the invoice amount).' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoice Voided' ,
value : 'invoice.voided' ,
description : 'Occurs whenever an invoice is voided.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoiceitem Created' ,
value : 'invoiceitem.created' ,
description : 'Occurs whenever an invoice item is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoiceitem Deleted' ,
value : 'invoiceitem.deleted' ,
description : 'Occurs whenever an invoice item is deleted.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Invoiceitem Updated' ,
value : 'invoiceitem.updated' ,
description : 'Occurs whenever an invoice item is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Authorization.created' ,
value : 'issuing_authorization.created' ,
description : 'Occurs whenever an authorization is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Authorization.request' ,
value : 'issuing_authorization.request' ,
description :
'Represents a synchronous request for authorization, see Using your integration to handle authorization requests.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Authorization.updated' ,
value : 'issuing_authorization.updated' ,
description : 'Occurs whenever an authorization is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Card.created' ,
value : 'issuing_card.created' ,
description : 'Occurs whenever a card is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Card.updated' ,
value : 'issuing_card.updated' ,
description : 'Occurs whenever a card is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Cardholder.created' ,
value : 'issuing_cardholder.created' ,
description : 'Occurs whenever a cardholder is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Cardholder.updated' ,
value : 'issuing_cardholder.updated' ,
description : 'Occurs whenever a cardholder is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Dispute.created' ,
value : 'issuing_dispute.created' ,
description : 'Occurs whenever a dispute is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Dispute.updated' ,
value : 'issuing_dispute.updated' ,
description : 'Occurs whenever a dispute is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Settlement.created' ,
value : 'issuing_settlement.created' ,
description : 'Occurs whenever an issuing settlement is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Settlement.updated' ,
value : 'issuing_settlement.updated' ,
description : 'Occurs whenever an issuing settlement is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Transaction.created' ,
value : 'issuing_transaction.created' ,
description : 'Occurs whenever an issuing transaction is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Issuing Transaction.updated' ,
value : 'issuing_transaction.updated' ,
description : 'Occurs whenever an issuing transaction is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Order Created' ,
value : 'order.created' ,
description : 'Occurs whenever an order is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Order Payment_failed' ,
value : 'order.payment_failed' ,
description : 'Occurs whenever an order payment attempt fails.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Order Payment_succeeded' ,
value : 'order.payment_succeeded' ,
description : 'Occurs whenever an order payment attempt succeeds.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Order Updated' ,
value : 'order.updated' ,
description : 'Occurs whenever an order is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Order Return.created' ,
value : 'order_return.created' ,
description : 'Occurs whenever an order return is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payment Intent.amount_capturable_updated' ,
value : 'payment_intent.amount_capturable_updated' ,
description :
'Occurs when a PaymentIntent has funds to be captured. Check the amount_capturable property on the PaymentIntent to determine the amount that can be captured. You may capture the PaymentIntent with an amount_to_capture value up to the specified amount. Learn more about capturing PaymentIntents.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payment Intent.canceled' ,
value : 'payment_intent.canceled' ,
description : 'Occurs when a PaymentIntent is canceled.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payment Intent.created' ,
value : 'payment_intent.created' ,
description : 'Occurs when a new PaymentIntent is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payment Intent.payment_failed' ,
value : 'payment_intent.payment_failed' ,
description :
'Occurs when a PaymentIntent has failed the attempt to create a source or a payment.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payment Intent.succeeded' ,
value : 'payment_intent.succeeded' ,
description : 'Occurs when a PaymentIntent has been successfully fulfilled.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payment Method.attached' ,
value : 'payment_method.attached' ,
description : 'Occurs whenever a new payment method is attached to a customer.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payment Method.card_automatically_updated' ,
value : 'payment_method.card_automatically_updated' ,
description :
"Occurs whenever a card payment method's details are automatically updated by the network." ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payment Method.detached' ,
value : 'payment_method.detached' ,
description : 'Occurs whenever a payment method is detached from a customer.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payment Method.updated' ,
value : 'payment_method.updated' ,
description :
'Occurs whenever a payment method is updated via the PaymentMethod update API.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payout Canceled' ,
value : 'payout.canceled' ,
description : 'Occurs whenever a payout is canceled.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payout Created' ,
value : 'payout.created' ,
description : 'Occurs whenever a payout is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payout Failed' ,
value : 'payout.failed' ,
description : 'Occurs whenever a payout attempt fails.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payout Paid' ,
value : 'payout.paid' ,
description :
'Occurs whenever a payout is expected to be available in the destination account. If the payout fails, a payout.failed notification is also sent, at a later time.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Payout Updated' ,
value : 'payout.updated' ,
description : 'Occurs whenever a payout is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Person Created' ,
value : 'person.created' ,
description : 'Occurs whenever a person associated with an account is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Person Deleted' ,
value : 'person.deleted' ,
description : 'Occurs whenever a person associated with an account is deleted.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Person Updated' ,
value : 'person.updated' ,
description : 'Occurs whenever a person associated with an account is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Plan Created' ,
value : 'plan.created' ,
description : 'Occurs whenever a plan is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Plan Deleted' ,
value : 'plan.deleted' ,
description : 'Occurs whenever a plan is deleted.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Plan Updated' ,
value : 'plan.updated' ,
description : 'Occurs whenever a plan is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Product Created' ,
value : 'product.created' ,
description : 'Occurs whenever a product is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Product Deleted' ,
value : 'product.deleted' ,
description : 'Occurs whenever a product is deleted.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Product Updated' ,
value : 'product.updated' ,
description : 'Occurs whenever a product is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Radar Early_fraud_warning.created' ,
value : 'radar.early_fraud_warning.created' ,
description : 'Occurs whenever an early fraud warning is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Radar Early_fraud_warning.updated' ,
value : 'radar.early_fraud_warning.updated' ,
description : 'Occurs whenever an early fraud warning is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Recipient Created' ,
value : 'recipient.created' ,
description : 'Occurs whenever a recipient is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Recipient Deleted' ,
value : 'recipient.deleted' ,
description : 'Occurs whenever a recipient is deleted.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Recipient Updated' ,
value : 'recipient.updated' ,
description : 'Occurs whenever a recipient is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Reporting Report_run.failed' ,
value : 'reporting.report_run.failed' ,
description : 'Occurs whenever a requested **ReportRun** failed to complete.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Reporting Report_run.succeeded' ,
value : 'reporting.report_run.succeeded' ,
description : 'Occurs whenever a requested **ReportRun** completed succesfully.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Reporting Report_type.updated' ,
value : 'reporting.report_type.updated' ,
description :
"Occurs whenever a **ReportType** is updated (typically to indicate that a new day's data has come available)." ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Review Closed' ,
value : 'review.closed' ,
description :
"Occurs whenever a review is closed. The review's reason field indicates why: approved, disputed, refunded, or refunded_as_fraud." ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Review Opened' ,
value : 'review.opened' ,
description : 'Occurs whenever a review is opened.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Setup Intent.canceled' ,
value : 'setup_intent.canceled' ,
description : 'Occurs when a SetupIntent is canceled.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Setup Intent.created' ,
value : 'setup_intent.created' ,
description : 'Occurs when a new SetupIntent is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Setup Intent.setup_failed' ,
value : 'setup_intent.setup_failed' ,
description :
'Occurs when a SetupIntent has failed the attempt to setup a payment method.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Setup Intent.succeeded' ,
value : 'setup_intent.succeeded' ,
description : 'Occurs when an SetupIntent has successfully setup a payment method.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Sigma Scheduled_query_run.created' ,
value : 'sigma.scheduled_query_run.created' ,
description : 'Occurs whenever a Sigma scheduled query run finishes.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Sku Created' ,
value : 'sku.created' ,
description : 'Occurs whenever a SKU is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Sku Deleted' ,
value : 'sku.deleted' ,
description : 'Occurs whenever a SKU is deleted.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Sku Updated' ,
value : 'sku.updated' ,
description : 'Occurs whenever a SKU is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Source Canceled' ,
value : 'source.canceled' ,
description : 'Occurs whenever a source is canceled.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Source Chargeable' ,
value : 'source.chargeable' ,
description : 'Occurs whenever a source transitions to chargeable.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Source Failed' ,
value : 'source.failed' ,
description : 'Occurs whenever a source fails.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Source Mandate_notification' ,
value : 'source.mandate_notification' ,
description : 'Occurs whenever a source mandate notification method is set to manual.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Source Refund_attributes_required' ,
value : 'source.refund_attributes_required' ,
description :
'Occurs whenever the refund attributes are required on a receiver source to process a refund or a mispayment.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Source Transaction.created' ,
value : 'source.transaction.created' ,
description : 'Occurs whenever a source transaction is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Source Transaction.updated' ,
value : 'source.transaction.updated' ,
description : 'Occurs whenever a source transaction is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Subscription Schedule.aborted' ,
value : 'subscription_schedule.aborted' ,
description :
'Occurs whenever a subscription schedule is canceled due to the underlying subscription being canceled because of delinquency.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Subscription Schedule.canceled' ,
value : 'subscription_schedule.canceled' ,
description : 'Occurs whenever a subscription schedule is canceled.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Subscription Schedule.completed' ,
value : 'subscription_schedule.completed' ,
description : 'Occurs whenever a new subscription schedule is completed.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Subscription Schedule.created' ,
value : 'subscription_schedule.created' ,
description : 'Occurs whenever a new subscription schedule is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Subscription Schedule.expiring' ,
value : 'subscription_schedule.expiring' ,
description : 'Occurs 7 days before a subscription schedule will expire.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Subscription Schedule.released' ,
value : 'subscription_schedule.released' ,
description : 'Occurs whenever a new subscription schedule is released.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Subscription Schedule.updated' ,
value : 'subscription_schedule.updated' ,
description : 'Occurs whenever a subscription schedule is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Tax Rate.created' ,
value : 'tax_rate.created' ,
description : 'Occurs whenever a new tax rate is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Tax Rate.updated' ,
value : 'tax_rate.updated' ,
description : 'Occurs whenever a tax rate is updated.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Topup Canceled' ,
value : 'topup.canceled' ,
description : 'Occurs whenever a top-up is canceled.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Topup Created' ,
value : 'topup.created' ,
description : 'Occurs whenever a top-up is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Topup Failed' ,
value : 'topup.failed' ,
description : 'Occurs whenever a top-up fails.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Topup Reversed' ,
value : 'topup.reversed' ,
description : 'Occurs whenever a top-up is reversed.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Topup Succeeded' ,
value : 'topup.succeeded' ,
description : 'Occurs whenever a top-up succeeds.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Transfer Created' ,
value : 'transfer.created' ,
description : 'Occurs whenever a transfer is created.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Transfer Failed' ,
value : 'transfer.failed' ,
description : 'Occurs whenever a transfer failed.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Transfer Paid' ,
value : 'transfer.paid' ,
description :
'Occurs after a transfer is paid. For Instant Payouts, the event will be sent on the next business day, although the funds should be received well beforehand.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Transfer Reversed' ,
value : 'transfer.reversed' ,
description : 'Occurs whenever a transfer is reversed, including partial reversals.' ,
2020-05-11 15:06:51 -07:00
} ,
{
2022-08-17 08:50:24 -07:00
name : 'Transfer Updated' ,
value : 'transfer.updated' ,
description : "Occurs whenever a transfer's description or metadata is updated." ,
2020-10-22 06:46:03 -07:00
} ,
] ,
} ,
2020-05-11 15:06:51 -07:00
] ,
} ;
2019-10-14 17:43:19 -07:00
2019-10-15 05:46:42 -07:00
webhookMethods = {
default : {
async checkExists ( this : IHookFunctions ) : Promise < boolean > {
2020-05-11 15:06:51 -07:00
const webhookData = this . getWorkflowStaticData ( 'node' ) ;
2019-10-15 05:46:42 -07:00
if ( webhookData . webhookId === undefined ) {
// No webhook id is set so no webhook can exist
return false ;
}
// Webhook got created before so check if it still exists
const endpoint = ` /webhook_endpoints/ ${ webhookData . webhookId } ` ;
try {
await stripeApiRequest . call ( this , 'GET' , endpoint , { } ) ;
2021-04-16 09:33:36 -07:00
} catch ( error ) {
2021-11-13 01:54:14 -08:00
if ( error . httpCode === '404' || error . message . includes ( 'resource_missing' ) ) {
2019-10-15 05:46:42 -07:00
// Webhook does not exist
delete webhookData . webhookId ;
2020-05-11 15:06:51 -07:00
delete webhookData . webhookEvents ;
delete webhookData . webhookSecret ;
2019-10-15 05:46:42 -07:00
return false ;
}
// Some error occured
2021-04-16 09:33:36 -07:00
throw error ;
2019-10-15 05:46:42 -07:00
}
// If it did not error then the webhook exists
return true ;
} ,
async create ( this : IHookFunctions ) : Promise < boolean > {
const webhookUrl = this . getNodeWebhookUrl ( 'default' ) ;
2020-05-11 15:06:51 -07:00
const events = this . getNodeParameter ( 'events' , [ ] ) ;
2019-10-15 05:46:42 -07:00
const endpoint = '/webhook_endpoints' ;
const body = {
url : webhookUrl ,
enabled_events : events ,
} ;
let responseData ;
try {
responseData = await stripeApiRequest . call ( this , 'POST' , endpoint , body ) ;
2021-04-16 09:33:36 -07:00
} catch ( error ) {
throw error ;
2019-10-15 05:46:42 -07:00
}
2022-08-17 08:50:24 -07:00
if (
responseData . id === undefined ||
responseData . secret === undefined ||
responseData . status !== 'enabled'
) {
2019-10-15 05:46:42 -07:00
// Required data is missing so was not successful
2023-02-27 19:39:43 -08:00
throw new NodeApiError ( this . getNode ( ) , responseData as JsonObject , {
2022-08-17 08:50:24 -07:00
message : 'Stripe webhook creation response did not contain the expected data.' ,
} ) ;
2019-10-15 05:46:42 -07:00
}
const webhookData = this . getWorkflowStaticData ( 'node' ) ;
webhookData . webhookId = responseData . id as string ;
2020-05-11 15:06:51 -07:00
webhookData . webhookEvents = responseData . enabled_events as string [ ] ;
webhookData . webhookSecret = responseData . secret as string ;
2019-10-15 05:46:42 -07:00
return true ;
} ,
async delete ( this : IHookFunctions ) : Promise < boolean > {
const webhookData = this . getWorkflowStaticData ( 'node' ) ;
if ( webhookData . webhookId !== undefined ) {
const endpoint = ` /webhook_endpoints/ ${ webhookData . webhookId } ` ;
const body = { } ;
try {
await stripeApiRequest . call ( this , 'DELETE' , endpoint , body ) ;
2021-04-16 09:33:36 -07:00
} catch ( error ) {
2019-10-15 05:46:42 -07:00
return false ;
}
// Remove from the static workflow data so that it is clear
// that no webhooks are registred anymore
delete webhookData . webhookId ;
2020-05-11 15:06:51 -07:00
delete webhookData . webhookEvents ;
delete webhookData . webhookSecret ;
2019-10-15 05:46:42 -07:00
}
return true ;
} ,
} ,
} ;
2020-05-11 15:06:51 -07:00
async webhook ( this : IWebhookFunctions ) : Promise < IWebhookResponseData > {
2022-12-02 12:54:28 -08:00
const bodyData = this . getBodyData ( ) ;
2019-10-14 17:43:19 -07:00
const req = this . getRequestObject ( ) ;
const events = this . getNodeParameter ( 'events' , [ ] ) as string [ ] ;
const eventType = bodyData . type as string | undefined ;
2022-08-17 08:50:24 -07:00
if ( eventType === undefined || ( ! events . includes ( '*' ) && ! events . includes ( eventType ) ) ) {
2019-10-14 17:43:19 -07:00
// If not eventType is defined or when one is defined but we are not
// listening to it do not start the workflow.
return { } ;
}
return {
2023-02-27 19:39:43 -08:00
workflowData : [ this . helpers . returnJsonArray ( req . body as IDataObject ) ] ,
2019-10-14 17:43:19 -07:00
} ;
2020-05-11 15:06:51 -07:00
}
2019-10-14 17:43:19 -07:00
}