Here's an example script to get you started with parsing the subscription datafeed. Note, this should be the same file that you use for parsing your normal FoxyCart datafeed as well.
This code (heavily modified) will live on your server and you'll put the URL in the FoxyCart admin under the advanced section for datafeeds. Please test you script throughly before turning on your datafeed in the FoxyCart admin.
PHP5+
<?PHP $DataFeedKey = 'XXXXXXXXXXXXXX YOUR DATAFEED KEY HERE XXXXXXXXXXXXXX'; $failedDaysBeforeCancel = 30; $billingReminderFrequencyInDays = 3; $updatePaymentMethodReminderDaysOfTheMonth = array(1,15); if (isset($_POST["FoxyData"])) { // normal datafeed stuff here... } else { // see if we're doing a subscription if (isset($_POST["FoxySubscriptionData"])) { $FoxyData_encrypted = urldecode($_POST["FoxySubscriptionData"]); $FoxyData_decrypted = rc4crypt::decrypt($DataFeedKey,$FoxyData_encrypted); // make sure we have a valid character encoding $enc = mb_detect_encoding($FoxyData_decrypted); $FoxyData_decrypted = mb_convert_encoding($FoxyData_decrypted, 'UTF-8', $enc); $FoxyDataArray = new SimpleXMLElement($FoxyData_decrypted); foreach($FoxyDataArray->subscriptions->subscription AS $subscription) { foreach($subscription->transaction_details->transaction_detail AS $transaction_detail) { // do stuff here, collect data, etc... } $canceled = 0; $sendReminder = 0; if (date("Y-m-d",strtotime("now")) == date("Y-m-d", strtotime($subscription->end_date))) { // this entry was cancelled today... $canceled = 1; } if (!$canceled && $subscription->past_due_amount > 0) { $failedDays = floor((strtotime("now") - strtotime($subscription->transaction_date)) / (60 * 60 * 24)); if ($failedDays > $failedDaysBeforeCancel) { $canceled = 1; } else { if (($failedDays % $billingReminderFrequencyInDays) == 0) { $sendReminder = 1; } } } if ($canceled) { // send emails, update your database, etc... } if ($sendReminder) { // send reminder emails, etc... } } // send emails to customers with soon to expire credit cards. Ignore already expired cards, since they should have already been // sent an email when their payment failed. if (in_array(date("j"),$updatePaymentMethodReminderDaysOfTheMonth)) { foreach($FoxyDataArray->payment_methods_soon_to_expire->customer AS $customer) { if (mktime(0,0,0,$customer->cc_exp_month+1, 1, $customer->cc_exp_year+0) > strtotime("now")) { // email reminders } } } } else { print "error"; } } ?>