Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jessegomez's avatar

Nested IF statement not working with Vendor Email Template

Hi everyone, Can you please help me see what I am doing wrong here? When I cancel a booking and choose the option to refund the amount paid for some reason the BookingCancelled email blade template is not kicking off to the customer. Below is the full code of the email template.

<!--
|--------------------------------------------------------------------------
| BOOKING CANCELLED USER EMAIL
|--------------------------------------------------------------------------
|
|  Available class objects to be used
|  $booking, $refund_status (boolean)
|
|
-->

<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<!-- NAME: ANNOUNCE -->
<!--[if gte mso 15]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ __('emails.booking_cancelled_subject', ['booking_id' => $booking->id]) }}</title>

<style type="text/css">
p{
margin:10px 0;
padding:0;
}
table{
border-collapse:collapse;
}
h1,h2,h3,h4,h5,h6{
display:block;
margin:0;
padding:0;
}
img,a img{
border:0;
height:auto;
outline:none;
text-decoration:none;
}
body,#bodyTable,#bodyCell{
height:100%;
margin:0;
padding:0;
width:100%;
}
.mcnPreviewText{
display:none !important;
}
#outlook a{
padding:0;
}
img{
-ms-interpolation-mode:bicubic;
}
table{
mso-table-lspace:0pt;
mso-table-rspace:0pt;
}
.ReadMsgBody{
width:100%;
}
.ExternalClass{
width:100%;
}
p,a,li,td,blockquote{
mso-line-height-rule:exactly;
}
a[href^=tel],a[href^=sms]{
color:inherit;
cursor:default;
text-decoration:none;
}
p,a,li,td,body,table,blockquote{
-ms-text-size-adjust:100%;
-webkit-text-size-adjust:100%;
}
.ExternalClass,.ExternalClass p,.ExternalClass td,.ExternalClass div,.ExternalClass span,.ExternalClass font{
line-height:100%;
}
a[x-apple-data-detectors]{
color:inherit !important;
text-decoration:none !important;
font-size:inherit !important;
font-family:inherit !important;
font-weight:inherit !important;
line-height:inherit !important;
}
.templateContainer{
max-width:600px !important;
}
a.mcnButton{
display:block;
}
.mcnImage,.mcnRetinaImage{
vertical-align:bottom;
}
.mcnTextContent{
word-break:break-word;
}
.mcnTextContent img{
height:auto !important;
}
.mcnDividerBlock{
table-layout:fixed !important;
}
/*
@tab Page
//section Heading 1
@style heading 1
*/
h1{
/*@editable*/color:#000000;
/*@editable*/font-family:'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
/*@editable*/font-size:40px;
/*@editable*/font-style:normal;
/*@editable*/font-weight:bold;
/*@editable*/line-height:150%;
/*@editable*/letter-spacing:normal;
/*@editable*/text-align:center;
}
/*
@tab Page
//section Heading 2
@style heading 2
*/
h2{
/*@editable*/color:#000000;
/*@editable*/font-family:'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
/*@editable*/font-size:34px;
/*@editable*/font-style:normal;
/*@editable*/font-weight:bold;
/*@editable*/line-height:150%;
/*@editable*/letter-spacing:normal;
/*@editable*/text-align:left;
}
/*
@tab Page
//section Heading 3
@style heading 3
*/
h3{
/*@editable*/color:#000000;
/*@editable*/font-family:'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
/*@editable*/font-size:22px;
/*@editable*/font-style:normal;
/*@editable*/font-weight:bold;
/*@editable*/line-height:150%;
/*@editable*/letter-spacing:normal;
/*@editable*/text-align:left;
}
/*
@tab Page
//section Heading 4
@style heading 4
*/
h4{
/*@editable*/color:#4e5e6a;
/*@editable*/font-family:Georgia, Times, 'Times New Roman', serif;
/*@editable*/font-size:20px;
/*@editable*/font-style:italic;
/*@editable*/font-weight:normal;
/*@editable*/line-height:125%;
/*@editable*/letter-spacing:normal;
/*@editable*/text-align:center;
}
/*
@tab Header
//section Header Container Style
*/
#templateHeader{
/*@editable*/background-color:{{ config('settings.primary_color') ? config('settings.primary_color') : '#007bff' }};
/*@editable*/background-image:none;
/*@editable*/background-repeat:no-repeat;
/*@editable*/background-position:center;
/*@editable*/background-size:cover;
/*@editable*/border-top:0;
/*@editable*/border-bottom:0;
/*@editable*/padding-top:11px;
/*@editable*/padding-bottom:11px;
}
/*
@tab Header
//section Header Interior Style
*/
.headerContainer{
/*@editable*/background-color:#transparent;
/*@editable*/background-image:none;
/*@editable*/background-repeat:no-repeat;
/*@editable*/background-position:center;
/*@editable*/background-size:cover;
/*@editable*/border-top:0;
/*@editable*/border-bottom:0;
/*@editable*/padding-top:0;
/*@editable*/padding-bottom:0;
}
/*
@tab Header
//section Header Text
*/
.headerContainer .mcnTextContent,.headerContainer .mcnTextContent p{
/*@editable*/color:#ffffff;
/*@editable*/font-family:'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
/*@editable*/font-size:16px;
/*@editable*/line-height:150%;
/*@editable*/text-align:left;
}
/*
@tab Header
//section Header Link
*/
.headerContainer .mcnTextContent a,.headerContainer .mcnTextContent p a{
/*@editable*/color:#ffffff;
/*@editable*/font-weight:normal;
/*@editable*/text-decoration:underline;
}
/*
@tab Body
//section Body Container Style
*/
#templateBody{
/*@editable*/background-color:#fafafa;
/*@editable*/background-image:none;
/*@editable*/background-repeat:no-repeat;
/*@editable*/background-position:center;
/*@editable*/background-size:cover;
/*@editable*/border-top:0;
/*@editable*/border-bottom:0;
/*@editable*/padding-top:51px;
/*@editable*/padding-bottom:51px;
}
/*
@tab Body
//section Body Interior Style
*/
.bodyContainer{
/*@editable*/background-color:#transparent;
/*@editable*/background-image:none;
/*@editable*/background-repeat:no-repeat;
/*@editable*/background-position:center;
/*@editable*/background-size:cover;
/*@editable*/border-top:0;
/*@editable*/border-bottom:0;
/*@editable*/padding-top:0px;
/*@editable*/padding-bottom:0px;
}
/*
@tab Body
//section Body Text
*/
.bodyContainer .mcnTextContent,.bodyContainer .mcnTextContent p{
/*@editable*/color:#000000;
/*@editable*/font-family:'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
/*@editable*/font-size:16px;
/*@editable*/line-height:150%;
/*@editable*/text-align:left;
}
/*
@tab Body
//section Body Link
*/
.bodyContainer .mcnTextContent a,.bodyContainer .mcnTextContent p a{
/*@editable*/color:#007bff;
/*@editable*/font-weight:normal;
/*@editable*/text-decoration:underline;
}
/*
@tab Footer
//section Footer Style
*/
#templateFooter{
/*@editable*/background-color:{{ config('settings.secondary_color') ? config('settings.secondary_color') : '#4e5e6a' }};
/*@editable*/background-image:none;
/*@editable*/background-repeat:no-repeat;
/*@editable*/background-position:center;
/*@editable*/background-size:cover;
/*@editable*/border-top:0;
/*@editable*/border-bottom:0;
/*@editable*/padding-top:15px;
/*@editable*/padding-bottom:15px;
}
/*
@tab Footer
//section Footer Interior Style
*/
.footerContainer{
/*@editable*/background-color:#transparent;
/*@editable*/background-image:none;
/*@editable*/background-repeat:no-repeat;
/*@editable*/background-position:center;
/*@editable*/background-size:cover;
/*@editable*/border-top:0;
/*@editable*/border-bottom:0;
/*@editable*/padding-top:0;
/*@editable*/padding-bottom:0;
}
/*
@tab Footer
//section Footer Text
*/
.footerContainer .mcnTextContent,.footerContainer .mcnTextContent p{
/*@editable*/color:#FFFFFF;
/*@editable*/font-family:'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
/*@editable*/font-size:12px;
/*@editable*/line-height:150%;
/*@editable*/text-align:center;
}
/*
@tab Footer
//section Footer Link
*/
.footerContainer .mcnTextContent a,.footerContainer .mcnTextContent p a{
/*@editable*/color:#FFFFFF;
/*@editable*/font-weight:normal;
/*@editable*/text-decoration:underline;
}
@media only screen and (min-width:768px){
.templateContainer{
width:600px !important;
}

}   @media only screen and (max-width: 480px){
body,table,td,p,a,li,blockquote{
-webkit-text-size-adjust:none !important;
}

}   @media only screen and (max-width: 480px){
body{
width:100% !important;
min-width:100% !important;
}

}   @media only screen and (max-width: 480px){
.mcnRetinaImage{
max-width:100% !important;
}

}   @media only screen and (max-width: 480px){
.mcnImage{
width:100% !important;
}

}   @media only screen and (max-width: 480px){
.mcnCartContainer,.mcnCaptionTopContent,.mcnRecContentContainer,.mcnCaptionBottomContent,.mcnTextContentContainer,.mcnBoxedTextContentContainer,.mcnImageGroupContentContainer,.mcnCaptionLeftTextContentContainer,.mcnCaptionRightTextContentContainer,.mcnCaptionLeftImageContentContainer,.mcnCaptionRightImageContentContainer,.mcnImageCardLeftTextContentContainer,.mcnImageCardRightTextContentContainer,.mcnImageCardLeftImageContentContainer,.mcnImageCardRightImageContentContainer{
max-width:100% !important;
width:100% !important;
}

}   @media only screen and (max-width: 480px){
.mcnBoxedTextContentContainer{
min-width:100% !important;
}

}   @media only screen and (max-width: 480px){
.mcnImageGroupContent{
padding:9px !important;
}

}   @media only screen and (max-width: 480px){
.mcnCaptionLeftContentOuter .mcnTextContent,.mcnCaptionRightContentOuter .mcnTextContent{
padding-top:9px !important;
}

}   @media only screen and (max-width: 480px){
.mcnImageCardTopImageContent,.mcnCaptionBottomContent:last-child .mcnCaptionBottomImageContent,.mcnCaptionBlockInner .mcnCaptionTopContent:last-child .mcnTextContent{
padding-top:18px !important;
}

}   @media only screen and (max-width: 480px){
.mcnImageCardBottomImageContent{
padding-bottom:9px !important;
}

}   @media only screen and (max-width: 480px){
.mcnImageGroupBlockInner{
padding-top:0 !important;
padding-bottom:0 !important;
}

}   @media only screen and (max-width: 480px){
.mcnImageGroupBlockOuter{
padding-top:9px !important;
padding-bottom:9px !important;
}

}   @media only screen and (max-width: 480px){
.mcnTextContent,.mcnBoxedTextContentColumn{
padding-right:18px !important;
padding-left:18px !important;
}

}   @media only screen and (max-width: 480px){
.mcnImageCardLeftImageContent,.mcnImageCardRightImageContent{
padding-right:18px !important;
padding-bottom:0 !important;
padding-left:18px !important;
}

}   @media only screen and (max-width: 480px){
.mcpreview-image-uploader{
display:none !important;
width:100% !important;
}

}   @media only screen and (max-width: 480px){
/*
@tab Mobile Styles
//section Heading 1
@tip Make the first-level headings larger in size for better readability on small screens.
*/
h1{
/*@editable*/font-size:30px !important;
/*@editable*/line-height:125% !important;
}

}   @media only screen and (max-width: 480px){
/*
@tab Mobile Styles
//section Heading 2
@tip Make the second-level headings larger in size for better readability on small screens.
*/
h2{
/*@editable*/font-size:26px !important;
/*@editable*/line-height:125% !important;
}

}   @media only screen and (max-width: 480px){
/*
@tab Mobile Styles
//section Heading 3
@tip Make the third-level headings larger in size for better readability on small screens.
*/
h3{
/*@editable*/font-size:20px !important;
/*@editable*/line-height:150% !important;
}

}   @media only screen and (max-width: 480px){
/*
@tab Mobile Styles
//section Heading 4
@tip Make the fourth-level headings larger in size for better readability on small screens.
*/
h4{
/*@editable*/font-size:18px !important;
/*@editable*/line-height:150% !important;
}

}   @media only screen and (max-width: 480px){
/*
@tab Mobile Styles
//section Boxed Text
@tip Make the boxed text larger in size for better readability on small screens. We recommend a font size of at least 16px.
*/
.mcnBoxedTextContentContainer .mcnTextContent,.mcnBoxedTextContentContainer .mcnTextContent p{
/*@editable*/font-size:14px !important;
/*@editable*/line-height:150% !important;
}

}   @media only screen and (max-width: 480px){
/*
@tab Mobile Styles
//section Header Text
@tip Make the header text larger in size for better readability on small screens.
*/
.headerContainer .mcnTextContent,.headerContainer .mcnTextContent p{
/*@editable*/font-size:16px !important;
/*@editable*/line-height:150% !important;
}

}   @media only screen and (max-width: 480px){
/*
@tab Mobile Styles
//section Body Text
@tip Make the body text larger in size for better readability on small screens. We recommend a font size of at least 16px.
*/
.bodyContainer .mcnTextContent,.bodyContainer .mcnTextContent p{
/*@editable*/font-size:16px !important;
/*@editable*/line-height:150% !important;
}

}   @media only screen and (max-width: 480px){
/*
@tab Mobile Styles
//section Footer Text
@tip Make the footer content text larger in size for better readability on small screens.
*/
.footerContainer .mcnTextContent,.footerContainer .mcnTextContent p{
/*@editable*/font-size:14px !important;
/*@editable*/line-height:150% !important;
}

}</style></head>
<body>
<center>
<table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable">
<tr>
<td align="center" valign="top" id="bodyCell">
<!-- BEGIN TEMPLATE // -->
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center" valign="top" id="templateHeader" data-template-container>
<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600" style="width:600px;">
<tr>
<td align="center" valign="top" width="600" style="width:600px;">
<![endif]-->
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" class="templateContainer">
<tr>
<td valign="top" class="headerContainer"><table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnImageBlock" style="min-width:100%;">
<tbody class="mcnImageBlockOuter">
<tr>
<td valign="top" style="padding:0px" class="mcnImageBlockInner">
<table align="left" width="100%" border="0" cellpadding="0" cellspacing="0" class="mcnImageContentContainer" style="min-width:100%;">
<tbody><tr>
<td class="mcnImageContent" valign="top" style="padding-right: 0px; padding-left: 0px; padding-top: 0; padding-bottom: 0;">


