mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -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 = {};
|
||||
for (let i = 0; i < length; i++) {
|
||||
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++) {
|
||||
if (resource === 'payout') {
|
||||
if (operation === 'create') {
|
||||
const body: IPaymentBatch = {};
|
||||
|
@ -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,27 +256,27 @@ 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 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
|
@ -300,7 +290,7 @@ export const payoutFields = [
|
|||
'payout',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
'get',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -317,7 +307,7 @@ export const payoutFields = [
|
|||
'payout',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
'get',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -338,7 +328,7 @@ export const payoutFields = [
|
|||
'payout',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
'get',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
|
@ -348,18 +338,53 @@ export const payoutFields = [
|
|||
description: 'If all results should be returned or only up to a given limit.',
|
||||
},
|
||||
|
||||
] 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 = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payout:get */
|
||||
/* payoutItem:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Payout Item Id',
|
||||
name: 'payoutItemId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'payout',
|
||||
'payoutItem',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
|
@ -370,21 +395,22 @@ export const payoutFields = [
|
|||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payout:delete */
|
||||
/* payoutItem:cancel */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
displayName: 'Payout Item Id',
|
||||
name: 'payoutItemId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'payout',
|
||||
'payoutItem',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
'cancel',
|
||||
],
|
||||
},
|
||||
},
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
Loading…
Reference in a new issue