Totes McGoats
Totes McGoats

Reputation: 121

How to know if a Recurly subscription will renew at the end of its period?

When viewing an active, non-renewing subscription on the Recurly website, such as

https://xxxxxx.recurly.com/subscriptions/xxxxxxxxba354d5b84812419xxxxxxxx

the Recurly website shows info like this:

Status: Active
Start Date: Feb 9, 2016 7:44 PM UTC
Current Period: Feb 09, 2016 — Mar 09, 2016
Next Invoice: Will not renew
Billing Cycles: 0 renewals remaining (of 1)
End Date: Mar 9, 2016 7:44 PM UTC

Looking up the same subscription using the Recurly API, I cannot figure out how to determine if the subscription will renew. This is PHP, but language doesn't matter:

const TFORMAT = "D d M H:i:s \U\T\C Y";
$sub = Recurly_Subscription::get('xxxxxxxxba354d5b84812419xxxxxxxx');
echo $sub->state;
echo '<br>' . ($sub->activated_at ? $sub->activated_at->format(TFORMAT) : "nope");
echo '<br>' . ($sub->current_period_started_at ? $sub->current_period_started_at->format(TFORMAT) : "nope");
echo '<br>' . ($sub->current_period_ends_at ? $sub->current_period_ends_at->format(TFORMAT) : "nope");
echo '<br>' . ($sub->expires_at ? $sub->expires_at->format(TFORMAT) : "nope");
echo '<br>' . ($sub->canceled_at ? $sub->canceled_at->format(TFORMAT) : "nope");

This outputs:

active
Tue 09 Feb 19:44:48 UTC 2016
Tue 09 Feb 19:44:48 UTC 2016
Wed 09 Mar 19:44:48 UTC 2016
nope
nope

How can I determine if this subscription will renew?

Upvotes: 1

Views: 365

Answers (2)

Totes McGoats
Totes McGoats

Reputation: 121

Sent my request to Recurly Support and got this reply. Hope it helps someone in the future:

A subscription that has a fixed number of billing cycles does not renew. A subscription details API call of this type of subscription would expose the following parameters:

  • total_billing_cycles

  • remaining_billing_cycles

These parameters are not exposed with a renewable subscription.

Therefore by adding (PHP) these lines in the details call will ID whether the subscription is a non-renewing subscription:

// test to determine if the total_billing_cycles parameter is exposed/present

  if (isset($subscription->total_billing_cycles)) {
    // If true...do something
    echo "This subscription will not renew";
  }

I hope this answers your question. Thank you again. Regards,

Ian Recurly Support

Upvotes: 2

Jannik
Jannik

Reputation: 2429

I never used Recurly but it seems like you first have to get the invoice of the subscription.

When you have the invoice, you could use the

<state>open</state>

and

<collection_method>automatic</collection_method>

to calculate, if the subscription will be renewed.

Upvotes: 0

Related Questions