<img align="left" alt="{{ config('settings.business_name') }}" src="{{ asset('images/logo-light.png') }}" width="250" style="max-width:500px; padding-bottom: 0; display: inline !important; vertical-align: bottom;" class="mcnRetinaImage">


</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody>
</table></td>
</tr>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
<tr>
<td align="center" valign="top" id="templateBody" data-template-container>
<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600" style="width:600px;">
<tr>
<td align="center" valign="top" width="600" style="width:600px;">
<![endif]-->
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" class="templateContainer">
<tr>
<td valign="top" class="bodyContainer"><table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnTextBlock" style="min-width:100%;">
<tbody class="mcnTextBlockOuter">
<tr>
<td valign="top" class="mcnTextBlockInner" style="padding-top:9px;">
<!--[if mso]>
<table align="left" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100%;">
<tr>
<![endif]-->

<!--[if mso]>
<td valign="top" width="600" style="width:600px;">
<![endif]-->
<table align="left" border="0" cellpadding="0" cellspacing="0" style="max-width:100%; min-width:100%;" width="100%" class="mcnTextContentContainer">
<tbody><tr>

<td valign="top" class="mcnTextContent" style="padding-top:0; padding-right:18px; padding-bottom:9px; padding-left:18px;">

<p style="text-align: left;"><strong><span style="font-size:24px">{{ __('emails.greeting') }}  {{ $booking->first_name }} {{ $booking->last_name }}!</span></strong><br>
<br>
{{ __('emails.booking_cancelled_message', ['booking_id' => $booking->id]) }}<br>
<br>
@if($refund_status)
@if(!$booking->invoice->is_partial == 1 && $booking->invoice->is_paid == 0)
    Your payment of ${{ $booking->invoice->is_partial ? $booking->invoice->amount_paid : }} was refunded via {{ $booking->invoice->payment_method }}. If you have any questions, please contact
    us.

