Why does the API return multiple subscriptions per customer?

Jason MacInnes's Avatar

Jason MacInnes

19 Nov, 2011 04:50 PM

Hello,

I am doing some integration with the developer API and I am confused on one point. Why does the API return an array of subscriptions for a single customer? Other discussions on here seem to indicate that a customer has a one to one relationship with a subscription (at least currently).

Is it currently possible to get a result where a single customer record returns multiple subscriptions? If so, what API calls would I make to create such a customer?

Thanks,
Jason

  1. Support Staff 1 Posted by Marc Guyer on 19 Nov, 2011 09:55 PM

    Marc Guyer's Avatar

    If there's more than one subscription in the response, you're seeing a history of plan changes.

    >

  2. 2 Posted by George on 20 Nov, 2011 05:55 PM

    George's Avatar

    I had the same question as Jason. all plans (history changes) show isActive a true. What's the best and simple way to check if a customer's subscription has expired and therefore should not be allowed to use the service?

    thanks

  3. Support Staff 3 Posted by Marc Guyer on 21 Nov, 2011 01:32 PM

    Marc Guyer's Avatar

    I guys. isActive simply indicates whether or not the subscription is canceled.

    What's the best and simple way to check if a customer's subscription has expired and therefore should not be allowed to use the service?

    What do you mean by "expired"? Maybe this will help: the "current" subscription is the latest one. It just so happens to be the first one in the list returned by the API. If the current subscription isActive then the subscription is in good standing as far as CG is concerned.

  4. 4 Posted by George on 21 Nov, 2011 05:33 PM

    George's Avatar

    I created a new customer with paid subscription plan 'A', I then changed it to plan 'B'. Then I cancelled the account.

    Now if I query the customer, I get BOTH subscriptions with isActive = 1

    what I would like to do is find a a way to query the customer record on CG to determine if the customer should be allowed to use my site. in other words I need to determine they still have a valid subscription plan. By valid i mean, the subscription was paid and wasn't cancelled.

    hope this clarifies what I'm doing.

    thanks.

  5. 5 Posted by Jason MacInnes on 21 Nov, 2011 05:34 PM

    Jason MacInnes's Avatar

    Thanks for the clarification, Marc. Follow up question - what about multiple plans returned by a subscription? Is the first one on the list the current plan and the others are the ones that the customer used to subscribe to?

  6. 6 Posted by George on 22 Nov, 2011 07:17 PM

    George's Avatar

    Hey Marc, any thoughts on querying the customer to find out out if they have an active/valid subscription?

    thanks

  7. Support Staff 7 Posted by Marc Guyer on 22 Nov, 2011 09:30 PM

    Marc Guyer's Avatar

    Thanks for the clarification, Marc. Follow up question - what about multiple plans returned by a subscription? Is the first one on the list the current plan and the others are the ones that the customer used to subscribe to?

    That's exactly correct.

    Hey Marc, any thoughts on querying the customer to find out out if they have an active/valid subscription?

    There are two ways to do that. One is quite rudimentary and is documented here: http://support.cheddargetter.com/kb/hosted-payment-pages/hosted-pay.... That would only be relevant if you're using hosted pages.

    The other way is to simply pull the customer data from the API and check the first subscription isActive node. You could also check for a canceledDatetime.

  8. 8 Posted by George on 23 Nov, 2011 01:55 AM

    George's Avatar

    Hi Marc, here are my results based on your feedback. btw, i'm not using hosted pages, so all of the following is done through the APIs.

    -Created a customer (using the APIs)

    -Queried the customer (using curl): isActive is set to 1. No value for canceledDatetime. (this is done using /customers/get/)

    -Canceled the customer (using the APIs)

    -Queried the customer (using curl): isActive is still set to 1. canceledDatetime has a value.

    So either there is a bug causing isActive to be always 1 or I'm still missing something. I can use the canceledDatetime but this strikes me as an odd way of validating a subscription.

    Does this mean i have to do this validation as described in the link you provided like this: $status = file_get_contents('https://yoursite.chargevault.com/status?key=a1b2c3d4e6&code=you...');

    How is everyone else doing it using the APIs then?

    thanks

  9. 9 Posted by George on 24 Nov, 2011 05:29 PM

    George's Avatar

    Marc, any thoughts on how I can achieve that using the APIs rather than using the store URL?

  10. Support Staff 10 Posted by Marc Guyer on 25 Nov, 2011 11:21 PM

    Marc Guyer's Avatar

    -Queried the customer (using curl): isActive is still set to 1. canceledDatetime has a value.

    I checked to verify but didn't find any customers in your account. Can you replicate this and let me take a look?

    So either there is a bug causing isActive to be always 1 or I'm still missing something. I can use the canceledDatetime but this strikes me as an odd way of validating a subscription.

    A subscription being active is somewhat subjective. As such, we do not intend for CG to be the ultimate authority on whether or not a customer has access to your system. We do provide several conveniences but you need to decide how to put it together. For example, even a subscription with a canceledDatetime might be considered active (maybe the customer paid through the end of the current period, for example).

    Maybe we're confusing this with the plans->plan->isActive node. Could that be?

    Marc, any thoughts on how I can achieve that using the APIs rather than using the store URL?

    Have you looked at the API wrappers? The PHP wrapper, for example, has the following method:

    /**
     * Whether or not a customer's subscription is active and in good standing
     *
     * @param $code string your code for the customer - required if more than one customer is in the response
     * @param $remainActiveThroughEndOfPeriod bool Set to true if you'd like the account to remain active until the end of the current payment period rather than inactive at the moment of cancelation
     * @throws CheddarGetter_Response_Exception if the response type is incompatible or if a $code is not provided and the response contains more than one customer
     * @return array
     */
    public function getCustomerIsActive($code = null, $remainActiveThroughEndOfPeriod = false) {
        $subscription = $this->getCustomerSubscription($code);
        if ($subscription['canceledDatetime']) {
            if (strtotime($subscription['canceledDatetime']) <= time()) {
                if ($remainActiveThroughEndOfPeriod) {
                    $invoice = $this->getCustomerInvoice($code);
                    if (strtotime($invoice['billingDatetime']) > time()) {
                        return true;
                    }
                }
                return false;
            }
        }
        return true;
    }
    
  11. Marc Guyer closed this discussion on 05 Dec, 2011 05:04 PM.

Discussions are closed to public comments.
If you need help with Cheddar please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

28 Mar, 2024 10:45 PM
24 Jan, 2024 08:33 AM
11 Jan, 2024 07:13 AM
30 Nov, 2023 02:07 AM
22 Nov, 2023 08:41 AM