---- dataentry ----
type : integration # do not change this line
systems : PHP5 # the system(s) that the integration is for, separated with commas if more than one
name : Exmaple subscription datafeed processor # the name of the integration
description : For v050+, should give you some ideas for automating your billing and payment card reminders.
tags : datafeed, subscriptions, php # tags, separated by commas. don't include the "system" here.
date_dt : 2009-03-15 # the date in YYYY-MM-DD format
version : 050 # if you have a version for your code, enter it here
developer_url : https://www.foxycart.com # if you'd like a link back to your site, stick it here
----
====== Subscription Datafeed ======
//**Please note:**//
The code on this page is submitted by members of the FoxyCart community, and may not verified by FoxyCart.com LLC in any way, shape, or form. Please double check the code before installing. If you need help with it please [[http://forum.foxycart.com/|post in our forum]], but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance.
===== Description =====
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.
===== Installation =====
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 your script throughly before turning on your datafeed in the FoxyCart admin.
===== Requirements =====
PHP5+
===== Code =====
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";
}
}
?>