first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
import type {
|
||||
JsonObject,
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IWebhookFunctions,
|
||||
IHttpRequestMethods,
|
||||
IRequestOptions,
|
||||
} from 'n8n-workflow';
|
||||
import { BINARY_ENCODING, NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
function getEnvironment(env: string) {
|
||||
return {
|
||||
sanbox: 'https://api-m.sandbox.paypal.com',
|
||||
live: 'https://api-m.paypal.com',
|
||||
}[env];
|
||||
}
|
||||
|
||||
async function getAccessToken(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('payPalApi');
|
||||
const env = getEnvironment(credentials.env as string);
|
||||
const data = Buffer.from(`${credentials.clientId}:${credentials.secret}`).toString(
|
||||
BINARY_ENCODING,
|
||||
);
|
||||
const headerWithAuthentication = Object.assign(
|
||||
{},
|
||||
{ Authorization: `Basic ${data}`, 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
);
|
||||
const options: IRequestOptions = {
|
||||
headers: headerWithAuthentication,
|
||||
method: 'POST',
|
||||
form: {
|
||||
grant_type: 'client_credentials',
|
||||
},
|
||||
uri: `${env}/v1/oauth2/token`,
|
||||
json: true,
|
||||
};
|
||||
try {
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(this.getNode(), error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function payPalApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
||||
endpoint: string,
|
||||
method: IHttpRequestMethods,
|
||||
|
||||
body: any = {},
|
||||
query?: IDataObject,
|
||||
uri?: string,
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('payPalApi');
|
||||
const env = getEnvironment(credentials.env as string);
|
||||
const tokenInfo = await getAccessToken.call(this);
|
||||
const headerWithAuthentication = Object.assign(
|
||||
{},
|
||||
{ Authorization: `Bearer ${tokenInfo.access_token}`, 'Content-Type': 'application/json' },
|
||||
);
|
||||
const options = {
|
||||
headers: headerWithAuthentication,
|
||||
method,
|
||||
qs: query || {},
|
||||
uri: uri || `${env}/v1${endpoint}`,
|
||||
body,
|
||||
json: true,
|
||||
};
|
||||
try {
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
function getNext(links: IDataObject[]): string | undefined {
|
||||
for (const link of links) {
|
||||
if (link.rel === 'next') {
|
||||
return link.href as string;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an API request to paginated paypal endpoint
|
||||
* and return all results
|
||||
*/
|
||||
export async function payPalApiRequestAllItems(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
||||
propertyName: string,
|
||||
endpoint: string,
|
||||
method: IHttpRequestMethods,
|
||||
|
||||
body: any = {},
|
||||
query?: IDataObject,
|
||||
uri?: string,
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
|
||||
query!.page_size = 1000;
|
||||
|
||||
do {
|
||||
responseData = await payPalApiRequest.call(this, endpoint, method, body, query, uri);
|
||||
uri = getNext(responseData.links as IDataObject[]);
|
||||
returnData.push.apply(returnData, responseData[propertyName] as IDataObject[]);
|
||||
} while (getNext(responseData.links as IDataObject[]) !== undefined);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export function validateJSON(json: string | undefined): any {
|
||||
let result;
|
||||
try {
|
||||
result = JSON.parse(json!);
|
||||
} catch (exception) {
|
||||
result = '';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function upperFist(s: string): string {
|
||||
return s
|
||||
.split('.')
|
||||
.map((e) => {
|
||||
return e.toLowerCase().charAt(0).toUpperCase() + e.toLowerCase().slice(1);
|
||||
})
|
||||
.join(' ');
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.payPal",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Finance & Accounting", "Sales"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/paypal/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.paypal/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
INodeCredentialTestResult,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
IRequestOptions,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { payPalApiRequest, payPalApiRequestAllItems, validateJSON } from './GenericFunctions';
|
||||
import {
|
||||
payoutFields,
|
||||
payoutItemFields,
|
||||
payoutItemOperations,
|
||||
payoutOperations,
|
||||
} from './PaymentDescription';
|
||||
import type {
|
||||
IAmount,
|
||||
IItem,
|
||||
IPaymentBatch,
|
||||
ISenderBatchHeader,
|
||||
RecipientType,
|
||||
RecipientWallet,
|
||||
} from './PaymentInteface';
|
||||
|
||||
export class PayPal implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'PayPal',
|
||||
name: 'payPal',
|
||||
icon: 'file:paypal.svg',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume PayPal API',
|
||||
defaults: {
|
||||
name: 'PayPal',
|
||||
},
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'payPalApi',
|
||||
required: true,
|
||||
testedBy: 'payPalApiTest',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Payout',
|
||||
value: 'payout',
|
||||
},
|
||||
{
|
||||
name: 'Payout Item',
|
||||
value: 'payoutItem',
|
||||
},
|
||||
],
|
||||
default: 'payout',
|
||||
},
|
||||
|
||||
// Payout
|
||||
...payoutOperations,
|
||||
...payoutItemOperations,
|
||||
...payoutFields,
|
||||
...payoutItemFields,
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
credentialTest: {
|
||||
async payPalApiTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
const credentials = credential.data;
|
||||
const clientId = credentials!.clientId;
|
||||
const clientSecret = credentials!.secret;
|
||||
const environment = credentials!.env;
|
||||
|
||||
if (!clientId || !clientSecret || !environment) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: 'Connection details not valid: missing credentials',
|
||||
};
|
||||
}
|
||||
|
||||
let baseUrl = '';
|
||||
if (environment !== 'live') {
|
||||
baseUrl = 'https://api-m.sandbox.paypal.com';
|
||||
} else {
|
||||
baseUrl = 'https://api-m.paypal.com';
|
||||
}
|
||||
|
||||
const base64Key = Buffer.from(`${clientId}:${clientSecret}`).toString('base64');
|
||||
|
||||
const options: IRequestOptions = {
|
||||
headers: {
|
||||
Authorization: `Basic ${base64Key}`,
|
||||
},
|
||||
method: 'POST',
|
||||
uri: `${baseUrl}/v1/oauth2/token`,
|
||||
form: {
|
||||
grant_type: 'client_credentials',
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
await this.helpers.request(options);
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Authentication successful!',
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: `Connection details not valid: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
const length = items.length;
|
||||
let responseData;
|
||||
const qs: IDataObject = {};
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
if (resource === 'payout') {
|
||||
if (operation === 'create') {
|
||||
const body: IPaymentBatch = {};
|
||||
const header: ISenderBatchHeader = {};
|
||||
const jsonActive = this.getNodeParameter('jsonParameters', i);
|
||||
const senderBatchId = this.getNodeParameter('senderBatchId', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
header.sender_batch_id = senderBatchId;
|
||||
if (additionalFields.emailSubject) {
|
||||
header.email_subject = additionalFields.emailSubject as string;
|
||||
}
|
||||
if (additionalFields.emailMessage) {
|
||||
header.email_message = additionalFields.emailMessage as string;
|
||||
}
|
||||
if (additionalFields.note) {
|
||||
header.note = additionalFields.note as string;
|
||||
}
|
||||
body.sender_batch_header = header;
|
||||
if (!jsonActive) {
|
||||
const payoutItems: IItem[] = [];
|
||||
const itemsValues = (this.getNodeParameter('itemsUi', i) as IDataObject)
|
||||
.itemsValues as IDataObject[];
|
||||
if (itemsValues && itemsValues.length > 0) {
|
||||
itemsValues.forEach((o) => {
|
||||
const payoutItem: IItem = {};
|
||||
const amount: IAmount = {};
|
||||
amount.currency = o.currency as string;
|
||||
amount.value = parseFloat(o.amount as string);
|
||||
payoutItem.amount = amount;
|
||||
payoutItem.note = (o.note as string) || '';
|
||||
payoutItem.receiver = o.receiverValue as string;
|
||||
payoutItem.recipient_type = o.recipientType as RecipientType;
|
||||
payoutItem.recipient_wallet = o.recipientWallet as RecipientWallet;
|
||||
payoutItem.sender_item_id = (o.senderItemId as string) || '';
|
||||
payoutItems.push(payoutItem);
|
||||
});
|
||||
body.items = payoutItems;
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), 'You must have at least one item.', {
|
||||
itemIndex: i,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const itemsJson = validateJSON(this.getNodeParameter('itemsJson', i) as string);
|
||||
body.items = itemsJson;
|
||||
}
|
||||
responseData = await payPalApiRequest.call(this, '/payments/payouts', 'POST', body);
|
||||
}
|
||||
if (operation === 'get') {
|
||||
const payoutBatchId = this.getNodeParameter('payoutBatchId', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', 0);
|
||||
if (returnAll) {
|
||||
responseData = await payPalApiRequestAllItems.call(
|
||||
this,
|
||||
'items',
|
||||
`/payments/payouts/${payoutBatchId}`,
|
||||
'GET',
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.page_size = this.getNodeParameter('limit', i);
|
||||
responseData = await payPalApiRequest.call(
|
||||
this,
|
||||
`/payments/payouts/${payoutBatchId}`,
|
||||
'GET',
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
}
|
||||
}
|
||||
} else if (resource === 'payoutItem') {
|
||||
if (operation === 'get') {
|
||||
const payoutItemId = this.getNodeParameter('payoutItemId', i) as string;
|
||||
responseData = await payPalApiRequest.call(
|
||||
this,
|
||||
`/payments/payouts-item/${payoutItemId}`,
|
||||
'GET',
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
}
|
||||
if (operation === 'cancel') {
|
||||
const payoutItemId = this.getNodeParameter('payoutItemId', i) as string;
|
||||
responseData = await payPalApiRequest.call(
|
||||
this,
|
||||
`/payments/payouts-item/${payoutItemId}/cancel`,
|
||||
'POST',
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
const executionErrorData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ error: error.message }),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionErrorData);
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.payPalTrigger",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Finance & Accounting", "Sales"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/paypal/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.paypaltrigger/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
import type {
|
||||
IHookFunctions,
|
||||
IWebhookFunctions,
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
IWebhookResponseData,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError, NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
import { payPalApiRequest, upperFist } from './GenericFunctions';
|
||||
|
||||
export class PayPalTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'PayPal Trigger',
|
||||
name: 'payPalTrigger',
|
||||
icon: 'file:paypal.svg',
|
||||
group: ['trigger'],
|
||||
version: 1,
|
||||
description: 'Handle PayPal events via webhooks',
|
||||
defaults: {
|
||||
name: 'PayPal Trigger',
|
||||
},
|
||||
inputs: [],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'payPalApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
webhooks: [
|
||||
{
|
||||
name: 'default',
|
||||
httpMethod: 'POST',
|
||||
responseMode: 'onReceived',
|
||||
path: 'webhook',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Event Names or IDs',
|
||||
name: 'events',
|
||||
type: 'multiOptions',
|
||||
required: true,
|
||||
default: [],
|
||||
description:
|
||||
'The event to listen to. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getEvents',
|
||||
},
|
||||
options: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
// Get all the events types to display them to user so that they can
|
||||
// select them easily
|
||||
async getEvents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [
|
||||
{
|
||||
name: '*',
|
||||
value: '*',
|
||||
description: 'Any time any event is triggered (Wildcard Event)',
|
||||
},
|
||||
];
|
||||
let events;
|
||||
try {
|
||||
const endpoint = '/notifications/webhooks-event-types';
|
||||
events = await payPalApiRequest.call(this, endpoint, 'GET');
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
for (const event of events.event_types) {
|
||||
const eventName = upperFist(event.name as string);
|
||||
const eventId = event.name;
|
||||
const eventDescription = event.description;
|
||||
|
||||
returnData.push({
|
||||
name: eventName,
|
||||
value: eventId,
|
||||
description: eventDescription,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
webhookMethods = {
|
||||
default: {
|
||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
if (webhookData.webhookId === undefined) {
|
||||
// No webhook id is set so no webhook can exist
|
||||
return false;
|
||||
}
|
||||
const endpoint = `/notifications/webhooks/${webhookData.webhookId}`;
|
||||
try {
|
||||
await payPalApiRequest.call(this, endpoint, 'GET');
|
||||
} catch (error) {
|
||||
if (error.response && error.response.name === 'INVALID_RESOURCE_ID') {
|
||||
// Webhook does not exist
|
||||
delete webhookData.webhookId;
|
||||
return false;
|
||||
}
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
async create(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
const events = this.getNodeParameter('events', []) as string[];
|
||||
const body = {
|
||||
url: webhookUrl,
|
||||
event_types: events.map((event) => {
|
||||
return { name: event };
|
||||
}),
|
||||
};
|
||||
const endpoint = '/notifications/webhooks';
|
||||
const webhook = await payPalApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (webhook.id === undefined) {
|
||||
return false;
|
||||
}
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
webhookData.webhookId = webhook.id as string;
|
||||
return true;
|
||||
},
|
||||
|
||||
async delete(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
if (webhookData.webhookId !== undefined) {
|
||||
const endpoint = `/notifications/webhooks/${webhookData.webhookId}`;
|
||||
try {
|
||||
await payPalApiRequest.call(this, endpoint, 'DELETE', {});
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
delete webhookData.webhookId;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
const bodyData = this.getBodyData();
|
||||
const req = this.getRequestObject();
|
||||
const headerData = this.getHeaderData() as IDataObject;
|
||||
const endpoint = '/notifications/verify-webhook-signature';
|
||||
|
||||
const { env } = await this.getCredentials<{ env: string }>('payPalApi');
|
||||
|
||||
// if sanbox omit verification
|
||||
if (env === 'sanbox') {
|
||||
return {
|
||||
workflowData: [this.helpers.returnJsonArray(req.body as IDataObject)],
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
headerData['paypal-auth-algo'] !== undefined &&
|
||||
headerData['paypal-cert-url'] !== undefined &&
|
||||
headerData['paypal-transmission-id'] !== undefined &&
|
||||
headerData['paypal-transmission-sig'] !== undefined &&
|
||||
headerData['paypal-transmission-time'] !== undefined
|
||||
) {
|
||||
const body = {
|
||||
auth_algo: headerData['paypal-auth-algo'],
|
||||
cert_url: headerData['paypal-cert-url'],
|
||||
transmission_id: headerData['paypal-transmission-id'],
|
||||
transmission_sig: headerData['paypal-transmission-sig'],
|
||||
transmission_time: headerData['paypal-transmission-time'],
|
||||
webhook_id: webhookData.webhookId,
|
||||
webhook_event: bodyData,
|
||||
};
|
||||
const webhook = await payPalApiRequest.call(this, endpoint, 'POST', body);
|
||||
if (webhook.verification_status !== 'SUCCESS') {
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
workflowData: [this.helpers.returnJsonArray(req.body as IDataObject)],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const payoutOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payout'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a batch payout',
|
||||
action: 'Create a payout',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Show batch payout details',
|
||||
action: 'Get a payout',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
export const payoutFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payout:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
displayName: 'Sender Batch ID',
|
||||
name: 'senderBatchId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payout'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'A sender-specified ID number. Tracks the payout in an accounting system.',
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payout'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Items',
|
||||
name: 'itemsUi',
|
||||
placeholder: 'Add Item',
|
||||
type: 'fixedCollection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payout'],
|
||||
operation: ['create'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'itemsValues',
|
||||
displayName: 'Item',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Recipient Type',
|
||||
name: 'recipientType',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Phone',
|
||||
value: 'phone',
|
||||
description: 'The unencrypted phone number',
|
||||
},
|
||||
{
|
||||
name: 'Email',
|
||||
value: 'email',
|
||||
description: 'The unencrypted email',
|
||||
},
|
||||
{
|
||||
name: 'PayPal ID',
|
||||
value: 'paypalId',
|
||||
description: 'The encrypted PayPal account number',
|
||||
},
|
||||
],
|
||||
default: 'email',
|
||||
description: 'The ID type that identifies the recipient of the payment',
|
||||
},
|
||||
{
|
||||
displayName: 'Receiver Value',
|
||||
name: 'receiverValue',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description:
|
||||
'The receiver of the payment. Corresponds to the recipient_type value in the request. Max length: 127 characters.',
|
||||
},
|
||||
{
|
||||
displayName: 'Currency',
|
||||
name: 'currency',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Australian Dollar',
|
||||
value: 'AUD',
|
||||
},
|
||||
{
|
||||
name: 'Brazilian Real',
|
||||
value: 'BRL',
|
||||
},
|
||||
{
|
||||
name: 'Canadian Dollar',
|
||||
value: 'CAD',
|
||||
},
|
||||
{
|
||||
name: 'Czech Koruna',
|
||||
value: 'CZK',
|
||||
},
|
||||
{
|
||||
name: 'Danish Krone',
|
||||
value: 'DKK',
|
||||
},
|
||||
{
|
||||
name: 'Euro',
|
||||
value: 'EUR',
|
||||
},
|
||||
{
|
||||
name: 'United States Dollar',
|
||||
value: 'USD',
|
||||
},
|
||||
],
|
||||
default: 'USD',
|
||||
},
|
||||
{
|
||||
displayName: 'Amount',
|
||||
name: 'amount',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'The value, which might be',
|
||||
},
|
||||
{
|
||||
displayName: 'Note',
|
||||
name: 'note',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'The sender-specified note for notifications. Supports up to 4000 ASCII characters and 1000 non-ASCII characters.',
|
||||
},
|
||||
{
|
||||
displayName: 'Sender Item ID',
|
||||
name: 'senderItemId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'The sender-specified ID number. Tracks the payout in an accounting system.',
|
||||
},
|
||||
{
|
||||
displayName: 'Recipient Wallet',
|
||||
name: 'recipientWallet',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'PayPal',
|
||||
value: 'paypal',
|
||||
description: 'PayPal Wallet',
|
||||
},
|
||||
{
|
||||
name: 'Venmo',
|
||||
value: 'venmo',
|
||||
description: 'Venmo Wallet',
|
||||
},
|
||||
],
|
||||
default: 'paypal',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Items',
|
||||
name: 'itemsJson',
|
||||
type: 'json',
|
||||
default: '',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
description: 'An array of individual payout items',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payout'],
|
||||
operation: ['create'],
|
||||
jsonParameters: [true],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payout'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Email Subject',
|
||||
name: 'emailSubject',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'The subject line for the email that PayPal sends when payment for a payout item completes. The subject line is the same for all recipients. Max length: 255 characters.',
|
||||
},
|
||||
{
|
||||
displayName: 'Email Message',
|
||||
name: 'emailMessage',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'The email message that PayPal sends when the payout item completes. The message is the same for all recipients.',
|
||||
},
|
||||
{
|
||||
displayName: 'Note',
|
||||
name: 'note',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'The payouts and item-level notes are concatenated in the email. Max length: 1000 characters.',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payout:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
displayName: 'Payout Batch ID',
|
||||
name: 'payoutBatchId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payout'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
description: 'The ID of the payout for which to show details',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payout'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
maxValue: 1000,
|
||||
minValue: 1,
|
||||
},
|
||||
default: 100,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payout'],
|
||||
operation: ['get'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
|
||||
export const payoutItemOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payoutItem'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Cancel',
|
||||
value: 'cancel',
|
||||
description: 'Cancels an unclaimed payout item',
|
||||
action: 'Cancel a payout item',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Show payout item details',
|
||||
action: 'Get a payout item',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
},
|
||||
];
|
||||
|
||||
export const payoutItemFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payoutItem:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Payout Item ID',
|
||||
name: 'payoutItemId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payoutItem'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
description: 'The ID of the payout item for which to show details',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payoutItem:cancel */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
displayName: 'Payout Item ID',
|
||||
name: 'payoutItemId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payoutItem'],
|
||||
operation: ['cancel'],
|
||||
},
|
||||
},
|
||||
description: 'The ID of the payout item to cancel',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,40 @@
|
||||
export const RecipientTypes = {
|
||||
email: 'EMAIL',
|
||||
phone: 'PHONE',
|
||||
paypalId: 'PAYPAL_ID',
|
||||
} as const;
|
||||
|
||||
export type RecipientType = (typeof RecipientTypes)[keyof typeof RecipientTypes];
|
||||
|
||||
export const RecipientWallets = {
|
||||
paypal: 'PAYPAL',
|
||||
venmo: 'VENMO',
|
||||
} as const;
|
||||
|
||||
export type RecipientWallet = (typeof RecipientWallets)[keyof typeof RecipientWallets];
|
||||
|
||||
export interface IAmount {
|
||||
currency?: string;
|
||||
value?: number;
|
||||
}
|
||||
|
||||
export interface ISenderBatchHeader {
|
||||
sender_batch_id?: string;
|
||||
email_subject?: string;
|
||||
email_message?: string;
|
||||
note?: string;
|
||||
}
|
||||
|
||||
export interface IItem {
|
||||
recipient_type?: RecipientType;
|
||||
amount?: IAmount;
|
||||
note?: string;
|
||||
receiver?: string;
|
||||
sender_item_id?: string;
|
||||
recipient_wallet?: RecipientWallet;
|
||||
}
|
||||
|
||||
export interface IPaymentBatch {
|
||||
sender_batch_header?: ISenderBatchHeader;
|
||||
items?: IItem[];
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"batch_header": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"batch_status": {
|
||||
"type": "string"
|
||||
},
|
||||
"payout_batch_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"sender_batch_header": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"sender_batch_id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"links": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"encType": {
|
||||
"type": "string"
|
||||
},
|
||||
"href": {
|
||||
"type": "string"
|
||||
},
|
||||
"method": {
|
||||
"type": "string"
|
||||
},
|
||||
"rel": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60"><g fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"><path fill="#009CDE" d="M59.444 21.742c0 6.191-2.574 11.192-7.71 14.99s-12.315 5.692-21.545 5.692h-5.102l-3.913 16.963H7.69L20.14 7.361h18.258c3.41 0 6.36.238 8.901.703 2.529.465 4.718 1.27 6.546 2.416 1.814 1.145 3.208 2.63 4.161 4.456.952 1.814 1.429 4.093 1.429 6.815z"/><path fill="#FFF" d="M21.627 59.945H6.987L19.71 6.795h18.687c3.413 0 6.441.239 8.992.704 2.586.477 4.854 1.316 6.748 2.484 1.893 1.19 3.368 2.765 4.366 4.672C59.5 16.56 60 18.949 60 21.742c0 6.35-2.673 11.555-7.928 15.444-5.216 3.856-12.575 5.806-21.885 5.806h-4.661zM8.404 58.833H20.73l3.912-16.963h5.545c9.06 0 16.205-1.882 21.217-5.59 2.483-1.837 4.377-3.992 5.623-6.396s1.86-5.148 1.86-8.142c0-2.618-.465-4.83-1.372-6.576-.907-1.735-2.234-3.153-3.958-4.241-1.77-1.1-3.912-1.883-6.36-2.336-2.484-.454-5.444-.692-8.8-.692H20.583z"/><path fill="#0F3572" d="M53.457 15.957c0 6.192-2.573 11.192-7.71 14.99S33.432 36.64 24.204 36.64H19.1l-3.904 16.953H1.703L13.722 1.556h18.7c3.41 0 6.36.238 8.9.703 2.53.465 4.718 1.27 6.546 2.416 1.814 1.145 3.208 2.63 4.161 4.456.953 1.814 1.43 4.093 1.43 6.826z"/><path fill="#FFF" d="M15.628 54.15H1L13.258 1h19.153c3.413 0 6.441.238 8.992.703 2.586.477 4.854 1.316 6.748 2.484 1.894 1.191 3.368 2.766 4.366 4.672.999 1.906 1.497 4.287 1.497 7.087 0 6.35-2.673 11.555-7.928 15.445-5.216 3.855-12.574 5.806-21.885 5.806H19.53zM2.406 53.027h12.337l3.913-16.963H24.2c9.06 0 16.205-1.882 21.216-5.59 2.483-1.837 4.377-3.992 5.623-6.396s1.86-5.148 1.86-8.142c0-2.618-.465-4.83-1.372-6.576-.907-1.735-2.234-3.153-3.958-4.241-1.77-1.1-3.912-1.883-6.36-2.336-2.484-.454-5.443-.692-8.8-.692H14.142zm37.193-35.221c-.092 1.587-.42 2.765-1.395 4.105-.964 1.35-2.098 2.212-3.617 2.948a9.8 9.8 0 0 1-2.87.85c-.997.137-2.188.217-3.583.217h-6.702l3.752-13.46h6.09c1.553 0 2.8.023 3.742.238.94.203 1.712.489 2.291.83.805.476 1.451 1.054 1.825 1.791.465.862.522 1.418.465 2.461z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
Reference in New Issue
Block a user