I recently began integrating the Chargify service into a web app I am coding for codeigniter. Chargify is seems to be a slick web service for creating subscription based services. They provide a strong API, and along with a slick web based dashboard (GUI). One of the points on using the API are Chargify postbacks. I did some quick googling and didn’t turn up much in the way of chargify and codeigniter. I did find a great library for integrating the API called ChargeIgniter.
Chargify will send a json array back a POST var to your site. The docs for Chargify don’t state what variable they are submitted as. This is what I came up with.
function post_back(){ $body = file_get_contents("php://input"); $replace = array('[', ']'); $replacements = array('', ''); $body = explode(',', str_replace($replace, $replacements, $body)); //$body now contains array of subscription ID's //Iterate through returned subscription IDs foreach($body as $subscription_id){ $subscription = $this->chargify->get_subscription($subscription_id); //Do something here with $subscription details } } |