{% if order.payments is not empty %} {% set payment = order.payments|first %} {% set Paymentamount = payment.paymentamount %} {# Check if the payment has subscriptions #} {% if payment.subscriptions is not empty %} {% set subscription = payment.subscriptions|first %} {% set subscriptionduration = subscription.duration ~ ' ' ~ (subscription.duration == 1 ? 'Month' : 'Months') %} {# Check if subscription has auto-renewal enabled #} {% if subscription.autorenewal == 1 %} {# Calculate next payment date if auto-renewal is enabled #} {% set nextpayment = subscription.enddate|date('Y-m-d') %} {% else %} {% set nextpayment = 'No next payment' %} {% endif %} {% else %} {% set subscriptionduration = 'No subscription found' %} {% set nextpayment = 'N/A' %} {% endif %} {% else %} {% set Paymentamount = 'No payment found' %} {% set subscriptionduration = 'N/A' %} {% set nextpayment = 'N/A' %} {% endif %}