Chat Message

dave's Avatar

dave

07 May, 2013 07:51 AM

Hi,

I've just signed up to the developer plan and I'm trying to figure out how to use the api for my needs.

What I require is this:

1) User signs up - I have done this with your api
2) Check user has paid this month / initial payment cleared - how do I do this with the api? Is there a user id that I cross reference? I need to check this user has paid the subscription when they login.
3) Allow user access to platform / website.

I've had a look through your api docs and I'd just like some advise on how to achieve this process. Baiscally, when a customer is created, what should I save to the db to allow me to check this user has paid when they login to my site?

Many thanks in advance for your time and support.

Cheers,

Dave.

  1. Support Staff 1 Posted by Marc Guyer on 07 May, 2013 12:24 PM

    Marc Guyer's Avatar

    Hi Dave

    2) Check user has paid this month / initial payment cleared - how do I do this with the api? Is there a user id that I cross reference? I need to check this user has paid the subscription when they login.

    If a transaction occurs on signup (whether for the subscription or a small validation transaction), then there will be an error in the response if the transaction was declined. The subscription is not created unless that transaction is successful. You can also confirm the subscription transaction in the response. It's the first transaction node in the second (previous) invoice node. The PHP wrapper does it like this:

    /**
     * Get an array representation of a single customer's last 
     * transaction (successful or otherwise)
     *
     * @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|false
     */
    public function getCustomerLastTransaction($code = null) {
        $lastBilledInvoice = $this->getCustomerLastBilledInvoice($code);
        if (isset($lastBilledInvoice['transactions'])) {
            return current($lastBilledInvoice['transactions']);
        }
        return false;
    }
    

    Baiscally, when a customer is created, what should I save to the db to allow me to check this user has paid when they login to my site?

    You should check the customer record in CG during your authorization routine. You can use the simple status call:

    http://support.cheddargetter.com/kb/hosted-payment-pages/hosted-pay...

    Just check if the account is active using the API. You'll need this if you want to use tracked items for feature access or usage tracking.

    /**
     * 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;
    }
    

    Mind if I make this thread public?

  2. 2 Posted by dave on 07 May, 2013 08:13 PM

    dave's Avatar

    Hi Marc,

    Thanks for the detailed response. However, I am getting a 'false' returned
    from the method:

    $response -> getCustomerLastTransaction('MyCodeForCustomer');

    I'm not sure if this is why:

    paypal-wait
    PayPal preapproval is pending

    I get the above in the response when creating a new customer using the
    following method:

     $response = $client -> newCustomer($data);

    Is this becuase it's the developer version? I've attached the response to
    this email.

    Ps, by all means make this thread public ;)

    Thanks again for your time. I look forward to your reply.

    Cheers,

    Dave.

  3. Support Staff 3 Posted by Marc Guyer on 07 May, 2013 08:19 PM

    Marc Guyer's Avatar

    That's because you're using PayPal. It's not possible to transaction on the initial request. The transaction occurs after the customer has approved the preapproval. Once you've redirect the customer to PayPal, then pull the customer data, the result of the initial transaction will be there. Have you seen this doc?

    http://support.cheddargetter.com/kb/api-8/using-paypal-with-the-api...

  4. 4 Posted by dave on 07 May, 2013 10:08 PM

    dave's Avatar

    Thanks again Marc,

    That last link explained it better. One question though, how do I check
    that the customer has paid once I've redirected to the PayPal auth, so the
    customer has agreed to pay and they are returned to my returnUrl, I check
    the condition in the url and call this to get the user:

    $customer = $client -> getCustomer($code);

    So basically which parameter tells me they're up to date with their
    payments and PayPal has cleared the funds etc?

    Really appreciate your help with this, you've explained a lot.

    PS, would you mind removing the abs path from the text doc I sent, didn't
    realise that was going to be posted publicly cheers ;)

  5. Support Staff 5 Posted by Marc Guyer on 08 May, 2013 12:17 PM

    Marc Guyer's Avatar

    That's explained briefly in the doc:

    http://support.cheddargetter.com/kb/api-8/using-paypal-with-the-api...

    The API response includes all the information required to make the determination. The PHP method getCustomerIsActive() posted in my comment 2 explains it. In the most basic terms, a customer can be considered in good standing if their current subscription does not have a canceledDatetime.

  6. 6 Posted by dave on 08 May, 2013 01:04 PM

    dave's Avatar

    Perfect, thanks for all the help Marc! :)

  7. Dean closed this discussion on 17 May, 2013 03:13 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