Subscription: Search
Note
Results are limited according to the PayPal Data Protection Addendum For Card Processing Products policy.
- Node
const stream = gateway.subscription.search((search) => {
search.planId().is("the_plan_id");
}, (err, response) => {
response.each((err, subscription) => {
console.log(subscription.billingDayOfMonth);
});
});Subscription: Find
instead.
;Parameters
The number of billing cycles remaining in the subscription.
createdAtrangeThe date/time the subscription was created.
daysPastDuerangeThe number of days past due the subscription is.
idtextThe ID of the subscription.
idsmultipleA list of subscription IDs to search for.
inTrialPeriodmultipleWhether the subscription is in a trial period. Can be true or false. This parameter must be used in conjunction with status.
merchantAccountIdmultipleA list of merchant account IDs to search for.
A fragment of the merchant account ID to search for.
containstextA part of the merchant account ID to search for.
endsWithtextA postfix for the merchant account ID to search for.
istextAn exact merchant account ID to search for.
isNottextA merchant account ID to be excluded from the search.
startsWithtextA prefix for the merchant account ID to search for.
nextBillingDaterangeThe date the subscription will next be billed.
planIdmultipleA list of plan IDs to search for.
pricerangeThe price of the subscription.
statusmultipleThe status of the subscription. Possible values:
ActiveCanceledPastDuePendingExpired
transactionIdtextThe transaction ID associated with the subscription.
Search results
All examples assume version
- Node
const stream = gateway.subscription.search((search) => {
search.price().between(5, 15);
});
stream.pipe(someWritableStream);- Node
const stream = gateway.subscription.search((search) => {
search.price().between(5, 15);
});
stream.on("data", (subscription) => {
// ...
});
stream.on("end", () => {
// ...
});
stream.resume();Examples
Searching by price
Searching on price uses a range field.
- Node
const stream = gateway.subscription.search((search) => {
search.price().between(5, 15);
});Searching by plan ID
Searching on plan ID uses a multiple value field.
- Node
const stream = gateway.subscription.search((search) => {
search.planId().is("goldPlan");
});Searching by status
Searching on status uses a multiple value field.
- Node
const stream = gateway.subscription.search((search) => {
search.status().is(braintree.Subscription.Status.Active);
});- Node
const stream = gateway.subscription.search((search) => {
search.status().is(braintree.Subscription.Status.Active);
});- Node
const stream = gateway.subscription.search((search) => {
search.status().is(braintree.Subscription.Status.Active);
search.inTrialPeriod().is(true);
});- Node
const stream = gateway.subscription.search((search) => { search.status().is(braintree.Subscription.Status.Active); search.inTrialPeriod().is(false); });Searching by days past due
Searching on days past due uses a range field.
- Node
const stream = gateway.subscription.search((search) => {
search.daysPastDue().min(42);
});Searching by merchant account ID
Searching on merchant account ID acts like a multiple value
field.
- Node
const stream = gateway.subscription.search((search) => {
search.merchantAccountId().in("42", "43");
});Searching by billing cycles remaining
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.
- Node
const stream = gateway.subscription.search((search) => {
search.billingCyclesRemaining().between(1, 2);
});Searching by next billing date
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.
- Node
const today = new Date();
const fiveDaysFromNow = new Date();
fiveDaysFromNow.setDate(today.getDate() + 5);
const stream = gateway.subscription.search((search) => {
search.nextBillingDate().max(fiveDaysFromNow);
});Searching by created-at date/time
Searching on created-at date/time will return subscriptions that were created during the range you
have given.
- Node
const today = new Date();
const yesterday = new Date();
yesterday.setDate(today.getDate() - 1);
const stream = gateway.subscription.search((search) => {
search.createdAt().between(yesterday, today);
});Searching a combination
You can combine any of the search fields into a single search.
- Node
const stream = gateway.subscription.search((search) => {
search.planId().is("goldPlan");
search.status().is(braintree.Subscription.Status.Active);
});