Foxy Forum Status

We're no longer responding to questions via our forum, but we will keep it up for historical reasons. If you can't find the answer you're looking for, please visit our knowledge base or contact us. If there's enough interest in the future, we may bring the forum back.

Modifying the subscription datafeed example to send processing reminders

MindSculptMindSculpt Member
in Help edited February 2012
I've got a few threads going here on subscriptions at the interest of getting all these questions answered as soon as possible :)

This question relies around modifying the custom subscription script to send out email reminders to customers that the store will be charging their card in x amount of days. Here's the script I'm working with from the wiki:

At the bottom of this script is a conditional with a similar idea, but runs for soon to expire cards:
// 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

I'm thinking there is a way to create a similar conditional that sends reminders to customers that the store will be charging them soon. Thoughts?
  • lukeluke FoxyCart Team
    Hey MindSculpt. The key think to remember is that the subscriptions datafeed is not a listing of all your active subscriptions:

    The FoxyCart subscription XML datafeed runs once a day, and sends data to the same location configured for your regular data feed. It contains:
    * transaction information for subscriptions that are either past due,
    * subscriptions that were canceled (on the day of the datafeed),
    * subscriptions that have a subscription end date set, and
    * customer information for customers whose payment methods are about to expire.

    What you're describing would probably be done best via the API and a cron script on your server to query for just the active subscriptions you're interested in at that time.

    I see what you're trying to accomplish and that does make sense. If you could request it on our features page, that would be great:
  • MindSculptMindSculpt Member
    edited February 2012
    @luke Ah, ok. That is the #1 issue I was hoping to address transitioning to the use of foxycart. I've found that no matter how clear you are up front about how recurring billing works, customers still forget completely.

    Is there no way to grab a common value during the daily subscription ping, maybe make a separate transaction API call and then figure out who needs an email reminder? It's kind of a hack but it seems like something like this could be done.

    Also, what's the easiest way to actually test subscriptions w/o waiting for them to run themselves?
  • fc_adamfc_adam FoxyCart Team

    You can use the API to modify a subscription as required (give it overdue payments, set it to cancel etc) and then refeed the subscription datafeed also with the API. You can also manually feed the example datafeed ( which contains a few different examples of what you can expect.

    You can also use the API to get a list of your current subscriptions using the subcription_list method as described here: and filter subs based on a next transaction date range.
  • MindSculptMindSculpt Member
    edited February 2012
    @fc_adam So only subscriptions that require customer action are sent to the datafeed daily, not all active subscriptions? I wrote up a sample api call that I could run manually from a browser to send notifications, but obviously would rather it be automated some how.

    If manual is the only current solution, i'm assuming you'd create an api call that grabs all the transactions, loop through each to grab the transaction_id, then call the api in another loop to determine renewal dates, then send the notification?
  • lukeluke FoxyCart Team
    Hey MindSculpt. As to your first question, the only thing sent in the subscription datafeed are subscriptions that fall under one of the bullet points I posted above. It does not send all theactive subscriptions.

    As for automating it, that's where I mentioned you'd need a cron task on your server to automatically call a script at whatever interval you prefer to hit the subscription_list API call as Adam mentioned and just filter for the subscriptions you're interested in.

    For example, you could write a PHP script to hit the API and list out all the subscriptions that are going to process in exactly 7 days. You loop through those results and send an email to those customers as a reminder. Next you setup a cron task on your server to call that PHP script with wget every day. That way, every day, customers who will be charged in 7 days are notified of the upcoming charge. For added awesomeness, you can include the sub_token link in the email along with instructions to cancel if the customer would like to cancel before they get charged (the sub_token will be part of the subscriptions_list API call).

    Make sense?
  • MindSculptMindSculpt Member
    edited February 2012
    @luke Yes, that makes sense. Can you provide a barebones example of how that PHP script might look?
  • lukeluke FoxyCart Team
    I'm afraid that's a little beyond the level of support we can provide here in the forum as it relates to your specific business requirements, but this page has a PHP script example that should be somewhat helpful:

    To get started, I'd put together a simple PHP test script and hit subscription_list with various filters to see how things work and what type of data you get back. If you like, we can recommend a developer for you who could help further.
  • MindSculptMindSculpt Member
    edited February 2012
    @luke I've got the basic code set up, just confused around in which order to integrate the api loop. I didn't see syntax in the wiki for how to actually use filters with the api. Is it just setting another $foxyData array option?
  • lukeluke FoxyCart Team
    Based on that example, yes, since that's the data being sent to the API via the curl method. So if you wanted to see subscriptions that will run from 2/22/2012 to 2/28/12, you'd use this filter:
    $foxyData['next_transaction_date_filter_begin'] = '2012-02-22';
    $foxyData['next_transaction_date_filter_end'] = '2012-02-28';
Sign In or Register to comment.