How can I tell via API if a customer has cancelled their subscription?

camerongarvie's Avatar

camerongarvie

22 Jan, 2012 10:18 AM

I'm currently dealing with paypal preapproved payments, if that is relevant.

Thanks,

Cameron

  1. Support Staff 1 Posted by Marc Guyer on 23 Jan, 2012 02:27 PM

    Marc Guyer's Avatar

    Hi Cameron -- Probably the best resource for that is here which briefly discusses the raw customers/get API call. However, you might consider using this method for checking status.

    Determining whether or not a customer is canceled via the API is usually left up to a wrapper. Here's the relevant methods of the PHP wrapper (CheddarGetter_Response):

    /**
     * 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;
    }
    
    /**
     * Is this customer's account pending paypal preapproval confirmation?
     *
     * @param $code string your code for the customer - required if more than one customer is in the response
     * @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 getCustomerIsWaitingForPayPal($code = null) {
        $subscription = $this->getCustomerSubscription($code);
        if (
            $subscription['canceledDatetime']
            && strtotime($subscription['canceledDatetime']) <= time()
            && $subscription['cancelType'] == 'paypal-wait'
        ) {
            return true;
        }
        return false;
    }
    
  2. Dean closed this discussion on 18 Jan, 2013 04:33 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