@else

    Your payment of ${{ $booking->invoice->amount_paid }} was not refundable. If you have any questions, please contact
    us.

@endif
@endif
<br>
</td>
</tr>
<tr>
<td valign="top" class="mcnTextContent" style="padding-top:0; padding-right:18px; padding-bottom:9px; padding-left:18px;">

<p style="text-align: left;"><strong><span style="font-size:24px">{{ __('emails.greeting') }}  {{ $booking->first_name }} {{ $booking->last_name }}!</span></strong><br>
<br>
{{ __('emails.booking_cancelled_message', ['booking_id' => $booking->id]) }}<br>
<br>
@if($refund_status) 
@if(!$booking->invoice->is_paid == 1 && $booking->invoice->is_partial == 0)

    Your payment of ${{ $booking->invoice->is_paid ? $booking->invoice->amount : }} was refunded via {{ $booking->invoice->payment_method }}. If you have any questions, please contact
    us.

@else

    Your payment of ${{ $booking->invoice->amount }} was not refundable. If you have any questions, please contact
    us.

@endif
@endif
<br>
</td>
</tr>
</tbody></table>
<!--[if mso]>
</td>
<![endif]-->

<!--[if mso]>
</tr>
</table>
<![endif]-->
</td>
</tr>
</tbody>
</table><table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnDividerBlock" style="min-width:100%;">
<tbody class="mcnDividerBlockOuter">
<tr>
<td class="mcnDividerBlockInner" style="min-width: 100%; padding: 18px 18px 25px;">
<table class="mcnDividerContent" border="0" cellpadding="0" cellspacing="0" width="100%" style="min-width: 100%;border-top: 2px solid #EAEAEA;">
<tbody><tr>
<td>
<span></span>
</td>
</tr>
</tbody></table>
<!--
<td class="mcnDividerBlockInner" style="padding: 18px;">
<hr class="mcnDividerContent" style="border-bottom-color:none; border-left-color:none; border-right-color:none; border-bottom-width:0; border-left-width:0; border-right-width:0; margin-top:0; margin-right:0; margin-bottom:0; margin-left:0;" />
-->
</td>
</tr>
</tbody>
</table></td>
</tr>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
<tr>
<td align="center" valign="top" id="templateFooter" data-template-container>
<!--[if (gte mso 9)|(IE)]>
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600" style="width:600px;">
<tr>
<td align="center" valign="top" width="600" style="width:600px;">
<![endif]-->
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" class="templateContainer">
<tr>
<td valign="top" class="footerContainer"><table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnFollowBlock" style="min-width:100%;">
<tbody class="mcnFollowBlockOuter">
<tr>
<td align="center" valign="top" style="padding:9px" class="mcnFollowBlockInner">
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnFollowContentContainer" style="min-width:100%;">
<tbody><tr>
<td align="center" style="padding-left:9px;padding-right:9px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="min-width:100%;" class="mcnFollowContent">
<tbody><tr>
    <td align="center" valign="top" style="padding-top:9px; padding-right:9px; padding-left:9px;">
        <table align="center" border="0" cellpadding="0" cellspacing="0">
            <tbody><tr>
                <td align="center" valign="top">
                    <!--[if mso]>
                    <table align="center" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                    <![endif]-->

                    <!--[if mso]>
                    <td align="center" valign="top">
                    <![endif]-->

                    @if(config('settings.facebook_link'))<table align="left" border="0" cellpadding="0" cellspacing="0" class="mcnFollowStacked" style="display:inline;">
                        <tbody><tr>
                            <td align="center" valign="top" class="mcnFollowIconContent" style="padding-right:10px; padding-bottom:9px;">
                                <a href="{{ config('settings.facebook_link', '#') }}" target="_blank"><img src="https://cdn-images.mailchimp.com/icons/social-block-v2/color-facebook-96.png" alt="Facebook" class="mcnFollowBlockIcon" width="48" style="width:48px; max-width:48px; display:block;"></a>
                            </td>
                        </tr>
                        </tbody>
                    </table>@endif


                    <!--[if mso]>
                    </td>
                    <![endif]-->

                    <!--[if mso]>
                    <td align="center" valign="top">
                    <![endif]-->

                    @if(config('settings.twitter_link'))<table align="left" border="0" cellpadding="0" cellspacing="0" class="mcnFollowStacked" style="display:inline;">
                        <tbody><tr>
                            <td align="center" valign="top" class="mcnFollowIconContent" style="padding-right:10px; padding-bottom:9px;">
                                <a href="{{ config('settings.twitter_link', '#') }}" target="_blank"><img src="https://cdn-images.mailchimp.com/icons/social-block-v2/color-twitter-96.png" alt="Twitter" class="mcnFollowBlockIcon" width="48" style="width:48px; max-width:48px; display:block;"></a>
                            </td>
                        </tr>
                        </tbody>
                    </table>@endif


                    <!--[if mso]>
                    </td>
                    <![endif]-->

                    <!--[if mso]>
                    <td align="center" valign="top">
                    <![endif]-->

                    @if(config('settings.instagram_link'))<table align="left" border="0" cellpadding="0" cellspacing="0" class="mcnFollowStacked" style="display:inline;">
                        <tbody><tr>
                            <td align="center" valign="top" class="mcnFollowIconContent" style="padding-right:10px; padding-bottom:9px;">
                                <a href="{{ config('settings.instagram_link', '#') }}" target="_blank"><img src="https://cdn-images.mailchimp.com/icons/social-block-v2/color-instagram-96.png" alt="Link" class="mcnFollowBlockIcon" width="48" style="width:48px; max-width:48px; display:block;"></a>
                            </td>
                        </tr>
                        </tbody>
                    </table>@endif


                    <!--[if mso]>
                    </td>
                    <![endif]-->

                    <!--[if mso]>
                    <td align="center" valign="top">
                    <![endif]-->

                    @if(config('settings.google_plus_link'))<table align="left" border="0" cellpadding="0" cellspacing="0" class="mcnFollowStacked" style="display:inline;">
                        <tbody><tr>
                            <td align="center" valign="top" class="mcnFollowIconContent" style="padding-right:10px; padding-bottom:9px;">
                                <a href="{{ config('settings.google_plus_link', '#') }}" target="_blank"><img src="https://cdn-images.mailchimp.com/icons/social-block-v2/color-googleplus-96.png" alt="Google Plus" class="mcnFollowBlockIcon" width="48" style="width:48px; max-width:48px; display:block;"></a>
                            </td>
                        </tr>
                        </tbody>
                    </table>@endif


                    <!--[if mso]>
                    </td>
                    <![endif]-->

                    <!--[if mso]>
                    </tr>
                    </table>
                    <![endif]-->
                </td>
            </tr>
            </tbody></table>
    </td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>

