PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.13
Yatra – Travel Booking & Tour Operator Software v3.0.13
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / app / Services / EmailTemplateSampleData.php

EmailTemplateSampleData.php in Yatra – Travel Booking & Tour Operator Software 3.0.13, at app/Services/EmailTemplateSampleData.php

204 lines 10.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Services;
6
7 use Yatra\Repositories\TripRepository;
8
9 /**
10 * Sample merge-tag data for email previews and tests.
11 * Trip context: pass {@see self::forTemplateKey()} a trip ID to hydrate trip_* tags from the database.
12 *
13 * @see apply_filters('yatra_email_template_preview_variables', ...)
14 * @see apply_filters('yatra_email_template_trip_variables', ...)
15 */
16 final class EmailTemplateSampleData
17 {
18 /**
19 * @param int|null $tripId Optional Yatra trip ID to merge real trip_name, trip_url, trip_id
20 * @return array<string, string>
21 */
22 public static function forTemplateKey(string $templateKey, ?int $tripId = null): array
23 {
24 $vars = self::baseSamples();
25 if ($tripId !== null && $tripId > 0) {
26 $vars = self::mergeTripContext($tripId, $vars);
27 }
28
29 if ($templateKey === 'trip_consent_request') {
30 $vars['recipient_name'] = $vars['customer_name'] ?? __('Alex Traveler', 'yatra');
31 $vars['form_name'] = __('Trip liability & release', 'yatra');
32 $vars['consent_link'] = home_url('/trip-consent/preview-token/');
33 $vars['expiry_notice_html'] = '<strong>' . esc_html__('This link expires soon.', 'yatra') . '</strong> '
34 . esc_html__('Request a new email from the operator if needed.', 'yatra');
35 $vars['consent_test_notice_html'] = '';
36 }
37
38 if ($templateKey === 'customer_email_verification') {
39 $previewTok = defined('YATRA_EMAIL_VERIFICATION_PREVIEW_TOKEN')
40 ? (string) YATRA_EMAIL_VERIFICATION_PREVIEW_TOKEN
41 : 'preview-verify-token';
42 $vars['verification_link'] = function_exists('yatra_get_email_verification_url')
43 ? yatra_get_email_verification_url($previewTok)
44 : home_url('/?yatra_verify_email=' . rawurlencode($previewTok));
45 $vars['intro_paragraph'] = __('Thank you for registering. Click the button below to verify your email and activate your account.', 'yatra');
46 $vars['footer_note'] = __('If you did not create an account, you can ignore this email.', 'yatra');
47 $vars['expiry_notice_html'] = esc_html(
48 sprintf(
49 /* translators: %d: hours until link expiry */
50 __('This verification link expires in %d hours for your security.', 'yatra'),
51 24
52 )
53 );
54 }
55
56 if ($templateKey === 'account_email_change_request') {
57 $vars['new_email'] = 'alex.new@example.com';
58 $vars['verification_link'] = home_url('/?yatra_email_token=preview-change-token');
59 $vars['intro_paragraph'] = __('You recently requested to change the email address on your account. To confirm this new address, click the button below.', 'yatra');
60 $vars['footer_note'] = __('If you did not request this change, you can safely ignore this email — your address will not change.', 'yatra');
61 }
62
63 if ($templateKey === 'account_email_changed') {
64 $vars['new_email'] = 'alex.new@example.com';
65 $vars['intro_paragraph'] = __('The email address on your account was just changed. If this was you, no further action is needed.', 'yatra');
66 $vars['footer_note'] = __('If you did not make this change, please contact us immediately.', 'yatra');
67 }
68
69 /** @var array<string, string> $filtered */
70 $filtered = apply_filters('yatra_email_template_preview_variables', $vars, $templateKey, $tripId);
71
72 return TransactionalEmailTemplateService::mergeTemplateVariables($filtered);
73 }
74
75 /**
76 * @return array<string, string>
77 */
78 private static function baseSamples(): array
79 {
80 $currency = SettingsService::getCurrency();
81 $travelSample = date_i18n(get_option('date_format'), strtotime('+14 days'));
82 $specialSample = __('Late check-in after 10pm if possible.', 'yatra');
83
84 return [
85 'customer_name' => __('Alex Traveler', 'yatra'),
86 'customer_first_name' => 'Alex',
87 'customer_last_name' => __('Traveler', 'yatra'),
88 'customer_email' => 'alex@example.com',
89 'new_email' => 'alex.new@example.com',
90 'customer_phone' => '+1 555 0100',
91 'booking_reference' => 'YTR-PREVIEW-001',
92 'booking_id' => '42',
93 'trip_id' => '101',
94 'trip_name' => __('Sample Mountain Trek', 'yatra'),
95 'travel_date' => $travelSample,
96 'travelers_count' => '2',
97 'total_amount_formatted' => yatra_format_price(2499.0, $currency),
98 'amount_due_formatted' => yatra_format_price(499.0, $currency),
99 // Aliases for the same monetary values — keep the preview
100 // consistent regardless of which spelling the template
101 // uses ({{total_amount}} vs {{total_amount_formatted}},
102 // {{balance_due}} vs {{amount_due_formatted}}, etc.).
103 'total_amount' => yatra_format_price(2499.0, $currency),
104 'balance_due' => yatra_format_price(499.0, $currency),
105 'amount_due' => yatra_format_price(499.0, $currency),
106 'amount_paid' => yatra_format_price(2000.0, $currency),
107 'amount_paid_formatted' => yatra_format_price(2000.0, $currency),
108 'currency' => $currency,
109 'booking_status' => __('confirmed', 'yatra'),
110 'payment_status' => __('pending', 'yatra'),
111 'intro_paragraph' => __('Thank you for your booking. This preview uses sample data.', 'yatra'),
112 'details_html' => '<p><strong>' . esc_html__('Note', 'yatra') . ':</strong> ' . esc_html__('Optional line items appear here.', 'yatra') . '</p>',
113 'footer_note' => __('We look forward to hosting you.', 'yatra'),
114 'payment_amount_formatted' => yatra_format_price(500.0, $currency),
115 'payment_method' => __('Credit card', 'yatra'),
116 'transaction_id' => 'txn_preview_001',
117 'reminder_days' => '7',
118 'days_until_trip' => '7',
119 'reminder_extra_html' => '<p>' . esc_html__('Reminder: check your packing list before departure.', 'yatra') . '</p>',
120 'trip_url' => home_url('/'),
121 'review_url' => home_url('/#reviews'),
122 'admin_url' => admin_url('admin.php?page=yatra'),
123 'booking_url' => home_url('/my-account/bookings/42'),
124 'message' => __('Could you confirm whether airport pickup is included on day one?', 'yatra'),
125 'response' => __('Hi Alex, yes — pickup is included for all guests. Safe travels!', 'yatra'),
126 'original_message' => __('Interested in the April departure dates.', 'yatra'),
127 'expiry_policy_note' => __('Unpaid bookings are released after the deadline.', 'yatra'),
128 'scheduled_amount_formatted' => yatra_format_price(750.0, $currency),
129 'scheduled_date_formatted' => date_i18n(get_option('date_format'), strtotime('+5 days')),
130 'payment_type_label' => __('Installment', 'yatra'),
131 'scheduled_payment_id' => '9',
132 'balance_after_formatted' => yatra_format_price(1749.0, $currency),
133 'failure_reason' => __('Card declined (insufficient funds).', 'yatra'),
134 'failure_intro_html' => '<p style="margin:0;">'
135 . esc_html__('We could not process your scheduled payment.', 'yatra')
136 . '</p>',
137 'failure_followup_html' => esc_html__(
138 'Please update your payment method or contact us so we can retry before your booking is affected.',
139 'yatra'
140 ),
141 'recovery_intro_html' => '<p style="margin:0;">'
142 . esc_html__('You left items in your cart — your trip is still available to book.', 'yatra')
143 . '</p>',
144 'recovery_reminder_label' => __('48 hours left at this price', 'yatra'),
145 'recovery_link' => home_url('/book/preview-recovery/'),
146 'payment_gateway' => 'stripe',
147 'payment_gateway_label' => 'Stripe',
148 'payment_schedule' => 'deposit',
149 'payment_schedule_label' => __('Deposit (balance due later)', 'yatra'),
150 'travelers_list' => "1. Alex Traveler (" . __('Lead', 'yatra') . ")\n2. Sam Guest",
151 'travelers_list_html' => '<ul style="margin:8px 0;padding-left:20px;">'
152 . '<li style="margin:4px 0;">Alex Traveler <span style="color:#64748b;font-size:12px;">(' . esc_html__('Lead', 'yatra') . ')</span></li>'
153 . '<li style="margin:4px 0;">Sam Guest</li></ul>',
154 'traveler_custom_fields_html' => '<div style="margin:12px 0 0;">'
155 . '<p style="margin:0 0 6px;font-weight:600;">' . esc_html__('Traveler 1 — Alex Traveler', 'yatra') . '</p>'
156 . '<table role="presentation" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:collapse;">'
157 . '<tr><td style="padding:4px 12px 4px 0;vertical-align:top;color:#64748b;width:40%;">' . esc_html__('Dietary Requirements', 'yatra') . '</td>'
158 . '<td style="padding:4px 0;vertical-align:top;">' . esc_html__('Vegetarian', 'yatra') . '</td></tr></table></div>',
159 'booking_custom_fields_html' => '<div style="margin:12px 0 0;">'
160 . '<p style="margin:0 0 6px;font-weight:600;">' . esc_html__('Additional services', 'yatra') . '</p>'
161 . '<ul style="margin:0;padding-left:20px;">'
162 . '<li style="margin:4px 0;">' . esc_html__('Airport transfer', 'yatra') . '' . esc_html(yatra_format_price(45.0, $currency)) . '</li>'
163 . '</ul></div>',
164 'special_requests' => $specialSample,
165 'special_requests_html' => nl2br(esc_html($specialSample)),
166 ];
167 }
168
169 /**
170 * @param array<string, string> $vars
171 * @return array<string, string>
172 */
173 private static function mergeTripContext(int $tripId, array $vars): array
174 {
175 try {
176 $repo = new TripRepository();
177 $trip = $repo->findWithRelations($tripId, true);
178 if ($trip && !empty($trip->id)) {
179 $vars['trip_id'] = (string) (int) $trip->id;
180 if (!empty($trip->title)) {
181 $vars['trip_name'] = (string) $trip->title;
182 }
183 if (!empty($trip->slug)) {
184 $vars['trip_url'] = home_url('/' . SettingsService::getTripBase() . '/' . rawurlencode((string) $trip->slug) . '/');
185 }
186 }
187 } catch (\Throwable $e) {
188 // Leave sample trip_* as-is
189 }
190
191 /** @var array<string, string> */
192 return apply_filters('yatra_email_template_trip_variables', $vars, $tripId);
193 }
194
195 public static function isPreviewableTemplateKey(string $templateKey): bool
196 {
197 if (TransactionalEmailTemplateService::coreTemplateKeyToType($templateKey) !== null) {
198 return true;
199 }
200
201 return EmailTemplateDefaults::proSystemTemplate($templateKey) !== null;
202 }
203 }
204