PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.4
Yatra – Travel Booking & Tour Operator Software v3.0.4
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.4, at app/Services/EmailTemplateSampleData.php

181 lines 9.3 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 */
50 __('This verification link expires in %d hours for your security.', 'yatra'),
51 24
52 )
53 );
54 }
55
56 /** @var array<string, string> $filtered */
57 $filtered = apply_filters('yatra_email_template_preview_variables', $vars, $templateKey, $tripId);
58
59 return TransactionalEmailTemplateService::mergeTemplateVariables($filtered);
60 }
61
62 /**
63 * @return array<string, string>
64 */
65 private static function baseSamples(): array
66 {
67 $currency = SettingsService::getCurrency();
68 $travelSample = date_i18n(get_option('date_format'), strtotime('+14 days'));
69 $specialSample = __('Late check-in after 10pm if possible.', 'yatra');
70
71 return [
72 'customer_name' => __('Alex Traveler', 'yatra'),
73 'customer_first_name' => 'Alex',
74 'customer_last_name' => __('Traveler', 'yatra'),
75 'customer_email' => 'alex@example.com',
76 'customer_phone' => '+1 555 0100',
77 'booking_reference' => 'YTR-PREVIEW-001',
78 'booking_id' => '42',
79 'trip_id' => '101',
80 'trip_name' => __('Sample Mountain Trek', 'yatra'),
81 'travel_date' => $travelSample,
82 'travelers_count' => '2',
83 'total_amount_formatted' => yatra_format_price(2499.0, $currency),
84 'amount_due_formatted' => yatra_format_price(499.0, $currency),
85 'currency' => $currency,
86 'booking_status' => __('confirmed', 'yatra'),
87 'payment_status' => __('pending', 'yatra'),
88 'intro_paragraph' => __('Thank you for your booking. This preview uses sample data.', 'yatra'),
89 'details_html' => '<p><strong>' . esc_html__('Note', 'yatra') . ':</strong> ' . esc_html__('Optional line items appear here.', 'yatra') . '</p>',
90 'footer_note' => __('We look forward to hosting you.', 'yatra'),
91 'payment_amount_formatted' => yatra_format_price(500.0, $currency),
92 'payment_method' => __('Credit card', 'yatra'),
93 'transaction_id' => 'txn_preview_001',
94 'reminder_days' => '7',
95 'days_until_trip' => '7',
96 'reminder_extra_html' => '<p>' . esc_html__('Reminder: check your packing list before departure.', 'yatra') . '</p>',
97 'trip_url' => home_url('/'),
98 'review_url' => home_url('/#reviews'),
99 'admin_url' => admin_url('admin.php?page=yatra'),
100 'booking_url' => home_url('/my-account/bookings/42'),
101 'message' => __('Could you confirm whether airport pickup is included on day one?', 'yatra'),
102 'response' => __('Hi Alex, yes — pickup is included for all guests. Safe travels!', 'yatra'),
103 'original_message' => __('Interested in the April departure dates.', 'yatra'),
104 'expiry_policy_note' => __('Unpaid bookings are released after the deadline.', 'yatra'),
105 'scheduled_amount_formatted' => yatra_format_price(750.0, $currency),
106 'scheduled_date_formatted' => date_i18n(get_option('date_format'), strtotime('+5 days')),
107 'payment_type_label' => __('Installment', 'yatra'),
108 'scheduled_payment_id' => '9',
109 'balance_after_formatted' => yatra_format_price(1749.0, $currency),
110 'failure_reason' => __('Card declined (insufficient funds).', 'yatra'),
111 'failure_intro_html' => '<p style="margin:0;">'
112 . esc_html__('We could not process your scheduled payment.', 'yatra')
113 . '</p>',
114 'failure_followup_html' => esc_html__(
115 'Please update your payment method or contact us so we can retry before your booking is affected.',
116 'yatra'
117 ),
118 'recovery_intro_html' => '<p style="margin:0;">'
119 . esc_html__('You left items in your cart — your trip is still available to book.', 'yatra')
120 . '</p>',
121 'recovery_reminder_label' => __('48 hours left at this price', 'yatra'),
122 'recovery_link' => home_url('/book/preview-recovery/'),
123 'payment_gateway' => 'stripe',
124 'payment_gateway_label' => 'Stripe',
125 'payment_schedule' => 'deposit',
126 'payment_schedule_label' => __('Deposit (balance due later)', 'yatra'),
127 'travelers_list' => "1. Alex Traveler (" . __('Lead', 'yatra') . ")\n2. Sam Guest",
128 'travelers_list_html' => '<ul style="margin:8px 0;padding-left:20px;">'
129 . '<li style="margin:4px 0;">Alex Traveler <span style="color:#64748b;font-size:12px;">(' . esc_html__('Lead', 'yatra') . ')</span></li>'
130 . '<li style="margin:4px 0;">Sam Guest</li></ul>',
131 'traveler_custom_fields_html' => '<div style="margin:12px 0 0;">'
132 . '<p style="margin:0 0 6px;font-weight:600;">' . esc_html__('Traveler 1 — Alex Traveler', 'yatra') . '</p>'
133 . '<table role="presentation" cellpadding="0" cellspacing="0" style="width:100%;border-collapse:collapse;">'
134 . '<tr><td style="padding:4px 12px 4px 0;vertical-align:top;color:#64748b;width:40%;">' . esc_html__('Dietary Requirements', 'yatra') . '</td>'
135 . '<td style="padding:4px 0;vertical-align:top;">' . esc_html__('Vegetarian', 'yatra') . '</td></tr></table></div>',
136 'booking_custom_fields_html' => '<div style="margin:12px 0 0;">'
137 . '<p style="margin:0 0 6px;font-weight:600;">' . esc_html__('Additional services', 'yatra') . '</p>'
138 . '<ul style="margin:0;padding-left:20px;">'
139 . '<li style="margin:4px 0;">' . esc_html__('Airport transfer', 'yatra') . '' . esc_html(yatra_format_price(45.0, $currency)) . '</li>'
140 . '</ul></div>',
141 'special_requests' => $specialSample,
142 'special_requests_html' => nl2br(esc_html($specialSample)),
143 ];
144 }
145
146 /**
147 * @param array<string, string> $vars
148 * @return array<string, string>
149 */
150 private static function mergeTripContext(int $tripId, array $vars): array
151 {
152 try {
153 $repo = new TripRepository();
154 $trip = $repo->findWithRelations($tripId, true);
155 if ($trip && !empty($trip->id)) {
156 $vars['trip_id'] = (string) (int) $trip->id;
157 if (!empty($trip->title)) {
158 $vars['trip_name'] = (string) $trip->title;
159 }
160 if (!empty($trip->slug)) {
161 $vars['trip_url'] = home_url('/' . SettingsService::getTripBase() . '/' . rawurlencode((string) $trip->slug) . '/');
162 }
163 }
164 } catch (\Throwable $e) {
165 // Leave sample trip_* as-is
166 }
167
168 /** @var array<string, string> */
169 return apply_filters('yatra_email_template_trip_variables', $vars, $tripId);
170 }
171
172 public static function isPreviewableTemplateKey(string $templateKey): bool
173 {
174 if (TransactionalEmailTemplateService::coreTemplateKeyToType($templateKey) !== null) {
175 return true;
176 }
177
178 return EmailTemplateDefaults::proSystemTemplate($templateKey) !== null;
179 }
180 }
181