@@ -254,6 +254,19 @@ convert_to_form_fields(), _get() can now easily handle the same calling
254
254
form as _post(), eliminating the need for _get_collections() and
255
255
_get_with_args(). We have also updated _delete() accordingly.
256
256
257
+ =item add _get_all()
258
+
259
+ Similar to methods provided by other SDKs, calls using this method will allow
260
+ access to all records for a given object type without having to manually
261
+ paginate through the results. It is not intended to be used directly, but
262
+ will be accessed through new and existing list-retrieval methods. In order to
263
+ maintain backwards-compatibility with existing list retrieval behavior, this
264
+ method supports passing a value of 0 for 'limit' in order to retrieve all
265
+ records. Any other positive integer value for 'limit' will attempt to retrieve
266
+ that number of records up to the maximum available. As before, not passing a
267
+ value for 'limit', or explicitly passing an undefined value, retrieves whatever
268
+ number of records the API returns by default.
269
+
257
270
=back
258
271
259
272
=head3 UPDATES
@@ -560,13 +573,14 @@ Charges: {
560
573
$customer = $customer -> id;
561
574
}
562
575
my %args = (
576
+ path => ' charges' ,
563
577
created => $created ,
564
578
customer => $customer ,
565
579
ending_before => $ending_before ,
566
580
limit => $limit ,
567
581
starting_after => $starting_after ,
568
582
);
569
- $self -> _get( ' charges ' , \ %args );
583
+ $self -> _get_all( %args );
570
584
}
571
585
572
586
method capture_charge(
@@ -788,11 +802,12 @@ Customers: {
788
802
$customer = $customer -> id;
789
803
}
790
804
my %args = (
805
+ path => " customers/$customer /subscriptions" ,
791
806
ending_before => $ending_before ,
792
807
limit => $limit ,
793
808
starting_after => $starting_after ,
794
809
);
795
- return $self -> _get( " customers/ $customer /subscriptions " , \ %args );
810
+ return $self -> _get_all( %args );
796
811
}
797
812
798
813
method get_customer(Str :$customer_id ) {
@@ -808,13 +823,14 @@ Customers: {
808
823
809
824
method get_customers(HashRef :$created ?, Str :$ending_before ?, Int :$limit ?, Str :$starting_after ?, Str :$email ?) {
810
825
my %args = (
826
+ path => ' customers' ,
811
827
created => $created ,
812
828
ending_before => $ending_before ,
813
829
limit => $limit ,
814
830
starting_after => $starting_after ,
815
831
email => $email ,
816
832
);
817
- $self -> _get( ' customers ' , \ %args );
833
+ $self -> _get_all( %args );
818
834
}
819
835
}
820
836
@@ -946,13 +962,14 @@ Cards: {
946
962
}
947
963
948
964
my %args = (
965
+ path => " customers/$customer /sources" ,
949
966
object => " card" ,
950
967
created => $created ,
951
968
ending_before => $ending_before ,
952
969
limit => $limit ,
953
970
starting_after => $starting_after ,
954
971
);
955
- $self -> _get( " customers/ $customer /sources " , \ %args );
972
+ $self -> _get_all( %args );
956
973
}
957
974
958
975
method post_card(
@@ -1570,11 +1587,12 @@ Plans: {
1570
1587
1571
1588
method get_plans(Str :$ending_before ?, Int :$limit ?, Str :$starting_after ?) {
1572
1589
my %args = (
1590
+ path => ' plans' ,
1573
1591
ending_before => $ending_before ,
1574
1592
limit => $limit ,
1575
1593
starting_after => $starting_after ,
1576
1594
);
1577
- $self -> _get( ' plans ' , \ %args );
1595
+ $self -> _get_all( %args );
1578
1596
}
1579
1597
}
1580
1598
@@ -1701,11 +1719,12 @@ Coupons: {
1701
1719
1702
1720
method get_coupons(Str :$ending_before ?, Int :$limit ?, Str :$starting_after ?) {
1703
1721
my %args = (
1722
+ path => ' coupons' ,
1704
1723
ending_before => $ending_before ,
1705
1724
limit => $limit ,
1706
1725
starting_after => $starting_after ,
1707
1726
);
1708
- $self -> _get( ' coupons ' , \ %args );
1727
+ $self -> _get_all( %args );
1709
1728
}
1710
1729
}
1711
1730
@@ -1941,9 +1960,10 @@ Invoices: {
1941
1960
$customer = $customer -> id;
1942
1961
}
1943
1962
my %args = (
1963
+ path => ' invoices/upcoming' ,
1944
1964
customer => $customer ,
1945
1965
);
1946
- return $self -> _get( " invoices/upcoming " , \ %args );
1966
+ return $self -> _get_all( %args );
1947
1967
}
1948
1968
}
1949
1969
@@ -2119,12 +2139,13 @@ InvoiceItems: {
2119
2139
$customer = $customer -> id;
2120
2140
}
2121
2141
my %args = (
2142
+ path => ' invoiceitems' ,
2122
2143
created => $created ,
2123
2144
ending_before => $ending_before ,
2124
2145
limit => $limit ,
2125
2146
starting_after => $starting_after ,
2126
2147
);
2127
- $self -> _get( ' invoiceitems ' , \ %args );
2148
+ $self -> _get_all( %args );
2128
2149
}
2129
2150
}
2130
2151
@@ -2458,6 +2479,66 @@ fun _post_2019_10_17_processing(
2458
2479
return $hash ;
2459
2480
}
2460
2481
2482
+ method _get_all(
2483
+ Str :$path !,
2484
+ Maybe[Str] :$ending_before ?,
2485
+ Maybe[Int] :$limit ?,
2486
+ Maybe[Str] :$starting_after ?,
2487
+ %object_filters ,
2488
+ ) {
2489
+
2490
+ # minimize the number of API calls by retrieving as many results as
2491
+ # possible per call. the API currently returns a maximum of 100 results.
2492
+ my $API_PAGE_SIZE = 100;
2493
+ my $PAGE_SIZE = $limit ;
2494
+ my $GET_MORE ;
2495
+ if ( defined ( $limit ) && ( $limit eq ' 0' || $limit > $API_PAGE_SIZE ) ) {
2496
+ $PAGE_SIZE = $API_PAGE_SIZE ;
2497
+ $GET_MORE = 1;
2498
+ }
2499
+
2500
+ my %args = (
2501
+ %object_filters ,
2502
+ ending_before => $ending_before ,
2503
+ limit => $PAGE_SIZE ,
2504
+ starting_after => $starting_after ,
2505
+ );
2506
+ my $list = $self -> _get($path , \%args );
2507
+
2508
+ if ( $GET_MORE ) {
2509
+ # passing 'ending_before' causes the API to start with the oldest
2510
+ # records. so in order to always provide records in reverse-chronological
2511
+ # order, we must prepend these to the existing records.
2512
+ my $REVERSE = defined ( $ending_before ) && ! defined ( $starting_after );
2513
+ my $MAX_COUNT = $limit eq ' 0' ? undef : $limit ;
2514
+ while ( 1 ) {
2515
+ my $PAGE_SIZE = $API_PAGE_SIZE ;
2516
+ if ( defined ( $MAX_COUNT ) ) {
2517
+ my $TO_FETCH = $MAX_COUNT - scalar ( $list -> elements );
2518
+ last if $TO_FETCH <= 0;
2519
+ $PAGE_SIZE = $TO_FETCH if $TO_FETCH < $PAGE_SIZE ;
2520
+ }
2521
+
2522
+ my %args = (
2523
+ %object_filters ,
2524
+ limit => $PAGE_SIZE ,
2525
+ ( $REVERSE ? $list -> _previous_page_args() : $list -> _next_page_args() ),
2526
+ );
2527
+ my $page = $self -> _get($path , \%args );
2528
+
2529
+ last if $page -> is_empty;
2530
+
2531
+ $list = Net::Stripe::List::_merge_lists(
2532
+ lists => [ $REVERSE ?
2533
+ ( $page , $list ) :
2534
+ ( $list , $page )
2535
+ ],
2536
+ );
2537
+ }
2538
+ }
2539
+ return $list ;
2540
+ }
2541
+
2461
2542
method _build_api_base { ' https://api.stripe.com/v1' }
2462
2543
2463
2544
method _build_ua {
0 commit comments