🐛 Fix Stripe pagination (#2402)

* Fix Stripe pagination

* Fix displayOptions for type
This commit is contained in:
Iván Ovejero 2021-11-04 01:42:57 +01:00 committed by GitHub
parent aaa39876f9
commit a3bfdd3805
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 11 deletions

View file

@ -255,7 +255,7 @@ export class Stripe implements INodeType {
// charge: getAll
// ----------------------------------
responseData = await handleListing.call(this, resource);
responseData = await handleListing.call(this, resource, i);
} else if (operation === 'update') {
@ -313,7 +313,7 @@ export class Stripe implements INodeType {
// coupon: getAll
// ----------------------------------
responseData = await handleListing.call(this, resource);
responseData = await handleListing.call(this, resource, i);
}
@ -374,7 +374,7 @@ export class Stripe implements INodeType {
qs.email = filters.email;
}
responseData = await handleListing.call(this, resource, qs);
responseData = await handleListing.call(this, resource, i, qs);
} else if (operation === 'update') {

View file

@ -43,6 +43,16 @@ export const tokenFields = [
value: 'cardToken',
},
],
displayOptions: {
show: {
resource: [
'token',
],
operation: [
'create',
],
},
},
},
{
displayName: 'Card Number',

View file

@ -154,19 +154,25 @@ export async function loadResource(
export async function handleListing(
this: IExecuteFunctions,
resource: string,
i: number,
qs: IDataObject = {},
) {
const returnData: IDataObject[] = [];
let responseData;
responseData = await stripeApiRequest.call(this, 'GET', `/${resource}s`, qs, {});
responseData = responseData.data;
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const limit = this.getNodeParameter('limit', i, 0) as number;
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
do {
responseData = await stripeApiRequest.call(this, 'GET', `/${resource}s`, {}, qs);
returnData.push(...responseData.data);
if (!returnAll) {
const limit = this.getNodeParameter('limit', 0) as number;
responseData = responseData.slice(0, limit);
}
if (!returnAll && returnData.length >= limit) {
return returnData.slice(0, limit);
}
return responseData;
qs.starting_after = returnData[returnData.length - 1].id;
} while (responseData.has_more);
return returnData;
}