mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
done
This commit is contained in:
parent
eaa33e0a8d
commit
6e4d6a5c1c
121
packages/nodes-base/nodes/Paypal/PaypalTriger.node.ts
Normal file
121
packages/nodes-base/nodes/Paypal/PaypalTriger.node.ts
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
import {
|
||||||
|
IHookFunctions,
|
||||||
|
IWebhookFunctions,
|
||||||
|
} from 'n8n-core';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IDataObject,
|
||||||
|
INodeTypeDescription,
|
||||||
|
INodeType,
|
||||||
|
IWebhookResponseData,
|
||||||
|
ILoadOptionsFunctions,
|
||||||
|
INodePropertyOptions,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
import {
|
||||||
|
paypalApiRequest,
|
||||||
|
} from './GenericFunctions';
|
||||||
|
|
||||||
|
export class PayPalTrigger implements INodeType {
|
||||||
|
description: INodeTypeDescription = {
|
||||||
|
displayName: 'PayPal Trigger',
|
||||||
|
name: 'PayPal',
|
||||||
|
icon: 'file:paypal.png',
|
||||||
|
group: ['trigger'],
|
||||||
|
version: 1,
|
||||||
|
description: 'Handle PayPal events via webhooks',
|
||||||
|
defaults: {
|
||||||
|
name: 'PayPal Trigger',
|
||||||
|
color: '#32325d',
|
||||||
|
},
|
||||||
|
inputs: [],
|
||||||
|
outputs: ['main'],
|
||||||
|
credentials: [
|
||||||
|
{
|
||||||
|
name: 'paypalApi',
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
webhooks: [
|
||||||
|
{
|
||||||
|
name: 'default',
|
||||||
|
httpMethod: 'POST',
|
||||||
|
reponseMode: 'onReceived',
|
||||||
|
path: 'webhook',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Events',
|
||||||
|
name: 'events',
|
||||||
|
type: 'multiOptions',
|
||||||
|
required: true,
|
||||||
|
default: [],
|
||||||
|
description: 'The event to listen to.',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getEvents'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
methods = {
|
||||||
|
loadOptions: {
|
||||||
|
// Get all the events types to display them to user so that he can
|
||||||
|
// select them easily
|
||||||
|
async getEvents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
const returnData: INodePropertyOptions[] = [];
|
||||||
|
let events;
|
||||||
|
try {
|
||||||
|
events = await paypalApiRequest.call(this, '/webhooks-event-types', 'GET');
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`PayPal Error: ${err}`);
|
||||||
|
}
|
||||||
|
for (const event of events.event_types) {
|
||||||
|
const eventName = event.name;
|
||||||
|
const eventId = event.name;
|
||||||
|
const eventDescription = event.description;
|
||||||
|
|
||||||
|
returnData.push({
|
||||||
|
name: eventName,
|
||||||
|
value: eventId,
|
||||||
|
description: eventDescription,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return returnData;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// @ts-ignore (because of request)
|
||||||
|
webhookMethods = {
|
||||||
|
default: {
|
||||||
|
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||||
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
async delete(this: IHookFunctions): Promise<boolean> {
|
||||||
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||||
|
const bodyData = this.getBodyData() as IDataObject;
|
||||||
|
const req = this.getRequestObject();
|
||||||
|
|
||||||
|
const events = this.getNodeParameter('events', []) as string[];
|
||||||
|
|
||||||
|
const eventType = bodyData.type as string | undefined;
|
||||||
|
|
||||||
|
return {
|
||||||
|
workflowData: [
|
||||||
|
this.helpers.returnJsonArray(req.body)
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -110,7 +110,8 @@
|
||||||
"dist/nodes/Pipedrive/Pipedrive.node.js",
|
"dist/nodes/Pipedrive/Pipedrive.node.js",
|
||||||
"dist/nodes/Pipedrive/PipedriveTrigger.node.js",
|
"dist/nodes/Pipedrive/PipedriveTrigger.node.js",
|
||||||
"dist/nodes/Postgres/Postgres.node.js",
|
"dist/nodes/Postgres/Postgres.node.js",
|
||||||
"dist/nodes/PayPal/PayPal.node.js",
|
"dist/nodes/Paypal/Paypal.node.js",
|
||||||
|
"dist/nodes/Paypal/PaypalTriger.node.js",
|
||||||
"dist/nodes/Rocketchat/Rocketchat.node.js",
|
"dist/nodes/Rocketchat/Rocketchat.node.js",
|
||||||
"dist/nodes/ReadBinaryFile.node.js",
|
"dist/nodes/ReadBinaryFile.node.js",
|
||||||
"dist/nodes/ReadBinaryFiles.node.js",
|
"dist/nodes/ReadBinaryFiles.node.js",
|
||||||
|
|
Loading…
Reference in a new issue