All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.stripe.model.StripeCollection Maven / Gradle / Ivy

There is a newer version: 28.2.0
Show newest version
package com.stripe.model;

import com.stripe.Stripe;
import com.stripe.exception.ApiKeyMissingException;
import com.stripe.net.RequestOptions;
import java.util.List;
import java.util.Map;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

/**
 * Provides a representation of a single page worth of data from the Stripe API.
 *
 * 

The following code will have the effect of iterating through a single page worth of invoice * data retrieve from the API: * *

* *

{@code
 * foreach (Invoice invoice : Invoice.list(...).getData()) {
 *   System.out.println("Current invoice = " + invoice.toString());
 * }
 * }
* *

The class also provides a helper for iterating over collections that may be longer than a * single page: * *

* *

{@code
 * foreach (Invoice invoice : Invoice.list(...).autoPagingIterable()) {
 *   System.out.println("Current invoice = " + invoice.toString());
 * }
 * }
*/ @Getter @Setter @EqualsAndHashCode(callSuper = false) public abstract class StripeCollection extends StripeObject implements StripeCollectionInterface { String object; @Getter(onMethod_ = {@Override}) List data; @Getter(onMethod_ = {@Override}) Boolean hasMore; @Getter(onMethod_ = {@Override}) String url; @Getter(onMethod_ = {@Override}) @Setter(onMethod = @__({@Override})) private transient RequestOptions requestOptions; @Getter(onMethod_ = {@Override}) @Setter(onMethod = @__({@Override})) private Map requestParams; public Iterable autoPagingIterable() { if (Stripe.apiKey == null && (this.requestOptions == null || this.requestOptions.getApiKey() == null)) { throw new ApiKeyMissingException( "API key is not set for autoPagingIterable. You can set the API key globally using Stripe.ApiKey, or through RequestOptions with autoPagingIterable(params, options)."); } return new PagingIterable<>(this); } public Iterable autoPagingIterable(Map params) { if (Stripe.apiKey == null && (this.requestOptions == null || this.requestOptions.getApiKey() == null)) { throw new ApiKeyMissingException( "API key is not set for autoPagingIterable. You can set the API key globally using Stripe.ApiKey, or through RequestOptions with autoPagingIterable(params, options)."); } this.setRequestParams(params); return new PagingIterable<>(this); } /** * Constructs an iterable that can be used to iterate across all objects across all pages. As page * boundaries are encountered, the next page will be fetched automatically for continued * iteration. * * @param params request parameters (will override the parameters from the initial list request) * @param options request options (will override the options from the initial list request) */ public Iterable autoPagingIterable(Map params, RequestOptions options) { String apiKey = options.getApiKey(); if (Stripe.apiKey == null && apiKey == null) { throw new ApiKeyMissingException( "API key is not set for autoPagingIterable. You can set the API key globally using Stripe.ApiKey, or through RequestOptions with autoPagingIterable(params, options)."); } this.setRequestOptions(options); this.setRequestParams(params); return new PagingIterable<>(this); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy