Subscription Dunning Emails in Foxycart and OrderDesk

EpotratzEpotratz Member
in Help edited November 2016
Hello,

It seems that Foxycart only allows for a single Dunning email based on the single "language" field in the admin. (i.e., the customer will get the same email on the 1st, 2nd, and 3rd reminder) However, based on what I've stumbled upon in OrderDesk after integrating with Foxycart, it looks like I can create multiple Dunning email templates based on the number of "days after failed payment".

Will the OrderDesk schedule be reset each time I reattempt (and fail) a charge in Foxycart based on the "Failed transactions reattempt schedule"? (see attached)

And is the OrderDesk dunning email timing influenced by the "reminder email schedule" in the Foxycart admin? (see attached) In other words, should I remove the "reminder email schedule" in Foxycart, and use the OrderDesk Dunning feature instead to avoid sending duplicate dunning emails?

Thanks.

image

Comments
  • fc_romanfc_roman Member, FoxyCart Team
    Hi @Epotratz,

    Using FoxyCart only, you can modify the text of email message based on the value of the days_since_first_failed_transaction Twig variable.

    With OrderDesk, you'd be able to set up your own processing rules based on what the datafeed contains, for example, a subscription error. This approach does not require any programming expertise, as they will process the datafeed for you. In this case you should be able to dismiss the rules inside FoxyCart once you've developed your own in OrderDesk.

    In the same vein, we are currently working on a Zapier integration to let you create rules based on the datafeed content. If you can afford to wait a few weeks, this could be a major boon to your store management and subscription management.

    Each number in the screenshot represents the number of days after the _initial_ failure, that is, it should not reset upon subsequent failures.
  • Hey @fc_roman,

    1) regarding the days_since_first_failed_transaction Twig variable, how would I send different emails for the 1st, 2nd, and 3rd dunning email? Also, I don't see any reference to days_since_first_failed_transaction here: https://wiki.foxycart.com/v/2.0/templates/view_data

    Am I missing something?

    2) And what advantages would the Zapier integration would offer?

    Thanks.
  • fc_adamfc_adam FoxyCart Team
    @Epotratz,

    Just to jump back quickly to your first post to clarify, the reminder options you see in OrderDesk are completely separate to the dunning options you see in the FoxyCart administration, the settings of each won't have any effect on the other.
    regarding the days_since_first_failed_transaction Twig variable, how would I send different emails for the 1st, 2nd, and 3rd dunning email?
    You could simply set up an if statement to change the content of the email, such as:
    {% if days_since_first_failed_transaction == 1 %}
    {# First email #}
    {% elseif days_since_first_failed_transaction == 15 %}
    {# Second email #}
    {% elseif days_since_first_failed_transaction == 30 %}
    {# Third email #}
    {% endif %}
    Also, I don't see any reference to days_since_first_failed_transaction here: https://wiki.foxycart.com/v/2.0/templates/view_data
    Ah sorry - looks like we missed adding that reference there. We'll get that updated.
    And what advantages would the Zapier integration would offer?
    For your dunning requirements, you'd probably still want to use our default functionality here. Our Zapier integration will allow you to feed information about transactions on to a whole host of other services though much easier - negating the need to set up a custom datafeed endpoint like you do now for sending data on to third-party services.
  • EpotratzEpotratz Member
    edited November 2016
    Hey @fc_adam,

    So i would write out the entire HTML email within these braces: {# First email #}, {# Second email #}, etc ?

    And this statement below would replace the highlighted section in the template below??

    {% if days_since_first_failed_transaction == 1 %}
    {# First email #}
    {% elseif days_since_first_failed_transaction == 15 %}
    {# Second email #}
    {% elseif days_since_first_failed_transaction == 30 %}
    {# Third email #}
    {% endif %}
    imagehttps://gmkr.io/s/582264997858fd9867b2c19f/0" />


    Thanks!
  • fc_adamfc_adam FoxyCart Team
    @Epotratz,

    It depends how much you need to customise. If it's just changing a specific language string, you can just replace that specific language string in the template with that if/else conditional block.

    The code you highlighted is not what you'd replace. That section is updating a twig placeholder contained within a language string to be the actual value. We don't currently support twig placeholders within the language strings - so that's a little bit of code that does the replacing for the "html message subscription dunning reminder" language string.

    Or is that the string you want to change depending on the days past?
  • EpotratzEpotratz Member
    edited November 2016
    @fc_adam,

    Are you're suggesting the if/elseif code should be put into the html message subscription dunning reminder: field in the language section of the admin? And nothing will need to be changed in the email template itself?

    And I now see the email_html_message_subscription_dunning_reminder code in the email template matches the <label for= value for the language field in Foxycart admin. This explicit connection between templates and language 'strings' was not clear to me until just now.
    That section is updating a twig placeholder contained within a language string to be the actual value.
    Apparently I still don't know where these twig sections are beginning <> ending. Can you highlight the full "section" for me that you are referencing?

    And now I'm wondering, how do I create a failed credit card charge in a test environment so I can see this dunning email?

    Thanks!
  • fc_adamfc_adam FoxyCart Team
    @Epotratz,

    Sorry for the confusion. I'm not suggesting that you place the twig logic in a language string. Our language strings don't currently support including Twig logic - so won't be correctly executed if placed there. Any twig logic will need to be placed within the actual template.

    Maybe let's take a step back. Could you clarify for me exactly what customisations you're wanting to make, and I can then give you some steps to get started on that path.
  • @fc_adam,

    I need to send unique dunning emails after 1 day, 15 days, and 30 days of a failed transaction. We'd like each dunning email to be unique (e.g., "Your card was declined", "Your card was declined again", etc.)

    In addition, I also need to customize our email template with our branding, and move a few blocks of Twig content around in the email, so it would be helpful to know where the Twig sections begin <> end. I'm watching some Twig tutorials to get a better grasp on this syntax, but it would still be helpful to have an example.

  • fc_adamfc_adam FoxyCart Team
    @Epotratz,

    One quick follow-up question - Is there just one or two specific sections of the dunning email that you need to customise - for example just maybe the subject, main title and main body, or would it be a brand new email entirely?
  • @fc_adam,

    I'd like to update the subject, and the body text.

    But I have yet to see an actual dunning email because I don't know how to trigger one in a test environment.
  • fc_adamfc_adam FoxyCart Team
    @Epotratz,

    Thanks for confirming - and just to mention as well, I'm sorry that it's as confusing as it is to work with the email template. Because of the inlined styles, and it handling multiple different kinds of emails, the Twig logic can get a bit full on. We are discussing future changes to make this easier to work with.

    So for now - let's focus on changing the subject and body text for the dunning emails. The subject can be customised by using some special Twig logic - and so we can do that when we change the body as well.

    First things first, we need to find where the body text is output. Within the HTML email template - it looks like this:
    <!-- MESSAGE -->
    <table cellspacing="0" cellpadding="0" id="fc-message" style="margin: 0;padding: 0;font-family: Verdana, Helvetica, Arial, sans-serif;width: 100%;">
    <tr style="margin: 0;padding: 0;font-family: Verdana, Helvetica, Arial, sans-serif;">
    <td style="margin: 0;padding: 0;font-family: Verdana, Helvetica, Arial, sans-serif;">
    <p style="margin: 0;padding: 0;font-family: Verdana, Helvetica, Arial, sans-serif;line-height: 20px;margin-bottom: 30px;">
    {% if is_order %}
    {{ config.lang.email_html_message_order|replace({
    '{{ config.store_domain }}': config.store_domain
    })|raw }}
    {% elseif is_subscription_dunning_reminder %}
    {% set sub = subscriptions|first %}
    {% if sub %}
    {{ config.lang.email_html_message_subscription_dunning_reminder|replace({
    '{{ sub_token_url }}': sub.sub_token_url
    })|replace(
    {
    '{{ days_since_first_failed_transaction }}': days_since_first_failed_transaction
    })|raw }}
    {% endif %}
    {% elseif is_updateinfo %}
    {{ config.lang.email_message_updateinfo|replace({
    '{{ config.store_domain }}': config.store_domain
    })|raw }}
    {% elseif is_subscription_modification %}
    {{ config.lang.email_message_subscription_modification|raw }}
    {% elseif is_subscription_cancel %}
    {% if is_subscription_dunning_cancellation %}
    {{ config.lang.email_message_subscription_dunning_cancel|raw }}
    {% else %}
    {{ config.lang.email_message_subscription_cancel|raw }}
    {% endif %}
    {% endif %}
    </p>
    </td>
    </tr>
    </table>
    <!-- /MESSAGE -->
    You'll see within this is an if/elseif/else block of logic which changes what language string is being output to the page. Within that - as we're just after dunning - this is the relevant code:
    {% elseif is_subscription_dunning_reminder %}
    {% set sub = subscriptions|first %}
    {% if sub %}
    {{ config.lang.email_html_message_subscription_dunning_reminder|replace({
    '{{ sub_token_url }}': sub.sub_token_url
    })|replace(
    {
    '{{ days_since_first_failed_transaction }}': days_since_first_failed_transaction
    })|raw }}
    {% endif %}
    You can then customise this to output your own text as needed. That could look like this:
    {% elseif is_subscription_dunning_reminder %}
    {% set sub = subscriptions|first %}
    {% if sub %}
    {% if days_since_first_failed_transaction == 1 %}
    {% set custom_subject = 'custom email subject for ' ~ days_since_first_failed_transaction ~ ' days since failure' %}
    {{ custom_subject|fc_output_data('email_subject') }}

    <p>Your custom message for first dunning email</p>
    {% elseif days_since_first_failed_transaction == 15 %}
    {% set custom_subject = 'Second custom email subject for ' ~ days_since_first_failed_transaction ~ ' days since failure' %}
    {{ custom_subject|fc_output_data('email_subject') }}

    <p>Your custom message for second dunning email</p>
    {% elseif days_since_first_failed_transaction == 30 %}
    {% set custom_subject = 'Last custom email subject for ' ~ days_since_first_failed_transaction ~ ' days since failure' %}
    {{ custom_subject|fc_output_data('email_subject') }}

    <p>Your custom message for the third dunning email</p>
    {% else %}
    {{ config.lang.email_html_message_subscription_dunning_reminder|replace({
    '{{ sub_token_url }}': sub.sub_token_url
    })|replace(
    {
    '{{ days_since_first_failed_transaction }}': days_since_first_failed_transaction
    })|raw }}
    {% endif %}
    {% endif %}
    So each if statement there is doing two things. Firstly it's creating a custom email subject and using the special output filter to customise the email subject. This replaces whatever the email subject is set to in the admin with that new string:
    {% set custom_subject = 'Last custom email subject for ' ~ days_since_first_failed_transaction ~ ' days since failure' %}
    {{ custom_subject|fc_output_data('email_subject') }}
    Next it's simply outputting a paragraph tag with the custom message.

    In terms of testing out the dunning email - we don't have a quick way just yet, but you can fake it by altering the Twig variables to match what they'd look like. Add this to the top of the email, and then re-send an email receipt (by clicking the "(email)" link on the corresponding transaction in the admin) for a previous receipt of a subscription:
    {% set is_order = false %}
    {% set is_subscription_dunning_reminder = true %}
    {% set days_since_first_failed_transaction = 5 %}
  • @fc_adam,

    Thanks for the detailed response.

    Where am I putting my custom email subject? Is it (' my custom text here? ')?
  • @fc_adam,

    I input that "testing code", and I can see the dunning reminder at the top of the email, but the remainder of the email looks like a receipt, which doesn't really belong in a dunning email.

    Is this the intended appearance? Or is it just a side-effect of the "testing code"?
  • fc_adamfc_adam FoxyCart Team
    @Epotratz,

    It is intended - as it shows the customer what subscription this past due notice relates to. If you don't want that to appear you can certainly customise the email template to not show it for dunning emails.

    For setting your custom subject - you edit this variable:
    {% set custom_subject = 'Last custom email subject for ' ~ days_since_first_failed_transaction ~ ' days since failure' %}
    That string is including a Twig variable in the middle there - if you just wanted the custom subject to say "Your payment has failed", it would look like this:
    {% set custom_subject = 'Your payment has failed' %}
  • @fc_adam,

    Since I'm not able to test this on a "real" past due transaction, I'm curious about what happens when the new card info is updated.

    Does the charge immediately go through and restart on the day they update their card info? Or does it not charge until the next transaction date?

    Thanks.
  • fc_adamfc_adam FoxyCart Team
    @Epotratz,

    Good question. If the subscription has a past due amount, that is charged straight away. The subscription will then renew on it's normal next date.
  • @fc_adam,

    We have the following code in our email for a custom email subject on failed payments, here:
    {% if days_since_first_failed_transaction == 5 %}
    {% set custom_subject = 'Please update your payment info for Palm Fruit' %}
    {{ custom_subject|fc_output_data('email_subject') }}


    ... and here:
    {% elseif days_since_first_failed_transaction == 25 %}
    {% set custom_subject = 'Last chance to reactivate your Palm Fruit subscription' %}
    {{ custom_subject|fc_output_data('email_subject') }}



    We also have these custom subjects for updates and cancellations:
    {% if is_subscription_modification %}
    {% set email_subject = "Your subscription has been updated" %}
    {{ email_subject|fc_output_data('email_subject') }}
    {% elseif is_subscription_cancel %}
    {% set email_subject = "Your subscription has been cancelled" %}
    {{ email_subject|fc_output_data('email_subject') }}
    {% endif %}



    However, our first failed transaction email that was just sent out had the "Your subscription has been updated" email subject.

    How can we get our email to use the failed payment subject?



    Here is our full email template.
  • fc_adamfc_adam FoxyCart Team
    @Epotratz,

    From that, it sounds like the is_subscription_modification is being incorrectly set to true for a dunning reminder email. I've created a ticket to dig into that and correct it if it is, as a workaround for that now, you can update the twig block at the end of your template like this:
    {% if not is_subscription_dunning_reminder %}
    {% if is_subscription_modification %}
    {% set email_subject = "Your subscription has been updated" %}
    {{ email_subject|fc_output_data('email_subject') }}
    {% elseif is_subscription_cancel %}
    {% set email_subject = "Your subscription has been cancelled" %}
    {{ email_subject|fc_output_data('email_subject') }}
    {% endif %}
    {% endif %}
  • @fc_adam Ok, I got that extra Twig added. I'll keep an eye out for the next dunning reminder.

    Thanks!
Sign In or Register to comment.