</td>
</tr>
</tbody>
</table><table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnTextBlock" style="min-width:100%;">
<tbody class="mcnTextBlockOuter">
<tr>
<td valign="top" class="mcnTextBlockInner" style="padding-top:9px;">
<!--[if mso]>
<table align="left" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100%;">
<tr>
<![endif]-->

<!--[if mso]>
<td valign="top" width="600" style="width:600px;">
<![endif]-->
<table align="left" border="0" cellpadding="0" cellspacing="0" style="max-width:100%; min-width:100%;" width="100%" class="mcnTextContentContainer">
<tbody><tr>

<td valign="top" class="mcnTextContent" style="padding-top:0; padding-right:18px; padding-bottom:9px; padding-left:18px;">

{{ __('emails.spam_notice') }}<br>
<br>
<em>{{ __('auth.copyrights') }}. &copy; {{ date('Y') }}. {{ __('auth.rights_reserved') }} {{ config('settings.business_name', 'Bookify') }}.</em>
</td>
</tr>
</tbody></table>
<!--[if mso]>
</td>
<![endif]-->

<!--[if mso]>
</tr>
</table>
<![endif]-->
</td>
</tr>
</tbody>
</table></td>
</tr>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</table>
<!-- // END TEMPLATE -->
</td>
</tr>
</table>
</center>
</body>
</html>

