Calculating - Cancellation fee

Hi guys,
I'm new here and just tried to make my first snippet with a calculation.
The situation is that depending on the date of cancellation we refund a % of the price.
The goal is that our support just inserts the dates (current day and booking date) and the full amount. According to the days, it should insert automatically the % we refund and the amount.

60 days in advance 10%
45 days in advance 20%
30 days in advance 40%
20 days in advance 70%
12 days in advance 100%

The total amount of your booking € {formtext: name=Total}

{formdate: DD.MM.YYYY; name=today} and {formdate: DD.MM.YYYY; name=booking}

With your cancellation today it is {days=abs({time: X; at={=booking}; pattern=DD.MM.YYYY}-{time: X; at={=today}; pattern=DD.MM.YYYY})} {=floor(days/(606024))} days in advance.

Therefore we can refund you {if: floor(days/(606024))>60; trim=left} {={=0.9; format=.0%}} {elseif: 60>floor(days/(606024))>45; trim=right} {={=0.8; format=.0%}} {endif} of the booking amount,
days in advance and therefore we can refund you

I would be thankful if one of you can give me a hint on how to solve it.
And what I'm doing wrong that the if-condition always gives the error " Cannot convert "yes" to a number.".

Cheers,
Elisa

Hi @Rapturecamps_Elisa_P - welcome to the forum.

You're in luck. This month we launched some new time/date related functions that are just perfect for your use case.

Here's my take on how you can do it.

I've made some pretty significant changes to really take advantage of everything Text Blaze has to offer.

For instance:

  • I used a couple {note} commands to insert notes for the agent, which will not be inserted in the final snippet.
  • I created a keyed list with the time brackets and associated refund amounts, and used it in a number of ways, such as generating the refund policy data for the agent, checking the number of days against the values in the list, and referencing the refund amount accordingly.
  • I used the {if} command to insert text based on conditional logic
  • I used the {error} command to prevent the agent from inserting the snippet unless they've filled in the booking amount.

Have a look and let me know what you think. You can copy the snippet directly to your dashboard by clicking on the "Copy to Text Blaze" button in the top right corner.

{note: trim=right; preview=no}
{days=datetimediff(datetimeparse(booking, "DD.MM.YYYY"), datetimeparse(cancellation, "DD.MM.YYYY"), "D")}
List with cancellation periods (in days) and corresponding refund percentages:
{periods=["60":90, "45":80, "30":60, "20":30, "12":0]}
{bracket=min(filter(keys(periods), item -> days <= item))}
{refund=catch(periods[bracket], "0")}
{endnote: trim=right}

{note: trim=right}
For agent:

Booking date:
{formdate: DD.MM.YYYY; name=booking} ({=datetimeformat(datetimeparse(booking, "DD.MM.YYYY"), "dddd, MMMM Do, YYYY")})
Cancellation date:
{formdate: DD.MM.YYYY; name=cancellation} ({=datetimeformat(datetimeparse(cancellation, "DD.MM.YYYY"), "dddd, MMMM Do, YYYY")})
Difference in days: {=days}

Cancellation refund policy:
{repeat: for period in periods; trim=right}
{=period} days in advance: {if: periods[period] == 0}No{else}{=periods[period]}%{endif} refund.
{endrepeat}
================ END OF NOTES ================

{endnote: trim=right}

Total booking amount: ${formtext: name=total} {if: total <= 0}{error: Fill in booking amount; block=yes}{endif}
Booking date: {=booking}
Cancellation date: {=cancellation}

{if: days > 12; trim=right}
Since you are cancelling {=days} prior to your booking date, we can refund you {=refund}% of the booking amount, which comes to ${=(total/100)*refund}.
{else: trim=right}
Unfortunately, we are unable to refund any part of your booking since your cancellation is less than 12 days prior to your booking date.
{endif: trim=right}

1 Like