@@ -263,10 +263,84 @@ protected IEnumerable<T> ListRequestAutoPaging<T>(
263
263
RequestOptions requestOptions )
264
264
where T : IStripeEntity
265
265
{
266
+ #if NET461
267
+ return
268
+ this . ListRequestAutoPagingSync < T > ( url , options , requestOptions ) ;
269
+ #else
266
270
return AsyncUtils . ToEnumerable (
267
271
this . ListRequestAutoPagingAsync < T > ( url , options , requestOptions ) ) ;
272
+ #endif
268
273
}
269
274
275
+ #if NET461
276
+ protected IEnumerable < T > ListRequestAutoPagingSync < T > (
277
+ string url ,
278
+ ListOptions options ,
279
+ RequestOptions requestOptions )
280
+ where T : IStripeEntity
281
+ {
282
+ var page = this . Request < StripeList < T > > (
283
+ HttpMethod . Get ,
284
+ url ,
285
+ options ,
286
+ requestOptions ) ;
287
+
288
+ options = options ?? new ListOptions ( ) ;
289
+ bool iterateBackward = false ;
290
+
291
+ // Backward iterating activates if we have an `EndingBefore`
292
+ // constraint and not a `StartingAfter` constraint
293
+ if ( ! string . IsNullOrEmpty ( options . EndingBefore ) && string . IsNullOrEmpty ( options . StartingAfter ) )
294
+ {
295
+ iterateBackward = true ;
296
+ }
297
+
298
+ while ( true )
299
+ {
300
+ if ( iterateBackward )
301
+ {
302
+ page . Reverse ( ) ;
303
+ }
304
+
305
+ string itemId = null ;
306
+ foreach ( var item in page )
307
+ {
308
+ // Elements in `StripeList` instances are decoded by `StripeObjectConverter`,
309
+ // which returns `null` for objects it doesn't know how to decode.
310
+ // When auto-paginating, we simply ignore these null elements but still return
311
+ // other elements.
312
+ if ( item == null )
313
+ {
314
+ continue ;
315
+ }
316
+
317
+ itemId = ( ( IHasId ) item ) . Id ;
318
+ yield return item ;
319
+ }
320
+
321
+ if ( ! page . HasMore || string . IsNullOrEmpty ( itemId ) )
322
+ {
323
+ break ;
324
+ }
325
+
326
+ if ( iterateBackward )
327
+ {
328
+ options . EndingBefore = itemId ;
329
+ }
330
+ else
331
+ {
332
+ options . StartingAfter = itemId ;
333
+ }
334
+
335
+ page = this . Request < StripeList < T > > (
336
+ HttpMethod . Get ,
337
+ url ,
338
+ options ,
339
+ requestOptions ) ;
340
+ }
341
+ }
342
+
343
+ #endif
270
344
protected async IAsyncEnumerable < T > ListRequestAutoPagingAsync < T > (
271
345
string url ,
272
346
ListOptions options ,
0 commit comments