This is the code with the nested IF statements:

<table align="left" border="0" cellpadding="0" cellspacing="0" style="max-width:100%; min-width:100%;" width="100%" class="mcnTextContentContainer">
<tbody><tr>

<td valign="top" class="mcnTextContent" style="padding-top:0; padding-right:18px; padding-bottom:9px; padding-left:18px;">

<p style="text-align: left;"><strong><span style="font-size:24px">{{ __('emails.greeting') }}  {{ $booking->first_name }} {{ $booking->last_name }}!</span></strong><br>
<br>
{{ __('emails.booking_cancelled_message', ['booking_id' => $booking->id]) }}<br>
<br>
@if($refund_status)
@if(!$booking->invoice->is_partial == 1 && $booking->invoice->is_paid == 0)
    Your payment of ${{ $booking->invoice->is_partial ? $booking->invoice->amount_paid : }} was refunded via {{ $booking->invoice->payment_method }}. If you have any questions, please contact
    us.

@else

    Your payment of ${{ $booking->invoice->amount_paid }} was not refundable. If you have any questions, please contact
    us.

@endif
@endif
<br>
</td>
</tr>
<tr>
<td valign="top" class="mcnTextContent" style="padding-top:0; padding-right:18px; padding-bottom:9px; padding-left:18px;">

