Subscription: Search
Note
Results are limited according to the PayPal Data Protection Addendum For Card Processing Products policy.
- Ruby
collection = gateway.subscription.search do |search|
search.plan_id.is "the_plan_id"
end
collection.each do |subscription|
puts subscription.billing_day_of_month
endSubscription: Find
instead.
;Parameters
The number of billing cycles remaining in the subscription.
:created_atrangeThe date/time the subscription was created.
:days_past_duerangeThe number of days past due the subscription is.
:idtextThe ID of the subscription.
:idsmultipleA list of subscription IDs to search for.
:in_trial_periodmultipleWhether the subscription is in a trial period. Can be true or false. This parameter must be used in conjunction with status.
:merchant_account_idmultipleA 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.
:ends_withtextA postfix for the merchant account ID to search for.
:istextAn exact merchant account ID to search for.
:is_nottextA merchant account ID to be excluded from the search.
:starts_withtextA prefix for the merchant account ID to search for.
:next_billing_daterangeThe date the subscription will next be billed.
:plan_idmultipleA list of plan IDs to search for.
:pricerangeThe price of the subscription.
:statusmultipleThe status of the subscription. Possible values:
ActiveCanceledPastDuePendingExpired
:transaction_idtextThe transaction ID associated with the subscription.
Examples
Searching by price
Searching on price uses a range field.
- Ruby
search_results = gateway.subscription.search do |search|
search.price <= 5
end
search_results = gateway.subscription.search do |search|
search.price.between 3, 10
endSearching by plan ID
Searching on plan ID uses a multiple value field.
- Ruby
search_results = gateway.subscription.search do |search|
search.plan_id.is "gold_plan"
end
search_results = gateway.subscription.search do |search|
search.plan_id.in "silver_plan", "gold_plan"
endSearching by status
Searching on status uses a multiple value field.
- Ruby
search_results = gateway.subscription.search do |search|
search.status.is Braintree::Subscription::Status::Active
end
search_results = gateway.subscription.search do |search|
search.status.in( Braintree::Subscription::Status::Active,
Braintree::Subscription::Status::Canceled,
Braintree::Subscription::Status::Expired,
Braintree::Subscription::Status::PastDue,
Braintree::Subscription::Status::Pending )
end- Ruby
search_results = gateway.subscription.search do |search|
search.status.is Braintree::Subscription::Status::Active
end
search_results = gateway.subscription.search do |search|
search.status.is Braintree::Subscription::Status::Active
search.in_trial_period.is true
end
search_results = gateway.subscription.search do |search|
search.status.is Braintree::Subscription::Status::Active
search.in_trial_period.is false
endSearching by days past due
Searching on days past due uses a range field.
- Ruby
search_results = gateway.subscription.search do |search|
search.days_past_due <= 5
end
search_results = gateway.subscription.search do |search|
search.days_past_due.between 1, 5
endSearching by merchant account ID
Searching on merchant account ID acts like a multiple value
field.
- Ruby
search_results = gateway.subscription.search do |search|
search.merchant_account_id.in "usd_merchant_account", "another"
endSearching 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.
- Ruby
search_results = gateway.subscription.search do |search|
search.billing_cycles_remaining <= 5
endSearching 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.
- Ruby
five_days_from_now = Time.now + (5 * 24 * 60 * 60)
search_results = gateway.subscription.search do |search|
search.next_billing_date <= five_days_from_now
endSearching by created-at date/time
Searching on created-at date/time will return subscriptions that were created during the range you
have given.
- Ruby
search_results = gateway.subscription.search do |search|
search.created_at.between( Time.now - 60*60*24, Time.now )
endSearching a combination
You can combine any of the search fields into a single search.
- Ruby
search_results = gateway.subscription.search do |search|
search.plan_id.is "gold_plan"
search.status.is "Active"
end