Aug 18 2010

Speedy Subscriptions Using Spreedly (Part 4) – Checking for Updates

by Chris

OK let’s recap. So far in this guide I’ve covered: creating your Spreedly account, setting up your subscription plans and (most recently) linking your applications sign-up process to your Spreedly account. The elephant in the room at this point is managing updates and allowing Spreedly to notify our application when users make modifications to their subscription/billing settings or when something goes wrong: like when a credit card expires or a transaction can’t be processed. In this final post I will review how to open the lines of communication between your Spreedly account (a.k.a. your billing system) and your application.

Why is this important?

Some of you may be asking yourselves “what is Chris talking about? I’ve linked up my sign-up form so I’m done, right?” Unfortunately no, your not quite finished. The thing to keep in mind, when working with any kind of third party billing service, is that we’re talking about 2 separate and distinct systems. Your application is not aware of any changes/updates made in the billing system and vice verse.  This is a problem because if a users credit card expires in your billing system you need some way of notifying your application so you can suspend access. Or if your customer cancels their account in your application you need to be sure to update your billing system so they don’t continue to get charged.

This is the same concept when working with PayPal or any other 3rd party payment processor where the transaction takes place on their servers. We need a method for identifying accounts that have changed recently in our billing system so we can make any necessary updates in our application.

Listening for Changes

Spreedly is not shy about telling you when your customer data changes. In fact, when any of your subscribers change, Spreedly will POST a comma separated list of subscriber id’s (your customer id’s) to a URL which you specify. While tooling around your Spreedly accounts general settings you may have noticed a group of fields that start with “Subscribers Changed Notification URL”. This field is where you place the URL that Spreedly should use when POSTing changed accounts back to your application. This page can be part of your application or just a script that has access to  your database, but it needs to be there so that Spreedly has someone to talk to.

When any of your subscribers change within Spreedly, the application will send a POST request to an address you specify in your settings containing a comma separated list of IDs. These are the customer IDs of those subscribers who have changed. So this is Spreedlys way of telling you that account 2, 4, 6 and 8 have changed and you may want to check them out and update your DB accordingly.

As far as the necessary code, basically all we’re talking about is a method of a new or existing controller (using CodeIgniter) looking for the “subscriber_ids” POST variable and processing appropriately:

public function update_customers
{
$ids = explode(',', $this->input->post('subscriber_ids'));

foreach($ids as $id)
{
// get users data from Spreedly

// update your DB with new data
}
}

Pretty easy huh?

Why did this take so long?

This series set a new record for how long it’s taken me to wrap up a post series and I apologize for that. The reason though is because I’ve been taking a good long look at all the payment services out there (they’re popping up all over the place) and have determined that there are others I like better than Spreedly. So as I started to change my mind and focus I spent less time with this service and as a result was unable to share my knowledge as I had planned.

Currently Sign-Up-Sheet.com uses Chargify which won me over shortly after I started this series. However, I have since found another app that I like better called OpenGateway. The details as to why one is better than the other is for another post, but that’s what happened here. I got sidetracked by other options and simply was unable to regain my focus. Stay tuned for additional information on these payment options and let me know if you would like to see another series possibly on OpenGateway (which coincidentally happens to be built on CI) in the comments.

That’s all folks

And that does it for the Spreedly guide. My apologies for taking so long to complete but things got away from me a bit and one thing lead to another. If you think there is something I didn’t cover or have any additional questions please let me know in the comments.

Related posts:

  1. Speedy Subscriptions Using Spreedly (Part 2) – Account Configuration
  2. Speedy Subscriptions Using Spreedly (Part 1) – Overview & Account Setup
  3. Speedy Subscriptions Using Spreedly (Part 3) – The Sign-up Process

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>