<p style="text-align: left;"><strong><span style="font-size:24px">{{ __('emails.greeting') }}  {{ $booking->first_name }} {{ $booking->last_name }}!</span></strong><br>
<br>
{{ __('emails.booking_cancelled_message', ['booking_id' => $booking->id]) }}<br>
<br>
@if($refund_status) 
@if(!$booking->invoice->is_paid == 1 && $booking->invoice->is_partial == 0)

    Your payment of ${{ $booking->invoice->is_paid ? $booking->invoice->amount : }} was refunded via {{ $booking->invoice->payment_method }}. If you have any questions, please contact
    us.

@else

    Your payment of ${{ $booking->invoice->amount }} was not refundable. If you have any questions, please contact
    us.

@endif
@endif
<br>
</td>
</tr>
</tbody></table>
0 likes
12 replies
Snapey's avatar

The content of the template should not have any influence on whether it gets sent or not?

Unless it throws an error, which would be evident in error logs or failed queue jobs

jessegomez's avatar

Yeah nothing in the logs. If I remove the nested IF statements it works. This confirms to me that is not an issue with the controller. So I am not sure why adding nested IF statements after a boolean “$refund_status” class it doesn’t work? I need those IF statements but I cannot figure why is not working? Any advise is highly appreciate it. Thank you.

@if($refund_status)
Your payment of ${{ $booking->invoice->amount }} was refunded via {{ $booking->invoice->payment_method }}. If you have any questions, please contact us.
@else
Your payment of ${{ $booking->invoice->amount }} was not refundable. If you have any questions, please contact
us.
@endif
Snapey's avatar

Rethink what you are doing.

Work out in the controller if you are sending a refund. I assume you have actually sent refund or not. This is just confirmation.

Send the email appropriate to what happened. You have been refunded or you have not been refunded (two different mailables)

Putting business logic into the email template is not good practice.

jessegomez's avatar

Thank you for your willingness to help. After examining my code I have come to the conclusion that the issue resides in my controller file. Below is the code in my controller that triggers the mail blade. I am sure the if if and else nested statements within the controller is what's causing the email not to be sent out. I just know what to do at this point? Anyway you can analyze the code and see if you can see some issues or anything that will cause Laravel to skip the sending of the email notification?

/**
*
* Cancel a booking
*
* @param Request $request
* @param $id
* @return \Illuminate\Http\RedirectResponse
*/

