Subscription

Subscription: Search

Returns a collection of Subscription response objects.

You can search for subscriptions using a variety of criteria. For operators available on search fields, see the search fields page.

  1. Java
SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .planId().is("the_plan_id");

ResourceCollection<Subscription> collection = gateway.subscription().search(request);

for (Subscription subscription : collection) {
  System.out.println(subscription.getBillingDayOfMonth());
}

If you want to look up a single subscription using its ID, use Subscription: Find instead.

Parameters
The number of billing cycles remaining in the subscription.
The date/time the subscription was created.
The number of days past due the subscription is.
The ID of the subscription.
.ids(…)multiple
A list of subscription IDs to search for.

Whether the subscription is in a trial period. Can be true or false. This parameter must be used in conjunction with status().

A list of merchant account IDs to search for.

A part of the merchant account ID to search for.
A postfix for the merchant account ID to search for.
An exact merchant account ID to search for.
A merchant account ID to be excluded from the search.
A prefix for the merchant account ID to search for.
The date the subscription will next be billed.
.planId(…)multiple
A list of plan IDs to search for.
The price of the subscription.
.status(…)multiple

The status of the subscription. Possible values:

  • ACTIVE
  • CANCELED
  • PAST_DUE
  • PENDING
  • EXPIRED
The transaction ID associated with the subscription.

Examplesanchor

Searching by priceanchor

Searching on price uses a range field.

  1. Java
SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .price().between(new BigDecimal(5), new BigDecimal(15));

ResourceCollection<Subscription> collection = gateway.subscription().search(request);

Searching by plan IDanchor

Searching on plan ID uses a multiple value field.

  1. Java
SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .planId().is("gold_plan");

ResourceCollection<Subscription> collection = gateway.subscription().search(request);

Searching by statusanchor

Searching on status uses a multiple value field.

  1. Java
SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .status().is(Subscription.Status.ACTIVE);

SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .status().in(
    Subscription.Status.ACTIVE,
    Subscription.Status.CANCELED,
    Subscription.Status.EXPIRED,
    Subscription.Status.PAST_DUE,
    Subscription.Status.PENDING
  );

ResourceCollection<Subscription> collection = gateway.subscription().search(request);

When searching for subscriptions that are active, you have the ability to search for all active subscriptions (with or without a trial period), subscriptions with a trial period, or subscriptions without a trial period.

  1. Java
SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .status().is(Subscription.Status.ACTIVE);

SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .status().is(Subscription.Status.ACTIVE)
  .inTrialPeriod().is(true);

SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .status().is(Subscription.Status.ACTIVE)
  .inTrialPeriod().is(false);

Searching by days past dueanchor

Searching on days past due uses a range field.

  1. Java
SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .daysPastDue().greaterThanOrEqualTo(42);

ResourceCollection<Subscription> collection = gateway.subscription().search(request);

Searching by merchant account IDanchor

Searching on merchant account ID acts like a multiple value field.

  1. Java
SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .merchantAccountId().in("42", "43");

ResourceCollection<Subscription> collection = gateway.subscription().search(request);

Searching by billing cycles remaininganchor

Searching on billing cycles remaining will find subscriptions which have a set limit to the number of times they will recur. It uses a range field.

  1. Java
SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .billingCyclesRemaining().between(1, 2);

ResourceCollection<Subscription> collection = gateway.subscription().search(request);

Searching by next billing dateanchor

Searching on next billing date will return subscriptions that will bill again during the date range you have given it. The example below will return any subscriptions that will be billed in the next five days.

  1. Java
Calendar expectedNextBillingDate = Calendar.getInstance();
expectedNextBillingDate.add(Calendar.DAY_OF_MONTH, 5);

SubscriptionSearchRequest search = new SubscriptionSearchRequest()
  .nextBillingDate().lessThanOrEqualTo(expectedNextBillingDate);
ResourceCollection<Subscription> results = gateway.subscription().search(search);

Searching by created-at date/timeanchor

Searching on created-at date/time will return subscriptions that were created during the range you have given.

  1. Java
Calendar yesterday = Calendar.getInstance();
yesterday.add(Calendar.DAY_OF_MONTH, -1);
Calendar today = Calendar.getInstance();

SubscriptionSearchRequest searchRequest = new SubscriptionSearchRequest()
  .createdAt().between(
    yesterday,
    today
  );
ResourceCollection<Subscription> collection = gateway.subscription().search(searchRequest);

Searching a combinationanchor

You can combine any of the search fields into a single search.

  1. Java
SubscriptionSearchRequest request = new SubscriptionSearchRequest()
  .planId().is("gold_plan")
  .status().is(Subscription.Status.ACTIVE);

ResourceCollection<Subscription> collection = gateway.subscription().search(request);

See also