mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
⚡ Fixed build and made some smaller changes
This commit is contained in:
parent
beccf379a1
commit
20eab17b23
|
@ -5,7 +5,7 @@ import {
|
|||
|
||||
|
||||
export class PayPalApi implements ICredentialType {
|
||||
name = 'paypalApi';
|
||||
name = 'payPalApi';
|
||||
displayName = 'PayPal API';
|
||||
properties = [
|
||||
{
|
|
@ -12,8 +12,8 @@ import {
|
|||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function paypalApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('paypalApi');
|
||||
export async function payPalApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('payPalApi');
|
||||
const env = getEnviroment(credentials!.env as string);
|
||||
const tokenInfo = await getAccessToken.call(this);
|
||||
const headerWithAuthentication = Object.assign({ },
|
||||
|
@ -47,7 +47,7 @@ function getEnviroment(env: string): string {
|
|||
}
|
||||
|
||||
async function getAccessToken(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('paypalApi');
|
||||
const credentials = this.getCredentials('payPalApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
@ -75,11 +75,12 @@ async function getAccessToken(this: IHookFunctions | IExecuteFunctions | IExecut
|
|||
throw error.response.body;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an API request to paginated paypal endpoint
|
||||
* and return all results
|
||||
*/
|
||||
export async function paypalApiRequestAllItems(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function payPalApiRequestAllItems(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
|
@ -88,7 +89,7 @@ export async function paypalApiRequestAllItems(this: IHookFunctions | IExecuteFu
|
|||
query!.page_size = 1000;
|
||||
|
||||
do {
|
||||
responseData = await paypalApiRequest.call(this, endpoint, method, body, query, uri);
|
||||
responseData = await payPalApiRequest.call(this, endpoint, method, body, query, uri);
|
||||
uri = getNext(responseData.links);
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
} while (
|
|
@ -1,7 +1,6 @@
|
|||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
INodeTypeDescription,
|
||||
|
@ -9,8 +8,10 @@ import {
|
|||
INodeType,
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
payoutOpeations,
|
||||
payoutOperations,
|
||||
payoutItemOperations,
|
||||
payoutFields,
|
||||
payoutItemFields,
|
||||
} from './PaymentDescription';
|
||||
import {
|
||||
IPaymentBatch,
|
||||
|
@ -21,14 +22,14 @@ import {
|
|||
} from './PaymentInteface';
|
||||
import {
|
||||
validateJSON,
|
||||
paypalApiRequest,
|
||||
paypalApiRequestAllItems
|
||||
payPalApiRequest,
|
||||
payPalApiRequestAllItems
|
||||
} from './GenericFunctions';
|
||||
|
||||
export class PayPal implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'PayPal',
|
||||
name: 'paypal',
|
||||
name: 'payPal',
|
||||
icon: 'file:paypal.png',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
|
@ -42,7 +43,7 @@ export class PayPal implements INodeType {
|
|||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'paypalApi',
|
||||
name: 'payPalApi',
|
||||
required: true,
|
||||
}
|
||||
],
|
||||
|
@ -55,14 +56,21 @@ export class PayPal implements INodeType {
|
|||
{
|
||||
name: 'Payout',
|
||||
value: 'payout',
|
||||
description: 'Use the Payouts API to make payments to multiple PayPal or Venmo recipients. The Payouts API is a fast, convenient way to send commissions, rebates, rewards, and general disbursements. You can send up to 15,000 payments per call. If you integrated the Payouts API before September 1, 2017, you receive transaction reports through Mass Payments Reporting.',
|
||||
},
|
||||
{
|
||||
name: 'Payout Item',
|
||||
value: 'payoutItem',
|
||||
},
|
||||
],
|
||||
default: 'payout',
|
||||
description: 'Resource to consume.',
|
||||
},
|
||||
...payoutOpeations,
|
||||
|
||||
// Payout
|
||||
...payoutOperations,
|
||||
...payoutItemOperations,
|
||||
...payoutFields,
|
||||
...payoutItemFields,
|
||||
],
|
||||
};
|
||||
|
||||
|
@ -71,10 +79,12 @@ export class PayPal implements INodeType {
|
|||
const returnData: IDataObject[] = [];
|
||||
const length = items.length as unknown as number;
|
||||
let responseData;
|
||||
let qs: IDataObject = {};
|
||||
const qs: IDataObject = {};
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
if (resource === 'payout') {
|
||||
if (operation === 'create') {
|
||||
const body: IPaymentBatch = {};
|
||||
|
@ -97,18 +107,18 @@ export class PayPal implements INodeType {
|
|||
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);
|
||||
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 {
|
||||
|
@ -119,40 +129,41 @@ export class PayPal implements INodeType {
|
|||
body.items = itemsJson;
|
||||
}
|
||||
try {
|
||||
responseData = await paypalApiRequest.call(this, '/payments/payouts', 'POST', body);
|
||||
responseData = await payPalApiRequest.call(this, '/payments/payouts', 'POST', body);
|
||||
} catch (err) {
|
||||
throw new Error(`Paypal Error: ${JSON.stringify(err)}`);
|
||||
throw new Error(`PayPal Error: ${JSON.stringify(err)}`);
|
||||
}
|
||||
}
|
||||
if (operation === 'get') {
|
||||
const payoutItemId = this.getNodeParameter('payoutItemId', i) as string;
|
||||
try {
|
||||
responseData = await paypalApiRequest.call(this,`/payments/payouts-item/${payoutItemId}`, 'GET', {}, qs);
|
||||
} catch (err) {
|
||||
throw new Error(`Paypal Error: ${JSON.stringify(err)}`);
|
||||
}
|
||||
}
|
||||
if (operation === 'getAll') {
|
||||
const payoutBatchId = this.getNodeParameter('payoutBatchId', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
|
||||
try {
|
||||
if (returnAll === true) {
|
||||
responseData = await paypalApiRequestAllItems.call(this, 'items', `/payments/payouts/${payoutBatchId}`, 'GET', {}, qs);
|
||||
responseData = await payPalApiRequestAllItems.call(this, 'items', `/payments/payouts/${payoutBatchId}`, 'GET', {}, qs);
|
||||
} else {
|
||||
qs.page_size = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await paypalApiRequest.call(this,`/payments/payouts/${payoutBatchId}`, 'GET', {}, qs);
|
||||
responseData = await payPalApiRequest.call(this, `/payments/payouts/${payoutBatchId}`, 'GET', {}, qs);
|
||||
responseData = responseData.items;
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`Paypal Error: ${JSON.stringify(err)}`);
|
||||
throw new Error(`PayPal Error: ${JSON.stringify(err)}`);
|
||||
}
|
||||
}
|
||||
if (operation === 'delete') {
|
||||
} else if (resource === 'payoutItem') {
|
||||
if (operation === 'get') {
|
||||
const payoutItemId = this.getNodeParameter('payoutItemId', i) as string;
|
||||
try {
|
||||
responseData = await paypalApiRequest.call(this,`/payments/payouts-item/${payoutItemId}/cancel`, 'POST', {}, qs);
|
||||
responseData = await payPalApiRequest.call(this,`/payments/payouts-item/${payoutItemId}`, 'GET', {}, qs);
|
||||
} catch (err) {
|
||||
throw new Error(`Paypal Error: ${JSON.stringify(err)}`);
|
||||
throw new Error(`PayPal Error: ${JSON.stringify(err)}`);
|
||||
}
|
||||
}
|
||||
if (operation === 'cancel') {
|
||||
const payoutItemId = this.getNodeParameter('payoutItemId', i) as string;
|
||||
try {
|
||||
responseData = await payPalApiRequest.call(this,`/payments/payouts-item/${payoutItemId}/cancel`, 'POST', {}, qs);
|
||||
} catch (err) {
|
||||
throw new Error(`PayPal Error: ${JSON.stringify(err)}`);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { INodeProperties } from "n8n-workflow";
|
||||
|
||||
export const payoutOpeations = [
|
||||
export const payoutOperations = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
|
@ -21,17 +21,7 @@ export const payoutOpeations = [
|
|||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Show payout item details',
|
||||
},
|
||||
{
|
||||
name: 'Get All',
|
||||
value: 'getAll',
|
||||
description: 'Show payout batch details',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Cancels an unclaimed payout item, by ID.',
|
||||
description: 'Show batch payout details',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
|
@ -120,7 +110,7 @@ export const payoutFields = [
|
|||
{
|
||||
name: 'Email',
|
||||
value: 'email',
|
||||
description: 'The unencrypted email. Value is a string of up to 127 single-byte characters.',
|
||||
description: 'The unencrypted email.',
|
||||
},
|
||||
{
|
||||
name: 'PayPal ID',
|
||||
|
@ -137,7 +127,7 @@ export const payoutFields = [
|
|||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'The receiver of the payment. Corresponds to the recipient_type value in the request. Max value of up to 127 single-byte characters.',
|
||||
description: 'The receiver of the payment. Corresponds to the recipient_type value<br />in the request. Max length: 127 characters.',
|
||||
},
|
||||
{
|
||||
displayName: 'Currency',
|
||||
|
@ -190,7 +180,7 @@ export const payoutFields = [
|
|||
type: 'string',
|
||||
required: false,
|
||||
default: '',
|
||||
description: 'The sender-specified note for notifications. Supports up to 4000 ASCII characters and 1000 non-ASCII characters.',
|
||||
description: 'The sender-specified note for notifications. Supports up to<br />4000 ASCII characters and 1000 non-ASCII characters.',
|
||||
},
|
||||
{
|
||||
displayName: 'Sender Item ID',
|
||||
|
@ -266,128 +256,164 @@ export const payoutFields = [
|
|||
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. Value is an alphanumeric string of up to 255 single-byte characters.',
|
||||
description: 'The subject line for the email that PayPal sends when payment<br />for a payout item completes. The subject line is the same for all<br />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.',
|
||||
description: 'The email message that PayPal sends when the payout item completes.<br />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. The maximum combined length of the notes is 1000 characters.',
|
||||
description: 'The payouts and item-level notes are concatenated in the email.<br />Max length: 1000 characters.',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payout:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payout:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
displayName: 'Payout Batch Id',
|
||||
name: 'payoutBatchId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'payout',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
{
|
||||
displayName: 'Payout Batch Id',
|
||||
name: 'payoutBatchId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'payout',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The ID of the payout for which to show details.',
|
||||
},
|
||||
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: [
|
||||
'getAll',
|
||||
],
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'payout',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'If all results should be returned or only up to a given limit.',
|
||||
},
|
||||
description: 'If all results should be returned 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: [
|
||||
'getAll',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
maxValue: 1000,
|
||||
minValue: 1
|
||||
},
|
||||
default: 100,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'payout',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'If all results should be returned or only up to a given limit.',
|
||||
},
|
||||
description: 'If all results should be returned or only up to a given limit.',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payout:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Payout Item Id',
|
||||
name: 'payoutItemId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'payout',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The ID of the payout item for which to show details.',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payout:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
displayName: 'Payout Item Id',
|
||||
name: 'payoutItemId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'payout',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The ID of the payout item to cancel.',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
||||
|
||||
export const payoutItemOperations = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'payoutItem',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Cancel',
|
||||
value: 'cancel',
|
||||
description: 'Cancels an unclaimed payout item',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Show payout item details',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
||||
export const payoutItemFields = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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.',
|
||||
},
|
||||
] as INodeProperties[];
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
|
@ -52,8 +52,8 @@
|
|||
"dist/credentials/NextCloudApi.credentials.js",
|
||||
"dist/credentials/OpenWeatherMapApi.credentials.js",
|
||||
"dist/credentials/PipedriveApi.credentials.js",
|
||||
"dist/credentials/Postgres.credentials.js",
|
||||
"dist/credentials/PayPalApi.credentials.js",
|
||||
"dist/credentials/Postgres.credentials.js",
|
||||
"dist/credentials/PayPalApi.credentials.js",
|
||||
"dist/credentials/Redis.credentials.js",
|
||||
"dist/credentials/RocketchatApi.credentials.js",
|
||||
"dist/credentials/SlackApi.credentials.js",
|
||||
|
@ -115,8 +115,8 @@
|
|||
"dist/nodes/OpenWeatherMap.node.js",
|
||||
"dist/nodes/Pipedrive/Pipedrive.node.js",
|
||||
"dist/nodes/Pipedrive/PipedriveTrigger.node.js",
|
||||
"dist/nodes/Postgres/Postgres.node.js",
|
||||
"dist/nodes/PayPal/PayPal.node.js",
|
||||
"dist/nodes/Postgres/Postgres.node.js",
|
||||
"dist/nodes/PayPal/PayPal.node.js",
|
||||
"dist/nodes/Rocketchat/Rocketchat.node.js",
|
||||
"dist/nodes/ReadBinaryFile.node.js",
|
||||
"dist/nodes/ReadBinaryFiles.node.js",
|
||||
|
|
Loading…
Reference in a new issue