public function cancel(Request $request, $id)
{
$input = $request->all();

//find booking
$booking = Booking::find($id);

//refund if selected
if($input['refund_selection'] == 1)
{

//issue refund
$invoice = $booking->invoice()->first();

if($invoice['payment_method'] == __('app.credit_card'))
{
try {
//refund via stripe
if($booking->invoice->is_partial == 1){
if($booking->invoice->amount_left != 0){
//     print_r($booking->invoice->transaction_id);
// exit();
Stripe::refunds()->create($booking->invoice->transaction_id, $booking->invoice->first_payment, [
'reason' => 'requested_by_customer'
]);
}
else{
$transaction_ids = explode(',', $booking->invoice->transaction_id);
Stripe::refunds()->create($transaction_ids[0], $booking->invoice->first_payment, [
'reason' => 'requested_by_customer'
]);
Stripe::refunds()->create($transaction_ids[1], $booking->invoice->second_payment, [
'reason' => 'requested_by_customer'
]);
}
}
else{
Stripe::refunds()->create($booking->invoice->transaction_id, $booking->invoice->amount , [
'reason' => 'requested_by_customer'
]);
}

//cancel booking
$booking->update([
'status' => __('backend.cancelled')
]);

//If have cancel request, set to Completed
$cancel_request = $booking->cancel_request()->first();
if(count($cancel_request))
{
$cancel_request->update([
'status' => __('backend.completed')
]);
}

//update invoice to refunded
$booking->invoice()->update([
'is_refunded' => 1
]);

//update google calendar event if set
if(config('settings.sync_events_to_calendar') && config('settings.google_calendar_id') && $booking->google_calendar_event_id != NULL)
{
$new_status = __('backend.cancelled');
try {
//update google calendar event
$event = Event::find($booking->google_calendar_event_id);
$event->name = $booking->package->category->title." - ".$booking->package->title." ".__('app.booking')." - ".$new_status;
$event->save();
} catch(\Exception $ex) {
//do nothing
}
}

//send email to customer - refund true
try {
Mail::to($booking->email)->send(new BookingCancelled($booking , "1"));
} catch(\Exception $ex) {
//do nothing
}
} catch(\Exception $ex) {
//set stripe refund error and redirect back
Session::flash('stripe_refund_failed', $ex->getMessage());
return redirect()->route('bookings.show', $booking->id);
}
}
else if($invoice['payment_method'] == __('app.paypal'))
{
try {
//refund via paypal - get relative paypal transaction
if($booking->invoice->is_partial == 1){
if($booking->invoice->amount_left != 0){

$payment = Payment::get($booking->invoice->transaction_id, $this->_api_context);
$transactions = $payment->getTransactions();
$resources = $transactions[0]->getRelatedResources();

//get saleID from transaction
$sale = $resources[0]->getSale();
$saleID = $sale->getId();

//set amount and currency
$amt = new Amount();
$amt->setTotal($booking->invoice->first_payment)
->setCurrency(config('settings.default_currency'));

//create refund request
$refund = new RefundRequest();
$refund->setAmount($amt);


//set saleID for refund
$sale = new Sale();
$sale->setId($saleID);


//execute refund
$sale->refundSale($refund, $this->_api_context);

}
else{
$transaction_ids = explode(',', $booking->invoice->transaction_id);
$payment = Payment::get($booking->invoice->transaction_id[0], $this->_api_context);
$transactions = $payment->getTransactions();
$resources = $transactions[0]->getRelatedResources();

//get saleID from transaction
$sale = $resources[0]->getSale();
$saleID = $sale->getId();

//set amount and currency
$amt = new Amount();
$amt->setTotal($booking->invoice->first_payment)
->setCurrency(config('settings.default_currency'));

//create refund request
$refund = new RefundRequest();
$refund->setAmount($amt);


//set saleID for refund
$sale = new Sale();
$sale->setId($saleID);


//execute refund
$sale->refundSale($refund, $this->_api_context);

///////////////////////////////////////

$payment = Payment::get($booking->invoice->transaction_id[1], $this->_api_context);
$transactions = $payment->getTransactions();
$resources = $transactions[0]->getRelatedResources();

//get saleID from transaction
$sale = $resources[0]->getSale();
$saleID = $sale->getId();

//set amount and currency
$amt = new Amount();
$amt->setTotal($booking->invoice->second_payment)
->setCurrency(config('settings.default_currency'));

//create refund request
$refund = new RefundRequest();
$refund->setAmount($amt);


//set saleID for refund
$sale = new Sale();
$sale->setId($saleID);


//execute refund
$sale->refundSale($refund, $this->_api_context);

}
}
else{

$payment = Payment::get($booking->invoice->transaction_id, $this->_api_context);
$transactions = $payment->getTransactions();
$resources = $transactions[0]->getRelatedResources();

//get saleID from transaction
$sale = $resources[0]->getSale();
$saleID = $sale->getId();

//set amount and currency
$amt = new Amount();
$amt->setTotal($booking->invoice->amount)
->setCurrency(config('settings.default_currency'));

//create refund request
$refund = new RefundRequest();
$refund->setAmount($amt);


//set saleID for refund
$sale = new Sale();
$sale->setId($saleID);


//execute refund
$sale->refundSale($refund, $this->_api_context);

}

//cancel booking
$booking->update([
'status' => __('backend.cancelled')
]);

//If have cancel request, set to Completed
$cancel_request = $booking->cancel_request()->first();
if(count($cancel_request))
{
$cancel_request->update([
'status' => __('backend.completed')
]);
}

//update invoice to refunded
$booking->invoice()->update([
'is_refunded' => 1
]);

//update google calendar event if set
if(config('settings.sync_events_to_calendar') && config('settings.google_calendar_id') && $booking->google_calendar_event_id != NULL)
{
$new_status = __('backend.cancelled');
try {
//update google calendar event
$event = Event::find($booking->google_calendar_event_id);
$event->name = $booking->package->category->title." - ".$booking->package->title." ".__('app.booking')." - ".$new_status;
$event->save();
} catch(\Exception $ex) {
//do nothing
}
}

//send email to customer - refund true
try {
Mail::to($booking->email)->send(new BookingCancelled($booking , "1"));
} catch(\Exception $ex) {
//do nothing
}
} catch(\Exception $ex) {
//set paypal refund error and redirect back
Session::flash('paypal_refund_failed', $ex->getMessage());
return redirect()->route('bookings.show', $booking->id);
}
}
else if($invoice['payment_method']== __('app.offline_payment'))
{
//cancel booking
$booking->update([
'status' => __('backend.cancelled')
]);

//If have cancel request, set to Completed
$cancel_request = $booking->cancel_request()->first();
if(count($cancel_request))
{
$cancel_request->update([
'status' => __('backend.completed')
]);
}

//update invoice to refunded
$booking->invoice()->update([
'is_refunded' => 1
]);

//update google calendar event if set
if(config('settings.sync_events_to_calendar') && config('settings.google_calendar_id') && $booking->google_calendar_event_id != NULL)
{
$new_status = __('backend.cancelled');
try {
//update google calendar event
$event = Event::find($booking->google_calendar_event_id);
$event->name = $booking->package->category->title." - ".$booking->package->title." ".__('app.booking')." - ".$new_status;
$event->save();
} catch(\Exception $ex) {
//do nothing
}
}

//send email to customer - refund true
try {
Mail::to($booking->email)->send(new BookingCancelled($booking , "1"));
} catch(\Exception $ex) {
//do nothing
}
}

}
else
{
//cancel booking
$booking->update([
'status' => __('backend.cancelled')
]);

//If have cancel request, set to Completed
$cancel_request = $booking->cancel_request()->first();
if(count($cancel_request))
{
$cancel_request->update([
'status' => __('backend.completed')
]);
}

//send email to customer - refund false
try {
Mail::to($booking->email)->send(new BookingCancelled($booking, "0"));
} catch (\Exception $ex) {
//do nothing
}
}

//set success message and redirect to bookings.show
Session::flash('booking_cancelled', __('backend.booking_cancelled_message'));
return redirect()->route('bookings.show',$id);
}

The following code within my controller specifies which email template to send:

try {
Mail::to($booking->email)->send(new BookingCancelled($booking, "0"));
} catch (\Exception $ex) {
//do nothing
}
}

Here is the mail "BookingCancelled" file:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class BookingCancelled extends Mailable
{
    use Queueable, SerializesModels;

    public $booking;
    public $refund_status;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($booking, $refund_status)
    {
        $this->booking = $booking;
        $this->refund_status = $refund_status;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $this->subject(__('emails.booking_cancelled_subject', ['booking_id' => $this->booking->id]));
        return $this->view('vendor.emails.BookingCancelled');
    }
}
Snapey's avatar

No, sorry

That is way too much code to have in one function. no wonder you cannot see what is going on.

jessegomez's avatar

no problem thank you for trying. Have a great day! I will continue to troubleshoot and try harder :) Take care!

Snapey's avatar

break it down into functions that you can test individually.

And study some code style suggestions. Its not good practice to just have everything aligned left.

1 like
jessegomez's avatar

For anyone experiencing this issue see notes below. I had some html comments in the blade template <!-- html comment --> and I learned that PHP Laravel blade templates do not like html comments instead a comment is {{-- comment here --}} so this was breaking my code and causing the email not to work.

As far as the nested if statements I was able to execute the code with the correct payment amounts in the body of the cancellation email by doing:

{{-- If booking is paid then execute correct amount in email body --}}
        @if($refund_status == true && $booking->invoice->is_partial == 0)

        Your payment of ${{ $booking->invoice->amount }} was refunded via {{ $booking->invoice->payment_method }}.<br> 
           If you have any questions, please contact us.

        @elseif($refund_status == false && $booking->invoice->is_partial == 0)
        Your payment of ${{ $booking->invoice->amount }} was not refundable.<br>
        If you have any questions, please contact us.

        @endif         
        {{-- If booking is partial then execute correct amount in email body --}}   
        @if($refund_status == true && $booking->invoice->is_partial == 1)

        Your payment of ${{ $booking->invoice->amount_paid }} was refunded via {{ $booking->invoice->payment_method }}. <br>
        If you have any questions, please contact us.

        @elseif($refund_status == false && $booking->invoice->is_partial == 1)

        Your payment of ${{ $booking->invoice->amount_paid }} was not refundable.<br>
        If you have any questions, please contact us.

        @endif

I hope this helps anyone struggling with the same issue I was :).

Snapey's avatar

I had some html comments in the blade template and I learned that PHP Laravel blade templates do not like html comments instead a comment is {{-- comment here --}} so this was breaking my code and causing the email not to work.

No, that is complete rubbish.

You can have any valid html code in an html template.

What can be a problem though is if you don't close the comment, or you close the comment inside a block that is excluded because you have an @if statement inbetween.

jessegomez's avatar

my html comment was in between @if statement that is why it was breaking the code. Silly me! Is better to use {{-- comment here --}} .

Snapey's avatar

Blade comments are better because they don't appear in your output

HTML comments can be seen by the user if they view source

1 like

Please or to participate in this conversation.